fix(agc): sample a stencil kept in HTILE without metadata after an in-place expand #25871

Merged
birdmarty merged 1 commit from upstream-pr/25871 into main 2026-11-24 15:00:44 +00:00
birdmarty commented 2026-11-22 19:38:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by birdmarty on 2026-11-22T19:38:33Z.


What

The stencil plane of a native multisampled D32S8 target was sampled through a descriptor without metadata only when its HTILE held depth alone. With the stencil in HTILE, every such read threw native multisample depth sampled metadata or XOR mismatch. With the stencil in HTILE the plane in memory is compressed until an in-place expand, which is why the read was refused.

Depth reads without metadata are already accepted after an observed in-place expand of depth and, with a stencil plane, stencil (DB_RENDER_CONTROL.DEPTH_COMPRESS_DISABLE and STENCIL_COMPRESS_DISABLE). The stencil read now follows the same rule, until the HTILE clears and fills, plane fills and clear draws that end it. A target the host has never written is a separate case, covered by #25874: its plane in memory is still what was published or imported.

Changes

  • core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp: the stencil branch of CheckResource also accepts a target that is expanded.
  • core/libs/prx/libSceAgcDriver/tests/execution/NativeMultisampleDepth.cpp (run by agc_driver_native_depth_expand_gate for 2, 4 and 8 samples): a target with the stencil in HTILE that the host has written refuses a stencil read without metadata before any expand and after a depth-only expand, accepts it after an expand of depth and stencil, and refuses it again after an HTILE fill.
  • docs/dev/debt/changes/fix-agc-sample-htile-stencil-after-expand.md: the "Native multisample stencil plane sampling" entry.

Tested

Windows 11 Pro (build 26300), Intel Core i9-9900K, AMD Radeon RX 6800 (AMD driver 26.10.1, Windows driver 32.0.21045.16010, Vulkan 1.4.315), MinGW-w64 GCC 15.3.0, Release, main 66668ebb8b.

Focused set (agc_driver_graphics, agc_shader_memory, agc_driver_sample_multisample_target, agc_driver_recorder, agc_driver_cached_image_multisample_guard, agc_driver_cmask_fast_clear, agc_driver_pipelined_metadata_pass*, agc_driver_native_*, agc_driver_fmask_*, agc_driver_msaa_*, agc_driver_multisample*, agc_driver_sampled_cache*, image_msaa*, agc_driver_depth*, agc_driver_htile*, agc_driver_stencil*) with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation (1.4.363) and VK_LOADER_DEBUG=layer:

main 66668ebb8b this change
Passed / failed 149 / 0 149 / 0
Validation layer inserted 189 189
VUID- lines 0 0

Without the fix (main's DepthSurface.cpp with this branch's test), agc_driver_native_depth_expand_gate fails with AGC graphics: native multisample depth sampled metadata or XOR mismatch at the read after the expand of depth and stencil.

Forza Horizon 5 (PPSA22327 01.685.672), local stack of open PRs:

  • What the game does: it reads the stencil plane of its native 4x D32S8 target, whose stencil is in HTILE, through an R8_UINT descriptor without metadata.
  • Without this change: the refusal stopped 5 runs.
  • With this change and #25872: 18 runs, none with it; the same message came back in 5 of them for a different read, the stencil plane right after an HTILE fast clear, fixed by #25874. In that game the target's memory is decompressed by AnyPS5's publication, not by an expand draw, so it needs both.

py -3 tools/check_conventions.py --base origin/main and py -3 tools/debt_fold.py --check pass. py -3 tools/pr_overlap.py --branch fix/agc-sample-htile-stencil-after-expand (2,360 open PRs): #16880 renames the call on the same line (Require to a local require), a textual conflict only. Twenty PRs that conflict with main were searched by hand; #6808 adds an import refusal for this flag combination, and none changes this read.

Not tested: whether the console's reads of the plane through such a descriptor match the host stencil (not measured, as the debt entry says), other GPUs, Linux.

