fix(agc): drop depth and stencil plane results over memory unmapped since they were drawn #15466

Merged
JJenkx merged 9 commits from upstream-pr/15466 into main 2026-11-03 19:13:34 +00:00
JJenkx commented 2026-11-03 13:18:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-11-03T13:18:27Z.


What

A depth or stencil plane keeps the results of its draws on the GPU until something reads its guest memory. FlushDepthPlanes already drops those results when the plane's memory is unmapped at store time ("depth plane … was unmapped with GPU results pending; they are dropped"). But a title that unmaps the memory and maps new memory at the same addresses before the store gets the old results written into its new data.

Contra: Operation Galuga (PPSA15368) does this at the transition from the title screen to the intro. A pool that held its depth and stencil planes is unmapped, and new memory, which the game uses as a heap, is mapped at the same addresses about a second later. The next read stores the old planes over the heap. The game's allocator then follows a zeroed free-list link and crashes, or hangs walking the list. On main 4f41f4c375 this crash happened in 2 of 6 runs here (Contra row in Tested). In a local diagnostic build on the same main, every run logged 11 to 17 such plane stores over memory removed since the plane's last draw, and 4 of 6 crashed or hung.

This change:

  • Recording removals: the guest-allocation unmap observer (retireUnmapped, which RetireUnmappedDepth_nid_no_patch is part of) now records each removed range that overlaps a stale depth or stencil plane, with a serial. The observer fires only for removals (Remove, Unmap), not for protection changes, so a reprotected plane keeps its results.
  • Mark serials: each surface records a serial from the same counter when real work reaches a plane: a draw that writes or clears depth, an HTILE clear or plane fill recorded for it, or a stencil write or clear. Expanding a pending clear over a plane's units while storing it does not count. A surface that takes another owner's pending clear also takes that owner's mark.
  • Dropping stale results: where a removal that overlaps the plane came after the plane's last mark, the stores drop results. For a depth plane, FlushDepthPlanes and retireStoringStale drop only the 64 KiB units that overlap a removed range, and the other units are stored as before. A stencil plane is stored whole, so its stores (FlushDepthPlanes and storeStaleStencil) drop the whole plane. That loses the results of stencil units outside the removed range, a limit the debt entry now states. A plane that is entirely uncommitted is still dropped whole, as before. A draw after the remap marks the plane again, and its results are stored.
  • Observer installation: the observer is now installed once a stale plane exists (DepthPlanesStale() joins the condition in UpdateResidentImageUnmapObserver_nid_no_patch).

Lock order: the observer runs under the registry mutation. It takes planes.mutex (through overlapsStalePlane) and the new list's mutex, each released before the other is taken. Neither is held while taking any other lock. The store paths read the list under the surfaces mutex, and FlushDepthPlanes prunes it under planes.mutex. No path holds the list's mutex while taking planes.mutex.

#8932 (closed) drops pending storage-image results at an unmap through the same observer. This change covers depth and stencil planes, which that PR does not touch.

Tested

