fix(agc): copy a depth surface's plane through the texture's padded linear slices #4873

Merged
GustavoGamarra95 merged 3 commits from upstream-pr/4873 into main 2026-10-14 17:49:45 +00:00
GustavoGamarra95 commented 2026-10-13 01:14:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by GustavoGamarra95 on 2026-10-13T01:14:32Z.


What

Follow-up to #425 for depth surfaces whose linear layout is padded. DepthPlaneCopy laid its staging buffer out as tight slices, while the detiler writes the guest's linear layout, which pads rows and slices, so the copy refused these surfaces with depth plane copy geometry does not match its layers. Two shapes of padding reach it:

  • a 32x32 D16 surface sampled as a six-face cube through a depth-bits view (T# format 7, swizzle 24, type cube; Beast of Reincarnation, PPSA29343) is smaller than a 64 KiB block, so DescribeSurface gives 16384-byte slices where the copy expected 2048: the padding is in the slice size;
  • a 128x128 D16 cube read through an R16 view in a 64 KiB Z swizzle (Kena: Bridge of Spirits, PPSA01802, from #4722) has 512-byte rows where the copy expected 256, and 64 KiB faces: the padding is in the row pitch.

Changes:

  • fix: each region in record() takes the layer's LinearLayerOffset plus the mip's linear offset, and the mip's pitch as the row length, for both the slices copied from a live depth surface and the ones detiled from guest memory. The staging buffer grows to the padded size whenever a larger layout shows up, keeping the buffer it replaces alive for copies already recorded, and a mismatch says which geometry it saw.
  • test: agc_driver_depth_plane_sampling samples both cubes (face 0 from the live surface, faces 1-5 from guest memory). The draw helper sizes its color target with ColorTargetLayout, since a linear 32x32 target is padded to a 64-pixel pitch. The 128x128 case is taken from #4722 with its authorship kept.

Overlaps #4722, which implements the same fix for the 128x128 case; this PR carries its test case too, so the maintainers can pick one. Rebased onto main after #2490/#2491: the fix now lives in record() with its copiedLayers/uploadLayers split.

Tested

Linux, RTX 3050 Laptop (NVIDIA 615.78.08), on main dacd78525. Both new cases fail without the fix with the message above (the 32x32 case also on its own) and pass with it; the depth ctests and agc_driver_graphics pass, and tools/check_conventions.py passes. Beast of Reincarnation (PPSA29343) gets past this copy on current main; it then stops at a separate refusal of a multi-layer depth storage view, which we are still working on. @ps54all also ran this PR on Super Meat Boy 3D (PPSA31162, Windows, RTX 3080): it reaches its main menu instead of stopping at this refusal.

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: PPSA29343 (Beast of Reincarnation), PPSA31162 (Super Meat Boy 3D), PPSA01802 (Kena: Bridge of Spirits)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4836949599 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4873). Originally posted by [GustavoGamarra95](https://github.com/GustavoGamarra95) on 2026-10-13T01:14:32Z. --- ### What Follow-up to #425 for depth surfaces whose linear layout is padded. `DepthPlaneCopy` laid its staging buffer out as tight slices, while the detiler writes the guest's linear layout, which pads rows and slices, so the copy refused these surfaces with `depth plane copy geometry does not match its layers`. Two shapes of padding reach it: - a 32x32 D16 surface sampled as a six-face cube through a depth-bits view (T# format 7, swizzle 24, type cube; Beast of Reincarnation, PPSA29343) is smaller than a 64 KiB block, so `DescribeSurface` gives 16384-byte slices where the copy expected 2048: the padding is in the slice size; - a 128x128 D16 cube read through an R16 view in a 64 KiB Z swizzle (Kena: Bridge of Spirits, PPSA01802, from #4722) has 512-byte rows where the copy expected 256, and 64 KiB faces: the padding is in the row pitch. Changes: - fix: each region in `record()` takes the layer's `LinearLayerOffset` plus the mip's linear offset, and the mip's pitch as the row length, for both the slices copied from a live depth surface and the ones detiled from guest memory. The staging buffer grows to the padded size whenever a larger layout shows up, keeping the buffer it replaces alive for copies already recorded, and a mismatch says which geometry it saw. - test: `agc_driver_depth_plane_sampling` samples both cubes (face 0 from the live surface, faces 1-5 from guest memory). The draw helper sizes its color target with `ColorTargetLayout`, since a linear 32x32 target is padded to a 64-pixel pitch. The 128x128 case is taken from #4722 with its authorship kept. Overlaps #4722, which implements the same fix for the 128x128 case; this PR carries its test case too, so the maintainers can pick one. Rebased onto `main` after #2490/#2491: the fix now lives in `record()` with its `copiedLayers`/`uploadLayers` split. ### Tested Linux, RTX 3050 Laptop (NVIDIA 615.78.08), on `main` dacd78525. Both new cases fail without the fix with the message above (the 32x32 case also on its own) and pass with it; the `depth` ctests and `agc_driver_graphics` pass, and `tools/check_conventions.py` passes. Beast of Reincarnation (PPSA29343) gets past this copy on current `main`; it then stops at a separate refusal of a multi-layer depth storage view, which we are still working on. @ps54all also ran this PR on Super Meat Boy 3D (PPSA31162, Windows, RTX 3080): it reaches its main menu instead of stopping at this refusal. ### 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 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: PPSA29343 (Beast of Reincarnation), PPSA31162 (Super Meat Boy 3D), PPSA01802 (Kena: Bridge of Spirits) - [x] AI-assisted: yes
ps54all commented 2026-10-13 17:37:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ps54all on 2026-10-13T17:37:40Z.


Super Meat Boy 3D (PPSA31162, UE5) data point, Windows 11, RTX 3080 (610.74), WinLibs GCC 15.2.0 r7, Release.

Without this PR (on main plus unrelated picks) the title runs about 120 s and stops at AGC graphics: depth plane copy geometry does not match its layers. With this PR it reaches its main menu (Continue / Start Game / Theater / Settings / Credits) and stays up for the full 420 s run.

The PR no longer merges cleanly: main now copies only changed layers (#2490/#2491), and the detiled uploads already land in the staging buffer at geometry.LinearLayerOffset(layer). I ported it by giving that region lambda bufferOffset = geometry.LinearLayerOffset(layer) + mip.linearOffset and bufferRowLength = mip.pitchBytes / texel, and keeping your stagingSize/retiredStaging growth. #4722 covers the same refusal from the Kena side.

AI-assisted (Claude Code); I ran the above on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6151478093 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4873#issuecomment-6151478093). Originally posted by [ps54all](https://github.com/ps54all) on 2026-10-13T17:37:40Z. --- Super Meat Boy 3D (PPSA31162, UE5) data point, Windows 11, RTX 3080 (610.74), WinLibs GCC 15.2.0 r7, Release. Without this PR (on `main` plus unrelated picks) the title runs about 120 s and stops at `AGC graphics: depth plane copy geometry does not match its layers`. With this PR it reaches its main menu (Continue / Start Game / Theater / Settings / Credits) and stays up for the full 420 s run. The PR no longer merges cleanly: `main` now copies only changed layers (#2490/#2491), and the detiled uploads already land in the staging buffer at `geometry.LinearLayerOffset(layer)`. I ported it by giving that `region` lambda `bufferOffset = geometry.LinearLayerOffset(layer) + mip.linearOffset` and `bufferRowLength = mip.pitchBytes / texel`, and keeping your `stagingSize`/`retiredStaging` growth. #4722 covers the same refusal from the Kena side. AI-assisted (Claude Code); I ran the above on my machine.
blawesom commented 2026-10-13 18:00:39 +00:00 (Migrated from github.com)

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


Cross-reference before further review effort: #4722 (alfalfa-star) implements the same padded depth-plane copy, and its version is already aligned with main's newer structure.

Both PRs make the depth-plane copy handle linearly padded layouts with the same core mechanism — bufferOffset = geometry.LinearLayerOffset(layer) + linearOffset and bufferRowLength = pitchBytes / texelBytes — but they're built against different generations of the surrounding code: main has since refactored the copy path into the record() helper (with the region() lambda and the copiedLayers/uploadLayers split), which #4722's diff already matches, while this PR reworks the older inline path.

A plain rebase of this PR would therefore mean porting its region computation into record() — work #4722 appears to have already done, on top of the motivating case (Kena's 128x128 D16 shadow-map cubes) and the tight-packing refusal fix. I'd suggest the maintainers pick between them before anyone spends merge effort here; happy to do the port into record() if this PR's version is the one that should carry it.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6151886934 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4873#issuecomment-6151886934). Originally posted by [blawesom](https://github.com/blawesom) on 2026-10-13T18:00:39Z. --- **Cross-reference before further review effort: #4722 (alfalfa-star) implements the same padded depth-plane copy**, and its version is already aligned with `main`'s newer structure. Both PRs make the depth-plane copy handle linearly padded layouts with the same core mechanism — `bufferOffset = geometry.LinearLayerOffset(layer) + linearOffset` and `bufferRowLength = pitchBytes / texelBytes` — but they're built against different generations of the surrounding code: `main` has since refactored the copy path into the `record()` helper (with the `region()` lambda and the copiedLayers/uploadLayers split), which #4722's diff already matches, while this PR reworks the older inline path. A plain rebase of this PR would therefore mean porting its region computation into `record()` — work #4722 appears to have already done, on top of the motivating case (Kena's 128x128 D16 shadow-map cubes) and the tight-packing refusal fix. I'd suggest the maintainers pick between them before anyone spends merge effort here; happy to do the port into `record()` if this PR's version is the one that should carry it.
GustavoGamarra95 commented 2026-10-13 19:19:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by GustavoGamarra95 on 2026-10-13T19:19:18Z.


@blawesom thanks for the cross-reference. I rebased this PR onto main: the fix now lives in record() (with #2491's copiedLayers/uploadLayers split) and keeps both test cases, because they cover two different kinds of padding the same rule has to handle:

  • 32x32 D16 (Beast of Reincarnation, PPSA29343): the surface is smaller than the 64 KiB swizzle block, so each linear face is 16384 bytes instead of a tight 2048. The padding is in the face size.
  • 128x128 D16 (Kena, PPSA01802, taken from #4722 with its authorship kept, @alfalfa-star): the block holds 256x128 texels, so each row is 512 bytes instead of 256 and each face 64 KiB. The padding is in the row pitch.

A fix tested on only one of them could get the per-face offset right and the row length wrong, or the other way around. Both cases fail without the fix with depth plane copy geometry does not match its layers and pass with it.

The staging buffer grows whenever a larger layout shows up, keeping the previous one alive for copies already recorded, instead of refusing a larger layout after the first copy. Thanks also to @ps54all for the Super Meat Boy 3D (PPSA31162) run.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6153308916 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4873#issuecomment-6153308916). Originally posted by [GustavoGamarra95](https://github.com/GustavoGamarra95) on 2026-10-13T19:19:18Z. --- @blawesom thanks for the cross-reference. I rebased this PR onto `main`: the fix now lives in `record()` (with #2491's `copiedLayers`/`uploadLayers` split) and keeps both test cases, because they cover two different kinds of padding the same rule has to handle: - **32x32 D16 (Beast of Reincarnation, PPSA29343):** the surface is smaller than the 64 KiB swizzle block, so each linear face is 16384 bytes instead of a tight 2048. The padding is in the face size. - **128x128 D16 (Kena, PPSA01802, taken from #4722 with its authorship kept, @alfalfa-star):** the block holds 256x128 texels, so each row is 512 bytes instead of 256 and each face 64 KiB. The padding is in the row pitch. A fix tested on only one of them could get the per-face offset right and the row length wrong, or the other way around. Both cases fail without the fix with `depth plane copy geometry does not match its layers` and pass with it. The staging buffer grows whenever a larger layout shows up, keeping the previous one alive for copies already recorded, instead of refusing a larger layout after the first copy. Thanks also to @ps54all for the Super Meat Boy 3D (PPSA31162) run.
ps54all commented 2026-10-14 07:07:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ps54all on 2026-10-14T07:07:30Z.


Super Meat Boy 3D (PPSA31162, UE5) retest on the rebased head, Windows 11, RTX 3080 (610.74), WinLibs GCC 15.2.0 r7, Release: main f74ec639c + this PR (17423e21e merge in a scratch tree).

The depth plane copy geometry does not match its layers stop is gone: three runs (300 s, 240 s, ~300 s) never hit it. The game stays on the Unreal/FMOD logo screen at about 2.4 FPS for the first 240 s on a warm second run and does not reach its main menu in these runs; the third run aborts at about 300 s with a different, existing refusal (storing storage image results pending over memory outside the write watch without the guest bytes saved before them is not implemented, Texture.cpp), which this PR does not touch. Earlier today the same title reached its main menu on my integration branch (main 8cf6a0bc3 plus my port of this PR); that branch has other local changes, so I do not claim a regression from this PR.

AI-assisted (Claude Code); I ran the above on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6162903071 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4873#issuecomment-6162903071). Originally posted by [ps54all](https://github.com/ps54all) on 2026-10-14T07:07:30Z. --- Super Meat Boy 3D (PPSA31162, UE5) retest on the rebased head, Windows 11, RTX 3080 (610.74), WinLibs GCC 15.2.0 r7, Release: main `f74ec639c` + this PR (`17423e21e` merge in a scratch tree). The `depth plane copy geometry does not match its layers` stop is gone: three runs (300 s, 240 s, ~300 s) never hit it. The game stays on the Unreal/FMOD logo screen at about 2.4 FPS for the first 240 s on a warm second run and does not reach its main menu in these runs; the third run aborts at about 300 s with a different, existing refusal (`storing storage image results pending over memory outside the write watch without the guest bytes saved before them is not implemented`, Texture.cpp), which this PR does not touch. Earlier today the same title reached its main menu on my integration branch (main 8cf6a0bc3 plus my port of this PR); that branch has other local changes, so I do not claim a regression from this PR. AI-assisted (Claude Code); I ran the above on my machine.
adriadam10 commented 2026-10-14 17:26:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T17:26:35Z.


Rebased onto current main (the depth plane copy now keys its textures by base slice; conflicts were only in the DepthPlaneCopy members and the test list, no logic changed). Checked: build and the libSceAgcDriver ctest scope are green (the only failure, agc_driver_tessellation, is a RADV segfault unrelated to this change), agc_driver_depth_plane_sampling passes, and it fails with DepthSurface.cpp reverted, so both new cube cases exercise the fix. Per-layer LinearLayerOffset plus the mip's pitch as bufferRowLength is consistent with how the detiler writes the guest's linear layout. This covers #4722's case as well (its test is kept with authorship); merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6174258086 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4873#issuecomment-6174258086). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-14T17:26:35Z. --- Rebased onto current `main` (the depth plane copy now keys its textures by base slice; conflicts were only in the `DepthPlaneCopy` members and the test list, no logic changed). Checked: build and the libSceAgcDriver ctest scope are green (the only failure, `agc_driver_tessellation`, is a RADV segfault unrelated to this change), `agc_driver_depth_plane_sampling` passes, and it fails with `DepthSurface.cpp` reverted, so both new cube cases exercise the fix. Per-layer `LinearLayerOffset` plus the mip's pitch as `bufferRowLength` is consistent with how the detiler writes the guest's linear layout. This covers #4722's case as well (its test is kept with authorship); merging.
github-actions[bot] commented 2026-10-14 17:32:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-14T17:32:57Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#5054 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp L332
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6174378507 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4873#issuecomment-6174378507). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-14T17:32:57Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #5054 | `core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp` [L332](https://github.com/boykopovar/AnyPS5/blob/26ce6e954a3945c847d179a275f3b97dac7cb4c1/core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp#L332) | | |
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!4873
No description provided.