[Mesa-dev] [PATCH v14 26/36] i965: Pretend that CCS modified images are two planes

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


From: Ben Widawsky <ben at bwidawsk.net>

v2: move is_aux into if block. (Jason)
Use else block instead of goto (Jason)

v3: Fix up logic for is_aux (Ben)
Fix up size calculations and add FIXME (Ben)

Cc: Jason Ekstrand <jason at jlekstrand.net>
Signed-off-by: Ben Widawsky <ben at bwidawsk.net>
Acked-by: Daniel Stone <daniels at collabora.com>
---
 src/mesa/drivers/dri/i965/intel_screen.c | 98 +++++++++++++++++++++++++++-----
 1 file changed, 83 insertions(+), 15 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/intel_screen.c b/src/mesa/drivers/dri/i965/intel_screen.c
index 9509ba2..86618d7 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -295,6 +295,10 @@ static const struct {
    uint32_t tiling;
    uint64_t modifier;
    unsigned height_align;
+   unsigned aux_w_block;
+   unsigned aux_w_align;
+   unsigned aux_h_block;
+   unsigned aux_h_align;
 } tiling_modifier_map[] = {
    { .tiling = I915_TILING_NONE, .modifier = DRM_FORMAT_MOD_LINEAR,
      .height_align = 1 },
@@ -343,6 +347,57 @@ get_tiled_height(uint32_t tiling, unsigned height)
    unreachable("get_tiled_height received unknown tiling mode");
 }
 
+static unsigned
+get_aux_width(uint64_t modifier, unsigned width)
+{
+   int i;
+
+   for (i = 0; i < ARRAY_SIZE(tiling_modifier_map); i++) {
+      if (tiling_modifier_map[i].modifier != modifier)
+         continue;
+      if (tiling_modifier_map[i].aux_w_block == 0)
+         return 0;
+      return ALIGN(DIV_ROUND_UP(width, tiling_modifier_map[i].aux_w_block),
+                   tiling_modifier_map[i].aux_w_align);
+   }
+
+   unreachable("get_aux_width received unknown modifier");
+}
+
+static unsigned
+get_aux_stride(uint64_t modifier, unsigned stride)
+{
+   int i;
+
+   for (i = 0; i < ARRAY_SIZE(tiling_modifier_map); i++) {
+      if (tiling_modifier_map[i].modifier != modifier)
+         continue;
+      if (tiling_modifier_map[i].aux_w_block == 0)
+         return 0;
+      return ALIGN(stride / tiling_modifier_map[i].aux_w_block,
+                   tiling_modifier_map[i].aux_w_align);
+   }
+
+   unreachable("get_aux_stride received unknown modifier");
+}
+
+static unsigned
+get_aux_height(uint64_t modifier, unsigned height)
+{
+   int i;
+
+   for (i = 0; i < ARRAY_SIZE(tiling_modifier_map); i++) {
+      if (tiling_modifier_map[i].modifier != modifier)
+         continue;
+      if (tiling_modifier_map[i].aux_h_block == 0)
+         return 0;
+      return ALIGN(DIV_ROUND_UP(height, tiling_modifier_map[i].aux_h_block),
+                   tiling_modifier_map[i].aux_h_align);
+   }
+
+   unreachable("get_aux_height received unknown modifier");
+}
+
 static void
 intel_image_warn_if_unaligned(__DRIimage *image, const char *func)
 {
@@ -760,7 +815,7 @@ intel_query_image(__DRIimage *image, int attrib, int *value)
    case __DRI_IMAGE_ATTRIB_FOURCC:
       return intel_lookup_fourcc(image->dri_format, value);
    case __DRI_IMAGE_ATTRIB_NUM_PLANES:
-      *value = 1;
+      *value = image->aux_offset ? 2: 1;
       return true;
    case __DRI_IMAGE_ATTRIB_OFFSET:
       *value = image->offset;
@@ -984,20 +1039,33 @@ intel_from_planar(__DRIimage *parent, int plane, void *loaderPrivate)
     struct intel_image_format *f;
     __DRIimage *image;
 
-    if (parent == NULL || parent->planar_format == NULL)
-        return NULL;
-
-    f = parent->planar_format;
-
-    if (plane >= f->nplanes)
-        return NULL;
-
-    width = parent->width >> f->planes[plane].width_shift;
-    height = parent->height >> f->planes[plane].height_shift;
-    dri_format = f->planes[plane].dri_format;
-    index = f->planes[plane].buffer_index;
-    offset = parent->offsets[index];
-    stride = parent->strides[index];
+    if (parent == NULL) {
+       return NULL;
+    } else if (parent->planar_format == NULL) {
+       const bool is_aux = parent->aux_offset && plane == 1;
+       if (!is_aux)
+          return NULL;
+
+       width = get_aux_width(parent->modifier, parent->width);
+       height = get_aux_width(parent->modifier, parent->height);
+       stride = get_aux_stride(parent->modifier, parent->pitch);
+       dri_format = parent->dri_format;
+       offset = parent->aux_offset;
+    } else {
+       /* Planar formats don't support aux buffers/images */
+       assert(!parent->aux_offset);
+       f = parent->planar_format;
+
+       if (plane >= f->nplanes)
+          return NULL;
+
+       width = parent->width >> f->planes[plane].width_shift;
+       height = parent->height >> f->planes[plane].height_shift;
+       dri_format = f->planes[plane].dri_format;
+       index = f->planes[plane].buffer_index;
+       offset = parent->offsets[index];
+       stride = parent->strides[index];
+    }
 
     image = intel_allocate_image(parent->screen, dri_format, loaderPrivate);
     if (image == NULL)
-- 
2.10.0



More information about the mesa-dev mailing list