fix(agc): collect fresh CPU writes before a retiring depth surface stores its stale units #16368

Merged
SleglJan merged 3 commits from upstream-pr/16368 into main 2026-11-17 20:57:47 +00:00
SleglJan commented 2026-11-06 12:25:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by SleglJan on 2026-11-06T12:25:23Z.


What

A depth surface retired for an unmatched view (retireStoringStale) decides which stale units to store from WrittenUnits, whose collect of the plane is memoized. A guest write that lands after the thread's earlier walk of the plane in the same collect epoch is not stamped, the unit reads as unwritten, and the store goes over the write. #11690 fixed this decision in the flush path, where FlushDepthPlanes collects uncached first. This is the same write at the retire path.

  • test(agc): a mode of the agc_driver_depth_plane_partial_store_tests executable, registered as agc_driver_depth_plane_cpu_write_after_memo_retire. A depth draw covers the plane and the guest fills one unit, so the plane reads as overwritten in memory; the collect epoch moves and the plane is collected; the guest then writes descriptors into another unit; a view with two levels, which the surface does not serve, retires it. On main it fails with AGC graphics: the retire of a depth surface overwrote CPU descriptors written after a memoized collect. Without a write watch it skips like the flush-path step (agc_driver_depth_plane_cpu_write_after_memo).
  • fix(agc): one uncached collect of the plane before WrittenUnits in retireStoringStale, the call #11690 added to the flush path.

Cost: one walk of the plane per retire of this kind.

Related: #14969 (open) covers the stale stencil plane of the same retire; it changes other lines. #15058 changes WrittenUnits itself, for shared memory; this PR adds a call in front of it. #15404 and #9895 add callers of retireStoringStale. #15059 changes the line two above the inserted one. #16011 adds a mode and its registration at the same place in the same test file and fragment; #15015 changes the same test file and adds a line to the fragment. I am happy to rebase behind any of them.

Tested

Head 4a5b07ede6 is this PR's two commits on upstream/main 75a1ced878.

  • Linux (CachyOS, kernel 7.2.10), Release, GCC 16.2.1, write watch available. ctest -V -R '^agc_driver_depth_plane_cpu_write_after_memo' with VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ANYPS5_NO_SHADER_CACHE=1 ANYPS5_REQUIRE_VULKAN=1, on an AMD Radeon RX 9070 XT (RADV GFX1201, Mesa 26.2.4) and on lavapipe (llvmpipe, LLVM 23.1.1, Mesa 26.2.4). The pattern matches the new step and the flush-path step of #11690.
    • main + the test commit: on both drivers agc_driver_depth_plane_cpu_write_after_memo_retire fails with the line above, and it is a failure, not a skip; agc_driver_depth_plane_cpu_write_after_memo passes. No VUID-.
    • with the fix: both pass on both drivers (the new step in 0.17 s on the RX 9070 XT and 0.05 s on lavapipe). No VUID-.
    • On both drivers and both sides the loader's debug log shows VK_LAYER_KHRONOS_validation inserted; no log reports was not found but was requested by env var VK_INSTANCE_LAYERS.
  • ctest -R '^agc' on the RX 9070 XT, without the validation layer: 2 of 1342 fail with the test commit, 1 of 1342 with the fix. The new step is the only difference in the failed list. agc_driver_tessellation fails (segmentation fault) on both sides, and the same 23 tests skip on both.
  • python3 tools/check_conventions.py --base upstream/main: passes.

No title effect is claimed.

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: AMD Radeon RX 9070 XT (RADV GFX1201), Mesa 26.2.4, Linux (CachyOS, kernel 7.2.10); lavapipe (llvmpipe, LLVM 23.1.1), Mesa 26.2.4, same host
  • AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5187791227 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16368). Originally posted by [SleglJan](https://github.com/SleglJan) on 2026-11-06T12:25:23Z. --- ### What A depth surface retired for an unmatched view (`retireStoringStale`) decides which stale units to store from `WrittenUnits`, whose collect of the plane is memoized. A guest write that lands after the thread's earlier walk of the plane in the same collect epoch is not stamped, the unit reads as unwritten, and the store goes over the write. #11690 fixed this decision in the flush path, where `FlushDepthPlanes` collects uncached first. This is the same write at the retire path. - `test(agc)`: a mode of the `agc_driver_depth_plane_partial_store_tests` executable, registered as `agc_driver_depth_plane_cpu_write_after_memo_retire`. A depth draw covers the plane and the guest fills one unit, so the plane reads as overwritten in memory; the collect epoch moves and the plane is collected; the guest then writes descriptors into another unit; a view with two levels, which the surface does not serve, retires it. On main it fails with `AGC graphics: the retire of a depth surface overwrote CPU descriptors written after a memoized collect`. Without a write watch it skips like the flush-path step (`agc_driver_depth_plane_cpu_write_after_memo`). - `fix(agc)`: one uncached collect of the plane before `WrittenUnits` in `retireStoringStale`, the call #11690 added to the flush path. Cost: one walk of the plane per retire of this kind. Related: #14969 (open) covers the stale stencil plane of the same retire; it changes other lines. #15058 changes `WrittenUnits` itself, for shared memory; this PR adds a call in front of it. #15404 and #9895 add callers of `retireStoringStale`. #15059 changes the line two above the inserted one. #16011 adds a mode and its registration at the same place in the same test file and fragment; #15015 changes the same test file and adds a line to the fragment. I am happy to rebase behind any of them. ### Tested Head 4a5b07ede6 is this PR's two commits on upstream/main 75a1ced878. - Linux (CachyOS, kernel 7.2.10), Release, GCC 16.2.1, write watch available. `ctest -V -R '^agc_driver_depth_plane_cpu_write_after_memo'` with `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ANYPS5_NO_SHADER_CACHE=1 ANYPS5_REQUIRE_VULKAN=1`, on an AMD Radeon RX 9070 XT (RADV GFX1201, Mesa 26.2.4) and on lavapipe (llvmpipe, LLVM 23.1.1, Mesa 26.2.4). The pattern matches the new step and the flush-path step of #11690. - `main` + the test commit: on both drivers `agc_driver_depth_plane_cpu_write_after_memo_retire` fails with the line above, and it is a failure, not a skip; `agc_driver_depth_plane_cpu_write_after_memo` passes. No `VUID-`. - with the fix: both pass on both drivers (the new step in 0.17 s on the RX 9070 XT and 0.05 s on lavapipe). No `VUID-`. - On both drivers and both sides the loader's debug log shows `VK_LAYER_KHRONOS_validation` inserted; no log reports `was not found but was requested by env var VK_INSTANCE_LAYERS`. - `ctest -R '^agc'` on the RX 9070 XT, without the validation layer: 2 of 1342 fail with the test commit, 1 of 1342 with the fix. The new step is the only difference in the failed list. `agc_driver_tessellation` fails (segmentation fault) on both sides, and the same 23 tests skip on both. - `python3 tools/check_conventions.py --base upstream/main`: passes. No title effect is claimed. ### 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: AMD Radeon RX 9070 XT (RADV GFX1201), Mesa 26.2.4, Linux (CachyOS, kernel 7.2.10); lavapipe (llvmpipe, LLVM 23.1.1), Mesa 26.2.4, same host - [x] AI-assisted: yes (Claude Code) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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!16368
No description provided.