fix(agc): keep the gate run going past indirect dispatches whose arguments stay on the GPU #5747

Merged
fisherjoey merged 1 commit from upstream-pr/5747 into main 2026-10-15 15:39:46 +00:00
fisherjoey commented 2026-10-14 09:12:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-14T09:12:12Z.


What

The dispatch look-ahead added in #1864 resolves a gated compute group at the gate, before the title can rewrite the tables the group reads. #2990 made the look-ahead stop before a DISPATCH_INDIRECT whose 12 argument bytes an earlier dispatch of the run may write (or when an earlier dispatch has unknown writes). The stop is needed when the driver reads the arguments on the CPU at resolve time. It also fires when the arguments stay on the GPU, where the CPU never reads them, so in that case it protects nothing.

With this change the look-ahead stops only for the CPU-read paths. Driver::indirectArgumentsPath() now holds the path choice that dispatchIndirect already made (thread dimensions, misaligned, APS5_NO_GPU_INDIRECT), and resolveGroupAhead (DispatchAhead.cpp) asks it before stopping. The dynamic CPU-read reasons (pending image results, workgroup memory, a pending label or copied writer over the argument dwords, no host import) are decided in VulkanDevice::decideIndirect. That runs only on the queue-order pass, after the look-ahead's parked result is adopted (Driver::dispatch returns before any device call while resolving), so it sees the earlier dispatches of the run already recorded. A new entry point, AgcDriverDispatchesAdoptedAhead_nid_postfix, counts the dispatches adopted from the look-ahead so a test can tell a gate-time capture from a late one.

Why

When the stop fires on a GPU-read indirect dispatch, that dispatch and everything behind it in the group are captured when the worker reaches them, after the GPU-mutex waits between dispatches. That is the late read from #1787: by then the title has re-armed the gate and started reusing its table slots, so the capture can read a descriptor the title has not written yet.

Demon's Souls (PPSA01341 v1.07) hits this while loading the tutorial level, on compute shader 0x248a05b00, with the same messages #1787 listed: buffer descriptor uses an unsupported type (ShaderResources.cpp) and runtime image descriptor is invalid. Every indirect dispatch in that title is GPU-read. The [groupcap] ... read an earlier dispatch's output counter was 0 on the #1864 build and has been 150 to 760 per 10 s on every build since 10-11.

@CnRJay, this narrows your stop from #2990; every path that reads the arguments on the CPU still stops. #2990's test agc_driver_indirect_arguments_written_ahead still passes.

#5058 (@Kikoarl) changes the same lines and adds two more CPU-read reasons: arguments not covered by a registered readable range, and pending image writes to flush. Whichever of the two lands second should put the new checks in indirectArgumentsPath(). The look-ahead then keeps stopping for them, because both places use the same function. I'll rebase this PR if #5058 goes in first.

