perf(agc): cheaper shader-memory captures per draw #1193
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1193"
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 MichonGoddijn231849 on 2026-10-07T17:04:12Z.
What
The per-draw capture of a shader's memory (the SRT walk and the guest pages it reads) cost about 15 µs per draw packet in GTA V Performance mode. It now costs about 6.6 µs.
ExtractPlanalso stores the plan's values as 32-byte records with argument ids, and the walk evaluates that compact copy. The IR walk spent most of its time in cache misses (3.6 to 2.7 µs). The evaluator is a template over the node view, so both walks share every opcode's semantics, memo, cycle and failure rules. A plan that cannot be expressed compactly keeps the IR walk.APS5_VERIFY_SRT_COMPACT=1walks both and throws on any difference.ShaderMemory's valid/read/recent marks are arrays of 64-bit words scanned withcountr_zero, instead of bitsets tested bit by bit (about 1 µs per draw packet).APS5_PROFILE_DRAWsplits the capture time into SRT evaluation and materialization, and prints the[capture]line once per 10 s instead of every 500 captures (it cost about 2 µs per capture).APS5_PROFILE_DRAW(@Raghav314's review, his commit as co-author; on Hades II, RTX 4090:capture_resources2.48 -> 2.14 ms per frame).denseValueIdsand rebuilds the compact plan on load (ResourceMaterializer::CompactPlan); format 31.Tested
Windows 11 Pro, AMD Ryzen 5 7600, NVIDIA GeForce RTX 5080 (driver 32.0.16.1074), 32 GB, MinGW-w64 GCC 15.2.0.
main872f52320(2026-10-14) on its own; it no longer depends on #1191.agc_*andshader*suite passes on Windows: 504 tests, 1 skipped (agc_driver_stencil_ref_export). Not run here: the relinker's Python tests (my local Python does not find their helper modules) andguest_gameupdate.mainand of this PR (GTA V PPSA04264 Performance mode, the same scene, warm caches, traces attached): to follow in a comment.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 MichonGoddijn231849 on 2026-10-09T08:32:55Z.
Parked as a draft: the capture path changed a lot with #639 (captures now run against the prepared invocation), so this needs a rework rather than a rebase. I'll mark it ready again once it is ported.
Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-13T16:25:24Z.
Rebased onto current
main(a56c905df) on top of the rebased #1191 (thanks @gjonn:main's null-root and inaccessible-read reporting, signed min/less-than and zero out-of-range constant-buffer reads are now in the templated evaluator), and ready for review. Theagc_*suite passes on Windows (483 tests, 1 skipped).Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T00:10:23Z.
This applies cleanly to main on its own. Could you base it on main instead of #1191, so it can go in first?
It also needs the summary lines of main and of this change from one machine and scene (CONTRIBUTING), and the
GPUs testedline, since it changes the SRT evaluator incore/shader/.Imported from boykopovar/AnyPS5. Originally posted by Raghav314 on 2026-10-14T07:37:03Z.
I ran this on my machine (Linux, CachyOS, GCC, RTX 4090, NVIDIA 615.78.08) as part of a local stack with #494, #1201 and a few other draw PRs on top of
main, with Hades II (PPSA36082) standing in the hub. One thing in the lazy pages costs more than it should.ShaderMemory::pagechecks the whole page withGuestMemory::Accessiblebefore it marks itlazy. ButShaderMemory::accessibleonly skips its ownGuestMemory::Accessiblecall whenpage.valid.All(), and a lazy page has only the 64-byte blocks that were read marked valid. So almost every word read of the SRT walk (the evaluator asksaccessiblebefore each raw read) pays a page-state lookup again for a page already known to be readable. The lazy read path itself already relies on that first check when it copies a block straight from guest memory, so treating a lazy page as accessible is consistent with it:Two smaller things on the same path (they are on
maintoo):++CaptureTotals().readsand++CaptureTotals().pagesare atomic increments on every read and page, but the counts are only printed by the[capture]line underAPS5_PROFILE_DRAW; and every read andaccessiblecall does anupper_boundoninitialeven when the address is nowhere near the registered code and header. Gating the counters onCaptureProfiled()and checking the overall[begin, end)ofinitialbefore the lookup removes both.With the three together, same machine and scene, one run after the other (
APS5_PIPELINED_DRAWS=1, no profiling),Shader.DrawStage.capture_resourceswent from 2.48 to 2.14 ms per frame, the queue worker from 12.26 to 11.48 ms, and frame time p50 from 12.34 to 11.60 ms (1195 to 1277 presents in 15 s). Picture unchanged,agc_*tests pass.LLM assistance used.
Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-14T08:46:23Z.
Rebased onto
main(872f52320) on its own, so it no longer depends on #1191. Two changes on the way:APS5_PROFILE_DRAW.main's plan encoder check caught the plan's new fields: the disk cache now storesdenseValueIdsand rebuilds the compact plan on load (format 31).The
agc_*andshader*suites pass on Windows (504 tests, RTX 5080), and theGPUs testedline is in the description. The summary lines ofmainand of this PR from one machine and scene (GTA V Performance mode, warm caches, traces attached) follow in a comment today.Imported from boykopovar/AnyPS5. Originally posted by Raghav314 on 2026-10-14T13:17:17Z.
Thanks for taking the three read-path points in. One thing for Linux: the rebased head doesn't build there.
ShaderDiskCache.cppcheckssizeof(IrResourcePlan) == 584inside the__linux__ && __x86_64__ && __GLIBCXX__block, and with the compact plan the struct is 712 bytes with libstdc++ (I checked with asizeofprobe on my machine: Linux, CachyOS, GCC). The encoder already storesdenseValueIdsand the compact plan is rebuilt on load, so I think only the number needs to change:With that it builds, and the
agc_*suite passes here onmain98541c674with #1193 merged in (alongside #494, #1201, #1202 and #5687, so not on its own).LLM assistance used.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-15T09:17:59Z.
Rebased onto current main (
0afa6a607e) and force-pushed; the previous head is kept atadriadam10/AnyPS5:backup/MichonGoddijn231849-perf-capture-plan-walk.IrValueArenaand the compact plan structs live side by side inResourcePlan.hpp;MayEvaluateis a static member of the templated evaluator; the materializer clones through the arena. Shader cacheFormatVersionbumped to 36.sizeof(IrResourcePlan)assert set to 712 (libstdc++, as Raghav measured);fieldCountstays 23,denseValueIdsis encoded andCompactPlanruns on decode.ShaderMemory::readWordsadapted to main'sWordMask(newSetRuninstead of astd::bitsetshift), and theMayEvaluatetest calls the evaluator throughDetail::IrNode.Tested on Linux (RADV 660M,
-DANYPS5_ENABLE_SPIRV_TOOLS=ON,APS5_VERIFY_SRT_COMPACT=1): shader/agc/recompiler ctest 588/589; the one failure isagc_driver_tessellation, which segfaults the same way on main on this GPU. Windows build dispatched next. No title runs on this machine, so the before/after summary lines Dean asked for still need someone with a game.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T09:26:20Z.
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/shader/recompiler/ShaderDiskCache.hppL16core/shader/recompiler/Optimization/include/Optimization/SrtWalker/SrtEvaluator.hppL78-80core/shader/recompiler/Optimization/src/SrtWalker/SrtEvaluator.cppL277core/shader/recompiler/IntermediateRepresentation/include/IntermediateRepresentation/IrMetadata/ResourcePlan.hppL132core/shader/recompiler/Optimization/src/SrtWalker/SrtDescriptorEvaluation.cppL7, L46-48, L203core/shader/recompiler/ShaderDiskCache.cppL148Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-15T09:57:34Z.
One thing we noticed while porting #1201's version, in case it helps: since this merged, a shader-memory capture page that's marked lazy skips the multisample read guard.
Before (
042eb7c801), a page a capture first touched was read whole withGuestMemory::Read(ShaderMemory.cpp L111), which runs the read guard before its flush (GuestMemory.cpp L2004).MultisampleTarget.cppinstalls that guard so that a CPU read of a live multisample target throws (L233-L234, L344).On
mainnow (1db84d5748), the page only getsFlushGpuWritesand is marked lazy (ShaderMemory.cpp L191-L194), and each 64-byte block is later copied from guest memory withstd::memcpy(L220-L223). So a capture whose first read lands on a live multisample target's memory now reads the guest bytes without that check.We haven't seen a title hit it. Running the guard for the page when it's marked lazy would keep the check. Happy to send the small fix with a test if you'd like one.
Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-15T15:19:47Z.
@EagleBearerYS you're right, thanks for catching it. On
mainthe lazy page only getsFlushGpuWrites(ShaderMemory.cpp L191-L194) and its blocks are later copied withmemcpy, so the read guard thatGuestMemory::Readran first is skipped for a capture's first touch of a page. Running the guard over the page when it is marked lazy keeps the check at no per-word cost. Yes please, send the fix with the test; I'll review it.