perf(shader): avoid redundancy traversal map copies #5511
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5511"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-13T21:51:19Z.
What
The bundled redundancy-elimination traversal copies inherited value maps for sibling branches. Replace those copies with an iterative depth-first traversal, one scoped value map, and a log of values inserted by each subtree. Roll back each subtree's insertions on return so ancestor reuse is preserved and sibling values remain isolated. Optimization passes, type restrictions, value numbering and validation are unchanged.
CMake patches a build-directory copy of the pinned SPIRV-Tools source and rejects drift in the traversal and elimination helper. The dependency checkout is untouched. This extends SPIRV-Tools #6962, which releases processed maps but retains sibling map copies; it does not replace the separate AnyPS5 IR work in #4948.
Tested
Current published head
b00931842321f466b8ce1e7a48ac952d4f06f1ecis three topic/documentation commits directly above main56429064fc3074ed5192e32a06ba0cf7813af4fc, with zero merge commits. Additive shader-debt conflicts were resolved while retaining main's structurizer entry. Conventions and whitespace checks pass. The production patch and optimizer regression file are byte-for-byte identical to measured head5aea65b4b1c363c8783beb804f7e7579a2e9001e. The current-head Linux Release runtime builds with bundled SPIRV-Tools; default/full/none optimizer checks pass (3 passed, 0 skipped). Fresh full Linux/Windows CI passes this head against base56429064fc3074ed5192e32a06ba0cf7813af4fc: Linux 1,073 passed / 48 skipped / 1,121 total; Windows 739 passed / 406 skipped / 1,145 total. All three optimizer modes pass on Linux. Windows disables SPIRV-Tools and does not validate the traversal patch; skipped cases remain unvalidated. The measurements below retain their original revisions; no performance measurement against the new base is claimed.5aea65b4b1c3, Linux Release builds with bundled SPIRV-Tools enabled pass. Default/full/none optimizer checks pass on both main and this PR, with zero skips, including ancestor reuse, sibling scopes, conditional control flow, volatile stores and storage-only byte output. The earlier omitted-rollback negative control fails validation because the sibling value does not dominate its use.5aea65b4b1c363c8783beb804f7e7579a2e9001eand base1e7272196389c30eff9af9e91a51c72d781f46c6: Linux 1068 passed / 46 skipped / 1114 total; Windows 735 passed / 402 skipped / 1137 total. Linux exercises all three optimizer modes. The Windows configuration does not enable SPIRV-Tools and does not validate the dependency traversal patch. Skips remain unvalidated.Cold-title measurements
Astro Bot PPSA21564, untouched startup with no input, main
1e7272196389versus main plus this PR5aea65b4b1c3. Same machine, executable, modules, assets and settings; separate empty AnyPS5 shader, Vulkan pipeline and Mesa caches. Both builds enableAPS5_ENABLE_TIMING_LOG=ONto retain preparation before first present. OfficialAPS5_TRACE_SECONDS=0:60traces start at first present; no other trace/profile switch and console output not redirected. This deliberately measures cold loading, as requested, rather than the performance form's warm-cache gameplay protocol.First-flip wait is 13.0% shorter in the first pair and 16.0% shorter in the reverse-order repeat. Inclusive preparation is 23.6% / 26.6% lower. Repeat call counts are identical (2,245); the first pair differs by two calls. Both repeat runs reached the ASTRO BOT title screen in PID-matched snapshots at approximately 612 seconds, without input, and closed normally (exit 0); temporary kernel settings were restored.
Shader preparation includes translation, optimization and cache work. It sums inclusive elapsed calls across concurrent threads, so it exceeds wall-clock time and is not optimizer-only CPU time. First flip completion has
display_confirmed=0; it is not the time to a visible frame or completed title loading. Sparse title-screen snapshots establish the destination, not a precisely measured time-to-menu gain. The traces cover initial loading, with different present counts (the seconds-based window ends after its final present). No gameplay or steady-FPS improvement is claimed. Build timing adds overhead to both builds. Two pairs establish a repeated observed gain on this host, not broad hardware coverage.The first pair closed earlier during resource loading and both processes exited 139 after the close request. Those unresolved shutdown observations remain recorded; both longer repeat runs closed normally. No game assets, screenshots, core dumps or raw console logs are published.
Download all four traces, summary lines, digests and extracted timing comparison. The fork prerelease is a timing attachment, not an emulator build release; each
.json.gzopens in Perfetto.Official summary lines (pair 1 main/PR, then reverse-order repeat main/PR):
Independent title validation
milescoviello’s Forspoken PPSA03984 report tests this PR’s code commit
8ed0bc395on maine34c47921plus #5937, using an RTX 4070 Ti on Linux. Under a 15 GiB cap, the cold baseline reached the cap after 130 seconds and 1,624 shaders; the candidate completed the 150-second window with 2,505 shaders and 8.3 GiB peak anonymous memory versus 11.7 GiB. Two warm candidate launches reached a separate guest-memory-read stop rather than the baseline’s memory cap. That remaining stop prevents a playability claim.The same contributor reports byte-identical optimized output for 40 captured production modules; the module with 1,925,310 words dropped from 8,069 MiB peak RSS to 371 MiB. These measurements belong to that contributor’s setup and dependency stack; they complement the Astro measurements above and were not rerun locally.
Checklist
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-13T22:20:51Z.
Review: COMMENTED
I checked the merge state against current
main(bf8dc61). GitHub marks this PRDIRTY; a local merge-tree check finds the only conflict indocs/dev/debt/shader.md, where this PR appends a new Build entry. The contribution docs describe resolving additive debt-file conflicts during rebase withpython3 tools/debt_split.py resolve, then splitting withpython3 tools/debt_split.py splitif needed. The source/test/workflow files otherwise merge cleanly. Please refresh the branch and rerun the checks.Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-13T23:03:58Z.
Refreshed and rechecked against current main
30f961266ade83b41d5c9de7dec1393e7fcecfb7. Published head isd7828747a19fe04b69c5cc63b5228a5d5c5b4c0e, which contains current main. The additivedocs/dev/debt/shader.mdconflict is resolved, preserving the upstream SDWA Functional entry and this PR's Build entry. The source patch is unchanged.GitHub now reports MERGEABLE / CLEAN, and a fresh local
git merge-tree --write-tree origin/main HEADexits successfully with no conflicts. Conventions and whitespace checks pass. Fresh full fork CI passes for this head/base: Linux 1,037 passed / 46 expected skips; Windows 713 passed / 389 expected skips; zero failures. Skipped cases remain unvalidated.The earlier DIRTY result against
bf8dc61describes the old branch state.Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-13T23:44:33Z.
Resolved the reported overlaps in published head
180d47af0daa91bef8dac60d24361411599619ba, which includes current maind1670009fbf. Fresh local merge-tree checks merge this branch without conflicts with #4926, #4964 and #5028. The PR body describes the edits; these are independent features, soDepends on: noneremains correct.Conventions and whitespace checks pass. The compiler patch is unchanged; the duplicate Build section was consolidated into the existing section. Fresh full Linux/Windows CI passes on Linux and Windows for this published head; expected skips remain unvalidated.
The overlap workflow runs on main pushes and hourly, rather than PR pushes, so its earlier comment may remain until the next sweep.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-13T23:53:51Z.
Review: APPROVED
Reviewed the updated SPIRV-Tools traversal and regression coverage. The published head
180d47af0daa91bef8dac60d24361411599619bacontains current upstream maind1670009fbfdfe57f8f26ee09ced77fe6b18c2ca; the exact-head full Linux and Windows run 38485823046 completed successfully. The current PR check set also has passing conventions, eligibility and report checks; the Linux/Windows jobs on that upstream run are skipped by path filters. No remaining blocker found in the diff I reviewed.\n\nAI-assisted: yes; reviewed by MarcZX100.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T06:18:53Z.
Please rebase without the merge commits; the branch should be your commits on top of main.
Perf PRs need the summary lines of main and of the change from the same machine and scene (CONTRIBUTING, performance report form). The synthetic compiler numbers don't show what a title gains; a cold-cache load of a title, main against main plus this PR, with the shader compile time, would.
Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-14T07:37:37Z.
Rebased to three topic/documentation commits directly on main
1e7272196389, with no merge commits; published head5aea65b4b1c3. Full Linux/Windows CI passes (Linux enables the patched SPIRV-Tools; Windows does not).The description now includes matched Astro Bot PPSA21564 cold-start results from two pairs, with reverse order on the repeat. First submit to first flip is 349.480→303.908 seconds and 344.934→289.638 seconds (13.0% and16.0% shorter). Repeat shader-preparation call counts match at2,245; inclusive preparation elapsed is26.6% lower. Both repeat runs reach the title screen and close normally. This is cold-loading evidence, not a gameplay-FPS claim or an optimizer-only CPU measurement.
All four official summary lines, the protocol, limitations and a downloadable trace/digest bundle are in the description. The initial pair’s shutdown failures remain disclosed. Returned the PR to ready for review.
AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-14T17:20:50Z.
A title comparison, since a cold-cache load of a title was asked for above: Forspoken (PPSA03984), relinked with
--to-intel, on Linux (Ubuntu 24.04, GCC 13.3, Release with CI's flags, RTX 4070 Ti, NVIDIA 595.99.02). Both builds aremaine34c47921plus #5937, without which the title stops at 43 s; one also has this PR's code commit (8ed0bc395), and they differ only inlibSceAgcDriver.prx. Each run had a 15 GiB memory cap without swap, and the runs alternated, starting from an empty shader cache:mainThe warm runs with this PR end at an unrelated stop (
AGC driver: guest memory is not readable at 0x1037024000), which I'm looking at separately. A jemalloc heap profile of a warmmainstart had about 3.5 GiB of its live heap instd::map<uint32_t, uint32_t>copies underRedundancyEliminationPass::EliminateRedundanciesFrom.Offline, I passed the 40 largest modules the title sends to
ValidateAndOptimizeSpirv(1.0 to 5.3 M words, dumped by a local change) throughspirv-optbuilt from the pinned SPIRV-Tools, once withmain's patchedredundancy_elimination.cppand once with this PR's, using the default pass list fromSpirvOptimizer.cppand one process at a time. All 40 outputs are byte-identical. The largest differences in peak RSS:mainAI-assisted: yes