perf(shader): skip impossible NaN repair for normal multipliers #14892

Merged
Filip722 merged 3 commits from upstream-pr/14892 into main 2026-11-03 05:11:54 +00:00
Filip722 commented 2026-11-01 23:13:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Filip722 on 2026-11-01T23:13:43Z.


What

nanResultF32 builds a canonical-NaN result fallback even for an exact FP32 multiply with a known normal, finite, nonzero factor. That factor excludes the invalid zero-times-infinity case, so any NaN already comes from an input and is handled by the existing input-payload selections.

  • Pass explicit multiplication intent only from the FPMul32 caller and inspect the effective operands after input modifiers and denormal handling.
  • Reuse the existing constant-bit recognition to omit only the impossible result fallback. Preserve source NaN priority, IEEE quieting, input/output denormal behavior, result modifiers and every unproved-factor/other-opcode fallback.
  • Extend the existing arithmetic fixture with synthetic literals 2, 0.5, zero and infinity, reusing its signed-zero, infinity and signaling/quiet NaN payload inputs.

This branch now merges pinned main 66e1f7f993c9 into ed98df2caf76, retaining the same four-file change. The six-pair ordinary gameplay comparison below remains the original 5bae1a4bc2cf / f2fae88ef0a3 result. It is not a gameplay timing report for the refreshed head.

Ready for review: the implementation, matched focused validation and separately scoped gameplay/native evidence are complete. Shared-helper merge ordering is still unresolved and must be settled before merging; questions are posted on #4287, #11490 and #12548. Those proposals do not implement this normal-constant proof. This standalone branch includes none of them, so no dependency or ordering agreement is claimed. The remaining ordering decision is part of review; any subsequent reconciliation will be validated before merge.

Tested

The original 5bae1a4bc2cf / f2fae88ef0a3 hardware comparison passed for arithmetic NaNs (exact and fast), add/multiply denormal modes, denormal flush, constant-factor tininess and output modifiers. Both arms used the same synthetic fixture, ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1 and VK_LAYER_KHRONOS_validation; all six checks loaded the actual Khronos layer, with no VUID errors, missing-layer reports or skips.

For the refreshed integration, 66e1f7f993c9 plus the identical synthetic fixture and ed98df2caf76 each passed all six focused Vulkan checks listed above under the same required Vulkan/cache-bypass validation settings; each individual test loaded the actual Khronos instance and device layer, with zero VUID errors, missing layers, skips or truncated validation output. The staged libraries came from a newly built current-main snapshot, with 399 libraries per arm, 398 byte-identical current-main libraries (including the shared 66e1f7f993 VideoOut binary), and only the graphics driver differing.

The separate refreshed actual GPL+LTO native check found 27 targeted result repairs reduced to zero and fragment native code reduced from 13,148 to 12,760 bytes; both retained 32 VGPR, 108 SGPR, wave64 and zero scratch, joined to actual bound draws at 2560×1440 guest/render/physical Vulkan targets with single-sample images (1920×1080 presentation). This verifies the refreshed shader-work result; no new ordinary gameplay timing was run for the merged head.

Ordinary Sons of Sparta camp comparison on AMD Radeon 760M, private RADV Mesa 26.2.6 / libdrm 2.4.133, Debian 13: 12 valid runs in six matched pairs, zero retries, all six pairs faster. Actual rendering was 2560×1440 with 1920×1080 presentation, normal GPL+LTO and journal OFF. Mean frame time changed from 21.96919873535 ms on 5bae1a4bc2cf to 21.07197233492 ms on f2fae88ef0a3. The paired reduction was 0.8972264 ms, 95% Student-t interval [0.831245, 0.963208] ms, or 4.083505% [3.793507, 4.373503]%. The six run pairs are the repetitions used for that interval.

Timing evidence bundle: All twelve original timing traces, summaries, digests and paired analysis

Original upstream summary lines from the first prospective pair (all twelve lines and tools/trace_digest.py outputs are in the bundle):

