From 80e6b468f435aea09c085b14efff9e70c32ec4dd Mon Sep 17 00:00:00 2001 From: "Eric R. Smith" Date: Thu, 23 Apr 2026 15:22:13 -0300 Subject: [PATCH] panfrost: add helper function for checking for active queries Add a convenience helper function, and use this for checking whether queries are active. This fixes a bug where we were basically always using a software fallback for indirect rendering rather than the CSF hardware loop. Cc: mesa-stable Reviewed-by: Erik Faye-Lund Reviewed-by: Boris Brezillon Reviewed-by: Christian Gmeiner Part-of: --- src/gallium/drivers/panfrost/pan_cmdstream.c | 5 +++-- src/gallium/drivers/panfrost/pan_context.h | 6 ++++++ src/gallium/drivers/panfrost/pan_csf.c | 2 +- src/gallium/drivers/panfrost/pan_jm.c | 4 ++-- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/gallium/drivers/panfrost/pan_cmdstream.c b/src/gallium/drivers/panfrost/pan_cmdstream.c index 6327b4e4ef9..87a3cbbe7ea 100644 --- a/src/gallium/drivers/panfrost/pan_cmdstream.c +++ b/src/gallium/drivers/panfrost/pan_cmdstream.c @@ -497,7 +497,7 @@ panfrost_prepare_fs_state(struct panfrost_context *ctx, uint64_t *blend_shaders, for (unsigned c = 0; c < rt_count; ++c) has_blend_shader |= (blend_shaders[c] != 0); - bool has_oq = ctx->occlusion_query && ctx->active_queries; + bool has_oq = panfrost_occlusion_query_active(ctx); pan_pack(rsd, RENDERER_STATE, cfg) { if (panfrost_fs_required(fs, so, &ctx->pipe_framebuffer, zsa)) { @@ -3567,7 +3567,8 @@ panfrost_draw_indirect(struct pipe_context *pipe, { struct panfrost_context *ctx = pan_context(pipe); - if (!PAN_GPU_SUPPORTS_DRAW_INDIRECT || ctx->active_queries || + if (!PAN_GPU_SUPPORTS_DRAW_INDIRECT || + panfrost_occlusion_query_active(ctx) || ctx->streamout.num_targets) { util_draw_indirect(pipe, info, drawid_offset, indirect); perf_debug(ctx, "Emulating indirect draw on the CPU"); diff --git a/src/gallium/drivers/panfrost/pan_context.h b/src/gallium/drivers/panfrost/pan_context.h index b230ea62e27..6cf759843d8 100644 --- a/src/gallium/drivers/panfrost/pan_context.h +++ b/src/gallium/drivers/panfrost/pan_context.h @@ -545,6 +545,12 @@ panfrost_clean_state_3d(struct panfrost_context *ctx) } } +static inline bool +panfrost_occlusion_query_active(struct panfrost_context *ctx) +{ + return ctx->occlusion_query && ctx->active_queries; +} + void panfrost_set_batch_masks_blend(struct panfrost_batch *batch); void panfrost_set_batch_masks_zs(struct panfrost_batch *batch); diff --git a/src/gallium/drivers/panfrost/pan_csf.c b/src/gallium/drivers/panfrost/pan_csf.c index 2389926de3b..2246804b85c 100644 --- a/src/gallium/drivers/panfrost/pan_csf.c +++ b/src/gallium/drivers/panfrost/pan_csf.c @@ -1177,7 +1177,7 @@ csf_emit_draw_state(struct panfrost_batch *batch, fui(batch->maximum_z)); #endif - if (ctx->occlusion_query && ctx->active_queries) { + if (panfrost_occlusion_query_active(ctx)) { struct panfrost_resource *rsrc = pan_resource(ctx->occlusion_query->rsrc); cs_move64_to(b, cs_sr_reg64(b, IDVS, OQ), rsrc->plane.base); panfrost_batch_write_rsrc(ctx->batch, rsrc, MESA_SHADER_FRAGMENT); diff --git a/src/gallium/drivers/panfrost/pan_jm.c b/src/gallium/drivers/panfrost/pan_jm.c index 620800d4efb..845c238853e 100644 --- a/src/gallium/drivers/panfrost/pan_jm.c +++ b/src/gallium/drivers/panfrost/pan_jm.c @@ -522,7 +522,7 @@ jm_emit_tiler_draw(struct mali_draw_packed *out, struct panfrost_batch *batch, cfg.front_face_ccw = rast->front_ccw; #endif - if (ctx->occlusion_query && ctx->active_queries) { + if (panfrost_occlusion_query_active(ctx)) { #if PAN_ARCH == 9 if (ctx->occlusion_query->type == PIPE_QUERY_OCCLUSION_COUNTER) cfg.flags_0.occlusion_query = MALI_OCCLUSION_MODE_COUNTER; @@ -569,7 +569,7 @@ jm_emit_tiler_draw(struct mali_draw_packed *out, struct panfrost_batch *batch, cfg.flags_0.multisample_enable = true; if (fs_required) { - bool has_oq = ctx->occlusion_query && ctx->active_queries; + bool has_oq = panfrost_occlusion_query_active(ctx); struct pan_earlyzs_state earlyzs = pan_earlyzs_get( fs->earlyzs, ctx->depth_stencil->writes_zs || has_oq,