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

Merged
TideOPL merged 3 commits from upstream-pr/1495 into main 2026-10-10 01:04:14 +00:00
TideOPL commented 2026-10-08 09:15:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by TideOPL on 2026-10-08T09:15:18Z.


What

Engines alias transient render targets, so a texture can sit at the address of a depth surface after that memory has been handed to a color image: a 384x384 R11G11B10 texture over a 384x384 D32S8 surface, for example. DepthSurfaceTexture sent every texture at a depth surface's address to DepthSurface::Sampled, which threw sampling the depth plane ... is not implemented, and the draw was skipped.

Now a view with a different extent, or a depth-plane view in a format that cannot hold the plane, is treated as reused memory. "Cannot hold the plane" means it is neither the plane's own R32F / R16 unorm nor a T# that reads the raw depth bits. The lookup returns null, so the texture goes through the ordinary texture path, as it would at any other address. Stencil-plane views keep their current handling.

#425 rewrites DepthSurfaceTexture for array and cube depth reads but has no reuse rule. The two touch the same function, so whichever merges second needs a small rebase.

Tested

Windows 11, NVIDIA RTX 5070 (driver 610.88).

  • PPSA16064 (Minecraft Dungeons II): the main menu's 384x384 draw that samples the reused memory (... as a 384x384 texture of guest format 36 (vk 122), tile mode 7 ...) was skipped every frame. It now records, and that skip no longer appears in the log.
  • ctest: 426 of 426 pass on current main with this PR and #1494 (unrelated files) applied.

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 (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 (overlaps #425 textually)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4784529541 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1495). Originally posted by [TideOPL](https://github.com/TideOPL) on 2026-10-08T09:15:18Z. --- ### What Engines alias transient render targets, so a texture can sit at the address of a depth surface after that memory has been handed to a color image: a 384x384 R11G11B10 texture over a 384x384 D32S8 surface, for example. `DepthSurfaceTexture` sent every texture at a depth surface's address to `DepthSurface::Sampled`, which threw `sampling the depth plane ... is not implemented`, and the draw was skipped. Now a view with a different extent, or a depth-plane view in a format that cannot hold the plane, is treated as reused memory. "Cannot hold the plane" means it is neither the plane's own R32F / R16 unorm nor a T# that reads the raw depth bits. The lookup returns null, so the texture goes through the ordinary texture path, as it would at any other address. Stencil-plane views keep their current handling. #425 rewrites `DepthSurfaceTexture` for array and cube depth reads but has no reuse rule. The two touch the same function, so whichever merges second needs a small rebase. ### Tested Windows 11, NVIDIA RTX 5070 (driver 610.88). - PPSA16064 (Minecraft Dungeons II): the main menu's 384x384 draw that samples the reused memory (`... as a 384x384 texture of guest format 36 (vk 122), tile mode 7 ...`) was skipped every frame. It now records, and that skip no longer appears in the log. - `ctest`: 426 of 426 pass on current `main` with this PR and #1494 (unrelated files) applied. ### 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](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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 (overlaps #425 textually) - [x] AI-assisted: yes
klosixgaming-arch commented 2026-10-08 11:30:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by klosixgaming-arch on 2026-10-08T11:30:56Z.

Review: APPROVED


Good improvement to depth surface texture matching. This adds proper validation to ensure the depth format matches between the requested resource and existing depth surfaces, preventing incorrect texture reuse that could cause rendering issues.

Strengths:

  • Clean implementation with proper validation of width, height, and depth format
  • Good handling of both depth-only and stencil surfaces
  • Proper use of ShaderRecompiler::DepthBitsTextureWidth for format detection
  • Correct distinction between D16 and D32 formats

This will improve rendering correctness by preventing mismatched depth texture reuse. Ready to merge.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5455871910 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1495#pullrequestreview-5455871910). Originally posted by [klosixgaming-arch](https://github.com/klosixgaming-arch) on 2026-10-08T11:30:56Z. **Review:** APPROVED --- Good improvement to depth surface texture matching. This adds proper validation to ensure the depth format matches between the requested resource and existing depth surfaces, preventing incorrect texture reuse that could cause rendering issues. **Strengths:** - Clean implementation with proper validation of width, height, and depth format - Good handling of both depth-only and stencil surfaces - Proper use of ShaderRecompiler::DepthBitsTextureWidth for format detection - Correct distinction between D16 and D32 formats This will improve rendering correctness by preventing mismatched depth texture reuse. Ready to merge.
orbz22 commented 2026-10-09 07:12:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by orbz22 on 2026-10-09T07:12:01Z.


Another case this rule fixes, from Astro's Playroom (PPSA01325), Windows 11 / RTX 3060 Laptop:

  • After the start sequence, the game renders its shadow map at 0x529430000 as a 1536x1536 depth target. An earlier scene had used the same memory as a 2048x2048 D16 surface (vk format 124), and that surface is still resident.
  • The deferred lighting dispatch 0x5001c6a00 samples the memory as a 1536x1536 2D array (guest format 7, R16 unorm, tile mode 4, slice 0). On main, ValidateSampled throws, and because the format is depth-like the title aborts:
compute shader 0x5001c6a00: AGC graphics: sampling the depth plane of depth surface 0x529430000 (2048x2048, vk format 124) as a 1536x1536 texture of guest format 7 (vk 70), tile mode 4, dimension 2, levels 0-0, slice 0 is not implemented
  • On main this crash only shows up when no stale stage-A cache entry hides the depth surface; #1957 removes that stale entry, so it shows up more often.
  • Locally I applied the same extent rule as this PR (return null for another extent, arrays included), retired the old surface, and preferred a resident surface of the sampled extent when several share the address. With that, the game runs on into the in-game DualSense platform with correct shadows.

The preference matters when both shapes are resident: a newest-first search can return the other one. That could be a follow-up; it's not needed for this PR.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6076249622 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1495#issuecomment-6076249622). Originally posted by [orbz22](https://github.com/orbz22) on 2026-10-09T07:12:01Z. --- Another case this rule fixes, from Astro's Playroom (PPSA01325), Windows 11 / RTX 3060 Laptop: - After the start sequence, the game renders its shadow map at `0x529430000` as a 1536x1536 depth target. An earlier scene had used the same memory as a 2048x2048 D16 surface (vk format 124), and that surface is still resident. - The deferred lighting dispatch `0x5001c6a00` samples the memory as a 1536x1536 **2D array** (guest format 7, R16 unorm, tile mode 4, slice 0). On `main`, `ValidateSampled` throws, and because the format is depth-like the title aborts: ``` compute shader 0x5001c6a00: AGC graphics: sampling the depth plane of depth surface 0x529430000 (2048x2048, vk format 124) as a 1536x1536 texture of guest format 7 (vk 70), tile mode 4, dimension 2, levels 0-0, slice 0 is not implemented ``` - On `main` this crash only shows up when no stale stage-A cache entry hides the depth surface; #1957 removes that stale entry, so it shows up more often. - Locally I applied the same extent rule as this PR (return null for another extent, arrays included), retired the old surface, and preferred a resident surface of the sampled extent when several share the address. With that, the game runs on into the in-game DualSense platform with correct shadows. The preference matters when both shapes are resident: a newest-first search can return the other one. That could be a follow-up; it's not needed for this PR.
hugodearaujo commented 2026-10-09 18:08:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by hugodearaujo on 2026-10-09T18:08:14Z.


Another title that hits this: Hollow Knight: Silksong (PPSA12544) on Linux (RX 9070 XT), after lowering the in-game resolution scale.

Before this PR:

AGC graphics: sampling the depth plane of depth surface 0x265e90000 (1920x1080, vk format 130) as a 1882x1058 texture of guest format 56 (vk 37), tile mode 7, dimension 1, levels 0-0, slice 0 is not implemented

With this PR, that stop is gone. The same reuse then happens on the stencil plane, which this PR leaves as it was:

AGC graphics: sampling the stencil plane of depth surface 0x266010000 (1766x994, vk format 130) as a 1766x994 texture of guest format 56 (vk 37), tile mode 7, dimension 1, levels 0-0, slice 0 is not implemented (T# 02667200 43800000 00f841b9 91b00fac 00000000 00700000 107b0000 00026671)

The extent matches, but an R8G8B8A8 view cannot be a stencil read: Sampled only accepts VK_FORMAT_R8_UINT for that plane. Applying the same rule to the stencil plane gets the title past this point:

const bool stencil = target.stencilAddress != 0 && resource.baseAddress == target.stencilAddress;
if (stencil && ResolveTextureFormat(resource.format) != VK_FORMAT_R8_UINT) return nullptr;

I only ran it locally, so I'm leaving it here in case you want it in this PR rather than opening a separate one.

Base for these runs: main + #1836 + #1431 + #846 + #2323 + #861 + #2401 + #1902.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6086560523 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1495#issuecomment-6086560523). Originally posted by [hugodearaujo](https://github.com/hugodearaujo) on 2026-10-09T18:08:14Z. --- Another title that hits this: Hollow Knight: Silksong (PPSA12544) on Linux (RX 9070 XT), after lowering the in-game resolution scale. Before this PR: ``` AGC graphics: sampling the depth plane of depth surface 0x265e90000 (1920x1080, vk format 130) as a 1882x1058 texture of guest format 56 (vk 37), tile mode 7, dimension 1, levels 0-0, slice 0 is not implemented ``` With this PR, that stop is gone. The same reuse then happens on the stencil plane, which this PR leaves as it was: ``` AGC graphics: sampling the stencil plane of depth surface 0x266010000 (1766x994, vk format 130) as a 1766x994 texture of guest format 56 (vk 37), tile mode 7, dimension 1, levels 0-0, slice 0 is not implemented (T# 02667200 43800000 00f841b9 91b00fac 00000000 00700000 107b0000 00026671) ``` The extent matches, but an R8G8B8A8 view cannot be a stencil read: `Sampled` only accepts `VK_FORMAT_R8_UINT` for that plane. Applying the same rule to the stencil plane gets the title past this point: ```cpp const bool stencil = target.stencilAddress != 0 && resource.baseAddress == target.stencilAddress; if (stencil && ResolveTextureFormat(resource.format) != VK_FORMAT_R8_UINT) return nullptr; ``` I only ran it locally, so I'm leaving it here in case you want it in this PR rather than opening a separate one. Base for these runs: `main` + #1836 + #1431 + #846 + #2323 + #861 + #2401 + #1902.
github-actions[bot] commented 2026-10-09 22:04:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-09T22:04:24Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#374 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp L172
#454 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp L169-172
#1186 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp L172
#2053 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp L172
#2076 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp L172
#2169 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp L172
#2490 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp L172
#2491 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp L172
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6090018916 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1495#issuecomment-6090018916). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-09T22:04:24Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #374 | `core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp` [L172](https://github.com/boykopovar/AnyPS5/blob/7703fda15e4ab4025dd817eae5964315e6dd134b/core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp#L172) | | | | #454 | `core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp` [L169-172](https://github.com/boykopovar/AnyPS5/blob/7703fda15e4ab4025dd817eae5964315e6dd134b/core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp#L169-L172) | | | | #1186 | `core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp` [L172](https://github.com/boykopovar/AnyPS5/blob/7703fda15e4ab4025dd817eae5964315e6dd134b/core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp#L172) | | | | #2053 | `core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp` [L172](https://github.com/boykopovar/AnyPS5/blob/7703fda15e4ab4025dd817eae5964315e6dd134b/core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp#L172) | | | | #2076 | `core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp` [L172](https://github.com/boykopovar/AnyPS5/blob/7703fda15e4ab4025dd817eae5964315e6dd134b/core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp#L172) | | | | #2169 | `core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp` [L172](https://github.com/boykopovar/AnyPS5/blob/7703fda15e4ab4025dd817eae5964315e6dd134b/core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp#L172) | | | | #2490 | `core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp` [L172](https://github.com/boykopovar/AnyPS5/blob/7703fda15e4ab4025dd817eae5964315e6dd134b/core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp#L172) | | | | #2491 | `core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp` [L172](https://github.com/boykopovar/AnyPS5/blob/7703fda15e4ab4025dd817eae5964315e6dd134b/core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp#L172) | | |
adriadam10 commented 2026-10-09 23:37:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-09T23:37:14Z.

Review: CHANGES_REQUESTED


Thanks for the fix, and for the title logs. The rule looks right to me, but it needs a test before it can merge:

  • No test covers this. Fixes for a title-specific crash need a Linux test that reproduces the case (CONTRIBUTING: tests next to their component, registered in ctest). Suggested cases in the existing libSceAgcDriver graphics tests: a depth surface plus a texture at the same address with (a) a different extent, (b) the same extent but a colour format that cannot hold the plane (e.g. R11G11B10), (c) a 2D array view of a different extent (the Astro's Playroom case reported by @orbz22). Each must go through the ordinary texture path instead of throwing, and a texture of the surface's own extent and R32F/R16 must still hit DepthSurface::Sampled. The new tests must fail on main.
  • DepthSurface.cpp:178-179: please pin the "raw depth bits" exception (DepthBitsTextureWidth) with a test row too, so the !depthBits branch is covered both ways.
  • @hugodearaujo reports (Silksong, PPSA12544) the same reuse on the stencil plane with an R8G8B8A8 view, which this PR leaves as is. If you add the R8_UINT check for the stencil plane here, add a test row for it as well. Otherwise it is a separate PR.
  • CI covers the build only; the title runs (PPSA16064 / PPSA01325 / PPSA12544) are not something we can reproduce, hence the test request.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5476363541 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1495#pullrequestreview-5476363541). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-09T23:37:14Z. **Review:** CHANGES_REQUESTED --- Thanks for the fix, and for the title logs. The rule looks right to me, but it needs a test before it can merge: - No test covers this. Fixes for a title-specific crash need a Linux test that reproduces the case (CONTRIBUTING: tests next to their component, registered in ctest). Suggested cases in the existing `libSceAgcDriver` graphics tests: a depth surface plus a texture at the same address with (a) a different extent, (b) the same extent but a colour format that cannot hold the plane (e.g. R11G11B10), (c) a 2D array view of a different extent (the Astro's Playroom case reported by @orbz22). Each must go through the ordinary texture path instead of throwing, and a texture of the surface's own extent and R32F/R16 must still hit `DepthSurface::Sampled`. The new tests must fail on `main`. - `DepthSurface.cpp:178-179`: please pin the "raw depth bits" exception (`DepthBitsTextureWidth`) with a test row too, so the `!depthBits` branch is covered both ways. - @hugodearaujo reports (Silksong, PPSA12544) the same reuse on the stencil plane with an R8G8B8A8 view, which this PR leaves as is. If you add the `R8_UINT` check for the stencil plane here, add a test row for it as well. Otherwise it is a separate PR. - CI covers the build only; the title runs (PPSA16064 / PPSA01325 / PPSA12544) are not something we can reproduce, hence the test request.
TideOPL commented 2026-10-10 00:21:11 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by TideOPL on 2026-10-10T00:21:11Z.


Thanks. I added RunDepthSurfaceReuseTests to agc_driver_graphics (tests/DepthSurfaceReuse.cpp, mock device, no GPU needed). It registers a 384x384 D32 and a 256x256 D16 surface:

  • (a) R32F view at 192x192 → null (ordinary texture path)
  • (b) R11G11B10 view at the surface's own extent → null
  • (c) 2D array view at 512x512, 6 layers → null
  • R32F view of the D32 surface and R16 view of the D16 surface at their own extents → DepthSurface::Sampled
  • raw depth bits: R32 uint (D32) and R16 uint (D16) views in a depth tile layout → Sampled; R32 uint in a render-target layout → null
  • R32F view of the D16 surface → null

On current main it fails in Sampled ("sampling the depth plane ... is not implemented"). Full ctest passes on Linux and Windows. I left the stencil-plane check for a separate PR.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6091539855 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1495#issuecomment-6091539855). Originally posted by [TideOPL](https://github.com/TideOPL) on 2026-10-10T00:21:11Z. --- Thanks. I added `RunDepthSurfaceReuseTests` to `agc_driver_graphics` (`tests/DepthSurfaceReuse.cpp`, mock device, no GPU needed). It registers a 384x384 D32 and a 256x256 D16 surface: - (a) R32F view at 192x192 → null (ordinary texture path) - (b) R11G11B10 view at the surface's own extent → null - (c) 2D array view at 512x512, 6 layers → null - R32F view of the D32 surface and R16 view of the D16 surface at their own extents → `DepthSurface::Sampled` - raw depth bits: R32 uint (D32) and R16 uint (D16) views in a depth tile layout → `Sampled`; R32 uint in a render-target layout → null - R32F view of the D16 surface → null On current `main` it fails in `Sampled` ("sampling the depth plane ... is not implemented"). Full ctest passes on Linux and Windows. I left the stencil-plane check for a separate PR.
adriadam10 commented 2026-10-10 01:04:11 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T01:04:11Z.

Review: APPROVED


Thanks for the test. Checked: the new cases pass, and they fail with DepthSurface.cpp reverted (negative check); libSceAgcDriver ctest 270/270 green on current main. Merging once CI is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5476775783 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1495#pullrequestreview-5476775783). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T01:04:11Z. **Review:** APPROVED --- Thanks for the test. Checked: the new cases pass, and they fail with `DepthSurface.cpp` reverted (negative check); `libSceAgcDriver` ctest 270/270 green on current main. Merging once CI is green.
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!1495
No description provided.