From 967757a2088b00fa0e564ebfe31411ec1ec3e8be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Thu, 22 Apr 2021 00:11:18 -0400 Subject: [PATCH] gallium+(u_threaded,r300,r600,radeonsi): move transfer offset into pipe_transfer Let's use the 4 bytes of unused padding usefully in pipe_transfer. Reviewed-By: Mike Blumenkrantz Part-of: --- src/gallium/auxiliary/util/u_threaded_context.c | 4 ++-- src/gallium/auxiliary/util/u_threaded_context.h | 4 ---- src/gallium/drivers/r300/r300_transfer.c | 7 ++----- src/gallium/drivers/r600/r600_buffer_common.c | 4 ++-- src/gallium/drivers/r600/r600_pipe_common.h | 1 - src/gallium/drivers/radeonsi/si_buffer.c | 4 ++-- src/gallium/drivers/radeonsi/si_pipe.h | 1 - src/gallium/include/pipe/p_state.h | 5 +++++ 8 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/gallium/auxiliary/util/u_threaded_context.c b/src/gallium/auxiliary/util/u_threaded_context.c index 691c01c83a4..73d45a6c909 100644 --- a/src/gallium/auxiliary/util/u_threaded_context.c +++ b/src/gallium/auxiliary/util/u_threaded_context.c @@ -1710,7 +1710,7 @@ tc_transfer_map(struct pipe_context *_pipe, u_upload_alloc(tc->base.stream_uploader, 0, box->width + (box->x % tc->map_buffer_alignment), - tc->map_buffer_alignment, &ttrans->offset, + tc->map_buffer_alignment, &ttrans->b.offset, &ttrans->staging, (void**)&map); if (!map) { slab_free(&tc->pool_transfers, ttrans); @@ -1806,7 +1806,7 @@ tc_buffer_do_flush_region(struct threaded_context *tc, if (ttrans->staging) { struct pipe_box src_box; - u_box_1d(ttrans->offset + ttrans->b.box.x % tc->map_buffer_alignment + + u_box_1d(ttrans->b.offset + ttrans->b.box.x % tc->map_buffer_alignment + (box->x - ttrans->b.box.x), box->width, &src_box); diff --git a/src/gallium/auxiliary/util/u_threaded_context.h b/src/gallium/auxiliary/util/u_threaded_context.h index 6d0227a4a14..59c6f4acab2 100644 --- a/src/gallium/auxiliary/util/u_threaded_context.h +++ b/src/gallium/auxiliary/util/u_threaded_context.h @@ -298,10 +298,6 @@ struct threaded_transfer { /* Staging buffer for DISCARD_RANGE transfers. */ struct pipe_resource *staging; - - /* Offset into the staging buffer, because the backing buffer is - * sub-allocated. */ - unsigned offset; }; struct threaded_query { diff --git a/src/gallium/drivers/r300/r300_transfer.c b/src/gallium/drivers/r300/r300_transfer.c index 8274de5f4b4..bceeb712459 100644 --- a/src/gallium/drivers/r300/r300_transfer.c +++ b/src/gallium/drivers/r300/r300_transfer.c @@ -33,9 +33,6 @@ struct r300_transfer { /* Parent class */ struct pipe_transfer transfer; - /* Offset from start of buffer. */ - unsigned offset; - /* Linear texture. */ struct r300_resource *linear_texture; }; @@ -206,7 +203,7 @@ r300_texture_transfer_map(struct pipe_context *ctx, /* Unpipelined transfer. */ trans->transfer.stride = tex->tex.stride_in_bytes[level]; trans->transfer.layer_stride = tex->tex.layer_size_in_bytes[level]; - trans->offset = r300_texture_get_offset(tex, level, box->z); + trans->transfer.offset = r300_texture_get_offset(tex, level, box->z); if (referenced_cs && !(usage & PIPE_MAP_UNSYNCHRONIZED)) { @@ -237,7 +234,7 @@ r300_texture_transfer_map(struct pipe_context *ctx, } *transfer = &trans->transfer; - return map + trans->offset + + return map + trans->transfer.offset + box->y / util_format_get_blockheight(format) * trans->transfer.stride + box->x / util_format_get_blockwidth(format) * util_format_get_blocksize(format); } diff --git a/src/gallium/drivers/r600/r600_buffer_common.c b/src/gallium/drivers/r600/r600_buffer_common.c index 7dbf7a1baaf..c390b2bf4b5 100644 --- a/src/gallium/drivers/r600/r600_buffer_common.c +++ b/src/gallium/drivers/r600/r600_buffer_common.c @@ -322,7 +322,7 @@ static void *r600_buffer_get_transfer(struct pipe_context *ctx, transfer->b.b.stride = 0; transfer->b.b.layer_stride = 0; transfer->b.staging = NULL; - transfer->offset = offset; + transfer->b.b.offset = offset; transfer->staging = staging; *ptransfer = &transfer->b.b; return data; @@ -490,7 +490,7 @@ static void r600_buffer_do_flush_region(struct pipe_context *ctx, dst = transfer->resource; src = &rtransfer->staging->b.b; - soffset = rtransfer->offset + box->x % R600_MAP_BUFFER_ALIGNMENT; + soffset = rtransfer->b.b.offset + box->x % R600_MAP_BUFFER_ALIGNMENT; u_box_1d(soffset, box->width, &dma_box); diff --git a/src/gallium/drivers/r600/r600_pipe_common.h b/src/gallium/drivers/r600/r600_pipe_common.h index b55a27d63f0..91c92dad50e 100644 --- a/src/gallium/drivers/r600/r600_pipe_common.h +++ b/src/gallium/drivers/r600/r600_pipe_common.h @@ -178,7 +178,6 @@ struct r600_resource { struct r600_transfer { struct threaded_transfer b; struct r600_resource *staging; - unsigned offset; }; struct r600_fmask_info { diff --git a/src/gallium/drivers/radeonsi/si_buffer.c b/src/gallium/drivers/radeonsi/si_buffer.c index 5a9d7b9473e..bc3b2af8349 100644 --- a/src/gallium/drivers/radeonsi/si_buffer.c +++ b/src/gallium/drivers/radeonsi/si_buffer.c @@ -319,8 +319,8 @@ static void *si_buffer_get_transfer(struct pipe_context *ctx, struct pipe_resour transfer->b.b.box = *box; transfer->b.b.stride = 0; transfer->b.b.layer_stride = 0; + transfer->b.b.offset = offset; transfer->b.staging = NULL; - transfer->offset = offset; transfer->staging = staging; *ptransfer = &transfer->b.b; return data; @@ -480,7 +480,7 @@ static void si_buffer_do_flush_region(struct pipe_context *ctx, struct pipe_tran if (stransfer->staging) { unsigned src_offset = - stransfer->offset + transfer->box.x % SI_MAP_BUFFER_ALIGNMENT + (box->x - transfer->box.x); + stransfer->b.b.offset + transfer->box.x % SI_MAP_BUFFER_ALIGNMENT + (box->x - transfer->box.x); /* Copy the staging buffer into the original one. */ si_copy_buffer(sctx, transfer->resource, &stransfer->staging->b.b, box->x, src_offset, diff --git a/src/gallium/drivers/radeonsi/si_pipe.h b/src/gallium/drivers/radeonsi/si_pipe.h index fba6d53a20c..4ce881ef24a 100644 --- a/src/gallium/drivers/radeonsi/si_pipe.h +++ b/src/gallium/drivers/radeonsi/si_pipe.h @@ -337,7 +337,6 @@ struct si_resource { struct si_transfer { struct threaded_transfer b; struct si_resource *staging; - unsigned offset; }; struct si_texture { diff --git a/src/gallium/include/pipe/p_state.h b/src/gallium/include/pipe/p_state.h index 7e9246a920a..f9027908b39 100644 --- a/src/gallium/include/pipe/p_state.h +++ b/src/gallium/include/pipe/p_state.h @@ -586,6 +586,11 @@ struct pipe_transfer struct pipe_box box; /**< region of the resource to access */ unsigned stride; /**< row stride in bytes */ unsigned layer_stride; /**< image/layer stride in bytes */ + + /* Offset into a driver-internal staging buffer to make use of unused + * padding in this structure. + */ + unsigned offset; };