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
|
|
|
|
|
|
2023-03-24 20:39:02 +08:00
|
|
|
|
#include<hgl/graph/VK.h>
|
2023-04-25 11:43:15 +08:00
|
|
|
|
#include<hgl/graph/VKDynamicBufferAccess.h>
|
2021-02-10 18:53:07 +08:00
|
|
|
|
namespace hgl
|
|
|
|
|
{
|
2023-03-24 20:39:02 +08:00
|
|
|
|
class Collection;
|
|
|
|
|
|
2021-02-10 18:53:07 +08:00
|
|
|
|
namespace graph
|
|
|
|
|
{
|
2023-03-24 20:39:02 +08:00
|
|
|
|
class VKMemoryAllocator;
|
|
|
|
|
|
2021-02-10 18:53:07 +08:00
|
|
|
|
/**
|
2021-03-25 20:00:19 +08:00
|
|
|
|
* GPU数据阵列缓冲区<br>
|
|
|
|
|
* 它用于储存多份相同格式的数据,常用于多物件渲染,instance等
|
2021-02-10 18:53:07 +08:00
|
|
|
|
*/
|
2023-03-22 21:18:46 +08:00
|
|
|
|
class GPUArrayBuffer
|
2021-02-10 18:53:07 +08:00
|
|
|
|
{
|
|
|
|
|
protected:
|
|
|
|
|
|
2023-04-25 11:36:50 +08:00
|
|
|
|
uint align_size;
|
|
|
|
|
uint range_size;
|
2023-03-22 21:18:46 +08:00
|
|
|
|
|
2021-06-15 15:03:09 +08:00
|
|
|
|
VKMemoryAllocator *vk_ma;
|
|
|
|
|
|
2021-05-08 18:14:44 +08:00
|
|
|
|
Collection *coll;
|
2021-02-10 18:53:07 +08:00
|
|
|
|
|
2023-03-28 21:52:08 +08:00
|
|
|
|
protected:
|
|
|
|
|
|
|
|
|
|
void * Map(const uint32 start,const uint32 count);
|
|
|
|
|
void Flush(const uint32 count);
|
|
|
|
|
|
2023-03-28 22:24:22 +08:00
|
|
|
|
private:
|
|
|
|
|
|
2023-04-25 11:36:50 +08:00
|
|
|
|
GPUArrayBuffer(VKMemoryAllocator *,const uint,const uint);
|
2023-03-28 22:24:22 +08:00
|
|
|
|
|
|
|
|
|
friend class GPUDevice;
|
|
|
|
|
|
2021-04-26 20:36:56 +08:00
|
|
|
|
public:
|
2021-04-06 19:13:53 +08:00
|
|
|
|
|
2023-03-24 20:39:02 +08:00
|
|
|
|
virtual ~GPUArrayBuffer();
|
2021-02-10 18:53:07 +08:00
|
|
|
|
|
2023-04-25 11:36:50 +08:00
|
|
|
|
const uint32_t GetAlignSize()const{return align_size;} ///<数据对齐字节数
|
|
|
|
|
const uint32_t GetRangeSize()const{return range_size;} ///<单次渲染访问最大字节数
|
|
|
|
|
|
2023-03-24 20:39:02 +08:00
|
|
|
|
DeviceBuffer * GetBuffer();
|
2021-03-25 20:00:19 +08:00
|
|
|
|
|
2023-04-25 11:36:50 +08:00
|
|
|
|
uint32 Alloc(const uint32 max_count); ///<预分配空间
|
2023-03-24 20:39:02 +08:00
|
|
|
|
void Clear();
|
2021-06-22 21:33:47 +08:00
|
|
|
|
|
2023-03-28 21:52:08 +08:00
|
|
|
|
template<typename T>
|
2023-04-25 11:43:15 +08:00
|
|
|
|
bool Start(DynamicBufferAccess<T> *dba,const uint32 start,const uint32 count)
|
2023-03-28 21:52:08 +08:00
|
|
|
|
{
|
2023-04-25 11:43:15 +08:00
|
|
|
|
if(!dba)return(false);
|
2023-03-28 21:52:08 +08:00
|
|
|
|
|
|
|
|
|
void *ptr=Map(start,count);
|
|
|
|
|
|
|
|
|
|
if(!ptr)return(false);
|
|
|
|
|
|
2023-04-25 11:43:15 +08:00
|
|
|
|
dba->Start((uchar *)ptr,align_size,count);
|
2023-03-28 21:52:08 +08:00
|
|
|
|
return(true);
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-29 11:45:15 +08:00
|
|
|
|
template<typename T>
|
2023-04-25 11:43:15 +08:00
|
|
|
|
void End(DynamicBufferAccess<T> *dba)
|
2023-03-28 21:52:08 +08:00
|
|
|
|
{
|
2023-04-25 11:43:15 +08:00
|
|
|
|
if(!dba)return;
|
2023-03-28 21:52:08 +08:00
|
|
|
|
|
2023-04-25 11:43:15 +08:00
|
|
|
|
Flush(dba->GetCount());
|
2023-03-28 21:52:08 +08:00
|
|
|
|
|
2023-04-25 11:43:15 +08:00
|
|
|
|
dba->Restart();
|
2023-03-28 21:52:08 +08:00
|
|
|
|
}
|
2021-02-10 18:53:07 +08:00
|
|
|
|
};//class GPUArrayBuffer
|
|
|
|
|
}//namespace graph
|
|
|
|
|
}//namespace hgl
|
|
|
|
|
#endif//HGL_GRAPH_VULKAN_ARRAY_BUFFER_INCLUDE
|