feat(shader): choose f32 arithmetic NaN results on the bits #2083
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2083"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-09T07:15:08Z.
What
Part of #981. The NaN result of f32 add, sub, mul and fma was whatever NaN the driver produced. Vulkan doesn't specify its payload or sign, and NVIDIA returns a canonical NaN. The NaN is now chosen on the bits, following the hardware and
IEEE_MODE(#1816, #1867).Measured on RDNA2 (gfx1035) with the HW oracle, over 1000 operand triples (quiet and signaling NaNs of both signs and payloads, ±inf, ±0, ±1) at IEEE=0 and IEEE=1. The ops were
v_add/sub/subrev/mul/fma/fmac/fmamk/fmaak/mul_legacy/fma_legacy_f32,v_fma_mix_f32,v_add_f32 -v4, |v5|andv_mul_f32 mul:2. The rule below matches every cell (0 mismatches):v_sub_f32andv_subrev_f32add the negation of the subtrahend, so a NaN in that position comes out with its sign flipped (src0 + -src1,-src0 + src1).0xffc00000.The sign flip is applied as an integer XOR.
OpFNegateisn't relied on for a NaN's payload.The f16 arithmetic,
v_fma_mix_f32with f16 sources,v_cubema,v_mac_legacy_f32and the separately rounded mad/mac forms (gfx1035 doesn't have them) still leave the NaN to the driver. TechnicalDebt says so.Tested
Linux (CachyOS, GCC), RADV (gfx1035) and CI's lavapipe (Mesa 25.2.8).
agc_driver_f32_arithmetic_nan: 16 instructions (including modifiers, omod and clamp) × 32 rows captured on hardware at IEEE=0 and IEEE=1. 624 of the 1024 cells are NaN, and every cell is compared bit for bit, because the translation now chooses the NaN bits. The non-NaN rows use exact values (±0, ±1, ±inf), so the result doesn't depend on whether the driver fusesFma.agc_driver_f32_denormal_flush,agc_driver_nan_quieting,agc_driver_f32_output_modifier,agc_driver_divisionandvector_fused_multiply_addpass unchanged. Full Release ctest: 494/494.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)