From 51f6d5de5c8b2de021f4161346af37ac18d2cac2 Mon Sep 17 00:00:00 2001
From: Tobias Frisch <tfrisch@uni-koblenz.de>
Date: Wed, 1 Sep 2021 16:51:08 +0200
Subject: [PATCH] [#105] Adjusted requirements in indirect_draw

Signed-off-by: Tobias Frisch <tfrisch@uni-koblenz.de>
---
 projects/bindless_textures/src/main.cpp |  4 ++--
 projects/draw_indirect/src/main.cpp     | 24 ++++++++++++++++++------
 src/vkcv/DescriptorManager.cpp          |  5 +++--
 3 files changed, 23 insertions(+), 10 deletions(-)

diff --git a/projects/bindless_textures/src/main.cpp b/projects/bindless_textures/src/main.cpp
index 99f36347..b340cba8 100644
--- a/projects/bindless_textures/src/main.cpp
+++ b/projects/bindless_textures/src/main.cpp
@@ -21,7 +21,6 @@ int main(int argc, const char** argv) {
 
 	vkcv::Features features;
 	features.requireExtension(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
-	features.requireExtension(VK_EXT_DESCRIPTOR_INDEXING_EXTENSION_NAME);
     features.requireExtensionFeature<vk::PhysicalDeviceDescriptorIndexingFeatures>(
             VK_EXT_DESCRIPTOR_INDEXING_EXTENSION_NAME, [](vk::PhysicalDeviceDescriptorIndexingFeatures &features) {
                 features.setShaderInputAttachmentArrayDynamicIndexing(true);
@@ -46,7 +45,8 @@ int main(int argc, const char** argv) {
                 features.setDescriptorBindingPartiallyBound(true);
                 features.setDescriptorBindingVariableDescriptorCount(true);
                 features.setRuntimeDescriptorArray(true);
-            });
+            }
+	);
 
 	vkcv::Core core = vkcv::Core::create(
 		window,
diff --git a/projects/draw_indirect/src/main.cpp b/projects/draw_indirect/src/main.cpp
index bc906f55..c175865f 100644
--- a/projects/draw_indirect/src/main.cpp
+++ b/projects/draw_indirect/src/main.cpp
@@ -32,14 +32,25 @@ int main(int argc, const char** argv) {
 		windowHeight,
 		false
 	);
+	
+	vkcv::Features features;
+	features.requireExtension(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
+	
+	features.requireExtensionFeature<vk::PhysicalDeviceDescriptorIndexingFeatures>(
+			VK_EXT_DESCRIPTOR_INDEXING_EXTENSION_NAME,
+			[](vk::PhysicalDeviceDescriptorIndexingFeatures& features) {
+				features.setDescriptorBindingPartiallyBound(true);
+				features.setDescriptorBindingVariableDescriptorCount(true);
+				features.setRuntimeDescriptorArray(true);
+			}
+	);
 
 	vkcv::Core core = vkcv::Core::create(
 		window,
 		applicationName,
 		VK_MAKE_VERSION(0, 0, 1),
 		{ vk::QueueFlagBits::eGraphics ,vk::QueueFlagBits::eCompute , vk::QueueFlagBits::eTransfer },
-		{},
-		{ "VK_KHR_swapchain", VK_EXT_DESCRIPTOR_INDEXING_EXTENSION_NAME }
+		features
 	);
 
 	vkcv::asset::Scene mesh;
@@ -54,7 +65,7 @@ int main(int argc, const char** argv) {
     for(uint32_t i = 0; i < 5; i++)
     {
         std::filesystem::path grassPath(grassPaths[i]);
-        vkcv::asset::TextureData grassTexture = vkcv::asset::loadTexture(grassPath);
+        vkcv::asset::Texture grassTexture = vkcv::asset::loadTexture(grassPath);
 
         vkcv::Image texture = core.createImage(vk::Format::eR8G8B8A8Srgb, grassTexture.width, grassTexture.height);
         texture.fill(grassTexture.data.data());
@@ -151,8 +162,9 @@ int main(int argc, const char** argv) {
 	
 	const vkcv::VertexLayout firstMeshLayout (bindings);
 
-	std::vector<vkcv::DescriptorBinding> descriptorBindings = { firstMeshProgram.getReflectedDescriptors()[0] };
-	vkcv::DescriptorSetHandle descriptorSet = core.createDescriptorSet(descriptorBindings);
+	vkcv::DescriptorBindings descriptorBindings = firstMeshProgram.getReflectedDescriptors().at(0);
+	vkcv::DescriptorSetLayoutHandle descriptorSetLayout = core.createDescriptorSetLayout(descriptorBindings);
+	vkcv::DescriptorSetHandle descriptorSet = core.createDescriptorSet(descriptorSetLayout);
 
 	const vkcv::PipelineConfig firstMeshPipelineConfig {
         firstMeshProgram,
@@ -160,7 +172,7 @@ int main(int argc, const char** argv) {
         UINT32_MAX,
         firstMeshPass,
         {firstMeshLayout},
-		{ core.getDescriptorSet(descriptorSet).layout },
+		{ core.getDescriptorSetLayout(descriptorSetLayout).vulkanHandle },
 		true
 	};
 	vkcv::PipelineHandle firstMeshPipeline = core.createGraphicsPipeline(firstMeshPipelineConfig);
diff --git a/src/vkcv/DescriptorManager.cpp b/src/vkcv/DescriptorManager.cpp
index 67f470d4..2ea408a9 100644
--- a/src/vkcv/DescriptorManager.cpp
+++ b/src/vkcv/DescriptorManager.cpp
@@ -83,7 +83,7 @@ namespace vkcv
 						vk::DescriptorBindingFlagBits::ePartiallyBound
 				);
 			} else {
-				bindingsFlags.push_back(vk::DescriptorBindingFlags());
+				bindingsFlags.emplace_back();
 			}
         }
 		
@@ -93,8 +93,9 @@ namespace vkcv
 
         //create the descriptor set's layout from the binding data gathered above
         vk::DescriptorSetLayout vulkanHandle = VK_NULL_HANDLE;
-        vk::DescriptorSetLayoutCreateInfo layoutInfo({}, bindingsVector);
+        vk::DescriptorSetLayoutCreateInfo layoutInfo(vk::DescriptorSetLayoutCreateFlags(), bindingsVector);
         layoutInfo.setPNext(&bindingFlagsInfo);
+		
         auto result = m_Device.createDescriptorSetLayout(&layoutInfo, nullptr, &vulkanHandle);
         if (result != vk::Result::eSuccess) {
             vkcv_log(LogLevel::ERROR, "Failed to create descriptor set layout");
-- 
GitLab