From 368d30befcffd4a4bb924e399ffc2002216ddcef Mon Sep 17 00:00:00 2001 From: Boris Brezillon Date: Fri, 7 Jun 2024 12:46:54 +0200 Subject: [PATCH] pan/bi: Fix dynamic indexing of push constants Base offset of the push constant access shouldn't be taken into account when selecting the push constant words to load. We should instead assume the first word in the range is the base of the dynamic indexing, which also simplifies the code. Fixes: d53e8489365f ("pan/bi: Lower load_push_constant with dynamic indexing") Signed-off-by: Boris Brezillon Reviewed-by: Mary Guillemard Acked-by: Erik Faye-Lund Part-of: --- src/panfrost/compiler/bifrost_compile.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/src/panfrost/compiler/bifrost_compile.c b/src/panfrost/compiler/bifrost_compile.c index 898e9188621..64bb2e45d9e 100644 --- a/src/panfrost/compiler/bifrost_compile.c +++ b/src/panfrost/compiler/bifrost_compile.c @@ -4814,8 +4814,6 @@ bi_lower_load_push_const_with_dyn_offset(nir_builder *b, uint32_t base = nir_intrinsic_base(intr); uint32_t range = nir_intrinsic_range(intr); uint32_t nwords = intr->def.num_components; - uint32_t first_word = base / 4; - uint32_t last_word = (base + range) / 4; b->cursor = nir_before_instr(&intr->instr); @@ -4825,12 +4823,12 @@ bi_lower_load_push_const_with_dyn_offset(nir_builder *b, */ nir_def *lut[64] = {0}; - assert(last_word <= ARRAY_SIZE(lut)); + assert(range / 4 <= ARRAY_SIZE(lut)); /* Load all words in the range. */ - for (uint32_t w = first_word; w < last_word; w++) { + for (uint32_t w = 0; w < range / 4; w++) { lut[w] = nir_load_push_constant(b, 1, 32, nir_imm_int(b, 0), - .base = w * 4, .range = 4); + .base = base + (w * 4), .range = 4); } nir_def *index = intr->src[0].ssa; @@ -4843,10 +4841,10 @@ bi_lower_load_push_const_with_dyn_offset(nir_builder *b, uint32_t stride = lut_sz / 2; nir_def *bit_test = NULL; - /* Stop when the first and last component don't fit in the new LUT - * window. + /* Stop when the LUT is smaller than the number of words we're trying to + * extract. */ - if (((first_word + nwords - 1) & stride) != (first_word & stride)) + if (lut_sz <= nwords) break; for (uint32_t i = 0; i < stride; i++) { @@ -4866,14 +4864,9 @@ bi_lower_load_push_const_with_dyn_offset(nir_builder *b, lut[i] = lut[i + stride]; } } - - /* Adjust first_word so it always points to the bottom half of our LUT, - * which contains the result of the CSELs we've just done. - */ - first_word &= stride - 1; } - nir_def *res = nir_vec(b, &lut[first_word], nwords); + nir_def *res = nir_vec(b, &lut[0], nwords); nir_def_rewrite_uses(&intr->def, res); nir_instr_remove(&intr->instr);