Vulkan: Improve readability of device/instance extension checks

This commit is contained in:
Stenzek 2017-10-11 23:15:08 +10:00
parent 79188d4f55
commit 06bbf111d9
1 changed files with 12 additions and 26 deletions

View File

@ -153,7 +153,7 @@ bool VulkanContext::SelectInstanceExtensions(ExtensionList* extension_list, bool
for (const auto& extension_properties : available_extension_list) for (const auto& extension_properties : available_extension_list)
INFO_LOG(VIDEO, "Available extension: %s", extension_properties.extensionName); 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(), if (std::find_if(available_extension_list.begin(), available_extension_list.end(),
[&](const VkExtensionProperties& properties) { [&](const VkExtensionProperties& properties) {
return !strcmp(name, properties.extensionName); return !strcmp(name, properties.extensionName);
@ -165,36 +165,31 @@ bool VulkanContext::SelectInstanceExtensions(ExtensionList* extension_list, bool
} }
if (required) if (required)
{
ERROR_LOG(VIDEO, "Vulkan: Missing required extension %s.", name); ERROR_LOG(VIDEO, "Vulkan: Missing required extension %s.", name);
return false;
}
return true; return false;
}; };
// Common extensions // Common extensions
if (enable_surface && !CheckForExtension(VK_KHR_SURFACE_EXTENSION_NAME, true)) if (enable_surface && !SupportsExtension(VK_KHR_SURFACE_EXTENSION_NAME, true))
{
return false; return false;
}
#if defined(VK_USE_PLATFORM_WIN32_KHR) #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; return false;
#elif defined(VK_USE_PLATFORM_XLIB_KHR) #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; return false;
#elif defined(VK_USE_PLATFORM_XCB_KHR) #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; return false;
#elif defined(VK_USE_PLATFORM_ANDROID_KHR) #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; return false;
#endif #endif
// VK_EXT_debug_report // 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."); WARN_LOG(VIDEO, "Vulkan: Debug report requested, but extension is not available.");
return true; return true;
@ -403,8 +398,7 @@ bool VulkanContext::SelectDeviceExtensions(ExtensionList* extension_list, bool e
for (const auto& extension_properties : available_extension_list) for (const auto& extension_properties : available_extension_list)
INFO_LOG(VIDEO, "Available extension: %s", extension_properties.extensionName); INFO_LOG(VIDEO, "Available extension: %s", extension_properties.extensionName);
auto CheckForExtension = [&](const char* name, bool required, auto SupportsExtension = [&](const char* name, bool required) {
bool* has_extension = nullptr) -> bool {
if (std::find_if(available_extension_list.begin(), available_extension_list.end(), if (std::find_if(available_extension_list.begin(), available_extension_list.end(),
[&](const VkExtensionProperties& properties) { [&](const VkExtensionProperties& properties) {
return !strcmp(name, properties.extensionName); return !strcmp(name, properties.extensionName);
@ -412,27 +406,19 @@ bool VulkanContext::SelectDeviceExtensions(ExtensionList* extension_list, bool e
{ {
INFO_LOG(VIDEO, "Enabling extension: %s", name); INFO_LOG(VIDEO, "Enabling extension: %s", name);
extension_list->push_back(name); extension_list->push_back(name);
if (has_extension)
*has_extension = true;
return true; return true;
} }
if (has_extension)
*has_extension = false;
if (required) if (required)
{
ERROR_LOG(VIDEO, "Vulkan: Missing required extension %s.", name); 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; 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; return true;
} }