[Mesa-dev] [PATCH] st/dri: Check for kernel support before enabling fd sharing

Thomas Hellstrom thellstrom at vmware.com
Tue Dec 17 06:58:16 PST 2013


The dri2 state tracker is checking for driver support before enabling
dri2ImageExtension version 7. This commit adds a check that also the
kernel driver supports fd sharing through prime.

Note that this adds a libdrm dependency on dri2.c.

Signed-off-by: Thomas Hellstrom <thellstrom at vmware.com>
---
 src/gallium/state_trackers/dri/drm/dri2.c |   13 +++++++++++--
 src/gallium/targets/dri-vmwgfx/target.c   |    6 ------
 2 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/src/gallium/state_trackers/dri/drm/dri2.c b/src/gallium/state_trackers/dri/drm/dri2.c
index 8ff77b3..b9f6928 100644
--- a/src/gallium/state_trackers/dri/drm/dri2.c
+++ b/src/gallium/state_trackers/dri/drm/dri2.c
@@ -28,6 +28,7 @@
  *    <wallbraker at gmail.com> Chia-I Wu <olv at lunarg.com>
  */
 
+#include <xf86drm.h>
 #include "util/u_memory.h"
 #include "util/u_inlines.h"
 #include "util/u_format.h"
@@ -1051,10 +1052,18 @@ dri2_init_screen(__DRIscreen * sPriv)
       screen->default_throttle_frames = throttle_ret->val.val_int;
    }
 
+#ifdef DRM_CAP_PRIME /* Old libdrm? */
    if (dmabuf_ret && dmabuf_ret->val.val_bool) {
-      dri2ImageExtension.base.version = 7;
-      dri2ImageExtension.createImageFromFds = dri2_from_fds;
+      uint64_t cap;
+
+      if (drmGetCap(sPriv->fd, DRM_CAP_PRIME, &cap) == 0 &&
+          !!(cap & DRM_PRIME_CAP_IMPORT)) {
+
+         dri2ImageExtension.base.version = 7;
+         dri2ImageExtension.createImageFromFds = dri2_from_fds;
+      }
    }
+#endif /* DRM_CAP_PRIME */
 
    sPriv->extensions = dri_screen_extensions;
 
diff --git a/src/gallium/targets/dri-vmwgfx/target.c b/src/gallium/targets/dri-vmwgfx/target.c
index aaf37b0..e3fbda1 100644
--- a/src/gallium/targets/dri-vmwgfx/target.c
+++ b/src/gallium/targets/dri-vmwgfx/target.c
@@ -31,12 +31,6 @@ static const struct drm_conf_ret throttle_ret = {
    .val.val_int = 2,
 };
 
-/* Technically this requires kernel support that is not yet
- * widespread.
- *
- * We could check for support in create_screen and return the correct
- * value, but for now just return true in all cases.
- */
 static const struct drm_conf_ret share_fd_ret = {
    .type = DRM_CONF_BOOL,
    .val.val_int = true,
-- 
1.7.10.4


More information about the mesa-dev mailing list