From 43ab72540fc140f73d5d21f98975f47ff0fa9705 Mon Sep 17 00:00:00 2001
From: Tobias Frisch <tfrisch@uni-koblenz.de>
Date: Mon, 24 Oct 2022 18:30:13 +0200
Subject: [PATCH] Cleanup with default extensions and features being enabled

Signed-off-by: Tobias Frisch <tfrisch@uni-koblenz.de>
---
 projects/fire_works/src/main.cpp       |  2 +-
 projects/head_demo/src/main.cpp        | 10 ++++-
 projects/indirect_dispatch/src/App.cpp | 34 ++++++++++++++++-
 projects/voxelization/src/main.cpp     |  6 +++
 src/vkcv/Context.cpp                   | 52 --------------------------
 5 files changed, 49 insertions(+), 55 deletions(-)

diff --git a/projects/fire_works/src/main.cpp b/projects/fire_works/src/main.cpp
index ad75a3ea..54a6e03c 100644
--- a/projects/fire_works/src/main.cpp
+++ b/projects/fire_works/src/main.cpp
@@ -754,7 +754,7 @@ int main(int argc, const char **argv) {
 			voxelHeight
 	);
 	
-	voxelImageConfig.setSupportingStorage(true);
+	voxelSamplesConfig.setSupportingStorage(true);
 	
 	vkcv::Image voxelSamples = vkcv::image(
 			core,
diff --git a/projects/head_demo/src/main.cpp b/projects/head_demo/src/main.cpp
index b3ed708e..771689e9 100644
--- a/projects/head_demo/src/main.cpp
+++ b/projects/head_demo/src/main.cpp
@@ -17,12 +17,20 @@ 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.requireFeature([](vk::PhysicalDeviceFeatures& features) {
+		features.setGeometryShader(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);
 	vkcv::camera::CameraManager cameraManager(window);
diff --git a/projects/indirect_dispatch/src/App.cpp b/projects/indirect_dispatch/src/App.cpp
index 18a6b9ad..b441c3dd 100644
--- a/projects/indirect_dispatch/src/App.cpp
+++ b/projects/indirect_dispatch/src/App.cpp
@@ -27,6 +27,38 @@ const char* MotionBlurModeLabels[3] = {
 		"Tile visualisation"
 };
 
+static vkcv::Features getAppFeatures() {
+	vkcv::Features features;
+	features.requireExtension(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
+	
+	features.requireFeature([](vk::PhysicalDeviceFeatures& features) {
+		features.setShaderInt16(true);
+	});
+	
+	features.requireExtensionFeature<vk::PhysicalDeviceSubgroupSizeControlFeatures>(
+			VK_EXT_SUBGROUP_SIZE_CONTROL_EXTENSION_NAME,
+			[](vk::PhysicalDeviceSubgroupSizeControlFeatures &features) {
+				features.setSubgroupSizeControl(true);
+			}
+	);
+	
+	features.requireExtensionFeature<vk::PhysicalDeviceShaderFloat16Int8Features>(
+			VK_KHR_SHADER_FLOAT16_INT8_EXTENSION_NAME,
+			[](vk::PhysicalDeviceShaderFloat16Int8Features &features) {
+				features.setShaderFloat16(true);
+			}
+	);
+	
+	features.tryExtensionFeature<vk::PhysicalDeviceCoherentMemoryFeaturesAMD>(
+			VK_AMD_DEVICE_COHERENT_MEMORY_EXTENSION_NAME,
+			[](vk::PhysicalDeviceCoherentMemoryFeaturesAMD &features) {
+				features.setDeviceCoherentMemory(true);
+			}
+	);
+	
+	return features;
+}
+
 App::App() : 
 	m_applicationName("Indirect Dispatch"),
 	m_windowWidth(AppConfig::defaultWindowWidth),
@@ -35,7 +67,7 @@ App::App() :
 		m_applicationName,
 		VK_MAKE_VERSION(0, 0, 1),
 		{ vk::QueueFlagBits::eGraphics ,vk::QueueFlagBits::eCompute , vk::QueueFlagBits::eTransfer },
-		{ VK_KHR_SWAPCHAIN_EXTENSION_NAME })),
+		getAppFeatures())),
 	m_windowHandle(m_core.createWindow(m_applicationName, m_windowWidth, m_windowHeight, true)),
 	m_cameraManager(m_core.getWindow(m_windowHandle)){}
 
