fix(shader): quiet signaling NaNs only in IEEE mode #1867
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1867"
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-08T22:27:16Z.
What
Part of #981. Several instructions always set the quiet bit on a signaling NaN input. The hardware does that only with
IEEE_MODE=1; with IEEE=0, the mode titles use, the NaN comes out unchanged.v_ldexp_f32had the opposite problem and never quieted. Translation now followsGuestContext::floatMode.ieeeMode(#1816) through two helpers,quietNan32andquietNan16.Measured on RDNA2 (gfx1035) with the HW oracle at IEEE=0 and IEEE=1, with signaling and quiet NaNs of both signs and with payloads in every operand position:
v_sqrt/rcp/rsq/log/exp/sin/cos/fract/floor/ceil/trunc/rndne/rcp_iflag/frexp_mant_f32v_sqrt/rcp/rsq/log/exp/sin/cos/fract/floor/trunc/rndne/frexp_mant_f16v_ldexp_f32/f16,v_div_fixup_f32/f16andv_mullit_f32floatUnary,float16Unary,vFrexpMantF32,vFrexpF16,vLdexpF16,vDivFixupF32/F16andvMullitF32quiet only at IEEE=1, andvLdexpF32now quiets a NaN at IEEE=1. A shader without a known float mode follows IEEE=0.v_add/mul/fma_f32/f16,v_mul_legacy,v_fma_mix,v_cubema) follows the same rule on hardware, but its NaN bits are still left to the driver.v_cvt_f16_f32andv_dot2_f32_f16always quiet, andv_div_scale_f32never does, as the code already does.TechnicalDebt: new line for the rule, the
v_mullit_f32line updated, and the float mode line now says only the binary and ternary arithmetic is left.Tested
Linux (CachyOS, GCC), RADV (gfx1035) and CI's lavapipe (Mesa 25.2.8).
agc_driver_nan_quieting: 16 instructions × 32 rows captured on hardware at IEEE=0 and IEEE=1. 105 of the 512 cells differ between the two modes. The test runs with no mode and IEEE=0 (checked against the IEEE=0 table) and with IEEE=1, bit for bit. Forv_sqrtandv_rcp, only the NaN cells are compared, because their finite results are the driver's approximation (TechnicalDebt).agc_driver_div_fixup_f16,agc_driver_division,agc_driver_sdwa_ldexp_f16andagc_driver_vop1_float_unaryhad tables captured with the oracle's old implicit mode (IEEE=1, denormals kept), so they expected quieted NaNs. They now pin that mode (FLOAT_MODE0xf0, IEEE=1), asInterpolationF16does since #697. The tables are unchanged.v_ldexp_f32not quieting.mainafter #1850.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)Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-08T22:33:32Z.
Rebased on
mainafter #1866 (conflict in the f16 unary NaN line, now keeps both theDX10_CLAMPand the IEEE-mode quieting).agc_driver_nan_quieting,agc_driver_dx10_clampand the four pinned tests pass on RADV and lavapipe.Imported from boykopovar/AnyPS5. Originally posted by SleglJan on 2026-10-08T23:02:10Z.
Cross-check of this PR together with #1866 against the hardware, continuing the audit on #981. The kernels of the 26 execution tests the audit found sensitive to
DX10_CLAMPorIEEE_MODE(28 kernels, 16,944 result cells per mode) ran through the recompiler ofef4dca9a(the recompiler tree ofmainat the merge,42e91486, before #1878) on an RTX 3080 (driver 615.71.09) and on the RADV iGPU (Mesa 26.2.4), Linux (CachyOS, kernel 7.2.9), Release build with CI's flags, withGuestContext::floatModeset to the titles' mode (FLOAT_MODE0xc0,DX10_CLAMP1, IEEE 0), to no mode, toDX10_CLAMP0, to IEEE 1 and to the oracle's former implicit mode (0xf0, IEEE 1), and were compared bit for bit with the oracle in the same mode. Per-cell data, driver and the replay harness with itsREPLAY_MODEsetting: https://github.com/SleglJan/AnyPS5/tree/audit/oracle-2026-10-08/oracle-audit/check-1866-1867.DX10_CLAMP, 31,910 forIEEE_MODE).DX10_CLAMP(#1866). 354 cells in 11 kernels change with the field on the oracle. 58 are in three of the four kernels with a clamped f64 result (DivisionOutputModifiers 14, DivisionResultModifiers 39, F64Transcendental 5); those four (F64Conversions too, with no sensitive cell) throw withDX10_CLAMP=0, as #1866 says. Of the other 296, RADV matches the hardware in 292 and returns the sNaN quieted in 4 (Float16TernaryClamp); NVIDIA matches in 204 and returns an all-ones NaN (0x7fffffff, 0x7fff in f16) in 92. No other difference.IEEE_MODE(this PR). 989 cells in 22 kernels change with the field. The four re-pinned tests match the hardware bit for bit with IEEE 1, and with IEEE 0 in all but Division's 10v_div_fmas_f32cells, where the driver's fma returns the input sNaN quieted (0x7fc00001 for 0x7f800001; ternary arithmetic whose NaN bits the description leaves to the driver): DivFixupF16 21 cells, SdwaLdexpF16 36, Vop1FloatUnary 118, Division 21. With IEEE 1, 9 cells differ, Float16TernaryClamp'sv_min3/max3/med3_f16 clampwith a NaN operand (the f16 min/max rule the TechnicalDebt entry lists as single-mode), and 40 more are NaN-payload differences on RADV (F32OutputModifier 21, Vop3CubeClamp 12, Float16Misc 4, Vop3PackLdexp 3), 53 on NVIDIA. In the titles' mode 39 cells differ: F64Arithmetic 14 (v_min_f64/v_max_f64return the quieted sNaN where the hardware returns the other operand) and F64Rounding 25 (v_cvt_f32_f64 mul:2, the output modifier the hardware applies to the f32 result, as noted on #1851). NaN-payload differences: 94 on RADV, 119 on NVIDIA (F32OutputModifier 21 and Float16Misc 4 more); 71 of the 94 are in the f64 tests (F64Arithmetic 21, F64Division 15, F64NanConversions 13, F64DivisionModifiers 10, F64Transcendental 8, F64Rounding 3, F64Conversions 1), where the tables hold the quieted NaN of IEEE 1 and both hosts produce it in every mode: 43 from the f64 emitter's unconditional quieting (Quietin SpirvAluEmitterFloat64.cpp, behind add, mul, fma, ldexp, min, max and the unary ops), 11 fromv_div_fixup_f64's in Float64Instructions.cpp, 17 in the f32/f64 conversions. Those tables were captured in the same implicit mode as the four this PR pins; as a follow-up, the samefloatModeline would make them declare it.The 28-kernel run predates the #1878 merge; #1878 changes only
v_fma_mix_f32, and MixPrecision rerun after it gives the same bits in every cell. Hardware: Ryzen 7950X3D iGPU (gfx1036, RDNA2) throughtools/hw-oracleunder hsa-rocr 7.2.4; not the PS5's gfx1013.AI-assisted: yes (Claude Code).