From 8d1fba686bb6f5b180854f61dbbe972ee76c3827 Mon Sep 17 00:00:00 2001 From: "Eric R. Smith" Date: Wed, 22 Apr 2026 20:49:53 -0300 Subject: [PATCH] panfrost: add some sanity checks `__builtin_ctz` is not well defined for `0`, so provide a default value of `0` for this case. The other sensible choice would be `64`, but that does not fit in the 5 bit `divisor_r` field (which is how I noticed this, we were triggering a run time assert in a debug build). We should skip `launch_draw` if there are no vertices to draw. This avoids a crash in some indirect rendering tests on Bifrost. Reviewed-by: Christoph Pillmayer Part-of: --- src/gallium/drivers/panfrost/pan_cmdstream.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/gallium/drivers/panfrost/pan_cmdstream.c b/src/gallium/drivers/panfrost/pan_cmdstream.c index 58b044c5295..6327b4e4ef9 100644 --- a/src/gallium/drivers/panfrost/pan_cmdstream.c +++ b/src/gallium/drivers/panfrost/pan_cmdstream.c @@ -2412,7 +2412,7 @@ panfrost_emit_vertex_data(struct panfrost_batch *batch, uint64_t *buffers) cfg.pointer = addr; cfg.stride = stride; cfg.size = size; - cfg.divisor_r = __builtin_ctz(hw_divisor); + cfg.divisor_r = hw_divisor ? __builtin_ctz(hw_divisor) : 0; } } else { @@ -3446,7 +3446,7 @@ panfrost_single_draw_direct(struct panfrost_batch *batch, struct panfrost_compiled_shader *vs = ctx->prog[MESA_SHADER_VERTEX]; bool idvs = vs->info.vs.idvs; - UNUSED unsigned vertex_count = + unsigned vertex_count = panfrost_draw_get_vertex_count(batch, info, draw, idvs); panfrost_statistics_record(ctx, info, draw); @@ -3476,7 +3476,8 @@ panfrost_single_draw_direct(struct panfrost_batch *batch, info->mode == MESA_PRIM_POINTS); #endif - JOBX(launch_draw)(batch, info, drawid_offset, draw, vertex_count); + if (vertex_count > 0) + JOBX(launch_draw)(batch, info, drawid_offset, draw, vertex_count); batch->draw_count++; }