From 0a36a33f538b2597eebd4ae7e8ffcf28f3b93c66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Molinari?= Date: Wed, 25 Mar 2026 16:29:23 +0100 Subject: [PATCH] panfrost: Move clear funcs to pan_blitter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Move panfrost_clear_render_target() and panfrost_clear_depth_stencil() to pan_blitter.c. This allows to make pan_blitter_save_states() static and avoids to expose the saved states enums. Signed-off-by: Loïc Molinari Reviewed-by: Ashley Smith Acked-by: Boris Brezillon Part-of: --- src/gallium/drivers/panfrost/pan_blitter.c | 112 +++++++++++++++++++- src/gallium/drivers/panfrost/pan_blitter.h | 45 ++++---- src/gallium/drivers/panfrost/pan_context.c | 39 +------ src/gallium/drivers/panfrost/pan_resource.c | 54 +--------- 4 files changed, 136 insertions(+), 114 deletions(-) diff --git a/src/gallium/drivers/panfrost/pan_blitter.c b/src/gallium/drivers/panfrost/pan_blitter.c index e03ad8fadfd..b0498ec226a 100644 --- a/src/gallium/drivers/panfrost/pan_blitter.c +++ b/src/gallium/drivers/panfrost/pan_blitter.c @@ -11,6 +11,26 @@ #include "pan_trace.h" #include "pan_util.h" +enum panfrost_blitter_op /* bitmask */ +{ + PAN_SAVE_TEXTURES = 1, + PAN_SAVE_FRAMEBUFFER = 2, + PAN_SAVE_FRAGMENT_STATE = 4, + PAN_SAVE_FRAGMENT_CONSTANT = 8, + PAN_DISABLE_RENDER_COND = 16, +}; + +enum { + PAN_RENDER_BLIT = + PAN_SAVE_TEXTURES | PAN_SAVE_FRAMEBUFFER | PAN_SAVE_FRAGMENT_STATE, + PAN_RENDER_BLIT_COND = PAN_SAVE_TEXTURES | PAN_SAVE_FRAMEBUFFER | + PAN_SAVE_FRAGMENT_STATE | PAN_DISABLE_RENDER_COND, + PAN_RENDER_BASE = PAN_SAVE_FRAMEBUFFER | PAN_SAVE_FRAGMENT_STATE, + PAN_RENDER_COND = + PAN_SAVE_FRAMEBUFFER | PAN_SAVE_FRAGMENT_STATE | PAN_DISABLE_RENDER_COND, + PAN_RENDER_CLEAR = PAN_SAVE_FRAGMENT_STATE | PAN_SAVE_FRAGMENT_CONSTANT, +}; + static void panfrost_blitter_draw_rectangle(struct blitter_context *blitter, void *vertex_elements_cso, @@ -82,7 +102,7 @@ panfrost_blitter_create(struct pipe_context *pipe) return blitter; } -void +static void panfrost_blitter_save(struct panfrost_context *ctx, const enum panfrost_blitter_op blitter_op) { @@ -172,3 +192,93 @@ panfrost_blitter_blit(struct pipe_context *pipe, panfrost_blitter_blit_no_afbc_legalization(pipe, info); panfrost_flush_all_batches(ctx, "Blit"); } + +void +panfrost_blitter_clear(struct pipe_context *pipe, unsigned buffers, + uint32_t color_clear_mask, uint8_t stencil_clear_mask, + const struct pipe_scissor_state *scissor_state, + const union pipe_color_union *color, double depth, + unsigned stencil) +{ + PAN_TRACE_FUNC(PAN_TRACE_GL_BLIT); + + if (!panfrost_render_condition_check(pan_context(pipe))) + return; + + /* Only get batch after checking the render condition, since the check can + * cause the batch to be flushed. + */ + struct panfrost_context *ctx = pan_context(pipe); + struct panfrost_batch *batch = panfrost_get_batch_for_fbo(ctx); + if (!batch) + return; + + /* At the start of the batch, we can clear for free */ + if (batch->draw_count == 0) { + panfrost_batch_clear(batch, buffers, color, depth, stencil); + return; + } + + /* Once there is content, clear with a fullscreen quad */ + panfrost_blitter_save(ctx, PAN_RENDER_CLEAR); + + perf_debug(ctx, "Clearing with quad"); + util_blitter_clear( + ctx->blitter, ctx->pipe_framebuffer.width, ctx->pipe_framebuffer.height, + util_framebuffer_get_num_layers(&ctx->pipe_framebuffer), buffers, color, + depth, stencil, + util_framebuffer_get_num_samples(&ctx->pipe_framebuffer) > 1); +} + +void +panfrost_blitter_clear_depth_stencil(struct pipe_context *pipe, + struct pipe_surface *dst, + unsigned clear_flags, double depth, + unsigned stencil, unsigned dstx, + unsigned dsty, unsigned width, + unsigned height, + bool render_condition_enabled) +{ + PAN_TRACE_FUNC(PAN_TRACE_GL_BLIT); + + struct panfrost_context *ctx = pan_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, + stencil, dstx, dsty, width, height); +} + +void +panfrost_blitter_clear_render_target(struct pipe_context *pipe, + struct pipe_surface *dst, + const union pipe_color_union *color, + unsigned dstx, unsigned dsty, + unsigned width, unsigned height, + bool render_condition_enabled) +{ + PAN_TRACE_FUNC(PAN_TRACE_GL_BLIT); + + struct panfrost_context *ctx = pan_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, height); +} diff --git a/src/gallium/drivers/panfrost/pan_blitter.h b/src/gallium/drivers/panfrost/pan_blitter.h index 64f381cbe21..55239e4fe0c 100644 --- a/src/gallium/drivers/panfrost/pan_blitter.h +++ b/src/gallium/drivers/panfrost/pan_blitter.h @@ -8,31 +8,8 @@ #include "pan_context.h" -enum panfrost_blitter_op /* bitmask */ -{ - PAN_SAVE_TEXTURES = 1, - PAN_SAVE_FRAMEBUFFER = 2, - PAN_SAVE_FRAGMENT_STATE = 4, - PAN_SAVE_FRAGMENT_CONSTANT = 8, - PAN_DISABLE_RENDER_COND = 16, -}; - -enum { - PAN_RENDER_BLIT = - PAN_SAVE_TEXTURES | PAN_SAVE_FRAMEBUFFER | PAN_SAVE_FRAGMENT_STATE, - PAN_RENDER_BLIT_COND = PAN_SAVE_TEXTURES | PAN_SAVE_FRAMEBUFFER | - PAN_SAVE_FRAGMENT_STATE | PAN_DISABLE_RENDER_COND, - PAN_RENDER_BASE = PAN_SAVE_FRAMEBUFFER | PAN_SAVE_FRAGMENT_STATE, - PAN_RENDER_COND = - PAN_SAVE_FRAMEBUFFER | PAN_SAVE_FRAGMENT_STATE | PAN_DISABLE_RENDER_COND, - PAN_RENDER_CLEAR = PAN_SAVE_FRAGMENT_STATE | PAN_SAVE_FRAGMENT_CONSTANT, -}; - struct blitter_context *panfrost_blitter_create(struct pipe_context *pipe); -void panfrost_blitter_save(struct panfrost_context *ctx, - const enum panfrost_blitter_op blitter_op); - /* 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 */ @@ -42,4 +19,26 @@ void panfrost_blitter_blit_no_afbc_legalization(struct pipe_context *pipe, void panfrost_blitter_blit(struct pipe_context *pipe, const struct pipe_blit_info *info); +void panfrost_blitter_clear(struct pipe_context *pipe, unsigned buffers, + uint32_t color_clear_mask, + uint8_t stencil_clear_mask, + const struct pipe_scissor_state *scissor_state, + const union pipe_color_union *color, double depth, + unsigned stencil); + +void panfrost_blitter_clear_depth_stencil(struct pipe_context *pipe, + struct pipe_surface *dst, + unsigned clear_flags, double depth, + unsigned stencil, unsigned dstx, + unsigned dsty, unsigned width, + unsigned height, + bool render_condition_enabled); + +void panfrost_blitter_clear_render_target(struct pipe_context *pipe, + struct pipe_surface *dst, + const union pipe_color_union *color, + unsigned dstx, unsigned dsty, + unsigned width, unsigned height, + bool render_condition_enabled); + #endif diff --git a/src/gallium/drivers/panfrost/pan_context.c b/src/gallium/drivers/panfrost/pan_context.c index 2def7f7fca6..4b258388591 100644 --- a/src/gallium/drivers/panfrost/pan_context.c +++ b/src/gallium/drivers/panfrost/pan_context.c @@ -39,43 +39,6 @@ #include "pan_trace.h" #include "pan_util.h" -static void -panfrost_clear(struct pipe_context *pipe, unsigned buffers, - uint32_t color_clear_mask, uint8_t stencil_clear_mask, - const struct pipe_scissor_state *scissor_state, - const union pipe_color_union *color, double depth, - unsigned stencil) -{ - PAN_TRACE_FUNC(PAN_TRACE_GL_CONTEXT); - - if (!panfrost_render_condition_check(pan_context(pipe))) - return; - - /* Only get batch after checking the render condition, since the check can - * cause the batch to be flushed. - */ - struct panfrost_context *ctx = pan_context(pipe); - struct panfrost_batch *batch = panfrost_get_batch_for_fbo(ctx); - if (!batch) - return; - - /* At the start of the batch, we can clear for free */ - if (batch->draw_count == 0) { - panfrost_batch_clear(batch, buffers, color, depth, stencil); - return; - } - - /* Once there is content, clear with a fullscreen quad */ - panfrost_blitter_save(ctx, PAN_RENDER_CLEAR); - - perf_debug(ctx, "Clearing with quad"); - util_blitter_clear( - ctx->blitter, ctx->pipe_framebuffer.width, ctx->pipe_framebuffer.height, - util_framebuffer_get_num_layers(&ctx->pipe_framebuffer), buffers, color, - depth, stencil, - util_framebuffer_get_num_samples(&ctx->pipe_framebuffer) > 1); -} - bool panfrost_writes_point_size(struct panfrost_context *ctx) { @@ -1031,7 +994,7 @@ panfrost_create_context(struct pipe_screen *screen, void *priv, unsigned flags) gallium->fence_server_sync = panfrost_fence_server_sync; gallium->flush = panfrost_flush; - gallium->clear = panfrost_clear; + gallium->clear = panfrost_blitter_clear; gallium->clear_texture = u_default_clear_texture; gallium->texture_barrier = panfrost_texture_barrier; gallium->set_frontend_noop = panfrost_set_frontend_noop; diff --git a/src/gallium/drivers/panfrost/pan_resource.c b/src/gallium/drivers/panfrost/pan_resource.c index 212fc84ba94..c94c185ac72 100644 --- a/src/gallium/drivers/panfrost/pan_resource.c +++ b/src/gallium/drivers/panfrost/pan_resource.c @@ -36,56 +36,6 @@ #include "pan_trace.h" #include "pan_util.h" -static void -panfrost_clear_depth_stencil(struct pipe_context *pipe, - struct pipe_surface *dst, unsigned clear_flags, - double depth, unsigned stencil, unsigned dstx, - unsigned dsty, unsigned width, unsigned height, - bool render_condition_enabled) -{ - PAN_TRACE_FUNC(PAN_TRACE_GL_RESOURCE); - - struct panfrost_context *ctx = pan_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, - stencil, dstx, dsty, width, height); -} - -static void -panfrost_clear_render_target(struct pipe_context *pipe, - struct pipe_surface *dst, - const union pipe_color_union *color, unsigned dstx, - unsigned dsty, unsigned width, unsigned height, - bool render_condition_enabled) -{ - PAN_TRACE_FUNC(PAN_TRACE_GL_RESOURCE); - - struct panfrost_context *ctx = pan_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, - height); -} - static uint64_t panfrost_max_res_size_b(unsigned arch) { @@ -2587,6 +2537,6 @@ panfrost_resource_context_init(struct pipe_context *pctx) pctx->buffer_subdata = u_default_buffer_subdata; pctx->texture_subdata = u_default_texture_subdata; pctx->clear_buffer = u_default_clear_buffer; - pctx->clear_render_target = panfrost_clear_render_target; - pctx->clear_depth_stencil = panfrost_clear_depth_stencil; + pctx->clear_render_target = panfrost_blitter_clear_render_target; + pctx->clear_depth_stencil = panfrost_blitter_clear_depth_stencil; }