fix(agc): keep a queued dispatch's captured memory until it is recorded #23722

Merged
slopezjur merged 1 commit from upstream-pr/23722 into main 2026-11-27 04:16:09 +00:00
slopezjur commented 2026-11-19 14:25:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by slopezjur on 2026-11-19T14:25:36Z.


What

With APS5_PIPELINE_DISPATCH=1 APS5_PIPELINE_DISPATCH_MISSES=1, a queued dispatch item carries the guest snapshots its capture took and the draw committer records the dispatch from them later. The snapshot bytes point into the dispatch's ShaderMemory pages, but the item didn't hold that ShaderMemory. A missed dispatch, or a hit without a recipe, records from its fresh capture; its cache variant copies the words it needs and lets the capture go. Its pages then return to the queue worker's page pool when Driver::dispatch returns, while the item still waits on the committer. Items for cache hits with a recipe read the variant's own words and were not affected, so this only bites with APS5_PIPELINE_DISPATCH_MISSES.

The next capture on queue 0 takes those pages and overwrites them. So when the committer records the queued dispatch, its snapshots hold another dispatch's words. A page the pool doesn't keep is freed instead, and the committer then reads freed memory.

On Ghost of Yōtei (PPSA26344) with APS5_PIPELINE_DISPATCH=1 APS5_PIPELINE_DISPATCH_MISSES=1, every run logged 23 or 24 guest snapshot differs from registered memory lines. In one run the draw committer died with 0xc0000005 in ShaderResources::Complete → GuestBufferMemory::AddSnapshot (memcpy of a freed page).

The item now also holds the dispatch's ShaderMemory and its registered shader until it is recorded. Driver::SetDispatchItemHook (same pattern as SetCaptureCheckHook) lets a test see the snapshots an item records from.

Tested

