From 698be4e09bf1f5b30600abef41e4be88a918da48 Mon Sep 17 00:00:00 2001 From: Charles Giessen Date: Tue, 19 May 2020 10:44:40 -0600 Subject: [PATCH] Fixed linux wsi extensions being added erroneously Previously, on linux all three windowing extensions would be added (xcb, xlib, wayland) even if they weren't available. Now, InstanceBuilder first makes sure they are present before adding them. Also added a new error code to represent the lack of wsi extensions --- src/VkBootstrap.cpp | 27 ++++++++++++++++++--------- src/VkBootstrap.h | 3 ++- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/VkBootstrap.cpp b/src/VkBootstrap.cpp index a89d568..870d3f3 100644 --- a/src/VkBootstrap.cpp +++ b/src/VkBootstrap.cpp @@ -241,6 +241,8 @@ const char* to_string (InstanceError err) { return "requested_layers_not_present"; case InstanceError::requested_extensions_not_present: return "requested_extensions_not_present"; + case InstanceError::windowing_extensions_not_present: + return "windowing_extensions_not_present"; default: return ""; } @@ -400,25 +402,32 @@ detail::Result InstanceBuilder::build () const { std::vector extensions; for (auto& ext : info.extensions) extensions.push_back (ext); - if (info.debug_callback != nullptr) { + if (info.debug_callback != nullptr && system.debug_utils_available) { extensions.push_back (VK_EXT_DEBUG_UTILS_EXTENSION_NAME); } if (!info.headless_context) { - extensions.push_back ("VK_KHR_surface"); + auto check_add_window_ext = [&] (const char* name) -> bool { + if (!detail::check_extension_supported(system.available_extensions, name)) + return false; + extensions.push_back(name); + return true; + }; + bool khr_surface_added = check_add_window_ext ("VK_KHR_surface"); #if defined(_WIN32) - extensions.push_back ("VK_KHR_win32_surface"); + bool added_window_exts = check_add_window_ext("VK_KHR_win32_surface"); #elif defined(__ANDROID__) - extensions.push_back ("VK_KHR_android_surface"); + bool added_window_exts = check_add_window_ext("VK_KHR_android_surface"); #elif defined(_DIRECT2DISPLAY) - extensions.push_back ("VK_KHR_display"); + bool added_window_exts = check_add_window_ext ("VK_KHR_display"); #elif defined(__linux__) - extensions.push_back ("VK_KHR_xcb_surface"); - extensions.push_back ("VK_KHR_xlib_surface"); - extensions.push_back ("VK_KHR_wayland_surface"); + bool added_window_exts = check_add_window_ext ("VK_KHR_xcb_surface") || check_add_window_ext ("VK_KHR_xlib_surface") || check_add_window_ext ("VK_KHR_wayland_surface"); #elif defined(__APPLE__) - extensions.push_back ("VK_KHR_metal_surface"); + bool added_window_exts = check_add_window_ext ("VK_KHR_metal_surface"); #endif + if (!khr_surface_added || !added_window_exts) + return make_error_code(InstanceError::windowing_extensions_not_present); + } bool all_extensions_supported = detail::check_extensions_supported (system.available_extensions, extensions); if (!all_extensions_supported) { diff --git a/src/VkBootstrap.h b/src/VkBootstrap.h index c3b2858..1048478 100644 --- a/src/VkBootstrap.h +++ b/src/VkBootstrap.h @@ -106,7 +106,8 @@ enum class InstanceError { failed_create_instance, failed_create_debug_messenger, requested_layers_not_present, - requested_extensions_not_present + requested_extensions_not_present, + windowing_extensions_not_present, }; enum class PhysicalDeviceError { no_surface_provided,