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.
This commit is contained in:
Krzysztof Hasiński
2026-10-06 00:04:14 +02:00
parent bc24783e5b
commit 09e41584ca
@@ -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");
}