fix(agc): stop the dispatch look-ahead before indirect arguments an earlier dispatch may write #2990

Merged
CnRJay merged 3 commits from upstream-pr/2990 into main 2026-10-10 23:46:18 +00:00
CnRJay commented 2026-10-10 20:01:11 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-10-10T20:01:11Z.


What

PPSA28416 (STAR WARS: Galactic Racer, UE5) runs a compute dispatch that writes the arguments of a DISPATCH_INDIRECT with USE_THREAD_DIMENSIONS later in the same run. After a gate opens, resolveGroupAhead resolves the run's dispatches ahead of execution. For this indirect dispatch the CPU reads the arguments then, before the dispatch that writes them has run, and the stale counts are adopted:

Vulkan dispatch: workgroup count exceeds device limits

(the counts were 16926492x1116079131x3241227624).

Changes:

  • resolveGroupAhead stops before a DISPATCH_INDIRECT whose 12 argument bytes overlap a range an earlier dispatch of the run writes or a label the run writes. It also stops when an earlier dispatch's writes are not known: one that was not parked, has no compiled result, or stores through guest pointers (a BdaPagetable binding). The stop is counted in writtenBefore.
  • The workgroup-limit error names the group counts and the device limits, and for a CPU-read indirect dispatch the argument address and the reason it was read by the CPU.

Tested

