From 6740764f0703558d9819bba23c6b8b6a6e147a00 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Sat, 25 May 2024 22:08:01 +0800 Subject: [PATCH] create DrawData that it split from VertexInputData --- example/common/VulkanAppFramework.h | 2 +- inc/hgl/graph/MaterialRenderList.h | 6 +- inc/hgl/graph/VK.h | 1 + inc/hgl/graph/VKCommandBuffer.h | 8 +- inc/hgl/graph/VKDescriptorSet.h | 10 +- inc/hgl/graph/VKMaterial.h | 4 +- inc/hgl/graph/VKPrimitive.h | 3 + inc/hgl/graph/VKRenderable.h | 64 +++++++------ inc/hgl/graph/VKVBOList.h | 28 +++--- src/SceneGraph/MaterialRenderList.cpp | 39 +++++--- .../Vulkan/VKCommandBufferRender.cpp | 68 +++++++------ src/SceneGraph/Vulkan/VKDescriptorSet.cpp | 6 +- src/SceneGraph/Vulkan/VKDeviceMaterial.cpp | 6 +- src/SceneGraph/Vulkan/VKMaterial.cpp | 12 +-- .../Vulkan/VKPipelineLayoutData.cpp | 2 +- src/SceneGraph/Vulkan/VKPipelineLayoutData.h | 2 +- src/SceneGraph/Vulkan/VKPrimitive.cpp | 5 + src/SceneGraph/Vulkan/VKPrimitiveData.h | 2 + .../Vulkan/VKRenderResourceMaterial.cpp | 2 +- src/SceneGraph/Vulkan/VKRenderable.cpp | 95 ++++++++++++++----- 20 files changed, 225 insertions(+), 140 deletions(-) diff --git a/example/common/VulkanAppFramework.h b/example/common/VulkanAppFramework.h index 1ca00e21..c810a6db 100644 --- a/example/common/VulkanAppFramework.h +++ b/example/common/VulkanAppFramework.h @@ -225,7 +225,7 @@ public: cb->BindPipeline(ri->GetPipeline()); cb->BindDescriptorSets(ri->GetMaterial()); cb->BindVBO(ri); - cb->Draw(vid); + cb->Draw(vid,ri->GetDrawData()); cb->EndRenderPass(); cb->End(); diff --git a/inc/hgl/graph/MaterialRenderList.h b/inc/hgl/graph/MaterialRenderList.h index a8fa0a0e..5a8b3ab0 100644 --- a/inc/hgl/graph/MaterialRenderList.h +++ b/inc/hgl/graph/MaterialRenderList.h @@ -3,9 +3,9 @@ #include VK_NAMESPACE_BEGIN -class RenderL2WBuffer; class RenderAssignBuffer; + /** * 同一材质的对象渲染列表 */ @@ -30,6 +30,7 @@ private: Pipeline * pipeline; MaterialInstance * mi; const VertexInputData * vid; + const DrawData * dd; public: @@ -47,9 +48,10 @@ protected: Pipeline * last_pipeline; const VertexInputData * last_vid; + const DrawData * last_dd; uint last_index; - bool Bind(const VertexInputData *,const uint); + bool BindVAB(const VertexInputData *,const DrawData *,const uint); void Render(RenderItem *); diff --git a/inc/hgl/graph/VK.h b/inc/hgl/graph/VK.h index 7f6c0b19..2919d5ad 100644 --- a/inc/hgl/graph/VK.h +++ b/inc/hgl/graph/VK.h @@ -55,6 +55,7 @@ class DeviceBuffer; struct DeviceBufferData; struct VertexInputData; +struct DrawData; class VertexAttribBuffer; using VAB=VertexAttribBuffer; diff --git a/inc/hgl/graph/VKCommandBuffer.h b/inc/hgl/graph/VKCommandBuffer.h index 5dfceb4f..13705c42 100644 --- a/inc/hgl/graph/VKCommandBuffer.h +++ b/inc/hgl/graph/VKCommandBuffer.h @@ -165,12 +165,12 @@ public: if(!vbo_list->IsFull())return(false); - vkCmdBindVertexBuffers(cmd_buf,0,vbo_list->binding_count,vbo_list->buffer_list,vbo_list->buffer_offset); + vkCmdBindVertexBuffers(cmd_buf,0,vbo_list->vab_count,vbo_list->vab_list,vbo_list->vab_offset); return(true); } -// void BindIBO(const IBAccess *); + void BindIBO(IndexBuffer *ibo,VkDeviceSize offset); ///<绑定IBO,注意offset意为索引偏移量,不是字节 bool BindVBO(Renderable *); @@ -200,8 +200,8 @@ 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 VertexInputData *vid); - void DrawIndexed (const IBAccess *iba,const uint32_t instance_count); + void Draw (const VertexInputData *vid,const DrawData *dd); +// void DrawIndexed (const IBAccess *iba,const uint32_t instance_count); public: //dynamic state };//class RenderCmdBuffer:public GPUCmdBuffer diff --git a/inc/hgl/graph/VKDescriptorSet.h b/inc/hgl/graph/VKDescriptorSet.h index b07404ce..476bd8b2 100644 --- a/inc/hgl/graph/VKDescriptorSet.h +++ b/inc/hgl/graph/VKDescriptorSet.h @@ -11,12 +11,12 @@ class DeviceBuffer; class DescriptorSet { VkDevice device; - int binding_count; + int vab_count; VkDescriptorSet desc_set; VkPipelineLayout pipeline_layout; - ObjectList buffer_list; + ObjectList vab_list; ObjectList image_list; List wds_list; @@ -29,7 +29,7 @@ public: DescriptorSet(VkDevice dev,const int bc,VkPipelineLayout pl,VkDescriptorSet ds) { device =dev; - binding_count =bc; + vab_count =bc; desc_set =ds; pipeline_layout =pl; @@ -38,11 +38,11 @@ public: ~DescriptorSet()=default; - const uint32_t GetCount ()const{return binding_count;} + const uint32_t GetCount ()const{return vab_count;} const VkDescriptorSet GetDescriptorSet ()const{return desc_set;} const VkPipelineLayout GetPipelineLayout ()const{return pipeline_layout;} - const bool IsReady ()const{return wds_list.GetCount()==binding_count;} + const bool IsReady ()const{return wds_list.GetCount()==vab_count;} void Clear(); diff --git a/inc/hgl/graph/VKMaterial.h b/inc/hgl/graph/VKMaterial.h index b22ce3fb..1d03d72a 100644 --- a/inc/hgl/graph/VKMaterial.h +++ b/inc/hgl/graph/VKMaterial.h @@ -22,7 +22,7 @@ class Material { AnsiString name; - VertexInput *vertex_input; + VertexInput *vertex_input_data; ShaderModuleMap *shader_maps; @@ -51,7 +51,7 @@ public: const AnsiString & GetName ()const{return name;} - const VertexInput * GetVertexInput ()const{return vertex_input;} + const VertexInput * GetVertexInput ()const{return vertex_input_data;} const ShaderStageCreateInfoList & GetStageList ()const{return shader_stage_list;} diff --git a/inc/hgl/graph/VKPrimitive.h b/inc/hgl/graph/VKPrimitive.h index aad8674d..77516d85 100644 --- a/inc/hgl/graph/VKPrimitive.h +++ b/inc/hgl/graph/VKPrimitive.h @@ -40,10 +40,13 @@ public: public: const AnsiString & GetName ()const{ return prim_name; } + const VkDeviceSize GetVertexCount ()const; const int GetVABCount ()const; VABAccess * GetVABAccess (const AnsiString &); + IBAccess * GetIBAccess (); + IndexBuffer * GetIBO (); const AABB & GetBoundingBox ()const{return BoundingBox;} };//class Primitive diff --git a/inc/hgl/graph/VKRenderable.h b/inc/hgl/graph/VKRenderable.h index 1a926a4c..5080d005 100644 --- a/inc/hgl/graph/VKRenderable.h +++ b/inc/hgl/graph/VKRenderable.h @@ -11,39 +11,35 @@ VK_NAMESPACE_BEGIN struct VertexInputData { - uint32_t binding_count; - VkBuffer *buffer_list; - VkDeviceSize *buffer_offset; - - uint32_t vertex_count; - - const IBAccess *ib_access; + uint32_t vab_count; + VkBuffer *vab_list; + IndexBuffer *ibo; public: - VertexInputData(const uint32_t,const uint32_t,const IBAccess *); + VertexInputData(const uint32_t,const uint32_t,const IBAccess *iba); ~VertexInputData(); - const bool Comp(const VertexInputData *vid)const - { - if(!vid)return(false); - - if(binding_count!=vid->binding_count)return(false); - - for(uint32_t i=0;ibuffer_list[i])return(false); - if(buffer_offset[i]!=vid->buffer_offset[i])return(false); - } - - if(vertex_count!=vid->vertex_count)return(false); - - if(ib_access!=vid->ib_access)return(false); - - return(true); - } + const bool Comp(const VertexInputData *vid)const; };//struct VertexInputData +struct DrawData +{ + uint vab_count; + VkDeviceSize * vab_offset; + VkDeviceSize vertex_count; + + VkDeviceSize index_start; + VkDeviceSize index_count; + +public: + + DrawData(const uint32_t bc,const VkDeviceSize vc,const IBAccess *iba); + ~DrawData(); + + const bool Comp(const DrawData *)const; +}; + /** * 可渲染对象
*/ @@ -53,17 +49,24 @@ class Renderable MaterialInstance * mat_inst; Primitive * primitive; - VertexInputData * vertex_input; + VertexInputData * vertex_input_data; + DrawData * draw_data; private: friend Renderable *CreateRenderable(Primitive *,MaterialInstance *,Pipeline *); - Renderable(Primitive *,MaterialInstance *,Pipeline *,VertexInputData *); + Renderable(Primitive *,MaterialInstance *,Pipeline *,VertexInputData *,DrawData *); public: - virtual ~Renderable(); + virtual ~Renderable() + { + //需要在这里添加删除pipeline/desc_sets/primitive引用计数的代码 + + SAFE_CLEAR(vertex_input_data); + SAFE_CLEAR(draw_data); + } void UpdatePipeline (Pipeline *p){pipeline=p;} @@ -74,7 +77,8 @@ public: Primitive * GetPrimitive (){return primitive;} const AABB & GetBoundingBox ()const{return primitive->GetBoundingBox();} - const VertexInputData * GetVertexInputData ()const{return vertex_input;} + const VertexInputData * GetVertexInputData ()const{return vertex_input_data;} + const DrawData * GetDrawData ()const{return draw_data;} };//class Renderable Renderable *CreateRenderable(Primitive *,MaterialInstance *,Pipeline *); diff --git a/inc/hgl/graph/VKVBOList.h b/inc/hgl/graph/VKVBOList.h index 6ffba531..23a830a5 100644 --- a/inc/hgl/graph/VKVBOList.h +++ b/inc/hgl/graph/VKVBOList.h @@ -1,11 +1,11 @@ -#pragma once +#pragma once VK_NAMESPACE_BEGIN class VBOList { - uint32_t binding_count; - VkBuffer *buffer_list; - VkDeviceSize *buffer_offset; + uint32_t vab_count; + VkBuffer *vab_list; + VkDeviceSize *vab_offset; uint32_t write_count; @@ -15,17 +15,17 @@ public: VBOList(const uint32 bc) { - binding_count=bc; - buffer_list=new VkBuffer[binding_count]; - buffer_offset=new VkDeviceSize[binding_count]; + vab_count=bc; + vab_list=new VkBuffer[vab_count]; + vab_offset=new VkDeviceSize[vab_count]; write_count=0; } ~VBOList() { - delete[] buffer_offset; - delete[] buffer_list; + delete[] vab_offset; + delete[] vab_list; } void Restart() @@ -35,21 +35,21 @@ public: const bool IsFull()const { - return write_count>=binding_count; + return write_count>=vab_count; } void Add(const VkBuffer buf,const VkDeviceSize offset) { - buffer_list[write_count]=buf; - buffer_offset[write_count]=offset; + vab_list[write_count]=buf; + vab_offset[write_count]=offset; ++write_count; } void Add(const VkBuffer *buf,const VkDeviceSize *offset,const uint32_t count) { - hgl_cpy(buffer_list +write_count,buf, count); - hgl_cpy(buffer_offset+write_count,offset,count); + hgl_cpy(vab_list +write_count,buf, count); + hgl_cpy(vab_offset+write_count,offset,count); write_count+=count; } diff --git a/src/SceneGraph/MaterialRenderList.cpp b/src/SceneGraph/MaterialRenderList.cpp index 027fa7e0..5cadcd93 100644 --- a/src/SceneGraph/MaterialRenderList.cpp +++ b/src/SceneGraph/MaterialRenderList.cpp @@ -94,6 +94,7 @@ void MaterialRenderList::RenderItem::Set(Renderable *ri) pipeline =ri->GetPipeline(); mi =ri->GetMaterialInstance(); vid =ri->GetVertexInputData(); + dd =ri->GetDrawData(); } void MaterialRenderList::Stat() @@ -114,6 +115,7 @@ void MaterialRenderList::Stat() last_pipeline =ri->pipeline; last_vid =ri->vid; + last_dd =ri->dd; ++rn; @@ -121,11 +123,12 @@ void MaterialRenderList::Stat() { if(last_pipeline==rn->ri->GetPipeline()) if(last_vid->Comp(rn->ri->GetVertexInputData())) - { - ++ri->count; - ++rn; - continue; - } + if(last_dd->Comp(rn->ri->GetDrawData())) + { + ++ri->count; + ++rn; + continue; + } ++ri_count; ++ri; @@ -136,25 +139,26 @@ void MaterialRenderList::Stat() last_pipeline =ri->pipeline; last_vid =ri->vid; + last_dd =ri->dd; ++rn; } } -bool MaterialRenderList::Bind(const VertexInputData *vid,const uint ri_index) +bool MaterialRenderList::BindVAB(const VertexInputData *vid,const DrawData *dd,const uint ri_index) { //binding号都是在VertexInput::CreateVIL时连续紧密排列生成的,所以bind时first_binding写0就行了。 //const VIL *vil=last_vil; - //if(vil->GetCount(VertexInputGroup::Basic)!=vid->binding_count) + //if(vil->GetCount(VertexInputGroup::Basic)!=vid->vab_count) // return(false); //这里基本不太可能,因为CreateRenderable时就会检查值是否一样 vbo_list->Restart(); //Basic组,它所有的VAB信息均来自于Primitive,由vid参数传递进来 { - vbo_list->Add(vid->buffer_list,vid->buffer_offset,vid->binding_count); + vbo_list->Add(vid->vab_list,dd->vab_offset,vid->vab_count); } if(assign_buffer) //L2W/MI分发组 @@ -168,7 +172,7 @@ bool MaterialRenderList::Bind(const VertexInputData *vid,const uint ri_index) // { // count+=joint_id_binding_count; - // if(countGetCount(VertexInputGroup::JointWeight); @@ -188,7 +192,7 @@ bool MaterialRenderList::Bind(const VertexInputData *vid,const uint ri_index) // } //} - //if(count!=binding_count) + //if(count!=vab_count) //{ // //还有没支持的绑定组???? @@ -214,17 +218,24 @@ void MaterialRenderList::Render(RenderItem *ri) if(!ri->vid->Comp(last_vid)) { - Bind(ri->vid,ri->first); last_vid=ri->vid; } - if(last_vid->ib_access) + if(!ri->dd->Comp(last_dd)) { - cmd_buf->DrawIndexed(last_vid->ib_access,ri->count); + BindVAB(ri->vid,ri->dd,ri->first); + last_dd=ri->dd; + } + + if(last_vid->ibo) + { + cmd_buf->BindIBO(ri->vid->ibo,ri->dd->index_start); + cmd_buf->DrawIndexed(ri->dd->index_count, + ri->count); } else { - cmd_buf->Draw(last_vid->vertex_count,ri->count); + cmd_buf->Draw(ri->dd->vertex_count,ri->count); } } diff --git a/src/SceneGraph/Vulkan/VKCommandBufferRender.cpp b/src/SceneGraph/Vulkan/VKCommandBufferRender.cpp index ae5257b7..0f73efe2 100644 --- a/src/SceneGraph/Vulkan/VKCommandBufferRender.cpp +++ b/src/SceneGraph/Vulkan/VKCommandBufferRender.cpp @@ -130,13 +130,13 @@ bool RenderCmdBuffer::BindDescriptorSets(Material *mtl) return(true); } -//void RenderCmdBuffer::BindIBO(const IBAccess *iba) -//{ -// vkCmdBindIndexBuffer( cmd_buf, -// iba->buffer->GetBuffer(), -// iba->start, -// VkIndexType(iba->buffer->GetType())); -//} +void RenderCmdBuffer::BindIBO(IndexBuffer *ibo,VkDeviceSize offset) +{ + vkCmdBindIndexBuffer(cmd_buf, + ibo->GetBuffer(), + offset*ibo->GetStride(), + VkIndexType(ibo->GetType())); +} bool RenderCmdBuffer::BindVBO(Renderable *ri) { @@ -145,18 +145,18 @@ bool RenderCmdBuffer::BindVBO(Renderable *ri) const VertexInputData *vid=ri->GetVertexInputData(); - if(vid->binding_count<=0) + if(vid->vab_count<=0) return(false); - vkCmdBindVertexBuffers(cmd_buf,0,vid->binding_count,vid->buffer_list,vid->buffer_offset); + const DrawData *dd=ri->GetDrawData(); - IndexBuffer *indices_buffer=vid->ib_access->buffer; + if(dd->vertex_count<=0) + return(false); - if(indices_buffer) - vkCmdBindIndexBuffer(cmd_buf, - indices_buffer->GetBuffer(), - vid->ib_access->start, - VkIndexType(indices_buffer->GetType())); + vkCmdBindVertexBuffers(cmd_buf,0,vid->vab_count,vid->vab_list,dd->vab_offset); + + if(vid->ibo&&dd->index_count) + BindIBO(vid->ibo,dd->index_start); return(true); } @@ -185,23 +185,31 @@ void RenderCmdBuffer::DrawIndexedIndirect( VkBuffer buffer, vkCmdDrawIndexedIndirect(cmd_buf,buffer,offset+i*stride,1,stride); } -void RenderCmdBuffer::Draw(const VertexInputData *vid) +void RenderCmdBuffer::Draw(const VertexInputData *vid,const DrawData *dd) { - if (vid->ib_access->buffer) - DrawIndexed(vid->ib_access->count); + if(!vid||!dd) + return; + + if (vid->ibo) + DrawIndexed(dd->index_count); else - Draw(vid->vertex_count); + Draw(dd->vertex_count); } -void RenderCmdBuffer::DrawIndexed(const IBAccess *iba,const uint32_t instance_count) -{ - if(!iba||instance_count<=0)return; - - vkCmdBindIndexBuffer(cmd_buf, - iba->buffer->GetBuffer(), - iba->start*iba->buffer->GetStride(), - VkIndexType(iba->buffer->GetType())); - - vkCmdDrawIndexed(cmd_buf,iba->count,instance_count,0,0,0); -} +//void RenderCmdBuffer::DrawIndexed(const IBAccess *iba,const uint32_t instance_count) +//{ +// if(!iba||instance_count<=0)return; +// +// vkCmdBindIndexBuffer(cmd_buf, +// iba->buffer->GetBuffer(), +// iba->start*iba->buffer->GetStride(), +// VkIndexType(iba->buffer->GetType())); +// +// vkCmdDrawIndexed(cmd_buf, +// iba->count, +// instance_count, +// 0, //first index +// 0, //vertex offset +// 0); //first instance +//} VK_NAMESPACE_END diff --git a/src/SceneGraph/Vulkan/VKDescriptorSet.cpp b/src/SceneGraph/Vulkan/VKDescriptorSet.cpp index f5df71e6..f5e9b53e 100644 --- a/src/SceneGraph/Vulkan/VKDescriptorSet.cpp +++ b/src/SceneGraph/Vulkan/VKDescriptorSet.cpp @@ -69,7 +69,7 @@ namespace void DescriptorSet::Clear() { - buffer_list.Clear(); + vab_list.Clear(); image_list.Clear(); wds_list.Clear(); binded_sets.Clear(); @@ -101,7 +101,7 @@ bool DescriptorSet::BindUBO(const int binding,const DeviceBuffer *buf,const VkDe DescriptorBufferInfo *buf_info=new DescriptorBufferInfo(buf,offset,range); - buffer_list.Add(buf_info); + vab_list.Add(buf_info); const VkDescriptorType desc_type=dynamic?VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; @@ -137,7 +137,7 @@ bool DescriptorSet::BindSSBO(const int binding,const DeviceBuffer *buf,const VkD DescriptorBufferInfo *buf_info=new DescriptorBufferInfo(buf,offset,range); - buffer_list.Add(buf_info); + vab_list.Add(buf_info); const VkDescriptorType desc_type=dynamic?VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:VK_DESCRIPTOR_TYPE_STORAGE_BUFFER; diff --git a/src/SceneGraph/Vulkan/VKDeviceMaterial.cpp b/src/SceneGraph/Vulkan/VKDeviceMaterial.cpp index 92772d5c..53eacc6d 100644 --- a/src/SceneGraph/Vulkan/VKDeviceMaterial.cpp +++ b/src/SceneGraph/Vulkan/VKDeviceMaterial.cpp @@ -18,9 +18,9 @@ namespace { RANGE_CHECK_RETURN_NULLPTR(type); - const uint32_t binding_count=pld->binding_count[size_t(type)]; + const uint32_t vab_count=pld->vab_count[size_t(type)]; - if(!binding_count) + if(!vab_count) return(nullptr); DescriptorSetAllocateInfo alloc_info; @@ -34,7 +34,7 @@ namespace if(vkAllocateDescriptorSets(device,&alloc_info,&desc_set)!=VK_SUCCESS) return(nullptr); - return(new DescriptorSet(device,binding_count,pld->pipeline_layout,desc_set)); + return(new DescriptorSet(device,vab_count,pld->pipeline_layout,desc_set)); } }//namespace diff --git a/src/SceneGraph/Vulkan/VKMaterial.cpp b/src/SceneGraph/Vulkan/VKMaterial.cpp index 794f1fa6..0772afec 100644 --- a/src/SceneGraph/Vulkan/VKMaterial.cpp +++ b/src/SceneGraph/Vulkan/VKMaterial.cpp @@ -13,7 +13,7 @@ Material::Material(const AnsiString &n) { name=n; - vertex_input=nullptr; + vertex_input_data=nullptr; shader_maps=new ShaderModuleMap; desc_manager=nullptr; pipeline_layout_data=nullptr; @@ -28,7 +28,7 @@ Material::~Material() { SAFE_CLEAR(mi_data_manager); - ReleaseVertexInput(vertex_input); + ReleaseVertexInput(vertex_input_data); delete shader_maps; //不用SAFE_CLEAR是因为这个一定会有 SAFE_CLEAR(desc_manager); SAFE_CLEAR(pipeline_layout_data); @@ -49,22 +49,22 @@ const bool Material::hasSet(const DescriptorSetType &dst)const const VIL *Material::GetDefaultVIL()const { - return vertex_input->GetDefaultVIL(); + return vertex_input_data->GetDefaultVIL(); } VIL *Material::CreateVIL(const VILConfig *format_map) { - return vertex_input->CreateVIL(format_map); + return vertex_input_data->CreateVIL(format_map); } bool Material::Release(VIL *vil) { - return vertex_input->Release(vil); + return vertex_input_data->Release(vil); } const uint Material::GetVILCount() { - return vertex_input->GetInstanceCount(); + return vertex_input_data->GetInstanceCount(); } bool Material::BindUBO(const DescriptorSetType &type,const AnsiString &name,DeviceBuffer *ubo,bool dynamic) diff --git a/src/SceneGraph/Vulkan/VKPipelineLayoutData.cpp b/src/SceneGraph/Vulkan/VKPipelineLayoutData.cpp index 12a471a7..40ddfdd0 100644 --- a/src/SceneGraph/Vulkan/VKPipelineLayoutData.cpp +++ b/src/SceneGraph/Vulkan/VKPipelineLayoutData.cpp @@ -26,7 +26,7 @@ PipelineLayoutData *GPUDevice::CreatePipelineLayoutData(const MaterialDescriptor return(nullptr); } - pld->binding_count[i]=dslci->bindingCount; + pld->vab_count[i]=dslci->bindingCount; pld->fin_dsl[pld->fin_dsl_count]=pld->layouts[i]; ++pld->fin_dsl_count; diff --git a/src/SceneGraph/Vulkan/VKPipelineLayoutData.h b/src/SceneGraph/Vulkan/VKPipelineLayoutData.h index 02a5b5ec..b2310dbc 100644 --- a/src/SceneGraph/Vulkan/VKPipelineLayoutData.h +++ b/src/SceneGraph/Vulkan/VKPipelineLayoutData.h @@ -9,7 +9,7 @@ struct PipelineLayoutData { VkDevice device; - int binding_count[DESCRIPTOR_SET_TYPE_COUNT]; + int vab_count[DESCRIPTOR_SET_TYPE_COUNT]; VkDescriptorSetLayout layouts[DESCRIPTOR_SET_TYPE_COUNT]; VkDescriptorSetLayout fin_dsl[DESCRIPTOR_SET_TYPE_COUNT]; diff --git a/src/SceneGraph/Vulkan/VKPrimitive.cpp b/src/SceneGraph/Vulkan/VKPrimitive.cpp index c9161519..d754fb17 100644 --- a/src/SceneGraph/Vulkan/VKPrimitive.cpp +++ b/src/SceneGraph/Vulkan/VKPrimitive.cpp @@ -61,4 +61,9 @@ IBAccess *Primitive::GetIBAccess() return prim_data->GetIBAccess(); } +IndexBuffer *Primitive::GetIBO() +{ + return prim_data->GetIBO(); +} + VK_NAMESPACE_END diff --git a/src/SceneGraph/Vulkan/VKPrimitiveData.h b/src/SceneGraph/Vulkan/VKPrimitiveData.h index 83beb0fd..283ba2f2 100644 --- a/src/SceneGraph/Vulkan/VKPrimitiveData.h +++ b/src/SceneGraph/Vulkan/VKPrimitiveData.h @@ -38,7 +38,9 @@ public: const int GetVABIndex (const AnsiString &name)const; VABAccess * GetVABAccess (const int index); VABAccess * GetVABAccess (const AnsiString &name); + IBAccess * GetIBAccess (){return &ib_access;} + IndexBuffer * GetIBO (){return ib_access.buffer;} public: diff --git a/src/SceneGraph/Vulkan/VKRenderResourceMaterial.cpp b/src/SceneGraph/Vulkan/VKRenderResourceMaterial.cpp index 295e6241..f16abf34 100644 --- a/src/SceneGraph/Vulkan/VKRenderResourceMaterial.cpp +++ b/src/SceneGraph/Vulkan/VKRenderResourceMaterial.cpp @@ -124,7 +124,7 @@ Material *RenderResource::CreateMaterial(const mtl::MaterialCreateInfo *mci) ShaderCreateInfoVertex *vert=mci->GetVS(); if(vert) - mtl->vertex_input=GetVertexInput(vert->sdm->GetShaderStageIO().input); + mtl->vertex_input_data=GetVertexInput(vert->sdm->GetShaderStageIO().input); } { diff --git a/src/SceneGraph/Vulkan/VKRenderable.cpp b/src/SceneGraph/Vulkan/VKRenderable.cpp index 870d6c3e..280fd100 100644 --- a/src/SceneGraph/Vulkan/VKRenderable.cpp +++ b/src/SceneGraph/Vulkan/VKRenderable.cpp @@ -3,46 +3,92 @@ #include #include #include +#include #include VK_NAMESPACE_BEGIN VertexInputData::VertexInputData(const uint32_t c,const uint32_t vc,const IBAccess *iba) { - binding_count=c; + vab_count=c; - buffer_list=new VkBuffer[binding_count]; - buffer_offset=new VkDeviceSize[binding_count]; + vab_list=hgl_zero_new(vab_count); - vertex_count=vc; - - if(!iba||!iba->buffer) - ib_access=nullptr; + if(iba&&iba->buffer) + ibo=iba->buffer; else - ib_access=iba; + ibo=nullptr; } VertexInputData::~VertexInputData() { - delete[] buffer_list; - delete[] buffer_offset; + delete[] vab_list; } -Renderable::Renderable(Primitive *r,MaterialInstance *mi,Pipeline *p,VertexInputData *vi) +const bool VertexInputData::Comp(const VertexInputData *vid)const +{ + if(!vid)return(false); + + if(vab_count!=vid->vab_count)return(false); + + for(uint32_t i=0;ivab_list[i])return(false); + } + + if(ibo!=vid->ibo)return(false); + + return(true); +} + +Renderable::Renderable(Primitive *r,MaterialInstance *mi,Pipeline *p,VertexInputData *vid,DrawData *dd) { primitive=r; pipeline=p; mat_inst=mi; - vertex_input=vi; + vertex_input_data=vid; + draw_data=dd; +} + +DrawData::DrawData(const uint32_t bc,const VkDeviceSize vc,const IBAccess *iba) +{ + vab_count=bc; + + vab_offset=new VkDeviceSize[vab_count]; + + vertex_count=vc; + + if(iba&&iba->buffer) + { + index_start=iba->start; + index_count=iba->count; + } +} + +DrawData::~DrawData() +{ + delete[] vab_offset; +} + +const bool DrawData::Comp(const DrawData *dd)const +{ + if(!dd)return(false); + + if(vab_count!=dd->vab_count)return(false); + + for(uint i=0;ivab_offset[i])return(false); + } + + if(vertex_count!=dd->vertex_count)return(false); + + if(index_start!=dd->index_start)return(false); + if(index_count!=dd->index_count)return(false); + + return(true); } -Renderable::~Renderable() -{ - //需要在这里添加删除pipeline/desc_sets/primitive引用计数的代码 - - delete vertex_input; -} - Renderable *CreateRenderable(Primitive *prim,MaterialInstance *mi,Pipeline *p) { if(!prim||!mi||!p)return(nullptr); @@ -58,7 +104,10 @@ Renderable *CreateRenderable(Primitive *prim,MaterialInstance *mi,Pipeline *p) return(nullptr); } - VertexInputData *vid=new VertexInputData(input_count,prim->GetVertexCount(),prim->GetIBAccess()); + const IBAccess *iba=prim->GetIBAccess(); + + VertexInputData *vid=new VertexInputData(input_count,prim->GetVertexCount(),iba); + DrawData *dd=new DrawData(input_count,prim->GetVertexCount(),iba); const VertexInputFormat *vif=vil->GetVIFList(VertexInputGroup::Basic); VABAccess *vab_access; @@ -96,11 +145,11 @@ Renderable *CreateRenderable(Primitive *prim,MaterialInstance *mi,Pipeline *p) return(nullptr); } - vid->buffer_offset[i]=vab_access->start*vif->stride; - vid->buffer_list[i]=vab_access->vab->GetBuffer(); + dd->vab_offset[i]=vab_access->start*vif->stride; + vid->vab_list[i]=vab_access->vab->GetBuffer(); ++vif; } - return(new Renderable(prim,mi,p,vid)); + return(new Renderable(prim,mi,p,vid,dd)); } VK_NAMESPACE_END