AMD Radeon RX 6650 XT, RADV Mesa 26.2.6, Linux 7.2.11, Release.

  • New test agc_driver_depth_plane_unmapped_plane (DepthPlanePartialStore --unmapped-plane): a depth draw over a registered plane, then one mutation that removes and adds the allocation again, then a CPU fill of the plane. A whole-plane FlushDepthPlanes must store nothing and leave the CPU's bytes. A second draw after the remap must then be stored in full. agc_driver_stencil_plane_memory gains the same case for a stencil plane: stencil 0x33 drawn, the allocation removed and added again, the CPU writes 0x44, and a flush must store nothing; stencil 0x18 drawn after the remap must reach guest memory. On main plus only the tests, both fail: "a read of a plane unmapped and mapped again stored the results drawn before the unmap" and "a read of a stencil plane unmapped and mapped again stored the stencil drawn before the unmap". With this change both pass.
  • Unmap after a pending fill, and partial unmap (review follow-up, agc_driver_depth_plane_unmapped_plane_fill and agc_driver_depth_plane_partially_unmapped_plane): a depth fill recorded before an unmap and remap must not be stored by a later flush with no further draw. When only the first unit is unmapped and mapped again, a flush must store exactly the other five units and leave the first unit's new bytes. Both fail at the previous head a82312517b and pass at be898698d1.
  • Existing tests: with this change at be898698d1, every built agc_driver_(depth|stencil|native_multisample|multisample|idle_store|graphics) test passes: 59 of 59 with VK_LAYER_KHRONOS_validation, ANYPS5_NO_SHADER_CACHE=1 and ANYPS5_REQUIRE_VULKAN=1, with no VUID- in any log. The Contra runs below are at the earlier head a82312517b.
  • Contra: Operation Galuga (PPSA15368): 300 s runs from boot through the title screen into the intro, Cross every 12 s. Six alternating runs per build:
    • main 4f41f4c375 plus only this PR's tests, so its libraries are main's: 2 of 6 crashed (SIGSEGV at 125 s and 101 s, in the allocator after the transition).
    • This PR: 0 of 6 crashed or hung. Every one of its runs logs the depth-plane drop warning, for the same 32 MiB plane at 0x241dd0000. No main run does.
    • Six runs per build are too few to show the crash difference on their own (Fisher two-sided p ≈ 0.45). The tests above are the deterministic evidence; the runs show that the new drop happens in the title and that nothing else broke there.

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; #14052 reports this crash, but six runs do not show that its loading stall is gone
  • Unblocks: PPSA15368 #14053 (crash after the title screen; issue #14052)
  • GPUs tested: AMD Radeon RX 6650 XT, RADV Mesa 26.2.6, Linux 7.2.11
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5137910076 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15466). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-11-03T13:18:27Z. --- ### What A depth or stencil plane keeps the results of its draws on the GPU until something reads its guest memory. `FlushDepthPlanes` already drops those results when the plane's memory is unmapped at store time ("depth plane … was unmapped with GPU results pending; they are dropped"). But a title that unmaps the memory and maps new memory at the same addresses before the store gets the old results written into its new data. Contra: Operation Galuga (PPSA15368) does this at the transition from the title screen to the intro. A pool that held its depth and stencil planes is unmapped, and new memory, which the game uses as a heap, is mapped at the same addresses about a second later. The next read stores the old planes over the heap. The game's allocator then follows a zeroed free-list link and crashes, or hangs walking the list. On `main` `4f41f4c375` this crash happened in 2 of 6 runs here (Contra row in Tested). In a local diagnostic build on the same `main`, every run logged 11 to 17 such plane stores over memory removed since the plane's last draw, and 4 of 6 crashed or hung. This change: - **Recording removals:** the guest-allocation unmap observer (`retireUnmapped`, which `RetireUnmappedDepth_nid_no_patch` is part of) now records each removed range that overlaps a stale depth or stencil plane, with a serial. The observer fires only for removals (`Remove`, `Unmap`), not for protection changes, so a reprotected plane keeps its results. - **Mark serials:** each surface records a serial from the same counter when real work reaches a plane: a draw that writes or clears depth, an HTILE clear or plane fill recorded for it, or a stencil write or clear. Expanding a pending clear over a plane's units while storing it does not count. A surface that takes another owner's pending clear also takes that owner's mark. - **Dropping stale results:** where a removal that overlaps the plane came after the plane's last mark, the stores drop results. For a depth plane, `FlushDepthPlanes` and `retireStoringStale` drop only the 64 KiB units that overlap a removed range, and the other units are stored as before. A stencil plane is stored whole, so its stores (`FlushDepthPlanes` and `storeStaleStencil`) drop the whole plane. That loses the results of stencil units outside the removed range, a limit the debt entry now states. A plane that is entirely uncommitted is still dropped whole, as before. A draw after the remap marks the plane again, and its results are stored. - **Observer installation:** the observer is now installed once a stale plane exists (`DepthPlanesStale()` joins the condition in `UpdateResidentImageUnmapObserver_nid_no_patch`). **Lock order:** the observer runs under the registry mutation. It takes `planes.mutex` (through `overlapsStalePlane`) and the new list's mutex, each released before the other is taken. Neither is held while taking any other lock. The store paths read the list under the surfaces mutex, and `FlushDepthPlanes` prunes it under `planes.mutex`. No path holds the list's mutex while taking `planes.mutex`. #8932 (closed) drops pending storage-image results at an unmap through the same observer. This change covers depth and stencil planes, which that PR does not touch. ### Tested AMD Radeon RX 6650 XT, RADV Mesa 26.2.6, Linux 7.2.11, Release. - **New test** `agc_driver_depth_plane_unmapped_plane` (`DepthPlanePartialStore --unmapped-plane`): a depth draw over a registered plane, then one mutation that removes and adds the allocation again, then a CPU fill of the plane. A whole-plane `FlushDepthPlanes` must store nothing and leave the CPU's bytes. A second draw after the remap must then be stored in full. `agc_driver_stencil_plane_memory` gains the same case for a stencil plane: stencil 0x33 drawn, the allocation removed and added again, the CPU writes 0x44, and a flush must store nothing; stencil 0x18 drawn after the remap must reach guest memory. On `main` plus only the tests, both fail: "a read of a plane unmapped and mapped again stored the results drawn before the unmap" and "a read of a stencil plane unmapped and mapped again stored the stencil drawn before the unmap". With this change both pass. - **Unmap after a pending fill, and partial unmap** (review follow-up, `agc_driver_depth_plane_unmapped_plane_fill` and `agc_driver_depth_plane_partially_unmapped_plane`): a depth fill recorded before an unmap and remap must not be stored by a later flush with no further draw. When only the first unit is unmapped and mapped again, a flush must store exactly the other five units and leave the first unit's new bytes. Both fail at the previous head `a82312517b` and pass at `be898698d1`. - **Existing tests:** with this change at `be898698d1`, every built `agc_driver_(depth|stencil|native_multisample|multisample|idle_store|graphics)` test passes: 59 of 59 with `VK_LAYER_KHRONOS_validation`, `ANYPS5_NO_SHADER_CACHE=1` and `ANYPS5_REQUIRE_VULKAN=1`, with no `VUID-` in any log. The Contra runs below are at the earlier head `a82312517b`. - **Contra: Operation Galuga (PPSA15368):** 300 s runs from boot through the title screen into the intro, Cross every 12 s. Six alternating runs per build: - `main` `4f41f4c375` plus only this PR's tests, so its libraries are `main`'s: 2 of 6 crashed (SIGSEGV at 125 s and 101 s, in the allocator after the transition). - This PR: 0 of 6 crashed or hung. Every one of its runs logs the depth-plane drop warning, for the same 32 MiB plane at `0x241dd0000`. No `main` run does. - Six runs per build are too few to show the crash difference on their own (Fisher two-sided p ≈ 0.45). The tests above are the deterministic evidence; the runs show that the new drop happens in the title and that nothing else broke there. ### 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) - [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; #14052 reports this crash, but six runs do not show that its loading stall is gone - [x] Unblocks: PPSA15368 #14053 (crash after the title screen; issue #14052) - [x] GPUs tested: AMD Radeon RX 6650 XT, RADV Mesa 26.2.6, Linux 7.2.11 - [x] AI-assisted: yes
XairRrR commented 2026-11-03 13:36:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-03T13:36:51Z.

