fix(shader): flush v_fma_f16 family denormals by the f16 denormal field #7034
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7034"
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 thuanquang on 2026-10-17T06:44:13Z.
What
v_fma_f16,v_fmac_f16,v_fmamk_f16andv_fmaak_f16ignored theFLOAT_MODEf16 denormal field; the technical debt entry for the scalar f16 ops listed "ternary arithmetic" as keeping the previous lowering. On the GPU, at f16 round to nearest even:FLOAT_MODEclear (f16 denormal modes 0 and 2) every denormal input is flushed to a zero of its sign, sov_fma_f16 0, 0, 0x8001is0x0000wheremainwrites0x8001;v_mul_f16already follows. Sov_fma_f16 0, 0, 0x0001is0x0000wheremainwrites0x0001, while0x0400 * 0x0400 + 0x8400(exactly -2^-14 + 2^-28) rounds to0x8400and is kept. Detecting tininess before rounding instead flushes it to0x8000and disagrees with the GPU on 10 (mode 0) and 103 (mode 1) of the 4580 rows without NaN operands.float16Ternarynow flushes the inputs of the f16 FMA path withflushF16InputValueand its round-to-odd f32 result against 2^-14 - 2^-26 (0x387ff000) in the modes that flush them, gated likefloat16Binaryon f16 round to nearest even. The magnitude test moves from a lambda infloat16BinarytoflushTinyF16Value, which both paths andflushF16InputValueuse. Comparing the round-to-odd value is the same as comparing the exact one, since0x387ff000has an even significand.v_fma_mixlo/mixhi_f16, directed rounding and shaders without a known float mode are translated as before.Measured
The same instructions were run directly on the GPU with the
tools/hw-oracletemplate, launched through the driver's HIP runtime, and through the recompiler on Vulkan, at IEEE 0 and 1, over 5075 operand triples: the 4000 from 20 halves around the denormal range (±0, ±0x0001, ±0x03ff, 0x0200, ±0x0400, 0x0401, ±0.5, ±1, 0x7bff, inf, 0x3bff, 0x3c01, 0x1fff, 0x2001), 75 whose product-sum lies just below 2^-14, and 1000 random ones:mainvs GPU (v_fma_f16andv_fmac_f16each)With this change every mode also matches, at IEEE 0 and 1 and
FP16_OVFL0 and 1, over the first 4075 triples forv_fmamk_f16with literals0x8400and0x3bff,v_fmaak_f16with0x8400,v_fma_f16 -v4, |v5|, -v6,op_sel:[1,1,1,0]high-half sources,op_sel:[0,0,0,1]into a register holding another value,clamp, and VOP3v_fmac_f16_e64(0 mismatches each). VOP3v_fmac_f16_e64with a source modifier orclampthrows "VOP3 source modifiers are not implemented" in the recompiler; this PR does not touch that path.Tested
Windows 11 26200, AMD Radeon RX 6700 XT (gfx1031), driver 32.0.21045.5002, WinLibs GCC 15.2.0 r7, Release,
BUILD_TESTING=ON,ANYPS5_REQUIRE_VULKAN=1:agc_driver_f16_fma_denormal_modes:v_fma_f16and VOP2v_fmac_f16over 64 of those triples (inputs and results at the denormal boundary, the triples just below 2^-14, infinities and invalid products), in f16 denormal modes 0 to 3 at IEEE 0 and 1 and without a known float mode, against the GPU's results for each mode. Onmainit fails:v_fma_f16 f16 denormal mode 0, IEEE mode on of 0x3bff, 0x0400, 0x0000 is 0x0400, expected 0x0000. With this change it passes.ctest --parallel 4 --timeout 120onmain6a32550fdwith this change: 1368 tests, 2 fail, both failing onmainon this GPU too:agc_driver_lds_mixed_width_atomics(#5271) andagc_driver_layered_volume_vertex_no_gpl(#4768).agc_driver_float16_fma_rounding,agc_driver_f16_denormal_flushand the other f16 tests pass.python tools/check_conventions.py --base origin/mainwith this title and body passes.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-17T06:56:47Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)docs/dev/debt/shader.mdL95-96Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
core/shader/recompiler/Translation/include/Translation/TranslationContext.hppcore/shader/recompiler/Translation/src/FloatInstructions.cppcore/shader/recompiler/Translation/src/FloatInstructions.cppdocs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.mdcore/shader/recompiler/Translation/include/Translation/TranslationContext.hppImported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-17T08:08:59Z.
Another AMD driver, since the description lists other AMD drivers as untested.
Windows 11 (26300), Radeon 860M (RDNA 3.5,
1002:1114), driver 32.0.13058.8001, WinLibs GCC 15.2.0, Release,ANYPS5_REQUIRE_VULKAN=1. Tree:main17cfb1f4cwith #7018, #7034, #7036, #7038, #7040, #7041 and #7042 merged together (onlydocs/dev/debt/shader.mdconflicted, for #7040); "main" is the same tree with the six recompiler files reverted tomainand the tests kept.agc_driver_f16_fma_denormal_modes: fails onmain, passes 3 of 3 with this change.AI-assisted: yes (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by Amoenus on 2026-10-17T08:31:59Z.
Confirmed a cross-vendor test failure on unchanged main
adb0e7a8cb, without our integration patches:ANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1.10de:2c02), driver32.0.16.1062:agc_driver_f16_fma_denormal_modesfails 3/3 fresh processes, each under0.4s, at the same first assertion:1002:13c0), driver32.0.21036.18, same build: 3/3 pass, each under0.5s. Device identity is checked in each process log.Built
agc_driver_f16_fma_denormal_modes_testson the clean detached main, then ranctest -V --no-tests=error --timeout 30 -R '^agc_driver_f16_fma_denormal_modes$'withANYPS5_GPUset to each adapter. Both observed bit patterns are NaNs, but this alone does not settle the required payload/sign semantics or justify weakening the assertion. This reports the test's cross-vendor failure; it does not establish a denormal-semantics regression or a cause of our title's separate DCC/Vulkan stops. No source changes or proposed NaN fix in this report. AI-assisted: yes (Codex); author responsible.Imported from boykopovar/AnyPS5. Originally posted by screamm on 2026-10-17T11:42:17Z.
Second NVIDIA data point, with the bit pattern explained: RTX 4070 (driver 596.21, Windows 11 Pro 26220, WinLibs GCC 15.2) on plain
mainca82d7d88fails 3 of 3 with the same message, and so doesagc_driver_fma_mix_f16_denormal_modesfrom #7040 (is 0x7fffffff, expected 0xffc00000). Both are inf * 0 cases: the table holds the AMD default NaN (sign set), NVIDIA returns its canonical NaN (sign clear). Details in #7100.Written with Claude Code assistance (validation by a subagent, reviewed in this session).