fix(shader): flush v_cvt_pkrtz_f16_f32 and v_pack_b32_f16 f16 denormals #7031

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

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


What

v_cvt_pkrtz_f16_f32 and v_pack_b32_f16 ignored the FLOAT_MODE f16 denormal field. On the GPU:

  • v_cvt_pkrtz_f16_f32 flushes each half result that is denormal after the conversion to its signed zero when bit 7 of FLOAT_MODE is clear (f16 denormal modes 0 and 1). v_cvt_pkrtz_f16_f32 0, 0x33800000 (2^-24) gives 0x00000000 there; main writes 0x00010000.
  • v_pack_b32_f16 flushes each denormal half input to its signed zero when bit 6 is clear (modes 0 and 2). v_pack_b32_f16 0x8000, 0x0001 gives 0x00008000 there; main writes 0x00018000.

vCvtPkrtzF16F32 now passes both result halves through flushF16Result in the modes that flush them, and vPackB32F16 passes each half through flushF16Input after its modifiers. Modes that keep them, 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, over the 256 pairs of 16 f32 values around the f16 denormal range (±0, ±2^-24, 1.5 * 2^-24, 2^-25, ±0x387fc000, 0x387fffff, ±2^-14, 0x37730edf, 1, 65520, ±inf) for v_cvt_pkrtz_f16_f32 and the 256 pairs of 16 halves (±0, ±0x0001, ±0x03ff, 0x0200, ±0x0400, ±1, 0x7bff, ±inf, 0x7e00, 0x7d00) for v_pack_b32_f16, at IEEE 0 and 1:

f16 denormal mode v_cvt_pkrtz_f16_f32, main vs GPU v_pack_b32_f16, main vs GPU this change vs GPU
0 175 / 256 135 / 256 0 / 256 each
1 175 / 256 0 / 256 0 / 256 each
2 0 / 256 135 / 256 0 / 256 each
3 0 / 256 0 / 256 0 / 256 each

With this change every mode also matches for v_cvt_pkrtz_f16_f32_e64 v10, -v4, |v5|, v_pack_b32_f16 v10, -v4, |v5| and v_pack_b32_f16 v10, v4, v5 op_sel:[1,1,0] (0 mismatches each, IEEE 0 and 1).

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_pack_denormal_modes: both instructions over the pairs above in f16 denormal modes 0 to 3 at IEEE 0 and 1 and without a known float mode. The round-toward-zero halves of the 16 f32 values are the GPU's; the flush and the IEEE=1 quieting of 0x7d00 follow the rule above, which matched the GPU on every pair. On main it fails: v_cvt_pkrtz_f16_f32 f16 denormal mode 0, IEEE mode on of 0x00000000 and 0x33800000 is 0x00010000, expected 0x00000000. 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_f16_pack_toward_zero 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, 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:4897926798 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7031). Originally posted by [thuanquang](https://github.com/thuanquang) on 2026-10-17T06:28:36Z. --- ### What `v_cvt_pkrtz_f16_f32` and `v_pack_b32_f16` ignored the `FLOAT_MODE` f16 denormal field. On the GPU: - `v_cvt_pkrtz_f16_f32` flushes each half result that is denormal after the conversion to its signed zero when bit 7 of `FLOAT_MODE` is clear (f16 denormal modes 0 and 1). `v_cvt_pkrtz_f16_f32 0, 0x33800000` (2^-24) gives `0x00000000` there; `main` writes `0x00010000`. - `v_pack_b32_f16` flushes each denormal half input to its signed zero when bit 6 is clear (modes 0 and 2). `v_pack_b32_f16 0x8000, 0x0001` gives `0x00008000` there; `main` writes `0x00018000`. `vCvtPkrtzF16F32` now passes both result halves through `flushF16Result` in the modes that flush them, and `vPackB32F16` passes each half through `flushF16Input` after its modifiers. Modes that keep them, 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, over the 256 pairs of 16 f32 values around the f16 denormal range (±0, ±2^-24, 1.5 * 2^-24, 2^-25, ±0x387fc000, 0x387fffff, ±2^-14, 0x37730edf, 1, 65520, ±inf) for `v_cvt_pkrtz_f16_f32` and the 256 pairs of 16 halves (±0, ±0x0001, ±0x03ff, 0x0200, ±0x0400, ±1, 0x7bff, ±inf, 0x7e00, 0x7d00) for `v_pack_b32_f16`, at IEEE 0 and 1: | f16 denormal mode | `v_cvt_pkrtz_f16_f32`, `main` vs GPU | `v_pack_b32_f16`, `main` vs GPU | this change vs GPU | |---|---|---|---| | 0 | 175 / 256 | 135 / 256 | 0 / 256 each | | 1 | 175 / 256 | 0 / 256 | 0 / 256 each | | 2 | 0 / 256 | 135 / 256 | 0 / 256 each | | 3 | 0 / 256 | 0 / 256 | 0 / 256 each | With this change every mode also matches for `v_cvt_pkrtz_f16_f32_e64 v10, -v4, |v5|`, `v_pack_b32_f16 v10, -v4, |v5|` and `v_pack_b32_f16 v10, v4, v5 op_sel:[1,1,0]` (0 mismatches each, IEEE 0 and 1). ### 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_pack_denormal_modes`: both instructions over the pairs above in f16 denormal modes 0 to 3 at IEEE 0 and 1 and without a known float mode. The round-toward-zero halves of the 16 f32 values are the GPU's; the flush and the IEEE=1 quieting of `0x7d00` follow the rule above, which matched the GPU on every pair. On `main` it fails: `v_cvt_pkrtz_f16_f32 f16 denormal mode 0, IEEE mode on of 0x00000000 and 0x33800000 is 0x00010000, expected 0x00000000`. 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_f16_pack_toward_zero` 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, 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)
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!7031
No description provided.