Review: APPROVED


Reviewed — approved

The change stops depth and stencil plane results drawn before an unmap from being stored over memory mapped again at the same addresses. Both new test cases fail on main and pass with the change. I found one non-blocking gap: a depth fast clear still pending at the time of the remap.

What I ran

Head a82312517b2691efc9c98db52404cc9c56d51f35, main 4f41f4c375f5abb487dbd184fbc150f31994d762, merged with --no-ff in a clean worktree. Debian 13 VM, GCC 14.2.0, lavapipe (Mesa 26.1.6, LLVM 19), Release.

git diff --check 4f41f4c375f5abb487dbd184fbc150f31994d762...a82312517b2691efc9c98db52404cc9c56d51f35
python3 tools/check_conventions.py --base 4f41f4c375f5abb487dbd184fbc150f31994d762
ctest --test-dir build -j8 --test-load 32 --output-on-failure -R "depth_plane|stencil_plane"
# negative control
git show 4f41f4c375f5abb487dbd184fbc150f31994d762:core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp > core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
git show 4f41f4c375f5abb487dbd184fbc150f31994d762:core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cpp > core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cpp
ninja -C build -j32 -l32 agc_driver_stencil_plane_memory_tests agc_driver_depth_plane_partial_store_tests
ctest --test-dir build --output-on-failure -R "agc_driver_stencil_plane_memory|agc_driver_depth_plane_unmapped_plane"
# restore
git show f84aff456d68a25009a9e425859c9c24dc7efd7d:<both files> > <both files>
ninja -C build -j32 -l32 agc_driver_stencil_plane_memory_tests agc_driver_depth_plane_partial_store_tests libs
ctest --test-dir build -j8 --test-load 32 -R "depth_plane|stencil_plane"
git status --porcelain

Results

Check Result
git diff --check clean
check_conventions.py All conventions checks passed
Configure / build / libs (script) ok
Selected tests (script, 2207 run) no new failures, no timeouts. 7 known failures, which also fail on main (agc_driver_division, the denormal-mode tests, vector_constant_factor_tininess, an unwrap test); none are related to this change
Validation layer (script, 771 tests vs main) layer loaded in 770, missing in none; 0 tests with new VUID- lines
depth_plane|stencil_plane (13 tests, including agc_driver_depth_plane_unmapped_plane and agc_driver_stencil_plane_memory) 13/13 passed, slowest 5.7 s
Worktree after the negative control git status --porcelain is empty

Negative control

I restored DepthSurface.cpp and MultisampleTarget.cpp from main, kept the PR's tests, and rebuilt both test executables. Both new cases failed with the messages the description quotes:

output on main + tests
AGC graphics: a read of a plane unmapped and mapped again stored the results drawn before the unmap
AGC graphics: a read of a stencil plane unmapped and mapped again stored the stencil drawn before the unmap
The following tests FAILED:
	1504 - agc_driver_stencil_plane_memory (Failed)
	1674 - agc_driver_depth_plane_unmapped_plane (Failed)

After I restored the merged files and rebuilt, all 13 depth and stencil plane tests passed again.

Findings

Blocking

None.

