feat(shader): follow FP16_OVFL in every f16 result #2025
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2025"
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 snoozedDev on 2026-10-09T05:16:05Z.
What
Part of #981.
FP16_OVFLwas decoded intoGuestContext::floatMode, serialized and part of the cache key (#1816), but nothing read it: every f16 result overflowed to infinity. Translation now followsfloatMode.fp16Overflow.Measured on RDNA2 (gfx1036, a Ryzen 7 7700X iGPU, not the PS5's gfx1013) with the HW oracle, 32 f16 instruction forms (add, sub, mul, fma, fmac, div_fixup, med3, max, pk_mul, pk_add, pk_fma, fma_mixlo, mul with clamp, mul with
mul:2, add through SDWA toWORD_1, fma with clamp, exp, log, rcp, rsq, sqrt, sin, cos, ldexp, cvt_f16_f32, cvt_f16_u16, cvt_f16_i16, cvt_pkrtz_f16_f32, rcp withmul:2, exp with clamp, frexp_mant, floor) over 32 rows each, at IEEE=0 and IEEE=1 with f16 denormals kept, and at IEEE=0 with them flushed,DX10_CLAMP=1, f32 denormals flushed, round to nearest even,FP16_OVFL=0 and =1 (--ieee I --dx10-clamp 1 --denorm32 0 --denorm16 D --round32 0 --round16 0 --fp16-overflow O):FP16_OVFL=1: an f16 result that would round to ±infinity is written as ±0x7bff, in every form above, unless a source operand is infinite, in which case the infinity passes through (inf + 1,inf * 2,fma(65504, 2, -inf),ldexp(inf, 1),exp(inf),cvt_f16_f32(inf)). A zero source is not exempt:v_rcp_f16,v_rsq_f16andv_log_f16of ±0 give ±0x7bff, and so dov_exp_f16of 16 or more andv_rcp_f16of 2^-16, whose f32 intermediate overflows or not. The threshold is the nearest-even one: 65504 + 16 (a tie) overflows, 65504 + 15.99 does not. The sign is kept (-65504 - 16gives 0xfbff).v_div_fixup_f16keeps the infinity it writes for a zero denominator or an infinite numerator and clamps any other infinite quotient, including the one it writes for a NaN quotient.v_cvt_pkrtz_f16_f32never overflows and is unchanged. NaN results, the clamp modifier andDX10_CLAMPare unaffected; withmul:2applied (f16 denormals flushed, IEEE=0) the doubled result is clamped the same way.IEEE_MODEand the f16 denormal mode do not change the rule: the IEEE=1 runs differ from the IEEE=0 ones only in signalling NaN quieting, the flushed runs only in the flushed denormals.Changes:
clampF16Overflowapplies the rule to an f32 value before it is converted to f16, given the source values whose infinity exempts the result.writeF16takes those sources, so the scalar binary, ternary, mix, SDWA, convert andv_interp_p2_f16paths get it, as do the packed lanes, the unary instructions,v_ldexp_f16andv_div_fixup_f16on its bits.FP16_OVFL=0, keep the previous lowering.HW_ORACLE.md: thefp16_overflowrow said division by zero still produces infinity; the measurement above saysv_rcp_f16of zero is clamped and onlyv_div_fixup_f16keeps it. TechnicalDebt: the float mode entry listsFP16_OVFLas read, and a new entry records the rule and what it leaves open (v_fma_mix*_f16with f32 sources andv_interp_p2_f16with infinite inputs follow the rule unmeasured; round modes other than nearest even are not modelled).Raw data (bodies, rows and the results in all six modes): https://gist.github.com/snoozedDev/9174fac268859aba2e9ff790b5dabe6b
Tested
Arch Linux (kernel 7.2.5), GCC 16.2.1, Release, RTX 3090 (NVIDIA 610.57.04) and the RADV iGPU (gfx1036, Mesa 26.2.2),
mainf1451396.agc_driver_fp16_overflow: 16 instructions (add, sub, mul, fma, div_fixup, pk_mul, pk_add, fma_mixlo, add through SDWA, exp, log, rcp, rsq, ldexp, cvt_f16_f32, cvt_f16_u16) × 32 rows captured on gfx1036 withFP16_OVFL=0 and =1, IEEE=0,FLOAT_MODE0xc0,DX10_CLAMP=1; 109 of the 512 cells differ between the two settings. The test runs with no mode and withFP16_OVFL=0 (checked against the first table) and withFP16_OVFL=1 (the second). Where the NaN bits come from a driver op any NaN is accepted; where translation chooses them (v_div_fixup_f16, packed,v_ldexp_f16) they are compared bit for bit. Passes on both GPUs; withmain's translation it fails on both atlane 0 FP16_OVFL=1 v_add_f16 is 0x00007c00, expected 0x00007bff.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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by popcoder565 on 2026-10-09T19:43:20Z.
Native Windows run, since no Windows results were posted. Setup: Windows 10 (19045), RTX 3060 Laptop (NVIDIA 616.92), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. Head
0d1e1e08, merged ontomain8b393b6ein one build with 31 other PRs that had no Windows run.agc_driver_fp16_overflow.guest_offline_imports, broken by #2359 (reported there).No title was run.
🤖 Addressed by Claude Code
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T07:06:41Z.
Rebased onto current
main: #3a9da568fchangedfloat16Ternary(v_fma_mixlo/mixhi_f16now go throughFPInterpolateF16), so the conflict kept that lowering and passes the source operands towriteF16there too, so the FP16_OVFL exemption for infinite sources applies. No other change.Rechecked on the rebased tree:
agc_driver_fp16_overflowpasses on RADV (it coversv_fma_mixlo_f16) and fails without the translation change; the f16 fma, div_fixup and mix_precision tests pass. Thanks @popcoder565 for the Windows run on the previous head. Merging once the full Linux/Windows build is green on the rebased head.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T07:44:25Z.
Rechecked on the current head (
0bea402a1, rebased ontomaine8b47b927):agc_driver_fp16_overflowpasses on RADV and fails without the translation change; the 326 tests of libSceAgc/libSceAgcDriver pass. The f16 semantics are unchanged from what was measured (including thev_fma_mix*path throughFPInterpolateF16). Thanks @popcoder565 for the Windows run. Merging once the full Linux/Windows build is green.