GPU: stop copying game memory to the card and back every frame (opt-in): 75% less copy-back, half the buffer uploads #772
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/772"
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 fxceless/victory-fork. Originally posted by sirrus98 on 2026-11-25T07:13:48Z.
Summary
Every frame, victory copies the game's GPU memory out of game RAM into host copies, uploads them to the card, hashes them, and after the card is done copies what shaders wrote back into game RAM. This PR stops most of that copying.
VICTORY_INPLACE=3). Each region of game memory the GPU can reach is opened once as a D3D12 heap over the game's own pages (OpenExistingHeapFromAddress1). Buffers and windows then point straight at the game's bytes: no copy, no refresh, no copy-back.VICTORY_INPLACE_POOL=1). The game's physical page pool is made of committed sections, opened the same way.VICTORY_INPLACE=4). Memory the card reads every frame (big buffers, windows in use for several frames) gets a copy in video memory. A GPU copy brings it up to date from game RAM before the frame's lists run. Afterwards, a GPU compute pass writes back only the bytes shaders changed, leaving any bytes the CPU wrote untouched. No CPU copy, hash or read-back is involved.Everything is opt-in. Without these switches nothing changes.
Results
Measured on an RTX 4090, release build, 120 s in the game world after a warm-up. Each column is one run of this branch with the switches shown;
mainis8dd30abwith the same measurement switches (VICTORY_CARD_TIME=1 VICTORY_INPLACE_PROBE=2).Per frame:
INPLACE=3INPLACE=3POOL=1INPLACE=4POOL=1With hot memory in VRAM, the card holds about 107 such copies (875 MB). Per frame, the GPU brings 21 MB up to date from game RAM, compares 556 MB and writes 39 MB back.
What this shows
main, identical runs on this machine vary by up to ±15% (a "D3D Background Thread" uses about 3.8 cores in every run,mainincluded), and these are single runs. On the previousmain(4e17478), with no such load, the full set ran at 234.6 ms against 240.1 ms with these switches off.Fixes and findings along the way
OpenExistingHeapFromFileMapping) keeps its commit until the PC restarts: 256 MB per test, every time. Sections are now opened through a view of their own, by address. The system's commit stays flat across runs.VICTORY_INPLACE_MIN_KB, 1024 by default). Card atomics into tiny buffers left in game RAM have to cross the bus each time. Three once-a-frame compute passes went from 1–6 ms to 19–67 ms of card time. With the floor, the game's command lists went from 222–244 ms back to 100–129 ms of card time.Switches
All off unless set.
VICTORY_INPLACE=3VICTORY_INPLACE=4VICTORY_INPLACE_POOL=1VICTORY_INPLACE_MIN_KBVICTORY_RESIDENT_*ONE_OWNER,PARTIAL,HOT_FRAMES,NO_MERGE, …)VICTORY_ARENA_EARLY=1,VICTORY_EARLY_SIGNAL=1VICTORY_CARD_TIME=1,VICTORY_INPLACE_PROBE=2,VICTORY_DRAW_PROBES=1,VICTORY_PROBE_PIPELINESvictory inplace-probeVerification
cargo check --workspace --all-targets --locked). The branch merges intomain(a26859f) without conflicts.cargo clippy --workspace --all-targets --locked -- -D warnings, with and without--all-features, reports only the warningsmainalready has (draw.rssort_unstable_by,indirect.rsdepth_written,resource.rsplaced_filler_twins). None is in this PR's code.cargo test --workspace --locked:victory-gpu: 165 passed, 10 ignored, run with--test-threads=1. In parallel, one existing in-place test fails now and then, because the tests share the process-wide table of the game's views. It passes alone and serially.victory-shader: 213 passed, 2 failed (emit::rect::tests::the_rectangle_stage_is_a_geometry_shader,rectangles_are_drawn_whole). Both fail the same way on plainmain; this PR doesn't touch that crate.main.main's CI fails at the Clippy step on its last commits (the three warnings above), and the twovictory-shadertests fail onmaintoo. This PR changes neither, so it stays focused.main, all without a device loss. Measured on8dd30ab, then rebased ontoa26859f(one upstream commit, descriptor records mirrored).Risks
VICTORY_INPLACE_MB(4096) and the in-place budget.ID3D12Device13and heap tier 2. Where opening is refused (for example Wine, or memory from victory's own heap), memory falls back to host copies, and the log line says why.Related work
Searched: every open and closed PR here and on upstream VIctory, plus GitHub code. None opens memory in place over committed ranges, keeps hot memory in VRAM, or writes back on the GPU. These overlap in part:
inplace.rs; happy to rebase on whichever lands first.VICTORY_INPLACE_POOLand the leak fix here.Reviewing
17 commits; best read one at a time:
🤖 Generated with Claude Code
Imported from fxceless/victory-fork. Originally posted by Kanthon1209 on 2026-11-25T07:16:30Z.
UP NB
Imported from fxceless/victory-fork. Originally posted by alpz1000 on 2026-11-25T17:40:15Z.
Independent Windows 11 build 26200 result on RTX 3060 12 GiB (610.88), i5-8400 and 32 GiB RAM. I integrated
70302bainto a local465b94f-based Series S build with the same display, range-lock and idle-cache changes in both runs. The shortinplace-probeconfirmed GPU reads and writes through the private allocation and section-backed views. I kept the 2 GiB Windows commit-headroom guard enabled.VICTORY_INPLACE=4 VICTORY_INPLACE_POOL=1 VICTORY_INPLACE_MB=2048 VICTORY_RESIDENT_MB=1024: the guard ended the launch after 188 s during loading. Near that point the arena census showed 1.42 GiB locked, and 24 residents used 121 MiB plus 121 MiB of comparison buffers.VICTORY_INPLACE_MB=1024 VICTORY_RESIDENT_MB=768: reached the same gameplay checkpoint. The arena held one 1 GiB section. After warm-up, the resident line showed seven buffers (12 MiB plus comparison buffers) and no resident merge work in the sampled steady intervals. A 240-frame window at roughly 4,500 draws averaged 5.21 FPS (P90 216 ms). The comparable local build without this PR averaged 4.92 FPS over 250 frames (P90 225 ms). There was one launch per setting, and the steady FPS difference is too small to attribute to resident work.The smaller budget let the run finish loading on this configuration. The low number of active residents in the steady checkpoint is the main difference from the 4090 results above. AI-assisted with OpenAI Codex.
Imported from fxceless/victory-fork. Originally posted by UwUCammie on 2026-11-26T00:52:40Z.
The bounded physical import test passed both directions on an RX 7900 XT with Wine 11.22 and RADV 26.3.1. In the 230-second title run, level 4 with the pool enabled imported 10,093 windows and had 9.99 GiB locked at the last report. It was still showing a white transition screen at the late check. I can’t assign a gameplay FPS to that run. The same executable with both options off reached the character and courtyard (356 accepted presents in 73.82 s, 4.82 FPS). No device removal was reported. GPU fixture · Build and measurement window
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.