GPU: a page's saved bytes are read into an unzeroed buffer #3260
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/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?
Imported from Marvisak/VIctory. Originally posted by Creaa on 2026-11-26T14:54:14Z.
watch.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
Imported from Marvisak/VIctory. Originally posted by Bj0rnis on 2026-11-26T14:56:59Z.
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.
Imported from Marvisak/VIctory. Originally posted by AurumCarlos on 2026-11-26T15:08:40Z.
Review: COMMENTED
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.Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T15:10:24Z.
Review: APPROVED
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).
Imported from Marvisak/VIctory. Originally posted by Creaa on 2026-11-26T15:18:10Z.
@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.
Imported from Marvisak/VIctory. Originally posted by neonbyte1 on 2026-11-27T14:26:00Z.
Tested in game together with #3215 (both merged cleanly) on an RTX 5090 (driver 620.73.04), Linux, GE-Proton11-14 Wine with its vkd3d-proton, GTA VI's opening prison yard, on
mainplus the unmerged PRs this setup needs (listed in #3425). 420 s runs, medians of the last 30 frame-rate lines, against three adjacent controls of the same base:No measurable change in frame or preparing time here: whatever the two save is below our run-to-run spread (a few ms). No crash, same pictures. Not a reason against either; the work they remove is real, just small on this scene.
AI-assisted (Claude); measured on my machine, no game data shared.
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.