diff --git a/projects/voxelization/src/main.cpp b/projects/voxelization/src/main.cpp
index 6b6e2eea..fe58a620 100644
--- a/projects/voxelization/src/main.cpp
+++ b/projects/voxelization/src/main.cpp
@@ -25,6 +25,12 @@ int main(int argc, const char** argv) {
 	vkcv::Features features;
 	features.requireExtension(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
 	
+	features.requireFeature([](vk::PhysicalDeviceFeatures& features) {
+		features.setGeometryShader(true);
+		features.setDepthClamp(true);
+		features.setShaderInt16(true);
+	});
+	
 	features.requireExtensionFeature<vk::PhysicalDeviceDescriptorIndexingFeatures>(
 			VK_EXT_DESCRIPTOR_INDEXING_EXTENSION_NAME,
 			[](vk::PhysicalDeviceDescriptorIndexingFeatures& features) {
diff --git a/src/vkcv/Context.cpp b/src/vkcv/Context.cpp
index c26bf632..1d92268e 100644
--- a/src/vkcv/Context.cpp
+++ b/src/vkcv/Context.cpp
@@ -409,58 +409,6 @@ namespace vkcv {
 		featureManager.useExtension("VK_KHR_portability_subset", true);
 #endif
 
-		if (featureManager.useExtension(VK_KHR_SHADER_FLOAT16_INT8_EXTENSION_NAME, false)) {
-			featureManager.useFeatures<vk::PhysicalDeviceShaderFloat16Int8Features>(
-				[](vk::PhysicalDeviceShaderFloat16Int8Features &features) {
-					features.setShaderFloat16(true);
-				},
-				false
-			);
-		}
-
-		if (featureManager.useExtension(VK_KHR_16BIT_STORAGE_EXTENSION_NAME, false)) {
-			featureManager.useFeatures<vk::PhysicalDevice16BitStorageFeatures>(
-				[](vk::PhysicalDevice16BitStorageFeatures &features) {
-					features.setStorageBuffer16BitAccess(true);
-				},
-				false
-			);
-		}
-		
-		if (featureManager.useExtension(VK_AMD_DEVICE_COHERENT_MEMORY_EXTENSION_NAME, false)) {
-			featureManager.useFeatures<vk::PhysicalDeviceCoherentMemoryFeaturesAMD>(
-				[](vk::PhysicalDeviceCoherentMemoryFeaturesAMD &features) {
-					features.setDeviceCoherentMemory(true);
-				},
-				false
-			);
-		}
-		
-		if (featureManager.useExtension(VK_EXT_SUBGROUP_SIZE_CONTROL_EXTENSION_NAME, false)) {
-			featureManager.useFeatures<vk::PhysicalDeviceSubgroupSizeControlFeatures>(
-					[](vk::PhysicalDeviceSubgroupSizeControlFeatures &features) {
-						features.setSubgroupSizeControl(true);
-					},
-					false
-			);
-		}
-		
-		if (featureManager.useExtension(VK_EXT_INDEX_TYPE_UINT8_EXTENSION_NAME, false)) {
-			featureManager.useFeatures<vk::PhysicalDeviceIndexTypeUint8FeaturesEXT>(
-				[](vk::PhysicalDeviceIndexTypeUint8FeaturesEXT &features) {
-					features.setIndexTypeUint8(true);
-				},
-				false
-			);
-		}
-
-		featureManager.useFeatures([](vk::PhysicalDeviceFeatures &features) {
-			features.setFragmentStoresAndAtomics(true);
-			features.setGeometryShader(true);
-			features.setDepthClamp(true);
-			features.setShaderInt16(true);
-		});
-
 		for (const auto &feature : features.getList()) {
 			feature(featureManager);
 		}
-- 
GitLab