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

Closed
freneza wants to merge 0 commits from upstream-pr/14173 into main
freneza commented 2026-10-31 22:07:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by freneza on 2026-10-31T22:07:19Z.


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.

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:5101983643 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14173). Originally posted by [freneza](https://github.com/freneza) on 2026-10-31T22:07:19Z. --- ### 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. ### 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)

Pull request closed

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!14173
No description provided.