freedreno: Split out helper for staging blit

We are also going to want to use this for fallback when mmap fails.

Signed-off-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16086>
This commit is contained in:
Rob Clark
2022-04-20 09:41:31 -07:00
committed by Marge Bot
parent 0b7d910b2c
commit a6be0cc12d
@@ -741,6 +741,43 @@ invalidate_resource(struct fd_resource *rsc, unsigned usage) assert_dt
}
}
static void *
resource_transfer_map_staging(struct pipe_context *pctx,
struct pipe_resource *prsc,
unsigned level, unsigned usage,
const struct pipe_box *box,
struct fd_transfer *trans)
in_dt
{
struct fd_context *ctx = fd_context(pctx);
struct fd_resource *rsc = fd_resource(prsc);
struct fd_resource *staging_rsc;
assert(prsc->target != PIPE_BUFFER);
staging_rsc = fd_alloc_staging(ctx, rsc, level, box);
if (!staging_rsc)
return NULL;
trans->staging_prsc = &staging_rsc->b.b;
trans->b.b.stride = fd_resource_pitch(staging_rsc, 0);
trans->b.b.layer_stride = fd_resource_layer_stride(staging_rsc, 0);
trans->staging_box = *box;
trans->staging_box.x = 0;
trans->staging_box.y = 0;
trans->staging_box.z = 0;
if (usage & PIPE_MAP_READ) {
fd_blit_to_staging(ctx, trans);
fd_resource_wait(ctx, staging_rsc, FD_BO_PREP_READ);
}
ctx->stats.staging_uploads++;
return fd_bo_map(staging_rsc->bo);
}
static void *
resource_transfer_map_unsync(struct pipe_context *pctx,
struct pipe_resource *prsc, unsigned level,
@@ -795,32 +832,7 @@ resource_transfer_map(struct pipe_context *pctx, struct pipe_resource *prsc,
* texture.
*/
if (rsc->layout.tile_mode) {
struct fd_resource *staging_rsc;
assert(prsc->target != PIPE_BUFFER);
staging_rsc = fd_alloc_staging(ctx, rsc, level, box);
if (staging_rsc) {
trans->staging_prsc = &staging_rsc->b.b;
trans->b.b.stride = fd_resource_pitch(staging_rsc, 0);
trans->b.b.layer_stride = fd_resource_layer_stride(staging_rsc, 0);
trans->staging_box = *box;
trans->staging_box.x = 0;
trans->staging_box.y = 0;
trans->staging_box.z = 0;
if (usage & PIPE_MAP_READ) {
fd_blit_to_staging(ctx, trans);
fd_resource_wait(ctx, staging_rsc, FD_BO_PREP_READ);
}
buf = fd_bo_map(staging_rsc->bo);
ctx->stats.staging_uploads++;
return buf;
}
return resource_transfer_map_staging(pctx, prsc, level, usage, box, trans);
} else if ((usage & PIPE_MAP_READ) && !fd_bo_is_cached(rsc->bo)) {
perf_debug_ctx(ctx, "wc readback: prsc=%p, level=%u, usage=%x, box=%dx%d+%d,%d",
prsc, level, usage, box->width, box->height, box->x, box->y);