ULRE/src/SceneGraph/Vulkan/VKDescriptorSetLayoutCreater.h

78 lines
2.7 KiB
C
Raw Normal View History

#pragma once
#include<hgl/graph/VK.h>
2020-06-09 19:40:08 +08:00
#include<hgl/graph/shader/ShaderResource.h>
#include<hgl/type/Map.h>
VK_NAMESPACE_BEGIN
class DescriptorSets;
2021-06-15 17:58:27 +08:00
enum class DescriptorSetType
{
Material=0,
Renderable,
2021-06-15 19:03:15 +08:00
Global,
2021-06-15 17:58:27 +08:00
};//
/**
*
*/
class DescriptorSetLayoutCreater
{
VkDevice device;
VkDescriptorPool pool;
List<VkDescriptorSetLayoutBinding> layout_binding_list;
2019-07-06 16:46:19 +08:00
VkDescriptorSetLayout dsl=VK_NULL_HANDLE;
BindingMapping index_by_binding;
2021-06-15 17:43:06 +08:00
BindingMapping index_by_binding_ri;
2021-06-15 19:03:15 +08:00
BindingMapping index_by_binding_global;
2019-07-06 16:46:19 +08:00
VkPipelineLayout pipeline_layout=VK_NULL_HANDLE;
public:
DescriptorSetLayoutCreater(VkDevice dev,VkDescriptorPool dp){device=dev;pool=dp;}
~DescriptorSetLayoutCreater();
2021-06-15 17:43:06 +08:00
void Bind(const ShaderDescriptorList *sd_list,VkDescriptorType type,VkShaderStageFlagBits stage);
2020-06-09 19:40:08 +08:00
void Bind(const ShaderDescriptorList *sdl,VkShaderStageFlagBits stage)
{
for(uint32_t i=VK_DESCRIPTOR_TYPE_BEGIN_RANGE;i<=VK_DESCRIPTOR_TYPE_END_RANGE;i++)
{
2021-06-15 17:43:06 +08:00
if(sdl->GetCount()>0)
Bind(sdl,(VkDescriptorType)i,stage);
2020-06-09 19:40:08 +08:00
++sdl;
}
}
//以下代码不再需要使用一个void Bind(const ShaderResource &sr,VkShaderStageFlagBits stage)即可全部替代,而且更方便,但以此为提示
//
//#define DESC_SET_BIND_FUNC(name,vkname) void Bind##name(const uint32_t binding,VkShaderStageFlagBits stage_flag){Bind(binding,VK_DESCRIPTOR_TYPE_##vkname,stage_flag);} \
// void Bind##name(const uint32_t *binding,const uint32_t count,VkShaderStageFlagBits stage_flag){Bind(binding,count,VK_DESCRIPTOR_TYPE_##vkname,stage_flag);}
//
// DESC_SET_BIND_FUNC(Sampler, SAMPLER);
//
// DESC_SET_BIND_FUNC(CombinedImageSampler, COMBINED_IMAGE_SAMPLER);
// DESC_SET_BIND_FUNC(SampledImage, SAMPLED_IMAGE);
// DESC_SET_BIND_FUNC(StorageImage, STORAGE_IMAGE);
//
// DESC_SET_BIND_FUNC(UTBO, UNIFORM_TEXEL_BUFFER);
// DESC_SET_BIND_FUNC(SSTBO, STORAGE_TEXEL_BUFFER);
// DESC_SET_BIND_FUNC(UBO, UNIFORM_BUFFER);
// DESC_SET_BIND_FUNC(SSBO, STORAGE_BUFFER);
// DESC_SET_BIND_FUNC(UBODynamic, UNIFORM_BUFFER_DYNAMIC);
// DESC_SET_BIND_FUNC(SSBODynamic, STORAGE_BUFFER_DYNAMIC);
//
// DESC_SET_BIND_FUNC(InputAttachment, INPUT_ATTACHMENT);
//
//#undef DESC_SET_BIND_FUNC
bool CreatePipelineLayout();
const VkPipelineLayout GetPipelineLayout()const{return pipeline_layout;}
2021-06-15 17:58:27 +08:00
DescriptorSets *Create(const DescriptorSetType &type=DescriptorSetType::Material);
};//class DescriptorSetLayoutCreater
VK_NAMESPACE_END