Module: Mesa
Branch: main
Commit: 78a999ecfac9f4fe752efb16a8535c6a317a2d1a
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=78a999ecfac9f4fe752efb16a8535c6a317a2d1a

Author: Lucas Stach <[email protected]>
Date:   Fri Jul 14 17:54:45 2023 +0200

etnaviv: don't allocate full resource as transfer staging

The transfer only targets a specific level of a resource, so we don't
need to allocate all potential resource levels for the staging resource,
but instead shrink the allocation to a single level.

Signed-off-by: Lucas Stach <[email protected]>
Reviewed-by: Christian Gmeiner <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24164>

---

 src/gallium/drivers/etnaviv/etnaviv_transfer.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/src/gallium/drivers/etnaviv/etnaviv_transfer.c 
b/src/gallium/drivers/etnaviv/etnaviv_transfer.c
index 07159f91132..18b021e2800 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_transfer.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_transfer.c
@@ -141,7 +141,7 @@ etna_transfer_unmap(struct pipe_context *pctx, struct 
pipe_transfer *ptrans)
           * tiling format. Write back the updated buffer contents.
           */
          etna_copy_resource_box(pctx, ptrans->resource, trans->rsc,
-                                ptrans->level, ptrans->level, &ptrans->box);
+                                ptrans->level, 0, &ptrans->box);
       } else if (trans->staging) {
          /* map buffer object */
          if (rsc->layout == ETNA_LAYOUT_TILED) {
@@ -209,6 +209,7 @@ etna_transfer_map(struct pipe_context *pctx, struct 
pipe_resource *prsc,
    struct etna_context *ctx = etna_context(pctx);
    struct etna_screen *screen = ctx->screen;
    struct etna_resource *rsc = etna_resource(prsc);
+   struct etna_resource_level *res_level = &rsc->levels[level];
    struct etna_transfer *trans;
    struct pipe_transfer *ptrans;
    enum pipe_format format = prsc->format;
@@ -292,6 +293,9 @@ etna_transfer_map(struct pipe_context *pctx, struct 
pipe_resource *prsc,
       }
 
       struct pipe_resource templ = *prsc;
+      templ.last_level = 0;
+      templ.width0 = res_level->width;
+      templ.height0 = res_level->height;
       templ.nr_samples = 0;
       templ.bind = PIPE_BIND_RENDER_TARGET;
 
@@ -325,14 +329,13 @@ etna_transfer_map(struct pipe_context *pctx, struct 
pipe_resource *prsc,
       }
 
       if ((usage & PIPE_MAP_READ) || !(usage & ETNA_PIPE_MAP_DISCARD_LEVEL))
-         etna_copy_resource_box(pctx, trans->rsc, &rsc->base, level, level, 
&ptrans->box);
+         etna_copy_resource_box(pctx, trans->rsc, &rsc->base, 0, level, 
&ptrans->box);
 
       /* Switch to using the temporary resource instead */
       rsc = etna_resource(trans->rsc);
+      res_level = &rsc->levels[0];
    }
 
-   struct etna_resource_level *res_level = &rsc->levels[level];
-
    /* XXX we don't handle PIPE_MAP_FLUSH_EXPLICIT; this flag can be ignored
     * when mapping in-place,
     * but when not in place we need to fire off the copy operation in

Reply via email to