Skip to content

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

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
xXPBSXx:carry/4278-denormal-flush-more-cases
Nov 1, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
xXPBSXx:carry/4278-denormal-flush-more-cases

Conversation

@xXPBSXx

@xXPBSXx xXPBSXx commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

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 7ce3b1d 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 perf(shader): drop flushes of f32 results that cannot be denormal #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).

Rounding to an integral value, a square root, a reciprocal square root
and an OR with an exponent bit cannot produce a denormal, so the flush
after them is redundant. Rebased onto current main from boykopovar#4278, keeping
only the cases main does not cover yet.

Co-Authored-By: Friesmaniac <181011464+Friesmaniac@users.noreply.github.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@MarcZX10

Copy link
Copy Markdown
Contributor

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 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@xXPBSXx

xXPBSXx commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review. #8958 supersedes #4278: it changes the same two files (DenormalFlushElimination.cpp and DenormalFlushEliminator.cpp), rebased onto current main, and keeps only the cases main does not cover yet (+42 lines against +74 in #4278, because main now skips the flush for floor/ceil/min/max/med, the sign-bit masks and phis).

State of #4278 as of today: still open; a git merge-tree of its head 9989fd08e8 against main (2e0c9251df) reports conflicts in both files; its last commit is from 12.10., and the author has not commented since the rebase request of 17.10. I cannot close #4278 myself. If its author does not object, maintainers may close #4278 when this PR merges; I offered the rebase there on 20.10. and will drop #8958 if the author pushes an updated #4278.
AI-assisted (Claude Code).

@fogydes

fogydes commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

Should-fix, and one thing needs a maintainer decision rather than a code change.

