perf(agc): keep the collect epoch at a wait an earlier wait already ordered #16897
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/16897"
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 klosixgaming-arch on 2026-11-07T21:04:38Z.
What
A
WAIT_REG_MEMthat is already satisfied when the queue worker reaches it starts a new collect epoch, so every range collected before it (render targets, shader resources, vertex ranges) is walked again withGetWriteWatchafter it. When the awaited value was written by the CPU long before and has not changed, the wait orders no new CPU store: everything the CPU stored before that value was already ordered by the earlier wait that saw it.Each queue worker now remembers, per awaited address, the value an earlier wait saw and the write generation of the address when that wait bumped the epoch. A later wait that finds the same value, after a fresh
CollectWritesUncachedof the awaited bytes, and whose range isUnchangedSincethat generation keeps the epoch. A changed value, any write to the awaited range's 64 KiB block, an unwatched range (generation 0) orAPS5_NO_ORDERED_WAITS=1bumps as before. This applies to the pipelined at-entry path inPacketExecution.cppand towaitMemory. The memo holds at most 4096 addresses per worker and is cleared when it is full. The[packets]line counts the waits ordered this way.Why: in Soul Hackers 2 gameplay about 88 waits per frame are satisfied at entry. Sampling them showed
func=3 ref=1on many addresses that no GPU label store wrote, so they are CPU-written flags the title leaves at 1. Each one reset the collect memo. With this change about 57% of those bumps go away (16.3k to 7.1k per 10 s),GetWriteWatchtime drops from about 3.4 s to 2.4 s per 10 s, and the draw committer's draw work drops by about a third in the trace. The other bumps are waits whose block the CPU wrote since (the title rewrites its flags), which still start an epoch.Tested
Windows 11 (build 26200), RTX 5090 (driver 617.42), Ryzen 9 9950X3D, WinLibs GCC 15.2, Release.
Soul Hackers 2 (PPSA03743, 01.002.000), 3840x2160. Each run loads the same save with scripted pad input and stands at the East Shipping District spawn. Trace window
APS5_TRACE_SECONDS=85:5, no other trace or profile switch:105 -> 112 presents in the window, frame p50 47.6 -> 45.0 ms. Traces: aps5-trace-fc42d49548b9-9312.json.gz (main), aps5-trace-b7936ecc5f69-57468.json.gz (change).
Interval summaries (
APS5_TRACE_SUMMARY_EVERY=10), median presents per 10 s over the gameplay windows of each run. The machine was slower in the afternoon than in the morning for every build, so only compare runs inside one block:APS5_NO_ORDERED_WAITS=1)fc42d49548(morning), alternating runsmain8f7c957ed0(afternoon), alternating runs8f7c957ed0, alternating runsDifferent builds, morning:
main8f7c957ed0210; this change 219, 218.5, 220.5. Afternoon:main8f7c957ed0211.5, 198, 193.Different builds back to back in the evening, the gameplay windows from 50 to 90 s of each run (the GPU time per present is the same, 37.8 to 38.2 ms):
main8f7c957ed0: 214, 215, 215, 215, 215With the GPU still waiting on vertex reads over PCIe (plain
main) the gain is about 4%. Once #9712 moves those reads to device memory the frame is bound by the draw committer, and this change gives about 12% (GPU 12.2 ms per present in both).Stability: 21 runs with this change in the build (morning, afternoon and evening, switch on and off, alone and with #9712). One of them, the first morning run, stopped about 47 s in, during loading, with an access violation in the title's SPFXUnityPlugin on
UnityGfxDeviceWorker(read of 0x8). The other 20 reached gameplay without a stop. I have not seen that stop onmain(10 runs of8f7c957ed0today), so I can't rule the change out, but I could not make it happen again.Tests:
agc_driver_same_queue_label_waitnow also waits 16 times on a write-watched CPU flag that an earlier wait saw: 0 extra epoch bumps with this change, 16 withAPS5_NO_ORDERED_WAITS=1(the test then fails). Rewriting the flag with the same value before one wait gives 1 extra bump, as it should. Passing:agc_driver_same_queue_label_wait,agc_driver_same_queue_label_wait_draw_pipeline,agc_driver_recorder,agc_graphics_profile_draw.Validation layer (Vulkan SDK in
aps5-toolchain,VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,ANYPS5_NO_SHADER_CACHE=1,ANYPS5_REQUIRE_VULKAN=1,ctest -V): the four tests above onmainfc42d49548(without the new test cases) and on this change: 0VUID-in both logs, nowas not found but was requested by env var VK_INSTANCE_LAYERS.Checklist
main; no other open PR implements the same functions.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by gabichuuuuu on 2026-11-08T01:31:07Z.
Review: COMMENTED
Ran
46d30d5049merged onmain302864d48con Windows 11 x64 (WinLibs GCC 15.2), on an NVIDIA laptop GPU (Turing, driver 610) and an Intel iGPU (driver 101.70xx), withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1andVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation(Khronos validation layer 1.4.368),ctest -R '^(agc_driver_same_queue_label_wait|agc_completion_label_wait)' -V.16cf4d9070(theAccessibleguard and theENVIRONMENT.mdrow) landed after these runs; I'll add a run of it.mainmain+ the PR'sSameQueueLabelWait.cpponlyWaitStatistics.cppchange, the PR's version ofagc_driver_same_queue_label_waitand its_draw_pipelinevariant fail on both GPUs with the failure the PR describes: "WAIT_REG_MEMs on a CPU flag an earlier wait already saw with the same value, unwritten since, started new collect epochs: 16 extra bumps for 16 waits" (17 bumps with 16 waits, against 1 without). With the change they pass, and the rewritten-flag cases still bump once per wait.was not found but was requested by env var VK_INSTANCE_LAYERS, and no log on either side has aVUID-. To be sure validation messages reach these logs, the same layer with best practices on printed 28BestPractices-warnings into anagc_driver_recorderlog on each GPU.No finding in the code.
orderedis per queue worker thread, a changed value or any write to the range since the stored generation still bumps, and withAPS5_NO_ORDERED_WAITSsetgenerationstays 0, so every wait bumps as onmain.AI-assisted: yes.