<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Aug 11, 2016 at 3:26 PM, Kevin Strasser <span dir="ltr"><<a href="mailto:kevin.strasser@intel.com" target="_blank">kevin.strasser@intel.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Some applications continue to use the Xlib client library and expect that<br>
VK_KHR_xlib_surface will be available in the driver. Service these<br>
applications by converting the Display pointer to xcb_connection_t and use<br>
the existing xcb code in the driver.<br>
<br>
Signed-off-by: Kevin Strasser <<a href="mailto:kevin.strasser@intel.com">kevin.strasser@intel.com</a>><br>
Cc: Jason Ekstrand <<a href="mailto:jason.ekstrand@intel.com">jason.ekstrand@intel.com</a>><br>
---<br>
 src/intel/vulkan/Makefile.am   |  7 ++--<br>
 src/intel/vulkan/anv_device.c  |  6 +++<br>
 src/intel/vulkan/anv_wsi_x11.c | 87 ++++++++++++++++++++++++++++++<wbr>++++++------<br>
 3 files changed, 86 insertions(+), 14 deletions(-)<br>
<br>
diff --git a/src/intel/vulkan/Makefile.am b/src/intel/vulkan/Makefile.am<br>
index fe7371e..73db8f5 100644<br>
--- a/src/intel/vulkan/Makefile.am<br>
+++ b/src/intel/vulkan/Makefile.am<br>
@@ -85,7 +85,8 @@ VULKAN_LIB_DEPS =<br>
 if HAVE_PLATFORM_X11<br>
 AM_CPPFLAGS += \<br>
        $(XCB_DRI3_CFLAGS) \<br>
-       -DVK_USE_PLATFORM_XCB_KHR<br>
+       -DVK_USE_PLATFORM_XCB_KHR \<br>
+       -DVK_USE_PLATFORM_XLIB_KHR<br>
<br>
 VULKAN_SOURCES += $(VULKAN_WSI_X11_FILES)<br>
 VULKAN_LIB_DEPS += $(XCB_DRI3_LIBS)<br>
@@ -145,7 +146,7 @@ EXTRA_DIST = \<br>
        <a href="http://dev_icd.json.in" rel="noreferrer" target="_blank">dev_icd.json.in</a> \<br>
        intel_icd.json<br>
<br>
-libvulkan_intel_la_LIBADD = $(VULKAN_LIB_DEPS)<br>
+libvulkan_intel_la_LIBADD = $(VULKAN_LIB_DEPS) -lX11-xcb<br>
<br>
 libvulkan_intel_la_LDFLAGS = \<br>
        -shared \<br>
@@ -168,7 +169,7 @@ dev_icd.json : <a href="http://dev_icd.json.in" rel="noreferrer" target="_blank">dev_icd.json.in</a><br>
<br>
 # Libvulkan with dummy gem. Used for unit tests.<br>
 libvulkan_test_la_SOURCES = $(VULKAN_GEM_STUB_FILES)<br>
-libvulkan_test_la_LIBADD = $(VULKAN_LIB_DEPS)<br>
+libvulkan_test_la_LIBADD = $(VULKAN_LIB_DEPS) -lX11-xcb<br>
<br>
 include $(top_srcdir)/<a href="http://install-lib-links.mk" rel="noreferrer" target="_blank">install-lib-<wbr>links.mk</a><br>
<br>
diff --git a/src/intel/vulkan/anv_device.<wbr>c b/src/intel/vulkan/anv_device.<wbr>c<br>
index aae925d..3546682 100644<br>
--- a/src/intel/vulkan/anv_device.<wbr>c<br>
+++ b/src/intel/vulkan/anv_device.<wbr>c<br>
@@ -182,6 +182,12 @@ static const VkExtensionProperties global_extensions[] = {<br>
       .specVersion = 5,<br>
    },<br>
 #endif<br>
