OK! Can RUN! full OK!...next step is to create VDMRender in MaterialRenderList

This commit is contained in:
hyzboy 2024-05-28 23:10:50 +08:00
parent 86ff7517d9
commit ca8e36687f
16 changed files with 163 additions and 153 deletions

2
CMCore

@ -1 +1 @@
Subproject commit d70d31288f601061a69f93b4970af6692e53a34b Subproject commit b7e0852bd4b781abbb8a0815f5f456b0f810ce95

@ -1 +1 @@
Subproject commit a6a368031209ce23dc14e88acf45dd8298a19886 Subproject commit 3d69fc8b48d844b9761ec7d9b1a357a5684a295e

View File

@ -216,16 +216,14 @@ public:
{ {
if(!ri)return(false); if(!ri)return(false);
const PrimitiveDataBuffer *prb=ri->GetRenderBuffer();
cb->Begin(); cb->Begin();
cb->BindFramebuffer(rp,fb); cb->BindFramebuffer(rp,fb);
cb->SetClearColor(0,clear_color); cb->SetClearColor(0,clear_color);
cb->BeginRenderPass(); cb->BeginRenderPass();
cb->BindPipeline(ri->GetPipeline()); cb->BindPipeline(ri->GetPipeline());
cb->BindDescriptorSets(ri->GetMaterial()); cb->BindDescriptorSets(ri->GetMaterial());
cb->BindVAB(ri); cb->BindRenderBuffer(ri->GetRenderBuffer());
cb->Draw(prb,ri->GetRenderData()); cb->Draw(ri->GetRenderBuffer(),ri->GetRenderData());
cb->EndRenderPass(); cb->EndRenderPass();
cb->End(); cb->End();

View File

@ -24,11 +24,11 @@ private:
struct RenderItem struct RenderItem
{ {
uint32_t first; uint32_t first;
uint32_t count; uint32_t instance_count;
Pipeline * pipeline; Pipeline * pipeline;
MaterialInstance * mi; MaterialInstance * mi;
const PrimitiveDataBuffer * prb; const PrimitiveDataBuffer * pdb;
const PrimitiveRenderData * prd; const PrimitiveRenderData * prd;
public: public:
@ -43,10 +43,10 @@ private:
protected: protected:
VABList * vbo_list; VABList * vab_list;
Pipeline * last_pipeline; Pipeline * last_pipeline;
const PrimitiveDataBuffer * last_render_buf; const PrimitiveDataBuffer * last_data_buffer;
const PrimitiveRenderData * last_render_data; const PrimitiveRenderData * last_render_data;
bool BindVAB(const PrimitiveDataBuffer *,const uint); bool BindVAB(const PrimitiveDataBuffer *,const uint);

View File

@ -25,6 +25,8 @@ protected:
uint32_t vertices_number; ///<顶点数量 uint32_t vertices_number; ///<顶点数量
void_pointer *map_ptr_list; ///<映射指针列表
uint32_t index_number; ///<索引数量 uint32_t index_number; ///<索引数量
IndexType index_type; ///<索引类型 IndexType index_type; ///<索引类型
IndexBuffer * ibo; ///<索引缓冲区 IndexBuffer * ibo; ///<索引缓冲区
@ -127,10 +129,10 @@ template<typename T> class VABMap
public: public:
VABMap(PrimitiveCreater *pc,const AnsiString &name) VABMap(PrimitiveCreater *c,const AnsiString &name)
{ {
pc=c; pc=c;
vab_index=pc->GetVABIndex(name,T::GetVulkanFormat(),nullptr); vab_index=pc->GetVABIndex(name,T::GetVulkanFormat());
void *map_ptr=(T *)(pc->MapVAB(vab_index)); void *map_ptr=(T *)(pc->MapVAB(vab_index));
@ -148,7 +150,7 @@ public:
~VABMap() ~VABMap()
{ {
if(vab) if(pc&&vab_index>=0)
pc->UnmapVAB(vab_index); pc->UnmapVAB(vab_index);
} }

View File

@ -174,9 +174,9 @@ public:
return(true); return(true);
} }
void BindIBO(IBAccess *); void BindIBO(IndexBuffer *,const VkDeviceSize byte_offset=0);
bool BindVAB(Renderable *); bool BindRenderBuffer(const PrimitiveDataBuffer *);
void SetViewport (uint32_t first,uint32_t count,const VkViewport *vp) {vkCmdSetViewport(cmd_buf,first,count,vp);} void SetViewport (uint32_t first,uint32_t count,const VkViewport *vp) {vkCmdSetViewport(cmd_buf,first,count,vp);}
void SetScissor (uint32_t first,uint32_t count,const VkRect2D *sci) {vkCmdSetScissor(cmd_buf,first,count,sci);} void SetScissor (uint32_t first,uint32_t count,const VkRect2D *sci) {vkCmdSetScissor(cmd_buf,first,count,sci);}
@ -213,8 +213,7 @@ public: //draw
void DrawIndirect (VkBuffer buf, uint32_t drawCount,uint32_t stride=sizeof(VkDrawIndirectCommand )){return DrawIndirect( buf,0,drawCount,stride);} 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 DrawIndexedIndirect(VkBuffer buf, uint32_t drawCount,uint32_t stride=sizeof(VkDrawIndexedIndirectCommand )){return DrawIndexedIndirect( buf,0,drawCount,stride);}
void Draw (const PrimitiveDataBuffer *prb,const PrimitiveRenderData *prd); void Draw (const PrimitiveDataBuffer *prb,const PrimitiveRenderData *prd,const uint32_t instance_count=1,const uint32_t first_instance=0);
// void DrawIndexed (const IBAccess *iba,const uint32_t instance_count);
public: //dynamic state public: //dynamic state
};//class RenderCmdBuffer:public GPUCmdBuffer };//class RenderCmdBuffer:public GPUCmdBuffer

View File

@ -33,10 +33,14 @@ public:
const VkDeviceSize GetVertexCount ()const; const VkDeviceSize GetVertexCount ()const;
const int GetVABCount ()const; const int GetVABCount ()const;
const int GetVABIndex (const AnsiString &name)const;
VAB * GetVAB (const int);
VAB * GetVAB (const AnsiString &name){return GetVAB(GetVABIndex(name));}
const int32_t GetVertexOffset ()const; ///<取得顶点偏移(注意是顶点不是字节)
VABAccess * GetVABAccess (const AnsiString &); const uint32_t GetIndexCount ()const;
IndexBuffer * GetIBO (); IndexBuffer * GetIBO ();
const uint32_t GetFirstIndex ()const; ///<取得第一个索引
const AABB & GetBoundingBox ()const{return BoundingBox;} const AABB & GetBoundingBox ()const{return BoundingBox;}
};//class Primitive };//class Primitive

View File

@ -31,10 +31,10 @@ struct PrimitiveDataBuffer
public: public:
PrimitiveDataBuffer(const uint32_t,const uint32_t, IndexBuffer *); PrimitiveDataBuffer(const uint32_t,IndexBuffer *);
~PrimitiveDataBuffer(); ~PrimitiveDataBuffer();
const bool Comp(const PrimitiveDataBuffer *prb)const; const bool Comp(const PrimitiveDataBuffer *pdb)const;
};//struct PrimitiveDataBuffer };//struct PrimitiveDataBuffer
/** /**
@ -43,19 +43,27 @@ public:
*/ */
struct PrimitiveRenderData struct PrimitiveRenderData
{ {
uint vab_count; //因为要VAB是流式访问所以我们这个结构会被用做排序依据
uint32_t vertex_count; //也因此把vertex_offset放在最前面
uint32_t index_count;
int32_t vertex_offset; //注意这里的offset是相对于vertex的代表第几个顶点不是字节偏移 int32_t vertex_offset; //注意这里的offset是相对于vertex的代表第几个顶点不是字节偏移
uint32_t first_index; uint32_t first_index;
uint32_t vertex_count;
uint32_t index_count;
public: public:
PrimitiveRenderData(const uint32_t bc,const uint32_t vc); PrimitiveRenderData(const uint32_t vc,const uint32_t ic,const int32_t vo=0,const uint32_t fi=0)
~PrimitiveRenderData(); {
vertex_count =vc;
index_count =ic;
vertex_offset =vo;
first_index =fi;
}
const bool Comp(const PrimitiveRenderData *)const; CompOperatorMemcmp(const PrimitiveRenderData &);
CompOperatorMemcmpPointer(PrimitiveRenderData);
}; };
/** /**
@ -95,8 +103,8 @@ public:
Primitive * GetPrimitive (){return primitive;} Primitive * GetPrimitive (){return primitive;}
const AABB & GetBoundingBox ()const{return primitive->GetBoundingBox();} const AABB & GetBoundingBox ()const{return primitive->GetBoundingBox();}
const PrimitiveDataBuffer * GetRenderBuffer ()const{return primitive_data_buffer;} const PrimitiveDataBuffer *GetRenderBuffer ()const{return primitive_data_buffer;}
const PrimitiveRenderData * GetRenderData ()const{return primitive_render_data;} const PrimitiveRenderData *GetRenderData ()const{return primitive_render_data;}
};//class Renderable };//class Renderable
Renderable *CreateRenderable(Primitive *,MaterialInstance *,Pipeline *); Renderable *CreateRenderable(Primitive *,MaterialInstance *,Pipeline *);

View File

@ -55,12 +55,12 @@ MaterialRenderList::MaterialRenderList(GPUDevice *d,bool l2w,Material *m)
assign_buffer=new RenderAssignBuffer(device,material); assign_buffer=new RenderAssignBuffer(device,material);
vbo_list=new VABList(material->GetVertexInput()->GetCount()); vab_list=new VABList(material->GetVertexInput()->GetCount());
} }
MaterialRenderList::~MaterialRenderList() MaterialRenderList::~MaterialRenderList()
{ {
SAFE_CLEAR(vbo_list); SAFE_CLEAR(vab_list);
SAFE_CLEAR(assign_buffer); SAFE_CLEAR(assign_buffer);
} }
@ -93,7 +93,7 @@ void MaterialRenderList::RenderItem::Set(Renderable *ri)
{ {
pipeline=ri->GetPipeline(); pipeline=ri->GetPipeline();
mi =ri->GetMaterialInstance(); mi =ri->GetMaterialInstance();
prb =ri->GetRenderBuffer(); pdb =ri->GetRenderBuffer();
prd =ri->GetRenderData(); prd =ri->GetRenderData();
} }
@ -110,11 +110,11 @@ void MaterialRenderList::Stat()
ri_count=1; ri_count=1;
ri->first=0; ri->first=0;
ri->count=1; ri->instance_count=1;
ri->Set(rn->ri); ri->Set(rn->ri);
last_pipeline =ri->pipeline; last_pipeline =ri->pipeline;
last_render_buf =ri->prb; last_data_buffer =ri->pdb;
last_render_data=ri->prd; last_render_data=ri->prd;
++rn; ++rn;
@ -122,10 +122,10 @@ void MaterialRenderList::Stat()
for(uint i=1;i<count;i++) for(uint i=1;i<count;i++)
{ {
if(last_pipeline==rn->ri->GetPipeline()) if(last_pipeline==rn->ri->GetPipeline())
if(last_render_buf->Comp(rn->ri->GetRenderBuffer())) if(last_data_buffer->Comp(rn->ri->GetRenderBuffer()))
if(last_render_data->Comp(rn->ri->GetRenderData())) if(last_render_data->_Comp(rn->ri->GetRenderData())==0)
{ {
++ri->count; ++ri->instance_count;
++rn; ++rn;
continue; continue;
} }
@ -134,18 +134,18 @@ void MaterialRenderList::Stat()
++ri; ++ri;
ri->first=i; ri->first=i;
ri->count=1; ri->instance_count=1;
ri->Set(rn->ri); ri->Set(rn->ri);
last_pipeline =ri->pipeline; last_pipeline =ri->pipeline;
last_render_buf =ri->prb; last_data_buffer =ri->pdb;
last_render_data=ri->prd; last_render_data=ri->prd;
++rn; ++rn;
} }
} }
bool MaterialRenderList::BindVAB(const PrimitiveDataBuffer *prb,const uint ri_index) bool MaterialRenderList::BindVAB(const PrimitiveDataBuffer *pdb,const uint ri_index)
{ {
//binding号都是在VertexInput::CreateVIL时连续紧密排列生成的所以bind时first_binding写0就行了。 //binding号都是在VertexInput::CreateVIL时连续紧密排列生成的所以bind时first_binding写0就行了。
@ -154,19 +154,19 @@ bool MaterialRenderList::BindVAB(const PrimitiveDataBuffer *prb,const uint ri_in
//if(vil->GetCount(VertexInputGroup::Basic)!=prb->vab_count) //if(vil->GetCount(VertexInputGroup::Basic)!=prb->vab_count)
// return(false); //这里基本不太可能因为CreateRenderable时就会检查值是否一样 // return(false); //这里基本不太可能因为CreateRenderable时就会检查值是否一样
vbo_list->Restart(); vab_list->Restart();
//Basic组它所有的VAB信息均来自于Primitive由vid参数传递进来 //Basic组它所有的VAB信息均来自于Primitive由vid参数传递进来
{ {
vbo_list->Add(prb->vab_list, vab_list->Add(pdb->vab_list,
prb->vab_offset, nullptr,//prb->vab_offset,
prb->vab_count); pdb->vab_count);
} }
if(assign_buffer) //L2W/MI分发组 if(assign_buffer) //L2W/MI分发组
vbo_list->Add(assign_buffer->GetVAB(),0);//ASSIGN_VAB_STRIDE_BYTES*ri_index); vab_list->Add(assign_buffer->GetVAB(),0);//ASSIGN_VAB_STRIDE_BYTES*ri_index);
//if(!vbo_list.IsFull()) //Joint组暂未支持 //if(!vab_list.IsFull()) //Joint组暂未支持
//{ //{
// const uint joint_id_binding_count=vil->GetCount(VertexInputGroup::JointID); // const uint joint_id_binding_count=vil->GetCount(VertexInputGroup::JointID);
@ -201,7 +201,7 @@ bool MaterialRenderList::BindVAB(const PrimitiveDataBuffer *prb,const uint ri_in
// return(false); // return(false);
//} //}
cmd_buf->BindVAB(vbo_list); cmd_buf->BindVAB(vab_list);
return(true); return(true);
} }
@ -213,36 +213,23 @@ void MaterialRenderList::Render(RenderItem *ri)
cmd_buf->BindPipeline(ri->pipeline); cmd_buf->BindPipeline(ri->pipeline);
last_pipeline=ri->pipeline; last_pipeline=ri->pipeline;
last_render_buf=nullptr; last_data_buffer=nullptr;
//这里未来尝试换pipeline同时不换mi/primitive是否需要重新绑定mi/primitive //这里未来尝试换pipeline同时不换mi/primitive是否需要重新绑定mi/primitive
} }
if(!ri->prb->Comp(last_render_buf)) if(!ri->pdb->Comp(last_data_buffer))
{ {
last_render_buf=ri->prb; last_data_buffer=ri->pdb;
last_render_data=nullptr; last_render_data=nullptr;
BindVAB(ri->prb,ri->first); BindVAB(ri->pdb,ri->first);
if(ri->prb->ib_access->buffer) if(ri->pdb->ibo)
cmd_buf->BindIBO(ri->prb->ib_access); cmd_buf->BindIBO(ri->pdb->ibo);
} }
if(last_render_buf->ib_access->buffer) cmd_buf->Draw(ri->pdb,ri->prd,ri->instance_count,ri->first);
{
cmd_buf->DrawIndexed(ri->prd->index_count,
ri->count,
ri->prd->first_index,
ri->prd->vertex_offset, //因为vkCmdDrawIndexed的vertexOffset是针对所有VAB的所以所有的VAB数据都必须是对齐的
//最终这里使用vab_offset[0]是可以的因为它也等于其它所有的vab_offset。未来考虑统一成一个。
ri->first); //这里vkCmdDrawIndexed的firstInstance参数指的是instance Rate更新的VAB的起始实例数不是指instance批量渲染。
//所以这里使用ri->first是对的。
}
else
{
cmd_buf->Draw(ri->prd->vertex_count,ri->count);
}
} }
void MaterialRenderList::Render(RenderCmdBuffer *rcb) void MaterialRenderList::Render(RenderCmdBuffer *rcb)
@ -259,7 +246,7 @@ void MaterialRenderList::Render(RenderCmdBuffer *rcb)
RenderItem *ri=ri_array.GetData(); RenderItem *ri=ri_array.GetData();
last_pipeline =nullptr; last_pipeline =nullptr;
last_render_buf =nullptr; last_data_buffer =nullptr;
if(assign_buffer) if(assign_buffer)
assign_buffer->Bind(material); assign_buffer->Bind(material);

View File

@ -15,6 +15,8 @@ PrimitiveCreater::PrimitiveCreater(GPUDevice *dev,const VIL *v)
prim_data =nullptr; prim_data =nullptr;
map_ptr_list =hgl_zero_new<void_pointer>(v->GetVertexAttribCount());
Clear(); Clear();
} }
@ -29,6 +31,7 @@ PrimitiveCreater::PrimitiveCreater(VertexDataManager *_vdm)
PrimitiveCreater::~PrimitiveCreater() PrimitiveCreater::~PrimitiveCreater()
{ {
SAFE_CLEAR(prim_data); SAFE_CLEAR(prim_data);
SAFE_CLEAR_ARRAY(map_ptr_list)
} }
void PrimitiveCreater::Clear() void PrimitiveCreater::Clear()
@ -120,9 +123,7 @@ const int PrimitiveCreater::GetVABIndex(const AnsiString &name,const VkFormat &a
VAB *vab=prim_data->GetVAB(vab_index); VAB *vab=prim_data->GetVAB(vab_index);
if(!vab) if(!vab)
return(-1); vab=prim_data->InitVAB(vab_index,acquire_format,nullptr);
vab=prim_data->InitVAB(vab_index,acquire_format,nullptr);
if(!vab) if(!vab)
return(-1); return(-1);
@ -145,16 +146,23 @@ const int PrimitiveCreater::GetVABIndex(const AnsiString &name,const VkFormat &a
void *PrimitiveCreater::MapVAB(const int vab_index) void *PrimitiveCreater::MapVAB(const int vab_index)
{ {
if(!prim_data)
return(nullptr);
VAB *vab=prim_data->GetVAB(vab_index); VAB *vab=prim_data->GetVAB(vab_index);
if(!vab) if(!vab)
return(nullptr); return(nullptr);
return vab->Map(prim_data->GetVertexOffset(),vertices_number); map_ptr_list[vab_index]=vab->Map(prim_data->GetVertexOffset(),vertices_number);
return map_ptr_list[vab_index];
} }
void PrimitiveCreater::UnmapVAB(const int vab_index) void PrimitiveCreater::UnmapVAB(const int vab_index)
{ {
if(!prim_data)return;
VAB *vab=prim_data->GetVAB(vab_index); VAB *vab=prim_data->GetVAB(vab_index);
if(!vab)return; if(!vab)return;
@ -208,6 +216,13 @@ Primitive *PrimitiveCreater::Create()
if(!prim_data) if(!prim_data)
return(nullptr); return(nullptr);
for(int i=0;i<vil->GetVertexAttribCount();i++)
if(map_ptr_list[i])
{
prim_data->GetVAB(i)->Unmap();
map_ptr_list[i]=nullptr;
}
Primitive *primitive=new Primitive(prim_name,prim_data); Primitive *primitive=new Primitive(prim_name,prim_data);
if(!primitive) if(!primitive)

View File

@ -13,7 +13,7 @@ namespace hgl
device=dev; device=dev;
vil=_vil; vil=_vil;
vi_count=_vil->GetCount(); vi_count=_vil->GetVertexAttribCount();
vif_list=_vil->GetVIFList(); //来自于Material不会被释放所以指针有效 vif_list=_vil->GetVIFList(); //来自于Material不会被释放所以指针有效
vab_max_size=0; vab_max_size=0;

View File

@ -130,39 +130,32 @@ bool RenderCmdBuffer::BindDescriptorSets(Material *mtl)
return(true); return(true);
} }
void RenderCmdBuffer::BindIBO(IBAccess *iba) void RenderCmdBuffer::BindIBO(IndexBuffer *ibo,const VkDeviceSize byte_offset)
{ {
if(!iba)return;
IndexBuffer *ibo=iba->buffer;
if(!ibo)return; if(!ibo)return;
vkCmdBindIndexBuffer(cmd_buf, vkCmdBindIndexBuffer(cmd_buf,
ibo->GetBuffer(), ibo->GetBuffer(),
iba->start*ibo->GetStride(), byte_offset,
VkIndexType(ibo->GetType())); VkIndexType(ibo->GetType()));
} }
bool RenderCmdBuffer::BindVAB(Renderable *ri) bool RenderCmdBuffer::BindRenderBuffer(const PrimitiveDataBuffer *pdb)
{ {
if(!ri) if(!pdb)
return(false); return(false);
const PrimitiveDataBuffer *prb=ri->GetRenderBuffer(); if(pdb->vab_count<=0)
if(prb->vab_count<=0)
return(false); return(false);
const PrimitiveRenderData *prd=ri->GetRenderData(); vkCmdBindVertexBuffers(cmd_buf,
0, //first binding
pdb->vab_count,
pdb->vab_list,
nullptr); //vab byte offsets
if(prd->vertex_count<=0) if(pdb->ibo)
return(false); BindIBO(pdb->ibo);
vkCmdBindVertexBuffers(cmd_buf,0,prb->vab_count,prb->vab_list,prb->vab_offset);
if(prb->ib_access->buffer)
BindIBO(prb->ib_access);
return(true); return(true);
} }
@ -191,15 +184,24 @@ void RenderCmdBuffer::DrawIndexedIndirect( VkBuffer buffer,
vkCmdDrawIndexedIndirect(cmd_buf,buffer,offset+i*stride,1,stride); vkCmdDrawIndexedIndirect(cmd_buf,buffer,offset+i*stride,1,stride);
} }
void RenderCmdBuffer::Draw(const PrimitiveDataBuffer *prb,const PrimitiveRenderData *prd) void RenderCmdBuffer::Draw(const PrimitiveDataBuffer *prb,const PrimitiveRenderData *prd,const uint32_t instance_count,const uint32_t first_instance)
{ {
if(!prb||!prd) if(!prb||!prd)
return; return;
if (prb->ib_access->buffer) if (prb->ibo)
DrawIndexed(prd->index_count); vkCmdDrawIndexed( cmd_buf,
prd->index_count,
instance_count,
prd->first_index,
prd->vertex_offset, //这里的vertexOffset是针对所有VAB的
first_instance); //这里的first_instance针对的是instance Rate更新的VAB的起始实例数不是指instance批量渲染
else else
Draw(prd->vertex_count); vkCmdDraw( cmd_buf,
prd->vertex_count,
instance_count,
prd->vertex_offset,
first_instance);
} }
//void RenderCmdBuffer::DrawIndexed(const IBAccess *iba,const uint32_t instance_count) //void RenderCmdBuffer::DrawIndexed(const IBAccess *iba,const uint32_t instance_count)

View File

@ -51,14 +51,24 @@ const int Primitive::GetVABCount()const
return prim_data->GetVABCount(); return prim_data->GetVABCount();
} }
VABAccess *Primitive::GetVABAccess(const AnsiString &name) const int Primitive::GetVABIndex(const AnsiString &name)const
{ {
return prim_data->GetVABAccess(name); return prim_data->GetVABIndex(name);
} }
IBAccess *Primitive::GetIBAccess() VAB *Primitive::GetVAB(const int vab_index)
{ {
return prim_data->GetIBAccess(); return prim_data->GetVAB(vab_index);
}
const int32_t Primitive::GetVertexOffset()const
{
return prim_data->GetVertexOffset();
}
const uint32_t Primitive::GetIndexCount()const
{
return prim_data->GetIndexCount();
} }
IndexBuffer *Primitive::GetIBO() IndexBuffer *Primitive::GetIBO()
@ -66,4 +76,8 @@ IndexBuffer *Primitive::GetIBO()
return prim_data->GetIBO(); return prim_data->GetIBO();
} }
const uint32_t Primitive::GetFirstIndex()const
{
return prim_data->GetFirstIndex();
}
VK_NAMESPACE_END VK_NAMESPACE_END

View File

@ -13,7 +13,7 @@ PrimitiveData::PrimitiveData(const VIL *_vil,const uint32_t vc)
vertex_count=vc; vertex_count=vc;
vab_list=hgl_zero_new<VAB *>(_vil->GetCount()); vab_list=hgl_zero_new<VAB *>(_vil->GetVertexAttribCount());
ibo=nullptr; ibo=nullptr;
} }
@ -25,7 +25,7 @@ PrimitiveData::~PrimitiveData()
const int PrimitiveData::GetVABCount()const const int PrimitiveData::GetVABCount()const
{ {
return vil->GetCount(); return vil->GetVertexAttribCount();
} }
const int PrimitiveData::GetVABIndex(const AnsiString &name) const const int PrimitiveData::GetVABIndex(const AnsiString &name) const
@ -37,7 +37,7 @@ const int PrimitiveData::GetVABIndex(const AnsiString &name) const
VAB *PrimitiveData::GetVAB(const int index) VAB *PrimitiveData::GetVAB(const int index)
{ {
if(index<0||index>=vil->GetCount())return(nullptr); if(index<0||index>=vil->GetVertexAttribCount())return(nullptr);
return vab_list[index]; return vab_list[index];
} }
@ -67,7 +67,7 @@ namespace
{ {
VAB **vab=vab_list; VAB **vab=vab_list;
for(uint i=0;i<vil->GetCount();i++) for(uint i=0;i<vil->GetVertexAttribCount();i++)
{ {
if(*vab) if(*vab)
delete *vab; delete *vab;
@ -100,7 +100,7 @@ namespace
if(!device)return(nullptr); if(!device)return(nullptr);
if(!vil)return(nullptr); if(!vil)return(nullptr);
if(vab_index<0||vab_index>=vil->GetCount()) if(vab_index<0||vab_index>=vil->GetVertexAttribCount())
return(nullptr); return(nullptr);
const VertexInputFormat *vif=vil->GetConfig(vab_index); const VertexInputFormat *vif=vil->GetConfig(vab_index);
@ -159,14 +159,14 @@ namespace
vdm->ReleaseVAB(vab_node); vdm->ReleaseVAB(vab_node);
} }
IndexBuffer *InitIBO(const uint32_t index_count,IndexType it) override IndexBuffer *InitIBO(const uint32_t ic,IndexType it) override
{ {
if(index_count<=0)return(nullptr); if(ic<=0)return(nullptr);
if(!vdm)return(nullptr); if(!vdm)return(nullptr);
if(!ib_node) if(!ib_node)
{ {
ib_node=vdm->AcquireIB(index_count); ib_node=vdm->AcquireIB(ic);
if(!ib_node) if(!ib_node)
return(nullptr); return(nullptr);
@ -174,6 +174,8 @@ namespace
ibo=vdm->GetIBO(); ibo=vdm->GetIBO();
} }
index_count=ic;
return ibo; return ibo;
} }
@ -182,7 +184,7 @@ namespace
if(!vdm)return(nullptr); if(!vdm)return(nullptr);
if(!vil)return(nullptr); if(!vil)return(nullptr);
if (vab_index<0||vab_index>=vil->GetCount()) if (vab_index<0||vab_index>=vil->GetVertexAttribCount())
return(nullptr); return(nullptr);
const VertexInputFormat *vif=vil->GetConfig(vab_index); const VertexInputFormat *vif=vil->GetConfig(vab_index);

View File

@ -38,6 +38,7 @@ public:
const int GetVABCount ()const; const int GetVABCount ()const;
const int GetVABIndex (const AnsiString &name)const; const int GetVABIndex (const AnsiString &name)const;
VAB * GetVAB (const int index); VAB * GetVAB (const int index);
VAB * GetVAB (const AnsiString &name){return GetVAB(GetVABIndex(name));}
IndexBuffer * GetIBO (){return ibo;} IndexBuffer * GetIBO (){return ibo;}
uint32_t GetIndexCount ()const{return index_count;} uint32_t GetIndexCount ()const{return index_count;}

View File

@ -7,7 +7,7 @@
#include<hgl/log/LogInfo.h> #include<hgl/log/LogInfo.h>
VK_NAMESPACE_BEGIN VK_NAMESPACE_BEGIN
PrimitiveDataBuffer::PrimitiveDataBuffer(const uint32_t c,const uint32_t vc, IndexBuffer *ib) PrimitiveDataBuffer::PrimitiveDataBuffer(const uint32_t c,IndexBuffer *ib)
{ {
vab_count=c; vab_count=c;
@ -20,60 +20,39 @@ PrimitiveDataBuffer::~PrimitiveDataBuffer()
delete[] vab_list; delete[] vab_list;
} }
const bool PrimitiveDataBuffer::Comp(const PrimitiveDataBuffer *prb)const const bool PrimitiveDataBuffer::Comp(const PrimitiveDataBuffer *pdb)const
{ {
if(!prb)return(false); if(!pdb)return(false);
if(vab_count!=prb->vab_count)return(false); if(vab_count!=pdb->vab_count)return(false);
for(uint32_t i=0;i<vab_count;i++) for(uint32_t i=0;i<vab_count;i++)
{ {
if(vab_list[i]!=prb->vab_list[i])return(false); if(vab_list[i]!=pdb->vab_list[i])return(false);
} }
if(ibo!=prb->ibo) if(ibo!=pdb->ibo)
return(false); return(false);
return(true); return(true);
} }
Renderable::Renderable(Primitive *r,MaterialInstance *mi,Pipeline *p,PrimitiveDataBuffer *prb,PrimitiveRenderData *prd) Renderable::Renderable(Primitive *r,MaterialInstance *mi,Pipeline *p,PrimitiveDataBuffer *pdb,PrimitiveRenderData *prd)
{ {
primitive=r; primitive=r;
pipeline=p; pipeline=p;
mat_inst=mi; mat_inst=mi;
primitive_data_buffer=prb; primitive_data_buffer=pdb;
primitive_render_data=prd; primitive_render_data=prd;
} }
PrimitiveRenderData::PrimitiveRenderData(const uint32_t bc,const uint32_t vc)
{
vab_count=bc;
vertex_count=vc;
vertex_offset=0;
first_index=0;
}
PrimitiveRenderData::~PrimitiveRenderData()
{
}
const bool PrimitiveRenderData::Comp(const PrimitiveRenderData *prd)const
{
if(!prd)return(false);
return !memcmp(this,prd,sizeof(PrimitiveRenderData));
}
Renderable *CreateRenderable(Primitive *prim,MaterialInstance *mi,Pipeline *p) Renderable *CreateRenderable(Primitive *prim,MaterialInstance *mi,Pipeline *p)
{ {
if(!prim||!mi||!p)return(nullptr); if(!prim||!mi||!p)return(nullptr);
const VIL *vil=mi->GetVIL(); const VIL *vil=mi->GetVIL();
const uint32_t input_count=vil->GetCount(VertexInputGroup::Basic); //不统计Bone/LocalToWorld组的 const uint32_t input_count=vil->GetVertexAttribCount(VertexInputGroup::Basic); //不统计Bone/LocalToWorld组的
const UTF8String &mtl_name=mi->GetMaterial()->GetName(); const UTF8String &mtl_name=mi->GetMaterial()->GetName();
if(prim->GetVABCount()<input_count) //小于材质要求的数量?那自然是不行的 if(prim->GetVABCount()<input_count) //小于材质要求的数量?那自然是不行的
@ -83,51 +62,50 @@ Renderable *CreateRenderable(Primitive *prim,MaterialInstance *mi,Pipeline *p)
return(nullptr); return(nullptr);
} }
PrimitiveDataBuffer *prb=new PrimitiveDataBuffer(input_count,prim->GetVertexCount(),prim->GetIBO()); PrimitiveDataBuffer *pdb=new PrimitiveDataBuffer(input_count,prim->GetIBO());
PrimitiveRenderData *prd=new PrimitiveRenderData(input_count,prim->GetVertexCount()); PrimitiveRenderData *prd=new PrimitiveRenderData(prim->GetVertexCount(),prim->GetIndexCount(),prim->GetVertexOffset(),prim->GetFirstIndex());
const VertexInputFormat *vif=vil->GetVIFList(VertexInputGroup::Basic); const VertexInputFormat *vif=vil->GetVIFList(VertexInputGroup::Basic);
VABAccess *vab_access; VAB *vab;
for(uint i=0;i<input_count;i++) for(uint i=0;i<input_count;i++)
{ {
//注: VIF来自于材质但VAB来自于Primitive。 //注: VIF来自于材质但VAB来自于Primitive。
// 两个并不一定一样排序也不一定一样。所以不能让PRIMTIVE直接提供BUFFER_LIST/OFFSET来搞一次性绑定。 // 两个并不一定一样排序也不一定一样。所以不能让PRIMTIVE直接提供BUFFER_LIST/OFFSET来搞一次性绑定。
vab_access=prim->GetVABAccess(vif->name); vab=prim->GetVAB(vif->name);
if(!vab_access||!vab_access->vab) if(!vab)
{ {
LOG_ERROR("[FATAL ERROR] not found VAB \""+AnsiString(vif->name)+"\" in Material: "+mtl_name); LOG_ERROR("[FATAL ERROR] not found VAB \""+AnsiString(vif->name)+"\" in Material: "+mtl_name);
return(nullptr); return(nullptr);
} }
if(vab_access->vab->GetFormat()!=vif->format) if(vab->GetFormat()!=vif->format)
{ {
LOG_ERROR( "[FATAL ERROR] VAB \""+UTF8String(vif->name)+ LOG_ERROR( "[FATAL ERROR] VAB \""+UTF8String(vif->name)+
UTF8String("\" format can't match Renderable, Material(")+mtl_name+ UTF8String("\" format can't match Renderable, Material(")+mtl_name+
UTF8String(") Format(")+GetVulkanFormatName(vif->format)+ UTF8String(") Format(")+GetVulkanFormatName(vif->format)+
UTF8String("), VAB Format(")+GetVulkanFormatName(vab_access->vab->GetFormat())+ UTF8String("), VAB Format(")+GetVulkanFormatName(vab->GetFormat())+
")"); ")");
return(nullptr); return(nullptr);
} }
if(vab_access->vab->GetStride()!=vif->stride) if(vab->GetStride()!=vif->stride)
{ {
LOG_ERROR( "[FATAL ERROR] VAB \""+UTF8String(vif->name)+ LOG_ERROR( "[FATAL ERROR] VAB \""+UTF8String(vif->name)+
UTF8String("\" stride can't match Renderable, Material(")+mtl_name+ UTF8String("\" stride can't match Renderable, Material(")+mtl_name+
UTF8String(") stride(")+UTF8String::numberOf(vif->stride)+ UTF8String(") stride(")+UTF8String::numberOf(vif->stride)+
UTF8String("), VAB stride(")+UTF8String::numberOf(vab_access->vab->GetStride())+ UTF8String("), VAB stride(")+UTF8String::numberOf(vab->GetStride())+
")"); ")");
return(nullptr); return(nullptr);
} }
prb->vab_offset[i]=vab_access->start; pdb->vab_list[i]=vab->GetBuffer();
prb->vab_list[i]=vab_access->vab->GetBuffer();
++vif; ++vif;
} }
return(new Renderable(prim,mi,p,prb,prd)); return(new Renderable(prim,mi,p,pdb,prd));
} }
VK_NAMESPACE_END VK_NAMESPACE_END