fix(agc): discard a new depth surface's depth before taking storage writes #10681

Merged
PYTHONRETARDE merged 1 commit from upstream-pr/10681 into main 2026-10-26 08:29:53 +00:00
PYTHONRETARDE commented 2026-10-24 17:31:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PYTHONRETARDE on 2026-10-24T17:31:36Z.


What

DepthSurface::TakeStorage copied the storage image into a new single-sample depth surface in GENERAL, right after the surface's creation clear. On an RX 7800 XT one or two 8x8 blocks of a D16 surface then tested as the clear value in about 1 of 12 runs of agc_driver_depth_surface_from_storage (#6630). A copy of the depth image back to a buffer read the copied values in every row, so the stale data is in the depth test's view of the surface (likely its HTILE state from the clear), not in its texels.

Without a stencil plane the depth aspect now goes UNDEFINED to TRANSFER_DST_OPTIMAL before the copy and back to GENERAL after it, so the clear's state is discarded before the copy writes every texel. A surface with a stencil plane keeps the previous path, since its depth aspect is not discarded alone. The behaviour is recorded in docs/dev/debt/libSceAgcDriver.md.

Tested

Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, RX 7800 XT, AMD driver 32.0.31041.1004. %LOCALAPPDATA%\AMD\VkCache cleared before each set.

agc_driver_depth_surface_from_storage, run repeatedly:

Build Failed runs
main 29f539a5f 0/60, 16/200
this PR, d84a94e6d on 29f539a5f 0/100, 0/200
earlier: main bfb080619 4/60, 3/60, 6/60, 5/60
earlier: main bfb080619 with the creation clear skipped (diagnostic only) 0/150
earlier: this change on 5d251e6b0 and 6cd36e651 0/150, 0/200, 0/100

The failing runs on main all report a new D16 depth surface over a pending R16 unorm storage write: 79 pixels passed, expected 15.

Validation: ctest --test-dir build -R "depth|stencil" -V (42 tests) on main 29f539a5f and on this PR d84a94e6d, with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation (Vulkan SDK 1.4.363.0). Neither log contains was not found but was requested by env var VK_INSTANCE_LAYERS, and neither contains a VUID- error.

Failures this PR does not change, seen in both validation runs:

  • agc_driver_depth_clear_hle: 16-bit plane, mode 0: after a clear to 0.0 the depth test 0.5 > 0.0 did not pass everywhere. It fails in about 1 of 4 runs on main on this GPU.
  • agc_driver_depth_plane_partial_store: repeated lookups of the first layer of an unchanged array proved no refresh.

