fix(agc): bound the writes of dispatches that cannot store through pointers #20018

Merged
slopezjur merged 2 commits from upstream-pr/20018 into main 2026-11-25 15:28:43 +00:00
slopezjur commented 2026-11-14 11:57:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by slopezjur on 2026-11-14T11:57:47Z.


What

DispatchWriteRanges marked a compute result as unbounded whenever it used the BDA ABI (unless it had a fault buffer), and whenever it bound GDS or the BDA page table. An unbounded queue-0 dispatch always drains the draw pipeline instead of becoming a commit item, so most BDA compute work forced a drain.

  • The fault buffer and the page table belong to the driver. A result with no page table has no address table, so it cannot store to guest memory through pointers.
  • A result now stays unbounded only when it binds the page table and stores through addresses (bdaWrites, or the SPIR-V scan the driver already uses for draws, ShaderStoresThroughAddresses, which is cached per module).
  • A GDS binding adds the fixed GDS range instead of making the dispatch unbounded.
  • The existing rule that keeps fault-buffer-only results bounded (e2338d5bd1) becomes part of the general one.

agc_driver_draw_write_ranges gains cases for a fault-buffer-only result (bounded, keeps its written image), a result that only reads through its page table (bounded), one that stores through it (unbounded), and a GDS binding (bounded, GDS range present).

agc_driver_write_data_written_ahead expected a dispatch that binds GDS to stay unbounded and stop resolveGroupAhead after two dispatches. Under the new rule that dispatch is bounded to the GDS range and the one after it is adopted ahead, so the GDS case now expects 3 adopted, and the "an unbounded write stops resolveGroupAhead" check uses a dispatch that stores through a raw pointer, which stays unbounded, and expects 2. With pointer stores forced bounded, the new case fails with got 3.

Tested

Windows 11, WinLibs GCC 15.2.0 r7, Release, NVIDIA GeForce RTX 4080 SUPER (driver 621.14), Vulkan SDK 1.4.363.0 validation layer.

Focused tests on main 2cebbe43ee and on this branch, same machine, with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, VK_LOADER_DEBUG=layer (ctest -R <pattern> -V): draw write ranges (plain, draw pipeline, plan verify), BDA reads/device/shadowed results, GDS append/consume, DMA fill and 64-bit atomics, dispatch-ahead adopt check, snapshot and write-tracking tests.

tests failed layer inserted VUID-
main 49 0 31 of 31 Vulkan processes 0
this PR 49 0 31 of 31 0

That list missed agc_driver_write_data_written_ahead (plain, draw pipeline, plan verify), which failed with the first head (reported by rth9z). With the test update 1619ab9d6e, on main 178944e753 and on the change, same machine and environment: those three and agc_driver_draw_write_ranges* pass, and ctest -R '^(agc_|shader_)' gives 1793 tests, 18 skipped and 0 VUID- on both sides. agc_driver_upload_cache_read_only_flush does not compile with MinGW on main and was not run on either side.

Reported by reviewers on this PR:

  • JJenkx, Windows 11, AMD Radeon RX 6700 XT (driver 26.10.1), head 1d240739b2 merged onto main dcb5aabff0: agc_driver_draw_write_ranges, _draw_pipeline and _plan_verify pass 3 of 3 runs on the GPU with ANYPS5_REQUIRE_VULKAN=1, and 3 of 3 on the CPU.
  • rth9z, Windows 11, NVIDIA GeForce RTX 5070 Ti (driver 621.01), head 1619ab9d6e merged onto main 6dbb02e37e: the three agc_driver_write_data_written_ahead tests pass, agc_driver_draw_write_ranges passes 3 of 3, and ctest -R '^(agc|shader|video_out|guest_video_out)' passes 1854 of 1854 with the same 40 skips as main.

