From 27268f86d35848bc69d3a699f646388832457a3b Mon Sep 17 00:00:00 2001 From: Wunkolo Date: Fri, 11 Aug 2023 18:40:47 -0700 Subject: [PATCH] Fix instance-extension iteration Add the extensions when they are available rather than statically including them. --- src/core/renderer_vk/renderer_vk.cpp | 34 +++++++++++++++++++--------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/src/core/renderer_vk/renderer_vk.cpp b/src/core/renderer_vk/renderer_vk.cpp index f255eb0b..ef64bd5c 100644 --- a/src/core/renderer_vk/renderer_vk.cpp +++ b/src/core/renderer_vk/renderer_vk.cpp @@ -587,12 +587,30 @@ void RendererVK::initGraphicsContext(SDL_Window* window) { instanceInfo.pApplicationInfo = &applicationInfo; - std::vector instanceExtensions = { + std::unordered_set instanceExtensionsAvailable = {}; + if (const auto enumerateResult = vk::enumerateInstanceExtensionProperties(); enumerateResult.result == vk::Result::eSuccess) { + for (const auto& curExtension : enumerateResult.value) { + instanceExtensionsAvailable.emplace(curExtension.extensionName); + } + } + + std::vector instanceExtensions = {}; + + if (instanceExtensionsAvailable.contains(VK_KHR_SURFACE_EXTENSION_NAME)) { + instanceExtensions.emplace_back(VK_KHR_SURFACE_EXTENSION_NAME); + } + + bool debugUtils = false; + if (instanceExtensionsAvailable.contains(VK_EXT_DEBUG_UTILS_EXTENSION_NAME)) { + instanceExtensions.emplace_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); + debugUtils = true; + } + #if defined(__APPLE__) - VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME, + if (instanceExtensionsAvailable.contains(VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME)) { + instanceExtensionNames.emplace_back(VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME); + } #endif - VK_EXT_DEBUG_UTILS_EXTENSION_NAME, - }; // Get any additional extensions that SDL wants as well if (targetWindow) { @@ -620,13 +638,7 @@ void RendererVK::initGraphicsContext(SDL_Window* window) { VULKAN_HPP_DEFAULT_DISPATCHER.init(instance.get()); // Enable debug messenger if the instance was able to be created with debug_utils - if (std::find( - instanceExtensions.begin(), instanceExtensions.end(), - // std::string_view has a way to compare itself to `const char*` - // so by casting it, we get the actual string comparisons - // and not pointer-comparisons - std::string_view(VK_EXT_DEBUG_UTILS_EXTENSION_NAME) - ) != instanceExtensions.end()) { + if (debugUtils) { vk::DebugUtilsMessengerCreateInfoEXT debugCreateInfo{}; debugCreateInfo.messageSeverity = vk::DebugUtilsMessageSeverityFlagBitsEXT::eVerbose | vk::DebugUtilsMessageSeverityFlagBitsEXT::eInfo | vk::DebugUtilsMessageSeverityFlagBitsEXT::eError | vk::DebugUtilsMessageSeverityFlagBitsEXT::eWarning;