Module: Mesa Branch: main Commit: 7a09499fa6f83456223eafd027b05478ccecb1e5 URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=7a09499fa6f83456223eafd027b05478ccecb1e5
Author: Jason Volk <[email protected]> Date: Thu Apr 21 18:12:53 2022 -0700 r600: Elide downloads for discarded and immutable compute memories. Compute memory item demotion invokes a device to host transfer unconditionally, but there are at least two cases where this is not necessary: 1. The item is mapped for discarding with PIPE_MAP_DISCARD_RANGE (e.g. CL_MAP_WRITE_INVALIDATE_REGION). 2. The item cannot be written to by the device. Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16116> --- src/gallium/drivers/r600/compute_memory_pool.c | 16 +++++++++++----- src/gallium/drivers/r600/evergreen_compute.c | 11 +++++++---- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/gallium/drivers/r600/compute_memory_pool.c b/src/gallium/drivers/r600/compute_memory_pool.c index 0157b0508d2..2e4b26c9586 100644 --- a/src/gallium/drivers/r600/compute_memory_pool.c +++ b/src/gallium/drivers/r600/compute_memory_pool.c @@ -430,12 +430,18 @@ void compute_memory_demote_item(struct compute_memory_pool *pool, dst = (struct pipe_resource *)item->real_buffer; /* We transfer the memory from the item in the pool to the - * temporary buffer */ - u_box_1d(item->start_in_dw * 4, item->size_in_dw * 4, &box); + * temporary buffer. Download is skipped for items: + * - Not mapped for reading or writing (PIPE_MAP_DISCARD_RANGE). + * - Not writable by the device. */ + if ((item->status & (ITEM_MAPPED_FOR_READING|ITEM_MAPPED_FOR_WRITING)) && + !(r600_resource(dst)->flags & RADEON_FLAG_READ_ONLY)) { + + u_box_1d(item->start_in_dw * 4, item->size_in_dw * 4, &box); - rctx->b.b.resource_copy_region(pipe, - dst, 0, 0, 0, 0, - src, 0, &box); + rctx->b.b.resource_copy_region(pipe, + dst, 0, 0, 0, 0, + src, 0, &box); + } /* Remember to mark the buffer as 'pending' by setting start_in_dw to -1 */ item->start_in_dw = -1; diff --git a/src/gallium/drivers/r600/evergreen_compute.c b/src/gallium/drivers/r600/evergreen_compute.c index 4d10e2b604e..18a50b5b864 100644 --- a/src/gallium/drivers/r600/evergreen_compute.c +++ b/src/gallium/drivers/r600/evergreen_compute.c @@ -1247,6 +1247,12 @@ void *r600_compute_global_transfer_map(struct pipe_context *ctx, struct pipe_resource *dst = NULL; unsigned offset = box->x; + if (usage & PIPE_MAP_READ) + buffer->chunk->status |= ITEM_MAPPED_FOR_READING; + + if (usage & PIPE_MAP_WRITE) + buffer->chunk->status |= ITEM_MAPPED_FOR_WRITING; + if (is_item_in_pool(item)) { compute_memory_demote_item(pool, item, ctx); } @@ -1259,9 +1265,6 @@ void *r600_compute_global_transfer_map(struct pipe_context *ctx, dst = (struct pipe_resource*)item->real_buffer; - if (usage & PIPE_MAP_READ) - buffer->chunk->status |= ITEM_MAPPED_FOR_READING; - COMPUTE_DBG(rctx->screen, "* r600_compute_global_transfer_map()\n" "level = %u, usage = %u, box(x = %u, y = %u, z = %u " "width = %u, height = %u, depth = %u)\n", level, usage, @@ -1282,7 +1285,7 @@ void *r600_compute_global_transfer_map(struct pipe_context *ctx, ///TODO: do it better, mapping is not possible if the pool is too big return pipe_buffer_map_range(ctx, dst, - offset, box->width, usage, ptransfer); + offset, box->width, usage & ~PIPE_MAP_READ, ptransfer); } void r600_compute_global_transfer_unmap(struct pipe_context *ctx,
