fix(agc): render partially resident depth and stencil planes whose pages are all mapped #16644

Merged
freneza merged 4 commits from upstream-pr/16644 into main 2026-11-11 01:23:09 +00:00
freneza commented 2026-11-07 12:20:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by freneza on 2026-11-07T12:20:36Z.


What

DecodeState refused every depth or stencil plane with PARTIALLY_RESIDENT (bit 12 of DB_Z_INFO or DB_STENCIL_INFO):

partially resident depth (DB_Z_INFO) is unsupported (register 0x10 = 0x80001181)

That bit only changes how the DB treats pages that are not mapped. So a plane with it whose every page is mapped renders like any other plane, and this change lets it render.

  • Decode: DecodeState now marks the plane (DepthTarget::depthPartiallyResident, stencilPartiallyResident) instead of refusing it. The mark needs the plane: a depth format or a stencil plane.
  • Residency check: DepthSurfaceView checks residency each time it binds the plane, not at decode. Draw decodes are cached by their registers, and a title can unmap pages between two draws with the same registers. The check covers the range the driver reads and writes: the depth plane and its HTILE, and the stencil plane, each through GuestMemory::DescribeCommitted.
  • Unmapped pages: a plane with a page that is not mapped throws (... with pages that are not mapped is unsupported). What the depth and stencil tests read from such a page, and whether a write to it lands, is not modeled. docs/dev/debt/libSceAgcDriver.md records it.
  • Depth copies: a DB depth copy from a partially resident plane still throws, as before.

Where this was found. PPSA01317 (01.710.000) draws into a 2304x2304 D16 plane at 0x2900000000, with DB_Z_INFO = 0x80001181 and no stencil or HTILE. A local log showed the following:

  • The plane sits at the start of a 4 GiB PRT aperture that the title sets with sceKernelSetPrtAperture(0, 0x2900000000, 0x100000000).
  • Before the draw, the title maps 162 pages of 64 KiB there with sceKernelBatchMap, from 0x2900000000 to 0x2900a20000, exactly the plane's 0xa20000 bytes.
  • At the refusal, DescribeCommitted reported the whole plane as mapped, in one run.

This replaces #14173, which GitHub refuses to reopen (Could not open the pull request) after the open PR limit closed it.

Tested

Linux (Bazzite 44, Fedora-based), GCC 16.2.1, Release, BUILD_TESTING=ON.

New tests:

  • tests/Graphics.cpp: DecodeState marks a PARTIALLY_RESIDENT depth plane and stencil plane, and doesn't mark a plane without the bit.
  • tests/DepthSurfaceReuse.cpp (TestPartiallyResidentPlanes), over real memory with pages left unmapped:
    • A plane with an unmapped page and no PARTIALLY_RESIDENT still renders.
    • A partially resident depth plane with an unmapped page, a partially resident depth plane with an unmapped HTILE, and a partially resident stencil plane with an unmapped page are each refused.
    • Once every page is mapped, the planes render.

Focused tests with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1 and VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation (loader output confirms VK_LAYER_KHRONOS_validation is inserted), ctest --test-dir build-test -R '<pattern>' -V -j1, on main 4977f64052 and on this change merged onto it (20a0a6450d). The pattern is agc_driver_graphics, agc_driver_depth_bounds_state, agc_depth_copy_kept_bytes, agc_driver_unused_viewport_depth, agc_driver_depth_plane_.*, agc_driver_native_depth_.* and agc_driver_depth_surface_last_writer.

tests VUID- lines was not found but was requested by env var VK_INSTANCE_LAYERS
main 39 / 39 0 0
this change 39 / 39 0 0

