GPU: a page's saved bytes are read into an unzeroed buffer #3262
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!3262
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3262"
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?
@Creaa on GitHub · 2026-11-26 14:54 UTC · original
Creaa:gpu/watch-save-unzeroed→main· +25 −3 · 2 files · 1 commits · openwatch.rsChanged::savekeeps a page's bytes from before its first write (the copy-back of marked pages compares against them). @borosf measured it at about 4.2 us a page in #1633 (a 64 KiB alloc, zeroing it, andReadProcessMemoryunder the lock); #3241 tried to avoid the read and was closed as unsound because the saved bytes must stay the pre-write bytes and the source may hold unmapped pages. This keeps both and drops the work that is not needed: the buffer is no longer zeroed before the kernel overwrites all of it.What is in it
crates/victory-gpu/src/watch.rs:Changed::savereads the page intoBox::<[u8]>::new_uninit_slice(PAGE)instead of a zeroedvec!, still under the tracker's lock (so the bytes belong to the arming it checked; an earlier version of this PR read outside the lock, and @AurumCarlos pointed out the page could be disarmed and armed again meanwhile). A read that fails keeps nothing (as before).crates/victory-gpu/src/host.rs:read_into_uninit,read_intofor a buffer not yet written (the sameReadProcessMemorycall).a_read_into_an_unwritten_buffer_fails_on_an_unreadable_source: the read fails on an unreadable source and, when it succeeds, writes every byte. The existingarmed_ranges_keep_their_pages_bytes_from_before_the_first_writecovers that the saved bytes are still the pre-write ones.Tested
main63bcca4.cargo test -q --locked -p victory-gpu --lib --no-fail-fast: 230 passed, 2 failed, 1 ignored. The 2 (dynamic_slots_are_held_until_released,lists_share_a_table_and_copies_keep_their_views) fail the same way onmainon this card (the capped view heap; #2461). Thewatchtests: 16 passed, also with--features diagnostics.descriptor::host::tests::a_slot_rewritten_while_its_view_is_prepared_views_the_new_record(not touched here); it passes 5 of 5 locally, so it was pushed again unchanged.cargo clippy --workspace --all-targets --locked -- -D warningsand with--all-features: clean.cargo xtask policy: 191 files ok.saveon each, 20 rounds, release: median 21.1-21.7 us a page before, 16.0-17.2 after (three runs each, the same pages; the lock is not contended there, so this is the zeroing). A breakdown on the same machine: allocation plusReadProcessMemoryplus free is about 3.4 us; most of what is left is the first touch of the fresh heap memory when many saved pages are alive at once, which a pool of returned buffers would remove (not in this PR: it needs the consumers inshadow.rsto hand the buffers back).Not tested
AI use
🤖 Generated with Claude Code
@Bj0rnis on GitHub · 2026-11-26 14:56 UTC · original
Verified head
30abde89on 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.97s) — 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.97s)-p victory-gpu --lib --tests --features diagnostics -- -D warnings): clean (0 warnings)cargo xtask policy: 191 files okNot tested: live title workload.
AI-assisted test run and summary.
@AurumCarlos on GitHub · 2026-11-26 15:08 UTC · original · reviewed
The uninit read is fine:
ReadProcessMemoryeither fails (nothing kept) or writes the whole page, and your test pins both.One question about dropping the lock: the re-check after the read only asks whether the page is armed and unsaved, not whether it's the same arming. If the page is disarmed and armed again by a new submission while the read is in flight (on the submitting thread, while a title thread is inside
save), the bytes read before the re-arm get kept as the new arming's "before" bytes. If the title wrote the page in between, copy-back would then treat those title writes as GPU writes. The window is a few µs, but an arming generation checked at insert (or recorded at the first check) would close it.Nit: the diff adds a blank line at the end of
watch.rs.@Dukestar69 on GitHub · 2026-11-26 15:10 UTC · original · approved these changes
Reviewed the diff and verified locally on Windows 11 x64:
Box::<[u8]>::new_uninit_slice(PAGE)viaread_into_uninit(callingassume_init()only afterreadconfirms alllenbytes were written) avoids 64 KiB zero-initialization and drops theSavedmutex during the kernel read while re-checkingarmed/contains_keybefore insertion.cargo test -p victory-gpu --lib watch:: -- --test-threads=1: 16 passed, 0 failed (includinga_read_into_an_unwritten_buffer_fails_on_an_unreadable_source).cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
30abde8941to7d5b8eb5c6@Creaa on GitHub · 2026-11-26 15:18 UTC · original
@AurumCarlos thanks, right: the re-check only proved "armed", not "the same arming", and a disarm + re-arm during the read would keep bytes from before the new arming. Fixed in
7d5b8eb(amended) the simple way: the read is back under the tracker's lock, so only the unzeroed buffer remains. In the same synthetic loop that is still most of the gain (median 16.0-17.2 us a page against 21.1-21.7 before), since the lock was not contended there. The trailing blank line is gone too.watchtests (16, also withdiagnostics) andvictory-gpuclippy (default and--all-features) pass.AI use: Claude Code (Claude Opus 5.5) made the change and drafted this reply.
7d5b8eb5c6to461cfc8ff7View 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.