updated few codes.but it can't run for the new material writer.
This commit is contained in:
parent
538b69cb45
commit
15a9c8cb38
2
CMCore
2
CMCore
@ -1 +1 @@
|
|||||||
Subproject commit f42fd8a5b8fb5e67df0a37ed95ed798e268fb9ca
|
Subproject commit 468aa4462224a722b334d7140723b169556ba368
|
@ -72,11 +72,12 @@ private:
|
|||||||
sampler=db->CreateSampler();
|
sampler=db->CreateSampler();
|
||||||
|
|
||||||
{
|
{
|
||||||
MaterialParameters *mp_texture=material_instance->GetMP(DescriptorSetsType::Value);
|
MaterialParameters *mp_texture=material_instance->GetMP(DescriptorSetsType::Material);
|
||||||
|
|
||||||
if(!mp_texture)
|
if(!mp_texture)
|
||||||
|
return(false);
|
||||||
|
|
||||||
if(!mp_texture->BindUBO("tex",ubo_camera_info))return(false);
|
if(!mp_texture->BindSampler("m_tex",texture,sampler))return(false);
|
||||||
|
|
||||||
mp_texture->Update();
|
mp_texture->Update();
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ class DescriptorSets
|
|||||||
VkDevice device;
|
VkDevice device;
|
||||||
int layout_binding_count;
|
int layout_binding_count;
|
||||||
VkDescriptorSet desc_set;
|
VkDescriptorSet desc_set;
|
||||||
const BindingMapping *index_by_binding;
|
// const BindingMapping *index_by_binding;
|
||||||
|
|
||||||
VkPipelineLayout pipeline_layout;
|
VkPipelineLayout pipeline_layout;
|
||||||
|
|
||||||
@ -23,10 +23,10 @@ private:
|
|||||||
|
|
||||||
friend class DescriptorSetLayoutCreater;
|
friend class DescriptorSetLayoutCreater;
|
||||||
|
|
||||||
DescriptorSets(VkDevice dev,const int c,VkPipelineLayout pl,VkDescriptorSet ds,const BindingMapping *bi):index_by_binding(bi)
|
DescriptorSets(VkDevice dev,const int lbc,VkPipelineLayout pl,VkDescriptorSet ds)//,const BindingMapping *bi):index_by_binding(bi)
|
||||||
{
|
{
|
||||||
device=dev;
|
device=dev;
|
||||||
layout_binding_count=c;
|
layout_binding_count=lbc;
|
||||||
desc_set=ds;
|
desc_set=ds;
|
||||||
pipeline_layout=pl;
|
pipeline_layout=pl;
|
||||||
}
|
}
|
||||||
|
2
res
2
res
@ -1 +1 @@
|
|||||||
Subproject commit 27da09e0b6027a5651a030334d5026adef2aaff7
|
Subproject commit 179d904193cfbd0a3292fd7e7d0ed034011ed15d
|
@ -13,86 +13,106 @@ DescriptorSetLayoutCreater::~DescriptorSetLayoutCreater()
|
|||||||
if(pipeline_layout)
|
if(pipeline_layout)
|
||||||
vkDestroyPipelineLayout(device,pipeline_layout,nullptr);
|
vkDestroyPipelineLayout(device,pipeline_layout,nullptr);
|
||||||
|
|
||||||
if(dsl)
|
for(ShaderDescriptorSet s:sds)
|
||||||
vkDestroyDescriptorSetLayout(device,dsl,nullptr);
|
if(s.layout)
|
||||||
|
vkDestroyDescriptorSetLayout(device,s.layout,nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DescriptorSetLayoutCreater::Bind(const ShaderDescriptorList *sd_list,VkDescriptorType desc_type,VkShaderStageFlagBits stageFlags)
|
void DescriptorSetLayoutCreater::Bind(const ShaderDescriptorList *sd_list,VkDescriptorType desc_type,VkShaderStageFlagBits stageFlags)
|
||||||
{
|
{
|
||||||
if(!sd_list||sd_list->GetCount()<=0)return;
|
if(!sd_list||sd_list->GetCount()<=0)return;
|
||||||
|
|
||||||
const uint32_t binding_count=sd_list->GetCount();
|
uint32_t binding_count[size_t(DescriptorSetsType::RANGE_SIZE)],
|
||||||
|
old_count[size_t(DescriptorSetsType::RANGE_SIZE)],
|
||||||
|
fin_count[size_t(DescriptorSetsType::RANGE_SIZE)];
|
||||||
|
VkDescriptorSetLayoutBinding *p[size_t(DescriptorSetsType::RANGE_SIZE)];
|
||||||
|
|
||||||
const uint old_count=layout_binding_list.GetCount();
|
hgl_zero(binding_count);
|
||||||
|
hgl_zero(old_count);
|
||||||
|
hgl_zero(fin_count);
|
||||||
|
hgl_zero(p);
|
||||||
|
|
||||||
layout_binding_list.PreMalloc(old_count+binding_count);
|
for(const ShaderDescriptor &sd:*sd_list)
|
||||||
|
{
|
||||||
|
all_set.Add(sd.set);
|
||||||
|
|
||||||
VkDescriptorSetLayoutBinding *p=layout_binding_list.GetData()+old_count;
|
++binding_count[sd.set];
|
||||||
|
}
|
||||||
|
|
||||||
uint fin_count=0;
|
ENUM_CLASS_FOR(DescriptorSetsType,int,i)
|
||||||
|
if(binding_count[i]>0)
|
||||||
|
{
|
||||||
|
old_count[i]=sds[i].binding_list.GetCount();
|
||||||
|
|
||||||
|
sds[i].binding_list.PreMalloc(old_count[i]+binding_count[i]);
|
||||||
|
p[i]=sds[i].binding_list.GetData()+old_count[i];
|
||||||
|
}
|
||||||
|
|
||||||
for(const ShaderDescriptor &sd:*sd_list)
|
for(const ShaderDescriptor &sd:*sd_list)
|
||||||
{
|
{
|
||||||
//重复的绑定点是有可能存在的,比如CameraInfo在vs/fs中同时存在
|
//重复的绑定点是有可能存在的,比如CameraInfo在vs/fs中同时存在
|
||||||
|
|
||||||
if(!all_index_by_binding.KeyExist(sd.binding))
|
if(!all_binding.IsMember(sd.binding))
|
||||||
{
|
{
|
||||||
p->binding = sd.binding;
|
p[sd.set]->binding = sd.binding;
|
||||||
p->descriptorType = desc_type;
|
p[sd.set]->descriptorType = desc_type;
|
||||||
p->descriptorCount = 1;
|
p[sd.set]->descriptorCount = 1;
|
||||||
p->stageFlags = stageFlags;
|
p[sd.set]->stageFlags = stageFlags;
|
||||||
p->pImmutableSamplers = nullptr;
|
p[sd.set]->pImmutableSamplers = nullptr;
|
||||||
|
|
||||||
if(sd.name[0]=='r'
|
all_binding.Add(sd.binding);
|
||||||
&&sd.name[1]=='_')
|
|
||||||
index_by_binding[(size_t)DescriptorSetsType::Renderable].Add(sd.binding,fin_count+old_count);
|
|
||||||
else
|
|
||||||
if(sd.name[0]=='g'
|
|
||||||
&&sd.name[1]=='_')
|
|
||||||
index_by_binding[(size_t)DescriptorSetsType::Global].Add(sd.binding,fin_count+old_count);
|
|
||||||
else
|
|
||||||
index_by_binding[(size_t)DescriptorSetsType::Value].Add(sd.binding,fin_count+old_count);
|
|
||||||
|
|
||||||
all_index_by_binding.Add(sd.binding,fin_count+old_count);
|
++p[sd.set];
|
||||||
|
++fin_count[sd.set];
|
||||||
++p;
|
|
||||||
++fin_count;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
layout_binding_list.SetCount(old_count+fin_count);
|
ENUM_CLASS_FOR(DescriptorSetsType,int,i)
|
||||||
|
if(binding_count[i]>0)
|
||||||
|
sds[i].binding_list.SetCount(old_count[i]+fin_count[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DescriptorSetLayoutCreater::CreatePipelineLayout()
|
bool DescriptorSetLayoutCreater::CreatePipelineLayout()
|
||||||
{
|
{
|
||||||
const int count=layout_binding_list.GetCount();
|
fin_dsl_count=0;
|
||||||
|
|
||||||
if(count<=0)
|
ENUM_CLASS_FOR(DescriptorSetsType,int,i)
|
||||||
|
{
|
||||||
|
const int count=sds[i].binding_list.GetCount();
|
||||||
|
|
||||||
|
if(count<=0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
DescriptorSetLayoutCreateInfo descriptor_layout;
|
||||||
|
|
||||||
|
descriptor_layout.bindingCount = count;
|
||||||
|
descriptor_layout.pBindings = sds[i].binding_list.GetData();
|
||||||
|
|
||||||
|
if(sds[i].layout)
|
||||||
|
vkDestroyDescriptorSetLayout(device,sds[i].layout,nullptr);
|
||||||
|
|
||||||
|
if(vkCreateDescriptorSetLayout(device,&descriptor_layout,nullptr,&(sds[i].layout))!=VK_SUCCESS)
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
fin_dsl[fin_dsl_count]=sds[i].layout;
|
||||||
|
++fin_dsl_count;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(fin_dsl_count<=0)
|
||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
DescriptorSetLayoutCreateInfo descriptor_layout;
|
//VkPushConstantRange push_constant_range;
|
||||||
|
|
||||||
descriptor_layout.bindingCount = count;
|
//push_constant_range.stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
|
||||||
descriptor_layout.pBindings = layout_binding_list.GetData();
|
//push_constant_range.size = MAX_PUSH_CONSTANT_BYTES;
|
||||||
|
//push_constant_range.offset = 0;
|
||||||
if(dsl)
|
|
||||||
vkDestroyDescriptorSetLayout(device,dsl,nullptr);
|
|
||||||
|
|
||||||
if(vkCreateDescriptorSetLayout(device,&descriptor_layout,nullptr,&dsl)!=VK_SUCCESS)
|
|
||||||
return(false);
|
|
||||||
|
|
||||||
VkPushConstantRange push_constant_range;
|
|
||||||
|
|
||||||
push_constant_range.stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
|
|
||||||
push_constant_range.size = MAX_PUSH_CONSTANT_BYTES;
|
|
||||||
push_constant_range.offset = 0;
|
|
||||||
|
|
||||||
PipelineLayoutCreateInfo pPipelineLayoutCreateInfo;
|
PipelineLayoutCreateInfo pPipelineLayoutCreateInfo;
|
||||||
|
|
||||||
pPipelineLayoutCreateInfo.setLayoutCount = 1;
|
pPipelineLayoutCreateInfo.setLayoutCount = fin_dsl_count;
|
||||||
pPipelineLayoutCreateInfo.pSetLayouts = &dsl;
|
pPipelineLayoutCreateInfo.pSetLayouts = fin_dsl;
|
||||||
pPipelineLayoutCreateInfo.pushConstantRangeCount = 1;
|
pPipelineLayoutCreateInfo.pushConstantRangeCount = 0;//1;
|
||||||
pPipelineLayoutCreateInfo.pPushConstantRanges = &push_constant_range;
|
pPipelineLayoutCreateInfo.pPushConstantRanges = nullptr;//&push_constant_range;
|
||||||
|
|
||||||
if(vkCreatePipelineLayout(device,&pPipelineLayoutCreateInfo,nullptr,&pipeline_layout)!=VK_SUCCESS)
|
if(vkCreatePipelineLayout(device,&pPipelineLayoutCreateInfo,nullptr,&pipeline_layout)!=VK_SUCCESS)
|
||||||
return(false);
|
return(false);
|
||||||
@ -102,43 +122,28 @@ bool DescriptorSetLayoutCreater::CreatePipelineLayout()
|
|||||||
|
|
||||||
DescriptorSets *DescriptorSetLayoutCreater::Create(const DescriptorSetsType &type)const
|
DescriptorSets *DescriptorSetLayoutCreater::Create(const DescriptorSetsType &type)const
|
||||||
{
|
{
|
||||||
if(!pipeline_layout||!dsl)
|
if(!pipeline_layout)
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
|
|
||||||
const int count=layout_binding_list.GetCount();
|
ENUM_CLASS_RANGE_ERROR_RETURN_NULLPTR(DescriptorSetsType,type);
|
||||||
|
|
||||||
if(count<=0)
|
const uint32_t count=sds[(size_t)type].binding_list.GetCount();
|
||||||
return(nullptr);
|
|
||||||
|
|
||||||
const BindingMapping *bm=nullptr;
|
if(!count)
|
||||||
|
|
||||||
if(type==DescriptorSetsType::Material
|
|
||||||
// ||type==DescriptorSetsType::Texture
|
|
||||||
||type==DescriptorSetsType::Value) //未来会区分开
|
|
||||||
bm=&index_by_binding[(size_t)DescriptorSetsType::Value];
|
|
||||||
else
|
|
||||||
if(type==DescriptorSetsType::Renderable)
|
|
||||||
bm=&index_by_binding[(size_t)DescriptorSetsType::Renderable];
|
|
||||||
else
|
|
||||||
if(type==DescriptorSetsType::Global)
|
|
||||||
bm=&index_by_binding[(size_t)DescriptorSetsType::Global];
|
|
||||||
else
|
|
||||||
return(nullptr);
|
|
||||||
|
|
||||||
if(bm->GetCount()==0)
|
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
|
|
||||||
DescriptorSetAllocateInfo alloc_info;
|
DescriptorSetAllocateInfo alloc_info;
|
||||||
|
|
||||||
alloc_info.descriptorPool = pool;
|
alloc_info.descriptorPool = pool;
|
||||||
alloc_info.descriptorSetCount = 1;
|
alloc_info.descriptorSetCount = 1;
|
||||||
alloc_info.pSetLayouts = &dsl;
|
alloc_info.pSetLayouts = &(sds[(size_t)type].layout);
|
||||||
|
|
||||||
VkDescriptorSet desc_set;
|
VkDescriptorSet desc_set;
|
||||||
|
|
||||||
if(vkAllocateDescriptorSets(device,&alloc_info,&desc_set)!=VK_SUCCESS)
|
if(vkAllocateDescriptorSets(device,&alloc_info,&desc_set)!=VK_SUCCESS)
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
|
|
||||||
return(new DescriptorSets(device,count,pipeline_layout,desc_set,bm));
|
return(new DescriptorSets(device,count,pipeline_layout,desc_set));//,bm));
|
||||||
}
|
}
|
||||||
VK_NAMESPACE_END
|
VK_NAMESPACE_END
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include<hgl/graph/VK.h>
|
#include<hgl/graph/VK.h>
|
||||||
#include<hgl/graph/shader/ShaderResource.h>
|
#include<hgl/graph/shader/ShaderResource.h>
|
||||||
#include<hgl/type/Map.h>
|
#include<hgl/type/Map.h>
|
||||||
|
#include<hgl/type/Sets.h>
|
||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
class DescriptorSets;
|
class DescriptorSets;
|
||||||
|
|
||||||
@ -14,17 +15,33 @@ class DescriptorSetLayoutCreater
|
|||||||
VkDevice device;
|
VkDevice device;
|
||||||
VkDescriptorPool pool;
|
VkDescriptorPool pool;
|
||||||
|
|
||||||
List<VkDescriptorSetLayoutBinding> layout_binding_list;
|
Sets<uint32_t> all_set;
|
||||||
VkDescriptorSetLayout dsl=VK_NULL_HANDLE;
|
Sets<uint32_t> all_binding;
|
||||||
|
|
||||||
BindingMapping all_index_by_binding;
|
struct ShaderDescriptorSet
|
||||||
BindingMapping index_by_binding[size_t(DescriptorSetsType::RANGE_SIZE)];
|
{
|
||||||
|
List<VkDescriptorSetLayoutBinding> binding_list;
|
||||||
|
VkDescriptorSetLayout layout;
|
||||||
|
};
|
||||||
|
|
||||||
|
ShaderDescriptorSet sds[size_t(DescriptorSetsType::RANGE_SIZE)];
|
||||||
|
|
||||||
|
VkDescriptorSetLayout fin_dsl[size_t(DescriptorSetsType::RANGE_SIZE)];
|
||||||
|
uint32_t fin_dsl_count;
|
||||||
|
|
||||||
VkPipelineLayout pipeline_layout=VK_NULL_HANDLE;
|
VkPipelineLayout pipeline_layout=VK_NULL_HANDLE;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
DescriptorSetLayoutCreater(VkDevice dev,VkDescriptorPool dp){device=dev;pool=dp;}
|
DescriptorSetLayoutCreater(VkDevice dev,VkDescriptorPool dp)
|
||||||
|
{
|
||||||
|
ENUM_CLASS_FOR(DescriptorSetsType,int,i)
|
||||||
|
sds[i].layout=nullptr;
|
||||||
|
|
||||||
|
hgl_zero(fin_dsl);
|
||||||
|
fin_dsl_count=0;
|
||||||
|
device=dev;pool=dp;
|
||||||
|
}
|
||||||
~DescriptorSetLayoutCreater();
|
~DescriptorSetLayoutCreater();
|
||||||
|
|
||||||
void Bind(const ShaderDescriptorList *sd_list,VkDescriptorType type,VkShaderStageFlagBits stage);
|
void Bind(const ShaderDescriptorList *sd_list,VkDescriptorType type,VkShaderStageFlagBits stage);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user