From 606d24d88af1197704acb047af5f4fe46e4dc8d6 Mon Sep 17 00:00:00 2001 From: Jeroen Bakker Date: Fri, 16 May 2025 08:47:04 +0200 Subject: [PATCH] Fix #138942: Vulkan: Use different scaling on first swapchain First time a swap chain is created an incorrect resolution can be reported back by the driver as the window is still initializing. We stretch the swap chain to cover to reduce a black line rendering in top of the window (due to content flipping). Any subsequent frame will not do stretching to reduce artifacts when resizing the window. Pull Request: https://projects.blender.org/blender/blender/pulls/138964 --- intern/ghost/intern/GHOST_ContextVK.cc | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/intern/ghost/intern/GHOST_ContextVK.cc b/intern/ghost/intern/GHOST_ContextVK.cc index bd422872035..61e8f3bcdd7 100644 --- a/intern/ghost/intern/GHOST_ContextVK.cc +++ b/intern/ghost/intern/GHOST_ContextVK.cc @@ -948,20 +948,27 @@ GHOST_TSuccess GHOST_ContextVK::recreateSwapchain() image_count_requested = capabilities.maxImageCount; } + VkSwapchainKHR old_swapchain = m_swapchain; + + /* First time we stretch the swapchain image as it can happen that the first frame size isn't + * correctly reported by the initial swapchain. All subsequent creations will use one to one as + * that can reduce resizing artifacts. */ + VkPresentScalingFlagBitsEXT vk_present_scaling = old_swapchain == VK_NULL_HANDLE ? + VK_PRESENT_SCALING_STRETCH_BIT_EXT : + VK_PRESENT_SCALING_ONE_TO_ONE_BIT_EXT; + VkSwapchainPresentModesCreateInfoEXT vk_swapchain_present_modes = { VK_STRUCTURE_TYPE_SWAPCHAIN_PRESENT_MODES_CREATE_INFO_EXT, nullptr, 1, &present_mode}; VkSwapchainPresentScalingCreateInfoEXT vk_swapchain_present_scaling = { VK_STRUCTURE_TYPE_SWAPCHAIN_PRESENT_SCALING_CREATE_INFO_EXT, &vk_swapchain_present_modes, - vk_surface_present_scaling_capabilities.supportedPresentScaling & - VK_PRESENT_SCALING_ONE_TO_ONE_BIT_EXT, + vk_surface_present_scaling_capabilities.supportedPresentScaling & vk_present_scaling, vk_surface_present_scaling_capabilities.supportedPresentGravityX & VK_PRESENT_GRAVITY_MIN_BIT_EXT, vk_surface_present_scaling_capabilities.supportedPresentGravityY & VK_PRESENT_GRAVITY_MAX_BIT_EXT, }; - VkSwapchainKHR old_swapchain = m_swapchain; VkSwapchainCreateInfoKHR create_info = {}; create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; if (vulkan_device->use_vk_ext_swapchain_maintenance_1) {