Skip to content

fix(shader): flush v_fma_f16 family denormals by the f16 denormal field - #7034

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
thuanquang:fix/f16-fma-denormal-flush
Oct 17, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
thuanquang:fix/f16-fma-denormal-flush

Conversation

@thuanquang

Copy link
Copy Markdown
Contributor

What

v_fma_f16, v_fmac_f16, v_fmamk_f16 and v_fmaak_f16 ignored the FLOAT_MODE f16 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:

  • with bit 6 of FLOAT_MODE clear (f16 denormal modes 0 and 2) every denormal input is flushed to a zero of its sign, so v_fma_f16 0, 0, 0x8001 is 0x0000 where main writes 0x8001;
  • with bit 7 clear (modes 0 and 1) the result is flushed to a zero of its sign when the exact product-sum, rounded to 11 significant bits with an unbounded exponent, is below 2^-14, the rule v_mul_f16 already follows. So v_fma_f16 0, 0, 0x0001 is 0x0000 where main writes 0x0001, while 0x0400 * 0x0400 + 0x8400 (exactly -2^-14 + 2^-28) rounds to 0x8400 and is kept. Detecting tininess before rounding instead flushes it to 0x8000 and disagrees with the GPU on 10 (mode 0) and 103 (mode 1) of the 4580 rows without NaN operands.

float16Ternary now flushes the inputs of the f16 FMA path with flushF16InputValue and its round-to-odd f32 result against 2^-14 - 2^-26 (0x387ff000) in the modes that flush them, gated like float16Binary on f16 round to nearest even. The magnitude test moves from a lambda in float16Binary to flushTinyF16Value, which both paths and flushF16InputValue use. Comparing the round-to-odd value is the same as comparing the exact one, since 0x387ff000 has 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-oracle template, 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:

f16 denormal mode main vs GPU (v_fma_f16 and v_fmac_f16 each) this change vs GPU
0 2167 / 5075 0 / 5075
1 1461 / 5075 0 / 5075
2 2049 / 5075 0 / 5075
3 0 / 5075 0 / 5075

With this change every mode also matches, at IEEE 0 and 1 and FP16_OVFL 0 and 1, over the first 4075 triples for v_fmamk_f16 with literals 0x8400 and 0x3bff, v_fmaak_f16 with 0x8400, 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 VOP3 v_fmac_f16_e64 (0 mismatches each). VOP3 v_fmac_f16_e64 with a source modifier or clamp throws "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:

  • New agc_driver_f16_fma_denormal_modes: v_fma_f16 and VOP2 v_fmac_f16 over 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. On main it fails: v_fma_f16 f16 denormal mode 0, IEEE mode on of 0x3bff, 0x0400, 0x0000 is 0x0400, expected 0x0000. With this change it passes.
  • Full ctest --parallel 4 --timeout 120 on main 6a32550fd with this change: 1368 tests, 2 fail, both failing on main on this GPU too: agc_driver_lds_mixed_width_atomics (agc_* tests: 3 of 483 fail on AMD Radeon RX 6400, pass on NVIDIA RTX 4080 SUPER #5271) and agc_driver_layered_volume_vertex_no_gpl (AMD Windows: GPL-mode cache failures (alpha/wave32 pass after local driver update) #4768). agc_driver_float16_fma_rounding, agc_driver_f16_denormal_flush and the other f16 tests pass.
  • python tools/check_conventions.py --base origin/main with this title and body passes.
  • Not tested: the PS5's gfx1013, directed f16 rounding, other AMD drivers, NVIDIA, Intel, and titles.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none
  • GPUs tested: AMD Radeon RX 6700 XT (gfx1031), driver 32.0.21045.5002, Windows 11 26200
  • AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

v_fma_f16, v_fmac_f16, v_fmamk_f16 and v_fmaak_f16 ignored the
FLOAT_MODE f16 denormal field. On RDNA2 (gfx1031) at f16 round to
nearest even, bit 6 clear flushes every denormal input to a zero of its
sign, and bit 7 clear flushes the result when the exact product-sum
rounded to 11 significant bits with an unbounded exponent is below
2^-14, the rule v_mul_f16 already follows. The f16 FMA path now flushes
its inputs and its round-to-odd result in those modes; the magnitude
test is shared with float16Binary as flushTinyF16Value.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added shader core/shader docs agc libSceAgc* labels Oct 17, 2026
@github-actions

github-actions Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

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.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 5782 docs/dev/debt/shader.md L95-96

Some 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.

Pull request Shared files not compared
PR 4072 core/shader/recompiler/Translation/include/Translation/TranslationContext.hpp
core/shader/recompiler/Translation/src/FloatInstructions.cpp
PR 5021 core/shader/recompiler/Translation/src/FloatInstructions.cpp
docs/dev/debt/shader.md
PR 5371 docs/dev/debt/shader.md
PR 5426 docs/dev/debt/shader.md
PR 5500 docs/dev/debt/shader.md
PR 6222 docs/dev/debt/shader.md
PR 6235 docs/dev/debt/shader.md
PR 6412 docs/dev/debt/shader.md
PR 6503 core/shader/recompiler/Translation/include/Translation/TranslationContext.hpp

@oneandonlydean
oneandonlydean merged commit a60ac1f into boykopovar:main Oct 17, 2026
9 checks passed
@LeandroLP23

Copy link
Copy Markdown
Contributor

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: main 17cfb1f4c with #7018, #7034, #7036, #7038, #7040, #7041 and #7042 merged together (only docs/dev/debt/shader.md conflicted, for #7040); "main" is the same tree with the six recompiler files reverted to main and the tests kept.

  • agc_driver_f16_fma_denormal_modes: fails on main, passes 3 of 3 with this change.

AI-assisted: yes (Claude Code).

@Amoenus

Amoenus commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

Confirmed a cross-vendor test failure on unchanged main adb0e7a8cb, without our integration patches:

  • Windows 11 Enterprise 26200, WinLibs GCC15.2r7, Release; ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1.
  • Actual RTX5080 (10de:2c02), driver32.0.16.1062: agc_driver_f16_fma_denormal_modes fails 3/3 fresh processes, each under0.4s, at the same first assertion:
AGC graphics: v_fma_f16 without a known float mode of 0x7c00, 0x0000, 0x0000 is 0x7fff, expected 0xfe00
  • Actual Radeon(TM) Graphics (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_tests on the clean detached main, then ran ctest -V --no-tests=error --timeout 30 -R '^agc_driver_f16_fma_denormal_modes$' with ANYPS5_GPU set 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.

@screamm

screamm commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

Second NVIDIA data point, with the bit pattern explained: RTX 4070 (driver 596.21, Windows 11 Pro 26220, WinLibs GCC 15.2) on plain main ca82d7d fails 3 of 3 with the same message, and so does agc_driver_fma_mix_f16_denormal_modes from #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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* docs shader core/shader

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants