fix(agc): retire a multisampled color target the title wrote over #8223
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/8223"
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 savvaniss on 2026-10-20T04:27:41Z.
What
A multisampled color target keeps its samples on the host. Its guest memory stays guarded until an unmap or an allocation removal covers it: any access of that memory throws "overlaps multisampled color target … guest access to it is not implemented". A title with its own memory pool never unmaps. It reuses the memory of a render target it no longer needs, and the next access of the new data throws, although the target is dead. This PR takes two kinds of reuse as evidence that a target is dead:
CollectWritesover its color memory each time it is used. When a guarded access overlaps a target in write-watched memory, and the CPU wrote the overlapped bytes since that generation (UnchangedSinceCollected), the title has put other data there.DepthSurfaceView, before any import), a single-sample color target (whereDrawalready retires the depth surfaces it overlaps), and a draw of a multisampled color target with another address, extent, sample count or format. A draw through the target's sRGB twin format is served by the same target, so it is a draw of that target, not a claim.A target's use clears its own mark and takes a new write generation. A use is a draw, and, as #9186 already holds a target host-only there, a dispatch's storage view of it or a color fill it absorbs. A target used again after the claim keeps its guard.
Since #9186, a guarded access also retires a target whose samples are not only on the host, that is a texture sampled before any draw, until a draw, a storage write or an absorbed fill. The three conditions sit together in
RequireNoMultisampleColorTarget, in #9186's order: when every guarded range that an access overlaps can retire, they are all retired the way an unmap retires them, and the access goes on; when any of them cannot, the access refuses and nothing is retired. A later draw to the same address creates and guards a new target. A target is only retired at an access thatmainrefuses with an exception, so nothing that runs onmainbehaves differently.Each target keeps this state in one
TargetUse(hostOnly,writes,claimed), and every guarded range of the target points to it, the DCC, CMASK and 8-sample FMASK ranges included. The one-fragment FMASK range ofGuardOneFragmentFmaskkeeps itsfmaskflag and gets aTargetUseof its own, but claims skip it, so it refuses every guest access as onmain.guard()returns void as onmain; the color footprint it computes isguardedColorBytes(), which the use stamp also calls.The debt entry for multisampled color targets records the rule and its gap: a target that is only sampled after another target was bound over it loses its samples. #6987, #6989 and #6995 work toward reading live samples from guest memory, which this does not do. Amoenus's adaptation of this branch onto
main5a2744c55e(25907aa1fb) was the reference for the one-fragment FMASK check in the test.Tested
Windows 11 Pro 26300, WinLibs GCC 15.2.0 r7, Release, AMD Radeon RX 9070 XT, on
mainb7488e1ff5(merged into this branch on 30 Oct).agc_driver_sample_multisample_targetrunsCheckOverwrittenTargetandCheckClaimedTargetsaftermain's sampling test. The first is the CPU-write case: a write over a drawn 4x target in watched memory retires it at the next guarded read, and a later draw guards the new target. The second has the bind cases, in plain (unwatched) memory:holdHostOnlystamps no use, case 5: "a 2x target that a dispatch stored to after a D32S8 target's stencil plane was bound over it is not guarded";CheckOverwrittenTarget: "a read of target memory the title wrote over … overlaps multisampled color target".agc_driver_sample_multisample_targetonmain's production code stops 3 of 3 at the CPU-write case ("a read of target memory the title wrote over … overlaps multisampled color target").mainand on this head, on the same machine, withANYPS5_GPU=AMD,ANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1andVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, 31 tests:agc_driver_sample_multisample_target,agc_driver_native_msaa_vertex_input,agc_driver_native_fmask,agc_multisample_guest_access(withmain's one-fragment FMASK guard tests),agc_driver_msaa_dcc_state,agc_driver_msaa_dcc_clear_2,_4and_8,agc_driver,agc_driver_cached_image_multisample_guard,agc_driver_multisample_fill_host_only,agc_driver_multisample_retirement,agc_driver_multisampled_pass_order,agc_driver_multisample_readbackand its eight cases,agc_driver_multisample_srgb_twin,agc_driver_multisample_centered_lines,agc_driver_msaa_layout,agc_driver_depth_copy_draw, and the native depth testsagc_driver_native_multisample_depth,agc_driver_native_depth_retirement,_clears,_clear_refusalsandagc_driver_native_depth_bda_clear. On this head, onmainb7488e1ff5, all 31 pass, andagc_driver_sample_multisample_targetpasses 3 of 3. Onmain07da04f947(25 Oct, not rerun for the latest merge), all 31 pass, and itsagc_driver_sample_multisample_target(without this PR's cases) passes 3 of 3. Neither log has aVUID-line orwas not found but was requested by env var VK_INSTANCE_LAYERS, and everySelected GPUandVulkan device:line names the RX 9070 XT.main's newagc_driver_packed_unorm4444_multisample_partial_writedoes not build in this tree on either side: its object's dependency file path passes Windows' 260-character limit.maincecb540a63(21 Oct): the only conflict was thedepthWrittenparameter thatmainadded toDepthSurfaceView.mainhad moved the guard loop intoRequireNoMultisampleColorTarget, and the retirement moved with it.main1da03c6f34(22 Oct, after #7948): #7948's FMASKguarded()range takes the target'suse, like the DCC and CMASK ranges. In the test'sBlock, both sides had added the samewatchedparameter, andmain's version is kept.main07da04f947(25 Oct, after #9186 and the one-fragment FMASK guard): conflicts inMultisampleTarget.hpp,Draw.cpp,MultisampleTarget.cpp, the test and the debt file, resolved as described above. InDraw.cppand the header, the claim comes beforeGuardOneFragmentFmask.mainb7488e1ff5(30 Oct, after #6498 and #12566): the debt doc keeps this PR's entry and #6498's shader buffer entry, and the test file keeps both sides' test blocks.HostOnlySampleRangesfrom #12566 readsrange.use->hostOnly(found by hugodearaujo).main, a native multisample stencil plane is not imported, so the test reads the overlapped bytes throughRequireNoMultisampleTargetinstead of through that import. The claim happens before the import.mainbb04a4f1eait aborts at 86 s on a CPU read over a 4x target, and with this PR that stop is gone (comment). It then aborts at 79 s on a cached image access over another 4x target. Their trace shows that access is a dispatch's store-only clear over part of the target, a GPU write that is neither a CPU write nor a bind, so it still refuses and is a follow-up.main'sMultisampleTarget.cppfails 3 of 3, comment) also covered the CPU-write case only.tools/check_conventions.py --base origin/mainpasses, andtools/pr_overlap.pyfinds no shared exports.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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by simonbbby on 2026-10-20T06:26:13Z.
Native Linux write-watch control for exact head
eb9807f341a11320a50d8d188ab7ff902598c089, parentc9c7e6cfaf602d3d9a83b13251e14a810831fce9. I rebuilt the execution fixture and runtime dependencies, then ran the completeagc_driver_sample_multisample_target_testsin three fresh processes per restricted ICD.MultisampleTarget.cpprestored to the exact parentAll nine parent controls stop at
a read of target memory the title wrote over ... overlaps multisampled color target ... whose samples are only on the host. All 18 PR processes execute the new watched-memory case, including the refusal before the CPU overwrite, access after the middle 256-byte overwrite, access to the remaining prefix after retirement, and the refusal after drawing the target again. None printsoverwritten target retirement not tested, skips, or times out. Thus this is a Linux before/after result for the new behavior, not a green run that bypasses write watching.After restoration, the seven registered tests matching
agc_multisample_guest_access,agc_driver_native_msaa_vertex_input,agc_driver_msaa_dcc_state,agc_driver_msaa_dcc_clear_[248], andagc_driver_sample_multisample_targetpass 7/7 on NVIDIA and 7/7 on RADV. Lavapipe passes five and skips the 2x/8x DCC cases withthe device lacks the requested multisample color attachments; no failures. The source tree is clean. Raw logs and JUnit results are retained.Ubuntu 24.04, kernel 7.0.0-38, Ryzen 9950X, GCC 13.3, Release; NVIDIA 595.99.02, gfx1036
1002:13c0/ Mesa 25.2.8, lavapipe LLVM 20.1.2. Actual devices verified from loader output, required Vulkan, shader cache and pipeline journal disabled, other AnyPS5/Vulkan overrides removed. No Khronos validation layer is installed. Boggle, Windows, performance and the full suite were not tested here.Imported from boykopovar/AnyPS5. Originally posted by savvaniss on 2026-10-20T12:31:06Z.
Rebased onto
main56b299c3a; the head is now79b42bd76. The only textual conflict was the debt line next to the stencil entry. The rebase also needed one code change: #7641 added aguard()call where a target is recreated with another pipe-bank XOR. That call now also records the recreated target's color bytes and use stamp, as the two otherguard()calls do.On the RX 9070 XT, Windows, with the validation layer:
agc_driver_sample_multisample_target,agc_driver_native_msaa_vertex_input,agc_multisample_guest_access,agc_driver_msaa_dcc_stateandagc_driver_msaa_dcc_clear_2,_4and_8pass 3 of 3 onmainand on this head.VUID-line.main'sMultisampleTarget.cpp.@simonbbby thank you for the Linux control with write watching on three ICDs. I added it to the description.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-21T14:28:13Z.
@savvaniss thanks for #8223. We hit a second form of the same reuse in PPSA03208, one that the CPU-write evidence can't see: the title reuses the memory through the GPU.
From a trace on our bring-up tree (
mainplus open multisample-depth PRs, with a diagnostic at colour-target registration):0x1546eb0000(format 13, 1920x2160,0x870000bytes) and drawn once.stencilAddress=0x1546eb0000, depth-only HTILE at0x1547720000).0x1546eb0000+0x1000. That read lands inside the colour target's guard (last use 0.002 s, 1 use). Without a retire, it is refused and the title stops there.Nothing wrote over the colour bytes from the CPU, so the write-tracker generation never changes, and as we read #8223 it would keep the guard here. To get past it, we used an unconditional retire-on-read as a probe. The title then runs about 20 s further, to its next, unrelated stop. We don't think that rule is safe for a live target, so we're not proposing it.
Could #8223 accept a second piece of evidence? When a native depth/stencil target (or a colour target with a different layout) claims a range that overlaps a guarded multisampled colour target, and the colour target's last use came before that claim, retire the colour guard through the same retirement #8223 adds for overwritten targets. That's the GPU-side counterpart of "the title wrote over it". A colour target that is still drawn after the claim would keep its guard and still refuse.
For the test, the existing fixture could:
plus a control where the colour target is drawn again after the depth bind and the read still refuses. We're happy to run the title on the result.
Imported from boykopovar/AnyPS5. Originally posted by fma-rc on 2026-10-21T14:43:22Z.
@savvaniss #9186 changes the same function for a different case: a multisampled texture that a shader sampled before any draw, later accessed by the GPU with no CPU write in between (Death Stranding 2 stops there even with #8223). The two conflict in
guard()andRequireNoMultisampleColorTarget. I merged them locally, so each target keeps your write stamp and the new host-only flag, and the test cases from both PRs pass together on an RTX 5080.I'm happy for #8223 to land first and then rebase #9186 onto it. If you'd rather go second, I can point you at the merged version. Which order works for you?
Imported from boykopovar/AnyPS5. Originally posted by savvaniss on 2026-10-21T16:42:07Z.
@oneandonlydean thanks for the trace. The rule is in
93a76298e1(withmainmerged inf4352b5ed0), close to how you described it:DepthSurfaceView, before any import reads guest memory.SampleMultisampleTargethas the cases you suggested: it draws a 2x target, binds a 2x D32S8 target whose stencil plane is that memory, and reads 0x1000 bytes of it, which passes. In the control, the color target is drawn again after the bind, and the read is still refused. Two more cases cover the color-layout claims: a single-sample draw over a 2x target, and a 4x draw over part of a 2x target. With the previous head's production code, the test fails 3 of 3 at the first case. When I removed one part of the change at a time, each case failed at its own check. On the RX 9070 XT the MSAA and native-depth set (23 tests) passes under the validation layer onmainand on this head, with noVUID-line. The PR description has the details.On
main, a native multisample stencil plane is not imported yet, so the test reads the overlapped bytes directly instead of going through the import from your trace. The claim comes before that import, so I expect PPSA03208 to get past its stop at 1.349 s, but I could not check that here. Thanks for offering to run it.One trade-off is in the debt entry: a bind is taken as reuse. So if a title binds another target over a live multisampled target and afterwards only samples that target, without drawing to it, the samples are lost at the next guarded access.
Imported from boykopovar/AnyPS5. Originally posted by savvaniss on 2026-10-21T16:42:09Z.
@fma-rc thanks for merging the two. Yes: #8223 first, and #9186 rebases onto it, as you offered.
Your merged version needs one more pass, though. Today's push changes the same code again for oneandonlydean's request:
usedAtatomic. Each target has oneTargetUse(writes,claimed), and every guarded range of the target points to it, the DCC and CMASK ranges included. Your host-only flag can go in the same struct.main'sRequireNoMultisampleColorTarget. It retires a target there when it is claimed (another target was bound over it after its last draw) or when the CPU wrote over it.This does not cover your case. DS2's storage access over a texture that was sampled before any draw has no bind over it, so #9186 is still needed after #8223.
Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-22T09:12:21Z.
@savvaniss a merge-order note: #9533 (a draft) overlaps this PR in
DepthSurfaceViewand inMultisampleTarget.cpp'sguard. It imports native multisampled D32S8 targets with a separate stencil plane, and before reading that plane it asks whether a host-only multisampled colour target covers it: the PPSA03208 shape your claim-and-retire rule handles. #9533 goes after this PR and rebases onto it, keeping your claims and retires. Its import then needs a colour target you retire to stay known to it: a retired target over the plane keeps its known fill value, or else leaves the stencil plane unproven, so stale guest bytes there are never taken as the clear value. That's a change on #9533's side; nothing changes here.Imported from boykopovar/AnyPS5. Originally posted by savvaniss on 2026-10-22T10:56:50Z.
@EagleBearerYS thanks for the merge-order note. Understood: #9533 goes after this pull request and rebases onto it, keeping its claims and retires, and the handling of a retired colour target over the stencil plane is on #9533's side. Nothing changes here.