What verified from the branch:

  1. The optimization is the sound one: setsExponentBit (DenormalFlushEliminator.cpp:74) treats a bitwise OR whose immediate carries an exponent bit as denormal-free (an OR can only add bits, so the result cannot be a subnormal pattern), and the four new denormal-free opcodes FPTrunc32 / FPRoundEven32 / FPSqrt / FPRecipSqrt32 (lines 117–120) cannot produce denormals for any representable f32 input (sqrt's minimum positive result is ≈2^-74.5, reciprocal-qrt of the max normal ≈2^-64.5; round/trunc outputs land on integers). The mixed-unknown case stays conservative — OR-of-two-unknowns is still flushed, which is the right side to err on. [verified arithmetically over the read code]
  2. The tests distinguish branch from main: the rounded/sqrt case pins exactly the four new opcodes plus FPFract32/FPRecip32 retaining their flushes (eliminate() == 6, where unchanged main yields 4), and the OR case pins sign-bit masks flushing while an exponent-bit-setting 0x00800000-masked OR doesn't. Test binary stays pre-registered (agc_denormal_flush_elimination). [verified existence + assertions; runtime passes author-reported]
  3. The body's "main already skips X" statements match main's current file. [verified]
  4. No flush-transformation semantics change, so the AGC cited-sources rule isn't violated; the IEEE claims in item 1 are static reasoning, not measurements.

Should-fix items:

  • Title/subject mismatch: PR title says refactor(shader)… while the branch commit is perf(shader): drop flushes of f32 results that cannot be denormal — and perf matches main's own precedents for this file (d7007db4, 69d0dc22). Bring the PR title to perf(shader): … and either attach the two trace_digest.py lines or keep the body's explicit "no speed claim is intended" wording, as those precedent commits do. [verified]
  • Open duplicate: perf(shader): drop flushes of f32 results that cannot be denormal #4278 (perf/shader-denormal-free-results) is still OPEN with the identical commit subject and the same change — this PR is its successor, but both are open against DenormalFlushEliminator.cpp. Needs an explicit maintainer call (close perf(shader): drop flushes of f32 results that cannot be denormal #4278 in favor of this one, or supersede this one); until then the cross-PR ledger has a live collision. [verified via gh and merge-tree]

Envelope: current main is 0a0ed72167; 1645 commits behind base 3bd7173b77, no main commits since the base touch DenormalFlushEliminator.cpp or the test file, and git merge-tree against current main is clean. [verified]

Disclosure: source-level verification on Windows; I did not compile or run the elimination test, so the 3×-pass/3×-fail-with-revert claims are author-reported — but the assertions themselves are branch-from-main distinguishing, so a single run on the merged result is the cheap confirmation.

@xXPBSXx xXPBSXx changed the title refactor(shader): skip the f32 flush after results that cannot be denormal perf(shader): skip the f32 flush after results that cannot be denormal Oct 23, 2026
@xXPBSXx

xXPBSXx commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review.

  • Title: agreed, the commit is perf(shader): ...; the PR title now reads perf(shader): skip the f32 flush after results that cannot be denormal. The body keeps its wording that no speed difference is claimed and no performance numbers were measured, so no trace_digest.py lines are attached.
  • perf(shader): drop flushes of f32 results that cannot be denormal #4278: see my earlier comment on this PR (same two files; perf(shader): drop flushes of f32 results that cannot be denormal #4278 is open and conflicts with main; maintainers decide which one stays open).
  • Test run on the merged result: on main 6687ed0bb2 merged with this PR's head a0e98fcf35 (Windows 10 19045, WinLibs GCC 15.2.0, Release), ctest -R '^agc_denormal_flush_elimination$' passes 3 of 3. The revert run (DenormalFlushEliminator.cpp restored to main) was not repeated on this main; the earlier 3-of-3 failure in the PR body was measured on main 7ce3b1df3e.
    AI-assisted (Claude Code).

@github-actions github-actions Bot added perf Performance change perf numbers missing perf pull request without a before and after summary line labels Oct 23, 2026
@github-actions

Copy link
Copy Markdown

This pull request is labeled perf, so it needs the summary line of a capture on main and one with the change, from the same title, scene and machine, as the Performance report form asks. Please paste both aps5-summary.jsonl lines, attach the two traces and add the output of tools/trace_digest.py.

@fogydes

fogydes commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

Follow-up numbers from today (main 1e20650e84), and one correction to my earlier framing.

Correction — I described this PR and #4278 as "the identical commit subject and the same change" in one sentence; that's too strong. Measured:

Still-current facts (re-measured): both PRs are open; git merge-tree origin/main pr-4278 conflicts in both of its changed files, while this PR still merges cleanly against main; git merge-tree pr-4278 pr-8958 conflicts in both shared files — they remain mutually unmergeable, so one of the two needs explicit closure (maintainer decision; this PR's author has said they'll drop it in favor of #4278 if #4278 gets pushed forward, and #4278 has been idle since 12.10). [verified]

Envelope refresh: my earlier comment cited main 0a0ed72167 / 1,645 behind base 3bd7173b77; it's now 1e20650e84 / 2,648 behind. Still no main commits since the base touch DenormalFlushEliminator.cpp or the test file. [verified]

One arithmetic footnote to my item 1 from the same earlier comment: sqrt's minimum positive result is ≈2^-63 (sqrt of the smallest normal), reciprocal-sqrt of the largest finite ≈2^-64 — I wrote ≈2^-74.5/2^-64.5 there; conclusion (never denormal) unchanged. Sigh.

@Meh7an

Meh7an commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

@xXPBSXx Here are measurements in a title, in the Performance report format, since the PR has none yet.

Setup: Windows 11 Pro 10.0.26300, NVIDIA GeForce RTX 2080 Ti, driver 617.14, i9-9900K. Sonic Origins Plus (PPSA05324), Sonic 2 page of the main menu, main's defaults. This PR's commit was cherry-picked onto main 5e6ae6e (3899c4e359, no conflicts) for measuring only. On that page the GPU is busy about 70 ms per present, and the shaders run in exact f32 mode.

  • The denormal and f32 tests (ctest -R "denormal|_f32|f32_", 37 tests) all pass with the change.
  • Full window captures of every reading render the page the same as main.

Captures: one warm-up boot each (the shader cache changes), then three interleaved traced rounds with APS5_TRACE_SECONDS=200:15, no other switch:

GPU busy per present (ms) frame p50 (ms) Driver.Packet (ms/frame)
main 5e6ae6e 75.0 / 75.1 / 68.9 83.0 / 84.0 / 83.2 85.7 / 86.9 / 84.3
this PR 72.3 / 70.1 / 68.3 82.7 / 83.4 / 82.4 83.0 / 82.9 / 82.6
  • The GPU is busy less per present than in main in each round, by 2.7, 5.0 and 0.6 ms. main's own rounds spread over 6 ms, though, so this is a small gain within the noise, not a firm number.
  • Frame time does not change, because the queue worker bounds this page (about 97 % busy).
  • A GPU-bound scene would show it better.

The two summaries and their digests (the median frame-time round of each build):

main (round 3)

seconds 200:15 from present 3463: 173 presents, frame p50 83.2 / p90 104.1 / p99 114.2 / max 115.3 ms, GPU busy 68.9 ms per present
NVIDIA GeForce RTX 2080 Ti, NVIDIA 617.14, Windows 10.0.26300, 3840x2160, commit 5e6ae6e, dropped: yes

{"commit":"5e6ae6e3d077","dirty":false,"env":{"APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"200:15"},"gpu":"NVIDIA GeForce RTX 2080 Ti","driver":"NVIDIA 617.14","os":"Windows 10.0.26300","cpu":"Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz","cpu_threads":16,"memory_mib":32684,"title_id":"PPSA05324","title":"Sonic Origins","content_version":"02.002.000","resolution":"3840x2160","window":{"spec":"seconds 200:15","first_present":3463,"ms":15006.972},"presents":173,"frame_ms":{"p50":83.184,"p90":104.067,"p99":114.236,"max":115.305},"gpu_busy_ms_per_present":68.891,"worker_busy_pct":{"queue worker 0x0":97.249},"top_phases_ms_per_frame":{"Driver.Packet":84.284,"Driver.Packet.draw":65.848,"Graphics.Draw":65.737,"Driver.Draw":64.847,"Graphics.Draw.draw_and_resource_release":55.302,"Driver.Draw.shader_compile_and_link":41.407,"Shader.DrawStage":30.679,"VideoOut.Flip":28.035},"trace_dropped":true,"trace_dropped_threads":{"queue worker 0x0":{"events_full_after_s":5.998,"events_lost":393530,"totals_full":false},"draw committer":{"events_full_after_s":13.533,"events_lost":28675,"totals_full":false}},"trace":"aps5-trace-5e6ae6e3d077-17460.json.gz"}

Slowest frames (largest slices inside each, inclusive)

  • present 3530: 115.3 ms at 5818 ms: Driver.Packet (queue worker 0x0) 79.5, batch (gpu) 69.8, Driver.Packet.draw (queue worker 0x0) 69.6, Driver.Draw (queue worker 0x0) 68.8
  • present 3543: 114.2 ms at 6987 ms: batch (gpu) 68.9, Graphics.Draw (draw committer) 64.1, Graphics.Draw.draw_and_resource_release (draw committer) 58.5, VideoOut.Flip (presenter) 29.1
  • present 3540: 112.1 ms at 6710 ms: batch (gpu) 67.3, Graphics.Draw (draw committer) 65.4, Graphics.Draw.draw_and_resource_release (draw committer) 59.6, VideoOut.Flip (presenter) 27.6
  • present 3553: 111.6 ms at 7837 ms: batch (gpu) 70.9, Graphics.Draw (draw committer) 65.3, Graphics.Draw.draw_and_resource_release (draw committer) 59.7, VideoOut.Flip (presenter) 29.7
  • present 3634: 111.5 ms at 14813 ms: batch (gpu) 68.7, VideoOut.Flip (presenter) 28.0, VideoOut.Flip.present (presenter) 27.8, Driver.Present (presenter) 27.8

Threads (ms per frame)

thread busy wait untraced in slices < 20 us largest
title 0.6 (1 %) 0.0 (0 %) 86.1 0.6 Shader.ResolveGraphicsAbi 0.2, Shader.ResolveGraphicsStagesAbi 0.2
queue worker 0x0 18.6 (21 %) 0.0 (0 %) 68.2 78.7 Driver.Packet 18.6, Driver.EndSubmission 0.0
draw committer 36.3 (42 %) 0.4 (1 %) 50.0 54.5 Graphics.Draw 34.6, Recorder.Submit 1.2
title 0.2 (0 %) 0.0 (0 %) 86.5 0.1 Shader.ResolveGraphicsAbi 0.1, Shader.ResolveGraphicsStagesAbi 0.1
title 0.1 (0 %) 0.0 (0 %) 86.6 0.1 Shader.ResolveGraphicsAbi 0.1, Shader.ResolveGraphicsStagesAbi 0.0
title 0.2 (0 %) 0.0 (0 %) 86.6 0.1 Shader.ResolveGraphicsAbi 0.1, Shader.ResolveGraphicsStagesAbi 0.1
presenter 0.7 (1 %) 27.5 (32 %) 58.5 0.0 VideoOut.Flip 28.0, Driver.Present 0.2
title 0.2 (0 %) 0.0 (0 %) 86.5 0.1 Shader.ResolveGraphicsAbi 0.1, Shader.ResolveGraphicsStagesAbi 0.1
title 0.2 (0 %) 0.0 (0 %) 86.5 0.1 Shader.ResolveGraphicsAbi 0.1, Shader.ResolveGraphicsStagesAbi 0.1
title 0.2 (0 %) 0.0 (0 %) 86.6 0.1 Shader.ResolveGraphicsAbi 0.1, Shader.ResolveGraphicsStagesAbi 0.1
title 0.2 (0 %) 0.0 (0 %) 86.6 0.1 Shader.ResolveGraphicsAbi 0.1, Shader.ResolveGraphicsStagesAbi 0.1
title 0.2 (0 %) 0.0 (0 %) 86.6 0.1 Shader.ResolveGraphicsAbi 0.1, Shader.ResolveAbi 0.0
title 0.2 (0 %) 0.0 (0 %) 86.5 0.1 Shader.ResolveGraphicsAbi 0.1, Shader.ResolveGraphicsStagesAbi 0.1
title 0.2 (0 %) 0.0 (0 %) 86.6 0.1 Shader.ResolveGraphicsAbi 0.1, Shader.ResolveAbi 0.1
title 0.2 (0 %) 0.0 (0 %) 86.5 0.1 Shader.ResolveGraphicsAbi 0.1, Shader.ResolveGraphicsStagesAbi 0.1
title 0.2 (0 %) 0.0 (0 %) 86.6 0.1 Shader.ResolveGraphicsStagesAbi 0.1, Shader.ResolveGraphicsAbi 0.1
gpu 68.8 (79 %) 0.0 (0 %) 17.9 0.0 batch 68.8

Largest slices (ms per frame, inclusive, all threads): batch 68.8, Graphics.Draw 34.6, Graphics.Draw.draw_and_resource_release 29.0, VideoOut.Flip 28.0, Driver.Present 28.0, VideoOut.Flip.present 27.8, Driver.Present.render_fence_wait 27.5, Vulkan.Retire 27.5, Vulkan.Retire.wait 27.5, Driver.Packet 18.6

Longest waits

  • Driver.Present.render_fence_wait (presenter) 31.1 ms at 1 ms, present 3463
  • Driver.Present.render_fence_wait (presenter) 30.8 ms at 4081 ms, present 3510
  • Driver.Present.render_fence_wait (presenter) 30.6 ms at 5572 ms, present 3527
  • Driver.Present.render_fence_wait (presenter) 30.6 ms at 4000 ms, present 3509
  • Driver.Present.render_fence_wait (presenter) 30.4 ms at 5407 ms, present 3525
  • Driver.Present.render_fence_wait (presenter) 30.4 ms at 1604 ms, present 3481
  • Driver.Present.render_fence_wait (presenter) 30.3 ms at 9625 ms, present 3573
  • Driver.Present.render_fence_wait (presenter) 30.2 ms at 7670 ms, present 3551
  • Driver.Present.render_fence_wait (presenter) 30.2 ms at 5328 ms, present 3524
  • Driver.Present.render_fence_wait (presenter) 30.0 ms at 9800 ms, present 3575

Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)

  • batch 10023: 13.6 ms at 12131 ms, present 3602: GPU no ranges; recorded by no CPU slices
  • batch 3274: 13.5 ms at 3999 ms, present 3508: GPU no ranges; recorded by Graphics.Draw (draw committer) 1.1, Graphics.Draw.draw_and_resource_release (draw committer) 1.0, Resources.Prepare (draw committer) 0.1, Resources.Complete (draw committer) 0.1
  • batch 11027: 13.4 ms at 13333 ms, present 3616: GPU no ranges; recorded by no CPU slices
  • batch 10454: 13.2 ms at 12647 ms, present 3608: GPU no ranges; recorded by Graphics.Draw (draw committer) 1.1, Graphics.Draw.draw_and_resource_release (draw committer) 1.0, Resources.Prepare (draw committer) 0.1, Resources.Complete (draw committer) 0.1
  • batch 774: 13.2 ms at 975 ms, present 3473: GPU no ranges; recorded by Driver.Packet (queue worker 0x0) 1.0, Driver.Packet.dispatch (queue worker 0x0) 0.5, Driver.Dispatch (queue worker 0x0) 0.5, Vulkan.Dispatch (queue worker 0x0) 0.3

this PR (round 1)

seconds 200:15 from present 3446: 176 presents, frame p50 82.7 / p90 91.9 / p99 117.5 / max 121.7 ms, GPU busy 72.3 ms per present
NVIDIA GeForce RTX 2080 Ti, NVIDIA 617.14, Windows 10.0.26300, 3840x2160, commit 3899c4e35916, dropped: yes

{"commit":"3899c4e35916","dirty":false,"env":{"APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"200:15"},"gpu":"NVIDIA GeForce RTX 2080 Ti","driver":"NVIDIA 617.14","os":"Windows 10.0.26300","cpu":"Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz","cpu_threads":16,"memory_mib":32684,"title_id":"PPSA05324","title":"Sonic Origins","content_version":"02.002.000","resolution":"3840x2160","window":{"spec":"seconds 200:15","first_present":3446,"ms":15038.578},"presents":176,"frame_ms":{"p50":82.731,"p90":91.896,"p99":117.453,"max":121.683},"gpu_busy_ms_per_present":72.261,"worker_busy_pct":{"queue worker 0x0":97.221},"top_phases_ms_per_frame":{"Driver.Packet":82.996,"Driver.Packet.draw":64.396,"Graphics.Draw":64.243,"Driver.Draw":63.382,"Graphics.Draw.draw_and_resource_release":53.45,"Driver.Draw.shader_compile_and_link":41.683,"Shader.DrawStage":30.854,"Driver.Present":29.705},"trace_dropped":true,"trace_dropped_threads":{"queue worker 0x0":{"events_full_after_s":5.761,"events_lost":419704,"totals_full":false},"draw committer":{"events_full_after_s":13.021,"events_lost":42256,"totals_full":false}},"trace":"aps5-trace-3899c4e35916-30560.json.gz"}

Slowest frames (largest slices inside each, inclusive)

  • present 3471: 121.7 ms at 2182 ms: Driver.Packet (queue worker 0x0) 91.2, Driver.Packet.draw (queue worker 0x0) 80.4, Graphics.Draw (draw committer) 79.6, Driver.Draw (queue worker 0x0) 78.9
  • present 3559: 117.5 ms at 9678 ms: Graphics.Draw (draw committer) 74.7, batch (gpu) 71.1, Graphics.Draw.draw_and_resource_release (draw committer) 60.2, VideoOut.Flip (presenter) 29.4
  • present 3519: 117.1 ms at 6184 ms: batch (gpu) 73.3, Graphics.Draw (draw committer) 68.9, Graphics.Draw.draw_and_resource_release (draw committer) 62.2, VideoOut.Flip (presenter) 31.1
  • present 3457: 116.0 ms at 931 ms: Driver.Packet (queue worker 0x0) 73.9, batch (gpu) 73.4, Graphics.Draw (draw committer) 66.5, Driver.Packet.draw (queue worker 0x0) 63.8
  • present 3469: 115.3 ms at 1981 ms: Driver.Packet (queue worker 0x0) 73.8, batch (gpu) 72.3, Graphics.Draw (draw committer) 65.5, Driver.Packet.draw (queue worker 0x0) 63.1

Threads (ms per frame)

thread busy wait untraced in slices < 20 us largest
title 0.6 (1 %) 0.0 (0 %) 84.8 0.6 Shader.ResolveGraphicsAbi 0.2, Shader.ResolveGraphicsStagesAbi 0.2
queue worker 0x0 17.3 (20 %) 0.0 (0 %) 68.2 75.3 Driver.Packet 17.3, Driver.EndSubmission 0.0
draw committer 34.4 (40 %) 0.4 (1 %) 50.6 51.3 Graphics.Draw 32.7, Recorder.Submit 1.2
title 0.2 (0 %) 0.0 (0 %) 85.3 0.1 Shader.ResolveGraphicsAbi 0.1, Shader.ResolveGraphicsStagesAbi 0.1
title 0.2 (0 %) 0.0 (0 %) 85.2 0.1 Shader.ResolveGraphicsAbi 0.1, Shader.ResolveGraphicsStagesAbi 0.1
title 0.2 (0 %) 0.0 (0 %) 85.3 0.1 Shader.ResolveGraphicsAbi 0.1, Shader.ResolveAbi 0.1
title 0.2 (0 %) 0.0 (0 %) 85.2 0.1 Shader.ResolveGraphicsAbi 0.1, Shader.ResolveGraphicsStagesAbi 0.1
presenter 0.6 (1 %) 29.2 (34 %) 55.6 0.0 VideoOut.Flip 29.7, Driver.Present 0.2
title 0.2 (0 %) 0.0 (0 %) 85.3 0.1 Shader.ResolveGraphicsAbi 0.1, Shader.ResolveGraphicsStagesAbi 0.1
title 0.1 (0 %) 0.0 (0 %) 85.3 0.1 Shader.ResolveGraphicsAbi 0.1, Shader.ResolveAbi 0.0
title 0.2 (0 %) 0.0 (0 %) 85.2 0.1 Shader.ResolveGraphicsAbi 0.1, Shader.ResolveGraphicsStagesAbi 0.1
title 0.2 (0 %) 0.0 (0 %) 85.3 0.1 Shader.ResolveGraphicsAbi 0.1, Shader.ResolveGraphicsStagesAbi 0.1
title 0.2 (0 %) 0.0 (0 %) 85.3 0.1 Shader.ResolveGraphicsStagesAbi 0.1, Shader.ResolveGraphicsAbi 0.1
title 0.2 (0 %) 0.0 (0 %) 85.3 0.1 Shader.ResolveGraphicsAbi 0.1, Shader.ResolveGraphicsStagesAbi 0.1
title 0.2 (0 %) 0.0 (0 %) 85.3 0.1 Shader.ResolveGraphicsAbi 0.1, Shader.ResolveGraphicsStagesAbi 0.1
title 0.2 (0 %) 0.0 (0 %) 85.3 0.1 Shader.ResolveGraphicsAbi 0.1, Shader.ResolveGraphicsStagesAbi 0.1
gpu 71.8 (84 %) 0.0 (0 %) 13.6 0.0 batch 71.8

Largest slices (ms per frame, inclusive, all threads): batch 71.8, Graphics.Draw 32.7, Driver.Present 29.7, VideoOut.Flip 29.7, VideoOut.Flip.present 29.5, Driver.Present.render_fence_wait 29.2, Vulkan.Retire 29.2, Vulkan.Retire.wait 29.2, Graphics.Draw.draw_and_resource_release 26.7, Driver.Packet 17.3

Longest waits

  • Driver.Present.render_fence_wait (presenter) 32.5 ms at 3051 ms, present 3481
  • Driver.Present.render_fence_wait (presenter) 31.9 ms at 4065 ms, present 3493
  • Driver.Present.render_fence_wait (presenter) 31.8 ms at 6020 ms, present 3517
  • Driver.Present.render_fence_wait (presenter) 31.7 ms at 8986 ms, present 3551
  • Driver.Present.render_fence_wait (presenter) 31.7 ms at 13043 ms, present 3598
  • Driver.Present.render_fence_wait (presenter) 31.6 ms at 5784 ms, present 3514
  • Driver.Present.render_fence_wait (presenter) 31.5 ms at 7153 ms, present 3530
  • Driver.Present.render_fence_wait (presenter) 31.5 ms at 7518 ms, present 3534
  • Driver.Present.render_fence_wait (presenter) 31.5 ms at 7321 ms, present 3532
  • Driver.Present.render_fence_wait (presenter) 31.5 ms at 12964 ms, present 3597

Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)

  • batch 6229: 14.6 ms at 7402 ms, present 3532: GPU no ranges; recorded by no CPU slices
  • batch 634: 14.3 ms at 769 ms, present 3454: GPU no ranges; recorded by Driver.Packet (queue worker 0x0) 1.2, Driver.Packet.dispatch (queue worker 0x0) 0.6, Driver.Dispatch (queue worker 0x0) 0.5, Driver.Packet.pipeline_drain (queue worker 0x0) 0.4
  • batch 1427: 14.3 ms at 1736 ms, present 3465: GPU no ranges; recorded by Driver.Packet (queue worker 0x0) 1.2, Driver.Packet.dispatch (queue worker 0x0) 0.5, Driver.Dispatch (queue worker 0x0) 0.5, Driver.Packet.pipeline_drain (queue worker 0x0) 0.4
  • batch 9330: 14.3 ms at 11173 ms, present 3575: GPU no ranges; recorded by no CPU slices
  • batch 2717: 14.3 ms at 3301 ms, present 3483: GPU no ranges; recorded by Driver.Packet (queue worker 0x0) 1.3, Driver.Packet.dispatch (queue worker 0x0) 0.6, Driver.Dispatch (queue worker 0x0) 0.5, Driver.Packet.pipeline_drain (queue worker 0x0) 0.4

The traces of all three rounds, one zip per round, each with the main and the PR capture:

pr8958-sonic-s2-round1.zip
pr8958-sonic-s2-round2.zip
pr8958-sonic-s2-round3.zip

@xXPBSXx

xXPBSXx commented Oct 24, 2026

Copy link
Copy Markdown
Contributor Author

@Meh7an thank you for the measurements and the traces. This PR still claims no change in speed. Your numbers, as you write them: GPU busy per present 2.7, 5.0 and 0.6 ms lower than main in the three rounds, within main's own 6 ms spread, and an unchanged frame time because the queue worker bounds that page. I have not reproduced them; they are the Performance report data the perf label asked for.
AI-assisted (Claude Code).

@imellag imellag left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

@blawesom

Copy link
Copy Markdown
Contributor

Static review plus an independent Linux/AMD run on both trees per the repo AGENTS shader-recompiler/AGC protocol (CachyOS, kernel 7.2.10, GCC 16.2.1, Ninja 1.13.2, Release, BUILD_TESTING=ON, Ryzen 7 9800X3D). No findings.

What I checked (static)

  • The elimination predicate grows along two axes, both narrow and checkable bit-level:
    1. Four more opcodes join DenormalFreeValues — FPTrunc32, FPRoundEven32, FPSqrt, FPRecipSqrt32. Each either rounds to an integer-valued result (trunk/round-even; zero input stays zero) or maps every finite input to a non-denormal output (±sqrt, ±rsqrt of a normal are ≥ the smallest normal or exactly zero; of a denormal/zero are zero). Output of these can never be a denormal float, so the flush's zero-subnormal step is dead.
    2. BitwiseOr32 with any immediate operand carrying an exponent bit (setsExponentBit, any of 0x7f800000) can never produce a denormal — the OR forces bit 23+, moving any result into normal/inf/nan territory.
  • The classification is correctly conservative: BitwiseOr32 without an exponent-immediate falls through (kept flushed), quiet (OR with 0x00400000, a mantissa bit only) and unknownOr (no constants) stay flushed — exactly what the new test's quiet.HasUses() && unknownOr.HasUses() half asserts. The predicate only fires for 2-argument ops with immediate operands, so a register-fed OR can never be misclassified.
  • Matches the review style elsewhere in DenormalFlushEliminator.cpp: a local named predicate added alongside clearsSignificand, narrow case-arm additions to the opcode switch.

Focused paired run (VVL env)

tree agc_denormal_flush_elimination _f16_denormal_flush _f32_denormal_flush total VUID- missing-layer
this head a0e98fcf35 Passed (0.00s) Passed (0.49s) Passed (0.06s) 3/3 0 0
main bb04a4f1ea Passed (0.00s) Passed (0.55s) Passed (0.17s) 3/3 0 0

Comparing logs, no new validation errors from this change.

Not covered

The four newly-classified opcodes are pinned at IR-construction level ("flush not emitted"); their hardware-denormal behavior under RADV (f32_denormal_flush covers FP16/FP32 flush on real GPU paths) is pinned by the pre-existing fixtures passing unchanged — the change does not widen what those assert. A regression reintroducing flushes here would show up as growth in builder.eliminate() counts, which the new test pins exactly (6 kept + 3 = the elimination counts asserted in each half).

@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown

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 12548 core/shader/recompiler/Optimization/src/DenormalFlushEliminator.cpp

@oneandonlydean
oneandonlydean merged commit ec31e2a into boykopovar:main Nov 1, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* perf numbers missing perf pull request without a before and after summary line perf Performance change shader core/shader

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants