perf(agc): answer guard range checks from a per-thread span copy before taking the guard locks #16116
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/16116"
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 Nesyth on 2026-11-05T17:43:09Z.
What
Every guest buffer of every draw, and every index buffer, vertex buffer, texture and storage image read, asks two guard lists whether it touches memory whose samples live only on the host:
RequireNoResidentDepthRead_nid_no_patch(native multisample depth planes) andRequireNoMultisampleColorTarget(multisampled colour targets and their FMASK, DCC and CMASK). Once a title has made either kind of target, each check takes the list'sstd::shared_mutexand walks the list, although almost every check overlaps nothing. With MinGW the shared mutex is a winpthreads read-write lock. In PPSA04264 the two functions took 9.0 % of the draw committer's busy samples, 7.5 % of them inside the lock.This PR keeps a per-thread copy of each list's ranges, tagged with the list's generation (
GuardSpansinGraphics/include/GuardSpans.hpp). The copy is sorted by begin and stores, for each begin, the largest end so far. A check first loads the list's generation. If the copy is current and a binary search shows that no range overlaps, the check returns without the lock. Any overlap goes the old way, and so does a check whose copy is behind (the copy is refilled under the shared lock first).publishDepthGuardswhen a range is added or removed. The multisample list's (moveGuardSpans) moves wherever the existingguardedGenerationmoves, and also whenGuardOneFragmentFmaskadds a range and whenRequireNoMultisampleColorTargetretires ranges.guardedGeneration, which keys the BDA tables, moves exactly as before.RequireNoResidentDepthRead_nid_no_patch,RoutesToNativeDepthOwner,RequireNoMultisampleColorTarget,ClaimMultisampleTargetMemoryandMultisampleColorTargetsOver. Each of them does nothing when no range overlaps.APS5_NO_GUARD_SPANS=1turns it off. It is a runtime switch (RuntimeSwitch::NoGuardSpans), soAPS5_ABcan toggle it.APS5_VERIFY_GUARD_SPANS=1checks every lock-free answer against the list under the lock and takes the list's answer. A copy can miss an overlapping guard in two ways: it was current, or it was refilled from the changed list and still misses the guard. For the first twenty such misses a[guard-spans] verifyline is printed. A[guard-spans]line every 10 s counts the lock-free answers, refills, overlaps, checks and misses. It also prints withAPS5_PROFILE_DRAW; the counts are kept per thread, so the line adds no shared atomic to each check.Both variables have rows in
docs/dev/ENVIRONMENT.md.docs/dev/TRACING.mdnow says thatAPS5_ABtakes any runtime switch, not onlyAPS5_NO_BARRIER_BATCH.agc_guard_spanstests the copy against the list check: edges, nested and empty guards, and 400,000 random queries.Tested
Windows 11 Pro 26300, Radeon RX 7900 XTX (AMD Software 26.10.1), Ryzen 7 7800X3D, MinGW-w64 GCC 15.2, Ninja, Release,
BUILD_TESTING=ON, this head rebased on currentmain4741457fed.main4741457fed(ninja -C build): clean.agc_guard_spans,agc_runtime_switches, the tests for multisampled colour targets, native multisample depth, HTILE, FMASK, EQAA and alpha to coverage, and theagc_driver_recorder,agc_driver_graphics,_draw_pipelineandagc_driver_draw_cache_reuseregistrations: 84 tests,ANYPS5_REQUIRE_VULKAN=1,-j4: 100% pass, 0 failed (one,agc_driver_native_depth_driver_queued_fill, skips itself). The fouragc_driver_native_depth_aliased_depth*/_publicationtests that failed on the old base now pass on4741457fed.main4741457fed,APS5_AB=30:APS5_NO_GUARD_SPANS, 30 s phases from 190 s, 20 phases, each B phase against its neighbouring A phases.APS5_DRAW_PIPELINE=1is set in both arms, because its[draw]report gives the commits per present. The guard checks run on whichever thread prepares a draw, with or without the pipeline. Draws per present swing with the scene, so frame time is fitted against commits per present with a common slope (residual SD 3.3 ms, n 20).No errors in the run.
Performance report
Captures of PPSA04264 on
main4741457fedand on this head, same scene, machine and settings (APS5_DRAW_PIPELINE=1, trace window 240-300 s). The two traces, both digests and a second pair of boots are in the report comment.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)