Issue with SDL_Vulkan_GetDrawableSize()?

When creating a swapchain I use SDL_Vulkan_GetDrawableSize() to get information for the extent right before calling vkCreateSwapchainKHR(). This works fine until I drag-resize the window. When I drag-resize the window I tear down my swapchain and build it again calling SDL_Vulkan_GetDrawableSize() many times as I drag, but the validation layers start giving out messages like these:

vkCreateSwapchainKHR() called with imageExtent = (1194,720), which is outside the bounds returned by vkGetPhysicalDeviceSurfaceCapabilitiesKHR(): currentExtent = (1102,720), minImageExtent = (1102,720), maxImageExtent = (1102,720). The Vulkan spec states: imageExtent must be between minImageExtent and maxImageExtent, inclusive, where minImageExtent and maxImageExtent are members of the VkSurfaceCapabilitiesKHR structure returned by vkGetPhysicalDeviceSurfaceCapabilitiesKHR for the surface (https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#VUID-VkSwapchainCreateInfoKHR-imageExtent-01274)

At first I thought there might be a race condition between resizing the window and creating the supposedly new swapchain, but it works perfectly if I manually clamp the results returned by SDL_Vulkan_GetDrawableSize()

int width, height;
SDL_Vulkan_GetDrawableSize(win, &width, &height);
width = CLAMP(width, sc.capabilities.minImageExtent.width, sc.capabilities.maxImageExtent.width);
height = CLAMP(height, sc.capabilities.minImageExtent.height, sc.capabilities.maxImageExtent.height);
swapchainExtent.width = width;
swapchainExtent.height = height;

This code does not generate validation errors. Is this a bug in SDL_Vulkan_GetDrawableSize()? Should I just use the swapchain’s currentExtent and forego SDL_Vulkan_GetDrawableSize() altogether?

EDIT: Using SDL 2.0.9 on GNOME with proprietary NVIDIA drivers. IIRC the same thing happens on Intel with Mesa.
EDIT: Filed a bug report at https://bugzilla.libsdl.org/show_bug.cgi?id=4671

1 Like