From 0b029f319f037911ee871e2e5196e0b8f1e265b1 Mon Sep 17 00:00:00 2001 From: Faith Ekstrand Date: Tue, 24 Mar 2026 09:53:03 -0400 Subject: [PATCH] pan/bi: Properly handle large 8-bit vectors in bi_alu_src_index() Previously, we used bi_src_index() directly and ignored the offset we took all that care to calculate at the top of the function. For most cases, this is fine since the offset is 0. But if we ever have an i8v8, or larger, this doesn't work. It's not really more work to handle this case. All we have to do is use the offset and &3 the swizzle. It just means we can't have false code sharing with the bi_make_vec_to() case. Reviewed-by: Lars-Ivar Hesselberg Simonsen Reviewed-by: Christoph Pillmayer Reviewed-by: Lorenzo Rossi Part-of: --- .../compiler/bifrost/bifrost_compile.c | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/panfrost/compiler/bifrost/bifrost_compile.c b/src/panfrost/compiler/bifrost/bifrost_compile.c index 0ea1597bd5c..71245aa2be6 100644 --- a/src/panfrost/compiler/bifrost/bifrost_compile.c +++ b/src/panfrost/compiler/bifrost/bifrost_compile.c @@ -2567,6 +2567,18 @@ bi_alu_src_index(bi_builder *b, nir_alu_src src, unsigned comps) } else if (bitsize == 8 && comps == 1) { idx.swizzle = BI_SWIZZLE_B0000 + (src.swizzle[0] & 3); } else if (bitsize == 8) { + if (comps == 2 || comps == 4) { + unsigned c[4] = {0}; + for (unsigned i = 0; i < comps; ++i) + c[i] = src.swizzle[i] & 3; + + enum bi_swizzle swizzle; + if (bi_byte_swizzle_from_nir_swizzle(c, comps, &swizzle)) { + idx.swizzle = swizzle; + return idx; + } + } + /* XXX: Use optimized swizzle when posisble */ bi_index unoffset_srcs[NIR_MAX_VEC_COMPONENTS] = {bi_null()}; unsigned channels[NIR_MAX_VEC_COMPONENTS] = {0}; @@ -2576,15 +2588,6 @@ bi_alu_src_index(bi_builder *b, nir_alu_src src, unsigned comps) channels[i] = src.swizzle[i]; } - if (comps == 2 || comps == 4) { - enum bi_swizzle swizzle; - if (bi_byte_swizzle_from_nir_swizzle(channels, comps, &swizzle)) { - bi_index ret = bi_src_index(&src.src); - ret.swizzle = swizzle; - return ret; - } - } - bi_index temp = bi_temp(b->shader); bi_make_vec_to(b, temp, unoffset_srcs, channels, comps, bitsize);