perf(agc): memoize the per-use write checks of native multisample targets #18288
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/18288"
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-11T03:29:27Z.
What
A resident native multisample target is checked on every use for CPU writes over its planes:
DepthSurface::CheckCurrentwalks each of its ranges, andMultisampleTarget::checkDccCurrentits DCC and FMASK ranges, withCollectWritesUncached. Each walk is aPAGEMAP_SCANover the whole plane. A 4K 4x depth plane is about 106 MiB, so each walk is cheap, but these checks run on every draw that uses the target, and in a title that samples its depth target on most draws the walks are most of the draw thread's time.These three walks only decide whether to refuse the target because the guest wrote over it. This PR makes them use the memoized
CollectWrites. Within one collect epoch, a range already walked is not walked again. A CPU write that lands between two collects of one epoch is seen at the next ordering point, which is the orderingGuestMemory.hppstates real hardware gives a CPU write made while a submission runs. So a write ordered before the draw is still refused at this check, and a later unordered one at the next use after an ordering point. The uncached walks that decide which bytes to keep stay as they are: those inCheckCurrent's clear-proof paths, in publication and in stores. #18102 makes the same argument for the walk inStorageTexture::markLayersPending.Threads that never bump an epoch get a fresh epoch for every collect, so nothing changes there; the native multisample unit tests run on such threads, so they exercise the same walks as before.
Tested
Linux 7.2.14, Ryzen 9 7950X, RX 6650 XT (RADV NAVI23, Mesa 26.2.6), GCC 16.2.1, Release.
mainisf0bb282eed, this change isd1b5779bcbon it.GPU tests. The same focused tests on both,
ctest -V -R '^(agc_driver_graphics.*|agc_driver_.*(depth|stencil|multisample|msaa|sample|dcc|fmask|collect|memo).*)$'withVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,ANYPS5_NO_SHADER_CACHE=1andANYPS5_REQUIRE_VULKAN=1:main192 of 192. This change: 192 of 192. NoVUID-lines and nowas not found but was requestedin any log. The same set on the earlier basefb26c5e4e0(190 tests) also passed on both sides, twice for the change.Snoopy & The Great Mystery Club (PPSA28795), the first backyard scene, where the native multisample depth target is sampled on most draws. Cross every 15 s from 30 s,
APS5_PLAYGO_UNLISTED_CHUNKS=installed, 140 s runs in A, B, B, A order, a 20 s trace from 100 s (APS5_TRACE_SECONDS=100:20), a screenshot at 110 s.mainmainmain(Graphics.Draw129.9 ms) and 27.8 ms with the change (Graphics.Draw20.7 ms). The graphics queue worker, which waits for the committer, goes from 91.6 to 21.3 ms.fb26c5e4e0gave the same split (frame p50 199.3 and 196.7 ms against 89.0 and 92.5 ms).Bugsnax (PPSA01503), a title whose log shows multisampled colour targets, as a check on another title. Same input and timing:
mainmainNo change beyond run-to-run spread; this title is GPU-bound.
Traces, summaries and screenshots:
evidence/msaa-memo-20261111. Summary lines:Snoopy (A1, B2, B3, A4)
Bugsnax (A1, B2, B3, A4)
Windows, AMD (reviewer run): @Ethan-Hainline ran this head merged onto
main22cc516f87on Windows 11 with a Radeon Vega (GCN, AMD 23.19.24.04) and Khronos validation 1.4.363.1:agc_driver_cached_image_multisample_guard,agc_driver_native_multisample_depthandagc_driver_native_depth_separate_stencilpassed 3 of 3 each, with noVUID-lines. That was those three tests, not the full set above.Not verified: other GPUs and drivers, the full test set on Windows, and macOS.
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-12T18:04:32Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this; the points below are optional.
What I ran
d1b5779bcbcdad5082933516caf2d6965e01cce1, basemain.Results
Reader output used for the review
The commands are listed under What I ran. Their output is the repository text at the head SHA; nothing was edited.
Findings
Blocking
Non-blocking
core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp:785andcore/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cpp:883and:895: the three checks now use the epoch memo, so a second walk of the same range in one epoch is skipped. The diff adds no test for this changed call path. The existingCollectMemoGeneration.cpptests cover the memo itself, andDepthSurfaceReuse.cppbumps epochs, but I did not confirm that any test reaches these three call sites on a thread that bumps its epoch.Sources
GuestMemory.hpplines 131–145 at the head.CollectWritesUncachedis documented for decisions about pending GPU results: same header, lines 135–137.DepthSurface.cpp785,MultisampleTarget.cpp883 and 895.tree/evidence/msaa-memo-20261111), not to a commit-pinned permalink.Not verified
files.jsonlistsDepthSurface.cppandMultisampleTarget.cppas reviewed. I read only the changed regions with context, not the whole files.To get this to a good state
Nothing is required.
Optional: