fix(agc): keep write-tracker generations 64-bit so they cannot wrap #14899
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/14899"
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 Sam-mon7 on 2026-11-01T23:37:15Z.
What
WriteTracker(GuestMemory.cpp) kept its generation counter, its stable counter and every stored stamp as 32-bit values: the per-block arrays (blocks,cpuBlocks,coarseBlocks,hintBlocks), the CPU and walk page stamps, the driver pieces, the refused-block map and the unstamped-store ring. Every consumer (UnchangedSince,WrittenSince,StoredAllSince,NewestStamp,ChangedBlocks) compares 64-bit stamps, andnoteWrittenRunnarrowed the generation it passes on to 32 bits. After 2^32 generation bumps, a block written after the wrap carried a small stamp. It then compared as older than a stamp taken before the wrap, so changed memory read as unchanged and a cached resource could be reused over new data.The counters, every stored stamp and
noteWrittenRun's parameter are now 64-bit, and nothing narrows between the counter, the stored stamps and the 64-bit API values. Block offsets inside aDriverPiecestay 32-bit. Each 4 GiB tracking leaf grows from 772 KiB to 1544 KiB; leaves are allocated only once a block in them is stamped.agc_write_tracking_generation_wrapmoves the generation to just below 2^32 throughAdvanceTrackerGenerationForTest. It then checks that driver and CPU stores made after the crossing still read as changed, over coarse runs, single blocks, CPU pages, driver pieces andChangedBlocks.Noticed while working on Demon's Souls (PPSA01341) on a local branch; the change is generic.
Tested
Windows 11 Pro 10.0.26200, WinLibs GCC 15.2.0 r7, Release, NVIDIA GeForce RTX 4070 (driver 610.88). Branch based on
main2c28d327e3; headbcda8554da.ctest -R '^(agc_write_tracking|agc_resident_direct_remap|agc_rewatched_direct_shared|agc_import_alias_shared|agc_compared_shared_generations|agc_collect_mapping_history|agc_draw_snapshot_epoch|agc_driver_store_over_untracked|agc_driver_untracked_snapshot_hint|agc_driver_write_data_written_ahead|agc_private_collect|agc_shared_write_partial_collect|agc_unchanged_cpu_stamps|agc_driver_resource_cache_collect_refusals|agc_screenshot)' -V -j2withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1andVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation:main2c28d327e323/23 pass; headbcda8554da24/24 pass, including the new test. Neither log containsVUID-or a missing-validation-layer message.main's GuestMemory.cpp (32-bit tracker, plus only the test hook),agc_write_tracking_tests --generation-wrapfails withthe tracker generation did not cross 2^32; with this change it passes.python tools/check_conventions.py --base upstream/mainpasses.Overlap:
tools/pr_overlap.py --branchfound no shared lines with any open pull request it could compare. It could not compare #5021, #6187, #6188, #6192, #6209, #6273, #7048, #7604, #7642 and #12840, which conflict withmain. They share GuestMemory.cpp/.hpp, and #6273, #7048 and #7604 also share WriteTracking.cpp. Checked by hand: none of #6187, #6192, #7048 and #7604 touches the tracker's stamp declarations, and #12840 is a BDA heap-mirror write-back. If one of them lands first, I'll rebase.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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-02T02:03:05Z.
Review: APPROVED
Windows 11, WinLibs GCC 15.2.0 r7, Release, AMD Radeon RX 9070 XT,
ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation. Headbcda8554damerged into upstream/main93dbd0f82a:ctest -R '^agc_write_tracking': 5/5 pass, includingagc_write_tracking_generation_wrap.GuestMemory.cpp(32-bit tracker), with only yourAdvanceTrackerGenerationForTestadded so the test links.agc_write_tracking_generation_wrapfails (the tracker generation did not cross 2^32), and the other four pass. It fails at the crossing check rather than at a stale "unchanged" answer, because the 32-bit counter can't hold the advanced value. That still shows main can't represent a post-wrap generation.Read against main:
noteWrittenRun's parameter and every stored stamp are now 64-bit, so nothing narrows between the counter and the 64-bit API values. The doubled leaf (772 KiB to 1544 KiB per 4 GiB) is only paid for leaves that are actually stamped.