feat(agc): reuse a native multisample colour target and honour guest HTILE clears #6808
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6808"
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 KingDarkHN on 2026-10-16T12:53:36Z.
What
Sonic Superstars (PPSA06888) reaches the menu, but as soon as a level starts the emulator aborts
because it renders into a native multisampled colour target and then reuses that guest memory
for something else while the driver still guards it as a resident target (issue #5933). This branch
builds on #6297 and #6300 (its first three commits) and adds:
RequireNoMultisampleTargetinstead of throwing, viathe new
retireGuardForAddress(issue #5933).the surface's clear value and neither the depth nor the stencil plane changed.
the plane up to whole 128x128 blocks, so a neighbouring allocation could land in the padding and
wrongly retire a surface it never reused.
disabled (
TILE_STENCIL_DISABLE), and accept a clear-proven HTILE without ITERATE_256 or pipealignment.
A guest read over a resident native multisample depth guard is not retired: it keeps
refusing (
sample-preserving guest publication of native multisample depth is not implemented),matching the contract of #6727 for an unwritten surface, until sample-preserving publication of the
depth, stencil and HTILE planes to guest memory exists. The read-site classification, whole-fill
HTILE note and exact-plane overlap work are intended to be rebased onto #6727 once it lands;
written-owner publication will be a separate change with its own regression. With this branch Sonic
Superstars aborts on a register read over a written depth owner — the documented follow-up.
Tested
agc_driver_native_multisample_depth(a metadata-only HTILE write with no producer notemust be served as a fast clear; a reuse read over a resident depth guard must refuse and leave the
owner resident),
agc_driver_depth_fast_clear,agc_driver_depth_fast_clear_submit,agc_driver_depth_surface_last_writerandagc_driver_depth_storage_reusepass. Fullctest -R agc_driveris at 98% with the same pre-existing failures as the base commit; none areintroduced (
worker_failure_logalso fails identically with this branch stashed).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-16T13:04:11Z.
I compared this head with open #6727 because both replace
RequireNoResidentDepthReadinDepthSurface.cpp. #6727 tracks host writes (NoteDepthSurfaceWrite,CopyAspectFrom, store-back) and only retires a guard on a guest read whenhostWrittenis false. In this PR’s replacement, a guest reuse read retires the owner whenattachmentActiveis false, but I don’t see an equivalenthostWrittencheck. Those conditions can differ for a native depth surface that was written by the host and is no longer the current attachment. Could you coordinate with #6727 and preserve that refusal (or explain why this reuse path proves the guest memory is current), with a regression covering a host-written inactive owner? The two heads touch the same guard/lifecycle code, so they should be reviewed together before either merges.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-16T13:14:30Z.
Review: CHANGES_REQUESTED
The updated head still has this correctness gap at
RequireNoResidentDepthRead_nid_no_patch: once an overlapping guard is inactive as an attachment, it retires the owning surface without checking whether the host image contains writes that have not been published to guest memory.retire()only marks the owner inactive and erases the guards; it does not copy the host depth/HTILE contents back. An inactive owner can therefore still have newer host data, so a guest read after reuse can observe stale bytes. The related open #6727 trackshostWrittenand refuses this transition for a written owner. Please preserve the same refusal (or provide a path that publishes the written data first), and add a regression that writes the depth target on the host, makes it inactive, then attempts the guest reuse read.Imported from boykopovar/AnyPS5. Originally posted by KingDarkHN on 2026-10-16T13:32:58Z.
You're right about the underlying gap:
retire()drops the owner without copying the host depth/stencil/HTILE image back, so a guest read that means to observe the rendered samples can see stale bytes. I tried your suggestion before replying.I added the same
hostWrittennotion #6727 uses — set from draws with depth writes or stencil writes on both the plain and cached-recipe draw paths, fromCopyAspectFrom, and from storage write-back, with host clears after a proven guest HTILE clear not counted — and made the overlapping owner refuse. The suite stays green, but the title then aborts on a real reuse site:So the strict refusal can't ship on top of this head without sample-preserving publication, which is not implemented for native multisample depth (the sampling debt entry already says so). I also tried letting the retirement through only once the guest has overwritten the owner's memory, the
memoryOverwrittenpredicate the create-time path already uses; the title still aborts, because a 17 MB owner range is not fully write-watched, soWrittenSincereports no reuse even when the guest has repurposed the memory.What this PR does instead is bounded and explicit: it retires only when the surface is not the current attachment and the read is a reuse read (context-register, texture or vertex-buffer). It is a compatibility workaround for SONIC SUPERSTARS (PPSA06888), not a correct general fix, so I have recorded the gap as a debt entry in
docs/dev/debt/libSceAgcDriver.mdrather than leaving it implicit. That is also why I did not add the regression you asked for: it would pin the refusal that aborts the title.On coordination: #6727 and this head both rewrite
RequireNoResidentDepthRead_nid_no_patchand touch the same guard lifecycle, so they cannot both land as they are. I am happy to rebase on #6727 once it is in and keep only the parts that don't overlap — the read-site classification, the whole-fill HTILE note and theOverlapsused-size fix — and to split publication of a written native multisample depth owner into its own task.Would you rather I gate the retirement further in the meantime, or land the debt-documented workaround and follow up with publication?
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-16T13:36:47Z.
Thanks for adding the host-write tracking and documenting the limitation. I would not merge the current compatibility retirement as a general fix: it can discard newer host depth/stencil/HTILE data, and #6727’s contract is explicitly to refuse that state until sample-preserving publication exists. The measured title failure makes this a real follow-up, but it does not make the guest bytes safe to expose. Please rebase the read-site classification, whole-fill HTILE note and exact-plane overlap work onto #6727 after it lands, and keep written-owner publication as a separate change with its own regression. If you want to pursue the bounded workaround independently, please first provide evidence that the guest read is a reuse/alias event whose contents are intentionally replacing the old surface; the current “not attached” condition alone does not establish that. I’ll keep the changes-requested review in place until the unsafe retirement is removed or a publication path is added.
Imported from boykopovar/AnyPS5. Originally posted by KingDarkHN on 2026-10-16T13:55:43Z.
Thanks for the careful review — I agree, and I've followed it. Exposing guest bytes for a written
owner is not safe, and #6727's contract is the right one until publication exists.
I've removed the unsafe retirement. A guest read over the guard of a resident native multisample
depth surface now refuses again (
sample-preserving guest publication of native multisample depth is not implemented); it no longer retires the owner, so no host depth, stencil or HTILE data isdiscarded on a read.
RequireNoResidentDepthReadis back to a plain overlap refusal, the read-siteclassification is no longer wired into a retirement path, and the
hostWritten/read-site machineryis gone.
What the branch keeps:
depth and stencil planes untouched);
Overlapsnow compares the bytes the plane stores, not the padded128x128 footprint);
TILE_STENCIL_DISABLE) import and the clear-proven-HTILEacceptance without
ITERATE_256/pipe alignment.I updated the debt entry (
docs/dev/debt/libSceAgcDriver.md): a written owner is refused, SONICSUPERSTARS (PPSA06888) aborts on a register read over one (measured on an RTX 5060 Ti, driver
610.57.04), and publishing the samples is the follow-up.
Plan, as you suggest:
exact-plane overlap work onto it;
with its own regression.
Branch updated (head
734edb5c2); title and description reflect the narrower scope. Fullagc_driversuite at its pre-existing pass rate, andagc_driver_native_multisample_depthpasses(the reuse-read cases now assert a refusal that leaves the owner resident).
Imported from boykopovar/AnyPS5. Originally posted by billythemenace2 on 2026-10-16T15:26:27Z.
A Windows data point for this branch: SONIC SUPERSTARS (PPSA06888) on
734edb5c2merged ontomain452494439. Windows 11, MinGW-w64 GCC 15, Release, AMD Radeon RX 5700 XT (driver 32.0.21045.5002). No input, no environment variables.It now stops a few seconds after start, during the logo screens, at the depth refusal you describe:
So it matches your Linux run on the RTX 5060 Ti. The
native multisample stencil import requires HTILE stencil metadatastop from #6300 (eight 1920x1080 2-sample D32S8 targets withhtileStencil=0,htileDepthOnly=1) did not appear before this stop. I can't tell from this run whether those targets were reached, so I'm not counting it as confirmed.I can rerun it on this machine when the depth publication follow-up is up.
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by Amoenus on 2026-10-16T19:56:27Z.
Code review location:
core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cpp; line 609[P1] Preserve written color data before retiring its guard
This executes for every overlapping color guard. retireGuardForAddress marks the resident inactive and erases its guard without checking whether the host image has unpublished writes or copying its samples back. RequireNoMultisampleTarget then returns, allowing a guest reader to consume the old bytes. A read classified as reuse does not prove those bytes replace the rendered content; this function does not even classify the access. The same ownership concern that prompted the depth correction still applies to color. The drawn-color/guest-buffer counterexample in #6480 documents the stale-byte hazard, although I have not run that fixture against this PR. Please preserve the refusal until replacement is established or samples are published, and add a written-color/read regression.
Imported from boykopovar/AnyPS5. Originally posted by Amoenus on 2026-10-16T19:56:27Z.
Code review location:
core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cpp; line 611[P2] Copy the guard before unlocking and erasing it
range is a reference to an element of guarded(). After the shared lock is released, another writer can invalidate it; retireGuardForAddress then calls std::erase_if on that same vector and removes the overlapping entry. Reading range.address, range.bytes and range.samples afterward therefore uses an invalidated reference. Copy the needed fields while the shared lock is still held and use that copy for the diagnostic. This remains necessary if the retirement semantics are corrected separately.
Imported from boykopovar/AnyPS5. Originally posted by Amoenus on 2026-10-16T19:56:27Z.
Review: COMMENTED
Source review of exact head
734edb5c2while checking overlap with native color publication work. The previous depth correction is acknowledged; the remaining color retirement has the two findings below. I did not build or run this PR or its title. AI-assisted: Codex; author responsible.Imported from boykopovar/AnyPS5. Originally posted by Amoenus on 2026-10-17T00:35:10Z.
@KingDarkHN Updated in place: the qualified sample-preserving stack is #6973 → #6987 → #6989 → #6995 → #7002
0cdc81ae9f, retaining exact credited #6498e15c428b4dancestry.#7002 has 99 focused passes (87 actual NVIDIA/AMD GPU, 12 CPU), full Windows builds, and the same nine AMD DCC assertion failures as literal main
1e774a3b22; zero VUIDs/validation errors/warnings. All writable bindings are checked before read-only publication. Historical dependency/reversed-order controls retain their original pins, without a new rerun claim. Current scope and stack evidence are maintained in #6480 and #7002.This is our adapted composition, not validation of unchanged #6808 or SONIC SUPERSTARS. For PPSA06888 reuse in #5933, format, tile/sample count, DCC/CMASK state and the next consumer still matter; I have not tested that title. #7260 retains Sonic's ordinary-run boundary and historical gameplay; no new title/FPS claim. AI-assisted: Codex; author responsible.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-17T16:56:47Z.
I checked the linked #5933 report for the format/reuse details. It records a 4x, 64 KiB native target overlapping a 512x512 texture view (format 173, tile mode 2, 10 mips, size 0x56000); the view starts 0x51000 before the target. The report also has separate storage-image and CPU-read overlaps. It does not record DCC/CMASK state or establish whether the aliased texture is meant to consume the old rendered samples versus data written after reuse, so I cannot say the #7002 buffer-publication path applies. Its stated scope is read-only shader-buffer consumers; this #5933 example is a texture read and needs its own publication evidence/coverage.
Imported from boykopovar/AnyPS5. Originally posted by hugodearaujo on 2026-10-18T16:18:12Z.
Another title that stops on this refusal: Assassin's Creed Mirage (PPSA13960, 01.007.000), on
mainwith #6343, #7532 and #7533:With a local change equivalent to this PR's
RequireNoMultisampleTarget(retire the guard instead of throwing), it passes that point and runs about two more minutes through its start-up screens, then stops at an unrelatedguest memory is not readableerror. Unlike Sonic Superstars, Mirage does not reuse the memory later: every frame it renders two 960x540 4x MSAA targets (R11G11B10F and R16F) and then accesses the same memory as 1920x1080 single-sample images (a compute storage write in SW_64KB_S and a texture read). With the guard retired, those views do not see the samples drawn on the host.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-20T12:51:13Z.
Thanks. This branch is far behind
mainand conflicts inDepthSurface.cpp,MultisampleTarget.cpp, both multisample execution tests and the debt file.mainhas since changed the same paths (retired multisample colour targets are reclaimed, HTILE clears of later slices, the ITERATE_256 depth import). Could you rebase onto currentmain? It would also help to say how this relates to the sample-preserving stack in #6973 to #7002, which covers part of the same ground, so it's clear which parts are still needed here.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-20T17:53:31Z.
@KingDarkHN a follow-up to my rebase ask: we're going to take the native multisample colour work forward through Amoenus's stack (#6973 → #6987 → #6989 → #6995 → #7002), which adapts this approach and is kept up to date with
main.Two questions, so nothing in this PR gets lost:
main? On its own it's much easier to review and test.Thanks for the original work. The stack builds on it.
Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-10-29T05:05:18Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
The head conflicts with
mainin five files and breaks an existing test (agc_driver_native_depth_retirement). I also found two defects in the depth half that the earlier reviews did not cover: a guest HTILE write clears the host stencil plane when the HTILE has no stencil metadata, and the newOverlapsbound leaves real tiled pixel data outside the retirement range.What I ran
734edb5c279d2f9de101d8ecf555f55b6f40d613main:52c09d567d2fa453494dd720fcf53a98149468e4main:5d9dcc42d2ec5401aebd089028b8d4d7410a77b4(12,344 commits behindmain)Results
mainGraphics/src/DepthSurface.cpp,Graphics/src/MultisampleTarget.cpp,tests/execution/NativeMultisampleDepth.cpp,tests/execution/SampleMultisampleTarget.cpp,docs/dev/debt/libSceAgcDriver.mdgit diff --checkcheck_conventions.py --base origin/mainAll conventions checks passed.agc_driver_native_depth_retirementfailsagc_driver_native_depth_retirementpasses; the five tests the PR adds or changes fail (see Negative control)was not found but was requested by env var VK_INSTANCE_LAYERSVUID-IDsVUID-vkBeginCommandBuffer-commandBuffer-00050(84 lines). Merge base: the same single ID (108 lines). No new VUID ID. The count differs because different tests stop at different pointsagc_driver_native_depth_retirementon the PR headPR head test summary
Negative control
The head does not merge, so I could not restore files from
origin/mainagainst a merged tree, andmainis too far ahead to build against the head's tests. Instead I restoredDepthSurface.cppandMultisampleTarget.cppfrom the merge base (5d9dcc42d2), kept the head's tests, rebuilt and reran:So the new and changed tests do depend on the production change.
agc_driver_native_depth_retirementpasses on the base and fails on the head, so the PR causes that failure; it is not pre-existing. The base includes #6297, which has since merged; the head's diff also carries #6300, which is still open.Findings
Blocking
Conflicts with
main. These five files conflict:DepthSurface.cpp,MultisampleTarget.cpp, both multisample execution tests and the debt file. This confirms the maintainer's comments of 20, 25 and 28 Oct.mainhas since rewrittenRequireNoMultisampleColorTarget: it now retires a guard only when the target is nothostOnly, and refuses otherwise. Most of this PR's colour change is therefore superseded, and the colour work is going forward through #6973 to #7002.The colour guard drop breaks an existing regression. In
MultisampleTarget.cppL602-L614, any overlapping access now retires the guard and returns, without classifying the access.NativeMultisampleDepth.cppL1327-L1332 asserts that a CPU read over a still-allocated multisampled colour target refuses, and it now fails (log above). The description reportsagc_driver_native_multisample_depthpassing and only pre-existing failures elsewhere, butagc_driver_native_depth_retirementpasses on the base and fails here. This failure is concrete evidence for Amoenus's P1: the change removes a refusal that an existing test pins and puts no debt entry in its place. The debt entries atlibSceAgcDriver.mdL48 ("guest access to live multisampled data remain unsupported") and L116 ("the memory a multisampled color target throws on (CPU read, DMA copy, texture or storage image read)") are now wrong. Suggested fix: drop this hunk when rebasing, sincemainand the #6973–#7002 stack cover colour retirement.A guest HTILE fast clear clears the host stencil plane even when the HTILE has no stencil metadata. In
DepthSurface.cppL276-L290, the honour path only checks the stencil clear whentarget.htileStencilis set. It still callsRecordClear(DEPTH | STENCIL)whenevertarget.stencilAddress != 0. WithTILE_STENCIL_DISABLE, which this PR newly accepts at import, the HTILE carries no stencil state, and the stencil plane is required to be unwritten. The guest therefore did not clear the stencil, yetRecordClearoverwrites the host stencil image withclearStenciland discards any stencil the host drew.main's own metadata-fill path makes the opposite choice:written = DEPTH | (target.htileStencil ? STENCIL : 0)at L1597. Suggested fix: addVK_IMAGE_ASPECT_STENCIL_BITonly whentarget.htileStencilis set, and add a case with a stencil plane,htileStencil = 0, a host stencil draw and then a guest HTILE clear that checks the stencil is preserved.The new
Overlapsbound misses stored pixels.DepthSurface.cppL438-L445 now bounds each plane bywidth * height * bytes * samplesfrom its base. That counts the stored bytes correctly, but they are not the first bytes of the range. Tiled blocks are stored in row-major order (TextureTiling.hppL34-L36), so the padding is the unused rows inside each block of the last block row, not a tail.Take a 1920x1080 single-sample D32 surface (128x128 blocks of 64 KiB):
A colour target or storage write over those blocks goes through
RetireDepthSurfaces(Draw.cpp,ShaderResources.cpp), no longer retires the depth surface, and leaves a stale owner that later lookups can return. Suggested fix: keep the block-rounded footprint, or useCoveredMipBytes-style per-block ranges if you want to exclude padding exactly. Add a test that writes the last block of the last block row.Unchecked retirement in
DepthSurfaceView.requireNoOverlapinDepthSurface.cppL1300-L1308 retires an overlapping owner whenattachmentInactiveholds, without checking for unpublished host writes. This is the same concern MarcZX10 raised forRequireNoResidentDepthReadand oneandonlydean raised on 28 Oct. I have no new evidence beyond confirming that the code still does this at the head.Non-blocking
rangeis used afterlock.unlock()and afterretireGuardForAddresshas erased it from the vector. I confirmed this by reading the code; it is moot if the hunk is dropped.fprintf(stderr, ...)lines ([gpu] ... retired guard,[agc] honoured a guest fast clear ...) print on every occurrence. Once a title hits them every frame, they flood the log.Not verified
main. All results are for the standalone head against its merge base, and the Vulkan validation comparison is against that merge base, not currentmain.agc_driversuite and did not run any title.To get this to a good state
mainand #6973–#7002 cover, and rebase the depth/HTILE half onto currentmainas its own PR.htileStencilis set (finding 3), keep the block-rounded overlap or make it exact per block (finding 4), and address the inactive-owner retirement (finding 5). Add a regression for each.agc_driver_native_depth_retirementpasses, and use the title ID only in the debt entry.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T17:13:21Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
A guest read overlapping a guarded multisampled color target now retires the guard and proceeds, exposing stale guest bytes while the rendered samples remain only in the host image.
What I ran
Reviewed head
734edb5c279d2f9de101d8ecf555f55b6f40d613from the prepared diff and targeted reader context. No tests or build commands were run.Results
Findings
Blocking
core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cpp:538—RequireNoMultisampleTargetis called for CPU reads, texture reads, and DMA source reads as well as target reuse. On any overlap this change removes the guard and returns, allowing the read to continue against guest memory even though the color samples reside only in the host image. Preserve the refusal for read accesses; retire the guard only when the overlapping access establishes that the allocation is being reused.Non-blocking
None.
Not verified
core/libs/prx/libSceAgcDriver/tests/Graphics.cppwas excluded from the review folder; only its changed hunk was read through the reader.DepthSurface.cppandMultisampleTarget.cpp; the diff was inspected for the other changes.To get this to a good state
Keep read accesses from proceeding after retiring a multisampled color guard. Add or update regression coverage for CPU, texture, and DMA source reads against a resident target, then rerun the relevant AGC tests.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.