ULRE/inc/hgl/graph/VKArrayBuffer.h

71 lines
2.0 KiB
C
Raw Normal View History

2021-03-25 20:00:19 +08:00
#ifndef HGL_GRAPH_VULKAN_ARRAY_BUFFER_INCLUDE
2021-02-10 18:53:07 +08:00
#define HGL_GRAPH_VULKAN_ARRAY_BUFFER_INCLUDE
#include<hgl/graph/VKBuffer.h>
2021-03-25 20:00:19 +08:00
#include<hgl/graph/VKDevice.h>
#include<hgl/graph/VKMemoryAllocator.h>
#include<hgl/type/Collection.h>
2021-02-10 18:53:07 +08:00
namespace hgl
{
namespace graph
{
/**
2021-03-25 20:00:19 +08:00
* GPU数据阵列缓冲区<br>
* instance等
2021-02-10 18:53:07 +08:00
*/
template<typename T> class GPUArrayBuffer
2021-02-10 18:53:07 +08:00
{
protected:
GPUDevice *device;
VkBufferUsageFlags buffer_usage_flags;
2021-02-10 18:53:07 +08:00
2021-05-08 18:14:44 +08:00
Collection *coll;
2021-02-10 18:53:07 +08:00
public:
GPUArrayBuffer(GPUDevice *dev,VkBufferUsageFlags flags)
{
device=dev;
buffer_usage_flags=flags;
2021-05-08 18:14:44 +08:00
{
2021-05-08 19:02:08 +08:00
uint32_t unit_size=sizeof(T);
VKMemoryAllocator *ma=new VKMemoryAllocator(device,buffer_usage_flags); // construct function is going to set AllocUnitSize by minUniformOffsetAlignment
2021-05-08 18:14:44 +08:00
MemoryBlock *mb=new MemoryBlock(ma);
const uint32_t align_size=ma->GetAllocUnitSize()-1; // this value is "min UBO Offset alignment"
2021-05-08 19:02:08 +08:00
unit_size=(unit_size+align_size)&(~align_size);
2021-05-08 18:14:44 +08:00
coll=new Collection(unit_size,mb);
}
}
virtual ~GPUArrayBuffer()
{
delete coll;
}
uint32 Alloc(const uint32 max_count) ///<预分配空间
{
if(!coll->Alloc(max_count))
return(0);
2021-02-10 18:53:07 +08:00
return coll->GetAllocCount();
}
2021-02-10 18:53:07 +08:00
void Clear()
{
coll->Clear();
}
2021-03-25 20:00:19 +08:00
T *Map(const uint32 start,const uint32 count)
{
return (T *)(coll->Map(start,count));
}
2021-02-10 18:53:07 +08:00
};//class GPUArrayBuffer
}//namespace graph
}//namespace hgl
#endif//HGL_GRAPH_VULKAN_ARRAY_BUFFER_INCLUDE