perf(shader): keep memoized results in a set-associative table #6733
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6733"
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 meh7an on 2026-10-16T08:19:43Z.
What
materializePreparedMemoizedkeeps each source's materialized results by variant and snapshot hash, so a capture that reproduces a snapshot gets the shared result instead of a freshPopulate. The memo is astd::listin LRU order with anunordered_mapindex (256 entries). Every hit splices the list. Every insert allocates a list node and a hash node, and evicts the oldest, which frees two more.The memo is now a fixed table of 64 sets of 4 entries per source, allocated with its first insert:
The eviction policy changes from LRU over all 256 entries to LRU within a set of 4.
On the S2 page of Sonic Origins Plus's main menu, the queue worker spent, per frame (APS5 sampler, 15 s):
materializePreparedMemoizedminus thematerializeResultit calls on a miss): 1.87 to 1.92 in three runs without this change, 1.33 to 1.60 in four runs with it;materializeResult, the misses' work: 2.3 to 2.9 in all seven runs, so the sets do not miss noticeably more.That is about 1.2% of the worker's frame (31 to 33 samples), so the frame times below move within run-to-run noise.
The change is in the recompiler's sources, so the shader cache version changes with it.
Tested
Windows 11 (10.0.26300), WinLibs GCC 15.2.0 (UCRT), Release, NVIDIA GeForce RTX 2080 Ti, driver 617.14.
5d9dcc42dwith this change, the full ctest suite passes 1298 of 1300 tests. (agc_device_faultwas linked again and rerun after a locked file stopped its first link.)agc_driver_gpu_indirect_arguments_misaligned_writer_aheadis not run: main itself does not compile it with MinGW (alignas(65536)).agc_driver_multisample_fill_host_onlyfailed once ("the sentinel fill did not land"). That is main's own race, #6512, which #6522 fixes; with #6522's line added it failed 0 of 200 runs (8 at a time).APS5_TRACE_SECONDS=200:15on the same machine in one session, caches warm. Traces attached.The FPS shown in the title went from 10.36 to 10.48 (median of six readings), and a sampled pair taken about 40 minutes earlier went from 10.50 to 10.82. Last night's windows of this page varied by about 5% at the median, so this pair's gap is mostly noise.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Traces and summary lines (baseline 40a918442, whose summary says 390f624712bf; this change 11882cc99, whose summary says 40a91844263b):
memo-traces.zip
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-16T08:39:18Z.
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.
core/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.cppImported from boykopovar/AnyPS5. Originally posted by parl0v on 2026-10-17T00:05:18Z.
Data point from a CPU-bound scene on Windows: RTX 3060 12 GB (NVIDIA 617.42), i5-12400F, Windows 10 19045, MinGW GCC Release. Minecraft Dungeons II (PPSA16064 01.100.100), title screen, no input, 200 s rows,
APS5_PROFILE_DRAW=1 APS5_PROFILE_GPU=1;mainaf0fff762vsmain+ this PR, interleaved with five other PRs in one batch, two rounds. FPS is the mean of the last 10[present]windows, GPU busy and idle gaps per frame over the last 8. This scene is CPU-bound on this machine (44-47 ms of idle gaps per frame).main92e5b971c)Within the run-to-run spread (
mainitself moved 6.61 -> 6.76 between rounds), no regression, 0 fatal.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T10:22:02Z.
Checked the hit/insert paths under
source.mutex, victim selection (empty ways first, then least recently used), the unchanged counters and capacity; the shader cache version bump is automatic. Merged.