fix(agc): collect fresh CPU writes before depth plane stores #11690

Merged
JJenkx merged 2 commits from upstream-pr/11690 into main 2026-10-28 03:49:44 +00:00
JJenkx commented 2026-10-27 02:56:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-27T02:56:32Z.


What

A CPU write after an earlier memoized CollectWrites in the same epoch can be missed when a stale depth plane is flushed. The depth store then overwrites the CPU-repurposed unit, including vertex descriptors. Collect writes uncached immediately before FlushDepthPlanes synchronizes the plane, matching the existing storage-image writeback rule; keep collect memoization elsewhere.

The regression draws depth into a six-unit plane, primes the collect memo, writes a descriptor into one unit without advancing the epoch, then requests a small read from that unit. It checks that the descriptor survives, that the repurposed unit is not stored, and that an untouched unit still returns its GPU depth.

Overlap review: #11685 changes depth-copy methods and adds a different argument to the same fixture. Neither implementation depends on the other; preserve both command-line modes when combining their test edits. Other shared depth-source diffs were checked for a duplicate fresh collection in this store path; none found.

Tested

Current-main refresh, 2026-10-27 10:18 UTC pass: exact head 748661795896eca6fd54dbae3a7aad3de45ac859 on main 3fea2a937ba9fbab2f06c51691fe0c5763659aa3. One topic commit retains the fresh collect immediately before the stale-plane store, with current main's separate buffer-copy control preserved. All submodule pointers match that main.

Linux Release, RX 6650 XT/RADV Mesa 26.2.4, required Vulkan and shader caches disabled. Matched main passes all three existing controls three times (9 passes). Candidate passes four groups × three repetitions (12 passes), then 12 again after restoration. Replacing only production DepthSurface.cpp with main fails exactly the memoized-collect regression; the three controls pass. The within-unit regression places a 4 KiB unwatched hole and CPU descriptors in an adjacent watched page of the same 64 KiB unit, checking descriptor preservation and retained GPU depth.

Every individual physical execution proves RX 6650 XT selection and actual Khronos instance/device-layer insertion; zero skips, VUIDs or missing-layer failures. Restored production source matches the candidate, and the rebuilt AGC driver is byte-identical to its initial candidate. The forced-buffer setting is recorded in the executed harness/process environment and linked to the startup flag; CTest does not print every inherited variable. Conventions and whitespace pass. This is synthetic GPU regression evidence, without a new title, console, Windows or performance run. Earlier contributor results retain their original exact pins.

Exact source/dependency pins, initial/negative/restored raw logs and JUnit, forced-buffer receipt, independent reviews, hashes and service-owned FIFO/PTY receipts. SHA-256: 4787a341e92b9f1764de6e6bc11f7ae5af8d8e21ff5c75f8f71483c60742d798; downloaded copy verified.

Independent validation by jotitadev, exact head 0907519c74 on main b986c11a34: RTX 3070 / NVIDIA 595.99.02 and lavapipe / Mesa 26.0.3, Ubuntu 26.04. Main plus the new memo regression fails on both devices; adding the production fix gives 3/3 passes on both. These are reviewer-run results, separate from the author RADV qualification.

Arch Linux, AMD Radeon RX 6650 XT, Mesa RADV 26.2.4-1. Same source/build directory and GPU for both arms; main abed03546804575703dbedcdd3c65efc6bf5d0f2 plus only the new regression is a43914cb24230136104b74e8cf7653ec4bf7cb2f; adding the one-line fix is 0907519c746f153526c619f1fefb738ef406b1dd.

Both ran:

ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 \
VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation \
ctest --test-dir build -R '^(agc_driver_depth_plane_partial_store|agc_driver_depth_plane_partial_store_unimported|agc_driver_depth_plane_cpu_write_after_memo)$' -V

Main plus regression: existing two controls pass; the new test fails with a depth flush overwrote CPU descriptors written after a memoized collect. With the fix: 3/3 pass. Both logs show three actual Khronos layer insertions, no missing layer, no skipped tests, and zero VUID- errors. python3 tools/check_conventions.py --base origin/main passes. tools/pr_overlap.py --branch codex/depth-plane-fresh-collect-20261027 was run; shared-fixture overlap noted above.

