From 427340132f55e7b8730550502495aa29597c8ef5 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Fri, 6 Jun 2025 00:22:45 +0800 Subject: [PATCH] =?UTF-8?q?VABList=E6=95=B0=E6=8D=AE=E5=86=99=E5=85=A5?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=B6=8A=E7=95=8C=E6=A3=80=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inc/hgl/graph/VKVABList.h | 20 ++++++++++++-- src/SceneGraph/render/MaterialRenderList.cpp | 28 +++++++++++++++----- 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/inc/hgl/graph/VKVABList.h b/inc/hgl/graph/VKVABList.h index 645a144e..526c117d 100644 --- a/inc/hgl/graph/VKVABList.h +++ b/inc/hgl/graph/VKVABList.h @@ -38,16 +38,31 @@ public: return write_count>=vab_count; } - void Add(const VkBuffer buf,const VkDeviceSize offset) + bool Add(const VkBuffer buf,const VkDeviceSize offset) { + if(IsFull()) + { + //如果在这里出现错误,一般是材质的VertexInput与实现要使用的不匹配。很多时候是由于引擎自动添加的VertexInput但材质里没有。 + //比较典型的情况是创建材质时设置了不需要L2W,但实际又进行了传递 + return(false); //列表已满 + } + vab_list[write_count]=buf; vab_offset[write_count]=offset; ++write_count; + + return(true); } - void Add(const VkBuffer *buf,const VkDeviceSize *offset,const uint32_t count) + bool Add(const VkBuffer *buf,const VkDeviceSize *offset,const uint32_t count) { + if(!buf||!offset||!count) + return(false); + + if(write_count+count>vab_count) + return(false); //列表已满 + hgl_cpy(vab_list +write_count,buf, count); if(offset) @@ -56,6 +71,7 @@ public: hgl_set(vab_offset+write_count,VkDeviceSize(0),count); write_count+=count; + return(true); } };//class VABList VK_NAMESPACE_END diff --git a/src/SceneGraph/render/MaterialRenderList.cpp b/src/SceneGraph/render/MaterialRenderList.cpp index 3744dd4a..7efa081e 100644 --- a/src/SceneGraph/render/MaterialRenderList.cpp +++ b/src/SceneGraph/render/MaterialRenderList.cpp @@ -346,13 +346,21 @@ bool MaterialRenderList::BindVAB(const MeshDataBuffer *pdb,const uint ri_index) //Basic组,它所有的VAB信息均来自于Primitive,由vid参数传递进来 { - vab_list->Add(pdb->vab_list, - pdb->vab_offset, - pdb->vab_count); + if(!vab_list->Add(pdb->vab_list,pdb->vab_offset,pdb->vab_count)) + { + //这个情况很严重哦! + return(false); + } } - if(assign_buffer) //L2W/MI分发组 - vab_list->Add(assign_buffer->GetVAB(),0);//ASSIGN_VAB_STRIDE_BYTES*ri_index); + if (assign_buffer) //L2W/MI分发组 + { + if(!vab_list->Add(assign_buffer->GetVAB(),0))//ASSIGN_VAB_STRIDE_BYTES*ri_index); + { + //一般出现这个情况是因为材质中没有配置需要L2W + return(false); + } + } //if(!vab_list.IsFull()) //Joint组,暂未支持 //{ @@ -405,7 +413,7 @@ void MaterialRenderList::ProcIndirectRender() indirect_draw_count=0; } -void MaterialRenderList::Render(RenderItem *ri) +bool MaterialRenderList::Render(RenderItem *ri) { if(!last_data_buffer||*(ri->pdb)!=*last_data_buffer) //换buf了 { @@ -415,7 +423,11 @@ void MaterialRenderList::Render(RenderItem *ri) last_data_buffer=ri->pdb; last_render_data=nullptr; - BindVAB(ri->pdb,ri->first_instance); + if(!BindVAB(ri->pdb,ri->first_instance)) + { + //这个问题很严重哦 + return(false); + } if(ri->pdb->ibo) cmd_buf->BindIBO(ri->pdb->ibo); @@ -432,6 +444,8 @@ void MaterialRenderList::Render(RenderItem *ri) { cmd_buf->Draw(ri->pdb,ri->prd,ri->instance_count,ri->first_instance); } + + return(true); } void MaterialRenderList::Render(RenderCmdBuffer *rcb)