Repository navigation
perf(shader): skip the f32 flush after results that cannot be denormal - #8958
Conversation
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>
|
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 |
MarcZX10
left a comment
There was a problem hiding this comment.
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.
|
Thanks for the review. #8958 supersedes #4278: it changes the same two files ( State of #4278 as of today: still open; a |
|
Should-fix, and one thing needs a maintainer decision rather than a code change. What verified from the branch:
Should-fix items:
Envelope: current 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. |
|
Thanks for the review.
|
|
This pull request is labeled |
|
Follow-up numbers from today (main 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; Envelope refresh: my earlier comment cited main 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. |
|
@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,
Captures: one warm-up boot each (the shader cache changes), then three interleaved traced rounds with
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 {"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)
Threads (ms per frame)
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
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
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 {"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)
Threads (ms per frame)
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
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
The traces of all three rounds, one zip per round, each with the pr8958-sonic-s2-round1.zip |
|
@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 |
imellag
left a comment
There was a problem hiding this comment.
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)
|
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, What I checked (static)
Focused paired run (VVL env)
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 ( |
|
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.
|
What
Carries #4278 (@Friesmaniac) onto current
main, as the maintainers asked on that PR (rebase onto currentmain;mainalready skips the flush for floor/ceil/min/max/med, the sign-bit masks and phis). It keeps only whatmaindoes not cover yet: the flush afterFPTrunc32,FPRoundEven32,FPSqrtandFPRecipSqrt32(their results cannot be denormal) and after aBitwiseOr32with an exponent bit set.FPFract32andFPRecip32keep 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, onmain7ce3b1d plus this commit:ctest -R '^agc_denormal_flush_elimination$'passes 3 of 3.core/shader/recompiler/Optimization/src/DenormalFlushEliminator.cpprestored tomain(the new test cases kept), the same test fails 3 of 3.-R 'denormal|_f32', 35 tests, missing executables built first) passes 35 of 35.python tools/check_conventions.py --base upstream/mainpasses;git merge-treeagainstmainis clean.Checklist
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).mdfiles or images added to the repositoryctest -Vprints no GPU selection)AI-assisted (Claude Code).