fix(agc-driver): delay storage writeback until queue activity settles #4410
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4410"
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 MarcZX10 on 2026-10-12T09:48:16Z.
What
Fixes #4398 by waiting for 50 ms of queue quiet before calling
StoreIdleResults, and only when storage results are pending and no queue work or completions remain. If queue activity changes the idle epoch during the wait, queue 0 rechecks its state instead of exiting. The existing direct-poll fallback remains available for guest code that reads memory without a read hook.Tested
Linux Release, Ninja, current
maine7c70a2df:agc_driver_store_idle_results_tests.ctest -R '^agc_driver_store_idle_results$': passed (1/1) on llvmpipe/lavapipe.agc_driver_store_idle_results_tests --idle-epoch-wake: passed on llvmpipe/lavapipe.tools/check_conventions.py --base upstream/mainandgit diff --check: passed.Scramblrrrr's Windows/RTX 5070 Ti cross-test reproduced the interrupted-wait failure on the original code and reported that the regression mode and six related tests pass with the corrected path. Their separate one-run-per-variant game comparison used an older sparse stack and did not demonstrate a meaningful performance gain; it does not establish the reported #4398 performance delta.
Checklist
main; no other open PR implements the same fixNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt (not applicable).mdfiles or images added to the repositoryImported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-12T09:51:01Z.
Preparing a Windows/RTX 5070 Ti 007 cross-test of your existing #4410 fix, preserving author/cherry-pick attribution: https://github.com/Scramblrrrr/AnyPS5/tree/codex/first-light-idle-storage-cross-test head e1a2c7f3c (from ddc0d2a65). Applied cleanly to our older public-perf/cache-preserving sparse stack cc495f66d; not a uniform current-main build. Source only so far, native checks/game result pending. Current campaign control is still running, so I am deferring compilation until it ends to keep FPS samples uncontaminated. Will report results here and on #2523. AI-assisted: Codex.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-12T09:51:31Z.
Thanks for preparing the cross-test and for preserving the original commit attribution. The Windows/RTX result on that older stack will be useful context alongside the Linux/lavapipe regression test; please report it whenever your current campaign is finished. No urgency from my side.
Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-12T09:53:51Z.
One control-flow concern while reviewing ddc0d2a65 before staging: in the new quiet wait,
if (idleEpoch != idleEpochAtWait) { if (idleResultsPending()) continue; break; }can break thewhile (!ready())with queue 0 still having no pending packet. Below that loop,pending.empty()breaks the outer worker loop, so this seems able to permanently stop queue 0 when another queue changes the idle epoch and the storage-idle predicate becomes false (for example outstanding completions or pending work on another queue).ready()was checked false just above.Would
continueto re-evaluate/poll instead of that innerbreakbe appropriate? This is a source-level concern, not a reproduced Windows failure yet; existing StoreIdleResults fixture only submits queue 0 once and may not cover this wake-up. I have not staged the change or claimed a game result.AI-assisted: Codex.
Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-12T10:05:51Z.
Reproduced the wake-up concern on Windows/RTX 5070 Ti. Added a behavioral fixture mode
agc_driver_store_idle_results_tests.exe --idle-epoch-wake: observe pending storage, allow queue 0 to enter the quiet wait, explicitly flush under GpuMutex, then submit a NOP on queue 0x30 to move the idle epoch; a subsequent queue-0 dispatch writes a different, initially untouched surface. No old surface contents can satisfy the second check.Test-only commit 0792abc93 on your original ddc0d2a65 port fails with the original assertion (exit 1): "the queue-idle store did not bring the result to guest memory without a direct flush or further submission". With f7be67521 (replace the epoch-changed block with unconditional
continue), the wake mode exits 0 and the existing CTest mode passes 1/1 in 0.48 s. Both targets were rebuilt against matching source/headers/DLLs. The fixture includes teardown before its backing vectors die on failure.Public cross-test branch: https://github.com/Scramblrrrr/AnyPS5/tree/codex/first-light-idle-storage-cross-test. Please feel free to cherry-pick 0792abc93 and f7be67521 into #4410; no competing upstream PR. Your original fix remains credited as e1a2c7f3c. Related queue/draw fixtures are building next; corrected game result still pending. AI-assisted: Codex.
Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-12T10:13:49Z.
Corrected idle-writeback stack f7be67521 reached the fully rendered title at frame 848, ~1.61 FPS, ~20.17 decimal GB private. Preceding cc495 control title was frame851 ~1.57 FPS/~20.3 GB. One run/sample each, camera/timing differ, so there is no demonstrated meaningful 007 speed gain from #4410 here. No queue shutdown/new fatal observed during this startup. Stopped intentionally at title for next native cross-test, not a campaign/playability claim.
The concrete contribution is the reproduced multi-queue wake-up failure and its fix already offered on #4410 (0792abc93 / f7be67521). Six related native tests and separate wake mode passed. Host-window #290 preparation 4e4083057 remains source-only and is next; import budget will be explicitly 6144 MiB. AI-assisted: Codex.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-12T10:33:36Z.
Good catch. The epoch wake can arrive while the predicate is temporarily false (for example, completion state changes), and breaking there could let queue 0 exit with no queued submission. I changed that path to continue and re-evaluate
ready()and the idle/completion predicates. The storage idle regression test passes on Linux/lavapipe after the change, and conventions pass on current main. I also rebased onto current main and corrected the commit subject; the commit remains authored and committed by MarcZX100 with no coauthor trailer.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-12T10:37:02Z.
I cherry-picked the wake-up regression fixture as a separate commit authored by you, preserving its original author and adding no coauthor trailer. Both the regular CTest case and
--idle-epoch-wakenow pass here on llvmpipe/lavapipe. The PR title/body now match the repository template; the refreshed conventions workflow is queued.Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-12T10:37:33Z.
Thanks. I checked 746a6ad73cebb82406bdf36f79ecdf5faf01ae98; its epoch-change path now matches the continue/recheck behavior we independently tested on Windows. My earlier six-test pass and wake-mode pass were on the older port f7be67521, not a build of this newly rebased full head, so I won't conflate those.
The reusable two-surface/multi-queue regression remains separately available as 0792abc93 if you want it in the PR's tests. The 007 quiet title result was
1.61 FPS versus the preceding1.57 control, so no meaningful speedup established for this title. Current run is the separate #290 stack. Thanks for resolving the failure before it got carried further.AI-assisted: Codex.
Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-12T13:16:25Z.
Ran this on AMD hardware, since the GPU tests in CI only use lavapipe: Windows 11 (26300), AMD Radeon 860M (RDNA 3.5, driver 32.0.13058.8001), WinLibs GCC 15.2.0, Release,
BUILD_TESTING=ON. Head746a6ad73merged ontomainf8dee0595, together with #4445: on this GPU,maincrashes 47agc_tests insideamdvlk64.dllwithout it (#4435), which would hide anything else.ctest -R '^agc_' -j 1: 435/435.ctest -E '^agc_' -j 4: 530/530.agc_driver_store_idle_results: 3/3.agc_driver_store_idle_results_tests --idle-epoch-wake: exit 0, 3/3.main'sQueueWorker.cpprestored,--idle-epoch-wakeexits 1, 3/3, withAGC graphics: idle wake fixture did not observe pending storage results. That is the fixture's setup check, not its write-back assertion. The plainctestcase still passes onmain'sQueueWorker.cpp, so--idle-epoch-wakeis the only part that fails without the change.I can't run Dreaming Sarah here, so this says nothing about the FPS figure in #4398.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-12T19:11:21Z.
Planet of Lana (PPSA19450) is a title where the per-present store costs a lot. Setup: Windows 11, MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, RTX 3070 Laptop. The build is a local test stack on
maind146ec1b6, with #4267 so the game boots, plus #494, #2863 and #290, which I was measuring for other reasons.Without a quiet period (
main's #3777 behaviour), with Lana standing in the first village:With a 16 ms quiet period (my own draft, before I found this PR), the same scene went from 75.1 to 92.3 presents per 10 s. GPU busy time went from 95 to 34 ms per present, read from the driver profile. These are single runs.
That build also needed #2904, now merged: with the store postponed, a compute shader reached reused depth memory as a storage image, and the game stopped with
storage image access to depth/stencil surface ... is not implementeduntil #2904 was added. On currentmainthis is covered. That build also had #4320, now merged too, for frame dumps.With this PR's queue logic in place of the draft (its
QueueWorker.cppchange, the same as at3824282e5), a later area ran at 177.8 presents per 10 s for 300 s with no errors. That matches the draft's 176.7-181.4 in the same area.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-12T21:39:32Z.
Thanks for adding the Planet of Lana measurements and describing the dependency stack. The 300-second run suggests this queue logic avoids per-present writebacks in that later area without errors, and the single-run 16 ms draft comparison is useful context; I will not attribute the frame-rate change to this PR alone. Noted that the reported build also included #4267 and other local stack changes.
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-12T23:24:53Z.
Windows test (MinGW GCC 15.2, Release, Windows 10, RTX 4080 SUPER). Built in a batch with five other open GPU PRs cherry-picked onto main
44ab0c39e(not current main, which needs a submodule that isn't checked out here), so only the tests that belong to this PR say anything about it:tests/execution/StoreIdleResults.cpp(agc_driver_store_idle_results): 3 of 3 runs passed. TheQueueWorker.cppchange itself was only exercised through that test; no title was run.Not tested: no game run; the batch was not rebuilt per PR, so a failure would have needed a bisect (there was none besides the flake).
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-13T00:20:05Z.
Why 50 ms? EagleBearerYS's PPSA19450 runs cover the gain, but with a 16 ms wait: the queues there are idle for 5-10 ms between frames, so 16 ms already skips every store. A title that polls guest memory with no read hook, the case #3777 went in for, gets each result later by the whole wait, so it should be no longer than it has to be.
Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-13T00:31:39Z.
A second title shows the same effect: Animal Well (PPSA22520), a 2D game on its own engine. Setup: Windows 11, MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, RTX 3070 Laptop. The build is
main43e3a70f8plus #4859, so the game boots, and #4693, measured with and without this PR at3824282e5. Same scene each run (new game, first room, standing),APS5_PROFILE_DRAW=1, runs interleaved A, B, A, windows after 80 s:Without the quiet period, the idle store writes back ~41 MiB of storage results every frame, and the flip then reads the 3840x2160 display buffer back from guest memory instead of presenting the resident image. With this PR both go away, and the game goes from ~33 to ~42 fps, beyond this PC's ~15% run-to-run noise. Four more runs with this PR and other settings (mailbox present mode, high thread priority, a smaller batch cap, a usleep trace) stayed at 391-428 presents per 10 s.
Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-13T01:22:46Z.
On the 16 ms question: I measured both waits on Animal Well (PPSA22520), with the same setup as my comment above. The build is
main43e3a70f8plus #4859 and #4693, with this PR at3824282e5; the 16 ms runs change onlyIdleResultsQuietPeriod. Same scene (new game, first room, standing),APS5_PROFILE_DRAW=1, 10 s windows after 80 s, runs interleaved 50, 16, 50, 16:16 ms keeps the gain on this title too. The frame rate matches 50 ms within this PC's ~15% noise (means 388 and 389), and over 99.7% of the write-back volume is gone. It doesn't skip every store, though, because Animal Well's queues stay idle longer between frames than Lana's. An instrumented 50 ms run timed each quiet wait until new activity ended it. In the first room, per 10 s window:
On the logos and menus, the median is 7.5-8.1 ms, and one wait in five windows reached 50 ms. So in these runs, a wait just above 28 ms would have skipped every store in gameplay. A 16 ms wait sits around this title's p90, which is why a few windows still store and the flip then reads the display buffer through guest memory.
Imported from boykopovar/AnyPS5. Originally posted by tibzejoker on 2026-10-13T04:56:19Z.
A regression from this PR in GTA V (PPSA04264). Windows 11, RTX 4090, GCC 15.2.0 UCRT, Release, write watch on.
Setup. Base:
mainat37dd48308plus the open PRs GTA needs to reach Story (#757, #423, #290, #637, #4082, #4114, #4163, #4500, #448 ported, a few cherry-picks) and our local hacks. Branchtibzejoker/AnyPS5gtav-next6. The only difference between the two builds is the revert of048206e18.Result. Same scripted path each time: menu, Story, prologue.
With #4410,
libSceJobManagerkernels on queue 0x20 start reading V#s that are all0xFF:Our local
GTAV_SKIP_DISPATCH_ERRORShack skipped 37 of those. Then another JobManager kernel aborts the run:With the revert, none of these appear.
mainup toe55b881f0, the merge before this one, is fine. Reverting #4468 or #4500 instead didn't help.What I think happens (not traced): these kernels take their V#s from a block that earlier GPU work on the same submission fills in (see #3055 for how this title uses that pool). If that write reaches guest memory through the idle storage results path, the 50 ms quiet period means the next dispatch's capture reads the block before the store, so it sees the pool's
0xFFfill. That's the "guest reads memory without a read hook" case @oneandonlydean raised above, here with the reader being a later dispatch's capture rather than CPU code.I can test a fix or a shorter wait on this title.
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-13T05:30:52Z.
Thanks for the bisect. A dispatch's capture reads through the flush hook, so a pending store over that block should land before the V#s are read, and the #3055 notes say this block is filled by
WRITE_DATA, which flushes pending images first. To find which read misses it, could you run the #4410 build three ways: withAPS5_TRACE_FLUSH=1, withAPS5_BDA_FLUSH=1, and withoutGTAV_SKIP_DISPATCH_ERRORS? The first failing line of each would do.Imported from boykopovar/AnyPS5. Originally posted by tibzejoker on 2026-10-13T05:44:26Z.
@oneandonlydean the three runs, same #4410 build as above (gtav-next6 with the revert dropped), same scripted path:
APS5_TRACE_FLUSH=1APS5_BDA_FLUSH=10x25b45a200, the known #757 one, same as with the revertGTAV_SKIP_DISPATCH_ERRORScompute shader 0x7ff73adc1200: buffer descriptor 1 uses an unsupported type: ffffffff ffffffff ffffffff ffffffffThe trace shows a storage image whose range covers the JobManager block. It is still pending well into Story, and the first failure comes right after it is flushed by a CPU access:
The same image is flushed again for accesses at 0x2a6408000, 0x2a649d000, 0x2a64b5000, 0x2a64c4000, 0x2a64d1000 and 0x2a6533000, with the failing dispatches in between. The failing blocks are around 0x2a63e4500, inside it.
Before this run, the only flushes were the eight
for idle 0x0+0xffffffffffffffffones at startup.So the capture doesn't miss a store. It looks like the opposite: an old storage-image result over 0x2a63e0000 is still pending when the title reuses that memory as the JobManager pool. The CP and CPU write the pool, a CPU access then flushes the stale image result over it, and the kernels read the image's bytes (0xFF) where their V#s should be. Without the 50 ms wait, that result was stored at idle long before the pool was reused. With
APS5_BDA_FLUSH=1it is stored at an earlier read, also before the reuse.That's my reading of the log, not traced further. Logs are available if you want them: about 3 MB, 0.5 MB gzipped.
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-13T06:51:56Z.
Reproduced on main with a test, thanks for the trace. It's older than this PR: on memory that isn't write-tracked (imports on Windows), a partial store drops the saved original, and the next store of the same image writes the layer whole over newer CPU data. This PR only keeps results pending long enough to hit it; with it reverted the same test still fails. A fix for the store is coming as its own PR.