Windows 11, RTX 4080 SUPER.

  • New kept capture rounds in tests/execution/PipelinedDispatch.cpp (run by agc_driver_pipelined_dispatch_misses). Two missed dispatches queue behind a held committer and read different descriptor tables; when each is recorded, its snapshots must still hold the words it captured. Without the fix, round 0 fails: 1 snapshots of the queued dispatches no longer held the guest words they captured. With it, all rounds pass.
  • ^(agc_|shader_) with ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer, base (this branch with the item capture reverted, hook inert) and change, 2014 tests each, 0 was not found lines, 0 VUID- lines:
    • change: 4 failed, stencil_plane_memory, store_over_untracked, msaa_dcc_unwatch (all three fail on base too) and store_pending_identity, which passed 10 of 10 reruns on the change and does not turn dispatch items on; 1815 layer inserts
    • base: 4 failed, the same three plus pipelined_dispatch_misses (the new kept capture rounds); 1814 layer inserts
  • Ghost of Yōtei 02.002.000 DLC screen, 4 × 600 s runs with APS5_PIPELINE_DISPATCH=1 APS5_PIPELINE_DISPATCH_MISSES=1 on a test stack that includes this fix: 0 guest snapshot differs lines, no committer fault. Every earlier run with miss items had 23–24 of those lines, and one died on the committer.

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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.24, Windows 11
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5396750687 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/23722). Originally posted by [slopezjur](https://github.com/slopezjur) on 2026-11-19T14:25:36Z. --- ### What With `APS5_PIPELINE_DISPATCH=1 APS5_PIPELINE_DISPATCH_MISSES=1`, a queued dispatch item carries the guest snapshots its capture took and the draw committer records the dispatch from them later. The snapshot bytes point into the dispatch's `ShaderMemory` pages, but the item didn't hold that `ShaderMemory`. A missed dispatch, or a hit without a recipe, records from its fresh capture; its cache variant copies the words it needs and lets the capture go. Its pages then return to the queue worker's page pool when `Driver::dispatch` returns, while the item still waits on the committer. Items for cache hits with a recipe read the variant's own words and were not affected, so this only bites with `APS5_PIPELINE_DISPATCH_MISSES`. The next capture on queue 0 takes those pages and overwrites them. So when the committer records the queued dispatch, its snapshots hold another dispatch's words. A page the pool doesn't keep is freed instead, and the committer then reads freed memory. On Ghost of Yōtei (PPSA26344) with `APS5_PIPELINE_DISPATCH=1 APS5_PIPELINE_DISPATCH_MISSES=1`, every run logged 23 or 24 `guest snapshot differs from registered memory` lines. In one run the draw committer died with `0xc0000005` in `ShaderResources::Complete` → `GuestBufferMemory::AddSnapshot` (memcpy of a freed page). The item now also holds the dispatch's `ShaderMemory` and its registered shader until it is recorded. `Driver::SetDispatchItemHook` (same pattern as `SetCaptureCheckHook`) lets a test see the snapshots an item records from. ### Tested Windows 11, RTX 4080 SUPER. - New `kept capture` rounds in `tests/execution/PipelinedDispatch.cpp` (run by `agc_driver_pipelined_dispatch_misses`). Two missed dispatches queue behind a held committer and read different descriptor tables; when each is recorded, its snapshots must still hold the words it captured. Without the fix, round 0 fails: `1 snapshots of the queued dispatches no longer held the guest words they captured`. With it, all rounds pass. - `^(agc_|shader_)` with `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer`, base (this branch with the item capture reverted, hook inert) and change, 2014 tests each, 0 `was not found` lines, 0 `VUID-` lines: - change: 4 failed, `stencil_plane_memory`, `store_over_untracked`, `msaa_dcc_unwatch` (all three fail on base too) and `store_pending_identity`, which passed 10 of 10 reruns on the change and does not turn dispatch items on; 1815 layer inserts - base: 4 failed, the same three plus `pipelined_dispatch_misses` (the new kept capture rounds); 1814 layer inserts - Ghost of Yōtei 02.002.000 DLC screen, 4 × 600 s runs with `APS5_PIPELINE_DISPATCH=1 APS5_PIPELINE_DISPATCH_MISSES=1` on a test stack that includes this fix: 0 `guest snapshot differs` lines, no committer fault. Every earlier run with miss items had 23–24 of those lines, and one died on the committer. ### 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) and the licence notice of code adapted from upstream (see AGENTS.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.24, Windows 11 - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-11-19 14:35:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-19T14:35:03Z.

Review: APPROVED


Reviewed — looks good

The reviewed change retains the captured shader memory and registered shader until the queued dispatch is recorded; the inspected ownership path supports the stated fix.

What I ran

Reviewed head a56ad682f28ee6f57ba2d69a0d9391eae37aca90. Read description.md, commits.md, manifest.json, diff.patch, and all three changed files listed in the manifest using the pinned reader. No commands or tests were run.

Results

Check Result Note
Changed code review passed All three changed files read
Tests not run Author-reported results not independently verified

Findings

Blocking

None.

Non-blocking

None.

Not verified

The author-reported Windows, Vulkan, and Ghost of Yōtei test results were not rerun. No build or automated tests were run. No files were excluded by the manifest.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5976995936 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/23722#pullrequestreview-5976995936). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-19T14:35:03Z. **Review:** APPROVED --- # Reviewed — looks good The reviewed change retains the captured shader memory and registered shader until the queued dispatch is recorded; the inspected ownership path supports the stated fix. ## What I ran Reviewed head `a56ad682f28ee6f57ba2d69a0d9391eae37aca90`. Read `description.md`, `commits.md`, `manifest.json`, `diff.patch`, and all three changed files listed in the manifest using the pinned reader. No commands or tests were run. ## Results | Check | Result | Note | |---|---|---| | Changed code review | passed | All three changed files read | | Tests | not run | Author-reported results not independently verified | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified The author-reported Windows, Vulkan, and Ghost of Yōtei test results were not rerun. No build or automated tests were run. No files were excluded by the manifest. ## To get this to a good state Nothing is required.
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!23722
No description provided.