From 104ea2e4cf0ab5d949c6c58a9fea1f0230dd7892 Mon Sep 17 00:00:00 2001 From: Olivia Lee Date: Thu, 15 May 2025 19:00:43 -0700 Subject: [PATCH] panfrost: legalize afbc before zs and rt clears In panfrost_clear_depth_stencil and panfrost_clear_render_target, we start the blit context before binding the clear targets. If we don't legalize AFBC beforehand, we get a recursive blit crash. panfrost_clear does not need this because the resource should already be legalized in panfrost_batch_add_surface. Fixes the following piglit tests with pan_force_afbc_packing: - spec@arb_clear_texture@arb_clear_texture-base-formats - spec@arb_clear_texture@arb_clear_texture-simple - spec@arb_clear_texture@arb_clear_texture-sized-formats Fixes: 17a62ff9934 ("panfrost: legalize afbc before blitting") Signed-off-by: Olivia Lee Reviewed-by: Eric R. Smith Part-of: --- src/gallium/drivers/panfrost/pan_resource.c | 10 ++++++++++ src/gallium/drivers/panfrost/pan_resource.h | 3 +++ 2 files changed, 13 insertions(+) diff --git a/src/gallium/drivers/panfrost/pan_resource.c b/src/gallium/drivers/panfrost/pan_resource.c index 26ca139ec6b..c612db03a92 100644 --- a/src/gallium/drivers/panfrost/pan_resource.c +++ b/src/gallium/drivers/panfrost/pan_resource.c @@ -70,6 +70,11 @@ panfrost_clear_depth_stencil(struct pipe_context *pipe, if (render_condition_enabled && !panfrost_render_condition_check(ctx)) return; + /* Legalize here because it could trigger a recursive blit otherwise */ + struct panfrost_resource *rdst = pan_resource(dst->texture); + enum pipe_format dst_view_format = util_format_linear(dst->format); + pan_legalize_format(ctx, rdst, dst_view_format, true, false); + panfrost_blitter_save( ctx, render_condition_enabled ? PAN_RENDER_COND : PAN_RENDER_BASE); util_blitter_clear_depth_stencil(ctx->blitter, dst, clear_flags, depth, @@ -88,6 +93,11 @@ panfrost_clear_render_target(struct pipe_context *pipe, if (render_condition_enabled && !panfrost_render_condition_check(ctx)) return; + /* Legalize here because it could trigger a recursive blit otherwise */ + struct panfrost_resource *rdst = pan_resource(dst->texture); + enum pipe_format dst_view_format = util_format_linear(dst->format); + pan_legalize_format(ctx, rdst, dst_view_format, true, false); + panfrost_blitter_save( ctx, (render_condition_enabled ? PAN_RENDER_COND : PAN_RENDER_BASE) | PAN_SAVE_FRAGMENT_CONSTANT); util_blitter_clear_render_target(ctx->blitter, dst, color, dstx, dsty, width, diff --git a/src/gallium/drivers/panfrost/pan_resource.h b/src/gallium/drivers/panfrost/pan_resource.h index f6e5f54e6cd..82973a945f3 100644 --- a/src/gallium/drivers/panfrost/pan_resource.h +++ b/src/gallium/drivers/panfrost/pan_resource.h @@ -137,6 +137,9 @@ enum { PAN_RENDER_CLEAR = PAN_SAVE_FRAGMENT_STATE | PAN_SAVE_FRAGMENT_CONSTANT, }; +/* Callers should ensure that all AFBC/AFRC resources that will be used in the + * blit operation are legalized before calling blitter operations, otherwise + * we may trigger a recursive blit */ void panfrost_blitter_save(struct panfrost_context *ctx, const enum panfrost_blitter_op blitter_op);