增加DescriptorSetLayout类,理清与PipelineLayout关系
This commit is contained in:
parent
772c147c71
commit
d6f3e7bc36
@ -15,8 +15,9 @@ SET(VULKAN_TEST_SOURCE_FILES main.cpp
|
|||||||
RenderSurfaceCreater.cpp
|
RenderSurfaceCreater.cpp
|
||||||
RenderSurface.cpp
|
RenderSurface.cpp
|
||||||
VKBuffer.cpp
|
VKBuffer.cpp
|
||||||
# VKPipelineLayout.cpp
|
VKDescriptorSet.cpp
|
||||||
# VKDescriptorSet.cpp
|
VKDescriptorSetLayout.cpp
|
||||||
|
VKPipelineLayout.cpp
|
||||||
VKRenderPass.cpp
|
VKRenderPass.cpp
|
||||||
VKShader.cpp
|
VKShader.cpp
|
||||||
VKVertexInput.cpp
|
VKVertexInput.cpp
|
||||||
@ -31,8 +32,9 @@ SET(VULKAN_TEST_HEADER_FILES VK.h
|
|||||||
RenderSurfaceAttribute.h
|
RenderSurfaceAttribute.h
|
||||||
RenderSurface.h
|
RenderSurface.h
|
||||||
VKBuffer.h
|
VKBuffer.h
|
||||||
# VKPipelineLayout.h
|
VKDescriptorSetLayout.h
|
||||||
# VKDescriptorSet.h
|
VKDescriptorSet.h
|
||||||
|
VKPipelineLayout.h
|
||||||
VKRenderPass.h
|
VKRenderPass.h
|
||||||
VKShader.h
|
VKShader.h
|
||||||
VKVertexInput.h
|
VKVertexInput.h
|
||||||
|
@ -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);}
|
#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(UBO,UNIFORM)
|
||||||
CREATE_BUFFER_OBJECT(SSBO,STORAGE)
|
CREATE_BUFFER_OBJECT(SBO,STORAGE)
|
||||||
CREATE_BUFFER_OBJECT(INBO,INDIRECT)
|
CREATE_BUFFER_OBJECT(INBO,INDIRECT)
|
||||||
|
|
||||||
#undef CREATE_BUFFER_OBJECT
|
#undef CREATE_BUFFER_OBJECT
|
||||||
|
@ -3,9 +3,6 @@
|
|||||||
|
|
||||||
#include"VK.h"
|
#include"VK.h"
|
||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
class DescriptorSet
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
};//class DescriptorSet
|
|
||||||
VK_NAMESPACE_END
|
VK_NAMESPACE_END
|
||||||
#endif//HGL_GRAPH_VULKAN_DESCRIPTOR_SET_INCLUDE
|
#endif//HGL_GRAPH_VULKAN_DESCRIPTOR_SET_INCLUDE
|
||||||
|
48
example/Vulkan/VKDescriptorSetLayout.cpp
Normal file
48
example/Vulkan/VKDescriptorSetLayout.cpp
Normal 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
|
65
example/Vulkan/VKDescriptorSetLayout.h
Normal file
65
example/Vulkan/VKDescriptorSetLayout.h
Normal 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
|
@ -3,21 +3,25 @@
|
|||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
PipelineLayout::~PipelineLayout()
|
PipelineLayout::~PipelineLayout()
|
||||||
{
|
{
|
||||||
if(!layout)return;
|
if(layout)
|
||||||
|
|
||||||
const int count=desc_set_layout.GetCount();
|
|
||||||
|
|
||||||
if(count>0)
|
|
||||||
{
|
|
||||||
VkDescriptorSetLayout *dsl=desc_set_layout.GetData();
|
|
||||||
|
|
||||||
for(int i=0;i<count;i++)
|
|
||||||
{
|
|
||||||
vkDestroyDescriptorSetLayout(device,*dsl,nullptr);
|
|
||||||
++dsl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
vkDestroyPipelineLayout(device,layout,nullptr);
|
vkDestroyPipelineLayout(device,layout,nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
||||||
|
VkPipelineLayout pipeline_layout;
|
||||||
|
|
||||||
|
if(vkCreatePipelineLayout(dev, &pPipelineLayoutCreateInfo, nullptr, &pipeline_layout)!=VK_SUCCESS)
|
||||||
|
return(nullptr);
|
||||||
|
|
||||||
|
return(new PipelineLayout(dev,pipeline_layout));
|
||||||
|
}
|
||||||
VK_NAMESPACE_END
|
VK_NAMESPACE_END
|
||||||
|
@ -2,17 +2,19 @@
|
|||||||
#define HGL_GRAPH_VULKAN_PIPELINE_LAYOUT_INCLUDE
|
#define HGL_GRAPH_VULKAN_PIPELINE_LAYOUT_INCLUDE
|
||||||
|
|
||||||
#include"VK.h"
|
#include"VK.h"
|
||||||
|
#include"VKDescriptorSetLayout.h"
|
||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
class PipelineLayout
|
class PipelineLayout
|
||||||
{
|
{
|
||||||
VkDevice device;
|
VkDevice device;
|
||||||
VkPipelineLayout layout;
|
VkPipelineLayout layout;
|
||||||
List<VkDescriptorSetLayout> desc_set_layout;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
PipelineLayout();
|
PipelineLayout(VkDevice dev,VkPipelineLayout pl){device=dev;layout=pl;}
|
||||||
~PipelineLayout();
|
~PipelineLayout();
|
||||||
};//class PipelineLayout
|
};//class PipelineLayout
|
||||||
|
|
||||||
|
PipelineLayout *CreatePipelineLayout(VkDevice dev,const DescriptorSetLayout &dsl);
|
||||||
VK_NAMESPACE_END
|
VK_NAMESPACE_END
|
||||||
#endif//HGL_GRAPH_VULKAN_PIPELINE_LAYOUT_INCLUDE
|
#endif//HGL_GRAPH_VULKAN_PIPELINE_LAYOUT_INCLUDE
|
||||||
|
4
example/Vulkan/VKSemaphore.cpp
Normal file
4
example/Vulkan/VKSemaphore.cpp
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
#include"VKSemaphore.h"
|
||||||
|
|
||||||
|
VK_NAMESPACE_BEGIN
|
||||||
|
VK_NAMESPACE_END
|
11
example/Vulkan/VKSemaphore.h
Normal file
11
example/Vulkan/VKSemaphore.h
Normal 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
|
Loading…
x
Reference in New Issue
Block a user