Windows 11, WinLibs GCC 15.2.0 r7, Release, RTX 4080.

  • New agc_driver_indirect_arguments_written_ahead: on queue 0x20, after a satisfied WAIT_REG_MEM, a dispatch stores 2,3,4 into a buffer and a DISPATCH_INDIRECT with USE_THREAD_DIMENSIONS reads them; its program adds 1 to a counter per group. A warm-up submission comes first, because the look-ahead needs a device. Without the fix the look-ahead reads the initial 1,1,1, and the counter is 1. With it the counter is 24. Runs in 0.25 s with ANYPS5_NO_SHADER_CACHE=1.
  • agc_driver_gated_dispatch_capture passes. Full suite: 718/718 pass (6 VideoOut tests skipped, as on main).
  • PPSA28416: the workgroup-limit error above is gone.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4814057309 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2990). Originally posted by [CnRJay](https://github.com/CnRJay) on 2026-10-10T20:01:11Z. --- ### What PPSA28416 (STAR WARS: Galactic Racer, UE5) runs a compute dispatch that writes the arguments of a `DISPATCH_INDIRECT` with `USE_THREAD_DIMENSIONS` later in the same run. After a gate opens, `resolveGroupAhead` resolves the run's dispatches ahead of execution. For this indirect dispatch the CPU reads the arguments then, before the dispatch that writes them has run, and the stale counts are adopted: ``` Vulkan dispatch: workgroup count exceeds device limits ``` (the counts were 16926492x1116079131x3241227624). Changes: - `resolveGroupAhead` stops before a `DISPATCH_INDIRECT` whose 12 argument bytes overlap a range an earlier dispatch of the run writes or a label the run writes. It also stops when an earlier dispatch's writes are not known: one that was not parked, has no compiled result, or stores through guest pointers (a `BdaPagetable` binding). The stop is counted in `writtenBefore`. - The workgroup-limit error names the group counts and the device limits, and for a CPU-read indirect dispatch the argument address and the reason it was read by the CPU. ### Tested Windows 11, WinLibs GCC 15.2.0 r7, Release, RTX 4080. - New `agc_driver_indirect_arguments_written_ahead`: on queue 0x20, after a satisfied `WAIT_REG_MEM`, a dispatch stores 2,3,4 into a buffer and a `DISPATCH_INDIRECT` with `USE_THREAD_DIMENSIONS` reads them; its program adds 1 to a counter per group. A warm-up submission comes first, because the look-ahead needs a device. Without the fix the look-ahead reads the initial 1,1,1, and the counter is 1. With it the counter is 24. Runs in 0.25 s with `ANYPS5_NO_SHADER_CACHE=1`. - `agc_driver_gated_dispatch_capture` passes. Full suite: 718/718 pass (6 VideoOut tests skipped, as on `main`). - PPSA28416: the workgroup-limit error above is gone. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
Mouhand-Kaddo commented 2026-10-10 20:35:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Mouhand-Kaddo on 2026-10-10T20:35:24Z.


Windows and Linux validation on current main 262c03169, with both commits of this PR's head 7a3c38c00 applied and no other compatibility changes:

  • Windows 11 x64, MinGW-w64 GCC 15.2.0, Release, RX 6900 XT: agc_driver_indirect_arguments_written_ahead and agc_driver_gated_dispatch_capture passed 2/2 (1.79 s).
  • Arch WSL2, GCC 16.2.1, Release, lavapipe (software Vulkan): the same tests passed 2/2 (0.84 s).

These results cover the argument-producing dispatch followed by a thread-dimension indirect dispatch and the gated-capture regression. They are focused test results, not a full-suite or boot claim. No game payloads are attached. Linux hardware rendering was not tested.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6101914533 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2990#issuecomment-6101914533). Originally posted by [Mouhand-Kaddo](https://github.com/Mouhand-Kaddo) on 2026-10-10T20:35:24Z. --- Windows and Linux validation on current main `262c03169`, with both commits of this PR's head `7a3c38c00` applied and no other compatibility changes: - Windows 11 x64, MinGW-w64 GCC 15.2.0, Release, RX 6900 XT: `agc_driver_indirect_arguments_written_ahead` and `agc_driver_gated_dispatch_capture` passed 2/2 (1.79 s). - Arch WSL2, GCC 16.2.1, Release, lavapipe (software Vulkan): the same tests passed 2/2 (0.84 s). These results cover the argument-producing dispatch followed by a thread-dimension indirect dispatch and the gated-capture regression. They are focused test results, not a full-suite or boot claim. No game payloads are attached. Linux hardware rendering was not tested.
Dextroid17 commented 2026-10-10 21:50:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-10T21:50:27Z.

Review: COMMENTED


Read this against the surrounding code rather than the summary. In substance it looks right; three observations follow, none of them blocking.

The shape is correct, and it is the only shape that can work. resolveGroupAhead already refused to adopt a captured result overlapping an earlier write (OverlapsLabel and OverlapsRange), but those run after dispatchIndirect(...) has already read the arguments through the checked guest-memory path. Once the stale counts are in hand, declining to adopt them is too late — so checking the arguments before the call is the right place. Wrapping DispatchArgumentAddress so a throw stops the run matches how the neighbouring dispatchIndirect call is already guarded in the same loop.

The arithmetic is sound. Both overlap tests are half-open (range.first < argumentsEnd && arguments < range.second, and the label form), and 12 bytes is right by contract: Pm4.hpp documents the argument address as "the guest address of its three group-count dwords".

The test is the strongest part, because it can actually fail before the fix: the writer sets the arguments to 2, 3, 4, and the assertion is 24 — which 2×3×4 produces and the initial 1,1,1 cannot (the counter blob adds one per group, as the description says). A stale read gives 1, not 24, so the test separates the two worlds instead of merely exercising the path.

Three things I would like to know — again, none blocking:

  1. Does unknownWrites cost look-ahead breadth on any measured title? It now also stops the run for a dispatch with no compiled result, and for one storing through a BdaPagetable binding. That is deliberately conservative and the new counter makes it visible in [groupcap], but a before/after on a title that leans on pointer stores would show whether the conservatism is free.
  2. writtenBefore now counts two different things — the new "the arguments were written ahead" and the existing "the captured range overlapped" — while the report line renders it as "read an earlier dispatch's output". A reader cannot tell which happened; a second counter, or a word in the report, would fix that.
  3. Does the test fail without the fix, as run? The body reads as though it should (24 against 1), but saying so, and how it was observed, would let a reviewer skip proving it.

One thing I checked that turned out to be a non-issue, so it is not a request: the 12-byte argument width, since a DISPATCH_INDIRECT shaped without thread dimensions might look like it needs more. Pm4.hpp settles it as three group-count dwords, so the code is right as written.

Written with AI assistance.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5480925649 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2990#pullrequestreview-5480925649). Originally posted by [Dextroid17](https://github.com/Dextroid17) on 2026-10-10T21:50:27Z. **Review:** COMMENTED --- Read this against the surrounding code rather than the summary. In substance it looks right; three observations follow, none of them blocking. **The shape is correct, and it is the only shape that can work.** `resolveGroupAhead` already refused to *adopt* a captured result overlapping an earlier write (`OverlapsLabel` and `OverlapsRange`), but those run *after* `dispatchIndirect(...)` has already read the arguments through the checked guest-memory path. Once the stale counts are in hand, declining to adopt them is too late — so checking the arguments *before* the call is the right place. Wrapping `DispatchArgumentAddress` so a throw stops the run matches how the neighbouring `dispatchIndirect` call is already guarded in the same loop. **The arithmetic is sound.** Both overlap tests are half-open (`range.first < argumentsEnd && arguments < range.second`, and the label form), and 12 bytes is right by contract: `Pm4.hpp` documents the argument address as *"the guest address of its three group-count dwords"*. **The test is the strongest part**, because it can actually fail before the fix: the writer sets the arguments to 2, 3, 4, and the assertion is **24** — which 2×3×4 produces and the initial `1,1,1` cannot (the counter blob adds one per group, as the description says). A stale read gives 1, not 24, so the test separates the two worlds instead of merely exercising the path. Three things I would like to know — again, none blocking: 1. **Does `unknownWrites` cost look-ahead breadth on any measured title?** It now also stops the run for a dispatch with no compiled result, and for one storing through a `BdaPagetable` binding. That is deliberately conservative and the new counter makes it visible in `[groupcap]`, but a before/after on a title that leans on pointer stores would show whether the conservatism is free. 2. **`writtenBefore` now counts two different things** — the new "the arguments were written ahead" and the existing "the captured range overlapped" — while the report line renders it as *"read an earlier dispatch's output"*. A reader cannot tell which happened; a second counter, or a word in the report, would fix that. 3. **Does the test fail without the fix, as run?** The body reads as though it should (24 against 1), but saying so, and how it was observed, would let a reviewer skip proving it. One thing I checked that turned out to be a non-issue, so it is not a request: the 12-byte argument width, since a `DISPATCH_INDIRECT` shaped without thread dimensions might look like it needs more. `Pm4.hpp` settles it as three group-count dwords, so the code is right as written. Written with AI assistance.
adriadam10 commented 2026-10-10 23:46:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T23:46:06Z.


Checked on current main: both agc_driver_indirect_arguments_written_ahead and agc_driver_gated_dispatch_capture pass, and the new test fails without the src changes. Windows/Linux runs by @Mouhand-Kaddo and the review by @Dextroid17 cover the rest; merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6103444258 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2990#issuecomment-6103444258). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T23:46:06Z. --- Checked on current main: both agc_driver_indirect_arguments_written_ahead and agc_driver_gated_dispatch_capture pass, and the new test fails without the src changes. Windows/Linux runs by @Mouhand-Kaddo and the review by @Dextroid17 cover the rest; merging.
Sign in to join this conversation.
No reviewers
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!2990
No description provided.