2021-03-25 20:00:19 +08:00
|
|
|
#include<hgl/graph/VKMemoryAllocator.h>
|
|
|
|
#include<hgl/graph/VKDevice.h>
|
|
|
|
#include<hgl/graph/VKPhysicalDevice.h>
|
|
|
|
#include<hgl/graph/VKBuffer.h>
|
|
|
|
|
|
|
|
VK_NAMESPACE_BEGIN
|
|
|
|
VKMemoryAllocator::VKMemoryAllocator(GPUDevice *d,const uint32_t flags)
|
|
|
|
{
|
|
|
|
device=d;
|
|
|
|
buffer_usage_flag_bits=flags;
|
|
|
|
gpu_buffer=nullptr;
|
|
|
|
|
|
|
|
const GPUPhysicalDevice *pd=device->GetPhysicalDevice();
|
|
|
|
|
2021-05-08 17:55:16 +08:00
|
|
|
SetAllocUnitSize(pd->GetUBOAlign());
|
2021-03-25 20:00:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
VKMemoryAllocator::~VKMemoryAllocator()
|
|
|
|
{
|
2021-04-06 19:13:53 +08:00
|
|
|
if(gpu_buffer)
|
|
|
|
{
|
|
|
|
gpu_buffer->Unmap();
|
|
|
|
delete gpu_buffer;
|
|
|
|
}
|
2021-03-25 20:00:19 +08:00
|
|
|
}
|
|
|
|
|
2021-05-08 17:55:16 +08:00
|
|
|
bool VKMemoryAllocator::AllocMemory()
|
2021-03-25 20:00:19 +08:00
|
|
|
{
|
|
|
|
if(gpu_buffer)
|
|
|
|
delete gpu_buffer;
|
|
|
|
|
|
|
|
gpu_buffer=device->CreateBuffer(buffer_usage_flag_bits,alloc_size);
|
|
|
|
|
|
|
|
if(!gpu_buffer)
|
|
|
|
{
|
|
|
|
memory_block=nullptr;
|
|
|
|
return(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
memory_block=gpu_buffer->Map();
|
|
|
|
|
|
|
|
return(true);
|
|
|
|
}
|
|
|
|
VK_NAMESPACE_END
|