fix(agc): copy only the viewed slices of a 2D array over a depth surface #22778
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/22778"
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 milescoviello on 2026-11-18T08:47:09Z.
What
DepthSurfaceTexturebuilds a plane copy when a 2D array texture sits over a depth surface. It built that copy from slice 0 to the view's last slice, whatever the view's base slice was. For each slice with no depth surface,DepthPlaneCopy::Refreshuploads the guest layer through its own host buffer, and the staging buffer covers every layer. A view of one slice far into the array therefore allocated, uploaded and staged every slice before it.Crimson Desert (PPSA25286) hits this about two minutes into a warm-cache boot. A diagnostic print at the copy's creation shows the descriptor:
That's one viewed slice in a 328-layer, 5248 MiB copy. In another run the texture cache was asked for 14432 MiB for the same kind of copy. With the per-layer host uploads, the process's RSS reached 29 GB. Three such runs on the same build and cache ended at 100 s and 125 s (killed at the 22 GB cgroup limit) and at 124 s (host memory guard).
Changes:
ViewedArrayWindowof the view, the helpercachedTexturealready uses for arrays. It moves the base to the first viewed slice, rounded down to the swizzle's slice alignment, and shortens the array to match. The slices, the copy's key, its layer count and theRefreshview all come from that window, so the copy holds only slices the view can read.SharedLayerRangeschecks.The viewed slices get the same contents as before. Only the slices outside the view are no longer copied.
Tested
11-24, merge
e83fe3cf0a(mainadacf0bd83merged into the branch): #26579 and #25871 (birdmarty) madeDepthSurfaceTexturesample stencil planes too, frombase.stencilAddresswithstencilSliceand the stencil copy format, which conflicted with this PR's moved copy-key code. The resolution keeps both: the copy key, the shared-copy lookup and the slice addresses start from the plane's address (stencil or depth), offset by the viewed window (viewed.baseAddress - resource.baseAddress), and the stencil format and mirror sync come frommainunchanged. Linux, the same setup as below:agc_driver_depth_plane_*,agc_driver_depth_surface_*,agc_driver_native_multisample_depth*andagc_driver_graphicstests, which include birdmarty's new stencil-plane cases, pass in 3 of 3 runs;main'sDepthSurface.cpp,agc_driver_depth_plane_guest_layersfails withsampling only the last slice of the array read 2 times from the guest layers before it.DepthPlaneGuestLayers,DepthPlaneSampling,NativeMultisampleDepthandDepthPlaneSampling_evictingpass in 3 of 3 rounds on an Intel UHD (driver 101.6127) and on an RTX 4070 Laptop (621.01), with noVUID-orSYNC-HAZARDmessages. A local stencil-array variant of theirs (not in this PR), whose view starts at slice 1, passes on both GPUs and fails on the RTX when onlyviewedAddressis put back toplaneAddress, so the adjusted stencil address is exercised. They also note that #25534 conflicts with this PR aroundDepthPlaneCopy; whichever lands second needs a rebase that keeps both.Earlier heads:
Linux (Ubuntu 26.04.1, kernel 7.0), GCC 15.2, Ninja, Release,
-DBUILD_TESTING=ON, RTX 4070 Ti (NVIDIA 615.71.09):agc_driver_depth_plane_guest_layersgainsViewedSliceWindow. A 4-slice array has a depth surface at slice 0 only, and a view of slice 3 alone must:The 21
agc_driver_depth_plane_*andagc_driver_depth_surface_*tests pass, 3 runs.Negative control: with
main'sDepthSurface.cppand the new test, onlyagc_driver_depth_plane_guest_layersfails, withsampling only the last slice of the array read 2 times from the guest layers before it.domx4q's run with the Khronos validation layer (Arch Linux, GCC 16.2.1, RTX 4090, NVIDIA 620.70.06, layer 1.4.363.1), this head merged onto
main1ccc399b17: the 21 tests pass on bothmainand this PR with noVUID-errors, and the negative control failsagc_driver_depth_plane_guest_layersin 2 of 2 runs with the same message.maskym's Windows run (Windows 11, RTX 2070 SUPER, WinLibs GCC 15.2.0), this head merged alone onto
main6286d36449:ctest -R '^(agc|guest_video_out|video_out|pad_sdl)'with the Khronos validation layer passes 2050 of 2054 on both trees, with the sameVUID-set. The failures on this PR's tree also fail onmainthere.git merge-treeagainstmainis clean. Of the 42 open PRs that editDepthSurface.cpporDepthPlaneGuestLayers.cpp, 23 merge with this branch cleanly. 18 others already conflict withmainon their own.#22531 (bagodees, opened first) is the remaining one. It also changes how plane copies are allocated and edits the same line of
DepthSurfaceTexture, so the two conflict textually. They cover different cases:LAST_ARRAY);The two combine: the window would go first, and #22531's backed-slice count would apply inside it. If #22531 merges first, I'll rebase this onto it.
tools/check_conventions.pypasses on the branch and this body.Crimson Desert (PPSA25286), warm shader cache,
APS5_NET_DISCONNECTED=1, 22 GB cap. Both arms aremain604828bd44+ #22534 + #22609 + #22690 + diagnostic prints; the second adds this change:ui/media/titleview_*.mp4videos. None asked the texture caches for more than 1 GiBPresents ran at about 1 to 2 per second in both arms, so this changes how long the title runs, not its frame rate. The five 600 s runs also carried a diagnostic print in libSceAvPlayer (logging only), and no frames were dumped, so I'm not claiming a new screen.
The same A/B on current
main, without the diagnostic prints: base452e171f80(main6119c53c4b+ #22534 + #22609) and fix1e1230ed68(base + this change), same warm cache, cap and presses, interleaved:4831838208 bytes placed in host memory type 0(one 4608 MiB buffer)Three more fix runs with logging-only prints in libSceAvPlayer (
e9b89ad8ce) ran to the 600 s timeout (553 to 604 presents, peak RSS 19.9 to 20.7 GB). They placed two to eight 832 MiB buffers in host memory, 1664 to 6656 MiB in all, and stayed under the cap. No fix run logged a single buffer near the base run's 4608 MiB.b92cb7f02cmerged ontomaind89f26516c(Linux 7.3.4, GCC 16.2.1, Mesa 26.2.6, RX 7900 XT and the Ryzen 7 7800X3D iGPU, Khronos validation layer 1.4.363.1): no new failures againstmain(6171 tests on the 7900 XT, the 2007 GPU tests on the iGPU, and^agcwith the layer), and noVUID-orSYNC-HAZARDlines.Helldiverr's Windows run of
b92cb7f02cmerged ontomainc3aec4c2f3, AMD Radeon AI PRO R9700 (RDNA4, driver 32.0.31044.16), WinLibs GCC 15.2, Release, with the Khronos validation layer:mainand in each of 3 runs at the head.main'sDepthSurface.cpp, the new case fails 3 of 3 with the message above.VUID-and 0SYNC-HAZARDlines in every log.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-19T05:26:09Z.
Review: APPROVED
Reviewed — looks good
The change limits depth plane copies to the viewed array window, and the inspected implementation and regression test support that behavior.
What I ran
Head:
b92cb7f02cf4e23993bce2550fe6669d35613644. I read the prepared diff and changed code throughrepo_read.py; I ran no commands or tests. Test results in the description are author or CI reports.Results
Findings
Blocking
None.
Non-blocking
None.
Sources
The relevant slice-window behavior is implemented in
TextureTiling.cpp, and the copy refresh uses the supplied resource window inDepthSurface.cpp.Not verified
No tests were run in this review. I read
DepthSurface.cppandDepthPlaneGuestLayers.cpp;files.jsonwas not provided in the review folder, so exclusions listed there could not be checked. The prepared manifest lists both changed files as included, and all added lines in each were read.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by mihiii1337 on 2026-11-24T20:21:31Z.
Review: APPROVED
Approved at exact head
e83fe3cf0aec4aeea72ac46c432d2c3d168defaeafter a fresh Windows build, source/merge-resolution review, and physical Intel + NVIDIA validation.The merge reconciliation looks consistent: the whole-plane lookup remains keyed by the original depth/stencil plane address, while a narrowed array view uses its adjusted address for slice discovery and its copy key. The stencil-specific format/address, per-slice synchronization, reuse callback, and copy eviction path remain intact.
Hardware setup: Windows 11 build 26300, Release, WinLibs GCC 15.2.0 r7, Vulkan validation 1.4.369 with synchronization validation and loader layer tracing. Each GPU was pinned with
VK_DRIVER_FILESonly; shader cache and pipeline journal were disabled andANYPS5_REQUIRE_VULKAN=1was set.8086:a78b, driver 101.6127, Vulkan 1.3.295:DepthPlaneGuestLayers,DepthPlaneSampling,NativeMultisampleDepth, andDepthPlaneSampling_evictingpassed in 3/3 rounds (12/12 CTest outcomes). Every Vulkan process selected the Intel device and inserted the validation layer; 0VUID-, 0SYNC-HAZARD, no skips.10de:2860, driver 621.01, Vulkan 1.4.357: the same matrix passed in 3/3 rounds (12/12 outcomes), with the RTX and validation layer confirmed in every process; 0VUID-, 0SYNC-HAZARD, no skips.I also made a local test-only coverage variant, not part of this PR:
StencilArrayCaseused the compatible standard 64 KiB swizzle and performed the coldbaseArray=1reads before creating a whole-array copy. That makes the viewed stencil address advance by one 64 KiB layer. Both normal and evicting tests passed in 3/3 rounds on each GPU (6/6 outcomes per GPU), with the same device/layer and validation checks. As a negative control, changing onlyviewedAddressback toplaneAddressmade the RTX run fail at the intended first marker: it read0x5ainstead of0xa5. This demonstrates that the variant actually exercises the adjusted-address path rather than merely a cold cache path.Both local source changes were then restored byte-for-byte to the PR blobs, the target was rebuilt, the tracked worktree was clean, and both sampling tests passed once more on each GPU with validation (4/4 outcomes, 0 VUID/SYNC).
Non-blocking integration note: #25534 is individually mergeable but pairwise conflicts with this PR around
DepthPlaneCopy; whichever lands second will need a rebase that preserves both the narrowed viewed-layer/address logic and the copy replacement/eviction behavior.No PS5/title run was performed.
AI-assisted: yes (OpenAI Codex); the exact heads, source blobs, device selection, layer insertion, outputs, and restoration were checked directly.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T08:54:15Z.
Review: COMMENTED
Reviewed — no blocking findings
The inspected changes limit depth plane copies to the viewed array window; I found no concrete blocking defect, but did not run the reported checks.
What I ran
Reviewed head
e83fe3cf0aec4aeea72ac46c432d2c3d168defaeusing the prepared diff andrepo_read.pyto inspect the changed code and relevant helpers. No tests or build commands were run. The author-reported test results are not runs performed in this review.Results
Findings
Blocking
None found in the inspected changes.
Non-blocking
None.
Not verified
DepthSurface.cppandDepthPlaneGuestLayers.cpp; both are marked included in the manifest and relevant changed sections were read. No files were excluded in the manifest.files.jsonwas unavailable in the review folder, so additional exclusions are not verified.To get this to a good state
Nothing is required.