[Mesa-dev] [PATCH 16/32] i965: Separate image allocation with modifiers

Ben Widawsky ben at bwidawsk.net
Tue Jan 3 02:37:07 UTC 2017


Since the code doesn't support modifiers yet, this patch should do
nothing other than prepare for more patches.

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 | 73 ++++++++++++++++++++++++++------
 1 file changed, 60 insertions(+), 13 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/intel_screen.c b/src/mesa/drivers/dri/i965/intel_screen.c
index 056da48a07..df5d69834f 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -541,6 +541,43 @@ intel_destroy_image(__DRIimage *image)
    free(image);
 }
 
+static int
+create_image_with_modifier(struct intel_screen *screen,
+                             __DRIimage *image, uint64_t modifier,
+                             int width, int height, int cpp)
+{
+   uint32_t tiling;
+   unsigned long pitch;
+
+   switch (modifier) {
+   case I915_FORMAT_MOD_Y_TILED:
+      tiling = I915_TILING_Y;
+   }
+
+   /* For now, all modifiers require some tiling */
+   assert(tiling);
+
+   cpp = _mesa_get_format_bytes(image->format);
+   image->bo = drm_intel_bo_alloc_tiled(screen->bufmgr, "image+mod",
+                                        width, height, cpp, &tiling,
+                                        &pitch, 0);
+   if (image->bo == NULL)
+      return false;
+
+   if (tiling != I915_TILING_Y) {
+      drm_intel_bo_unreference(image->bo);
+      return false;
+   }
+
+   image->width = width;
+   image->height = height;
+   image->pitch = pitch;
+   image->tile_y = I915_TILING_Y;
+   image->modifier = modifier;
+
+   return true;
+}
+
 static __DRIimage *
 __intel_create_image(__DRIscreen *dri_screen,
 		   int width, int height, int format,
@@ -554,6 +591,7 @@ __intel_create_image(__DRIscreen *dri_screen,
    uint32_t tiling = I915_TILING_X;
    int cpp;
    unsigned long pitch;
+   uint64_t modifier = 0;
 
    /* Callers of this may specify a modifier, or a dri usage, but not both. The
     * newer modifier interface deprecates the older usage flags
@@ -566,6 +604,15 @@ __intel_create_image(__DRIscreen *dri_screen,
    if (image == NULL)
       return NULL;
 
+   if (use & __DRI_IMAGE_USE_CURSOR) {
+      if (width != 64 || height != 64)
+	 return NULL;
+      tiling = I915_TILING_NONE;
+   }
+
+   if (use & __DRI_IMAGE_USE_LINEAR)
+      tiling = I915_TILING_NONE;
+
    /* Prioritize the modifiers based on what we think will work best. */
    for (int i = 0; i < count; i++) {
       switch (modifiers[i]) {
@@ -582,26 +629,26 @@ __intel_create_image(__DRIscreen *dri_screen,
             continue;
          }
 
-         image->modifier = I915_FORMAT_MOD_Y_TILED;
+         if (tiling == I915_TILING_NONE) {
+            _mesa_warning(NULL, "Invalid use/modifier combination (%x %llx)\n",
+                          use, I915_FORMAT_MOD_Y_TILED);
+            continue;
+         }
+
+         modifier = I915_FORMAT_MOD_Y_TILED;
          break;
       }
    }
 
-   if (use & __DRI_IMAGE_USE_CURSOR) {
-      if (width != 64 || height != 64)
-	 return NULL;
-      tiling = I915_TILING_NONE;
-   }
-
-   if (use & __DRI_IMAGE_USE_LINEAR)
-      tiling = I915_TILING_NONE;
+   cpp = _mesa_get_format_bytes(image->format);
 
-   if (image->modifier == I915_FORMAT_MOD_Y_TILED) {
-      assert(tiling != I915_TILING_NONE);
-      tiling = I915_TILING_Y;
+   if (modifier) {
+      if (create_image_with_modifier(screen, image, modifier, width,
+                                     height, cpp)) {
+         return image;
+      }
    }
 
-   cpp = _mesa_get_format_bytes(image->format);
    image->bo = drm_intel_bo_alloc_tiled(screen->bufmgr, "image",
                                         width, height, cpp, &tiling,
                                         &pitch, 0);
-- 
2.11.0



More information about the mesa-dev mailing list