From 2537864f9002b0ccebf93c9a6f50c428ae40cac0 Mon Sep 17 00:00:00 2001 From: Xaver Hugl Date: Mon, 17 Oct 2022 18:40:13 +0200 Subject: [PATCH] vulkan wsi: add support for PresentOptionAsyncMayTear This commit adds tearing support for Xwayland Signed-off-by: Xaver Hugl Reviewed-by: Emil Velikov Cc: mesa-stable Part-of: (cherry picked from commit 0a1ccd4a9a6c85bce2013d8ff843e96d151288c9) --- .pick_status.json | 2 +- src/vulkan/wsi/wsi_common_x11.c | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/.pick_status.json b/.pick_status.json index ae35f933895..737cf4cf3c7 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -4584,7 +4584,7 @@ "description": "vulkan wsi: add support for PresentOptionAsyncMayTear", "nominated": true, "nomination_type": 0, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": null, "notes": null diff --git a/src/vulkan/wsi/wsi_common_x11.c b/src/vulkan/wsi/wsi_common_x11.c index 6dd22b5804b..c99239de9ec 100644 --- a/src/vulkan/wsi/wsi_common_x11.c +++ b/src/vulkan/wsi/wsi_common_x11.c @@ -68,6 +68,13 @@ #include #endif +#ifndef XCB_PRESENT_OPTION_ASYNC_MAY_TEAR +#define XCB_PRESENT_OPTION_ASYNC_MAY_TEAR 16 +#endif +#ifndef XCB_PRESENT_CAPABILITY_ASYNC_MAY_TEAR +#define XCB_PRESENT_CAPABILITY_ASYNC_MAY_TEAR 8 +#endif + struct wsi_x11_connection { bool has_dri3; bool has_dri3_modifiers; @@ -1041,6 +1048,7 @@ struct x11_swapchain { bool has_dri3_modifiers; bool has_mit_shm; + bool has_async_may_tear; xcb_connection_t * conn; xcb_window_t window; @@ -1597,6 +1605,10 @@ x11_present_to_x11_dri3(struct x11_swapchain *chain, uint32_t image_index, chain->base.present_mode == VK_PRESENT_MODE_FIFO_RELAXED_KHR) options |= XCB_PRESENT_OPTION_ASYNC; + if (chain->base.present_mode == VK_PRESENT_MODE_IMMEDIATE_KHR + && chain->has_async_may_tear) + options |= XCB_PRESENT_OPTION_ASYNC_MAY_TEAR; + #ifdef HAVE_DRI3_MODIFIERS if (chain->has_dri3_modifiers) options |= XCB_PRESENT_OPTION_SUBOPTIMAL; @@ -2724,6 +2736,15 @@ x11_surface_create_swapchain(VkIcdSurfaceBase *icd_surface, chain->has_dri3_modifiers = wsi_conn->has_dri3_modifiers; chain->has_mit_shm = wsi_conn->has_mit_shm; + xcb_present_query_capabilities_cookie_t present_query_cookie; + xcb_present_query_capabilities_reply_t *present_query_reply; + present_query_cookie = xcb_present_query_capabilities(conn, chain->window); + present_query_reply = xcb_present_query_capabilities_reply(conn, present_query_cookie, NULL); + if (present_query_reply) { + chain->has_async_may_tear = present_query_reply->capabilities & XCB_PRESENT_CAPABILITY_ASYNC_MAY_TEAR; + free(present_query_reply); + } + /* When images in the swapchain don't fit the window, X can still present them, but it won't * happen by flip, only by copy. So this is a suboptimal copy, because if the client would change * the chain extents X may be able to flip