<div dir="auto"><div><div class="gmail_extra"><div class="gmail_quote">On Feb 18, 2017 9:48 PM, "Dave Airlie" <<a href="mailto:airlied@gmail.com">airlied@gmail.com</a>> wrote:<br type="attribution"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">From: Dave Airlie <<a href="mailto:airlied@redhat.com">airlied@redhat.com</a>><br>
<br>
This adds support to radv_<wbr>GetPhysicalDeviceXlibPresentat<wbr>ionSupportKHR<br>
and radv_<wbr>GetPhysicalDeviceXcbPresentati<wbr>onSupportKHR to check if the<br>
local device file descriptor is compatible with the descriptor<br>
retrieved from the X server via DRI3.<br>
<br>
This will stop radv binding to an X server until we have prime<br>
support in place. Hopefully apps use this API before trying<br>
to render things.<br>
<br>
Signed-off-by: Dave Airlie <<a href="mailto:airlied@redhat.com">airlied@redhat.com</a>><br>
---<br>
 src/amd/vulkan/radv_device.c    |  5 ++-<br>
 src/amd/vulkan/radv_private.h   |  1 +<br>
 src/amd/vulkan/radv_wsi_x11.c   |  8 +++--<br>
 src/intel/vulkan/Makefile.am    |  3 +-<br>
 src/intel/vulkan/anv_device.c   |  3 +-<br>
 src/intel/vulkan/anv_private.h  |  1 +<br>
 src/intel/vulkan/anv_wsi_x11.c  |  8 +++--<br>
 src/vulkan/wsi/Makefile.am      |  1 +<br>
 src/vulkan/wsi/wsi_common_x11.<wbr>c | 69 ++++++++++++++++++++++++++++++<wbr>++++++++++-<br>
 src/vulkan/wsi/wsi_common_x11.<wbr>h |  1 +<br>
 10 files changed, 92 insertions(+), 8 deletions(-)<br>
<br>
diff --git a/src/amd/vulkan/radv_device.c b/src/amd/vulkan/radv_device.c<br>
index 7932f31..55616e8 100644<br>
--- a/src/amd/vulkan/radv_device.c<br>
+++ b/src/amd/vulkan/radv_device.c<br>
@@ -225,6 +225,8 @@ radv_physical_device_init(<wbr>struct radv_physical_device *device,<br>
                result = VK_ERROR_INCOMPATIBLE_DRIVER;<br>
                goto fail;<br>
        }<br>
+<br>
+       device->local_fd = fd;<br>
        device->ws->query_info(device-<wbr>>ws, &device->rad_info);<br>
        result = radv_init_wsi(device);<br>
        if (result != VK_SUCCESS) {<br>
@@ -249,7 +251,7 @@ radv_physical_device_init(<wbr>struct radv_physical_device *device,<br>
<br>
        fprintf(stderr, "WARNING: radv is not a conformant vulkan implementation, testing use only.\n");<br>
        device->name = device-><a href="http://rad_info.name" rel="noreferrer" target="_blank">rad_info.name</a>;<br>
-       close(fd);<br>
+<br>
        return VK_SUCCESS;<br>
<br>
 fail:<br>
@@ -263,6 +265,7 @@ radv_physical_device_finish(<wbr>struct radv_physical_device *device)<br>
        radv_extensions_finish(device-<wbr>>instance, &device->extensions);<br>
        radv_finish_wsi(device);<br>
        device->ws->destroy(device-><wbr>ws);<br>
+       close(device->local_fd);<br>
 }<br>
<br>
<br>
diff --git a/src/amd/vulkan/radv_private.<wbr>h b/src/amd/vulkan/radv_private.<wbr>h<br>
index 099dba3..2e4bdcd 100644<br>
--- a/src/amd/vulkan/radv_private.<wbr>h<br>
+++ b/src/amd/vulkan/radv_private.<wbr>h<br>
@@ -280,6 +280,7 @@ struct radv_physical_device {<br>
        const char *                                name;<br>
        uint8_t                                     uuid[VK_UUID_SIZE];<br>
<br>
+       int local_fd;<br>
        struct wsi_device                       wsi_device;<br>
        struct radv_extensions                      extensions;<br>
 };<br>
diff --git a/src/amd/vulkan/radv_wsi_x11.<wbr>c b/src/amd/vulkan/radv_wsi_x11.<wbr>c<br>
index 946b990..97d4277 100644<br>
--- a/src/amd/vulkan/radv_wsi_x11.<wbr>c<br>
+++ b/src/amd/vulkan/radv_wsi_x11.<wbr>c<br>
@@ -45,7 +45,9 @@ VkBool32 radv_<wbr>GetPhysicalDeviceXcbPresentati<wbr>onSupportKHR(<br>
    return wsi_get_physical_device_xcb_<wbr>presentation_support(<br>
       &device->wsi_device,<br>
       &device->instance->alloc,<br>
-      queueFamilyIndex, connection, visual_id);<br>
+      queueFamilyIndex,<br>
+      device->local_fd,<br>
+      connection, visual_id);<br>
 }<br>
