fix(shader): flush denormal v_trig_preop_f64 results in the f64 flush modes #22688

Merged
MichonGoddijn231849 merged 1 commit from upstream-pr/22688 into main 2026-11-26 08:53:39 +00:00
MichonGoddijn231849 commented 2026-11-18 02:37:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-11-18T02:37:17Z.


What

v_trig_preop_f64 kept a denormal result in every FLOAT_MODE. On hardware the result is flushed to zero when bit 1 of the f16/f64 denormal field is clear (modes 0 and 1). For ordinary inputs, segment 20 returns 0x000000000000294a with denormals kept and 0 with them flushed. AnyPS5 returned 0x294a in all four modes.

  • Float64Instructions.cpp: the FPTrigPreop64 result goes through the existing flushTinyF64Result (the non-product branch: a nonzero magnitude below 2^-1022 becomes its signed zero), as v_add_f64 results already do. It is a no-op when bit 1 is set or the shader has no known float mode.
  • test: new F64TrigPreopDenormalModes.cpp runs v_trig_preop_f64 on 20 lanes × 2 segment selectors in each of the four f16/f64 denormal modes and compares every dword with the hardware results. The 20 lanes cover zeros, the smallest denormal, the minimum normal, 1, 3, 0.5, 1e10, 2^100, 1e300, 2^1023, infinities, a quiet and a signaling NaN, segments 0 to 31, and a 0xffffffff selector.
  • debt: a v_trig_preop_f64 entry in shader.md (fragment docs/dev/debt/changes/fix-trig-preop-denormal-flush.md).

Source of the semantics: measured on RDNA2 hardware (gfx1036, AMD Windows driver 32.0.21045.16010) with tools/hw-oracle. The mismatch first showed in a differential run of the hardware oracle against AnyPS5's agc_oracle_runner on both Vulkan devices: 21 inputs × 10 segment selectors, IEEE 0 and 1, f16/f64 denormal modes 0 to 3. Before this change, modes 0 and 1 differed on 10 of 210 rows, all denormal results; modes 2 and 3 matched. With this change all 8 mode combinations match on both devices (0 of 210 rows differ). The test's expected values are the hardware's output for its own rows.

Tested

Windows 11 Pro 10.0.26200, ctest --test-dir build -R 'f64_trig_preop|f64_transcendental' -V with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, VK_LOADER_DEBUG=layer, validation layer 1.4.363, once per GPU (ANYPS5_GPU):

GPU this branch's tests on main (fix reverted) this branch
NVIDIA GeForce RTX 5080, driver 610.74 (32.0.16.1074) f64_transcendental passes; the new test fails: v_trig_preop_f64 f64 denormal mode 0: lane 0 word 0 is 0x0000294a, expected 0x00000000 2/2 passed, 0 VUID-
AMD Radeon(TM) Graphics (RDNA2 iGPU, gfx1036), driver 32.0.21045.16010 the same 2/2 passed, 0 VUID-

