fix(agc): treat other-shaped views of a depth surface's stencil plane as reused memory #3277

Merged
oneandonlydean merged 1 commit from upstream-pr/3277 into main 2026-10-11 06:08:59 +00:00
oneandonlydean commented 2026-10-11 04:54:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-11T04:54:41Z.


Carried unchanged from @AlxcBTW's fork (AlxcBTW/AnyPS5#26, a1827af1, authorship kept); the intake pause closes PRs opened from that account.

What

FPV Simulator (PPSA10698 v01.006.000, Unity 2021.3 URP) ends when it presents a frame:

[gpu] color target 0x231590000 stays non-resident: AGC graphics: storage image access to depth/stencil surface 0x231590000 is not implemented
[videoout] presentation failed: AGC graphics: sampling the stencil plane of depth surface 0x230cd0000 (1920x1080, vk format 130) as a 1920x1080 texture of guest format 130 (vk 43), tile mode 7, dimension 1, levels 0-0, slice 0 is not implemented (T# 02315900 c8200000 010dc1df 91b00fac 00000000 00700000 00000000 00000000)
terminate called after throwing an instance of 'std::runtime_error'

Unity reuses the memory of transient render targets. The T# base, 0x231590000, is the stencil plane of the D32S8 surface at 0x230cd0000, and the first line shows the title binding that address as a color target. The view is a 1920x1080 RGBA8 sRGB texture, which reads the color data, not an 8-bit stencil plane.

9d65003c (#1495) already treats this as memory reuse for the depth plane: a view with another extent, or a depth-plane view in a format that cannot hold the plane, falls through to the ordinary texture path. Stencil-plane views of the same extent kept the old handling: they all went to the depth surface, which throws for any format other than R8 uint. This applies the same rule to the stencil plane: a view whose texels are not one byte wide cannot hold the 8-bit plane, so DepthSurfaceTexture returns nothing and the memory is read like any texture.

  • An 8-bit view of the plane's own extent still samples the stencil plane.
  • An 8-bit view in another format than R8 uint still throws, as before.

Related: #454 (open) is broader: it retires a depth surface once another writer covers its depth or stencil plane. This PR extends only the format rule from #1495 and doesn't track writers. Both change the same lines in DepthSurfaceTexture, so whichever lands second needs a small rebase.

Tested

Windows 11, WinLibs GCC 15.2.0 r7, Release, RTX 5070 Laptop (driver 616.92).

  • New cases in DepthSurfaceReuse.cpp (agc_driver_graphics), on a 320x180 D32S8 surface: an R8 uint view of the stencil plane still samples the plane; RGBA8 and R32F views of the same extent are read as reused memory. Without the source change, agc_driver_graphics fails on the RGBA8 case with the original error: sampling the stencil plane of depth surface 0x60000000 (320x180, vk format 130) as a 320x180 texture of guest format 56 (vk 37) ... is not implemented.
  • Related tests (agc_driver_graphics, agc_driver_depth_bias_per_face, agc_driver_pending_exact_surface, agc_driver_prepared_graphics, agc_driver_cmask_fast_clear, agc_pass_hazards): 6/6.
  • Suites:
    • Non-GPU tests: 446/446.
    • agc_driver on NVIDIA RTX 5070 Laptop: 253/253.
    • check_conventions.py passes.
  • In-game: not re-run on this branch. The stop above is from a local build of main with other patches.

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 in TechnicalDebt
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

Fixes #2994.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4816681474 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3277). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-11T04:54:41Z. --- Carried unchanged from @AlxcBTW's fork (AlxcBTW/AnyPS5#26, `a1827af1`, authorship kept); the intake pause closes PRs opened from that account. ### What FPV Simulator (PPSA10698 v01.006.000, Unity 2021.3 URP) ends when it presents a frame: ``` [gpu] color target 0x231590000 stays non-resident: AGC graphics: storage image access to depth/stencil surface 0x231590000 is not implemented [videoout] presentation failed: AGC graphics: sampling the stencil plane of depth surface 0x230cd0000 (1920x1080, vk format 130) as a 1920x1080 texture of guest format 130 (vk 43), tile mode 7, dimension 1, levels 0-0, slice 0 is not implemented (T# 02315900 c8200000 010dc1df 91b00fac 00000000 00700000 00000000 00000000) terminate called after throwing an instance of 'std::runtime_error' ``` Unity reuses the memory of transient render targets. The T# base, 0x231590000, is the stencil plane of the D32S8 surface at 0x230cd0000, and the first line shows the title binding that address as a color target. The view is a 1920x1080 RGBA8 sRGB texture, which reads the color data, not an 8-bit stencil plane. 9d65003c (#1495) already treats this as memory reuse for the depth plane: a view with another extent, or a depth-plane view in a format that cannot hold the plane, falls through to the ordinary texture path. Stencil-plane views of the same extent kept the old handling: they all went to the depth surface, which throws for any format other than R8 uint. This applies the same rule to the stencil plane: a view whose texels are not one byte wide cannot hold the 8-bit plane, so `DepthSurfaceTexture` returns nothing and the memory is read like any texture. - An 8-bit view of the plane's own extent still samples the stencil plane. - An 8-bit view in another format than R8 uint still throws, as before. Related: #454 (open) is broader: it retires a depth surface once another writer covers its depth or stencil plane. This PR extends only the format rule from #1495 and doesn't track writers. Both change the same lines in `DepthSurfaceTexture`, so whichever lands second needs a small rebase. ### Tested Windows 11, WinLibs GCC 15.2.0 r7, Release, RTX 5070 Laptop (driver 616.92). - **New cases** in `DepthSurfaceReuse.cpp` (`agc_driver_graphics`), on a 320x180 D32S8 surface: an R8 uint view of the stencil plane still samples the plane; RGBA8 and R32F views of the same extent are read as reused memory. Without the source change, `agc_driver_graphics` fails on the RGBA8 case with the original error: `sampling the stencil plane of depth surface 0x60000000 (320x180, vk format 130) as a 320x180 texture of guest format 56 (vk 37) ... is not implemented`. - **Related tests** (`agc_driver_graphics`, `agc_driver_depth_bias_per_face`, `agc_driver_pending_exact_surface`, `agc_driver_prepared_graphics`, `agc_driver_cmask_fast_clear`, `agc_pass_hazards`): 6/6. - **Suites:** - Non-GPU tests: 446/446. - `agc_driver` on NVIDIA RTX 5070 Laptop: 253/253. - `check_conventions.py` passes. - **In-game:** not re-run on this branch. The stop above is from a local build of `main` with other patches. ### Checklist - [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 - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in TechnicalDebt - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes (Claude Code) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Fixes #2994.
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!3277
No description provided.