From: Simon Ser Date: Tue, 7 Sep 2021 13:06:46 +0000 (+0200) Subject: vulkan/wsi/x11: add driconf option to not wait under Xwayland X-Git-Tag: upstream/22.3.5~18064 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3c18e69078a1e6bf9d46273536cadfcac072c6c9;p=platform%2Fupstream%2Fmesa.git vulkan/wsi/x11: add driconf option to not wait under Xwayland By default, Mesa's X11 Vulkan WSI will wait for buffers to be ready before submitting them to Xwayland when the swapchain is created with the IMMEDIATE mode. This is undesirable when the Wayland compositor already monitors fences. A Wayland compositor may want to know the delay between the buffer submition and the end of the GPU work, this is impossible to measure if the WSI waits for the buffer to be ready before submission. Since most compositors don't monitor fences, let's introduce a driconf option for this for now. We can reconsider once more compositors have better support for fences. Signed-off-by: Simon Ser Acked-by: Michel Dänzer Reviewed-by: Bas Nieuwenhuizen Part-of: --- diff --git a/src/amd/vulkan/radv_device.c b/src/amd/vulkan/radv_device.c index d8d77ce..03a4405 100644 --- a/src/amd/vulkan/radv_device.c +++ b/src/amd/vulkan/radv_device.c @@ -857,6 +857,7 @@ static const driOptionDescription radv_dri_options[] = { DRI_CONF_VK_X11_OVERRIDE_MIN_IMAGE_COUNT(0) DRI_CONF_VK_X11_STRICT_IMAGE_COUNT(false) DRI_CONF_VK_X11_ENSURE_MIN_IMAGE_COUNT(false) + DRI_CONF_VK_XWAYLAND_WAIT_READY(true) DRI_CONF_RADV_REPORT_LLVM9_VERSION_STRING(false) DRI_CONF_RADV_ENABLE_MRT_OUTPUT_NAN_FIXUP(false) DRI_CONF_RADV_DISABLE_SHRINK_IMAGE_STORE(false) diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c index 9afc592..6ff8e2b 100644 --- a/src/intel/vulkan/anv_device.c +++ b/src/intel/vulkan/anv_device.c @@ -63,6 +63,7 @@ static const driOptionDescription anv_dri_options[] = { DRI_CONF_SECTION_PERFORMANCE DRI_CONF_VK_X11_OVERRIDE_MIN_IMAGE_COUNT(0) DRI_CONF_VK_X11_STRICT_IMAGE_COUNT(false) + DRI_CONF_VK_XWAYLAND_WAIT_READY(true) DRI_CONF_SECTION_END DRI_CONF_SECTION_DEBUG diff --git a/src/util/driconf.h b/src/util/driconf.h index 0b6434a..35f1941 100644 --- a/src/util/driconf.h +++ b/src/util/driconf.h @@ -333,6 +333,10 @@ DRI_CONF_OPT_B(vk_x11_ensure_min_image_count, def, \ "Force the X11 WSI to create at least the number of image specified by the driver in VkSurfaceCapabilitiesKHR::minImageCount") +#define DRI_CONF_VK_XWAYLAND_WAIT_READY(def) \ + DRI_CONF_OPT_B(vk_xwayland_wait_ready, def, \ + "Wait for fences before submitting buffers to Xwayland") + #define DRI_CONF_MESA_GLTHREAD(def) \ DRI_CONF_OPT_B(mesa_glthread, def, \ "Enable offloading GL driver work to a separate thread") diff --git a/src/vulkan/wsi/wsi_common.h b/src/vulkan/wsi/wsi_common.h index adf275e..473efcc 100644 --- a/src/vulkan/wsi/wsi_common.h +++ b/src/vulkan/wsi/wsi_common.h @@ -121,6 +121,11 @@ struct wsi_device { * driver in VkSurfaceCapabilitiesKHR::minImageCount. */ bool ensure_minImageCount; + + /* Wait for fences before submitting buffers to Xwayland. Defaults to + * true. + */ + bool xwaylandWaitReady; } x11; bool sw; diff --git a/src/vulkan/wsi/wsi_common_x11.c b/src/vulkan/wsi/wsi_common_x11.c index fcda05d..aac45b3 100644 --- a/src/vulkan/wsi/wsi_common_x11.c +++ b/src/vulkan/wsi/wsi_common_x11.c @@ -39,6 +39,7 @@ #include #include "drm-uapi/drm_fourcc.h" #include "util/hash_table.h" +#include "util/u_debug.h" #include "util/u_thread.h" #include "util/xmlconfig.h" @@ -1262,6 +1263,25 @@ x11_queue_present(struct wsi_swapchain *anv_chain, } } +static bool +x11_needs_wait_for_fences(const struct wsi_device *wsi_device, + struct wsi_x11_connection *wsi_conn, + VkPresentModeKHR present_mode) +{ + if (wsi_conn->is_xwayland && !wsi_device->x11.xwaylandWaitReady) { + return false; + } + + switch (present_mode) { + case VK_PRESENT_MODE_MAILBOX_KHR: + return true; + case VK_PRESENT_MODE_IMMEDIATE_KHR: + return wsi_conn->is_xwayland; + default: + return false; + } +} + static void * x11_manage_fifo_queues(void *state) { @@ -1291,9 +1311,8 @@ x11_manage_fifo_queues(void *state) return NULL; } - if (chain->base.present_mode == VK_PRESENT_MODE_MAILBOX_KHR || - (chain->base.present_mode == VK_PRESENT_MODE_IMMEDIATE_KHR && - wsi_conn->is_xwayland)) { + if (x11_needs_wait_for_fences(chain->base.wsi, wsi_conn, + chain->base.present_mode)) { result = chain->base.wsi->WaitForFences(chain->base.device, 1, &chain->base.fences[image_index], true, UINT64_MAX); @@ -1679,9 +1698,7 @@ x11_surface_create_swapchain(VkIcdSurfaceBase *icd_surface, unsigned num_images = pCreateInfo->minImageCount; if (wsi_device->x11.strict_imageCount) num_images = pCreateInfo->minImageCount; - else if (present_mode == VK_PRESENT_MODE_MAILBOX_KHR || - (present_mode == VK_PRESENT_MODE_IMMEDIATE_KHR && - wsi_conn->is_xwayland)) + else if (x11_needs_wait_for_fences(wsi_device, wsi_conn, present_mode)) num_images = MAX2(num_images, 5); else if (wsi_device->x11.ensure_minImageCount) num_images = MAX2(num_images, x11_get_min_image_count(wsi_device)); @@ -1791,10 +1808,10 @@ x11_surface_create_swapchain(VkIcdSurfaceBase *icd_surface, } if ((chain->base.present_mode == VK_PRESENT_MODE_FIFO_KHR || - chain->base.present_mode == VK_PRESENT_MODE_FIFO_RELAXED_KHR || - chain->base.present_mode == VK_PRESENT_MODE_MAILBOX_KHR || - (chain->base.present_mode == VK_PRESENT_MODE_IMMEDIATE_KHR && - wsi_conn->is_xwayland)) && !chain->base.wsi->sw) { + chain->base.present_mode == VK_PRESENT_MODE_FIFO_RELAXED_KHR || + x11_needs_wait_for_fences(wsi_device, wsi_conn, + chain->base.present_mode)) && + !chain->base.wsi->sw) { chain->has_present_queue = true; /* Initialize our queues. We make them base.image_count + 1 because we will @@ -1912,7 +1929,11 @@ wsi_x11_init_wsi(struct wsi_device *wsi_device, wsi_device->x11.ensure_minImageCount = driQueryOptionb(dri_options, "vk_x11_ensure_min_image_count"); } - + wsi_device->x11.xwaylandWaitReady = true; + if (driCheckOption(dri_options, "vk_xwayland_wait_ready", DRI_BOOL)) { + wsi_device->x11.xwaylandWaitReady = + driQueryOptionb(dri_options, "vk_xwayland_wait_ready"); + } } wsi->base.get_support = x11_surface_get_support;