From ff56e1842549bcb45533e9bf43e35adcee3b3ebd Mon Sep 17 00:00:00 2001
From: Mark Oliver Mints <mmints@uni-koblenz.de>
Date: Sat, 4 Sep 2021 12:57:41 +0200
Subject: [PATCH] [#71] introduce compute pipeline config struct

---
 config/Sources.cmake                   |  1 +
 include/vkcv/ComputePipelineConfig.hpp | 17 +++++++++++++++++
 src/vkcv/ComputePipelineManager.cpp    | 10 ++++------
 src/vkcv/ComputePipelineManager.hpp    | 12 +++++++++---
 4 files changed, 31 insertions(+), 9 deletions(-)
 create mode 100644 include/vkcv/ComputePipelineConfig.hpp

diff --git a/config/Sources.cmake b/config/Sources.cmake
index 22bb0470..46ac4f00 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 00000000..a99d75e6
--- /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 ae2f4407..f090b6db 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 9539c6c8..527243e6 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 {
-- 
GitLab