fix(agc): leave no empty layered depth storage behind when building it throws #23864

Merged
milescoviello merged 2 commits from upstream-pr/23864 into main 2026-11-27 07:06:39 +00:00
milescoviello commented 2026-11-19 20:13:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-11-19T20:13:06Z.


What

layeredDepthStorage (DepthSurface.cpp) inserted its layeredStorages() entry with operator[] and only then constructed the LayeredDepthStorage into it. When the constructor threw, for example because StorageTexture::Create refuses the view or an allocation fails, the map kept the key with a null unique_ptr. The next DepthSurfaceStoreBack walks every entry and reads entry->storage, so it crashed on that null entry.

Crimson Desert (PPSA25286) hit this in one run. On main it first stops on the cube-face image store that #22534 fixes. With #22534, #22609 and #22778 (all open) on main 7c836568c, it crashed at 361 s with fatal SIGSEGV (code 1) at address 0x00000000000007d8, right after a 39 GB storage texture was placed in host memory and a 75 GB texture-cache release request freed nothing. 0x7d8 is offsetof(LayeredDepthStorage, storage), measured with a struct that has the class's data members in order (Context, 0x760 bytes; DepthTarget, 0x58; the extent, the three layer counts and the layer pitch), so the crash is the read of storage through a null entry. Later runs of the same stack ended earlier in other crashes. #22534 and #22609 have merged since, and round 37 of my rotation on plain main 21baa27bf ended the same way within 520 s. It hit fatal SIGSEGV (code 1) at address 0x00000000000007d8 in DepthSurfaceStoreBack, called from ShaderResources::MarkGpuWrites, right after the same 39,397,711,872-byte storage texture and a 75,145 MiB release request that freed nothing. I haven't run the title with this change on that main.

The change: look the key up, construct the storage, and insert it only when construction succeeds. An existing entry is refreshed as before. A failed construction now propagates its own error and leaves the map as it was.

This doesn't change why that title's construction fails, which I haven't pinned down: the 39 GB storage texture before it comes from another path (a later run with #23880 still makes it), so the failure is likely allocation pressure rather than this view itself.

Tested

