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

Author: Boris Brezillon <[email protected]>
Date:   Tue Jun  1 10:20:28 2021 +0200

pan/blit: Let the caller offset the start/end coords passed to the blitter

Since we have no guarantee that start < end, we can't really tell to
which one the offset applies to. Let the caller take care of that.

Signed-off-by: Boris Brezillon <[email protected]>
Acked-by: Alyssa Rosenzweig <[email protected]>
Reviewed-by: Tomeu Vizoso <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12961>

---

 src/panfrost/lib/pan_blitter.c | 31 +++++++++++++++++++------------
 src/panfrost/lib/pan_blitter.h | 14 +++++++++++---
 2 files changed, 30 insertions(+), 15 deletions(-)

diff --git a/src/panfrost/lib/pan_blitter.c b/src/panfrost/lib/pan_blitter.c
index 890904292ea..053896ad85a 100644
--- a/src/panfrost/lib/pan_blitter.c
+++ b/src/panfrost/lib/pan_blitter.c
@@ -1273,9 +1273,6 @@ GENX(pan_blit_ctx_init)(struct panfrost_device *dev,
 {
         memset(ctx, 0, sizeof(*ctx));
 
-        ctx->z_scale = (float)(info->dst.end.z - info->dst.start.z + 1) /
-                       (info->src.end.z - info->src.start.z + 1);
-
         struct pan_image_view sviews[2] = {
                 {
                         .format = info->src.planes[0].format,
@@ -1319,13 +1316,19 @@ GENX(pan_blit_ctx_init)(struct panfrost_device *dev,
                 ctx->src.layer_offset = info->src.start.layer;
 
         if (info->dst.planes[0].image->layout.dim == 
MALI_TEXTURE_DIMENSION_3D) {
+                unsigned max_z = 
u_minify(info->dst.planes[0].image->layout.depth, info->dst.level) - 1;
+
                 ctx->dst.layer_offset = info->dst.start.z;
                 ctx->dst.cur_layer = info->dst.start.z;
-                ctx->dst.last_layer = info->dst.end.z;
+                ctx->dst.last_layer = MIN2(MAX2(info->dst.end.z, 0), max_z);
+                ctx->z_scale = (float)(info->dst.end.z - info->dst.start.z) /
+                               (info->src.end.z - info->src.start.z);
         } else {
+                unsigned max_layer = 
info->dst.planes[0].image->layout.array_size - 1;
                 ctx->dst.layer_offset = info->dst.start.layer;
                 ctx->dst.cur_layer = info->dst.start.layer;
-                ctx->dst.last_layer = info->dst.end.layer;
+                ctx->dst.last_layer = MIN2(info->dst.end.layer, max_layer);
+                ctx->z_scale = 1;
         }
 
         /* Split depth and stencil */
@@ -1370,9 +1373,9 @@ GENX(pan_blit_ctx_init)(struct panfrost_device *dev,
 
         float dst_rect[] = {
                 info->dst.start.x, info->dst.start.y, 0.0, 1.0,
-                info->dst.end.x + 1, info->dst.start.y, 0.0, 1.0,
-                info->dst.start.x, info->dst.end.y + 1, 0.0, 1.0,
-                info->dst.end.x + 1, info->dst.end.y + 1, 0.0, 1.0,
+                info->dst.end.x, info->dst.start.y, 0.0, 1.0,
+                info->dst.start.x, info->dst.end.y, 0.0, 1.0,
+                info->dst.end.x, info->dst.end.y, 0.0, 1.0,
         };
 
         ctx->position =
@@ -1386,7 +1389,11 @@ GENX(pan_blit)(struct pan_blit_context *ctx,
                struct pan_scoreboard *scoreboard,
                mali_ptr tsd, mali_ptr tiler)
 {
-        if (ctx->dst.cur_layer < 0 || ctx->dst.cur_layer > ctx->dst.last_layer)
+        if (ctx->dst.cur_layer < 0 ||
+            (ctx->dst.last_layer >= ctx->dst.layer_offset &&
+             ctx->dst.cur_layer > ctx->dst.last_layer) ||
+            (ctx->dst.last_layer < ctx->dst.layer_offset &&
+             ctx->dst.cur_layer < ctx->dst.last_layer))
                 return (struct panfrost_ptr){ 0 };
 
         int32_t layer = ctx->dst.cur_layer - ctx->dst.layer_offset;
@@ -1398,9 +1405,9 @@ GENX(pan_blit)(struct pan_blit_context *ctx,
 
         float src_rect[] = {
                 ctx->src.start.x, ctx->src.start.y, src_z, 1.0,
-                ctx->src.end.x + 1, ctx->src.start.y, src_z, 1.0,
-                ctx->src.start.x, ctx->src.end.y + 1, src_z, 1.0,
-                ctx->src.end.x + 1, ctx->src.end.y + 1, src_z, 1.0,
+                ctx->src.end.x, ctx->src.start.y, src_z, 1.0,
+                ctx->src.start.x, ctx->src.end.y, src_z, 1.0,
+                ctx->src.end.x, ctx->src.end.y, src_z, 1.0,
         };
 
         mali_ptr src_coords =
diff --git a/src/panfrost/lib/pan_blitter.h b/src/panfrost/lib/pan_blitter.h
index 17a8865911e..61e982195a8 100644
--- a/src/panfrost/lib/pan_blitter.h
+++ b/src/panfrost/lib/pan_blitter.h
@@ -105,10 +105,18 @@ GENX(pan_blit_ctx_init)(struct panfrost_device *dev,
 static inline bool
 pan_blit_next_surface(struct pan_blit_context *ctx)
 {
-        if (ctx->dst.cur_layer >= ctx->dst.last_layer)
-                return false;
+        if (ctx->dst.last_layer < ctx->dst.layer_offset) {
+                if (ctx->dst.cur_layer <= ctx->dst.last_layer)
+                        return false;
+
+                ctx->dst.cur_layer--;
+        } else {
+                if (ctx->dst.cur_layer >= ctx->dst.last_layer)
+                        return false;
+
+                ctx->dst.cur_layer++;
+        }
 
-        ctx->dst.cur_layer++;
         return true;
 }
 

Reply via email to