From 0edceaf383a3265f8ecdad0fd3a62f60d4f3a1cd Mon Sep 17 00:00:00 2001 From: Faith Ekstrand Date: Mon, 30 Mar 2026 12:40:33 -0400 Subject: [PATCH] pan/bi: Add a bi_op_supports_swizzle() helper Reviewed-by: Lorenzo Rossi Part-of: --- src/panfrost/compiler/bifrost/bi_lower_swizzle.c | 13 ++++++++++--- src/panfrost/compiler/bifrost/compiler.h | 3 +++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/panfrost/compiler/bifrost/bi_lower_swizzle.c b/src/panfrost/compiler/bifrost/bi_lower_swizzle.c index 40b39e69e85..42a7d5f917f 100644 --- a/src/panfrost/compiler/bifrost/bi_lower_swizzle.c +++ b/src/panfrost/compiler/bifrost/bi_lower_swizzle.c @@ -95,6 +95,15 @@ va_op_swizzles(enum bi_opcode op, unsigned src) return swizzles; } +bool +bi_op_supports_swizzle(enum bi_opcode op, unsigned src, + enum bi_swizzle swizzle, unsigned arch) +{ + uint32_t supported_swizzles = arch >= 9 ? + va_op_swizzles(op, src) : bi_op_swizzles[op][src]; + return supported_swizzles & BITFIELD_BIT(swizzle); +} + static void lower_swizzle(bi_context *ctx, bi_instr *ins, unsigned src) { @@ -112,9 +121,7 @@ lower_swizzle(bi_context *ctx, bi_instr *ins, unsigned src) return; } - uint32_t supported_swizzles = pan_arch(ctx->inputs->gpu_id) >= 9 ? - va_op_swizzles(ins->op, src) : bi_op_swizzles[ins->op][src]; - if (supported_swizzles & (1 << ins->src[src].swizzle)) + if (bi_op_supports_swizzle(ins->op, src, ins->src[src].swizzle, ctx->arch)) return; /* First, try to apply a given swizzle to a constant to clear the diff --git a/src/panfrost/compiler/bifrost/compiler.h b/src/panfrost/compiler/bifrost/compiler.h index fcbe016c0b1..d6dca04fc9b 100644 --- a/src/panfrost/compiler/bifrost/compiler.h +++ b/src/panfrost/compiler/bifrost/compiler.h @@ -98,6 +98,9 @@ enum bi_swizzle { BI_SWIZZLE_B33 = BI_SWIZZLE_B3333, }; +bool bi_op_supports_swizzle(enum bi_opcode op, unsigned src, + enum bi_swizzle swizzle, unsigned arch); + static inline void bi_swizzle_to_byte_channels(enum bi_swizzle swizzle, unsigned *channels) {