AGC: a compute dispatch is captured before the title has written its tables when a cross-queue wait passes on a recorded label #1787
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 fisherjoey on 2026-10-08T19:10:46Z.
Summary
A compute queue worker passes a
WAIT_REG_MEMas soon as another queue's worker has recorded the label store it waits for (storedSince, or the recorder's label table throughtakeLabelinWaitMemory.cpp). The GPU has not executed that store yet. The dispatches after the wait are then captured from guest memory the title has not filled yet.On hardware the CP cannot pass the wait before the GPU executes the producer's store, so titles fill memory a gated dispatch reads after they submit the buffer and rely on GPU latency to keep it ordered. Demon's Souls does this every frame:
The queue 0 worker records that label about 6 ms after the submit burst. The queue 0x20 worker passes the wait at once and captures the dispatch while the table slot still holds an older allocation's bytes.
This is not the #479 class (a static SRT walk through a NULL pointer behind an exec guard). That was my first guess, because one of the variants reads a NULL pointer. Here the pointer is NULL or garbage because the table has not been written yet. #1100 is the same kind of problem for
SET_*_REG_INDIRECTregister lists that a title rewrites after submit. That one is fixed by reading at submit, which does not work for memory the title writes later.Evidence
Demon's Souls (PPSA01341 v1.07), always 20-90 s into boot (SIE logo, PS Studios movie, start of the opening cinematic). The exception is thrown on a compute queue worker in
Driver::dispatch:table - 0x120, a per-dispatch struct in the same ring. In the failing captures that pointer was0(hence+0x60), or the struct held floats from an earlier use of the ring (hence the bad V#). The memory stayed that way for the 889 ms the worker kept retrying, with no CPU store into it, because the title was itself waiting for the stalled queue.0x2425ff520 == 1,0x2425ff480 == 1) that memory did not satisfy 1 s later. The worker had passed them on the label table, from a store that queue 0 had recorded in the 4855-dword graphics buffer submitted just before.APS5_THREAD_PRIORITY=high, #1788), 9 of 15 boots failed. Before any of this work it was about 3 of 35.Landing the waits alone (polling until memory satisfies them before the next guest read) removes this early read but exposes a late one: 4 of 8 boots still failed. The gate lands, but the worker captures dispatch k of the group 11-25 ms later, because it waits for the GPU mutex behind queue 0 between dispatches. The title re-arms the gate label and reuses the slots 8-16 ms after the gate lands, always after a flip completes. Holding the worker 60 ms after the gate with queue 0 blocked at its flip packet gave 0 re-arms in about 90 holds; without the flip block, the title re-armed after the next flip. On hardware the CP reads the whole group within microseconds of the gate, so the title never sees the late read.
Proposed fix
Two commits:
LabelStorerecords the writing queue for that check. The graphics queue is exempt by default. Landing its waits on the compute queues' labels took the attract from 50-54 to 36-39.5 fps, and this title fills its graphics buffers before it submits them.APS5_LAND_WAITS_ALL_QUEUES=1includes it, andAPS5_NO_LAND_WAITS=1turns landing off. A landing wait restarts its timeout only when packets finish, since it runs inside a packet that is itself in flight.SET_*packets. The real dispatch then adopts the parked result if the program address and cache key still match. The lookahead stops at a packet that writes guest memory other than a label, at conditional or predicated packets, and at a dispatch that reads a label or a buffer an earlier dispatch of the run writes. CPU-path indirect arguments are read at the gate too. If the device later finds the memory changed (guest snapshot differs from registered memory), the dispatch is resolved again from current memory, as onmain.APS5_NO_GROUP_CAPTURE=1disables it.Results with both,
APS5_THREAD_PRIORITY=high: 15 of 15 boots ran their 150 s, against 4 of 4 failures with landing alone on the same day. That includes 6 standard runs, 4 with a 48x24 depth copy that made the crash 2 of 2 before, and 5 with other diagnostics. The group capture costs 25-75 ms per 10 s on queue 0x20 and is adopted 0.35-0.65 ms after the gate on average. Movie and attract frame rates are unchanged: 305-346 presents per 10 s in the movie, and the attract alternates between about 360 and about 520 presents with and without the change, for an unrelated texture reason.One thing is left for discussion. The capture now holds gate-time memory, but the GPU still reads the live import later. Queue 0's next frame overwrites a few structs the group reads, so the device check rejects about 5 dispatches per frame, which are then resolved live (708 in 150 s). Binding gate-time snapshots for those regions would close that gap. It is not in this change.
The settle condition and the landing timeout in commit 1 came later, after a landing wait on a re-armed label hung the title past the main menu. They were not in the build behind the 15 runs above.
Found on Linux 7.2 (Nobara 44), GCC 16, RTX 5070 Ti (595.91.07), Ryzen 5 7600X, with Demon's Souls PPSA01341 v1.07. Measured on
mainatc1241ad0with #157, #861, #864 and #1051, the path fix from #1047 and the changes from #1132 and #1133. The branch is rebased on currentmain(6b56175a) without the diagnostics.The fix is ready on a branch: https://github.com/fisherjoey/AnyPS5/compare/main...fisherjoey:AnyPS5:fix/agc-compute-gate-capture
I'll open the PR if the approach looks right.
AI-assisted: yes.