[Mesa-dev] [PATCH v14 15/36] i965: Improve same-buffer restriction for imports

Varad Gautam varadgautam at gmail.com
Tue May 30 11:53:48 UTC 2017


From: Daniel Stone <daniels at collabora.com>

Intel hardware requires that all planes of an image come from the same
buffer, which is currently implemented by testing that all FDs are
numerically the same.

However, when going through a winsys (e.g.) or anything which transits
FDs individually, the FDs may be different even if the underlying buffer
is the same.

Instead of checking the FDs for equality, we must check if they actually
point to the same buffer (Jason).

Signed-off-by: Daniel Stone <daniels at collabora.com>
Signed-off-by: Varad Gautam <varad.gautam at collabora.com>
---
 src/mesa/drivers/dri/i965/intel_screen.c | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/intel_screen.c b/src/mesa/drivers/dri/i965/intel_screen.c
index 9842de6..ddaa8cf 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -815,20 +815,32 @@ intel_create_image_from_fds(__DRIscreen *dri_screen,
    struct intel_screen *screen = dri_screen->driverPrivate;
    struct intel_image_format *f;
    __DRIimage *image;
-   int i, index;
+   struct brw_bo *bo;
+   int i, index, size = 0;
 
    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;
 
+   for (i = 0; i < f->nplanes; i++) {
+      index = f->planes[i].buffer_index;
+      const int plane_height = height >> f->planes[i].height_shift;
+      const int end = offsets[index] + plane_height * strides[index];
+      if (size < end)
+         size = end;
+   }
+   /* We only support all planes from the same bo.
+    * brw_bo_gem_create_from_prime() should return the same pointer for all
+    * fds received here */
+   bo = brw_bo_gem_create_from_prime(screen->bufmgr, fds[0], size);
+   for (i = 1; i < num_fds; i++) {
+      if (bo != brw_bo_gem_create_from_prime(screen->bufmgr, fds[i], size))
+         return NULL;
+   }
+
    if (f->nplanes == 1)
       image = intel_allocate_image(screen, f->planes[0].dri_format,
                                    loaderPrivate);
-- 
2.10.0



More information about the mesa-dev mailing list