[Mesa-dev] [RFC v2 2/5] vulkan: Check whether X server supports DMA fences

Louis-Francis Ratté-Boulianne lfrb at collabora.com
Thu Sep 28 08:25:25 UTC 2017


Signed-off-by: Louis-Francis Ratté-Boulianne <lfrb at collabora.com>
---
 src/vulkan/wsi/wsi_common_x11.c | 46 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)

diff --git a/src/vulkan/wsi/wsi_common_x11.c b/src/vulkan/wsi/wsi_common_x11.c
index 4569c928c8..d9467092d2 100644
--- a/src/vulkan/wsi/wsi_common_x11.c
+++ b/src/vulkan/wsi/wsi_common_x11.c
@@ -52,8 +52,10 @@
 struct wsi_x11_connection {
    bool has_dri3;
    bool has_dri3_v1_1;
+   bool has_dri3_v1_2;
    bool has_present;
    bool has_present_v1_1;
+   bool has_present_v1_2;
    bool is_proprietary_x11;
 };
 
@@ -176,6 +178,8 @@ wsi_x11_connection_create(const VkAllocationCallbacks *alloc,
       ver_reply = xcb_dri3_query_version_reply(conn, ver_cookie, NULL);
       wsi_conn->has_dri3_v1_1 =
          (ver_reply->major_version > 1 || ver_reply->minor_version >= 1);
+      wsi_conn->has_dri3_v1_2 =
+         (ver_reply->major_version > 1 || ver_reply->minor_version >= 2);
       free(ver_reply);
    }
 #endif
@@ -190,6 +194,8 @@ wsi_x11_connection_create(const VkAllocationCallbacks *alloc,
       ver_reply = xcb_present_query_version_reply(conn, ver_cookie, NULL);
       wsi_conn->has_present_v1_1 =
          (ver_reply->major_version > 1 || ver_reply->minor_version >= 1);
+      wsi_conn->has_present_v1_2 =
+         (ver_reply->major_version > 1 || ver_reply->minor_version >= 2);
       free(ver_reply);
    }
 #endif
@@ -655,6 +661,9 @@ struct x11_swapchain {
    struct wsi_swapchain                        base;
 
    bool                                         has_dri3_v1_1;
+   bool                                         has_dri3_v1_2;
+   bool                                         has_present_v1_2;
+   bool                                         has_dma_fence;
 
    xcb_connection_t *                           conn;
    xcb_window_t                                 window;
@@ -667,6 +676,8 @@ struct x11_swapchain {
    uint64_t                                     send_sbc;
    uint64_t                                     last_present_msc;
    uint32_t                                     stamp;
+   bool                                         present_capabilities_retrieved;
+   uint32_t                                     present_capabilities;
 
    bool                                         threaded;
    VkResult                                     status;
@@ -1001,6 +1012,35 @@ fail:
    return NULL;
 }
 
+static void
+wsi_x11_get_present_capabilities(struct x11_swapchain *chain)
+{
+#if XCB_PRESENT_MAJOR_VERSION > 1 || XCB_PRESENT_MINOR_VERSION >= 2
+   xcb_present_query_capabilities_cookie_t present_capabilities_cookie;
+   xcb_present_query_capabilities_reply_t  *present_capabilities_reply;
+
+   if (chain->present_capabilities_retrieved)
+      return;
+
+   present_capabilities_cookie =
+      xcb_present_query_capabilities(chain->conn, chain->window);
+   present_capabilities_reply =
+        xcb_present_query_capabilities_reply(chain->conn,
+                                                 present_capabilities_cookie,
+                                                 NULL);
+
+   if (present_capabilities_reply) {
+      chain->present_capabilities_retrieved = true;
+      chain->present_capabilities = present_capabilities_reply->capabilities;
+      chain->has_dma_fence = chain->present_capabilities &
+                             XCB_PRESENT_CAPABILITY_IDLE_FENCE;
+      free(present_capabilities_reply);
+   } else {
+      chain->present_capabilities = 0;
+   }
+#endif
+}
+
 static VkResult
 x11_image_init(VkDevice device_h, struct x11_swapchain *chain,
                const VkSwapchainCreateInfoKHR *pCreateInfo,
@@ -1075,6 +1115,9 @@ x11_image_init(VkDevice device_h, struct x11_swapchain *chain,
    for (i = 0; i < image->base.num_planes; i++)
       image->base.fds[i] = -1;
 
+   if (chain->has_present_v1_2 && chain->has_dri3_v1_2)
+      wsi_x11_get_present_capabilities(chain);
+
    int fence_fd = xshmfence_alloc_shm();
    if (fence_fd < 0)
       goto fail_pixmap;
@@ -1283,6 +1326,7 @@ x11_surface_create_swapchain(VkIcdSurfaceBase *icd_surface,
    chain->threaded = false;
    chain->status = VK_SUCCESS;
    chain->crtc_changed = false;
+   chain->present_capabilities_retrieved = false;
 
    free(geometry);
 
@@ -1292,6 +1336,8 @@ x11_surface_create_swapchain(VkIcdSurfaceBase *icd_surface,
       return VK_ERROR_OUT_OF_HOST_MEMORY;
 
    chain->has_dri3_v1_1 = wsi_conn->has_dri3_v1_1;
+   chain->has_dri3_v1_2 = wsi_conn->has_dri3_v1_2;
+   chain->has_present_v1_2 = wsi_conn->has_present_v1_2;
 
    chain->base.needs_linear_copy = false;
    if (!wsi_x11_check_dri3_compatible(conn, local_fd))
-- 
2.13.0



More information about the mesa-dev mailing list