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>
This commit is contained in:
antonino
2023-08-21 22:50:34 +02:00
committed by Marge Bot
parent d45f598ece
commit aa657247ce
9 changed files with 28 additions and 1 deletions

View File

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

View File

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

View File

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

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

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

View File

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

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

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