diff --git a/CMUtil b/CMUtil index d789bc24..953ecf80 160000 --- a/CMUtil +++ b/CMUtil @@ -1 +1 @@ -Subproject commit d789bc24237c08028d53467d34a15fe18b92414e +Subproject commit 953ecf8079845ddfd8d31d62c945c9a5206b2199 diff --git a/inc/hgl/graph/VK.h b/inc/hgl/graph/VK.h index c456b84e..d489497f 100644 --- a/inc/hgl/graph/VK.h +++ b/inc/hgl/graph/VK.h @@ -26,7 +26,10 @@ constexpr size_t VK_DESCRIPTOR_TYPE_RANGE_SIZE=VK_DESCRIPTOR_TYPE_END_RANGE-VK_D #endif//VK_DESCRIPTOR_TYPE_RANGE_SIZE using CharPointerList=hgl::List; -using BindingMapping=Map; +using BindingMapping =Map; + +using BindingMap =Map; +using BindingMapArray =BindingMap[VK_DESCRIPTOR_TYPE_RANGE_SIZE]; class VulkanInstance; class GPUPhysicalDevice; diff --git a/inc/hgl/graph/VKDescriptorBindingManage.h b/inc/hgl/graph/VKDescriptorBindingManage.h index 0f920859..07c4cc3b 100644 --- a/inc/hgl/graph/VKDescriptorBindingManage.h +++ b/inc/hgl/graph/VKDescriptorBindingManage.h @@ -1,8 +1,9 @@ -#ifndef HGL_GRAPH_DESCRIPTOR_BINDING_MANAGE_INCLUDE +#ifndef HGL_GRAPH_DESCRIPTOR_BINDING_MANAGE_INCLUDE #define HGL_GRAPH_DESCRIPTOR_BINDING_MANAGE_INCLUDE #include #include +#include #include namespace hgl { @@ -11,10 +12,15 @@ namespace hgl class DeviceBuffer; class Texture; class Material; + class MaterialParameters; + /** + * 描述符绑定器
+ * 一般用于注册通用数据,为材质进行自动绑定。 + */ class DescriptorBinding { - DescriptorSetType set_type; + DescriptorSetType set_type; ///<描述符合集类型 Map ubo_map; Map ssbo_map; @@ -93,6 +99,12 @@ namespace hgl texture_map.DeleteByValue(tex); } + private: + + void BindUBO(MaterialParameters *,const BindingMap &); + + public: + bool Bind(Material *); };//class DescriptorBinding }//namespace graph diff --git a/inc/hgl/graph/VKMaterialDescriptorManager.h b/inc/hgl/graph/VKMaterialDescriptorManager.h index 5e420e9b..7a971e87 100644 --- a/inc/hgl/graph/VKMaterialDescriptorManager.h +++ b/inc/hgl/graph/VKMaterialDescriptorManager.h @@ -5,9 +5,6 @@ #include VK_NAMESPACE_BEGIN -using BindingMap=Map; -using BindingMapArray=BindingMap[VK_DESCRIPTOR_TYPE_RANGE_SIZE]; - class MaterialDescriptorManager { UTF8String mtl_name; diff --git a/src/SceneGraph/Vulkan/VKDescriptorBindingManage.cpp b/src/SceneGraph/Vulkan/VKDescriptorBindingManage.cpp index 110608ca..6be023c5 100644 --- a/src/SceneGraph/Vulkan/VKDescriptorBindingManage.cpp +++ b/src/SceneGraph/Vulkan/VKDescriptorBindingManage.cpp @@ -3,6 +3,27 @@ #include VK_NAMESPACE_BEGIN +void DescriptorBinding::BindUBO(MaterialParameters *mp,const BindingMap &binding_map) +{ + DeviceBuffer* buf = nullptr; + + if (binding_map.GetCount() > 0) + { + const auto* dp = binding_map.GetDataList(); + const uint count = binding_map.GetCount(); + + for (uint i = 0; i < count; i++) + { + buf = GetUBO((*dp)->key); + + if (buf) + mp->BindUBO((*dp)->value, buf, false); + + ++dp; + } + } +} + bool DescriptorBinding::Bind(Material *mtl) { if(!mtl) @@ -15,47 +36,13 @@ bool DescriptorBinding::Bind(Material *mtl) const BindingMapArray &bma=mp->GetBindingMap(); - const BindingMap &ubo_bm=bma[VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER]; - const BindingMap &ubo_dynamic_bm=bma[VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC]; - // const BindingMap &ssbo_bm=bma[VK_DESCRIPTOR_TYPE_STORAGE_BUFFER]; // const BindingMap &ssbo_dynamic_bm=bma[VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC]; // const BindingMap &texture_bm=bma[VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER]; - DeviceBuffer *buf=nullptr; - - if(ubo_bm.GetCount()>0) - { - const auto *dp=ubo_bm.GetDataList(); - const uint count=ubo_bm.GetCount(); - - for(uint i=0;ikey); - - if(buf) - mp->BindUBO((*dp)->value,buf,false); - - ++dp; - } - } - - if(ubo_dynamic_bm.GetCount()>0) - { - const auto *dp=ubo_dynamic_bm.GetDataList(); - const uint count=ubo_dynamic_bm.GetCount(); - - for(uint i=0;ikey); - - if(buf) - mp->BindUBO((*dp)->value,buf,true); - - ++dp; - } - } + BindUBO(mp,bma[VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER]); + BindUBO(mp,bma[VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC]); mp->Update(); return(true);