refactor ShaderDescriptorList.
This commit is contained in:
parent
983202966e
commit
0ad2c96645
2
CMUtil
2
CMUtil
@ -1 +1 @@
|
||||
Subproject commit 863293fbc8e900688773f3724a53f1c99f67c6fd
|
||||
Subproject commit 9982ca25af1a52981054af8636dfc5f3e2ea59c9
|
@ -44,13 +44,15 @@ using ShaderStageList =ObjectList<ShaderStage>;
|
||||
using DescriptorSetList =List<uint32_t>;
|
||||
using DescriptorBindingList =List<uint32_t>;
|
||||
|
||||
struct ShaderDescriptorList
|
||||
struct ShaderDescriptor
|
||||
{
|
||||
AnsiStringList name_list;
|
||||
DescriptorSetList set_list;
|
||||
DescriptorBindingList binding_list;
|
||||
char name[128];
|
||||
uint32_t set;
|
||||
uint32_t binding;
|
||||
};
|
||||
|
||||
using ShaderDescriptorList=List<ShaderDescriptor>;
|
||||
|
||||
#ifndef VK_DESCRIPTOR_TYPE_BEGIN_RANGE
|
||||
constexpr size_t VK_DESCRIPTOR_TYPE_BEGIN_RANGE=VK_DESCRIPTOR_TYPE_SAMPLER;
|
||||
#endif//VK_DESCRIPTOR_TYPE_BEGIN_RANGE
|
||||
@ -109,13 +111,13 @@ public:
|
||||
ShaderDescriptorList &GetSampler(){return descriptor_list[VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER];}
|
||||
|
||||
const int GetBinding (VkDescriptorType desc_type,const AnsiString &name)const;
|
||||
const DescriptorBindingList * GetBindingList (VkDescriptorType desc_type)const
|
||||
{
|
||||
if(desc_type<VK_DESCRIPTOR_TYPE_BEGIN_RANGE
|
||||
||desc_type>VK_DESCRIPTOR_TYPE_END_RANGE)return nullptr;
|
||||
//const DescriptorBindingList * GetBindingList (VkDescriptorType desc_type)const
|
||||
//{
|
||||
// if(desc_type<VK_DESCRIPTOR_TYPE_BEGIN_RANGE
|
||||
// ||desc_type>VK_DESCRIPTOR_TYPE_END_RANGE)return nullptr;
|
||||
|
||||
return &(descriptor_list[desc_type].binding_list);
|
||||
}
|
||||
// return &(descriptor_list[desc_type].binding_list);
|
||||
//}
|
||||
};//class ShaderResource
|
||||
|
||||
ShaderResource *LoadShaderResource(const uint8 *origin_filedata,const int64 filesize,bool include_file_header);
|
||||
|
@ -17,30 +17,33 @@ DescriptorSetLayoutCreater::~DescriptorSetLayoutCreater()
|
||||
vkDestroyDescriptorSetLayout(device,dsl,nullptr);
|
||||
}
|
||||
|
||||
void DescriptorSetLayoutCreater::Bind(const uint32_t binding,VkDescriptorType desc_type,VkShaderStageFlagBits stageFlags)
|
||||
//单个版本,暂时用不到
|
||||
//void DescriptorSetLayoutCreater::Bind(const uint32_t binding,VkDescriptorType desc_type,VkShaderStageFlagBits stageFlags)
|
||||
//{
|
||||
// if(index_by_binding.KeyExist(binding))
|
||||
// {
|
||||
// //重复的绑定点,有可能存在的,比如CameraMatrix在vs/fs中同时存在
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// VkDescriptorSetLayoutBinding layout_binding;
|
||||
//
|
||||
// layout_binding.binding = binding;
|
||||
// layout_binding.descriptorType = desc_type;
|
||||
// layout_binding.descriptorCount = 1;
|
||||
// layout_binding.stageFlags = stageFlags;
|
||||
// layout_binding.pImmutableSamplers = nullptr;
|
||||
//
|
||||
// const int index=layout_binding_list.Add(layout_binding);
|
||||
//
|
||||
// index_by_binding.Add(binding,index);
|
||||
//}
|
||||
|
||||
void DescriptorSetLayoutCreater::Bind(const ShaderDescriptorList *sd_list,VkDescriptorType desc_type,VkShaderStageFlagBits stageFlags)
|
||||
{
|
||||
if(index_by_binding.KeyExist(binding))
|
||||
{
|
||||
//重复的绑定点,有可能存在的,比如CameraMatrix在vs/fs中同时存在
|
||||
return;
|
||||
}
|
||||
if(!sd_list||sd_list->GetCount()<=0)return;
|
||||
|
||||
VkDescriptorSetLayoutBinding layout_binding;
|
||||
|
||||
layout_binding.binding = binding;
|
||||
layout_binding.descriptorType = desc_type;
|
||||
layout_binding.descriptorCount = 1;
|
||||
layout_binding.stageFlags = stageFlags;
|
||||
layout_binding.pImmutableSamplers = nullptr;
|
||||
|
||||
const int index=layout_binding_list.Add(layout_binding);
|
||||
|
||||
index_by_binding.Add(binding,index);
|
||||
}
|
||||
|
||||
void DescriptorSetLayoutCreater::Bind(const uint32_t *binding,const uint32_t binding_count,VkDescriptorType desc_type,VkShaderStageFlagBits stageFlags)
|
||||
{
|
||||
if(!binding||binding_count<=0)return;
|
||||
const uint32_t binding_count=sd_list->GetCount();
|
||||
|
||||
const uint old_count=layout_binding_list.GetCount();
|
||||
|
||||
@ -50,23 +53,22 @@ void DescriptorSetLayoutCreater::Bind(const uint32_t *binding,const uint32_t bin
|
||||
|
||||
uint fin_count=0;
|
||||
|
||||
for(uint i=old_count;i<old_count+binding_count;i++)
|
||||
for(const ShaderDescriptor &sd:*sd_list)
|
||||
{
|
||||
if(!index_by_binding.KeyExist(*binding))
|
||||
if((!index_by_binding.KeyExist(sd.binding))
|
||||
&&(!index_by_binding_ri.KeyExist(sd.binding)))
|
||||
{
|
||||
p->binding = *binding;
|
||||
p->binding = sd.binding;
|
||||
p->descriptorType = desc_type;
|
||||
p->descriptorCount = 1;
|
||||
p->stageFlags = stageFlags;
|
||||
p->pImmutableSamplers = nullptr;
|
||||
|
||||
index_by_binding.Add(*binding,i);
|
||||
index_by_binding.Add(sd.binding,fin_count+old_count);
|
||||
|
||||
++p;
|
||||
++fin_count;
|
||||
}
|
||||
|
||||
++binding;
|
||||
}
|
||||
|
||||
layout_binding_list.SetCount(old_count+fin_count);
|
||||
|
@ -17,6 +17,7 @@ class DescriptorSetLayoutCreater
|
||||
List<VkDescriptorSetLayoutBinding> layout_binding_list;
|
||||
VkDescriptorSetLayout dsl=VK_NULL_HANDLE;
|
||||
BindingMapping index_by_binding;
|
||||
BindingMapping index_by_binding_ri;
|
||||
|
||||
VkPipelineLayout pipeline_layout=VK_NULL_HANDLE;
|
||||
|
||||
@ -25,20 +26,20 @@ public:
|
||||
DescriptorSetLayoutCreater(VkDevice dev,VkDescriptorPool dp){device=dev;pool=dp;}
|
||||
~DescriptorSetLayoutCreater();
|
||||
|
||||
void Bind(const uint32_t binding,VkDescriptorType,VkShaderStageFlagBits);
|
||||
void Bind(const uint32_t *binding,const uint32_t count,VkDescriptorType type,VkShaderStageFlagBits stage);
|
||||
void Bind(const DescriptorBindingList &dbl,VkDescriptorType type,VkShaderStageFlagBits stage)
|
||||
{
|
||||
if(dbl.GetCount()>0)
|
||||
Bind(dbl.GetData(),dbl.GetCount(),type,stage);
|
||||
}
|
||||
// void Bind(const uint32_t binding,VkDescriptorType,VkShaderStageFlagBits); //单个版本,暂时用不到
|
||||
void Bind(const ShaderDescriptorList *sd_list,VkDescriptorType type,VkShaderStageFlagBits stage);
|
||||
//void Bind(const DescriptorBindingList &dbl,VkDescriptorType type,VkShaderStageFlagBits stage)
|
||||
//{
|
||||
// if(dbl.GetCount()>0)
|
||||
// Bind(dbl.GetData(),dbl.GetCount(),type,stage);
|
||||
//}
|
||||
|
||||
void Bind(const ShaderDescriptorList *sdl,VkShaderStageFlagBits stage)
|
||||
{
|
||||
for(uint32_t i=VK_DESCRIPTOR_TYPE_BEGIN_RANGE;i<=VK_DESCRIPTOR_TYPE_END_RANGE;i++)
|
||||
{
|
||||
if(sdl->binding_list.GetCount()>0)
|
||||
Bind(sdl->binding_list.GetData(),sdl->binding_list.GetCount(),(VkDescriptorType)i,stage);
|
||||
if(sdl->GetCount()>0)
|
||||
Bind(sdl,(VkDescriptorType)i,stage);
|
||||
|
||||
++sdl;
|
||||
}
|
||||
|
@ -64,19 +64,22 @@ VK_NAMESPACE_BEGIN
|
||||
|
||||
uint str_len;
|
||||
|
||||
sd_list->binding_list.PreMalloc(count);
|
||||
sd_list->set_list.PreMalloc(count);
|
||||
sd_list->SetCount(count);
|
||||
|
||||
ShaderDescriptor *sd=sd_list->GetData();
|
||||
|
||||
for(uint i=0;i<count;i++)
|
||||
{
|
||||
if(version>=1)
|
||||
sd_list->set_list.Add(*data++);
|
||||
sd->set=*data++;
|
||||
else
|
||||
sd_list->set_list.Add(0);
|
||||
sd->set=0;
|
||||
|
||||
sd_list->binding_list.Add(*data++);
|
||||
sd->binding=*data++;
|
||||
str_len=*data++;
|
||||
sd_list->name_list.Add(AnsiString((char *)data,str_len));
|
||||
|
||||
memcpy(sd->name,(char *)data,str_len);
|
||||
sd->name[str_len]=0;
|
||||
data+=str_len;
|
||||
}
|
||||
|
||||
@ -158,14 +161,11 @@ VK_NAMESPACE_BEGIN
|
||||
|
||||
const ShaderDescriptorList *sdl=descriptor_list+(size_t)desc_type;
|
||||
|
||||
const int index=sdl->name_list.Find(name);
|
||||
for(const ShaderDescriptor &sd:*sdl)
|
||||
if(name==sd.name)
|
||||
return sd.binding;
|
||||
|
||||
uint binding;
|
||||
|
||||
if(sdl->binding_list.Get(index,binding))
|
||||
return binding;
|
||||
else
|
||||
return -1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
ShaderResource *LoadShaderResource(const uint8 *origin_filedata,const int64 filesize,bool include_file_header)
|
||||
|
Loading…
x
Reference in New Issue
Block a user