From 06bbf111d97b417aa70565a9629f97376f297ecf Mon Sep 17 00:00:00 2001 From: Stenzek Date: Wed, 11 Oct 2017 23:15:08 +1000 Subject: [PATCH] Vulkan: Improve readability of device/instance extension checks --- .../VideoBackends/Vulkan/VulkanContext.cpp | 38 ++++++------------- 1 file changed, 12 insertions(+), 26 deletions(-) diff --git a/Source/Core/VideoBackends/Vulkan/VulkanContext.cpp b/Source/Core/VideoBackends/Vulkan/VulkanContext.cpp index 765a6f33f3..e2f44b73be 100644 --- a/Source/Core/VideoBackends/Vulkan/VulkanContext.cpp +++ b/Source/Core/VideoBackends/Vulkan/VulkanContext.cpp @@ -153,7 +153,7 @@ bool VulkanContext::SelectInstanceExtensions(ExtensionList* extension_list, bool for (const auto& extension_properties : available_extension_list) INFO_LOG(VIDEO, "Available extension: %s", extension_properties.extensionName); - auto CheckForExtension = [&](const char* name, bool required) -> bool { + auto SupportsExtension = [&](const char* name, bool required) { if (std::find_if(available_extension_list.begin(), available_extension_list.end(), [&](const VkExtensionProperties& properties) { return !strcmp(name, properties.extensionName); @@ -165,36 +165,31 @@ bool VulkanContext::SelectInstanceExtensions(ExtensionList* extension_list, bool } if (required) - { ERROR_LOG(VIDEO, "Vulkan: Missing required extension %s.", name); - return false; - } - return true; + return false; }; // Common extensions - if (enable_surface && !CheckForExtension(VK_KHR_SURFACE_EXTENSION_NAME, true)) - { + if (enable_surface && !SupportsExtension(VK_KHR_SURFACE_EXTENSION_NAME, true)) return false; - } #if defined(VK_USE_PLATFORM_WIN32_KHR) - if (enable_surface && !CheckForExtension(VK_KHR_WIN32_SURFACE_EXTENSION_NAME, true)) + if (enable_surface && !SupportsExtension(VK_KHR_WIN32_SURFACE_EXTENSION_NAME, true)) return false; #elif defined(VK_USE_PLATFORM_XLIB_KHR) - if (enable_surface && !CheckForExtension(VK_KHR_XLIB_SURFACE_EXTENSION_NAME, true)) + if (enable_surface && !SupportsExtension(VK_KHR_XLIB_SURFACE_EXTENSION_NAME, true)) return false; #elif defined(VK_USE_PLATFORM_XCB_KHR) - if (enable_surface && !CheckForExtension(VK_KHR_XCB_SURFACE_EXTENSION_NAME, true)) + if (enable_surface && !SupportsExtension(VK_KHR_XCB_SURFACE_EXTENSION_NAME, true)) return false; #elif defined(VK_USE_PLATFORM_ANDROID_KHR) - if (enable_surface && !CheckForExtension(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME, true)) + if (enable_surface && !SupportsExtension(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME, true)) return false; #endif // VK_EXT_debug_report - if (enable_debug_report && !CheckForExtension(VK_EXT_DEBUG_REPORT_EXTENSION_NAME, true)) + if (enable_debug_report && !SupportsExtension(VK_EXT_DEBUG_REPORT_EXTENSION_NAME, false)) WARN_LOG(VIDEO, "Vulkan: Debug report requested, but extension is not available."); return true; @@ -403,8 +398,7 @@ bool VulkanContext::SelectDeviceExtensions(ExtensionList* extension_list, bool e for (const auto& extension_properties : available_extension_list) INFO_LOG(VIDEO, "Available extension: %s", extension_properties.extensionName); - auto CheckForExtension = [&](const char* name, bool required, - bool* has_extension = nullptr) -> bool { + auto SupportsExtension = [&](const char* name, bool required) { if (std::find_if(available_extension_list.begin(), available_extension_list.end(), [&](const VkExtensionProperties& properties) { return !strcmp(name, properties.extensionName); @@ -412,27 +406,19 @@ bool VulkanContext::SelectDeviceExtensions(ExtensionList* extension_list, bool e { INFO_LOG(VIDEO, "Enabling extension: %s", name); extension_list->push_back(name); - if (has_extension) - *has_extension = true; return true; } - if (has_extension) - *has_extension = false; - if (required) - { ERROR_LOG(VIDEO, "Vulkan: Missing required extension %s.", name); - return false; - } - return true; + return false; }; - if (enable_surface && !CheckForExtension(VK_KHR_SWAPCHAIN_EXTENSION_NAME, true)) + if (enable_surface && !SupportsExtension(VK_KHR_SWAPCHAIN_EXTENSION_NAME, true)) return false; - CheckForExtension(VK_NV_GLSL_SHADER_EXTENSION_NAME, false, &m_supports_nv_glsl_extension); + m_supports_nv_glsl_extension = SupportsExtension(VK_NV_GLSL_SHADER_EXTENSION_NAME, false); return true; }