On Feb 18, 2017 9:48 PM, "Dave Airlie" <airl...@gmail.com> wrote:
From: Dave Airlie <airl...@redhat.com> This adds support to radv_GetPhysicalDeviceXlibPresentationSupportKHR and radv_GetPhysicalDeviceXcbPresentationSupportKHR to check if the local device file descriptor is compatible with the descriptor retrieved from the X server via DRI3. This will stop radv binding to an X server until we have prime support in place. Hopefully apps use this API before trying to render things. Signed-off-by: Dave Airlie <airl...@redhat.com> --- src/amd/vulkan/radv_device.c | 5 ++- src/amd/vulkan/radv_private.h | 1 + src/amd/vulkan/radv_wsi_x11.c | 8 +++-- src/intel/vulkan/Makefile.am | 3 +- src/intel/vulkan/anv_device.c | 3 +- src/intel/vulkan/anv_private.h | 1 + src/intel/vulkan/anv_wsi_x11.c | 8 +++-- src/vulkan/wsi/Makefile.am | 1 + src/vulkan/wsi/wsi_common_x11.c | 69 ++++++++++++++++++++++++++++++ ++++++++++- src/vulkan/wsi/wsi_common_x11.h | 1 + 10 files changed, 92 insertions(+), 8 deletions(-) diff --git a/src/amd/vulkan/radv_device.c b/src/amd/vulkan/radv_device.c index 7932f31..55616e8 100644 --- a/src/amd/vulkan/radv_device.c +++ b/src/amd/vulkan/radv_device.c @@ -225,6 +225,8 @@ radv_physical_device_init(struct radv_physical_device *device, result = VK_ERROR_INCOMPATIBLE_DRIVER; goto fail; } + + device->local_fd = fd; device->ws->query_info(device->ws, &device->rad_info); result = radv_init_wsi(device); if (result != VK_SUCCESS) { @@ -249,7 +251,7 @@ radv_physical_device_init(struct radv_physical_device *device, fprintf(stderr, "WARNING: radv is not a conformant vulkan implementation, testing use only.\n"); device->name = device->rad_info.name; - close(fd); + return VK_SUCCESS; fail: @@ -263,6 +265,7 @@ radv_physical_device_finish(struct radv_physical_device *device) radv_extensions_finish(device->instance, &device->extensions); radv_finish_wsi(device); device->ws->destroy(device->ws); + close(device->local_fd); } diff --git a/src/amd/vulkan/radv_private.h b/src/amd/vulkan/radv_private.h index 099dba3..2e4bdcd 100644 --- a/src/amd/vulkan/radv_private.h +++ b/src/amd/vulkan/radv_private.h @@ -280,6 +280,7 @@ struct radv_physical_device { const char * name; uint8_t uuid[VK_UUID_SIZE]; + int local_fd; struct wsi_device wsi_device; struct radv_extensions extensions; }; diff --git a/src/amd/vulkan/radv_wsi_x11.c b/src/amd/vulkan/radv_wsi_x11.c index 946b990..97d4277 100644 --- a/src/amd/vulkan/radv_wsi_x11.c +++ b/src/amd/vulkan/radv_wsi_x11.c @@ -45,7 +45,9 @@ VkBool32 radv_GetPhysicalDeviceXcbPresentationSupportKHR( return wsi_get_physical_device_xcb_presentation_support( &device->wsi_device, &device->instance->alloc, - queueFamilyIndex, connection, visual_id); + queueFamilyIndex, + device->local_fd, + connection, visual_id); } VkBool32 radv_GetPhysicalDeviceXlibPresentationSupportKHR( @@ -59,7 +61,9 @@ VkBool32 radv_GetPhysicalDeviceXlibPresentationSupportKHR( return wsi_get_physical_device_xcb_presentation_support( &device->wsi_device, &device->instance->alloc, - queueFamilyIndex, XGetXCBConnection(dpy), visualID); + queueFamilyIndex, + device->local_fd, + XGetXCBConnection(dpy), visualID); } VkResult radv_CreateXcbSurfaceKHR( diff --git a/src/intel/vulkan/Makefile.am b/src/intel/vulkan/Makefile.am index 4197b0e..93f2ceb 100644 --- a/src/intel/vulkan/Makefile.am +++ b/src/intel/vulkan/Makefile.am @@ -68,6 +68,7 @@ AM_CPPFLAGS += \ endif AM_CPPFLAGS += \ + $(LIBDRM_CFLAGS) \ $(INTEL_CFLAGS) \ $(VALGRIND_CFLAGS) \ $(DEFINES) @@ -93,7 +94,7 @@ VULKAN_SOURCES = \ $(VULKAN_GENERATED_FILES) \ $(VULKAN_FILES) -VULKAN_LIB_DEPS = +VULKAN_LIB_DEPS = $(LIBDRM_LIBS) if HAVE_PLATFORM_X11 AM_CPPFLAGS += \ diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c index cae5fef..dd2a1ea 100644 --- a/src/intel/vulkan/anv_device.c +++ b/src/intel/vulkan/anv_device.c @@ -202,7 +202,7 @@ anv_physical_device_init(struct anv_physical_device *device, isl_device_init(&device->isl_dev, &device->info, swizzled); - close(fd); + device->local_fd = fd; return VK_SUCCESS; fail: @@ -215,6 +215,7 @@ anv_physical_device_finish(struct anv_physical_device *device) { anv_finish_wsi(device); ralloc_free(device->compiler); + close(device->local_fd); } static const VkExtensionProperties global_extensions[] = { diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h index da1ca29..82e2831 100644 --- a/src/intel/vulkan/anv_private.h +++ b/src/intel/vulkan/anv_private.h @@ -532,6 +532,7 @@ struct anv_physical_device { uint8_t uuid[VK_UUID_SIZE]; struct wsi_device wsi_device; + int local_fd; }; struct anv_instance { diff --git a/src/intel/vulkan/anv_wsi_x11.c b/src/intel/vulkan/anv_wsi_x11.c index 60bc568..3042509 100644 --- a/src/intel/vulkan/anv_wsi_x11.c +++ b/src/intel/vulkan/anv_wsi_x11.c @@ -41,7 +41,9 @@ VkBool32 anv_GetPhysicalDeviceXcbPresentationSupportKHR( return wsi_get_physical_device_xcb_presentation_support( &device->wsi_device, &device->instance->alloc, - queueFamilyIndex, connection, visual_id); + queueFamilyIndex, + device->local_fd, + connection, visual_id); } VkBool32 anv_GetPhysicalDeviceXlibPresentationSupportKHR( @@ -55,7 +57,9 @@ VkBool32 anv_GetPhysicalDeviceXlibPresentationSupportKHR( return wsi_get_physical_device_xcb_presentation_support( &device->wsi_device, &device->instance->alloc, - queueFamilyIndex, XGetXCBConnection(dpy), visualID); + queueFamilyIndex, + device->local_fd, + XGetXCBConnection(dpy), visualID); } VkResult anv_CreateXcbSurfaceKHR( diff --git a/src/vulkan/wsi/Makefile.am b/src/vulkan/wsi/Makefile.am index a712799..b5ccf98 100644 --- a/src/vulkan/wsi/Makefile.am +++ b/src/vulkan/wsi/Makefile.am @@ -13,6 +13,7 @@ AM_CPPFLAGS = \ -I$(top_srcdir)/src/gallium/include AM_CFLAGS = \ + $(LIBDRM_CFLAGS) \ $(VISIBILITY_CFLAGS) VULKAN_LIB_DEPS = diff --git a/src/vulkan/wsi/wsi_common_x11.c b/src/vulkan/wsi/wsi_common_ x11.c index 64ba921..bc4af5a 100644 --- a/src/vulkan/wsi/wsi_common_x11.c +++ b/src/vulkan/wsi/wsi_common_x11.c @@ -33,8 +33,9 @@ #include <unistd.h> #include <errno.h> #include <string.h> - +#include <fcntl.h> #include <poll.h> +#include <xf86drm.h> #include "util/hash_table.h" #include "wsi_common.h" @@ -59,6 +60,52 @@ struct wsi_x11 { struct hash_table *connections; }; + +/** wsi_dri3_open + * + * Wrapper around xcb_dri3_open + */ +static int +wsi_dri3_open(xcb_connection_t *conn, + xcb_window_t root, + uint32_t provider) +{ + xcb_dri3_open_cookie_t cookie; + xcb_dri3_open_reply_t *reply; + int fd; + + cookie = xcb_dri3_open(conn, + root, + provider); + + reply = xcb_dri3_open_reply(conn, cookie, NULL); + if (!reply) + return -1; + + if (reply->nfd != 1) { + free(reply); + return -1; + } + + fd = xcb_dri3_open_reply_fds(conn, reply)[0]; + free(reply); + fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC); + + return fd; +} + +static int +x11_get_dri3_fd(xcb_connection_t *conn, xcb_screen_t *screen) +{ + int dri3_fd; + + dri3_fd = wsi_dri3_open(conn, screen->root, None); + if (dri3_fd == -1) + return -1; This helper is entirely pointless. Maybe it makes sense in your prime patches but it makes none as it stands. + + return dri3_fd; +} + static struct wsi_x11_connection * wsi_x11_connection_create(const VkAllocationCallbacks *alloc, xcb_connection_t *conn) @@ -255,6 +302,7 @@ VkBool32 wsi_get_physical_device_xcb_ presentation_support( struct wsi_device *wsi_device, VkAllocationCallbacks *alloc, uint32_t queueFamilyIndex, + int fd, xcb_connection_t* connection, xcb_visualid_t visual_id) { @@ -270,6 +318,25 @@ VkBool32 wsi_get_physical_device_xcb_ presentation_support( return false; } + xcb_screen_iterator_t screen_iter = + xcb_setup_roots_iterator(xcb_get_setup(connection)); + xcb_screen_t *screen = screen_iter.data; + + char *local_dev = drmGetRenderDeviceNameFromFd(fd); + int dri3_fd = x11_get_dri3_fd(connection, screen); + if (dri3_fd != -1) { + char *dri3_dev = drmGetRenderDeviceNameFromFd(dri3_fd); 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. + int ret; + close(dri3_fd); + + ret = strcmp(local_dev, dri3_dev); + + free(local_dev); You're leaking local_dev when dri3_fd == -1 + free(dri3_dev); + if (ret != 0) + return false; + } + unsigned visual_depth; if (!connection_get_visualtype(connection, visual_id, &visual_depth)) return false; diff --git a/src/vulkan/wsi/wsi_common_x11.h b/src/vulkan/wsi/wsi_common_ x11.h index 7166f09..01f1d66 100644 --- a/src/vulkan/wsi/wsi_common_x11.h +++ b/src/vulkan/wsi/wsi_common_x11.h @@ -29,6 +29,7 @@ VkBool32 wsi_get_physical_device_xcb_presentation_support( struct wsi_device *wsi_device, VkAllocationCallbacks *alloc, uint32_t queueFamilyIndex, + int local_fd, xcb_connection_t* connection, xcb_visualid_t visual_id); -- 2.9.3 _______________________________________________ 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