PPSA01317 on a local branch of main 92d2fdc343 with the GPU pull requests listed in #4697 and this change draws past the point where it used to stop on partially resident depth. It now stops in two refusals that are not this one:

  • The table call limit in the World Map material compute shader 0x120aed7f00, whose table holds 140 distinct targets (limit 64).
  • the depth target's sample count differs from the rasterizer's, when entering one of the areas the World Map opens (#14861).

That game run predates the merge of current main; the focused tests above are from the merged head.

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: PPSA01317 #4697
  • GPUs tested: NVIDIA GeForce RTX 5070, driver 615.78.08, Linux (Bazzite 44)
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5201552832 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16644). Originally posted by [freneza](https://github.com/freneza) on 2026-11-07T12:20:36Z. --- ### What `DecodeState` refused every depth or stencil plane with `PARTIALLY_RESIDENT` (bit 12 of `DB_Z_INFO` or `DB_STENCIL_INFO`): ``` partially resident depth (DB_Z_INFO) is unsupported (register 0x10 = 0x80001181) ``` That bit only changes how the DB treats pages that are not mapped. So a plane with it whose every page is mapped renders like any other plane, and this change lets it render. - **Decode:** `DecodeState` now marks the plane (`DepthTarget::depthPartiallyResident`, `stencilPartiallyResident`) instead of refusing it. The mark needs the plane: a depth format or a stencil plane. - **Residency check:** `DepthSurfaceView` checks residency each time it binds the plane, not at decode. Draw decodes are cached by their registers, and a title can unmap pages between two draws with the same registers. The check covers the range the driver reads and writes: the depth plane and its HTILE, and the stencil plane, each through `GuestMemory::DescribeCommitted`. - **Unmapped pages:** a plane with a page that is not mapped throws (`... with pages that are not mapped is unsupported`). What the depth and stencil tests read from such a page, and whether a write to it lands, is not modeled. `docs/dev/debt/libSceAgcDriver.md` records it. - **Depth copies:** a DB depth copy from a partially resident plane still throws, as before. **Where this was found.** PPSA01317 (01.710.000) draws into a 2304x2304 D16 plane at `0x2900000000`, with `DB_Z_INFO = 0x80001181` and no stencil or HTILE. A local log showed the following: - The plane sits at the start of a 4 GiB PRT aperture that the title sets with `sceKernelSetPrtAperture(0, 0x2900000000, 0x100000000)`. - Before the draw, the title maps 162 pages of 64 KiB there with `sceKernelBatchMap`, from `0x2900000000` to `0x2900a20000`, exactly the plane's `0xa20000` bytes. - At the refusal, `DescribeCommitted` reported the whole plane as mapped, in one run. This replaces #14173, which GitHub refuses to reopen (`Could not open the pull request`) after the open PR limit closed it. ### Tested Linux (Bazzite 44, Fedora-based), GCC 16.2.1, Release, `BUILD_TESTING=ON`. New tests: - `tests/Graphics.cpp`: `DecodeState` marks a `PARTIALLY_RESIDENT` depth plane and stencil plane, and doesn't mark a plane without the bit. - `tests/DepthSurfaceReuse.cpp` (`TestPartiallyResidentPlanes`), over real memory with pages left unmapped: - A plane with an unmapped page and no `PARTIALLY_RESIDENT` still renders. - A partially resident depth plane with an unmapped page, a partially resident depth plane with an unmapped HTILE, and a partially resident stencil plane with an unmapped page are each refused. - Once every page is mapped, the planes render. Focused tests with `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1` and `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation` (loader output confirms `VK_LAYER_KHRONOS_validation` is inserted), `ctest --test-dir build-test -R '<pattern>' -V -j1`, on `main` 4977f64052 and on this change merged onto it (20a0a6450d). The pattern is `agc_driver_graphics`, `agc_driver_depth_bounds_state`, `agc_depth_copy_kept_bytes`, `agc_driver_unused_viewport_depth`, `agc_driver_depth_plane_.*`, `agc_driver_native_depth_.*` and `agc_driver_depth_surface_last_writer`. | | tests | `VUID-` lines | `was not found but was requested by env var VK_INSTANCE_LAYERS` | |---|---|---|---| | `main` | 39 / 39 | 0 | 0 | | this change | 39 / 39 | 0 | 0 | PPSA01317 on a local branch of `main` 92d2fdc343 with the GPU pull requests listed in #4697 and this change draws past the point where it used to stop on `partially resident depth`. It now stops in two refusals that are not this one: - The table call limit in the World Map material compute shader `0x120aed7f00`, whose table holds 140 distinct targets (limit 64). - `the depth target's sample count differs from the rasterizer's`, when entering one of the areas the World Map opens (#14861). That game run predates the merge of current `main`; the focused tests above are from the merged head. ### 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: PPSA01317 #4697 - [x] GPUs tested: NVIDIA GeForce RTX 5070, driver 615.78.08, Linux (Bazzite 44) - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Superseabas commented 2026-11-07 13:03:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Superseabas on 2026-11-07T13:03:07Z.

Review: APPROVED


Windows check of head 20a0a6450d, merged onto main 4977f64052 (clean merge). The PR was tested on Linux only, so this is the first run of the _WIN32 branch of the new fixture (VirtualAlloc reserve, then commit page by page).

Setup: Windows 11 Home 10.0.26200, WinLibs GCC 16.2.0 (x86_64-ucrt-posix-seh, r3), Release, BUILD_TESTING=ON. Both GPUs, selected with ANYPS5_GPU: an RTX 5070 Ti (driver 621.01) and the Ryzen 7 7700X's integrated Radeon (AMD 26.10.2). ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1 and VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation.

Full ^agc suite (1,406 tests, -j 8):

RTX 5070 Ti Radeon (iGPU)
main 1405 / 1406 1404 / 1406
this PR 1405 / 1406 1404 / 1406

The same tests fail with and without this PR, and they fail on main on this machine: agc_driver_quad_pixel_mask on the RTX (#14341), and agc_driver_scratch_pool (#15566) and agc_driver_sample_order_grid_reference (#9503) on the Radeon. No VUID- lines and no missing-layer lines in any run. agc_driver_graphics, which runs both new test blocks, passes on both GPUs.

Red checks, agc_driver_graphics on both GPUs with the PR's tests kept:

  • With main's DepthSurface.cpp (no residency check), it fails with a partially resident depth plane with an unmapped page must be refused.
  • With main's State.cpp (the decoder refuses the bit), it fails with partially resident depth (DB_Z_INFO) is unsupported (register 0x10 = 0x80001180).

So each of the two production changes has a test that catches its removal.

Reading the code:

  • Both places a draw binds its depth target go through the checked function: the normal draw path and the cached-recipe replay (Draw.cpp, DepthSurfaceViewWithStencilWriteIntent at 3330 and 4142). A replayed draw with unchanged registers therefore still checks residency, which is the case the description gives for checking at bind rather than at decode.
  • The check runs before ClaimMultisampleTargetMemory, so a refused plane claims nothing.
  • The DB depth copy keeps its own refusal of the bit (State.cpp:2491), as the description says.

tools/check_conventions.py --base main passes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5812353176 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16644#pullrequestreview-5812353176). Originally posted by [Superseabas](https://github.com/Superseabas) on 2026-11-07T13:03:07Z. **Review:** APPROVED --- Windows check of head `20a0a6450d`, merged onto `main` `4977f64052` (clean merge). The PR was tested on Linux only, so this is the first run of the `_WIN32` branch of the new fixture (`VirtualAlloc` reserve, then commit page by page). **Setup:** Windows 11 Home 10.0.26200, WinLibs GCC 16.2.0 (`x86_64-ucrt-posix-seh`, r3), Release, `BUILD_TESTING=ON`. Both GPUs, selected with `ANYPS5_GPU`: an RTX 5070 Ti (driver 621.01) and the Ryzen 7 7700X's integrated Radeon (AMD 26.10.2). `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1` and `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`. **Full `^agc` suite** (1,406 tests, `-j 8`): | | RTX 5070 Ti | Radeon (iGPU) | |---|---|---| | `main` | 1405 / 1406 | 1404 / 1406 | | this PR | 1405 / 1406 | 1404 / 1406 | The same tests fail with and without this PR, and they fail on `main` on this machine: `agc_driver_quad_pixel_mask` on the RTX (#14341), and `agc_driver_scratch_pool` (#15566) and `agc_driver_sample_order_grid_reference` (#9503) on the Radeon. No `VUID-` lines and no missing-layer lines in any run. `agc_driver_graphics`, which runs both new test blocks, passes on both GPUs. **Red checks**, `agc_driver_graphics` on both GPUs with the PR's tests kept: - With `main`'s `DepthSurface.cpp` (no residency check), it fails with `a partially resident depth plane with an unmapped page must be refused`. - With `main`'s `State.cpp` (the decoder refuses the bit), it fails with `partially resident depth (DB_Z_INFO) is unsupported (register 0x10 = 0x80001180)`. So each of the two production changes has a test that catches its removal. **Reading the code:** - Both places a draw binds its depth target go through the checked function: the normal draw path and the cached-recipe replay (`Draw.cpp`, `DepthSurfaceViewWithStencilWriteIntent` at 3330 and 4142). A replayed draw with unchanged registers therefore still checks residency, which is the case the description gives for checking at bind rather than at decode. - The check runs before `ClaimMultisampleTargetMemory`, so a refused plane claims nothing. - The DB depth copy keeps its own refusal of the bit (`State.cpp:2491`), as the description says. `tools/check_conventions.py --base main` passes.
gabichuuuuu commented 2026-11-08 14:27:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by gabichuuuuu on 2026-11-08T14:27:56Z.

Review: COMMENTED


Ran 20a0a6450d merged on main 302864d48c on Windows 11 x64 (WinLibs GCC 15.2), on an NVIDIA laptop GPU (Turing, driver 621) and an Intel iGPU (driver 101.70xx), with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1 and VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation (Khronos validation layer 1.4.368), ctest -R '^(agc_driver_graphics|agc_driver_depth_surface)' -V.

main change with main's State.cpp change, 2 runs each
NVIDIA 3/3 2/3 3/3
Intel 3/3 2/3 3/3
  • The PR's tests can't build on main, because they use the new DepthTarget fields. For the middle column I kept the PR whole and put back main's State.cpp, which refuses the PARTIALLY_RESIDENT bits and doesn't decode them.
  • Without that decode, agc_driver_graphics fails on both GPUs with "partially resident depth (DB_Z_INFO) is unsupported (register 0x10 = 0x80001180)". With it, the test passes every time.
  • agc_driver_depth_surface_from_storage and _last_writer pass in all three builds. They open the real device: the layer was inserted in each, no log has was not found but was requested by env var VK_INSTANCE_LAYERS, and no log on either side has a VUID-. agc_driver_graphics runs against MockVulkan, so the layer doesn't apply to it.

Not covered here: a plane whose pages aren't all mapped, where the new Require in DepthSurfaceViewWithStencilWriteIntent throws. These tests only map whole planes.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5818254945 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16644#pullrequestreview-5818254945). Originally posted by [gabichuuuuu](https://github.com/gabichuuuuu) on 2026-11-08T14:27:56Z. **Review:** COMMENTED --- Ran `20a0a6450d` merged on `main` 302864d48c on Windows 11 x64 (WinLibs GCC 15.2), on an NVIDIA laptop GPU (Turing, driver 621) and an Intel iGPU (driver 101.70xx), with `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1` and `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation` (Khronos validation layer 1.4.368), `ctest -R '^(agc_driver_graphics|agc_driver_depth_surface)' -V`. | | `main` | change with `main`'s `State.cpp` | change, 2 runs each | |---|---|---|---| | NVIDIA | 3/3 | 2/3 | 3/3 | | Intel | 3/3 | 2/3 | 3/3 | - The PR's tests can't build on `main`, because they use the new `DepthTarget` fields. For the middle column I kept the PR whole and put back `main`'s `State.cpp`, which refuses the `PARTIALLY_RESIDENT` bits and doesn't decode them. - Without that decode, `agc_driver_graphics` fails on both GPUs with "partially resident depth (DB_Z_INFO) is unsupported (register 0x10 = 0x80001180)". With it, the test passes every time. - `agc_driver_depth_surface_from_storage` and `_last_writer` pass in all three builds. They open the real device: the layer was inserted in each, no log has `was not found but was requested by env var VK_INSTANCE_LAYERS`, and no log on either side has a `VUID-`. `agc_driver_graphics` runs against `MockVulkan`, so the layer doesn't apply to it. Not covered here: a plane whose pages aren't all mapped, where the new `Require` in `DepthSurfaceViewWithStencilWriteIntent` throws. These tests only map whole planes. 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!16644
No description provided.