From 015a4d0b8ec86575603a6a1fb5ff8557479e0c1b Mon Sep 17 00:00:00 2001 From: hyzboy Date: Tue, 11 May 2021 20:45:00 +0800 Subject: [PATCH] (WIP) renamed a few values, new SceneTreeToRenderList --- inc/hgl/graph/SceneTreeToRenderList.h | 4 +- inc/hgl/graph/VKArrayBuffer.h | 6 +- inc/hgl/graph/VKDescriptorSets.h | 6 +- inc/hgl/graph/font/TextRenderable.h | 2 +- src/SceneGraph/RenderList.cpp | 5 +- src/SceneGraph/SceneTreeToRenderList.cpp | 95 +++++++++---------- src/SceneGraph/Vulkan/VKDebugOut.cpp | 6 +- .../Vulkan/VKDescriptorSetLayoutCreater.cpp | 8 +- src/SceneGraph/Vulkan/VKRenderResource.cpp | 1 + .../Vulkan/VKRenderableInstance.cpp | 32 ++++++- src/SceneGraph/font/TextRenderable.cpp | 1 + 11 files changed, 95 insertions(+), 71 deletions(-) diff --git a/inc/hgl/graph/SceneTreeToRenderList.h b/inc/hgl/graph/SceneTreeToRenderList.h index c6ef00b9..533e0ea1 100644 --- a/inc/hgl/graph/SceneTreeToRenderList.h +++ b/inc/hgl/graph/SceneTreeToRenderList.h @@ -27,7 +27,7 @@ namespace hgl protected: Camera * camera; - CameraInfo * camera_matrix; + CameraInfo * camera_info; Frustum frustum; protected: @@ -56,7 +56,7 @@ namespace hgl { device=d; camera=nullptr; - camera_matrix=nullptr; + camera_info=nullptr; scene_node_list=nullptr; render_list=nullptr; diff --git a/inc/hgl/graph/VKArrayBuffer.h b/inc/hgl/graph/VKArrayBuffer.h index c0b2a426..4ac8f5f5 100644 --- a/inc/hgl/graph/VKArrayBuffer.h +++ b/inc/hgl/graph/VKArrayBuffer.h @@ -31,10 +31,10 @@ namespace hgl { uint32_t unit_size=sizeof(T); - VKMemoryAllocator *ma=new VKMemoryAllocator(device,buffer_usage_flags); + VKMemoryAllocator *ma=new VKMemoryAllocator(device,buffer_usage_flags); // construct function is going to set AllocUnitSize by minUniformOffsetAlignment MemoryBlock *mb=new MemoryBlock(ma); - uint32_t align_size=ma->GetAllocUnitSize()-1; ///< this value is "min UBO Offset alignment" + const uint32_t align_size=ma->GetAllocUnitSize()-1; // this value is "min UBO Offset alignment" unit_size=(unit_size+align_size)&(~align_size); @@ -62,7 +62,7 @@ namespace hgl T *Map(const uint32 start,const uint32 count) { - return coll->Map(start,count); + return (T *)(coll->Map(start,count)); } };//class GPUArrayBuffer }//namespace graph diff --git a/inc/hgl/graph/VKDescriptorSets.h b/inc/hgl/graph/VKDescriptorSets.h index e97a1b4b..ac05b3b8 100644 --- a/inc/hgl/graph/VKDescriptorSets.h +++ b/inc/hgl/graph/VKDescriptorSets.h @@ -9,7 +9,7 @@ class GPUBuffer; class DescriptorSets { VkDevice device; - int count; + int layout_binding_count; VkDescriptorSet desc_set; const BindingMapping *index_by_binding; @@ -26,7 +26,7 @@ private: DescriptorSets(VkDevice dev,const int c,VkPipelineLayout pl,VkDescriptorSet ds,const BindingMapping *bi):index_by_binding(bi) { device=dev; - count=c; + layout_binding_count=c; desc_set=ds; pipeline_layout=pl; } @@ -35,7 +35,7 @@ public: ~DescriptorSets()=default; - const uint32_t GetCount ()const{return count;} + const uint32_t GetCount ()const{return layout_binding_count;} const VkDescriptorSet * GetDescriptorSets ()const{return &desc_set;} const VkPipelineLayout GetPipelineLayout ()const{return pipeline_layout;} diff --git a/inc/hgl/graph/font/TextRenderable.h b/inc/hgl/graph/font/TextRenderable.h index 66a21b6d..cddad0de 100644 --- a/inc/hgl/graph/font/TextRenderable.h +++ b/inc/hgl/graph/font/TextRenderable.h @@ -14,7 +14,7 @@ namespace hgl GPUDevice * device; Material * mtl; - uint max_count; ///<缓冲区最大容量 + uint max_count; ///<缓冲区最大容量 VAB * vab_position; VAB * vab_tex_coord; diff --git a/src/SceneGraph/RenderList.cpp b/src/SceneGraph/RenderList.cpp index 02a6ada5..ec4cf94d 100644 --- a/src/SceneGraph/RenderList.cpp +++ b/src/SceneGraph/RenderList.cpp @@ -15,7 +15,6 @@ namespace hgl { constexpr size_t MVPMatrixBytes=sizeof(MVPMatrix); - //bool FrustumClipFilter(const SceneNode *node,void *fc) //{ // if(!node||!fc)return(false); @@ -57,7 +56,7 @@ namespace hgl scene_node_list.Add(node); } - void RenderList::End(CameraInfo *camera_matrix) + void RenderList::End(CameraInfo *camera_info) { //清0计数器 uint32_t mvp_count=0; //local to world矩阵总数量 @@ -80,7 +79,7 @@ namespace hgl if(!l2w.IsIdentity()) { - mp->Set(l2w,camera_matrix->vp); + mp->Set(l2w,camera_info->vp); ++mp; *op=mvp_count*MVPMatrixBytes; diff --git a/src/SceneGraph/SceneTreeToRenderList.cpp b/src/SceneGraph/SceneTreeToRenderList.cpp index bc21512c..5acb1ad2 100644 --- a/src/SceneGraph/SceneTreeToRenderList.cpp +++ b/src/SceneGraph/SceneTreeToRenderList.cpp @@ -17,69 +17,68 @@ namespace hgl return( length_squared(obj_one->GetCenter(),camera->pos)- length_squared(obj_two->GetCenter(),camera->pos)); } - } - bool SceneTreeToRenderList::InFrustum(const SceneNode *,void *) - { - return(true); - } + //bool SceneTreeToRenderList::InFrustum(const SceneNode *,void *) + //{ + // return(true); + //} - bool SceneTreeToRenderList::Begin() - { - if(!scene_node_list) - scene_node_list=new SceneNodeList; + //bool SceneTreeToRenderList::Begin() + //{ + // if(!scene_node_list) + // scene_node_list=new SceneNodeList; - scene_node_list->ClearData(); + // scene_node_list->ClearData(); - pipeline_sets.ClearData(); - material_sets.ClearData(); - mat_instance_sets.ClearData(); + // pipeline_sets.ClearData(); + // material_sets.ClearData(); + // mat_instance_sets.ClearData(); - return(true); - } + // return(true); + //} - /** - * 理论上讲,我们需要按以下顺序排序 - * - * for(material) - * for(pipeline) - * for(material_instance) - * for(vbo) - */ + ///** + //* 理论上讲,我们需要按以下顺序排序 + //* + //* for(material) + //* for(pipeline) + //* for(material_instance) + //* for(vbo) + //*/ - bool SceneTreeToRenderList::End() - { - } + //bool SceneTreeToRenderList::End() + //{ + //} - bool SceneTreeToRenderList::Expend(SceneNode *sn) - { - if(!sn)return(false); + //bool SceneTreeToRenderList::Expend(SceneNode *sn) + //{ + // if(!sn)return(false); - if(sn->renderable_instances) - scene_node_list->Add(sn); + // if(sn->renderable_instances) + // scene_node_list->Add(sn); - for(SceneNode *sub:sn->SubNode) - Expend(sub); + // for(SceneNode *sub:sn->SubNode) + // Expend(sub); - return(true); - } + // return(true); + //} - bool SceneTreeToRenderList::Expend(RenderList *rl,Camera *c,SceneNode *sn) - { - if(!device)return(false); - if(!rl||!c||sn)return(false); + //bool SceneTreeToRenderList::Expend(RenderList *rl,Camera *c,SceneNode *sn) + //{ + // if(!device)return(false); + // if(!rl||!c||sn)return(false); - camera=c; - camera->Refresh(); - camera_matrix=&(camera->matrix); + // camera=c; + // camera->Refresh(); + // camera_info=&(camera->matrix); - //Frustum f; + // //Frustum f; - render_list=rl; + // render_list=rl; - Begin(); - Expend(sn); - End(); - } + // Begin(); + // Expend(sn); + // End(); + //} }//namespace graph }//namespace hgl diff --git a/src/SceneGraph/Vulkan/VKDebugOut.cpp b/src/SceneGraph/Vulkan/VKDebugOut.cpp index 76fcd327..2c0f9e21 100644 --- a/src/SceneGraph/Vulkan/VKDebugOut.cpp +++ b/src/SceneGraph/Vulkan/VKDebugOut.cpp @@ -201,13 +201,11 @@ bool VKDebugOut::Init(VkInstance i) create_info.pNext =nullptr; create_info.flags =0; - create_info.messageSeverity =VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT + create_info.messageSeverity =VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT |VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT |VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT; - create_info.messageType =VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT - |VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT - |VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT; + create_info.messageType =VK_DEBUG_UTILS_MESSAGE_TYPE_FLAG_BITS_MAX_ENUM_EXT; create_info.pfnUserCallback =vulkan_debug_utils_callback; create_info.pUserData =this; diff --git a/src/SceneGraph/Vulkan/VKDescriptorSetLayoutCreater.cpp b/src/SceneGraph/Vulkan/VKDescriptorSetLayoutCreater.cpp index 2c06c0ac..96590308 100644 --- a/src/SceneGraph/Vulkan/VKDescriptorSetLayoutCreater.cpp +++ b/src/SceneGraph/Vulkan/VKDescriptorSetLayoutCreater.cpp @@ -38,19 +38,19 @@ void DescriptorSetLayoutCreater::Bind(const uint32_t binding,VkDescriptorType de index_by_binding.Add(binding,index); } -void DescriptorSetLayoutCreater::Bind(const uint32_t *binding,const uint32_t count,VkDescriptorType desc_type,VkShaderStageFlagBits stageFlags) +void DescriptorSetLayoutCreater::Bind(const uint32_t *binding,const uint32_t binding_count,VkDescriptorType desc_type,VkShaderStageFlagBits stageFlags) { - if(!binding||count<=0)return; + if(!binding||binding_count<=0)return; const uint old_count=layout_binding_list.GetCount(); - layout_binding_list.PreMalloc(old_count+count); + layout_binding_list.PreMalloc(old_count+binding_count); VkDescriptorSetLayoutBinding *p=layout_binding_list.GetData()+old_count; uint fin_count=0; - for(uint i=old_count;i #include #include +#include VK_NAMESPACE_BEGIN VAB *RenderResource::CreateVAB(VkFormat format,uint32_t count,const void *data,SharingMode sharing_mode) diff --git a/src/SceneGraph/Vulkan/VKRenderableInstance.cpp b/src/SceneGraph/Vulkan/VKRenderableInstance.cpp index ba229d89..a0607ada 100644 --- a/src/SceneGraph/Vulkan/VKRenderableInstance.cpp +++ b/src/SceneGraph/Vulkan/VKRenderableInstance.cpp @@ -1,6 +1,7 @@ #include #include #include +#include VK_NAMESPACE_BEGIN RenderableInstance::RenderableInstance(Renderable *r,MaterialInstance *mi,Pipeline *p,const uint32_t count,VkBuffer *bl,VkDeviceSize *bs) @@ -35,7 +36,11 @@ RenderableInstance *CreateRenderableInstance(Renderable *r,MaterialInstance *mi, const int input_count=ssl.GetCount(); if(r->GetBufferCount()GetName()); + return(nullptr); + } AutoDeleteArray buffer_list(input_count); AutoDeleteArray buffer_size(input_count); @@ -53,10 +58,31 @@ RenderableInstance *CreateRenderableInstance(Renderable *r,MaterialInstance *mi, vab=r->GetVAB((*ss)->name,buffer_size+i); - if(!vab)return(nullptr); + if(!vab) + { + LOG_ERROR("[FATAL ERROR] can't find VAB \""+(*ss)->name+"\" in Material: "+mtl->GetName()); + return(nullptr); + } - if(vab->GetFormat()!=attr->format)return(nullptr); - if(vab->GetStride()!=desc->stride)return(nullptr); + if(vab->GetFormat()!=attr->format) + { + LOG_ERROR( "[FATAL ERROR] VAB \""+(*ss)->name+ + UTF8String("\" format can't match Renderable, Material(")+mtl->GetName()+ + UTF8String(") Format(")+GetVulkanFormatName(attr->format)+ + UTF8String("), VAB Format(")+GetVulkanFormatName(vab->GetFormat())+ + ")"); + return(nullptr); + } + + if(vab->GetStride()!=desc->stride) + { + LOG_ERROR( "[FATAL ERROR] VAB \""+(*ss)->name+ + UTF8String("\" stride can't match Renderable, Material(")+mtl->GetName()+ + UTF8String(") stride(")+UTF8String::valueOf(desc->stride)+ + UTF8String("), VAB stride(")+UTF8String::valueOf(vab->GetStride())+ + ")"); + return(nullptr); + } buffer_list[i]=vab->GetBuffer(); diff --git a/src/SceneGraph/font/TextRenderable.cpp b/src/SceneGraph/font/TextRenderable.cpp index 58a100de..857c7b80 100644 --- a/src/SceneGraph/font/TextRenderable.cpp +++ b/src/SceneGraph/font/TextRenderable.cpp @@ -1,6 +1,7 @@ #include #include #include +#include namespace hgl {