fix(agc): read a single-sample depth surface's memory through a multisampled descriptor #25868

Merged
birdmarty merged 1 commit from upstream-pr/25868 into main 2026-11-23 08:27:42 +00:00
birdmarty commented 2026-11-22 19:38:24 +00:00 (Migrated from github.com)

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


What

A multisampled texture or storage descriptor over the memory of a resident single-sample depth surface threw multisample reader overlaps a single-sample depth attachment. Only a native multisampled depth surface could serve a multisampled reader. The GPU reads the bytes in memory, so the reader now takes the guest-memory path, the same path it takes when no depth surface is there.

That path built its copy from memory without storing depth planes that are newer on the host first. Texture imports already store them (Texture.cpp). MultisampleTargetTexture, MultisampleTargetFirstSample and MultisampleTargetStorageView now store them before they read memory or reuse a cached copy, so a read after the depth surface is drawn again sees the new depth.

Changes

  • core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp: DepthSurfaceTexture returns no texture for a multisampled reader over a single-sample depth surface instead of throwing.
  • core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cpp: the multisampled sampling, first-sample and storage paths store stale depth planes under the descriptor first.
  • core/libs/prx/libSceAgcDriver/tests/execution/SampleMultisampleTarget.cpp, tests/cmake/agc_driver_sample_multisample_target_tests.cmake: agc_driver_multisample_read_single_sample_depth. A single-sample 128x128 D32 surface is drawn at depth 0.25 and read through a 4-sample 16x16 R32 descriptor over the same 64 KiB: every sample reads 0.25. It is drawn again at 0.75 and read again: every sample reads 0.75.

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_native_fmask_*, agc_driver_fmask_*, agc_driver_msaa_*, agc_driver_multisample*, agc_driver_native_multisample*, agc_driver_native_color*, agc_driver_native_msaa*, 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 118 / 0 119 / 0 (adds agc_driver_multisample_read_single_sample_depth)
Validation layer inserted 128 129
VUID- lines 0 0

Without the fix (main's DepthSurface.cpp and MultisampleTarget.cpp with this branch's test), the new test fails with AGC graphics: multisample reader overlaps a single-sample depth attachment. With only the DepthSurface.cpp part, it reads the stale memory: ...did not read the depth it published after the first draw: 0.000000.

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

  • What the game does: it binds a 3840x2160 D32 depth target with HTILE as single-sample (depth writes on). A compute shader then reads the same address through a 4-sample R32 descriptor without HTILE. A diagnostic showed the surface live, no multisampled color target there, and every HTILE tile expanded.
  • Without this change: that read stopped 8 of 12 runs at about 128 s.
  • With this exact commit added: 27 runs, none with the refusal.

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-multisample-read-single-sample-depth (2,364 open PRs): #16880 changes the line next to this one in DepthSurfaceTexture, for the opposite case (a single-sample reader over native multisampled depth). Twenty-three PRs that conflict with main were searched by hand; none changes this path.

