perf(agc): return settled imports under live storage images to the write watch #19071
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/19071"
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 klosixgaming-arch on 2026-11-12T18:42:42Z.
What
A Windows host import of private memory under the settle floor starts out compared. When its deferred settle read completes, it returns to the write watch. Since
0623263512, an import that a live storage image overlaps stays compared for good, becauseGuestMemory::Rewatchstamps the returning blocks as a CPU store. An image with results pending would take that stamp for a CPU store over its results and drop them.Keeping it compared is expensive. One compared block makes every storage image over it untracked, so each refresh of such an image compares the image's whole guest range. Before comparing, it flushes the pending results of the other images over that range. In Cyberpunk 2077 (PPSA03974) this happens in every run:
mainwith #10443 and my open series), I profiled a run with 6 such images. There,StorageTexture::compareUntrackedtakes about 20% of queue worker 0's time, and 62% of that is the flush hook'sRecorder::SyncThrough.This change returns such an import to the write watch even under live storage images. An image then proves a block that only the rewatch stamped, instead of reading the stamp as a CPU store:
Rewatchrecords the stamp it gives each block.GuestMemory::RewatchedBlocks(one tracker lock per block scan),OnlyRewatchedSinceandRewatchedtell a storage image which of its stamped blocks were last stamped by a rewatch. An atomic skips the lookup while no rewatch has happened.StorageTexture::rewatchProof, afterFlushGpuWritesover the block:baselineMissproves the units' bytes (the upload copy of a small image, or the hash taken when the range left the watch). Without a proof, the stamp keeps its old meaning.refresh(in the block scan and in the per-layer check) and inwriteBackLayers.APS5_NO_REWATCH_UNDER_IMAGESrestores the old rule, with onedocs/dev/ENVIRONMENT.mdrow.Tests:
agc_import_settle_storage_image(changed). The settled import of a 64 KiB image now returns to the write watch.agc_import_rewatch_under_image(new). A 2 MiB image is uploaded over watched memory, so its units have generations. Then its first block leaves the watch and returns throughUnwatchandRewatch, as an overlapping compared import would.Tested
Windows 11 (10.0.26200), NVIDIA GeForce RTX 5090 (driver 617.42), Ryzen 9 9950X3D, WinLibs GCC 15.2, Release.
Tests.
^agc_(import|storage|unwatch|untracked)pass, the two above included. They ran withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1andVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, as did the same 35 tests onmain09ab49de96, which also pass. Neither log has aVUID-line or a layer-not-found line.agc_import_settle_storage_image(ii) loses the CPU store, andagc_import_rewatch_under_image(i) loses the clear in the rewatched block;agc_import_settle_storage_image(ii) andagc_import_rewatch_under_image(i) fail as well. That is why the proof is needed.Cyberpunk 2077 (PPSA03974), intro movie, 3200x1800. Alternating builds on an otherwise idle machine,
APS5_TRACE_SECONDS=60:10andAPS5_TRACE_SUMMARY_EVERY=10. "Movie mean" is the mean of the run's 10 s summary windows during the movie. Traces and every summary line are in the release perf-captures-2026-11-12.main09ab49de9652207f887aThe median of the movie means goes from 48.6 to 91.1 presents per 10 s, about +85%. In the traced windows
Vulkan.Dispatch.shader_resourcesfalls from 86.9 to 16.7 ms per frame (run 3 of each).On my experimental stack (this change plus #10443 and my open series), the intro ran at 122.8, 125.5, 104.5, 114.0 and 103.6. With
APS5_NO_REWATCH_UNDER_IMAGES=1in the same build it ran at 101.6, 65.2, 67.9, 110.4 and 78.9. The old rule's slow runs do not happen with the change.Frame dumps of the intro movie and of the title screen with the change look right. No run aborted.
Summary lines of the traced windows, run 3 of each (paths replaced)
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-12T20:05:02Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this; the points below are optional.
What I ran
Head
52207f887a74d7ff3f0071ff3187c75aeaadc446(PR #19071, basemain). I read the diff and the head text throughrepo_read.py. I did not build or run the tests: the change is Windows-only, and this review ran on Linux.Read: the diff hunks of all 8 files in
files.jsonreviewed. Head text ofGuestMemory.cppandTexture.cppin the ranges above. Not read at head:GuestBufferMemory.cppandRecorder.cpp, which are excluded from the review folder as too large, and the rest ofTexture.cpp.Results
agc_import_*testsFindings
Blocking
None.
Non-blocking
core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp:1431:rewatchStampsgets one entry per rewatched block (GuestMemory.cpp:2322) and nothing ever erases one. A search forrewatchStampsfinds no erase. Stale entries are harmless, because lookups compare the stored stamp with the current one (GuestMemory.cpp:2445,GuestMemory.cpp:2477). The map still keeps an entry for each rewatched 64 KiB block for the life of the process. Erasing the entry when the block is stamped again would bound it.Not verified
confirmRewatchedproves unchanged gets proved again on every refresh. That depends on whether the block-scan path advanceslayerGenerationafter an unchanged proof, and I did not read that path (Texture.cpp:2592to2640).writeBackLayers(Texture.cpp:7187, wherecomparedUnitsisnullptr). I did not trace it.GuestBufferMemory.cppandRecorder.cpp, and most ofTexture.cpp. I read only their diff hunks.GuestMemory.cppfunctions (from line 2433) sit outside the#ifdef _WIN32block at 2411 to 2413, asWriteWatcheddoes. I checked this by reading, not by building.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-13T23:01:36Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this change; the points below are optional.
What I ran
Reviewed head
699ec1e45f90000020acb1c368e72cf65d2c1611from the prepared diff and targeted source reads. No commands or tests were run in this review.Results
Findings
Blocking
None.
Non-blocking
GuestBufferMemory.cppandTexture.cppreceive a final full-file review before merge; the review bundle excluded them because they were too large. The changed hunks and relevant code paths were inspected throughrepo_read.py.Not verified
The full text of
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp,core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp, andcore/libs/prx/libSceAgcDriver/tests/Recorder.cppwas excluded as too large; targeted relevant ranges were read throughrepo_read.py. The other changed files were included in the manifest, but not all were opened in full. No tests, build, runtime, or physical-console checks were performed. The reported Windows test and performance results were not independently verified.To get this to a good state
Nothing is required. Optional: complete a full review of the excluded files before merge.