fix(agc): copy depth planes whose detiled rows are padded to the swizzle block #4722

Closed
alfalfa-star wants to merge 1 commit from upstream-pr/4722 into main
alfalfa-star commented 2026-10-12 19:45:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by alfalfa-star on 2026-10-12T19:45:27Z.


What

DepthPlaneCopy (from #425, now on main) refuses any depth plane whose linear layout was not tightly packed: geometry.sliceLinearBytes == sliceBytes(), where sliceBytes() is width × height × texel size.

Kena: Bridge of Spirits (PPSA01802) samples its point-light shadow maps as 128x128 D16 cubes, through an R16 view in a 64 KiB Z swizzle. That block holds 256x128 texels of 16 bits, so the detiled row is 512 bytes and a face is 64 KiB, while the copy assumed 256-byte rows and 32 KiB faces:

copy 128x128 D16 layers 6 slice 32768; resource 128x128 fmt 7 tile 4 dim 3 (cube); geometry layers 6 slice 65536 pitch 512

Every shadow projection draw that bound one was skipped, about 4,400 per 4-minute run. The scene was then lit as if no point light cast a shadow, and the image came out white or heavily overexposed.

  • The staging buffer is sized for the surface's linear layout, using the last face's LinearLayerOffset plus the first mip's pitch × height. It's reallocated, if the constructor's packed size is too small, only before the copy is first recorded; a later, larger layout is still refused.
  • Each face's region (in record, which only copies the layers that changed) uses LinearLayerOffset(layer) plus the mip's linearOffset, with bufferRowLength = pitch / texel size and bufferImageHeight = the mip's height. This now applies to both the slices copied from a live depth surface and the ones the detiler writes from guest memory, which already landed at LinearLayerOffset.
  • The geometry still has to match the copy's layer count, and a pitch narrower than the plane or a short mip still throws.

Tested

Arch Linux, KDE Plasma, GCC, Release, RADV (RX 9070 XT, Mesa 26.2.4), on main 0214069e3 (rebased onto main's reworked DepthPlaneCopy with kept guest layers).

  • New PaddedCubeCase in agc_driver_depth_plane_sampling: a 128x128 D16 cube read through a depth-bits R16_UINT T# in the 64 KiB Z swizzle. Face 0 comes from the live surface and faces 1-5 from guest memory, and each face reads its value. Without this commit it fails with depth plane copy geometry does not match its layers. The existing array/cube, integer, depth-bits array and first-slice cases still pass.
  • ctest -R '^agc_|^shader': 486/487. The one failure, agc_driver_tessellation (SEGFAULT), fails the same way on unmodified main 0214069e3 on this machine. All agc_driver_depth* tests and agc_driver_graphics pass. tools/check_conventions.py passes.
  • Kena in game (on the earlier version of this commit, before the rebase), on a local stack of main + #425 + #3763 + #3816 + #4031 + #4500 + #4586 plus local stand-ins. The depth plane copy refusals are gone, the shadowed scene has plausible exposure instead of a white frame, and there was no GPU hang.

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 (#425 is merged)
  • AI-assisted: yes (Claude Code)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4834225312 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4722). Originally posted by [alfalfa-star](https://github.com/alfalfa-star) on 2026-10-12T19:45:27Z. --- ### What `DepthPlaneCopy` (from #425, now on `main`) refuses any depth plane whose linear layout was not tightly packed: `geometry.sliceLinearBytes == sliceBytes()`, where `sliceBytes()` is width × height × texel size. Kena: Bridge of Spirits (PPSA01802) samples its point-light shadow maps as 128x128 D16 cubes, through an R16 view in a 64 KiB Z swizzle. That block holds 256x128 texels of 16 bits, so the detiled row is 512 bytes and a face is 64 KiB, while the copy assumed 256-byte rows and 32 KiB faces: ``` copy 128x128 D16 layers 6 slice 32768; resource 128x128 fmt 7 tile 4 dim 3 (cube); geometry layers 6 slice 65536 pitch 512 ``` Every shadow projection draw that bound one was skipped, about 4,400 per 4-minute run. The scene was then lit as if no point light cast a shadow, and the image came out white or heavily overexposed. - The staging buffer is sized for the surface's linear layout, using the last face's `LinearLayerOffset` plus the first mip's pitch × height. It's reallocated, if the constructor's packed size is too small, only before the copy is first recorded; a later, larger layout is still refused. - Each face's region (in `record`, which only copies the layers that changed) uses `LinearLayerOffset(layer)` plus the mip's `linearOffset`, with `bufferRowLength` = pitch / texel size and `bufferImageHeight` = the mip's height. This now applies to both the slices copied from a live depth surface and the ones the detiler writes from guest memory, which already landed at `LinearLayerOffset`. - The geometry still has to match the copy's layer count, and a pitch narrower than the plane or a short mip still throws. ### Tested Arch Linux, KDE Plasma, GCC, Release, RADV (RX 9070 XT, Mesa 26.2.4), on `main` 0214069e3 (rebased onto main's reworked `DepthPlaneCopy` with kept guest layers). - New `PaddedCubeCase` in `agc_driver_depth_plane_sampling`: a 128x128 D16 cube read through a depth-bits R16_UINT T# in the 64 KiB Z swizzle. Face 0 comes from the live surface and faces 1-5 from guest memory, and each face reads its value. Without this commit it fails with `depth plane copy geometry does not match its layers`. The existing array/cube, integer, depth-bits array and first-slice cases still pass. - `ctest -R '^agc_|^shader'`: 486/487. The one failure, `agc_driver_tessellation` (SEGFAULT), fails the same way on unmodified `main` 0214069e3 on this machine. All `agc_driver_depth*` tests and `agc_driver_graphics` pass. `tools/check_conventions.py` passes. - Kena in game (on the earlier version of this commit, before the rebase), on a local stack of main + #425 + #3763 + #3816 + #4031 + #4500 + #4586 plus local stand-ins. The depth plane copy refusals are gone, the shadowed scene has plausible exposure instead of a white frame, and there was no GPU hang. ### 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 (#425 is merged) - [x] AI-assisted: yes (Claude Code)
blawesom commented 2026-10-13 18:00:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-13T18:00:41Z.


Cross-reference: #4873 implements the same padded depth-plane copy (same LinearLayerOffset/bufferRowLength region mechanism) against the older inline path. Since this PR already matches main's record() refactor and carries the Kena motivating case, it looks like the more current of the two — flagging the duplication so the maintainers can choose once rather than review twice. (This PR still shows needs-rebase for staleness; I can rebase it on request.)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6151887326 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4722#issuecomment-6151887326). Originally posted by [blawesom](https://github.com/blawesom) on 2026-10-13T18:00:41Z. --- **Cross-reference:** #4873 implements the same padded depth-plane copy (same `LinearLayerOffset`/`bufferRowLength` region mechanism) against the older inline path. Since this PR already matches `main`'s `record()` refactor and carries the Kena motivating case, it looks like the more current of the two — flagging the duplication so the maintainers can choose once rather than review twice. (This PR still shows needs-rebase for staleness; I can rebase it on request.)
alfalfa-star commented 2026-10-14 05:25:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by alfalfa-star on 2026-10-14T05:25:12Z.


@oneandonlydean #4873 now carries this fix. Since its rebase it sits in record() and uses the same per-layer LinearLayerOffset and padded bufferRowLength. It keeps this PR's Kena (PPSA01802) 128x128 D16 cube test, adds the 32x32 case from PPSA29343, and grows the staging buffer for larger layouts, so it covers everything this PR does. I'm fine with #4873 going in instead, and I'll close this one when it merges. Thanks @GustavoGamarra95 for keeping the Kena case.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6161563327 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4722#issuecomment-6161563327). Originally posted by [alfalfa-star](https://github.com/alfalfa-star) on 2026-10-14T05:25:12Z. --- @oneandonlydean #4873 now carries this fix. Since its rebase it sits in `record()` and uses the same per-layer `LinearLayerOffset` and padded `bufferRowLength`. It keeps this PR's Kena (PPSA01802) 128x128 D16 cube test, adds the 32x32 case from PPSA29343, and grows the staging buffer for larger layouts, so it covers everything this PR does. I'm fine with #4873 going in instead, and I'll close this one when it merges. Thanks @GustavoGamarra95 for keeping the Kena case.
oneandonlydean commented 2026-10-14 18:15:48 +00:00 (Migrated from github.com)

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


Closing in favour of #4873, which is now on main and carries this fix (per-layer LinearLayerOffset with the padded bufferRowLength) together with your Kena (PPSA01802) 128x128 D16 cube test, as you suggested. Thanks for the original fix.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6175188362 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4722#issuecomment-6175188362). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-14T18:15:48Z. --- Closing in favour of #4873, which is now on main and carries this fix (per-layer `LinearLayerOffset` with the padded `bufferRowLength`) together with your Kena (PPSA01802) 128x128 D16 cube test, as you suggested. Thanks for the original fix.

Pull request closed

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!4722
No description provided.