From 0c459dca6fa8b1e0e552e9835fdaac54220387a6 Mon Sep 17 00:00:00 2001 From: Charles Giessen Date: Mon, 9 Jan 2023 11:51:06 -0700 Subject: [PATCH] Add new error condition for DeviceBuilder If an application uses add_required_extension_features but also adds a VkPhysicalDeviceFeatures2 to the pNext chain of VkDeviceCreateInfo, this will now result in an error. The reason is that Vk-Bootstrap is perfectly capable of adding VkPhysicalDeviceFeatures to the pNext chain itself but only if the user didn't already add their own. --- src/VkBootstrap.cpp | 6 ++---- src/VkBootstrap.h | 3 +++ 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/VkBootstrap.cpp b/src/VkBootstrap.cpp index adda443..e33f8a8 100644 --- a/src/VkBootstrap.cpp +++ b/src/VkBootstrap.cpp @@ -1519,8 +1519,7 @@ Result DeviceBuilder::build() const { } } } else { - printf("User provided VkPhysicalDeviceFeatures2 instance found in pNext chain. All " - "requirements added via 'add_required_extension_features' will be ignored."); + return { DeviceError::VkPhysicalDeviceFeatures2_in_pNext_chain_while_using_add_required_extension_features }; } if (!user_defined_phys_dev_features_2 && !has_phys_dev_features_2) { @@ -1772,8 +1771,7 @@ Result SwapchainBuilder::build() const { image_count = surface_support.capabilities.maxImageCount; } - VkSurfaceFormatKHR surface_format = - detail::find_best_surface_format(surface_support.formats, desired_formats); + VkSurfaceFormatKHR surface_format = detail::find_best_surface_format(surface_support.formats, desired_formats); VkExtent2D extent = detail::find_extent(surface_support.capabilities, info.desired_width, info.desired_height); diff --git a/src/VkBootstrap.h b/src/VkBootstrap.h index a089346..f03294f 100644 --- a/src/VkBootstrap.h +++ b/src/VkBootstrap.h @@ -205,6 +205,7 @@ enum class QueueError { }; enum class DeviceError { failed_create_device, + VkPhysicalDeviceFeatures2_in_pNext_chain_while_using_add_required_extension_features, }; enum class SwapchainError { surface_handle_not_provided, @@ -594,6 +595,8 @@ class PhysicalDeviceSelector { PhysicalDeviceSelector& disable_portability_subset(); // Require a physical device which supports a specific set of general/extension features. + // If this function is used, the user should not put their own VkPhysicalDeviceFeatures2 in + // the pNext chain of VkDeviceCreateInfo. #if defined(VKB_VK_API_VERSION_1_1) template PhysicalDeviceSelector& add_required_extension_features(T const& features) { criteria.extended_features_chain.push_back(features);