From 244a44da51e1f7c6c999b3c9d051190964f5dae7 Mon Sep 17 00:00:00 2001 From: Charles Giessen Date: Thu, 10 Jun 2021 10:43:19 -0600 Subject: [PATCH] Guard vkGetPhysicalDeviceFeatures2 behind instance version Also make it so that instance extensions are queried in the instance only. --- src/VkBootstrap.cpp | 20 +++++++------------- src/VkBootstrap.h | 2 +- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/src/VkBootstrap.cpp b/src/VkBootstrap.cpp index bd2c5a6..26f77fc 100644 --- a/src/VkBootstrap.cpp +++ b/src/VkBootstrap.cpp @@ -618,8 +618,9 @@ detail::Result InstanceBuilder::build() const { if (info.debug_callback != nullptr && system.debug_utils_available) { extensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); } - if (detail::check_extension_supported( - system.available_extensions, VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME)) { + bool supports_properties2_ext = detail::check_extension_supported( + system.available_extensions, VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME); + if (supports_properties2_ext) { extensions.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME); } @@ -731,9 +732,8 @@ detail::Result InstanceBuilder::build() const { } } - if (info.headless_context) { - instance.headless = true; - } + instance.headless = info.headless_context; + instance.supports_properties2_ext = supports_properties2_ext; instance.allocation_callbacks = info.allocation_callbacks; instance.instance_version = api_version; instance.fp_vkGetInstanceProcAddr = detail::vulkan_functions().ptr_vkGetInstanceProcAddr; @@ -1020,7 +1020,7 @@ PhysicalDeviceSelector::PhysicalDeviceDesc PhysicalDeviceSelector::populate_devi VkPhysicalDeviceFeatures2 local_features{}; local_features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2; local_features.pNext = &fill_chain.front(); - if (desc.device_properties.apiVersion >= VK_API_VERSION_1_1) { + if (instance_info.version >= VK_API_VERSION_1_1 && desc.device_properties.apiVersion >= VK_API_VERSION_1_1) { detail::vulkan_functions().fp_vkGetPhysicalDeviceFeatures2(phys_device, &local_features); } else if (instance_info.supports_properties2_ext) { detail::vulkan_functions().fp_vkGetPhysicalDeviceFeatures2KHR(phys_device, &local_features); @@ -1134,13 +1134,10 @@ PhysicalDeviceSelector::PhysicalDeviceSelector(Instance const& instance) { instance_info.instance = instance.instance; instance_info.headless = instance.headless; instance_info.version = instance.instance_version; + instance_info.supports_properties2_ext = instance.supports_properties2_ext; criteria.require_present = !instance.headless; criteria.required_version = instance.instance_version; criteria.desired_version = instance.instance_version; - detail::get_vector( - instance_info.extensions, detail::vulkan_functions().fp_vkEnumerateInstanceExtensionProperties, nullptr); - instance_info.supports_properties2_ext = detail::check_extension_supported( - instance_info.extensions, VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME); } detail::Result PhysicalDeviceSelector::select() const { @@ -1149,9 +1146,6 @@ detail::Result PhysicalDeviceSelector::select() const { return detail::Result{ PhysicalDeviceError::no_surface_provided }; } - - - std::vector physical_devices; auto physical_devices_ret = detail::get_vector( diff --git a/src/VkBootstrap.h b/src/VkBootstrap.h index e276838..4bb0fce 100644 --- a/src/VkBootstrap.h +++ b/src/VkBootstrap.h @@ -219,6 +219,7 @@ struct Instance { private: bool headless = false; + bool supports_properties2_ext = false; uint32_t instance_version = VK_MAKE_VERSION(1, 0, 0); friend class InstanceBuilder; @@ -474,7 +475,6 @@ class PhysicalDeviceSelector { VkInstance instance = VK_NULL_HANDLE; VkSurfaceKHR surface = VK_NULL_HANDLE; uint32_t version = VK_MAKE_VERSION(1, 0, 0); - std::vector extensions; bool headless = false; bool supports_properties2_ext = false; } instance_info;