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

Merged
thuanquang merged 1 commit from upstream-pr/7040 into main 2026-10-17 08:21:53 +00:00
thuanquang commented 2026-10-17 07:09:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by thuanquang on 2026-10-17T07:09:29Z.


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 (#5271) and agc_driver_layered_volume_vertex_no_gpl (#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

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4898153059 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7040). Originally posted by [thuanquang](https://github.com/thuanquang) on 2026-10-17T07:09:29Z. --- ### 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` (#5271) and `agc_driver_layered_volume_vertex_no_gpl` (#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 - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: none - [x] GPUs tested: AMD Radeon RX 6700 XT (gfx1031), driver 32.0.21045.5002, Windows 11 26200 - [x] AI-assisted: yes (Claude Code) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-17 07:30:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-17T07:30:32Z.


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
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6231231319 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7040#issuecomment-6231231319). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-17T07:30:32Z. --- <!-- pr-overlap --> 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](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `docs/dev/debt/shader.md` | | [PR 5371](https://www.github.com/boykopovar/AnyPS5/pull/5371) | `docs/dev/debt/shader.md` | | [PR 5426](https://www.github.com/boykopovar/AnyPS5/pull/5426) | `docs/dev/debt/shader.md` | | [PR 5500](https://www.github.com/boykopovar/AnyPS5/pull/5500) | `docs/dev/debt/shader.md` | | [PR 5782](https://www.github.com/boykopovar/AnyPS5/pull/5782) | `docs/dev/debt/shader.md` | | [PR 6222](https://www.github.com/boykopovar/AnyPS5/pull/6222) | `docs/dev/debt/shader.md` | | [PR 6235](https://www.github.com/boykopovar/AnyPS5/pull/6235) | `docs/dev/debt/shader.md` | | [PR 6412](https://www.github.com/boykopovar/AnyPS5/pull/6412) | `docs/dev/debt/shader.md` |
LeandroLP23 commented 2026-10-17 08:09:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-17T08:09:02Z.


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

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6231565095 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7040#issuecomment-6231565095). Originally posted by [LeandroLP23](https://github.com/LeandroLP23) on 2026-10-17T08:09:02Z. --- 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 in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!7040
No description provided.