Skip to content

Commit

Permalink
i965/miptree: Don't gtt map from map_depthstencil
Browse files Browse the repository at this point in the history
Instead of gtt mapping, call out to other map functions (map_map
or map_tiled_memcpy) for the depth surface. Removes a place where
gtt mapping is used.
  • Loading branch information
Scott D Phillips committed Jan 23, 2018
1 parent 1f6069f commit 0b6dac4
Showing 1 changed file with 30 additions and 18 deletions.
48 changes: 30 additions & 18 deletions src/mesa/drivers/dri/i965/intel_mipmap_tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -3460,16 +3460,21 @@ intel_miptree_map_depthstencil(struct brw_context *brw,
* temporary buffer back out.
*/
if (!(map->mode & GL_MAP_INVALIDATE_RANGE_BIT)) {
struct intel_miptree_map z_mt_map = {
.mode = map->mode & ~GL_MAP_WRITE_BIT, .x = map->x, .y = map->y,
.w = map->w, .h = map->h,
};
if (z_mt->surf.tiling == ISL_TILING_LINEAR)
intel_miptree_map_map(brw, z_mt, &z_mt_map, level, slice);
else
intel_miptree_map_tiled_memcpy(brw, z_mt, &z_mt_map, level, slice);
uint32_t *z_map = z_mt_map.ptr;
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;

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++) {
for (uint32_t x = 0; x < map->w; x++) {
Expand All @@ -3478,9 +3483,7 @@ intel_miptree_map_depthstencil(struct brw_context *brw,
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));
ptrdiff_t z_offset = y * (z_mt_map.stride / 4) + x;
uint8_t s = s_map[s_offset];
uint32_t z = z_map[z_offset];

Expand All @@ -3494,12 +3497,15 @@ intel_miptree_map_depthstencil(struct brw_context *brw,
}

intel_miptree_unmap_raw(s_mt);
intel_miptree_unmap_raw(z_mt);
if (z_mt->surf.tiling == ISL_TILING_LINEAR)
intel_miptree_unmap_map(z_mt);
else
intel_miptree_unmap_tiled_memcpy(brw, z_mt, &z_mt_map, level, slice);

DBG("%s: %d,%d %dx%d from z mt %p %d,%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,
s_mt, map->x + s_image_x, map->y + s_image_y,
map->ptr, map->stride);
} else {
Expand All @@ -3521,26 +3527,29 @@ intel_miptree_unmap_depthstencil(struct brw_context *brw,
bool map_z32f_x24s8 = mt->format == MESA_FORMAT_Z_FLOAT32;

if (map->mode & GL_MAP_WRITE_BIT) {
struct intel_miptree_map z_mt_map = {
.mode = map->mode | GL_MAP_INVALIDATE_RANGE_BIT, .x = map->x,
.y = map->y, .w = map->w, .h = map->h,
};
if (z_mt->surf.tiling == ISL_TILING_LINEAR)
intel_miptree_map_map(brw, z_mt, &z_mt_map, level, slice);
else
intel_miptree_map_tiled_memcpy(brw, z_mt, &z_mt_map, level, slice);
uint32_t *z_map = z_mt_map.ptr;
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;

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++) {
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));
ptrdiff_t z_offset = y * (z_mt_map.stride / 4) + x;

if (map_z32f_x24s8) {
z_map[z_offset] = packed_map[(y * map->w + x) * 2 + 0];
Expand All @@ -3554,13 +3563,16 @@ intel_miptree_unmap_depthstencil(struct brw_context *brw,
}

intel_miptree_unmap_raw(s_mt);
intel_miptree_unmap_raw(z_mt);
if (z_mt->surf.tiling == ISL_TILING_LINEAR)
intel_miptree_unmap_map(z_mt);
else
intel_miptree_unmap_tiled_memcpy(brw, z_mt, &z_mt_map, level, slice);

DBG("%s: %d,%d %dx%d from z mt %p (%s) %d,%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,
s_mt, map->x + s_image_x, map->y + s_image_y,
map->ptr, map->stride);
}
Expand Down

0 comments on commit 0b6dac4

Please sign in to comment.