optimized codes of VKArrayBuffer

This commit is contained in:
HuYingzhuo(hugo/hyzboy) 2023-03-29 11:45:15 +08:00
parent 59b02bcb8c
commit 38f9a2896f
2 changed files with 20 additions and 25 deletions

View File

@ -19,10 +19,6 @@ namespace hgl
{ {
protected: protected:
GPUDevice *device;
VkBufferUsageFlags buffer_usage_flags;
uint item_length; ///<单个数据长度
uint unit_size; uint unit_size;
VKMemoryAllocator *vk_ma; VKMemoryAllocator *vk_ma;
@ -36,7 +32,7 @@ namespace hgl
private: private:
GPUArrayBuffer(GPUDevice *dev,const VkBufferUsageFlags &flag,const uint il,const uint us); GPUArrayBuffer(VKMemoryAllocator *,const uint);
friend class GPUDevice; friend class GPUDevice;
@ -59,11 +55,12 @@ namespace hgl
if(!ptr)return(false); if(!ptr)return(false);
ubo_access->Start((uchar *)ptr,start,count); ubo_access->Start((uchar *)ptr,unit_size,count);
return(true); return(true);
} }
void End(UBODynamicAccess<void> *ubo_access) template<typename T>
void End(UBODynamicAccess<T> *ubo_access)
{ {
if(!ubo_access)return; if(!ubo_access)return;

View File

@ -8,15 +8,11 @@ namespace hgl
{ {
namespace graph namespace graph
{ {
GPUArrayBuffer::GPUArrayBuffer(GPUDevice *dev,const VkBufferUsageFlags &flag,const uint il,const uint us) GPUArrayBuffer::GPUArrayBuffer(VKMemoryAllocator *va,const uint us)
{ {
device=dev; vk_ma=va;
item_length=il; unit_size=us;
buffer_usage_flags=flag;
unit_size=hgl_align<VkDeviceSize>(item_length,us);
vk_ma=new VKMemoryAllocator(device,buffer_usage_flags,unit_size); // construct function is going to set AllocUnitSize by minUniformOffsetAlignment
MemoryBlock *mb=new MemoryBlock(vk_ma); MemoryBlock *mb=new MemoryBlock(vk_ma);
coll=new Collection(unit_size,mb); coll=new Collection(unit_size,mb);
@ -52,23 +48,25 @@ namespace hgl
void GPUArrayBuffer::Flush(const uint32 count) void GPUArrayBuffer::Flush(const uint32 count)
{ {
vk_ma->Flush(count*GetUnitSize()); vk_ma->Flush(count*unit_size);
} }
GPUArrayBuffer *GPUDevice::CreateUBO(const VkDeviceSize &uint_size) GPUArrayBuffer *GPUDevice::CreateUBO(const VkDeviceSize &item_length)
{ {
return(new GPUArrayBuffer( this, const uint unit_size=hgl_align<VkDeviceSize>(item_length,GetUBOAlign());
VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
uint_size, auto vk_ma=new VKMemoryAllocator(this,VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,unit_size);
GetUBOAlign()));
return(new GPUArrayBuffer(vk_ma,unit_size));
} }
GPUArrayBuffer *GPUDevice::CreateSSBO(const VkDeviceSize &uint_size) GPUArrayBuffer *GPUDevice::CreateSSBO(const VkDeviceSize &item_length)
{ {
return(new GPUArrayBuffer( this, const uint unit_size=hgl_align<VkDeviceSize>(item_length,GetSSBOAlign());
VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
uint_size, auto vk_ma=new VKMemoryAllocator(this,VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,unit_size);
GetSSBOAlign()));
return(new GPUArrayBuffer(vk_ma,unit_size));
} }
}//namespace graph }//namespace graph
}//namespace hgl }//namespace hgl