From 280c64d720299c2b53aa53a34cfbca7178b463d3 Mon Sep 17 00:00:00 2001 From: Connor Abbott Date: Wed, 15 Apr 2026 14:21:42 -0400 Subject: [PATCH] ir3: Don't reset immediate count to 0 after lowering We need to know the immediate count even after lowering, to compute the overall const size. Previously we were using the capacity field, but that's unreliable and won't be available once we switch to a real dynamic array container instead of (poorly) reinventing one. Fixes: 86f3c0c4c2c ("ir3: simplify constlen calculation") Part-of: --- src/freedreno/ir3/ir3_preamble.c | 1 - src/freedreno/vulkan/tu_shader.cc | 3 ++- src/gallium/drivers/freedreno/ir3/ir3_const.h | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/freedreno/ir3/ir3_preamble.c b/src/freedreno/ir3/ir3_preamble.c index 70400a8dadc..475d77c792d 100644 --- a/src/freedreno/ir3/ir3_preamble.c +++ b/src/freedreno/ir3/ir3_preamble.c @@ -47,6 +47,5 @@ ir3_imm_const_to_preamble(struct ir3 *ir, struct ir3_shader_variant *so) ir3_store_const(so, &build, src, dst); } - imms->count = 0; return true; } diff --git a/src/freedreno/vulkan/tu_shader.cc b/src/freedreno/vulkan/tu_shader.cc index ac0bae6bda9..0347db46acd 100644 --- a/src/freedreno/vulkan/tu_shader.cc +++ b/src/freedreno/vulkan/tu_shader.cc @@ -1576,7 +1576,8 @@ tu_xs_get_immediates_packet_size_dwords(const struct ir3_shader_variant *xs) const struct ir3_const_state *const_state = ir3_const_state(xs); uint32_t base = const_state->allocs.max_const_offset_vec4; const struct ir3_imm_const_state *imm_state = &xs->imm_state; - int32_t size = DIV_ROUND_UP(imm_state->count, 4); + int32_t size = xs->compiler->info->props.load_shader_consts_via_preamble ? + 0 : DIV_ROUND_UP(imm_state->count, 4); /* truncate size to avoid writing constants that shader * does not use: diff --git a/src/gallium/drivers/freedreno/ir3/ir3_const.h b/src/gallium/drivers/freedreno/ir3/ir3_const.h index 2d42e21a27a..c9081f65333 100644 --- a/src/gallium/drivers/freedreno/ir3/ir3_const.h +++ b/src/gallium/drivers/freedreno/ir3/ir3_const.h @@ -302,7 +302,8 @@ ir3_emit_immediates(const struct ir3_shader_variant *v, { const struct ir3_const_state *const_state = ir3_const_state(v); uint32_t base = const_state->allocs.max_const_offset_vec4; - int size = DIV_ROUND_UP(v->imm_state.count, 4); + int size = v->compiler->info->props.load_shader_consts_via_preamble ? 0 : + DIV_ROUND_UP(v->imm_state.count, 4); /* truncate size to avoid writing constants that shader * does not use: