perf(agc): cache CPU-path indirect draws behind APS5_DRAW_CACHE_INDIRECT #9243
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9243"
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 fisherjoey on 2026-10-21T16:24:05Z.
What
cacheDrawStagesnever admits a draw that an indirect packet runs on the CPU path (drawParameters.indirect && indirectCpu), since29b460156: "the CPU path of an indirect draw recompiles on patched words below: nothing of it is kept". That is only half true. On the CPU path the front stage is materialized once with the packet's user words to classify the draw, then per record only the programs holding a patched word are materialized again, and the fragment stage is reused from the first pass. A title whose draws are mostly CPU-path indirect draws therefore looks up every draw and never inserts one, whatever the cache size. On Demon's Souls 97% of the draw packets areDRAW_INDEX_INDIRECTdraws whose record patches a user word the vertex program reads as a value, so the draw cache missed 92% of its lookups andAPS5_DRAW_CACHE_ENTRIES=32768did not move the hit rate.With
APS5_DRAW_CACHE_INDIRECTset,cacheDrawStagesadmits these draws like any other. A hit reuses the fragment stage and skips the first front-stage pass. The stage whose user word the record patches is still materialized once per record, which the hit path already provides for (materializeDrawStageadds the matched stages' regions whendrawHit). Nothing else changes: the key, the validation and the eviction are the ones direct draws use.The switch is off by default, so
mainbehaves as before without it. It stays a switch because a hit still pays the full word validation (about 15 us per lookup on the title below) and one materialization per record, so the gain on its own is small. The follow-up PR that forwards the record's word as push data removes the second cost. It has a row indocs/dev/ENVIRONMENT.md.Related, not overlapping:
DrawCache.cpp,Driver.hppand the test list near these lines. Whichever lands second needs a rebase.Tested
agc_driver_draw_cache_reuse_indirect(theagc_driver_draw_cache_reuse_testsbinary withAPS5_DRAW_CACHE_INDIRECT=1andAPS5_PROFILE_DRAW=1): threeDRAW_INDIRECTdraws whose packet patches a user word the vertex program reads as a value, so they take the CPU path (IndirectDrawPath::NotFolded, 3 of 3). With the switch they insert once and hit once; the existingagc_driver_draw_cache_reuse,_off,_verifyand_inlinevariants run the same draws without it and have to see no insert and no hit. All five pass on lavapipe (Mesa llvmpipe) and on the RTX 5070 Ti (ANYPS5_REQUIRE_VULKAN=1), on this branch at maincecb540a6, Linux, Release, GCC 16.2.RecordsKeepThePacketsFragmentWordin the same binary, run by all five variants: aDRAW_INDIRECT_MULTIwith two records on the CPU path, the first moving the triangle off screen through the vertex word the packet names, the second drawing it, with the fragment stage reading its own user word 0 as its color. Submitted three times with the word 0.75 (absent, insert, hit; 191 drawn), once with 0.25 (no hit, 64 drawn), twice more (insert, hit), then with 0.75 again (hits the first entry, 191 drawn). A record never patches a fragment word (UserDataWordsskips the fragment role) and the fragment word is part of the key; the test pins both. Passes in all five variants on lavapipe and on the RTX 5070 Ti.ctest -R agcon lavapipe,ANYPS5_NO_SHADER_CACHE=1: 857 of 858 pass. The one failure isagc_driver_multisample_retirement(MSAA storage promotion did not retain its source image), which passes on the RTX 5070 Ti. It does not set the switch and does not reach the draw cache, and it fails the same way on lavapipe with amaincecb540a6build, so it comes from main (MSAA retirement,adc46f3ea), not from this change. The 24 draw-cache, draw-data-hit, key-miss, register-key and indirect-draw tests pass on the RTX 5070 Ti. The Khronos validation layer is not installed here, so the validation-layer comparison againstmainis not done.python3 tools/check_conventions.py --base origin/mainpasses.libSceAgcDriver.prx. The numbers are medians over the level windows (10 s each, 56 to 68 per run), judged from the[packets],[draw]and[draw-cache]profile lines.main. The base was main676269473plus #6280, #6926, #7844, #8047, #7984, #7981, #7930, a local stencil-export workaround this GPU needs to reach the level (never upstream), and two local diagnostics that were off. The change arm was the same set with this PR's driver andAPS5_DRAW_CACHE_INDIRECT=1.[draw]106.2 vs 108.6 us per packet (-2.2%, no overlap). Capture plus recompile 25.0 vs 35.2 us per packet. GPU busy flat (162.8 vs 163.1 ms per present), drains and committer flat, screenshots clean.perflabel asks for are not attached yet. A capture pair (APS5_TRACE_SECONDS, same scene, base and change) follows as a comment.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); this change adds no stubs.mdfiles or images added to the repository (attach them to this PR)AI-assisted: yes
Performance summary lines
mainand this change, same machine and scene. The full captures, traces and digests are in https://github.com/boykopovar/AnyPS5/pull/9243#issuecomment-6326683722.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-21T16:24:23Z.
This pull request is labeled
perf, so it needs the summary line of a capture onmainand one with the change, from the same title, scene and machine, as the Performance report form asks. Please paste bothaps5-summary.jsonllines, attach the two traces and add the output oftools/trace_digest.py.Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-10-21T17:42:53Z.
Review: COMMENTED
The diagnosis is good (97% of Demon's Souls draw packets are CPU-path indirect draws, so the draw cache missed 92% of its lookups whatever its size) and the evidence is honest about the size of the win. It argues against merging the switch by itself.
mainplus seven open PRs and a local stencil-export workaround. The change arm differs only inlibSceAgcDriver.prx, which is the right design, but the base isn'tmain, and the summary lines and traces theperflabel asks for "follow as a comment". Please attach them, with the A/A spread of the setup, so +1.5% can be told from drift.Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-21T17:44:48Z.
I checked the PRs the overlap bot named by trial-merging each head onto this branch (
git merge-tree, no build). None of them does what this PR does.cacheDrawStagesline and inmain()ofDrawCacheReuse.cpp. Resolution: keep its newstageDataparameter plus this PR'sdrawCacheIndirect()condition, and putCpuPathIndirectDrawsAreCachedWhenAskedin itselsebranch. With both merged, itsAPS5_VERIFY_DRAW_ENTRIEScheck also runs on admitted CPU-path indirect entries. Those are inserted before the record loop, from the packet's words, so I don't expect either side to need a change. I haven't run that combination.DrawCache.cpp; keep both. Admitted indirect entries go throughinsertDrawEntry, so its byte bound already counts them.Either order works; whichever lands second takes the resolutions above.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-21T18:54:34Z.
Thanks for the read. Three answers, in your order.
On landing it with the push-data follow-up: the follow-up is #9248, open, "Depends on #9243". It forwards the record's patched word as push data instead of materializing the stage per record, and on the same 3v3 method (same title, same level, alternating arms, measuring mode, 900 s) it measures 11.87 vs 10.76 presents per 10 s (+10.3%; 11.91, 11.66, 12.05 vs 10.84, 10.62, 10.82) and 798.5 vs 884.4 ms queue 0 per present (-9.7%). #9248 now sits on this branch's head. If you would rather review one PR, say so and I fold #9248 into this one; I have not done that on my own.
On the base, the summary lines and the A/A spread: agreed that the base is not
main. Captures onmainfollow as a comment once the sets are rebuilt: they will bemainplus the local stencil-export workaround (needed to reach the level on this GPU) plus the #6280 mip clamp. Today's first capture session onmainplus the workaround alone stopped on an Xid 31 that, going by the log and the kernel line, is the known copy-past-the-image fault #6280 clamps (a 4x1 BC3 array T# naming 8 mip levels,vkCmdCopyBufferToImageon the copy engine); the same signature has hit three times before on sets without the clamp and never on sets with it, including this PR's 3v3 runs. So the clamp goes into both capture arms and the pair is re-run; one valid capture of the change arm exists, none ofmainyet.A/A numbers from the same setup (steady presents per 10 s and queue 0 ms per present, medians over the level windows, measuring mode, 900 s each):
So +1.5% is about the size of the within-session spread and well inside the drift between sessions. The alternation is what makes it readable, and I would not claim more for it than "small, same sign in every pair". The number that moves without ambiguity is the hit rate.
On the fragment stage: a record never patches a fragment-stage word, with or without the switch.
UserDataWords(DrawDecode.cpp) resolves the packet's base-vertex, start-instance and draw-index register locations into (program, word) pairs and skips theFragmentandGeometryBackroles; the packet names registers in the front stages' user-data ranges, the fragment stage's user words live in their own range. What the fragment stage does read as a value is its own user word, which the packet sets, and that word is in the key either way: the draw key mixes every program's user words (DrawLookup.cpp), the register key hashes the user-data registers of all three ranges (forEachKeyedUserWordinDrawRegisterKey.cpp), and a data-only hit refuses a stage whose changed word is in itsuserDataMask. The captured-word validation and the LRU eviction are the ones direct draws use; this PR does not touch them. The reuse itself is whatmain's miss path already does: the fragment stage is materialized once with the packet's words and used for every record of the packet.That was by reading, so there is now a test for it,
RecordsKeepThePacketsFragmentWordinDrawCacheReuse.cpp, run by all fiveagc_driver_draw_cache_reuse*variants (with and without the switch). ADRAW_INDIRECT_MULTIwith two records takes the CPU path: the first record moves the triangle off screen through the vertex word the packet names, the second draws it, and the fragment stage reads its own user word 0 as its color. The draw is submitted three times with the fragment word 0.75 (absent, insert, hit; 191 drawn), then with 0.25 (must not reuse the entry: 64 drawn, no hit), twice more (insert, hit; 64), then back to 0.75 (hits the first entry; 191). It passes on lavapipe in all five variants, and in all seven on #9248 rebased onto it. The GPU here is held for the fault above today, so the RTX run of the new test follows with the captures. The Tested sections of both PRs say which runs are lavapipe-only.On the default: the switch stays off while a hit still pays one materialization per record. The condition I would propose for flipping it is #9248 merged, then full level runs of the pair with
APS5_VERIFY_DRAW_ENTRIESandAPS5_VERIFY_DRAW_PUSH_WORDclean on Demon's Souls, and no regression from at least two other titles run with both switches by people who have them. I only have the one title here, so that last part needs other hands, and I am fine with the switch staying opt-in until then.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-21T21:13:24Z.
Captures for the
perflabel, onmain. Demon's Souls PPSA01341 v1.07, in the first level, 1920x1080, Linux (Nobara, kernel 7.2), RTX 5070 Ti, driver 595.91.07. Four 900 s runs from boot into the level, one session, in this order: main, this PR, #9248, main again. The window isAPS5_TRACE_SECONDS=400:60(60 s from t+400 s, level loaded).Setup
cecb540a6plus the local stencil-export workaround (this GPU needs it to reach the level, never upstream) plus the #6280 mip clamp. Without the clamp, main hits the Xid 31 from my earlier comment (a 4x1 BC3 array T# naming 8 mip levels). The trace's commit field, 3e72d893778d, is that local build. dd46b3e09585 is the same tree plus this PR's head b2b765ad4; ab0687554423 adds #9248's head b0442fbd8 on top. Each set differs from main only inlibSceAgcDriver.prx(checked with an aps5-libs diff: exactly one file).APS5_TRACE_*orAPS5_PROFILE_*switch. The otherAPS5_*values in the env field (memory caps,APS5_IGNORE_STENCIL_EXPORT,APS5_GPU_MEASURING, the lock name) are the same on all four arms.trace_dropped: truein all four: the event buffer ofqueue worker 0x0filled after 10.2 to 12.6 s (1.0 to 1.3 M events lost,totals_full: false). The per-slice tables for that worker in the digests cover the first 10 to 13 s of the window; the totals in the summary line (frame_ms,top_phases_ms_per_frame,worker_busy_pct) are not marked full, and the phase comparison below uses those.Summary lines (
aps5-summary.jsonl, verbatim: main run329, this PR run330, main again run332; #9248's run331 is on #9248)Traces (a release on my fork; the assets keep their
aps5-trace-<commit>-<pid>.json.gznames and open in ui.perfetto.dev)Frame times (ms, the 60 s window)
APS5_DRAW_CACHE_INDIRECT=1APS5_DRAW_CACHE_PUSH_WORD=1A/A spread of the two main captures: p50 43 ms (3.6%), p90 131 ms, presents 50 against 48.
Reading, with the mean of the two mains (p50 1204.5) as the reference:
mainit is not a win.Where the frame goes, from
top_phases_ms_per_frame(ms per frame, summed over threads) and the digest's thread tableWhat the digests show:
mainthe frame is queue 0.queue worker 0x0is 99.5% busy in all four captures. Draw plus dispatch summed over the workers is 1250 to 1350 ms per frame against a p50 of 1170 to 1270, and most of it sits on that worker. The seven other queue workers spend 95 to 100% of the frame inDriver.Packet.memory_wait(about 0.88 of the frame each; 7342 of the 8670 ms of Driver.Packet on run329), and the largest slice in each of the five slowest frames of every capture is a memory_wait onqueue worker 0x30, 1.36 to 2.02 s. memory_wait is 6.0 to 6.2 times p50 on all four arms, so it is the other queues waiting for the frame, not a stall of its own. The GPU is 12 to 13% busy. A draw-path change has to show on queue 0 to show at all.main. Driver.Draw is 927 ms per frame against 894 and 920 on the two mains. Inside it,Shader.DrawStagedrops 18% (321 against 380 and 405; that is the first front-stage pass a hit skips), butDriver.Draw.draw_enqueuedis up 18% (500 against 426 and 424),Driver.Packet.dispatchsits at the top of the main range (419 against 374 and 409), and the draw committer'sGraphics.Drawis up on its own thread (181 against 136 and 155 ms per frame, most of itdraw_and_resource_release). The saving and the extra cost cancel, which matches what the description says a hit still pays: the word validation and one materialization per record.Driver.Packet.dispatchdoes not move (414), and the committer stays above main (169). Against this PR the frame moves by about the Driver.Draw delta (-96 ms Driver.Draw, -100 ms p50); against main it moves by less (-75 ms Driver.Draw, -32 ms p50, with dispatch +23 ms of the difference).mainthe frame is about 1200 ms and queue 0 is busy for all of it. The digests say where main's frame goes, not which of the stack's PRs account for the shorter queue 0 there, so I am not claiming that here.On the review's first point: this agrees with it. On plain
mainthis switch alone is not worth landing; the change you can measure comes with the push-word forwarding. The offer stands: say so and I fold #9248 into this PR, so there is one PR to review with one capture pair. Otherwise they stay stacked as they are.Digests, made with
tools/trace_digest.pyon each trace. The JSON block is the summary line above; the title-thread rows and the GPU batch list are left out for length.trace_digest.py, run329, main 3e72d893778d
seconds 400:60 from present 2883: 50 presents, frame p50 1183.1 / p90 1376.2 / p99 1632.9 / max 1632.9 ms, GPU busy 155.4 ms per present
NVIDIA GeForce RTX 5070 Ti, NVIDIA 595.91.07, Linux 7.2.0-202.nobara.fc44.x86_64, 1920x1080, commit 3e72d893778d, dropped: yes
Slowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 7662.2, Driver.Packet.memory_wait 7340.8, Driver.WorkerWait 963.2, Driver.WorkerWait.idle_and_completion_poll 963.1, Driver.Packet.dispatch 165.7, batch 155.4, Graphics.Draw 152.2, Driver.Packet.draw 146.0, Driver.Draw 145.6, Graphics.Draw.draw_and_resource_release 119.3
Longest waits
trace_digest.py, run330, PR 9243 dd46b3e09585 (APS5_DRAW_CACHE_INDIRECT=1)
seconds 400:60 from present 2403: 47 presents, frame p50 1271.8 / p90 1519.6 / p99 2048.9 / max 2048.9 ms, GPU busy 156.5 ms per present
NVIDIA GeForce RTX 5070 Ti, NVIDIA 595.91.07, Linux 7.2.0-202.nobara.fc44.x86_64, 1920x1080, commit dd46b3e09585, dropped: yes
Slowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 8144.9, Driver.Packet.memory_wait 7788.9, Driver.WorkerWait 1052.0, Driver.WorkerWait.idle_and_completion_poll 1051.9, Graphics.Draw 194.1, Driver.Packet.dispatch 192.2, Graphics.Draw.draw_and_resource_release 162.4, batch 156.5, Driver.Packet.draw 151.9, Driver.Draw 151.4
Longest waits
trace_digest.py, run331, PR 9248 ab0687554423 (APS5_DRAW_CACHE_INDIRECT=1 APS5_DRAW_CACHE_PUSH_WORD=1)
seconds 400:60 from present 2312: 52 presents, frame p50 1172.3 / p90 1415.7 / p99 1536.4 / max 1536.4 ms, GPU busy 156.7 ms per present
NVIDIA GeForce RTX 5070 Ti, NVIDIA 595.91.07, Linux 7.2.0-202.nobara.fc44.x86_64, 1920x1080, commit ab0687554423, dropped: yes
Slowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 7399.7, Driver.Packet.memory_wait 7023.3, Driver.WorkerWait 1027.7, Driver.WorkerWait.idle_and_completion_poll 1027.6, Driver.Packet.dispatch 197.2, Graphics.Draw 186.3, Driver.Packet.draw 165.9, Driver.Draw 165.6, batch 156.7, Graphics.Draw.draw_and_resource_release 153.7
Longest waits
trace_digest.py, run332, main again (A/A) 3e72d893778d
seconds 400:60 from present 2351: 48 presents, frame p50 1226.0 / p90 1507.5 / p99 1802.5 / max 1802.5 ms, GPU busy 153.8 ms per present
NVIDIA GeForce RTX 5070 Ti, NVIDIA 595.91.07, Linux 7.2.0-202.nobara.fc44.x86_64, 1920x1080, commit 3e72d893778d, dropped: yes
Slowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 7995.5, Driver.Packet.memory_wait 7649.4, Driver.WorkerWait 1053.6, Driver.WorkerWait.idle_and_completion_poll 1053.5, Driver.Packet.dispatch 183.5, Graphics.Draw 169.7, batch 157.1, Driver.Packet.draw 150.1, Driver.Draw 149.5, Graphics.Draw.draw_and_resource_release 136.8
Longest waits
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T12:00:37Z.
Review: DISMISSED
I reviewed the new coverage, including
RecordsKeepThePacketsFragmentWord, which does exercise the case where the packet-patched word is also read by the fragment stage. The updated performance report now supplies the requested same-machinemain/PR/#9248 captures and A/A spread; the report check passes.The branch still needs a current-main refresh before this change can be re-reviewed. Its measurement base is
cecb540a6; currentmainis0f8da39a, and the compare reports 1,491 commits ahead. More importantly, current main changed the same draw-cache files:Driver.hpp,DrawCache.cpp, andDrawCapture.cpp, adding shape-entry replacement andshapeNeedsEntryhandling alongside the cache-admission path this PR changes. Please rebase/merge current main, preserve those semantics while applying the indirect admission condition, and rerun the focused draw-cache tests withAPS5_DRAW_CACHE_INDIRECTboth unset and set. The merge preview being clean does not validate this interaction.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T06:01:13Z.
Review: CHANGES_REQUESTED
Re-checked — changes requested
What I checked
949c9cf477ce8857fedc2683a560a2fe23dd91bdagainst fetchedmain2960e9a6e7. The current-main merge preview andgit diff --checkpass.shapeNeedsEntry/replaceShapebehavior, and the author reports 59 focused draw-cache tests passing with the switch both unset and enabled. Hosted Windows and conventions checks pass; product Linux and specialized jobs were skipped. I did not run GPU tests locally.Blocking items
perf, but the current description still lacks the required pairedaps5-summary.jsonllines for the same title, scene, and machine, attached baseline/change traces, andtools/trace_digest.pyoutput. The older capture data and trace filenames do not meet that report checklist; please add the required artifacts from the current head and currentmain.Depends on. Please coordinate with #5609’s author and record the order.main. Please refresh and rerun the focused draw-cache tests and the required performance pair on that integration head.The 59/59 test result is author-reported from the earlier base
3a40945e6; no local GPU tests were run. I cannot approve until the performance evidence, overlap order, and current-head validation are complete.