For context only (not main): on Ghost of Yōtei (PPSA26344) with the yotei/best-based driver of slopezjur/AnyPS5 yotei/next2, where this change was first made (42ea26a7c9), in the tree scene with APS5_PIPELINE_DISPATCH_MISSES=1, the unbounded fallbacks fell from 103k to 3.4k and dispatch-caused drains from 1,232 to 261 per 10 s. Frame time did not change there, so this PR claims no speed-up.

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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: NVIDIA GeForce RTX 4080 SUPER, driver 621.14, Windows 11. Reported by reviewers: AMD Radeon RX 6700 XT, driver 26.10.1, Windows 11 (JJenkx); NVIDIA GeForce RTX 5070 Ti, driver 621.01, Windows 11 (rth9z); NVIDIA GeForce RTX 4090, driver 620.70.06, Arch Linux (domx4q)
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5310984447 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/20018). Originally posted by [slopezjur](https://github.com/slopezjur) on 2026-11-14T11:57:47Z. --- ### What `DispatchWriteRanges` marked a compute result as unbounded whenever it used the BDA ABI (unless it had a fault buffer), and whenever it bound GDS or the BDA page table. An unbounded queue-0 dispatch always drains the draw pipeline instead of becoming a commit item, so most BDA compute work forced a drain. - The fault buffer and the page table belong to the driver. A result with no page table has no address table, so it cannot store to guest memory through pointers. - A result now stays unbounded only when it binds the page table **and** stores through addresses (`bdaWrites`, or the SPIR-V scan the driver already uses for draws, `ShaderStoresThroughAddresses`, which is cached per module). - A GDS binding adds the fixed GDS range instead of making the dispatch unbounded. - The existing rule that keeps fault-buffer-only results bounded (e2338d5bd1) becomes part of the general one. `agc_driver_draw_write_ranges` gains cases for a fault-buffer-only result (bounded, keeps its written image), a result that only reads through its page table (bounded), one that stores through it (unbounded), and a GDS binding (bounded, GDS range present). `agc_driver_write_data_written_ahead` expected a dispatch that binds GDS to stay unbounded and stop `resolveGroupAhead` after two dispatches. Under the new rule that dispatch is bounded to the GDS range and the one after it is adopted ahead, so the GDS case now expects 3 adopted, and the "an unbounded write stops `resolveGroupAhead`" check uses a dispatch that stores through a raw pointer, which stays unbounded, and expects 2. With pointer stores forced bounded, the new case fails with `got 3`. ### Tested Windows 11, WinLibs GCC 15.2.0 r7, Release, NVIDIA GeForce RTX 4080 SUPER (driver 621.14), Vulkan SDK 1.4.363.0 validation layer. Focused tests on `main` 2cebbe43ee and on this branch, same machine, with `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1`, `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`, `VK_LOADER_DEBUG=layer` (`ctest -R <pattern> -V`): draw write ranges (plain, draw pipeline, plan verify), BDA reads/device/shadowed results, GDS append/consume, DMA fill and 64-bit atomics, dispatch-ahead adopt check, snapshot and write-tracking tests. | | tests | failed | layer inserted | `VUID-` | |---|---|---|---|---| | `main` | 49 | 0 | 31 of 31 Vulkan processes | 0 | | this PR | 49 | 0 | 31 of 31 | 0 | That list missed `agc_driver_write_data_written_ahead` (plain, draw pipeline, plan verify), which failed with the first head (reported by rth9z). With the test update `1619ab9d6e`, on `main` 178944e753 and on the change, same machine and environment: those three and `agc_driver_draw_write_ranges*` pass, and `ctest -R '^(agc_|shader_)'` gives 1793 tests, 18 skipped and 0 `VUID-` on both sides. `agc_driver_upload_cache_read_only_flush` does not compile with MinGW on `main` and was not run on either side. Reported by reviewers on this PR: - JJenkx, Windows 11, AMD Radeon RX 6700 XT (driver 26.10.1), head `1d240739b2` merged onto `main` dcb5aabff0: `agc_driver_draw_write_ranges`, `_draw_pipeline` and `_plan_verify` pass 3 of 3 runs on the GPU with `ANYPS5_REQUIRE_VULKAN=1`, and 3 of 3 on the CPU. - rth9z, Windows 11, NVIDIA GeForce RTX 5070 Ti (driver 621.01), head `1619ab9d6e` merged onto `main` 6dbb02e37e: the three `agc_driver_write_data_written_ahead` tests pass, `agc_driver_draw_write_ranges` passes 3 of 3, and `ctest -R '^(agc|shader|video_out|guest_video_out)'` passes 1854 of 1854 with the same 40 skips as `main`. For context only (not `main`): on Ghost of Yōtei (PPSA26344) with the `yotei/best`-based driver of [`slopezjur/AnyPS5` `yotei/next2`](https://github.com/slopezjur/AnyPS5/tree/yotei/next2), where this change was first made (42ea26a7c9), in the tree scene with `APS5_PIPELINE_DISPATCH_MISSES=1`, the unbounded fallbacks fell from 103k to 3.4k and dispatch-caused drains from 1,232 to 261 per 10 s. Frame time did not change there, so this PR claims no speed-up. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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 under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/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] Fixes: none - [x] Unblocks: none - [x] GPUs tested: NVIDIA GeForce RTX 4080 SUPER, driver 621.14, Windows 11. Reported by reviewers: AMD Radeon RX 6700 XT, driver 26.10.1, Windows 11 (JJenkx); NVIDIA GeForce RTX 5070 Ti, driver 621.01, Windows 11 (rth9z); NVIDIA GeForce RTX 4090, driver 620.70.06, Arch Linux (domx4q) - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-11-17 19:56:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-17T19:56:45Z.

Review: COMMENTED


Reviewed — no blocking findings

Nothing blocks this; the points below are optional.

What I ran

Head 1619ab9d6ec3925debb7aeddeb4a975ba4a3c839, base main. No build, no tests, no hosted-CI inspection. Repository reads with the reader:

python3 repo_read.py search ShaderStoresThroughAddresses
python3 repo_read.py search GdsBytes
python3 repo_read.py search bdaWrites
python3 repo_read.py cat core/libs/prx/libSceAgcDriver/Graphics/src/ShaderAddressResources.cpp 112 165

Results

Check Result Note
Description against diff passed Claims match the three changed files
Full text of changed files not run Only the diff and the helpers above were read
Comments in added code passed None added
Build and tests not run Not built here
Hosted CI not run Not inspected

Findings

Blocking

None verified.

Non-blocking

None verified.

Sources

Not verified

  • The full text of the three changed files in the run folder was not read, and files.json was not read. The review covers the changed hunks and their helpers only.
  • The description's claim that a result without a page table cannot store through pointers was not checked against the recompiler.
  • WrittenBuffers.cpp line 61 calls the store check whenever a page-table binding exists. Whether compiled.spirv can be empty there was not checked.
  • The hand-encoded PointerStoreCode in WriteDataWrittenAhead.cpp line 87 was not decoded, so the test's pointer store was not confirmed.
  • The test results in the description, and the reports from JJenkx and rth9z, are author or reviewer reports. They are not runs by this review.
  • The required hosted checks for this head were not confirmed.

To get this to a good state

Nothing is required.

Optional: confirm that the hosted checks pass on 1619ab9d6e, and that the pointer-store test fails if the store is removed.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5945577624 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/20018#pullrequestreview-5945577624). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-17T19:56:45Z. **Review:** COMMENTED --- # Reviewed — no blocking findings Nothing blocks this; the points below are optional. **What I ran** Head `1619ab9d6ec3925debb7aeddeb4a975ba4a3c839`, base `main`. No build, no tests, no hosted-CI inspection. Repository reads with the reader: ```sh python3 repo_read.py search ShaderStoresThroughAddresses python3 repo_read.py search GdsBytes python3 repo_read.py search bdaWrites python3 repo_read.py cat core/libs/prx/libSceAgcDriver/Graphics/src/ShaderAddressResources.cpp 112 165 ``` **Results** | Check | Result | Note | |---|---|---| | Description against diff | passed | Claims match the three changed files | | Full text of changed files | not run | Only the diff and the helpers above were read | | Comments in added code | passed | None added | | Build and tests | not run | Not built here | | Hosted CI | not run | Not inspected | **Findings** **Blocking** None verified. **Non-blocking** None verified. **Sources** - [`WrittenBuffers.cpp` lines 61–62](https://github.com/boykopovar/AnyPS5/blob/1619ab9d6ec3925debb7aeddeb4a975ba4a3c839/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Memory/WrittenBuffers.cpp#L61-L62): a dispatch stays unbounded only with a page-table binding that stores through addresses; a GDS binding adds the GDS range. - [`ShaderAddressResources.cpp` lines 144–146](https://github.com/boykopovar/AnyPS5/blob/1619ab9d6ec3925debb7aeddeb4a975ba4a3c839/core/libs/prx/libSceAgcDriver/Graphics/src/ShaderAddressResources.cpp#L144-L146): the store check is cached per SPIR-V module, as the description says. **Not verified** - The full text of the three changed files in the run folder was not read, and `files.json` was not read. The review covers the changed hunks and their helpers only. - The description's claim that a result without a page table cannot store through pointers was not checked against the recompiler. - `WrittenBuffers.cpp` line 61 calls the store check whenever a page-table binding exists. Whether `compiled.spirv` can be empty there was not checked. - The hand-encoded `PointerStoreCode` in `WriteDataWrittenAhead.cpp` line 87 was not decoded, so the test's pointer store was not confirmed. - The test results in the description, and the reports from JJenkx and rth9z, are author or reviewer reports. They are not runs by this review. - The required hosted checks for this head were not confirmed. **To get this to a good state** Nothing is required. Optional: confirm that the hosted checks pass on `1619ab9d6e`, and that the pointer-store test fails if the store is removed.
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!20018
No description provided.