From 209b3737fe03db7825c1b764579841c29c629f11 Mon Sep 17 00:00:00 2001
From: Tobias Frisch <tfrisch@uni-koblenz.de>
Date: Mon, 5 Sep 2022 10:49:31 +0200
Subject: [PATCH] Support multiple descriptor sets with indirect drawcalls

Signed-off-by: Tobias Frisch <tfrisch@uni-koblenz.de>
---
 include/vkcv/Buffer.hpp             |  4 ++--
 include/vkcv/Core.hpp               |  6 +++---
 projects/indirect_draw/src/main.cpp |  2 +-
 src/vkcv/Core.cpp                   | 25 +++++++++++++------------
 4 files changed, 19 insertions(+), 18 deletions(-)

diff --git a/include/vkcv/Buffer.hpp b/include/vkcv/Buffer.hpp
index 352d7e89..5a4afb06 100644
--- a/include/vkcv/Buffer.hpp
+++ b/include/vkcv/Buffer.hpp
@@ -26,12 +26,12 @@ namespace vkcv {
 		Buffer(Core* core, const BufferHandle& handle) : m_core(core), m_handle(handle) {}
 		
 		Buffer(const Buffer& other) = default;
-		Buffer(Buffer&& other) = default;
+		Buffer(Buffer&& other) noexcept = default;
 		
 		~Buffer() = default;
 		
 		Buffer& operator=(const Buffer& other) = default;
-		Buffer& operator=(Buffer&& other) = default;
+		Buffer& operator=(Buffer&& other) noexcept = default;
 		
 		/**
 		 * @brief Returns the buffers handle.
diff --git a/include/vkcv/Core.hpp b/include/vkcv/Core.hpp
index 83524865..39addd72 100644
--- a/include/vkcv/Core.hpp
+++ b/include/vkcv/Core.hpp
@@ -555,7 +555,7 @@ namespace vkcv
 		 * @param cmdStreamHandle Handle of the command stream that the drawcalls are recorded into
 		 * @param pipelineHandle Handle of the pipeline that is used for the drawcalls
 		 * @param pushConstantData Push constants that are used for the drawcalls, ignored if constant size is set to 0
-		 * @param compiledDescriptorSet TODO
+		 * @param descriptorSetUsages Descriptor set usages of the drawcalls
 		 * @param compiledMesh TODO
 		 * @param drawcalls Information about each drawcall, consisting of mesh handle, descriptor set bindings and instance count
 		 * @param renderTargets Image handles that are used as render targets
@@ -567,7 +567,7 @@ namespace vkcv
 				const CommandStreamHandle                           cmdStreamHandle,
 				const GraphicsPipelineHandle                        &pipelineHandle,
 				const PushConstants                                 &pushConstantData,
-                const vkcv::DescriptorSetHandle                     &compiledDescriptorSet,
+				const std::vector<DescriptorSetUsage> 				&descriptorSetUsages,
 				const vkcv::Mesh                                    &compiledMesh,
 				const std::vector<ImageHandle>                      &renderTargets,
 				const BufferHandle  								&indirectBuffer,
@@ -625,7 +625,7 @@ namespace vkcv
 		 * @param cmdStream Handle of the command stream that the dispatch is recorded into
 		 * @param computePipeline Handle of the pipeline that is used for the dispatch
 		 * @param dispatchSize How many work groups are dispatched
-		 * @param descriptorSetUsages Descriptor set bindings of the dispatch
+		 * @param descriptorSetUsages Descriptor set usages of the dispatch
 		 * @param pushConstants Push constant data for the dispatch
 		 */
 		void recordComputeDispatchToCmdStream(const CommandStreamHandle& cmdStream,
diff --git a/projects/indirect_draw/src/main.cpp b/projects/indirect_draw/src/main.cpp
index 2f1f0845..b6e9049b 100644
--- a/projects/indirect_draw/src/main.cpp
+++ b/projects/indirect_draw/src/main.cpp
@@ -553,7 +553,7 @@ int main(int argc, const char** argv) {
 			cmdStream,
             sponzaPipelineHandle,
             pushConstants,
-            descriptorSet,
+			{ vkcv::DescriptorSetUsage(0, descriptorSet) },
             compiledMesh,
 			renderTargets,
 			indirectBuffer.getHandle(),
diff --git a/src/vkcv/Core.cpp b/src/vkcv/Core.cpp
index ad0b7d49..3d7d126c 100644
--- a/src/vkcv/Core.cpp
+++ b/src/vkcv/Core.cpp
@@ -413,7 +413,7 @@ namespace vkcv
 					pipelineLayout,
 					descriptorUsage.setLocation,
 					descriptorSetManager.getDescriptorSet(descriptorUsage.descriptorSet).vulkanHandle,
-					nullptr
+					descriptorUsage.dynamicOffsets
 			);
 		}
 		
@@ -574,7 +574,7 @@ namespace vkcv
     void Core::recordIndexedIndirectDrawcallsToCmdStream(const CommandStreamHandle cmdStreamHandle,
 														 const GraphicsPipelineHandle &pipelineHandle,
 														 const PushConstants &pushConstantData,
-														 const vkcv::DescriptorSetHandle &compiledDescriptorSet,
+														 const std::vector<DescriptorSetUsage> &descriptorSetUsages,
 														 const vkcv::Mesh &compiledMesh,
 														 const std::vector<ImageHandle> &renderTargets,
 														 const BufferHandle &indirectBuffer,
@@ -590,15 +590,15 @@ namespace vkcv
 		);
 	
 		auto recordFunction = [&](const vk::CommandBuffer& cmdBuffer) {
-			const auto& descSet = m_DescriptorSetManager->getDescriptorSet(compiledDescriptorSet);
-			
-			cmdBuffer.bindDescriptorSets(
-					vk::PipelineBindPoint::eGraphics,
-					pipelineLayout,
-					0,
-					descSet.vulkanHandle,
-					nullptr
-			);
+			for (const auto& usage : descriptorSetUsages) {
+				cmdBuffer.bindDescriptorSets(
+						vk::PipelineBindPoint::eGraphics,
+						pipelineLayout,
+						usage.setLocation,
+						m_DescriptorSetManager->getDescriptorSet(usage.descriptorSet).vulkanHandle,
+						usage.dynamicOffsets
+				);
+			}
 			
 			if (pushConstantData.getSizePerDrawcall() > 0) {
 				cmdBuffer.pushConstants(
@@ -660,7 +660,8 @@ namespace vkcv
 					pipelineLayout,
 					descriptorUsage.setLocation,
 					descriptorSetManager.getDescriptorSet(descriptorUsage.descriptorSet).vulkanHandle,
-					nullptr);
+					descriptorUsage.dynamicOffsets
+			);
 		}
 		
 		if (pushConstantData.getData()) {
-- 
GitLab