Skip to content
Snippets Groups Projects

Resolve "Resource Management"

Merged Ghost User requested to merge 22-resource-management into develop
Files
2
+ 33
24
@@ -34,26 +34,32 @@ namespace vkcv {
// explicit destruction of default constructor
Buffer<T>() = delete;
// is never called directly
~Buffer<T>() {
~Buffer<T>() noexcept {
m_Device.freeMemory(m_BufferMemory);
m_Device.destroyBuffer(m_Buffer);
} //noexcept; //gibt Fehlermeldung
}
Buffer<T>(const Buffer<T>& other) = delete; // copy-ctor
Buffer<T>(Buffer<T>&& other) {
Buffer<T>(Buffer<T>&& other) noexcept :
m_Buffer(other.m_Buffer),
m_BufferMemory(other.m_BufferMemory),
m_Device(other.m_Device),
m_MemoryRequirement(other.m_MemoryRequirement),
m_Type(other.m_Type),
m_Size(other.m_Size),
m_DataP(other.m_DataP)
{
other.m_Buffer = nullptr;
other.m_BufferMemory = nullptr;
other.m_Device = nullptr;
other.m_MemoryRequirement = nullptr;
other.m_Type = vkcv::VERTEX;
//other.m_MemoryRequirement = nullptr; // WIP alternative to nullptr has to be found
other.m_Type = vkcv::VERTEX; //set to 0
other.m_Size = 0;
other.m_DataP = nullptr;
return *this;
} //noexcept; // move-ctor
} // move-ctor
Buffer<T>& operator=(const Buffer<T>& other) = delete; // copy assignment
Buffer<T>& operator=(Buffer<T>&& other) {
Buffer<T>& operator=(Buffer<T>&& other) noexcept {
m_Buffer = other.m_Buffer;
m_BufferMemory = other.m_BufferMemory;
m_Device = other.m_Device;
@@ -65,28 +71,32 @@ namespace vkcv {
other.m_Buffer = nullptr;
other.m_BufferMemory = nullptr;
other.m_Device = nullptr;
other.m_MemoryRequirement = nullptr;
other.m_Type = vkcv::VERTEX;
//other.m_MemoryRequirement = nullptr; // WIP alternative to nullptr has to be found
other.m_Type = vkcv::VERTEX; //set to 0
other.m_Size = 0;
other.m_DataP = nullptr;
}//noexcept; // move assignment
}// move assignment
BufferType getType() { return m_Type; };
size_t getSize() { return m_Size; };
//i'm not sure what the input argument has to be, WORK IN PROGRESS
//TODO
void fill(void* data) {
// TODO: we will probably need staging-buffer here later (possible add in BufferManager later?)
void fill(T* data, size_t count) {
// TODO: check if mapped already
m_DataP = static_cast<uint8_t*>(m_Device.mapMemory(m_BufferMemory, 0, m_MemoryRequirement.size));
memcpy(m_DataP, data, sizeof(data));
memcpy(m_DataP, data, sizeof(T) * count);
m_Device.unmapMemory(m_BufferMemory);
};
void map() {
m_DataP = static_cast<uint8_t*>(m_Device.mapMemory(m_BufferMemory, 0, m_MemoryRequirement.size));
// TODO: make sure to unmap before deallocation
};
void unmap() {
m_Device.unmapMemory(m_BufferMemory);
// TODO: mark m_DataP as invalid?
};
private:
@@ -96,14 +106,14 @@ namespace vkcv {
vk::MemoryRequirements m_MemoryRequirement;
BufferType m_Type;
size_t m_Size=0;
static uint8_t* m_DataP;
uint8_t* m_DataP;
/**
* @brief searches memory type index for buffer allocation, inspired by vulkan tutorial and "https://github.com/KhronosGroup/Vulkan-Hpp/blob/master/samples/utils/utils.hpp"
* @param memoryProperties
* @param physicalMemoryProperties Memory Properties of physical device
* @param typeBits
* @param requirementsMask
* @return memory type for Buffer
* @param requirements Property flags that are required
* @return memory type index for Buffer
*/
uint32_t searchMemoryType(vk::PhysicalDeviceMemoryProperties const& physicalMemoryProperties, uint32_t typeBits, vk::MemoryPropertyFlags requirements) {
uint32_t memoryTypeIndex = uint32_t(0);
@@ -121,8 +131,7 @@ namespace vkcv {
};
/**
* * Constructor of #Buffer requires a @p device, a @p physicalDevice, a @p buffer type and a @p size.
*
* * Constructor of #Buffer requires a @p device, a @p physicalDevice, a @p buffer type and a @p size. *
* @param device Vulkan-Device
* @param physicalDevice Vulkan-PhysicalDevice
* @param type Enum type of possible vkcv::BufferType
@@ -132,7 +141,7 @@ namespace vkcv {
m_Type = type;
m_Size = size;
m_Device = device;
m_DataP = nullptr;
switch (m_Type) {
case VERTEX: {
Loading