fix(shader): flush f16 compare inputs by the FLOAT_MODE f16 denormal field #7021

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

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


What

v_cmp_X_f16 and v_cmpx_X_f16 ignored the FLOAT_MODE f16 denormal field: they compared denormal halves as their exact values in every mode. On the GPU, f16 denormal mode 0 or 2 (bit 6 of FLOAT_MODE clear) flushes both compare inputs to a zero of the same sign first, so v_cmp_eq_f16 0x0000, 0x0001 is true there and v_cmp_lt_f16 0x0000, 0x0001 is false. The half branch of emitFloatCompare now passes both inputs through flushF16InputValue, which the f16 unary ops and v_cvt_f32_f16 already use for the same field. Modes 1 and 3, and shaders without a known float mode, are translated as before.

The f64 compares have the same gap and are handled separately by #6850; this PR does not touch them.

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 halves (±0, ±0x0001, ±0x03ff, ±0x0400, ±1, ±inf, 0x7e00, 0x7c01, 0xfe00, 0x7bff), all twelve conditions (eq, ge, gt, le, lg, lt, neq, nge, ngt, nle, nlg, nlt) in VOPC and VOPCX form, at IEEE 0 and 1 with f16 denormal modes 0 to 3:

f16 denormal mode GPU vs flush-then-compare model main vs GPU this change vs GPU
0 0 / 3072 224 / 3072 0 / 3072
1 0 / 3072 0 / 3072 0 / 3072
2 0 / 3072 224 / 3072 0 / 3072
3 0 / 3072 0 / 3072 0 / 3072

(each cell is the same for IEEE 0 and 1 and for both forms)

v_cmp_class_f16 reports a denormal input as denormal in every mode on the GPU and is left as it is: 200 value and class-bit pairs, f16 denormal modes 0 to 3 at IEEE 0 and 1, 0 mismatches before and after this change.

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_vcmp_f16_denormal_modes: both forms, the 256 pairs and twelve conditions above, f16 denormal modes 0 to 3 at IEEE 0 and 1; the expected bits are the GPU's. On main it fails: v_cmp_eq_f16 f16 denormal mode 0, IEEE mode on of 0x0000 and 0x0001 is 0x0000, expected 1. With this change it passes. It is laid out like agc_driver_vcmp_f32_denormal_modes; the expected tables come out identical to that test's because the 16 values have the same order of classes.
  • Full ctest --parallel 4 --timeout 120 on main 6a32550fd with this change: 1368 tests, 3 fail, all failing on main on this PC too: agc_driver_lds_mixed_width_atomics (#5271), agc_driver_layered_volume_vertex_no_gpl (#4768) and conventions_function_bodies_shard_4, which times out here because Python takes about 0.4 s to start on this PC.
  • agc_driver_vopc_compare, agc_driver_vopc_compare_table, agc_driver_vop3_compare_modifiers, agc_driver_vcmp_eq_f16_clamp and agc_driver_f16_denormal_flush 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:4897838627 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7021). Originally posted by [thuanquang](https://github.com/thuanquang) on 2026-10-17T06:11:52Z. --- ### What `v_cmp_X_f16` and `v_cmpx_X_f16` ignored the `FLOAT_MODE` f16 denormal field: they compared denormal halves as their exact values in every mode. On the GPU, f16 denormal mode 0 or 2 (bit 6 of `FLOAT_MODE` clear) flushes both compare inputs to a zero of the same sign first, so `v_cmp_eq_f16 0x0000, 0x0001` is true there and `v_cmp_lt_f16 0x0000, 0x0001` is false. The half branch of `emitFloatCompare` now passes both inputs through `flushF16InputValue`, which the f16 unary ops and `v_cvt_f32_f16` already use for the same field. Modes 1 and 3, and shaders without a known float mode, are translated as before. The f64 compares have the same gap and are handled separately by #6850; this PR does not touch them. ### 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 halves (±0, ±0x0001, ±0x03ff, ±0x0400, ±1, ±inf, 0x7e00, 0x7c01, 0xfe00, 0x7bff), all twelve conditions (eq, ge, gt, le, lg, lt, neq, nge, ngt, nle, nlg, nlt) in VOPC and VOPCX form, at IEEE 0 and 1 with f16 denormal modes 0 to 3: | f16 denormal mode | GPU vs flush-then-compare model | `main` vs GPU | this change vs GPU | |---|---|---|---| | 0 | 0 / 3072 | 224 / 3072 | 0 / 3072 | | 1 | 0 / 3072 | 0 / 3072 | 0 / 3072 | | 2 | 0 / 3072 | 224 / 3072 | 0 / 3072 | | 3 | 0 / 3072 | 0 / 3072 | 0 / 3072 | (each cell is the same for IEEE 0 and 1 and for both forms) `v_cmp_class_f16` reports a denormal input as denormal in every mode on the GPU and is left as it is: 200 value and class-bit pairs, f16 denormal modes 0 to 3 at IEEE 0 and 1, 0 mismatches before and after this change. ### 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_vcmp_f16_denormal_modes`: both forms, the 256 pairs and twelve conditions above, f16 denormal modes 0 to 3 at IEEE 0 and 1; the expected bits are the GPU's. On `main` it fails: `v_cmp_eq_f16 f16 denormal mode 0, IEEE mode on of 0x0000 and 0x0001 is 0x0000, expected 1`. With this change it passes. It is laid out like `agc_driver_vcmp_f32_denormal_modes`; the expected tables come out identical to that test's because the 16 values have the same order of classes. - Full `ctest --parallel 4 --timeout 120` on `main` `6a32550fd` with this change: 1368 tests, 3 fail, all failing on `main` on this PC too: `agc_driver_lds_mixed_width_atomics` (#5271), `agc_driver_layered_volume_vertex_no_gpl` (#4768) and `conventions_function_bodies_shard_4`, which times out here because Python takes about 0.4 s to start on this PC. - `agc_driver_vopc_compare`, `agc_driver_vopc_compare_table`, `agc_driver_vop3_compare_modifiers`, `agc_driver_vcmp_eq_f16_clamp` and `agc_driver_f16_denormal_flush` 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:41:53 +00:00 (Migrated from github.com)

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


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 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:6230802024 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7021#issuecomment-6230802024). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-17T06:41:53Z. --- <!-- 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 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!7021
No description provided.