testvulkan: Clamp the drawable size to the allowed range

SDL_Vulkan_GetDrawableSize() doesn't always return a size which is
within the Vulkan swapchain's allowed image extent range.

(This happens on X11 a lot when resizing, which is bug #3287)

Clamp the value we get back from SDL_Vulkan_GetDrawableSize() to this
range. Given the range usually is just a single value, this is almost
always equivalent to just using the min or max image extent, but this
seems logically most correct.
This commit is contained in:
David Gow 2021-08-08 11:00:07 +08:00 committed by Sam Lantinga
parent 2e6dac870f
commit 773e1ba19f

View file

@ -719,8 +719,17 @@ static SDL_bool createSwapchain(void)
// get size
SDL_Vulkan_GetDrawableSize(state->windows[0], &w, &h);
vulkanContext.swapchainSize.width = w;
vulkanContext.swapchainSize.height = h;
// Clamp the size to the allowable image extent.
// SDL_Vulkan_GetDrawableSize()'s result it not always in this range (bug #3287)
vulkanContext.swapchainSize.width = SDL_max(vulkanContext.surfaceCapabilities.minImageExtent.width,
SDL_min(w,
vulkanContext.surfaceCapabilities.maxImageExtent.width));
vulkanContext.swapchainSize.height = SDL_max(vulkanContext.surfaceCapabilities.minImageExtent.height,
SDL_min(h,
vulkanContext.surfaceCapabilities.maxImageExtent.height));
if(w == 0 || h == 0)
return SDL_FALSE;