GPU: remember unmapped guarded view blocks instead of re-copying them every submission #464
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/464"
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 wbkepler on 2026-11-24T03:43:34Z.
Problem
Host copies of view memory (physical-page views; they cannot be write-watched) learn what the title wrote by guarding each 64 KiB block read-only once copied (
watch::guard). A block in the range that is not mapped (a placeholder between views of a big GPU heap) cannot be made read-only, so it never became clean. Every asking reported it written again, andcopy_stalecopied it again throughcopy_mapped's fallback: a failing 64 KiB kernel read, then 16 failing 4 KiB reads, then zeros. A world frame makes about 150 submissions, most of which refresh the same big heap, so the same unmapped blocks were re-copied each time.Measured with temporary timing around the fallback loop (diagnostics build, RTX 5090, world): 380–1020 ms per frame in the fallback path, 460–930 MB/frame "unmapped", ~2,200 fallbacks/frame. That was the largest cost in "preparing".
Change
crates/victory-gpu/src/watch.rsonly:Guardsgains anabsentset. Whenprotectfails on a block andVirtualQuerysays the block is not committed, the block is noted as absent.guardreports an absent block like a clean one: not written. The first asking after it went unmapped still reports it, so the copy takes its zeros once.title_memory_remappedclearsabsentfor its range. xmem already calls it after mapping a view and before unmapping one, so a block mapped later is reported (and copied) at the next asking.Soundness: view memory comes from placeholders, and only the runtime's mapping (which notifies) can fill those.
VirtualQueryruns only on a block whose protection change failed, so blocks we can guard never pay for it. Shortcut, noted in the module docs: if memory gets committed some other way into such a block (a range reaching from a view into a plain reservation), the copy won't see it.Measured
Same save, start screen to world, diagnostics build of
mainwith and without this change. One run each. The numbers are thecopystatlines of steady world windows, per frame:Example world lines:
1.5 fps, 683.5 ms/frame (406.5 preparing: copies 297.3 ms ...), 2030 draws/frame,500.34 MB unmapped; ... 2222.5 fallbacks1.4 fps, 700.1 ms/frame (350.2 preparing: copies 197.8 ms ...), 4532 draws/frame,27.06 MB unmapped; ... 286.5 fallbacks2.6 fps, 377.7 ms/frame (210.1 preparing: copies 103.4 ms ...), 2257 draws/frame,16.87 MB unmapped; ... 247.0 fallbacksWhat's left in preparing for follow-ups (not in this PR): the guard walk itself (one set lookup per block over the 174 MB heap for every asking, about 100–210 ms/frame), and page faults from write snapshots and copy-back.
Tests
watch::tests::unmapped_blocks_are_reported_once_until_mapped: a three-block placeholder with a section view in block 0. The first asking reports all three blocks. The next reports none. After block 1 is mapped andtitle_memory_remappedruns, only block 1 is reported.watch.rscleanly; it had two unformatted test statements before, and oneSAFETYcomment moved with them.cargo fmt --check(watch.rs),cargo clippy --workspace --all-targets,cargo clippy -p victory --features diagnostics --all-targets(no new warnings),cargo test --workspace, andcargo xtask policyall pass.🤖 Generated with Claude Code
Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T06:10:36Z.
Review: APPROVED
Tested
41af42eon Windows 11, RTX 5070, MSVC:cargo test --workspace --no-fail-fastpasses (265 passed, 0 failed), includingunmapped_blocks_are_reported_once_until_mapped, which really builds a placeholder withVirtualAlloc2andMapViewOfFile3. I could not measure the per-frame timings without a game package.VirtualQueryruns only afterVirtualProtectfailed on a block, so blocks that can be guarded pay nothing extra.State != MEM_COMMITmatches a placeholder (MEM_RESERVE).title_memory_remapped, which xmem calls on map and before unmap, clearsabsentwithprotected/clean, so a block mapped later is copied at the next asking. That matches the new test.No issues found.
AI-assisted (Claude Code).
Imported from Marvisak/VIctory. Originally posted by DaviTostes on 2026-11-24T03:46:11Z.
Verified
41af42eon Arch Linux x86_64, Windows MSVC release build under Wine 11.22 (victory-gpu,--test-threads=1): 44 passed, 0 failed, 1 ignored.Not covered: the runtime mapping/unmapping a guarded title block during submission (no game data, and this Wine prefix does not exercise the same page transitions).
Imported from Marvisak/VIctory. Originally posted by LocranKing on 2026-11-24T04:18:29Z.
Tested on Windows 11 + NVIDIA GeForce RTX 3060 Ti (8 GB, MSVC
1.98.1).Tested
41af42e(pr-464, clean tree)32.0.16.2101), Rust1.98.1(x86_64-pc-windows-msvc)cargo xtask policy:asset policy: 151 files okcargo test --workspace: 265 passed, 0 failed, 4 ignoreddiagbuild (VICTORY_D3D12_DRED=1) live boot/first-screen run (45 s) on RTX 3060 Ti:33.3–33.4 ms/frame(0.2 mspreparing,0.1 mscopies,5.8–8.3 mson the GPU,0.0 mscopying back),13draws/frame,0dropped (frame=1024:6656/6656draws,512/512dispatches).copystat(steady state):14.8–15.3submissions,69–71title copies (0.1 MB),74–76refreshes (62.5–64.6 MB),10watches (0.12–0.13 ms,13.1–13.5 MBchecked),0–1page faults,0.0fallbacks.crashes.logempty.Not tested: World streaming / world-load heap refreshes past the first screens, AMD GPUs.
AI use: Antigravity (
Gemini 4 Hydrogen) ran the checks and diagnostics run and drafted this report from the logs.Imported from Marvisak/VIctory. Originally posted by wbkepler on 2026-11-24T20:48:57Z.
Rebased onto current main (
ffe310e) as9dd1507; inwatch.rsthe remap range keeps main's overflow-safesaturating_addwhile also clearing the unmapped set, and both tests are kept. Gate clean.AI-assisted (Claude Code); checked on Windows 11 / RTX 5090.
Pull request closed