perf(agc): queue occlusion counter dumps behind pipelined draws instead of draining #6501
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6501"
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 Nesyth on 2026-10-15T17:45:07Z.
What
With pipelined draws, queue 0 drains the draw pipeline before every occlusion counter dump (
EVENT_WRITEevent 0x39): it waits until the committer has recorded every queued draw, then records the dump itself. A title that wraps its draws in occlusion queries pays that wait hundreds of times per frame.This change queues the dump as an ordered commit item, as labels and DMA stores already are, so the committer records it right after the draws before it and queue 0 moves on.
DumpSamplesOnGpu. When that refuses, the item idles the device under the GPU mutex (ascommitDmaStoredoes, instead of the drain's unlocked wait) and writes the counters on the CPU.APS5_PIPELINE_DRAIN_SAMPLE_DUMPS=1drains for every dump, as before.[sync]counter shows how many dumps were queued.APS5_DRAW_PIPELINE=1(#6946) a dump still drains the draw finisher before it is queued, as every packet outside the finisher's list does. Queueing it through the finisher, as labels are, is a follow-up.Tested
Windows 11 Pro 10.0.22631, Ryzen 7 7800X3D, RX 7900 XTX, WinLibs GCC 15.2.0, Release, on
mainaeeaefad9.tests/execution/PipelinedSampleDump.cpp. One DCB holds a DMA fill over the dump slots, a begin dump, a draw, an end dump, a second query with no draw in it, and a fill over the last slot. The end dump has to count the draw's samples and the empty query none, every slot has to show the ready bit over the first fill, and the last fill has to land on top; all four dumps have to go through the queue.agc_driver_pipelined_sample_dump_drainedruns it with the switch set and requires the same values with no dump queued. Recording the dump at once instead of in order makes the test fail. The cases that stay on the drain path are not covered by a test.ctest -Vof the pipeline, label, finisher and occlusion query tests (agc_driver_(pipelined|finisher_label|same_queue_label|draw_pipeline_trace|unimported_label|alias_copy_label),agc_sample_dumps,agc_predication_tests,agc_instrumentation_query_size_tests) withVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation(SDK 1.4.363.0),ANYPS5_NO_SHADER_CACHE=1andANYPS5_REQUIRE_VULKAN=1: 28 of 28 pass with this change and 26 of 26 onmainaeeaefad9, the two new tests being the difference. Neither log reports the layer missing or aVUID-.agc_driver_pipelined_sample_dumpalso passes 10 runs in a row, and 3 runs withAPS5_DRAW_PIPELINE=1.ctest -R "agc|shader"run (603 of 606) is from the previous basefa9365ca7and was not repeated onaeeaefad9.Linux: not run.
Ready or Not (PPSA18605)
The station lobby after Continue, standing still, 3840x2160.
mainaeeaefad9againstaeeaefad9with this commit, onlylibSceAgcDriverswapped, caches warm,APS5_TRACE_SECONDS=80:15withAPS5_TRACE_EVENTS=1048576andAPS5_NO_PAD_INPUT=1, no otherAPS5_TRACE_*orAPS5_PROFILE_*switch, log not redirected, nothing dropped. The window is earlier than the 160:10 used for this scene before:mainaeeaefad9aborts here 60 to 130 s after the station loads, in both builds, withstoring storage image results pending over memory outside the write watch without the guest bytes saved before them is not implemented(as in #7017).Six captures in the order
main, change, change,main,main, change; captures 1, 4 and 6 are reruns of runs that aborted before their window closed:mainmainmainQueue worker 0x0 is 99 % busy in every capture. The sessions of this scene land in states that differ more than the two builds do: capture 1 shows the colour cast, in capture 2 the committer takes 161 ms per frame against about 100 and queue 0 waits 101 ms per frame for it in
pipeline_drain, in capture 5 draws take 53 ms per frame against about 85, and in capture 6Resources.Completetakes 86 ms per frame. Captures 3 and 4 landed in the same state: 77 against 76 presents, frame p50 189.1 against 190.8 ms, the same GPU time. An earlier batch, run withoutAPS5_NO_PAD_INPUTso that host input could reach the title, gave 77 and 77 presents with this change against 74 and 74 onmainin that state. So in this scene the change is worth a few percent at most, within the spread between sessions; the title stays bound by queue 0.Summary lines of captures 4 (
main) and 3 (this change):Traces:
aps5-trace-aeeaefad9861-15348.json.gz
aps5-trace-63555394784d-34412.json.gz
tools/trace_digest.py, capture 4 (main)seconds 80:15 from present 363: 76 presents, frame p50 190.8 / p90 230.9 / p99 244.5 / max 244.5 ms, GPU busy 112.1 ms per present
AMD Radeon RX 7900 XTX, AMD proprietary driver 26.8.1 (LLPC), Windows 10.0.22631, 3840x2160, commit
aeeaefad98, dropped: noSlowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 279.0, batch 112.2, Graphics.Draw 96.1, Driver.Packet.memory_wait 91.4, Driver.WorkerWait 88.2, Driver.WorkerWait.dequeue_order 88.2, Graphics.Draw.draw_and_resource_release 86.2, Driver.Packet.dispatch 80.8, Driver.Packet.draw 79.9, Driver.Draw 79.6
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
tools/trace_digest.py, capture 3 (this change)seconds 80:15 from present 397: 77 presents, frame p50 189.1 / p90 223.1 / p99 240.5 / max 240.5 ms, GPU busy 111.7 ms per present
AMD Radeon RX 7900 XTX, AMD proprietary driver 26.8.1 (LLPC), Windows 10.0.22631, 3840x2160, commit
6355539478, dropped: noSlowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 284.2, batch 111.6, Driver.Packet.memory_wait 95.8, Graphics.Draw 95.3, Driver.WorkerWait 88.2, Driver.WorkerWait.dequeue_order 88.2, Graphics.Draw.draw_and_resource_release 85.2, Driver.Packet.draw 80.4, Driver.Draw 80.1, Driver.Packet.dispatch 73.3
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
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)Imported from boykopovar/AnyPS5. Originally posted by Pacuka on 2026-10-18T12:18:33Z.
Linux data point (the PR says Linux was not run): The Smurfs - Dreams (PPSA21607, Unreal Engine), CachyOS, RX 6650 XT / RADV Mesa 26.2.4, main
9f25d0bf5+ this PR + #6208 (APS5_PIPELINE_DMA=1) + unrelated local rendering fixes. Same spot in the Smurfs' Village, standing still,APS5_PROFILE_DRAW=1, A/B withAPS5_PIPELINE_DRAIN_SAMPLE_DUMPS=1:EVENT_WRITE(0x46); 79–81 presents per 10 s.EVENT_WRITEdrains left; 75–78 presents per 10 s.So it works here: no rendering differences, no aborts, and every dump drain is gone. There is no frame-rate win in this title, though. The draw pipeline is committer-bound (~110k commits per 10 s at ~79 us each), and the remaining drains (
DISPATCH_DIRECTx3.8k,WAIT_REG_MEMx2.2k) wait for the same committer. The GPU is busy ~42 ms and idle ~85 ms per frame.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by teepean on 2026-10-18T21:45:58Z.
@Nesyth a Linux and NVIDIA data point, from a title that wraps most of its draws in occlusion queries: Stray (PPSA02100, Unreal Engine 4) at the same save, standing still. Linux 7.2 (CachyOS, scx_lavd scheduler), Ryzen 9 9950X, RTX 3090 (NVIDIA 615.78.08), GCC 16.2.1, Release, 3840x2160;
main864729dc0with and without this PR (327a2bb7f), stock settings, one run at a time, alternating.With
APS5_PROFILE_DRAW=1, one run each, mean of the last 8 windows of 10 s:mainFrame p50 from trace summaries (
APS5_TRACE_SECONDS=185:20, no other variables):main170.5, 172.6, 165.0 and 171.2 ms; this PR 167.8, 171.1 and 157.7 ms. A fourth run of this PR hit the #5372 import race (about 1 fps for the whole window) and is left out. The profiled pair above: 168.4 and 155.3 ms.So queue 0 no longer drains for the dumps, and its drain wait falls by about 1 s per 10 s, but the frame time falls by less than that (about 2.5 %, within the spread between runs). In this scene queue worker 0 is about 97 % busy and the committer, which now also records the dumps, goes from about 67 to 74 % busy, so the two threads still pace each other. I didn't compare frame dumps for this PR.
With #6946 on top, the queued dumps drain that PR's draw finisher instead, because its
keepsDrawPipelinestill treats 0x46 sample dumps as drains. The numbers are on #6946: https://github.com/boykopovar/AnyPS5/pull/6946#issuecomment-6255512105AI-assisted: yes (analysis and text with Claude Code; the runs are from my machine).
Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-19T03:06:45Z.
Linux validation of #6501 at
327a2bb7f7ed36b3d2d02d1221a72ece2bad4918, integrated into a local Crimson Spires composition based on mainc8e3fcb703852e0b256f708fdf47360ee895625a(also includes existing title prerequisites and #6616). This is not a clean main-versus-PR comparison.Both
agc_driver_pipelined_sample_dumpvariants pass without skips on RX 6650 XT/RADV and lavapipe (2/2 per driver). Two warm native runs also reach the first driving/dialogue scene and close normally. Their sampled screenshots show no obvious new rendering issue; this does not establish full gameplay correctness.Same compiled integration
328ecb92f21f885e706ebf7f3f57b1163569c07f, 3840×2160 internal rendering, same scripted input, official 20-second trace at 90 seconds after first present. A setsAPS5_PIPELINE_DRAIN_SAMPLE_DUMPS=1; B leaves it unset. Linux 7.2.9, RADV Mesa 26.2.4, RX 6650 XT. No trace events dropped.One sequential pair only: median and GPU time are essentially unchanged, with lower tail times in B. This is exploratory evidence, not a repeatable FPS improvement claim. Screenshots have the same dialogue/scene, but the animated road/camera are not frame-identical. Windows and other titles were not tested here.
Official trace_digest summary records
AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by m335671 on 2026-10-19T12:23:33Z.
Windows / NVIDIA / Unreal Engine 5 data point: Sword of the Sea (PPSA25344), Windows 11 26200, RTX 4070 12 GB, NVIDIA 617.42, Ryzen 9 7900, 3840x2160.
Build:
main36f60df9e+ #6763 + this PR (327a2bb7f), merged locally. There were two textual conflicts with currentmain, and I kept both sides of each:PacketExecution.cpp:main's!submission.flips.contains(cursor)and this PR'senqueueSampleDumpPacket(...), in the same condition;CMakeLists.txt: two independent test registrations.On that merge
agc_driver_pipelined_sample_dumpandagc_driver_pipelined_sample_dump_drainedpass. A/B on the same binary:APS5_PIPELINE_DRAIN_SAMPLE_DUMPS=1;Both runs used
APS5_PROFILE_DRAW=1 APS5_PROFILE_GPU=1 APS5_TRACE_SUMMARY_EVERY=10 APS5_THREAD_PRIORITY=highand a warm shader cache, over the same path: title screen, opening cinematic, then about 1 min in game. Both had a Discord stream running.The mechanism works. This title issues a sample dump about every draw. In the opening cinematic (
[draw] pipelined, per 10 s):0x46(sample dumps)But the frame time does not move, because this title stays CPU-bound on queue 0. The figures are medians over each scene's 10 s summary intervals:
queue worker 0x0busyBetween identical runs of this title I measure about ±6 % of noise in the cinematic, so all three rows are within noise. In the summaries, the worker time the drains no longer take reappears in
Driver.Packet.draw: +11.6 ms per frame in the cinematic and +19.5 ms in game.Driver.Packet.dispatchdrops by 9.7 ms in the cinematic. My guess is that queue 0 and the committer now meet on the same locks more often, but I have not traced that.tools/performance_compare.py, in-game interval (baseline = drained, candidate = queued)So on this title the PR removes a real serialization point (sample-dump drains go from ~140k to 0 per 10 s). The frame rate is bound by the single queue-0 worker plus the single committer. I'll post the wider picture in #5436.
AI-assisted: yes (Claude Code). The build, 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:45:45Z.
Windows / NVIDIA / SWAG data point (Squirrel with a Gun, PPSA22102, Unreal Engine, RTX 3070 8 GB, Windows 11)
Build: cherry-pick of
327a2bb7fonto a local base (448cf78c6, the AGC storage write-back fix #7912 - the same base my other SWAG runs used), not a rebase tomain. The same two conflicts as @m335671, resolved the same way (kept both sides inPacketExecution.cpp, both test registrations inCMakeLists.txt).Tests:
agc_driver_pipelined_sample_dumpandagc_driver_pipelined_sample_dump_drainedpass on Windows/NVIDIA (2/2, no skip, RTX 3070).A/B: same save and scripted input; 6-minute runs in the title's heavy state (~1 FPS, 0.9-1.1 s frames);
APS5_PROFILE_DRAW=1only. Baseline is the driver build this title had been running on (same source base, pre-PR); the steady-state baseline band across three earlier runs on this save is 9-12 presents/10 s.[draw]commits0x46The mechanism works here too:
0x46drains go to zero and packet drains drop by about half, with no correctness issue seen in the run. Frame time stays in the same 9-10 presents band - this title's heavy state is bound by the single committer's recording chain (readTarget~1,020 ms and resource builds ~945 ms per 10 s of a ~0.9 s frame), not by sample-dump drains, so no FPS change was expected. Commit count per 10 s rises while per-commit cost falls, consistent with @m335671's observation that queue 0 and the committer meet on the same locks more often.Run environment
Profile logs from
APS5_PROFILE_DRAW=1, 360 s each, steady windows from the 2nd-6th minute:[draw]PR window:19424 commits at 214.9 us each ... waiting 74.3 us per draw for room; drains: packet 3962 (2339.6 ms); packet drains by opcode: 0x50 x1603 0x15 x1111 0x3c x954 0x16 x241 0x10 x26[draw]baseline window:16640 commits at 251.2 us each ... waiting 96.6 us per draw for room; drains: packet 7798 (2176.4 ms); packet drains by opcode: 0x46 x3384 0x50 x1728 0x15 x1183 ...[draws]PR window:7668 draws over 10 s ... readTarget=1016.5ms (8999 resident lookups, 193 of them >= 1 ms = 852.4 ... pages walked 3750210), resources=945.0ms, record=233.7ms[sync]PR tail:786 device drains by packet: DMA_DATA=786(this counter is device drains; the 0x46 sample dumps are what stopped draining).AI-assisted: yes (the build, the runs and this text were produced by an AI-assisted workflow on the reporter's machine).
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-20T15:05:40Z.
An Unreal title data point on Linux: Super Meat Boy 3D (PPSA31162), level 1-1, RTX 4070 Ti (NVIDIA 595.99.02), Ubuntu 24.04, Release.
Setup:
main30fda0a03aagainst the samemainwith this PR merged (327a2bb7f). I resolved the conflicts by keeping both sides: the extraflipscheck inPacketExecution.cpp, both test registrations, both counters. Each run starts from a fresh boot. A script waits for the game's ownLoad map completelines (menu, slot 1, world map, level 1), settles for 30 s in the level and then counts presents for 60 s withAPS5_PROFILE_DRAW=1. Each build had its own shader cache, and the second run of each is warm.EVENT_WRITE0x39 drains per 10 smain(2 runs)main+ this PR (2 runs)That's about 2.9×. With this PR the GPU is busy about 100 ms per frame, out of about 190 ms. On
mainit's 135 ms out of 590 ms, and the draw pipeline averages 1.3 items queued, against about 5 with the PR.One note for comparison. This title bundles its own
libc.prx, and #7897 alone gives about the same gain here (51 presents per 10 s), through a different cost: it brings the per-commit time down to 16 µs while the dumps still drain. With both PRs merged I measured 48 and 32 presents per 10 s in two runs, so I saw no further gain from combining them. I haven't explained the lower second run.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-20T19:25:22Z.
@Nesyth thanks for this. It now conflicts with current
mainin code, not just adjacent lines:SynchronizationStatistics.hpp/.cppandPacketExecution.cpp(plusCMakeLists.txt). Could you rebase it onto currentmain? Once it's rebased we'll run CI and measure it againstmain.