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: 6139493ae3 ("vulkan/wsi: return VK_SUBOPTIMAL_KHR for sw/x11 on window resize")
Reviewed-by: Mike Blumenkrantz <michael.blumenkrantz@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24818>
(cherry picked from commit aa657247ce)
This commit is contained in:
antonino 2023-08-21 22:50:34 +02:00 committed by Eric Engestrom
parent e055eef4bc
commit c93039d661
10 changed files with 29 additions and 2 deletions

View file

@ -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"
},

View file

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

View file

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

View file

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

View file

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

View file

@ -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
};

View file

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

View file

@ -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 */
};

View file

@ -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;

View file

@ -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 */