[Mesa-dev] [PATCH] i965: Allow creating image from different dma_buf fds

krh at bitplanet.net krh at bitplanet.net
Tue Aug 30 23:49:53 UTC 2016


From: "Kristian H. Kristensen" <hoegsberg at chromium.org>

As long as the dma_buf fds import to the same drm_intel_bo, we're fine.

Reviewed-by: Stéphane Marchesin <marcheu at chromium.org>
---
 src/mesa/drivers/dri/i965/intel_screen.c | 36 +++++++++++++++++++++++---------
 1 file changed, 26 insertions(+), 10 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/intel_screen.c b/src/mesa/drivers/dri/i965/intel_screen.c
index 84977a7..560935d 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -706,11 +706,6 @@ intel_create_image_from_fds(__DRIscreen *screen,
    if (fds == NULL || num_fds < 1)
       return NULL;
 
-   /* We only support all planes from the same bo */
-   for (i = 0; i < num_fds; i++)
-      if (fds[0] != fds[i])
-         return NULL;
-
    f = intel_image_format_lookup(fourcc);
    if (f == NULL)
       return NULL;
@@ -740,11 +735,25 @@ intel_create_image_from_fds(__DRIscreen *screen,
          size = end;
    }
 
-   image->bo = drm_intel_bo_gem_create_from_prime(intelScreen->bufmgr,
-                                                  fds[0], size);
-   if (image->bo == NULL) {
-      free(image);
-      return NULL;
+   /* We only support all planes from the same bo, but the fds may be
+    * different. Make sure all fds import to the same bo. The kernel and
+    * libdrm guarantees this, if the fds refer to the same kernel bo. */
+   for (i = 0; i < num_fds; i++) {
+      drm_intel_bo *bo =
+         drm_intel_bo_gem_create_from_prime(intelScreen->bufmgr, fds[i], size);
+      if (bo == NULL)
+         goto err_out;
+
+      if (i == 0) {
+         image->bo = bo;
+      } else {
+         /* We need to unref the bo in either case, so do it up front. We can
+          * still compare the pointers below to see if the bo matches.
+          */
+         drm_intel_bo_unreference(bo);
+         if (image->bo != bo)
+            goto err_out;
+      }
    }
 
    if (f->nplanes == 1) {
@@ -753,6 +762,13 @@ intel_create_image_from_fds(__DRIscreen *screen,
    }
 
    return image;
+
+err_out:
+   if (image->bo)
+      drm_intel_bo_unreference(image->bo);
+   free(image);
+
+   return NULL;
 }
 
 static __DRIimage *
-- 
2.8.0.rc3.226.g39d4020



More information about the mesa-dev mailing list