Paired logs, results and patch, SHA256 2ce1a72c81723057ac6024668414a33b661fb425e1610274e80c09a0bb202188. No performance claim. Windows and other GPU vendors not tested. Bendy PPSA27624 discussion #10154 motivated the investigation. A follow-up native run on the same earlier diagnostic integration plus only this production line still exits 134 with overwritten descriptors (actual Khronos active, zero VUIDs, all state restored); the fresh scan fixes the synthetic memo regression but does not fix the title. No native-title unblock 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 6650 XT, Mesa RADV 26.2.4-1, Arch Linux
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5027871261 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11690). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-10-27T02:56:32Z. --- ### What A CPU write after an earlier memoized `CollectWrites` in the same epoch can be missed when a stale depth plane is flushed. The depth store then overwrites the CPU-repurposed unit, including vertex descriptors. Collect writes uncached immediately before `FlushDepthPlanes` synchronizes the plane, matching the existing storage-image writeback rule; keep collect memoization elsewhere. The regression draws depth into a six-unit plane, primes the collect memo, writes a descriptor into one unit without advancing the epoch, then requests a small read from that unit. It checks that the descriptor survives, that the repurposed unit is not stored, and that an untouched unit still returns its GPU depth. Overlap review: #11685 changes depth-copy methods and adds a different argument to the same fixture. Neither implementation depends on the other; preserve both command-line modes when combining their test edits. Other shared depth-source diffs were checked for a duplicate fresh collection in this store path; none found. ### Tested <!-- codex-main-refresh-20261027-1018-pr11690 --> **Current-main refresh, 2026-10-27 10:18 UTC pass:** exact head `748661795896eca6fd54dbae3a7aad3de45ac859` on main `3fea2a937ba9fbab2f06c51691fe0c5763659aa3`. One topic commit retains the fresh collect immediately before the stale-plane store, with current main's separate buffer-copy control preserved. All submodule pointers match that main. Linux Release, RX 6650 XT/RADV Mesa 26.2.4, required Vulkan and shader caches disabled. Matched main passes all three existing controls three times (9 passes). Candidate passes four groups × three repetitions (12 passes), then 12 again after restoration. Replacing only production DepthSurface.cpp with main fails exactly the memoized-collect regression; the three controls pass. The within-unit regression places a 4 KiB unwatched hole and CPU descriptors in an adjacent watched page of the same 64 KiB unit, checking descriptor preservation and retained GPU depth. Every individual physical execution proves RX 6650 XT selection and actual Khronos instance/device-layer insertion; zero skips, VUIDs or missing-layer failures. Restored production source matches the candidate, and the rebuilt AGC driver is byte-identical to its initial candidate. The forced-buffer setting is recorded in the executed harness/process environment and linked to the startup flag; CTest does not print every inherited variable. Conventions and whitespace pass. This is synthetic GPU regression evidence, without a new title, console, Windows or performance run. Earlier contributor results retain their original exact pins. [Exact source/dependency pins, initial/negative/restored raw logs and JUnit, forced-buffer receipt, independent reviews, hashes and service-owned FIFO/PTY receipts](https://github.com/JJenkx/AnyPS5/releases/download/linux-validation-20261023/pr11690-74866179-pr11692-1646ca28-main3fea-linux-20261027-1018.tar.gz). SHA-256: `4787a341e92b9f1764de6e6bc11f7ae5af8d8e21ff5c75f8f71483c60742d798`; downloaded copy verified. Independent validation by [jotitadev](https://github.com/boykopovar/AnyPS5/pull/11690#pullrequestreview-5662475032), exact head `0907519c74` on main `b986c11a34`: RTX 3070 / NVIDIA 595.99.02 and lavapipe / Mesa 26.0.3, Ubuntu 26.04. Main plus the new memo regression fails on both devices; adding the production fix gives 3/3 passes on both. These are reviewer-run results, separate from the author RADV qualification. Arch Linux, AMD Radeon RX 6650 XT, Mesa RADV 26.2.4-1. Same source/build directory and GPU for both arms; main `abed03546804575703dbedcdd3c65efc6bf5d0f2` plus only the new regression is `a43914cb24230136104b74e8cf7653ec4bf7cb2f`; adding the one-line fix is `0907519c746f153526c619f1fefb738ef406b1dd`. Both ran: ```sh ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 \ VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation \ ctest --test-dir build -R '^(agc_driver_depth_plane_partial_store|agc_driver_depth_plane_partial_store_unimported|agc_driver_depth_plane_cpu_write_after_memo)$' -V ``` Main plus regression: existing two controls pass; the new test fails with `a depth flush overwrote CPU descriptors written after a memoized collect`. With the fix: 3/3 pass. Both logs show three actual Khronos layer insertions, no missing layer, no skipped tests, and zero `VUID-` errors. `python3 tools/check_conventions.py --base origin/main` passes. `tools/pr_overlap.py --branch codex/depth-plane-fresh-collect-20261027` was run; shared-fixture overlap noted above. [Paired logs, results and patch](https://github.com/JJenkx/AnyPS5/releases/download/linux-validation-20261023/depth-plane-fresh-collect-linux-20261027.tar.gz), SHA256 `2ce1a72c81723057ac6024668414a33b661fb425e1610274e80c09a0bb202188`. No performance claim. Windows and other GPU vendors not tested. Bendy PPSA27624 discussion #10154 motivated the investigation. A follow-up native run on the same earlier diagnostic integration plus only this production line still exits 134 with overwritten descriptors (actual Khronos active, zero VUIDs, all state restored); the fresh scan fixes the synthetic memo regression but does **not** fix the title. No native-title unblock claimed. <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> ### 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 6650 XT, Mesa RADV 26.2.4-1, Arch Linux - [x] AI-assisted: yes
jotitadev commented 2026-10-27 05:08:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-27T05:08:43Z.

Review: COMMENTED


