feat(shader): translate packed f16 in the f16 denormal modes that flush #7038

Merged
thuanquang merged 1 commit from upstream-pr/7038 into main 2026-10-17 08:56:30 +00:00
thuanquang commented 2026-10-17 07:03:40 +00:00 (Migrated from github.com)

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


What

v_pk_add_f16, v_pk_mul_f16, v_pk_fma_f16, v_pk_fmac_f16, v_pk_min_f16 and v_pk_max_f16 threw "not implemented" in every f16 denormal mode but 3, so a shader using them with FLOAT_MODE f16 denormals flushed could not be translated. On the GPU, at f16 round to nearest even, per lane:

  • with bit 6 clear (modes 0 and 2) each denormal input is flushed to a zero of its sign, before the existing NaN rules, so inf * 0x0001 is an invalid product there;
  • with bit 7 clear (modes 0 and 1) a v_pk_add_f16 result below 2^-14, and a v_pk_mul_f16, v_pk_fma_f16 or v_pk_fmac_f16 result whose exact value rounded to 11 significant bits with an unbounded exponent is below 2^-14, is flushed to a zero of its sign, the rules the scalar v_add_f16 and v_mul_f16 follow;
  • v_pk_min_f16 and v_pk_max_f16 flush only their inputs; flushing their result as well disagrees with the GPU on 3218 to 3622 lanes in mode 1.

packedFloat16 now flushes the float and bit views of every source lane with the existing flushF16Input/flushF16InputValue, flushes tiny add/mul/fma results in the modes that flush them, and does not use the native f16x2 add and multiply while results are flushed (with results flushed, 0x3bff * 0x0400 must give 0 where an IEEE f16 multiply rounds to 0x0400). It still throws for f16 rounding other than nearest even. Modes that keep f16 denormals, and shaders without a known float mode, are translated as before. #4072 changes how v_pk_fma_f16 is computed in the same function; whichever lands second needs a small rebase.

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 and f16 denormal modes 0 to 3, with op_sel, op_sel_hi, neg_lo, neg_hi and clamp variants, v_pk_fmac_f16 with either accumulator half, all pairs or triples of 26 special halves, products and sums at the 2^-14 boundary and random lanes. With this change every lane matches the GPU:

instruction lanes per mode this change vs GPU, every mode tininess before rounding vs GPU, modes 0 / 1
v_pk_add_f16 33,586 0 0 / 0
v_pk_mul_f16 38,384 0 1872 / 2204
v_pk_fma_f16 162,204 0 2712 / 3285
v_pk_fmac_f16 46,344 0 856 / 912
v_pk_min_f16 19,192 0 n/a
v_pk_max_f16 19,192 0 n/a

