增加DescriptorSetLayout类,理清与PipelineLayout关系

This commit is contained in:
HuYingzhuo 2019-04-18 15:49:13 +08:00
parent 772c147c71
commit d6f3e7bc36
9 changed files with 156 additions and 23 deletions

View File

@ -15,8 +15,9 @@ SET(VULKAN_TEST_SOURCE_FILES main.cpp
RenderSurfaceCreater.cpp
RenderSurface.cpp
VKBuffer.cpp
# VKPipelineLayout.cpp
# VKDescriptorSet.cpp
VKDescriptorSet.cpp
VKDescriptorSetLayout.cpp
VKPipelineLayout.cpp
VKRenderPass.cpp
VKShader.cpp
VKVertexInput.cpp
@ -31,8 +32,9 @@ SET(VULKAN_TEST_HEADER_FILES VK.h
RenderSurfaceAttribute.h
RenderSurface.h
VKBuffer.h
# VKPipelineLayout.h
# VKDescriptorSet.h
VKDescriptorSetLayout.h
VKDescriptorSet.h
VKPipelineLayout.h
VKRenderPass.h
VKShader.h
VKVertexInput.h

View File

@ -48,7 +48,7 @@ public:
#define CREATE_BUFFER_OBJECT(LargeName,type) Buffer *Create##LargeName(VkDeviceSize size,VkSharingMode sharing_mode=VK_SHARING_MODE_EXCLUSIVE){return CreateBuffer(VK_BUFFER_USAGE_##type##_BUFFER_BIT,size,sharing_mode);}
CREATE_BUFFER_OBJECT(UBO,UNIFORM)
CREATE_BUFFER_OBJECT(SSBO,STORAGE)
CREATE_BUFFER_OBJECT(SBO,STORAGE)
CREATE_BUFFER_OBJECT(INBO,INDIRECT)
#undef CREATE_BUFFER_OBJECT

View File

@ -3,9 +3,6 @@
#include"VK.h"
VK_NAMESPACE_BEGIN
class DescriptorSet
{
public:
};//class DescriptorSet
VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_DESCRIPTOR_SET_INCLUDE

View File

@ -0,0 +1,48 @@
#include"VKDescriptorSetLayout.h"
VK_NAMESPACE_BEGIN
DescriptorSetLayout::~DescriptorSetLayout()
{
const int count=desc_set_layout_list.GetCount();
if(count>0)
{
VkDescriptorSetLayout *dsl=desc_set_layout_list.GetData();
for(int i=0;i<count;i++)
{
vkDestroyDescriptorSetLayout(device,*dsl,nullptr);
++dsl;
}
}
}
void DescriptorSetLayoutCreater::Bind(const int binding,VkDescriptorType desc_type,VkShaderStageFlagBits stageFlags)
{
VkDescriptorSetLayoutBinding layout_binding = {};
layout_binding.binding = binding;
layout_binding.descriptorType = desc_type;
layout_binding.descriptorCount = 1;
layout_binding.stageFlags = stageFlags;
layout_binding.pImmutableSamplers = nullptr;
layout_binding_list.Add(layout_binding);
}
DescriptorSetLayout *DescriptorSetLayoutCreater::Creater()
{
VkDescriptorSetLayoutCreateInfo descriptor_layout = {};
descriptor_layout.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
descriptor_layout.pNext = nullptr;
descriptor_layout.bindingCount = layout_binding_list.GetCount();
descriptor_layout.pBindings = layout_binding_list.GetData();
List<VkDescriptorSetLayout> dsl_list;
dsl_list.SetCount(layout_binding_list.GetCount());
if(vkCreateDescriptorSetLayout(device,&descriptor_layout, nullptr, dsl_list.GetData())!=VK_SUCCESS)
return(false);
return(new DescriptorSetLayout(device,dsl_list));
}
VK_NAMESPACE_END

View File

@ -0,0 +1,65 @@
#ifndef HGL_GRAPH_VULKAN_DESCRIPTOR_SET_LAYOUT_INCLUDE
#define HGL_GRAPH_VULKAN_DESCRIPTOR_SET_LAYOUT_INCLUDE
#include"VK.h"
VK_NAMESPACE_BEGIN
class DescriptorSetLayout
{
VkDevice device;
List<VkDescriptorSetLayout> desc_set_layout_list;
public:
DescriptorSetLayout(VkDevice dev,const List<VkDescriptorSetLayout> &dsl_list)
{
device=dev;
desc_set_layout_list=dsl_list;
}
~DescriptorSetLayout();
const uint32_t GetCount()const{return desc_set_layout_list.GetCount();}
const VkDescriptorSetLayout * GetData ()const{return desc_set_layout_list.GetData();}
};//class DescriptorSetLayout
/**
*
*/
class DescriptorSetLayoutCreater
{
VkDevice device;
VkDescriptorSet desc_set;
List<VkDescriptorSetLayoutBinding> layout_binding_list;
public:
DescriptorSetLayoutCreater(VkDevice dev):device(dev){}
~DescriptorSetLayoutCreater()=default;
void Bind(const int binding,VkDescriptorType,VkShaderStageFlagBits);
#define DESC_SET_BIND_FUNC(name,vkname) void Bind##name(const int binding,VkShaderStageFlagBits stage_flag){Bind(binding,VK_DESCRIPTOR_TYPE_##vkname,stage_flag);}
DESC_SET_BIND_FUNC(Sampler, SAMPLER);
DESC_SET_BIND_FUNC(UBO, UNIFORM_BUFFER);
DESC_SET_BIND_FUNC(SBO, STORAGE_BUFFER);
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(UniformTexelBuffer, UNIFORM_TEXEL_BUFFER);
DESC_SET_BIND_FUNC(StorageTexelBuffer, STORAGE_TEXEL_BUFFER);
DESC_SET_BIND_FUNC(UBODynamic, UNIFORM_BUFFER_DYNAMIC);
DESC_SET_BIND_FUNC(SBODynamic, STORAGE_BUFFER_DYNAMIC);
DESC_SET_BIND_FUNC(InputAttachment, INPUT_ATTACHMENT);
#undef DESC_SET_BIND_FUNC
DescriptorSetLayout *Creater();
};//class DescriptorSet
VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_DESCRIPTOR_SET_LAYOUT_INCLUDE

View File

@ -3,21 +3,25 @@
VK_NAMESPACE_BEGIN
PipelineLayout::~PipelineLayout()
{
if(!layout)return;
if(layout)
vkDestroyPipelineLayout(device,layout,nullptr);
}
const int count=desc_set_layout.GetCount();
PipelineLayout *CreatePipelineLayout(VkDevice dev,const DescriptorSetLayout &dsl)
{
VkPipelineLayoutCreateInfo pPipelineLayoutCreateInfo = {};
pPipelineLayoutCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
pPipelineLayoutCreateInfo.pNext = nullptr;
pPipelineLayoutCreateInfo.pushConstantRangeCount = 0;
pPipelineLayoutCreateInfo.pPushConstantRanges = nullptr;
pPipelineLayoutCreateInfo.setLayoutCount = dsl.GetCount();
pPipelineLayoutCreateInfo.pSetLayouts = dsl.GetData();
if(count>0)
{
VkDescriptorSetLayout *dsl=desc_set_layout.GetData();
VkPipelineLayout pipeline_layout;
for(int i=0;i<count;i++)
{
vkDestroyDescriptorSetLayout(device,*dsl,nullptr);
++dsl;
}
}
if(vkCreatePipelineLayout(dev, &pPipelineLayoutCreateInfo, nullptr, &pipeline_layout)!=VK_SUCCESS)
return(nullptr);
vkDestroyPipelineLayout(device,layout,nullptr);
return(new PipelineLayout(dev,pipeline_layout));
}
VK_NAMESPACE_END

View File

@ -2,17 +2,19 @@
#define HGL_GRAPH_VULKAN_PIPELINE_LAYOUT_INCLUDE
#include"VK.h"
#include"VKDescriptorSetLayout.h"
VK_NAMESPACE_BEGIN
class PipelineLayout
{
VkDevice device;
VkPipelineLayout layout;
List<VkDescriptorSetLayout> desc_set_layout;
public:
PipelineLayout();
PipelineLayout(VkDevice dev,VkPipelineLayout pl){device=dev;layout=pl;}
~PipelineLayout();
};//class PipelineLayout
PipelineLayout *CreatePipelineLayout(VkDevice dev,const DescriptorSetLayout &dsl);
VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_PIPELINE_LAYOUT_INCLUDE

View File

@ -0,0 +1,4 @@
#include"VKSemaphore.h"
VK_NAMESPACE_BEGIN
VK_NAMESPACE_END

View File

@ -0,0 +1,11 @@
#ifndef HGL_GRAPH_VULKAN_SEMAPHORE_INCLUDE
#define HGL_GRAPH_VULKAN_SEMAPHORE_INCLUDE
#include"VK.h"
VK_NAMESPACE_BEGIN
class Semaphore
{
};//class Semaphore
VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_SEMAPHORE_INCLUDE