optimized MaterialRenderList, removed last_vil(pipeline already include vil), don't create assign_buffer if material don't include assign
This commit is contained in:
parent
255c7859f1
commit
317635877b
@ -1 +1 @@
|
|||||||
Subproject commit 0e91540e0aed109464cf1cceba0f3b417f706b64
|
Subproject commit a2f5b2d3c65bf8136e3bd53b05164c4f72de23ac
|
@ -92,7 +92,7 @@ private:
|
|||||||
camera_control->SetTarget(Vector3f(0,0,0));
|
camera_control->SetTarget(Vector3f(0,0,0));
|
||||||
camera_control->Refresh();
|
camera_control->Refresh();
|
||||||
|
|
||||||
camera_control->SetReserveDirection(true,true); //反转x,y
|
// camera_control->SetReserveDirection(true,true); //反转x,y
|
||||||
|
|
||||||
render_root.RefreshMatrix();
|
render_root.RefreshMatrix();
|
||||||
render_list->Expend(&render_root);
|
render_list->Expend(&render_root);
|
||||||
|
@ -13,7 +13,7 @@ class MaterialRenderList
|
|||||||
GPUDevice *device;
|
GPUDevice *device;
|
||||||
RenderCmdBuffer *cmd_buf;
|
RenderCmdBuffer *cmd_buf;
|
||||||
|
|
||||||
Material *mtl;
|
Material *material;
|
||||||
|
|
||||||
RenderNodeList rn_list;
|
RenderNodeList rn_list;
|
||||||
|
|
||||||
@ -46,12 +46,10 @@ protected:
|
|||||||
|
|
||||||
VBOList * vbo_list;
|
VBOList * vbo_list;
|
||||||
|
|
||||||
const VIL * last_vil;
|
|
||||||
Pipeline * last_pipeline;
|
Pipeline * last_pipeline;
|
||||||
const VertexInputData * last_vid;
|
const VertexInputData * last_vid;
|
||||||
uint last_index;
|
uint last_index;
|
||||||
|
|
||||||
void Bind(MaterialInstance *);
|
|
||||||
bool Bind(const VertexInputData *,const uint);
|
bool Bind(const VertexInputData *,const uint);
|
||||||
|
|
||||||
void Render(RenderItem *);
|
void Render(RenderItem *);
|
||||||
|
@ -69,6 +69,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
const bool hasSet (const DescriptorSetType &type)const;
|
const bool hasSet (const DescriptorSetType &type)const;
|
||||||
|
const bool hasAssign ()const;
|
||||||
|
|
||||||
const VIL * GetDefaultVIL()const;
|
const VIL * GetDefaultVIL()const;
|
||||||
VIL * CreateVIL(const VILConfig *format_map=nullptr);
|
VIL * CreateVIL(const VILConfig *format_map=nullptr);
|
||||||
|
@ -34,15 +34,6 @@ int Comparator<hgl::graph::RenderNode>::compare(const hgl::graph::RenderNode &ob
|
|||||||
return off;
|
return off;
|
||||||
}
|
}
|
||||||
|
|
||||||
//比较顶点输入格式
|
|
||||||
{
|
|
||||||
off=ri_one->GetMaterialInstance()->GetVIL()
|
|
||||||
-ri_two->GetMaterialInstance()->GetVIL();
|
|
||||||
|
|
||||||
if(off)
|
|
||||||
return off;
|
|
||||||
}
|
|
||||||
|
|
||||||
//比较模型
|
//比较模型
|
||||||
{
|
{
|
||||||
off=ri_one->GetPrimitive()
|
off=ri_one->GetPrimitive()
|
||||||
@ -60,10 +51,14 @@ MaterialRenderList::MaterialRenderList(GPUDevice *d,Material *m)
|
|||||||
{
|
{
|
||||||
device=d;
|
device=d;
|
||||||
cmd_buf=nullptr;
|
cmd_buf=nullptr;
|
||||||
mtl=m;
|
material=m;
|
||||||
assign_buffer=new RenderAssignBuffer(d,mtl->GetMIDataBytes());
|
|
||||||
|
|
||||||
vbo_list=new VBOList(mtl->GetVertexInput()->GetCount());
|
if(material->hasAssign())
|
||||||
|
assign_buffer=new RenderAssignBuffer(d,material->GetMIDataBytes());
|
||||||
|
else
|
||||||
|
assign_buffer=nullptr;
|
||||||
|
|
||||||
|
vbo_list=new VBOList(material->GetVertexInput()->GetCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
MaterialRenderList::~MaterialRenderList()
|
MaterialRenderList::~MaterialRenderList()
|
||||||
@ -91,13 +86,16 @@ void MaterialRenderList::End()
|
|||||||
|
|
||||||
if(node_count<=0)return;
|
if(node_count<=0)return;
|
||||||
|
|
||||||
if(mtl->HasMI())
|
|
||||||
StatMI();
|
|
||||||
|
|
||||||
Stat();
|
Stat();
|
||||||
|
|
||||||
//写入LocalToWorld数据
|
if(assign_buffer)
|
||||||
assign_buffer->WriteNode(rn_list.GetData(),node_count,mi_set);
|
{
|
||||||
|
if(material->HasMI())
|
||||||
|
StatMI();
|
||||||
|
|
||||||
|
//写入LocalToWorld数据
|
||||||
|
assign_buffer->WriteNode(rn_list.GetData(),node_count,mi_set);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MaterialRenderList::RenderItem::Set(Renderable *ri)
|
void MaterialRenderList::RenderItem::Set(Renderable *ri)
|
||||||
@ -114,7 +112,7 @@ void MaterialRenderList::StatMI()
|
|||||||
for(RenderNode &rn:rn_list)
|
for(RenderNode &rn:rn_list)
|
||||||
mi_set.Add(rn.ri->GetMaterialInstance());
|
mi_set.Add(rn.ri->GetMaterialInstance());
|
||||||
|
|
||||||
if(mi_set.GetCount()>mtl->GetMIMaxCount())
|
if(mi_set.GetCount()>material->GetMIMaxCount())
|
||||||
{
|
{
|
||||||
//超出最大数量了怎么办???
|
//超出最大数量了怎么办???
|
||||||
}
|
}
|
||||||
@ -137,7 +135,6 @@ void MaterialRenderList::Stat()
|
|||||||
ri->Set(rn->ri);
|
ri->Set(rn->ri);
|
||||||
|
|
||||||
last_pipeline =ri->pipeline;
|
last_pipeline =ri->pipeline;
|
||||||
last_vil =ri->mi->GetVIL();
|
|
||||||
last_vid =ri->vid;
|
last_vid =ri->vid;
|
||||||
|
|
||||||
++rn;
|
++rn;
|
||||||
@ -145,13 +142,12 @@ 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_vil==rn->ri->GetMaterialInstance()->GetVIL())
|
if(last_vid->Comp(rn->ri->GetVertexInputData()))
|
||||||
if(last_vid->Comp(rn->ri->GetVertexInputData()))
|
{
|
||||||
{
|
++ri->count;
|
||||||
++ri->count;
|
++rn;
|
||||||
++rn;
|
continue;
|
||||||
continue;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
++ri_count;
|
++ri_count;
|
||||||
++ri;
|
++ri;
|
||||||
@ -161,30 +157,20 @@ void MaterialRenderList::Stat()
|
|||||||
ri->Set(rn->ri);
|
ri->Set(rn->ri);
|
||||||
|
|
||||||
last_pipeline =ri->pipeline;
|
last_pipeline =ri->pipeline;
|
||||||
last_vil =ri->mi->GetVIL();
|
|
||||||
last_vid =ri->vid;
|
last_vid =ri->vid;
|
||||||
|
|
||||||
++rn;
|
++rn;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MaterialRenderList::Bind(MaterialInstance *mi)
|
|
||||||
{
|
|
||||||
if(!mi)return;
|
|
||||||
|
|
||||||
assign_buffer->Bind(mi);
|
|
||||||
|
|
||||||
cmd_buf->BindDescriptorSets(mi->GetMaterial());
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MaterialRenderList::Bind(const VertexInputData *vid,const uint ri_index)
|
bool MaterialRenderList::Bind(const VertexInputData *vid,const uint ri_index)
|
||||||
{
|
{
|
||||||
//binding号都是在VertexInput::CreateVIL时连续紧密排列生成的,所以bind时first_binding写0就行了。
|
//binding号都是在VertexInput::CreateVIL时连续紧密排列生成的,所以bind时first_binding写0就行了。
|
||||||
|
|
||||||
const VIL *vil=last_vil;
|
//const VIL *vil=last_vil;
|
||||||
|
|
||||||
if(vil->GetCount(VertexInputGroup::Basic)!=vid->binding_count)
|
//if(vil->GetCount(VertexInputGroup::Basic)!=vid->binding_count)
|
||||||
return(false); //这里基本不太可能,因为CreateRenderable时就会检查值是否一样
|
// return(false); //这里基本不太可能,因为CreateRenderable时就会检查值是否一样
|
||||||
|
|
||||||
vbo_list->Restart();
|
vbo_list->Restart();
|
||||||
|
|
||||||
@ -221,17 +207,10 @@ bool MaterialRenderList::Bind(const VertexInputData *vid,const uint ri_index)
|
|||||||
// }
|
// }
|
||||||
//}
|
//}
|
||||||
|
|
||||||
if(!vbo_list->IsFull()) //Assign组
|
//if(!vbo_list->IsFull()) //Assign组
|
||||||
{
|
{
|
||||||
const uint assign_binding_count=vil->GetCount(VertexInputGroup::Assign);
|
if(assign_buffer)
|
||||||
|
|
||||||
if(assign_binding_count>0)
|
|
||||||
{
|
|
||||||
if(assign_binding_count!=1)
|
|
||||||
return(false);
|
|
||||||
|
|
||||||
vbo_list->Add(assign_buffer->GetAssignVBO(),ASSIGN_VBO_STRIDE_BYTES*ri_index);
|
vbo_list->Add(assign_buffer->GetAssignVBO(),ASSIGN_VBO_STRIDE_BYTES*ri_index);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//if(count!=binding_count)
|
//if(count!=binding_count)
|
||||||
@ -258,14 +237,6 @@ void MaterialRenderList::Render(RenderItem *ri)
|
|||||||
//这里未来尝试换pipeline同时不换mi/primitive是否需要重新绑定mi/primitive
|
//这里未来尝试换pipeline同时不换mi/primitive是否需要重新绑定mi/primitive
|
||||||
}
|
}
|
||||||
|
|
||||||
if(last_vil!=ri->mi->GetVIL())
|
|
||||||
{
|
|
||||||
Bind(ri->mi);
|
|
||||||
last_vil=ri->mi->GetVIL();
|
|
||||||
|
|
||||||
last_vid=nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!ri->vid->Comp(last_vid))
|
if(!ri->vid->Comp(last_vid))
|
||||||
{
|
{
|
||||||
Bind(ri->vid,ri->first);
|
Bind(ri->vid,ri->first);
|
||||||
@ -300,9 +271,13 @@ void MaterialRenderList::Render(RenderCmdBuffer *rcb)
|
|||||||
RenderItem *ri=ri_array.GetData();
|
RenderItem *ri=ri_array.GetData();
|
||||||
|
|
||||||
last_pipeline =nullptr;
|
last_pipeline =nullptr;
|
||||||
last_vil =nullptr;
|
|
||||||
last_vid =nullptr;
|
last_vid =nullptr;
|
||||||
|
|
||||||
|
if(assign_buffer)
|
||||||
|
assign_buffer->Bind(material);
|
||||||
|
|
||||||
|
cmd_buf->BindDescriptorSets(material);
|
||||||
|
|
||||||
for(uint i=0;i<ri_count;i++)
|
for(uint i=0;i<ri_count;i++)
|
||||||
{
|
{
|
||||||
Render(ri);
|
Render(ri);
|
||||||
|
@ -25,15 +25,12 @@ VkBuffer RenderAssignBuffer::GetAssignVBO()const
|
|||||||
return vbo_assigns->GetBuffer();
|
return vbo_assigns->GetBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderAssignBuffer::Bind(MaterialInstance *mi)const
|
void RenderAssignBuffer::Bind(Material *mtl)const
|
||||||
{
|
{
|
||||||
const VIL *vil=mi->GetVIL();
|
if(!mtl)return;
|
||||||
|
|
||||||
const uint assign_binding_count=vil->GetCount(VertexInputGroup::Assign);
|
if(!mtl->hasAssign())
|
||||||
|
return;
|
||||||
if(assign_binding_count<=0)return;
|
|
||||||
|
|
||||||
Material *mtl=mi->GetMaterial();
|
|
||||||
|
|
||||||
mtl->BindUBO(DescriptorSetType::PerFrame,mtl::SBS_LocalToWorld.name,ubo_l2w);
|
mtl->BindUBO(DescriptorSetType::PerFrame,mtl::SBS_LocalToWorld.name,ubo_l2w);
|
||||||
mtl->BindUBO(DescriptorSetType::PerMaterial,mtl::SBS_MaterialInstance.name,ubo_mi);
|
mtl->BindUBO(DescriptorSetType::PerMaterial,mtl::SBS_MaterialInstance.name,ubo_mi);
|
||||||
|
@ -54,7 +54,7 @@ public:
|
|||||||
|
|
||||||
VkBuffer GetAssignVBO()const;
|
VkBuffer GetAssignVBO()const;
|
||||||
|
|
||||||
void Bind(MaterialInstance *)const;
|
void Bind(Material *)const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -47,6 +47,11 @@ const bool Material::hasSet(const DescriptorSetType &dst)const
|
|||||||
return desc_manager->hasSet(dst);
|
return desc_manager->hasSet(dst);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const bool Material::hasAssign()const
|
||||||
|
{
|
||||||
|
return vertex_input->hasAssign();
|
||||||
|
}
|
||||||
|
|
||||||
const VIL *Material::GetDefaultVIL()const
|
const VIL *Material::GetDefaultVIL()const
|
||||||
{
|
{
|
||||||
return vertex_input->GetDefaultVIL();
|
return vertex_input->GetDefaultVIL();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user