diff --git a/config/Sources.cmake b/config/Sources.cmake index 22bb0470b62503f0395acb03709d13e53f2cd3dc..46ac4f0096e0584398111ccd15629fbe8a22884d 100644 --- a/config/Sources.cmake +++ b/config/Sources.cmake @@ -52,6 +52,7 @@ set(vkcv_sources ${vkcv_source}/vkcv/ShaderProgram.cpp ${vkcv_include}/vkcv/PipelineConfig.hpp + ${vkcv_include}/vkcv/ComputePipelineConfig.hpp ${vkcv_source}/vkcv/ComputePipelineManager.hpp ${vkcv_source}/vkcv/ComputePipelineManager.cpp diff --git a/include/vkcv/ComputePipelineConfig.hpp b/include/vkcv/ComputePipelineConfig.hpp new file mode 100644 index 0000000000000000000000000000000000000000..a99d75e6a0e4ec332588e7ff48a7d1ca112eccb4 --- /dev/null +++ b/include/vkcv/ComputePipelineConfig.hpp @@ -0,0 +1,17 @@ +#pragma once +/** + * @authors Mark Mints + * @file src/vkcv/ComputePipelineConfig.hpp + * @brief Compute Pipeline Config Struct to hand over required information to Pipeline Creation. + */ + +#include <vector> +#include "ShaderProgram.hpp" + +namespace vkcv +{ + struct ComputePipelineConfig { + ShaderProgram& m_ShaderProgram; + std::vector<vk::DescriptorSetLayout> m_DescriptorSetLayouts; + }; +} \ No newline at end of file diff --git a/src/vkcv/ComputePipelineManager.cpp b/src/vkcv/ComputePipelineManager.cpp index ae2f4407e98f782585cef5fc5d6ee107bb5afbf7..f090b6dbe7e05f488958c072a758fbf2d2938ab5 100644 --- a/src/vkcv/ComputePipelineManager.cpp +++ b/src/vkcv/ComputePipelineManager.cpp @@ -41,13 +41,11 @@ namespace vkcv return pipeline.m_layout; } - ComputePipelineHandle ComputePipelineManager::createComputePipeline( - const ShaderProgram &shaderProgram, - const std::vector <vk::DescriptorSetLayout> &descriptorSetLayouts) { + ComputePipelineHandle ComputePipelineManager::createComputePipeline(const ComputePipelineConfig& config) { // Temporally handing over the Shader Program instead of a pipeline config vk::ShaderModule computeModule{}; - if (createShaderModule(computeModule, shaderProgram, ShaderStage::COMPUTE) != vk::Result::eSuccess) + if (createShaderModule(computeModule, config.m_ShaderProgram, ShaderStage::COMPUTE) != vk::Result::eSuccess) return ComputePipelineHandle(); vk::PipelineShaderStageCreateInfo pipelineComputeShaderStageInfo( @@ -58,9 +56,9 @@ namespace vkcv nullptr ); - vk::PipelineLayoutCreateInfo pipelineLayoutCreateInfo({}, descriptorSetLayouts); + vk::PipelineLayoutCreateInfo pipelineLayoutCreateInfo({}, config.m_DescriptorSetLayouts); - const size_t pushConstantSize = shaderProgram.getPushConstantSize(); + const size_t pushConstantSize = config.m_ShaderProgram.getPushConstantSize(); vk::PushConstantRange pushConstantRange(vk::ShaderStageFlagBits::eCompute, 0, pushConstantSize); if (pushConstantSize > 0) { pipelineLayoutCreateInfo.setPushConstantRangeCount(1); diff --git a/src/vkcv/ComputePipelineManager.hpp b/src/vkcv/ComputePipelineManager.hpp index 9539c6c87196f5a57893837610a5f6be1adc922f..527243e6ec43850d416a7d929e01351454c40086 100644 --- a/src/vkcv/ComputePipelineManager.hpp +++ b/src/vkcv/ComputePipelineManager.hpp @@ -11,6 +11,7 @@ #include "vkcv/Handles.hpp" #include "vkcv/ShaderProgram.hpp" +#include "vkcv/ComputePipelineConfig.hpp" namespace vkcv { @@ -44,9 +45,14 @@ namespace vkcv [[nodiscard]] vk::PipelineLayout getVkPipelineLayout(const ComputePipelineHandle &handle) const; - ComputePipelineHandle createComputePipeline( - const ShaderProgram& shaderProgram, - const std::vector<vk::DescriptorSetLayout>& descriptorSetLayouts); + /** + * Creates a Compute Pipeline based on the set shader stages in the Config Struct. + * This function is wrapped in /src/vkcv/Core.cpp by Core::createComputePipeline(const ComputePipelineConfig &config). + * On application level it is necessary first to fill a ComputePipelineConfig Struct. + * @param config Hands over all needed information for pipeline creation. + * @return A Handler to the created Compute Pipeline Object. + */ + ComputePipelineHandle createComputePipeline(const ComputePipelineConfig& config); private: struct ComputePipeline {