perf(shader): skip the f32 flush after results that cannot be denormal #8958

Merged
xXPBSXx merged 1 commit from upstream-pr/8958 into main 2026-11-01 21:59:57 +00:00
xXPBSXx commented 2026-10-21 07:15:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-21T07:15:04Z.


What

Carries #4278 (@Friesmaniac) onto current main, as the maintainers asked on that PR (rebase onto current main; main already skips the flush for floor/ceil/min/max/med, the sign-bit masks and phis). It keeps only what main does not cover yet: the flush after FPTrunc32, FPRoundEven32, FPSqrt and FPRecipSqrt32 (their results cannot be denormal) and after a BitwiseOr32 with an exponent bit set. FPFract32 and FPRecip32 keep their flush, and the tests say so. Based on the head of #4278; the original author is kept.

The change claims no speed difference; no performance numbers were measured.

Tested

Windows 10 19045, WinLibs GCC 15.2.0 r7, Release, BUILD_TESTING=ON, on main 7ce3b1df3e plus this commit:

  • ctest -R '^agc_denormal_flush_elimination$' passes 3 of 3.
  • With core/shader/recompiler/Optimization/src/DenormalFlushEliminator.cpp restored to main (the new test cases kept), the same test fails 3 of 3.
  • The denormal and f32 family (-R 'denormal|_f32', 35 tests, missing executables built first) passes 35 of 35.
  • python tools/check_conventions.py --base upstream/main passes; git merge-tree against main is clean.
  • Not tested: GPU runs, a title, Linux/macOS.

Checklist

  • Based on current main; no other open PR implements the same functions (the original #4278 is the same change; this PR replaces it if the author does not update it)
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw; silent stubs are listed in technical debt (none added)
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source (none)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a (CPU shader-recompiler tests; no GPU run, ctest -V prints no GPU selection)
  • AI-assisted: yes

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4947853942 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8958). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-21T07:15:04Z. --- ### What Carries #4278 (@Friesmaniac) onto current `main`, as the maintainers asked on that PR (rebase onto current `main`; `main` already skips the flush for floor/ceil/min/max/med, the sign-bit masks and phis). It keeps only what `main` does not cover yet: the flush after `FPTrunc32`, `FPRoundEven32`, `FPSqrt` and `FPRecipSqrt32` (their results cannot be denormal) and after a `BitwiseOr32` with an exponent bit set. `FPFract32` and `FPRecip32` keep their flush, and the tests say so. Based on the head of #4278; the original author is kept. The change claims no speed difference; no performance numbers were measured. ### Tested Windows 10 19045, WinLibs GCC 15.2.0 r7, Release, `BUILD_TESTING=ON`, on `main` 7ce3b1df3e plus this commit: - `ctest -R '^agc_denormal_flush_elimination$'` passes 3 of 3. - With `core/shader/recompiler/Optimization/src/DenormalFlushEliminator.cpp` restored to `main` (the new test cases kept), the same test fails 3 of 3. - The denormal and f32 family (`-R 'denormal|_f32'`, 35 tests, missing executables built first) passes 35 of 35. - `python tools/check_conventions.py --base upstream/main` passes; `git merge-tree` against `main` is clean. - Not tested: GPU runs, a title, Linux/macOS. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions (the original #4278 is the same change; this PR replaces it if the author does not update it) - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw; silent stubs are listed in technical debt (none added) - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source (none) - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a (CPU shader-recompiler tests; no GPU run, `ctest -V` prints no GPU selection) - [x] AI-assisted: yes AI-assisted (Claude Code).
MarcZX10 commented 2026-10-21 07:35:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T07:35:08Z.


The code/test change looks narrowly scoped, and the reported Windows regression and negative-control runs are useful. One overlap question before I approve: #4278 is still open and changes the same two files for the same denormal-flush elimination. This PR says it carries that work onto current main; could you mark #4278 superseded (or clarify the intended merge order) so maintainers do not merge both copies?

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6310650267 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8958#issuecomment-6310650267). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-21T07:35:08Z. --- The code/test change looks narrowly scoped, and the reported Windows regression and negative-control runs are useful. One overlap question before I approve: #4278 is still open and changes the same two files for the same denormal-flush elimination. This PR says it carries that work onto current `main`; could you mark #4278 superseded (or clarify the intended merge order) so maintainers do not merge both copies?
MarcZX10 commented 2026-10-21 07:35:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T07:35:09Z.

Review: COMMENTED


