Skip to content

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

Merged
oneandonlydean merged 2 commits into
boykopovar:mainfrom
milescoviello:fix/agc-layered-depth-storage-no-empty-entry
Nov 27, 2026
Merged

oneandonlydean merged 2 commits into
boykopovar:mainfrom
milescoviello:fix/agc-layered-depth-storage-no-empty-entry

Conversation

@milescoviello

@milescoviello milescoviello commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

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 fix(agc): copy only the viewed slices of a 2D array over a depth surface #22778 or feat(agc): test the depth bounds in the pixel program when the device lacks the depthBounds feature #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 fix(shader): give converted image stores the cube-face mode again #22534 and feat(agc): draw into 2_10_10_10 UINT color targets #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

…t throws

layeredDepthStorage inserted its map entry before constructing the
LayeredDepthStorage. When the constructor threw (StorageTexture::Create
refusing the view), the map kept a null entry, and the next
DepthSurfaceStoreBack dereferenced it while walking the map. Construct
the storage first and insert it only when that succeeds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@domx4q

domx4q commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

Ran the depth storage tests on NVIDIA's proprietary Linux driver with the Khronos validation layer; the description's RTX 4070 Ti run names no validation-layer run.

Setup: Arch Linux (kernel 7.3.4), GCC 16.2.1, Release, NVIDIA GeForce RTX 4090 (vendor 0x10de, device 0x2684, Ada), proprietary driver 620.70.06, Vulkan 1.4.357, Khronos validation layer 1.4.363.1. Head 6db22413e4 merged onto main 34369467e4 with --no-ff, clean merge. Main baseline is a Release build of 34369467e4 on the same machine.

WAYLAND_DISPLAY=wayland-1 XDG_RUNTIME_DIR=/run/user/1000 DISPLAY=:0 ANYPS5_REQUIRE_DISPLAY=1 \
ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer \
ctest --test-dir build -R '^agc_driver_depth_storage' -V
main 34369467e4 this PR
Result 7/7 passed 7/7 passed
Insert instance layer "VK_LAYER_KHRONOS_validation" 7 7
was not found but was requested by env var VK_INSTANCE_LAYERS 0 0
VUID- none none

All seven tests select the RTX 4090; none skips. On main, agc_driver_depth_storage is the unchanged test, so the new layered-view check only runs on the PR side.

Negative control: this PR's tree with DepthSurface.cpp from main (new test kept) fails agc_driver_depth_storage with [libc] fatal SIGSEGV (code 1) at address 0x00000000000007d8, the same address as in the description, also with no VUID- lines.

No new VUID- errors; all seven depth storage tests pass on Ada, and the new check fails without the fix.

AI-assisted: yes (Claude Code)

@milescoviello

Copy link
Copy Markdown
Contributor Author

@domx4q thanks for the RTX 4090 run with the validation layer: all seven depth storage tests pass with no VUID- lines, and the negative control crashes at the same 0x7d8. Added to Tested and the GPUs tested line.

AI-assisted: yes

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

…ge test

The test now checks that the three-layer view under a two-layer limit is
refused, so it fails if its setup stops reaching the failed construction
that the store back after it walks past.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@milescoviello

Copy link
Copy Markdown
Contributor Author

@MarcZX10 thanks, done in f26c5230de (test only): the three-layer view under the two-layer limit now goes through the file's ExpectFailure with maxImageArrayLayers, so the test fails if its setup stops reaching the failed construction. It passes 3 of 3 on Linux, and with main's DepthSurface.cpp it still ends in SIGSEGV at 0x7d8.

AI-assisted: yes

@Colewiz7

Copy link
Copy Markdown
Contributor

Head f26c5230de merged onto main 50d85e27bc as 7fdff8f081, no conflict. Linux 7.3.4, GCC 16.2.1 Release, Mesa 26.2.6 RADV, RX 7900 XT (gfx1100) and 7800X3D iGPU (gfx1036).

No new failures and no new validation messages on either GPU.

