[WIP] optimizing VDM Support
This commit is contained in:
@@ -28,7 +28,7 @@ private:
|
||||
|
||||
Pipeline * pipeline;
|
||||
MaterialInstance * mi;
|
||||
const PrimitiveRenderBuffer * prb;
|
||||
const PrimitiveDataBuffer * prb;
|
||||
const PrimitiveRenderData * prd;
|
||||
|
||||
public:
|
||||
@@ -46,10 +46,10 @@ protected:
|
||||
VABList * vbo_list;
|
||||
|
||||
Pipeline * last_pipeline;
|
||||
const PrimitiveRenderBuffer * last_render_buf;
|
||||
const PrimitiveDataBuffer * last_render_buf;
|
||||
const PrimitiveRenderData * last_render_data;
|
||||
|
||||
bool BindVAB(const PrimitiveRenderBuffer *,const PrimitiveRenderData *,const uint);
|
||||
bool BindVAB(const PrimitiveDataBuffer *,const uint);
|
||||
|
||||
void Render(RenderItem *);
|
||||
|
||||
|
@@ -27,7 +27,7 @@ protected:
|
||||
|
||||
uint32_t index_number; ///<索引数量
|
||||
IndexType index_type; ///<索引类型
|
||||
IBAccess * iba; ///<索引缓冲区
|
||||
IndexBuffer * ibo; ///<索引缓冲区
|
||||
|
||||
public:
|
||||
|
||||
@@ -52,11 +52,12 @@ public: //顶点缓冲区
|
||||
|
||||
const uint32_t GetVertexCount()const{ return vertices_number; } ///<取得顶点数量
|
||||
|
||||
VABAccess * AcquireVAB (const AnsiString &name,const VkFormat &format,const void *data=nullptr); ///<请求一个顶点属性数据区
|
||||
bool WriteVAB (const AnsiString &name,const VkFormat &format,const void *data) ///<直接写入顶点属性数据
|
||||
{
|
||||
return AcquireVAB(name,format,data);
|
||||
}
|
||||
const int GetVABIndex (const AnsiString &name,const VkFormat &format); ///<取得顶点属性索引
|
||||
|
||||
void * MapVAB (const int vab_index); ///<映射一个顶点属性数据区
|
||||
void UnmapVAB (const int vab_index); ///<取消映射
|
||||
|
||||
bool WriteVAB (const AnsiString &name,const VkFormat &format,const void *data); ///<直接写入顶点属性数据
|
||||
|
||||
public: //索引缓冲区
|
||||
|
||||
@@ -81,28 +82,27 @@ public: //创建可渲染对象
|
||||
*/
|
||||
template<typename T> class VABRawMap
|
||||
{
|
||||
VABAccess *vaba;
|
||||
PrimitiveCreater *pc;
|
||||
int vab_index;
|
||||
T *map_ptr;
|
||||
|
||||
public:
|
||||
|
||||
VABRawMap(PrimitiveCreater *pc,const VkFormat &format,const AnsiString &name)
|
||||
VABRawMap(PrimitiveCreater *c,const VkFormat &format,const AnsiString &name)
|
||||
{
|
||||
vaba=pc->AcquireVAB(name,format);
|
||||
|
||||
if(vaba)
|
||||
map_ptr=(T *)(vaba->vab->Map(vaba->start,vaba->count));
|
||||
else
|
||||
map_ptr=nullptr;
|
||||
pc=c;
|
||||
vab_index=pc->GetVABIndex(name,format);
|
||||
|
||||
map_ptr=(T *)(pc->MapVAB(vab_index));
|
||||
}
|
||||
|
||||
~VABRawMap()
|
||||
{
|
||||
if(vaba)
|
||||
vaba->vab->Unmap();
|
||||
if(map_ptr)
|
||||
pc->UnmapVAB(vab_index);
|
||||
}
|
||||
|
||||
const bool IsValid()const{ return vaba; }
|
||||
const bool IsValid()const{ return map_ptr; }
|
||||
|
||||
operator T *(){ return map_ptr; }
|
||||
};//template<typename T> class VABRawMap
|
||||
@@ -121,19 +121,21 @@ typedef VABRawMap<double> VABRawMapDouble;
|
||||
*/
|
||||
template<typename T> class VABMap
|
||||
{
|
||||
VABAccess *vaba;
|
||||
PrimitiveCreater *pc;
|
||||
int vab_index;
|
||||
T *vb;
|
||||
|
||||
public:
|
||||
|
||||
VABMap(PrimitiveCreater *pc,const AnsiString &name)
|
||||
{
|
||||
vaba=pc->AcquireVAB(name,T::GetVulkanFormat(),nullptr);
|
||||
pc=c;
|
||||
vab_index=pc->GetVABIndex(name,T::GetVulkanFormat(),nullptr);
|
||||
|
||||
if(vaba)
|
||||
void *map_ptr=(T *)(pc->MapVAB(vab_index));
|
||||
|
||||
if(map_ptr)
|
||||
{
|
||||
void *map_ptr=vaba->vab->Map(vaba->start,vaba->count);
|
||||
|
||||
vb=T::Create(pc->GetVertexCount(),map_ptr);
|
||||
|
||||
vb->Begin();
|
||||
@@ -146,8 +148,8 @@ public:
|
||||
|
||||
~VABMap()
|
||||
{
|
||||
if(vaba)
|
||||
vaba->vab->Unmap();
|
||||
if(vab)
|
||||
pc->UnmapVAB(vab_index);
|
||||
}
|
||||
|
||||
void Restart()
|
||||
|
@@ -54,34 +54,14 @@ class DeviceMemory;
|
||||
class DeviceBuffer;
|
||||
struct DeviceBufferData;
|
||||
|
||||
struct PrimitiveRenderBuffer;
|
||||
struct PrimitiveDataBuffer;
|
||||
struct PrimitiveRenderData;
|
||||
|
||||
class VertexAttribBuffer;
|
||||
using VAB=VertexAttribBuffer;
|
||||
|
||||
struct VABAccess
|
||||
{
|
||||
VAB *vab;
|
||||
uint32_t start;
|
||||
uint32_t count;
|
||||
|
||||
public:
|
||||
|
||||
CompOperatorMemcmp(const VABAccess &);
|
||||
};//class VABAccess
|
||||
|
||||
class IndexBuffer;
|
||||
|
||||
struct IndexBufferAccess
|
||||
{
|
||||
IndexBuffer *buffer;
|
||||
uint32_t start;
|
||||
uint32_t count;
|
||||
};
|
||||
|
||||
using IBAccess=IndexBufferAccess;
|
||||
|
||||
class GPUCmdBuffer;
|
||||
class RenderCmdBuffer;
|
||||
class TextureCmdBuffer;
|
||||
|
@@ -165,12 +165,16 @@ public:
|
||||
|
||||
if(!vab_list->IsFull())return(false);
|
||||
|
||||
vkCmdBindVertexBuffers(cmd_buf,0,vab_list->vab_count,vab_list->vab_list,vab_list->vab_offset);
|
||||
vkCmdBindVertexBuffers(cmd_buf,
|
||||
0, //first binding
|
||||
vab_list->vab_count, //binding count
|
||||
vab_list->vab_list, //buffers
|
||||
vab_list->vab_offset); //buffer offsets
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void BindIBO(IndexBuffer *ibo,VkDeviceSize offset); ///<绑定IBO,注意offset意为索引偏移量,不是字节
|
||||
void BindIBO(IBAccess *);
|
||||
|
||||
bool BindVAB(Renderable *);
|
||||
|
||||
@@ -209,7 +213,7 @@ public: //draw
|
||||
void DrawIndirect (VkBuffer buf, uint32_t drawCount,uint32_t stride=sizeof(VkDrawIndirectCommand )){return DrawIndirect( buf,0,drawCount,stride);}
|
||||
void DrawIndexedIndirect(VkBuffer buf, uint32_t drawCount,uint32_t stride=sizeof(VkDrawIndexedIndirectCommand )){return DrawIndexedIndirect( buf,0,drawCount,stride);}
|
||||
|
||||
void Draw (const PrimitiveRenderBuffer *prb,const PrimitiveRenderData *prd);
|
||||
void Draw (const PrimitiveDataBuffer *prb,const PrimitiveRenderData *prd);
|
||||
// void DrawIndexed (const IBAccess *iba,const uint32_t instance_count);
|
||||
|
||||
public: //dynamic state
|
||||
|
@@ -22,7 +22,7 @@ class Material
|
||||
{
|
||||
AnsiString name;
|
||||
|
||||
VertexInput *primitive_render_buffer;
|
||||
VertexInput *vertex_input;
|
||||
|
||||
ShaderModuleMap *shader_maps;
|
||||
|
||||
@@ -51,7 +51,7 @@ public:
|
||||
|
||||
const AnsiString & GetName ()const{return name;}
|
||||
|
||||
const VertexInput * GetVertexInput ()const{return primitive_render_buffer;}
|
||||
const VertexInput * GetVertexInput ()const{return vertex_input;}
|
||||
|
||||
const ShaderStageCreateInfoList & GetStageList ()const{return shader_stage_list;}
|
||||
|
||||
|
@@ -7,18 +7,8 @@
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
/**
|
||||
* 单一图元数据访问接口<br>
|
||||
*
|
||||
* 这个只是单纯的提供原始VAB/IB数据,派生为两类
|
||||
*
|
||||
* 一类是传统的,使用独统的独立VAB的
|
||||
* 一类是使用VDM的
|
||||
*
|
||||
*
|
||||
*
|
||||
* WIP: *** 1.将数据全部转移到PrimitiveData,完成旧的渲染测试
|
||||
* 2.改成抽象类,将独立VAB的做成一个实现
|
||||
* 3.实现VDM支持
|
||||
* 原始图元数据访问接口<br>
|
||||
* Primitive的存为是为了屏蔽PrimitiveData的初始化之类的访问接口,以便于更好的管理和使用
|
||||
*/
|
||||
class Primitive
|
||||
{
|
||||
@@ -43,9 +33,9 @@ public:
|
||||
|
||||
const VkDeviceSize GetVertexCount ()const;
|
||||
const int GetVABCount ()const;
|
||||
|
||||
VABAccess * GetVABAccess (const AnsiString &);
|
||||
|
||||
IBAccess * GetIBAccess ();
|
||||
IndexBuffer * GetIBO ();
|
||||
|
||||
const AABB & GetBoundingBox ()const{return BoundingBox;}
|
||||
|
@@ -9,32 +9,50 @@
|
||||
#include<hgl/graph/VKMaterialInstance.h>
|
||||
#include<hgl/graph/VertexAttrib.h>
|
||||
VK_NAMESPACE_BEGIN
|
||||
struct PrimitiveRenderBuffer
|
||||
/**
|
||||
* 原始图元数据缓冲区<Br>
|
||||
* 提供在渲染之前的数据绑定信息
|
||||
*/
|
||||
struct PrimitiveDataBuffer
|
||||
{
|
||||
uint32_t vab_count;
|
||||
VkBuffer * vab_list;
|
||||
|
||||
// 理论上讲,每个VAB绑定时都是可以指定byte offsets的。但是随后Draw时,又可以指定vertexOffset。
|
||||
// 在我们支持的两种draw模式中,一种是每个模型一批VAB,所有VAB的offset都是0。
|
||||
// 另一种是使用VDM,为了批量渲染,所有的VAB又必须对齐,所以每个VAB单独指定offset也不可行。
|
||||
// 所以干脆不支持VAB的offset,只支持vertexOffset。
|
||||
|
||||
// uint32_t * vab_offset; //注意:这里的offset是相对于vertex的,代表第几个顶点,不是字节偏移
|
||||
|
||||
// IndexBuffer 同理也不再支持buffer的offset
|
||||
|
||||
IndexBuffer * ibo;
|
||||
|
||||
public:
|
||||
|
||||
PrimitiveRenderBuffer(const uint32_t,const uint32_t,const IBAccess *iba);
|
||||
~PrimitiveRenderBuffer();
|
||||
PrimitiveDataBuffer(const uint32_t,const uint32_t, IndexBuffer *);
|
||||
~PrimitiveDataBuffer();
|
||||
|
||||
const bool Comp(const PrimitiveRenderBuffer *prb)const;
|
||||
};//struct PrimitiveRenderBuffer
|
||||
const bool Comp(const PrimitiveDataBuffer *prb)const;
|
||||
};//struct PrimitiveDataBuffer
|
||||
|
||||
/**
|
||||
* 原始图元渲染数据<Br>
|
||||
* 提供在渲染时的数据
|
||||
*/
|
||||
struct PrimitiveRenderData
|
||||
{
|
||||
uint vab_count;
|
||||
VkDeviceSize * vab_offset;
|
||||
uint32_t vertex_count;
|
||||
|
||||
uint32_t index_start;
|
||||
uint32_t index_count;
|
||||
|
||||
int32_t vertex_offset; //注意:这里的offset是相对于vertex的,代表第几个顶点,不是字节偏移
|
||||
uint32_t first_index;
|
||||
|
||||
public:
|
||||
|
||||
PrimitiveRenderData(const uint32_t bc,const uint32_t vc,const IBAccess *iba);
|
||||
PrimitiveRenderData(const uint32_t bc,const uint32_t vc);
|
||||
~PrimitiveRenderData();
|
||||
|
||||
const bool Comp(const PrimitiveRenderData *)const;
|
||||
@@ -49,14 +67,14 @@ class Renderable
|
||||
MaterialInstance * mat_inst;
|
||||
Primitive * primitive;
|
||||
|
||||
PrimitiveRenderBuffer * primitive_render_buffer;
|
||||
PrimitiveRenderData * primitive_render_data;
|
||||
PrimitiveDataBuffer * primitive_data_buffer;
|
||||
PrimitiveRenderData * primitive_render_data;
|
||||
|
||||
private:
|
||||
|
||||
friend Renderable *CreateRenderable(Primitive *,MaterialInstance *,Pipeline *);
|
||||
|
||||
Renderable(Primitive *,MaterialInstance *,Pipeline *,PrimitiveRenderBuffer *,PrimitiveRenderData *);
|
||||
Renderable(Primitive *,MaterialInstance *,Pipeline *,PrimitiveDataBuffer *,PrimitiveRenderData *);
|
||||
|
||||
public:
|
||||
|
||||
@@ -64,7 +82,7 @@ public:
|
||||
{
|
||||
//需要在这里添加删除pipeline/desc_sets/primitive引用计数的代码
|
||||
|
||||
SAFE_CLEAR(primitive_render_buffer);
|
||||
SAFE_CLEAR(primitive_data_buffer);
|
||||
SAFE_CLEAR(primitive_render_data);
|
||||
}
|
||||
|
||||
@@ -77,7 +95,7 @@ public:
|
||||
Primitive * GetPrimitive (){return primitive;}
|
||||
const AABB & GetBoundingBox ()const{return primitive->GetBoundingBox();}
|
||||
|
||||
const PrimitiveRenderBuffer * GetRenderBuffer ()const{return primitive_render_buffer;}
|
||||
const PrimitiveDataBuffer * GetRenderBuffer ()const{return primitive_data_buffer;}
|
||||
const PrimitiveRenderData * GetRenderData ()const{return primitive_render_data;}
|
||||
};//class Renderable
|
||||
|
||||
|
Reference in New Issue
Block a user