fix(agc): place a layered depth storage view at the guest's layer pitch #8109

Merged
ebosido444-ai merged 2 commits from upstream-pr/8109 into main 2026-10-23 16:40:17 +00:00
ebosido444-ai commented 2026-10-19 22:01:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ebosido444-ai on 2026-10-19T22:01:40Z.


What

A 2D-array storage view over a depth surface is served as one storage image with a copy per layer, but each layer's depth surface was looked up at layer * DepthSliceBytes(extent, bytesPerTexel), and any other guest layer pitch was refused outright:

AGC graphics: storage image access to the depth planes of depth surface 0x… with a layer pitch of 0x4000 bytes, not the depth slice size 0x10000, is not implemented

That comparison is wrong in the ordinary case. DepthSliceBytes is the 64 KiB-aligned slice size the driver copies, while a linear (untilied) depth array's layer pitch is the texel-tight size — the case in tests/execution/DepthStorage.cpp, where the pitch is 0x4000 and the aligned slice is 0x10000. Nothing else in the file assumes the aligned size: the depth-plane sampling path already reads each layer at geometry.GuestLayerOffset(layer), and LayeredDepthStorage is built from that same DescribeSurface geometry.

The layer lookup now uses the descriptor geometry's layer pitch, stored with the layered storage, and the refusal is gone. The image, the per-layer copies, the store-back and the cache key are unchanged; only the address of layer N moves.

Tested

Windows 11 26200.8117, winlibs GCC 15.2.0, Ninja, Release. GPU: NVIDIA GeForce GTX 1650 Ti, driver 617.14 (Vulkan).

tests/execution/DepthStorage.cpp previously asserted the refusal ("a two-layer 2D array view of the depth plane with a layer pitch other than the depth slice size was accepted"). It now asserts that the view is taken with two image layers, that the plane's data reaches it, and that a view from layer 1 is taken too.

  • unmodified main: agc_driver_depth_storage exits 1 with AGC graphics: storage image access to the depth planes of depth surface … with a layer pitch of 0x4000 bytes, not the depth slice size 0x10000, is not implemented
  • with this change: agc_driver_depth_storage exits 0, depth surface storage access tests passed
  • neighbours with this change: agc_driver_depth_plane_guest_layers (passed), agc_driver_depth_storage_reuse (passed)

