Commit 773e1ba19f655339b1ccb3300ddbb888278df3a9

David Gow 2021-08-08T11:00:07

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.

diff --git a/test/testvulkan.c b/test/testvulkan.c
index 620dd84..fe0cb79 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;