Skip to content

fix(shader): flush v_fma_mix_f32 f16 sources by the f16 denormal field - #7040

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

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

Conversation

@thuanquang

Copy link
Copy Markdown
Contributor

What

v_fma_mix_f32 used its f16 sources (op_sel_hi set) unflushed in every mode; the technical debt entry on f32 denormals says "f16 inputs retain their previous conversion and denormal handling". On the GPU, f16 denormal mode 0 or 2 (bit 6 of FLOAT_MODE clear) flushes each f16 source to a zero of its sign before the fused multiply-add, whatever the f32 denormal field. So v_fma_mix_f32 0, 0, 0x0001 with all three sources f16 gives 0x00000000 there; main gives 0x33800000 (2^-24).

readMixF32 now passes an f16 source through flushF16InputValue, as v_cvt_f32_f16 already does. f32 sources, modes that keep f16 denormals, and shaders without a known float mode are translated as before. v_fma_mixlo/mixhi_f16 share readMixF32 but still throw in the modes that flush f16 denormals, so they are unchanged.

Measured

The same instruction was 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, with f32 denormal modes 0 and 3 and f16 denormal modes 0 to 3:

form rows main vs GPU, f16 modes 0 and 2 this change vs GPU, every mode
three f16 sources (op_sel_hi:[1,1,1]), 14 halves 2744 1121 0
high halves (op_sel:[1,1,1]) 2744 0
-src0, |src1|, -src2, three f16 sources 2744 0
f16 * f32 + f16 (op_sel_hi:[1,0,1]), f32 denormals flushed 1960 660 0
f16 * f32 + f16, f32 denormals kept 1960 706 99 (modes 0 and 2), 61 (modes 1 and 3)

The rows left in the last line are not about the f16 field: on main the same form already gives 61 mismatches with f16 denormals kept, and every remaining row (plus 2 that differ only in NaN payload) has an f32 denormal source or an f32 denormal GPU result while f32 denormals are kept (the GPU keeps a result like -2^-140 and f16 inf * f32 0x807fffff = -inf, where the translation gives 0 and NaN). Flushing a denormal f16 addend makes more of those f32 results denormal, which is where the extra 38 rows come from.

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_fma_mix_f16_denormal_modes: three f16 sources, and f16 * f32 + f16, over 16 rows (denormal f16 sources, products and sums at the f16 and f32 denormal boundaries, inf * denormal, signed zeros) in f32 denormal modes 0 and 3 with f16 denormal modes 0 to 3 at IEEE 0 and 1, against the GPU's results; none of the expected values is an f32 denormal. On main it fails: v_fma_mix_f32 of three f16 sources f32 denormals flushed, f16 denormal mode 0, IEEE mode off of 0x00010000, 0x00000000, 0x3f800000 is 0x33800000, expected 0x00000000. With this change it passes.
  • Full ctest --parallel 4 --timeout 120 on main f8b22edfb 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). The f16, fma and interpolation tests pass.
  • python tools/check_conventions.py --base origin/main with this title and body passes.
  • Not tested: the PS5's gfx1013, 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_mix_f32 used its f16 sources unflushed in every mode. On RDNA2
(gfx1031) f16 denormal modes 0 and 2 flush each f16 source to a zero
of its sign, whatever the f32 denormal field, so
v_fma_mix_f32 0, 0, 0x0001 (all f16) is 0 there instead of 2^-24.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

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 5021 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 5782 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

@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_fma_mix_f16_denormal_modes: fails on main, passes 3 of 3 with this change.

AI-assisted: yes (Claude Code).

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.

3 participants