diff --git a/inc/hgl/graph/VK.h b/inc/hgl/graph/VK.h index 0f524435..32a5c1ab 100644 --- a/inc/hgl/graph/VK.h +++ b/inc/hgl/graph/VK.h @@ -56,7 +56,7 @@ class GPUSemaphore; enum class DescriptorSetType { - //设计使其对应shader中的sets + //设计使其对应shader中的set Global=0, ///<全局参数(如太阳光等) Material, ///<材质中永远不变的参数 @@ -67,6 +67,8 @@ enum class DescriptorSetType ENUM_CLASS_RANGE(Global,Renderable) };// +const DescriptorSetType CheckDescriptorSetType(const char *str); + class DescriptorSetLayoutCreater; class DescriptorSets; diff --git a/inc/hgl/graph/VKMaterialParameters.h b/inc/hgl/graph/VKMaterialParameters.h index f35d3991..864d7c24 100644 --- a/inc/hgl/graph/VKMaterialParameters.h +++ b/inc/hgl/graph/VKMaterialParameters.h @@ -21,7 +21,7 @@ private: public: - const DescriptorSetType GetType (){return ds_type;} + const DescriptorSetType GetType (){return ds_type;} DescriptorSets * GetDescriptorSet (){return descriptor_sets;} const VkDescriptorSet GetVkDescriptorSet ()const{return descriptor_sets->GetDescriptorSet();} diff --git a/inc/hgl/graph/shader/ShaderResource.h b/inc/hgl/graph/shader/ShaderResource.h index f7493d27..287289e9 100644 --- a/inc/hgl/graph/shader/ShaderResource.h +++ b/inc/hgl/graph/shader/ShaderResource.h @@ -2,8 +2,7 @@ #include #include #include -#include -#include +#include VK_NAMESPACE_BEGIN @@ -26,6 +25,7 @@ using ShaderStageList =ObjectList; struct ShaderDescriptor { char name[128]; + DescriptorSetType type; uint32_t set; uint32_t binding; }; diff --git a/src/SceneGraph/Vulkan/VKDescriptorSetLayoutCreater.cpp b/src/SceneGraph/Vulkan/VKDescriptorSetLayoutCreater.cpp index 22afaa3e..c5870aef 100644 --- a/src/SceneGraph/Vulkan/VKDescriptorSetLayoutCreater.cpp +++ b/src/SceneGraph/Vulkan/VKDescriptorSetLayoutCreater.cpp @@ -34,9 +34,9 @@ void DescriptorSetLayoutCreater::Bind(const ShaderDescriptorList *sd_list,VkDesc for(const ShaderDescriptor &sd:*sd_list) { - all_set.Add(sd.set); + all_set.Add(sd.type); - ++binding_count[sd.set]; + ++binding_count[(size_t)sd.type]; } ENUM_CLASS_FOR(DescriptorSetType,int,i) @@ -53,17 +53,17 @@ void DescriptorSetLayoutCreater::Bind(const ShaderDescriptorList *sd_list,VkDesc //重复的绑定点是有可能存在的,比如CameraInfo在vs/fs中同时存在 if(!all_binding.IsMember(sd.binding)) - { - p[sd.set]->binding = sd.binding; - p[sd.set]->descriptorType = desc_type; - p[sd.set]->descriptorCount = 1; - p[sd.set]->stageFlags = stageFlags; - p[sd.set]->pImmutableSamplers = nullptr; + { + p[(size_t)sd.type]->binding = sd.binding; + p[(size_t)sd.type]->descriptorType = desc_type; + p[(size_t)sd.type]->descriptorCount = 1; + p[(size_t)sd.type]->stageFlags = stageFlags; + p[(size_t)sd.type]->pImmutableSamplers = nullptr; all_binding.Add(sd.binding); - ++p[sd.set]; - ++fin_count[sd.set]; + ++p[(size_t)sd.type]; + ++fin_count[(size_t)sd.type]; } } diff --git a/src/SceneGraph/Vulkan/VKDescriptorSetLayoutCreater.h b/src/SceneGraph/Vulkan/VKDescriptorSetLayoutCreater.h index cb140ad4..cb2faef1 100644 --- a/src/SceneGraph/Vulkan/VKDescriptorSetLayoutCreater.h +++ b/src/SceneGraph/Vulkan/VKDescriptorSetLayoutCreater.h @@ -15,7 +15,7 @@ class DescriptorSetLayoutCreater VkDevice device; VkDescriptorPool pool; - Sets all_set; + Sets all_set; Sets all_binding; struct ShaderDescriptorSet diff --git a/src/SceneGraph/shader/ShaderResource.cpp b/src/SceneGraph/shader/ShaderResource.cpp index 40f86ca0..e6d43b8c 100644 --- a/src/SceneGraph/shader/ShaderResource.cpp +++ b/src/SceneGraph/shader/ShaderResource.cpp @@ -5,6 +5,18 @@ VK_NAMESPACE_BEGIN + const DescriptorSetType CheckDescriptorSetType(const char *str) + { + if(str[1]=='_') + { + if(str[0]=='m')return DescriptorSetType::Material; + if(str[0]=='g')return DescriptorSetType::Global; + if(str[0]=='r')return DescriptorSetType::Renderable; + } + + return DescriptorSetType::Value; + } + #define AccessByPointer(data,type) *(type *)data;data+=sizeof(type); namespace @@ -81,6 +93,8 @@ VK_NAMESPACE_BEGIN memcpy(sd->name,(char *)data,str_len); sd->name[str_len]=0; data+=str_len; + + sd->type=CheckDescriptorSetType(sd->name); } return data;