Fixed Validation Error for Zero MaxImageCount (#1844)

Correctly handle a zero max image count in VkSurfaceCapabilitiesKHR
which indicates no upper limit to the number of images in a swapchain.
Fixes validation error VUID-VkSwapchainCreateInfoKHR-minImageCount-01271
This commit is contained in:
Andrew H. Cox 2024-04-10 23:44:50 -07:00 committed by GitHub
parent 3134b1b42a
commit df42194eec
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 14 additions and 4 deletions

View File

@ -120,7 +120,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::SwapchainCreateInfoKHR swapChainCreateInfo( vk::SwapchainCreateFlagsKHR(),
surface,
vk::su::clamp( 3u, surfaceCapabilities.minImageCount, surfaceCapabilities.maxImageCount ),
vk::su::clampSurfaceImageCount( 3u, surfaceCapabilities.minImageCount, surfaceCapabilities.maxImageCount ),
format,
vk::ColorSpaceKHR::eSrgbNonlinear,
swapchainExtent,

View File

@ -123,7 +123,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::SwapchainCreateInfoKHR swapChainCreateInfo( vk::SwapchainCreateFlagsKHR(),
surface,
vk::su::clamp( 3u, surfaceCapabilities.minImageCount, surfaceCapabilities.maxImageCount ),
vk::su::clampSurfaceImageCount( 3u, surfaceCapabilities.minImageCount, surfaceCapabilities.maxImageCount ),
format,
vk::ColorSpaceKHR::eSrgbNonlinear,
swapchainExtent,

View File

@ -826,7 +826,7 @@ namespace vk
vk::PresentModeKHR presentMode = vk::su::pickPresentMode( physicalDevice.getSurfacePresentModesKHR( surface ) );
vk::SwapchainCreateInfoKHR swapChainCreateInfo( {},
surface,
vk::su::clamp( 3u, surfaceCapabilities.minImageCount, surfaceCapabilities.maxImageCount ),
vk::su::clampSurfaceImageCount( 3u, surfaceCapabilities.minImageCount, surfaceCapabilities.maxImageCount ),
colorFormat,
surfaceFormat.colorSpace,
swapchainExtent,

View File

@ -74,6 +74,16 @@ namespace vk
return v < lo ? lo : hi < v ? hi : v;
}
VULKAN_HPP_INLINE uint32_t clampSurfaceImageCount( const uint32_t desiredImageCount, const uint32_t minImageCount, const uint32_t maxImageCount )
{
uint32_t imageCount = std::max( desiredImageCount, minImageCount );
if( maxImageCount > 0 )
{
imageCount = std::min( imageCount, maxImageCount );
}
return imageCount;
}
void setImageLayout(
vk::CommandBuffer const & commandBuffer, vk::Image image, vk::Format format, vk::ImageLayout oldImageLayout, vk::ImageLayout newImageLayout );

View File

@ -195,7 +195,7 @@ vk::UniqueSwapchainKHR createSwapchainKHRUnique( vk::PhysicalDevice physicalDevi
: vk::CompositeAlphaFlagBitsKHR::eOpaque;
vk::SwapchainCreateInfoKHR swapChainCreateInfo( {},
surface,
vk::su::clamp( 3u, surfaceCapabilities.minImageCount, surfaceCapabilities.maxImageCount ),
vk::su::clampSurfaceImageCount( 3u, surfaceCapabilities.minImageCount, surfaceCapabilities.maxImageCount ),
surfaceFormat.format,
surfaceFormat.colorSpace,
swapchainExtent,