GPU: stop copying game memory to the card and back every frame (opt-in): 75% less copy-back, half the buffer uploads #772

Open
sirrus98 wants to merge 18 commits from upstream-pr/772 into main
sirrus98 commented 2026-11-25 07:13:48 +00:00 (Migrated from github.com)

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.

  • Game memory opened in place (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.
  • Page pool opened in place (VICTORY_INPLACE_POOL=1). The game's physical page pool is made of committed sections, opened the same way.
  • Hot memory kept in VRAM (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.
  • Fallback. Memory that can't be opened stays a host copy, as today.

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; main is 8dd30ab with the same measurement switches (VICTORY_CARD_TIME=1 VICTORY_INPLACE_PROBE=2).

Per frame:

main in place + page pool + hot memory in VRAM
switches – INPLACE=3 INPLACE=3 POOL=1 INPLACE=4 POOL=1
buffers uploaded to the card 205.4 MB 197.3 MB 180.3 MB 96.4 MB (−53%)
copied back to game RAM 71.6 MB 75.5 MB 79.0 MB 18.1 MB (−75%)
time copying back 143.5 ms 153.4 ms 148.9 ms 62.8 ms (−56%)
CPU time copying buffers 59.5 ms 57.7 ms 42.5 ms 35.0 ms (−41%)
hash passes 257.9 255.7 252.7 165.4 (−36%)
textures uploaded 155.0 MB 145.3 MB 180.9 MB 185.7 MB (+20%)
frame median 395.4 ms 364.7 ms 296.4 ms 356.8 ms
frame p90 768.1 ms 557.5 ms 579.4 ms 617.3 ms
average fps 2.77 2.82 3.03 2.98

With 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

  • With all three parts on, copying falls sharply: half the buffer uploads, a quarter of the copy-back, and less than half the time spent copying back. These counters are stable from run to run.
  • Opening memory in place on its own changes little. It is what lets hot memory stay in VRAM.
  • Frame time: no gain is claimed. On current main, identical runs on this machine vary by up to ±15% (a "D3D Background Thread" uses about 3.8 cores in every run, main included), and these are single runs. On the previous main (4e17478), with no such load, the full set ran at 234.6 ms against 240.1 ms with these switches off.
  • Open issue: with the page pool, texture uploads grow by 17–20%. Not investigated yet.

Fixes and findings along the way

  • A commit-charge leak on NVIDIA. A section opened as a heap by its handle (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.
  • Small buffers stay host copies (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.
  • One VRAM copy per range of game memory. Overlapping copies are joined into one, and old ones are let go. This cut re-uploads from 199 to 24 MB a frame.
  • Write-back by store width. Where shaders only write whole dwords, the write-back stores whole dwords instead of atomics. Card time for the write-back fell from 165 to about 10 ms.

Switches

All off unless set.

switch what it does
VICTORY_INPLACE=3 game memory opened in place
VICTORY_INPLACE=4 the same, plus hot memory kept in VRAM
VICTORY_INPLACE_POOL=1 the page pool opened in place
VICTORY_INPLACE_MIN_KB buffers smaller than this stay host copies (default 1024; 0 = no floor)
VICTORY_RESIDENT_* tuning and measuring the VRAM copies (ONE_OWNER, PARTIAL, HOT_FRAMES, NO_MERGE, …)
VICTORY_ARENA_EARLY=1, VICTORY_EARLY_SIGNAL=1 experimental; not shown to help, keep off
VICTORY_CARD_TIME=1, VICTORY_INPLACE_PROBE=2, VICTORY_DRAW_PROBES=1, VICTORY_PROBE_PIPELINES measurement only
victory inplace-probe runs the device checks on their own

Verification

  • Every commit builds (cargo check --workspace --all-targets --locked). The branch merges into main (a26859f) without conflicts.
  • cargo clippy --workspace --all-targets --locked -- -D warnings, with and without --all-features, reports only the warnings main already has (draw.rs sort_unstable_by, indirect.rs depth_written, resource.rs placed_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 plain main; this PR doesn't touch that crate.
    • The other 20 test suites pass.
  • CI will fail here, as it does on main. main's CI fails at the Clippy step on its last commits (the three warnings above), and the two victory-shader tests fail on main too. This PR changes neither, so it stays focused.
  • Four game runs of this branch and one of main, all without a device loss. Measured on 8dd30ab, then rebased onto a26859f (one upstream commit, descriptor records mirrored).

Risks

  • Locked memory. Opening memory in place locks those pages into RAM, untouched ones included. This is bounded by VICTORY_INPLACE_MB (4096) and the in-place budget.
  • Platform. The path needs ID3D12Device13 and 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.
  • Tested on NVIDIA only (RTX 4090).

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:

  • #358 (open) fixes the existing in-place path (aligned spans, a CAS budget) and turns in-place memory off while late wait or the relay is on. This PR goes the other way: shader writes to memory in place are declared to the in-flight submissions, so in place works with late wait and the relay. The two conflict in inplace.rs; happy to rebase on whichever lands first.
  • #651 (closed, not merged) also declared these writes for late wait. This PR does the same, independently.
  • victory-chapter-ii (a separate repository, not a PR here) independently opens committed pool sections through a view by address, after the same commit leak, seen there on AMD. It's the same idea as VICTORY_INPLACE_POOL and the leak fix here.
  • Upstream Marvisak/VIctory#2112 (loose windows in place) and #2130 (written buffers in video memory) aim the same way with other mechanisms. The design threads are upstream #407, #880 and #1147.

Reviewing

17 commits; best read one at a time:

  • The first 8 open game memory in place: device checks, opening in place, the page pool, the leak fix, the small-buffer floor.
  • The last 9 keep hot memory in VRAM: VRAM copies, joining overlaps, the GPU write-back, card-time and draw-time measurements.

🤖 Generated with Claude Code

<!-- greyfinch-sync:fxceless/victory-fork:issue:6599275169 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/772). Originally posted by [sirrus98](https://github.com/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. - **Game memory opened in place** (`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. - **Page pool opened in place** (`VICTORY_INPLACE_POOL=1`). The game's physical page pool is made of committed sections, opened the same way. - **Hot memory kept in VRAM** (`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. - **Fallback.** Memory that can't be opened stays a host copy, as today. **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; `main` is `8dd30ab` with the same measurement switches (`VICTORY_CARD_TIME=1 VICTORY_INPLACE_PROBE=2`). Per frame: | | main | in place | + page pool | **+ hot memory in VRAM** | |---|---|---|---|---| | switches | – | `INPLACE=3` | `INPLACE=3` `POOL=1` | **`INPLACE=4` `POOL=1`** | | buffers uploaded to the card | 205.4 MB | 197.3 MB | 180.3 MB | **96.4 MB (−53%)** | | copied back to game RAM | 71.6 MB | 75.5 MB | 79.0 MB | **18.1 MB (−75%)** | | time copying back | 143.5 ms | 153.4 ms | 148.9 ms | **62.8 ms (−56%)** | | CPU time copying buffers | 59.5 ms | 57.7 ms | 42.5 ms | **35.0 ms (−41%)** | | hash passes | 257.9 | 255.7 | 252.7 | **165.4 (−36%)** | | textures uploaded | 155.0 MB | 145.3 MB | 180.9 MB | 185.7 MB (+20%) | | frame median | 395.4 ms | 364.7 ms | 296.4 ms | 356.8 ms | | frame p90 | 768.1 ms | 557.5 ms | 579.4 ms | 617.3 ms | | average fps | 2.77 | 2.82 | 3.03 | 2.98 | With 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** - With all three parts on, copying falls sharply: half the buffer uploads, a quarter of the copy-back, and less than half the time spent copying back. These counters are stable from run to run. - Opening memory in place on its own changes little. It is what lets hot memory stay in VRAM. - **Frame time:** no gain is claimed. On current `main`, identical runs on this machine vary by up to ±15% (a "D3D Background Thread" uses about 3.8 cores in every run, `main` included), and these are single runs. On the previous `main` (`4e17478`), with no such load, the full set ran at 234.6 ms against 240.1 ms with these switches off. - **Open issue:** with the page pool, texture uploads grow by 17–20%. Not investigated yet. ## Fixes and findings along the way - **A commit-charge leak on NVIDIA.** A section opened as a heap by its handle (`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. - **Small buffers stay host copies** (`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. - **One VRAM copy per range of game memory.** Overlapping copies are joined into one, and old ones are let go. This cut re-uploads from 199 to 24 MB a frame. - **Write-back by store width.** Where shaders only write whole dwords, the write-back stores whole dwords instead of atomics. Card time for the write-back fell from 165 to about 10 ms. ## Switches All off unless set. | switch | what it does | |---|---| | `VICTORY_INPLACE=3` | game memory opened in place | | `VICTORY_INPLACE=4` | the same, plus hot memory kept in VRAM | | `VICTORY_INPLACE_POOL=1` | the page pool opened in place | | `VICTORY_INPLACE_MIN_KB` | buffers smaller than this stay host copies (default 1024; 0 = no floor) | | `VICTORY_RESIDENT_*` | tuning and measuring the VRAM copies (`ONE_OWNER`, `PARTIAL`, `HOT_FRAMES`, `NO_MERGE`, …) | | `VICTORY_ARENA_EARLY=1`, `VICTORY_EARLY_SIGNAL=1` | experimental; not shown to help, keep off | | `VICTORY_CARD_TIME=1`, `VICTORY_INPLACE_PROBE=2`, `VICTORY_DRAW_PROBES=1`, `VICTORY_PROBE_PIPELINES` | measurement only | | `victory inplace-probe` | runs the device checks on their own | ## Verification - Every commit builds (`cargo check --workspace --all-targets --locked`). The branch merges into `main` (`a26859f`) without conflicts. - `cargo clippy --workspace --all-targets --locked -- -D warnings`, with and without `--all-features`, reports only the warnings `main` already has (`draw.rs` `sort_unstable_by`, `indirect.rs` `depth_written`, `resource.rs` `placed_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 plain `main`; this PR doesn't touch that crate. - The other 20 test suites pass. - **CI will fail here, as it does on `main`.** `main`'s CI fails at the Clippy step on its last commits (the three warnings above), and the two `victory-shader` tests fail on `main` too. This PR changes neither, so it stays focused. - Four game runs of this branch and one of `main`, all without a device loss. Measured on `8dd30ab`, then rebased onto `a26859f` (one upstream commit, descriptor records mirrored). ## Risks - **Locked memory.** Opening memory in place locks those pages into RAM, untouched ones included. This is bounded by `VICTORY_INPLACE_MB` (4096) and the in-place budget. - **Platform.** The path needs `ID3D12Device13` and 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. - **Tested on NVIDIA only** (RTX 4090). ## 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: - **#358** (open) fixes the existing in-place path (aligned spans, a CAS budget) and turns in-place memory off while late wait or the relay is on. This PR goes the other way: shader writes to memory in place are declared to the in-flight submissions, so in place works with late wait and the relay. The two conflict in `inplace.rs`; happy to rebase on whichever lands first. - **#651** (closed, not merged) also declared these writes for late wait. This PR does the same, independently. - **victory-chapter-ii** (a separate repository, not a PR here) independently opens committed pool sections through a view by address, after the same commit leak, seen there on AMD. It's the same idea as `VICTORY_INPLACE_POOL` and the leak fix here. - Upstream **Marvisak/VIctory#2112** (loose windows in place) and **#2130** (written buffers in video memory) aim the same way with other mechanisms. The design threads are upstream #407, #880 and #1147. ## Reviewing 17 commits; best read one at a time: - The first 8 open game memory in place: device checks, opening in place, the page pool, the leak fix, the small-buffer floor. - The last 9 keep hot memory in VRAM: VRAM copies, joining overlaps, the GPU write-back, card-time and draw-time measurements. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Kanthon1209 commented 2026-11-25 08:08:58 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by Kanthon1209 on 2026-11-25T07:16:30Z.


UP NB

<!-- greyfinch-sync:fxceless/victory-fork:comment:7155679966 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/772#issuecomment-7155679966). Originally posted by [Kanthon1209](https://github.com/Kanthon1209) on 2026-11-25T07:16:30Z. --- UP NB
alpz1000 commented 2026-11-25 18:05:13 +00:00 (Migrated from github.com)

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 70302ba into a local 465b94f-based Series S build with the same display, range-lock and idle-cache changes in both runs. The short inplace-probe confirmed 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.
  • Same options with 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.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7169833519 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/772#issuecomment-7169833519). Originally posted by [alpz1000](https://github.com/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 `70302ba` into a local `465b94f`-based Series S build with the same display, range-lock and idle-cache changes in both runs. The short `inplace-probe` confirmed 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. - Same options with `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.
UwUCammie commented 2026-11-26 01:06:17 +00:00 (Migrated from github.com)

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

<!-- greyfinch-sync:fxceless/victory-fork:comment:7179203411 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/772#issuecomment-7179203411). Originally posted by [UwUCammie](https://github.com/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](https://github.com/sirrus98/victory-fork/pull/1) · [Build and measurement window](https://github.com/UwUCammie/victory-amd/blob/f07b535/benchmarks/README.md#in-place-title-memory-on-radv)
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/772:upstream-pr/772'
git switch 'upstream-pr/772'

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.

git switch 'main'
git merge --no-ff 'upstream-pr/772'
git switch 'upstream-pr/772'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/772'
git switch 'upstream-pr/772'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/772'
git switch 'main'
git merge --squash 'upstream-pr/772'
git switch 'main'
git merge --ff-only 'upstream-pr/772'
git switch 'main'
git merge 'upstream-pr/772'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
fxceless/victory-fork!772
No description provided.