@@ -2887,21 +2887,28 @@ Error RenderingDeviceDriverVulkan::swap_chain_resize(CommandQueueID p_cmd_queue,
28872887
28882888 // No swapchain yet, this is the first time we're creating it.
28892889 if (!swap_chain->vk_swapchain ) {
2890- uint32_t width = surface_capabilities.currentExtent .width ;
2891- uint32_t height = surface_capabilities.currentExtent .height ;
2890+ if (surface_capabilities.currentExtent .width == 0xFFFFFFFF ) {
2891+ // The current extent is currently undefined, so the current surface width and height will be clamped to the surface's capabilities.
2892+ // We make sure to overwrite surface_capabilities.currentExtent.width so that the same check further below
2893+ // does not set extent.width = CLAMP( surface->width, ... ) on the first run of this function, because
2894+ // that'd be potentially unswapped.
2895+ surface_capabilities.currentExtent .width = CLAMP (surface->width , surface_capabilities.minImageExtent .width , surface_capabilities.maxImageExtent .width );
2896+ surface_capabilities.currentExtent .height = CLAMP (surface->height , surface_capabilities.minImageExtent .height , surface_capabilities.maxImageExtent .height );
2897+ }
2898+
2899+ // We must SWAP() only once otherwise we'll keep ping-ponging between
2900+ // the right and wrong resolutions after multiple calls to swap_chain_resize().
28922901 if (surface_capabilities.currentTransform & VK_SURFACE_TRANSFORM_ROTATE_90_BIT_KHR ||
28932902 surface_capabilities.currentTransform & VK_SURFACE_TRANSFORM_ROTATE_270_BIT_KHR) {
28942903 // Swap to get identity width and height.
2895- surface_capabilities.currentExtent .height = width;
2896- surface_capabilities.currentExtent .width = height;
2904+ SWAP (surface_capabilities.currentExtent .width , surface_capabilities.currentExtent .height );
28972905 }
2898-
2899- native_display_size = surface_capabilities.currentExtent ;
29002906 }
29012907
29022908 VkExtent2D extent;
29032909 if (surface_capabilities.currentExtent .width == 0xFFFFFFFF ) {
29042910 // The current extent is currently undefined, so the current surface width and height will be clamped to the surface's capabilities.
2911+ // We can only be here on the second call to swap_chain_resize(), by which time surface->width & surface->height should already be swapped if needed.
29052912 extent.width = CLAMP (surface->width , surface_capabilities.minImageExtent .width , surface_capabilities.maxImageExtent .width );
29062913 extent.height = CLAMP (surface->height , surface_capabilities.minImageExtent .height , surface_capabilities.maxImageExtent .height );
29072914 } else {
@@ -2991,7 +2998,7 @@ Error RenderingDeviceDriverVulkan::swap_chain_resize(CommandQueueID p_cmd_queue,
29912998 swap_create_info.minImageCount = desired_swapchain_images;
29922999 swap_create_info.imageFormat = swap_chain->format ;
29933000 swap_create_info.imageColorSpace = swap_chain->color_space ;
2994- swap_create_info.imageExtent = native_display_size ;
3001+ swap_create_info.imageExtent = extent ;
29953002 swap_create_info.imageArrayLayers = 1 ;
29963003 swap_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
29973004 swap_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
0 commit comments