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

Ben Widawsky ben at bwidawsk.net
Tue Jan 24 06:21:39 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 | 64 ++++++++++++++++++++++++--------
 1 file changed, 49 insertions(+), 15 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/intel_screen.c b/src/mesa/drivers/dri/i965/intel_screen.c
index b7c0a55231..e3fe2a468f 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -599,6 +599,48 @@ select_best_modifier(struct gen_device_info *devinfo,
 #undef YTILE
 }
 
+static int
+create_image_with_modifier(struct intel_screen *screen,
+                             __DRIimage *image, uint64_t modifier,
+                             int width, int height, int cpp)
+{
+   uint32_t tiling = I915_TILING_X;
+   unsigned long pitch;
+
+   switch (modifier) {
+   case I915_FORMAT_MOD_Y_TILED:
+      tiling = I915_TILING_Y;
+      break;
+   case I915_FORMAT_MOD_X_TILED:
+      assert(tiling == I915_TILING_X);
+      break;
+   case DRM_FORMAT_MOD_LINEAR:
+      tiling = I915_TILING_NONE;
+      break;
+   case DRM_FORMAT_MOD_INVALID:
+   default:
+      break;
+   }
+
+   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->modifier = modifier;
+
+   return true;
+}
+
 static __DRIimage *
 __intel_create_image(__DRIscreen *dri_screen,
 		   int width, int height, int format,
@@ -623,20 +665,6 @@ __intel_create_image(__DRIscreen *dri_screen,
    assert(!(use && count));
 
    uint64_t modifier = select_best_modifier(&screen->devinfo, modifiers, count);
-   switch (modifier) {
-   case I915_FORMAT_MOD_X_TILED:
-      assert(tiling == I915_TILING_X);
-      break;
-   case DRM_FORMAT_MOD_LINEAR:
-      tiling = I915_TILING_NONE;
-      break;
-   case I915_FORMAT_MOD_Y_TILED:
-      tiling = I915_TILING_Y;
-      break;
-   case DRM_FORMAT_MOD_INVALID:
-   default:
-         break;
-   }
 
    if (use & __DRI_IMAGE_USE_CURSOR) {
       if (width != 64 || height != 64)
@@ -652,6 +680,13 @@ __intel_create_image(__DRIscreen *dri_screen,
       return NULL;
 
    cpp = _mesa_get_format_bytes(image->format);
+   if (modifier != DRM_FORMAT_MOD_INVALID) {
+      if (create_image_with_modifier(screen, image, modifier, width,
+                                     height, cpp)) {
+         return image;
+      }
+   }
+
    image->bo = drm_intel_bo_alloc_tiled(screen->bufmgr, "image",
                                         width, height, cpp, &tiling,
                                         &pitch, 0);
@@ -662,7 +697,6 @@ __intel_create_image(__DRIscreen *dri_screen,
    image->width = width;
    image->height = height;
    image->pitch = pitch;
-   image->modifier = modifier;
 
    return image;
 }
-- 
2.11.0



More information about the mesa-dev mailing list