fix(agc): treat a view past a depth surface's first level as memory #5982

Merged
milescoviello merged 1 commit from upstream-pr/5982 into main 2026-10-16 23:15:56 +00:00
milescoviello commented 2026-10-14 18:15:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-14T18:15:17Z.


What

Forspoken (PPSA03984) builds a depth pyramid from its 1984x1116 D32_SFLOAT_S8_UINT depth surface: a compute shader samples one level of a five-level R32F view at the surface's address and stores the next. It stops at the first sample:

compute shader 0x900857a300: AGC graphics: sampling the depth plane of depth surface 0xa22c1b0000 (1984x1116, vk format 130) as a 1984x1116 texture of guest format 22 (vk 100), tile mode 7, dimension 1, levels 1-1, slice 0 is not implemented

A depth surface is one level here, because the driver rejects draws that render a depth mip (DB_DEPTH_VIEW MIP_LEVEL). A view at the surface's address and extent that starts at a later level does not read or write that level, so it is not the depth plane: what it reaches was written by other GPU work or the CPU. DepthSurfaceTexture and DepthSurfaceStorage sent such views to the surface anyway, and the surface rejected the level. They now return no surface for a sampled or storage view that starts past the first level, or a storage access to a later level. The texture and storage caches then read it from memory, as they already do for a view of another extent or format. The level check in RequireStorable can no longer fail and is removed.

A view that starts at the first level and also covers later levels is unchanged: it still includes the depth plane, and sampling it is still rejected.

agc_driver_graphics gains a five-level R32F view of a D32 surface's own extent: its first level must still sample the depth plane, and a view of level 1 must be read as memory. In agc_driver_depth_storage, a storage access to level 1 and a storage and a sampled view of level 1 must leave the depth surface alone. The storage check there expected "not implemented" before. With main's DepthSurface.cpp the graphics test stops with the "levels 1-1" error above and the storage test with "storage image access to level 1 of the depth plane".

Tested

