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 <boris.brezillon@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26077>
This commit is contained in:
Erik Faye-Lund 2023-11-06 17:41:02 +01:00 committed by Marge Bot
parent b27ca68143
commit 777c25255b

View file

@ -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);
}
}