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