Linux run on NVIDIA and lavapipe, since the description covers RADV only. Head 0907519c74 on main b986c11a34 (patch applies cleanly). Ubuntu 26.04, GCC 15.2, Release. ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1, -j1. lavapipe selected with VK_ICD_FILENAMES=.../lvp_icd.json.

agc_driver_depth_plane_partial_store, _partial_store_unimported and agc_driver_depth_plane_cpu_write_after_memo:

RTX 3070 (NVIDIA 595.99.02) lavapipe (Mesa 26.0.3)
main + the new test only memo test fails: a depth flush overwrote CPU descriptors written after a memoized collect; both controls pass same failure, controls pass
main + the test + the DepthSurface.cpp line 3/3 pass 3/3 pass

So the test catches the bug on both devices, and the one-line fix is what makes it pass.

Full ^agc suite (without agc_display_buffer_dcc, agc_driver_flip, agc_driver_lds_atomics64, --timeout 30) with #11692 and #11691 applied together on main: 1041/1042 on both devices. The one failure on each also fails on unmodified main on this machine, with the same message: agc_driver_pipeline_journal on the 3070 (the oversized record was not counted as a write failure; it passes when only the NVIDIA ICD is visible), and agc_driver_multisample_retirement on lavapipe (MSAA storage promotion did not retain its source image).

GPUs tested: NVIDIA GeForce RTX 3070 (proprietary 595.99.02, Linux), lavapipe (Mesa 26.0.3, LLVM 21).

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5662475032 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11690#pullrequestreview-5662475032). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-27T05:08:43Z. **Review:** COMMENTED --- Linux run on NVIDIA and lavapipe, since the description covers RADV only. Head `0907519c74` on `main` `b986c11a34` (patch applies cleanly). Ubuntu 26.04, GCC 15.2, Release. `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1`, `-j1`. lavapipe selected with `VK_ICD_FILENAMES=.../lvp_icd.json`. `agc_driver_depth_plane_partial_store`, `_partial_store_unimported` and `agc_driver_depth_plane_cpu_write_after_memo`: | | RTX 3070 (NVIDIA 595.99.02) | lavapipe (Mesa 26.0.3) | |---|---|---| | `main` + the new test only | memo test fails: `a depth flush overwrote CPU descriptors written after a memoized collect`; both controls pass | same failure, controls pass | | `main` + the test + the `DepthSurface.cpp` line | 3/3 pass | 3/3 pass | So the test catches the bug on both devices, and the one-line fix is what makes it pass. Full `^agc` suite (without `agc_display_buffer_dcc`, `agc_driver_flip`, `agc_driver_lds_atomics64`, `--timeout 30`) with #11692 and #11691 applied together on `main`: 1041/1042 on both devices. The one failure on each also fails on unmodified `main` on this machine, with the same message: `agc_driver_pipeline_journal` on the 3070 (`the oversized record was not counted as a write failure`; it passes when only the NVIDIA ICD is visible), and `agc_driver_multisample_retirement` on lavapipe (`MSAA storage promotion did not retain its source image`). GPUs tested: NVIDIA GeForce RTX 3070 (proprietary 595.99.02, Linux), lavapipe (Mesa 26.0.3, LLVM 21). Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
MarcZX10 commented 2026-10-27 05:28:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-27T05:28:18Z.

Review: APPROVED


Reviewed exact head 0907519c746f153526c619f1fefb738ef406b1dd; approve.

The fresh uncached collect is placed immediately before SyncFromMemory in the stale-plane flush path. That refreshes write stamps even when a same-epoch memoized collect would otherwise be reused, allowing the existing per-unit WrittenSince comparison to protect CPU-repurposed bytes. The new regression primes that memo, performs a CPU descriptor write without advancing the epoch, and checks descriptor preservation plus GPU depth in an untouched unit. I found no duplicate fresh collect in the same path.

Validation evidence: the author reports main-plus-test failing and the fix passing on RADV with the validation layer active and zero VUIDs. An independent reviewer reports the same focused result on RTX 3070 and lavapipe. I could not run a fresh local GPU test in this environment; hosted product jobs are skipped by path policy. The fixture also overlaps #11685, so integration should retain both PRs' separate test modes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5662616280 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11690#pullrequestreview-5662616280). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-27T05:28:18Z. **Review:** APPROVED --- Reviewed exact head `0907519c746f153526c619f1fefb738ef406b1dd`; approve. The fresh uncached collect is placed immediately before `SyncFromMemory` in the stale-plane flush path. That refreshes write stamps even when a same-epoch memoized collect would otherwise be reused, allowing the existing per-unit `WrittenSince` comparison to protect CPU-repurposed bytes. The new regression primes that memo, performs a CPU descriptor write without advancing the epoch, and checks descriptor preservation plus GPU depth in an untouched unit. I found no duplicate fresh collect in the same path. Validation evidence: the author reports main-plus-test failing and the fix passing on RADV with the validation layer active and zero VUIDs. An independent reviewer reports the same focused result on RTX 3070 and lavapipe. I could not run a fresh local GPU test in this environment; hosted product jobs are skipped by path policy. The fixture also overlaps #11685, so integration should retain both PRs' separate test modes.
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!11690
No description provided.