perf(agc): prepare pipelined draws on a thread pool #6949
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6949"
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 alfalfa-star on 2026-10-16T20:50:48Z.
What
With pipelined draws, every queue-0 draw is still prepared on the packet worker: shader captures, resource materialization and draw-cache lookups run one draw at a time before the draw is queued for the committer. In Kena: Bridge of Spirits (PPSA01802) the forest scene issues around 30,000 draws per second, and this preparation is the CPU bottleneck that keeps the title far below 30 fps.
APS5_DRAW_PREP_THREADS=N(N > 0) prepares queue-0 draws on a pool of N threads:APS5_DRAW_PREP_AFFINITY_MASKoverrides), and the committer to the queue workers' cores.The pool is off by default; nothing changes unless
APS5_DRAW_PREP_THREADSis set.Tested
AMD Radeon RX 9070 XT (RADV GFX1201), Mesa 26.2.4, Arch Linux (kernel 7.2.9), Kena: Bridge of Spirits (PPSA01802).
agc_driver_tessellationsegfaults on main with and without this change).APS5_DRAW_PREP_THREADS=4: the pool prepares about 300,000 draws per 10 s with ~20 in flight. Together with the other work in our local test stack it brings the forest scene to about 24 fps. A measurement of this change alone on top of main will 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 github-actions[bot] on 2026-10-16T21:04:31Z.
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/Draw/DrawPipeline.hppL39core/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketExecution.cppL34core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawPipeline.cppL2-3, L119core/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketExecution.cppL175-176core/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketExecution.cppL175-176core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppL4core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawPipeline.cppL68, L179-180core/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketExecution.cppL175-176core/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketExecution.cppL175-176Some 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/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketExecution.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketExecution.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketExecution.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/shader/recompiler/Optimization/include/Optimization/SrtWalker/SrtEvaluator.hppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketExecution.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Draw/DrawPipeline.hppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawPipeline.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketExecution.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/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/DrawPipeline.hppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawPipeline.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketExecution.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/shader/recompiler/Optimization/include/Optimization/SrtWalker/SrtEvaluator.hppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/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/DrawPipeline.hppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawPipeline.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketExecution.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Draw/DrawPipeline.hppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawPipeline.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketExecution.cppImported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-10-16T21:58:33Z.
Review: COMMENTED
Off by default, but this is a concurrency design with correctness risks and no test or measurement yet.
const Submission* pooledSubmission = &submission;is used inside the pool job (materializeDrawStage(..., *pooledSubmission, ...)) afterdraw()has returneddrawn(). Nothing in the diff shows what keeps thatSubmissionalive until the job has run. If it is a stack or per-submit object, the job reads a dead object once the worker moves on. Say what guarantees the lifetime, or copy what the job needs intoPooled.detach()ed from a leakednew DrawPrepPool()with no stop path. AtAgcDriverShutdowna job can still be running againstthis(the Driver) and the device it captured. Shutdown has toWaitAll()before teardown, and the pool has to be stoppable.poolMiss/poolSeenblock runs on every draw when the pool is on: eight atomics, astd::all_ofoverdataCandidates, the verify and trace probes, and a stderr line every 100k draws. It is diagnostic code in the hottest function. Please remove it or put it behind a profile switch.Enqueue,Drain,PendingLabelandOverlapsnow callWaitAll(), and so does every packet that is not incommutesWithPreparedDraws. Each of those collapses the pool back to the single-threaded path for that stretch. The[prep-pool]line already countswaitAlls; please post it, since it decides whether four threads buy anything in a title that interleaves labels or DMA with draws.WrittenBetween) redoes the whole preparation. That doubles the CPU cost on exactly the draws that depend on each other. Post theredosratio from the same run.APS5_DRAW_PREP_AFFINITY_MASKset to the P-cores. Also, "about 20 in flight" cannot come fromAPS5_DRAW_PREP_THREADS=4:maxInFlightiscount * 3= 12.SrtEvaluator.hppdropsexplicitfromIrNode(IrValue*). That makes everyIrValue*convert implicitly toIrNodeacross the recompiler, in a header that has nothing to do with this topic. Revert it, or say why the pool needs it.WaitAllat drain are all untested, and each is a place where a race gives wrong pictures instead of a crash. A test that runs two dependent draws (the second reads what the first writes) through the pool, once with the conflict and once without, would cover the redo.APS5_DRAW_PREP_THREADSunset and set, same scene in PPSA01802, noAPS5_PROFILE_*.Imported from boykopovar/AnyPS5. Originally posted by parl0v on 2026-10-16T22:13:56Z.
Data point from a CPU-bound scene on Windows: RTX 3060 12 GB (NVIDIA 617.42), i5-12400F, Windows 10 19045, MinGW GCC Release. Minecraft Dungeons II (PPSA16064 01.100.100), title screen, no input, 200 s rows,
APS5_PROFILE_DRAW=1 APS5_PROFILE_GPU=1;mainbc3c0fc13vsmain+ this PR, interleaved with five other PRs in one batch, two rounds. FPS is the mean of the last 10[present]windows, GPU busy and idle gaps per frame over the last 8. This scene is CPU-bound on this machine (45-47 ms of idle gaps per frame).maine2d9ac88c)Within the run-to-run spread (about ±1.5 % here), no regression, 0 fatal.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by Raghav314 on 2026-10-17T07:59:01Z.
@alfalfa-star a data point from Hades II (PPSA36082), the level's item pickup UI, where queue worker 0's draw preparation is the limit. Linux, RTX 4090, 7800X3D, NVIDIA 615.78.08. All three builds are
main2fab88d10+ #5656 + #6632; this PR is a local cherry-pick ofe2d9ac88conto it (applies cleanly).APS5_PIPELINED_DRAWS=32 APS5_PIPELINE_DISPATCH=1 APS5_HOST_IMPORT_MIB=6784, warm shader cache, trace70:10, one run each:Driver.Drawms per frameAPS5_DRAW_PREP_THREADS=4APS5_DRAW_PIPELINE=1The pool's own line during the window:
So in this scene the jobs run one at a time:
shader_compile_and_linkon the worker drops from 12.3 to 9.1 ms per frame, but the worker waits for the pool to empty about 13,000 times a second, which takes the time back. No redos or skipped draws.#6946 changes the same part of
Driver::draw(it hands the second half of a draw to one finisher thread), so the two conflict there and inDrawPipelineand the packet filter; whichever lands second will need a rebase.LLM assistance used.
Imported from boykopovar/AnyPS5. Originally posted by tibzejoker on 2026-10-17T09:11:37Z.
GTA V (PPSA04264) data for this PR, as suggested by @teepean on #1203.
Setup. i9-13900K, RTX 4090 (NVIDIA 616.92), Windows 11, WinLibs GCC 15.2. Built from main
5f61879a9plus #6488 and #6848 (GTA needs them), then this PR'se2d9ac88ccherry-picked. Story mode, same scene, warm shader cache. FPS is the frame counter delta from t=180 s to t=330 s; one run each.APS5_DRAW_PREP_THREADS=4APS5_DRAW_PREP_THREADS=2APS5_POOL_DATA_HITS=1APS5_DRAW_PREP_AFFINITY_MASK=0xffff)So nothing measurable on this title. The counters say why.
Default gate: most draws stay on the packet worker.
[prep-pool-gate]reports eligible 782,337 and data entry 6,417,663: about 89 % of GTA's draws are draw-cache data-only hits. They aren't pooled, and each one goes throughDrawPipeline::Enqueue, which callsWaitAll(). In Story the pool gets ~23k jobs per 10 s with 0.3 in flight on average, and the front waits for all of them ~20k times per 10 s. The pool is drained before nearly every pooled draw.With
APS5_POOL_DATA_HITS=1: ~165-190k jobs per 10 s, 7-8 in flight. But turn waits are about 16 s per 10 s (summed over 4 threads), room waits ~3 s, and ~30k full drains per 10 s are still there. On the default E-core pinning that is −17 %; on the P-cores it is back to the baseline.My reading: on GTA, the ordered stage after preparation (the committer and the in-order turn) is what limits the frame, not preparation itself. Prepared draws queue up behind it. The 13900K's E-cores are also noticeably slower for this work than the P-cores, so the default affinity may hurt on hybrid Intel CPUs.
Happy to rerun with other settings or a newer head, or to capture a worker profile of the committer if that helps.
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by alfalfa-star on 2026-10-17T10:07:04Z.
Closing this. On Kena it doesn't pay for its risk, and your review found real problems. Details for anyone who picks up the idea (@tibzejoker, @teepean):
Measured on Kena (PPSA01802), forest title scene, no input.
mainf8b22edfb+ this PR,APS5_TRACE_SECONDS=100:30, three rounds with the pool off and on alternating. Linux, RX 9070 XT, RADV.APS5_DRAW_PREP_THREADSThe pool-off rows spread more than the difference. An earlier batch had pool off 210 / 239 against pool on 217 / 223. The
[prep-pool]line (APS5_PROFILE_DRAW=1) shows why there is little to gain here: 505 jobs per 10 s, 0.5 in flight on average, the front waited for all 317 times (21 ms), 0 redos, 0 front-read conflicts. Most draws don't qualify for the pool, and labels or other non-commuting packets drain it before it fills.Bug found while writing the test you asked for. Pool threads never set
DrawPipeline::Active(), soqueryPendingWriteandVariantValidationon a pool thread skipped the draw-pipeline check. A redone preparation then read memory that an earlier queued draw writes, before that draw ran. The test, behind a full draw pipeline, has draw A render a pixel that draw B reads as a scalar constant. It got 0 instead of the value A wrote. The fix sets the flag in the pool job, and the test then passes with one redo. The other points (submission pointer, a stoppable pool joined at shutdown, gate counters removed, report only withAPS5_PROFILE_DRAW, no default E-core or committer pinning,explicitback onIrNode) are fixed on my branch too. I'm not pushing them, since the PR is closed.Not fixed, and the reason to close rather than finish. The packet worker still decodes vertex tables and validates draw-cache hits against guest memory before a draw reaches the pool. Those reads don't see writes from earlier draws still preparing on the pool. A redo re-runs only the captures, with the worker's snapshots. Making that correct means running the whole draw on the pool from a copy of the queue state and redoing all of it on a conflict, as in @teepean's place-reserving design. Their Stray numbers suggest the committer becomes the limit once the worker isn't.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by alfalfa-star on 2026-10-17T10:38:33Z.
Thanks @Raghav314 and @tibzejoker. Your Hades II and GTA V numbers came in while I was measuring Kena, and they say the same thing: the pool holds 0.0–0.3 draws on average because the front drains it, and pooling the data-only hits moves the wait into the in-order commit. That, plus the ordering hole above, is why this is closed in favour of teepean's reserved-places design (perf/reserved-prep, linked on #1203).
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by teepean on 2026-10-19T22:05:25Z.
A follow-up for anyone who lands here from the note above: the reserved-places design (
perf/reserved-prep) didn't pay either. On Stray it lost about 14 % with #6501, and @tibzejoker's GTA V runs showed the same. In both titles the committer is the ceiling (busy 75–90 % of the frame with or without the pool), so preparing draws in parallel only adds waits. The numbers are on #1203. I've stopped working on it; cutting the committer's serial cost has paid instead (#5436).AI-assisted: yes (text with Claude Code).
Pull request closed