use type instead of set in ShaderDescriptorSet. example "texture rect" can run OK.

This commit is contained in:
hyzboy 2021-06-22 17:39:15 +08:00
parent 2b70ee07c8
commit 713e76215c
6 changed files with 31 additions and 15 deletions

View File

@ -56,7 +56,7 @@ class GPUSemaphore;
enum class DescriptorSetType enum class DescriptorSetType
{ {
//设计使其对应shader中的sets //设计使其对应shader中的set
Global=0, ///<全局参数(如太阳光等) Global=0, ///<全局参数(如太阳光等)
Material, ///<材质中永远不变的参数 Material, ///<材质中永远不变的参数
@ -67,6 +67,8 @@ enum class DescriptorSetType
ENUM_CLASS_RANGE(Global,Renderable) ENUM_CLASS_RANGE(Global,Renderable)
};// };//
const DescriptorSetType CheckDescriptorSetType(const char *str);
class DescriptorSetLayoutCreater; class DescriptorSetLayoutCreater;
class DescriptorSets; class DescriptorSets;

View File

@ -2,8 +2,7 @@
#include<hgl/type/String.h> #include<hgl/type/String.h>
#include<hgl/type/List.h> #include<hgl/type/List.h>
#include<hgl/type/StringList.h> #include<hgl/type/StringList.h>
#include<hgl/graph/VKFormat.h> #include<hgl/graph/VK.h>
#include<hgl/graph/VKStruct.h>
VK_NAMESPACE_BEGIN VK_NAMESPACE_BEGIN
@ -26,6 +25,7 @@ using ShaderStageList =ObjectList<ShaderStage>;
struct ShaderDescriptor struct ShaderDescriptor
{ {
char name[128]; char name[128];
DescriptorSetType type;
uint32_t set; uint32_t set;
uint32_t binding; uint32_t binding;
}; };

View File

@ -34,9 +34,9 @@ void DescriptorSetLayoutCreater::Bind(const ShaderDescriptorList *sd_list,VkDesc
for(const ShaderDescriptor &sd:*sd_list) 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) ENUM_CLASS_FOR(DescriptorSetType,int,i)
@ -54,16 +54,16 @@ void DescriptorSetLayoutCreater::Bind(const ShaderDescriptorList *sd_list,VkDesc
if(!all_binding.IsMember(sd.binding)) if(!all_binding.IsMember(sd.binding))
{ {
p[sd.set]->binding = sd.binding; p[(size_t)sd.type]->binding = sd.binding;
p[sd.set]->descriptorType = desc_type; p[(size_t)sd.type]->descriptorType = desc_type;
p[sd.set]->descriptorCount = 1; p[(size_t)sd.type]->descriptorCount = 1;
p[sd.set]->stageFlags = stageFlags; p[(size_t)sd.type]->stageFlags = stageFlags;
p[sd.set]->pImmutableSamplers = nullptr; p[(size_t)sd.type]->pImmutableSamplers = nullptr;
all_binding.Add(sd.binding); all_binding.Add(sd.binding);
++p[sd.set]; ++p[(size_t)sd.type];
++fin_count[sd.set]; ++fin_count[(size_t)sd.type];
} }
} }

View File

@ -15,7 +15,7 @@ class DescriptorSetLayoutCreater
VkDevice device; VkDevice device;
VkDescriptorPool pool; VkDescriptorPool pool;
Sets<uint32_t> all_set; Sets<DescriptorSetType> all_set;
Sets<uint32_t> all_binding; Sets<uint32_t> all_binding;
struct ShaderDescriptorSet struct ShaderDescriptorSet

View File

@ -5,6 +5,18 @@
VK_NAMESPACE_BEGIN 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); #define AccessByPointer(data,type) *(type *)data;data+=sizeof(type);
namespace namespace
@ -81,6 +93,8 @@ VK_NAMESPACE_BEGIN
memcpy(sd->name,(char *)data,str_len); memcpy(sd->name,(char *)data,str_len);
sd->name[str_len]=0; sd->name[str_len]=0;
data+=str_len; data+=str_len;
sd->type=CheckDescriptorSetType(sd->name);
} }
return data; return data;