<div dir="ltr"><div>Reviewed-by: Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>><br><br></div>I would still like to see a review from Emil.  He's on vacation at the moment, but he should be back next week.<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Aug 12, 2016 at 2:17 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"><span class="">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>
</span> src/intel/vulkan/anv_device.c  |  6 ++++<br>
 src/intel/vulkan/anv_wsi_x11.c | 82 ++++++++++++++++++++++++++++++<wbr>+++++-------<br>
 3 files changed, 80 insertions(+), 15 deletions(-)<br>
<div><div class="h5"><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>
</div></div>index 2895d6b..7c6ef97 100644<br>
<span class="">--- 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>
</span>@@ -256,16 +257,47 @@ VkBool32 anv_<wbr>GetPhysicalDeviceXcbPresentati<wbr>onSupportKHR(<br>
    return true;<br>
 }<br>
<br>
<span class="">+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>
</span><div><div class="h5">+<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>
</div></div>+      wsi_x11_get_connection(device, conn);<br>
    if (!wsi_conn)<br>
       return vk_error(VK_ERROR_OUT_OF_HOST_<wbr>MEMORY);<br>
<br>
@@ -276,8 +308,7 @@ x11_surface_get_support(<wbr>VkIcdSurfaceBase *icd_surface,<br>
<span class="">    }<br>
<br>
    unsigned visual_depth;<br>
-   if (!get_visualtype_for_window(<wbr>surface->connection, surface->window,<br>
</span>-                                  &visual_depth)) {<br>
<span class="">+   if (!get_visualtype_for_window(<wbr>conn, window, &visual_depth)) {<br>
       *pSupported = false;<br>
       return VK_SUCCESS;<br>
    }<br>
</span>@@ -296,22 +327,22 @@ x11_surface_get_capabilities(<wbr>VkIcdSurfaceBase *icd_surface,<br>
<span class="">                              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>
</span>-                                &visual_depth);<br>
<span class="">+      get_visualtype_for_window(<wbr>conn, window, &visual_depth);<br>
<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>
</span>@@ -420,6 +451,32 @@ VkResult anv_CreateXcbSurfaceKHR(<br>
    return VK_SUCCESS;<br>
 }<br>
<br>
<div><div class="h5">+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>
</div></div><span class="">+<br>
 struct x11_image {<br>
    struct anv_image *                        image;<br>
    struct anv_device_memory *                memory;<br>
</span>@@ -752,7 +809,6 @@ x11_surface_create_swapchain(<wbr>VkIcdSurfaceBase *icd_surface,<br>
<span class="">                              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>
</span>@@ -782,8 +838,8 @@ x11_surface_create_swapchain(<wbr>VkIcdSurfaceBase *icd_surface,<br>
<span class="">    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>
</span>@@ -877,6 +933,7 @@ anv_x11_init_wsi(struct anv_physical_device *device)<br>
<span class="">    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>
</span>@@ -886,6 +943,7 @@ fail_alloc:<br>
<div class="HOEnZb"><div class="h5">    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>
--<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>
</div></div></blockquote></div><br></div>