iris: Don't mutate box in transfer map code

Not mutating the boxes is arguably cleaner.

Split from a patch by Chris Wilson but reworked to use a pointer to the
original box rather than making a copy at all.
This commit is contained in:
Kenneth Graunke 2019-03-13 15:35:28 -07:00
parent 3b41175c22
commit 0c3adaad22
1 changed files with 28 additions and 37 deletions

View File

@ -951,6 +951,7 @@ static void
iris_unmap_s8(struct iris_transfer *map)
{
struct pipe_transfer *xfer = &map->base;
const struct pipe_box *box = &xfer->box;
struct iris_resource *res = (struct iris_resource *) xfer->resource;
struct isl_surf *surf = &res->surf;
const bool has_swizzling = false;
@ -960,24 +961,20 @@ iris_unmap_s8(struct iris_transfer *map)
uint8_t *tiled_s8_map =
iris_bo_map(map->dbg, res->bo, xfer->usage | MAP_RAW);
struct pipe_box box = xfer->box;
for (int s = 0; s < box.depth; s++) {
for (int s = 0; s < box->depth; s++) {
unsigned x0_el, y0_el;
get_image_offset_el(surf, xfer->level, box.z, &x0_el, &y0_el);
get_image_offset_el(surf, xfer->level, box->z + s, &x0_el, &y0_el);
for (uint32_t y = 0; y < box.height; y++) {
for (uint32_t x = 0; x < box.width; x++) {
for (uint32_t y = 0; y < box->height; y++) {
for (uint32_t x = 0; x < box->width; x++) {
ptrdiff_t offset = s8_offset(surf->row_pitch_B,
x0_el + box.x + x,
y0_el + box.y + y,
x0_el + box->x + x,
y0_el + box->y + y,
has_swizzling);
tiled_s8_map[offset] =
untiled_s8_map[s * xfer->layer_stride + y * xfer->stride + x];
}
}
box.z++;
}
}
@ -988,17 +985,18 @@ static void
iris_map_s8(struct iris_transfer *map)
{
struct pipe_transfer *xfer = &map->base;
const struct pipe_box *box = &xfer->box;
struct iris_resource *res = (struct iris_resource *) xfer->resource;
struct isl_surf *surf = &res->surf;
xfer->stride = surf->row_pitch_B;
xfer->layer_stride = xfer->stride * xfer->box.height;
xfer->layer_stride = xfer->stride * box->height;
/* The tiling and detiling functions require that the linear buffer has
* a 16-byte alignment (that is, its `x0` is 16-byte aligned). Here we
* over-allocate the linear buffer to get the proper alignment.
*/
map->buffer = map->ptr = malloc(xfer->layer_stride * xfer->box.depth);
map->buffer = map->ptr = malloc(xfer->layer_stride * box->depth);
assert(map->buffer);
const bool has_swizzling = false;
@ -1013,24 +1011,20 @@ iris_map_s8(struct iris_transfer *map)
uint8_t *tiled_s8_map =
iris_bo_map(map->dbg, res->bo, xfer->usage | MAP_RAW);
struct pipe_box box = xfer->box;
for (int s = 0; s < box.depth; s++) {
for (int s = 0; s < box->depth; s++) {
unsigned x0_el, y0_el;
get_image_offset_el(surf, xfer->level, box.z, &x0_el, &y0_el);
get_image_offset_el(surf, xfer->level, box->z + s, &x0_el, &y0_el);
for (uint32_t y = 0; y < box.height; y++) {
for (uint32_t x = 0; x < box.width; x++) {
for (uint32_t y = 0; y < box->height; y++) {
for (uint32_t x = 0; x < box->width; x++) {
ptrdiff_t offset = s8_offset(surf->row_pitch_B,
x0_el + box.x + x,
y0_el + box.y + y,
x0_el + box->x + x,
y0_el + box->y + y,
has_swizzling);
untiled_s8_map[s * xfer->layer_stride + y * xfer->stride + x] =
tiled_s8_map[offset];
}
}
box.z++;
}
}
@ -1043,7 +1037,7 @@ iris_map_s8(struct iris_transfer *map)
static inline void
tile_extents(struct isl_surf *surf,
const struct pipe_box *box,
unsigned level,
unsigned level, int z,
unsigned *x1_B, unsigned *x2_B,
unsigned *y1_el, unsigned *y2_el)
{
@ -1054,7 +1048,7 @@ tile_extents(struct isl_surf *surf,
assert(box->y % fmtl->bh == 0);
unsigned x0_el, y0_el;
get_image_offset_el(surf, level, box->z, &x0_el, &y0_el);
get_image_offset_el(surf, level, box->z + z, &x0_el, &y0_el);
*x1_B = (box->x / fmtl->bw + x0_el) * cpp;
*y1_el = box->y / fmtl->bh + y0_el;
@ -1066,7 +1060,7 @@ static void
iris_unmap_tiled_memcpy(struct iris_transfer *map)
{
struct pipe_transfer *xfer = &map->base;
struct pipe_box box = xfer->box;
const struct pipe_box *box = &xfer->box;
struct iris_resource *res = (struct iris_resource *) xfer->resource;
struct isl_surf *surf = &res->surf;
@ -1075,16 +1069,15 @@ iris_unmap_tiled_memcpy(struct iris_transfer *map)
if (xfer->usage & PIPE_TRANSFER_WRITE) {
char *dst = iris_bo_map(map->dbg, res->bo, xfer->usage | MAP_RAW);
for (int s = 0; s < box.depth; s++) {
for (int s = 0; s < box->depth; s++) {
unsigned x1, x2, y1, y2;
tile_extents(surf, &box, xfer->level, &x1, &x2, &y1, &y2);
tile_extents(surf, box, xfer->level, s, &x1, &x2, &y1, &y2);
void *ptr = map->ptr + s * xfer->layer_stride;
isl_memcpy_linear_to_tiled(x1, x2, y1, y2, dst, ptr,
surf->row_pitch_B, xfer->stride,
has_swizzling, surf->tiling, ISL_MEMCPY);
box.z++;
}
}
os_free_aligned(map->buffer);
@ -1095,21 +1088,22 @@ static void
iris_map_tiled_memcpy(struct iris_transfer *map)
{
struct pipe_transfer *xfer = &map->base;
const struct pipe_box *box = &xfer->box;
struct iris_resource *res = (struct iris_resource *) xfer->resource;
struct isl_surf *surf = &res->surf;
xfer->stride = ALIGN(surf->row_pitch_B, 16);
xfer->layer_stride = xfer->stride * xfer->box.height;
xfer->layer_stride = xfer->stride * box->height;
unsigned x1, x2, y1, y2;
tile_extents(surf, &xfer->box, xfer->level, &x1, &x2, &y1, &y2);
tile_extents(surf, box, xfer->level, 0, &x1, &x2, &y1, &y2);
/* The tiling and detiling functions require that the linear buffer has
* a 16-byte alignment (that is, its `x0` is 16-byte aligned). Here we
* over-allocate the linear buffer to get the proper alignment.
*/
map->buffer =
os_malloc_aligned(xfer->layer_stride * xfer->box.depth, 16);
os_malloc_aligned(xfer->layer_stride * box->depth, 16);
assert(map->buffer);
map->ptr = (char *)map->buffer + (x1 & 0xf);
@ -1119,19 +1113,16 @@ iris_map_tiled_memcpy(struct iris_transfer *map)
if (!(xfer->usage & PIPE_TRANSFER_DISCARD_RANGE)) {
char *src = iris_bo_map(map->dbg, res->bo, xfer->usage | MAP_RAW);
struct pipe_box box = xfer->box;
for (int s = 0; s < box.depth; s++) {
for (int s = 0; s < box->depth; s++) {
unsigned x1, x2, y1, y2;
tile_extents(surf, &box, xfer->level, &x1, &x2, &y1, &y2);
tile_extents(surf, box, xfer->level, s, &x1, &x2, &y1, &y2);
/* Use 's' rather than 'box.z' to rebase the first slice to 0. */
/* Use 's' rather than 'box->z' to rebase the first slice to 0. */
void *ptr = map->ptr + s * xfer->layer_stride;
isl_memcpy_tiled_to_linear(x1, x2, y1, y2, ptr, src, xfer->stride,
surf->row_pitch_B, has_swizzling,
surf->tiling, ISL_MEMCPY_STREAMING_LOAD);
box.z++;
}
}