perf(recompiler): keep image-table indexes in per-thread scratch #7193
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7193"
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 XairRrR on 2026-10-17T15:43:50Z.
What
Every image-table snapshot (
TableSnapshotter) and resolution (ResourceMaterializer::ResolveImageTables) built node-based indexes and threw them away at the end of the call:TableSnapshotter::WordsIndex: anunordered_mapfrom descriptor words to their index intables.words, one node per distinct descriptor;ResolveImageTables: astd::mapof poison records, astd::setof expected poison codes, astd::mapof bound elements and, per table, anunordered_mapof records by code.A table of N distinct entries therefore cost several heap allocations and frees per entry on every snapshot and resolution, on the dispatch path.
Profiled in Uncharted: Legacy of Thieves Collection (PPSA05684), orphanage (perf, DWARF call graphs, 20 s): the async compute queue 0x43 spends about 6.5 ms per dispatch, and on that thread
operator newis 20 % of samples (10.5 % called fromResolveImageTables, 6.5 % fromWordsIndex), mostly inside glibc's allocator;WordsIndexis 15.7 % inclusive;std::setis 4.7 % and the poisonstd::maplookups 4.3 %.Changes (
ResourceMaterializer.cpp)tables.words,out.elements,out.poison), compared by those vectors' fields. The records of a table are a dense array indexed by code.HostThreadLocal, so nothread_localdestructor is registered in the module and the scratch is freed at thread exit), stamped per use: a new call or table bumps the stamp instead of clearing the slots, so a call reuses the previous one's storage without touching it. Scratch larger than 2 MiB is released at the end of the call, so a thread keeps at most 2 MiB per index. A nested use on the same thread gets its own storage.tables.words,out.elementsandout.poisonis still insertion order, the element budget and every poison reason behave as before, and a code pasttables.wordsstill throwsstd::out_of_range.In-game A/B in PPSA05684 (orphanage, warm shader cache, 10 minutes after load per run). This was measured on a local integration build (
mainplus open PRs and local patches), with and without this change. The baseline comes from earlier runs of the same build; "with" is two runs:WAIT_REG_MEMon the async queues) per frameNo crashes and no Xids. Queue 0 waits much less for the async queues, but part of that wait moved to the GPU mutex, so the frame rate gain (about 6 %) is much smaller than the drop in label waits. This branch on its own, without the other local changes, was not run in the title.
Tested
Arch Linux (kernel 7.2.9-zen), NVIDIA RTX 4070 Ti SUPER, driver 615.78.08, GCC 16.2.1, Release,
BUILD_TESTING=ON.verifyImageTableScratchReuseinagc_shader_bindless(agc_shader_memory_tests --bindless). The test binary countsoperator newcalls per thread. It snapshots and resolves a 3000-entry table of distinct T#s, changes every entry, then does both again on the same thread and on a new thread. It checks that:main'sResourceMaterializer.cppthe warm pass allocates 9103 blocks and the test fails withimage table scratch: snapshotting and resolving a table allocated per record. After: 85.ctest -j4 -R "image_table|bindless|agc_shader_": the 16 built tests pass (agc_driver_image_table,_cache,_cache_bounds,_reuse,agc_driver_bindless_images,agc_shader_bindless,agc_shader_memory,agc_shader_disk_cache, and the otheragc_shader_*tests ofagc_shader_memory_tests).python3 tools/check_conventions.py --base origin/main: passed.Overlap
materializeSnapshot'svaluesandMaterialize'sactiveSourcesto thread-local storage in the same file. Complementary, different lines.wordsIndexinto a per-column structure but keeps theunordered_map. Textual conflict; whichever merges second rebases.WordsIndexfrom its replay path.WordsIndexkeeps its signature, so the conflict is textual only.Narrow(key scan), not these indexes.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)Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-17T15:57:19Z.
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/tests/ShaderMemory.cppL1276core/shader/recompiler/Optimization/src/ResourceMaterializer.cppL7-8, L403, L615-618, L1267-1271Some 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/Optimization/src/ResourceMaterializer.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/shader/recompiler/Optimization/src/ResourceMaterializer.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/shader/recompiler/Optimization/src/ResourceMaterializer.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/shader/recompiler/Optimization/src/ResourceMaterializer.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/shader/recompiler/Optimization/src/ResourceMaterializer.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/shader/recompiler/Optimization/src/ResourceMaterializer.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/shader/recompiler/Optimization/src/ResourceMaterializer.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/shader/recompiler/Optimization/src/ResourceMaterializer.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/shader/recompiler/Optimization/src/ResourceMaterializer.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/shader/recompiler/Optimization/src/ResourceMaterializer.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/shader/recompiler/Optimization/src/ResourceMaterializer.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/shader/recompiler/Optimization/src/ResourceMaterializer.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppImported from boykopovar/AnyPS5. Originally posted by TheSovietWaffle on 2026-10-17T16:38:30Z.
Windows data point: head
fd77d6939as-is, Release, Windows 10 Pro 22H2 (19045), WinLibs GCC 15.2.0 r7.agc_shader_memorypasses 5 of 5.Not checked: other tests, titles, timings.
AI-assisted: yes (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-18T00:26:47Z.
Thanks for this. It no longer merges cleanly into current main: #7101 has since changed
ResourceMaterializer.cpp. Could you rebase onto current main? We'll run full CI on the new head and take it through the game gates from there. This one is planned to land before #6454.