GPU: preparing a view heap's page table scans the change tracker a word at a time #3248
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!3248
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3248"
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?
@borosf on GitHub · 2026-11-26 14:29 UTC · original
borosf:vibe/prepare-scans-words-842ca5→main· +124 −10 · 2 files · 2 commits · openmemory::prepareran once per list binding a title-memory view heap, per submission, and askedwatch::clean_bitonce per copy the layout names.The shape of it
A world submission carries tens of lists; each list's
Step::Memorycallsprepare, which loops overl.copies.iter().zip(&l.bits)— every copy the heap's page table names, about 4,700 in the world, nearly all clean — doing one acquire-load plus shift/test per copy. That is hundreds of thousands of single-bit loads per frame for a handful of answers.What changes
The layout now stores its copies' tracker bits as
(bit, copy_index)pairs ordered by bit, plus the first and last tracker word they span (built once inrewrite).dirty_indiceswalks the tracker a word at a time (dirty_word+trailing_zeros) over that span and returns only the changed copies' indices, merged against the sorted pairs.addis exactly what the per-copy loop found: same bits, same order. Bits belonging to other layouts that share a tracker word are skipped, which the new test pins down.watchgainsdirty_word(the word-level read of the sameDIRTYarrayclean_bitreads);clean_bititself is untouched.Verification
cargo clippy -p victory-gpu --all-targets --locked -- -D warnings— clean;--all-featurestoo.cargo test -p victory-gpu --lib --locked --no-fail-fast— 231 passed, 2 failed, both the known Intel baseline failures pristinemainalso fails (descriptor::host::tests::dynamic_slots_are_held_until_released,memory::tests::lists_share_a_table_and_copies_keep_their_views, #1744/#1829).memory::tests::the_dirty_scan_finds_each_changed_copy_once_in_tracker_order: tracker order, an all-clean tracker, foreign bits in the same words, an empty layout.rustfmt --edition 2024 --checkhunk counts againstmain:memory.rs30/30,watch.rs39/39.The frame line's
StepMemoryUscounter already totals this step per frame, so a world run with this merged shows the delta directly; this PR claims the per-list arithmetic, not a frame-time number.Synthetic tests only; no game data.
Part of the fifteen gaps claimed for this sweep on #1633. AI-assisted.
@cloph-dsp on GitHub · 2026-11-26 14:42 UTC · original
Independent local verification of head
c1c3302on Windows 11, Rust 1.100.0/MSVC:cargo test --locked -p victory-gpu --lib -- memory::tests::the_dirty_scan_finds_each_changed_copy_once_in_tracker_order --exact— 1 passed, 0 failed.git diff --checkagainst merge base — clean.CPU-only synthetic tracker-order test; worktree-local
CARGO_TARGET_DIR. AI-assisted (Hy4 flash). GPU/driver N/A. No game data, assets or DRM material used.@Bj0rnis on GitHub · 2026-11-26 14:44 UTC · original
Verified head
c1c33027on Windows 11 (x64, Rust 1.98.1, NVIDIA GeForce RTX 5070 Ti + WARP):origin/main(63bcca43): cleancargo test -p victory-gpu --lib --features diagnostics): 245 passed, 2 failed, 1 ignored (2.96s) — the 2 failures are the pre-existing #1744 NVIDIA 1M view-heap cap failures onmain(descriptor::host::tests::dynamic_slots_are_held_until_released,memory::tests::lists_share_a_table_and_copies_keep_their_views); no regressions and the new test passes on hardwareVICTORY_D3D12_WARP=1): 247 passed, 0 failed, 1 ignored (1.89s)-p victory-gpu --lib --tests --features diagnostics -- -D warnings): clean (0 warnings)cargo xtask policy: 191 files okNot tested: live title workload / frame-prep performance under gameplay.
AI-assisted test run and summary.
@Dukestar69 on GitHub · 2026-11-26 14:52 UTC · original · reviewed
Reviewed the diff and ran local verification on Windows 11 x64 (
cargo test -p victory-gpu --lib memory::tests:: -- --test-threads=1 --skip lists_share_a_table_and_copies_keep_their_views: 8/8 passed;cargo clippy -p victory-gpu --all-targets -- -D warnings: clean;cargo xtask policy: 191 files ok).The word-at-a-time bitset scan in
dirty_indicesis neat, but there is a correctness regression for untracked copies (c.dirty_bit() == None):prepare()checked!crate::watch::clean_bit(*bit), andclean_bit(None)returnsfalse("none for memory that is not tracked: never clean" perShadow::dirty_bit), so untracked copies (or copies created when the tracker's bit pool is full) were always passed toadd(...).by_bitbuilt via.filter_map(|(i, c)| c.dirty_bit().map(|b| (b, i as u32))), any copy withdirty_bit() == Noneis silently omitted fromby_bitand will never be refreshed bymemory::prepare()(effectively treated as permanently clean instead of never clean).Keeping a separate
untracked: Vec<u32>onLayout(for indices wherec.dirty_bit().is_none()) and iterating it inprepare()preserves the original semantics while keeping the fast word-at-a-time scan for all tracked copies. (Also, an earlyif by_bit.is_empty() { return out; }indirty_indicesavoids reading word0whenby_bitis empty.)Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
@borosf on GitHub · 2026-11-26 14:55 UTC · original
Correction to the arithmetic in this PR's body, from measuring it rather than estimating: the per-copy loop over 4,700 copies costs 2.7 µs per list, not ~19 µs (I had assumed ~4 ns per
clean_bitload; measured it is 0.57 ns, hot in cache), and the word-scan costs 1.2 µs over the 74 words the bits span, not ~0.3 µs. So the real delta is ~2.3x per list, not ~60x — the win is smaller than the body claims, and the body's "~19 µs → ~0.3 µs" should be disregarded.Measured standalone on this B580 (
rustc -O, 4,700 copies / 74 words / 12 dirty bits, 20,000 rounds, both runs):Same hits both ways (240,000 = 240,000), so the answer is identical; only the cost differs. At 200–900 lists a submission that is ~0.3–1.0 ms a frame, not the several ms the body implied. The change stays — it is the same answer for less work and the test pins the semantics — but it is a small win, and this comment supersedes the body's numbers. Synthetic benchmark only; no game data.
@borosf on GitHub · 2026-11-26 14:59 UTC · original
Fixed at
1c18e7052f0cfc6ab746df210418a8847a3d1403: you're right —clean_bit(None)is false (never clean), so untracked copies were always passed toadd, and myfilter_mapsilently dropped them.Layoutnow keeps those indices inuntrackedandprepareasks for them unconditionally before the word-scan;dirty_indicesalso returns before reading any word whenby_bitis empty. Test updated to pin the empty case. Clippy clean both feature sets; memory:: tests 8 passed / 1 failed (the knownlists_share_a_table...B580 baseline); rustfmt memory.rs 30/30 vs main. Synthetic tests only; no game data.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.