Module: Mesa
Branch: main
Commit: 3c18e69078a1e6bf9d46273536cadfcac072c6c9
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=3c18e69078a1e6bf9d46273536cadfcac072c6c9

Author: Simon Ser <[email protected]>
Date:   Tue Sep  7 15:06:46 2021 +0200

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 <[email protected]>
Acked-by: Michel Dänzer <[email protected]>
Reviewed-by: Bas Nieuwenhuizen <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11290>

---

 src/amd/vulkan/radv_device.c    |  1 +
 src/intel/vulkan/anv_device.c   |  1 +
 src/util/driconf.h              |  4 ++++
 src/vulkan/wsi/wsi_common.h     |  5 +++++
 src/vulkan/wsi/wsi_common_x11.c | 43 ++++++++++++++++++++++++++++++-----------
 5 files changed, 43 insertions(+), 11 deletions(-)

diff --git a/src/amd/vulkan/radv_device.c b/src/amd/vulkan/radv_device.c
index d8d77ce8d2f..03a4405d4de 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 9afc5927fad..6ff8e2b38df 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 0b6434acf85..35f1941a8d2 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 adf275e8d48..473efcc16a4 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 fcda05d2d42..aac45b38553 100644
--- a/src/vulkan/wsi/wsi_common_x11.c
+++ b/src/vulkan/wsi/wsi_common_x11.c
@@ -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;

Reply via email to