vulkan/wsi/x11: add driconf option to not wait under Xwayland
authorSimon Ser <contact@emersion.fr>
Tue, 7 Sep 2021 13:06:46 +0000 (15:06 +0200)
committerMarge Bot <eric+marge@anholt.net>
Mon, 13 Sep 2021 19:38:13 +0000 (19:38 +0000)
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 <contact@emersion.fr>
Acked-by: Michel Dänzer <mdaenzer@redhat.com>
Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11290>

src/amd/vulkan/radv_device.c
src/intel/vulkan/anv_device.c
src/util/driconf.h
src/vulkan/wsi/wsi_common.h
src/vulkan/wsi/wsi_common_x11.c

index d8d77ce..03a4405 100644 (file)
@@ -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)
index 9afc592..6ff8e2b 100644 (file)
@@ -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
index 0b6434a..35f1941 100644 (file)
    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")
index adf275e..473efcc 100644 (file)
@@ -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;
index fcda05d..aac45b3 100644 (file)
@@ -39,6 +39,7 @@
 #include <xf86drm.h>
 #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;