Non-blocking

  1. A depth fast clear or plane fill pending since before the unmap is still stored over the remapped memory.

    • Where: DepthSurface.cpp:2802-2804.
    • What happens: FlushDepthPlanes calls surface->MarkAllStale(planeBytes) for a surface whose pendingClear has the depth bit. Only after that does it test unmappedSince(plane, plane + planeBytes, surface->depthMark). MarkAllStale now sets depthMark = nextPlaneSerial() (DepthSurface.cpp:1107-1111), so the mark is always newer than any recorded removal and the check never drops anything on this path.
    • Sequence that triggers it:
      1. A depth draw registers the plane.
      2. An HTILE fill or plane fill sets the depth pendingClear without marking the plane. The callers are DepthSurface.cpp:3034 and DepthSurface.cpp:3324.
      3. The pool is unmapped and mapped again.
      4. A read stores the cleared plane over the new data.
    • Why it matters: this is the corruption the PR fixes, through a different path. It also contradicts the new debt entry ("unmapped and mapped again since its last draw, is not stored"). I found this by reading the code; I did not write a test for it.
    • Suggested fix: move the unmappedSince check ahead of the MarkAllStale call at line 2802. Alternatively, take the depth mark when the clear is recorded (in NoteHtileClear / NotePlaneFill for the depth aspect) and keep it in MarkAllStale on this path. A variant of --unmapped-plane with a depth HTILE fill between the draw and the remap would cover it.
  2. The list of unmapped ranges is pruned only in FlushDepthPlanes. storeStaleStencil and retireStoringStale read the list but never prune it. The list stays bounded, because noteUnmappedPlane records only ranges that overlap a stale plane and the next flush that reaches its main loop prunes them. If no stale plane remains, FlushDepthPlanes returns early and old entries stay in memory until a later plane triggers a flush. This needs no change; I note it only for future readers.

I checked the lock order the description gives, and it holds:

  • pruneUnmappedPlanes runs with planes.mutex held (DepthSurface.cpp:2826-2830), so the order is planes.mutex → list mutex.
  • noteUnmappedPlane releases planes.mutex (in overlapsStalePlane) before it takes the list mutex. No path takes the two in the opposite order.
  • GuestAllocationsSetUnmapObserver_nid_postfix is a plain atomic store, so calling UpdateResidentImageUnmapObserver_nid_no_patch from noteStalePlane under the surfaces mutex cannot deadlock with the observer.

