fix(agc): retire a depth surface once a surface of another extent takes its planes #15404
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/15404"
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 JJenkx on 2026-11-03T05:39:00Z.
What
A depth surface is matched by its address, extent, format, samples and stencil address. A title with dynamic resolution binds the same depth memory at a slightly different extent from frame to frame, so each new extent creates a new surface.
takePlanethen hands the address's depth (and stencil) plane to the new surface. It copies the old surface's plane only when the extents are equal, so after a resize nothing is copied, and the old surface is left active, owning no plane, and never retired.releaseRetiredfrees only retired surfaces, so every resize leaks one depth image.Now
takePlanesremembers the surfaces that owned the address before. A single-sample surface that no longer owns any depth or stencil plane is retired withretireStoringStale. That stores its GPU results the guest has not received yet, skipping units the CPU has written since, so the guest memory holds what the console's would.releaseRetiredthen frees it at the next creation, unless a sampled view still holds it. Multisample surfaces are unchanged (#15300 covers their release).Seen in Contra: Operation Galuga (PPSA15368) on
main128b5c49ba. WithAPS5_TRACE_MEMORY_BUDGET, the device-local heap reached 19,676 MiB of an 8,176 MiB budget, 18,771 MiB of itvkAllocateMemory depth target. A local log of depth-surface creation (not part of this PR) showed 751 single-sample D32 surfaces at only 23 addresses, 177 of them at each of three addresses, with extents such as 3840x2160, 3132x1762, 2944x1656 and 2926x1646; 4 were released.Tested
tests/DepthSurfaceReuse.cppaddsTestDisplacedSurfaceRelease: three depth surfaces of different extents at one address, then a surface at another address (which runsreleaseRetired). The two displaced surfaces must have freed their images and the owner must keep its image. Onmainf6232fcfdawith only this test,agc_driver_graphicsfails with "a depth surface whose address a surface of another extent took over must free its image"; with this changeagc_driver_graphicspasses (VK_LAYER_KHRONOS_validation,ANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1; noVUID-lines).Measured in the title on the same base (
mainf6232fcfda), with the two arms run alternately (details in https://github.com/boykopovar/AnyPS5/pull/15404#issuecomment-6598654709). In full-length runs that reached the same briefing cutscene, peakvkAllocateMemory depth targetmemory was 6,403 and 6,481 MiB with this change, against 16,645 and 22,899 MiB onmain. Device-local usage still exceeds the 8 GiB budget, at 10.6 to 10.8 GiB instead of 17.2 to 23.1 GiB. Runs of both builds can stop at about 100 s from a separate heap corruption in this title, which also occurs onmain.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-03T05:44:49Z.
Review: COMMENTED
Reviewed — no blocking findings
The exact-head source review found no blocking defect in retiring a displaced single-sample surface after it relinquishes both tracked planes; hosted checks are still pending, so this is a comment rather than an approval.
What I ran
Reviewed both changed files at head
03a48a20a5226dfcf74254b35cbe6673cd426145against based1ae628bc2f62459cce1e9872ba5632c938c71f2; the merge preview is clean. Environment: Debian Linux x86_64, Python 3.11.2, GCC 12.2.0. The repository precheck and convention command were run; I did not configure or build AnyPS5.Results
Commands and unedited output
The precheck reported
checks failedonly because its optionaltools/pr_abi_audit.pyandtools/pr_test_quality.pyscripts were absent from the isolated PR snapshot; this PR changes no exports. Its diff, conventions and live mergeability checks passed.Negative control
I did not run a negative control: the added regression test needs the exact-head AGC test binary and Vulkan test setup, and no build was performed.
Findings
Blocking
None found in the reviewed change.
Non-blocking
The new regression asserts that displaced images are released and the current image remains alive. It does not directly assert guest-memory contents after retiring stale depth data; the implementation delegates that operation to the existing
retireStoringStalepath, which I inspected but did not execute here.Sources
Not verified
No local build, CTest, Vulkan validation run, console behavior or reproduced title memory measurement was performed. The author's AMD GPU test and main-versus-change observation are reported in the PR description, not reproduced here. Hosted checks were pending at the final refresh.
To get this to a good state
No code change is requested from this source review. I will refresh the hosted checks on this head and update the review if they complete; if the head changes, I will inspect the new diff and rerun relevant checks.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-03T07:37:42Z.
Review: APPROVED
Re-checked — same head, looks good
The exact-head source review found no blocking issue, and all applicable hosted checks now pass; the author reports the matched AMD Vulkan regression run succeeded.
What I ran
Re-checked open PR #15404 at head
03a48a20a5226dfcf74254b35cbe6673cd426145against based1ae628bc2f62459cce1e9872ba5632c938c71f2; the source diff is unchanged from the earlier full review and merges cleanly. Environment: Debian Linux x86_64, Python 3.11.2, GCC 12.2.0. I ran the no-build precheck, inspected the two changed files, verified the new test is included inagc_driver_graphics_tests, and refreshed hosted checks. I did not build locally.Results
Precheck table and unedited hosted check output
The precheck's optional helper errors were:
The separately run test-quality heuristic returned:
Negative control
I did not run one. The author reports that the new assertion fails on
mainand passes on this head under the stated AMD/Vulkan-validation setup; that hardware result is author-reported, not reproduced here.Findings
Blocking
None found in the reviewed change.
Non-blocking
The regression directly checks displaced image destruction and preservation of the current owner. The author reports the focused GPU test also passed with validation enabled and no VUID lines. The title memory measurement is from
mainonly; the PR does not claim a measured reduction on the changed build.Sources
Not verified
I did not independently run the AMD test, Vulkan validation, console behavior or a same-scene memory comparison. The author says the memory comparison remains unavailable because the title crashes on both builds before the relevant scene. No local build or CTest was run.
To get this to a good state
No change is requested for this reviewed head. If the head changes, I will review the new diff and rerun the applicable checks.