[Mesa-dev] [RFC PATCH 5/5] i965/miptree: recurse to miptree_map for depth in map_depthstencil

Scott D Phillips scott.d.phillips at intel.com
Wed Apr 11 17:04:22 UTC 2018


Call back to intel_miptree_map when mapping the separate depth
miptree in map_depthstencil. This brings us back to the mapping
method decision tree in miptree_map where we hopefully find the
most performant mapping method for depth.
---
Here's an idea for a replacement of patch 5. Squirreling the
depthstencil map away from the miptree when doing the recursive
map is kinda yuck, but it lets us go back to the main miptree_map
function for the depth map where we can get cpu detiling or
whatever else.

 src/mesa/drivers/dri/i965/intel_mipmap_tree.c | 54 +++++++++++++++------------
 1 file changed, 31 insertions(+), 23 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/intel_mipmap_tree.c b/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
index 98f71471bda..652074eb9fc 100644
--- a/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
+++ b/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
@@ -3525,27 +3525,30 @@ intel_miptree_map_depthstencil(struct brw_context *brw,
    if (!(map->mode & GL_MAP_INVALIDATE_RANGE_BIT)) {
       uint32_t *packed_map = map->ptr;
       uint8_t *s_map = intel_miptree_map_raw(brw, s_mt, GL_MAP_READ_BIT);
-      uint32_t *z_map = intel_miptree_map_raw(brw, z_mt, GL_MAP_READ_BIT);
       unsigned int s_image_x, s_image_y;
-      unsigned int z_image_x, z_image_y;
+
+      uint32_t *z_map = NULL;
+      ptrdiff_t z_stride = 0;
+
+      z_mt->level[level].slice[slice].map = NULL;
+      intel_miptree_map(brw, z_mt, level, slice, map->x, map->y, map->w, map->h,
+                        map->mode | BRW_MAP_DIRECT_BIT, (void **)&z_map,
+                        &z_stride);
+      assert(z_map && z_stride);
 
       intel_miptree_get_image_offset(s_mt, level, slice,
 				     &s_image_x, &s_image_y);
-      intel_miptree_get_image_offset(z_mt, level, slice,
-				     &z_image_x, &z_image_y);
 
       for (uint32_t y = 0; y < map->h; y++) {
+         uint32_t *z_line = (uint32_t *)((uint8_t *)z_map + z_stride * y);
 	 for (uint32_t x = 0; x < map->w; x++) {
 	    int map_x = map->x + x, map_y = map->y + y;
 	    ptrdiff_t s_offset = intel_offset_S8(s_mt->surf.row_pitch,
 						 map_x + s_image_x,
 						 map_y + s_image_y,
 						 brw->has_swizzling);
-	    ptrdiff_t z_offset = ((map_y + z_image_y) *
-                                  (z_mt->surf.row_pitch / 4) +
-				  (map_x + z_image_x));
 	    uint8_t s = s_map[s_offset];
-	    uint32_t z = z_map[z_offset];
+	    uint32_t z = z_line[x];
 
 	    if (map_z32f_x24s8) {
 	       packed_map[(y * map->w + x) * 2 + 0] = z;
@@ -3557,12 +3560,13 @@ intel_miptree_map_depthstencil(struct brw_context *brw,
       }
 
       intel_miptree_unmap_raw(s_mt);
-      intel_miptree_unmap_raw(z_mt);
+      intel_miptree_unmap(brw, z_mt, level, slice);
+      z_mt->level[level].slice[slice].map = map;
 
-      DBG("%s: %d,%d %dx%d from z mt %p %d,%d, s mt %p %d,%d = %p/%d\n",
+      DBG("%s: %d,%d %dx%d from z mt %p (%d,%d) @ (level:%d, slice:%d), s mt %p %d,%d = %p/%d\n",
 	  __func__,
 	  map->x, map->y, map->w, map->h,
-	  z_mt, map->x + z_image_x, map->y + z_image_y,
+	  z_mt, map->x, map->y, level, slice,
 	  s_mt, map->x + s_image_x, map->y + s_image_y,
 	  map->ptr, map->stride);
    } else {
@@ -3586,44 +3590,48 @@ intel_miptree_unmap_depthstencil(struct brw_context *brw,
    if (map->mode & GL_MAP_WRITE_BIT) {
       uint32_t *packed_map = map->ptr;
       uint8_t *s_map = intel_miptree_map_raw(brw, s_mt, GL_MAP_WRITE_BIT);
-      uint32_t *z_map = intel_miptree_map_raw(brw, z_mt, GL_MAP_WRITE_BIT);
       unsigned int s_image_x, s_image_y;
-      unsigned int z_image_x, z_image_y;
+
+      uint32_t *z_map = NULL;
+      ptrdiff_t z_stride = 0;
+
+      z_mt->level[level].slice[slice].map = NULL;
+      intel_miptree_map(brw, z_mt, level, slice, map->x, map->y, map->w, map->h,
+                        map->mode | GL_MAP_INVALIDATE_RANGE_BIT | BRW_MAP_DIRECT_BIT,
+                        (void **)&z_map, &z_stride);
+      assert(z_map && z_stride);
 
       intel_miptree_get_image_offset(s_mt, level, slice,
 				     &s_image_x, &s_image_y);
-      intel_miptree_get_image_offset(z_mt, level, slice,
-				     &z_image_x, &z_image_y);
 
       for (uint32_t y = 0; y < map->h; y++) {
+         uint32_t *z_line = (uint32_t *)((uint8_t *)z_map + z_stride * y);
 	 for (uint32_t x = 0; x < map->w; x++) {
 	    ptrdiff_t s_offset = intel_offset_S8(s_mt->surf.row_pitch,
 						 x + s_image_x + map->x,
 						 y + s_image_y + map->y,
 						 brw->has_swizzling);
-	    ptrdiff_t z_offset = ((y + z_image_y + map->y) *
-                                  (z_mt->surf.row_pitch / 4) +
-				  (x + z_image_x + map->x));
 
 	    if (map_z32f_x24s8) {
-	       z_map[z_offset] = packed_map[(y * map->w + x) * 2 + 0];
+	       z_line[x] = packed_map[(y * map->w + x) * 2 + 0];
 	       s_map[s_offset] = packed_map[(y * map->w + x) * 2 + 1];
 	    } else {
 	       uint32_t packed = packed_map[y * map->w + x];
 	       s_map[s_offset] = packed >> 24;
-	       z_map[z_offset] = packed;
+	       z_line[x] = packed;
 	    }
 	 }
       }
 
       intel_miptree_unmap_raw(s_mt);
-      intel_miptree_unmap_raw(z_mt);
+      intel_miptree_unmap(brw, z_mt, level, slice);
+      z_mt->level[level].slice[slice].map = map;
 
-      DBG("%s: %d,%d %dx%d from z mt %p (%s) %d,%d, s mt %p %d,%d = %p/%d\n",
+      DBG("%s: %d,%d %dx%d from z mt %p (%s) (%d,%d) @ (level:%d, slice:%d), s mt %p %d,%d = %p/%d\n",
 	  __func__,
 	  map->x, map->y, map->w, map->h,
 	  z_mt, _mesa_get_format_name(z_mt->format),
-	  map->x + z_image_x, map->y + z_image_y,
+	  map->x, map->y, level, slice,
 	  s_mt, map->x + s_image_x, map->y + s_image_y,
 	  map->ptr, map->stride);
    }
-- 
2.14.3



More information about the mesa-dev mailing list