Linux (Ubuntu 26.04.1, kernel 7.0), GCC 15.2, Ninja, Release, -DBUILD_TESTING=ON, RTX 4070 Ti on NVIDIA 615.71:

  • agc_driver_depth_storage (tests/execution/DepthStorage.cpp) gains a layered view whose construction fails: a copy of the test's context with maxImageArrayLayers lowered to 2, and a three-slice 2D array view of the depth plane, so StorageTexture::Create throws inside the LayeredDepthStorage constructor; the test requires that refusal, so it fails if the setup stops reaching the failed construction. It then runs its existing last check, a store back of an unrelated storage image, which walks the whole map and must return false.
  • agc_driver_depth_storage passes 3 runs on f26c5230de (and on 6db22413e4 before the test required the refusal).
  • Negative control: with main's DepthSurface.cpp and the new test, it ends in fatal SIGSEGV (code 1) at address 0x00000000000007d8, the same address as the title's crash.
  • Windows 11 (VM, GeForce GT 1030, WinLibs GCC 16.2, Ninja, Release, ANYPS5_REQUIRE_VULKAN=1): agc_driver_depth_storage passes 3 runs on 6db22413e4.
  • NVIDIA Ada with the validation layer: domx4q's RTX 4090 run (Linux, driver 620.70.06, Khronos validation layer 1.4.363.1) of 6db22413e4 merged onto main 34369467e4: all 7 agc_driver_depth_storage* tests pass with the layer inserted and no VUID- lines; with main's DepthSurface.cpp the new check ends in SIGSEGV at 0x7d8.
  • AMD: Colewiz7's Linux RADV run of f26c5230de merged onto main 50d85e27bc (Mesa 26.2.6, RX 7900 XT and 7800X3D iGPU, Khronos validation layer 1.4.363.1): no new failures against main in the full suite on the 7900 XT or the GPU tests on the iGPU, and no VUID- or SYNC-HAZARD lines.
  • git merge-tree against main is clean, and git apply -3 of this diff onto main with #22778 or #11551 merged is clean. tools/check_conventions.py passes on the branch and this body.
  • kiwe147's batch run of f26c5230de, applied with other PRs onto main fd4aeed483 (one combined tree, not this PR alone), Windows 11, WinLibs GCC 15.2.0 r7, Release, no validation layer: the 6 agc_driver_depth_storage* tests pass on an NVIDIA GeForce RTX 3080 (driver 621.24) and on the AMD Radeon iGPU of a Ryzen 7 9800X3D (gfx1036).
  • Plain main now reaches the crash, since #22534 and #22609 are merged: on main 66f88154a, a 600 s Crimson Desert (PPSA25286) run crashed at 272 s with fatal SIGSEGV (code 1) at address 0x00000000000007e0 (0x7d8 on the earlier build), with rip at libSceAgcDriver.prx+0x69277b. addr2line on that build resolves it to AgcDriver::Graphics::DepthSurfaceStoreBack, called from ShaderResources::MarkGpuWrites. The crash came right after vkAllocateMemory storage texture: ... 39397711872 bytes placed in host memory type 0 and a 75,145 MiB texture-cache release request that freed nothing.

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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: none (Crimson Desert's crash becomes the construction error; I haven't run the title with this change yet)
  • GPUs tested: NVIDIA RTX 4070 Ti (Linux), NVIDIA GeForce GT 1030 (Windows), NVIDIA RTX 4090 (Linux) by domx4q, AMD RX 7900 XT and 7800X3D iGPU (Linux RADV) by Colewiz7; NVIDIA RTX 3080 (Windows, kiwe147, batch tree); Ryzen 7 9800X3D iGPU (Windows, kiwe147, batch tree)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5402200415 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/23864). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-11-19T20:13:06Z. --- ### What `layeredDepthStorage` (`DepthSurface.cpp`) inserted its `layeredStorages()` entry with `operator[]` and only then constructed the `LayeredDepthStorage` into it. When the constructor threw, for example because `StorageTexture::Create` refuses the view or an allocation fails, the map kept the key with a null `unique_ptr`. The next `DepthSurfaceStoreBack` walks every entry and reads `entry->storage`, so it crashed on that null entry. Crimson Desert (PPSA25286) hit this in one run. On `main` it first stops on the cube-face image store that #22534 fixes. With #22534, #22609 and #22778 (all open) on `main` `7c836568c`, it crashed at 361 s with `fatal SIGSEGV (code 1) at address 0x00000000000007d8`, right after a 39 GB storage texture was placed in host memory and a 75 GB texture-cache release request freed nothing. `0x7d8` is `offsetof(LayeredDepthStorage, storage)`, measured with a struct that has the class's data members in order (`Context`, `0x760` bytes; `DepthTarget`, `0x58`; the extent, the three layer counts and the layer pitch), so the crash is the read of `storage` through a null entry. Later runs of the same stack ended earlier in other crashes. #22534 and #22609 have merged since, and round 37 of my rotation on plain `main` `21baa27bf` ended the same way within 520 s. It hit `fatal SIGSEGV (code 1) at address 0x00000000000007d8` in `DepthSurfaceStoreBack`, called from `ShaderResources::MarkGpuWrites`, right after the same 39,397,711,872-byte storage texture and a 75,145 MiB release request that freed nothing. I haven't run the title with this change on that `main`. The change: look the key up, construct the storage, and insert it only when construction succeeds. An existing entry is refreshed as before. A failed construction now propagates its own error and leaves the map as it was. This doesn't change why that title's construction fails, which I haven't pinned down: the 39 GB storage texture before it comes from another path (a later run with #23880 still makes it), so the failure is likely allocation pressure rather than this view itself. ### Tested Linux (Ubuntu 26.04.1, kernel 7.0), GCC 15.2, Ninja, Release, `-DBUILD_TESTING=ON`, RTX 4070 Ti on NVIDIA 615.71: - `agc_driver_depth_storage` (`tests/execution/DepthStorage.cpp`) gains a layered view whose construction fails: a copy of the test's context with `maxImageArrayLayers` lowered to 2, and a three-slice 2D array view of the depth plane, so `StorageTexture::Create` throws inside the `LayeredDepthStorage` constructor; the test requires that refusal, so it fails if the setup stops reaching the failed construction. It then runs its existing last check, a store back of an unrelated storage image, which walks the whole map and must return false. - `agc_driver_depth_storage` passes 3 runs on `f26c5230de` (and on `6db22413e4` before the test required the refusal). - Negative control: with `main`'s `DepthSurface.cpp` and the new test, it ends in `fatal SIGSEGV (code 1) at address 0x00000000000007d8`, the same address as the title's crash. - Windows 11 (VM, GeForce GT 1030, WinLibs GCC 16.2, Ninja, Release, `ANYPS5_REQUIRE_VULKAN=1`): `agc_driver_depth_storage` passes 3 runs on `6db22413e4`. - NVIDIA Ada with the validation layer: domx4q's [RTX 4090 run](https://github.com/boykopovar/AnyPS5/pull/23864#issuecomment-7023582942) (Linux, driver 620.70.06, Khronos validation layer 1.4.363.1) of `6db22413e4` merged onto `main` `34369467e4`: all 7 `agc_driver_depth_storage*` tests pass with the layer inserted and no `VUID-` lines; with `main`'s `DepthSurface.cpp` the new check ends in SIGSEGV at `0x7d8`. - AMD: Colewiz7's [Linux RADV run](https://github.com/boykopovar/AnyPS5/pull/23864#issuecomment-7027526904) of `f26c5230de` merged onto `main` `50d85e27bc` (Mesa 26.2.6, RX 7900 XT and 7800X3D iGPU, Khronos validation layer 1.4.363.1): no new failures against `main` in the full suite on the 7900 XT or the GPU tests on the iGPU, and no `VUID-` or `SYNC-HAZARD` lines. - `git merge-tree` against `main` is clean, and `git apply -3` of this diff onto `main` with #22778 or #11551 merged is clean. `tools/check_conventions.py` passes on the branch and this body. - kiwe147's [batch run](https://github.com/boykopovar/AnyPS5/pull/23864#issuecomment-7062719440) of `f26c5230de`, applied with other PRs onto `main` `fd4aeed483` (one combined tree, not this PR alone), Windows 11, WinLibs GCC 15.2.0 r7, Release, no validation layer: the 6 `agc_driver_depth_storage*` tests pass on an NVIDIA GeForce RTX 3080 (driver 621.24) and on the AMD Radeon iGPU of a Ryzen 7 9800X3D (gfx1036). - Plain `main` now reaches the crash, since #22534 and #22609 are merged: on `main` `66f88154a`, a 600 s Crimson Desert (PPSA25286) run crashed at 272 s with `fatal SIGSEGV (code 1) at address 0x00000000000007e0` (0x7d8 on the earlier build), with `rip` at `libSceAgcDriver.prx+0x69277b`. `addr2line` on that build resolves it to `AgcDriver::Graphics::DepthSurfaceStoreBack`, called from `ShaderResources::MarkGpuWrites`. The crash came right after `vkAllocateMemory storage texture: ... 39397711872 bytes placed in host memory type 0` and a 75,145 MiB texture-cache release request that freed nothing. ### 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) and the licence notice of code adapted from upstream (see AGENTS.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: none (Crimson Desert's crash becomes the construction error; I haven't run the title with this change yet) - [x] GPUs tested: NVIDIA RTX 4070 Ti (Linux), NVIDIA GeForce GT 1030 (Windows), NVIDIA RTX 4090 (Linux) by domx4q, AMD RX 7900 XT and 7800X3D iGPU (Linux RADV) by Colewiz7; NVIDIA RTX 3080 (Windows, kiwe147, batch tree); Ryzen 7 9800X3D iGPU (Windows, kiwe147, batch tree) - [x] AI-assisted: yes