On main the recompiler throws for every one of these shaders in modes 0 to 2.

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_packed_f16_denormal_modes: v_pk_add_f16, v_pk_mul_f16 and v_pk_fma_f16 over 32 lanes (denormal inputs, denormal and boundary results, signed zeros, inf * 0x0001) in f16 denormal modes 0 to 3 at IEEE 0 and 1, against the GPU's results for each mode. On main it fails: ShaderRecompiler::Recompile: packed f16 at pc 20 in FLOAT_MODE 48 (f16 denormals not kept or rounding not to nearest even) is not implemented. With this change it passes.
  • agc_driver_float16_min_max_bits now also runs its packed min/max checks in its two flushing modes (0x30 and 0xb0), with the same flushed-input model as its scalar checks, and passes. agc_driver_packed_alu checked that flushed f16 denormals are refused; it now checks the refusal of directed f16 rounding (0xf4) and 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). agc_driver_packed_float16_native, agc_driver_f16_min_max_nan 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, FP16_OVFL=1 and DX10_CLAMP=0 in the flushing modes, 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:4898121104 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7038). Originally posted by [thuanquang](https://github.com/thuanquang) on 2026-10-17T07:03:40Z. --- ### What `v_pk_add_f16`, `v_pk_mul_f16`, `v_pk_fma_f16`, `v_pk_fmac_f16`, `v_pk_min_f16` and `v_pk_max_f16` threw "not implemented" in every f16 denormal mode but 3, so a shader using them with `FLOAT_MODE` f16 denormals flushed could not be translated. On the GPU, at f16 round to nearest even, per lane: - with bit 6 clear (modes 0 and 2) each denormal input is flushed to a zero of its sign, before the existing NaN rules, so `inf * 0x0001` is an invalid product there; - with bit 7 clear (modes 0 and 1) a `v_pk_add_f16` result below 2^-14, and a `v_pk_mul_f16`, `v_pk_fma_f16` or `v_pk_fmac_f16` result whose exact value rounded to 11 significant bits with an unbounded exponent is below 2^-14, is flushed to a zero of its sign, the rules the scalar `v_add_f16` and `v_mul_f16` follow; - `v_pk_min_f16` and `v_pk_max_f16` flush only their inputs; flushing their result as well disagrees with the GPU on 3218 to 3622 lanes in mode 1. `packedFloat16` now flushes the float and bit views of every source lane with the existing `flushF16Input`/`flushF16InputValue`, flushes tiny add/mul/fma results in the modes that flush them, and does not use the native f16x2 add and multiply while results are flushed (with results flushed, `0x3bff * 0x0400` must give 0 where an IEEE f16 multiply rounds to `0x0400`). It still throws for f16 rounding other than nearest even. Modes that keep f16 denormals, and shaders without a known float mode, are translated as before. #4072 changes how `v_pk_fma_f16` is computed in the same function; whichever lands second needs a small rebase. ### 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 and f16 denormal modes 0 to 3, with `op_sel`, `op_sel_hi`, `neg_lo`, `neg_hi` and `clamp` variants, `v_pk_fmac_f16` with either accumulator half, all pairs or triples of 26 special halves, products and sums at the 2^-14 boundary and random lanes. With this change every lane matches the GPU: | instruction | lanes per mode | this change vs GPU, every mode | tininess before rounding vs GPU, modes 0 / 1 | |---|---|---|---| | `v_pk_add_f16` | 33,586 | 0 | 0 / 0 | | `v_pk_mul_f16` | 38,384 | 0 | 1872 / 2204 | | `v_pk_fma_f16` | 162,204 | 0 | 2712 / 3285 | | `v_pk_fmac_f16` | 46,344 | 0 | 856 / 912 | | `v_pk_min_f16` | 19,192 | 0 | n/a | | `v_pk_max_f16` | 19,192 | 0 | n/a | On `main` the recompiler throws for every one of these shaders in modes 0 to 2. ### 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_packed_f16_denormal_modes`: `v_pk_add_f16`, `v_pk_mul_f16` and `v_pk_fma_f16` over 32 lanes (denormal inputs, denormal and boundary results, signed zeros, `inf * 0x0001`) in f16 denormal modes 0 to 3 at IEEE 0 and 1, against the GPU's results for each mode. On `main` it fails: `ShaderRecompiler::Recompile: packed f16 at pc 20 in FLOAT_MODE 48 (f16 denormals not kept or rounding not to nearest even) is not implemented`. With this change it passes. - `agc_driver_float16_min_max_bits` now also runs its packed min/max checks in its two flushing modes (0x30 and 0xb0), with the same flushed-input model as its scalar checks, and passes. `agc_driver_packed_alu` checked that flushed f16 denormals are refused; it now checks the refusal of directed f16 rounding (0xf4) and 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). `agc_driver_packed_float16_native`, `agc_driver_f16_min_max_nan` 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, `FP16_OVFL`=1 and `DX10_CLAMP`=0 in the flushing modes, 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:30 +00:00 (Migrated from github.com)

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


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 6009 docs/dev/debt/shader.md L94-95
PR 6767 docs/dev/debt/shader.md L95

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 5782 core/shader/recompiler/Translation/src/FloatInstructions.cpp
docs/dev/debt/shader.md
PR 5941 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:6231230997 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7038#issuecomment-6231230997). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-17T07:30:30Z. --- <!-- pr-overlap --> 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 6009](https://www.github.com/boykopovar/AnyPS5/pull/6009) | `docs/dev/debt/shader.md` [L94-95](https://github.com/boykopovar/AnyPS5/blob/adb0e7a8cb68232f457c788afa90e53648c0f15f/docs/dev/debt/shader.md#L94-L95) | | | | [PR 6767](https://www.github.com/boykopovar/AnyPS5/pull/6767) | `docs/dev/debt/shader.md` [L95](https://github.com/boykopovar/AnyPS5/blob/adb0e7a8cb68232f457c788afa90e53648c0f15f/docs/dev/debt/shader.md#L95) | | | 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 5782](https://www.github.com/boykopovar/AnyPS5/pull/5782) | `core/shader/recompiler/Translation/src/FloatInstructions.cpp`<br>`docs/dev/debt/shader.md` | | [PR 5941](https://www.github.com/boykopovar/AnyPS5/pull/5941) | `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:01 +00:00 (Migrated from github.com)

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


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_packed_f16_denormal_modes, and the updated agc_driver_float16_min_max_bits and agc_driver_packed_alu: all three fail on main, and pass 3 of 3 with this change.

AI-assisted: yes (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6231564901 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7038#issuecomment-6231564901). Originally posted by [LeandroLP23](https://github.com/LeandroLP23) on 2026-10-17T08:09:01Z. --- 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_packed_f16_denormal_modes`, and the updated `agc_driver_float16_min_max_bits` and `agc_driver_packed_alu`: all three fail on `main`, and pass 3 of 3 with this change. AI-assisted: yes (Claude Code).
oneandonlydean commented 2026-10-17 08:24:09 +00:00 (Migrated from github.com)

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


@thuanquang #7040 merged, so this conflicted in docs/dev/debt/shader.md (adjacent lines). I rebased it onto main (maintainer edit): new head e5cc0bc0f keeps your 'Packed f16 NaN results' and v_fma_mix lines plus #7040's 'f32 denormals' line. The code is byte-identical to ab41718e3 (same patch-id). Full CI is running on the new head; it merges once that's green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6231704588 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7038#issuecomment-6231704588). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-17T08:24:09Z. --- @thuanquang #7040 merged, so this conflicted in docs/dev/debt/shader.md (adjacent lines). I rebased it onto main (maintainer edit): new head e5cc0bc0f keeps your 'Packed f16 NaN results' and v_fma_mix lines plus #7040's 'f32 denormals' line. The code is byte-identical to ab41718e3 (same patch-id). Full CI is running on the new head; it merges once that's green.
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!7038
No description provided.