perf(shader): reuse an image table column's records while its words are unchanged #6440
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6440"
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 SleglJan on 2026-10-15T15:32:00Z.
What
An image table snapshot reads every record of every column again on each materialization: it locates each record's dwords, answers page accessibility, reads the runs, assembles a descriptor per record and indexes it. In 007 First Light's menu (PPSA11386), with columns of up to 19k records, snapshots take 7.78 s of every 10 s on
main(5,209 snapshots, 1.49 ms each).Each column now keeps a memo of its last read: the column itself (
TableColumn), the narrowed record states it started from, the layout, the words it read, and their distinct descriptors with their available-dword masks. The layout covers which records are read whole or by dword, the runs, the states of the records left unread, and every page accessibility query the layout made with its answer.TableColumn::operator==), its narrowed states equal the current ones element by element, and every recorded accessibility query gives the same answer again, in order. The layout is then reused.[image-table]profile line counts hits, reused layouts and misses with the columns and MiB kept.ResourceMaterializer::ColumnMemoCounts()returns the totals, for the tests.Related:
[image-table]report line,TableCountersand the snapshot reader; whichever lands second rebases. It also widensTableColumnand itsoperator==, which keeps the comparison here complete.GuestMemory's verify path (#6184, #6179) are covered by the replay.Tested
agc_shader_memory: new cases forEach read asserts whether it was a hit, a reused layout or a miss.
ctest
agc|shader|recompileron lavapipe (Mesa 26.2.4, LLVM 23.1.1; Arch Linux container, GCC 16.2.1), this change onmain4186f06a9: 590 of 599 pass, the same 9 failures asmainbuilt the same way (5 known ones plus 4 that need write watching, which the container lacks).Rebased onto
mainf1af6c591(2026-10-18). Onlytests/ShaderMemory.cppconflicted, where #7325 addedverifyChainedTableOffsetat the same spot, and both tests are kept; the other files are unchanged. ctest^agcon lavapipe, in an Arch Linux container with the same Mesa, LLVM and GCC and also without write watching: 663 of 676 pass. The 13 failures are the same as onmainf1af6c591built the same way: the 9 above, plusagc_driver_msaa_dcc_clear_2,_4,_8andagc_driver_native_depth_bda_clear, which need write watching.RTX 3080 (NVIDIA 615.78.08), CachyOS (Linux 7.2.10), GCC 16.2.1, Release, ctest
agc|shader|recompiler: 599 of 600 pass. The failure,agc_driver_store_over_untracked, fails on Linuxmaintoo (reported on #5671).A local benchmark (200 captures of one shader with a 19k-entry image table; not part of this PR), 6 runs per side alternated on
main4186f06a9, on a Ryzen 7 5700X:maincapture (µs)Materialization time and peak RSS were equal to
mainin all three.007 First Light (PPSA11386), main menu, no input, warm caches, RTX 3080 as above.
Both arms are
main4186f06a9plus the title's start-up fixes (#5799, #6317, #6332, an earlier revision of #6346, and local commits: input scripting, an FPS logger and fault diagnostics (off), a registered-range join, a volume-sampling workaround). Arm A adds this change; arm B is the same tree with it reverted.mainalone stops before this menu.APS5_TRACE_FRAMES=200:40and no other trace or profile switch, presents 200–239, runs alternated ABBAAB:Menu rate, frames 215–255: A 1.325 / 1.312 / 1.307, B 0.680 / 0.714 / 0.724 (medians 1.312 and 0.714, 1.84×).
[image-table]per 10 s, A: 9,177 snapshots in 5.72 s (0.62 ms each), 10,490 memo hits, 0 misses, 38 columns and 29.8 MiB kept. B: 5,209 snapshots in 7.78 s (1.49 ms each).Summary lines (A1–A3, then B1–B3):
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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T15:45:42Z.
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/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/include/Optimization/ResourceMaterializer.hppcore/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/include/Optimization/ResourceMaterializer.hppcore/shader/recompiler/Optimization/src/ResourceMaterializer.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/shader/recompiler/Optimization/include/Optimization/ResourceMaterializer.hppcore/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/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/shader/recompiler/Optimization/src/ResourceMaterializer.cppcore/shader/recompiler/Optimization/src/ResourceMaterializer.cppcore/shader/recompiler/Optimization/include/Optimization/ResourceMaterializer.hppcore/shader/recompiler/Optimization/src/ResourceMaterializer.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/shader/recompiler/Optimization/src/ResourceMaterializer.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/shader/recompiler/Optimization/include/Optimization/ResourceMaterializer.hppcore/shader/recompiler/Optimization/src/ResourceMaterializer.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/shader/recompiler/Optimization/src/ResourceMaterializer.cppcore/shader/recompiler/Optimization/src/ResourceMaterializer.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppImported from boykopovar/AnyPS5. Originally posted by SleglJan on 2026-10-18T01:16:15Z.
Rebased onto
mainf1af6c591(727a810bd). The only conflict was intests/ShaderMemory.cpp, where #7325 addedverifyChainedTableOffsetat the same spot. Both tests are kept, and theResourceMaterializerchange is unchanged.The memo still compares:
TableColumn::operator==), includingfoldedAddend/foldedCarry, which #7325 now also sets for chained offsets;ctest
^agcon lavapipe (Arch Linux container without write watching): 663 of 676 pass, the same 13 failures asmainf1af6c591built the same way. Twelve of them report that they need write watching. The other one isagc_driver_storage_write_back_overhang, which also failed in the earlier lavapipe run listed in the PR body.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-18T23:50:56Z.
Review: CHANGES_REQUESTED
The memo looks sound: the key plus
TableColumn::operator==, the narrowed states and the replayed accessibility checks cover what the layout reads, and the words are always read again. The tests assert hit / layout reused / miss on each read, and they would fail without the change.Two things before this can merge:
docs/dev/ARCHITECTURE.md: this adds a cache to the image table snapshot, but theTableSnapshotterparagraph (the one starting "At every invocation,TableSnapshotter... reads each column's records") doesn't mention it. Please add a sentence under it: the per-column memo, what it is keyed and verified on, that the words are always re-read, and its bounds (512 columns, 256 MiB, LRU, admitted on the second sighting).ResourceMaterializer.cpp(merge-treeconflicts in that file). Whichever lands second needs a rebase, so please rebase once the other is onmain.Imported from boykopovar/AnyPS5. Originally posted by SleglJan on 2026-10-19T05:57:32Z.
@adriadam10 thanks for the review. I'm closing this PR, so the
ARCHITECTURE.mdparagraph and the rebase against #7395 don't arise. #6454 has merged, and in 007's menu with #6454 underneath, this memo was never reached, because #6454's table reuse took every column that would otherwise have reached it.Here is a measurement of this change on a stack that includes #6454. The setup is the one in https://github.com/boykopovar/AnyPS5/pull/7508#issuecomment-6255590327: 007 First Light's main menu, RTX 3080, NVIDIA 615.78.08, Linux 7.2.10. The title's executable is not patched, and pad input is scripted through
APS5_PAD_INPUT_FILE. The runs useAPS5_PROFILE_DRAW=1, the windowAPS5_TRACE_SECONDS=1320:180, and a warm shader cache per arm.main1b0c7cfa0plus #5799, #6317, #6332, #6881, #6346, #6868, #6465, #5372, #6471, #6918, #6454 (a508aa03c) and #6567, a test adaptation, and a local commit that logs the window-title FPS.ResourceMaterializerchange differs from81c1a5ff2only by#include <tuple>.APS5_NO_PAD_INPUT=1andSDL_GAMECONTROLLER_IGNORE_DEVICESalso set. G2 ran last.[image-table]lines (10 s or longer each) count 0 memo hits, 0 reused layouts and 0 misses.[image-table]line counts 0 of each.The 1.84× in the description was measured on
main4186f06a9plus the start-up fixes listed there, before #6243 merged and without #6454.If a title turns up where #6454's reuse keeps missing columns whose words have not changed, the branch is still there to rebase.
AI-assisted: yes (Claude Code)
Pull request closed