From 8d4ac0db50970c7f39ac386a185670c0fecab1b6 Mon Sep 17 00:00:00 2001 From: Mehmet Oguz Derin Date: Tue, 6 Apr 2021 19:01:34 +0300 Subject: [PATCH] Check usage flags when iterating desired formats --- src/VkBootstrap.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/VkBootstrap.cpp b/src/VkBootstrap.cpp index 0965698..c5bdfc6 100644 --- a/src/VkBootstrap.cpp +++ b/src/VkBootstrap.cpp @@ -1603,14 +1603,20 @@ Result query_surface_support_details(VkPhysicalDevice phy return SurfaceSupportDetails{ capabilities, formats, present_modes }; } -VkSurfaceFormatKHR find_surface_format(std::vector const& available_formats, - std::vector const& desired_formats) { +VkSurfaceFormatKHR find_surface_format(VkPhysicalDevice phys_device, + std::vector const& available_formats, + std::vector const& desired_formats, + VkImageUsageFlags usage_flags) { for (auto const& desired_format : desired_formats) { for (auto const& available_format : available_formats) { // finds the first format that is desired and available if (desired_format.format == available_format.format && desired_format.colorSpace == available_format.colorSpace) { - return desired_format; + VkFormatProperties properties; + detail::vulkan_functions().fp_vkGetPhysicalDeviceFormatProperties( + phys_device, desired_format.format, &properties); + if ((properties.optimalTilingFeatures & usage_flags) == usage_flags) + return desired_format; } } } @@ -1720,7 +1726,8 @@ detail::Result SwapchainBuilder::build() const { if (surface_support.capabilities.maxImageCount > 0 && image_count > surface_support.capabilities.maxImageCount) { image_count = surface_support.capabilities.maxImageCount; } - VkSurfaceFormatKHR surface_format = detail::find_surface_format(surface_support.formats, desired_formats); + VkSurfaceFormatKHR surface_format = detail::find_surface_format( + info.physical_device, surface_support.formats, desired_formats, info.image_usage_flags); VkExtent2D extent = detail::find_extent(surface_support.capabilities, info.desired_width, info.desired_height);