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

Author: Erik Faye-Lund <[email protected]>
Date:   Mon Nov  6 17:41:02 2023 +0100

panfrost: minify dimensions when converting modifiers

When blitting resources, we need to specify the boxes in mip-level sized
coordinates. For the X and Y coordinates, missing this makes things
behave correctly, but only because we end up clipping away the excess
area.

However, for the Z coordinate of 3D textures, this will make us read
outside of the mip-chain during blitting, making us stumble and crash.

But let's fix what we do for all dimensions. And while we're at it,
rewrite the code a bit, so we don't end up computing any needless
values.

Reviewed-by: Boris Brezillon <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26077>

---

 src/gallium/drivers/panfrost/pan_resource.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/src/gallium/drivers/panfrost/pan_resource.c 
b/src/gallium/drivers/panfrost/pan_resource.c
index 9abebde2266..4710ef9983b 100644
--- a/src/gallium/drivers/panfrost/pan_resource.c
+++ b/src/gallium/drivers/panfrost/pan_resource.c
@@ -1309,20 +1309,11 @@ pan_resource_modifier_convert(struct panfrost_context 
*ctx,
       ctx->base.screen, &rsrc->base, modifier);
    struct panfrost_resource *tmp_rsrc = pan_resource(tmp_prsrc);
 
-   unsigned depth = rsrc->base.target == PIPE_TEXTURE_3D
-                       ? rsrc->base.depth0
-                       : rsrc->base.array_size;
-
-   struct pipe_box box = {0,    0, 0, rsrc->base.width0, rsrc->base.height0,
-                          depth};
-
    struct pipe_blit_info blit = {
       .dst.resource = &tmp_rsrc->base,
       .dst.format = tmp_rsrc->base.format,
-      .dst.box = box,
       .src.resource = &rsrc->base,
       .src.format = rsrc->base.format,
-      .src.box = box,
       .mask = util_format_get_mask(tmp_rsrc->base.format),
       .filter = PIPE_TEX_FILTER_NEAREST,
    };
@@ -1330,6 +1321,14 @@ pan_resource_modifier_convert(struct panfrost_context 
*ctx,
    for (int i = 0; i <= rsrc->base.last_level; i++) {
       if (BITSET_TEST(rsrc->valid.data, i)) {
          blit.dst.level = blit.src.level = i;
+
+         u_box_3d(0, 0, 0,
+                  u_minify(rsrc->base.width0, i),
+                  u_minify(rsrc->base.height0, i),
+                  util_num_layers(&rsrc->base, i),
+                  &blit.dst.box);
+         blit.src.box = blit.dst.box;
+
          panfrost_blit(&ctx->base, &blit);
       }
    }

Reply via email to