<br>
 VkBool32 radv_<wbr>GetPhysicalDeviceXlibPresentat<wbr>ionSupportKHR(<br>
@@ -59,7 +61,9 @@ VkBool32 radv_<wbr>GetPhysicalDeviceXlibPresentat<wbr>ionSupportKHR(<br>
    return wsi_get_physical_device_xcb_<wbr>presentation_support(<br>
       &device->wsi_device,<br>
       &device->instance->alloc,<br>
-      queueFamilyIndex, XGetXCBConnection(dpy), visualID);<br>
+      queueFamilyIndex,<br>
+      device->local_fd,<br>
+      XGetXCBConnection(dpy), visualID);<br>
 }<br>
<br>
 VkResult radv_CreateXcbSurfaceKHR(<br>
diff --git a/src/intel/vulkan/Makefile.am b/src/intel/vulkan/Makefile.am<br>
index 4197b0e..93f2ceb 100644<br>
--- a/src/intel/vulkan/Makefile.am<br>
+++ b/src/intel/vulkan/Makefile.am<br>
@@ -68,6 +68,7 @@ AM_CPPFLAGS += \<br>
 endif<br>
<br>
 AM_CPPFLAGS += \<br>
+       $(LIBDRM_CFLAGS) \<br>
        $(INTEL_CFLAGS) \<br>
        $(VALGRIND_CFLAGS) \<br>
        $(DEFINES)<br>
@@ -93,7 +94,7 @@ VULKAN_SOURCES = \<br>
        $(VULKAN_GENERATED_FILES) \<br>
        $(VULKAN_FILES)<br>
<br>
-VULKAN_LIB_DEPS =<br>
+VULKAN_LIB_DEPS = $(LIBDRM_LIBS)<br>
<br>
 if HAVE_PLATFORM_X11<br>
 AM_CPPFLAGS += \<br>
diff --git a/src/intel/vulkan/anv_device.<wbr>c b/src/intel/vulkan/anv_device.<wbr>c<br>
index cae5fef..dd2a1ea 100644<br>
--- a/src/intel/vulkan/anv_device.<wbr>c<br>
+++ b/src/intel/vulkan/anv_device.<wbr>c<br>
@@ -202,7 +202,7 @@ anv_physical_device_init(<wbr>struct anv_physical_device *device,<br>
<br>
    isl_device_init(&device->isl_<wbr>dev, &device->info, swizzled);<br>
<br>
-   close(fd);<br>
+   device->local_fd = fd;<br>
    return VK_SUCCESS;<br>
<br>
 fail:<br>
@@ -215,6 +215,7 @@ anv_physical_device_finish(<wbr>struct anv_physical_device *device)<br>
 {<br>
    anv_finish_wsi(device);<br>
    ralloc_free(device->compiler);<br>
+   close(device->local_fd);<br>
 }<br>
<br>
 static const VkExtensionProperties global_extensions[] = {<br>
diff --git a/src/intel/vulkan/anv_<wbr>private.h b/src/intel/vulkan/anv_<wbr>private.h<br>
index da1ca29..82e2831 100644<br>
--- a/src/intel/vulkan/anv_<wbr>private.h<br>
+++ b/src/intel/vulkan/anv_<wbr>private.h<br>
@@ -532,6 +532,7 @@ struct anv_physical_device {<br>
     uint8_t                                     uuid[VK_UUID_SIZE];<br>
<br>
     struct wsi_device                       wsi_device;<br>
+    int                                         local_fd;<br>
 };<br>
<br>
 struct anv_instance {<br>
diff --git a/src/intel/vulkan/anv_wsi_<wbr>x11.c b/src/intel/vulkan/anv_wsi_<wbr>x11.c<br>
index 60bc568..3042509 100644<br>
--- a/src/intel/vulkan/anv_wsi_<wbr>x11.c<br>
+++ b/src/intel/vulkan/anv_wsi_<wbr>x11.c<br>
@@ -41,7 +41,9 @@ VkBool32 anv_<wbr>GetPhysicalDeviceXcbPresentati<wbr>onSupportKHR(<br>
    return wsi_get_physical_device_xcb_<wbr>presentation_support(<br>
       &device->wsi_device,<br>
       &device->instance->alloc,<br>
-      queueFamilyIndex, connection, visual_id);<br>
+      queueFamilyIndex,<br>
+      device->local_fd,<br>
+      connection, visual_id);<br>
 }<br>
<br>
 VkBool32 anv_<wbr>GetPhysicalDeviceXlibPresentat<wbr>ionSupportKHR(<br>
@@ -55,7 +57,9 @@ VkBool32 anv_<wbr>GetPhysicalDeviceXlibPresentat<wbr>ionSupportKHR(<br>
    return wsi_get_physical_device_xcb_<wbr>presentation_support(<br>
       &device->wsi_device,<br>
       &device->instance->alloc,<br>
-      queueFamilyIndex, XGetXCBConnection(dpy), visualID);<br>
+      queueFamilyIndex,<br>
+      device->local_fd,<br>
+      XGetXCBConnection(dpy), visualID);<br>
 }<br>
<br>
 VkResult anv_CreateXcbSurfaceKHR(<br>
diff --git a/src/vulkan/wsi/Makefile.am b/src/vulkan/wsi/Makefile.am<br>
index a712799..b5ccf98 100644<br>
--- a/src/vulkan/wsi/Makefile.am<br>
+++ b/src/vulkan/wsi/Makefile.am<br>
@@ -13,6 +13,7 @@ AM_CPPFLAGS = \<br>
        -I$(top_srcdir)/src/gallium/<wbr>include<br>
<br>
 AM_CFLAGS = \<br>
+       $(LIBDRM_CFLAGS) \<br>
        $(VISIBILITY_CFLAGS)<br>
<br>
 VULKAN_LIB_DEPS =<br>
diff --git a/src/vulkan/wsi/wsi_common_<wbr>x11.c b/src/vulkan/wsi/wsi_common_<wbr>x11.c<br>
index 64ba921..bc4af5a 100644<br>
--- a/src/vulkan/wsi/wsi_common_<wbr>x11.c<br>
+++ b/src/vulkan/wsi/wsi_common_<wbr>x11.c<br>
@@ -33,8 +33,9 @@<br>
 #include <unistd.h><br>
 #include <errno.h><br>
 #include <string.h><br>
-<br>
+#include <fcntl.h><br>
 #include <poll.h><br>
+#include <xf86drm.h><br>
 #include "util/hash_table.h"<br>
<br>
 #include "wsi_common.h"<br>
@@ -59,6 +60,52 @@ struct wsi_x11 {<br>
    struct hash_table *connections;<br>
 };<br>
<br>
+<br>
+/** wsi_dri3_open<br>
+ *<br>
+ * Wrapper around xcb_dri3_open<br>
+ */<br>
+static int<br>
+wsi_dri3_open(xcb_connection_<wbr>t *conn,<br>
+             xcb_window_t root,<br>
+             uint32_t provider)<br>
+{<br>
+   xcb_dri3_open_cookie_t       cookie;<br>
+   xcb_dri3_open_reply_t        *reply;<br>
+   int                          fd;<br>
+<br>
+   cookie = xcb_dri3_open(conn,<br>
+                          root,<br>
+                          provider);<br>
+<br>
+   reply = xcb_dri3_open_reply(conn, cookie, NULL);<br>
+   if (!reply)<br>
+      return -1;<br>
+<br>
+   if (reply->nfd != 1) {<br>
+      free(reply);<br>
+      return -1;<br>
+   }<br>
+<br>
+   fd = xcb_dri3_open_reply_fds(conn, reply)[0];<br>
+   free(reply);<br>
+   fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC);<br>
+<br>
+   return fd;<br>
+}<br>
+<br>
+static int<br>
+x11_get_dri3_fd(xcb_<wbr>connection_t *conn, xcb_screen_t *screen)<br>
+{<br>
+   int dri3_fd;<br>
+<br>
+   dri3_fd = wsi_dri3_open(conn, screen->root, None);<br>
+   if (dri3_fd == -1)<br>
+      return -1;<br></blockquote></div></div></div><div dir="auto"><br></div><div dir="auto">This helper is entirely pointless.  Maybe it makes sense in your prime patches but it makes none as it stands.</div><div dir="auto"><br></div><div dir="auto"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+<br>
+   return dri3_fd;<br>
+}<br>
+<br>
 static struct wsi_x11_connection *<br>
 wsi_x11_connection_create(<wbr>const VkAllocationCallbacks *alloc,<br>
                           xcb_connection_t *conn)<br>
@@ -255,6 +302,7 @@ VkBool32 wsi_get_physical_device_xcb_<wbr>presentation_support(<br>
     struct wsi_device *wsi_device,<br>
     VkAllocationCallbacks *alloc,<br>
     uint32_t                                    queueFamilyIndex,<br>
+    int fd,<br>
     xcb_connection_t*                           connection,<br>
     xcb_visualid_t                              visual_id)<br>
 {<br>
@@ -270,6 +318,25 @@ VkBool32 wsi_get_physical_device_xcb_<wbr>presentation_support(<br>
       return false;<br>
    }<br>
<br>
+   xcb_screen_iterator_t screen_iter =<br>
+      xcb_setup_roots_iterator(xcb_<wbr>get_setup(connection));<br>
+   xcb_screen_t *screen = screen_iter.data;<br>
+<br>
+   char *local_dev = drmGetRenderDeviceNameFromFd(<wbr>fd);<br>
+   int dri3_fd = x11_get_dri3_fd(connection, screen);<br>
+   if (dri3_fd != -1) {<br>
+      char *dri3_dev = drmGetRenderDeviceNameFromFd(<wbr>dri3_fd);<br></blockquote></div></div></div><div dir="auto"><br></div><div dir="auto">What exactly does this return?  Is it just the render node path?  I have no idea if this is the right way to compare two DRM devices or not.</div><div dir="auto"><br></div><div dir="auto"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+      int ret;<br>
+      close(dri3_fd);<br>
+<br>
+      ret = strcmp(local_dev, dri3_dev);<br>
+<br>
+      free(local_dev);<br></blockquote></div></div></div><div dir="auto"><br></div><div dir="auto">You're leaking local_dev when dri3_fd == -1</div><div dir="auto"><br></div><div dir="auto"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+      free(dri3_dev);<br>
+      if (ret != 0)<br>
+        return false;<br>
+   }<br>
+<br>
    unsigned visual_depth;<br>
    if (!connection_get_visualtype(<wbr>connection, visual_id, &visual_depth))<br>
       return false;<br>
diff --git a/src/vulkan/wsi/wsi_common_<wbr>x11.h b/src/vulkan/wsi/wsi_common_<wbr>x11.h<br>
index 7166f09..01f1d66 100644<br>
--- a/src/vulkan/wsi/wsi_common_<wbr>x11.h<br>
+++ b/src/vulkan/wsi/wsi_common_<wbr>x11.h<br>
@@ -29,6 +29,7 @@ VkBool32 wsi_get_physical_device_xcb_<wbr>presentation_support(<br>
     struct wsi_device *wsi_device,<br>
     VkAllocationCallbacks *alloc,<br>
     uint32_t                                    queueFamilyIndex,<br>
+    int local_fd,<br>
     xcb_connection_t*                           connection,<br>
     xcb_visualid_t                              visual_id);<br>
<font color="#888888"><br>
--<br>
2.9.3<br>
<br>
______________________________<wbr>_________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/mesa-dev</a><br>
</font></blockquote></div><br></div></div></div>