AGC: cached depth surfaces miss CPU edits after direct memory becomes compared shared #10797

Open
opened 2026-10-25 01:40:14 +00:00 by lgqdaxia · 0 comments
lgqdaxia commented 2026-10-25 01:40:14 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by lgqdaxia on 2026-10-25T01:40:14Z.


What happens

After Windows direct memory becomes shared and uses byte comparisons instead of continuous write watching, later CPU edits can be missed by a cached depth surface. A draw then uses old depth values.

This reproduces the existing depth-surfaces-over-compared-shared-memory debt entry. I found it while following up on #10746 and have a tested candidate fix.

Title, test or build step

Synthetic Vulkan regression: agc_driver_depth_compared_shared. No game or homebrew run.

The test source uses a 256x128 D32 depth plane containing two 64 KiB units. It establishes GPU depth 0.5, shares the backing, consumes the initial sharing report, then writes 0.75 into the left unit on the CPU. A subsequent LESS test at 0.5 should cover the left 16384 pixels and preserve the right unit's pending GPU results. The old runtime covers zero pixels.

The sharing step follows the existing unpin, map and registration sequence, retiring the original resident host import before its private backing becomes shared.

AnyPS5 commit

  • Candidate: e3e3cdd1b0002300567bf8011f49500ad0e5c266, based on main bd8e13428a10d9332c2911816ab672ea1b41418f.
  • Red control: a retained AGC DLL built at local commit 7e32da99051c7c6baad3b691a25c96da4ad07d29, whose parent is main cf528e78c6c8fd30696ccfca6c097f9828be2cf6. That local commit changes only tests/Recorder.cpp. Production AGC and shader sources are unchanged between that main revision and bd8e13428a.
  • The final comparison uses the same test EXE with the old or fixed AGC DLL and the same rebuilt dependencies. The old DLL is placed beside the baseline EXE to make its selection explicit. This red control reuses the earlier DLL; it is not a fresh clean build of main bd8e13428a.

System

Windows 11 Pro 10.0.26200; NVIDIA GeForce RTX 3080 Laptop GPU, driver 610.74; WinLibs GCC 15.2.0 r7; Release.

Steps to reproduce

In a separate Windows checkout of main bd8e13428a10d9332c2911816ab672ea1b41418f, with the toolchain from BUILD and the Khronos validation layer available, fetch the candidate and copy only its test source:

git fetch https://github.com/lgqdaxia/AnyPS5.git codex/fix-compared-shared-depth-refresh
git restore --source=e3e3cdd1b0002300567bf8011f49500ad0e5c266 --worktree -- core/libs/prx/libSceAgcDriver/tests/execution/DepthComparedShared.cpp
git submodule update --init --recursive
cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON -DANYPS5_AGC_EXECUTION_TESTS=DepthComparedShared
cmake --build build --target libs agc_driver_depth_compared_shared_tests --parallel 4

$env:ANYPS5_REQUIRE_VULKAN='1'
$env:ANYPS5_NO_SHADER_CACHE='1'
$env:VK_INSTANCE_LAYERS='VK_LAYER_KHRONOS_validation'
$env:ANYPS5_GPU='RTX 3080'
ctest --test-dir build -R '^agc_driver_depth_compared_shared$' -V --timeout 30

Set VK_LAYER_PATH to the installed validation layer directory if the Vulkan loader needs it, and select the available GPU. CMake discovers the added test automatically; no production fix or CMake change is needed for the red reproduction.

Run the same test in a checkout of the candidate for the green comparison. The measured test runs take about 0.5 seconds on the GPU above.

Log

Old runtime:

resident private depth: a same-value CPU store reloads the left unit covered 16384 pixels
late-shared compared depth: the first alias write after sharing reloads the left unit covered 16384 pixels
late-shared compared depth: an unchanged bind preserves pending depth 0.5 covered 0 pixels
late-shared compared depth: another unchanged epoch preserves pending depth 0.5 covered 0 pixels
AGC graphics: late-shared compared depth: a CPU write reloads only the left unit covered 0 pixels, expected 16384
agc_driver_depth_compared_shared ... Failed (0.52 sec)

Candidate:

late-shared compared depth: a CPU write reloads only the left unit covered 16384 pixels
late-shared compared depth: a second CPU write through the alias reloads the left unit covered 0 pixels
late-shared compared depth: a CPU write through the alias reloads the right unit covered 16384 pixels
late-shared compared depth: an unchanged bind after write-back preserves a newer GPU clear covered 32768 pixels
owner switch: an alias CPU write after owner inheritance reloads only the right unit covered 16384 pixels
agc_driver_depth_compared_shared ... Passed (0.53 sec)

