perf(shader): reclaim unreachable cached source IR values #4271
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4271"
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 eljackjoestar-cmd on 2026-10-12T03:42:41Z.
What
Cached resource-plan blocks retain four embedded SSA register tables even after construction is complete. Allocate those tables only when used and release their storage after resource preparation. Reclaim unreachable source IR values when retaining a pending source program; skip the reclamation pass for immediate shader preparation and temporary uncached plans, whose programs are consumed or destroyed immediately.
Reclamation traces instruction, metadata and resource owners, unlinks garbage cycles before deletion, preserves live IDs, and throws on an unexpected remaining external user. Shader instruction semantics are unchanged. Source and variant entries remain unbounded; this does not solve all shader memory growth.
Rebased onto main
fc1f063f51189be91a186fd943e809bab2ef1ea2. The reclamation/allocation patch is unchanged by this rebase (git range-diffmatches). The branch contains this topic alone. Searches found no equivalent SSA-storage/reclamation fix. A pairwise merge simulation conflicts with #4883 only inRecompiler.cpp; proposed order is #4271 then #4883, pending agreement. #4884 merges cleanly in that simulation; no combined runtime validation is claimed.Tested
Windows 11 x64, Ryzen 7 7800X3D, 32 GiB RAM, NVIDIA RTX 5070, WinLibs GCC 15.2, Ninja Release, BUILD_TESTING=ON, emulator SPIRV-Tools OFF. Lost Soul Aside, PPSA26358. The metric is Windows process commit/private bytes (
Process.PrivateMemorySize64), in MiB, rather than working set or cumulative freed-object counts.Isolated main revision
c2565f014versus that same main plus this PR alone, measured before the latest rebase, with the same executable, game/configuration and machine:c2565f014d317aa64d340.27 MiB lower process commit (2.86%). Checkpoint: first observed intro frame >=600, then suspend the process before reading commit; recorded frames are 605/605 on main and 600/604 on the PR. Both use
ANYPS5_NO_SHADER_CACHE=1,APS5_SYNC_SHADER_PREPARE=1andAPS5_NO_PAD_INPUT=1. File-backed SPIR-V and other local game fixes are absent. All runs are sequential without concurrent builds/tests. Clean main stops later withmipmapped or DCC 3D color targets are unsupported, so the failed title attempt is excluded.Separate local title-screen comparison, retaining the other local game fixes: rebuilt control without this PR = 9866.36 MiB; revised runs = 9563.39 and 9520.43 MiB, mean 9541.91 MiB. 324.45 MiB lower process commit (3.29%). Each reading is the median of five samples 10-15 seconds after title-label detection. Both use the common settings above plus file-backed SPIR-V. The control and revised sources differ only in
IrBlock.hppandRecompiler.cpp; all other 126 runtime files match. This is not the isolated-main comparison. Earlier original-PR on/off testing showed a 258.63 MiB regression; the revised allocation strategy replaces that implementation's unnecessary upfront reclamation work.Raw process traces, checkpoint readings, settings and calculation details. No title data is uploaded. Peak gameplay memory, complete playability and an FPS improvement are not claimed.
fc1f063f5. Ten focused tests pass again without skips in 2.19 s:agc_ir_reclaim,agc_shader_memory,agc_shader_control_flow,agc_shader_disk_cache, the threeagc_driver_relative_*tests,agc_masked_select,agc_vector_windowandpixel_ancillary.c2565f014main and its PR build, SHA-2561b8e6b2b8e1efc29db228684a88612a00cb8a516493d3dcbfa0333c193a9840b.Checklist
main; no equivalent open PR implements this fixdocs/dev/debt/shader.mdImported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-12T10:35:15Z.
Preparing an isolated allocation-lifetime probe for 007 on an older Windows integration base: https://github.com/Scramblrrrr/AnyPS5/tree/codex/first-light-ir-reclaim-probe head 69a5580ab, credited cherry-pick of your final 2c5ed6ff1. Source only, NOT built/staged/validated yet.
This is explicitly not a cross-test of the whole #4271 dependency stack. #4150's translation changes expect the newer private VGPR-window infrastructure absent from this older 007 base; that attempted dependency port was aborted entirely. The probe retains our existing translator/masked-select semantics and only takes your final reclamation API, ResourceProgram construction change and IrReclaim fixture. CMake conflict resolved by adding only agc_ir_reclaim, without the newer vector-window target. Base a33e1e5fc also includes #290/#4385/#3991 cross-test sources, and is not current main. No new upstream implementation/PR.
Ownership regression, existing shader/cache checks and unchanged output checks will gate any game carry. I won't call the whole PR validated from this probe or assume it solves steady-state growth. Current game run remains graphics4e4083057, unchanged by this source preparation. AI-assisted: Codex. No title data uploaded.
Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-12T11:05:31Z.
Isolated IR-reclamation probe 7a91759e4 (69a5580ab plus snapshot-fixture factory adaptation) passes six Windows native tests: ir_reclaim, shader_memory, structurizer, shader_disk_cache, shader_control_flow, graphics; no skips, 5.60s. Four complete local requests recompile with cache disabled to byte-identical SPIR-V versus efcd89969 (166156,2910928,3111352,45588 bytes). Old conditional-block36 request is truncated and excluded. Output identity is not runtime support for poisoned storage-table operations.
Still not the full #4271 dependencies/current main: credited final reclamation commit only, existing older translator semantics. Graphics SHA256 70E13CDABA52E5BF229A56EDE8BE53E9DF2EFB43AF9189BAF4672310FCC3EFF7. Starting guarded game comparison; no memory/FPS gain claim yet. https://github.com/Scramblrrrr/AnyPS5/tree/codex/first-light-ir-reclaim-probe . No title data uploaded. AI-assisted: Codex.
Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-12T15:09:48Z.
Rebase handoff — rebased onto current
main, authorship unchanged.One semantic conflict in
Recompiler.cpp, resolved deliberately: this PR ran the post-masked-select cleanup (fold + identity resolution) unconditionally, while main has since landed the same cleanup gated on a livePackedAncillarybuiltin. I kept main's gated version — it subsumes this PR's case (the gate only skips the passes when no live ancillary exists, and this PR's concern is precisely the ancillary one), so the proofs this PR needs are preserved while avoiding the unconditional cost. If you intended the cleanup for non-ancillary cases too, say so and I'll re-push with the unconditional form.Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release,
BUILD_TESTING=ON, AMD RX 9070 XT / RADV):tools/check_conventions.py --base origin/mainpassesTo pick it up:
Head is
e002a41a0.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-13T02:42:59Z.
Could you measure the process commit of a title at the same point,
mainagainstmainplus this PR alone? The description counts the IR values released and says itself that no reduction in process memory was measured; aperf(PR needs that number.Imported from boykopovar/AnyPS5. Originally posted by eljackjoestar-cmd on 2026-10-13T07:43:44Z.
Measured current main against main plus this PR alone after rebasing onto
c2565f014. The earlier implementation increased commit by 258.63 MiB in the separate local title-screen matrix, so I revised it: SSA construction tables are now lazy and released after preparation, and immediate compilation avoids the unnecessary reclamation pass.The isolated reduction is 340.27 MiB (2.86%). Same executable, game/configuration and machine; no other PRs are applied. Disk cache is disabled, preparation is synchronous, and file-backed SPIR-V is absent in both. The process is suspended at the first observed frame >=600 (actual frames 600-605) before reading
PrivateMemorySize64.Clean main stops later on an unsupported mipmapped/DCC 3D color target. Separately, the local build that reaches the title, with its other fixes retained, measured 9866.36 MiB without this PR versus 9563.39/9520.43 MiB with the revised implementation: 324.45 MiB (3.29%) lower. These title readings are medians 10-15 seconds after start-label detection, and are not presented as main plus this PR alone.
Raw traces, settings, individual readings and calculation details. Full Windows Release build and all ten focused tests pass; the captured title shader remains byte-identical to main. The PR description now includes the measured process-commit results.
The new scheduling hunk conflicts with #4883 only in
Recompiler.cppin a pairwise merge simulation. I propose #4271 first, then #4883 preserving the reclamation argument on its resource-plan cache-miss path. Does that order work? #4884 merges cleanly in the simulation; no combined build/runtime result is claimed.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T07:46:16Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)core/libs/prx/libSceAgcDriver/CMakeLists.txtL1181core/shader/recompiler/Recompiler.cppL346-347, L390-396core/libs/prx/libSceAgcDriver/CMakeLists.txtL1181core/libs/prx/libSceAgcDriver/CMakeLists.txtL1181Imported from boykopovar/AnyPS5. Originally posted by eljackjoestar-cmd on 2026-10-13T08:09:32Z.
Rebased again onto main
fc1f063f5after it advanced.git range-diffconfirms the allocation/reclamation patch is unchanged. Full Windows Release build and all ten focused regressions pass again without skips (2.19 s); conventions and whitespace checks pass. The published process-commit measurements remain explicitly pinned toc2565f014/d317aa64d, where they were captured; this rebase is not presented as a new memory measurement.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T14:04:45Z.
Thanks for the measurement. Checked:
agc_ir_reclaimpasses and fails to build without the change; the rest of the libSceAgc/libSceAgcDriver ctest scope is unaffected by it.Added one commit on your branch:
docs/dev/debt/shader.md: the PR re-encoded two existing lines (thev_rcp, v_rsq, ...andFP16_OVFLentries), turningπintoÏ€and±into±. Restored the UTF-8 characters so the diff only adds your entry.Merging once the full Build is green.