Module: Mesa Branch: staging/23.1 Commit: c93039d6612f7c39fc99184d12a07a203aae500d URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=c93039d6612f7c39fc99184d12a07a203aae500d
Author: antonino <antonino.manisca...@collabora.com> Date: Mon Aug 21 22:50:34 2023 +0200 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 <michael.blumenkra...@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24818> (cherry picked from commit aa657247ce8e4da53503c584a7a869a87b45f9fb) --- .pick_status.json | 2 +- 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 ++ 10 files changed, 29 insertions(+), 2 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index a69c0af356c..d5b782b1a48 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -328,7 +328,7 @@ "description": "vulkan/wsi: add `vk_wsi_force_swapchain_to_current_extent` driconf", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": "6139493ae384cfdc8452fabd41287ebd1d539f4c" }, diff --git a/src/amd/vulkan/radv_instance.c b/src/amd/vulkan/radv_instance.c index ebd2787fd24..4dcb829b7ed 100644 --- a/src/amd/vulkan/radv_instance.c +++ b/src/amd/vulkan/radv_instance.c @@ -130,6 +130,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 4d503e57073..ccb8942c4a7 100644 --- a/src/freedreno/vulkan/tu_device.cc +++ b/src/freedreno/vulkan/tu_device.cc @@ -442,6 +442,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 867b76425d3..e512394c7a3 100644 --- a/src/intel/vulkan/anv_device.c +++ b/src/intel/vulkan/anv_device.c @@ -82,6 +82,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_SECTION_END diff --git a/src/intel/vulkan_hasvk/anv_device.c b/src/intel/vulkan_hasvk/anv_device.c index 9f1e65a1723..b6694aef375 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 fda7863bb55..6f95085718b 100644 --- a/src/microsoft/vulkan/dzn_device.c +++ b/src/microsoft/vulkan/dzn_device.c @@ -1162,6 +1162,7 @@ static const driOptionDescription dzn_dri_options[] = { /* Default-disabled because the CTS doesn't check subgroupQuadOperationsInAllStages * and tries to do quad ops in VS/GS which is unsupported. */ DRI_CONF_DZN_ENABLE_SUBGROUP_OPS_IN_VTX_PIPELINE(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 08445d05066..819a6df560c 100644 --- a/src/util/driconf.h +++ b/src/util/driconf.h @@ -380,6 +380,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 1157f3fa1fe..35277d01002 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 b03a3590188..69b10e52726 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 346025602b9..1a2f0d8a1c5 100644 --- a/src/vulkan/wsi/wsi_common.h +++ b/src/vulkan/wsi/wsi_common.h @@ -134,6 +134,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 */