The excerpts omit CTest line prefixes. Both logs confirm that VK_LAYER_KHRONOS_validation was inserted and contain zero VUID- errors and no missing-layer warning.

What was checked

  • The private-memory control, same-value CPU stores while tracked, the first alias write after sharing, repeated CPU/alias edits, unchanged epochs, partial depth write-back and depth-owner switches through an HTILE clear.
  • The same nine existing focused CTests pass with both runtimes: windows_write_watch, agc_rewatched_direct_shared, agc_import_alias_shared, agc_compared_shared_generations, agc_driver_depth_fast_clear, agc_driver_depth_plane_buffer_memory, agc_driver_depth_surface_from_storage, agc_driver_compared_shared_snapshot, and agc_driver_depth_plane_partial_store_unimported.
  • All 12 GPU executions in those final baseline/candidate comparisons load the Khronos validation layer, with zero VUID errors. The four CPU-only tests on each side do not initialize Vulkan.
  • Disabling only the candidate's write-back baseline notification makes the newer-GPU-clear check fail with 16384 pixels instead of 32768. This checks that the fix preserves GPU results after write-back.
  • Full libs and relinker builds and conventions pass for the candidate.

Proposed fix and status

The public fix branch keeps a guest-byte baseline, compares units when write collection is unavailable, and refreshes the units that changed. Actual GPU write-back bytes update the baseline after completion, so a later bind can retain newer GPU results.

The host-import fixture question remains in #10746/#10785. This report tracks the separate depth-cache defect. I plan to submit the candidate PR once the current contribution slot becomes available.

Limits: tested only on the Windows/NVIDIA configuration above. No game, other GPU vendor, Linux, macOS, performance improvement or title unblock is claimed. Outside the write watch, same-value CPU stores remain unobservable; CPU and GPU changes within one tracking unit are not merged.