MarcZX10 commented 2026-11-19 22:31:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-19T22:31:54Z.

Review: COMMENTED


Reviewed — no blocking findings

The cache insertion now constructs the layered storage before adding its key, so a construction exception leaves no null entry; I have one optional test-coverage point.

What I ran

Reviewed head 6db22413e40b8ec0ce1652bec5fc21ce4ae3a6c1. Read the prepared description, commit summary, manifest, diff, and the changed function and test context through repo_read.py. No tests were run.

Results

Check Result Note
Patch review passed Inspected both changed hunks
Tests not run Reported runs are author supplied

Findings

Blocking

None identified in the inspected hunks.

Non-blocking

  • core/libs/prx/libSceAgcDriver/tests/execution/DepthStorage.cpp:315: the test silently catches the expected construction exception and continues even if construction succeeds. Consider asserting that the exception occurred, so the regression test fails if the setup no longer triggers the failure path.

Not verified

The full contents of both changed files and excluded files were not read. Tests and author-reported environment results were not independently verified.

To get this to a good state

Nothing is required. Optional: assert that the construction attempt throws, as noted above.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5984468020 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/23864#pullrequestreview-5984468020). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-19T22:31:54Z. **Review:** COMMENTED --- # Reviewed — no blocking findings The cache insertion now constructs the layered storage before adding its key, so a construction exception leaves no null entry; I have one optional test-coverage point. ## What I ran Reviewed head `6db22413e40b8ec0ce1652bec5fc21ce4ae3a6c1`. Read the prepared description, commit summary, manifest, diff, and the changed function and test context through `repo_read.py`. No tests were run. ## Results | Check | Result | Note | |---|---|---| | Patch review | passed | Inspected both changed hunks | | Tests | not run | Reported runs are author supplied | ## Findings ### Blocking None identified in the inspected hunks. ### Non-blocking - `core/libs/prx/libSceAgcDriver/tests/execution/DepthStorage.cpp:315`: the test silently catches the expected construction exception and continues even if construction succeeds. Consider asserting that the exception occurred, so the regression test fails if the setup no longer triggers the failure path. ## Not verified The full contents of both changed files and excluded files were not read. Tests and author-reported environment results were not independently verified. ## To get this to a good state Nothing is required. Optional: assert that the construction attempt throws, as noted above.
MarcZX10 commented 2026-11-20 04:41:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T04:41:37Z.

