From 77f9cbd0c2c203051d2ff4b3be4a6a51766677c4 Mon Sep 17 00:00:00 2001 From: Faith Ekstrand Date: Thu, 2 Apr 2026 02:06:32 -0400 Subject: [PATCH] pan/bi: Compose swizzles in bi_half() and bi_byte() At least bi_half() has the decency to assert if the swizzle isn't BI_SWIZZLE_H01 to start with but bi_byte() did an irrelevant assert and then overwrote the swizzle with BI_SWIZZLE_B regardless of what was there before. In a lot of cases, this doesn't matter but we use both in translating NIR to BI on things that may have already been swizzled so we need to do the composition. Reviewed-by: Lorenzo Rossi Part-of: --- src/panfrost/compiler/bifrost/compiler.h | 32 +++++++++++++----------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/panfrost/compiler/bifrost/compiler.h b/src/panfrost/compiler/bifrost/compiler.h index d4611030c18..d914c6712cf 100644 --- a/src/panfrost/compiler/bifrost/compiler.h +++ b/src/panfrost/compiler/bifrost/compiler.h @@ -341,8 +341,17 @@ bi_passthrough(enum bifrost_packed_src value) static inline bi_index bi_swz_16(bi_index idx, bool x, bool y) { - assert(idx.swizzle == BI_SWIZZLE_H01); - idx.swizzle = bi_swizzle_from_half(x, y); + bool halves[2]; + switch (idx.swizzle) { + case BI_SWIZZLE_H00: halves[0] = 0; halves[1] = 0; break; + case BI_SWIZZLE_H01: halves[0] = 0; halves[1] = 1; break; + case BI_SWIZZLE_H10: halves[0] = 1; halves[1] = 0; break; + case BI_SWIZZLE_H11: halves[0] = 1; halves[1] = 1; break; + default: UNREACHABLE("Not a half swizzle"); + } + assert(idx.swizzle == bi_swizzle_from_half(halves[0], halves[1])); + + idx.swizzle = bi_swizzle_from_half(halves[x], halves[y]); return idx; } @@ -352,22 +361,15 @@ bi_half(bi_index idx, bool upper) return bi_swz_16(idx, upper, upper); } -static inline bool -bi_valid_lane_for_byte_swizzle(enum bi_swizzle swizzle, unsigned lane) -{ - unsigned channels[4]; - if (bi_swizzle_to_byte_channels(swizzle, channels)) { - return lane == channels[0] || lane == channels[1] || - lane == channels[2] || lane == channels[3]; - } - return false; -} - static inline bi_index bi_byte(bi_index idx, unsigned lane) { - assert(bi_valid_lane_for_byte_swizzle(idx.swizzle, lane)); - idx.swizzle = (enum bi_swizzle)(BI_SWIZZLE_B0 + lane); + unsigned bytes[4]; + bool valid = bi_swizzle_to_byte_channels(idx.swizzle, bytes); + assert(valid); + + assert(lane < 4); + idx.swizzle = (enum bi_swizzle)(BI_SWIZZLE_B0 + bytes[lane]); return idx; }