feat(agc): read sample 0 of a native multisampled depth surface through a 2D image #12612

Merged
milescoviello merged 1 commit from upstream-pr/12612 into main 2026-11-02 13:38:44 +00:00
milescoviello commented 2026-10-28 22:58:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-28T22:58:00Z.


What

A DIM 2D image read of a two-dimensional multisampled T# reads the image's sample 0. thuanquang's 0a3ea213e1 serves that read for a multisampled color target by drawing sample 0 into a one-sample image (FirstSampleCopy). Over a native multisampled depth surface it refused:

AGC graphics: reading sample 0 of a multisampled depth surface through a 2D image is not implemented

Ghost of Tsushima Director's Cut (PPSA02225 02.024.000) reads its two-sample 1920x2160 checkerboard depth this way. With #12561 it gets to this read, and three runs stopped on this error 396 to 539 s in.

How

DepthSurfaceFirstSample takes the surface's multisampled sampled depth view through DepthSurfaceTexture (the checks and barrier of a multisampled depth read). It then draws that view's sample 0 into a one-sample VK_FORMAT_R32_SFLOAT image (VK_FORMAT_R16_UNORM for D16) with FirstSampleCopy, the same fragment pass the color targets use. The surface keeps the copy and its textures, one per component mapping, and the returned texture holds them, as MultisampleTarget::FirstSample does. ShaderResources sends the read there when a depth surface is at the T#'s address. A read with a depth comparison still throws, and so does one whose address is the surface's stencil plane.

Tested

Linux (Ubuntu 26.04.1, GCC 15.2), RTX 4070 Ti (NVIDIA 615.71.09), on main 319621ba2e:

  • New case in agc_driver_native_multisample_depth:
    • After each raster write of a distinct depth per sample ((s + 1) / 16 plus an offset), DepthSurfaceFirstSample over the target must read sample 0 (1/16 plus the offset) at every pixel, through a one-sample 2D fetch.
    • A second read must return the same texture.
    • With the copy taken out (3df8b006a1), the case fails: a 2D read of the native depth target did not return its sample 0 at pixel 0: 0.000000, expected 0.062500.
    • The test calls DepthSurfaceFirstSample directly. The ShaderResources routing to it is covered by the Ghost of Tsushima runs below.
  • Area: ^agc_driver_native_multisample_depth$|^agc_driver_depth|^agc_driver_sample_multisample_target$|^agc_driver_native_fmask$ (32 tests) pass 3 of 3.
  • Validation layer (Khronos VK_LAYER_KHRONOS_validation 1.4.363, LunarG SDK), on main 319621ba2e and at this head:
    VK_LAYER_PATH=<sdk>/layers VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 ctest -R '^agc_driver_native_multisample_depth$|^agc_driver_sample_multisample_target$' -V
    • Both pass 2 of 2, and neither log contains was not found but was requested by env var VK_INSTANCE_LAYERS.
    • The layer checked 4 devices on each side, with no VUID- messages on either.
  • Ghost of Tsushima (PPSA02225 02.024.000), pad input, on a local stack with #12561 and a local texture cache experiment that isn't in this PR (a reclaim change of mine, alone or with APS5_TEXTURE_CACHE_MIB=4096):
    • Without this change, the 3 runs with the experiment on stopped on the error above: at 495 and 539 s with the reclaim change alone, and at 396 s with both.
    • With it, two 600 s runs with both ran to their timeouts with no stop.
    • Runs with default settings didn't reach this read, with or without this change.

Windows 11 VM (GeForce GT 1030, WinLibs GCC 15.2, Release): agc_driver_native_multisample_depth and agc_driver_sample_multisample_target pass 3 of 3 at this head and on main 319621ba2e.