Not verified

  • The Contra: Operation Galuga (PPSA15368) runs and the RX 6650 XT / RADV results: I have no GPU here, and the rules forbid launching titles.
  • The pending-clear path in finding 1 is from reading the code only; I did not reproduce it with a test.
  • Tests ran on lavapipe only.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5753101521 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15466#pullrequestreview-5753101521). Originally posted by [XairRrR](https://github.com/XairRrR) on 2026-11-03T13:36:51Z. **Review:** APPROVED --- # Reviewed — approved The change stops depth and stencil plane results drawn before an unmap from being stored over memory mapped again at the same addresses. Both new test cases fail on `main` and pass with the change. I found one non-blocking gap: a depth fast clear still pending at the time of the remap. ## What I ran Head `a82312517b2691efc9c98db52404cc9c56d51f35`, `main` `4f41f4c375f5abb487dbd184fbc150f31994d762`, merged with `--no-ff` in a clean worktree. Debian 13 VM, GCC 14.2.0, lavapipe (Mesa 26.1.6, LLVM 19), Release. ``` git diff --check 4f41f4c375f5abb487dbd184fbc150f31994d762...a82312517b2691efc9c98db52404cc9c56d51f35 python3 tools/check_conventions.py --base 4f41f4c375f5abb487dbd184fbc150f31994d762 ctest --test-dir build -j8 --test-load 32 --output-on-failure -R "depth_plane|stencil_plane" # negative control git show 4f41f4c375f5abb487dbd184fbc150f31994d762:core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp > core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp git show 4f41f4c375f5abb487dbd184fbc150f31994d762:core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cpp > core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cpp ninja -C build -j32 -l32 agc_driver_stencil_plane_memory_tests agc_driver_depth_plane_partial_store_tests ctest --test-dir build --output-on-failure -R "agc_driver_stencil_plane_memory|agc_driver_depth_plane_unmapped_plane" # restore git show f84aff456d68a25009a9e425859c9c24dc7efd7d:<both files> > <both files> ninja -C build -j32 -l32 agc_driver_stencil_plane_memory_tests agc_driver_depth_plane_partial_store_tests libs ctest --test-dir build -j8 --test-load 32 -R "depth_plane|stencil_plane" git status --porcelain ``` ## Results | Check | Result | |---|---| | `git diff --check` | clean | | `check_conventions.py` | All conventions checks passed | | Configure / build / `libs` (script) | ok | | Selected tests (script, 2207 run) | no new failures, no timeouts. 7 known failures, which also fail on `main` (`agc_driver_division`, the denormal-mode tests, `vector_constant_factor_tininess`, an unwrap test); none are related to this change | | Validation layer (script, 771 tests vs `main`) | layer loaded in 770, missing in none; 0 tests with new `VUID-` lines | | `depth_plane\|stencil_plane` (13 tests, including `agc_driver_depth_plane_unmapped_plane` and `agc_driver_stencil_plane_memory`) | 13/13 passed, slowest 5.7 s | | Worktree after the negative control | `git status --porcelain` is empty | ## Negative control I restored `DepthSurface.cpp` and `MultisampleTarget.cpp` from `main`, kept the PR's tests, and rebuilt both test executables. Both new cases failed with the messages the description quotes: <details><summary>output on main + tests</summary> ``` AGC graphics: a read of a plane unmapped and mapped again stored the results drawn before the unmap AGC graphics: a read of a stencil plane unmapped and mapped again stored the stencil drawn before the unmap The following tests FAILED: 1504 - agc_driver_stencil_plane_memory (Failed) 1674 - agc_driver_depth_plane_unmapped_plane (Failed) ``` </details> After I restored the merged files and rebuilt, all 13 depth and stencil plane tests passed again. ## Findings ### Blocking None. ### Non-blocking 1. **A depth fast clear or plane fill pending since before the unmap is still stored over the remapped memory.** - **Where:** [`DepthSurface.cpp:2802-2804`](https://github.com/boykopovar/AnyPS5/blob/a82312517b2691efc9c98db52404cc9c56d51f35/core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp#L2802-L2804). - **What happens:** `FlushDepthPlanes` calls `surface->MarkAllStale(planeBytes)` for a surface whose `pendingClear` has the depth bit. Only after that does it test `unmappedSince(plane, plane + planeBytes, surface->depthMark)`. `MarkAllStale` now sets `depthMark = nextPlaneSerial()` ([`DepthSurface.cpp:1107-1111`](https://github.com/boykopovar/AnyPS5/blob/a82312517b2691efc9c98db52404cc9c56d51f35/core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp#L1107-L1111)), so the mark is always newer than any recorded removal and the check never drops anything on this path. - **Sequence that triggers it:** 1. A depth draw registers the plane. 2. An HTILE fill or plane fill sets the depth `pendingClear` without marking the plane. The callers are [`DepthSurface.cpp:3034`](https://github.com/boykopovar/AnyPS5/blob/a82312517b2691efc9c98db52404cc9c56d51f35/core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp#L3034) and [`DepthSurface.cpp:3324`](https://github.com/boykopovar/AnyPS5/blob/a82312517b2691efc9c98db52404cc9c56d51f35/core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp#L3324). 3. The pool is unmapped and mapped again. 4. A read stores the cleared plane over the new data. - **Why it matters:** this is the corruption the PR fixes, through a different path. It also contradicts the new debt entry ("unmapped and mapped again since its last draw, is not stored"). I found this by reading the code; I did not write a test for it. - **Suggested fix:** move the `unmappedSince` check ahead of the `MarkAllStale` call at line 2802. Alternatively, take the depth mark when the clear is recorded (in `NoteHtileClear` / `NotePlaneFill` for the depth aspect) and keep it in `MarkAllStale` on this path. A variant of `--unmapped-plane` with a depth HTILE fill between the draw and the remap would cover it. 2. **The list of unmapped ranges is pruned only in `FlushDepthPlanes`.** `storeStaleStencil` and `retireStoringStale` read the list but never prune it. The list stays bounded, because `noteUnmappedPlane` records only ranges that overlap a stale plane and the next flush that reaches its main loop prunes them. If no stale plane remains, `FlushDepthPlanes` returns early and old entries stay in memory until a later plane triggers a flush. This needs no change; I note it only for future readers. I checked the lock order the description gives, and it holds: - `pruneUnmappedPlanes` runs with `planes.mutex` held ([`DepthSurface.cpp:2826-2830`](https://github.com/boykopovar/AnyPS5/blob/a82312517b2691efc9c98db52404cc9c56d51f35/core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp#L2826-L2830)), so the order is `planes.mutex` → list mutex. - `noteUnmappedPlane` releases `planes.mutex` (in `overlapsStalePlane`) before it takes the list mutex. No path takes the two in the opposite order. - `GuestAllocationsSetUnmapObserver_nid_postfix` is a plain atomic store, so calling `UpdateResidentImageUnmapObserver_nid_no_patch` from `noteStalePlane` under the surfaces mutex cannot deadlock with the observer. ## Not verified - The Contra: Operation Galuga (PPSA15368) runs and the RX 6650 XT / RADV results: I have no GPU here, and the rules forbid launching titles. - The pending-clear path in finding 1 is from reading the code only; I did not reproduce it with a test. - Tests ran on lavapipe only. <!-- anyps5-bots job=3353 head=a82312517b2691efc9c98db52404cc9c56d51f35 -->
XairRrR commented 2026-11-03 14:40:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-03T14:40:45Z.

Review: APPROVED


Re-checked — approved

Commits 317296719d, ce8aaf32db and be898698d1 take the depth mark when a draw, clear or fill is recorded instead of in MarkAllStale, drop only the depth units a removal covers, add two tests and update the debt entry. This resolves the pending-fill finding from my previous review.