Rebased onto main f220c22162 (394 commits, none touching the files this PR changes, no conflicts). On the rebased commit check_conventions and debt_fold --check pass. All eight PRs merged together on f220c22162, the focused tests of all eight with the same environment: main 182 passed / 0 failed, validation layer inserted 242 times, 0 VUID- lines; the eight together 188 passed / 0 failed (the six new tests added), inserted 250 times, 0 VUID- lines. That combined run first failed this PR's test case: its target had been imported but never drawn, and #25874 reads such a target's stencil plane from memory, by design. The case now writes the target from the host first, which is the case this PR is about. On the amended commit, agc_driver_native_depth_expand_gate, _stencil, _stencil_view, _publication and _publication_without_htile pass with the validation layer (0 VUID- lines), and the test still fails without the fix.

Part of the Forza Horizon 5 (PPSA22327) bring-up, #25152. The game hits these stops one after another, so these PRs were found and tested together on one stack: the other open PRs the game needs (#24960, #24994, #25151, #23688, #23545, #21479, #11825, #23778, #21155, #22306, #21199) plus the PRs below. Each one stands alone: it applies to main by itself, needs none of the others to build or pass its tests, and merges cleanly with every other one.

  • #25867 fix/agc-materialize-cold-native-fmask: cold native FMASK pages read as stored after a first touch
  • #25868 fix/agc-multisample-read-single-sample-depth: multisampled read over a single-sample depth surface
  • #25869 fix/agc-claim-retires-memory-backed-msaa-copy: memory-backed multisampled copy treated as a host-only alias
  • #25870 fix/agc-skip-no-op-htile-hiz-patch: HTILE Hi-Z patch dispatch that writes nothing
  • #25872 fix/agc-expanded-after-whole-depth-publication: a whole native depth publication taken as an expand
  • #25873 fix/agc-htile-clear-supersedes-plane-writes: plane writes before a whole HTILE clear
  • #25874 fix/agc-read-unwritten-htile-stencil-from-memory: stencil plane read from memory for an unwritten native target

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: PPSA22327 #25152 (with #25872)
  • GPUs tested: AMD Radeon RX 6800 (vendor=0x1002, device=0x73bf), AMD proprietary driver 26.10.1 (Windows driver 32.0.21045.16010, Vulkan 1.4.315), Windows 11 Pro (build 26300); Khronos validation layer 1.4.363.0 on main and this change, 0 VUIDs
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5442604049 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/25871). Originally posted by [birdmarty](https://github.com/birdmarty) on 2026-11-22T19:38:33Z. --- ### What The stencil plane of a native multisampled D32S8 target was sampled through a descriptor without metadata only when its HTILE held depth alone. With the stencil in HTILE, every such read threw `native multisample depth sampled metadata or XOR mismatch`. With the stencil in HTILE the plane in memory is compressed until an in-place expand, which is why the read was refused. Depth reads without metadata are already accepted after an observed in-place expand of depth and, with a stencil plane, stencil (`DB_RENDER_CONTROL.DEPTH_COMPRESS_DISABLE` and `STENCIL_COMPRESS_DISABLE`). The stencil read now follows the same rule, until the HTILE clears and fills, plane fills and clear draws that end it. A target the host has never written is a separate case, covered by #25874: its plane in memory is still what was published or imported. #### Changes - `core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp`: the stencil branch of `CheckResource` also accepts a target that is expanded. - `core/libs/prx/libSceAgcDriver/tests/execution/NativeMultisampleDepth.cpp` (run by `agc_driver_native_depth_expand_gate` for 2, 4 and 8 samples): a target with the stencil in HTILE that the host has written refuses a stencil read without metadata before any expand and after a depth-only expand, accepts it after an expand of depth and stencil, and refuses it again after an HTILE fill. - `docs/dev/debt/changes/fix-agc-sample-htile-stencil-after-expand.md`: the "Native multisample stencil plane sampling" entry. ### Tested Windows 11 Pro (build 26300), Intel Core i9-9900K, AMD Radeon RX 6800 (AMD driver 26.10.1, Windows driver 32.0.21045.16010, Vulkan 1.4.315), MinGW-w64 GCC 15.3.0, Release, `main` 66668ebb8b. Focused set (`agc_driver_graphics`, `agc_shader_memory`, `agc_driver_sample_multisample_target`, `agc_driver_recorder`, `agc_driver_cached_image_multisample_guard`, `agc_driver_cmask_fast_clear`, `agc_driver_pipelined_metadata_pass*`, `agc_driver_native_*`, `agc_driver_fmask_*`, `agc_driver_msaa_*`, `agc_driver_multisample*`, `agc_driver_sampled_cache*`, `image_msaa*`, `agc_driver_depth*`, `agc_driver_htile*`, `agc_driver_stencil*`) with `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1`, `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation` (1.4.363) and `VK_LOADER_DEBUG=layer`: | | `main` 66668ebb8b | this change | |---|---|---| | Passed / failed | 149 / 0 | 149 / 0 | | Validation layer inserted | 189 | 189 | | `VUID-` lines | 0 | 0 | Without the fix (`main`'s `DepthSurface.cpp` with this branch's test), `agc_driver_native_depth_expand_gate` fails with `AGC graphics: native multisample depth sampled metadata or XOR mismatch` at the read after the expand of depth and stencil. Forza Horizon 5 (PPSA22327 01.685.672), local stack of open PRs: - **What the game does:** it reads the stencil plane of its native 4x D32S8 target, whose stencil is in HTILE, through an R8_UINT descriptor without metadata. - **Without this change:** the refusal stopped 5 runs. - **With this change and #25872:** 18 runs, none with it; the same message came back in 5 of them for a different read, the stencil plane right after an HTILE fast clear, fixed by #25874. In that game the target's memory is decompressed by AnyPS5's publication, not by an expand draw, so it needs both. `py -3 tools/check_conventions.py --base origin/main` and `py -3 tools/debt_fold.py --check` pass. `py -3 tools/pr_overlap.py --branch fix/agc-sample-htile-stencil-after-expand` (2,360 open PRs): #16880 renames the call on the same line (`Require` to a local `require`), a textual conflict only. Twenty PRs that conflict with `main` were searched by hand; #6808 adds an import refusal for this flag combination, and none changes this read. Not tested: whether the console's reads of the plane through such a descriptor match the host stencil (not measured, as the debt entry says), other GPUs, Linux. Rebased onto `main` f220c22162 (394 commits, none touching the files this PR changes, no conflicts). On the rebased commit `check_conventions` and `debt_fold --check` pass. All eight PRs merged together on f220c22162, the focused tests of all eight with the same environment: `main` 182 passed / 0 failed, validation layer inserted 242 times, 0 `VUID-` lines; the eight together 188 passed / 0 failed (the six new tests added), inserted 250 times, 0 `VUID-` lines. That combined run first failed this PR's test case: its target had been imported but never drawn, and #25874 reads such a target's stencil plane from memory, by design. The case now writes the target from the host first, which is the case this PR is about. On the amended commit, `agc_driver_native_depth_expand_gate`, `_stencil`, `_stencil_view`, `_publication` and `_publication_without_htile` pass with the validation layer (0 `VUID-` lines), and the test still fails without the fix. ### Related Part of the Forza Horizon 5 (PPSA22327) bring-up, #25152. The game hits these stops one after another, so these PRs were found and tested together on one stack: the other open PRs the game needs (#24960, #24994, #25151, #23688, #23545, #21479, #11825, #23778, #21155, #22306, #21199) plus the PRs below. Each one stands alone: it applies to `main` by itself, needs none of the others to build or pass its tests, and merges cleanly with every other one. - #25867 `fix/agc-materialize-cold-native-fmask`: cold native FMASK pages read as stored after a first touch - #25868 `fix/agc-multisample-read-single-sample-depth`: multisampled read over a single-sample depth surface - #25869 `fix/agc-claim-retires-memory-backed-msaa-copy`: memory-backed multisampled copy treated as a host-only alias - #25870 `fix/agc-skip-no-op-htile-hiz-patch`: HTILE Hi-Z patch dispatch that writes nothing - #25872 `fix/agc-expanded-after-whole-depth-publication`: a whole native depth publication taken as an expand - #25873 `fix/agc-htile-clear-supersedes-plane-writes`: plane writes before a whole HTILE clear - #25874 `fix/agc-read-unwritten-htile-stencil-from-memory`: stencil plane read from memory for an unwritten native target ### 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: PPSA22327 #25152 (with #25872) - [x] GPUs tested: AMD Radeon RX 6800 (vendor=0x1002, device=0x73bf), AMD proprietary driver 26.10.1 (Windows driver 32.0.21045.16010, Vulkan 1.4.315), Windows 11 Pro (build 26300); Khronos validation layer 1.4.363.0 on `main` and this change, 0 VUIDs - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-11-22 19:57:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T19:57:22Z.

Review: APPROVED


Reviewed — looks good

The change is consistent with the existing expand-state tracking and adds a focused regression case; I found no verified blocking defect.

What I ran

Reviewed head e87f7644a7c8447d0f1cfae726a6f8ff1c63da84. I read the prepared description, commits, manifest, diff, and all three changed files. I did not run tests or builds; repo_read.py was unavailable as a shell command in this review environment.

Results

Check Result Note
Changed code review passed All three changed files read
Tests and build not run No shell access

Findings

Blocking

None.

Non-blocking

None.

Not verified

I did not independently verify the author-reported test results, console behavior, other GPUs, or Linux. The review manifest lists three changed files, all included and read; files.json was not available as a review document.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6014173238 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/25871#pullrequestreview-6014173238). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-22T19:57:22Z. **Review:** APPROVED --- # Reviewed — looks good The change is consistent with the existing expand-state tracking and adds a focused regression case; I found no verified blocking defect. ## What I ran Reviewed head `e87f7644a7c8447d0f1cfae726a6f8ff1c63da84`. I read the prepared description, commits, manifest, diff, and all three changed files. I did not run tests or builds; `repo_read.py` was unavailable as a shell command in this review environment. ## Results | Check | Result | Note | |---|---|---| | Changed code review | passed | All three changed files read | | Tests and build | not run | No shell access | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified I did not independently verify the author-reported test results, console behavior, other GPUs, or Linux. The review manifest lists three changed files, all included and read; `files.json` was not available as a review document. ## To get this to a good state Nothing is required.
mihiii1337 commented 2026-11-22 21:08:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by mihiii1337 on 2026-11-22T21:08:03Z.

Review: APPROVED


Verified exact head e87f7644a7c8447d0f1cfae726a6f8ff1c63da84 against its direct parent production code on the RTX 4070 Laptop.

The head passed 3/3. Every run reached the new Native stencil in HTILE expand gate marker for 2x, 4x, and 8x, after checking refusal before expansion, continued refusal after depth-only expansion, successful routing after combined depth/stencil expansion, cache identity, and refusal again after the HTILE fill.

With only DepthSurface.cpp restored from direct parent f220c221625695bcd12615476d385a8977532aa3, the byte-identical test executable failed 3/3 with the expected native multisample depth sampled metadata or XOR mismatch before any new stencil marker.

All six invocations selected the RTX 4070 Laptop (10de:2860, NVIDIA 621.01), reported pipeline libraries enabled, and inserted Khronos Validation 1.4.369. There were no skips, missing-layer messages, device losses, VUIDs, or synchronization diagnostics. Runtime artifact hashes were unchanged.

This verifies the routing and cache behavior for the exercised D32S8 expand gate. It does not read stencil texel values or establish console expand equivalence.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6014539906 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/25871#pullrequestreview-6014539906). Originally posted by [mihiii1337](https://github.com/mihiii1337) on 2026-11-22T21:08:03Z. **Review:** APPROVED --- Verified exact head `e87f7644a7c8447d0f1cfae726a6f8ff1c63da84` against its direct parent production code on the RTX 4070 Laptop. The head passed 3/3. Every run reached the new `Native stencil in HTILE expand gate` marker for 2x, 4x, and 8x, after checking refusal before expansion, continued refusal after depth-only expansion, successful routing after combined depth/stencil expansion, cache identity, and refusal again after the HTILE fill. With only `DepthSurface.cpp` restored from direct parent `f220c221625695bcd12615476d385a8977532aa3`, the byte-identical test executable failed 3/3 with the expected `native multisample depth sampled metadata or XOR mismatch` before any new stencil marker. All six invocations selected the RTX 4070 Laptop (`10de:2860`, NVIDIA 621.01), reported pipeline libraries enabled, and inserted Khronos Validation 1.4.369. There were no skips, missing-layer messages, device losses, VUIDs, or synchronization diagnostics. Runtime artifact hashes were unchanged. This verifies the routing and cache behavior for the exercised D32S8 expand gate. It does not read stencil texel values or establish console expand equivalence. AI-assisted: yes.
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!25871
No description provided.