perf(agc): find cached draws across moved user-data pointers #4943
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4943"
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 TheAggie on 2026-10-13T05:49:30Z.
What
Addresses #4054: a guest driver that puts per-draw pointers in the user data (RADV does, for its descriptor sets and push constants) misses the draw cache on almost every draw, because the register key and the entry's memory runs both contain the pointer values.
mainnow caches a draw the second time its key is seen (#5216). With moving pointers the exact key never repeats, so a repeat of the alias key counts as a second sighting too, and one draw of a shader set that has not been learned yet is admitted so the pointer words can be learned from it. Alias admission is limited: a shader set gets two such admissions on probation, and after that only one whose relocated entries actually hit (validated hits, not donors found) is admitted through its alias. Without this, aliases that come up exactly twice each inserted an entry nobody used (the D2R hit drop in the review).[draw-relocate]line counts the dropped ones.shaderDataUserWordsfield of a result, and its Linux-only size asserts expect the grown structs.main's incremental register fingerprint:RegisterStateKeygets an optionalshapeKeyout-parameter, and the user words are walked by one shared helper.APS5_NO_DRAW_RELOCATION=1turns it off.Related: #494 (draft) reuses a shape's decode and stages when only user data differs; this PR covers the case where the user data are pointers and the data behind them is unchanged or moved. They touch the same lookup and would need a rebase against each other.
This is the first part. Later steps I have locally and would send separately, each with its own numbers: relocating stages independently, reusing a stage when only buffer base addresses moved, and reusing draw snapshots.
Tested
Windows 11, NVIDIA GeForce RTX 5070 Ti, MinGW-w64 GCC 15.2.0, rebased on main
940eba9a2.ctest: 1269 of 1291 pass, 14 skipped.guest_call_trace_abort,windows_backtrace_reportandagc_driver_store_over_untrackedfail, and fail the same way on plain main here. Three newer tests,agc_driver_prepared_graphics_prebuild_0/_1andundeliverable_host_exception, fail under my test runner because it skips their environment changes and pass pattern; run with those, all three pass.ShaderDiskCache.cpponly compile on Linux. I have no Linux build; I compiled the structs under MinGW libstdc++ on x86_64, where all 31 asserted sizes match, including the ones this PR does not touch.agc_shader_disk_cache's result round trip now setsshaderDataUserWordsand compares it after decoding; it fails if the decoder drops them.agc_driver_draw_cache_relocation: a pixel shader loads its colour through a user-data pointer. The same contents drawn from eight addresses hit the cached draw from the fifth draw on (two draws teach the shader set, two more are the first and second sighting of the contents); other contents do not hit; an address seen before still hits. It fails withAPS5_NO_DRAW_RELOCATION=1. A second case draws 12 aliases that each come up exactly twice, between draws of a repeated one: at most 2 of them are cached and the repeated draw keeps all its hits (with the old admission rule all 12 were cached; the case fails on it).4430780bd(without #5216) plus local changes outside this PR that the frontend needs to boot. Same build, relocation off against on, two unprofiled runs each: audio produced at 26.9% and 27.0% of real time against 38.5% and 39.1%.maina14ae8e23plus the same local changes) the same demo does not get faster with this PR alone: audio at 5.4% and 5.5% against 5.8% without it, unprofiled. About 40% of draws hit, but each draw on this base copies a 2 MiB guest buffer into a snapshot whether it hits or not, and that copy dominates. #5609 on top reaches 36%; see the numbers there.main940eba9a2, the same demo with this PR and #5609 on top against the same build without them (both with the same local changes the frontend needs to boot, immediate present, audio muted, three alternating unprofiled runs): audio produced at 34.5%, 35.7% and 35.6% of real time without, against 45.7%, 44.1% and 42.8% with.APS5_VERIFY_DRAW_ENTRIES=1, which captures every hit again and compares: 0 stages differed in every report (88,797 hits in the largest).Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-13T08:40:01Z.
Windows test (MinGW GCC 15.2, Release, Windows 10, RTX 4080 SUPER). Built on main
534451426together with six other open GPU PRs (their own commits applied, no merge conflicts), so only the tests that belong to this PR say something about it:tests/execution/DrawCacheRelocation.cpp, whichctestruns asagc_driver_draw_cache_relocation: 3 of 3 runs passed.Not tested: no game run. The batch was built once, not per PR; nothing failed, so no bisect was needed.
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by TideOPL on 2026-10-13T10:14:59Z.
Tested on Minecraft Dungeons II (PPSA16064) gameplay: Windows 11, RTX 5070, cherry-picked onto our MCD2 build (
main+ the import-join PRs). No change for this title; data in case it helps the later steps:[draw-relocate](report threshold lowered locally): 8,238 alias lookups over the whole run, 1 donor with moved user words, 0 refusals, 0 hits; 263 shader sets learned.c9ccc9a0->caf3c9a0, same low 16 bits: a per-frame ring) in PS u24/u26 and VS u28/u24/u12, plus a few small values (PS u22:0x280->0x610).So the data behind the pointers likely differs per draw (per-draw constants), which this first step does not cover. "Reusing a stage when only buffer base addresses moved" sounds like what this title needs; happy to test it.
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-13T12:54:29Z.
No measurable change on AMD in two light 2D catalog titles, the same result as @TideOPL's Minecraft Dungeons II run.
Setup: Windows 11 (26300), Radeon 860M (RDNA 3.5, AMD proprietary driver 24.30.58.08), WinLibs GCC 15.2.0, Release, 1920x1080. Base is
main5d50886ee+ #5081, which these titles need so their UI renders at all. Each PR head was merged onto that base, with a clean merge. Catalog releases relinked with--windows, one warm-up run per build, thenAPS5_TRACE_SECONDS=20:10with no otherAPS5_*switch. Three runs per build, interleaved (base, #4878, #4943, base, ...) so that laptop thermal drift hits every build alike. Medianframe_ms.p50, with the per-run range:In every build the queue worker is busy only 35-37 % of the window, and
gpu_busy_ms_per_presentis 2.9-8.1 ms.Driver.Packet.executeis 16-17 ms per frame in all three. These EVO-engine titles are bound by their own CPU side: each frame they wait on a fence withusleep(1000)and fill the 8 MB scanout from the CPU. So neither PR has much to remove here, and the EVO Player difference is inside the base's own spread. I'm posting it as a no-change data point on AMD; it isn't a regression claim. Summary lines and traces are available if you want them attached.Imported from boykopovar/AnyPS5. Originally posted by JAB-dev on 2026-10-13T23:47:23Z.
Besiege (PPSA20313), this branch (
df467c2b1) against its merge base2a55cfe1e, Windows 11, RTX 4070 SUPER, 1080p, three runs each (the base lost one capture):The relocation does not take effect on this title. Over 10 s the draw cache sees about 75,000 lookups with 74,000 "no entry" and 927 hits, and your counters read
[draw-relocate] 123013 alias lookups: 2 donors with moved user words, 0 refusals, 3 hits through a relocated entry; 59 shader sets learned, 12202 aliases held. So the keys that differ in Besiege are not the ones your alias path joins.Imported from boykopovar/AnyPS5. Originally posted by JAB-dev on 2026-10-14T00:16:21Z.
Data for why the relocation does not fire on Besiege (PPSA20313,
mainata0f5916a2plus #5364, local build that prints the old and new user-data words for the draws whose only changed key group is the user-data registers):In steady state 70% of the misses are exactly that case, and in the first 40 sampled draws a single word changes in 39 of them (the 40th printed no changed word): the second stage's user word 8 (register 0x94, index 8 of the 0x8c group). It goes up by exactly +176 each time (
1dacb3e0 -> 1dacb490 -> 1dacb540 -> ..., 39 of 39), with a jump now and then where draws in between were cache hits. No other user word differs. So the title walks a ring of 176-byte per-draw constant slots, and the draws are otherwise identical (same shaders, same registers).Imported from boykopovar/AnyPS5. Originally posted by TheAggie on 2026-10-14T02:06:42Z.
Thanks for the three data points. I've rebased the branch onto current
mainand force-pushed; what changed:@JAB-dev that 3-5% on Besiege was the alias lookup running for every draw with nothing to find (your counters show 2 donors in 123,013 lookups). Two changes for that case:
I don't have Besiege, so I can't confirm it closes the gap there. If you can run the new head against the same base, the
[draw-relocate]line should show far fewer alias lookups.Your second comment explains why nothing matches: one user word walking a ring of 176-byte per-draw constant slots, with everything else equal. Whether that can be reused depends on how the shader reaches the slot. If it binds the slot as a buffer, #5609 covers it: only the base address moves and the contents stay out of the match. If it reads the constants through the pointer during the capture, the contents differ every draw and neither PR can match; that case needs the constants refreshed in a cached stage rather than compared, which is closer to what #494 does for user data, and I haven't done it here. A run of #5609's head on Besiege would tell which it is.
The rebase also had to deal with #5216 (a draw is cached the second time its key is seen). With moving pointers the exact key never repeats, so nothing was cached and the relocation had nothing to reuse. A repeat of the alias key now counts as a second sighting too. On the Flycast workload, with the follow-up applied: 59% of real time without the admission, 51% with #5216 as merged, 59% with this change.
@TideOPL your shape analysis is the case the next step is for. A pointer pair that moves through a per-frame ring with different data behind it each draw can't hit here, since this PR only matches when the contents behind the pointers are equal. The follow-up keeps a cached stage when the only words that differ are buffer base addresses the shader binds as buffers, so the per-draw constants stay out of the match. It is up as #5609, stacked on this one.
@LeandroLP23 thanks for the AMD numbers; no change is what I'd expect on titles that don't put pointers in the user data.
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by Raghav314 on 2026-10-14T03:44:41Z.
I ran this with #5609 on top on my machine (Linux, CachyOS, GCC, RTX 4090, NVIDIA 615.78.08), merged with
maina5f493f90, and tried it on Hades II (PPSA36082). Two things, and some numbers.The Linux build fails.
ShaderDiskCache.cpphas layout asserts that only exist on Linux x86-64 with libstdc++, so a Windows build never sees them:shaderDataUserWords(5d8dff973, here) andbufferBaseSlots(54c1f168c, #5609) are what grew them. Nothing is lost on disk, since the cached variant only stores theCompiledBindingLayoutand both fields are rebuilt byDescriptorBindingBuilder::Populateon every capture. So it is only the asserts, plusEncodeResult/DecodeResultnot carrying the two fields. What I used locally:With that, the full ctest passes except
agc_driver_bc_block_copy, which fails the same way on plainmainhere.The
[draw-relocate]line never printed in Hades. It is only reached from insideif (!userPatches.empty()), oncelookups >= 100000, and Hades rarely gets there. I added a local counter line printed with the[draw-cache]report every 10 s to see what happens.Hades II, hub, standing still (
APS5_PROFILE_DRAW=1, per 10 s):APS5_VERIFY_DRAW_ENTRIES=1 APS5_VERIFY_REGISTER_KEYS=1 APS5_VERIFY_DRAW_SNAPSHOTS=1: 0 stages differed (about 49k hits captured again per 10 s), and the picture looks right.APS5_NO_DRAW_RELOCATION=1, so I have no frame-time number for the change itself.LLM assistance used.
Imported from boykopovar/AnyPS5. Originally posted by JAB-dev on 2026-10-14T03:46:41Z.
Reading the code to see why this does not fire on Besiege (the one moving word is user word 8 of the 0x8c group, register 0x94, +176 per draw; that group feeds
programs[0], the vertex stage), two things stand out:tagVariantRuns(..., decodeReads[i].empty() && (!vertexInfos[i] || resourcesNum == 0), ...)inDrawCapture.cppskips every vertex stage that has vertex inputs, so the word is never learned as relocatable and its raw value stays in the alias key: every draw gets a new alias, which matches 2 donors in 123,013 alias lookups. Dropping that gate and instead excluding the vertex-table pointer words thatDecodeVertexStageInforeads (ShaderInputState.cppnear line 209) would let the word be learned.SrtFlatSlotClasses.cpp) are left out of the content key and validated live, the way the dispatch cache's data hits do.Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-14T05:48:20Z.
Rebase handoff — rebased onto current
main(all four commits), authorship unchanged.One code conflict (main's skipped-shader early return beside this PR's user-patch application — both kept) plus one structural follow-through: this PR's
shaderDataUserWords(a runtime vector onRecompileResult/BindingAllocationResult) changes struct sizes thatmain's newer disk-cache encoders assert on. The handoff updates the twostatic_assertsizes for the merged layouts (320→344, 152→176); the field itself is not added to the encoders, as it looks runtime-only (recomputed per recompile, not persisted) — please confirm that's intended, since the assert message points at the encoders by design.Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release,
BUILD_TESTING=ON, AMD RX 9070 XT / RADV):tools/check_conventions.py --base origin/mainpassesmainregression (agc_driver_tessellationsegfault, #4727); the disk-cache and draw-cache-relocation tests all pass (4/4)To pick it up:
Head is
d94dc175e.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T11:12:20Z.
Review: CHANGES_REQUESTED
Thanks for the work and for the rebase after #5216. This head conflicts with
mainand, merged with it, does not build on Linux. Points to fix:Draw/Draw.cppconflicts withmain(the skipped-shader early return next to the user-patch application). Please rebase.core/shader/recompiler/ShaderDiskCache.cpp:79and:94(static_assertonsizeof(RecompileResult)/sizeof(BindingAllocationResult)) fail on Linux/libstdc++ becauseshaderDataUserWordsgrows both structs (see Raghav314's report). Updating the sizes alone is not enough: aRecompileResultdecoded from the disk cache comes back with an emptyshaderDataUserWords, soapplyShaderDataPatchespatches nothing and a relocated hit would keep the old pointer in the shader data. Either persist the field inEncodeResult/DecodeResultand the allocation encoder (and bump the cache version), or make the relocation refuse variants whose compiled result has no learned words. Please add a test for a result that went through the disk cache.DrawCapture.cpp(decodeReads[i].empty() && (!vertexInfos[i] || vertexInfos[i]->resourcesNum == 0)) never learns the word that moves in vertex stages with vertex inputs. Please say whether that case is in or out of this PR and, if out, why the trial back-off is enough there.APS5_NO_DRAW_RELOCATION=1would settle it.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T13:07:04Z.
Review: CHANGES_REQUESTED
Thanks for the update; persisting
shaderDataUserWordsinEncodeResult/DecodeResultis the right direction. What is still open:mainagain (Driver/Draw/DrawCache.hpp,core/shader/recompiler/ShaderDiskCache.cpp). Please rebase and re-check thestatic_assertsizes on Linux/libstdc++ against the merged structs.RecompileResultwith non-emptyshaderDataUserWordsand check the words (and an alias hit on the decoded result). Without it the encoder change is untested.DrawCapture.cppgate (decodeReads[i].empty() && (!vertexInfos[i] || vertexInfos[i]->resourcesNum == 0)) still skips vertex stages with vertex inputs, so Besiege's moving word is never learned (@JAB-dev above). Please say whether that case is in or out of this PR and, if out, why the trial back-off is enough there.APS5_NO_DRAW_RELOCATION=1on one of them would settle it.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T13:28:30Z.
Review: CHANGES_REQUESTED
Thanks for the rebase and for persisting
shaderDataUserWordsin the disk cache. Merged onto currentmain, the Agc/AgcDriver scope builds and passes here on Linux (agc_driver_draw_cache_relocationincluded). Still open from the last review:RecompileResultwith non-emptyshaderDataUserWordsand check the words (and an alias hit on the decoded result). The encoder/decoder lines added inShaderDiskCache.cppare untested.DrawCapture.cpp:103(decodeReads[i].empty() && (!vertexInfos[i] || vertexInfos[i]->resourcesNum == 0)) still skips vertex stages with vertex inputs, so Besiege's moving word (@JAB-dev above) is never learned. Please say whether that case is in or out of this PR and, if out, why the trial back-off is enough there.APS5_NO_DRAW_RELOCATION=1on one of them would settle it.Depends on(currentlynone) and say which lands first.Imported from boykopovar/AnyPS5. Originally posted by TheAggie on 2026-10-14T13:30:04Z.
Rebased onto
main7181fe94dand force-pushed. Since then #5656 went up, stacked on #494: it reuses a stage when the changed user words are ones that stage never reads, which is a different case from the moved pointers here. What changed since the last push:@Raghav314 thank you, that is a real break and I could not have seen it here. The Linux-only size asserts in
ShaderDiskCache.cppnow expect the grown structs (376 and 176 on this branch, 400 and 200 on #5609, on top ofmain's own growth), andEncodeResult/DecodeResultcarryshaderDataUserWords(andbufferBaseSlotson #5609). I have no Linux machine, so I checked the numbers by compiling that file once with the guard forced on under MinGW's libstdc++, which lays these structs out the same way; a Linux build of the new head would still be the real confirmation.You are also right that the
[draw-relocate]line is only reached from the patch path after 100,000 lookups, so a title that seldom patches never prints it. I have not changed that in this push. Your Hades II numbers are useful as they are: about 5% of draws turned into hits, 0 stages differing under the three verify switches, and more than half the draws skipped by the back-off.@JAB-dev both points are right.
DecodeVertexStageInforeads, as you suggest, is the right shape for it. It is not in this PR.So Besiege gains nothing from this PR until those two steps exist. What the back-off should do is take away the 3-5% it cost; I can't measure that here, so a rerun on your side is what would show it.
Two smaller changes came from the review on #5609 and apply here too: the content key now hashes the whole of each read instead of its first 64 words, and when the alias map reaches its limit every other entry is dropped instead of all of them.
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by mrfelek on 2026-10-14T16:13:08Z.
Data point from a title that misses the draw cache on almost every draw. Diablo II: Resurrected (PPSA03912, 01.039.000), Linux, RTX 3080 Ti (NVIDIA 615.71.09), in game (Rogue Encampment). Build:
main84b01f9cdplus #1186. A = that; C = A plus this PR (head 1c72efdc9); B = C plus #5609 (head d6abd5555). Three alternating runs of each, presents per 10 s: A 39.7 / 41.0 / 39.1; C 39.4 / 40.3 / 39.3; B 33.3 (a startup dip in its first window) / 40.0 / 39.7. No change in speed. The draw-cache hits per 10 s fall: about 377 (A), about 220 (C), about 201 (B).Why it does not help on this title: over 60,000 draws one stage's user-data word 0x090 changes on essentially every draw (59,959 of them). That stage holds inline V#s (base, stride and count, format) whose bases advance by a fixed step per draw, as a streaming vertex buffer does: word 0x08c over four consecutive draws is
5b199b00,5b19a000,5b19a500,5b19aa00(step 0x500). A second word, 0x00c, moves on almost every draw too (02e4dad0,02e50bf0,02e69ff0over three draws). So the values that change are the V# bases themselves and a constant pointer, and the key still never repeats. Happy to rerun with more registers or a trace if that helps.AI-assisted; the runs are from my machine.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T20:42:03Z.
Review: CHANGES_REQUESTED
Thanks for the update. On this head the Agc/AgcDriver scope builds and passes here on Linux, and
agc_driver_draw_cache_relocationfails withAPS5_NO_DRAW_RELOCATION=1, as it should. Your reasoning on the vertex-stage gate (DrawCapture.cpp:103, the vertex decode reads the table pointers) holds; that point is dropped. What blocks the merge is the performance case:mainyet. Your own run ona14ae8e23shows this PR alone slightly slower (audio 5.4/5.5% against 5.8%); @TideOPL (MCD2), @LeandroLP23 (two AMD titles) and @mrfelek (D2R) see no change, and @JAB-dev saw 3-5% lower on Besiege before the back-off. The 26.9% → 38.5% gain is from a base without #5216. Since the gain only comes back with #5609 on top, please post a before/after of the stack (#4943 + #5609) against currentmainon the Flycast demo, same build otherwise, a few alternating runs. If that holds, the two can land back to back.1c72efdc9, same commits as895d65498) shows hits per 10 s going from about 377 to about 220, with the speed unchanged. A likely cause:admitDrawKey(DrawCache.cpp:87-95) admits an exact key at its first sight whenever its alias key was seen before, whether or not that shader set's alias lookups ever relocate. On a title where they never do (buffer bases move, the validation refuses), those entries never hit and push live ones out of the cache, which undoes #5216's protection. Please either gate that admission on the shader set's alias lookups actually hitting, or show with insert/evict counters that the drop comes from somewhere else, and add a case toagc_driver_draw_cache_relocationwhere the alias repeats but never relocates and the exact keys keep their hits.ShaderDiskCache.cpp:1506/:1514encode and decodeshaderDataUserWords; a test that encodes aRecompileResultwith non-empty words, decodes it and checks them would pin it.The conflict with
mainis mechanical; we'll rebase it ourselves once the above is settled. We have also taken over #494's rebase, so you don't need to coordinate with it.Imported from boykopovar/AnyPS5. Originally posted by JAB-dev on 2026-10-15T05:09:56Z.
Besiege (PPSA20313), this branch (
895d65498) against its merge base (84b01f9cd), Windows 11, RTX 4070 SUPER, 1080p: title screen 15.2 / 14.1 FPS on the base, 15.1 / 15.2 / 15.0 on this branch (no change; the 3-5% loss I measured on the earlier head is gone).Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T12:07:10Z.
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/Execution/include/Driver/Driver.hppL350core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppL82-83core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawCache.cppL105-106core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawCapture.cppL7, L149-168, L180core/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hppL350-351core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppL146core/shader/recompiler/ShaderDiskCache.cppL89-90core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawCapture.cppL57, L161-168core/shader/recompiler/Optimization/include/Optimization/SrtWalker.hppL4-5, L37core/shader/recompiler/ShaderDiskCache.cppL89-90core/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hppL350-351Some 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/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Draw/DrawCache.hppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawCache.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawCapture.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawDecode.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawRegisterKey.cppcore/shader/recompiler/Optimization/src/SrtWalker/SrtEvaluator.cppcore/shader/recompiler/Recompiler.hppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Dispatch/DispatchCache.hppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Draw/DrawCache.hppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Dispatch/DispatchCache.hppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Draw/DrawCache.hppcore/shader/recompiler/Recompiler.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Dispatch/DispatchCache.hppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Draw/DrawCache.hppcore/shader/recompiler/Recompiler.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Dispatch/DispatchCache.hppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Draw/DrawCache.hppcore/shader/recompiler/Recompiler.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Dispatch/DispatchCache.hppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Draw/DrawCache.hppcore/shader/recompiler/Recompiler.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Dispatch/DispatchCache.hppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Draw/DrawCache.hppcore/shader/recompiler/Recompiler.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Dispatch/DispatchCache.hppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Draw/DrawCache.hppcore/shader/recompiler/Recompiler.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Dispatch/DispatchCache.hppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Draw/DrawCache.hppcore/shader/recompiler/Recompiler.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Dispatch/DispatchCache.hppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Draw/DrawCache.hppcore/shader/recompiler/Recompiler.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Dispatch/DispatchCache.hppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Draw/DrawCache.hppcore/shader/recompiler/Recompiler.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Dispatch/DispatchCache.hppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Draw/DrawCache.hppcore/shader/recompiler/Recompiler.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Dispatch/DispatchCache.hppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Draw/DrawCache.hppcore/shader/recompiler/Recompiler.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Dispatch/DispatchCache.hppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Draw/DrawCache.hppcore/shader/recompiler/Recompiler.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawDecode.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawRegisterKey.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.hppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Dispatch/DispatchCache.hppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Draw/DrawCache.hppcore/shader/recompiler/Recompiler.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Dispatch/DispatchCache.hppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Draw/DrawCache.hppcore/shader/recompiler/Recompiler.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Dispatch/DispatchCache.hppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Draw/DrawCache.hppcore/shader/recompiler/Recompiler.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Dispatch/DispatchCache.hppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Draw/DrawCache.hppcore/shader/recompiler/Recompiler.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Dispatch/DispatchCache.hppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Draw/DrawCache.hppcore/shader/recompiler/Recompiler.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Dispatch/DispatchCache.hppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Draw/DrawCache.hppcore/shader/recompiler/Recompiler.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/shader/recompiler/Optimization/src/DescriptorBindingBuilder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawCapture.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawDecode.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawRegisterKey.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.hppcore/shader/recompiler/ShaderDiskCache.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Dispatch/DispatchCache.hppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Draw/DrawCache.hppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawCache.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawCapture.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawDecode.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawRegisterKey.cppcore/shader/recompiler/Optimization/include/Optimization/SrtWalker.hppcore/shader/recompiler/Optimization/src/SrtWalker/SrtEvaluator.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.hppcore/shader/recompiler/ShaderDiskCache.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Draw/DrawCache.hppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawCache.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawCapture.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawDecode.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawRegisterKey.cppcore/shader/recompiler/Optimization/src/SrtWalker/SrtEvaluator.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/shader/recompiler/Recompiler.hppcore/shader/recompiler/ShaderDiskCache.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/shader/recompiler/Recompiler.hppcore/shader/recompiler/ShaderDiskCache.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.hppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.hppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawDecode.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawRegisterKey.cppcore/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cppcore/shader/recompiler/Recompiler.hppImported from boykopovar/AnyPS5. Originally posted by TheAggie on 2026-10-15T16:09:59Z.
@adriadam10 thanks for the review. Both branches are rebased onto
main940eba9a2(#4943 is now 5 commits, #5609 is 8 on top of it, without #5906's two commits, which are merged). The three points:Performance of the stack against current
main. Flycast demo (Crazy Taxi attract mode), RetroArch PPSA99169, the same local support commits on both sides (the emulator needs them to run RetroArch; they are identical in both builds), immediate present, audio muted, alternating runs:main+ support (audio)Audio produced as a share of real time, unprofiled, about 9 points higher with the stack in every alternating pair.
Draw-cache hits on D2R. You were right about the admission. An exact key was admitted at its first sight whenever its alias had been seen, whether or not that shader set's relocations ever hit. That admission exists so a shader set can get a first entry to relocate from: after an alias-admitted insert, the next draw with the same alias hits through relocation and is never inserted. So the cost falls on aliases that come up exactly twice. Each such pair inserts an entry that becomes a donor nobody uses. The rule now:
trial.hitsnow counts only hits that validated through a relocated entry, not donors found;The new case in
agc_driver_draw_cache_relocation(UnrelocatedAliasesStayOut) draws 12 aliases that each appear exactly twice, interleaved with a repeated draw. With the old rule it inserts 12 entries; with the new one at most 2, and the repeated draw keeps all 12 of its hits. The test fails on the old rule (checked by restoring it). I haven't got D2R to confirm the hit count on a real title; @mrfelek, if you can rerun with this head, the[draw-cache]inserts/evictions lines would show it.Disk-cache round trip.
agc_shader_disk_cache's result round trip now setsshaderDataUserWordsand compares it after decoding (it fails if the decoder drops the words). Thestatic_assertsizes were re-checked after the rebase: I compiled the structs with MinGW's libstdc++ on x86_64, where all 31 asserted sizes match, including the ones this branch doesn't touch. RecompileResult is 496 and BindingAllocationResult 184 on #4943, and 520/208 on #5609.AI-assisted (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-16T03:52:11Z.
Linux results, since the description has no Linux build. Ubuntu 24.04, GCC 13.3, Release, RTX 4070 Ti, NVIDIA 595.99,
244f41ed2merged ontomain5d9dcc42d(clean merge).ShaderDiskCache.cpp.agc_shader_disk_cacheandagc_driver_draw_cache_relocationpass 3 of 3. The 469 tests matching^agc_driver_|^agc_vertex_barrier|recompiler|shader_cache|request_serializer|spirvgive 468 passes.agc_driver_store_over_untrackedfails the same way onmainhere (#6385).main. WithAPS5_TRACE_DRAW_CACHE, about 10,000 lookups per 10 s find no entry, and about 9,700 of those areuser words/pointers only. The data-only path then compiles about 18,000 to 25,000 stages per 10 s, against 1,000 to 7,000 reused. With this PR (warm caches, after one warm-up run), the same counters look the same: 2.3% hits,user words/pointers only9,714, 18,682 stages compiled against 1,086 reused. There is no[draw-relocate]line in 150 s, so it made fewer than 100,000 alias lookups. Presents per 10 s vary too much between runs on this title to show a difference either way. So these draws don't take the relocated path. Maybe their user words are also used as values, or the shader sets aren't learned. I haven't looked into which.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by LuisAguilarDev on 2026-10-16T06:08:19Z.
Field data from PPSA08587 (Dragon Ball Xenoverse 2), in case it helps the relocation path: in its heavy gameplay scenes, this PR finds no donors, and the scene stays at 6-12 fps.
Setup: Windows 11, i5-11400, RTX 3070 Ti (NVIDIA 610.88). Build:
main5d9dcc42d+ #6539 (which includes this PR at244f41ed2) + the title's own unrelated fixes. Run withAPS5_PROFILE_DRAW=1 APS5_TRACE_DRAW_CACHE=1 APS5_DRAW_CACHE_ENTRIES=32768.The miss is in user data
Each frame has ~1,300 draws at ~65 µs each on the queue worker; the worker is ~90% busy and the GPU ~35%. 10 s window:
[draw-relocate]never printed, because it only reports onceuserPatchesis non-empty.Where the relocation path stops
To find out, I added counters at each exit of the relocation path. They are local only and don't change behaviour. One line per 10 s in the heavy scene, with this PR as is:
drawDecodes.find(aliases.structure). No donor is ever learned, becauselearnPendingRelocationneeds the pending key to have been inserted, andadmitDrawKeyadmits only repeated keys, which these never are.Same scene, with probation and idle bypassed
I then bypassed both, locally: a key whose alias
structurewas seen before is admitted, and the trial never goes idle. I also setAPS5_NO_DRAW_STAGE_DATA_HITS=1, sotagBufferWordsruns. Stage data hits were 0 in this title anyway. Result:The probation and idle gates were not the root cause:
structureitself is new on 97% of draws (29434 new vs. 880 repeated). About 70% of captured stages fail eligibility atDrawCapture.cpp(decodeReads[i].empty() && resourcesNum == 0), because they have vertex fetch. My guess is that their per-draw user words then enterotherat their raw value, so the structure is unique per draw.So for this title, the gain would come from making stages with vertex fetch relocatable, when their fetch descriptors are reached through the moved pointer, and from looking into why so many aliases are unreadable. I can run a build from a branch or share the counter patch if that helps; the full logs are available too.
The analysis was done with AI assistance (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-16T09:19:56Z.
Review: APPROVED
Thanks for the update. Checked against our last review:
main940eba9a2(audio 34.5-35.7% → 42.8-45.7%) answer the performance point; the gain needs #5609 on top, so the two should land back to back.UnrelocatedAliasesStayOutfails when the probation condition is forced to always admit, and passes with the PR as is.agc_shader_disk_cachenow round-tripsshaderDataUserWords.On this head merged onto
main, the Agc/AgcDriver scope builds andagc_shader_disk_cacheandagc_driver_draw_cache_relocationpass here on Linux; thanks @milescoviello for the independent Linux run. Not verified by us: the D2R hit counts on this head (@mrfelek's last run was on the earlier one), and Windows runtime behaviour beyond CI. Merging once the full Build is green.