Review: COMMENTED


Reviewed — no blocking findings

Nothing blocks this change; the optional point below is for clarity.

What I ran

Reviewed head f26c5230deb76f11a3dfc9baf96d398e95b90321 using repo_read.py. I read description.md, commits.md, manifest.json, diff.patch, and both changed files at the relevant code ranges. No commands or tests were run. Author-reported test results were not independently verified.

Results

Check Result Note
Changed code review passed Both changed files read
Tests not run Results in description only
Excluded files not applicable files.json was not available in the prepared bundle

Findings

Blocking

None.

Non-blocking

  • DepthStorage.cpp:315 expects the failure message to contain maxImageArrayLayers. Consider checking only that construction fails, or assert a more stable error contract if message text is not intended as API. The test otherwise exercises the failed layered-storage construction and subsequent store-back path.

Not verified

The reported Linux, Windows, NVIDIA, AMD, validation-layer, negative-control, merge-preview, and convention-check results were not run or independently confirmed. files.json was unavailable, so excluded-file details were not verified. Files read: core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp and core/libs/prx/libSceAgcDriver/tests/execution/DepthStorage.cpp. The manifest lists both changed files as included; no other changed files were listed.

To get this to a good state

Nothing is required. Optional: avoid coupling the test to the exact maxImageArrayLayers diagnostic unless that wording is part of the intended contract.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5987590319 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/23864#pullrequestreview-5987590319). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-20T04:41:37Z. **Review:** COMMENTED --- # Reviewed — no blocking findings Nothing blocks this change; the optional point below is for clarity. ## What I ran Reviewed head `f26c5230deb76f11a3dfc9baf96d398e95b90321` using `repo_read.py`. I read `description.md`, `commits.md`, `manifest.json`, `diff.patch`, and both changed files at the relevant code ranges. No commands or tests were run. Author-reported test results were not independently verified. ## Results | Check | Result | Note | |---|---|---| | Changed code review | passed | Both changed files read | | Tests | not run | Results in description only | | Excluded files | not applicable | `files.json` was not available in the prepared bundle | ## Findings ### Blocking None. ### Non-blocking - `DepthStorage.cpp:315` expects the failure message to contain `maxImageArrayLayers`. Consider checking only that construction fails, or assert a more stable error contract if message text is not intended as API. The test otherwise exercises the failed layered-storage construction and subsequent store-back path. ## Not verified The reported Linux, Windows, NVIDIA, AMD, validation-layer, negative-control, merge-preview, and convention-check results were not run or independently confirmed. `files.json` was unavailable, so excluded-file details were not verified. Files read: `core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp` and `core/libs/prx/libSceAgcDriver/tests/execution/DepthStorage.cpp`. The manifest lists both changed files as included; no other changed files were listed. ## To get this to a good state Nothing is required. Optional: avoid coupling the test to the exact `maxImageArrayLayers` diagnostic unless that wording is part of the intended contract.
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!23864
No description provided.