Ubuntu 24.04, GCC 13.3 (CI's compiler), Release with CI's configure flags, on main ed835aa76, RTX 4070 Ti with NVIDIA 595.99.02:

  • All 551 tests in libSceAgcDriver pass. agc_driver_stencil_ref_export is skipped because the device lacks VK_EXT_shader_stencil_export, and agc_host_import_sparse and agc_driver_sparse_dma_buf_import because /dev/udmabuf is not accessible here.
  • Forspoken (PPSA03984), relinked with --to-intel and run on Linux under a 15 GiB memory cap, measured on main 4d5411d7b. All builds carry #5937, #5511 and #5975, which the title needs to get this far, start from the same filled shader cache and differ only in libSceAgcDriver.prx:
    • Without this change, three runs: one stops on the error above at 68 s; the others end at 106 s at the memory cap and at 111 s when vkAllocateMemory runs out of device memory for a storage texture.
    • With only the sampled half of this change: stops at 68 s on storage image access to level 1 of the depth plane of depth surface 0xa22af20000 is not implemented.
    • With this change, two runs: no rejection of a later level, and both reach the memory cap, at 87 s and 90 s. A third run with a temporary counter added (not part of this PR) logged sampled views of levels 1 and 2 of the depth surface being read from memory, and stopped at 92 s on the next case, a view of levels 0-4 of the same surface.
  • tools/check_conventions.py --base upstream/main passes, and tools/pr_overlap.py --branch finds no overlap.
  • Forspoken (PPSA03984, PPSA03984-app0) on current main 8856f180c, 1920x1080, pad input, one run each: main stops at 22 s on the DB_RENDER_CONTROL check (#5937); with #5937 it stops at 61 s on the indirect vertex buffer read (#5975); with #5937 and #5975 at 116 s on the depth pyramid view (#5982); with all three it draws an in-game scene by 60 s (the lower half still black, about 4 FPS) and runs to 195 s, where vkAllocateMemory for a render target fails with VK_ERROR_OUT_OF_DEVICE_MEMORY on the 12 GB RTX 4070 Ti. The memory goes to retired depth surfaces that are never freed. With #6465 added as well, it reaches a 600 s limit (on main 0c4816f61).

Not checked on Windows or on a console.

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
  • Unblocks: none
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4862403214 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5982). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-14T18:15:17Z. --- ### What Forspoken (PPSA03984) builds a depth pyramid from its 1984x1116 `D32_SFLOAT_S8_UINT` depth surface: a compute shader samples one level of a five-level R32F view at the surface's address and stores the next. It stops at the first sample: ``` compute shader 0x900857a300: AGC graphics: sampling the depth plane of depth surface 0xa22c1b0000 (1984x1116, vk format 130) as a 1984x1116 texture of guest format 22 (vk 100), tile mode 7, dimension 1, levels 1-1, slice 0 is not implemented ``` A depth surface is one level here, because the driver rejects draws that render a depth mip (`DB_DEPTH_VIEW MIP_LEVEL`). A view at the surface's address and extent that starts at a later level does not read or write that level, so it is not the depth plane: what it reaches was written by other GPU work or the CPU. `DepthSurfaceTexture` and `DepthSurfaceStorage` sent such views to the surface anyway, and the surface rejected the level. They now return no surface for a sampled or storage view that starts past the first level, or a storage access to a later level. The texture and storage caches then read it from memory, as they already do for a view of another extent or format. The level check in `RequireStorable` can no longer fail and is removed. A view that starts at the first level and also covers later levels is unchanged: it still includes the depth plane, and sampling it is still rejected. `agc_driver_graphics` gains a five-level R32F view of a D32 surface's own extent: its first level must still sample the depth plane, and a view of level 1 must be read as memory. In `agc_driver_depth_storage`, a storage access to level 1 and a storage and a sampled view of level 1 must leave the depth surface alone. The storage check there expected "not implemented" before. With `main`'s `DepthSurface.cpp` the graphics test stops with the "levels 1-1" error above and the storage test with "storage image access to level 1 of the depth plane". ### Tested Ubuntu 24.04, GCC 13.3 (CI's compiler), Release with CI's configure flags, on `main` ed835aa76, RTX 4070 Ti with NVIDIA 595.99.02: - All 551 tests in `libSceAgcDriver` pass. `agc_driver_stencil_ref_export` is skipped because the device lacks `VK_EXT_shader_stencil_export`, and `agc_host_import_sparse` and `agc_driver_sparse_dma_buf_import` because `/dev/udmabuf` is not accessible here. - Forspoken (PPSA03984), relinked with `--to-intel` and run on Linux under a 15 GiB memory cap, measured on `main` 4d5411d7b. All builds carry #5937, #5511 and #5975, which the title needs to get this far, start from the same filled shader cache and differ only in `libSceAgcDriver.prx`: - Without this change, three runs: one stops on the error above at 68 s; the others end at 106 s at the memory cap and at 111 s when `vkAllocateMemory` runs out of device memory for a storage texture. - With only the sampled half of this change: stops at 68 s on `storage image access to level 1 of the depth plane of depth surface 0xa22af20000 is not implemented`. - With this change, two runs: no rejection of a later level, and both reach the memory cap, at 87 s and 90 s. A third run with a temporary counter added (not part of this PR) logged sampled views of levels 1 and 2 of the depth surface being read from memory, and stopped at 92 s on the next case, a view of levels 0-4 of the same surface. - `tools/check_conventions.py --base upstream/main` passes, and `tools/pr_overlap.py --branch` finds no overlap. - Forspoken (PPSA03984, `PPSA03984-app0`) on current `main` 8856f180c, 1920x1080, pad input, one run each: `main` stops at 22 s on the `DB_RENDER_CONTROL` check (#5937); with #5937 it stops at 61 s on the indirect vertex buffer read (#5975); with #5937 and #5975 at 116 s on the depth pyramid view (#5982); with all three it draws an in-game scene by 60 s (the lower half still black, about 4 FPS) and runs to 195 s, where `vkAllocateMemory` for a render target fails with `VK_ERROR_OUT_OF_DEVICE_MEMORY` on the 12 GB RTX 4070 Ti. The memory goes to retired depth surfaces that are never freed. With #6465 added as well, it reaches a 600 s limit (on `main` 0c4816f61). Not checked on Windows or on a console. ### 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] Unblocks: none - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-15 12:12:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T12:12:44Z.


Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 1368 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
core/libs/prx/libSceAgcDriver/tests/DepthSurfaceReuse.cpp
PR 1395 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 5499 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
core/libs/prx/libSceAgcDriver/tests/execution/DepthStorage.cpp
PR 5987 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
core/libs/prx/libSceAgcDriver/tests/DepthSurfaceReuse.cpp
PR 6222 core/libs/prx/libSceAgcDriver/tests/execution/DepthStorage.cpp
PR 6553 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
core/libs/prx/libSceAgcDriver/tests/DepthSurfaceReuse.cpp
PR 6808 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6191759721 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5982#issuecomment-6191759721). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-15T12:12:44Z. --- <!-- pr-overlap --> Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap. | Pull request | Shared files not compared | |---|---| | [PR 1368](https://www.github.com/boykopovar/AnyPS5/pull/1368) | `core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp`<br>`core/libs/prx/libSceAgcDriver/tests/DepthSurfaceReuse.cpp` | | [PR 1395](https://www.github.com/boykopovar/AnyPS5/pull/1395) | `core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp` | | [PR 5499](https://www.github.com/boykopovar/AnyPS5/pull/5499) | `core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp`<br>`core/libs/prx/libSceAgcDriver/tests/execution/DepthStorage.cpp` | | [PR 5987](https://www.github.com/boykopovar/AnyPS5/pull/5987) | `core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp`<br>`core/libs/prx/libSceAgcDriver/tests/DepthSurfaceReuse.cpp` | | [PR 6222](https://www.github.com/boykopovar/AnyPS5/pull/6222) | `core/libs/prx/libSceAgcDriver/tests/execution/DepthStorage.cpp` | | [PR 6553](https://www.github.com/boykopovar/AnyPS5/pull/6553) | `core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp`<br>`core/libs/prx/libSceAgcDriver/tests/DepthSurfaceReuse.cpp` | | [PR 6808](https://www.github.com/boykopovar/AnyPS5/pull/6808) | `core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp` |
adriadam10 commented 2026-10-16 20:06:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-16T20:06:39Z.


Checked on main + this PR: libSceAgcDriver ctest passes except agc_driver_tessellation, which segfaults on RADV on main as well. With DepthSurface.cpp reverted, agc_driver_graphics and agc_driver_depth_storage fail, so the new checks do exercise the change. A view starting past level 0 now goes to memory, and level 0 of a mipmapped view still samples the depth plane. Merging once the full Build is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6223729481 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5982#issuecomment-6223729481). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-16T20:06:39Z. --- Checked on main + this PR: `libSceAgcDriver` ctest passes except `agc_driver_tessellation`, which segfaults on RADV on main as well. With `DepthSurface.cpp` reverted, `agc_driver_graphics` and `agc_driver_depth_storage` fail, so the new checks do exercise the change. A view starting past level 0 now goes to memory, and level 0 of a mipmapped view still samples the depth plane. Merging once the full Build 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!5982
No description provided.