perf(agc): an untracked comparison memo holds until memory it covers is forgotten #14261
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/14261"
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 oneandonlydean on 2026-11-01T05:05:44Z.
What
Based on #6187 by @TheAggie, with the main-based port by @tibzejoker as the starting point. The two original commits keep their authorship; the third commit fixes a crash in the new test's teardown and the fourth makes the test skip, instead of passing, when it cannot run.
A storage image over guest memory the write watch does not cover (on Windows, every host-pointer import of the guest mapping, #1441) is checked by comparing its saved bytes with guest memory (
StorageTexture::compareUntracked). The comparison is memoized under a stamp, and one part of that stamp wasGuestMemory::ForgetSerial, a single counter that moves on everyForgetPagescall anywhere in guest memory, so a forget unrelated to the image dropped the memo.ForgetPagesalso raises a per-block stamp: a fixed table of 65,536 slots, one per 64 KiB block of the forgotten range (block index modulo the table), each holding the newest forget serial that touched it. A range wider than the table raises one shared stamp instead.GuestMemory::ForgetStamp(address, bytes)is the newest of those over a range. A collision between blocks only makes it newer, so the memo is dropped too often, never too rarely.compareUntrackedstamps withForgetStampof the surface instead of the global serial. A forget in progress (oddForgetSerial) still disables the memo, as before.No runtime switch.
Changes against the original PR:
main; the test registration moved totests/cmake/agc_driver_recorder_tests.cmake.agc_untracked_forgetcrashed on Linux CI (run 39153907046). The cause was the test, not the memo: it submits refresh work that uses the test'sTextureDetiler, and the detiler went out of scope while that work was still in flight. The test now drains the recorder before the detiler is destroyed, and again on every exit path through a small guard. It crashed 3 of 3 times on a software Vulkan device before the change and passed 10 of 10 after it.APS5_WRITE_WATCH_IMPORTS) it covered, so a skipped or unwatched run is not read as a pass.Tested
Linux (kernel 7.2.3), GCC 16.2.1, on main
b08c539c50; the branch also merges clean with mainb865ce7a93.agc_untracked_forgetpasses under lavapipe in all three write-watch modes (default probe,APS5_WRITE_WATCH_IMPORTS=watchand=unwatch), 20 of 20 consecutive runs. Only the Recorder test target was built on this base. On the previous base (16452da934) the test crashed 3 of 3 runs before the teardown fix and passed 10 of 10 after it, and the wholectest -R agcset passed under lavapipe (1146 passed, 73 skipped) with #6192 on top.agc_untracked_forgetpasses in watch and unwatch (2 of 2 each) on16452da934.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 CnRJay on 2026-11-01T19:47:51Z.
Review: COMMENTED
The change itself (a per-block forget stamp instead of the global
ForgetSerialin the comparison memo stamp) is reasonable, but the PR is labelledperf(agc)and carries no measurement of its own.1. No speed evidence. The Tested section says the performance figures are in #6192 and that Windows is untested. Nothing here is a
tools/trace_digest.pysummary ofmainand of this change from the same machine and scene. Please add one, on Windows, since the untracked-memory path only exists for host-pointer imports (#1441) and the PR itself says that on Linux most of guest memory is watched.2. Cost of the lookup.
ForgetStampwalks one atomic slot per 64 KiB block of the surface, up to 65,536 slots, on every memo check. For a large storage image that is thousands of loads per refresh, against the singleForgetSerialload it replaces.ForgetPagesdoes the same walk with a CAS loop per slot. Please show this is cheaper than the full compare it avoids on a scene with large untracked images, and say what happens to aForgetPagesof a multi-GiB range.3. AGC validation. Same-machine
mainvs change runs of the focused tests withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1andVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, plus theVUID-comparison, are not shown; the test is described as passing under lavapipe.4. Stacking. #14262 carries these commits as its first four. Please state the merge order so one of them is not reviewed twice.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-02T07:05:18Z.
Review: COMMENTED
Reviewed — no blocking findings; the recorder test was skipped on Windows
The guest-memory "forget" stamps are now kept per 64 KiB block in a fixed table of atomic slots, instead of one global serial, so a comparison memo holds until the memory it covers is forgotten. A block collision only makes a stamp more recent, which keeps the check conservative. The recorder test that covers this path was skipped on the Windows runner, so the change has no hosted pass.
What I ran
f1a259d63bfd571211c8c4d131f46775c1468333; basef377753dd22fa839d7a9071509ae97c3afaafad2. 5 files, +129/-4:Execution/src/GuestMemory.cppandExecution/include/GuestMemory.hpp(the slot table,raiseForgetSlotandForgetStamp),Graphics/src/Texture.cpp(uses the stamp),tests/Recorder.cppand a CMake fragment (the recorder test).GuestMemoryfiles in full (the slot table,raiseForgetSlot, the forget path andForgetStamp). Did not readTexture.cppor the recorder test.agc_driver_recorderis Skipped on the Windows runner (Test #1694), so the new behaviour has no hosted pass.Results
block % ForgetSlotCountshares slots; the stamp is a maximumTexture.cppuse and the recorder test (not read)agc_driver_recorder(hosted, Windows)Read-only check output
Precheck was not run: no PR-head code is run here. Diff check: passed. Conventions: passed. ABI audit: not applicable. Stack check: passed, no errors. Hosted:
gh api repos/boykopovar/AnyPS5/commits/f1a259d63bfd571211c8c4d131f46775c1468333/check-runs, and the Windows job log.Negative control
Not run here. A negative control needs a local build and run of the recorder test, and code from this head is not run here.
Findings
Blocking
None from the code read.
Non-blocking
agc_driver_recorderon a host that runs it would show the stale-memo case is covered.Sources
github.com/boykopovar/AnyPS5@f1a259d63b/core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppgithub.com/boykopovar/AnyPS5@f1a259d63b/core/libs/prx/libSceAgcDriver/Execution/include/GuestMemory.hppwindowsonf1a259d63bNot verified
Texture.cppand the recorder test.To get this to a good state
agc_driver_recorderat this head.