Recompiler: MemoryIndexBelongsTo walks the whole program on every call; about half of a warm start-up's CPU on 007 First Light #2774
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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-10T14:07:38Z.
Measured
PPSA11386 (007 First Light) v01.018.000, Linux (CachyOS, kernel 7.2.9, GCC 16.2.1), Ryzen 9 7950X3D (16 cores, 32 threads), RTX 3080 (NVIDIA 615.71.09), Release with SPIRV-Tools OFF. The base is
maina29ef592with the PRs that get 007 to its first flip (#2523), withResourceTracker.cppas onmain. The runs are warm: about 1,950 shader-cache hits and no misses. Each measures exec to the first flip, where 007 stops (#2523). Two separate warm runs were used, one per tool.perf record -e cycles:u -F 499attached to the process for 22 s of a 25.1 s run (163,328 samples) puts 76.5% of the samples inlibSceAgcDriver.prx:ShaderRecompiler::AddressOpcodeInfoOf(IrOpcode)(anonymous namespace)::Tracker::TryMakeTableImage(IrValue&, …)ShaderRecompiler::ImageOpcodeInfoOf(IrOpcode)MemoryIndexBelongsTois inlined intoTryMakeTableImage, and frame-pointer call graphs did not resolve in this build. The attribution therefore rests on the symbols and the A/B below.Cause
MemoryIndexBelongsTo(Optimization/src/ResourceTracker.cpp) walks every instruction of every block and callsBufferAccessOf,AddressOpcodeInfoOfandImageOpcodeInfoOfon each one.TryMakeTableImagecalls it for each of a table handle's eight descriptor dwords and once more for a material key.PlanIndirectImagescallsTryMakeTableImagefor every image instruction whose handle is not planned yet. So each such instruction can cost up to nine walks of the whole program.This runs once per shader per process, also when the shader disk cache hits: the resource plan, including
ResourceTracker::Track, is built beforeShaderDiskCache::Loadis consulted. For three of 007's shaders, one offline recompile takes 18 to 20 s withmain's code, and 2.2 to 2.3 s with the fix below.Fix
#2813 (from SleglJan/AnyPS5#23; one commit, +25/−2 in
ResourceTracker.cpp, now onmain57f96fd2):PlanIndirectImagesindexes the memory-accessing instructions by memory index once, andMemoryIndexBelongsTolooks the index up during that pass. The pass adds, removes and changes no instruction. #757 and #758 restructure this pass (PlanTableColumns) and conflict with the commit in one hunk (#757) and two (#758); their planning pass also emits no IR, so the same index should apply there.CompiledShaderInfo::shaderHash, which holds the shader's code address; 8 pairs are fully identical. As a control, two cold runs of one build with #1184's tracker hunk differ from each other only in address fields too.agc_shader_replay, 2 runs each on an idle machine, takes 18.3 to 19.9 s without the fix and 2.2 to 2.3 s with it, ending in the same offline error).Since #2808 it is open as #2813. A/B numbers from other titles (warm boot with and without the commit) would show how much of this is general.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-11T01:08:39Z.
Fixed by #2813.