AGC: a compute dispatch is captured before the title has written its tables when a cross-queue wait passes on a recorded label #1787

Closed
opened 2026-10-08 19:10:46 +00:00 by fisherjoey · 0 comments
fisherjoey commented 2026-10-08 19:10:46 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-08T19:10:46Z.


Summary

A compute queue worker passes a WAIT_REG_MEM as soon as another queue's worker has recorded the label store it waits for (storedSince, or the recorder's label table through takeLabel in WaitMemory.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:

  1. It submits the frame's graphics buffers, then the compute buffers. The first packets of the compute buffers wait on a label that the last graphics buffer writes at its very end.
  2. Its job threads then fill the compute dispatch tables (per-dispatch structs in a ring).

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_INDIRECT register 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:

[videoout] presentation failed: compute shader 0x248a1dd00: guest memory is not readable at 0x60 (range 0x60+0x4)
compute shader 0x2489e6d00: guest memory is not readable at 0x30
compute shader 0x248a1dd00: AGC graphics: shader buffer exceeds descriptor range limit
compute shader 0x248a05b00: buffer descriptor uses an unsupported type
compute shader 0x2489ff000: guest memory is not readable at 0x60
compute shader 0x248a05b00: guest texture descriptor has a null base address
  • 0x248a1dd00 reads a three-pointer table on queue 0x20 (submission of 1931 dwords, once per frame). The second pointer is table - 0x120, a per-dispatch struct in the same ring. In the failing captures that pointer was 0 (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.
  • A write-watch on the table slots showed every reuse written by the title's job threads, not by the GPU. For 0x2489e6d00 and 0x248a05b00 the data was written after the submit was received in 655 of 683 traced dispatches.
  • In the failing submission, an audit of the waits before the dispatch found two (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.
  • Anything that lets the driver run ahead makes the crash more likely. Without the fix and with the driver threads at a higher priority (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:

  1. Land cross-queue waits before a guest read. A wait a worker passes on another queue's recorded store (not yet in memory) is kept on the worker. Before its next dispatch, draw, COND_EXEC or predicated packet, the worker polls until memory satisfies the wait or no unfinished batch writes the label any more. The second condition covers a label the title re-arms after the store lands. A wait on a label the same queue wrote earlier orders no title write and is not kept. LabelStore records 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=1 includes it, and APS5_NO_LAND_WAITS=1 turns landing off. A landing wait restarts its timeout only when packets finish, since it runs inside a packet that is itself in flight.
  2. Resolve the gated group at the gate. Once a compute queue's wait has passed on memory, the worker resolves every dispatch up to the next wait that memory does not satisfy, before issuing any of them. Each one goes through dispatch-cache lookup, capture and recompile, against a scratch copy of the queue state driven through the 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 on main. APS5_NO_GROUP_CAPTURE=1 disables 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 main at c1241ad0 with #157, #861, #864 and #1051, the path fix from #1047 and the changes from #1132 and #1133. The branch is rebased on current main (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.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5767475943 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/1787). Originally posted by [fisherjoey](https://github.com/fisherjoey) on 2026-10-08T19:10:46Z. --- ### Summary A compute queue worker passes a `WAIT_REG_MEM` as soon as another queue's worker has recorded the label store it waits for (`storedSince`, or the recorder's label table through `takeLabel` in `WaitMemory.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: 1. It submits the frame's graphics buffers, then the compute buffers. The first packets of the compute buffers wait on a label that the last graphics buffer writes at its very end. 2. Its job threads then fill the compute dispatch tables (per-dispatch structs in a ring). 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_INDIRECT` register 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`: ``` [videoout] presentation failed: compute shader 0x248a1dd00: guest memory is not readable at 0x60 (range 0x60+0x4) compute shader 0x2489e6d00: guest memory is not readable at 0x30 compute shader 0x248a1dd00: AGC graphics: shader buffer exceeds descriptor range limit compute shader 0x248a05b00: buffer descriptor uses an unsupported type compute shader 0x2489ff000: guest memory is not readable at 0x60 compute shader 0x248a05b00: guest texture descriptor has a null base address ``` - 0x248a1dd00 reads a three-pointer table on queue 0x20 (submission of 1931 dwords, once per frame). The second pointer is `table - 0x120`, a per-dispatch struct in the same ring. In the failing captures that pointer was `0` (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. - A write-watch on the table slots showed every reuse written by the title's job threads, not by the GPU. For 0x2489e6d00 and 0x248a05b00 the data was written after the submit was received in 655 of 683 traced dispatches. - In the failing submission, an audit of the waits before the dispatch found two (`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. - Anything that lets the driver run ahead makes the crash more likely. Without the fix and with the driver threads at a higher priority (`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: 1. Land cross-queue waits before a guest read. A wait a worker passes on another queue's recorded store (not yet in memory) is kept on the worker. Before its next dispatch, draw, COND_EXEC or predicated packet, the worker polls until memory satisfies the wait or no unfinished batch writes the label any more. The second condition covers a label the title re-arms after the store lands. A wait on a label the same queue wrote earlier orders no title write and is not kept. `LabelStore` records 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=1` includes it, and `APS5_NO_LAND_WAITS=1` turns landing off. A landing wait restarts its timeout only when packets finish, since it runs inside a packet that is itself in flight. 2. Resolve the gated group at the gate. Once a compute queue's wait has passed on memory, the worker resolves every dispatch up to the next wait that memory does not satisfy, before issuing any of them. Each one goes through dispatch-cache lookup, capture and recompile, against a scratch copy of the queue state driven through the `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 on `main`. `APS5_NO_GROUP_CAPTURE=1` disables 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 `main` at c1241ad0 with #157, #861, #864 and #1051, the path fix from #1047 and the changes from #1132 and #1133. The branch is rebased on current `main` (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.
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5#1787
No description provided.