What changed since my last review

  • DepthSurface.cpp:
    • MarkAllStale no longer advances depthMark. A new NoteDepthWork() does that, called from three places: a depth-writing or clearing bind, NoteHtileClear with the depth aspect, and NotePlaneFill for depth.
    • takePlane takes the owner's mark along with the owner's pending clear.
    • FlushDepthPlanes and retireStoringStale use the new unmappedUnits to drop only the stale units that overlap a removal newer than the mark. A fully uncommitted plane is still dropped whole.
  • Tests: --partially-unmapped-plane and --unmapped-plane-fill, each registered as its own CTest case with TIMEOUT 30.
  • Debt entry: now says that a stencil plane is still dropped whole when only part of it was unmapped.
  • Discussion: the author replied to oneandonlydean's two points. Those points are the same as my previous finding 1, plus the partial-unmap case.

What I ran

Head be898698d1a6d310f010efd72c95ddb5c32920b5, main 4f41f4c375f5abb487dbd184fbc150f31994d762, merged with --no-ff (4d3ee2824ce1abd4dfc9c4eba41a451e0c6aa9a3) in a clean worktree. Debian 13 VM, GCC 14.2.0, lavapipe (Mesa 26.1.6, LLVM 19), Release.

git diff --check 4f41f4c375f5abb487dbd184fbc150f31994d762...be898698d1a6d310f010efd72c95ddb5c32920b5
python3 tools/check_conventions.py --base 4f41f4c375f5abb487dbd184fbc150f31994d762
git diff a82312517b2691efc9c98db52404cc9c56d51f35 be898698d1a6d310f010efd72c95ddb5c32920b5
ctest --test-dir build -j8 --test-load 32 --output-on-failure -R "depth_plane|stencil_plane"
# negative control A: previous head's DepthSurface.cpp
git show a82312517b2691efc9c98db52404cc9c56d51f35:core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp > core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
ninja -C build -j32 -l32 agc_driver_depth_plane_partial_store_tests agc_driver_stencil_plane_memory_tests
ctest --test-dir build --output-on-failure -R "agc_driver_depth_plane_(unmapped_plane|partially_unmapped_plane|unmapped_plane_fill)$"
# negative control B: main's DepthSurface.cpp and MultisampleTarget.cpp
git show 4f41f4c375f5abb487dbd184fbc150f31994d762:<file> > <file>   # both files
ninja -C build -j32 -l32 agc_driver_depth_plane_partial_store_tests agc_driver_stencil_plane_memory_tests
ctest --test-dir build --output-on-failure -R "agc_driver_depth_plane_(unmapped_plane|partially_unmapped_plane|unmapped_plane_fill)$|agc_driver_stencil_plane_memory$"
# restore
git show 4d3ee2824ce1abd4dfc9c4eba41a451e0c6aa9a3:<file> > <file>   # both files
ninja -C build -j32 -l32 agc_driver_depth_plane_partial_store_tests agc_driver_stencil_plane_memory_tests libs
ctest --test-dir build -j8 --test-load 32 -R "depth_plane|stencil_plane"
git status --porcelain
Check Result
git diff --check clean
check_conventions.py All conventions checks passed
Configure / build / libs (script) ok
Selected tests (script, 2209 run) no new failures, no timeouts. The 7 known failures also fail on main and are unrelated
Validation layer (script, 773 tests vs main) layer loaded in 772, missing in none; 0 tests with new VUID- lines
depth_plane|stencil_plane (15 tests) 15/15 passed, all under 6 s
Worktree after the negative controls git status --porcelain is empty; 15/15 pass again
Negative control output
# A: previous head a82312517b + new tests
agc_driver_depth_plane_unmapped_plane ............. Passed
agc_driver_depth_plane_partially_unmapped_plane ...***Failed
AGC graphics: a read of a plane whose first unit was unmapped and mapped again stored none of its other units
agc_driver_depth_plane_unmapped_plane_fill ........***Failed
AGC graphics: a read of a plane unmapped and mapped again after a depth fill stored the fill recorded before the unmap

# B: main production files + tests
agc_driver_stencil_plane_memory ...................***Failed
AGC graphics: a read of a stencil plane unmapped and mapped again stored the stencil drawn before the unmap
agc_driver_depth_plane_unmapped_plane .............***Failed
AGC graphics: a read of a plane unmapped and mapped again stored the results drawn before the unmap
agc_driver_depth_plane_partially_unmapped_plane ... Passed
agc_driver_depth_plane_unmapped_plane_fill ........***Failed
AGC graphics: a read of a plane unmapped and mapped again after a depth fill stored the fill recorded before the unmap

--partially-unmapped-plane passes on main, as expected: main stores every unit. The test guards against the whole-plane drop that the previous head introduced, and it fails there. So my run confirms the author's negative control against a82312517b.

Previous findings

  1. A depth fast clear or plane fill pending since before the unmap is stored over the remapped memory: Resolved.
    • MarkAllStale no longer touches the mark (DepthSurface.cpp:1114-1118).
    • The mark is now taken when the clear or fill is recorded (DepthSurface.cpp:739-755).
    • So the MarkAllStale expansion in FlushDepthPlanes no longer hides the removal (DepthSurface.cpp:2825-2835).
    • agc_driver_depth_plane_unmapped_plane_fill covers exactly this sequence. It fails at a82312517b and passes at this head.
  2. The unmapped list is pruned only in FlushDepthPlanes: No longer applies. This was an observation for future readers, not a requested change. The list is still bounded, because noteUnmappedPlane records only ranges that overlap a stale plane.

