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
This commit is contained in:
Jeroen Bakker
2025-05-16 08:47:04 +02:00
parent 1232d64681
commit 606d24d88a

View File

@@ -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) {