From ed50cf29f3f37acc85de09609a7cb7612969bf96 Mon Sep 17 00:00:00 2001 From: Georg Lehmann Date: Thu, 9 Apr 2026 17:48:25 +0200 Subject: [PATCH] spirv: map float control2 to fine grained nir flags instead of exact Reviewed-by: Alyssa Rosenzweig Reviewed-by: Rhys Perry Part-of: --- src/compiler/spirv/spirv_to_nir.c | 20 +++++++++++++------- src/compiler/spirv/vtn_alu.c | 14 ++++++-------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/compiler/spirv/spirv_to_nir.c b/src/compiler/spirv/spirv_to_nir.c index fea0580ee9f..7467de36912 100644 --- a/src/compiler/spirv/spirv_to_nir.c +++ b/src/compiler/spirv/spirv_to_nir.c @@ -6042,13 +6042,19 @@ vtn_handle_execution_mode_id(struct vtn_builder *b, struct vtn_value *entry_poin if (!fp_math_ctrl) vtn_fail("Unkown float type for FPFastMathDefault"); - SpvFPFastMathModeMask can_fast_math = - SpvFPFastMathModeAllowRecipMask | - SpvFPFastMathModeAllowContractMask | - SpvFPFastMathModeAllowReassocMask | - SpvFPFastMathModeAllowTransformMask; - if ((flags & can_fast_math) != can_fast_math) - *fp_math_ctrl |= nir_fp_exact; + if (!(flags & SpvFPFastMathModeAllowContractMask)) + *fp_math_ctrl |= nir_fp_no_contract; + + if (!(flags & SpvFPFastMathModeAllowReassocMask)) + *fp_math_ctrl |= nir_fp_no_reassoc; + + if (!(flags & SpvFPFastMathModeAllowTransformMask)) + *fp_math_ctrl |= nir_fp_no_transform; + + /* XXX maybe SpvFPFastMathModeAllowRecipMask + * should do something for CL? + * It's always allowed for VK/GL. + */ if (!(flags & SpvFPFastMathModeNotNaNMask)) *fp_math_ctrl |= nir_fp_preserve_nan; diff --git a/src/compiler/spirv/vtn_alu.c b/src/compiler/spirv/vtn_alu.c index 6898b2bf151..d506b2f4f9f 100644 --- a/src/compiler/spirv/vtn_alu.c +++ b/src/compiler/spirv/vtn_alu.c @@ -397,16 +397,14 @@ handle_fp_fast_math(struct vtn_builder *b, UNUSED struct vtn_value *val, if (dec->decoration != SpvDecorationFPFastMathMode) return; - SpvFPFastMathModeMask can_fast_math = - SpvFPFastMathModeAllowRecipMask | - SpvFPFastMathModeAllowContractMask | - SpvFPFastMathModeAllowReassocMask | - SpvFPFastMathModeAllowTransformMask; - /* Decoration overrides defaults. */ b->nb.fp_math_ctrl = 0; - if ((dec->operands[0] & can_fast_math) != can_fast_math) - b->nb.fp_math_ctrl |= nir_fp_exact; + if (!(dec->operands[0] & SpvFPFastMathModeAllowContractMask)) + b->nb.fp_math_ctrl |= nir_fp_no_contract; + if (!(dec->operands[0] & SpvFPFastMathModeAllowReassocMask)) + b->nb.fp_math_ctrl |= nir_fp_no_reassoc; + if (!(dec->operands[0] & SpvFPFastMathModeAllowTransformMask)) + b->nb.fp_math_ctrl |= nir_fp_no_transform; if (!(dec->operands[0] & SpvFPFastMathModeNSZMask)) b->nb.fp_math_ctrl |= nir_fp_preserve_signed_zero; if (!(dec->operands[0] & SpvFPFastMathModeNotNaNMask))