[Mesa-dev] [PATCH v13 35/36] i965: Support dmabuf import with modifiers

Daniel Stone daniels at collabora.com
Fri May 19 09:38:18 UTC 2017


From: Varad Gautam <varadgautam at gmail.com>

Add support for createImageFromDmaBufs2, adding a modifier to the
original.

Signed-off-by: Varad Gautam <varadgautam at gmail.com>
Signed-off-by: Daniel Stone <daniels at collabora.com>
---
 src/mesa/drivers/dri/i965/intel_mipmap_tree.c |   6 ++
 src/mesa/drivers/dri/i965/intel_screen.c      | 116 +++++++++++++++++++++++---
 2 files changed, 109 insertions(+), 13 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/intel_mipmap_tree.c b/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
index f8b72d668a..8ece47c2ce 100644
--- a/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
+++ b/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
@@ -847,6 +847,12 @@ intel_miptree_create_for_image(struct brw_context *intel,
    assert(mt->logical_depth0 == 1);
 
    create_ccs_buf_for_image(intel, image, mt);
+   if (image->dma_buf_imported)
+      /* We have an imported image with aux data. Mark it unresolved.
+       */
+      intel_miptree_set_fast_clear_state(intel, mt, mt->first_level,
+                                         0, mt->logical_depth0,
+                                         INTEL_FAST_CLEAR_STATE_UNRESOLVED);
 
    return mt;
 }
diff --git a/src/mesa/drivers/dri/i965/intel_screen.c b/src/mesa/drivers/dri/i965/intel_screen.c
index 1238afb5cb..f366fc4d4d 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -919,15 +919,19 @@ intel_create_image_from_names(__DRIscreen *dri_screen,
 }
 
 static __DRIimage *