git diff --check upstream/main HEAD, tools/check_conventions.py --base upstream/main and git merge-tree --write-tree upstream/main HEAD pass.

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: Fixes #6630
  • Unblocks: none
  • GPUs tested: AMD Radeon RX 7800 XT (1002:747e), driver 32.0.31041.1004, Windows 11 Pro 26200
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4997574610 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10681). Originally posted by [PYTHONRETARDE](https://github.com/PYTHONRETARDE) on 2026-10-24T17:31:36Z. --- ### What `DepthSurface::TakeStorage` copied the storage image into a new single-sample depth surface in `GENERAL`, right after the surface's creation clear. On an RX 7800 XT one or two 8x8 blocks of a D16 surface then tested as the clear value in about 1 of 12 runs of `agc_driver_depth_surface_from_storage` (#6630). A copy of the depth image back to a buffer read the copied values in every row, so the stale data is in the depth test's view of the surface (likely its HTILE state from the clear), not in its texels. Without a stencil plane the depth aspect now goes `UNDEFINED` to `TRANSFER_DST_OPTIMAL` before the copy and back to `GENERAL` after it, so the clear's state is discarded before the copy writes every texel. A surface with a stencil plane keeps the previous path, since its depth aspect is not discarded alone. The behaviour is recorded in `docs/dev/debt/libSceAgcDriver.md`. ### Tested Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, RX 7800 XT, AMD driver 32.0.31041.1004. `%LOCALAPPDATA%\AMD\VkCache` cleared before each set. `agc_driver_depth_surface_from_storage`, run repeatedly: | Build | Failed runs | |---|---| | `main` 29f539a5f | 0/60, 16/200 | | this PR, d84a94e6d on 29f539a5f | 0/100, 0/200 | | earlier: `main` bfb080619 | 4/60, 3/60, 6/60, 5/60 | | earlier: `main` bfb080619 with the creation clear skipped (diagnostic only) | 0/150 | | earlier: this change on 5d251e6b0 and 6cd36e651 | 0/150, 0/200, 0/100 | The failing runs on `main` all report `a new D16 depth surface over a pending R16 unorm storage write: 79 pixels passed, expected 15`. Validation: `ctest --test-dir build -R "depth|stencil" -V` (42 tests) on `main` 29f539a5f and on this PR d84a94e6d, with `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1`, `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation` (Vulkan SDK 1.4.363.0). Neither log contains `was not found but was requested by env var VK_INSTANCE_LAYERS`, and neither contains a `VUID-` error. Failures this PR does not change, seen in both validation runs: - `agc_driver_depth_clear_hle`: `16-bit plane, mode 0: after a clear to 0.0 the depth test 0.5 > 0.0 did not pass everywhere`. It fails in about 1 of 4 runs on `main` on this GPU. - `agc_driver_depth_plane_partial_store`: `repeated lookups of the first layer of an unchanged array proved no refresh`. `git diff --check upstream/main HEAD`, `tools/check_conventions.py --base upstream/main` and `git merge-tree --write-tree upstream/main HEAD` pass. ### 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: Fixes #6630 - [x] Unblocks: none - [x] GPUs tested: AMD Radeon RX 7800 XT (1002:747e), driver 32.0.31041.1004, Windows 11 Pro 26200 - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-10-24 17:37:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T17:37:37Z.

Review: CHANGES_REQUESTED


Reviewed head b529785d491d962222b0cabf302eb833d0336898 against current main (d0e7fe7bebcb20325d8fd707451afec7d40a57cb). The reported RX 7800 XT reproduction and the paired validation logs are useful, and the described transition discards the pre-clear depth contents before the replacement copy. I cannot approve yet because the validation baseline in the report is 6cd36e651, while current main has since changed DepthSurface.cpp substantially (including the depth sampling/copy-source path). This makes the posted 40-test comparison stale for the current PR base, even though the PR still merges cleanly. Please rerun the same focused depth/stencil validation set on current main and this exact PR head on the same machine/GPU, with VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, ANYPS5_NO_SHADER_CACHE=1, and ANYPS5_REQUIRE_VULKAN=1; include the exact tested commits and confirm the layer loaded and whether the VUID set changes. git diff --check, the current-main conventions check, and the merge-tree check pass. Hosted product build jobs are skipped for this PR. I could not execute AGC tests locally: this runner’s Xeon E5-1620 v2 lacks the AVX2/BMI/LZCNT/FMA extensions the test harness requires.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5639178701 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10681#pullrequestreview-5639178701). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-24T17:37:37Z. **Review:** CHANGES_REQUESTED --- Reviewed head `b529785d491d962222b0cabf302eb833d0336898` against current `main` (`d0e7fe7bebcb20325d8fd707451afec7d40a57cb`). The reported RX 7800 XT reproduction and the paired validation logs are useful, and the described transition discards the pre-clear depth contents before the replacement copy. I cannot approve yet because the validation baseline in the report is `6cd36e651`, while current `main` has since changed `DepthSurface.cpp` substantially (including the depth sampling/copy-source path). This makes the posted 40-test comparison stale for the current PR base, even though the PR still merges cleanly. Please rerun the same focused depth/stencil validation set on current `main` and this exact PR head on the same machine/GPU, with `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`, `ANYPS5_NO_SHADER_CACHE=1`, and `ANYPS5_REQUIRE_VULKAN=1`; include the exact tested commits and confirm the layer loaded and whether the VUID set changes. `git diff --check`, the current-main conventions check, and the merge-tree check pass. Hosted product build jobs are skipped for this PR. I could not execute AGC tests locally: this runner’s Xeon E5-1620 v2 lacks the AVX2/BMI/LZCNT/FMA extensions the test harness requires.
MarcZX10 commented 2026-10-24 19:28:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T19:28:35Z.

Review: APPROVED


Reviewed exact head d84a94e6d2833dcf0a1906be30fd377c79e703d4. For depth-only targets, the change inserts an execution-ordered discard transition to TRANSFER_DST_OPTIMAL, copies the full depth range, then transitions to GENERAL with transfer-write visibility; targets with stencil retain the combined-layout path. Barrier accounting is updated for the extra barrier. The author reports paired main/change validation runs on an RX 7800 XT with the Khronos layer confirmed and no VUIDs, plus 300 change runs with no reproduced stale-clear blocks; known unrelated depth failures are disclosed. Local diff-check and conventions pass; I did not run the Vulkan test here. Hosted product jobs are skipped by policy, and the PR is mergeable.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5639612544 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10681#pullrequestreview-5639612544). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-24T19:28:35Z. **Review:** APPROVED --- Reviewed exact head `d84a94e6d2833dcf0a1906be30fd377c79e703d4`. For depth-only targets, the change inserts an execution-ordered discard transition to `TRANSFER_DST_OPTIMAL`, copies the full depth range, then transitions to `GENERAL` with transfer-write visibility; targets with stencil retain the combined-layout path. Barrier accounting is updated for the extra barrier. The author reports paired main/change validation runs on an RX 7800 XT with the Khronos layer confirmed and no VUIDs, plus 300 change runs with no reproduced stale-clear blocks; known unrelated depth failures are disclosed. Local diff-check and conventions pass; I did not run the Vulkan test here. Hosted product jobs are skipped by policy, and the PR is mergeable.
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!10681
No description provided.