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 <christoph.pillmayer@arm.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41117>
This commit is contained in:
Eric R. Smith 2026-04-22 20:49:53 -03:00 committed by Marge Bot
parent 41965d4082
commit 8d1fba686b

View file

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