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`.
This commit is contained in:
Charles Giessen 2022-02-19 13:11:10 -07:00 committed by Charles Giessen
parent d3170c0657
commit 65071da181
2 changed files with 24 additions and 0 deletions

View File

@ -1182,11 +1182,20 @@ detail::Result<std::vector<PhysicalDevice>> 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<std::vector<PhysicalDevice>> 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;

View File

@ -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 <typename T> 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,