perf(agc): memoize untracked texture comparisons by the stores that reach the surface #2802
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2802"
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 ThatsLeo on 2026-10-10T15:30:24Z.
What
StorageTexture::compareUntrackedskips the byte comparison of an untracked surface while its memo stamp is unchanged. The stamp heldTrackerGeneration, which every collect and every driver store anywhere advances, so it almost never matched. On Linux with Intel Arc (Meteor Lake, Mesa 26.2.3 ANV), host imports resolve write protection and imported ranges are compared; in Dreaming Sarah (PPSA02929) 43,999 of 44,000 comparisons found the surface unchanged,TrackerGenerationcaused 90% of the memo misses, andperfput 58% of the graphics worker's samples in theirmemcmp.MarkWritten,StoreOwnBytes) into ranges the tracker does not cover, which leave no block stamp, record their generation per 64 KiB block.GuestMemory::NewestStampreturns the newest of those generations and of the block stamps over the covered part of a range.compareUntrackedkeys its memo onNewestStampof the surface instead ofTrackerGeneration.CollectEpoch,ForgetSerialandNewestWriteNotestay.docs/dev/ARCHITECTURE.mddescribes the memo stamp and the table.Tested
Rebased onto
maine7c70a2d. Fedora 44, GCC 16.2.1, Release, Intel Arc (Meteor Lake, Mesa 26.2.3 ANV).cteston Intel Arc and lavapipe: 942 of 942 pass on both.agc_write_trackinggainsCheckNewestStamp: a driver store into unwatched memory advances its stamp and not another range's, a collected CPU store elsewhere leaves it, and a collected store into the watched part of a partly watched range advances it. It fails without the store records.RunUntrackedReuseinagc_driver_dcc_keys_first_writecovers it, and it fails withan untracked CPU edit was missedwhen the epoch is taken out of the stamp.mainalready memoizes as often as this branch: Dreaming Sarah (PPSA02929) and Stray (PPSA02101) show the same hit rate and frame rate on both, see the measurements in the comments.mainat 0.2 to 0.6 FPS with about 0.57 ms per whole-surface comparison and this branch at 1.1 FPS with about 0.21 ms.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-10T15:30:34Z.
Thank you for your interest in the project! We are sorry, but we cannot accept more PRs while we work through the existing backlog. This PR has been automatically closed and labeled "intake paused". This is not a judgment of the quality of your changes.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T07:06:30Z.
Review: DISMISSED
Thanks for the measurements. Two problems before this can land:
compareUntrackedis only reached when the surface is not covered by the write watch (Texture.cpp:1418,:3814). There a CPU store leaves no stamp, and the byte comparison was the only way to see it. With the memo keyed onNewestStamp(stamps of covered blocks + driver stores), a CPU-updated untracked surface (video, streamed texture) is never re-compared while the driver writes nothing to it, so it stays on the old contents.CheckNewestStamppins exactly this ("a collected CPU store elsewhere leaves it") but nothing tests that the comparison still runs when the CPU changed unwatched bytes. Please add a test where an untracked surface is changed by a CPU store only andcompareUntrackedmust report it changed, and key the memo on something that sees it (e.g. limit the memo to ranges where every block is covered by the watch, or re-compare at a bounded interval), and show the Dreaming Sarah numbers again with that.unstampedStores(GuestMemory.cpp:905): one map entry per 64 KiB block ever stored to, never erased (not on unwatch/free/remap). Bound it or drop entries when the range is watched/released.Also, this adds a tracker structure, so
docs/dev/ARCHITECTURE.mdshould describe it where the write tracker is covered.Imported from boykopovar/AnyPS5. Originally posted by Mouhand-Kaddo on 2026-10-11T07:26:43Z.
Additional platform validation of standalone PR head
93f3adc2418ff2b172055dad2541e31ee4dcdfd0(2026-10-11):Windows: passed — Windows 11, WinLibs GCC 15.2.0 UCRT/POSIX/SEH r7; CMake 4.3.1 / Ninja; Release,
BUILD_TESTING=ON.2 checks, 0 failures, 0 CTest skips. Built the selected targets and dependencies; this is focused validation, not a full build or full-suite run.
Checks:
agc_write_tracking,agc_driver_graphics.Command after building:
ctest --test-dir <build> --verbose --no-tests=error --timeout 30 -R "^(agc_write_tracking|agc_driver_graphics)$".This scope checks CPU-side behavior; no GPU execution result is claimed.
No title/gameplay validation. These results cover the standalone head, not a merge with current main.
Imported from boykopovar/AnyPS5. Originally posted by ThatsLeo on 2026-10-11T12:00:59Z.
A second title, from Stray (PPSA02101 v01.002, UE4), on the same Intel Arc. It runs on
mainf1ae427bwith the set described in #2749.On ANV, host-pointer imports lose write protection, so imported storage surfaces are compared rather than watched. At the calibration screen,
perfput 54 to 57% of the process's samples inStorageTexture::compareUntracked, at about 2.8 GB/s of comparisons, render targets up to 3840x2160.With
93f3adc2the first 16 frames are presented by 43 s, where without it the first 17 came at about 103 s (warm shader cache, same set otherwise). The steady frame rate does not move (about 1 FPS): there the surfaces really change between uses, and the cost goes away only once the imports stay watched (#2434).AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by ThatsLeo on 2026-10-11T22:44:34Z.
@adriadam10 thanks for the review, and sorry for the delay. I rebased onto current
mainto address it, and measured first. On today'smainthe problem this PR fixed is mostly gone, so I'm closing it rather than asking you to review a larger version.Rebased PR (
48763caf) against plainmain(0a8b1d32). The counters are local, on everycompareUntrackedcall: how often the memo hits, and how many bytes are compared or skipped per run (Dreaming Sarah averaged over its two runs). Intel Arc (Mesa 26.2.3 ANV).mainmainThe Stray runs are with the set from #2749, without its dma-buf preference, so the imports stay unwatched and go through
compareUntracked.When I opened this, the stamp's
TrackerGenerationadvanced on almost every call and the memo almost never matched. On currentmainit already matches as often as with this PR, so replacing it withNewestStampno longer buys anything measurable.On your two points, for the record:
CollectEpoch(), so a CPU store into unwatched memory is compared again at the next ordering point, the same bound the collect memo gives watched memory.RunUntrackedReuseinagc_driver_dcc_keys_first_writealready checks it: a CPU edit afterBumpCollectEpochmust makeRefreshre-upload. With the epoch taken out of the stamp, that test fails withan untracked CPU edit was missed.Neither is needed now that the PR isn't. The remaining cost on ANV is the comparison itself, and keeping the imports watched (#2434) is what removes it.
AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by tibzejoker on 2026-10-12T09:19:46Z.
Data from another workload where this still matters: GTA V (PPSA04264), Windows 11, RTX 4090, write watch on. Tree: main
325e0a8bd(so it includes0a8b1d32) plus the PRs GTA needs to reach Story. I applied this PR's head 93f3adc24 as is (it cherry-picks cleanly onto that main).On Windows, the render targets GTA draws to are outside the write tracker (
GuestMemory::ChangedBlocksreturns false for them), so everyStorageTexture::Refreshof a resident target ends incompareUntrackedover the whole surface (up to 33 MB at 3840x2160). In Story, about 98% of these refreshes find the surface unchanged.Local timers inside
Refresh, per 10 s of the prologue, one run each:So on this workload the
TrackerGenerationkey still misses most of the time, and keying onNewestStamproughly halves the frame time. The compare is still the top cost with the PR. Covering these surfaces with the tracker on Windows would remove it, and I'm looking into why they are not covered.@ThatsLeo would you consider reopening it? If you'd rather not carry it, I can open it again with you as author of the commit and these numbers.
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by ThatsLeo on 2026-10-12T10:42:23Z.
Reopened at @tibzejoker's request, and rebased onto
maine7c70a2d(ca99658c). The GTA V numbers above show the case my Linux measurements missed: on Windows those render targets are outside the write tracker, theTrackerGenerationkey still misses, and keying onNewestStamproughly halves the frame time there.@adriadam10, on your review:
CollectEpoch(), which advances at every ordering point where a CPU store may have landed (submission start, a satisfiedWAIT_REG_MEM, a drain). A thread that never bumps it gets epoch 0 and is never memoized. So a CPU store into unwatched memory is compared again at the next ordering point, the same bound the collect memo gives watched memory. The test you asked for exists onmain:RunUntrackedReuseinagc_driver_dcc_keys_first_writechanges an unwatched image with a CPU store only and requires the nextRefreshafterBumpCollectEpochto upload it. With the epoch taken out of the stamp, it fails withan untracked CPU edit was missed.unstampedStores. It's now a fixed table of 65,536 slots indexed by block number modulo the table size. A collision can only raise a stamp: one comparison more, never one skipped.docs/dev/ARCHITECTURE.mdgets a section on untracked storage image comparisons, covering the stamp and the table.Full suite on Intel Arc and lavapipe: 942 of 942 pass on both. The description is updated.
AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by tibzejoker on 2026-10-12T10:53:53Z.
Thanks for reopening. Checked the rebased head
ca99658con Windows 11 (WinLibs GCC 15.2.0, Release, RTX 4090):ctest -R "agc|shader"on the PR head itself: 435 of 435 pass (agc_driver_stencil_ref_exportskipped as unsupported here).ca99658cin place of the old commit: 26k to 36k refreshes per 10 s and window FPS 1.35. Before the PR it was 11k to 15k refreshes and 0.2 to 0.6 FPS, so the rebase keeps the gain.AI-assisted (Claude Code).