[Mesa-dev] [PATCH v2 01/13] vl/dri3: add DRI3 support and implement create and destroy

Leo Liu leo.liu at amd.com
Thu May 12 17:13:31 UTC 2016


required functions into place for implementation, create screen
with device fd returned from X server, also bail out to DRI2
with certain conditions.

v2: -organize the error out path (Axel)
    -squash previous patch 1 and 2 into one (Emil)

Signed-off-by: Leo Liu <leo.liu at amd.com>
Reviewed-by: Alex Deucher <alexander.deucher at amd.com>
Reviewed-by: Christian K├Ânig <christian.koenig at amd.com>
---
 configure.ac                              |   7 +-
 src/gallium/auxiliary/Makefile.sources    |   5 +
 src/gallium/auxiliary/vl/vl_winsys.h      |   5 +
 src/gallium/auxiliary/vl/vl_winsys_dri3.c | 198 ++++++++++++++++++++++++++++++
 4 files changed, 214 insertions(+), 1 deletion(-)
 create mode 100644 src/gallium/auxiliary/vl/vl_winsys_dri3.c

diff --git a/configure.ac b/configure.ac
index 023110e..8c3960a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1779,7 +1779,12 @@ if test "x$enable_xvmc" = xyes -o \
         "x$enable_vdpau" = xyes -o \
         "x$enable_omx" = xyes -o \
         "x$enable_va" = xyes; then
-    PKG_CHECK_MODULES([VL], [x11-xcb xcb xcb-dri2 >= $XCBDRI2_REQUIRED])
+    if test x"$enable_dri3" = xyes; then
+        PKG_CHECK_MODULES([VL], [xcb-dri3 xcb-present xcb-sync xshmfence >= $XSHMFENCE_REQUIRED
+                                 x11-xcb xcb xcb-dri2 >= $XCBDRI2_REQUIRED])
+    else
+        PKG_CHECK_MODULES([VL], [x11-xcb xcb xcb-dri2 >= $XCBDRI2_REQUIRED])
+    fi
     need_gallium_vl_winsys=yes
 fi
 AM_CONDITIONAL(NEED_GALLIUM_VL_WINSYS, test "x$need_gallium_vl_winsys" = xyes)
diff --git a/src/gallium/auxiliary/Makefile.sources b/src/gallium/auxiliary/Makefile.sources
index 84da85c..44b3fec 100644
--- a/src/gallium/auxiliary/Makefile.sources
+++ b/src/gallium/auxiliary/Makefile.sources
@@ -354,6 +354,11 @@ VL_WINSYS_SOURCES := \
 	vl/vl_winsys_dri.c \
 	vl/vl_winsys_drm.c
 
+if HAVE_DRI3
+VL_WINSYS_SOURCES += \
+	vl/vl_winsys_dri3.c
+endif
+
 VL_STUB_SOURCES := \
 	vl/vl_stubs.c
 
diff --git a/src/gallium/auxiliary/vl/vl_winsys.h b/src/gallium/auxiliary/vl/vl_winsys.h
index 1af7653..26db9f2 100644
--- a/src/gallium/auxiliary/vl/vl_winsys.h
+++ b/src/gallium/auxiliary/vl/vl_winsys.h
@@ -69,4 +69,9 @@ vl_dri2_screen_create(Display *display, int screen);
 struct vl_screen *
 vl_drm_screen_create(int fd);
 
+#if defined(HAVE_DRI3)
+struct vl_screen *
+vl_dri3_screen_create(Display *display, int screen);
+#endif
+
 #endif
