fix(agc): reload a sampled depth plane the guest wrote since its surface was bound #12238
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12238"
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 XairRrR on 2026-10-28T04:17:11Z.
What
A depth plane with the 64 KiB Z swizzle reloads the units the guest wrote (
SyncFromMemory, #7154) when its surface is bound as a depth target. Sampling the plane through the surface (DepthSurfaceTexture, the single-sampleSampledpath) skipped that check and read the host image. A title that writes the plane with a buffer copy and samples it before it draws into it again therefore read the depth from before the copy.PPSA05684 (Uncharted: Legacy of Thieves Collection) does this every frame in Uncharted 4: it copies its depth pre-pass into a second depth target with a
buffer_load_format_x/buffer_store_format_xkernel, samples that copy right away to build the half-resolution depth its volumetric fog and dust read, and only later binds the target. The fog used the previous frame's depth, so at the frame rates reached here a dark or light silhouette followed every moving character through fog and dust (the orphanage's closing scene and the prison yard).Sampling a single-sample plane through its surface now runs the same reload first, so the sampled depth includes the guest's writes collected by then. The debt entry for depth planes in guest memory lists sampling among the points where guest writes are collected.
Tested
Arch Linux 7.2.11-zen, GCC 16.2.1, Ninja, Release, on
main3a2b919816, NVIDIA GeForce RTX 4070 Ti SUPER (615.78.08):agc_driver_depth_plane_samplinggainsGuestWriteAfterDrawCase. It draws depth 0.25 into a 128x128 D32 plane with the 64 KiB Z swizzle and samples it (0.25), then writes 0.75 into the guest memory under it and samples it again without binding the surface. WithDepthSurface.cppfrommainit fails:D32 plane the guest wrote after a draw, sampled before its surface is bound again: texel 0 read 0x3e800000, expected 0x3f400000.DrawDepthtakes an optional depth swizzle for it.APS5_NO_WRITE_WATCH=1, or a host without a write watch), the driver cannot see the guest's write. The case then printsguest memory has no write watch: the guest write after a draw is not checkedand returns, like the CPU-write cases ofagc_driver_depth_plane_partial_store.VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ANYPS5_NO_SHADER_CACHE=1 ANYPS5_REQUIRE_VULKAN=1 VK_LOADER_DEBUG=error,warn,layer ctest -V -R '^agc_driver_depth_plane_sampling'onmain3a2b919816and on this branch: 2/2 pass on both, and the layer is inserted in every test. No log reportswas not found but was requested by env var VK_INSTANCE_LAYERS, and neither log has aVUID-line. WithAPS5_NO_WRITE_WATCH=1, the branch also passes 2/2 with noVUID-line.ctest -j8on the first base (main3ca715ee15): 2620 of 2621 pass.agc_driver_mesh_barycentric_emulationfails the same way onmainon this GPU (the pixel shader did not emulate barycentrics).tools/check_conventions.py --base origin/mainpasses.SyncFromMemorycall in the prison yard fight of PPSA05684, where the fog and dust sample the copied depth plane every frame. It ran 6 to 17 thousand times per 10 s at about 1.1 us each, 7 to 16 ms per 10 s in total, so 0.2 to 0.4 ms of a ~260 ms frame.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-10-28T04:20:31Z.
Review: CHANGES_REQUESTED
The targeted test and negative-control evidence are strong, and the one-line reload is placed before the sampled image is consumed. I did not find a separate functional defect in the changed path. This branch is 38 commits behind current
main, though; the repository contribution rules require PR branches to stay up to date. Please rebase/update on currentmain(including resolving the debt-file overlap with #12210 if it is still open), rerun the focused depth-plane test and validation checks on the rebased head, then I can reassess.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-28T04:52:31Z.
Review: CHANGES_REQUESTED
I found one additional ordering case to address alongside the requested rebase and focused retest.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-28T11:23:09Z.
Review: CHANGES_REQUESTED
The change is the right one:
DepthSurface.cpp:2491runs the sameSyncFromMemorybehind the samemirrorablegate as the bind path, and the new test pins0x3f400000after a guest write, whichmainwould read as0x3e800000. Two things before it can land:CollectWritesplus a generation compare when nothing was written, a unit reload when something was). Please add a profile line or a before/after frame time (APS5_PROFILE_DRAWorAPS5_TRACE_SUMMARY_EVERY) from a scene that samples such a plane many times per frame, or say how you measured it as negligible.CollectWriteshiding a CPU write beforeFlushDepthPlanesstores a stale plane) is in code this PR does not change:FlushDepthPlanesalready callsSyncFromMemory(DepthSurface.cpp:2221) and the new line only adds a second caller. If you can show it is a real problem, it belongs in its own PR; please say in the thread whether the sample path makes it reachable in a way the bind path does not.The branch also conflicts with
main(theDepth planes in guest memorydebt entry, which #12210 edits too); we will do that rebase once the cost line is in.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T00:41:29Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
The new write-watch test and its no-write-watch skip address the reported test-environment issue, and the reported GPU run includes a main-code negative control; before this branch is ready, update it against current
mainand resolve its declared ordering with #12210.What I ran
78c1cb46e4017ab6865fa09df261148882ecfc38, its diff, currentmain(3a2b91981651569163768854a1fcdc7193b6667b), and the repository branch and AGC testing rules.git diff --checkagainst the merge base.mainusing Git's merge-tree preview. No conflicted merge was reported, but the branch is 233 commits behind and both branches edit the AGC debt file.Results
Raw status
windows passRaw status
conventions passRaw status
linux skipping; register-context skipping; relinker skipping; relinker-asan skipping; write-watch skippingRaw output
git diff --check upstream/main...refs/review/pr-12238— no output; exit status 0Raw output
merge-tree-exit=0; preview has edits from both branches indocs/dev/debt/libSceAgcDriver.mdNegative control
The author reports that
agc_driver_depth_plane_samplingand_evictingpassed with validation enabled on the candidate, and that the added sampling case failed withDepthSurface.cppfrommain(0x3e800000, expected0x3f400000). I have not independently run those GPU tests in this review.Findings
Blocking
main.CONTRIBUTING.mdrequires branches to be kept up to date. Please update it and rerun the focused AGC tests and checks on the resulting head.Depends on: none, but #12210 is still open and both PRs editdocs/dev/debt/libSceAgcDriver.md. Your comment says the combined result requires one branch's debt wording to be retained and “sample” added. The contribution rules require agreement on ordering and a matchingDepends on: #12210(or the agreed reverse order). Please coordinate and declare the agreed order.Non-blocking
Sources
78c1cb46e4017ab6865fa09df261148882ecfc38.mainat3a2b91981651569163768854a1fcdc7193b6667b.CONTRIBUTING.mdat3a2b91981651569163768854a1fcdc7193b6667b.Not verified
I did not run a local build, focused GPU tests, or console tests. Linux and specialized hosted checks were skipped. The reported GPU results are author-provided and are not a substitute for rerunning them after updating this branch.
To get this to a good state
Agree with #12210 on merge order, set the corresponding dependency on the checklist, update this branch to current
main, then rerun and report the required focused tests and validation checks on the new head. Add the requested cost measurement if available.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T05:49:31Z.
Review: CHANGES_REQUESTED
Re-checked — changes requested
The new sampled-depth reload and write-watch-gated regression address the previous test-scope concern, but this branch is still 36 commits behind current
main52c09d567d2fa453494dd720fcf53a98149468e4. The repository checklist requires a current-main base, and the reported tests are not on the refreshed integration.What I ran
29a96bfc5d1fa648096d68d6a2e4535d20b23bbcagainst currentmain.git merge-tree --write-treeandgit diff --check.Results
mainis not in the branch historygit diff --check3a2b919816basePlease update onto current
mainand rerun the focused sampled-depth tests and required validation-layer comparison on that head. I did not run the C++ or GPU tests locally.