fix(shader): flush v_div_fixup_f16 src1 and src2 by the f16 denormal field #7030

Merged
thuanquang merged 1 commit from upstream-pr/7030 into main 2026-10-17 07:22:22 +00:00
thuanquang commented 2026-10-17 06:23:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by thuanquang on 2026-10-17T06:23:38Z.


What

v_div_fixup_f16 ignored the FLOAT_MODE f16 denormal field. On the GPU, f16 denormal mode 0 or 2 (bit 6 of FLOAT_MODE clear) flushes src1 (the denominator) and src2 (the numerator) to a zero of the same sign before the fixup, and keeps a denormal src0 and result in every mode, the same split v_div_fixup_f32 has with the f32 field. So v_div_fixup_f16 0, 0, 0x0001 (0x0001 / 0) is the default NaN 0xfe00 there, where main writes +infinity 0x7c00; a denormal numerator over a normal denominator gives a signed zero instead of the quotient. src1 and src2 now go through flushF16Input after their modifiers. Modes 1 and 3, and shaders without a known float mode, are translated as before.

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, over the 6859 triples of 19 halves (±0, ±0x0001, ±0x03ff, 0x0200, ±0x0400, ±0.5, ±1, 0x7bff, ±inf, 0x7e00, 0x7d00, 0xfd00), at IEEE 0 and 1:

f16 denormal mode main vs GPU this change vs GPU
0 1940 / 6859 0 / 6859
1 0 / 6859 0 / 6859
2 1940 / 6859 0 / 6859
3 0 / 6859 0 / 6859

With this change every mode also matches with FP16_OVFL=1, with -src0, -src1, |src2|, with op_sel:[1,1,1,0] and with op_sel:[0,1,0,1] into a register holding another value (0 mismatches each, IEEE 0 and 1). A model that flushes src1 and src2 only matches the GPU in all of these modes; flushing src0 as well gives 245 mismatches per flushing mode, so src0 is kept.

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_div_fixup_f16_denormal_modes: the 1000 triples of 10 of those halves (±0, 0x0001, 0x83ff, 0x0200, 0x0400, 1, -inf, 0x7e00, 0x7d00) in f16 denormal modes 0 to 3 at IEEE 0 and 1 and without a known float mode, against the fixup rule above, which matched the GPU on the full 19-value set. On main it fails: v_div_fixup_f16 f16 denormal mode 0, IEEE mode on of 0x00000000, 0x00000000, 0x00000001 is 0x00007c00, expected 0x0000fe00. 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 (#5271) and agc_driver_layered_volume_vertex_no_gpl (#4768). agc_driver_div_fixup_f16, agc_driver_fp16_overflow and agc_driver_division 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:4897900443 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7030). Originally posted by [thuanquang](https://github.com/thuanquang) on 2026-10-17T06:23:38Z. --- ### What `v_div_fixup_f16` ignored the `FLOAT_MODE` f16 denormal field. On the GPU, f16 denormal mode 0 or 2 (bit 6 of `FLOAT_MODE` clear) flushes src1 (the denominator) and src2 (the numerator) to a zero of the same sign before the fixup, and keeps a denormal src0 and result in every mode, the same split `v_div_fixup_f32` has with the f32 field. So `v_div_fixup_f16 0, 0, 0x0001` (0x0001 / 0) is the default NaN 0xfe00 there, where `main` writes +infinity 0x7c00; a denormal numerator over a normal denominator gives a signed zero instead of the quotient. src1 and src2 now go through `flushF16Input` after their modifiers. Modes 1 and 3, and shaders without a known float mode, are translated as before. ### 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, over the 6859 triples of 19 halves (±0, ±0x0001, ±0x03ff, 0x0200, ±0x0400, ±0.5, ±1, 0x7bff, ±inf, 0x7e00, 0x7d00, 0xfd00), at IEEE 0 and 1: | f16 denormal mode | `main` vs GPU | this change vs GPU | |---|---|---| | 0 | 1940 / 6859 | 0 / 6859 | | 1 | 0 / 6859 | 0 / 6859 | | 2 | 1940 / 6859 | 0 / 6859 | | 3 | 0 / 6859 | 0 / 6859 | With this change every mode also matches with `FP16_OVFL`=1, with `-src0, -src1, |src2|`, with `op_sel:[1,1,1,0]` and with `op_sel:[0,1,0,1]` into a register holding another value (0 mismatches each, IEEE 0 and 1). A model that flushes src1 and src2 only matches the GPU in all of these modes; flushing src0 as well gives 245 mismatches per flushing mode, so src0 is kept. ### 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_div_fixup_f16_denormal_modes`: the 1000 triples of 10 of those halves (±0, 0x0001, 0x83ff, 0x0200, 0x0400, 1, -inf, 0x7e00, 0x7d00) in f16 denormal modes 0 to 3 at IEEE 0 and 1 and without a known float mode, against the fixup rule above, which matched the GPU on the full 19-value set. On `main` it fails: `v_div_fixup_f16 f16 denormal mode 0, IEEE mode on of 0x00000000, 0x00000000, 0x00000001 is 0x00007c00, expected 0x0000fe00`. 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` (#5271) and `agc_driver_layered_volume_vertex_no_gpl` (#4768). `agc_driver_div_fixup_f16`, `agc_driver_fp16_overflow` and `agc_driver_division` 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 06:42:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-17T06:42:03Z.


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/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 6612 docs/dev/debt/shader.md
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6230803664 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7030#issuecomment-6230803664). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-17T06:42:03Z. --- <!-- 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 4072](https://www.github.com/boykopovar/AnyPS5/pull/4072) | `core/shader/recompiler/Translation/src/FloatInstructions.cpp` | | [PR 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `core/shader/recompiler/Translation/src/FloatInstructions.cpp`<br>`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 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` | | [PR 6612](https://www.github.com/boykopovar/AnyPS5/pull/6612) | `docs/dev/debt/shader.md` |
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!7030
No description provided.