tests/execution/*.cpp targets and their ctest entries come from the existing glob, so no CMake change is part of this PR.

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 (no comment added)
  • Unimplemented paths throw (unchanged; this removes a refusal that had no unimplemented behaviour behind it)
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source (n/a)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none named; the refusal above is the stop, and it is the only one on this path
  • GPUs tested: NVIDIA GeForce GTX 1650 Ti, driver 617.14, Windows 11 26200.8117 (Vulkan)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4928012780 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8109). Originally posted by [ebosido444-ai](https://github.com/ebosido444-ai) on 2026-10-19T22:01:40Z. --- ### What A 2D-array storage view over a depth surface is served as one storage image with a copy per layer, but each layer's depth surface was looked up at `layer * DepthSliceBytes(extent, bytesPerTexel)`, and any other guest layer pitch was refused outright: ``` AGC graphics: storage image access to the depth planes of depth surface 0x… with a layer pitch of 0x4000 bytes, not the depth slice size 0x10000, is not implemented ``` That comparison is wrong in the ordinary case. `DepthSliceBytes` is the 64 KiB-aligned slice size the driver copies, while a linear (untilied) depth array's layer pitch is the texel-tight size — the case in `tests/execution/DepthStorage.cpp`, where the pitch is 0x4000 and the aligned slice is 0x10000. Nothing else in the file assumes the aligned size: the depth-plane sampling path already reads each layer at `geometry.GuestLayerOffset(layer)`, and `LayeredDepthStorage` is built from that same `DescribeSurface` geometry. The layer lookup now uses the descriptor geometry's layer pitch, stored with the layered storage, and the refusal is gone. The image, the per-layer copies, the store-back and the cache key are unchanged; only the address of layer N moves. ### Tested Windows 11 26200.8117, winlibs GCC 15.2.0, Ninja, Release. GPU: NVIDIA GeForce GTX 1650 Ti, driver 617.14 (Vulkan). `tests/execution/DepthStorage.cpp` previously asserted the refusal ("a two-layer 2D array view of the depth plane with a layer pitch other than the depth slice size was accepted"). It now asserts that the view is taken with two image layers, that the plane's data reaches it, and that a view from layer 1 is taken too. - unmodified `main`: `agc_driver_depth_storage` exits 1 with `AGC graphics: storage image access to the depth planes of depth surface … with a layer pitch of 0x4000 bytes, not the depth slice size 0x10000, is not implemented` - with this change: `agc_driver_depth_storage` exits 0, `depth surface storage access tests passed` - neighbours with this change: `agc_driver_depth_plane_guest_layers` (passed), `agc_driver_depth_storage_reuse` (passed) `tests/execution/*.cpp` targets and their ctest entries come from the existing glob, so no CMake change is part of this PR. ### 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 (no comment added) - [x] Unimplemented paths throw (unchanged; this removes a refusal that had no unimplemented behaviour behind it) - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source (n/a) - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: none named; the refusal above is the stop, and it is the only one on this path - [x] GPUs tested: NVIDIA GeForce GTX 1650 Ti, driver 617.14, Windows 11 26200.8117 (Vulkan) - [x] AI-assisted: yes
TheSovietWaffle commented 2026-10-20 07:38:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by TheSovietWaffle on 2026-10-20T07:38:54Z.


Tested on RTX 3080 (NVIDIA 617.42) and AMD Radeon RDNA 2 iGPU (1002:164e, 32.0.21045.5002), Windows 10 Pro 22H2, WinLibs GCC 15.2.0, Release, head 11cc05929: agc_driver_depth_storage passes 3 of 3 on both GPUs, so AMD (RDNA 2) and a second NVIDIA generation behave like the GTX 1650 Ti.

AI-assisted: yes (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6285918135 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8109#issuecomment-6285918135). Originally posted by [TheSovietWaffle](https://github.com/TheSovietWaffle) on 2026-10-20T07:38:54Z. --- Tested on RTX 3080 (NVIDIA 617.42) and AMD Radeon RDNA 2 iGPU (`1002:164e`, 32.0.21045.5002), Windows 10 Pro 22H2, WinLibs GCC 15.2.0, Release, head `11cc05929`: `agc_driver_depth_storage` passes 3 of 3 on both GPUs, so AMD (RDNA 2) and a second NVIDIA generation behave like the GTX 1650 Ti. AI-assisted: yes (Claude Code).
oneandonlydean commented 2026-10-21 00:41:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-21T00:41:42Z.


@ebosido444-ai Thanks, placing layer N at GuestLayerOffset(N) matches how the depth-plane sampling path already reads it, and the test covers the pitch != slice case. One question before merge:

Depth targets are always placed at slice * DepthSliceBytes (64 KiB aligned). When the view's layer pitch is smaller (the test's 0x4000 against 0x10000), view layers 1..3 fall inside layer 0's tracked depth surface without starting at it. layeredSlices matches surfaces by start address, so those layers aren't found and come from guest memory through StorageTexture::Create. If that depth surface holds data that hasn't been written back yet (rendered, store pending), the view would read stale bytes there. Main threw in this case, so nothing could read it stale before.

Could you confirm that the FlushPending at view creation also lands a tracked depth surface's pending bytes for a range that overlaps a view layer (a test that renders into layer 0's depth surface, then reads layer 1 of the view, would show it)? If it doesn't, please keep the refusal for the case where a tracked depth surface overlaps a view layer it doesn't start at.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6305100419 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8109#issuecomment-6305100419). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-21T00:41:42Z. --- @ebosido444-ai Thanks, placing layer N at `GuestLayerOffset(N)` matches how the depth-plane sampling path already reads it, and the test covers the pitch != slice case. One question before merge: Depth targets are always placed at `slice * DepthSliceBytes` (64 KiB aligned). When the view's layer pitch is smaller (the test's 0x4000 against 0x10000), view layers 1..3 fall *inside* layer 0's tracked depth surface without starting at it. `layeredSlices` matches surfaces by start address, so those layers aren't found and come from guest memory through `StorageTexture::Create`. If that depth surface holds data that hasn't been written back yet (rendered, store pending), the view would read stale bytes there. Main threw in this case, so nothing could read it stale before. Could you confirm that the `FlushPending` at view creation also lands a tracked depth surface's pending bytes for a range that overlaps a view layer (a test that renders into layer 0's depth surface, then reads layer 1 of the view, would show it)? If it doesn't, please keep the refusal for the case where a tracked depth surface overlaps a view layer it doesn't start at.
ebosido444-ai commented 2026-10-21 08:25:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ebosido444-ai on 2026-10-21T08:25:03Z.


Yes, it lands, and the case is now covered by a test rather than argued from the code.

FlushPending does not match pending images by start address: it walks the pending list and keeps every image whose guest range intersects the requested range (StorageTexture::overlaps, Graphics/src/Texture.cpp:3490, used at Texture.cpp:3661), then narrows to the images with a pending unit inside that range (pendingUnitInside, Texture.cpp:3633). A tracked depth surface that a view layer only overlaps is stored the same way as one the view starts at. There is a second call on the same path: StorageTexture::Create flushes the range again in its refresh (Texture.cpp:2057), so the store happens before the upload even without the constructor's call — disabling the constructor's FlushPending and rerunning still passes the new test, so the ordering does not rest on that line alone.

tests/execution/DepthStorage.cpp now covers your case: it fills a 64 KiB swizzled depth plane (kStandard64KB, guest 0x10000, pitch 0x10000) with 0.75 and does not store it back, marks the bytes of the layer that only overlaps the slice with a 0.375 sentinel, then takes a four-layer linear view at pitch 0x4000 over the same memory. It asserts that the pending 0.75 is in guest memory by the time the view exists, and that after the readback the overlapping layer still holds the 0.375 sentinel — the depth result reached the bytes the surface owns, and none of it leaked into the view layer that does not start at it.

I also found a hole in the assertion I had added: layerPitch + sliceBytes > BlockBytes || CountFloats(...) holds for this fixture, so the pitch check never ran. It runs now and asserts the added layer's content (the guest bytes at 0x4000, which the fixture leaves zero).

So I would not keep the refusal for the overlap-without-start case: the store covers it, and the test fails if neither flush reaches the range.

Ran on the GTX 1650 Ti, Windows 11, WinLibs GCC 15.2.0, ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 ctest --test-dir build -R agc_driver_depth_storage -V: agc_driver_depth_storage, _dispatch and _reuse all pass. There is no Khronos validation layer installed on this machine, so I could not run the VUID- comparison AGENTS.md asks for — say the word if you want that run before this goes in and I will install the layer and do it.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6311505852 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8109#issuecomment-6311505852). Originally posted by [ebosido444-ai](https://github.com/ebosido444-ai) on 2026-10-21T08:25:03Z. --- Yes, it lands, and the case is now covered by a test rather than argued from the code. `FlushPending` does not match pending images by start address: it walks the pending list and keeps every image whose guest range intersects the requested range (`StorageTexture::overlaps`, `Graphics/src/Texture.cpp:3490`, used at `Texture.cpp:3661`), then narrows to the images with a pending unit inside that range (`pendingUnitInside`, `Texture.cpp:3633`). A tracked depth surface that a view layer only overlaps is stored the same way as one the view starts at. There is a second call on the same path: `StorageTexture::Create` flushes the range again in its refresh (`Texture.cpp:2057`), so the store happens before the upload even without the constructor's call — disabling the constructor's `FlushPending` and rerunning still passes the new test, so the ordering does not rest on that line alone. `tests/execution/DepthStorage.cpp` now covers your case: it fills a 64 KiB swizzled depth plane (`kStandard64KB`, guest 0x10000, pitch 0x10000) with 0.75 and does not store it back, marks the bytes of the layer that only overlaps the slice with a 0.375 sentinel, then takes a four-layer linear view at pitch 0x4000 over the same memory. It asserts that the pending 0.75 is in guest memory by the time the view exists, and that after the readback the overlapping layer still holds the 0.375 sentinel — the depth result reached the bytes the surface owns, and none of it leaked into the view layer that does not start at it. I also found a hole in the assertion I had added: `layerPitch + sliceBytes > BlockBytes || CountFloats(...)` holds for this fixture, so the pitch check never ran. It runs now and asserts the added layer's content (the guest bytes at 0x4000, which the fixture leaves zero). So I would not keep the refusal for the overlap-without-start case: the store covers it, and the test fails if neither flush reaches the range. Ran on the GTX 1650 Ti, Windows 11, WinLibs GCC 15.2.0, `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 ctest --test-dir build -R agc_driver_depth_storage -V`: `agc_driver_depth_storage`, `_dispatch` and `_reuse` all pass. There is no Khronos validation layer installed on this machine, so I could not run the `VUID-` comparison AGENTS.md asks for — say the word if you want that run before this goes in and I will install the layer and do it. AI-assisted: yes.
ebosido444-ai commented 2026-10-21 08:58:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ebosido444-ai on 2026-10-21T08:58:40Z.


Follow-up on the VUID- comparison AGENTS.md asks for — I installed the validation layer here and ran it, so that gap is closed.

Machine: GTX 1650 Ti, Windows 11, WinLibs GCC 15.2.0, Release, BUILD_TESTING=ON. Layer: Khronos validation 1.4.363 from the Vulkan SDK, requested with VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation; the loader log confirms it was loaded (the was not found but was requested by env var VK_INSTANCE_LAYERS line does not appear).

  • main 50efb5c: ctest --test-dir build -R agc_driver_depth_storage -V with ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 — 3/3 passed, 0 VUID- lines.
  • This head 5a67ff9: same command — 3/3 passed, 0 VUID- lines.

So the change adds no validation errors, and the three depth storage tests behave the same on both trees. The new assertions above do not run on main at all, since the layered view throws there.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6312107559 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8109#issuecomment-6312107559). Originally posted by [ebosido444-ai](https://github.com/ebosido444-ai) on 2026-10-21T08:58:40Z. --- Follow-up on the `VUID-` comparison AGENTS.md asks for — I installed the validation layer here and ran it, so that gap is closed. Machine: GTX 1650 Ti, Windows 11, WinLibs GCC 15.2.0, Release, `BUILD_TESTING=ON`. Layer: Khronos validation 1.4.363 from the Vulkan SDK, requested with `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`; the loader log confirms it was loaded (the `was not found but was requested by env var VK_INSTANCE_LAYERS` line does not appear). - `main` `50efb5c`: `ctest --test-dir build -R agc_driver_depth_storage -V` with `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1` — 3/3 passed, 0 `VUID-` lines. - This head `5a67ff9`: same command — 3/3 passed, 0 `VUID-` lines. So the change adds no validation errors, and the three depth storage tests behave the same on both trees. The new assertions above do not run on `main` at all, since the layered view throws there. AI-assisted: yes.
ebosido444-ai commented 2026-10-22 10:11:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ebosido444-ai on 2026-10-22T10:11:33Z.


Heads-up: the conventions job had gone red on this head — my test added four explanatory comment lines, and this repo only allows comments that come with a debt file. They are removed in 2d7a8dab5 (the explanation lives here and in the commit message instead), so conventions, eligibility, labels and report all pass again and the PR is CLEAN.

Re-verified at 2d7a8dab5: agc_driver_depth_storage_tests builds in 15 s incremental and ctest -R agc_driver_depth_storage passes 3/3 with VK_LAYER_KHRONOS_validation loaded, 0 VUID- lines. Behaviour is unchanged — the diff is four deleted comment lines.

The open question above (view layers that only overlap the depth slice) is unchanged and still answered with the test at DepthStorage.cpp:274.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6338239804 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8109#issuecomment-6338239804). Originally posted by [ebosido444-ai](https://github.com/ebosido444-ai) on 2026-10-22T10:11:33Z. --- Heads-up: the `conventions` job had gone red on this head — my test added four explanatory comment lines, and this repo only allows comments that come with a debt file. They are removed in `2d7a8dab5` (the explanation lives here and in the commit message instead), so `conventions`, `eligibility`, `labels` and `report` all pass again and the PR is `CLEAN`. Re-verified at `2d7a8dab5`: `agc_driver_depth_storage_tests` builds in 15 s incremental and `ctest -R agc_driver_depth_storage` passes 3/3 with `VK_LAYER_KHRONOS_validation` loaded, 0 `VUID-` lines. Behaviour is unchanged — the diff is four deleted comment lines. The open question above (view layers that only overlap the depth slice) is unchanged and still answered with the test at `DepthStorage.cpp:274`. AI-assisted: yes.
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!8109
No description provided.