From ab4cc6157f9f9f4d90ef771b82b5663860cf9094 Mon Sep 17 00:00:00 2001 From: Mara Vogt <mvogt@uni-koblenz.de> Date: Thu, 13 May 2021 19:02:28 +0200 Subject: [PATCH] [#11] added documentation to pipeline class and core added doc for new function in core class added doc for pipeline class reformated some code in pipeline function in core class --- include/vkcv/Core.hpp | 11 +++++++++- include/vkcv/Pipeline.hpp | 14 ++++++++++++ src/vkcv/Core.cpp | 46 +++++++++++++++++++++++++++------------ 3 files changed, 56 insertions(+), 15 deletions(-) diff --git a/include/vkcv/Core.hpp b/include/vkcv/Core.hpp index aa5dc52e..ad3011b6 100644 --- a/include/vkcv/Core.hpp +++ b/include/vkcv/Core.hpp @@ -99,10 +99,19 @@ namespace vkcv std::vector<const char*> instanceExtensions = {}, std::vector<const char*> deviceExtensions = {}); + /** + * Creates a basic vulkan graphics pipeline using @p pipeline from the pipeline class and returns it using the @p handle. + * Fixed Functions for pipeline are set with standard values. + * + * @param pipeline a pipeline object from the pipeline class + * @param handle a handle to return the created vulkan handle + * @return True if Pipeline creation was successfull, False if not + */ + bool createPipeline(const Pipeline &pipeline, PipelineHandle &handle); + // TODO: BufferHandle createBuffer(const Buffer &buf); PassHandle createRenderPass(const Renderpass &pass) ; - bool createPipeline(const Pipeline &pipeline, PipelineHandle &handle); }; } diff --git a/include/vkcv/Pipeline.hpp b/include/vkcv/Pipeline.hpp index a0b5fdd2..8d39ca63 100644 --- a/include/vkcv/Pipeline.hpp +++ b/include/vkcv/Pipeline.hpp @@ -16,7 +16,21 @@ namespace vkcv { class Pipeline { public: + /** + * Default constructer is deleted! + */ Pipeline() = delete; + + /** + * Constructor for the pipeline. Creates a pipeline using @p vertexCode, @p fragmentCode as well as the + * dimensions of the application window @p width and @p height. A handle for the Render Pass is also needed, @p passHandle. + * + * @param vertexCode Spir-V of Vertex Shader + * @param fragCode Spir-V of Fragment Shader + * @param height height of the application window + * @param width width of the application window + * @param passHandle handle for Render Pass + */ Pipeline(const std::vector<uint32_t> &vertexCode, const std::vector<uint32_t> &fragCode, uint32_t height, uint32_t width, PassHandle &passHandle); std::vector<uint32_t> m_vertexCode; diff --git a/src/vkcv/Core.cpp b/src/vkcv/Core.cpp index eb3195b4..89ccb1be 100644 --- a/src/vkcv/Core.cpp +++ b/src/vkcv/Core.cpp @@ -281,29 +281,49 @@ namespace vkcv // vertex shader stage vk::ShaderModuleCreateInfo vertexModuleInfo({},pipeline.m_vertexCode.size(), pipeline.m_vertexCode.data()); vk::ShaderModule vertexModule{}; - if(m_Context.m_Device.createShaderModule(&vertexModuleInfo, nullptr, &vertexModule) != vk::Result::eSuccess){ + if(m_Context.m_Device.createShaderModule(&vertexModuleInfo, nullptr, &vertexModule) != vk::Result::eSuccess) return false; - }; - vk::PipelineShaderStageCreateInfo pipelineVertexShaderStageInfo({}, vk::ShaderStageFlagBits::eVertex,vertexModule, "main", - nullptr); + + vk::PipelineShaderStageCreateInfo pipelineVertexShaderStageInfo( + {}, + vk::ShaderStageFlagBits::eVertex, + vertexModule, + "main", + nullptr + ); // fragment shader stage vk::ShaderModuleCreateInfo fragmentModuleInfo({},pipeline.m_fragCode.size(), pipeline.m_fragCode.data()); vk::ShaderModule fragmentModule{}; - if(m_Context.m_Device.createShaderModule(&fragmentModuleInfo, nullptr, &fragmentModule) != vk::Result::eSuccess){ + if(m_Context.m_Device.createShaderModule(&fragmentModuleInfo, nullptr, &fragmentModule) != vk::Result::eSuccess) return false; - }; - vk::PipelineShaderStageCreateInfo pipelineFragmentShaderStageInfo({}, vk::ShaderStageFlagBits::eFragment,fragmentModule, "main", - nullptr); + + vk::PipelineShaderStageCreateInfo pipelineFragmentShaderStageInfo( + {}, + vk::ShaderStageFlagBits::eFragment, + fragmentModule, + "main", + nullptr + ); // vertex input state vk::VertexInputBindingDescription vertexInputBindingDescription(0,12,vk::VertexInputRate::eVertex); vk::VertexInputAttributeDescription vertexInputAttributeDescription(0, 0, vk::Format::eR32G32B32Sfloat, 0); - vk::PipelineVertexInputStateCreateInfo pipelineVertexInputStateCreateInfo({}, 1, &vertexInputBindingDescription, 1, &vertexInputAttributeDescription); + vk::PipelineVertexInputStateCreateInfo pipelineVertexInputStateCreateInfo( + {}, + 1, + &vertexInputBindingDescription, + 1, + &vertexInputAttributeDescription + ); // input assembly state - vk::PipelineInputAssemblyStateCreateInfo pipelineInputAssemblyStateCreateInfo({}, vk::PrimitiveTopology::eTriangleList, false); + vk::PipelineInputAssemblyStateCreateInfo pipelineInputAssemblyStateCreateInfo( + {}, + vk::PrimitiveTopology::eTriangleList, + false + ); // viewport state vk::Viewport viewport(0.f, 0.f, static_cast<float>(pipeline.m_width), static_cast<float>(pipeline.m_height), 0.f, 1.f); @@ -369,9 +389,8 @@ namespace vkcv {} ); vk::PipelineLayout vkPipelineLayout{}; - if(m_Context.m_Device.createPipelineLayout(&pipelineLayoutCreateInfo, nullptr, &vkPipelineLayout) != vk::Result::eSuccess){ + if(m_Context.m_Device.createPipelineLayout(&pipelineLayoutCreateInfo, nullptr, &vkPipelineLayout) != vk::Result::eSuccess) return false; - } // graphics pipeline create std::vector<vk::PipelineShaderStageCreateInfo> shaderStages = {pipelineVertexShaderStageInfo, pipelineFragmentShaderStageInfo}; @@ -396,9 +415,8 @@ namespace vkcv ); vk::Pipeline vkPipeline{}; - if(m_Context.m_Device.createGraphicsPipelines(nullptr, 1, &graphicsPipelineCreateInfo, nullptr, &vkPipeline) != vk::Result::eSuccess){ + if(m_Context.m_Device.createGraphicsPipelines(nullptr, 1, &graphicsPipelineCreateInfo, nullptr, &vkPipeline) != vk::Result::eSuccess) return false; - } m_Pipelines.push_back(vkPipeline); m_PipelineLayouts.push_back(vkPipelineLayout); -- GitLab