RX 7900 XT iGPU
tests run (6333 on the 7900 XT, the 2033 GPU ones on the iGPU), new failures vs main none none
-R '^agc' ( tests) with the layer, new failures vs main none none
VUID- / SYNC-HAZARD lines 0 / 0 0 / 0

Layer runs used VK_LAYER_KHRONOS_validation 1.4.363.1 with VK_LOADER_DEBUG=layer and ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1; the loader inserted the layer in every run, and the set of distinct validation messages matches main.

AI-assisted: yes

@milescoviello

Copy link
Copy Markdown
Contributor Author

@Colewiz7 thanks for running f26c5230de on RADV with the RX 7900 XT and the iGPU: no new failures and no VUID- or SYNC-HAZARD lines on either. Added to Tested and the GPUs tested line.

AI-assisted: yes

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@milescoviello

Copy link
Copy Markdown
Contributor Author

Thanks for the review, @MarcZX10.

I'd like to keep the substring. The second half of the test (the store back through the unrelated image) only means something if the layered storage failed for the reason under test: the three-layer view over a two-layer limit (Texture.cpp, "a texture array with more layers than maxImageArrayLayers is not implemented"). If construction failed for another reason, for example a missing device feature or a different Require on the way, a bare "it threw" check would still pass and the store-back half would be testing a different state. Matching the message also follows the other ExpectFailure calls in DepthStorage.cpp, which all match on part of the error. If that wording changes, the test will point at it straight away.

@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

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
PR 1395 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 6808 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 7256 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 7642 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 9508 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 9895 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 9950 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 10193 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 10469 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 10492 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 10497 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 11444 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 11551 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 13863 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 13920 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 13928 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 13929 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 15621 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 19557 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 20041 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 20315 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 22062 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 22531 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 22647 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 24083 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 25534 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 25610 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp

@kiwe147

kiwe147 commented Nov 21, 2026

Copy link
Copy Markdown

Tested head f26c5230de, applied with git apply on main fd4aeed483 together with the other 29 PRs of one batch (#24470, #24601, #17439, #17546, #21117, #21261, #21741, #21995, #22067, #22398, #23111, #23346, #24377, #24475, #24556, #14106, #14109, #19966, #20050, #20161, #20622, #21237, #22215, #22764, #22884, #22938, #23745, #24399, #24460). All applied without conflicts and the whole tree built.

Setup: Windows 11 Pro 10.0.26200, Ryzen 7 9800X3D, WinLibs GCC 15.2.0 r7, Release, BUILD_TESTING=ON. GPUs: NVIDIA GeForce RTX 3080 (driver 621.24) and the AMD Radeon iGPU of the CPU (gfx1036, driver 32.0.21036.18). No validation layer. iGPU run: ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 ANYPS5_GPU="AMD Radeon", agc_/video tests only.

tests RTX 3080 iGPU
agc_driver_depth_storage, agc_driver_depth_storage_copies, agc_driver_depth_storage_dispatch and 3 more (6 tests, matched by name to the test file this PR changes) all pass all pass

Whole batch: the full ctest -j 12 (6525 tests) on the RTX 3080 has 5 failing tests; the 4 that also fail on main fd4aeed483 are agc_driver_stencil_plane_memory, agc_driver_msaa_dcc_unwatch, agc_storage_write_back_host_retile, and pr_overlap_names, which needs a newer Python than my 3.10. Traced to other PRs of the batch, each by reverting it and testing again: #21117 (guest_pad); none is in this PR's area. The 2125 agc_/video tests on the iGPU have 1 failing: agc_driver_stencil_plane_memory (agc_driver_stencil_plane_memory also fails on main).

This is one combined tree, not a run of this PR alone.

AI-assisted: yes (Claude Code)

@milescoviello

Copy link
Copy Markdown
Contributor Author

Thanks @kiwe147 for including this one in the batch. The agc_driver_depth_storage* tests on both GPUs passing is a useful Windows data point, and I added it to the description, noted as a combined batch tree rather than this PR alone.

@oneandonlydean
oneandonlydean merged commit c282d4f into boykopovar:main Nov 27, 2026
24 of 27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc*

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants