From 6142780a4b39882e8269ea3d166c6d15b7422fc9 Mon Sep 17 00:00:00 2001 From: Johannes Unterguggenberger Date: Mon, 9 Oct 2023 15:30:00 +0200 Subject: [PATCH] Refactored supports_given_extensions (#180) * Added an overlod to supports_given_extensions, also listing which extensions are missing if some are missing * Linked to latest Auto-Vk's development commit --- auto_vk | 2 +- auto_vk_toolkit/include/context_vulkan.hpp | 17 +++++++--- auto_vk_toolkit/src/context_vulkan.cpp | 39 ++++++++++++++++++---- 3 files changed, 46 insertions(+), 12 deletions(-) diff --git a/auto_vk b/auto_vk index 2be07e68..a79bf351 160000 --- a/auto_vk +++ b/auto_vk @@ -1 +1 @@ -Subproject commit 2be07e6834d1617995414141710fb897ac344a03 +Subproject commit a79bf351b17bb4f577336e354706d8786ac07fd8 diff --git a/auto_vk_toolkit/include/context_vulkan.hpp b/auto_vk_toolkit/include/context_vulkan.hpp index 13ba1600..6e78ab61 100644 --- a/auto_vk_toolkit/include/context_vulkan.hpp +++ b/auto_vk_toolkit/include/context_vulkan.hpp @@ -238,11 +238,20 @@ namespace avk #endif /** Checks whether the given physical device supports given extensions. - * @return True if the physical device supports all the extensions, false otherwise. - */ - bool supports_given_extensions(const vk::PhysicalDevice& aPhysicalDevice, const std::vector& aExtensionsInQuestion) const; + * @param aPhysicalDevice The physical device whose extensions shall be compared with the extensions in question + * @param aExtensionsInQuestion The extensions in question, which we want to know of if the physical device supports them + * @return True if the physical device supports all the extensions, false otherwise. + */ + bool supports_given_extensions(const vk::PhysicalDevice& aPhysicalDevice, const std::vector& aExtensionsInQuestion) const; + + /** Checks whether the given physical device supports given extensions. + * @param aPhysicalDeviceExtensionsAvailable List of physical device extensions that are available + * @param aExtensionsInQuestion The extensions in question, which we want to know of if they are contained in the list of available extensions + * @return True if the physical device supports all the extensions, false otherwise. + */ + bool supports_given_extensions(const std::vector& aPhysicalDeviceExtensionsAvailable, const std::vector& aExtensionsInQuestion) const; - /** Pick the physical device which looks to be the most promising one */ + /** Pick the physical device which looks to be the most promising one */ void pick_physical_device(); /** Gets the right resolution for the given window, considering the window's size and surface capabilities */ diff --git a/auto_vk_toolkit/src/context_vulkan.cpp b/auto_vk_toolkit/src/context_vulkan.cpp index bca9ab67..08508cd4 100644 --- a/auto_vk_toolkit/src/context_vulkan.cpp +++ b/auto_vk_toolkit/src/context_vulkan.cpp @@ -967,19 +967,25 @@ namespace avk bool context_vulkan::supports_given_extensions(const vk::PhysicalDevice& aPhysicalDevice, const std::vector& aExtensionsInQuestion) const { // Search for each extension requested! + auto deviceExtensions = aPhysicalDevice.enumerateDeviceExtensionProperties(); + return supports_given_extensions(deviceExtensions, aExtensionsInQuestion); + } + + bool context_vulkan::supports_given_extensions(const std::vector& aPhysicalDeviceExtensionsAvailable, const std::vector& aExtensionsInQuestion) const + { for (const auto& extensionName : aExtensionsInQuestion) { - auto deviceExtensions = aPhysicalDevice.enumerateDeviceExtensionProperties(); - // See if we can find the current requested extension in the array of all device extensions - auto result = std::ranges::find_if(deviceExtensions, + // See if we can find the current requested extension in the array of all device extensions: + auto result = std::ranges::find_if(aPhysicalDeviceExtensionsAvailable, [extensionName](const vk::ExtensionProperties& devext) { return strcmp(extensionName, devext.extensionName) == 0; }); - if (result == std::end(deviceExtensions)) { + if (result == std::end(aPhysicalDeviceExtensionsAvailable)) { // could not find the device extension return false; } } return true; // All extensions supported + } void context_vulkan::pick_physical_device() @@ -1040,15 +1046,34 @@ namespace avk } } - // Check if extensions are required - if (!supports_given_extensions(physicalDevice, sRequiredDeviceExtensions)) { + // Check if Auto-Vk-Toolkit-required extensions are supported + auto deviceExtensions = physicalDevice.enumerateDeviceExtensionProperties(); + if (!supports_given_extensions(deviceExtensions, sRequiredDeviceExtensions)) { LOG_WARNING(fmt::format("Depreciating physical device \"{}\" because it does not support all extensions required by Auto-Vk-Toolkit.", properties.deviceName)); + for (const auto& extensionName : sRequiredDeviceExtensions) { + auto extensionInfo = std::string(" - ") + extensionName + " ..."; + while (extensionInfo.length() < 60) { + extensionInfo += "."; + } + auto result = std::ranges::find_if(deviceExtensions, [extensionName](const vk::ExtensionProperties& devext) { return strcmp(extensionName, devext.extensionName) == 0; }); + extensionInfo += result != deviceExtensions.end() ? " supported" : " NOT supported"; + LOG_WARNING(extensionInfo); + } score = 0; } - // Check if extensions are required + // Check if user-requested extensions are supported if (!supports_given_extensions(physicalDevice, mSettings.mRequiredDeviceExtensions.mExtensions)) { LOG_WARNING(fmt::format("Depreciating physical device \"{}\" because it does not support all extensions required by the application.", properties.deviceName)); + for (const auto& extensionName : mSettings.mRequiredDeviceExtensions.mExtensions) { + auto extensionInfo = std::string(" - ") + extensionName + " ..."; + while (extensionInfo.length() < 60) { + extensionInfo += "."; + } + auto result = std::ranges::find_if(deviceExtensions, [extensionName](const vk::ExtensionProperties& devext) { return strcmp(extensionName, devext.extensionName) == 0; }); + extensionInfo += result != deviceExtensions.end() ? " supported" : " NOT supported"; + LOG_WARNING(extensionInfo); + } score = 0; }