AMD RDNA 4, run by @bunbeans2-arch (comment): Windows 11 Pro, Radeon RX 9070 XT (driver 32.0.32015.7029), MSYS2 UCRT64 g++ 16.1.0, Release, ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 with the Khronos validation layer loaded. The 32-test area passes 3 of 3 on main 673fa865f4 and on this head d948d3052d merged onto it, with no VUID- line on either side.

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: none
  • Unblocks: PPSA02225 #4461 (Ghost of Tsushima, past this read, after #12561)
  • GPUs tested: NVIDIA GeForce RTX 4070 Ti (Linux), NVIDIA GeForce GT 1030 (Windows VM), AMD Radeon RX 9070 XT (Windows, @bunbeans2-arch)
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5059023774 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12612). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-28T22:58:00Z. --- ### What A DIM 2D image read of a two-dimensional multisampled T# reads the image's sample 0. thuanquang's 0a3ea213e1 serves that read for a multisampled color target by drawing sample 0 into a one-sample image (`FirstSampleCopy`). Over a native multisampled depth surface it refused: ``` AGC graphics: reading sample 0 of a multisampled depth surface through a 2D image is not implemented ``` Ghost of Tsushima Director's Cut (PPSA02225 02.024.000) reads its two-sample 1920x2160 checkerboard depth this way. With #12561 it gets to this read, and three runs stopped on this error 396 to 539 s in. ### How `DepthSurfaceFirstSample` takes the surface's multisampled sampled depth view through `DepthSurfaceTexture` (the checks and barrier of a multisampled depth read). It then draws that view's sample 0 into a one-sample `VK_FORMAT_R32_SFLOAT` image (`VK_FORMAT_R16_UNORM` for D16) with `FirstSampleCopy`, the same fragment pass the color targets use. The surface keeps the copy and its textures, one per component mapping, and the returned texture holds them, as `MultisampleTarget::FirstSample` does. `ShaderResources` sends the read there when a depth surface is at the T#'s address. A read with a depth comparison still throws, and so does one whose address is the surface's stencil plane. ### Tested Linux (Ubuntu 26.04.1, GCC 15.2), RTX 4070 Ti (NVIDIA 615.71.09), on `main` `319621ba2e`: - **New case in `agc_driver_native_multisample_depth`:** - After each raster write of a distinct depth per sample (`(s + 1) / 16` plus an offset), `DepthSurfaceFirstSample` over the target must read sample 0 (`1/16` plus the offset) at every pixel, through a one-sample 2D fetch. - A second read must return the same texture. - With the copy taken out (`3df8b006a1`), the case fails: `a 2D read of the native depth target did not return its sample 0 at pixel 0: 0.000000, expected 0.062500`. - The test calls `DepthSurfaceFirstSample` directly. The `ShaderResources` routing to it is covered by the Ghost of Tsushima runs below. - **Area:** `^agc_driver_native_multisample_depth$|^agc_driver_depth|^agc_driver_sample_multisample_target$|^agc_driver_native_fmask$` (32 tests) pass 3 of 3. - **Validation layer** (Khronos `VK_LAYER_KHRONOS_validation` 1.4.363, LunarG SDK), on `main` `319621ba2e` and at this head: `VK_LAYER_PATH=<sdk>/layers VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 ctest -R '^agc_driver_native_multisample_depth$|^agc_driver_sample_multisample_target$' -V` - Both pass 2 of 2, and neither log contains `was not found but was requested by env var VK_INSTANCE_LAYERS`. - The layer checked 4 devices on each side, with no `VUID-` messages on either. - **Ghost of Tsushima (PPSA02225 02.024.000)**, pad input, on a local stack with #12561 and a local texture cache experiment that isn't in this PR (a reclaim change of mine, alone or with `APS5_TEXTURE_CACHE_MIB=4096`): - Without this change, the 3 runs with the experiment on stopped on the error above: at 495 and 539 s with the reclaim change alone, and at 396 s with both. - With it, two 600 s runs with both ran to their timeouts with no stop. - Runs with default settings didn't reach this read, with or without this change. Windows 11 VM (GeForce GT 1030, WinLibs GCC 15.2, Release): `agc_driver_native_multisample_depth` and `agc_driver_sample_multisample_target` pass 3 of 3 at this head and on `main` `319621ba2e`. AMD RDNA 4, run by @bunbeans2-arch ([comment](https://github.com/boykopovar/AnyPS5/pull/12612#issuecomment-6516808004)): Windows 11 Pro, Radeon RX 9070 XT (driver 32.0.32015.7029), MSYS2 UCRT64 g++ 16.1.0, Release, `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1` with the Khronos validation layer loaded. The 32-test area passes 3 of 3 on `main` `673fa865f4` and on this head `d948d3052d` merged onto it, with no `VUID-` line on either side. ### 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: none - [x] Unblocks: PPSA02225 #4461 (Ghost of Tsushima, past this read, after #12561) - [x] GPUs tested: NVIDIA GeForce RTX 4070 Ti (Linux), NVIDIA GeForce GT 1030 (Windows VM), AMD Radeon RX 9070 XT (Windows, @bunbeans2-arch) - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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!12612
No description provided.