From 1c87479193d0a5e2b97c668f9c5e5d0c2fb7b723 Mon Sep 17 00:00:00 2001 From: Mary Guillemard Date: Thu, 24 Jul 2025 09:33:12 +0000 Subject: [PATCH] pan/bi: Properly handle SWZ.v4i8 lowering on v11+ We were not supporting non replicate swizzle and this trigger an assertion on fossils/parallel-rdp/small_subgroup.foz. Signed-off-by: Mary Guillemard Fixes: 1481b14fcb54 ("pan/bi: Lower SWZ.v4i8 to multiple MKVEC.v2i8 on v11+") Reviewed-by: Olivia Lee Part-of: (cherry picked from commit 525f2972a66ca9d952e8dcb5bea18e13da9e4c39) --- .pick_status.json | 2 +- src/panfrost/compiler/valhall/va_lower_isel.c | 59 +++++++++++++++++-- 2 files changed, 56 insertions(+), 5 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index 02f0120eb6a..b3be4e86381 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -1374,7 +1374,7 @@ "description": "pan/bi: Properly handle SWZ.v4i8 lowering on v11+", "nominated": true, "nomination_type": 2, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": "1481b14fcb54af9b2263caddc2788dc11e7dca08", "notes": null diff --git a/src/panfrost/compiler/valhall/va_lower_isel.c b/src/panfrost/compiler/valhall/va_lower_isel.c index d69b37f6e10..4a9e2f313c4 100644 --- a/src/panfrost/compiler/valhall/va_lower_isel.c +++ b/src/panfrost/compiler/valhall/va_lower_isel.c @@ -22,9 +22,54 @@ */ #include "bi_builder.h" +#include "compiler.h" #include "va_compiler.h" #include "valhall.h" +static void +va_compose_mkvec_swz_v4i8(bi_index *b, enum bi_swizzle swz) +{ +#define B(b0, b1, b2, b3) \ + case BI_SWIZZLE_B##b0##b1##b2##b3: \ + b[0].swizzle = BI_SWIZZLE_B##b0; \ + b[1].swizzle = BI_SWIZZLE_B##b1; \ + b[2].swizzle = BI_SWIZZLE_B##b2; \ + b[3].swizzle = BI_SWIZZLE_B##b3; \ + break; + + switch (swz) { + B(0, 1, 0, 1); + B(0, 1, 2, 3); + B(2, 3, 0, 1); + B(2, 3, 2, 3); + B(0, 0, 0, 0); + B(1, 1, 1, 1); + B(2, 2, 2, 2); + B(3, 3, 3, 3); + B(0, 0, 1, 1); + B(2, 2, 3, 3); + B(1, 0, 3, 2); + B(3, 2, 1, 0); + B(0, 0, 2, 2); + B(1, 1, 0, 0); + B(2, 2, 0, 0); + B(3, 3, 0, 0); + B(2, 2, 1, 1); + B(3, 3, 1, 1); + B(1, 1, 2, 2); + B(3, 3, 2, 2); + B(0, 0, 3, 3); + B(1, 1, 3, 3); + B(1, 1, 2, 3); + + default: + unreachable("Invalid swizzle"); + break; + } + +#undef B +} + static bi_instr * lower(bi_builder *b, bi_instr *I) { @@ -37,10 +82,16 @@ lower(bi_builder *b, bi_instr *I) case BI_OPCODE_SWZ_V4I8: { /* IADD.v4u8 is gone on v11 */ if (b->shader->arch >= 11) { - assert(I->src[0].swizzle >= BI_SWIZZLE_B0000 && - I->src[0].swizzle <= BI_SWIZZLE_B3333); - bi_index tmp = bi_mkvec_v2i8(b, I->src[0], I->src[0], bi_zero()); - return bi_mkvec_v2i8_to(b, I->dest[0], I->src[0], I->src[0], tmp); + bi_index bytes[4] = { + I->src[0], + I->src[0], + I->src[0], + I->src[0], + }; + + va_compose_mkvec_swz_v4i8(bytes, I->src[0].swizzle); + bi_index high = bi_mkvec_v2i8(b, bytes[2], bytes[3], bi_zero()); + return bi_mkvec_v2i8_to(b, I->dest[0], bytes[0], bytes[1], high); } return bi_iadd_v4u8_to(b, I->dest[0], I->src[0], bi_zero(), false);