perf(agc): the queue-0 draw committer bounds draw-heavy titles on the CPU — is parallel draw recording planned? #7895
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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 SP4C3B4R-8 on 2026-10-19T12:46:13Z.
@oneandonlydean @MichonGoddijn231849 asking before anyone starts, so nobody does the same work twice (I asked the same on #1201 on 10-16; posting it here where it is easier to find).
Measured on main
415cd49fd+ #6763, Windows 11, RTX 5070 Ti (NVIDIA 617.42), Ryzen 7 7800X3D. Scene: Astro Bot (PPSA21564), Crash Site hub, warm caches, ~3,000 draws per frame, ~10 fps.draw committerthread is busy ~88 of ~102 ms per frame (APS5_TRACE_SECONDSwindow:Graphics.Drawplus folded slices). It records ~290k draws per 10 s at ~25 µs each.queue worker 0x0is blocked ~72% of the samples, mostly inDrawPipeline::Enqueuewaiting for room. It is not the limit.gpu_busy_ms_per_present).[draws]phases on the committer per 10 s: lookup 2.0 s (mostlyShaderResources::Revalidate), record 1.47 s, vertex 0.82 s, readTarget 0.66 s, everything else under 0.25 s each. Only ~25% of the committer's time is command recording itself.Things that gave nothing measurable here: a deeper pipeline (
APS5_PIPELINED_DRAWS=32/64),APS5_PIPELINE_DISPATCH=1(drains 7.4k → 4.7k per 10 s, same fps), and moving write-watch walks to the worker.So the remaining CPU headroom on titles like this seems to need preparation outside the single committer: preparing draws N+1…N+k off the GPU mutex with a validity check at record time, and/or secondary command buffers per render pass. That touches the resource cache, the texture/storage registries and the recorder's snapshot arena, which is your area.
Question: is either of you planning this? If not, would you take it from us as a series of small PRs (first a split of
Graphics::Drawinto prepare and record with no behavior change), and in what shape?Written with AI assistance (Claude); measured on the machine above.
Imported from boykopovar/AnyPS5. Originally posted by m335671 on 2026-10-19T16:37:26Z.
A data point from the other side of the same problem, and an offer to take a share of it.
Setup: Sword of the Sea (PPSA25344, UE5), Windows 11, RTX 4070, NVIDIA 617.42, Ryzen 9 7900,
mainfrom today, in game.The limit is the queue-0 worker, not the committer:
queue worker 0x0is 98–99 % busy and thedraw committer~40–46 %. Frames take ~400 ms.Graphics::Draw7.6) and ~24k dispatches at ~100–120 µs each (capture 8–21, recompile 8–15, prepare stage A 10–23, device call 42–61).[indirect], 27k dispatches per 10 s), per dispatch:B upload~20 µs,B images~13 µs,record~12 µs, resource-template insert ~7 µs. The template cache inserts 26.7k of 27.4k, so nearly every dispatch builds fresh.What I measured that does not help on this title, so nobody repeats it:
APS5_DRAW_CACHE_ENTRIES=32768changes nothing).APS5_PIPELINE_DISPATCH=2that also pipelines dispatch-cache misses,APS5_PIPELINE_DMA=1). Each one removes drains: packet drains go ~160k → ~4k per 10 s. The wait just moves elsewhere, into the captures that read what the queued DMA and dispatch items write. Frame time is unchanged. Details are in #5436.So I agree with the direction, and both sides need it: the committer on Astro Bot, the worker's per-command preparation on this title. In #5436 I offered to take the dispatch side of the 2.2 split. Concretely, that means moving dispatch preparation (stage A, the guest buffer snapshot upload, the template build) off the queue-0 worker onto helper threads in guest order, with a validity check where the item is recorded, so it fits whatever shape you choose for draws.
Questions for oneandonlydean and MichonGoddijn231849, as above: which shape do you want, per-thread secondary command buffers per render pass or several prepared items feeding one recorder? Would a dispatch-side series in that shape, behind a switch and off by default, be welcome? I can also measure every step of the draw-side series on this title (Windows/NVIDIA, UE5), where the worker is the limit.
AI-assisted: yes (Claude Code). The builds, the runs and this comment were done and written by Claude Code on my machine.
Imported from boykopovar/AnyPS5. Originally posted by Rajkamalcode on 2026-10-19T17:28:37Z.
Data point from another Windows/NVIDIA title, and a scope question.
SWAG (PPSA22102) in its ~1 FPS spawn/streaming state has the same shape as the Astro Bot scene: the single queue-0 draw committer records ~2,000 commits/frame (about 890 of them draws, the rest label/store items) at 205-250 us each, i.e. ~400-430 ms of a ~0.9 s frame, while the GPU is busy only 414-487 ms and idles 426-579 ms. Queue worker 0 is blocked 14.9 % in
DrawPipeline::Enqueueand ~17 % inDrain(10-minute sampler), but the committer is the throughput limit, not the worker.Per-draw costs at that spot (six-minute
APS5_PROFILE_DRAWruns, 8-10k draws/10 s):readTarget880-1,147 ms/10 s - resident-target page walks, because the committer follows the worker's collect-epoch token (WaitStatistics.cpp:36->DrawPipeline::FollowEpoch), so every ordering point re-walks the target (4.4-4.9M pages/10 s; 190-219 lookups >= 1 ms consume ~90 % of the phase);resources815-889 ms/10 s (1,181-1,294 builds at 1.4-1.8 ms each vs 79 us template hits, mostly the images stage of stage B);record222-294 ms.Negative result that may save someone a cycle: removing drain waits does not move this title.
APS5_PIPELINE_DMA=1removed ~2.1k0x50packet drains per 10 s and left presents at 10-11/10 s, inside the 9-12 baseline spread; the worker's drain wait is symptom, not gate. Same conclusion m335671 reported for Sword of the Sea. Full logs/tables: #7947.Before anyone starts on parallel draw preparation/recording: is this claimed? If a maintainer wants it, we can help on the measurement/validation side (Windows 11, RTX 3070, SWAG as a draw-heavy 1 FPS case) and can test candidate branches with numbers. We are not starting an architecture PR without direction.
AI-assisted: the runs, log mining and this text were produced by an AI-assisted workflow on the reporter's machine.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-19T18:01:48Z.
@SP4C3B4R-8 Thanks for the measurements. Nobody on our side is working on this, and we'd welcome it as a series of small PRs. Please start with the split of
Graphics::Drawinto a prepare step and a record step with no behaviour change, so it can be reviewed and tested on its own. After that, each step that moves work off the GPU mutex or into per-pass secondary command buffers should bring before/after frame timings from the same scene. The maintainers have the final say on the overall design, so it's worth outlining the end state in this issue before the bigger steps.Imported from boykopovar/AnyPS5. Originally posted by johandavidcm on 2026-10-19T19:34:11Z.
Another title with the same shape, in case it helps with the order: PPSA31327 (Yakuza 0 Director's Cut) in gameplay, on the same CPU (Ryzen 7 7800X3D, RTX 4070). About 8,700 draws per frame at 3.3 FPS: the committer's
Graphics.Drawtakes 252 of the 299 ms frame, and queue worker 0 waits inDrawPipeline::Enqueuein 29 % of its samples.One part of the committer's time would not need parallel recording: 12 % of its samples rescan the DCC keys of sampled textures in
cachedTexture, throughTextureClearKeysrather than a proof. Summary lines, traces and the stacks of both threads are in #NNNN.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by m335671 on 2026-10-19T21:05:04Z.
Here is the dispatch side of the end state, outlined before any code as asked, so it lines up with the draw-side series.
Queue-0 dispatches already have half of the split.
PrepareDispatch(stage A) runs without the GPU mutex.VulkanDevice::dispatchthen does everything else under it, in this order: reap the presync batches, look up or insert the resource template, complete it (Complete(): images, guest-buffer uploads, descriptor writes) orRevalidateit, build aRecordedDispatch, and hand that torecordDispatch. Proposed series, each step behind a switch and off by default until it shows before/after timings from the same scene:VulkanDevice::dispatchinto a complete step and a record step, with no behaviour change. The complete step returns theRecordedDispatch, and the record step isrecordDispatchplus the marks and completions around it. This mirrors theGraphics::Drawprepare/record split so that both feed the same recorder interface.DispatchAheadadoption protocol. TodayDispatchAheadruns on the worker itself and skips queue 0. A rejection falls back to the current path, and a read over a range that a queued pipeline item writes rejects instead of draining. This step is independent of the recorder work.Steps 1–2 touch
VulkanDevice.cpp,ShaderResources,GuestBufferMemoryand the dispatch path. Step 4 touchesDispatchAhead.cpp,Dispatch.cppandPacketExecution.cpp. None of them touchesGraphics::Draw, so they don't conflict with SP4C3B4R-8's first PRs. I'll measure every step on Sword of the Sea (Windows/NVIDIA, worker-bound), and I'm glad to measure the draw-side steps there too.As a first-time contributor I can only have one open PR, and #7932 (a 3-line
DispatchWriteRangesfix with its test) is waiting for review, so step 1 will follow once that one is settled. If the maintainers prefer a different order or shape for the dispatch side, I'll follow it.AI-assisted: yes (Claude Code). The analysis and this comment were done and written by Claude Code on my machine.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-20T04:48:27Z.
@m335671 @SP4C3B4R-8 thanks, both measurements point the same way. On PPSA21564 about a quarter of the committer's time is recording, and in your dispatches the upload, images and template build are well over half of the device call, so preparation is what dominates on both titles.
So the shape we'd like is several prepared items feeding one recorder: prepare off the mutex (on helpers, in guest order), check validity where the item is recorded, and record on one thread in guest order. Per-pass secondary command buffers can come later as a step of their own, if recording itself becomes the limit. Nothing in the prepare/record split should rule them out.
The dispatch outline fits that, and it's welcome as a series, with two things for every step:
Step 4 doesn't depend on the recorder, so it can follow step 1 directly. Step 3 waits for the draw series. #7932 is merged, so your step 1 can follow.
Imported from boykopovar/AnyPS5. Originally posted by m335671 on 2026-10-20T08:19:04Z.
Step 1 is up: #8278. It splits
VulkanDevice::dispatchinto a complete and a record step, with no behaviour change.Next is step 4: queue-0 dispatch capture and recompile resolved ahead on a helper, behind a switch that is off by default. It comes with a test that writes in the prepare/record window and fails without the check. A capture that would wait on words the GPU is still writing is rejected and falls back to the normal path rather than waiting on the helper. I'll measure the ceiling with
APS5_GROUP_CAPTURE_ALL_QUEUES=1first and post the before/after on the same scene.AI-assisted: yes (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by teepean on 2026-10-20T18:58:13Z.
@SP4C3B4R-8 a Stray (PPSA02100, UE4) data point for this series, and an offer so we don't do the same work twice. In #5436 I said I'd take the draw-side recording split after the committer's per-draw costs. Your question here came first and the maintainers have set the shape, so I'd rather help with your series than start a second one.
Stray is committer-bound the same way. The setup: the start of the Dead City chapter, Linux, Ryzen 9 9950X, RTX 3090 (NVIDIA 615.78.08), stock
engine.ini, 3840x2160. The build is my local stack (showcase/stray-stack:main64e2a810a9plus stage instances, repeat-draw paths and #6970), at 16.5 FPS. These are 300 stack samples of the whole process:So it is the same picture as Astro Bot, with even less of the time in recording.
What I can offer:
Is the prepare/record split already in progress on your side?
AI-assisted: yes (text with Claude Code; the profile is from my machine).
Imported from boykopovar/AnyPS5. Originally posted by SleglJan on 2026-10-21T06:19:33Z.
A data point from 007 First Light (PPSA11386) on Linux. On this title neither the committer (Astro Bot, SWAG, Yakuza 0, Stray) nor queue
0's worker (Sword of the Sea) is the busy thread. In gameplay the draw committer waits for work 62% of the frame. While queue 0's worker
waits for room in the draw pipeline, the committer spends 64% of that time waiting for the GPU mutex.
Setup
68323bae7+ #5799 #6868 #5372 #6918 #7643 #6679 (#5799 and #6679 have merged since), Release (GCC 16.2.1). NoAPS5_*switch otherthan the pad input file, so the pipeline depth and the spin windows are the defaults.
DrawPipeline's waits,HandoffSpin,WaitMemoryandGpuMutexType::lockare unchanged on mainec7eacc62d, apart from the committersampler (#8075, Windows only, a no-op here). Only the code was compared; the numbers were not measured again on
ec7eacc62d.SDL_VIDEODRIVER=x11(XWayland), RTX 3080 (NVIDIA 615.78.08), Ryzen 9 7950X3D.-t vulkan,osrt --vulkan-gpu-workload=individual -s none --cpuctxsw=none --gpu-metrics-devices=0;stretch.
failed to write the report on this setup.
vkCmdDraw*andvkCmdDispatch*do not appear in the trace, socommand recording counts as untraced. This capture gives no draw count per frame.
APS5_TRACE_*shares of the reports above, so the percentages are not directlycomparable.
HandoffSpinwindow with more than 8usable CPUs);
DrawPipeline::Drainspins up to 300 µs;Per thread, ms per frame (share of the frame)
DrawPipeline::Enqueue, default depth 8) 264, of which 43 from label packets; waits for the pipeline to empty (DrawPipeline::Drain) 115; mutexes 32DrawPipeline::run) 781, GPU mutex 206 (commitDraw174,commitLabel26)PollSleep←Driver::waitMemory) 855–968 each, mutexes 139–171 each (nearly all the GPU mutex)The committer while queue 0's worker waits on the pipeline
GPU
that ended a gap was submitted inside it.
So on this scene the committer is outside traced calls at most 13% of the frame (171 ms), plus 56 ms (4%) in Vulkan calls other than
fence waits. The time queue 0's worker waits for room is mostly time the committer waits for the GPU mutex, which the async queue
workers and queue 0's worker also wait for. This capture does not show which thread holds it.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by SP4C3B4R-8 on 2026-10-21T08:52:59Z.
@oneandonlydean thanks. Here is the draw-side end state, outlined before the bigger steps as you asked, with the same shape as the dispatch side (several prepared items feeding one recorder). Step 1 is up: #8992.
Where the committer's time goes now (
mainf894ba69d, Astro Bot Crash Site, Windows 11, RTX 5070 Ti, Ryzen 7 7800X3D, warm caches, 10.2 fps,APS5_PROFILE_DRAW=1, per 10 s): ~219k draws at 28 µs. lookup 1.90 s, record 1.48 s, vertex 0.93 s, readTarget 0.77 s (315k resident lookups walking 18.4M pages), pipeline 0.24 s, resources 0.22 s, keep 0.20 s, prepare 0.20 s, validate 0.12 s. Record + keep is ~27%; the rest is preparation. The GPU is busy ~65 ms of the ~98 ms frame, so the ceiling for this scene is roughly 15 fps.Steps (each behind a switch, off by default, with before/after timings from the same scene):
Graphics::Drawsplit intoprepareDrawandrecordPreparedDraw, no behaviour change (#8992).recorder->Sync/PendingLabelIn(indirect records' path),BoundKeptBytes,SharedResourceCache().Insert,RetireDepthSurfaces/FlushDepthPlanes,materializeCmaskClear, the resident target refresh (CachedStorageSurface,StorageTexturerefresh),CachedPipeline/AcquireFramebuffer,prepareDrawInputs(Recorder::SnapshotUse,GuestMemory::FlushGpuWrites), andresolveDrawResources(Revalidate, which mutates the cached template). This step splits them into what only reads (lookups, keys, proofs) and what must stay at record time in guest order (syncs, retires, cache inserts, template mutation), still on the committer.@teepean thanks for the offer. Measuring each step on Stray (committer-bound UE4, Linux) would help most, because it covers Linux and a different engine. I'll tag you on each PR.
Imported from boykopovar/AnyPS5. Originally posted by SleglJan on 2026-10-21T09:04:10Z.
In issuecomment-6309486250, queue 0's worker in 007 First Light (PPSA11386) mostly waits for room in the draw pipeline while the draw
committer waits for the GPU mutex, and that capture did not show who holds the mutex. The driver's
[lock]lines from a longer profiledrun do: of the holds that ended while the committer waited, 98.7% by held time were the async compute queues' dispatch and indirect
holds.
Setup
68323bae7+ #5799 #6868 #5372 #6918 #7643 #6679 (#5799 and #6679 have merged since), Release (GCC 16.2.1).27c88a8d75:FlushDepthPlanes, which takesit only when a stale depth plane overlaps.
[indirect]counter shows 0 thread-dimension dispatches on the CPU side).27c88a8d75.SDL_VIDEODRIVER=x11(XWayland), RTX 3080 (NVIDIA 615.78.08), Ryzen 9 7950X3D.described in #6172 (local only).
APS5_PROFILE_DRAW=1 APS5_TRACE_SUMMARY_EVERY=60. In a 60 s perf profile in this run's gameplay, their clock reads took about 4% ofqueue 0's CPU.
[lock]line covers its own period, so every figure is a share of that thread's covered time (2,943–2,947 s per thread).10 s. Without those four lines the committer holds 16.4% (draw 15.8) and waits 12.5%, and the 98.7% is unchanged.
locked GPU waits: waits inRecorder::finishfor a recorded batch whose fence was stillunsignaled, made while the thread held the mutex. Other fence waits are not counted, so it is a lower bound.
including any part before the wait, so this is hold time, not wait time.
Share of time, per thread
Holds that ended during the committer's waits, by held time
The async holds
StorageTexture::FlushPending(Recorder::Sync/FinishUpTo) underShaderResources::Complete→buildComplete→
resolveImageBindingorGuestBufferMemory::UploadFinish, inVulkanDevice::dispatch;StorageTexture::FlushPendingunderStorageTexture::Refresh(its caller is not in the stack);Recorder::SyncThroughunderGuestMemory::EqualsCommitted/ReadCommitted);vkAllocateMemory), mostly fromStorageTexture::Create; where the stack goes further, it is underresolveImageBinding. These stacks end beforeVulkanDevice::dispatch.takes.
When the dispatch series' step 2 is up, I can measure it on this title the same way: the
[lock]lines and the holds the committer waitsbehind, same input, gameplay, Linux/NVIDIA.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-21T09:08:19Z.
@SP4C3B4R-8 thanks, this is the shape we described: helpers prepare in guest order, the committer checks each prepared item where it records it, and recording stays on one thread. The profile also shows why: most of the committer's time is preparation, not recording.
On step 3: the check has to cover both write paths you name, CPU writes since the item was prepared and GPU writes still queued over its read ranges. A test that writes in that window, as you plan, is the right proof. The 87.5% figure is one scene. Please give the survival rate per title in each step's description, because the speed-up depends on it.
For #8992 (step 1), the bar is no behaviour change: identical output and timings within noise on the same scene.
Imported from boykopovar/AnyPS5. Originally posted by teepean on 2026-10-21T10:27:39Z.
@SP4C3B4R-8 thanks, I'll measure each step on Stray (PPSA02100) and post the numbers on the step's PR.
One thing to know about the setup: Stray is committer-bound on my stack (
showcase/stray-stack). On plainmain, queue 0's worker bounds this scene instead: in the runs for #8895, the worker was 97-98 % busy and the committer about 48 ms of a ~168 ms frame (main7e95bde794). So for each step I'll give two things:mainwith and without the step: frames 26-39 of the Dead City start compared pixel by pixel, the committer's busy time per frame fromtools/trace_digest.py, and FPS from balanced rounds;For #8992 that means
mainb5d763770aagainstmain+ #8992, both on Linux, Ryzen 9 9950X, RTX 3090 (NVIDIA 615.78.08), stockengine.ini. My bench is busy at the moment, so expect it later today or tomorrow.@oneandonlydean on the survival rate per title: I counted it on Stray with a local diagnostic on my stack (same scene, about 730,000 pipelined draws per 10 s). For each pipelined draw, I checked whether one of the previous 16 committed pipeline items writes a range it reads. The reads were the index buffer, vertex buffers, buffer V#s and image T#s; the writes were each item's declared write ranges plus its attached labels and counter dumps.
So on Stray the rate depends on what the check compares. Against every declared write, it is about 58 %. If it only looks at what preparation read on the CPU (snapshots, uploads, synchronized reads), in-place buffers and GPU images drop out, and most of the 42 % would survive. CPU writes would still be caught, as you asked.
AI-assisted: yes (text with Claude Code; the counts are from my machine).
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-21T10:39:57Z.
@teepean thanks, those counts answer the question better than any estimate. I agree with your reading. What the check has to protect is what preparation consumed on the CPU (snapshots, uploads, synchronized reads, and the descriptor and table words it decoded), compared against CPU writes since the item was prepared and GPU writes still queued over those ranges. A buffer bound in place and an image sampled on the GPU are ordered by the queue itself, so they don't need the check. That puts PPSA02100 well above 58 %.
One caveat for the 4 % that read through the BDA table or image tables: if preparation resolves those tables on the CPU, the table words themselves are a CPU read, so a queued write over them has to fail the check. If the read set can't be bounded, those draws should fall back to recording in place, not be treated as unchanged.
The per-step plan sounds right. On
mainthe worker is the wall, so the committer's busy time and the pixel comparison are the numbers to watch there.Imported from boykopovar/AnyPS5. Originally posted by 00xDisaster on 2026-10-21T22:22:22Z.
We are not working on the full draw preparation (preparing draws N+1..N+k off the GPU mutex with a validity check at record time, or secondary command buffers per render pass) — the resource cache, the texture and storage registries and the recorder's snapshot arena are the part we have no answer for.
We do have a measurement of the part that the pipeline preparation covers, which may be useful here.
PR #5925 builds the pipelines of a submission ahead on a compile pool. I ported that feature onto current
mainand measured it on Pumpkin Jack (PPSA03446), a UE4 title, with a fixed camera and warm caches:So on that title the pipeline build is no longer on the draw's critical path. What the committer still spends is what this issue measures in Astro Bot — the lookups, the recording and the resource work (lookup 2.0 s, record 1.47 s, vertex 0.82 s of the 88 ms the committer is busy). The draw preparation you describe is what is left, and the same shape of problem is in #5485, #5345, #5529, #6257 and #8068.
The measurement and the port of the lookahead are in #5925.
AI-assisted: no