From 0ec24e9cd7eabf8698ce1a44ca70091206254caf Mon Sep 17 00:00:00 2001
From: Tobias Frisch <tfrisch@uni-koblenz.de>
Date: Fri, 19 Jul 2024 00:11:40 +0200
Subject: [PATCH] Remove waitIdle() from endFrame() and adjust feature
 requirements in projects

Signed-off-by: Tobias Frisch <tfrisch@uni-koblenz.de>
---
 projects/fire_works/src/main.cpp          |  8 ++++++++
 projects/indirect_dispatch/src/App.cpp    |  8 ++++++++
 projects/indirect_draw/src/main.cpp       |  1 -
 projects/particle_simulation/src/main.cpp | 12 +++++++++++-
 projects/path_tracer/src/main.cpp         | 13 ++++++++++++-
 projects/ray_tracer/src/main.cpp          | 13 ++++++++++++-
 projects/sph/src/main.cpp                 | 13 ++++++++++++-
 projects/voxelization/src/main.cpp        |  1 +
 src/vkcv/Core.cpp                         |  3 ---
 9 files changed, 64 insertions(+), 8 deletions(-)

diff --git a/projects/fire_works/src/main.cpp b/projects/fire_works/src/main.cpp
index ef1a66bf..7c703495 100644
--- a/projects/fire_works/src/main.cpp
+++ b/projects/fire_works/src/main.cpp
@@ -201,6 +201,14 @@ int main(int argc, const char **argv) {
 	features.requireFeature([](vk::PhysicalDeviceFeatures& features) {
 		features.setGeometryShader(true);
 	});
+
+	features.requireExtensionFeature<vk::PhysicalDeviceDescriptorIndexingFeatures>(
+			VK_EXT_DESCRIPTOR_INDEXING_EXTENSION_NAME,
+			[](vk::PhysicalDeviceDescriptorIndexingFeatures& features) {
+				features.setDescriptorBindingPartiallyBound(true);
+				features.setDescriptorBindingVariableDescriptorCount(true);
+			}
+	);
 	
 	vkcv::Core core = vkcv::Core::create(
 		"Firework",
diff --git a/projects/indirect_dispatch/src/App.cpp b/projects/indirect_dispatch/src/App.cpp
index 1c42cafc..7e29ea33 100644
--- a/projects/indirect_dispatch/src/App.cpp
+++ b/projects/indirect_dispatch/src/App.cpp
@@ -48,6 +48,14 @@ static vkcv::Features getAppFeatures() {
 				features.setShaderFloat16(true);
 			}
 	);
+
+	features.requireExtensionFeature<vk::PhysicalDeviceDescriptorIndexingFeatures>(
+			VK_EXT_DESCRIPTOR_INDEXING_EXTENSION_NAME,
+			[](vk::PhysicalDeviceDescriptorIndexingFeatures& features) {
+				features.setDescriptorBindingPartiallyBound(true);
+				features.setDescriptorBindingVariableDescriptorCount(true);
+			}
+	);
 	
 	features.tryExtensionFeature<vk::PhysicalDeviceCoherentMemoryFeaturesAMD>(
 			VK_AMD_DEVICE_COHERENT_MEMORY_EXTENSION_NAME,
diff --git a/projects/indirect_draw/src/main.cpp b/projects/indirect_draw/src/main.cpp
index 424f2e07..c24dd260 100644
--- a/projects/indirect_draw/src/main.cpp
+++ b/projects/indirect_draw/src/main.cpp
@@ -279,7 +279,6 @@ int main(int argc, const char** argv) {
     });
 
 	features.requireExtension(VK_KHR_SHADER_DRAW_PARAMETERS_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);
diff --git a/projects/particle_simulation/src/main.cpp b/projects/particle_simulation/src/main.cpp
index 09cb7028..af291257 100644
--- a/projects/particle_simulation/src/main.cpp
+++ b/projects/particle_simulation/src/main.cpp
@@ -16,12 +16,22 @@ int main(int argc, const char **argv) {
 
     uint32_t windowWidth = 800;
     uint32_t windowHeight = 600;
+
+    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);
+			}
+	);
 	
     vkcv::Core core = vkcv::Core::create(
             applicationName,
             VK_MAKE_VERSION(0, 0, 1),
             {vk::QueueFlagBits::eTransfer, vk::QueueFlagBits::eGraphics, vk::QueueFlagBits::eCompute},
-			{ VK_KHR_SWAPCHAIN_EXTENSION_NAME }
+			features
     );
 	vkcv::WindowHandle windowHandle = core.createWindow(applicationName, windowWidth, windowHeight, true);
     vkcv::Window& window = core.getWindow(windowHandle);
