fix(agc): retire a live depth surface an out-of-place DB expand covers whole #24927
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/24927"
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 frankea on 2026-11-21T11:18:58Z.
What
An out-of-place DB expand (#6146) is a draw with
DB_RENDER_CONTROL.DEPTH_COMPRESS_DISABLE(bit 6) andDB_Z_WRITE_BASE!=DB_Z_READ_BASE. The DB reads the source surface (DB_Z_READ_BASE, its HTILE at DB_HTILE_DATA_BASE whenDB_Z_INFO.TILE_SURFACE_ENABLE, bit 29, is set) and writes the plane, uncompressed, at the write base.RunDepthExpandPassrefused every expand whose write base held the plane of a live depth surface ("into a live depth surface"), because the copy would land in that surface's own storage view, sampled reads would still be served from its image, and its stale host depth could later be stored over the expand.This PR retires such a surface first when the expand rewrites its plane whole, which is the rule a written storage view already follows (
RetireCoveredDepthSurfaces,a714d1b370):RunDepthExpandPass: for each plane that moves (depth atpass.destination, stencil atpass.stencilDestination) whose write base holds a live surface's plane, it builds the written extent: the write base, the source extent, the plane's element size (4 for Z_32_FLOAT, 2 for Z_16, 1 for stencil), the 64 KiB SW_64KB_Z_X block (DepthBlockExtent) and its blocks per row.RetireCoveredDepthSurfacesthen retires each single-sample surface whose plane starts at that base with the same element size, block and blocks per row and an extent no larger than the source's. Before the retire it stores a stale stencil plane the expand does not write (storeStaleStencil);retire()drops depth the surface held only on the host, since the console's expand overwrites it. No byte range is passed, so a surface of another pitch whose plane happens to fit in the written bytes is not treated as covered: the expand writes the source extent's texels, not the padding.RetireCoveredDepthSurfacescounts a surface as covered when either plane is, and stores an uncovered stencil plane but not an uncovered depth plane. So when the stencil write base holds the stencil plane of a surface whose depth plane is elsewhere and still holds depth only on the host (AnyStale(), which its depth draws set), retiring it would drop depth the expand never writes. That case is refused: "into the stencil plane of a live depth surface whose host-only depth it does not write". Without this check the new test below reads 0 in all 15,360 texels of that surface's depth plane after the expand.After the retire,
CachedStorageSurfacereturns an ordinary storage image of the write base, and the existing copy, the repeat check andStoreDepthExpandWritesrun as they do for a write base without a surface.Register semantics (field positions from Mesa's gfx10.json at 761d5c8a54f: DB_RENDER_CONTROL, DB_RENDER_OVERRIDE, DB_Z_INFO, DB_HTILE_SURFACE):
DecodeDepthExpandPassstill does not read the register.Debt: the "Out-of-place DB expand" entry now says that a live surface the write covers whole is retired first, losing its host-only depth, that a later depth bind of the write base reads guest memory (so a plane still pending as a storage result there is not seen, the same gap #6146 records for a write base without a surface), and that a surface it covers only in part throws. It also says that a surface whose stencil plane alone the expand writes while it holds host-only depth throws. To stay under 1000 characters the entry drops the clause "the whole plane is written when the viewport and scissor cover it" and words a few other clauses shorter ("the read depth plane", "samples", "a CPU- or DMA-cleared HTILE", "no pixel shader runs"); nothing else in it changes.
Tested
tests/execution/DepthExpandReview.cpp(PM4 submissions throughsceAgcDriverSubmitDcb), three new cases. The live surface is drawn first at the write base with depth writes, then the read surface is drawn with a different gradient and expanded onto the live surface's base, so the live surface is not the current depth target, as in the title:agc_driver_depth_expand_partly_covered_live(--partly-covered-live), because a refused draw is raised again when the driver shuts down;agc_driver_depth_expand_live_stencil_plane,--live-stencil-plane).On main the first two fail on the old refusal and the last two fail because main words the refusal "into a live depth surface". Mutations checked on the Mac: retiring every surface at the write base, or passing the written byte range instead of the extent, fails the partly covered case; skipping the stencil store fails the D32S8 case; dropping the stencil-plane check fails the last case. In the base runs below, main's
DepthSurface.cppwas built with this PR's test files.fdf9d0ab79ec70570118agc_driver_depth_expand_review,agc_driver_depth_expand_partly_covered_live,agc_driver_depth_expand_live_stencil_planedepth_expand,depth_storage_reuse,depth_surface_last_writer,native_multisample_depth,native_depth_native_depth_bda_clearcrashes at startAPS5_PIPELINED_DRAWS=0), partly covered live, live stencil planedepth_expand_out_of_place(default and inline),depth_storage_reuse,depth_surface_last_writer,native_multisample_depthBoth refusal entries end with
std::_Exit(0)while the driver's threads still run. On Windows without the validation layer that exit faulted after the pass line (0xc0000005, ctestSegFault), which the layer-loaded runs above did not show;c0ae94e523callsTerminateProcessfirst on Windows, asMultisampleRetirement.cppdoes. Paired runs on the RTX 4090 (driver 621.14), after merging mainef7dc4452d(d381802127),ANYPS5_REQUIRE_VULKAN=1:d381802127(before)c0ae94e523agc_driver_depth_expand_review,_partly_covered_live,_live_stencil_plane, no layer, 3 runsOn the Mac (M5 Max, MoltenVK local build, layer inserted, 0 VUIDs)
c0ae94e523passes the default run,APS5_PIPELINED_DRAWS=0, and both refusal entries.Clean rerun on the RTX 4090 (driver 621.14) after both build trees were reconfigured and fully rebuilt (an earlier paired run shared a build tree with another job, so the rows above may carry stale objects; the
native_depth_bda_clearcrash they show does not reproduce here). Base is mainef7dc4452dwith this PR's two test files (10b68aa98a9);ANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1:c0ae94e523agc_driver_depth_expand_review,_partly_covered_live,_live_stencil_plane, no layer, 3 runsdepth_expand,storage_reuse,last_writer,native_depth,native_multisample_depth, without and with the layerThe skipped test,
agc_driver_native_depth_driver_queued_fill, needs a write-watched host import and is skipped on both sides.Title: Onimusha: Way of the Sword (PPSA27836 01.000.001), Windows, RTX 4090. Each frame of its first story load draws a 960x1080 D32 depth prepass into a transient pool slot, then a D32S8 main target, then expands the D32S8 surface out of place into that slot (DB_RENDER_CONTROL 0x60, DB_Z_READ_BASE 0x20015f0000, DB_Z_WRITE_BASE 0x2001170000, DB_RENDER_OVERRIDE 0xf8000000) and samples the result as a plain 2D 32_FLOAT texture with metadata off; it never binds the slot as a depth target again. When the pool hands the expand the slot the prepass target still lives in, main refuses the expand with "into a live depth surface" about 6 min after launch. The live surface there is a single-sample D32 of exactly the source's extent, with HTILE, not the current depth target, whose depth the prepass drew on the host; in gameplay the same shape comes up at 1536x1728 and 1456x1640. With this PR on main
3638c8e039+ #24572 + #24735 + #10469 (one run, 30 min cap, made on f85baaf2858, before the stencil-plane refusal was added, which this title's D32 destination cannot reach; CROSS throughAPS5_PAD_INPUT_FILEfor the autosave notice, New Game, difficulty and layout): the title gets past the expand, finishes the first story load (the 256-pass stencil replay draws of #24572) and reaches the first playable scene, the shrine courtyard fight, at about 0.3-0.5 FPS. About 24 min in it stops on the next refusal, "native multisample depth publication cannot distinguish an unwritten byte from a same-value guest store" (a compute shader reading a native multisample depth plane, DepthSurface.cpp, not touched here). That belongs in a separate PR.Checklist
main; no other open PR implements the same functions (#21486 takes out-of-place expands with vertex layer-export bits in State.cpp and does not touch the live-surface refusal;tools/pr_overlap.pyfinds no confirmed overlap, and none of the open PRs that changeDepthSurface.cpptouchRunDepthExpandPassorRetireCoveredDepthSurfaces)NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repositorySummary by CodeRabbit
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T11:43:57Z.
Review: COMMENTED
Reviewed — no blocking findings
The reviewed change is at head
ec7057011800297c789e7defd528eb6866cb262f; I found no verified blocking defect, but did not run the tests.What I ran
I inspected the prepared diff and changed files at the pinned head. No commands or tests were run.
Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
Runtime behavior and the author-reported Windows/macOS test results were not independently verified. Files read:
DepthSurface.cpp,agc_driver_depth_expand_review_tests.cmake,DepthExpandReview.cpp,agc-db-expand-covered-live-surface.md, and the prepared description, commits, manifest, diff, and review README. No files were excluded by the manifest.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T04:23:45Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the inspected implementation and tests support merging.
What I ran
Reviewed head
c0ae94e523c5bc370e80337e18e75c2d7d1c718a. No build or tests were run in this review.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
No commands or tests were run. The implementation was reviewed in
DepthSurface.cpp; the two added test cases and changed test sections were read inDepthExpandReview.cpp; all ofagc_driver_depth_expand_review_tests.cmakeand the debt entry were read. The full test file outside the changed ranges and unrelated repository files were not reviewed.files.jsonwas not present in the review folder, so exclusions could not be independently checked; the manifest lists four changed files, all marked included. The reported Windows, macOS, Vulkan validation-layer, and game behavior were not independently verified.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-26T15:32:12Z.
Review: COMMENTED
Actionable comments posted: 2
20039791-a7d0-42c7-9d84-37f6f0b01389Reviewing files that changed from the base of the PR and between
ef7dc4452dand5f5d9dd9cd.core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cppcore/libs/prx/libSceAgcDriver/tests/cmake/agc_driver_depth_expand_review_tests.cmakecore/libs/prx/libSceAgcDriver/tests/execution/DepthExpandReview.cppdocs/dev/debt/changes/agc-db-expand-covered-live-surface.mdIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-26T15:49:01Z.
Review: COMMENTED
Reviewed — no blocking findings
The inspected code supports the whole-plane retirement and refusal behavior; tests were not run in this review, so a formal approval is not justified.
What I ran
Read the prepared bundle for head
5f5d9dd9cddf5a6876b3482419dc19f3b24486b8and used the PR reader to inspect the changed implementation, test additions, and debt note. No commands or tests were run. The four changed files listed inmanifest.jsonwere present; no exclusions were reported there.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The submitted test and hardware results were not independently reproduced. I read the changed lines in all four files and the relevant coverage and retirement helpers, but did not read the entirety of the 5,327-line
DepthSurface.cppor the 799-line test file.To get this to a good state
Nothing is required. Optional: run the focused depth-expand test cases on the pinned head before merge.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-27T03:32:05Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the points below are optional.
What I ran
Reviewed head
8cac499a5a76070aa22b7960ab86e33337c8bdf8usingrepo_read.pyagainst the prepared review bundle and source at the pinned head. I did not run build or tests; reported test results below are author supplied.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
No build, tests, or hardware runs were performed. The author reports Windows 11/RTX 4090 and macOS/M5 Max test runs in
description.md; these were not independently confirmed. Read:description.md,commits.md,manifest.json,diff.patch,DepthSurface.cpp,DepthExpandReview.cpp,agc_driver_depth_expand_review_tests.cmake,ShaderResources.cpp, andagc-db-expand-covered-live-surface.md.files.jsonwas unavailable; the manifest marks all four changed files as included, and each changed file was read at the pinned head. No excluded changed files were listed in the manifest.To get this to a good state
Nothing is required.