From 773e1ba19f655339b1ccb3300ddbb888278df3a9 Mon Sep 17 00:00:00 2001 From: David Gow Date: Sun, 8 Aug 2021 11:00:07 +0800 Subject: [PATCH] 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. --- test/testvulkan.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/test/testvulkan.c b/test/testvulkan.c index 620dd84ce..fe0cb79a2 100644 --- a/test/testvulkan.c +++ b/test/testvulkan.c @@ -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;