Each log shows Insert instance layer "VK_LAYER_KHRONOS_validation" and none shows was not found but was requested by env var VK_INSTANCE_LAYERS. pr_overlap.py --branch reports #22034 and #22446 on the neighbouring line of float64Operation. They round v_add/mul/fma_f64 in directed modes and add a rounding argument to flushTinyF64Result, so whichever merges second needs a one-line rebase. Neither changes v_trig_preop_f64.

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: NVIDIA GeForce RTX 5080, driver 610.74, Windows 11 Pro 10.0.26200; AMD Radeon(TM) Graphics (RDNA2 iGPU, gfx1036), driver 32.0.21045.16010, Windows 11 Pro 10.0.26200
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5368841177 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22688). Originally posted by [MichonGoddijn231849](https://github.com/MichonGoddijn231849) on 2026-11-18T02:37:17Z. --- ### What `v_trig_preop_f64` kept a denormal result in every `FLOAT_MODE`. On hardware the result is flushed to zero when bit 1 of the f16/f64 denormal field is clear (modes 0 and 1). For ordinary inputs, segment 20 returns `0x000000000000294a` with denormals kept and `0` with them flushed. AnyPS5 returned `0x294a` in all four modes. - **`Float64Instructions.cpp`:** the `FPTrigPreop64` result goes through the existing `flushTinyF64Result` (the non-product branch: a nonzero magnitude below 2^-1022 becomes its signed zero), as `v_add_f64` results already do. It is a no-op when bit 1 is set or the shader has no known float mode. - **test:** new `F64TrigPreopDenormalModes.cpp` runs `v_trig_preop_f64` on 20 lanes × 2 segment selectors in each of the four f16/f64 denormal modes and compares every dword with the hardware results. The 20 lanes cover zeros, the smallest denormal, the minimum normal, 1, 3, 0.5, 1e10, 2^100, 1e300, 2^1023, infinities, a quiet and a signaling NaN, segments 0 to 31, and a 0xffffffff selector. - **debt:** a `v_trig_preop_f64` entry in `shader.md` (fragment `docs/dev/debt/changes/fix-trig-preop-denormal-flush.md`). **Source of the semantics:** measured on RDNA2 hardware (gfx1036, AMD Windows driver 32.0.21045.16010) with `tools/hw-oracle`. The mismatch first showed in a differential run of the hardware oracle against AnyPS5's `agc_oracle_runner` on both Vulkan devices: 21 inputs × 10 segment selectors, IEEE 0 and 1, f16/f64 denormal modes 0 to 3. Before this change, modes 0 and 1 differed on 10 of 210 rows, all denormal results; modes 2 and 3 matched. With this change all 8 mode combinations match on both devices (0 of 210 rows differ). The test's expected values are the hardware's output for its own rows. ### Tested Windows 11 Pro 10.0.26200, `ctest --test-dir build -R 'f64_trig_preop|f64_transcendental' -V` with `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1`, `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`, `VK_LOADER_DEBUG=layer`, validation layer 1.4.363, once per GPU (`ANYPS5_GPU`): | GPU | this branch's tests on main (fix reverted) | this branch | | --- | --- | --- | | NVIDIA GeForce RTX 5080, driver 610.74 (32.0.16.1074) | `f64_transcendental` passes; the new test fails: `v_trig_preop_f64 f64 denormal mode 0: lane 0 word 0 is 0x0000294a, expected 0x00000000` | 2/2 passed, 0 `VUID-` | | AMD Radeon(TM) Graphics (RDNA2 iGPU, gfx1036), driver 32.0.21045.16010 | the same | 2/2 passed, 0 `VUID-` | Each log shows `Insert instance layer "VK_LAYER_KHRONOS_validation"` and none shows `was not found but was requested by env var VK_INSTANCE_LAYERS`. `pr_overlap.py --branch` reports #22034 and #22446 on the neighbouring line of `float64Operation`. They round `v_add/mul/fma_f64` in directed modes and add a `rounding` argument to `flushTinyF64Result`, so whichever merges second needs a one-line rebase. Neither changes `v_trig_preop_f64`. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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) and the licence notice of code adapted from upstream (see AGENTS.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] Fixes: none - [x] Unblocks: none - [x] GPUs tested: NVIDIA GeForce RTX 5080, driver 610.74, Windows 11 Pro 10.0.26200; AMD Radeon(TM) Graphics (RDNA2 iGPU, gfx1036), driver 32.0.21045.16010, Windows 11 Pro 10.0.26200 - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-11-18 03:08:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-18T03:08:06Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; the points below are optional.

What I ran

Reviewed head 7623199a800c55cd894abe5bd428d35c55d9983d. I inspected the prepared diff and all three changed files; I did not run commands or tests. The description reports Windows/Vulkan runs on NVIDIA RTX 5080 and AMD RDNA2, which I did not independently verify.

Results

Check Result Note
Changed code review passed All changed files read
Tests not run Author-reported results only

Findings

Blocking

None.

Non-blocking

None.

Not verified

I did not run the tests or independently confirm the reported hardware results. Repository files read: core/libs/prx/libSceAgcDriver/tests/execution/F64TrigPreopDenormalModes.cpp, core/shader/recompiler/Translation/src/Float64Instructions.cpp, and docs/dev/debt/changes/fix-trig-preop-denormal-flush.md. No changed files were excluded; all three files listed as reviewed were read.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5950245951 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22688#pullrequestreview-5950245951). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-18T03:08:06Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; the points below are optional. ## What I ran Reviewed head `7623199a800c55cd894abe5bd428d35c55d9983d`. I inspected the prepared diff and all three changed files; I did not run commands or tests. The description reports Windows/Vulkan runs on NVIDIA RTX 5080 and AMD RDNA2, which I did not independently verify. ## Results | Check | Result | Note | |---|---|---| | Changed code review | passed | All changed files read | | Tests | not run | Author-reported results only | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified I did not run the tests or independently confirm the reported hardware results. Repository files read: `core/libs/prx/libSceAgcDriver/tests/execution/F64TrigPreopDenormalModes.cpp`, `core/shader/recompiler/Translation/src/Float64Instructions.cpp`, and `docs/dev/debt/changes/fix-trig-preop-denormal-flush.md`. No changed files were excluded; all three files listed as reviewed were read. ## To get this to a good state Nothing is required.
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!22688
No description provided.