Not tested: a first-sample read through a 2D image over a single-sample depth surface (it still refuses, now with "reading sample 0 of a multisampled depth surface whose depth plane is not at the descriptor's address is not implemented"), other GPUs, Linux, console behaviour.

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.

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. This PR depends on #25869 on drivers whose host imports keep write protection (such as Linux NVIDIA): without #25869, ClaimMultisampleTargetMemory leaves the memory-backed multisampled copy registered when the single-sample depth surface is bound again, and the GPU-direct flush path does not trigger the CPU read guard that happened to retire it on Windows. The two PRs merge cleanly with no conflicts.

  • #25867 fix/agc-materialize-cold-native-fmask: cold native FMASK pages read as stored after a first touch
  • #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
  • #25871 fix/agc-sample-htile-stencil-after-expand: stencil kept in HTILE read without metadata after an expand
  • #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: #25869
  • Fixes: none
  • Unblocks: PPSA22327 #25152
  • 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:5442602771 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/25868). Originally posted by [birdmarty](https://github.com/birdmarty) on 2026-11-22T19:38:24Z. --- ### What A multisampled texture or storage descriptor over the memory of a resident single-sample depth surface threw `multisample reader overlaps a single-sample depth attachment`. Only a native multisampled depth surface could serve a multisampled reader. The GPU reads the bytes in memory, so the reader now takes the guest-memory path, the same path it takes when no depth surface is there. That path built its copy from memory without storing depth planes that are newer on the host first. Texture imports already store them (`Texture.cpp`). `MultisampleTargetTexture`, `MultisampleTargetFirstSample` and `MultisampleTargetStorageView` now store them before they read memory or reuse a cached copy, so a read after the depth surface is drawn again sees the new depth. #### Changes - `core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp`: `DepthSurfaceTexture` returns no texture for a multisampled reader over a single-sample depth surface instead of throwing. - `core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cpp`: the multisampled sampling, first-sample and storage paths store stale depth planes under the descriptor first. - `core/libs/prx/libSceAgcDriver/tests/execution/SampleMultisampleTarget.cpp`, `tests/cmake/agc_driver_sample_multisample_target_tests.cmake`: `agc_driver_multisample_read_single_sample_depth`. A single-sample 128x128 D32 surface is drawn at depth 0.25 and read through a 4-sample 16x16 R32 descriptor over the same 64 KiB: every sample reads 0.25. It is drawn again at 0.75 and read again: every sample reads 0.75. ### 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_native_fmask_*`, `agc_driver_fmask_*`, `agc_driver_msaa_*`, `agc_driver_multisample*`, `agc_driver_native_multisample*`, `agc_driver_native_color*`, `agc_driver_native_msaa*`, `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 | 118 / 0 | 119 / 0 (adds `agc_driver_multisample_read_single_sample_depth`) | | Validation layer inserted | 128 | 129 | | `VUID-` lines | 0 | 0 | Without the fix (`main`'s `DepthSurface.cpp` and `MultisampleTarget.cpp` with this branch's test), the new test fails with `AGC graphics: multisample reader overlaps a single-sample depth attachment`. With only the `DepthSurface.cpp` part, it reads the stale memory: `...did not read the depth it published after the first draw: 0.000000`. Forza Horizon 5 (PPSA22327 01.685.672), local stack of open PRs without this change: - **What the game does:** it binds a 3840x2160 D32 depth target with HTILE as single-sample (depth writes on). A compute shader then reads the same address through a 4-sample R32 descriptor without HTILE. A diagnostic showed the surface live, no multisampled color target there, and every HTILE tile expanded. - **Without this change:** that read stopped 8 of 12 runs at about 128 s. - **With this exact commit added:** 27 runs, none with the refusal. `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-multisample-read-single-sample-depth` (2,364 open PRs): #16880 changes the line next to this one in `DepthSurfaceTexture`, for the opposite case (a single-sample reader over native multisampled depth). Twenty-three PRs that conflict with `main` were searched by hand; none changes this path. Not tested: a first-sample read through a 2D image over a single-sample depth surface (it still refuses, now with "reading sample 0 of a multisampled depth surface whose depth plane is not at the descriptor's address is not implemented"), other GPUs, Linux, console behaviour. 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. ### 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. This PR depends on #25869 on drivers whose host imports keep write protection (such as Linux NVIDIA): without #25869, `ClaimMultisampleTargetMemory` leaves the memory-backed multisampled copy registered when the single-sample depth surface is bound again, and the GPU-direct flush path does not trigger the CPU read guard that happened to retire it on Windows. The two PRs merge cleanly with no conflicts. - #25867 `fix/agc-materialize-cold-native-fmask`: cold native FMASK pages read as stored after a first touch - #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 - #25871 `fix/agc-sample-htile-stencil-after-expand`: stencil kept in HTILE read without metadata after an expand - #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: #25869 - [x] Fixes: none - [x] Unblocks: PPSA22327 #25152 - [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 20:02:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T20:02:24Z.

Review: COMMENTED


Reviewed — comments

The changed paths and test are present in the prepared bundle, but I could not run the pinned repository reader or verify the flush helper’s behavior and callers, so a formal decision is not justified.

What I ran

  • Read the prepared diff and full text for all four changed files, plus the PR description, commit summary, and manifest.
  • Attempted to invoke repo_read.py; the available environment did not provide the instructed shell command interface. No tests were run.

Results

Check Result Note
Prepared bundle review passed All changed files included
Targeted source context not run Reader invocation unavailable
Tests not run No test command run

Findings

Blocking

None verified.

Non-blocking

None.

Not verified

Repository context at the pinned head was not independently read through repo_read.py; in particular, callers and synchronization behavior of FlushDepthPlanes and DepthPlanesStale were not verified. Tests, build, and author-reported results were not independently verified. No files were excluded according to the manifest; all four changed files were read from the prepared bundle.

To get this to a good state

Nothing is required. Optional: rerun the review with repository-reader access to verify the flush helper and its callers.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6014210425 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/25868#pullrequestreview-6014210425). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-22T20:02:24Z. **Review:** COMMENTED --- # Reviewed — comments The changed paths and test are present in the prepared bundle, but I could not run the pinned repository reader or verify the flush helper’s behavior and callers, so a formal decision is not justified. ## What I ran - Read the prepared diff and full text for all four changed files, plus the PR description, commit summary, and manifest. - Attempted to invoke `repo_read.py`; the available environment did not provide the instructed shell command interface. No tests were run. ## Results | Check | Result | Note | |---|---|---| | Prepared bundle review | passed | All changed files included | | Targeted source context | not run | Reader invocation unavailable | | Tests | not run | No test command run | ## Findings ### Blocking None verified. ### Non-blocking None. ## Not verified Repository context at the pinned head was not independently read through `repo_read.py`; in particular, callers and synchronization behavior of `FlushDepthPlanes` and `DepthPlanesStale` were not verified. Tests, build, and author-reported results were not independently verified. No files were excluded according to the manifest; all four changed files were read from the prepared bundle. ## To get this to a good state Nothing is required. Optional: rerun the review with repository-reader access to verify the flush helper and its callers.
mihiii1337 commented 2026-11-22 20:54:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by mihiii1337 on 2026-11-22T20:54:44Z.

Review: APPROVED


Verified exact head 4e1d3c9480b6c928829e9eb253b080a802d39697 with a three-arm RTX matrix.

  • Head: 3/3 pass and reaches the exact success marker after both readbacks. Each readback checks 1,024 values; the first is 0.25f, the second after drawing again is 0.75f, and the 2D and array paths agree.
  • Both production files restored from direct parent f220c221625695bcd12615476d385a8977532aa3: 0/3, with the expected multisample reader overlaps a single-sample depth attachment refusal.
  • Head DepthSurface.cpp with only MultisampleTarget.cpp restored from the parent: 0/3 at the first value check, observing 0.000000 instead of the published depth.

All three arms used the byte-identical head test executable and fixture. All nine invocations selected the RTX 4070 Laptop (10de:2860, NVIDIA 621.01), reported pipeline libraries enabled and write watch retained, and inserted Khronos Validation 1.4.369. There were no skips, missing-layer messages, device losses, VUIDs, or synchronization diagnostics.

This independently exercises the normal LoadSamples / MultisampleTargetTexture path. I did not separately exercise the added MultisampleTargetFirstSample or MultisampleTargetStorageView call sites.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6014485840 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/25868#pullrequestreview-6014485840). Originally posted by [mihiii1337](https://github.com/mihiii1337) on 2026-11-22T20:54:44Z. **Review:** APPROVED --- Verified exact head `4e1d3c9480b6c928829e9eb253b080a802d39697` with a three-arm RTX matrix. - Head: 3/3 pass and reaches the exact success marker after both readbacks. Each readback checks 1,024 values; the first is `0.25f`, the second after drawing again is `0.75f`, and the 2D and array paths agree. - Both production files restored from direct parent `f220c221625695bcd12615476d385a8977532aa3`: 0/3, with the expected `multisample reader overlaps a single-sample depth attachment` refusal. - Head `DepthSurface.cpp` with only `MultisampleTarget.cpp` restored from the parent: 0/3 at the first value check, observing `0.000000` instead of the published depth. All three arms used the byte-identical head test executable and fixture. All nine invocations selected the RTX 4070 Laptop (`10de:2860`, NVIDIA 621.01), reported pipeline libraries enabled and write watch retained, and inserted Khronos Validation 1.4.369. There were no skips, missing-layer messages, device losses, VUIDs, or synchronization diagnostics. This independently exercises the normal `LoadSamples` / `MultisampleTargetTexture` path. I did not separately exercise the added `MultisampleTargetFirstSample` or `MultisampleTargetStorageView` call sites. 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!25868
No description provided.