AI-assisted: Codex assisted with the investigation, implementation, tests and this report. The results above are from local execution.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:6019690482 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/10797). Originally posted by [lgqdaxia](https://github.com/lgqdaxia) on 2026-10-25T01:40:14Z. --- ### What happens After Windows direct memory becomes shared and uses byte comparisons instead of continuous write watching, later CPU edits can be missed by a cached depth surface. A draw then uses old depth values. This reproduces the existing [depth-surfaces-over-compared-shared-memory debt entry](https://github.com/boykopovar/AnyPS5/blob/bd8e13428a10d9332c2911816ab672ea1b41418f/docs/dev/debt/libSceAgcDriver.md#L96). I found it while following up on #10746 and have a tested candidate fix. ### Title, test or build step Synthetic Vulkan regression: `agc_driver_depth_compared_shared`. No game or homebrew run. The [test source](https://github.com/lgqdaxia/AnyPS5/blob/e3e3cdd1b0002300567bf8011f49500ad0e5c266/core/libs/prx/libSceAgcDriver/tests/execution/DepthComparedShared.cpp) uses a 256x128 D32 depth plane containing two 64 KiB units. It establishes GPU depth 0.5, shares the backing, consumes the initial sharing report, then writes 0.75 into the left unit on the CPU. A subsequent LESS test at 0.5 should cover the left 16384 pixels and preserve the right unit's pending GPU results. The old runtime covers zero pixels. The sharing step follows the existing unpin, map and registration sequence, retiring the original resident host import before its private backing becomes shared. ### AnyPS5 commit - Candidate: [`e3e3cdd1b0002300567bf8011f49500ad0e5c266`](https://github.com/lgqdaxia/AnyPS5/commit/e3e3cdd1b0002300567bf8011f49500ad0e5c266), based on main `bd8e13428a10d9332c2911816ab672ea1b41418f`. - Red control: a retained AGC DLL built at local commit `7e32da99051c7c6baad3b691a25c96da4ad07d29`, whose parent is main `cf528e78c6c8fd30696ccfca6c097f9828be2cf6`. That local commit changes only `tests/Recorder.cpp`. Production AGC and shader sources are unchanged between that main revision and `bd8e13428a`. - The final comparison uses the same test EXE with the old or fixed AGC DLL and the same rebuilt dependencies. The old DLL is placed beside the baseline EXE to make its selection explicit. This red control reuses the earlier DLL; it is not a fresh clean build of main `bd8e13428a`. ### System Windows 11 Pro 10.0.26200; NVIDIA GeForce RTX 3080 Laptop GPU, driver 610.74; WinLibs GCC 15.2.0 r7; Release. ### Steps to reproduce In a separate Windows checkout of main `bd8e13428a10d9332c2911816ab672ea1b41418f`, with the toolchain from BUILD and the Khronos validation layer available, fetch the candidate and copy **only its test source**: ```powershell git fetch https://github.com/lgqdaxia/AnyPS5.git codex/fix-compared-shared-depth-refresh git restore --source=e3e3cdd1b0002300567bf8011f49500ad0e5c266 --worktree -- core/libs/prx/libSceAgcDriver/tests/execution/DepthComparedShared.cpp git submodule update --init --recursive cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON -DANYPS5_AGC_EXECUTION_TESTS=DepthComparedShared cmake --build build --target libs agc_driver_depth_compared_shared_tests --parallel 4 $env:ANYPS5_REQUIRE_VULKAN='1' $env:ANYPS5_NO_SHADER_CACHE='1' $env:VK_INSTANCE_LAYERS='VK_LAYER_KHRONOS_validation' $env:ANYPS5_GPU='RTX 3080' ctest --test-dir build -R '^agc_driver_depth_compared_shared$' -V --timeout 30 ``` Set `VK_LAYER_PATH` to the installed validation layer directory if the Vulkan loader needs it, and select the available GPU. CMake discovers the added test automatically; no production fix or CMake change is needed for the red reproduction. Run the same test in a checkout of the candidate for the green comparison. The measured test runs take about 0.5 seconds on the GPU above. ### Log Old runtime: ```text resident private depth: a same-value CPU store reloads the left unit covered 16384 pixels late-shared compared depth: the first alias write after sharing reloads the left unit covered 16384 pixels late-shared compared depth: an unchanged bind preserves pending depth 0.5 covered 0 pixels late-shared compared depth: another unchanged epoch preserves pending depth 0.5 covered 0 pixels AGC graphics: late-shared compared depth: a CPU write reloads only the left unit covered 0 pixels, expected 16384 agc_driver_depth_compared_shared ... Failed (0.52 sec) ``` Candidate: ```text late-shared compared depth: a CPU write reloads only the left unit covered 16384 pixels late-shared compared depth: a second CPU write through the alias reloads the left unit covered 0 pixels late-shared compared depth: a CPU write through the alias reloads the right unit covered 16384 pixels late-shared compared depth: an unchanged bind after write-back preserves a newer GPU clear covered 32768 pixels owner switch: an alias CPU write after owner inheritance reloads only the right unit covered 16384 pixels agc_driver_depth_compared_shared ... Passed (0.53 sec) ``` The excerpts omit CTest line prefixes. Both logs confirm that `VK_LAYER_KHRONOS_validation` was inserted and contain zero `VUID-` errors and no missing-layer warning. ### What was checked - The private-memory control, same-value CPU stores while tracked, the first alias write after sharing, repeated CPU/alias edits, unchanged epochs, partial depth write-back and depth-owner switches through an HTILE clear. - The same nine existing focused CTests pass with both runtimes: `windows_write_watch`, `agc_rewatched_direct_shared`, `agc_import_alias_shared`, `agc_compared_shared_generations`, `agc_driver_depth_fast_clear`, `agc_driver_depth_plane_buffer_memory`, `agc_driver_depth_surface_from_storage`, `agc_driver_compared_shared_snapshot`, and `agc_driver_depth_plane_partial_store_unimported`. - All 12 GPU executions in those final baseline/candidate comparisons load the Khronos validation layer, with zero VUID errors. The four CPU-only tests on each side do not initialize Vulkan. - Disabling only the candidate's write-back baseline notification makes the newer-GPU-clear check fail with 16384 pixels instead of 32768. This checks that the fix preserves GPU results after write-back. - Full `libs` and `relinker` builds and conventions pass for the candidate. ### Proposed fix and status The [public fix branch](https://github.com/lgqdaxia/AnyPS5/tree/codex/fix-compared-shared-depth-refresh) keeps a guest-byte baseline, compares units when write collection is unavailable, and refreshes the units that changed. Actual GPU write-back bytes update the baseline after completion, so a later bind can retain newer GPU results. The host-import fixture question remains in #10746/#10785. This report tracks the separate depth-cache defect. I plan to submit the candidate PR once the current contribution slot becomes available. Limits: tested only on the Windows/NVIDIA configuration above. No game, other GPU vendor, Linux, macOS, performance improvement or title unblock is claimed. Outside the write watch, same-value CPU stores remain unobservable; CPU and GPU changes within one tracking unit are not merged. AI-assisted: Codex assisted with the investigation, implementation, tests and this report. The results above are from local execution. <!-- compared-shared-depth-e3e3cdd1b0 -->
Sign in to join this conversation.
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#10797
No description provided.