+#ifdef VK_USE_PLATFORM_XLIB_KHR<br>
+   {<br>
+      .extensionName = VK_KHR_XLIB_SURFACE_EXTENSION_<wbr>NAME,<br>
+      .specVersion = 5,<br>
+   },<br>
+#endif<br>
 #ifdef VK_USE_PLATFORM_WAYLAND_KHR<br>
    {<br>
       .extensionName = VK_KHR_WAYLAND_SURFACE_<wbr>EXTENSION_NAME,<br>
diff --git a/src/intel/vulkan/anv_wsi_<wbr>x11.c b/src/intel/vulkan/anv_wsi_<wbr>x11.c<br>
index 2895d6b..2d50fff 100644<br>
--- a/src/intel/vulkan/anv_wsi_<wbr>x11.c<br>
+++ b/src/intel/vulkan/anv_wsi_<wbr>x11.c<br>
@@ -21,6 +21,7 @@<br>
  * IN THE SOFTWARE.<br>
  */<br>
<br>
+#include <X11/Xlib-xcb.h><br>
 #include <X11/xshmfence.h><br>
 #include <xcb/xcb.h><br>
 #include <xcb/dri3.h><br>
@@ -256,18 +257,52 @@ VkBool32 anv_<wbr>GetPhysicalDeviceXcbPresentati<wbr>onSupportKHR(<br>
    return true;<br>
 }<br>
<br>
+#ifdef VK_USE_PLATFORM_XLIB_KHR<br>
+VkBool32 anv_<wbr>GetPhysicalDeviceXlibPresentat<wbr>ionSupportKHR(<br>
+    VkPhysicalDevice                            physicalDevice,<br>
+    uint32_t                                    queueFamilyIndex,<br>
+    Display*                                    dpy,<br>
+    VisualID                                    visualID)<br>
+{<br>
+   return anv_<wbr>GetPhysicalDeviceXcbPresentati<wbr>onSupportKHR(physicalDevice,<br>
+                                                         queueFamilyIndex,<br>
+                                                         XGetXCBConnection(dpy),<br>
+                                                         visualID);<br>
+}<br>
+#endif<br></blockquote><div><br></div><div>I don't think we need to #ifdef things inside anv_wsi_x11.c since we're not supporting XCB without Xlib<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+<br>
+static xcb_connection_t*<br>
+x11_surface_get_connection(<wbr>VkIcdSurfaceBase *icd_surface)<br>
+{<br>
+   if (icd_surface->platform == VK_ICD_WSI_PLATFORM_XLIB)<br>
+      return XGetXCBConnection(((<wbr>VkIcdSurfaceXlib *)icd_surface)->dpy);<br>
+   else<br>
+      return ((VkIcdSurfaceXcb *)icd_surface)->connection;<br>
+}<br>
+<br>
+static xcb_window_t<br>
+x11_surface_get_window(<wbr>VkIcdSurfaceBase *icd_surface)<br>
+{<br>
+   if (icd_surface->platform == VK_ICD_WSI_PLATFORM_XLIB)<br>
+      return ((VkIcdSurfaceXlib *)icd_surface)->window;<br>
+   else<br>
+      return ((VkIcdSurfaceXcb *)icd_surface)->window;<br>
+}<br>
+<br>
 static VkResult<br>
 x11_surface_get_support(<wbr>VkIcdSurfaceBase *icd_surface,<br>
                         struct anv_physical_device *device,<br>
                         uint32_t queueFamilyIndex,<br>
                         VkBool32* pSupported)<br>
 {<br>
-   VkIcdSurfaceXcb *surface = (VkIcdSurfaceXcb *)icd_surface;<br>
+   xcb_connection_t *conn = x11_surface_get_connection(<wbr>icd_surface);<br>
+   xcb_window_t window = x11_surface_get_window(icd_<wbr>surface);<br>
<br>
    struct wsi_x11_connection *wsi_conn =<br>
-      wsi_x11_get_connection(device, surface->connection);<br>
-   if (!wsi_conn)<br>
+      wsi_x11_get_connection(device, conn);<br>
+   if (!wsi_conn) {<br>
       return vk_error(VK_ERROR_OUT_OF_HOST_<wbr>MEMORY);<br>
+   }<br>
<br>
    if (!wsi_conn->has_dri3) {<br>
       fprintf(stderr, "vulkan: No DRI3 support\n");<br>
@@ -276,7 +311,7 @@ x11_surface_get_support(<wbr>VkIcdSurfaceBase *icd_surface,<br>
    }<br>
<br>
    unsigned visual_depth;<br>
-   if (!get_visualtype_for_window(<wbr>surface->connection, surface->window,<br>
+   if (!get_visualtype_for_window(<wbr>conn, window,<br>
                                   &visual_depth)) {<br></blockquote><div><br></div><div>We could probably get rid of the line wrapping.  Meh...<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
       *pSupported = false;<br>
       return VK_SUCCESS;<br>
@@ -296,22 +331,23 @@ x11_surface_get_capabilities(<wbr>VkIcdSurfaceBase *icd_surface,<br>
                              struct anv_physical_device *device,<br>
                              VkSurfaceCapabilitiesKHR *caps)<br>
 {<br>
-   VkIcdSurfaceXcb *surface = (VkIcdSurfaceXcb *)icd_surface;<br>
+   xcb_connection_t *conn = x11_surface_get_connection(<wbr>icd_surface);<br>
+   xcb_window_t window = x11_surface_get_window(icd_<wbr>surface);<br>
    xcb_get_geometry_cookie_t geom_cookie;<br>
    xcb_generic_error_t *err;<br>
    xcb_get_geometry_reply_t *geom;<br>
    unsigned visual_depth;<br>
<br>
-   geom_cookie = xcb_get_geometry(surface-><wbr>connection, surface->window);<br>
+   geom_cookie = xcb_get_geometry(conn, window);<br>
<br>
    /* This does a round-trip.  This is why we do get_geometry first and<br>
     * wait to read the reply until after we have a visual.<br>
     */<br>
    xcb_visualtype_t *visual =<br>
-      get_visualtype_for_window(<wbr>surface->connection, surface->window,<br>
+      get_visualtype_for_window(<wbr>conn, window,<br>
                                 &visual_depth);<br></blockquote><div><br></div><div>line wrap<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
-   geom = xcb_get_geometry_reply(<wbr>surface->connection, geom_cookie, &err);<br>
+   geom = xcb_get_geometry_reply(conn, geom_cookie, &err);<br>
    if (geom) {<br>
       VkExtent2D extent = { geom->width, geom->height };<br>
       caps->currentExtent = extent;<br>
@@ -420,6 +456,34 @@ VkResult anv_CreateXcbSurfaceKHR(<br>
    return VK_SUCCESS;<br>
 }<br>
<br>
+#ifdef VK_USE_PLATFORM_XLIB_KHR<br></blockquote><div><br></div><div>Again, I don't think the ifdef is needed<br><br></div><div>Assuming that Emil signs off on the build system issues,<br><br></div><div>Reviewed-by: Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+VkResult anv_CreateXlibSurfaceKHR(<br>
+    VkInstance                                  _instance,<br>
+    const VkXlibSurfaceCreateInfoKHR*           pCreateInfo,<br>
+    const VkAllocationCallbacks*                pAllocator,<br>
+    VkSurfaceKHR*                               pSurface)<br>
+{<br>
+   ANV_FROM_HANDLE(anv_instance, instance, _instance);<br>
+<br>
+   assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_XLIB_<wbr>SURFACE_CREATE_INFO_KHR);<br>
+<br>
+   VkIcdSurfaceXlib *surface;<br>
+<br>
+   surface = anv_alloc2(&instance->alloc, pAllocator, sizeof *surface, 8,<br>
+                        VK_SYSTEM_ALLOCATION_SCOPE_<wbr>OBJECT);<br>
+   if (surface == NULL)<br>
+      return vk_error(VK_ERROR_OUT_OF_HOST_<wbr>MEMORY);<br>
+<br>
+   surface->base.platform = VK_ICD_WSI_PLATFORM_XLIB;<br>
+   surface->dpy = pCreateInfo->dpy;<br>
+   surface->window = pCreateInfo->window;<br>
+<br>
+   *pSurface = _VkIcdSurfaceBase_to_handle(&<wbr>surface->base);<br>
+<br>
+   return VK_SUCCESS;<br>
+}<br>
+#endif<br>
+<br>
 struct x11_image {<br>
    struct anv_image *                        image;<br>
    struct anv_device_memory *                memory;<br>
@@ -752,7 +816,6 @@ x11_surface_create_swapchain(<wbr>VkIcdSurfaceBase *icd_surface,<br>
                              const VkAllocationCallbacks* pAllocator,<br>
                              struct anv_swapchain **swapchain_out)<br>
 {<br>
-   VkIcdSurfaceXcb *surface = (VkIcdSurfaceXcb *)icd_surface;<br>
    struct x11_swapchain *chain;<br>
    xcb_void_cookie_t cookie;<br>
    VkResult result;<br>
@@ -782,8 +845,8 @@ x11_surface_create_swapchain(<wbr>VkIcdSurfaceBase *icd_surface,<br>
    chain->base.acquire_next_image = x11_acquire_next_image;<br>
    chain->base.queue_present = x11_queue_present;<br>
<br>
-   chain->conn = surface->connection;<br>
-   chain->window = surface->window;<br>
+   chain->conn = x11_surface_get_connection(<wbr>icd_surface);<br>
+   chain->window = x11_surface_get_window(icd_<wbr>surface);<br>
    chain->extent = pCreateInfo->imageExtent;<br>
    chain->image_count = num_images;<br>
<br>
@@ -877,6 +940,7 @@ anv_x11_init_wsi(struct anv_physical_device *device)<br>
    wsi->base.create_swapchain = x11_surface_create_swapchain;<br>
<br>
    device->wsi[VK_ICD_WSI_<wbr>PLATFORM_XCB] = &wsi->base;<br>
+   device->wsi[VK_ICD_WSI_<wbr>PLATFORM_XLIB] = &wsi->base;<br>
<br>
    return VK_SUCCESS;<br>
<br>
@@ -886,6 +950,7 @@ fail_alloc:<br>
    anv_free(&device->instance-><wbr>alloc, wsi);<br>
 fail:<br>
    device->wsi[VK_ICD_WSI_<wbr>PLATFORM_XCB] = NULL;<br>
+   device->wsi[VK_ICD_WSI_<wbr>PLATFORM_XLIB] = NULL;<br>
<br>
    return result;<br>
 }<br>
<span class="HOEnZb"><font color="#888888">--<br>
2.7.4<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></span></blockquote></div><br></div></div>