perf(agc): draws that differ only in user data reuse their shape's decode and stages #494
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/494"
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-04T09:11:12Z.
What
Split out of #291, as discussed there. It builds on #493 (merged), which keys draws on the user words each stage reads.
A draw that misses the cache often differs from an earlier draw only in user data, for example a per-object constant buffer pointer. Such a draw decoded and compiled from scratch. Now:
APS5_NO_DRAW_DATA_HITS=1disables it.APS5_VERIFY_DRAW_DATA_HITS=1also decodes and compiles everything in full and throws when the results differ.APS5_TRACE_DRAW_CACHEcounts why keys missed (new registers, user words only, evicted, never inserted), and the profile line counts data-only hits and reused or compiled stages.#291's time-based failure memo is not part of this: #422 memoizes source failures already, and a skip that ends on a timer isn't exact.
Tested
Windows 11 Pro, AMD Ryzen 5 7600, NVIDIA GeForce RTX 5080 (driver 32.0.16.1074), 32 GB DDR5-5600, MinGW-w64 GCC 15.2.0.
ctest: everything that passes onmainhere passes.maina56c905df(2026-10-13), starting from gjonn's rebase of this series onto6ac63bf0c(thanks). On Windows (MinGW GCC 15.2, RTX 5080) the wholeagc_*suite passes on the top of the series: 483 tests, 1 skipped (agc_driver_stencil_ref_export).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🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T09:52:56Z.
Thanks, the data-only path reads right to me. The same shape means the same registers apart from the user words and merged pointers, the copied decode re-reads exactly those, and a stage is only reused when its own user words are unchanged and its captured reads validate. So the result should match a full decode and compile.
Two things before I'd take it:
insertDrawEntryruns whether or not data hits are on:cacheDrawStagespasses the shape whenever the register key is used. So withAPS5_NO_DRAW_DATA_HITS=1, a new key of a shape still erases the previous key's entry, and the draw then decodes and compiles in full. That's worse than main rather than the old behaviour. Could the shape (and so the supersede) only be passed whendrawDataHits()is on?APS5_TRACE_DRAW_CACHEcounters (superseded, data-only hits, stages compiled) from a run of this split version, plus one run withAPS5_VERIFY_DRAW_DATA_HITS=1, would show whether keeping the previous entry and only pointing the shape at the newest key works better.A small one: this commit drops
<algorithm>and<array>from DrawRegisterKey.cpp while it still usesstd::minandstd::array. It builds through other headers, but I'd keep them.Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-05T15:40:41Z.
Thanks. Both points and the includes are done in 795b8bc9, on top of a rebase onto current
main:drawShapes) is only passed toinsertDrawEntrywhendrawDataHits()is on. WithAPS5_NO_DRAW_DATA_HITS=1nothing is keyed by shape, so it behaves like #493 alone.APS5_DRAW_CACHE_ENTRIES), and an evicted key's shape link is dropped as before.DrawRegisterKey.cppkeeps<algorithm>and<array>.The rebase had one conflict:
main's null pixel program (#469) reads RSRC2 as 0 when it's unset, and this PR had moved that read intoreadUserWords.DrawProgramnow carriesnullPixel, so the data-only path re-reads the user words the same way.I haven't measured the
APS5_TRACE_DRAW_CACHEcounters or aAPS5_VERIFY_DRAW_DATA_HITS=1run in GTA V on this version yet. I'll post both here once I have them. Build and ctest are clean apart from the failuresmainhas locally (agc_driver_f32_output_modifier,agc_driver_scalar_sop1and the relinker Python tests). #493 is rebased too, with its commit unchanged.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-06T05:34:18Z.
Thanks, both points are done in 795b8bc9. The shape is only passed when
drawDataHits()is on, soAPS5_NO_DRAW_DATA_HITS=1doesn't touch shapes at all. And with the supersede gone, a shape's earlier keys keep their entries, under the normal LRU.It conflicts with main now in
DrawCacheStatistics.cpp: #798 moved the periodic reports off the GPU workers and replaced thestd::fprintf(stderr, ...)calls withAgcDriver::ProfilePrint_nid_no_patch(...). Keeping yourtextassembly (withprofileDrawCacheLines) and printing it throughProfilePrint_nid_no_patch("%s", text.c_str())should resolve it.Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-06T15:29:23Z.
Rebased onto current
main(now 9f52b1ed). TheDrawCacheStatistics.cppconflict is resolved as you suggested: thetextassembly withprofileDrawCacheLinesstays and goes out throughProfilePrint_nid_no_patch("%s", text.c_str()). Its two profile lines are the same format strings asmain's, and the PR adds no otherstderrreports. Builds; the driver tests pass apart fromagc_driver_scalar_sop1, which fails without this PR too.Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-07T08:17:20Z.
Rebased onto current
main(now 35c8550e). One conflict, inDrawDecode.cpp: #1037 made unwritten user-data registers read as zero (readUserData) in the loop this PR moves intoreadUserWords.readUserWordsnow usesreadUserData, so the full decode and a data-only hit's refresh read the same words. #493's commit is still included first. Builds; the driver tests pass apart fromagc_driver_scalar_sop1(fixed by #928).Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-07T17:31:16Z.
Rebased onto current
mainand the rebased #493 (now cf9195e6), no conflicts. The draw-path PRs #1191, #1193, #1201 and #1202 build on this one. Build and ctest pass.Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-09T08:32:01Z.
Closing: superseded by #639. Prepared artifacts no longer depend on user data (it is read at runtime from the shader data block), so draws that differ only in user data already share one shader, which is what this PR added.
Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-09T08:32:34Z.
Reopening, I closed this too quickly: #639 removes the per-draw compile, but the decode reuse and the captured-stage reuse for draws that differ only in user words still apply. Parked as a draft until it is ported onto the prepared-shader path.
Imported from boykopovar/AnyPS5. Originally posted by Mouhand-Kaddo on 2026-10-10T10:22:37Z.
Additional platform validation of standalone PR head
7f13b7274f9ba5f6c9a1113f8b15d1ee849c1f6e(2026-10-11):Linux: passed — Arch Linux in WSL2 (kernel 6.6.87.2), GCC 16.2.1 20260810; CMake 4.3.1 / Ninja; Release,
BUILD_TESTING=ON.3 checks, 0 failures, 0 CTest skips. Built the selected targets and dependencies; this is focused validation, not a full build or full-suite run.
Checks:
agc_driver,agc_driver_pm4,agc_driver_graphics.Command after building:
ctest --test-dir <build> --verbose --no-tests=error --timeout 30 -R "^agc_driver($|_graphics$|_pm4$)".Vulkan: Mesa lavapipe 26.2.4 / LLVM 23.1.1 software Vulkan; no native Linux hardware-GPU result.
Internal limitation: heap-mirror subcases returned early because the guest arena was not write-watched in WSL. Zero CTest skips does not include that early return.
Focused driver, PM4 and graphics regression checks passed. No title replay, frame-time measurement, or comparison of draw-cache hit counters was performed; this does not quantify the performance gain.
No title/gameplay validation. These results cover the standalone head, not a merge with current main.
Imported from boykopovar/AnyPS5. Originally posted by Raghav314 on 2026-10-11T04:10:13Z.
Tried this with Hades II (PPSA36082) on my machine, rebased locally onto current main plus the stuff the game needs to get in game. The data-only hits fire a lot there, but almost none of them actually reuse a stage. Standing in the hub, every 10 s about 215k draws find their shape, yet only ~7k stages get reused and ~420k get built again.
I dumped what the rebuilt stages look like next to the kept variant. Around 186k of them read the exact same runs and come out with the same variant, bindings and push constants. The only user word that differs is word 8 of the sprite vertex shader, a small per-draw value (0x0c to 0x33) that the stage never reads. The candidate check in
lookupDrawdrops a stage as soon as any user word differs, so these never even get validated.So locally I made the check compare only the user words a stage reads:
GetUserDatacase ofBasicEvaluator::EvaluateInst, through a mask pointer onSrtRuntime)materializeResultadds the registers copied into the shader data (layout.userDataRegisters)DispatchVariant, andlookupDrawonly requires those words to match. Runs and words are still validated like before. If the walk reports nothing, every word counts.For the sprite shader that ends up as words 2-3 plus the fetch tables. I checked it with
APS5_VERIFY_DRAW_DATA_HITS=1: 145k reused stages per 10 s built again and compared, no mismatches. Then without verify:The fps is from two separate runs so I wouldn't read too much into it, the per-packet time is the better number.
The other big group (~248k per 10 s) is different: word 2 is a per-sprite pointer and word 4 a per-frame constant ring that moves by 0x200000 every frame. Both get copied straight into the push constants and the walk reads at the new addresses, so the stage really does change. Reusing those would need the push constants rebuilt from the new words and some proof that the pointer only feeds addresses, which I didn't try.
One thing to know if you want to do the mask: it adds a field to
ShaderInvocation, so the disk cache encoder and format version need a bump. Can share the diff if it helps.LLM assistance used.
Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-11T07:59:38Z.
@Raghav314 thanks, that's a good measurement, and the per-stage read mask is the right shape for it. This PR is parked as a draft, so please open your mask as its own PR on main rather than waiting on this one (with the disk cache format bump, and the
APS5_VERIFY_DRAW_DATA_HITSrun as its evidence); it doesn't depend on #494.Imported from boykopovar/AnyPS5. Originally posted by Raghav314 on 2026-10-12T01:03:47Z.
@MichonGoddijn231849 thanks. I looked at doing that, but on main the mask has nothing to attach to. It filters the data-hit candidates in
lookupDraw, and that path comes from this PR. Main's draw path has no data hits. Its draw key hashes every user word (DrawLookup.cpp), so a sprite draw whose unread word 8 changed is just a miss, before any stage gets looked at. Masking the key instead doesn't work, because the mask is only known after the stage has been built.APS5_VERIFY_DRAW_DATA_HITSis also from this PR (main only hasAPS5_VERIFY_DATA_HITSfor compute).So on its own against main it would record the reads and never use them. The whole gain I measured was on draws (the sprite vertex shader), and I have nothing showing it helps main's compute data hits.
I'll open it as a PR on top of this one instead (12 files, +35/-4, including the disk cache format bump and the
APS5_VERIFY_DRAW_DATA_HITSrun).LLM assistance used.
Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-12T19:11:23Z.
Another data point, from Planet of Lana (PPSA19450) on Windows 11, MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, RTX 3070 Laptop. I rebased this onto
maind146ec1b6and again ontoc36fd0a0e.agc_driver_draw_cache_reusepasses on both.APS5_VERIFY_DRAW_DATA_HITS=1, 240 s through the menus, a cutscene and gameplay, plus 300 s on the second rebase, gave no mismatch and no throw.APS5_NO_DRAW_DATA_HITS=1, with Lana standing in the first village andAPS5_PROFILE_DRAW=1. With data hits, the decode drops from 13-14 to 6.0 us per draw, and the draw packet from 140.5 to 130.4 us.[draw-cache] register keyreports the decode skipped for 63,186 of 63,195 draws. The frame rate went from 71.2 to 75.1 presents per 10 s, but single runs on this PC vary by ~15%, so I wouldn't read anything into that.Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-13T15:45:47Z.
Rebased onto current
main(a56c905df) as one commit, from @gjonn's rebase of the series (main's free-function decoder with its static-ABI mode; main's incremental register key is the shape key now).agc_driver_draw_cache_reuseand the rest of theagc_*suite pass on Windows.@EagleBearerYS thanks for the Planet of Lana numbers. @Raghav314 your per-stage read mask can go on top of this head now.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T00:10:26Z.
Thanks for the rebase. #5216 now conflicts here, and not only in text: a key gets its entry at its second sight, so a shape whose keys never repeat (per-frame user data) never gets an entry and its data-only hits never start. Before this goes in:
agc_driver_draw_cache_reusethat fails on main (a draw that differs only in user words reuses the decode), and the summary lines of main and of this change from one machine and scene, as CONTRIBUTING asks.If you'd rather we do the rebase over #5216, say so and we'll push it to your branch. #4943 changes the same lookup.
Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-14T08:36:05Z.
Yes please, if you can do the rebase over #5216 (and #4943) that's the cleaner way, since you know the new lookup. The admission rule I'd take: a key is admitted at its first sight when its shape already has an entry or was seen before, otherwise at its second sight as #5216 does. Remembering shapes in the same sightings table (or a small one next to it) keeps #5216's protection for keys that never repeat in shapes that also never repeat, and lets a shape whose user data changes every frame get its first entry on its second draw.
Once it's on the branch I'll add the
agc_driver_draw_cache_reusecase (a draw that differs only in user words reuses the decode; it fails onmain) and the summary lines ofmainand of the change from one machine and scene.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T20:30:16Z.
Taking the rebase onto #5216 (with the shape admission rule above and a case in
agc_driver_draw_cache_reuse) from here, so it isn't done twice.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T21:05:20Z.
Took over the rebase onto #5216, as announced. Pushed on top of your commit:
Draw.cpp(stageEntries/compiledStagesfrom main, your data-candidate reuse kept).ReadUserWordsnow recomputestailContinuationtoo, so a data-only hit refreshes it.sameDecodecompares it.DrawKeySightingstable.agc_driver_draw_cache_reusegets a new case,UserDataDrawsReuseTheirShape:agc_driver_draw_cache_reuse_verify, runs it withAPS5_VERIFY_DRAW_DATA_HITS=1.agc_driver_draw_cache_reuse,_offand_verifypass on RADV. The in-title numbers above were all measured before #5216. A before/after on one scene with this head would still be welcome. Merging once the Windows build is green.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-14T21:11:11Z.
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/src/Driver/Draw/Draw.cppL8core/libs/prx/libSceAgcDriver/Execution/include/Driver/Draw/DrawRegisterKey.hppL8core/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hppL130-131core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppL72-83core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawRegisterKey.cppL36, L63, L66-67core/libs/prx/libSceAgcDriver/CMakeLists.txtL1616core/libs/prx/libSceAgcDriver/tests/execution/DrawCacheReuse.cppL106, L129core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawDecode.cppL35-39