Skip to content

perf(agc): stores beside a range in its 64 KiB block leave the range unchanged - #6346

Merged
adriadam10 merged 1 commit into
boykopovar:mainfrom
SleglJan:pr/unchanged-shared-block
Oct 18, 2026
Merged

adriadam10 merged 1 commit into
boykopovar:mainfrom
SleglJan:pr/unchanged-shared-block

Conversation

@SleglJan

@SleglJan SleglJan commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

What

UnchangedSince and UnchangedSinceAll answered from the generations of the 64 KiB blocks a range touches. A CPU or driver store anywhere in a block failed every unchanged proof over any range in it. Among them are the proofs that let a draw keep its sampled textures (fastRevalidate), a reused image table (TableCurrent) and a storage image's upload (StorageTexture::refreshProved). Every caller of the two functions and of StoredOver gets the finer answer. In some runs of 007 First Light (PPSA11386) the CPU writes other pages of the blocks that hold sampled textures in nearly every frame, and most fast revalidations fail and take the full walk.

When a block's generation is newer than the query's, the two functions now look at what wrote the block: the CPU page generations over the range and the block's driver-store pieces, as StoredOver does. StoredOver was already used for this at the shared edge blocks of a surface's write-back (#441).

So that this answer sees every driver stamp:

  • The walk after an own store (storeOwn) stamps the pages it finds dirty in a page map of their own.
    • The unchanged proofs count those pages, so a guest store beside the stored bytes in the same page is not hidden.
    • StoredOver counts them only in a block without driver pieces; where pieces exist it answers as before.
    • They take no slot of the block's four driver pieces and do not count for the complete coverage StoredAllSince proves (fix(agc): apply completion-proven native depth clears #5554).
  • On Windows, a private mapping made over a block that has driver pieces marks them as forgotten instead of dropping them.

A block without pieces or walked pages has therefore had no driver store. Forgotten pieces still count as a store over the whole block. One answer of StoredOver changes: a block whose newer stamp comes only from CPU stores to other pages no longer reads as stored over.

Related:

Tested

  • agc_write_tracking:
    • CheckSharedBlockProofs (new): CPU and driver stores beside a range leave it unchanged, alone and in a batch. These are seen:
      • stores inside it;
      • a whole-block store;
      • a whole-block store followed by a partial one;
      • a guest store made beside an own store, in the same page, during the store.
    • A store over six pages of a block leaves the rest of the block unchanged.
    • StoredAllSince keeps an own store's exact coverage, is not proven by its dirty pages, and survives own stores elsewhere in the block; a neighbour in an own store's page is not stored over but reads as changed.
    • CheckVersionRanges: the exact expectation was block-wide. It now checks three things:
      • a range never reads unchanged over a newer write to its bytes;
      • it never reads changed while its blocks are unchanged;
      • the batch answers like the single calls.
        It also adds whole-block stores to the random history.
    • Without the change in GuestMemory.cpp the test fails at "stores beside the range in its 64 KiB block count for it".
  • Test machine: RTX 3080, NVIDIA 615.78.08, CachyOS (Linux 7.2.10), Ryzen 9 7950X3D, Release.
  • lavapipe (Mesa 26.2.4, LLVM 23.1.1; Arch Linux container, GCC 16.2.1, Release), before the rebase onto 0e4ea13: ctest -R '^agc', 589 tests, 8 failures, the same 8 as on main 4e9a2a8 built the same way. The container has no write watching, so the write-tracking tests skip there, agc_write_tracking included.
  • 007 First Light:
    • Scene: the menu with the gameplay save, no input, frames 215–255 by window title, warm shader cache.
    • Main at d92a8da stops at frame 38 (the 2D-biased volume sampling check of fix(shader): sample single-level volumes through biased 2D accesses #5461), so the runs use one tree: d92a8da plus 12 local commits.
    • These runs used the GuestMemory.cpp change of the revision before the rebase onto fix(agc): apply completion-proven native depth clears #5554, in which the walk's dirty runs were driver pieces and took slots of the block's four, so it answered changed at least wherever this revision does; the fallback in the unchanged proofs is otherwise the same.
    • Alternated ABBAABBA, without (A) and with (B) this change. The A build also carries a diagnostic that logs, for each failed fast revalidation, what wrote its changed ranges, only when its switch is set.
    • APS5_PROFILE_DRAW=1 in every run, for the revalidation counters. Both arms of these runs also set APS5_HOST_IMPORT_MIB=12288, APS5_RESOURCE_CACHE_ENTRIES=64 and APS5_NO_DRAW_SRT_ENTRIES=1.
run FPS fast revalidations full walks revalidation time
A1 0.514 14,513 24,005 46.2 s
B1 0.639 36,444 122 20.1 s
B2 0.625 38,735 123 21.5 s
A2 0.631 41,663 121 22.9 s
A3 0.593 36,690 393 20.8 s
B3 0.538 38,371 120 23.0 s
B4 0.581 24,986 136 13.5 s
A4 0.628 38,541 130 20.9 s

The counters are cumulative at the end of the run (frames 252–259). B4's menu started later than the others' (frame ~210 instead of ~175–185), so its window starts with the menu and it has fewer revalidations. In every 10 s interval that started after frame 150, the share of revalidations that took the full walk was:

  • without the change (8 runs: A1–A4, one more on the A build, and 3 on the A build with the diagnostic switched on): 61–65% in every interval of 2 runs (A1, FPS 0.514, and a diagnostic run, 0.505), 15% in every interval of 1 run (0.590), at most 1.2% in the other 5 (median FPS 0.627);
  • with the change (11 runs: B1–B4, five more on the B build, and two on a diagnostic build): 0.0% (at most one full walk per interval) in every run (median FPS 0.624, range 0.538–0.639).
  • In the three diagnostic runs without the change, 63,543 of 64,593 failing range queries of fast revalidations (98.4%) had newer CPU stores only on other pages of their 64 KiB block and no recorded driver store over them.
  • Summary lines: 11 captures alternated between the arms with only APS5_TRACE_FRAMES=200:40 set, warm caches, the same tree; the sandbox writes the log to a file. 2 of the 5 A captures ran at about 0.45 FPS over frames 215–255 (one of them while a build ran on the machine), none of the 6 B captures did. 6 are attached, the ones with a saved trace that ran without another load on the machine: 3 per arm (the trace files are the assets aps5-trace-A1–A3 and B1–B3 of https://github.com/SleglJan/AnyPS5/releases/tag/perf-traces-unchanged-shared-block, in the order of the lines below). Commit 7141b56717d8 is the A build and 91e399694be4 the B build (both local). Frame p50, base (A): 2,240, 1,547 and 1,561 ms; with the change (B): 1,554, 1,641 and 1,553 ms. The first A capture had 327 ms of GPU work per present against 158–166 in the others and 11,028 ms of Driver.Packet per frame against 7,636–8,083.
{"commit":"7141b56717d8","dirty":false,"env":{"APS5_TRACE_DIR":"<path>","APS5_TRACE_FRAMES":"200:40"},"gpu":"NVIDIA GeForce RTX 3080","driver":"NVIDIA 615.78.08","os":"Linux 7.2.10-1-cachyos","resolution":"3840x2160","window":{"spec":"frames 200:40","first_present":200,"ms":89632.562},"presents":40,"frame_ms":{"p50":2239.687,"p90":2341.581,"p99":2416.897,"max":2416.897},"gpu_busy_ms_per_present":327.461,"worker_busy_pct":{"queue worker 0x0":99.979,"queue worker 0x20":97.573,"queue worker 0x28":98.590,"queue worker 0x30":98.588,"queue worker 0x38":97.573},"top_phases_ms_per_frame":{"Driver.Packet":11028.243,"Driver.Packet.memory_wait":8297.673,"Driver.Packet.draw":2155.935,"Driver.Draw":2155.674,"Driver.Draw.shader_compile_and_link":1356.085,"Shader.DrawStage":1335.618,"Shader.DrawStage.capture_resources":1171.822,"Driver.Draw.draw_and_resource_release":779.367},"trace_dropped":false,"trace":"aps5-trace-7141b56717d8-2.json.gz"}
{"commit":"7141b56717d8","dirty":false,"env":{"APS5_TRACE_DIR":"<path>","APS5_TRACE_FRAMES":"200:40"},"gpu":"NVIDIA GeForce RTX 3080","driver":"NVIDIA 615.78.08","os":"Linux 7.2.10-1-cachyos","resolution":"3840x2160","window":{"spec":"frames 200:40","first_present":200,"ms":62039.415},"presents":40,"frame_ms":{"p50":1546.925,"p90":1593.178,"p99":1618.618,"max":1618.618},"gpu_busy_ms_per_present":158.336,"worker_busy_pct":{"queue worker 0x0":99.973,"queue worker 0x20":97.707,"queue worker 0x28":98.620,"queue worker 0x30":98.616,"queue worker 0x38":97.712},"top_phases_ms_per_frame":{"Driver.Packet":7636.375,"Driver.Packet.memory_wait":5873.218,"Driver.Packet.draw":1478.977,"Driver.Draw":1478.760,"Driver.Draw.shader_compile_and_link":1110.349,"Shader.DrawStage":1095.407,"Shader.DrawStage.capture_resources":943.222,"Driver.Draw.draw_and_resource_release":357.749},"trace_dropped":false,"trace":"aps5-trace-7141b56717d8-2.json.gz"}
{"commit":"7141b56717d8","dirty":false,"env":{"APS5_TRACE_DIR":"<path>","APS5_TRACE_FRAMES":"200:40"},"gpu":"NVIDIA GeForce RTX 3080","driver":"NVIDIA 615.78.08","os":"Linux 7.2.10-1-cachyos","resolution":"3840x2160","window":{"spec":"frames 200:40","first_present":200,"ms":62364.688},"presents":40,"frame_ms":{"p50":1560.970,"p90":1613.087,"p99":1644.182,"max":1644.182},"gpu_busy_ms_per_present":160.874,"worker_busy_pct":{"queue worker 0x0":99.974,"queue worker 0x20":97.500,"queue worker 0x38":97.519,"queue worker 0x28":98.506,"queue worker 0x30":98.503},"top_phases_ms_per_frame":{"Driver.Packet":7668.336,"Driver.Packet.memory_wait":5886.401,"Driver.Packet.draw":1485.632,"Driver.Draw":1485.405,"Driver.Draw.shader_compile_and_link":1112.668,"Shader.DrawStage":1095.616,"Shader.DrawStage.capture_resources":942.856,"Driver.Draw.draw_and_resource_release":361.708},"trace_dropped":false,"trace":"aps5-trace-7141b56717d8-2.json.gz"}
{"commit":"91e399694be4","dirty":false,"env":{"APS5_TRACE_DIR":"<path>","APS5_TRACE_FRAMES":"200:40"},"gpu":"NVIDIA GeForce RTX 3080","driver":"NVIDIA 615.78.08","os":"Linux 7.2.10-1-cachyos","resolution":"3840x2160","window":{"spec":"frames 200:40","first_present":200,"ms":62183.827},"presents":40,"frame_ms":{"p50":1554.095,"p90":1591.655,"p99":1630.537,"max":1630.537},"gpu_busy_ms_per_present":163.514,"worker_busy_pct":{"queue worker 0x0":99.971,"queue worker 0x20":97.632,"queue worker 0x28":98.608,"queue worker 0x30":98.606,"queue worker 0x38":97.635},"top_phases_ms_per_frame":{"Driver.Packet":7653.412,"Driver.Packet.memory_wait":5908.576,"Driver.Packet.draw":1486.227,"Driver.Draw":1486.015,"Driver.Draw.shader_compile_and_link":1110.462,"Shader.DrawStage":1099.376,"Shader.DrawStage.capture_resources":943.954,"Driver.Draw.draw_and_resource_release":367.067},"trace_dropped":false,"trace":"aps5-trace-91e399694be4-2.json.gz"}
{"commit":"91e399694be4","dirty":false,"env":{"APS5_TRACE_DIR":"<path>","APS5_TRACE_FRAMES":"200:40"},"gpu":"NVIDIA GeForce RTX 3080","driver":"NVIDIA 615.78.08","os":"Linux 7.2.10-1-cachyos","resolution":"3840x2160","window":{"spec":"frames 200:40","first_present":200,"ms":65669.167},"presents":40,"frame_ms":{"p50":1641.170,"p90":1688.472,"p99":1719.335,"max":1719.335},"gpu_busy_ms_per_present":159.693,"worker_busy_pct":{"queue worker 0x0":99.973,"queue worker 0x20":97.663,"queue worker 0x38":97.666,"queue worker 0x30":98.611,"queue worker 0x28":98.613},"top_phases_ms_per_frame":{"Driver.Packet":8082.924,"Driver.Packet.memory_wait":6239.263,"Driver.Packet.draw":1575.564,"Driver.Draw":1575.358,"Driver.Draw.shader_compile_and_link":1193.099,"Shader.DrawStage":1182.535,"Shader.DrawStage.capture_resources":1029.930,"Driver.Draw.draw_and_resource_release":372.720},"trace_dropped":false,"trace":"aps5-trace-91e399694be4-2.json.gz"}
{"commit":"91e399694be4","dirty":false,"env":{"APS5_TRACE_DIR":"<path>","APS5_TRACE_FRAMES":"200:40"},"gpu":"NVIDIA GeForce RTX 3080","driver":"NVIDIA 615.78.08","os":"Linux 7.2.10-1-cachyos","resolution":"3840x2160","window":{"spec":"frames 200:40","first_present":200,"ms":62375.632},"presents":40,"frame_ms":{"p50":1552.708,"p90":1610.929,"p99":1629.742,"max":1629.742},"gpu_busy_ms_per_present":165.812,"worker_busy_pct":{"queue worker 0x0":99.973,"queue worker 0x20":97.544,"queue worker 0x28":98.513,"queue worker 0x38":97.548,"queue worker 0x30":98.511},"top_phases_ms_per_frame":{"Driver.Packet":7669.890,"Driver.Packet.memory_wait":5933.916,"Driver.Packet.draw":1490.126,"Driver.Draw":1489.903,"Driver.Draw.shader_compile_and_link":1109.717,"Shader.DrawStage":1104.190,"Shader.DrawStage.capture_resources":948.091,"Driver.Draw.draw_and_resource_release":368.592},"trace_dropped":false,"trace":"aps5-trace-91e399694be4-2.json.gz"}

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none
  • GPUs tested: NVIDIA RTX 3080, driver 615.78.08, CachyOS Linux 7.2.10; lavapipe (Mesa 26.2.4, LLVM 23.1.1), Arch Linux container
  • AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

@SleglJan

Copy link
Copy Markdown
Contributor Author

@github-actions github-actions Bot added the agc libSceAgc* label Oct 15, 2026
This was referenced Oct 15, 2026
…unchanged

UnchangedSince and UnchangedSinceAll answered by the stamps of the 64 KiB blocks a range
touches, so a CPU or driver store anywhere in a shared block failed every unchanged proof
over it. When a block's stamp is newer, they now look at what wrote the block: the CPU page
stamps over the range and the block's driver-store pieces, as StoredOver does.

For that answer to see every driver stamp, the walk after an own store stamps the pages it
finds dirty in a page map of their own. The unchanged proofs count those pages, so a guest
store beside the stored bytes in the same page is not hidden. StoredOver counts them only in
a block without driver pieces: where pieces exist it answers as before. They take no
driver-piece slot and do not count for the complete coverage StoredAllSince proves. On
Windows, a private mapping made over a block that has driver pieces marks them as
forgotten instead of dropping them.

StoredOver no longer answers stored over for a block whose newer stamp comes only from CPU
stores to other pages.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@simonbbby

Copy link
Copy Markdown
Contributor

Independent CPU correctness check at exact head c128308d4053faa60b6eaa617e5ea314841980de, Ubuntu 24.04 / kernel 7.0.0-38 / GCC 13.3 / Ryzen 9 9950X, with real Linux write watching.

The unchanged WriteTracking.cpp, linked directly with the production GuestMemory.cpp, GuestAllocations.cpp, GuestArena.cpp and GuestWriteWatch.cpp, passes 3/3. Replacing only GuestMemory.cpp with HEAD^ makes that same test fail 3/3 at stores beside the range in its 64 KiB block count for it. No tracker or write-watch implementation was mocked. Standalone build: C++20, -O2 -pthread -msse4.2, function/data sections and linker garbage collection; this bypasses our unrelated SDL/XRandR configure blocker.

I also ran an external history oracle to vary the offsets beyond the fixed offsets in CheckVersionRanges:

  • 16 watched 64 KiB blocks; 2,048 events per seed. Interleaved CPU writes followed by CollectWritesUncached (modeled at page granularity), whole-block MarkWritten, variable-length MarkWritten spanning up to two blocks, and actual StoreOwnBytes writes up to 8,193 bytes. Starts and queries vary across page/block boundaries.
  • After each event: 36 single-range queries against randomly selected prior generation checkpoints and 12 three-range batches. An event list independently checks that no query reports unchanged over a newer write. Conservative changed answers are allowed within blocks with newer events; blocks with no newer event must remain unchanged. Batches must equal the conjunction of their single queries.
  • Seeds 6346, 1, 0xdeadbeef, 0x61387a29, 0xffffffffffffffff: 368,640 single queries and 122,880 batches pass. There were 22,147 unchanged answers, so this did not pass by returning changed for everything. Write-watch availability and nonzero collection results are hard requirements, not skips.
  • Sensitivity controls, changing only scratch production copies: omitting the whole-block generation (entry.whole = 0) is caught at step 1; forgetting overwritten pieces (entry.dropped = 0) is caught at step 33, both with seed 6346 and unsafe unchanged diagnostics. The untouched PR stock test and oracle pass again afterward; the worktree stays clean.

Scope: sequential CPU tracker correctness after dirty-page collection. This does not check concurrent renderer interactions, Windows private mappings, GPU execution, or the reported title performance; no FPS claim.

@SleglJan
SleglJan force-pushed the pr/unchanged-shared-block branch from c128308 to 5532d51 Compare October 15, 2026 15:07
@SleglJan

Copy link
Copy Markdown
Contributor Author

Rebased onto main 0e4ea13 after #5554 merged, and force-pushed as 5532d51.

#5554 added StoredAllSince, a proof that driver stores covered every byte of a range. To keep it exact, the walk after an own store no longer records its dirty runs as driver pieces. It stamps them in a page map of its own:

  • the unchanged proofs count those pages;
  • StoredOver counts them only in a block without driver pieces; where pieces exist it answers as on main;
  • they take no driver-piece slot and do not count for StoredAllSince.

On Windows, a private mapping made over a block with driver pieces marks them as forgotten instead of dropping them; a block without pieces gets no entry.

New checks in CheckSharedBlockProofs cover StoredAllSince after own stores and a neighbour in the page of an own store. #5554's CheckStoredAllSince passes unchanged.

RTX 3080 (NVIDIA 615.78.08), on 0e4ea13: ctest -R '^agc', 593 tests, 1 failure, agc_driver_store_over_untracked, which fails the same way on main 3ee5371 (see #5671). agc_write_tracking fails without the GuestMemory.cpp change and passes with it.

@simonbbby, thanks for the check at c128308. New since that head: the page map, and on Windows existing pieces are marked forgotten instead of every block being marked stored whole. The merge of touching same-generation pieces is gone, and the whole-block entry now comes from #5554.

AI-assisted: yes (Claude Code)

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 15, 2026
@simonbbby

Copy link
Copy Markdown
Contributor

Retested the changed page-map semantics at 5532d51fb80902de94501f3e0f360c94f5553ca1; my earlier result remains pinned to c128308d4.

Same Ubuntu 24.04 / kernel 7.0.0-38 / GCC 13.3 / Ryzen 9 9950X setup, standalone production CPU objects and real Linux write watching:

  • Unchanged current WriteTracking.cpp: 3/3 pass, including CheckStoredAllSince and the new own-store/neighbor checks. Substituting only current HEAD^'s GuestMemory.cpp fails 3/3 at the shared-block proof assertion.
  • Repeated the five seeded variable-offset histories from my previous comment, now also checking every positive StoredAllSince answer against a separately sorted union of newer driver intervals. CPU-only page events are excluded from that union. Conservative false answers remain allowed when history has been discarded.
  • 368,640 single-range queries, 122,880 batches, and 368,640 complete-coverage queries pass. Of the latter, 290,532 returned true and every one had full driver-byte coverage in the independent history. There were 22,837 unchanged answers; batches agree with singles.
  • Sensitivity: routing the own-store dirty walk back into driver pieces in a scratch production copy fails the stock test at one dword store proves complete surface coverage; the independent oracle also rejects it at step 8 with an unsafe complete coverage diagnostic. Omitting the new noteWalkStore call fails the stock test at a guest store beside a driver store in its page during the store is not seen. That neighbor-write case is covered by the stock fixture; the external oracle's own-store events model the declared store spans.

This covers the important separation: dirty pages can invalidate an unchanged proof without claiming that the driver stored every byte on those pages. No repository source was changed. Scope remains sequential Linux CPU tracking after collection; Windows private mappings, concurrent renderer interactions, GPU execution and title performance were not tested.

@Scramblrrrr

Copy link
Copy Markdown
Contributor

Windows/RTX5070Ti617.42 combined cross-test is ready at51b148e100509891c9b194da360e6dd80bdeb16b: https://github.com/Scramblrrrr/AnyPS5/tree/codex/first-light-watch-proof-current . Includes #6346 5532d51 and #6273 fdcbb83, on main93e54cedd plus our explicitly listed007/shared-table/level prerequisites. Both author commits applied cleanly; no replacement implementation.

30/30 selected native CPU/Vulkan checks PASS14.19s, no skips, including write_tracking's new cases, repeated-neighbour stores, image-table reuse/bounds, shared-table vouches, draw reuse/verify/inline, storage flush ordering, tessellation, serializer/cache and prebuild unset/0/1. Conventions clean. After final revision-string rebuild,5/5 related controlsPASS1.46s. Combined native evidence, not standalone each-PR evidence; no title FPS result yet.

Integration test adjustment: the a driver store over an entry case now counts2reuse/1resolution across its two dispatches, instead of1/1. With the finer range proof, clean siblings are reused even on the dispatch that rebuilds the changed entry. Both texel checks retained; no production proof weakened. #6273's CpuWriteResolutions=1 is retained. All other current #6340 expectations pass unchanged.

There is also an opt-in bounded copied-buffer ownership sampler in this test branch (maximum25small records per process, no game contents). Its initial asynchronous output triggered a native process-exit timeout; sampler-off control passed, and switching it to the existing direct trace sink made all3prebuild policies pass with sampling on. That defect was mine, not attributed to either PR. The full native result above has sampling enabled after the correction. Starting a guarded007 cross-test next. AI-assisted: Codex; raw title data local.

@github-actions github-actions Bot added the perf Performance change label Oct 18, 2026
@adriadam10 adriadam10 self-assigned this Oct 18, 2026
@adriadam10
adriadam10 merged commit 8f49a89 into boykopovar:main Oct 18, 2026
9 checks passed
oneandonlydean pushed a commit that referenced this pull request Oct 19, 2026
…e on Windows too

Since #6346 a CPU write elsewhere in an image table's 64 KiB block no
longer fails the table's unchanged proof on Windows, because the proof
is answered per page there too. The Windows-only expectation of a second
resolution is stale and agc_driver_image_table_reuse fails on Windows.
Expect the Linux count on every host.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* perf Performance change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants