AGC: console measurements of write order and read-after-write between draws and dispatches without a partial flush (hardware evidence for #7340 / #9852; queue-0 dispatches) #28656

Open
opened 2026-12-02 15:19:34 +00:00 by aKazm1 · 0 comments
aKazm1 commented 2026-12-02 15:19:34 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by aKazm1 on 2026-12-02T15:19:34Z.


Console measurements of an assumption several AGC driver changes rest on, with the method and the numbers. @teepean @EdouardSence: #7340 and #9852 state that the guest GPU leaves stores and atomics of draws that no barrier separates unordered; these runs confirm it on hardware. @Celegans12 @oneandonlydean: #9176 keeps queue-0 dispatches ordered and lists console behavior as untested; the graphics ring does not order dispatches either.

Console: retail PS5, system software 13.000.040, gfx1013, graphics ring (DCB, sceAgcDriverSubmitDcb), OpenAGC low-level path, hand-encoded wave32 shaders.

Method. Every pixel or thread of workload A takes a ticket with global_atomic_add ... glc on a counter and stores its workload id at log[ticket] with a plain global_store_dword; workload B does the same on the same counter and log. The log therefore lists the order in which the two workloads' memory operations reached memory. A is large (a 512x512 triangle, or 4096 groups of 64 threads: 262,144 invocations either way), optionally slowed by a bounded s_sleep 1 loop before its ticket. B is small (a 2,016-pixel triangle inside A's area, or 32 groups of 64) and does not wait. B is recorded right after A, with nothing between them or with one EVENT_WRITE (event index 4) between them. For read-after-write, A stores 1 at data[ticket], and every invocation of B reads data[slot * 128] and A's counter with an atomic add of 0 (a read at the L2, past the per-CU caches) and logs both values.

Write order (A's tickets taken after B's first ticket; every run counted all invocations, none lost):

A, then B no sync PS_PARTIAL_FLUSH between them CS_PARTIAL_FLUSH between them
draw, draw (same target, same buffer) 17,115 to 29,262 in 10 of 10 runs (the draws alternate 3,151 to 3,787 times in the log) 0 in 6 of 6
dispatch, dispatch 19,193 to 23,473 in 15 of 15 runs (3,175 to 3,875 alternations) 0 in 9 of 9
draw, dispatch all of B's 2,048 tickets before A's first, 2 of 2 (A's pixels sleep before their ticket) 0 in 2 of 2 all of B before A again, 2 of 2

Read after write (B's reads that returned 0 because A had not stored that slot yet):

A writes, B reads no sync matching partial flush CS_PARTIAL_FLUSH after a draw
dispatch, dispatch 73 and 102 of 2,048; every read of A's counter below 262,144 (242,739 to 260,193) CS: 0 of 2,048, 2 of 2
draw, draw 5 and 19 of 2,016; A's counter read at 250,241 to 262,112 PS: 0 of 2,016, 2 of 2
draw, dispatch 2,048 of 2,048, A's counter read as 0, 2 of 2 PS: 0 of 2,048, 2 of 2 2,048 of 2,048, 1 of 1

So on this console the GPU orders neither the writes nor the reads of a draw or dispatch against the one before it unless the command stream has a partial flush between them, and the flush has to cover the earlier work's stage: a CS_PARTIAL_FLUSH does not wait for earlier pixel work.

What this bears on in the driver:

  1. The premise of #7340 (write-only stores) and #9852 (atomic-only updates) holds on hardware: plain stores and atomics of consecutive draws reach memory interleaved without a flush, and one PS_PARTIAL_FLUSH orders them completely, which is what SealWriteOnly relies on.
  2. sealsWriteOnly also seals at CS_PARTIAL_FLUSH (event 0x07). On the console that event does not order earlier pixel work, so sealing draw writes there orders more than the hardware does. It is the safe direction; I mention it only for anyone narrowing the seals.
  3. Queue-0 dispatches: the graphics ring runs consecutive dispatches side by side even when they update the same counter and store to the same buffer, and lets a dispatch run before an earlier draw's pixel work, unless the command stream has the matching partial flush. AnyPS5 separates every queue-0 dispatch from the work around it with full barriers (DispatchTrailing after each one, DispatchLeading before it unless the previous barrier already covers it), and #9176 overlaps only compute-ring dispatches with disjoint accesses. Extending #9176 to queue 0 between guest flushes would match the hardware. SAROS (PPSA07631) records about 990 dispatches and about 1,650 of these barriers per frame.
  4. Read-after-write without a flush is unordered as well, but in the same-kind cases B only starts when A is nearly done (89 to 94 % of A's tickets taken), so most of B's reads already see A's values. A driver that dropped read-after-write breaks without a guest flush would produce more stale reads than the console does in practice, so these numbers are not an argument for doing that.

I have no numbers for a dispatch followed by a draw: in my hand-written command buffers that order did not complete. I can attach the payload source and the raw output.

AI-assisted: Yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:6748240820 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/28656). Originally posted by [aKazm1](https://github.com/aKazm1) on 2026-12-02T15:19:34Z. --- Console measurements of an assumption several AGC driver changes rest on, with the method and the numbers. @teepean @EdouardSence: #7340 and #9852 state that the guest GPU leaves stores and atomics of draws that no barrier separates unordered; these runs confirm it on hardware. @Celegans12 @oneandonlydean: #9176 keeps queue-0 dispatches ordered and lists console behavior as untested; the graphics ring does not order dispatches either. **Console:** retail PS5, system software 13.000.040, gfx1013, graphics ring (DCB, `sceAgcDriverSubmitDcb`), OpenAGC low-level path, hand-encoded wave32 shaders. **Method.** Every pixel or thread of workload A takes a ticket with `global_atomic_add ... glc` on a counter and stores its workload id at `log[ticket]` with a plain `global_store_dword`; workload B does the same on the same counter and log. The log therefore lists the order in which the two workloads' memory operations reached memory. A is large (a 512x512 triangle, or 4096 groups of 64 threads: 262,144 invocations either way), optionally slowed by a bounded `s_sleep 1` loop before its ticket. B is small (a 2,016-pixel triangle inside A's area, or 32 groups of 64) and does not wait. B is recorded right after A, with nothing between them or with one `EVENT_WRITE` (event index 4) between them. For read-after-write, A stores 1 at `data[ticket]`, and every invocation of B reads `data[slot * 128]` and A's counter with an atomic add of 0 (a read at the L2, past the per-CU caches) and logs both values. **Write order** (A's tickets taken after B's first ticket; every run counted all invocations, none lost): | A, then B | no sync | PS_PARTIAL_FLUSH between them | CS_PARTIAL_FLUSH between them | |---|---|---|---| | draw, draw (same target, same buffer) | 17,115 to 29,262 in 10 of 10 runs (the draws alternate 3,151 to 3,787 times in the log) | 0 in 6 of 6 | | | dispatch, dispatch | 19,193 to 23,473 in 15 of 15 runs (3,175 to 3,875 alternations) | | 0 in 9 of 9 | | draw, dispatch | all of B's 2,048 tickets before A's first, 2 of 2 (A's pixels sleep before their ticket) | 0 in 2 of 2 | all of B before A again, 2 of 2 | **Read after write** (B's reads that returned 0 because A had not stored that slot yet): | A writes, B reads | no sync | matching partial flush | CS_PARTIAL_FLUSH after a draw | |---|---|---|---| | dispatch, dispatch | 73 and 102 of 2,048; every read of A's counter below 262,144 (242,739 to 260,193) | CS: 0 of 2,048, 2 of 2 | | | draw, draw | 5 and 19 of 2,016; A's counter read at 250,241 to 262,112 | PS: 0 of 2,016, 2 of 2 | | | draw, dispatch | 2,048 of 2,048, A's counter read as 0, 2 of 2 | PS: 0 of 2,048, 2 of 2 | 2,048 of 2,048, 1 of 1 | So on this console the GPU orders neither the writes nor the reads of a draw or dispatch against the one before it unless the command stream has a partial flush between them, and the flush has to cover the earlier work's stage: a CS_PARTIAL_FLUSH does not wait for earlier pixel work. **What this bears on in the driver:** 1. The premise of #7340 (write-only stores) and #9852 (atomic-only updates) holds on hardware: plain stores and atomics of consecutive draws reach memory interleaved without a flush, and one PS_PARTIAL_FLUSH orders them completely, which is what `SealWriteOnly` relies on. 2. `sealsWriteOnly` also seals at CS_PARTIAL_FLUSH (event 0x07). On the console that event does not order earlier pixel work, so sealing draw writes there orders more than the hardware does. It is the safe direction; I mention it only for anyone narrowing the seals. 3. Queue-0 dispatches: the graphics ring runs consecutive dispatches side by side even when they update the same counter and store to the same buffer, and lets a dispatch run before an earlier draw's pixel work, unless the command stream has the matching partial flush. AnyPS5 separates every queue-0 dispatch from the work around it with full barriers (`DispatchTrailing` after each one, `DispatchLeading` before it unless the previous barrier already covers it), and #9176 overlaps only compute-ring dispatches with disjoint accesses. Extending #9176 to queue 0 between guest flushes would match the hardware. SAROS (PPSA07631) records about 990 dispatches and about 1,650 of these barriers per frame. 4. Read-after-write without a flush is unordered as well, but in the same-kind cases B only starts when A is nearly done (89 to 94 % of A's tickets taken), so most of B's reads already see A's values. A driver that dropped read-after-write breaks without a guest flush would produce more stale reads than the console does in practice, so these numbers are not an argument for doing that. I have no numbers for a dispatch followed by a draw: in my hand-written command buffers that order did not complete. I can attach the payload source and the raw output. 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#28656
No description provided.