fix(agc): clear the stencil shadow probe's destination before its copy #25608

Merged
androidbaklava merged 1 commit from upstream-pr/25608 into main 2026-11-27 17:44:44 +00:00
androidbaklava commented 2026-11-22 11:24:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by androidbaklava on 2026-11-22T11:24:30Z.


What

Refs #16883 and #16908. ProbeStencilShadowCopy decides whether a multisampled D32S8 image keeps the shadow-copy path or falls back to direct sampling. It copies a stencil pattern into a freshly allocated shadow image and checks the result, but it never initialises the shadow first. On a driver whose copy drops part of the stencil plane, the bytes the copy misses keep whatever the allocation held before, and an earlier probe's images can hold that same pattern. So the probe passed or failed by chance, and when it passed, the surface took the shadow path that does not keep its samples.

This change clears the shadow image (depth 0.25, stencil 0xa5, a value the pattern never uses) before the copy, with a transfer-to-transfer barrier. A copy that writes the whole stencil plane overwrites the clear, so on hosts whose copy works the probe result and the path do not change.

On Intel UHD Graphics (Raptor Lake, 8086:a7a8, driver 101.7084) on Windows, with logging added locally to the probe: on main the probe answered "copy works" for 4, 7 and 8 of the 18 D32S8 probes (2, 4 and 8 samples) in three runs of agc_driver_native_depth_other_identity, and every case that failed came straight after a probe that said "works" at 4 or 8 samples. With the clear it answered "does not work" for 18 of 18 in each of 3 runs. Forcing the shadow path on (local experiment) failed every 4- and 8-sample case of that test.

Tested

Windows 11 Home 10.0.26300, i7-13620H, Intel UHD Graphics 8086:a7a8 (Raptor Lake) driver 101.7084, Vulkan 1.4.323, WinLibs GCC 15.2.0 r7 UCRT, Release. main 6c70b74203 against this change from the same build tree. ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation and VK_LOADER_DEBUG=layer (Khronos validation 1.4.363).

ctest -R ^agc_driver_native_depth -V (31 tests) main this change
run 1 30 passed, native_depth_other_identity failed 31 passed
run 2 30 passed, native_depth_other_identity failed 31 passed
run 3 30 passed, native_depth_other_identity failed 31 passed
VUID- lines 0 0

Every log shows Insert instance layer "VK_LAYER_KHRONOS_validation", and none shows was not found but was requested. On main the test fails with the last identity over the shared planes did not publish its samples over them at byte 2: the guest planes still hold the first identity's depth samples (0.3125 to 0.5) instead of the second's (0.5625 to 0.75).

agc_driver_native_depth_publication, run alone 30 times without the layer: main failed 3 of 30 (native D32S8 publication lost live samples, HTILE, padding or guest writes), this change 0 of 30.