diff --git a/projects/path_tracer/src/main.cpp b/projects/path_tracer/src/main.cpp
index 1a87015e..8e37e6af 100644
--- a/projects/path_tracer/src/main.cpp
+++ b/projects/path_tracer/src/main.cpp
@@ -47,11 +47,22 @@ int main(int argc, const char** argv) {
 
 	const std::string applicationName = "Path Tracer";
 
+	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);
+			}
+	);
+
 	vkcv::Core core = vkcv::Core::create(
 		applicationName,
 		VK_MAKE_VERSION(0, 0, 1),
 		{ vk::QueueFlagBits::eTransfer,vk::QueueFlagBits::eGraphics, vk::QueueFlagBits::eCompute },
-		{ "VK_KHR_swapchain" }
+		features
 	);
 	
 	const int initialWidth = 1280;
diff --git a/projects/ray_tracer/src/main.cpp b/projects/ray_tracer/src/main.cpp
index 1a906d5d..838fd154 100644
--- a/projects/ray_tracer/src/main.cpp
+++ b/projects/ray_tracer/src/main.cpp
@@ -35,11 +35,22 @@ int main(int argc, const char** argv) {
 	const int windowWidth = 800;
 	const int windowHeight = 600;
 
+	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);
+			}
+	);
+
 	vkcv::Core core = vkcv::Core::create(
 		applicationName,
 		VK_MAKE_VERSION(0, 0, 1),
 		{ vk::QueueFlagBits::eTransfer,vk::QueueFlagBits::eGraphics, vk::QueueFlagBits::eCompute },
-		{ "VK_KHR_swapchain" }
+		features
 	);
 
 	vkcv::WindowHandle windowHandle = core.createWindow(applicationName, windowWidth, windowHeight, true);
diff --git a/projects/sph/src/main.cpp b/projects/sph/src/main.cpp
index 3d8cf078..b24ad385 100644
--- a/projects/sph/src/main.cpp
+++ b/projects/sph/src/main.cpp
@@ -16,12 +16,23 @@
 int main(int argc, const char **argv) {
     const std::string applicationName = "SPH";
 
+    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);
+			}
+	);
+
     // creating core object that will handle all vulkan objects
     vkcv::Core core = vkcv::Core::create(
         applicationName,
         VK_MAKE_VERSION(0, 0, 1),
         { vk::QueueFlagBits::eTransfer, vk::QueueFlagBits::eGraphics, vk::QueueFlagBits::eCompute },
-        { VK_KHR_SWAPCHAIN_EXTENSION_NAME }
+        features
     );
 
     vkcv::WindowHandle windowHandle = core.createWindow(applicationName, 1280, 720, true);
diff --git a/projects/voxelization/src/main.cpp b/projects/voxelization/src/main.cpp
index 9a6492b8..835bbf27 100644
--- a/projects/voxelization/src/main.cpp
+++ b/projects/voxelization/src/main.cpp
@@ -37,6 +37,7 @@ int main(int argc, const char** argv) {
 			VK_EXT_DESCRIPTOR_INDEXING_EXTENSION_NAME,
 			[](vk::PhysicalDeviceDescriptorIndexingFeatures& features) {
 				features.setDescriptorBindingPartiallyBound(true);
+				features.setDescriptorBindingVariableDescriptorCount(true);
 			}
 	);
 	
diff --git a/src/vkcv/Core.cpp b/src/vkcv/Core.cpp
index 4e7d9d94..5213c572 100644
--- a/src/vkcv/Core.cpp
+++ b/src/vkcv/Core.cpp
@@ -309,9 +309,6 @@ namespace vkcv {
 			m_currentSwapchainImageIndex = std::numeric_limits<uint32_t>::max();
 		}
 
-		m_Context.getDevice().waitIdle(); // TODO: this is a sin against graphics programming, but
-										  // its getting late - Alex
-
 		m_ImageManager->setCurrentSwapchainImageIndex(m_currentSwapchainImageIndex);
 
 		return (m_currentSwapchainImageIndex != std::numeric_limits<uint32_t>::max());
-- 
GitLab