From 6a9d197eaf762317409511371aeb9f01c9752678 Mon Sep 17 00:00:00 2001 From: Mark Oliver Mints <mmints@uni-koblenz.de> Date: Tue, 10 Aug 2021 18:17:30 +0200 Subject: [PATCH] [#71] Refactor: implement a create function for Layout and Depth Stencil --- src/vkcv/PipelineManager.cpp | 59 +++++++++++++++++++++++------------- src/vkcv/PipelineManager.hpp | 15 +++++++++ 2 files changed, 53 insertions(+), 21 deletions(-) diff --git a/src/vkcv/PipelineManager.cpp b/src/vkcv/PipelineManager.cpp index bca1f2ce..ac4d7a22 100644 --- a/src/vkcv/PipelineManager.cpp +++ b/src/vkcv/PipelineManager.cpp @@ -271,16 +271,10 @@ namespace vkcv createPipelineColorBlendStateCreateInfo(config); // pipeline layout - const size_t pushConstantSize = config.m_ShaderProgram.getPushConstantSize(); - const vk::PushConstantRange pushConstantRange(vk::ShaderStageFlagBits::eAll, 0, pushConstantSize); - vk::PipelineLayoutCreateInfo pipelineLayoutCreateInfo( - {}, - (config.m_DescriptorLayouts), - (pushConstantRange)); - if (pushConstantSize == 0) { - pipelineLayoutCreateInfo.pushConstantRangeCount = 0; - } + + vk::PipelineLayoutCreateInfo pipelineLayoutCreateInfo = + createPipelineLayoutCreateInfo(config); vk::PipelineLayout vkPipelineLayout{}; if (m_Device.createPipelineLayout(&pipelineLayoutCreateInfo, nullptr, &vkPipelineLayout) != vk::Result::eSuccess) @@ -290,18 +284,8 @@ namespace vkcv } // Depth Stencil - const vk::PipelineDepthStencilStateCreateInfo depthStencilCreateInfo( - vk::PipelineDepthStencilStateCreateFlags(), - config.m_depthTest != DepthTest::None, - config.m_depthWrite, - depthTestToVkCompareOp(config.m_depthTest), - false, - false, - {}, - {}, - 0.0f, - 1.0f - ); + const vk::PipelineDepthStencilStateCreateInfo depthStencilCreateInfo = + createPipelineDepthStencilStateCreateInfo(config); const vk::PipelineDepthStencilStateCreateInfo* p_depthStencilCreateInfo = nullptr; const PassConfig& passConfig = passManager.getPassConfig(config.m_PassHandle); @@ -638,4 +622,37 @@ namespace vkcv ); return pipelineColorBlendStateCreateInfo; } + + vk::PipelineLayoutCreateInfo PipelineManager::createPipelineLayoutCreateInfo(const PipelineConfig &config) { + const size_t pushConstantSize = config.m_ShaderProgram.getPushConstantSize(); + const vk::PushConstantRange pushConstantRange(vk::ShaderStageFlagBits::eAll, 0, pushConstantSize); + + vk::PipelineLayoutCreateInfo pipelineLayoutCreateInfo( + {}, + (config.m_DescriptorLayouts), + (pushConstantRange)); + if (pushConstantSize == 0) { + pipelineLayoutCreateInfo.pushConstantRangeCount = 0; + } + return pipelineLayoutCreateInfo; + } + + vk::PipelineDepthStencilStateCreateInfo + PipelineManager::createPipelineDepthStencilStateCreateInfo(const PipelineConfig &config) { + const vk::PipelineDepthStencilStateCreateInfo pipelineDepthStencilCreateInfo( + vk::PipelineDepthStencilStateCreateFlags(), + config.m_depthTest != DepthTest::None, + config.m_depthWrite, + depthTestToVkCompareOp(config.m_depthTest), + false, + false, + {}, + {}, + 0.0f, + 1.0f + ); + + return pipelineDepthStencilCreateInfo; + } + } diff --git a/src/vkcv/PipelineManager.hpp b/src/vkcv/PipelineManager.hpp index 9f967332..c638ea0c 100644 --- a/src/vkcv/PipelineManager.hpp +++ b/src/vkcv/PipelineManager.hpp @@ -115,5 +115,20 @@ namespace vkcv * @return */ vk::PipelineColorBlendStateCreateInfo createPipelineColorBlendStateCreateInfo(const PipelineConfig &config); + + /** + * Creates a Pipeline Layout Create Info Struct. + * @param config sets Push Constant Size and Descriptor Layouts. + * @return Pipeline Layout Create Info Struct + */ + vk::PipelineLayoutCreateInfo createPipelineLayoutCreateInfo(const PipelineConfig &config); + + /** + * Creates a Pipeline Depth Stencil State Create Info Struct. + * @param config sets if depth test in enabled or not. + * @return Pipeline Layout Create Info Struct + */ + vk::PipelineDepthStencilStateCreateInfo createPipelineDepthStencilStateCreateInfo(const PipelineConfig &config); + }; } -- GitLab