fix(libSceAgcDriver): sample a PS4 depth buffer through a T# smaller than its padded extent #9672
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9672"
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 ntamas94 on 2026-10-22T07:45:02Z.
What
On the PS4 a depth target's extent is decoded from
DB_DEPTH_SIZE, which holds the surface padded to whole macro tiles: the 1920x1080 Depth2D64 depth buffer of Gang Beasts (CUSA04865, Unity) is 2048x1152. The title then samples the depth plane through an R32F T# of the real size: 1920x1080, same base address, GCN pitch 2048.DepthSurfaceTextureonly took a view of exactly the target's extent, so this view fell back to guest memory, which never holds native depth. The depth-of-field and lighting passes read whatever the memory held:On the console the same scenes are sharp and stable.
A PS4 depth target now records that it is one (
DepthTarget::gcn, set where the padded extent is decoded). A view of its depth plane is served by the existing depth plane copy when all of these hold:The copy is sized and keyed by the view: it copies the view-sized top-left corner of the native depth, so texel (x,y) of the T# reads depth texel (x,y), and normalized coordinates and clamping follow the T#. A view of the exact extent, and every PS5 target, keep the previous path. A smaller view of the stencil plane still reads guest memory; the debt entry says so. Like the other plane copies, the copy is refreshed on each lookup while the surface is the last drawn depth target.
This moves Get-fix/AnyPS5#9 (opened against
ps4/limbo-gpu) tomain, as Get-fix asked there. It was stacked on #9431, which is merged; the branch now has currentmainmerged in.mainmeanwhile keys the plane copies without the layer count and evicts them over a budget (APS5_DEPTH_PLANE_COPY_MIB); the view-sized key and extent of this PR go into that key, so a cropped and a full-size view of one target are two copies under the same budget.main's cube-array rule for depth planes (any multiple of six layers) is kept in theplanescondition.Tested
Windows 11 Pro (10.0.26200), WinLibs GCC, NVIDIA GeForce RTX 2080 (driver 617.14), Release build with
BUILD_TESTING=ON, on this branch with currentmain(7d9a2fc713) merged in; #9431 is merged, so the branch's diff againstmainis this PR's own change:agc_driver_gcn_padded_depth_sampling(new) draws known depth into 64x64 D32 and D16 targets flagged as PS4 and reads it through 48x40 views. It checks 26 texels including the right and bottom edges, 6 out-of-range coordinates that clamp to the view's edge, and the same again after a redraw. It passes; withDepthSurface.cppreverted to the base it reads guest memory and fails (read 0.00000000, expected 0.25000000).agc_driver_graphicsand the depth execution tests pass:depth_bias_per_face,depth_compare_copy,depth_fast_clear,depth_fast_clear_submit,depth_htile_write,depth_plane_guest_layers,depth_plane_sampling,depth_storage,depth_storage_dispatch,depth_storage_reuse,depth_surface_from_storage,depth_surface_last_writer,gcn_detile,native_multisample_depth,sample_mask_depth_stencil,stencil_replay,stencil_replay_no_gpl,native_depth_retirement,native_depth_clears,native_depth_clear_refusals; three runs each, with--timeout 300;main'sstencil_plane_memorypasses too:native_multisample_depthtakes 1 to 2 s alone on both this branch andmain, but ran past its 30 s limit while builds loaded the machine.tools/check_conventions.py --base main(7d9a2fc713) with this title and description: no findings. The debt change is one sentence in the "PS4 render targets and display buffers" entry; "Depth plane copies" is untouched.main7d9a2fc713(100% tests passed out of 25, the depth, display-buffer and graphics tests of this stack) and this branch with thatmainmerged in (100% tests passed out of 23, the tests above andstencil_plane_memory) withVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,ANYPS5_NO_SHADER_CACHE=1,ANYPS5_REQUIRE_VULKAN=1andVK_LOADER_DEBUG=warn,error,ctest -V --timeout 300, on the NVIDIA GeForce RTX 2080, driver 617.14, Windows 11 (10.0.26200), Vulkan SDK 1.4.363.0: both logs carry the loader'sadding layers "VK_LAYER_KHRONOS_validation"line (62 and 62 times) and neither reportswas not found but was requested by env var VK_INSTANCE_LAYERS;VUID-ids onmain: 0, on this branch: 0, new on this branch: 0.43497e2a96merged ontomainba5b533: build passed, 2,211 tests passed, 0 new failures (3 also fail onmain, 1 unstable there), no new validation IDs againstmainin 856 GPU tests, on an NVIDIA RTX 2000 Ada under Ubuntu.Checklist
main; no other open PR implements the same functions (currentmain7d9a2fc713merged in; #9431 is merged; searched open boykopovar/AnyPS5 PRs for padded depth, depth extent andDB_DEPTH_SIZEon 2026-10-22)NotImplemented_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 fogydes on 2026-10-22T08:47:27Z.
Reviewed; the crop itself is right. The
croppedgate narrows properly (2D, level 0,lastLevel == 0,baseArray == 0, not stencil, host format equal to the base's, extents within the padded extent, pitch identity when a guest pitch is known), and the crop is a genuine top-left crop: the copy image is created at the sampled view's extent and the surface→staging/staging→copy regions use exactly{extent.width, extent.height, 1}, so texel (x,y) of the T# reads depth texel (x,y) — matching what the body claims. Exact views and PS5 targets fall to the old gate, and theplanespredicate correctly drops the terms the new top-of-functionbaseLevelcheck already enforces. Bothimage_sample_lzandimage_loadpaths and D32/D16, edge and recheck cases are covered by the execution test.Two things worth recording before merge (either in the debt entry or the body):
The GCN-pitch half of the headline fix (
resource.gcnPitch == base.extent.width) has no in-repo test —tests/execution/GcnPaddedDepthSampling.cppbinds a PS5-style T# because the harness has no GCN T# decode, so that branch is validated only by the title run. The body discloses this, but it's the PR's own integration point; if a harness path to decode a GCN T# becomes available, that's the first case to add. As it stands the gate also acceptsresource.gcnPitch == 0(an RDNA-styled T# over a PS4 depth base crops purely on host/plain-extent identity) — deliberate per the body, but the pitch-identity claim in the title is only about the gcnPitch branch, which is worth spelling out.The gate doesn't compare
resource.tileMode(or the DB tile mode) against the depth surface's — for the guest-memory fill path the detiler usesresource.tileModewhile the copy compares againstbase's properties. The same exposure predates this change for exact views, so it's not a regression; noting it because the crop gate is where the two descriptor families meet.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T08:58:47Z.
Review: CHANGES_REQUESTED
The isolated fix is narrowly gated to PS4 GCN depth targets and a smaller level-0 2D depth-plane view, and the new test exercises D16/D32, crop edges, clamp behavior, redraw refresh, and the unmodified failure path. The PR reports a useful Gang Beasts reproduction and broad depth-test coverage. The hosted conventions/intake/labels checks pass, and
git diff --checkpasses for the fetched head.The branch is currently
CONFLICTINGwithmain; its declared dependency #9431 is also conflicting, and the PR notes a debt-file conflict. Please coordinate/rebase after #9431 is resolved and rerun checks on the current merge commit.Because this changes the AGC driver, CONTRIBUTING requires paired focused tests on
mainand the change withVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,ANYPS5_NO_SHADER_CACHE=1, andANYPS5_REQUIRE_VULKAN=1, usingctest -Von the same machine/GPU. Please confirm the requested layer loaded, compare both logs for newVUID-errors, and record the GPU on the checklist. The reported Windows/NVIDIA test runs are extensive, but the PR does not include this required paired validation-layer comparison.Imported from boykopovar/AnyPS5. Originally posted by ntamas94 on 2026-10-22T10:13:50Z.
Thanks. The branch conflicts with
mainonly through #9431'sGraphics/src/State.cppand, for this commit, the "Depth plane copies" debt entry thatmainrewrote; I will rebase as soon as Get-fix has rebased #9431 and rerun the checks on the new merge commit. Paired validation-layer run, now in the description:main(100% tests passed, main build7e2ba73e4) and this branch (100% tests passed) withVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,ANYPS5_NO_SHADER_CACHE=1,ANYPS5_REQUIRE_VULKAN=1andVK_LOADER_DEBUG=warn,error,ctest -V, on the NVIDIA GeForce RTX 2080, driver 617.14, Windows 11 (10.0.26200), Vulkan SDK 1.4.363.0: both logs carry the loader'sadding layers "VK_LAYER_KHRONOS_validation"line (78 and 64 times) and neither reportswas not found but was requested by env var VK_INSTANCE_LAYERS;VUID-ids onmain: 0, on this branch: 0, new on this branch: 0.AI-assisted: yes (Claude Code)
🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T12:32:05Z.
Review: COMMENTED
The updated report addresses the paired validation-layer evidence requested earlier: it identifies the same RTX 2080/driver/Windows setup, confirms the layer was loaded, and reports no new VUIDs. The focused regression covers D16/D32 views, crop edges, clamping and redraw refresh, and the author reports the broader depth tests and Gang Beasts run.
The remaining issue is the dependency stack. This branch is still based on #9431, which conflicts with current main, and the reported before/after validation uses main
7e2ba73e4while current main has advanced. Please coordinate and rebase once #9431 is current, then rerun the focused depth sampling tests and current-main comparison on the resulting merge commit. The Gang Beasts report is from the earlier Get-fix branch, so please confirm the affected current-main path and update the bring-up discussion if the furthest point or blocker changes. I did not run a local C++ build because this checkout has no configured build tree and the filesystem is full.Imported from boykopovar/AnyPS5. Originally posted by ntamas94 on 2026-10-22T13:21:53Z.
Rebased onto #9431's new head (
26d651d3e, onmain7e2ba73e4); the commit applied without conflicts, the debt sentence merged into the current "PS4 render targets and display buffers" entry, and "Depth plane copies" is untouched. The 28 depth and graphics tests pass on the new base. Paired validation-layer run, now in the description:main(100% tests passed, main build7e2ba73e4) and this branch (100% tests passed) withVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,ANYPS5_NO_SHADER_CACHE=1,ANYPS5_REQUIRE_VULKAN=1andVK_LOADER_DEBUG=warn,error,ctest -V, on the NVIDIA GeForce RTX 2080, driver 617.14, Windows 11 (10.0.26200), Vulkan SDK 1.4.363.0: both logs carry the loader'sadding layers "VK_LAYER_KHRONOS_validation"line (78 and 66 times) and neither reportswas not found but was requested by env var VK_INSTANCE_LAYERS;VUID-ids onmain: 0, on this branch: 0, new on this branch: 0.AI-assisted: yes (Claude Code)
🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-10-29T10:43:44Z.
Review: APPROVED
Reviewed — approved
The crop merges cleanly into current
main, builds, passes the new test and the depth tests with the validation layer loaded and no newVUID-lines, and the new test fails with the production change reverted; one non-blocking note about the test-onlygcnPitch == 0clause.What I ran
43497e2a964d861222522467c363e5e7b3051cf1main:1db077e876a839f75d11a56e728e7f56a4a8c25emain+ head,--no-ff, no conflicts (docs/dev/debt/libSceAgcDriver.mdauto-merged)BUILD_TESTING=ON, in a clean worktreeResults
maingit diff --checktools/check_conventions.py --base origin/mainAll conventions checks passed.mainagc_driver_gcn_padded_depth_sampling0.47 smainInsert instance layer "VK_LAYER_KHRONOS_validation": 29 lines (merge), 28 (main)was not found but was requested by env var VK_INSTANCE_LAYERSVUID-linesmain, 0 on the merge, so none newwindows,conventions,labels,eligibility,reportsucceeded (a secondconventionsrun was cancelled);linux,relinker,relinker-asan,write-watchandregister-contextwere skippedctest on the merge (excerpt)
Negative control
I restored
Graphics/src/DepthSurface.cppandGraphics/src/State.cppfrommainand kept theDepthTarget::gcnfield inState.hpp, because the test sets it. With that tree,agc_driver_gcn_padded_depth_samplingfails on its first probe, as the description says:output
With the merged files restored, it passes again.
Findings
Blocking
None.
Non-blocking
The
gcnPitch == 0arm of the crop gate only runs in the test, and the production arm has no test. fogydes already raised this; here is new evidence that the two arms never overlap.DepthTarget::gcnis set fromShaderRecompiler::GcnGuestShaders()(State.cpp:453-454).gcnPitchand requiresgcnPitch >= width, so the pitch is never 0 (GuestTextureResource.cpp:312-315).base.gcn && resource.gcnPitch == 0cannot happen, and theresource.gcnPitch == 0 ||term incropped(DepthSurface.cpp:2509) exists only for the test.state.depth->gcn = trueby hand (GcnPaddedDepthSampling.cpp:173) over an RDNA T#.resource.gcnPitch == base.extent.width, is therefore covered only by the title run. Nothing in the repository would catch a pitch-unit mismatch betweenDB_DEPTH_SIZEand the T# pitch.The execution harness can already switch to GCN guest mode:
GcnBufferFormatLookup.cppcallsShaderRecompiler::SetGcnGuestShaders(true)after opening the device (GcnBufferFormatLookup.cpp:172). That needs GCN-encoded shader code, so it is more work than the current test. Suggested follow-up:resource.gcnPitch == 0 ||term, so that the gate only accepts what a PS4 title can produce.If that is out of scope here, please add one sentence to the debt entry saying the GCN-pitch arm is checked only by a title run.
Not verified
APS5_DEPTH_PLANE_COPY_MIBbudget when a title keeps both a cropped and a full-size copy of one target.agc_driver_depth_plane_sampling_evictingpasses, but it does not include a cropped view.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T11:08:00Z.
Review: CHANGES_REQUESTED
Re-checked — changes requested
The new report addresses the prior merge conflict and gives 22 depth tests three times each, paired validation-layer results, and conventions on head
43497e2a96. The branch is still based onf7e84c4cf1; currentmainisba5b5330b3. Current-main changes overlap the debt entry, and the repository requires the current main base. Please merge current main, run the focused depth tests and validation comparison on the resulting exact head, and update the report. The Gang Beasts result is correctly labeled historical; it does not substitute for current-head performance evidence.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T21:23:05Z.
Review: CHANGES_REQUESTED
Re-checked — new head, changes requested
The new depth-test report covers head
c599331a9b9e575a1458c75def9b03acd9d0cfb6againstmain951f374c87, but that branch does not include livemainc40cef843681418b4d66df2939a92ba8ba6ba5d9as required by the contribution rules.What I ran
Compared exact PR head
c599331a9b9e575a1458c75def9b03acd9d0cfb6against livemainc40cef843681418b4d66df2939a92ba8ba6ba5d9on Linux x86-64 using Git and GitHub CLI. The merge preview is clean. I did not build or run GPU tests locally.Results
mainmaingit diff --check951f374c87; not independently run hereUnedited command output
git diff --checkproduced no output and exited successfully.Findings
Blocking
main. The author’s refreshed tests cover the branch merged with951f374c87, while livemainis nowc40cef843681418b4d66df2939a92ba8ba6ba5d9. The merge preview is clean, butCONTRIBUTING.mdrequires one branch based on currentmain. Please update the branch and refresh the exact-head test report before approval.Non-blocking
stencil_plane_memoryand describes theDepthSurfaceTexture::planesconflict resolution. I did not independently run those tests or verify GPU behavior.Sources
c40cef843681418b4d66df2939a92ba8ba6ba5d9c599331a9b9e575a1458c75def9b03acd9d0cfb6Not verified
I did not run the focused tests, a local build, Vulkan validation, or a console/title run. The author’s test results are reported, not independently confirmed.
To get this to a good state
Update onto live
main, rerun the same focused depth and validation-layer checks on the resulting exact head and base, and refresh the report. I will rerun the merge preview, whitespace check, and relevant tests against that new head.Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-03T10:38:36Z.
Review: APPROVED
Re-checked — approved
Since my review of
43497e2a96, the branch has taken several merges ofmain(the latest isd8d638d5af) andf8bc6ebb92, which shortens this PR's sentence in the debt entry. The PR's own code is unchanged, the merge builds and passes, and the negative control still fails as it should.What changed since my last review
244e1da99bis unchanged. The PR's code diff againstmainis still the same:DepthTarget::gcnfield and the line that sets it;exact/croppedgate and the view-sized plane copy key and extent inDepthSurfaceTexture;maintouch theplanesline and the stale check right below it. The merged lines keepmain's cube-array rule and theOverwrittenInMemory() || OverwrittenOnGpu()check, and drop only the exact-extent andbaseLevelterms. ThebaseLevelcheck now happens earlier in the function.f8bc6ebb92shortens this PR's sentence in "PS4 render targets and display buffers" so the entry stays under the length limit.main's text in it is unchanged.main7d9a2fc713for the author's runs. It adds TechLevelZero's NVIDIA CI on43497e2a96. RNK123 also posted an AMD/RADV run onf8bc6ebb92(author-reported by them, not checked by me).What I ran
d8d638d5af0d0669cf6b1a2bc067acaa8c9e3343main4f41f4c375f5abb487dbd184fbc150f31994d762e0ab1c3b17ea3d18e2f157456f87ee00ceeb74d4git diff --checkcheck_conventions.pyAll conventions checks passed.maintoo.agc_driver_gcn_padded_depth_samplingdepth_plane_sampling*,native_depth_uniform_planesagc_driver_native_depth_uniform_planes; it comes frommain(see below).git status --porcelainemptyThe
agc_driver_native_depth_uniform_planesVUID comes frommain, not from this PR. The script flaggedVUID-vkCmdDispatch-groupCountX-00386there, marked "test not run on main": the baseline (d1ae628bc2) is older than the test. I ran the test withDepthSurface.cppandState.cpprestored frommain4f41f4c375. It reports the same 8VUID-vkCmdDispatch-groupCountX-00386lines as on the merged tree, so I do not count it against this PR.Negative control
With
DepthSurface.cppandState.cpprestored frommain, the new test fails on its first probe:output
With the merged files restored, it passes again.
Previous findings
gcnPitch == 0arm of the crop gate runs only in the test, and thegcnPitch == base.extent.widtharm has no test. The gate at DepthSurface.cpp:3082 is unchanged. The shortened debt sentence at libSceAgcDriver.md:119 does not say that the GCN-pitch arm is checked only by a title run. This does not block a merge; the earlier suggestions still apply: a GCN-mode test case, or one sentence in the debt entry.New findings
Blocking
None.
Non-blocking
None.
Not verified