Full suite on main on the same machine: the other agc failures are the known Intel ones (#20831, #21683, #21713, #21741, #21749, #24072), and the 4,626 non-agc tests pass. Not tested on NVIDIA or AMD. There the copy keeps stencil and overwrites the clear, so the probe should still pass and keep the shadow path.

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: Intel UHD Graphics (Raptor Lake, 8086:a7a8), driver 101.7084, Windows 11
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5438506559 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/25608). Originally posted by [androidbaklava](https://github.com/androidbaklava) on 2026-11-22T11:24:30Z. --- ### What Refs #16883 and #16908. `ProbeStencilShadowCopy` decides whether a multisampled D32S8 image keeps the shadow-copy path or falls back to direct sampling. It copies a stencil pattern into a freshly allocated shadow image and checks the result, but it never initialises the shadow first. On a driver whose copy drops part of the stencil plane, the bytes the copy misses keep whatever the allocation held before, and an earlier probe's images can hold that same pattern. So the probe passed or failed by chance, and when it passed, the surface took the shadow path that does not keep its samples. This change clears the shadow image (depth 0.25, stencil `0xa5`, a value the pattern never uses) before the copy, with a transfer-to-transfer barrier. A copy that writes the whole stencil plane overwrites the clear, so on hosts whose copy works the probe result and the path do not change. On Intel UHD Graphics (Raptor Lake, `8086:a7a8`, driver 101.7084) on Windows, with logging added locally to the probe: on `main` the probe answered "copy works" for 4, 7 and 8 of the 18 D32S8 probes (2, 4 and 8 samples) in three runs of `agc_driver_native_depth_other_identity`, and every case that failed came straight after a probe that said "works" at 4 or 8 samples. With the clear it answered "does not work" for 18 of 18 in each of 3 runs. Forcing the shadow path on (local experiment) failed every 4- and 8-sample case of that test. ### Tested Windows 11 Home 10.0.26300, i7-13620H, Intel UHD Graphics `8086:a7a8` (Raptor Lake) driver 101.7084, Vulkan 1.4.323, WinLibs GCC 15.2.0 r7 UCRT, Release. `main` `6c70b74203` against this change from the same build tree. `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1`, `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation` and `VK_LOADER_DEBUG=layer` (Khronos validation 1.4.363). | `ctest -R ^agc_driver_native_depth -V` (31 tests) | `main` | this change | |---|---|---| | run 1 | 30 passed, `native_depth_other_identity` failed | 31 passed | | run 2 | 30 passed, `native_depth_other_identity` failed | 31 passed | | run 3 | 30 passed, `native_depth_other_identity` failed | 31 passed | | `VUID-` lines | 0 | 0 | Every log shows `Insert instance layer "VK_LAYER_KHRONOS_validation"`, and none shows `was not found but was requested`. On `main` the test fails with `the last identity over the shared planes did not publish its samples over them at byte 2`: the guest planes still hold the first identity's depth samples (0.3125 to 0.5) instead of the second's (0.5625 to 0.75). `agc_driver_native_depth_publication`, run alone 30 times without the layer: `main` failed 3 of 30 (`native D32S8 publication lost live samples, HTILE, padding or guest writes`), this change 0 of 30. Full suite on `main` on the same machine: the other `agc` failures are the known Intel ones (#20831, #21683, #21713, #21741, #21749, #24072), and the 4,626 non-`agc` tests pass. Not tested on NVIDIA or AMD. There the copy keeps stencil and overwrites the clear, so the probe should still pass and keep the shadow path. ### 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) 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: Intel UHD Graphics (Raptor Lake, 8086:a7a8), driver 101.7084, Windows 11 - [x] AI-assisted: yes
MarcZX10 commented 2026-11-22 11:29:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T11:29:09Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; the inspected code supports merging, and the author-reported results are consistent with the fix.

What I ran

Reviewed head 62dc63885c52962fe28801b7070406a2e17d8708 using repo_read.py to read the prepared diff, manifest, description, and both changed files. No tests were run by me; the Windows test results in the description are author-reported.

Results

Check Result Note
Diff and changed files passed Both changed files read
Tests in this review not run Results supplied by author

Findings

Blocking

None.

Non-blocking

None.

Not verified

No tests were run in this review. The author-reported results were not independently verified. Other GPU vendors and console behavior were not tested by the author. Files read: core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp and docs/dev/debt/changes/fix-agc-stencil-shadow-probe-cleared.md. Excluded files: none (files.json was not provided in the prepared review folder).

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6011984581 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/25608#pullrequestreview-6011984581). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-22T11:29:09Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; the inspected code supports merging, and the author-reported results are consistent with the fix. ## What I ran Reviewed head `62dc63885c52962fe28801b7070406a2e17d8708` using `repo_read.py` to read the prepared diff, manifest, description, and both changed files. No tests were run by me; the Windows test results in the description are author-reported. ## Results | Check | Result | Note | |---|---|---| | Diff and changed files | passed | Both changed files read | | Tests in this review | not run | Results supplied by author | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified No tests were run in this review. The author-reported results were not independently verified. Other GPU vendors and console behavior were not tested by the author. Files read: `core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp` and `docs/dev/debt/changes/fix-agc-stencil-shadow-probe-cleared.md`. Excluded files: none (`files.json` was not provided in the prepared review folder). ## 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!25608
No description provided.