oneandonlydean's partial-unmap point is also addressed for depth:

  • unmappedUnits (DepthSurface.cpp:2363-2375) marks only the units that a removal newer than the mark overlaps.
  • FlushDepthPlanes clears only those units and stores the rest. retireStoringStale does the same (DepthSurface.cpp:2474-2480).
  • The unit bounds hold: the loop stops at count, and count is staleUnits.size(). retireStoringStale indexes removed[unit] only up to that same size.
  • The stencil plane is still dropped whole on a partial unmap. The debt entry now states this, which the rules allow.

New findings

Blocking

None.

Non-blocking

None.

Not verified

  • The Contra: Operation Galuga (PPSA15368) runs and the RX 6650 XT / RADV results. The Contra runs were at the previous head a82312517b, not at this one. I have no GPU here, and the rules forbid launching titles. The author's 59/59 run at be898698d1 is accepted as author-reported.
  • After a partial drop, the host image still holds the pre-unmap texels of the dropped units. They are reloaded only if the guest's writes to the new memory are collected; SyncFromMemory skips that while a depth clear is pending. A later draw that does not cover those units could then store old texels over the new memory. I did not check whether mapping fresh memory counts as a write in the tracker, and I did not write a test for this case.
  • Tests ran on lavapipe only.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5754126910 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15466#pullrequestreview-5754126910). Originally posted by [XairRrR](https://github.com/XairRrR) on 2026-11-03T14:40:45Z. **Review:** APPROVED --- # Re-checked — approved Commits `317296719d`, `ce8aaf32db` and `be898698d1` take the depth mark when a draw, clear or fill is recorded instead of in `MarkAllStale`, drop only the depth units a removal covers, add two tests and update the debt entry. This resolves the pending-fill finding from my previous review. ## What changed since my last review - **`DepthSurface.cpp`:** - `MarkAllStale` no longer advances `depthMark`. A new `NoteDepthWork()` does that, called from three places: a depth-writing or clearing bind, `NoteHtileClear` with the depth aspect, and `NotePlaneFill` for depth. - `takePlane` takes the owner's mark along with the owner's pending clear. - `FlushDepthPlanes` and `retireStoringStale` use the new `unmappedUnits` to drop only the stale units that overlap a removal newer than the mark. A fully uncommitted plane is still dropped whole. - **Tests:** `--partially-unmapped-plane` and `--unmapped-plane-fill`, each registered as its own CTest case with `TIMEOUT 30`. - **Debt entry:** now says that a stencil plane is still dropped whole when only part of it was unmapped. - **Discussion:** the author replied to oneandonlydean's two points. Those points are the same as my previous finding 1, plus the partial-unmap case. ## What I ran Head `be898698d1a6d310f010efd72c95ddb5c32920b5`, `main` `4f41f4c375f5abb487dbd184fbc150f31994d762`, merged with `--no-ff` (`4d3ee2824ce1abd4dfc9c4eba41a451e0c6aa9a3`) in a clean worktree. Debian 13 VM, GCC 14.2.0, lavapipe (Mesa 26.1.6, LLVM 19), Release. ``` git diff --check 4f41f4c375f5abb487dbd184fbc150f31994d762...be898698d1a6d310f010efd72c95ddb5c32920b5 python3 tools/check_conventions.py --base 4f41f4c375f5abb487dbd184fbc150f31994d762 git diff a82312517b2691efc9c98db52404cc9c56d51f35 be898698d1a6d310f010efd72c95ddb5c32920b5 ctest --test-dir build -j8 --test-load 32 --output-on-failure -R "depth_plane|stencil_plane" # negative control A: previous head's DepthSurface.cpp git show a82312517b2691efc9c98db52404cc9c56d51f35:core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp > core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp ninja -C build -j32 -l32 agc_driver_depth_plane_partial_store_tests agc_driver_stencil_plane_memory_tests ctest --test-dir build --output-on-failure -R "agc_driver_depth_plane_(unmapped_plane|partially_unmapped_plane|unmapped_plane_fill)$" # negative control B: main's DepthSurface.cpp and MultisampleTarget.cpp git show 4f41f4c375f5abb487dbd184fbc150f31994d762:<file> > <file> # both files ninja -C build -j32 -l32 agc_driver_depth_plane_partial_store_tests agc_driver_stencil_plane_memory_tests ctest --test-dir build --output-on-failure -R "agc_driver_depth_plane_(unmapped_plane|partially_unmapped_plane|unmapped_plane_fill)$|agc_driver_stencil_plane_memory$" # restore git show 4d3ee2824ce1abd4dfc9c4eba41a451e0c6aa9a3:<file> > <file> # both files ninja -C build -j32 -l32 agc_driver_depth_plane_partial_store_tests agc_driver_stencil_plane_memory_tests libs ctest --test-dir build -j8 --test-load 32 -R "depth_plane|stencil_plane" git status --porcelain ``` | Check | Result | |---|---| | `git diff --check` | clean | | `check_conventions.py` | All conventions checks passed | | Configure / build / `libs` (script) | ok | | Selected tests (script, 2209 run) | no new failures, no timeouts. The 7 known failures also fail on `main` and are unrelated | | Validation layer (script, 773 tests vs `main`) | layer loaded in 772, missing in none; 0 tests with new `VUID-` lines | | `depth_plane\|stencil_plane` (15 tests) | 15/15 passed, all under 6 s | | Worktree after the negative controls | `git status --porcelain` is empty; 15/15 pass again | <details><summary>Negative control output</summary> ``` # A: previous head a82312517b + new tests agc_driver_depth_plane_unmapped_plane ............. Passed agc_driver_depth_plane_partially_unmapped_plane ...***Failed AGC graphics: a read of a plane whose first unit was unmapped and mapped again stored none of its other units agc_driver_depth_plane_unmapped_plane_fill ........***Failed AGC graphics: a read of a plane unmapped and mapped again after a depth fill stored the fill recorded before the unmap # B: main production files + tests agc_driver_stencil_plane_memory ...................***Failed AGC graphics: a read of a stencil plane unmapped and mapped again stored the stencil drawn before the unmap agc_driver_depth_plane_unmapped_plane .............***Failed AGC graphics: a read of a plane unmapped and mapped again stored the results drawn before the unmap agc_driver_depth_plane_partially_unmapped_plane ... Passed agc_driver_depth_plane_unmapped_plane_fill ........***Failed AGC graphics: a read of a plane unmapped and mapped again after a depth fill stored the fill recorded before the unmap ``` </details> `--partially-unmapped-plane` passes on `main`, as expected: `main` stores every unit. The test guards against the whole-plane drop that the previous head introduced, and it fails there. So my run confirms the author's negative control against `a82312517b`. ## Previous findings 1. **A depth fast clear or plane fill pending since before the unmap is stored over the remapped memory: Resolved.** - `MarkAllStale` no longer touches the mark ([`DepthSurface.cpp:1114-1118`](https://github.com/boykopovar/AnyPS5/blob/be898698d1a6d310f010efd72c95ddb5c32920b5/core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp#L1114-L1118)). - The mark is now taken when the clear or fill is recorded ([`DepthSurface.cpp:739-755`](https://github.com/boykopovar/AnyPS5/blob/be898698d1a6d310f010efd72c95ddb5c32920b5/core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp#L739-L755)). - So the `MarkAllStale` expansion in `FlushDepthPlanes` no longer hides the removal ([`DepthSurface.cpp:2825-2835`](https://github.com/boykopovar/AnyPS5/blob/be898698d1a6d310f010efd72c95ddb5c32920b5/core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp#L2825-L2835)). - `agc_driver_depth_plane_unmapped_plane_fill` covers exactly this sequence. It fails at `a82312517b` and passes at this head. 2. **The unmapped list is pruned only in `FlushDepthPlanes`: No longer applies.** This was an observation for future readers, not a requested change. The list is still bounded, because `noteUnmappedPlane` records only ranges that overlap a stale plane. oneandonlydean's partial-unmap point is also addressed for depth: - `unmappedUnits` ([`DepthSurface.cpp:2363-2375`](https://github.com/boykopovar/AnyPS5/blob/be898698d1a6d310f010efd72c95ddb5c32920b5/core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp#L2363-L2375)) marks only the units that a removal newer than the mark overlaps. - `FlushDepthPlanes` clears only those units and stores the rest. `retireStoringStale` does the same ([`DepthSurface.cpp:2474-2480`](https://github.com/boykopovar/AnyPS5/blob/be898698d1a6d310f010efd72c95ddb5c32920b5/core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp#L2474-L2480)). - The unit bounds hold: the loop stops at `count`, and `count` is `staleUnits.size()`. `retireStoringStale` indexes `removed[unit]` only up to that same size. - The stencil plane is still dropped whole on a partial unmap. The debt entry now states this, which the rules allow. ## New findings ### Blocking None. ### Non-blocking None. ## Not verified - The Contra: Operation Galuga (PPSA15368) runs and the RX 6650 XT / RADV results. The Contra runs were at the previous head `a82312517b`, not at this one. I have no GPU here, and the rules forbid launching titles. The author's 59/59 run at `be898698d1` is accepted as author-reported. - After a partial drop, the host image still holds the pre-unmap texels of the dropped units. They are reloaded only if the guest's writes to the new memory are collected; `SyncFromMemory` skips that while a depth clear is pending. A later draw that does not cover those units could then store old texels over the new memory. I did not check whether mapping fresh memory counts as a write in the tracker, and I did not write a test for this case. - Tests ran on lavapipe only. <!-- anyps5-bots job=3385 head=be898698d1a6d310f010efd72c95ddb5c32920b5 -->
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!15466
No description provided.