moved codes to .cpp from VKArrayBuffer.h
This commit is contained in:
parent
939bbfeb1f
commit
8363275b36
@ -1,14 +1,15 @@
|
|||||||
#ifndef HGL_GRAPH_VULKAN_ARRAY_BUFFER_INCLUDE
|
#ifndef HGL_GRAPH_VULKAN_ARRAY_BUFFER_INCLUDE
|
||||||
#define HGL_GRAPH_VULKAN_ARRAY_BUFFER_INCLUDE
|
#define HGL_GRAPH_VULKAN_ARRAY_BUFFER_INCLUDE
|
||||||
|
|
||||||
#include<hgl/graph/VKBuffer.h>
|
#include<hgl/graph/VK.h>
|
||||||
#include<hgl/graph/VKDevice.h>
|
|
||||||
#include<hgl/graph/VKMemoryAllocator.h>
|
|
||||||
#include<hgl/type/Collection.h>
|
|
||||||
namespace hgl
|
namespace hgl
|
||||||
{
|
{
|
||||||
|
class Collection;
|
||||||
|
|
||||||
namespace graph
|
namespace graph
|
||||||
{
|
{
|
||||||
|
class VKMemoryAllocator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GPU数据阵列缓冲区<br>
|
* GPU数据阵列缓冲区<br>
|
||||||
* 它用于储存多份相同格式的数据,常用于多物件渲染,instance等
|
* 它用于储存多份相同格式的数据,常用于多物件渲染,instance等
|
||||||
@ -30,66 +31,18 @@ namespace hgl
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
GPUArrayBuffer(GPUDevice *dev,VkBufferUsageFlags flags,const uint il)
|
GPUArrayBuffer(GPUDevice *dev,VkBufferUsageFlags flags,const uint il);
|
||||||
{
|
virtual ~GPUArrayBuffer();
|
||||||
device=dev;
|
|
||||||
buffer_usage_flags=flags;
|
|
||||||
item_length=il;
|
|
||||||
|
|
||||||
{
|
const uint32_t GetOffsetAlignment()const{return ubo_offset_alignment;}
|
||||||
ubo_offset_alignment=device->GetUBOAlign();
|
const uint32_t GetUnitSize()const;
|
||||||
|
DeviceBuffer * GetBuffer();
|
||||||
|
|
||||||
const uint32_t unit_size=hgl_align<uint32_t>(item_length,ubo_offset_alignment);
|
uint32 Alloc(const uint32 max_count); ///<预分配空间
|
||||||
|
void Clear();
|
||||||
|
|
||||||
vk_ma=new VKMemoryAllocator(device,buffer_usage_flags,unit_size); // construct function is going to set AllocUnitSize by minUniformOffsetAlignment
|
void * Map(const uint32 start,const uint32 count);
|
||||||
MemoryBlock *mb=new MemoryBlock(vk_ma);
|
void Flush(const uint32 count);
|
||||||
|
|
||||||
coll=new Collection(unit_size,mb);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual ~GPUArrayBuffer()
|
|
||||||
{
|
|
||||||
delete coll;
|
|
||||||
}
|
|
||||||
|
|
||||||
const uint32_t GetOffsetAlignment()const
|
|
||||||
{
|
|
||||||
return ubo_offset_alignment;
|
|
||||||
}
|
|
||||||
|
|
||||||
const uint32_t GetUnitSize()const
|
|
||||||
{
|
|
||||||
return coll->GetUnitBytes();
|
|
||||||
}
|
|
||||||
|
|
||||||
DeviceBuffer *GetBuffer()
|
|
||||||
{
|
|
||||||
return vk_ma->GetBuffer();
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32 Alloc(const uint32 max_count) ///<预分配空间
|
|
||||||
{
|
|
||||||
if(!coll->Alloc(max_count))
|
|
||||||
return(0);
|
|
||||||
|
|
||||||
return coll->GetAllocCount();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Clear()
|
|
||||||
{
|
|
||||||
coll->Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
void *Map(const uint32 start,const uint32 count)
|
|
||||||
{
|
|
||||||
return coll->Map(start,count);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Flush(const uint32 count)
|
|
||||||
{
|
|
||||||
vk_ma->Flush(count*GetUnitSize());
|
|
||||||
}
|
|
||||||
};//class GPUArrayBuffer
|
};//class GPUArrayBuffer
|
||||||
}//namespace graph
|
}//namespace graph
|
||||||
}//namespace hgl
|
}//namespace hgl
|
||||||
|
@ -1,60 +1,65 @@
|
|||||||
#include<hgl/graph/VKArrayBuffer.h>
|
#include<hgl/graph/VKArrayBuffer.h>
|
||||||
|
#include<hgl/graph/VKMemoryAllocator.h>
|
||||||
|
#include<hgl/type/Collection.h>
|
||||||
|
#include<hgl/graph/VKBuffer.h>
|
||||||
|
#include<hgl/graph/VKDevice.h>
|
||||||
|
|
||||||
namespace hgl
|
namespace hgl
|
||||||
{
|
{
|
||||||
namespace graph
|
namespace graph
|
||||||
{
|
{
|
||||||
/**
|
GPUArrayBuffer::GPUArrayBuffer(GPUDevice *dev,VkBufferUsageFlags flags,const uint il)
|
||||||
* 本类构造函数
|
|
||||||
* @param d 设备指针
|
|
||||||
* @param s 单个数据长度
|
|
||||||
* @param c 数据个数
|
|
||||||
*/
|
|
||||||
GPUArrayBuffer::GPUArrayBuffer(GPUDevice *d,const uint32_t s,const uint32_t c)
|
|
||||||
{
|
{
|
||||||
device=d;
|
device=dev;
|
||||||
|
buffer_usage_flags=flags;
|
||||||
|
item_length=il;
|
||||||
|
|
||||||
item_size=s;
|
ubo_offset_alignment=device->GetUBOAlign();
|
||||||
count=c;
|
|
||||||
alloc_count=power_to_2(c);
|
|
||||||
|
|
||||||
buf_gpu=nullptr;
|
const uint32_t unit_size=hgl_align<uint32_t>(item_length,ubo_offset_alignment);
|
||||||
buf_cpu=nullptr;
|
|
||||||
offset=nullptr;
|
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);
|
||||||
|
|
||||||
|
coll=new Collection(unit_size,mb);
|
||||||
}
|
}
|
||||||
|
|
||||||
GPUArrayBuffer::~GPUArrayBuffer()
|
GPUArrayBuffer::~GPUArrayBuffer()
|
||||||
{
|
{
|
||||||
SAFE_CLEAR_ARRAY(offset);
|
delete coll;
|
||||||
SAFE_CLEAR(buf_gpu);
|
}
|
||||||
|
|
||||||
|
const uint32_t GPUArrayBuffer::GetUnitSize()const
|
||||||
|
{
|
||||||
|
return coll->GetUnitBytes();
|
||||||
|
}
|
||||||
|
|
||||||
|
DeviceBuffer *GPUArrayBuffer::GetBuffer()
|
||||||
|
{
|
||||||
|
return vk_ma->GetBuffer();
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32 GPUArrayBuffer::Alloc(const uint32 max_count) ///<预分配空间
|
||||||
|
{
|
||||||
|
if(!coll->Alloc(max_count))
|
||||||
|
return(0);
|
||||||
|
|
||||||
|
return coll->GetAllocCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GPUArrayBuffer::Clear()
|
void GPUArrayBuffer::Clear()
|
||||||
{
|
{
|
||||||
count=0;
|
coll->Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GPUArrayBuffer::Init(const uint32_t c)
|
void *GPUArrayBuffer::Map(const uint32 start,const uint32 count)
|
||||||
{
|
{
|
||||||
if(c<=0)return(false);
|
return coll->Map(start,count);
|
||||||
|
|
||||||
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
|
|
||||||
|
void GPUArrayBuffer::Flush(const uint32 count)
|
||||||
{
|
{
|
||||||
}
|
vk_ma->Flush(count*GetUnitSize());
|
||||||
}
|
}
|
||||||
}//namespace graph
|
}//namespace graph
|
||||||
}//namespace hgl
|
}//namespace hgl
|
||||||
|
Loading…
x
Reference in New Issue
Block a user