Reviewed the optimization logic and tests. The newly recognized outputs are not subnormal after the backend flushes inputs for sqrt/rsqrt, and the bitwise cases preserve a nonzero exponent as asserted. I am holding approval pending clarification of the still-open overlapping #4278.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5596368758 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8958#pullrequestreview-5596368758). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-21T07:35:09Z. **Review:** COMMENTED --- Reviewed the optimization logic and tests. The newly recognized outputs are not subnormal after the backend flushes inputs for sqrt/rsqrt, and the bitwise cases preserve a nonzero exponent as asserted. I am holding approval pending clarification of the still-open overlapping #4278.
imellag commented 2026-10-28 18:45:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by imellag on 2026-10-28T18:45:03Z.

Review: APPROVED


macOS / MoltenVK data point. Apple M4 Pro, macOS 27.2, MoltenVK 1.4.2, x86_64 Release under Rosetta. main doesn't run titles on macOS yet, so the base is a support branch, not main: main 750cf6cf48 + only the macOS boot PRs #7631 #10552 #11249 #11447 #11554 #10669 #7804, + #12529 (the revert of #10337, which roughly doubles the GPU time on this GPU and would hide smaller changes). Change: that base + eight open shader performance PRs merged together (#12287 #11952 #12299 #12280 #11368 #11265 #8716 #8958, all clean merges). I did not measure each PR alone.

Two alternated runs per side, warm shader cache, APS5_TRACE_SUMMARY_EVERY=10:

base with the eight PRs
God of War Sons of Sparta (PPSA28997), fps from 30 s 51.5 / 51.8 51.6 / 51.8
GoW GPU ms/present, gameplay before the fight / in the fight 13.6 / 19.6 13.5 / 19.5
Planet of Lana (PPSA19450), fps from 85 s 32.2 / 32.7 32.5 / 32.6

Together they don't raise the GPU time on MoltenVK. I'm checking open shader performance PRs on this GPU because #10337 was measured on RADV and doubled it here.

Focused tests below ran with ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation on the same two trees; the layer was found and both logs have the same VUID- lines (12 VUID-VkPipelineColorBlendStateCreateInfo-pAttachments-00605, 20 VUID-vkCreateDescriptorSetLayout-support-09582, from tests that fail the same way on the base).

This PR on MoltenVK: agc_denormal_flush_elimination passes with the change, and the group above shows no GPU cost. Each newly skipped flush follows a result that can't be denormal (rounded to integral, square root and reciprocal square root of flushed inputs, an OR with an exponent bit set), and the tests keep the flush after FPFract32 and FPRecip32. Approving from the macOS side.

AI-assisted: yes (Claude Code ran the builds, runs and tests and drafted this review)

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5687925296 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8958#pullrequestreview-5687925296). Originally posted by [imellag](https://github.com/imellag) on 2026-10-28T18:45:03Z. **Review:** APPROVED --- **macOS / MoltenVK data point.** Apple M4 Pro, macOS 27.2, MoltenVK 1.4.2, x86_64 Release under Rosetta. `main` doesn't run titles on macOS yet, so the base is a support branch, not `main`: `main` `750cf6cf48` + only the macOS boot PRs #7631 #10552 #11249 #11447 #11554 #10669 #7804, + #12529 (the revert of #10337, which roughly doubles the GPU time on this GPU and would hide smaller changes). Change: that base + eight open shader performance PRs merged together (#12287 #11952 #12299 #12280 #11368 #11265 #8716 #8958, all clean merges). I did not measure each PR alone. Two alternated runs per side, warm shader cache, `APS5_TRACE_SUMMARY_EVERY=10`: | | base | with the eight PRs | |---|---|---| | God of War Sons of Sparta (PPSA28997), fps from 30 s | 51.5 / 51.8 | 51.6 / 51.8 | | GoW GPU ms/present, gameplay before the fight / in the fight | 13.6 / 19.6 | 13.5 / 19.5 | | Planet of Lana (PPSA19450), fps from 85 s | 32.2 / 32.7 | 32.5 / 32.6 | Together they don't raise the GPU time on MoltenVK. I'm checking open shader performance PRs on this GPU because #10337 was measured on RADV and doubled it here. Focused tests below ran with `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation` on the same two trees; the layer was found and both logs have the same `VUID-` lines (12 `VUID-VkPipelineColorBlendStateCreateInfo-pAttachments-00605`, 20 `VUID-vkCreateDescriptorSetLayout-support-09582`, from tests that fail the same way on the base). **This PR on MoltenVK:** `agc_denormal_flush_elimination` passes with the change, and the group above shows no GPU cost. Each newly skipped flush follows a result that can't be denormal (rounded to integral, square root and reciprocal square root of flushed inputs, an OR with an exponent bit set), and the tests keep the flush after `FPFract32` and `FPRecip32`. Approving from the macOS side. AI-assisted: yes (Claude Code ran the builds, runs and tests and drafted this review)
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!8958
No description provided.