From aa657247ce8e4da53503c584a7a869a87b45f9fb Mon Sep 17 00:00:00 2001 From: antonino Date: Mon, 21 Aug 2023 22:50:34 +0200 Subject: [PATCH] vulkan/wsi: add `vk_wsi_force_swapchain_to_current_extent` driconf Add a driconf to force the swapchain size to match `VkSurfaceCapabilities2KHR::currentExtent` as a workaround for misbehaved games Fixes: 6139493ae38 ("vulkan/wsi: return VK_SUBOPTIMAL_KHR for sw/x11 on window resize") Reviewed-by: Mike Blumenkrantz Part-of: --- src/amd/vulkan/radv_instance.c | 1 + src/freedreno/vulkan/tu_device.cc | 1 + src/intel/vulkan/anv_device.c | 1 + src/intel/vulkan_hasvk/anv_device.c | 1 + src/microsoft/vulkan/dzn_device.c | 1 + src/util/driconf.h | 4 ++++ src/virtio/vulkan/vn_instance.c | 1 + src/vulkan/wsi/wsi_common.c | 17 ++++++++++++++++- src/vulkan/wsi/wsi_common.h | 2 ++ 9 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/amd/vulkan/radv_instance.c b/src/amd/vulkan/radv_instance.c index 7b07da3..d31a719 100644 --- a/src/amd/vulkan/radv_instance.c +++ b/src/amd/vulkan/radv_instance.c @@ -135,6 +135,7 @@ static const driOptionDescription radv_dri_options[] = { DRI_CONF_SECTION_DEBUG DRI_CONF_OVERRIDE_VRAM_SIZE() DRI_CONF_VK_WSI_FORCE_BGRA8_UNORM_FIRST(false) + DRI_CONF_VK_WSI_FORCE_SWAPCHAIN_TO_CURRENT_EXTENT(false) DRI_CONF_RADV_ZERO_VRAM(false) DRI_CONF_RADV_LOWER_DISCARD_TO_DEMOTE(false) DRI_CONF_RADV_INVARIANT_GEOM(false) diff --git a/src/freedreno/vulkan/tu_device.cc b/src/freedreno/vulkan/tu_device.cc index e977824..78786b6 100644 --- a/src/freedreno/vulkan/tu_device.cc +++ b/src/freedreno/vulkan/tu_device.cc @@ -745,6 +745,7 @@ static const driOptionDescription tu_dri_options[] = { DRI_CONF_SECTION_DEBUG DRI_CONF_VK_WSI_FORCE_BGRA8_UNORM_FIRST(false) + DRI_CONF_VK_WSI_FORCE_SWAPCHAIN_TO_CURRENT_EXTENT(false) DRI_CONF_VK_DONT_CARE_AS_LOAD(false) DRI_CONF_SECTION_END diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c index 0602da7..448b7a1 100644 --- a/src/intel/vulkan/anv_device.c +++ b/src/intel/vulkan/anv_device.c @@ -88,6 +88,7 @@ static const driOptionDescription anv_dri_options[] = { DRI_CONF_SECTION_DEBUG DRI_CONF_ALWAYS_FLUSH_CACHE(false) DRI_CONF_VK_WSI_FORCE_BGRA8_UNORM_FIRST(false) + DRI_CONF_VK_WSI_FORCE_SWAPCHAIN_TO_CURRENT_EXTENT(false) DRI_CONF_LIMIT_TRIG_INPUT_RANGE(false) DRI_CONF_ANV_MESH_CONV_PRIM_ATTRS_TO_VERT_ATTRS(-2) DRI_CONF_FORCE_VK_VENDOR(0) diff --git a/src/intel/vulkan_hasvk/anv_device.c b/src/intel/vulkan_hasvk/anv_device.c index 5b4371a..0016c40 100644 --- a/src/intel/vulkan_hasvk/anv_device.c +++ b/src/intel/vulkan_hasvk/anv_device.c @@ -75,6 +75,7 @@ static const driOptionDescription anv_dri_options[] = { DRI_CONF_SECTION_DEBUG DRI_CONF_ALWAYS_FLUSH_CACHE(false) DRI_CONF_VK_WSI_FORCE_BGRA8_UNORM_FIRST(false) + DRI_CONF_VK_WSI_FORCE_SWAPCHAIN_TO_CURRENT_EXTENT(false) DRI_CONF_LIMIT_TRIG_INPUT_RANGE(false) DRI_CONF_SECTION_END diff --git a/src/microsoft/vulkan/dzn_device.c b/src/microsoft/vulkan/dzn_device.c index f6189b7..a11a482 100644 --- a/src/microsoft/vulkan/dzn_device.c +++ b/src/microsoft/vulkan/dzn_device.c @@ -1442,6 +1442,7 @@ static const driOptionDescription dzn_dri_options[] = { DRI_CONF_SECTION_DEBUG DRI_CONF_DZN_CLAIM_WIDE_LINES(false) DRI_CONF_DZN_ENABLE_8BIT_LOADS_STORES(false) + DRI_CONF_VK_WSI_FORCE_SWAPCHAIN_TO_CURRENT_EXTENT(false) DRI_CONF_SECTION_END }; diff --git a/src/util/driconf.h b/src/util/driconf.h index 009fcce..3c598c9 100644 --- a/src/util/driconf.h +++ b/src/util/driconf.h @@ -394,6 +394,10 @@ DRI_CONF_OPT_B(vk_wsi_force_bgra8_unorm_first, def, \ "Force vkGetPhysicalDeviceSurfaceFormatsKHR to return VK_FORMAT_B8G8R8A8_UNORM as the first format") +#define DRI_CONF_VK_WSI_FORCE_SWAPCHAIN_TO_CURRENT_EXTENT(def) \ + DRI_CONF_OPT_B(vk_wsi_force_swapchain_to_current_extent, def, \ + "Force VkSwapchainCreateInfoKHR::imageExtent to be VkSurfaceCapabilities2KHR::currentExtent") + #define DRI_CONF_VK_X11_OVERRIDE_MIN_IMAGE_COUNT(def) \ DRI_CONF_OPT_I(vk_x11_override_min_image_count, def, 0, 999, \ "Override the VkSurfaceCapabilitiesKHR::minImageCount (0 = no override)") diff --git a/src/virtio/vulkan/vn_instance.c b/src/virtio/vulkan/vn_instance.c index 233a261..29aae7b 100644 --- a/src/virtio/vulkan/vn_instance.c +++ b/src/virtio/vulkan/vn_instance.c @@ -63,6 +63,7 @@ static const driOptionDescription vn_dri_options[] = { DRI_CONF_SECTION_END DRI_CONF_SECTION_DEBUG DRI_CONF_VK_WSI_FORCE_BGRA8_UNORM_FIRST(false) + DRI_CONF_VK_WSI_FORCE_SWAPCHAIN_TO_CURRENT_EXTENT(false) DRI_CONF_SECTION_END /* clang-format on */ }; diff --git a/src/vulkan/wsi/wsi_common.c b/src/vulkan/wsi/wsi_common.c index 4e848dd..27fd4ed 100644 --- a/src/vulkan/wsi/wsi_common.c +++ b/src/vulkan/wsi/wsi_common.c @@ -240,6 +240,11 @@ wsi_device_init(struct wsi_device *wsi, wsi->force_bgra8_unorm_first = driQueryOptionb(dri_options, "vk_wsi_force_bgra8_unorm_first"); } + + if (driCheckOption(dri_options, "vk_wsi_force_swapchain_to_current_extent", DRI_BOOL)) { + wsi->force_swapchain_to_currentExtent = + driQueryOptionb(dri_options, "vk_wsi_force_swapchain_to_current_extent"); + } } return VK_SUCCESS; @@ -923,12 +928,22 @@ wsi_CreateSwapchainKHR(VkDevice _device, else alloc = &device->alloc; + VkSwapchainCreateInfoKHR info = *pCreateInfo; + + if (wsi_device->force_swapchain_to_currentExtent) { + VkSurfaceCapabilities2KHR caps2 = { + .sType = VK_STRUCTURE_TYPE_SURFACE_CAPABILITIES_2_KHR, + }; + iface->get_capabilities2(surface, wsi_device, NULL, &caps2); + info.imageExtent = caps2.surfaceCapabilities.currentExtent; + } + /* Ignore DEFERRED_MEMORY_ALLOCATION_BIT. Would require deep plumbing to be able to take advantage of it. * bool deferred_allocation = pCreateInfo->flags & VK_SWAPCHAIN_CREATE_DEFERRED_MEMORY_ALLOCATION_BIT_EXT; */ VkResult result = iface->create_swapchain(surface, _device, wsi_device, - pCreateInfo, alloc, + &info, alloc, &swapchain); if (result != VK_SUCCESS) return result; diff --git a/src/vulkan/wsi/wsi_common.h b/src/vulkan/wsi/wsi_common.h index fc30bee..8fe8fb9 100644 --- a/src/vulkan/wsi/wsi_common.h +++ b/src/vulkan/wsi/wsi_common.h @@ -135,6 +135,8 @@ struct wsi_device { /* Create headless swapchains. */ bool force_headless_swapchain; + bool force_swapchain_to_currentExtent; + struct { /* Override the minimum number of images on the swapchain. * 0 = no override */ -- 2.7.4