perf(agc): keep a resource set's import proof across registry changes that leave the imports in place #7261
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7261"
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 tibzejoker on 2026-10-17T20:16:32Z.
What
A reused resource set that reads imported buffers in place proves, before each use, that every import it was built against is still the same one (
ShaderResources::Revalidate, the serial loop over its direct regions). An epoch gate skips that loop while the import table is unchanged since the set's last proof (HostImportsUnchanged). That proof is also tied to the guest allocation registry's generation, so any registry change fails it for every cached set, whether or not it touched an import. Each set then runs its serial loop, and the firstHostImportSerialcall reconciles the table with a fresh lease.A title that maps and unmaps guest memory often moves the generation between most frames. Each cached set used after that pays the loop, its lock round trips and a lease, even though no import changed.
This PR adds
HostImportsReconciledUnchanged. It reconciles the import table with the registry once, if the generation moved, then accepts the proof when no import was dropped (the existingepoch) and none was added (a newinsertedcount, also stored inHostImportsProof). Reconciling is what the serial loop's first lookup already did. After it, a set whose regions are all served by imports finds the same serials exactly when no import was added or dropped.Revalidateuses the new check only for sets whose direct regions are all served by host imports and have no committed-span bound (CutRegions). Sets with a read-only image mirror region, or a region bounded by its committed span, keep the current check: their serial loop also checks things the import table does not track. The other users ofHostImportsUnchanged(recipe presync,Texture.cpp) are unchanged.Test:
agc_driver_host_import_proofs(tests/execution/HostImportProofs.cpp). It imports a window through a GPU fill and takes a proof. It then checks that:Run with main's
HostImportsUnchangedin place of the new check, it fails: "an unrelated registration broke the proof, although every import stayed in place".Related: #6917 (keep the lease snapshot until the registry changes) and #6951 (memoize import run bounds) make each reconcile and lookup cheaper. This PR runs them less often. The three don't touch the same lines.
Tested
Windows 11 Pro (26200), RTX 4090 (NVIDIA 616.92), i9-13900K, MinGW GCC 15.2.0:
0c2a343d25, rebased onmain48c160c58b:agc_driver_host_import_proofspasses on the RTX 4090 and the UHD 770 (Intel 101.6129), underVK_LAYER_KHRONOS_validationwith noVUID-line. WithHostImportsUnchangedinstead, it fails with the message above.ctest -R "^agc" -E "^agc_driver_bda_device$"on the RTX 4090: 1078 of 1080 pass. The 2 failures,agc_host_import_cut_lifetimeandagc_driver_depth_plane_partial_store, also fail onmain.ctest -R "agc_driver|agc_masked|agc_shader", 524/524 pass, 2 skipped.mainstops GTA V before its menu, #11513). The build is main plus #6488, #6848 and #7189: GTA needs the first two to render, and #7189 removes the resource set rebuilds that hid this cost. Settings:APS5_PROFILE_DRAW=1, last 12 windows of 10 s, one run each:A stack sample of the draw committer before the change put
HostImportSerial(with itsGuestAllocationsAcquire) at 3 % of the committer's samples, all from this loop. The frame rate in this scene depends on where the save respawns the player (2-11 FPS within one run), so the committer figures are the comparison to read. The gain is one run each and larger than that 3 %, so take its size with care.Performance capture
GTA V (PPSA04264), open world from the same save, RTX 4090, one warm-up run then one traced run per side, same session. Base
17eacab0ecac=main47a266cf9+ #6488 + #6848 (GTA V does not run on plainmain) + #7189 + a local bench aid (keyboard pad input while an IME session is open). With the PR:57dd68bc3900= the same plus this change, cherry-picked onto that older base (one hunk adapted: only theinsertedcount). Traces: fork release perf-7261-20261019.320 -> 392 presents in the 60 s window, p50 189.4 -> 145.9 ms. Read this with care: in the open world frame time follows where the save respawns (2 to 11 FPS within one run), and the trace buffer of queue worker 0 fills after a few seconds (
trace_dropped). The committer cost per draw under Tested is the measurement this PR rests on.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)agc_driver_host_import_proofs3 of 3 on0c2a343d25+ mainf7f03daf52, validation on, 0VUID-lines)🤖 Generated with Claude Code
https://claude.ai/code/session_01XBXM4pgkMHYEtqN1EQni2P
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-17T21:39:56Z.
Review of e039bd7eb. The production change looks sound: I found no way for a kept proof to go stale. Every path that removes an import from the table bumps the epoch, the new
insertedcount catches new imports, and both only increase, so an old proof can't match by accident. Locally (main + this PR, NVIDIA), the 9 import/reuse tests pass, and dropping theinsertedcomparison makeshost_import_proofsfail, as it should.One ask, test only: the reconcile in
HostImportsReconciledUnchangedisn't pinned by a test. With therefreshImportscall removed,host_import_proofsstill passes. The test's "mapped again" case (Mutation().Remove+Add) is caught by the unmap hook, which retires the overlapping imports and bumps the epoch directly (GuestBufferMemory.cpp:2112-2125), so it never depends on the reconcile.The reconcile is what catches registry changes the hook doesn't see:
sameRun/importRundiffer although nothing overlapping was removed;failed/failedJoinsentries.Without it, a proof would be kept over an import whose registered range has changed, which is the staleness this PR has to guard against, and nothing in CI would notice if the reconcile were lost.
Could you add a case where the registry changes so that an import no longer matches its run, without the unmap hook retiring it, and require the proof to fail? One option is registering a range adjacent to the imported window's run so that
importRungrows, if that holds for a non-joined import. Please check that it fails with therefreshImportsline removed, the same way as forHostImportsUnchanged.Imported from boykopovar/AnyPS5. Originally posted by tibzejoker on 2026-10-17T21:47:21Z.
Thanks for checking. You're right: the remap case goes through the unmap hook and never needs the reconcile. I'll add a case where a registry change breaks the import's run without the hook retiring it, and check that it fails both with the
refreshImportsline removed and withHostImportsUnchangedin its place.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by tibzejoker on 2026-10-17T23:19:31Z.
Added in 21fe671d2.
ProofsFollowTheRunsregisters a range of 8 MiB minus 64 KiB at the start of an 8 MiB import window, imports it and takes a proof. It then registers the missing 64 KiB right after it. NowimportRuncovers the whole window as one run of two ranges, so the import'ssameRunno longer matches. Nothing was unmapped, so the unmap hook never runs. The proof must fail.refreshImportsline removed fromHostImportsReconciledUnchanged, the test fails: "a registration completed the import window of 0x2425b800000, but the proof over its import held".I first tried an adjacent range after a window-sized part of a larger block. That import covers only its own window, so
sameRangechecks just the owner and the proof rightly holds. The window has to be completed exactly for the run to change.ctest -R "agc_driver|agc_masked|agc_shader": 524/524 pass, 2 skipped (RTX 4090). In a second full run,agc_driver_multisample_fill_host_onlyfailed once under-j8. It passed 3/3 when run alone. It doesn't use host import proofs.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-18T10:37:40Z.
Rebase handoff — rebased onto current
main(all three commits, authorship unchanged). One conflict inGuestBufferMemory.cpp: the auto-merge had duplicated the import-table emplace —main's settle-block tail and your counting form ended up as two consecutiveemplacecalls with yours unreachable. The merged version is your[placed, added]form with theinsertedcounter (verified with the PR's own proof test: the counter now increments across a new import, which the dead duplicate had broken) plusmain's deferred-settle bookkeeping.Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release,
BUILD_TESTING=ON, AMD RX 9070 XT / RADV): builds; conventions pass; full suite green apart from the knownmainregression (agc_driver_tessellationsegfault — Mesa, #5444), not this PR — your import-proof tests pass.To pick it up:
Head is
b978a6b8d.Imported from boykopovar/AnyPS5. Originally posted by tibzejoker on 2026-10-18T10:43:01Z.
@blawesom thanks for the rebase and for catching the duplicated
emplace. I took your tree as is (git diffagainstb978a6b8dis empty), with one change: theGuestBufferMemory.cppfix now sits in the first commit instead of the third, so every commit builds without the dead secondemplace. Head is now89202144fon current main.On Windows (MinGW GCC 15.2, RTX 4090),
ctest -R agc_driver_host_import: 6/6 pass, includingagc_driver_host_import_proofs. Conventions pass.AI-assisted (Claude Code).