Tested

  • Test from review: agc_driver_gpu_indirect_arguments_misaligned_writer_ahead (the earlier dispatch writes registered arguments through a binding that is not minStorageBufferOffsetAlignment aligned). It and the gate and indirect tests (agc_driver_gpu_indirect_*, agc_driver_indirect_*, agc_driver_gated_dispatch_capture*, agc_driver_write_data_written_ahead, agc_driver_prepared_shaders_indirect, 8 tests) pass on an RTX 5070 Ti and on llvmpipe at 6b14169a4.
  • New test agc_driver_gpu_indirect_arguments_written_ahead (#2990's test, but with a GPU-read DISPATCH_INDIRECT): with main's stop it fails with the gated group adopted 1 dispatches resolved at the gate, expected 2, and with this change it passes. agc_driver_indirect_arguments_written_ahead (#2990) and agc_driver_gated_dispatch_capture (#1864) still pass. All three ran on lavapipe on this branch, rebased on main 66f894761.
  • Demon's Souls PPSA01341 v1.07, Linux, RTX 5070 Ti: a build with this change on top of the PRs that title needs to reach the tutorial level (#758, #5181, ThatsLeo's SPIR-V cache mapping, plus a local stencil-export workaround) ran the full 1500 s with no fatal error and reached the level. All 931 [groupcap] reports showed 0 read an earlier dispatch's output. Without the change, 3 of the last 5 runs on the same stack stopped on 0x248a05b00 during the level load. No performance claim.

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 under Silent stubs in their library's technical debt file
  • 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
  • Unblocks: PPSA01341 #1283
  • GPUs tested: lavapipe (Mesa llvmpipe, LLVM 22.1.8), Linux, for the tests; NVIDIA GeForce RTX 5070 Ti, driver 595.91, Linux (Nobara, kernel 7.2), for the game run
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4855595893 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5747). Originally posted by [fisherjoey](https://github.com/fisherjoey) on 2026-10-14T09:12:12Z. --- ### What The dispatch look-ahead added in #1864 resolves a gated compute group at the gate, before the title can rewrite the tables the group reads. #2990 made the look-ahead stop before a `DISPATCH_INDIRECT` whose 12 argument bytes an earlier dispatch of the run may write (or when an earlier dispatch has unknown writes). The stop is needed when the driver reads the arguments on the CPU at resolve time. It also fires when the arguments stay on the GPU, where the CPU never reads them, so in that case it protects nothing. With this change the look-ahead stops only for the CPU-read paths. `Driver::indirectArgumentsPath()` now holds the path choice that `dispatchIndirect` already made (thread dimensions, misaligned, `APS5_NO_GPU_INDIRECT`), and `resolveGroupAhead` (DispatchAhead.cpp) asks it before stopping. The dynamic CPU-read reasons (pending image results, workgroup memory, a pending label or copied writer over the argument dwords, no host import) are decided in `VulkanDevice::decideIndirect`. That runs only on the queue-order pass, after the look-ahead's parked result is adopted (`Driver::dispatch` returns before any device call while resolving), so it sees the earlier dispatches of the run already recorded. A new entry point, `AgcDriverDispatchesAdoptedAhead_nid_postfix`, counts the dispatches adopted from the look-ahead so a test can tell a gate-time capture from a late one. ### Why When the stop fires on a GPU-read indirect dispatch, that dispatch and everything behind it in the group are captured when the worker reaches them, after the GPU-mutex waits between dispatches. That is the late read from #1787: by then the title has re-armed the gate and started reusing its table slots, so the capture can read a descriptor the title has not written yet. Demon's Souls (PPSA01341 v1.07) hits this while loading the tutorial level, on compute shader `0x248a05b00`, with the same messages #1787 listed: `buffer descriptor uses an unsupported type` (ShaderResources.cpp) and `runtime image descriptor is invalid`. Every indirect dispatch in that title is GPU-read. The `[groupcap] ... read an earlier dispatch's output` counter was 0 on the #1864 build and has been 150 to 760 per 10 s on every build since 10-11. @CnRJay, this narrows your stop from #2990; every path that reads the arguments on the CPU still stops. #2990's test `agc_driver_indirect_arguments_written_ahead` still passes. #5058 (@Kikoarl) changes the same lines and adds two more CPU-read reasons: arguments not covered by a registered readable range, and pending image writes to flush. Whichever of the two lands second should put the new checks in `indirectArgumentsPath()`. The look-ahead then keeps stopping for them, because both places use the same function. I'll rebase this PR if #5058 goes in first. ### Tested - Test from review: `agc_driver_gpu_indirect_arguments_misaligned_writer_ahead` (the earlier dispatch writes registered arguments through a binding that is not `minStorageBufferOffsetAlignment` aligned). It and the gate and indirect tests (`agc_driver_gpu_indirect_*`, `agc_driver_indirect_*`, `agc_driver_gated_dispatch_capture*`, `agc_driver_write_data_written_ahead`, `agc_driver_prepared_shaders_indirect`, 8 tests) pass on an RTX 5070 Ti and on llvmpipe at 6b14169a4. - New test `agc_driver_gpu_indirect_arguments_written_ahead` (#2990's test, but with a GPU-read `DISPATCH_INDIRECT`): with main's stop it fails with `the gated group adopted 1 dispatches resolved at the gate, expected 2`, and with this change it passes. `agc_driver_indirect_arguments_written_ahead` (#2990) and `agc_driver_gated_dispatch_capture` (#1864) still pass. All three ran on lavapipe on this branch, rebased on main 66f894761. - Demon's Souls PPSA01341 v1.07, Linux, RTX 5070 Ti: a build with this change on top of the PRs that title needs to reach the tutorial level (#758, #5181, ThatsLeo's SPIR-V cache mapping, plus a local stencil-export workaround) ran the full 1500 s with no fatal error and reached the level. All 931 `[groupcap]` reports showed `0 read an earlier dispatch's output`. Without the change, 3 of the last 5 runs on the same stack stopped on `0x248a05b00` during the level load. No performance claim. ### 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 - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's technical debt file - [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] Unblocks: PPSA01341 #1283 - [x] GPUs tested: lavapipe (Mesa llvmpipe, LLVM 22.1.8), Linux, for the tests; NVIDIA GeForce RTX 5070 Ti, driver 595.91, Linux (Nobara, kernel 7.2), for the game run - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-14 13:51:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-14T13:51:18Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 5058 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Dispatch/IndirectDispatch.cpp L30-33

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 1191 core/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hpp
PR 1747 core/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hpp
core/libs/prx/libSceAgcDriver/Execution/src/Driver/Dispatch/Dispatch.cpp
PR 4040 core/libs/prx/libSceAgcDriver/Execution/src/Driver/EntryPoints.cpp
PR 4650 core/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hpp
PR 4891 core/libs/prx/libSceAgcDriver/Execution/include/Driver.hpp
core/libs/prx/libSceAgcDriver/Execution/src/Driver/EntryPoints.cpp
PR 4943 core/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hpp
PR 5497 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Dispatch/Dispatch.cpp
PR 5609 core/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hpp
PR 5656 core/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hpp
PR 5867 core/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hpp
core/libs/prx/libSceAgcDriver/Execution/src/Driver/Dispatch/Dispatch.cpp
PR 5925 core/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hpp
core/libs/prx/libSceAgcDriver/Execution/src/Driver/Dispatch/Dispatch.cpp
core/libs/prx/libSceAgcDriver/Execution/src/Driver/Dispatch/DispatchAhead.cpp
PR 6188 core/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hpp
PR 6208 core/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hpp
core/libs/prx/libSceAgcDriver/Execution/src/Driver/Dispatch/Dispatch.cpp
PR 6292 core/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hpp
core/libs/prx/libSceAgcDriver/Execution/src/Driver/Dispatch/IndirectDispatch.cpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6169948147 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5747#issuecomment-6169948147). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-14T13:51:18Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | [PR 5058](https://www.github.com/boykopovar/AnyPS5/pull/5058) | `core/libs/prx/libSceAgcDriver/Execution/src/Driver/Dispatch/IndirectDispatch.cpp` [L30-33](https://github.com/boykopovar/AnyPS5/blob/940eba9a26ec363eef9a461b24e94576317a4955/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Dispatch/IndirectDispatch.cpp#L30-L33) | | | Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap. | Pull request | Shared files not compared | |---|---| | [PR 1191](https://www.github.com/boykopovar/AnyPS5/pull/1191) | `core/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hpp` | | [PR 1747](https://www.github.com/boykopovar/AnyPS5/pull/1747) | `core/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hpp`<br>`core/libs/prx/libSceAgcDriver/Execution/src/Driver/Dispatch/Dispatch.cpp` | | [PR 4040](https://www.github.com/boykopovar/AnyPS5/pull/4040) | `core/libs/prx/libSceAgcDriver/Execution/src/Driver/EntryPoints.cpp` | | [PR 4650](https://www.github.com/boykopovar/AnyPS5/pull/4650) | `core/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hpp` | | [PR 4891](https://www.github.com/boykopovar/AnyPS5/pull/4891) | `core/libs/prx/libSceAgcDriver/Execution/include/Driver.hpp`<br>`core/libs/prx/libSceAgcDriver/Execution/src/Driver/EntryPoints.cpp` | | [PR 4943](https://www.github.com/boykopovar/AnyPS5/pull/4943) | `core/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hpp` | | [PR 5497](https://www.github.com/boykopovar/AnyPS5/pull/5497) | `core/libs/prx/libSceAgcDriver/Execution/src/Driver/Dispatch/Dispatch.cpp` | | [PR 5609](https://www.github.com/boykopovar/AnyPS5/pull/5609) | `core/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hpp` | | [PR 5656](https://www.github.com/boykopovar/AnyPS5/pull/5656) | `core/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hpp` | | [PR 5867](https://www.github.com/boykopovar/AnyPS5/pull/5867) | `core/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hpp`<br>`core/libs/prx/libSceAgcDriver/Execution/src/Driver/Dispatch/Dispatch.cpp` | | [PR 5925](https://www.github.com/boykopovar/AnyPS5/pull/5925) | `core/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hpp`<br>`core/libs/prx/libSceAgcDriver/Execution/src/Driver/Dispatch/Dispatch.cpp`<br>`core/libs/prx/libSceAgcDriver/Execution/src/Driver/Dispatch/DispatchAhead.cpp` | | [PR 6188](https://www.github.com/boykopovar/AnyPS5/pull/6188) | `core/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hpp` | | [PR 6208](https://www.github.com/boykopovar/AnyPS5/pull/6208) | `core/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hpp`<br>`core/libs/prx/libSceAgcDriver/Execution/src/Driver/Dispatch/Dispatch.cpp` | | [PR 6292](https://www.github.com/boykopovar/AnyPS5/pull/6292) | `core/libs/prx/libSceAgcDriver/Execution/include/Driver/Driver.hpp`<br>`core/libs/prx/libSceAgcDriver/Execution/src/Driver/Dispatch/IndirectDispatch.cpp` |
CnRJay commented 2026-10-14 16:57:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-10-14T16:57:17Z.

Review: COMMENTED


Thanks for the ping. Narrowing the stop to the paths that read the arguments on the CPU is the right idea. On a GPU-read dispatch it protects nothing, and stopping there brings back the late capture from #1787. Demon's Souls going from 3 of 5 stops to a full 1500 s run with 0 read an earlier dispatch's output is good evidence.

One gap: indirectArgumentsPath() covers only the three static reasons (gpuIndirect, thread dimensions, misalignment). VulkanDevice on main has four more CPU-read reasons, decided while the dispatch is being recorded:

  • cpuReason = 1: StorageTexture::FlushPending over the 12 argument bytes;
  • cpuReason = 8: the program uses workgroup memory;
  • cpuReason = 2: a pending label or CopiedWriterOverlaps over the argument dwords;
  • cpuReason = 3: no host import holds the arguments.

In each of these, GuestMemory::Read(arguments, …) reads the counts. My question is when that runs for a dispatch the look-ahead adopted. If an adopted dispatch is recorded in queue order, after the earlier dispatches of its run, those reasons are evaluated with the earlier writes in place and the narrowing is safe. If adopting it at the gate also settles its recipe, including cpuReason, then a dispatch that indirectArgumentsPath() calls GPU-read can still read its arguments on the CPU at gate time, before the earlier dispatch that writes them has run. That is exactly the case #2990 stops for. Reason 2 is the likely one: a writer from the same run whose staged region isn't registered yet in copiedWriters when the look-ahead runs.

Either answer is fine. If it's the first, a sentence in the description saying where the dynamic reasons are decided would let a maintainer check it quickly. If it's the second, the look-ahead could also stop when the arguments are covered by a write of the run and no import holds them yet. #5058's two extra checks would then go into indirectArgumentsPath() as you suggest. A test variant where the earlier dispatch writes the arguments through a misaligned or staged binding would pin it either way.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5521569554 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5747#pullrequestreview-5521569554). Originally posted by [CnRJay](https://github.com/CnRJay) on 2026-10-14T16:57:17Z. **Review:** COMMENTED --- Thanks for the ping. Narrowing the stop to the paths that read the arguments on the CPU is the right idea. On a GPU-read dispatch it protects nothing, and stopping there brings back the late capture from #1787. Demon's Souls going from 3 of 5 stops to a full 1500 s run with `0 read an earlier dispatch's output` is good evidence. One gap: `indirectArgumentsPath()` covers only the three *static* reasons (`gpuIndirect`, thread dimensions, misalignment). `VulkanDevice` on `main` has four more CPU-read reasons, decided while the dispatch is being recorded: - `cpuReason = 1`: `StorageTexture::FlushPending` over the 12 argument bytes; - `cpuReason = 8`: the program uses workgroup memory; - `cpuReason = 2`: a pending label or `CopiedWriterOverlaps` over the argument dwords; - `cpuReason = 3`: no host import holds the arguments. In each of these, `GuestMemory::Read(arguments, …)` reads the counts. My question is when that runs for a dispatch the look-ahead adopted. If an adopted dispatch is recorded in queue order, after the earlier dispatches of its run, those reasons are evaluated with the earlier writes in place and the narrowing is safe. If adopting it at the gate also settles its recipe, including `cpuReason`, then a dispatch that `indirectArgumentsPath()` calls GPU-read can still read its arguments on the CPU at gate time, before the earlier dispatch that writes them has run. That is exactly the case #2990 stops for. Reason 2 is the likely one: a writer from the same run whose staged region isn't registered yet in `copiedWriters` when the look-ahead runs. Either answer is fine. If it's the first, a sentence in the description saying where the dynamic reasons are decided would let a maintainer check it quickly. If it's the second, the look-ahead could also stop when the arguments are covered by a write of the run and no import holds them yet. #5058's two extra checks would then go into `indirectArgumentsPath()` as you suggest. A test variant where the earlier dispatch writes the arguments through a misaligned or staged binding would pin it either way.
fisherjoey commented 2026-10-14 18:10:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-14T18:10:36Z.


@CnRJay It's the first case. The look-ahead never reaches the device. While resolving, Driver::dispatch captures and recompiles, parks the result in resolvedAhead() and returns (the if (resolving) block in Dispatch.cpp, before any VulkanDevice call). The parked ResolvedDispatch holds the compiled result, the captured regions, the cache variant and the unresolved packet with its argument address. It holds no recipe, no cpuReason and no group counts.

When the worker reaches the packet in queue order, it adopts those fields and only then calls PrepareDispatch, takes the GPU mutex, records the queued labels and calls DispatchIndirect or DispatchRecipe. Both go through decideIndirect, which decides reasons 1, 8, 2 and 3 and does the GuestMemory::Read of the counts. By then the earlier dispatches of the run are recorded and listed in copiedWriters. A Recipe carries no cpuReason either, so a recipe hit decides again. The existing test already takes your reason 2: with a trace in decideIndirect, its indirect dispatch records with cpuReason 2 and one copied writer while it is adopted from the gate, and it runs the 24 groups the writer stored.

I found one CPU read of indirect arguments in the Driver itself. The fill kernel path in Driver::dispatch read the counts while resolving and then threw them away (the partial-group bit that would have parked them is rejected for DISPATCH_INDIRECT in Pm4.cpp). d70fd2273 returns before that read during the look-ahead, so nothing reads indirect arguments on the CPU at the gate now.

Two new tests pin it:

  • agc_driver_gpu_indirect_arguments_misaligned_writer_ahead: the arguments block is registered, so a host import holds it, and the earlier dispatch writes the arguments through a V# that is dword aligned but not aligned to minStorageBufferOffsetAlignment. The driver copies that region on the GPU and back, so the indirect dispatch stays GPU-read, and it has to run the written counts while still adopted at the gate.
  • agc_driver_indirect_fill_kernel_arguments_written_ahead: the same with an indirect fill kernel dispatch, the Driver-side CPU-read path.

Both pass on an RTX 5070 Ti and on llvmpipe, along with the ten gate and indirect tests from before. I also added a sentence to the description on where the dynamic reasons are decided.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6175089528 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5747#issuecomment-6175089528). Originally posted by [fisherjoey](https://github.com/fisherjoey) on 2026-10-14T18:10:36Z. --- @CnRJay It's the first case. The look-ahead never reaches the device. While resolving, `Driver::dispatch` captures and recompiles, parks the result in `resolvedAhead()` and returns (the `if (resolving)` block in Dispatch.cpp, before any `VulkanDevice` call). The parked `ResolvedDispatch` holds the compiled result, the captured regions, the cache variant and the unresolved packet with its argument address. It holds no recipe, no `cpuReason` and no group counts. When the worker reaches the packet in queue order, it adopts those fields and only then calls `PrepareDispatch`, takes the GPU mutex, records the queued labels and calls `DispatchIndirect` or `DispatchRecipe`. Both go through `decideIndirect`, which decides reasons 1, 8, 2 and 3 and does the `GuestMemory::Read` of the counts. By then the earlier dispatches of the run are recorded and listed in `copiedWriters`. A `Recipe` carries no `cpuReason` either, so a recipe hit decides again. The existing test already takes your reason 2: with a trace in `decideIndirect`, its indirect dispatch records with `cpuReason 2` and one copied writer while it is adopted from the gate, and it runs the 24 groups the writer stored. I found one CPU read of indirect arguments in the Driver itself. The fill kernel path in `Driver::dispatch` read the counts while resolving and then threw them away (the partial-group bit that would have parked them is rejected for DISPATCH_INDIRECT in Pm4.cpp). d70fd2273 returns before that read during the look-ahead, so nothing reads indirect arguments on the CPU at the gate now. Two new tests pin it: - `agc_driver_gpu_indirect_arguments_misaligned_writer_ahead`: the arguments block is registered, so a host import holds it, and the earlier dispatch writes the arguments through a V# that is dword aligned but not aligned to `minStorageBufferOffsetAlignment`. The driver copies that region on the GPU and back, so the indirect dispatch stays GPU-read, and it has to run the written counts while still adopted at the gate. - `agc_driver_indirect_fill_kernel_arguments_written_ahead`: the same with an indirect fill kernel dispatch, the Driver-side CPU-read path. Both pass on an RTX 5070 Ti and on llvmpipe, along with the ten gate and indirect tests from before. I also added a sentence to the description on where the dynamic reasons are decided. AI-assisted: yes
CnRJay commented 2026-10-14 19:11:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-10-14T19:11:43Z.


Thanks, that settles it. The dynamic reasons are decided in decideIndirect when the worker records the adopted dispatch in queue order, and the fill-kernel read was the one CPU read at the gate. d70fd2273 and the two new tests cover what I asked about. Nothing more from me.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6176245628 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5747#issuecomment-6176245628). Originally posted by [CnRJay](https://github.com/CnRJay) on 2026-10-14T19:11:43Z. --- Thanks, that settles it. The dynamic reasons are decided in `decideIndirect` when the worker records the adopted dispatch in queue order, and the fill-kernel read was the one CPU read at the gate. d70fd2273 and the two new tests cover what I asked about. Nothing more from me.
adriadam10 commented 2026-10-15 12:27:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-15T12:27:06Z.

Review: CHANGES_REQUESTED


Checked on the PR merged onto current main: libSceAgcDriver build + ctest green (only agc_driver_tessellation fails, it also fails on main without this PR). The first two tests fail without the change (they need AgcDriverDispatchesAdoptedAhead_nid_postfix) and pass with it.

One point:

  • IndirectFillKernelArgumentsWrittenAhead.cpp passes with the second commit's change removed. I replaced if (resolving) return; at Dispatch.cpp:63 with nothing, rebuilt, and agc_driver_indirect_fill_kernel_arguments_written_ahead still passed (128 records filled). So the test doesn't pin that behaviour. Please make the test reach the fill-kernel branch with the look-ahead active (for example, assert through AgcDriverDispatchesAdoptedAhead_nid_postfix that the fill kernel dispatch was not read at the gate, or change the setup so the argument read at the gate gives a different count) so that it fails without the line. If the line turns out to be unreachable in that setup, drop it from the PR.

Happy to look again once the test fails without that line.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5533056793 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5747#pullrequestreview-5533056793). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-15T12:27:06Z. **Review:** CHANGES_REQUESTED --- Checked on the PR merged onto current main: libSceAgcDriver build + ctest green (only `agc_driver_tessellation` fails, it also fails on main without this PR). The first two tests fail without the change (they need `AgcDriverDispatchesAdoptedAhead_nid_postfix`) and pass with it. One point: - `IndirectFillKernelArgumentsWrittenAhead.cpp` passes with the second commit's change removed. I replaced `if (resolving) return;` at `Dispatch.cpp:63` with nothing, rebuilt, and `agc_driver_indirect_fill_kernel_arguments_written_ahead` still passed (128 records filled). So the test doesn't pin that behaviour. Please make the test reach the fill-kernel branch with the look-ahead active (for example, assert through `AgcDriverDispatchesAdoptedAhead_nid_postfix` that the fill kernel dispatch was not read at the gate, or change the setup so the argument read at the gate gives a different count) so that it fails without the line. If the line turns out to be unreachable in that setup, drop it from the PR. Happy to look again once the test fails without that line.
fisherjoey commented 2026-10-15 12:54:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-15T12:54:00Z.


You're right, the test couldn't pin that line. With the look-ahead active, dispatch does enter the fill-kernel branch, and without the line it reads the arguments at the gate (groups 1 1 1, before the writer ran). The return at Dispatch.cpp:76 then throws that read away and leaves the dispatch unresolved, so both builds end in the same state. The only case where a gate-time read would be kept is partialLastGroup, and Pm4.cpp:360 rejects PARTIAL_TG_EN on DISPATCH_INDIRECT (mask 0xa06c), so no indirect dispatch gets there.

So I dropped the line and IndirectFillKernelArgumentsWrittenAhead.cpp, and squashed the branch to one commit, 6b14169a4 (not rebased, still on 922abe6a4). agc_driver_gpu_indirect_*, agc_driver_indirect_*, agc_driver_gated_dispatch_capture*, agc_driver_write_data_written_ahead and agc_driver_prepared_shaders_indirect pass, 8/8 on an RTX 5070 Ti and 8/8 on lavapipe. The description no longer mentions the fill-kernel change.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6192534844 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5747#issuecomment-6192534844). Originally posted by [fisherjoey](https://github.com/fisherjoey) on 2026-10-15T12:54:00Z. --- You're right, the test couldn't pin that line. With the look-ahead active, `dispatch` does enter the fill-kernel branch, and without the line it reads the arguments at the gate (groups 1 1 1, before the writer ran). The `return` at `Dispatch.cpp:76` then throws that read away and leaves the dispatch unresolved, so both builds end in the same state. The only case where a gate-time read would be kept is `partialLastGroup`, and `Pm4.cpp:360` rejects PARTIAL_TG_EN on `DISPATCH_INDIRECT` (mask `0xa06c`), so no indirect dispatch gets there. So I dropped the line and `IndirectFillKernelArgumentsWrittenAhead.cpp`, and squashed the branch to one commit, 6b14169a4 (not rebased, still on 922abe6a4). `agc_driver_gpu_indirect_*`, `agc_driver_indirect_*`, `agc_driver_gated_dispatch_capture*`, `agc_driver_write_data_written_ahead` and `agc_driver_prepared_shaders_indirect` pass, 8/8 on an RTX 5070 Ti and 8/8 on lavapipe. The description no longer mentions the fill-kernel change. AI-assisted: yes
adriadam10 commented 2026-10-15 13:02:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-15T13:02:57Z.

Review: APPROVED


Re-checked on the PR merged onto current main: libSceAgcDriver build + ctest green (only agc_driver_tessellation fails, as on main). The fill-kernel commit is gone, which settles my earlier point.

With AgcDriverDispatchesAdoptedAhead_nid_postfix kept but the indirectArgumentsPath(...) != IndirectGpu condition removed from DispatchAhead.cpp:153, both agc_driver_gpu_indirect_arguments_written_ahead and agc_driver_gpu_indirect_arguments_misaligned_writer_ahead fail; with the change they pass. Merging once the full Build is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5533515071 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5747#pullrequestreview-5533515071). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-15T13:02:57Z. **Review:** APPROVED --- Re-checked on the PR merged onto current main: libSceAgcDriver build + ctest green (only `agc_driver_tessellation` fails, as on main). The fill-kernel commit is gone, which settles my earlier point. With `AgcDriverDispatchesAdoptedAhead_nid_postfix` kept but the `indirectArgumentsPath(...) != IndirectGpu` condition removed from `DispatchAhead.cpp:153`, both `agc_driver_gpu_indirect_arguments_written_ahead` and `agc_driver_gpu_indirect_arguments_misaligned_writer_ahead` fail; with the change they pass. Merging once the full Build is green.
Amoenus commented 2026-10-15 15:56:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Amoenus on 2026-10-15T15:56:28Z.


@fisherjoey Independent Windows build finding after this merge: unchanged main 0c4816f6119e5dc1208b16b25a171d1c88aa18f4 cannot compile GpuIndirectArgumentsMisalignedWriterAhead.cpp:25 with the repository-required WinLibs GCC 15.2.0 r7 (Windows 11 Enterprise 26200, Release/bundled dependencies):

error: requested alignment '65536' exceeds object file maximum 8192

I reproduced it by building the fixture's object target from an otherwise clean main checkout. The file is also byte-identical on newer main 0029e62f9. The same error independently stopped our full integration build; this is a compiler limit, before GPU execution.

The four-line fixture-only correction is now proposed in #6452, fork commit 4fe92c9c2, based on main0029. Full Windows app/libs/checkers pass. Eight related groups pass five repetitions per NVIDIA/AMD selector; this fixture also passes twenty extra fresh processes per GPU, with verified device identity. It retains the 64 KiB registered block, four-byte argument offset, and original 24-group/two-adopted-dispatch assertions. The PR records the exact tests and the unchanged Low() Cppcheck advisory. No production-driver change or title result is claimed. AI-assisted: Codex.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6196365588 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5747#issuecomment-6196365588). Originally posted by [Amoenus](https://github.com/Amoenus) on 2026-10-15T15:56:28Z. --- @fisherjoey Independent Windows build finding after this merge: unchanged main `0c4816f6119e5dc1208b16b25a171d1c88aa18f4` cannot compile `GpuIndirectArgumentsMisalignedWriterAhead.cpp:25` with the repository-required WinLibs GCC 15.2.0 r7 (Windows 11 Enterprise 26200, Release/bundled dependencies): ```text error: requested alignment '65536' exceeds object file maximum 8192 ``` I reproduced it by building the fixture's object target from an otherwise clean main checkout. The file is also byte-identical on newer main `0029e62f9`. The same error independently stopped our full integration build; this is a compiler limit, before GPU execution. The four-line fixture-only correction is now proposed in [#6452](https://github.com/boykopovar/AnyPS5/pull/6452), [fork commit 4fe92c9c2](https://github.com/Amoenus/AnyPS5/commit/4fe92c9c23c7bd861d63664d4efde3033b6226f6), based on main0029. Full Windows app/libs/checkers pass. Eight related groups pass five repetitions per NVIDIA/AMD selector; this fixture also passes twenty extra fresh processes per GPU, with verified device identity. It retains the 64 KiB registered block, four-byte argument offset, and original 24-group/two-adopted-dispatch assertions. The PR records the exact tests and the unchanged Low() Cppcheck advisory. No production-driver change or title result is claimed. AI-assisted: Codex. <!-- codex-windows-indirect-alignment-v1 -->
fisherjoey commented 2026-10-15 16:41:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-15T16:41:39Z.


@Amoenus thanks for catching it. I only built and ran it on Linux (GCC 16), on an RTX 5070 Ti and lavapipe. #6452 looks right to me: a 128 KiB minus one buffer always contains a 64 KiB-aligned 64 KiB block, the new Require fails loudly if it doesn't, and the offset-4 arguments and the adopted-count assertions stay as they were.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6197276998 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5747#issuecomment-6197276998). Originally posted by [fisherjoey](https://github.com/fisherjoey) on 2026-10-15T16:41:39Z. --- @Amoenus thanks for catching it. I only built and ran it on Linux (GCC 16), on an RTX 5070 Ti and lavapipe. #6452 looks right to me: a 128 KiB minus one buffer always contains a 64 KiB-aligned 64 KiB block, the new `Require` fails loudly if it doesn't, and the offset-4 arguments and the adopted-count assertions stay as they were. AI-assisted: yes
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!5747
No description provided.