From 7cd7a6ab164f887b2831b3dba18e936e40e67d25 Mon Sep 17 00:00:00 2001 From: Charles Giessen Date: Sat, 19 Feb 2022 13:11:10 -0700 Subject: [PATCH] Enable VK_KHR_portability_subset if available Makes it easy to use vulkan on macOS since vk-bootstrap will auto-enable it if the extension is available. This can be disabled by calling `disable_portability_subset`. --- src/VkBootstrap.cpp | 19 +++++++++++++++++++ src/VkBootstrap.h | 5 +++++ 2 files changed, 24 insertions(+) diff --git a/src/VkBootstrap.cpp b/src/VkBootstrap.cpp index 573bdea..df297c8 100644 --- a/src/VkBootstrap.cpp +++ b/src/VkBootstrap.cpp @@ -1182,11 +1182,20 @@ detail::Result> PhysicalDeviceSelector::select_impl( auto fill_out_phys_dev_with_criteria = [&](PhysicalDevice& phys_dev) { phys_dev.features = criteria.required_features; phys_dev.extended_features_chain = criteria.extended_features_chain; + bool portability_ext_available = false; + for (const auto& ext : phys_dev.extensions) + if (criteria.enable_portability_subset && ext == "VK_KHR_portability_subset") + portability_ext_available = true; + + phys_dev.extensions.clear(); phys_dev.extensions.insert( phys_dev.extensions.end(), criteria.required_extensions.begin(), criteria.required_extensions.end()); auto desired_extensions_supported = detail::check_device_extension_support(phys_dev.extensions, criteria.desired_extensions); phys_dev.extensions.insert( phys_dev.extensions.end(), desired_extensions_supported.begin(), desired_extensions_supported.end()); + if (portability_ext_available) { + phys_dev.extensions.push_back("VK_KHR_portability_subset"); + } }; // if this option is set, always return only the first physical device found @@ -1216,6 +1225,11 @@ detail::Result> PhysicalDeviceSelector::select_impl( physical_devices.erase(partition_index, physical_devices.end() - 1); } + // Make the physical device ready to be used to create a Device from it + for (auto& physical_device : physical_devices) { + fill_out_phys_dev_with_criteria(physical_device); + } + return physical_devices; } @@ -1324,6 +1338,11 @@ PhysicalDeviceSelector& PhysicalDeviceSelector::set_desired_version(uint32_t maj criteria.desired_version = VKB_MAKE_VK_VERSION(0, major, minor, 0); return *this; } +PhysicalDeviceSelector& PhysicalDeviceSelector::disable_portability_subset() { + criteria.enable_portability_subset = false; + return *this; +} + PhysicalDeviceSelector& PhysicalDeviceSelector::set_required_features(VkPhysicalDeviceFeatures const& features) { criteria.required_features = features; return *this; diff --git a/src/VkBootstrap.h b/src/VkBootstrap.h index 8c7cbd8..61b116d 100644 --- a/src/VkBootstrap.h +++ b/src/VkBootstrap.h @@ -580,6 +580,10 @@ class PhysicalDeviceSelector { // Require a physical device that supports a (major, minor) version of vulkan. PhysicalDeviceSelector& set_minimum_version(uint32_t major, uint32_t minor); + // By default PhysicalDeviceSelector enables the portability subset if available + // This function disables that behavior + PhysicalDeviceSelector& disable_portability_subset(); + // Require a physical device which supports a specific set of general/extension features. #if defined(VKB_VK_API_VERSION_1_1) template PhysicalDeviceSelector& add_required_extension_features(T const& features) { @@ -648,6 +652,7 @@ class PhysicalDeviceSelector { #endif bool defer_surface_initialization = false; bool use_first_gpu_unconditionally = false; + bool enable_portability_subset = true; } criteria; PhysicalDevice populate_device_details(VkPhysicalDevice phys_device,