fix(agc): gather a sampled depth cube at the descriptor's layer offsets #5054
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5054"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by NFSS10 on 2026-10-13T09:59:48Z.
What
DepthPlaneCopyis the image a layered depth texture is sampled through.DepthSurfaceTexturegathers a cube/array whose faces are all backed by host depth surfaces, onevkCmdCopyImageper layer. It located the surface for layernatbase.address + n * DepthSliceBytes(extent)and refused the gather unless the guest descriptor matched the host depth slices exactly:Both halves of that assume more than the call requires:
DescribeSurface(...).GuestLayerOffset(n);sliceLinearBytes) need not equal the host depth slice, even when its tiled footprint (layerBytes) does.Bendy and the Ink Machine (PPSA27616) samples a 64x64 F32 cube over six contiguous D32 depth surfaces with
mipCount = 1. The descriptor's linear layer footprint is 0x8000 while one host depth slice is 0x10000, so the copy aborted withdepth plane copy geometry does not match its layersas soon as the title sampled the cube.This change:
natbase.address + geometry.GuestLayerOffset(n)- the address the descriptor itself uses, and the one the guest fill path already used, so the two ways of finding a layer agree by construction;VK_NULL_HANDLE) and would be filled from guest memory - the one path that reads the guest layout and needssliceLinearBytesto line up with the host depth slices one to one.The fill path is unchanged: a fill whose guest layout would misplace bytes is still refused with the same message. The storage-image path still refuses a layer pitch that is not the depth slice size; that is unchanged and out of scope.
Follow-up to #425, which added the layered depth plane copy. This is a new call shape (a fully host-backed cube), not a regression in that PR.
Before: No gameplay. The game wouldn't pass the main menu.
After: Game now loads pass the main menu and we have gameplay (with very graphical artifacts but it works)
https://github.com/user-attachments/assets/8285c6a3-6214-4b4d-904c-438a76c1e40d
Tested
Windows 11 Pro (build 22631), AMD Ryzen 9 7900X, MinGW-w64 GCC 15.2.0, on
23e93c054.GPUs tested: AMD Radeon RX 7900 GRE (driver 32.0.21013.1000).
agc_driver_depth_plane_guest_layers:mipCount = 1, whose tiled layer footprint equals the depth slice but whose linear footprint does not (0x8000 vs 0x10000) - the shape from the reported abort. It gathers all six faces host-to-host.agc_driver_graphics, theagc_driver_depth_*tests (bias per face, compare copy, fast clear, fast clear submit, plane sampling, storage, storage dispatch, storage reuse) andagc_driver_storage_*(cache budget, one slice alias) pass, as doescheck_conventions.py.main(23e93c054) the title aborts at gameplay start withAGC graphics: depth plane copy geometry does not match its layers;Checklist
main; no other open PR implements the same functions (#5003 covers storage-image access to depth planes, not the sampled copy)NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repositoryImported from boykopovar/AnyPS5. Originally posted by coltken95 on 2026-10-13T18:54:22Z.
Tested on Linux x86-64 (Release build, lavapipe / llvmpipe LLVM 20.1.2), with 7bca0b6b3 merged into main
9d0a41d5a:agc_driver_depth_plane_guest_layerspasses.agc_driver_depth_plane_guest_layersfails.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by NFSS10 on 2026-10-13T22:54:02Z.
Thanks for testing this against main. I’ve rebased PR #5054 onto current main and reran agc_driver_depth_plane_guest_layers; it passes locally on the updated branch. The PR’s guest-layer change is independent of the padded-layout work in #4722/#4873, and it does not rely on #5344, so I’ve kept Depends on: none. I’ll verify the combined DepthSurface.cpp behavior if those overlapping changes are merged.
Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-10-14T01:51:02Z.
Review: COMMENTED
I don't think the check can be skipped when every layer has a surface, because it does more than validate the guest-memory fallback. It is the only thing that keeps the two ways of locating a layer the same.
DepthSurfaceTexturefinds the surface for layernatbase.address + n * DepthSliceBytes(extent), using the host slice size as the stride. The guest descriptor puts layernatbaseAddress + geometry.GuestLayerOffset(n), and for this cube that isn * 0x500000because each face carries its mip chain. With the check in place the two strides are equal, so the surface found for a layer is the one at that face's address. With the check skipped they differ for every face after the first. Faces 1–5 are then gathered from the surfaces at0x400000,0x800000, … while the descriptor addresses0x500000,0xA00000, …, which are inside other surfaces. The storage-image path refuses the same layout inDepthSurface.cpp("with a layer pitch of 0x%llx bytes, not the depth slice size 0x%llx, is not implemented"), so the two paths would disagree too.That may be what the artifacts in the video are. The texture is a cube, so wrong faces would show up as shadows or reflections that look right from one direction and wrong from others.
To get past the menu without that, I see two options:
baseAddress + geometry.GuestLayerOffset(layer), so each face uses the surface at its own address (or falls back to guest memory when nothing is there), and keep the check for the mixed case.0x400000stride and samples them as a cube with a0x500000stride, that is worth establishing from the log first: the sixDepthTargetaddresses and the texture descriptor (baseAddress,mipCount,lastLevel). On the console the descriptor would read faces 1–5 from the middle of other surfaces, so one of the two values is probably not what the code assumes.Minor: this changes
libSceAgcDriveronly, so therelinkerlabel looks unintended. The GPU should be named (model and driver) in aGPUs testedline.Imported from boykopovar/AnyPS5. Originally posted by NFSS10 on 2026-10-14T10:36:40Z.
Thanks for the careful review.
You're right, and I went with option 1: the lookup no longer uses the host depth slice stride.
So the gather and the guest fill find a layer at the same address by construction, instead of by the check happening to hold. The geometry check is kept, now only for the mixed case (a layer left at
VK_NULL_HANDLEthat has to be filled from guest memory), which is the only path that actually reads the guest layout.On the 0x400000 / 0x500000 point: I re-checked the log and the resource that actually aborts is not a two-level chain. It's a 64x64 F32 cube with
mipCount = 1: its tiledlayerBytesequals the host depth slice, butsliceLinearBytesis 0x8000 against a 0x10000 host depth slice, so the oldsliceLinearBytes == sliceBytes()predicate refused it. I've corrected the PR description - my earlier note about a 0x500000 per-layer footprint and a two-level mip chain was wrong.I added a fixture for the stride case as well: a 256x256 cube whose surfaces sit at the descriptor's own offsets (0x50000 apart, one host depth slice 0x40000). With the old lookup only the first face was found, so the copy fell back to the guest path and was refused; now all six are gathered host-to-host. The missing-face variant still takes the fill path and is refused with the same message.
The storage-image path is indeed unchanged and still refuses a pitch that isn't the depth slice size; I agree that's out of scope here.
Rebased onto current
main(23e93c054);agc_driver_depth_plane_guest_layerspasses, and running the title the same way both before and after - onmainit aborts at gameplay start withdepth plane copy geometry does not match its layers, and with this change it goes through the menu into gameplay with no depth-plane errors.About the labels, I can't change the labels, they were auto-assigned by the bot and I don't have permissions to change them :/
Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-10-14T16:52:11Z.
Thanks. Looking each slice up at
baseAddress + geometry.GuestLayerOffset(layer)addresses what I raised: the gather and the guest fill now agree by construction, and the geometry check only guards the path that actually reads the guest layout. The corrected description (a 64×64mipCount = 1cube refused by the oldsliceLinearBytescomparison) also explains the abort better than the earlier mip-chain note. The new 0x50000-stride fixture covers the case the old lookup got wrong.The label isn't something you can change. A maintainer can drop
relinkerwhen they look at it.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T17:37:56Z.
Checked the layer lookup at
GuestLayerOffsetand the geometry check now limited to the guest-fill path; the new cases inagc_driver_depth_plane_guest_layerspass and fail without the change (negative check).libSceAgcDriverbuild and ctest are green apart fromagc_driver_tessellation, which crashes inside the local RADV pipeline-library link and does not touch this path. Also confirmed by @coltken95 on Linux/lavapipe. Merging once the full Build is green.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T18:02:39Z.
Main changed
DepthPlaneCopy::Refreshafter this was approved (the geometry check is nowsliceLinearBytes < sliceBytes()with a detailed message), which conflicted. I rebased and kept both: main's message and staging code, and the check only when a face is filled from guest memory.Added one commit: the two "missing face must be refused" cases in
DepthPlaneGuestLayers.cppare gone, since with main's<check the 0x50000 and 0x8000 footprints are accepted and no longer refused. The two gather cases remain and still fail without the change inDepthSurface.cpp(negative check).libSceAgcDriverctest is green on the rebased tree apart fromagc_driver_tessellation(crash in the local RADV pipeline-library link, not on this path). Merging once the full Build is green.