{"commit":"5bae1a4bc2cf","dirty":true,"env":{"APS5_NO_PAD_INPUT":"1","APS5_NO_PIPELINE_JOURNAL":"1","APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"25:12"},"gpu":"AMD Radeon 760M Graphics (RADV PHOENIX)","driver":"radv Mesa 26.2.6","os":"Linux 7.2.12-x64v3-xanmod1","cpu":"AMD Ryzen 5 7640HS w/ Radeon 760M Graphics","cpu_threads":12,"memory_mib":23820,"title_id":"PPSA28997","title":"God of War Sons of Sparta","content_version":"01.008.001","resolution":"1920x1080","window":{"spec":"seconds 25:12","first_present":950,"ms":12000.178},"presents":547,"frame_ms":{"p50":21.939,"p90":22.511,"p99":23.412,"max":24.651},"gpu_busy_ms_per_present":18.780,"worker_busy_pct":{"queue worker 0x0":75.087},"top_phases_ms_per_frame":{"Driver.Packet":16.360,"Driver.Packet.draw":14.097,"Driver.Draw":14.057,"Driver.Draw.draw_enqueued":10.536,"Recorder.Sync":9.702,"VideoOut.Flip":4.500,"Driver.Present":4.465,"VideoOut.Flip.present":4.462},"trace_dropped":false,"trace":"aps5-trace-5bae1a4bc2cf-1234406.json.gz"}
{"commit":"f2fae88ef0a3","dirty":true,"env":{"APS5_NO_PAD_INPUT":"1","APS5_NO_PIPELINE_JOURNAL":"1","APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"25:12"},"gpu":"AMD Radeon 760M Graphics (RADV PHOENIX)","driver":"radv Mesa 26.2.6","os":"Linux 7.2.12-x64v3-xanmod1","cpu":"AMD Ryzen 5 7640HS w/ Radeon 760M Graphics","cpu_threads":12,"memory_mib":23820,"title_id":"PPSA28997","title":"God of War Sons of Sparta","content_version":"01.008.001","resolution":"1920x1080","window":{"spec":"seconds 25:12","first_present":969,"ms":12001.964},"presents":569,"frame_ms":{"p50":20.994,"p90":21.740,"p99":23.035,"max":24.352},"gpu_busy_ms_per_present":18.404,"worker_busy_pct":{"queue worker 0x0":77.958},"top_phases_ms_per_frame":{"Driver.Packet":16.328,"Driver.Packet.draw":13.981,"Driver.Draw":13.944,"Driver.Draw.draw_enqueued":10.522,"Recorder.Sync":9.615,"VideoOut.Flip":4.268,"Driver.Present":4.232,"VideoOut.Flip.present":4.231},"trace_dropped":false,"trace":"aps5-trace-f2fae88ef0a3-1235197.json.gz"}

For the original 5bae1a4bc2cf / f2fae88ef0a3 comparison, the associated actual optimized GPL+LTO fragment native code shrank from 13,148 to 12,760 bytes and the 27 targeted result repairs disappeared. Allocation stayed at 32 VGPR, 108 SGPR, wave64 and zero scratch. The ordinary paired runs above establish the reported gameplay result.

Checklist

  • Based on current main; no other open PR implements the same functions — integrated pinned main 66e1f7f993c9 in ed98df2caf76; exact-head manual review found no duplicate normal-constant domain fold. Shared-helper merge-order coordination remains pending as described above.
  • 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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: AMD Radeon 760M; RADV Mesa 26.2.6 / libdrm 2.4.133 (private build); Debian 13, Linux x86_64
  • AI-assisted: yes (Codex)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5112547490 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14892). Originally posted by [Filip722](https://github.com/Filip722) on 2026-11-01T23:13:43Z. --- ### What `nanResultF32` builds a canonical-NaN result fallback even for an exact FP32 multiply with a known normal, finite, nonzero factor. That factor excludes the invalid zero-times-infinity case, so any NaN already comes from an input and is handled by the existing input-payload selections. - Pass explicit multiplication intent only from the `FPMul32` caller and inspect the effective operands after input modifiers and denormal handling. - Reuse the existing constant-bit recognition to omit only the impossible result fallback. Preserve source NaN priority, IEEE quieting, input/output denormal behavior, result modifiers and every unproved-factor/other-opcode fallback. - Extend the existing arithmetic fixture with synthetic literals 2, 0.5, zero and infinity, reusing its signed-zero, infinity and signaling/quiet NaN payload inputs. This branch now merges pinned `main` `66e1f7f993c9` into `ed98df2caf76`, retaining the same four-file change. The six-pair ordinary gameplay comparison below remains the original `5bae1a4bc2cf` / `f2fae88ef0a3` result. It is not a gameplay timing report for the refreshed head. **Ready for review:** the implementation, matched focused validation and separately scoped gameplay/native evidence are complete. Shared-helper merge ordering is still unresolved and must be settled before merging; questions are posted on [#4287](https://github.com/boykopovar/AnyPS5/pull/4287#issuecomment-6565076590), [#11490](https://github.com/boykopovar/AnyPS5/pull/11490#issuecomment-6565076829) and [#12548](https://github.com/boykopovar/AnyPS5/pull/12548#issuecomment-6565077066). Those proposals do not implement this normal-constant proof. This standalone branch includes none of them, so no dependency or ordering agreement is claimed. The remaining ordering decision is part of review; any subsequent reconciliation will be validated before merge. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> The original `5bae1a4bc2cf` / `f2fae88ef0a3` hardware comparison passed for arithmetic NaNs (exact and fast), add/multiply denormal modes, denormal flush, constant-factor tininess and output modifiers. Both arms used the same synthetic fixture, `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1` and `VK_LAYER_KHRONOS_validation`; all six checks loaded the actual Khronos layer, with no VUID errors, missing-layer reports or skips. For the refreshed integration, `66e1f7f993c9` plus the identical synthetic fixture and `ed98df2caf76` each passed all six focused Vulkan checks listed above under the same required Vulkan/cache-bypass validation settings; each individual test loaded the actual Khronos instance and device layer, with zero VUID errors, missing layers, skips or truncated validation output. The staged libraries came from a newly built current-main snapshot, with 399 libraries per arm, 398 byte-identical current-main libraries (including the shared 66e1f7f993c9 VideoOut binary), and only the graphics driver differing. The separate refreshed actual GPL+LTO native check found 27 targeted result repairs reduced to zero and fragment native code reduced from 13,148 to 12,760 bytes; both retained 32 VGPR, 108 SGPR, wave64 and zero scratch, joined to actual bound draws at 2560×1440 guest/render/physical Vulkan targets with single-sample images (1920×1080 presentation). This verifies the refreshed shader-work result; no new ordinary gameplay timing was run for the merged head. Ordinary Sons of Sparta camp comparison on AMD Radeon 760M, private RADV Mesa 26.2.6 / libdrm 2.4.133, Debian 13: 12 valid runs in six matched pairs, zero retries, all six pairs faster. Actual rendering was 2560×1440 with 1920×1080 presentation, normal GPL+LTO and journal OFF. Mean frame time changed from **21.96919873535 ms** on `5bae1a4bc2cf` to **21.07197233492 ms** on `f2fae88ef0a3`. The paired reduction was **0.8972264 ms**, 95% Student-t interval **[0.831245, 0.963208] ms**, or **4.083505% [3.793507, 4.373503]%**. The six run pairs are the repetitions used for that interval. Timing evidence bundle: [All twelve original timing traces, summaries, digests and paired analysis](https://gist.github.com/Filip722/c032bdd4e170cbb88197effca560dbc7) Original upstream summary lines from the first prospective pair (all twelve lines and `tools/trace_digest.py` outputs are in the bundle): ```json {"commit":"5bae1a4bc2cf","dirty":true,"env":{"APS5_NO_PAD_INPUT":"1","APS5_NO_PIPELINE_JOURNAL":"1","APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"25:12"},"gpu":"AMD Radeon 760M Graphics (RADV PHOENIX)","driver":"radv Mesa 26.2.6","os":"Linux 7.2.12-x64v3-xanmod1","cpu":"AMD Ryzen 5 7640HS w/ Radeon 760M Graphics","cpu_threads":12,"memory_mib":23820,"title_id":"PPSA28997","title":"God of War Sons of Sparta","content_version":"01.008.001","resolution":"1920x1080","window":{"spec":"seconds 25:12","first_present":950,"ms":12000.178},"presents":547,"frame_ms":{"p50":21.939,"p90":22.511,"p99":23.412,"max":24.651},"gpu_busy_ms_per_present":18.780,"worker_busy_pct":{"queue worker 0x0":75.087},"top_phases_ms_per_frame":{"Driver.Packet":16.360,"Driver.Packet.draw":14.097,"Driver.Draw":14.057,"Driver.Draw.draw_enqueued":10.536,"Recorder.Sync":9.702,"VideoOut.Flip":4.500,"Driver.Present":4.465,"VideoOut.Flip.present":4.462},"trace_dropped":false,"trace":"aps5-trace-5bae1a4bc2cf-1234406.json.gz"} {"commit":"f2fae88ef0a3","dirty":true,"env":{"APS5_NO_PAD_INPUT":"1","APS5_NO_PIPELINE_JOURNAL":"1","APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"25:12"},"gpu":"AMD Radeon 760M Graphics (RADV PHOENIX)","driver":"radv Mesa 26.2.6","os":"Linux 7.2.12-x64v3-xanmod1","cpu":"AMD Ryzen 5 7640HS w/ Radeon 760M Graphics","cpu_threads":12,"memory_mib":23820,"title_id":"PPSA28997","title":"God of War Sons of Sparta","content_version":"01.008.001","resolution":"1920x1080","window":{"spec":"seconds 25:12","first_present":969,"ms":12001.964},"presents":569,"frame_ms":{"p50":20.994,"p90":21.740,"p99":23.035,"max":24.352},"gpu_busy_ms_per_present":18.404,"worker_busy_pct":{"queue worker 0x0":77.958},"top_phases_ms_per_frame":{"Driver.Packet":16.328,"Driver.Packet.draw":13.981,"Driver.Draw":13.944,"Driver.Draw.draw_enqueued":10.522,"Recorder.Sync":9.615,"VideoOut.Flip":4.268,"Driver.Present":4.232,"VideoOut.Flip.present":4.231},"trace_dropped":false,"trace":"aps5-trace-f2fae88ef0a3-1235197.json.gz"} ``` For the original `5bae1a4bc2cf` / `f2fae88ef0a3` comparison, the associated actual optimized GPL+LTO fragment native code shrank from 13,148 to 12,760 bytes and the 27 targeted result repairs disappeared. Allocation stayed at 32 VGPR, 108 SGPR, wave64 and zero scratch. The ordinary paired runs above establish the reported gameplay result. ### 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 — integrated pinned main `66e1f7f993c9` in `ed98df2caf76`; exact-head manual review found no duplicate normal-constant domain fold. Shared-helper merge-order coordination remains pending as described above. - [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: <!-- #PR, or none --> none - [x] Fixes: <!-- issue it closes as Fixes #N, or none --> none - [x] Unblocks: <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> none - [x] GPUs tested: <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> AMD Radeon 760M; RADV Mesa 26.2.6 / libdrm 2.4.133 (private build); Debian 13, Linux x86_64 - [x] AI-assisted: <!-- yes / no --> yes (Codex)
BunnyFl commented 2026-11-03 05:01:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-03T05:01:07Z.

Review: APPROVED


The change is sound by reading. For FPMul32 with an effective constant factor whose exponent is neither 0 nor 0xff, only 0 × ∞ could make a NaN from non-NaN inputs, and a finite nonzero normal factor rules that out. NaN inputs still go through the existing input-payload selections, and every other opcode and unproved factor keeps the canonical-NaN fallback.

Windows 11, AMD RX 9070 XT, WinLibs GCC 15.2.0, ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1, merged onto current main f6232fcfda (clean merge): agc_driver_f32_arithmetic_nan and _fast pass, including the new literal 2, 0.5, zero and infinity cases. With main's TranslationContext.hpp, FloatInstructions.cpp and OperandAccess.cpp restored they pass too, as expected: results shouldn't change, only the emitted fallback.

Non-blocking: both summary lines in the description carry "dirty":true, and you note the timing is from the earlier 5bae1a4bc2cf/f2fae88ef0a3 pair, not the refreshed head.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5747460862 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14892#pullrequestreview-5747460862). Originally posted by [BunnyFl](https://github.com/BunnyFl) on 2026-11-03T05:01:07Z. **Review:** APPROVED --- The change is sound by reading. For `FPMul32` with an effective constant factor whose exponent is neither 0 nor 0xff, only `0 × ∞` could make a NaN from non-NaN inputs, and a finite nonzero normal factor rules that out. NaN inputs still go through the existing input-payload selections, and every other opcode and unproved factor keeps the canonical-NaN fallback. Windows 11, AMD RX 9070 XT, WinLibs GCC 15.2.0, `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1`, merged onto current `main` `f6232fcfda` (clean merge): `agc_driver_f32_arithmetic_nan` and `_fast` pass, including the new literal 2, 0.5, zero and infinity cases. With main's `TranslationContext.hpp`, `FloatInstructions.cpp` and `OperandAccess.cpp` restored they pass too, as expected: results shouldn't change, only the emitted fallback. Non-blocking: both summary lines in the description carry `"dirty":true`, and you note the timing is from the earlier `5bae1a4bc2cf`/`f2fae88ef0a3` pair, not the refreshed head.
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!14892
No description provided.