GPU: compact watch page tracking with dense PageBits and inline OneOrMany storage #3227
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3229"
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 Marvisak/VIctory. Originally posted by 0xKaji on 2026-11-26T13:48:02Z.
Summary
Compacts
victory-gpu's write-watch metadata inwatch.rsto eliminate per-pageBTreeSetnodes and per-page heapVecallocations when tracking hundreds of thousands of 64 KiB pages.Changes
PageBitsdense bitset (watch.rs): ReplacesChanged.0: Mutex<BTreeSet<usize>>with a contiguousBox<[u64]>bitset relative to the tracked range's start page (1 bit per 64 KiB page = 16 bytes per MiB), with O(1)insert/remove/containsandtrailing_zeros()-basedrange_pages.OneOrMany<T>inline storage (watch.rs): ReplacesVec<Arc<Changed>>inGuards::holdersandVec<usize>inGuards::alias_ofwith an inline single-element enum (One(T) | Many(Vec<T>)) that spills toVeconly when a page has multiple holders/aliases and collapses back toOneonretain.Tracked::disarmtrimming (watch.rs): Shrinks oversizedSaved::armed(> 64) andSaved::bytes(> 16) capacities when disarming.Verification
cargo xwin clippy --workspace --all-targets --locked --target x86_64-pc-windows-msvc -- -D warningscargo xwin clippy --workspace --all-targets --all-features --locked --target x86_64-pc-windows-msvc -- -D warningscargo test -p xtask --locked(6/6 passed)watch::tests:: --test-threads=1: 17/17 passed (includingpage_bits_tracks_multi_word_rangesandone_or_many_spills_and_collapses).Related PRs
watch.rsin areas distinct from#3154(alias page unprotection on last tracker drop),#3156(take_splitunmapped merge), and#3161(transitive alias groups).Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T14:09:06Z.
Review: APPROVED
Verified on RTX 5090 against
origin/main(63bcca4):cargo test -p victory-gpu --lib watch:: -- --test-threads=1: 17/17 passed (includingone_or_many_spills_and_collapsesandpage_bits_tracks_multi_word_ranges).cargo test -p victory-gpu --lib shadow:: -- --test-threads=1: 10/10 passed.cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Cleanly compacts watch page tracking with dense
PageBitsand inlineOneOrManystorage.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by Desamodeth on 2026-11-26T22:08:59Z.
Code review location:
crates/victory-gpu/src/watch.rs; line 122A mixed tracker can reach this with an empty dirty set. Its count is maintained on insert/remove, so this check skips scanning the whole bitset. The CPU measurements are in the review.
Imported from Marvisak/VIctory. Originally posted by Desamodeth on 2026-11-26T22:08:59Z.
Review: COMMENTED
Measured the dirty-page index on Windows x64 at
e3194263versusmain@63bcca43. For a 1 GiB span (16,384 console pages), a fully dirty index retained 167,064 B on main and 2,048 B here. Reading the whole dirty set took 11.9–12.0 → 7.73–7.74 µs. With only one dirty page, the same query took 28 → 252–254 ns. A 64-page query around it took about 28 ns on both. Heap figures cover the dirty index only.I suggest the empty-set check below. Mixed trackers have no clean bit and can still reach
range_pageswith zero dirty pages. With just the middle page eligible at registration, then removed, a full-span query took 9.8 ns on main, 223–224 ns here, and 8.9 ns with the check. The check also matched the tree oracle over 9,000 mutations and range queries.I updated #3395 (
31a5b6bd) to consume the borrowed aliases via.iter(). Both PRs together passed all 17 watch tests in default and diagnostics builds, and workspace Clippy in both configurations. The inline suggestion also passed both watch suites. CPU-only synthetic measurements on a Ryzen 7 9800X3D, rustc 1.98.1 release, two runs of 12 interleaved batches including the dirty-set lock and result vector. AI-assisted with Codex Astra 6.2 High.Imported from Marvisak/VIctory. Originally posted by Jackster on 2026-11-26T22:52:28Z.
Windows 11,
63bcca4+ this PR, Radeon RX 7900 XTX:cargo test -p victory-gpu --lib: 233 passed / 0 failed / 1 ignored (unpatched63bcca4here: 231 passed; +2).cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.The two added tests are
watch::tests::page_bits_tracks_multi_word_rangesandwatch::tests::one_or_many_spills_and_collapses, both passing, and the watch/eviction tests that useruntime_pagesare unchanged. Synthetic only. AI-assisted.Imported from Marvisak/VIctory. Originally posted by 0xKaji on 2026-11-26T22:55:10Z.
Thanks for the benchmark and review! Applied your
self.is_empty()fast-path suggestion inPageBits::range_pagesand re-verified with workspace clippy (-D warnings) and all 17watch::tests.Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-27T00:00:01Z.
Review: APPROVED
Looks good — clean, safe replacement of per-tracker
BTreeSet<usize>and per-pageVecallocations with densePageBitsand inlineOneOrManystorage.Checked
crates/victory-gpu/src/watch.rs:52-246and every call site (track_as,Drop for Tracked,take,taken,changed,disarm,mark_changed,title_memory_remapped,title_memory_aliased):PageBitsmaintainscountaccurately across duplicate inserts/removes, short-circuitsrange_pageswhen empty or out of bounds, and handles single-word, cross-word, and exact 64-page-aligned boundaries cleanly (andbase <= usize::MAX >> 16keepsbase + words.len() * 64overflow-free on 64-bit).OneOrMany+map_push/map_retainspill cleanly from inlineOnetoMany, collapse back toOnewhen reduced to a single element, remove empty map keys, and preserve alias deduplication intitle_memory_aliased.disarm()trims oversizedarmed/bytescapacities cleanly without changing semantics.Verification (
f992d7f3):cargo xtask policyandcargo clippy -p victory-gpu(default and--features diagnostics,--tests -- -D warnings): passed.watch::tests::(17/17): passed on both hardware GPU and WARP (--features diagnostics,VICTORY_D3D12_DEBUG=1).PageBitsagainstBTreeSet<usize>across 70(base, span)boundary configurations (including(usize::MAX >> 16) - 300, spans0/1/2/63/64/65/127/128/129/260, andto = usize::MAX, 80 ops each) andOneOrMany+map_push/map_retainagainstBTreeMap<usize, Vec<u32>>(5,000 ops): zero divergences.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.