From 09e41584ca92641e927736f1a90cece2dcb505a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Hasi=C5=84ski?= Date: Tue, 6 Oct 2026 00:04:14 +0200 Subject: [PATCH] fix(shader): apply f32 abs and neg source modifiers on the sign bit F32 operands applied |x| and -x as FAbs and OpFNegate. The NVIDIA driver returns its canonical NaN 0x7fffffff from FAbs of a NaN with a payload, so an instruction that passes a NaN operand through on the bits, such as v_div_fixup_f32 with |v5| = 0x7ff00000, loses the payload. RADV and lavapipe keep it. Clear or flip the sign bit instead, as readOperand already does for U32 operands. IEEE 754 defines abs and negate as sign-bit operations, so this is exact for every input. --- .../src/TranslationContext/OperandAccess.cpp | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/core/shader/recompiler/Translation/src/TranslationContext/OperandAccess.cpp b/core/shader/recompiler/Translation/src/TranslationContext/OperandAccess.cpp index d0b6568c0..4215fbd40 100644 --- a/core/shader/recompiler/Translation/src/TranslationContext/OperandAccess.cpp +++ b/core/shader/recompiler/Translation/src/TranslationContext/OperandAccess.cpp @@ -151,22 +151,15 @@ IrValue* TranslationContext::readOperand(const RdnaOperand& operand, IrType type return &ir.ConstructU64(pair[0].Value(), pair[1].Value()); } IrU32 bits = applyBitSourceModifiers(operand, readRawU32(operand)); - if (TypesOverlap(type, IrType::F32) && !TypesOverlap(type, IrType::U32)) { - IrF32 value(ir.BitCastF32(bits.Value())); - if (operand.absolute) { - value = IrF32(ir.Emit(IrOpcode::FPAbs32, IrType::F32, {&value.Value()})); - } - if (operand.negate) { - value = IrF32(ir.Emit(IrOpcode::FPNeg32, IrType::F32, {&value.Value()})); - } - return &value.Value(); - } if (operand.absolute) { bits = IrU32(ir.BitwiseAnd(bits.Value(), ir.Constant(0x7fffffffu))); } if (operand.negate) { bits = IrU32(ir.BitwiseXor(bits.Value(), ir.Constant(0x80000000u))); } + if (TypesOverlap(type, IrType::F32) && !TypesOverlap(type, IrType::U32)) { + return &ir.BitCastF32(bits.Value()); + } if (!TypesOverlap(type, IrType::U32)) { throw std::runtime_error("TranslationContext::readOperand requested unsupported operand type"); }