add VKMemoryAllocator
This commit is contained in:
@@ -1,16 +1,19 @@
|
||||
#include<hgl/graph/VKArrayBuffer.h>
|
||||
#include<hgl/graph/VKArrayBuffer.h>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
/**
|
||||
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>캯<EFBFBD><EFBFBD>
|
||||
* @param s <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>
|
||||
* @param c <20><><EFBFBD>ݸ<EFBFBD><DDB8><EFBFBD>
|
||||
* 本类构造函数
|
||||
* @param d 设备指针
|
||||
* @param s 单个数据长度
|
||||
* @param c 数据个数
|
||||
*/
|
||||
GPUArrayBuffer::GPUArrayBuffer(const uint32_t s,const uint32_t c)
|
||||
GPUArrayBuffer::GPUArrayBuffer(GPUDevice *d,const uint32_t s,const uint32_t c)
|
||||
{
|
||||
device=d;
|
||||
|
||||
item_size=s;
|
||||
count=c;
|
||||
alloc_count=power_to_2(c);
|
||||
@@ -22,6 +25,7 @@ namespace hgl
|
||||
|
||||
GPUArrayBuffer::~GPUArrayBuffer()
|
||||
{
|
||||
SAFE_CLEAR_ARRAY(offset);
|
||||
SAFE_CLEAR(buf_gpu);
|
||||
}
|
||||
|
||||
@@ -30,6 +34,27 @@ namespace hgl
|
||||
count=0;
|
||||
}
|
||||
|
||||
bool GPUArrayBuffer::Init(const uint32_t c)
|
||||
{
|
||||
if(c<=0)return(false);
|
||||
|
||||
if(!buf_gpu)
|
||||
{
|
||||
count=c;
|
||||
alloc_count=power_to_2(count);
|
||||
|
||||
total_bytes=item_size*alloc_count;
|
||||
|
||||
if(total_bytes<=0)return(false);
|
||||
|
||||
buf_gpu=device->CreateUBO(total_bytes);
|
||||
buf_cpu=(uint8 *)(buf_gpu->Map());
|
||||
|
||||
offset=new uint32_t[alloc_count];
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
}
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
|
@@ -15,7 +15,7 @@ GPUDevice::GPUDevice(GPUDeviceAttribute *da)
|
||||
{
|
||||
attr=da;
|
||||
|
||||
textureSQ=nullptr;
|
||||
texture_queue=nullptr;
|
||||
texture_cmd_buf=nullptr;
|
||||
|
||||
swapchain=nullptr;
|
||||
@@ -28,7 +28,7 @@ GPUDevice::~GPUDevice()
|
||||
SAFE_CLEAR(swapchainRT);
|
||||
SAFE_CLEAR(swapchain);
|
||||
|
||||
SAFE_CLEAR(textureSQ);
|
||||
SAFE_CLEAR(texture_queue);
|
||||
SAFE_CLEAR(texture_cmd_buf);
|
||||
|
||||
delete attr;
|
||||
@@ -39,7 +39,7 @@ bool GPUDevice::Resize(const VkExtent2D &extent)
|
||||
SAFE_CLEAR(swapchainRT);
|
||||
SAFE_CLEAR(swapchain);
|
||||
|
||||
SAFE_CLEAR(textureSQ);
|
||||
SAFE_CLEAR(texture_queue);
|
||||
SAFE_CLEAR(texture_cmd_buf);
|
||||
|
||||
attr->Refresh();
|
||||
@@ -48,7 +48,7 @@ bool GPUDevice::Resize(const VkExtent2D &extent)
|
||||
return(false);
|
||||
|
||||
texture_cmd_buf=CreateTextureCommandBuffer();
|
||||
textureSQ=new GPUQueue(this,attr->graphics_queue,1);
|
||||
texture_queue=new GPUQueue(this,attr->graphics_queue,1);
|
||||
|
||||
swapchainRT=new SwapchainRenderTarget(this,swapchain);
|
||||
|
||||
|
@@ -426,9 +426,9 @@ bool GPUDevice::SubmitTexture(const VkCommandBuffer *cmd_bufs,const uint32_t cou
|
||||
if(!cmd_bufs||count<=0)
|
||||
return(false);
|
||||
|
||||
textureSQ->Submit(cmd_bufs,count,nullptr,nullptr);
|
||||
// textureSQ->WaitQueue();
|
||||
textureSQ->WaitFence();
|
||||
texture_queue->Submit(cmd_bufs,count,nullptr,nullptr);
|
||||
// texture_queue->WaitQueue();
|
||||
texture_queue->WaitFence();
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
40
src/SceneGraph/Vulkan/VKMemoryAllocator.cpp
Normal file
40
src/SceneGraph/Vulkan/VKMemoryAllocator.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
#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();
|
||||
|
||||
SetAllocUnitSize(pd->GetConstantSize()); //<2F><>˵push constant<6E><74><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>GPU<50><55><EFBFBD><EFBFBD>С<EFBFBD><D0A1><EFBFBD>ʵ<EFBFBD>λ
|
||||
}
|
||||
|
||||
VKMemoryAllocator::~VKMemoryAllocator()
|
||||
{
|
||||
SAFE_CLEAR(gpu_buffer);
|
||||
}
|
||||
|
||||
bool VKMemoryAllocator::Alloc()
|
||||
{
|
||||
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
|
Reference in New Issue
Block a user