diff --git a/src/VkBootstrap.cpp b/src/VkBootstrap.cpp index 75f3c54..41ea018 100644 --- a/src/VkBootstrap.cpp +++ b/src/VkBootstrap.cpp @@ -443,7 +443,7 @@ const char* to_string(SwapchainError err) { CASE_TO_STRING(SwapchainError, failed_get_swapchain_images) CASE_TO_STRING(SwapchainError, failed_create_swapchain_image_views) CASE_TO_STRING(SwapchainError, required_min_image_count_too_low) - CASE_TO_STRING(SwapchainError, required_usage_or_features_not_supported) + CASE_TO_STRING(SwapchainError, required_usage_not_supported) default: return ""; } @@ -1585,8 +1585,7 @@ enum class SurfaceSupportError { surface_handle_null, failed_get_surface_capabilities, failed_enumerate_surface_formats, - failed_enumerate_present_modes, - no_suitable_format + failed_enumerate_present_modes }; struct SurfaceSupportErrorCategory : std::error_category { @@ -1633,7 +1632,7 @@ Result query_surface_support_details(VkPhysicalDevice phy return SurfaceSupportDetails{ capabilities, formats, present_modes }; } -Result find_surface_format(VkPhysicalDevice phys_device, +VkSurfaceFormatKHR find_surface_format(VkPhysicalDevice phys_device, std::vector const& available_formats, std::vector const& desired_formats, VkFormatFeatureFlags feature_flags) { @@ -1648,8 +1647,8 @@ Result find_surface_format(VkPhysicalDevice phys_device, } } - // If no format supports the provided feature, we report that no format is suitable to the user request - return { make_error_code(SurfaceSupportError::no_suitable_format) }; + // use the first available one if any desired formats aren't found + return available_formats[0]; } VkPresentModeKHR find_present_mode(std::vector const& available_resent_modes, @@ -1772,10 +1771,8 @@ Result SwapchainBuilder::build() const { image_count = surface_support.capabilities.maxImageCount; } - auto surface_format_ret = + VkSurfaceFormatKHR surface_format = detail::find_surface_format(info.physical_device, surface_support.formats, desired_formats, info.format_feature_flags); - if (!surface_format_ret.has_value()) return Error{ SwapchainError::required_usage_or_features_not_supported }; - auto surface_format = surface_format_ret.value(); VkExtent2D extent = detail::find_extent(surface_support.capabilities, info.desired_width, info.desired_height); @@ -1791,7 +1788,7 @@ Result SwapchainBuilder::build() const { if (detail::is_unextended_present_mode(present_mode) && (info.image_usage_flags & surface_support.capabilities.supportedUsageFlags) != info.image_usage_flags) { - return Error{ SwapchainError::required_usage_or_features_not_supported }; + return Error{ SwapchainError::required_usage_not_supported }; } VkSurfaceTransformFlagBitsKHR pre_transform = info.pre_transform; diff --git a/src/VkBootstrap.h b/src/VkBootstrap.h index 256bfc7..79e70d0 100644 --- a/src/VkBootstrap.h +++ b/src/VkBootstrap.h @@ -213,7 +213,7 @@ enum class SwapchainError { failed_get_swapchain_images, failed_create_swapchain_image_views, required_min_image_count_too_low, - required_usage_or_features_not_supported + required_usage_not_supported }; std::error_code make_error_code(InstanceError instance_error); @@ -851,9 +851,8 @@ class SwapchainBuilder { SwapchainBuilder& use_default_image_usage_flags(); // Set the bitmask of the format feature flag for acquired swapchain images. - // If the desired formats cannot allow it, building the swapchain will result in the - // `SwapchainError::required_usage_or_features_not_supported` error. Use this functionnality only if you require - // formats to support a set of feature flags that are not already implied by set_image_usage_flags + // Use this functionnality only if you require formats to support a set of feature flags + // that are not already implied by set_image_usage_flags SwapchainBuilder& set_format_feature_flags(VkFormatFeatureFlags feature_flags); // Add a format feature to the bitmask for acquired swapchain images. SwapchainBuilder& add_format_feature_flags(VkFormatFeatureFlags feature_flags); diff --git a/tests/bootstrap_tests.cpp b/tests/bootstrap_tests.cpp index e0a367d..24fbe84 100644 --- a/tests/bootstrap_tests.cpp +++ b/tests/bootstrap_tests.cpp @@ -305,7 +305,6 @@ TEST_CASE("Swapchain", "[VkBootstrap.bootstrap]") { vkb::SwapchainBuilder swapchain_builder(device); auto swapchain_ret = swapchain_builder.set_desired_extent(256, 256) .set_desired_format({ VK_FORMAT_R8G8B8A8_UNORM, VK_COLOR_SPACE_SRGB_NONLINEAR_KHR }) - .add_fallback_format({ VK_FORMAT_B8G8R8A8_UNORM, VK_COLOR_SPACE_SRGB_NONLINEAR_KHR }) .set_desired_present_mode(VK_PRESENT_MODE_IMMEDIATE_KHR) .set_pre_transform_flags(VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR) .set_composite_alpha_flags(VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR)