From be6d21ed56a02b4343442c3bf2b314fcdc5c34e2 Mon Sep 17 00:00:00 2001 From: Rob Clark Date: Mon, 12 Dec 2022 14:20:53 -0800 Subject: [PATCH] freedreno: Limit cached staging BOs to PIPE_MAP_READ WC is fine for staging upload buffers, and will let us hit the default heap. Probably introducing a separate cached-coherent heap is overkill, and given that staging uploads are common (but downloads uncommon, out- side of dEQP/piglit), it is better to just ask for WC. Signed-off-by: Rob Clark Part-of: --- src/gallium/drivers/freedreno/freedreno_resource.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/gallium/drivers/freedreno/freedreno_resource.c b/src/gallium/drivers/freedreno/freedreno_resource.c index e648fe4..6216c6e 100644 --- a/src/gallium/drivers/freedreno/freedreno_resource.c +++ b/src/gallium/drivers/freedreno/freedreno_resource.c @@ -209,7 +209,9 @@ realloc_bo(struct fd_resource *rsc, uint32_t size) struct fd_screen *screen = fd_screen(rsc->b.b.screen); uint32_t flags = COND(rsc->layout.tile_mode, FD_BO_NOMAP) | - COND(prsc->usage & PIPE_USAGE_STAGING, FD_BO_CACHED_COHERENT) | + COND((prsc->usage & PIPE_USAGE_STAGING) && + (prsc->flags & PIPE_RESOURCE_FLAG_MAP_COHERENT), + FD_BO_CACHED_COHERENT) | COND(prsc->bind & PIPE_BIND_SHARED, FD_BO_SHARED) | COND(prsc->bind & PIPE_BIND_SCANOUT, FD_BO_SCANOUT); /* TODO other flags? */ @@ -586,7 +588,7 @@ fd_resource_dump(struct fd_resource *rsc, const char *name) static struct fd_resource * fd_alloc_staging(struct fd_context *ctx, struct fd_resource *rsc, - unsigned level, const struct pipe_box *box) + unsigned level, const struct pipe_box *box, unsigned usage) assert_dt { struct pipe_context *pctx = &ctx->base; @@ -616,6 +618,7 @@ fd_alloc_staging(struct fd_context *ctx, struct fd_resource *rsc, tmpl.last_level = 0; tmpl.bind |= PIPE_BIND_LINEAR; tmpl.usage = PIPE_USAGE_STAGING; + tmpl.flags = (usage & PIPE_MAP_READ) ? PIPE_RESOURCE_FLAG_MAP_COHERENT : 0; struct pipe_resource *pstaging = pctx->screen->resource_create(pctx->screen, &tmpl); @@ -774,7 +777,7 @@ resource_transfer_map_staging(struct pipe_context *pctx, assert(prsc->target != PIPE_BUFFER); - staging_rsc = fd_alloc_staging(ctx, rsc, level, box); + staging_rsc = fd_alloc_staging(ctx, rsc, level, box, usage); if (!staging_rsc) return NULL; @@ -918,7 +921,7 @@ resource_transfer_map(struct pipe_context *pctx, struct pipe_resource *prsc, * use a staging buffer to do the upload. */ if (is_renderable(prsc)) - staging_rsc = fd_alloc_staging(ctx, rsc, level, box); + staging_rsc = fd_alloc_staging(ctx, rsc, level, box, usage); if (staging_rsc) { trans->staging_prsc = &staging_rsc->b.b; trans->b.b.stride = fd_resource_pitch(staging_rsc, 0); -- 2.7.4