From d6f3e7bc366634c9fc4fd23f32a15c8c8875874b Mon Sep 17 00:00:00 2001 From: HuYingzhuo Date: Thu, 18 Apr 2019 15:49:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0DescriptorSetLayout=E7=B1=BB?= =?UTF-8?q?=EF=BC=8C=E7=90=86=E6=B8=85=E4=B8=8EPipelineLayout=E5=85=B3?= =?UTF-8?q?=E7=B3=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- example/Vulkan/CMakeLists.txt | 10 ++-- example/Vulkan/RenderSurface.h | 2 +- example/Vulkan/VKDescriptorSet.h | 5 +- example/Vulkan/VKDescriptorSetLayout.cpp | 48 +++++++++++++++++ example/Vulkan/VKDescriptorSetLayout.h | 65 ++++++++++++++++++++++++ example/Vulkan/VKPipelineLayout.cpp | 28 +++++----- example/Vulkan/VKPipelineLayout.h | 6 ++- example/Vulkan/VKSemaphore.cpp | 4 ++ example/Vulkan/VKSemaphore.h | 11 ++++ 9 files changed, 156 insertions(+), 23 deletions(-) create mode 100644 example/Vulkan/VKDescriptorSetLayout.cpp create mode 100644 example/Vulkan/VKDescriptorSetLayout.h create mode 100644 example/Vulkan/VKSemaphore.cpp create mode 100644 example/Vulkan/VKSemaphore.h diff --git a/example/Vulkan/CMakeLists.txt b/example/Vulkan/CMakeLists.txt index 27552dc4..d311021e 100644 --- a/example/Vulkan/CMakeLists.txt +++ b/example/Vulkan/CMakeLists.txt @@ -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 diff --git a/example/Vulkan/RenderSurface.h b/example/Vulkan/RenderSurface.h index 806457e2..0130a644 100644 --- a/example/Vulkan/RenderSurface.h +++ b/example/Vulkan/RenderSurface.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);} CREATE_BUFFER_OBJECT(UBO,UNIFORM) - CREATE_BUFFER_OBJECT(SSBO,STORAGE) + CREATE_BUFFER_OBJECT(SBO,STORAGE) CREATE_BUFFER_OBJECT(INBO,INDIRECT) #undef CREATE_BUFFER_OBJECT diff --git a/example/Vulkan/VKDescriptorSet.h b/example/Vulkan/VKDescriptorSet.h index 1a6000f8..5ec0f51d 100644 --- a/example/Vulkan/VKDescriptorSet.h +++ b/example/Vulkan/VKDescriptorSet.h @@ -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 diff --git a/example/Vulkan/VKDescriptorSetLayout.cpp b/example/Vulkan/VKDescriptorSetLayout.cpp new file mode 100644 index 00000000..2eca9b6e --- /dev/null +++ b/example/Vulkan/VKDescriptorSetLayout.cpp @@ -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 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 diff --git a/example/Vulkan/VKDescriptorSetLayout.h b/example/Vulkan/VKDescriptorSetLayout.h new file mode 100644 index 00000000..a2f895ea --- /dev/null +++ b/example/Vulkan/VKDescriptorSetLayout.h @@ -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 desc_set_layout_list; + +public: + + DescriptorSetLayout(VkDevice dev,const List &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 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 diff --git a/example/Vulkan/VKPipelineLayout.cpp b/example/Vulkan/VKPipelineLayout.cpp index 68e1c766..67fdbb37 100644 --- a/example/Vulkan/VKPipelineLayout.cpp +++ b/example/Vulkan/VKPipelineLayout.cpp @@ -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 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 diff --git a/example/Vulkan/VKSemaphore.cpp b/example/Vulkan/VKSemaphore.cpp new file mode 100644 index 00000000..5217ca0d --- /dev/null +++ b/example/Vulkan/VKSemaphore.cpp @@ -0,0 +1,4 @@ +#include"VKSemaphore.h" + +VK_NAMESPACE_BEGIN +VK_NAMESPACE_END diff --git a/example/Vulkan/VKSemaphore.h b/example/Vulkan/VKSemaphore.h new file mode 100644 index 00000000..70a00c34 --- /dev/null +++ b/example/Vulkan/VKSemaphore.h @@ -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