diff --git a/src/gallium/auxiliary/vl/vl_winsys_dri3.c b/src/gallium/auxiliary/vl/vl_winsys_dri3.c
new file mode 100644
index 0000000..74f3891
--- /dev/null
+++ b/src/gallium/auxiliary/vl/vl_winsys_dri3.c
@@ -0,0 +1,198 @@
+/**************************************************************************
+ *
+ * Copyright 2016 Advanced Micro Devices, Inc.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+#include <fcntl.h>
+
+#include <X11/Xlib-xcb.h>
+#include <xcb/dri3.h>
+#include <xcb/present.h>
+
+#include "loader.h"
+
+#include "pipe/p_screen.h"
+#include "pipe-loader/pipe_loader.h"
+
+#include "util/u_memory.h"
+#include "vl/vl_winsys.h"
+
+struct vl_dri3_screen
+{
+   struct vl_screen base;
+   xcb_connection_t *conn;
+   xcb_drawable_t drawable;
+};
+
+static void
+vl_dri3_flush_frontbuffer(struct pipe_screen *screen,
+                          struct pipe_resource *resource,
+                          unsigned level, unsigned layer,
+                          void *context_private, struct pipe_box *sub_box)
+{
+   /* TODO */
+   return;
+}
+
+static struct pipe_resource *
+vl_dri3_screen_texture_from_drawable(struct vl_screen *vscreen, void *drawable)
+{
+   /* TODO */
+   return NULL;
+}
+
+static struct u_rect *
+vl_dri3_screen_get_dirty_area(struct vl_screen *vscreen)
+{
+   /* TODO */
+   return NULL;
+}
+
+static uint64_t
+vl_dri3_screen_get_timestamp(struct vl_screen *vscreen, void *drawable)
+{
+   /* TODO */
+   return 0;
+}
+
+static void
+vl_dri3_screen_set_next_timestamp(struct vl_screen *vscreen, uint64_t stamp)
+{
+   /* TODO */
+   return;
+}
+
+static void *
+vl_dri3_screen_get_private(struct vl_screen *vscreen)
+{
+   return vscreen;
+}
+
+static void
+vl_dri3_screen_destroy(struct vl_screen *vscreen)
+{
+   struct vl_dri3_screen *scrn = (struct vl_dri3_screen *)vscreen;
+
+   assert(vscreen);
+
+   scrn->base.pscreen->destroy(scrn->base.pscreen);
+   pipe_loader_release(&scrn->base.dev, 1);
+   FREE(scrn);
+
+   return;
+}
+
+struct vl_screen *
+vl_dri3_screen_create(Display *display, int screen)
+{
+   struct vl_dri3_screen *scrn;
+   const xcb_query_extension_reply_t *extension;
+   xcb_dri3_open_cookie_t open_cookie;
+   xcb_dri3_open_reply_t *open_reply;
+   xcb_get_geometry_cookie_t geom_cookie;
+   xcb_get_geometry_reply_t *geom_reply;
+   int is_different_gpu;
+   int fd;
+
+   assert(display);
+
+   scrn = CALLOC_STRUCT(vl_dri3_screen);
+   if (!scrn)
+      return NULL;
+
+   scrn->conn = XGetXCBConnection(display);
+   if (!scrn->conn)
+      goto free_screen;
+
+   xcb_prefetch_extension_data(scrn->conn , &xcb_dri3_id);
+   xcb_prefetch_extension_data(scrn->conn, &xcb_present_id);
+   extension = xcb_get_extension_data(scrn->conn, &xcb_dri3_id);
+   if (!(extension && extension->present))
+      goto free_screen;
+   extension = xcb_get_extension_data(scrn->conn, &xcb_present_id);
+   if (!(extension && extension->present))
+      goto free_screen;
+
+   open_cookie = xcb_dri3_open(scrn->conn, RootWindow(display, screen), None);
+   open_reply = xcb_dri3_open_reply(scrn->conn, open_cookie, NULL);
+   if (!open_reply)
+      goto free_screen;
+   if (open_reply->nfd != 1) {
+      free(open_reply);
+      goto free_screen;
+   }
+
+   fd = xcb_dri3_open_reply_fds(scrn->conn, open_reply)[0];
+   if (fd < 0) {
+      free(open_reply);
+      goto free_screen;
+   }
+   fcntl(fd, F_SETFD, FD_CLOEXEC);
+   free(open_reply);
+
+   fd = loader_get_user_preferred_fd(fd, &is_different_gpu);
+   /* TODO support different GPU */
+   if (is_different_gpu)
+      goto close_fd;
+
+   geom_cookie = xcb_get_geometry(scrn->conn, RootWindow(display, screen));
+   geom_reply = xcb_get_geometry_reply(scrn->conn, geom_cookie, NULL);
+   if (!geom_reply)
+      goto close_fd;
+   /* TODO support depth other than 24 */
+   if (geom_reply->depth != 24) {
+      free(geom_reply);
+      goto close_fd;
+   }
+   free(geom_reply);
+
+   if (pipe_loader_drm_probe_fd(&scrn->base.dev, fd))
+      scrn->base.pscreen = pipe_loader_create_screen(scrn->base.dev);
+
+   if (!scrn->base.pscreen)
+      goto release_pipe;
+
+   scrn->base.destroy = vl_dri3_screen_destroy;
+   scrn->base.texture_from_drawable = vl_dri3_screen_texture_from_drawable;
+   scrn->base.get_dirty_area = vl_dri3_screen_get_dirty_area;
+   scrn->base.get_timestamp = vl_dri3_screen_get_timestamp;
+   scrn->base.set_next_timestamp = vl_dri3_screen_set_next_timestamp;
+   scrn->base.get_private = vl_dri3_screen_get_private;
+   scrn->base.pscreen->flush_frontbuffer = vl_dri3_flush_frontbuffer;
+
+   return &scrn->base;
+
+release_pipe:
+   if (scrn->base.dev) {
+      pipe_loader_release(&scrn->base.dev, 1);
+      fd = -1;
+   }
+close_fd:
+   if (fd != -1)
+      close(fd);
+free_screen:
+   FREE(scrn);
+   return NULL;
+}
-- 
2.7.4



More information about the mesa-dev mailing list