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.
This commit is contained in:
Charles Giessen 2023-01-09 11:51:06 -07:00 committed by Charles Giessen
parent 9b3e648141
commit 0c459dca6f
2 changed files with 5 additions and 4 deletions

View File

@ -1519,8 +1519,7 @@ Result<Device> DeviceBuilder::build() const {
} }
} }
} else { } else {
printf("User provided VkPhysicalDeviceFeatures2 instance found in pNext chain. All " return { DeviceError::VkPhysicalDeviceFeatures2_in_pNext_chain_while_using_add_required_extension_features };
"requirements added via 'add_required_extension_features' will be ignored.");
} }
if (!user_defined_phys_dev_features_2 && !has_phys_dev_features_2) { if (!user_defined_phys_dev_features_2 && !has_phys_dev_features_2) {
@ -1772,8 +1771,7 @@ Result<Swapchain> SwapchainBuilder::build() const {
image_count = surface_support.capabilities.maxImageCount; image_count = surface_support.capabilities.maxImageCount;
} }
VkSurfaceFormatKHR surface_format = VkSurfaceFormatKHR surface_format = detail::find_best_surface_format(surface_support.formats, desired_formats);
detail::find_best_surface_format(surface_support.formats, desired_formats);
VkExtent2D extent = detail::find_extent(surface_support.capabilities, info.desired_width, info.desired_height); VkExtent2D extent = detail::find_extent(surface_support.capabilities, info.desired_width, info.desired_height);

View File

@ -205,6 +205,7 @@ enum class QueueError {
}; };
enum class DeviceError { enum class DeviceError {
failed_create_device, failed_create_device,
VkPhysicalDeviceFeatures2_in_pNext_chain_while_using_add_required_extension_features,
}; };
enum class SwapchainError { enum class SwapchainError {
surface_handle_not_provided, surface_handle_not_provided,
@ -594,6 +595,8 @@ class PhysicalDeviceSelector {
PhysicalDeviceSelector& disable_portability_subset(); PhysicalDeviceSelector& disable_portability_subset();
// Require a physical device which supports a specific set of general/extension features. // 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) #if defined(VKB_VK_API_VERSION_1_1)
template <typename T> PhysicalDeviceSelector& add_required_extension_features(T const& features) { template <typename T> PhysicalDeviceSelector& add_required_extension_features(T const& features) {
criteria.extended_features_chain.push_back(features); criteria.extended_features_chain.push_back(features);