-intel_create_image_from_fds(__DRIscreen *dri_screen,
-                            int width, int height, int fourcc,
-                            int *fds, int num_fds, int *strides, int *offsets,
-                            void *loaderPrivate)
+intel_create_image_from_fds_common(__DRIscreen *dri_screen,
+                                   int width, int height, int fourcc,
+                                   int *fds, int num_fds, int *strides,
+                                   int *offsets, uint64_t *modifiers,
+                                   void *loaderPrivate)
 {
    struct intel_screen *screen = dri_screen->driverPrivate;
    struct intel_image_format *f;
    __DRIimage *image;
-   uint32_t tiling = I915_TILING_X; /* default to X-tiling */
+   uint64_t modifier;
+   uint32_t tiling;
+   unsigned tiled_height;
+   unsigned ccs_height;
    int i, index;
 
    if (fds == NULL || num_fds < 1)
@@ -937,6 +941,22 @@ intel_create_image_from_fds(__DRIscreen *dri_screen,
    if (f == NULL)
       return NULL;
 
+   if (modifiers) {
+      modifier = select_best_modifier(&screen->devinfo, modifiers, 1);
+      if (modifier == DRM_FORMAT_MOD_INVALID)
+         return NULL; /* user specified unsupported modifier */
+      tiling = modifier_to_tiling(modifier);
+      ccs_height = get_aux_height(modifier, height);
+   } else {
+      modifier = DRM_FORMAT_MOD_INVALID;
+      /* X-tiling is the default, and also allows us to infer the tiling
+       * mode from the BO */
+      tiling = I915_TILING_X;
+      ccs_height = 0;
+   }
+
+   tiled_height = get_tiled_height(tiling, height);
+
    if (f->nplanes == 1)
       image = intel_allocate_image(screen, f->planes[0].dri_format,
                                    loaderPrivate);
@@ -958,8 +978,10 @@ intel_create_image_from_fds(__DRIscreen *dri_screen,
       image->offsets[index] = offsets[index];
       image->strides[index] = strides[index];
 
-      const int plane_height = height >> f->planes[i].height_shift;
-      const int end = offsets[index] + plane_height * strides[index];
+      const int plane_height = tiled_height >> f->planes[i].height_shift;
+      const int end = offsets[index] +
+                      (plane_height + ccs_height) * strides[index];
+
       if (size < end)
          size = end;
    }
@@ -970,10 +992,18 @@ intel_create_image_from_fds(__DRIscreen *dri_screen,
       free(image);
       return NULL;
    }
-   image->modifier = tiling_to_modifier(image->bo->tiling_mode);
+
+   /* If we've explicitly specified a modifier, then we use that; else
+    * we infer the modifier from the BO's tiling mode. */
+   if (modifier != DRM_FORMAT_MOD_INVALID)
+      image->modifier = modifier;
+   else
+      image->modifier = tiling_to_modifier(image->bo->tiling_mode);
 
    if (f->nplanes == 1) {
       image->offset = image->offsets[0];
+      if (ccs_height)
+         image->aux_offset = tiled_height * image->pitch;
       intel_image_warn_if_unaligned(image, __func__);
    }
 
@@ -981,10 +1011,22 @@ intel_create_image_from_fds(__DRIscreen *dri_screen,
 }
 
 static __DRIimage *
-intel_create_image_from_dma_bufs(__DRIscreen *dri_screen,
+intel_create_image_from_fds(__DRIscreen *dri_screen,
+                            int width, int height, int fourcc,
+                            int *fds, int num_fds, int *strides, int *offsets,
+                            void *loaderPrivate)
+{
+   return intel_create_image_from_fds_common(dri_screen, width, height,
+                                             fourcc, fds, num_fds, strides,
+                                             offsets, NULL, loaderPrivate);
+}
+
+static __DRIimage *
+intel_create_image_from_dma_bufs_common(__DRIscreen *dri_screen,
                                  int width, int height, int fourcc,
                                  int *fds, int num_fds,
                                  int *strides, int *offsets,
+                                 uint64_t *modifiers,
                                  enum __DRIYUVColorSpace yuv_color_space,
                                  enum __DRISampleRange sample_range,
                                  enum __DRIChromaSiting horizontal_siting,
@@ -1000,9 +1042,10 @@ intel_create_image_from_dma_bufs(__DRIscreen *dri_screen,
       return NULL;
    }
 
-   image = intel_create_image_from_fds(dri_screen, width, height, fourcc, fds,
-                                       num_fds, strides, offsets,
-                                       loaderPrivate);
+   image = intel_create_image_from_fds_common(dri_screen, width, height,
+                                              fourcc, fds, num_fds,
+                                              strides, offsets,
+                                              modifiers, loaderPrivate);
 
    /*
     * Invalid parameters and any inconsistencies between are assumed to be
@@ -1025,6 +1068,52 @@ intel_create_image_from_dma_bufs(__DRIscreen *dri_screen,
 }
 
 static __DRIimage *
+intel_create_image_from_dma_bufs(__DRIscreen *dri_screen,
+                                 int width, int height, int fourcc,
+                                 int *fds, int num_fds,
+                                 int *strides, int *offsets,
+                                 enum __DRIYUVColorSpace yuv_color_space,
+                                 enum __DRISampleRange sample_range,
+                                 enum __DRIChromaSiting horizontal_siting,
+                                 enum __DRIChromaSiting vertical_siting,
+                                 unsigned *error,
+                                 void *loaderPrivate)
+{
+   return intel_create_image_from_dma_bufs_common(dri_screen, width, height,
+                                                  fourcc, fds, num_fds,
+                                                  strides, offsets, NULL,
+                                                  yuv_color_space,
+                                                  sample_range,
+                                                  horizontal_siting,
+                                                  vertical_siting, error,
+                                                  loaderPrivate);
+}
+
+static __DRIimage *
+intel_create_image_from_dma_bufs2(__DRIscreen *dri_screen,
+                                  int width, int height, int fourcc,
+                                  int *fds, int num_fds,
+                                  int *strides, int *offsets,
+                                  uint64_t *modifiers,
+                                  enum __DRIYUVColorSpace yuv_color_space,
+                                  enum __DRISampleRange sample_range,
+                                  enum __DRIChromaSiting horizontal_siting,
+                                  enum __DRIChromaSiting vertical_siting,
+                                  unsigned *error,
+                                  void *loaderPrivate)
+{
+   return intel_create_image_from_dma_bufs_common(dri_screen, width, height,
+                                                  fourcc, fds, num_fds,
+                                                  strides, offsets,
+                                                  modifiers,
+                                                  yuv_color_space,
+                                                  sample_range,
+                                                  horizontal_siting,
+                                                  vertical_siting, error,
+                                                  loaderPrivate);
+}
+
+static __DRIimage *
 intel_from_planar(__DRIimage *parent, int plane, void *loaderPrivate)
 {
     int width, height, offset, stride, dri_format, index;
@@ -1084,7 +1173,7 @@ intel_from_planar(__DRIimage *parent, int plane, void *loaderPrivate)
 }
 
 static const __DRIimageExtension intelImageExtension = {
-    .base = { __DRI_IMAGE, 14 },
+    .base = { __DRI_IMAGE, 15 },
 
     .createImageFromName                = intel_create_image_from_name,
     .createImageFromRenderbuffer        = intel_create_image_from_renderbuffer,
@@ -1103,6 +1192,7 @@ static const __DRIimageExtension intelImageExtension = {
     .mapImage                           = NULL,
     .unmapImage                         = NULL,
     .createImageWithModifiers           = intel_create_image_with_modifiers,
+    .createImageFromDmaBufs2            = intel_create_image_from_dma_bufs2,
 };
 
 static uint64_t
-- 
2.13.0



More information about the mesa-dev mailing list