OK! Can RUN! full OK!...next step is to create VDMRender in MaterialRenderList
This commit is contained in:
@@ -130,39 +130,32 @@ bool RenderCmdBuffer::BindDescriptorSets(Material *mtl)
|
||||
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;
|
||||
|
||||
|
||||
vkCmdBindIndexBuffer(cmd_buf,
|
||||
ibo->GetBuffer(),
|
||||
iba->start*ibo->GetStride(),
|
||||
byte_offset,
|
||||
VkIndexType(ibo->GetType()));
|
||||
}
|
||||
|
||||
bool RenderCmdBuffer::BindVAB(Renderable *ri)
|
||||
bool RenderCmdBuffer::BindRenderBuffer(const PrimitiveDataBuffer *pdb)
|
||||
{
|
||||
if(!ri)
|
||||
if(!pdb)
|
||||
return(false);
|
||||
|
||||
const PrimitiveDataBuffer *prb=ri->GetRenderBuffer();
|
||||
|
||||
if(prb->vab_count<=0)
|
||||
if(pdb->vab_count<=0)
|
||||
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)
|
||||
return(false);
|
||||
|
||||
vkCmdBindVertexBuffers(cmd_buf,0,prb->vab_count,prb->vab_list,prb->vab_offset);
|
||||
|
||||
if(prb->ib_access->buffer)
|
||||
BindIBO(prb->ib_access);
|
||||
if(pdb->ibo)
|
||||
BindIBO(pdb->ibo);
|
||||
|
||||
return(true);
|
||||
}
|
||||
@@ -191,15 +184,24 @@ void RenderCmdBuffer::DrawIndexedIndirect( VkBuffer buffer,
|
||||
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)
|
||||
return;
|
||||
|
||||
if (prb->ib_access->buffer)
|
||||
DrawIndexed(prd->index_count);
|
||||
if (prb->ibo)
|
||||
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
|
||||
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)
|
||||
|
@@ -51,14 +51,24 @@ const int Primitive::GetVABCount()const
|
||||
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()
|
||||
@@ -66,4 +76,8 @@ IndexBuffer *Primitive::GetIBO()
|
||||
return prim_data->GetIBO();
|
||||
}
|
||||
|
||||
const uint32_t Primitive::GetFirstIndex()const
|
||||
{
|
||||
return prim_data->GetFirstIndex();
|
||||
}
|
||||
VK_NAMESPACE_END
|
||||
|
@@ -13,7 +13,7 @@ PrimitiveData::PrimitiveData(const VIL *_vil,const uint32_t vc)
|
||||
|
||||
vertex_count=vc;
|
||||
|
||||
vab_list=hgl_zero_new<VAB *>(_vil->GetCount());
|
||||
vab_list=hgl_zero_new<VAB *>(_vil->GetVertexAttribCount());
|
||||
|
||||
ibo=nullptr;
|
||||
}
|
||||
@@ -25,7 +25,7 @@ PrimitiveData::~PrimitiveData()
|
||||
|
||||
const int PrimitiveData::GetVABCount()const
|
||||
{
|
||||
return vil->GetCount();
|
||||
return vil->GetVertexAttribCount();
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
if(index<0||index>=vil->GetCount())return(nullptr);
|
||||
if(index<0||index>=vil->GetVertexAttribCount())return(nullptr);
|
||||
|
||||
return vab_list[index];
|
||||
}
|
||||
@@ -67,7 +67,7 @@ namespace
|
||||
{
|
||||
VAB **vab=vab_list;
|
||||
|
||||
for(uint i=0;i<vil->GetCount();i++)
|
||||
for(uint i=0;i<vil->GetVertexAttribCount();i++)
|
||||
{
|
||||
if(*vab)
|
||||
delete *vab;
|
||||
@@ -100,7 +100,7 @@ namespace
|
||||
if(!device)return(nullptr);
|
||||
if(!vil)return(nullptr);
|
||||
|
||||
if(vab_index<0||vab_index>=vil->GetCount())
|
||||
if(vab_index<0||vab_index>=vil->GetVertexAttribCount())
|
||||
return(nullptr);
|
||||
|
||||
const VertexInputFormat *vif=vil->GetConfig(vab_index);
|
||||
@@ -159,14 +159,14 @@ namespace
|
||||
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(!ib_node)
|
||||
{
|
||||
ib_node=vdm->AcquireIB(index_count);
|
||||
ib_node=vdm->AcquireIB(ic);
|
||||
|
||||
if(!ib_node)
|
||||
return(nullptr);
|
||||
@@ -174,6 +174,8 @@ namespace
|
||||
ibo=vdm->GetIBO();
|
||||
}
|
||||
|
||||
index_count=ic;
|
||||
|
||||
return ibo;
|
||||
}
|
||||
|
||||
@@ -182,7 +184,7 @@ namespace
|
||||
if(!vdm)return(nullptr);
|
||||
if(!vil)return(nullptr);
|
||||
|
||||
if (vab_index<0||vab_index>=vil->GetCount())
|
||||
if (vab_index<0||vab_index>=vil->GetVertexAttribCount())
|
||||
return(nullptr);
|
||||
|
||||
const VertexInputFormat *vif=vil->GetConfig(vab_index);
|
||||
|
@@ -38,6 +38,7 @@ public:
|
||||
const int GetVABCount ()const;
|
||||
const int GetVABIndex (const AnsiString &name)const;
|
||||
VAB * GetVAB (const int index);
|
||||
VAB * GetVAB (const AnsiString &name){return GetVAB(GetVABIndex(name));}
|
||||
|
||||
IndexBuffer * GetIBO (){return ibo;}
|
||||
uint32_t GetIndexCount ()const{return index_count;}
|
||||
|
@@ -7,7 +7,7 @@
|
||||
#include<hgl/log/LogInfo.h>
|
||||
|
||||
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;
|
||||
|
||||
@@ -20,60 +20,39 @@ PrimitiveDataBuffer::~PrimitiveDataBuffer()
|
||||
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++)
|
||||
{
|
||||
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(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;
|
||||
pipeline=p;
|
||||
mat_inst=mi;
|
||||
|
||||
primitive_data_buffer=prb;
|
||||
primitive_data_buffer=pdb;
|
||||
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)
|
||||
{
|
||||
if(!prim||!mi||!p)return(nullptr);
|
||||
|
||||
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();
|
||||
|
||||
if(prim->GetVABCount()<input_count) //小于材质要求的数量?那自然是不行的
|
||||
@@ -83,51 +62,50 @@ Renderable *CreateRenderable(Primitive *prim,MaterialInstance *mi,Pipeline *p)
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
PrimitiveDataBuffer *prb=new PrimitiveDataBuffer(input_count,prim->GetVertexCount(),prim->GetIBO());
|
||||
PrimitiveRenderData *prd=new PrimitiveRenderData(input_count,prim->GetVertexCount());
|
||||
PrimitiveDataBuffer *pdb=new PrimitiveDataBuffer(input_count,prim->GetIBO());
|
||||
PrimitiveRenderData *prd=new PrimitiveRenderData(prim->GetVertexCount(),prim->GetIndexCount(),prim->GetVertexOffset(),prim->GetFirstIndex());
|
||||
|
||||
const VertexInputFormat *vif=vil->GetVIFList(VertexInputGroup::Basic);
|
||||
|
||||
VABAccess *vab_access;
|
||||
VAB *vab;
|
||||
|
||||
for(uint i=0;i<input_count;i++)
|
||||
{
|
||||
//注: VIF来自于材质,但VAB来自于Primitive。
|
||||
// 两个并不一定一样,排序也不一定一样。所以不能让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);
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
if(vab_access->vab->GetFormat()!=vif->format)
|
||||
if(vab->GetFormat()!=vif->format)
|
||||
{
|
||||
LOG_ERROR( "[FATAL ERROR] VAB \""+UTF8String(vif->name)+
|
||||
UTF8String("\" format can't match Renderable, Material(")+mtl_name+
|
||||
UTF8String(") Format(")+GetVulkanFormatName(vif->format)+
|
||||
UTF8String("), VAB Format(")+GetVulkanFormatName(vab_access->vab->GetFormat())+
|
||||
UTF8String("), VAB Format(")+GetVulkanFormatName(vab->GetFormat())+
|
||||
")");
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
if(vab_access->vab->GetStride()!=vif->stride)
|
||||
if(vab->GetStride()!=vif->stride)
|
||||
{
|
||||
LOG_ERROR( "[FATAL ERROR] VAB \""+UTF8String(vif->name)+
|
||||
UTF8String("\" stride can't match Renderable, Material(")+mtl_name+
|
||||
UTF8String(") stride(")+UTF8String::numberOf(vif->stride)+
|
||||
UTF8String("), VAB stride(")+UTF8String::numberOf(vab_access->vab->GetStride())+
|
||||
UTF8String("), VAB stride(")+UTF8String::numberOf(vab->GetStride())+
|
||||
")");
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
prb->vab_offset[i]=vab_access->start;
|
||||
prb->vab_list[i]=vab_access->vab->GetBuffer();
|
||||
pdb->vab_list[i]=vab->GetBuffer();
|
||||
++vif;
|
||||
}
|
||||
|
||||
return(new Renderable(prim,mi,p,prb,prd));
|
||||
return(new Renderable(prim,mi,p,pdb,prd));
|
||||
}
|
||||
VK_NAMESPACE_END
|
||||
|
Reference in New Issue
Block a user