Mesa (main): freedreno: Split out helper for staging blit

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Apr 27 23:33:33 UTC 2022


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

Author: Rob Clark <robdclark at chromium.org>
Date:   Wed Apr 20 09:41:31 2022 -0700

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 at chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16086>

---

 src/gallium/drivers/freedreno/freedreno_resource.c | 64 +++++++++++++---------
 1 file changed, 38 insertions(+), 26 deletions(-)

diff --git a/src/gallium/drivers/freedreno/freedreno_resource.c b/src/gallium/drivers/freedreno/freedreno_resource.c
index f0553581d5c..78ea44079c9 100644
--- a/src/gallium/drivers/freedreno/freedreno_resource.c
+++ b/src/gallium/drivers/freedreno/freedreno_resource.c
@@ -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);



More information about the mesa-commit mailing list