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

Open
github-bot wants to merge 18 commits from github-bot/gh-772 into main AGit
Owner

@⁠sirrus98 on GitHub · 2026-11-25 07:13 UTC · original
sirrus98:perf/tier3-stage2 → main · +6944 −143 · 18 files · 18 commits · open

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

**@⁠sirrus98** on GitHub · 2026-11-25 07:13 UTC · [original](https://github.com/fxceless/victory-fork/pull/772) `sirrus98:perf/tier3-stage2` → `main` · +6944 −143 · 18 files · 18 commits · open ## 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)
The tier-3 design (title memory as the GPU's own, one opened heap per
region) rests on driver limits nobody had measured on the card. This adds
the design's probes (inplace_probes.rs), run on a queue and memory of
their own, and a way to run them without the title:

  victory inplace-probe [--small] [--tiles] [--debug-layer] [--mb N]

and `cargo test -p victory-gpu -- --ignored probe_on_hardware`. In game,
VICTORY_INPLACE_PROBE=1 adds the small ones (P2-P6, R9) to the first probe,
now on a thread of its own; =3 also the ones that lock or commit gigabytes
(P1, P2's 4 GiB part, P7).

Measured on the RTX 4090 (debug layer on, no errors except where said):
- P1: 40 bits of GPU VA per resource and per process. Parts of 2 GiB,
  4095 MiB and 4 GiB - 64 KiB open (343/684/672 ms) with a buffer over
  all of it, written at its far end by copy and shader. 4 GiB and 6 GiB
  are refused by the runtime ("must point to a memory region that is 4GiB
  or less"). Committed sections of 2 GiB and 4095 MiB open (89/177 ms);
  6 GiB is refused ("hFileMapping must be 4GiB or less").
- P2: opening private memory locks it: 1 GiB 173 ms +1,024 MB working set,
  4095 MiB 695 ms +4,096 MB; no commit added; the heap goes in 16/68 ms. A
  committed section's pages count in the working set when opened (no
  more when the GPU reads them).
- P3: InterlockedOr/And from a compute shader into a part and a section
  are exact, a byte replaced by And+Or keeps the dword's other bytes, and
  a CPU writing byte 0 of the same dwords all along keeps its last byte
  (32 of 32) while the GPU's bits all land.
- P4: with a part opened, write watching still reports CPU writes
  exactly ([1, 5, 9] -> [1, 5, 9]) and reports none of the GPU's (copy and
  shader: []).
- P5: 512 parts of 64 KiB with a buffer each: 93 ms, none refused, gone in
  41 ms. Two overlapping parts: written through one, UAV barrier, read
  through the other in one list: right, and the CPU sees it.
- P6: a buffer in an opened heap works as vertex and index views, root
  CBV, typed SRV and raw UAV in a table, ExecuteIndirect arguments and
  count, CopyTextureRegion both ways, ResolveQueryData. One buffer used as
  copy source then destination in one list needs an explicit transition
  (implicit promotion is once per list: risk R8).
- P7: commit headroom 63,990 MB; a 6 GiB SEC_RESERVE section adds 0 MB,
  SEC_COMMIT adds 6,156 MB (whole or as six 1 GiB sections, both made at
  once); a 6 GiB section cannot be opened as one heap.
- R9: on pages of an opened part VirtualProtect read-only, MEM_DECOMMIT and
  MEM_RELEASE fail with error 87, also while only a buffer placed in the
  heap is alive; MEM_RESET and an unchanged protection succeed.
- tiles (--tiles, a device of its own): a reserved buffer's tile mapped
  onto a heap in the card's memory works; mapped into an opened heap the
  runtime removes the device (0x887a0001), as on the software adapter.

R9 (count only): with VICTORY_INPLACE_PROBE, VICTORY_INPLACE or
VICTORY_MEMORY_CALLS=1 the title's kernel32 VirtualFree, VirtualProtect
and VirtualAlloc(MEM_RESET) go through wrappers in xmem.rs that call the
host's functions unchanged and count (and log, first 16 and every power
of two) the calls that touch memory XMemVirtualAlloc reserved. Without the
switches the imports go to the host as before.

Tests: victory-gpu 111 passed, 2 ignored (probe_on_hardware, and the one
ignored before); victory-hle 96 passed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SZC5U8SHMXUK5wS4AS2KxT
The two bugs of the tier-3 design (§11), both only with VICTORY_INPLACE.

1. memory.rs (raw-address directory of the BVH builder) wrote each page's
   offset from the title memory's first byte and gave each numbered copy a
   view of `len` bytes from the buffer's start. A copy in place is a
   buffer that begins on the 64 KiB line below the title memory (or, with
   arenas, at the arena's base): every raw access was `bias` bytes off and
   the last `bias` bytes were cut off. The offset is now
   `Shadow::offset(page)` and the view `offset(start) + len` bytes
   (entry_offset, view_bytes).

2. Shader writes to memory in place were not declared at all
   (`Shadow::gpu_writes` returned early), so late wait and the relay could
   let a CPU read of that memory (a title buffer copy, a fill, a texture,
   a step of ours, a value wait) run before the flight that writes it.
   The range is now declared like a copy's; `declared_writes` leaves it
   out of the copy-back (nothing to copy back), and the new
   `in_place_writes` puts it in the flight (`Sent`/`Flight::in_place`) and
   in the line's `written`, which `late_blocked`, `relay_wait`'s
   `blocked_by` and `late_met` read, and which a landing recomputes from
   the flights still in the air.

With this VICTORY_INPLACE=2 (and the coming 3) may be combined with
VICTORY_LATE_WAIT / VICTORY_RELAY: they hold back reads of in-place
writes exactly as of copies' declared ranges, under the same assumption
(shaders write only what is declared) and the same shortcut (another host
copy of the same bytes is not told). The doc's "do not combine" is
replaced by that. Behaviour without VICTORY_INPLACE is unchanged (no copy
is in place, so no range takes the new path).

Tests (software adapter): memory::tests::
warp_raw_addresses_into_memory_in_place_take_the_bias (the directory
offset reads the page's own bytes, the view reaches the last byte);
host::in_place_tests::warp_in_place_writes_reach_the_flights (in-place
ranges come out of a submission's steps joined, a copy's do not).
victory-gpu: 113 passed, 2 ignored.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SZC5U8SHMXUK5wS4AS2KxT
Stage 1 of the tier-3 design. Levels 1 and 2 open a heap of their own per
window or title buffer (`place_part`); level 3 opens one heap per region
the GPU reaches, an arena, with one buffer placed over all of it, and
every title buffer and window in it is that buffer at an offset
(`inplace::place_for` now returns a view: bias = start - arena base).

arena.rs:
- Parts of private title memory: only memory XMemVirtualAlloc committed
  (xmem reports it, `title_memory_committed`; nothing else, the Rust heap
  included, is ever opened). The runtime refuses a part of 4 GiB or more
  on the card (probe P1), so parts are at most 4 GiB - 64 KiB and a bigger
  region has overlapping parts every 2 GiB (P5: overlap works); a range
  takes the lowest part that holds it whole. Opened on first GPU use: at
  once up to VICTORY_ARENA_SYNC_MB (64, ~11 ms), else on a thread of its
  own (P2: 1 GiB locks in 173 ms), copies until then; a title buffer
  copied before its arena opened is let go at the next sweep when nothing
  holds it (`in_place_upgrade`), so the next ask finds it in place.
- Sections of the physical page pool made committed: view memory that is
  one run of one section is in place in the section's arena (the heap is
  the section; views come and go under it). Windows over view memory are
  the run around the ask (`inplace::run_window`): the census found 1,948
  MB of 4 MiB windows over views with unmapped pages, and the GPU never
  reads a view through a tile mapping (into an opened heap that removes
  the device: probe "tiles", on the card too).
- `resolve(addr, len)` gives resource, offset, GPU address, bytes left
  and kind (InPlace, Section). Budget: VICTORY_INPLACE_MB, by default a
  quarter of the PC's memory (opening locks pages: on this 96 GB PC 24
  GiB), scaled from the queried RAM.
- Free/protect (R9): the runtime's wrappers of the title's VirtualFree,
  VirtualProtect (other than read-write) and xmem's own release of 32-bit
  memory call `title_memory_released` first: the parts over the range are
  retired and what is in place in all of them let go, so the pages are no
  longer locked unless a list still holds the arena's buffer.
- Big buffers keep their copies in the card's memory
  (VICTORY_CARD_BUFFERS_*), as at level 2.

xmem.rs, VICTORY_INPLACE_POOL=1: the page pool is made of SEC_COMMIT
sections of VICTORY_POOL_SECTION_MB (1024; at most 4095: P1/P7 refuse a 6
GiB section as a heap) while the commit has room for the pool and 4 GiB
more (else reserved, as before, with a warning); `commit` does nothing for
a committed section; pages are slices of their chunk's section (`runs` and
mapping already break at sections). A closed section retires its arena.
Off, one reserved section as before.

The in-place line every ten seconds gains an arenas line: parts and
sections open, GiB locked against the budget, opened/refused/retired,
ranges resolved, MB of private and view memory placed in them.

Tests: arena::tests (parts of a region and the lowest that holds a range;
on the software adapter two title buffers resolve into one arena and the
GPU reads and writes their bytes there, retiring unlocks the pages; a run
of a committed section resolves at its section offset and the GPU's
write shows through the view), inplace::tests::
a_window_over_views_is_the_run_around_the_ask, and arena_on_hardware
(ignored; passes on the RTX 4090). victory-gpu 117 passed, 3 ignored;
victory-hle 96 passed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SZC5U8SHMXUK5wS4AS2KxT
In run inplace3-t3 (VICTORY_INPLACE=3) no part ever opened: the title
commits its 3.4 GB private region at 0xd00000000 in steps, with holes and
pages of other protections, and the arena asked for one part over the
whole region ("not private memory committed whole and read-write"); that
one refusal then turned down every range of the region. The pool run
(inplace3-pool-t3) worked: 8 sections open, 6.78 GiB locked, 6,011
windows (575 MB) and 80 title buffers in place, 2,018 MB of view memory
placed, median frame 233.8 ms against 285.5 ms for its control (-18%).

Parts come from runs of committed pages. `runs_of` asks Windows for the
runs of committed read-write private pages of a reported region, one
VirtualQuery per run. The runs are asked when first needed, and again
when the region changes or an opening finds the pages changed. A range is
in place when it lies in one run. Its part is the lowest of the run's
parts on the 2 GiB grid from the run's start (`grid_part`, at most
4 GiB - 64 KiB). An open part that holds the range is always taken
first. So when the title commits more and two runs join, ranges over the
join open a new, longer part beside the older ones, which stay for what
was placed in them until it is let go. A refusal is kept per part, not
per region, and a part refused because its pages changed is not kept at
all. The title's own kernel32 VirtualAlloc(MEM_COMMIT) in memory that
XMemVirtualAlloc reserved is reported too (xmem's wrapper).

Remaps. The pool run let 9,755 in-place windows go in three minutes
because the title remapped their pages. A placement in a section's arena
is now only marked when its pages are remapped. When it is next asked
for, it stays if its range is still the same run of the same section at
the same offset (`still_good`, `inplace::still_run`); otherwise it is let
go and placed again. Both outcomes are counted on the arenas line
(REMAPS: kept / placed again). Placements in private parts, and the
title's own frees and protects, still let go at once.

Why a range is turned down is now counted by kind (arena::Why):
- view memory not one run of a committed section;
- not memory the runtime reported committed;
- spans pages not committed;
- spans another protection;
- longer than a part of its run;
- over the budget;
- refused by the host;
- its arena still being opened.
The counts are given on the arenas line, so the census can be checked
against what placement does.

Off path: `host::in_place_writes` returns before any pass when
VICTORY_INPLACE is off, a closed section tells the arenas nothing below
level 3, and xmem's release of 32-bit memory asks nothing (no lock, no
VirtualQuery) unless the wrappers' switches are on. Everything else was
already behind a switch read once.

Tests:
- arena::tests::a_range_takes_the_lowest_part_of_its_run_that_holds_it
  (the grid; regions joined and cut).
- arena::tests::warp_runs_of_committed_pages_are_parts_of_their_own. A
  reservation is committed in two runs with a hole: a buffer in either run
  is placed in its run's part, and one over the hole is turned down. After
  the hole is committed and reported, a range over it gets a part of the
  joined run beside the older two. A range over a read-only page is turned
  down as another protection. The GPU reads the title's bytes through
  each part.
- shadow::remap_tests::warp_a_placement_in_a_section_outlives_a_remapping_
  to_the_same_pages.
- arena_on_hardware passes on the RTX 4090.
victory-gpu 119 passed, 3 ignored; victory-hle 96 passed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SZC5U8SHMXUK5wS4AS2KxT
A part or section bigger than VICTORY_ARENA_SYNC_MB is opened on the
arenas' thread. That thread read the bytes locked, opened the heap outside
the arenas' lock, and added the bytes only once it was open. So while a
4 GiB part was opening (695 ms on the card, probe P2), a second ask could
pass the same budget test, and both could be opened: VICTORY_INPLACE_MB
was not a bound. The same check-then-act class is open in fork PR #358's
place_for; it must not exist here.

Now the bytes are taken from the budget when the thread is asked
(Arenas::reserve, under the arenas' lock), and the slot remembers them
(Slot::Opening(bytes)):
- opened: they stay with the open part;
- refused by the host, or no host: given back when the thread lands it;
- retired (title_memory_released) or the section closed while it opens:
  given back then, and what the thread opens afterwards stays closed;
- over the budget at the ask: refused at once, and the refusal is kept,
  as a refusal by the thread was before.
Openings on the asking thread take the budget the same way, under the
same lock as before. The open functions no longer test the budget; their
callers do.

Arenas::committed now uses checked ends: a range reported at the top of
the address space is ignored instead of wrapping.

Tests: victory-gpu 120 passed, 3 ignored (was 119);
victory-hle 96 + 1 passed.
- arena::tests::warp_a_part_asked_of_the_thread_holds_its_budget (new).
  A second ask while the first part opens is refused for the budget. The
  thread's refusal gives the bytes back. A part retired while opening gives
  them back, and its late result stays closed. A part the thread opened
  keeps them, and resolves.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SZC5U8SHMXUK5wS4AS2KxT
In run inplace3-pool the private arenas opened (2 parts, 3.29 GiB
locked, 287 MB placed), but 1,320 placements were turned down "its arena
still being opened": a part is opened at its first GPU use, and a part of
2.2 GB takes about 365 ms to open on the arenas' thread. Meanwhile every
buffer in it gets a copy, and keeps it.

With the switch (off by default; with arenas, VICTORY_INPLACE=3 or more),
a commit of graphics memory the runtime reports (title_memory_committed)
is asked of the arenas' thread at once (Arenas::ask_early), so its part is
usually open before the GPU first uses it:
- the parts are cut from the commit itself, every 2 GiB from its start
  and up to 4 GiB - 64 KiB each, as a run is cut (grid_part), so commits
  made in steps never open parts over each other; a range over two
  commits gets the part of its run at its first use, as before;
- commits of VICTORY_ARENA_SYNC_MB (64) or less are left to their first
  use, which opens them on the asking thread (about 11 ms);
- the budget (VICTORY_INPLACE_MB) is held from the ask on; over it,
  nothing is asked and the first use decides, as before;
- commits reported before the host is up wait for the first range
  resolved (the host is not made for them);
- a range in a part asked early that is still opening is turned down as
  opening, and residents wait for it (resolve_waiting), instead of asking
  for a second, overlapping part of the same run;
- title_memory_released waits (five seconds at most) for a part asked
  early over the range that is still opening: while it opens its pages
  are locked, and the title's decommit or protect would fail (R9).
Without the switch nothing is asked early, the set of parts asked early
stays empty, and resolving and releasing are as before.

Each ask is logged:
"arena: committed graphics memory asked of the arenas' thread as the
runtime reported it (VICTORY_ARENA_EARLY=1)" start=.. mb=..
followed by the opening line as before. The effect shows in the existing
turned-down counts ("its arena still being opened").

Tests: victory-gpu 130 passed, 4 ignored (was 129); victory-hle 96 + 1.
- arena::tests::a_commit_asked_early_is_opened_in_parts_of_its_own (new):
  a 5 GiB commit is asked as two parts (0, 4 GiB - 64 KiB) and (2 GiB,
  3 GiB) with their bytes held; a range held already, a small commit and
  one over the budget are not asked; a range in an opening part is turned
  down as opening without a new ask; a release over it sees it; landed or
  released, it is no longer waited for and its bytes are given back.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SZC5U8SHMXUK5wS4AS2KxT
On the card's driver a section opened as a heap by its handle
(OpenExistingHeapFromFileMapping) keeps its commit until the PC restarts,
whether it is released in order or not: 256 MB kept in every case in
inplace::tests::section_heap_commit_comes_back (ignored; it runs on the
card). Opened through the address of a view of it
(OpenExistingHeapFromAddress1), none is kept. Every run with
VICTORY_INPLACE_POOL=1 left the pool's commit behind; after a few runs the
system's commit limit was reached.

An arena over a section now maps a view of the whole section of its own
(arena::SectionView) and opens the heap on it: an offset in the heap is the
offset in the section, and the title's views come and go over the same
pages as before. The view stays mapped while anything holds the heap
(arena::Heap holds both), and is unmapped 10 s after the last holder lets
go: a submission still in the air may hold the arena's buffer alone.

Opening by the handle stays possible for the probes with
VICTORY_ALLOW_SECTION_HEAPS=1; the probe line says why it is refused
otherwise.

Measured: the system's shared commit stays flat across runs (21.3 ->
21.4 GB after several runs with the pool), where it grew by the pool's
size every run before.

Tests: arena::tests::section_arena_on_hardware (ignored, on the card:
the commit comes back), warp_a_run_of_a_committed_section_is_in_place
through the same path.
With VICTORY_INPLACE=4 three compute passes that run once a frame took
1-6 ms of card time in the control and 19-67 ms with Tier 3 (timing runs
with VICTORY_GPU_TIMING; 5cf00dc3 3.3 -> 67 ms, cb6adcc6 5.6 -> 41.6 ms,
0a5ecfee 1.2 -> 19 ms). Their code is the same; what changed is where
they write: their buffer atomics go to tiny buffers (52 B, 480 B, 56 KB)
that were copies in system memory in the control and in place, in the
title's memory, with Tier 3. Shaders reach memory in place across the bus.

Title buffers smaller than VICTORY_INPLACE_MIN_KB (1024 by default, 0 for
no floor) now stay copies, as without VICTORY_INPLACE. Windows are not
affected. Such buffers are 42 MB in all (3,376 of them, 3,242 under
64 KiB), so copying them costs little.

Measured (RTX 4090, release, the same exe, the switches equal but this
one; inplace4 with VICTORY_CARD_TIME=1, 120 s after the world):

                          floor off    floor 1024 KiB   control (Tier 3 off)
  frame median            495.0 ms     234.6 ms         240.1 ms
  average fps             1.69         4.30             4.33
  title lists, card time  222-244 ms   100-129 ms       ~111-115 ms

The frame-rate line gets a placement census: title buffers and windows
apart, count and MB in a resident, in place (and of those under 64 KiB),
card copy and system copy; and the buffers the floor kept as copies.

Tests: inplace::min_tests (the default, 0 and bad settings).
Stage 1's pool run (VICTORY_INPLACE=3 VICTORY_INPLACE_POOL=1, per layer,
against its control) took the median frame from 285.5 to 233.8 ms. The
largest layers left are the copies of the big title buffers in the card's
memory (VICTORY_CARD_BUFFERS_MIN_MB=1, _MB=4096):
- the relay's copy-back, 115-127 ms a frame;
- 136-150 MB a frame still going up through staging in the PC's memory;
- 70 MB a frame fetched back;
- the copy engine at 0%.
Reading those buffers in place over the bus instead raised the GPU wait
from 81 to 103 ms: hot data belongs in the card's memory.

New crate::resident (design section 4). A title buffer that would get a
card copy, whose 64 KiB pages lie in an arena (a private part, or a run of
a committed section), becomes a resident:
- R, a buffer in the card's memory that shaders read and write;
- B, its twin.
The Shadow is R at a bias, as a placement is the arena's buffer at a bias,
so every binding path works unchanged.

Per submission, on the one host queue, each in an ExecuteCommandLists of
its own:
1. Upload. The pages the title wrote since they last went up (write
   watching or the guards, at the submission's refreshes:
   Resident::refresh) are copied arena -> R, then R -> B, whole pages.
   There is no CPU copy, no staging and no hash. A page the title wrote
   always goes up: no range is held back because a flight may write it
   (the #1322 class). Whole pages are safe: every earlier submission's
   merge has run on the queue when the copy runs.
2. The title's lists, and the card compare for copies that remain.
3. Merge (resident::MERGE), over the joined ranges the submission
   declared written. It compares R with B per dword. A dword that differs
   goes into the arena and into B: a plain store if all four bytes differ,
   else InterlockedAnd + InterlockedOr on the changed bytes, so the CPU's
   bytes of the same dword survive (probe P3).
Then the host fence is signalled as before. Title fences, events and
bottom-of-pipe writes still go out when the relay lands the flight; for a
resident it has nothing to fetch, compare or merge.

Removed for residents: the relay's fetch, card_merge(_relay), card_back,
snapshots and CARD_COMPARE hashing. They are not carded, and are left out
of declared_writes.

Their shader writes are still declared to the flights
(in_place_writes -> Line::written). So late wait and the relay hold back a
CPU read of them (a title buffer copy, a fill, a texture, a value wait)
until the flight has run. In-place memory and residents work with
VICTORY_LATE_WAIT / VICTORY_RELAY for that reason: their writes are
declared, as copies' are (f5725f4), instead of being kept away from late
waits.

Ordering (risk R8): no resource is a copy source and destination in one
list without an explicit transition. R goes COMMON -> COPY_DEST ->
COPY_SOURCE in the upload. The arena's buffer is only a copy source there,
and only unordered access in the merge. Separate ExecuteCommandLists make
buffers decay to common and flush the title's UAV writes to R before the
merge reads it.

Sharing. A buffer of any size inside a resident's pages is that resident
at its offset. Where two copies of the same memory still differ (a buffer
placed in the arena before the resident existed, or two residents over
the same pages), what one writes reaches the arena by the end of the
submission. Those pages are then marked to go up to the others before the
next submission (cross_mark), never to the writer.

Budget: VICTORY_RESIDENT_MB, R and B counted; by default 60% of the
adapter's local budget at the first ask, and each resident only while the
card's use stays under 80% of it, as card_for. The twin is made with R.
The first use of a big buffer opens its arena on that thread, or waits up
to 5 s for the arenas' thread (arena::resolve_waiting). Otherwise it would
keep a card copy for the run. A buffer not in an arena, an arena that
cannot be opened, or a spent budget keeps today's card copy.

Off path (VICTORY_INPLACE < 4): resident::on() is a OnceLock read. find
returns at once, submit records and runs nothing, sent and line return.
Behaviour is today's.

New line, with the frame-rate line:
residents (VICTORY_INPLACE=4): N alive, X MB in the card's memory and Y MB
of twins (budget Z MB); per frame: a MB uploaded from arenas in b ranges,
c MB compared in d merge passes, e MB merged into arenas (f partial
dwords), g MB marked to go up again after writes through other copies,
h submissions with work for residents

Tests: victory-gpu 126 passed, 4 ignored (was 120 and 3); victory-hle
96 + 1 passed. All new, in resident::tests:
- a_dword_takes_only_the_bytes_the_card_changed, pages_go_up_in_runs:
  the shader's byte mask and And/Or arithmetic, page runs, joins.
- warp_the_pages_the_title_wrote_go_up_from_the_arena (test a): write
  watching names exactly the pages the CPU wrote, and the upload brings
  them into R and B.
- warp_the_merge_stores_only_what_the_card_changed (test b), and
  merge_on_hardware (ignored; passes on the RTX 4090). Whole dwords are
  stored and partial dwords keep the title's other bytes. The CPU's byte
  0, written all along by another thread, survives. A byte only the CPU
  wrote stays. B takes R. Counts are 80 dwords, 64 of them partial.
- warp_a_merge_lands_before_the_next_upload_of_its_page (test c):
  submission 1's GPU dword is merged, the CPU writes a byte of the same
  page, and submission 2's upload carries both into R and B; its merge
  finds nothing.
- warp_a_buffer_outside_arenas_keeps_its_copy_and_nested_ones_share
  (test d): memory not reported committed gets no resident. One in an
  arena does, and a buffer in its pages shares it. Cross-marking marks the
  others and not the writer. forget unregisters.
The tests' title memory stays reserved to the end of the run. The
write-watch journal remembers pages, and a later test given the same
addresses failed (watch::tests::written_pages_are_reported_to_every_asker,
single-threaded).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SZC5U8SHMXUK5wS4AS2KxT
A title buffer shares a resident whose pages hold it (the previous commit).
But when an inner big buffer is used before the one around it, the outer
one got a resident of its own beside the inner one. Their bytes stayed in
step only between submissions (cross_mark), and the card's memory held
the overlap twice.

Now a big buffer whose pages no resident holds, but which overlaps
residents, gets one resident over all of them (resident::make_over), if
that lies in one arena within the budget; else one over its own pages, as
before. The new resident takes their places in the registry, and lookup
lets go of the title buffers whose shadows are in a replaced resident, so
their next ask finds the new one. A replaced resident stays alive for the
lists and descriptor slots that still hold it, and keeps receiving the
title's pages and the other copies' writes until they let go.

resident::find now returns Found { resident, bias, replaced }.

Tests: victory-gpu 127 passed, 4 ignored (was 126); victory-hle 96 + 1.
- resident::tests::warp_overlapping_residents_become_one (new). Residents
  over pages 1 and 5 are made first. A buffer over pages 0..3 replaces the
  one over page 1, and its pages find the new resident. One over 2..6
  joins the two remaining into 0..6. A write through the new one marks
  the replaced one's page.
Thirteen runs of the whole victory-gpu suite in a row passed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SZC5U8SHMXUK5wS4AS2KxT
This is the fence part of the design's Stage 3. It is behind its own
switch and works only with VICTORY_INPLACE=4 and the relay.

With residents and memory in place, a flight's shader writes are in the
title's memory when the host fence reaches it. The card put them there in
the submission, and its writes to an arena's write-back pages are seen by
the CPU once the fence completes. Such a flight has nothing for the relay
to fetch, compare or merge (Flight::covered: no ranges of copies in the
PC's memory, no pieces of copies in the card's memory). But relay_land
lands every flight the card has run in one go, the copy-back of all of
them first. So a covered flight's fence signals, events and bottom-of-pipe
writes waited for the copy-back of the flights after it.

With the switch, a landing first tells the title about the flights ahead
of the first one that still has a copy-back, with what follows each of
them: read-backs, bottom-of-pipe writes, fence signals (told_ahead). The
rest is landed as before. The line's order is kept: nothing behind a
flight with a copy-back is told before that copy-back, a covered flight
behind it included. Flights that still carry copy-back keep today's
behaviour. The telling is one method for both parts (Host::relay_tell).

Measured with the relay, switch on or off, in a new line after the relay
line:
title fence signals set by the relay per frame: N, X ms on average after
it took their flights from the card (the longest Y ms); M flights told
before the copy-back of later ones (VICTORY_EARLY_SIGNAL=1: now on|off)
The time is from the relay taking the landed flights, which is when it
saw the host fence reach them, to each fence signal.

Not done here (the rest of Stage 3): the present still settles, settle
points are as they were, the submission lock is not narrowed, and CBVs
are not bound as SRVs.

Tests: victory-gpu 128 passed, 4 ignored (was 127); victory-hle 96 + 1.
- host::relay_tests::covered_flights_are_told_before_the_copy_back_of_later_ones
  (new). With landable: a covered flight and what follows it go as soon
  as the card has run it. In a landing of three, the flight with a
  copy-back and the covered one behind it wait. A landing that starts with
  a copy-back tells nothing ahead.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SZC5U8SHMXUK5wS4AS2KxT
In-game Stage 1 (release, VICTORY_INPLACE=3 with and without
VICTORY_INPLACE_POOL=1, against controls first and last) moved the CPU
side as designed:
- preparing: 89.5 -> 79.9 / 75.2 ms;
- buffer copies: 41.6 -> 36.9 / 28.6 ms;
- snapshots compared: 23.7 -> 17.7 / 8.8 MB.
The card pays. With the pool, its waits went 79.5 -> 106.2 ms, the bus
3.5 -> 4.8 GB/s, and the card's shared memory 5.7 -> 14.3 GB: shaders read
the windows in place, sections of the pool above all, over the bus every
frame.

So at level 4, a window outside buffers that is in place, of the size of a
buffer that would get a copy in the card's memory (VICTORY_CARD_BUFFERS_MIN_MB)
or more, becomes a resident once it is asked for in
VICTORY_RESIDENT_HOT_FRAMES frames running (3 by default; frames more than
8 apart start the count anew). This holds for private windows and for runs
of committed sections alike. The window table hands out the resident from
then on. The window in place stays for the lists and slots that hold it;
cross-marking keeps the two in step. A resident's pages go up as any
resident's do, and a remap that changes a section run lets it go, as a
placement is let go. Windows that only ever get a single ask stay in
place, and a resident is attempted once per window.

The heat is two counters on the shadow, read and written only on the
level-4 path. Below it, hot_window returns at once.

Tests: victory-gpu 129 passed, 4 ignored (was 128); victory-hle 96 + 1.
- shadow::heat_tests::a_window_is_hot_in_the_third_frame_running (new):
  asks in one frame count once; a window becomes hot once; a gap of more
  than 8 frames starts anew.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SZC5U8SHMXUK5wS4AS2KxT
Stage 2 is measured by layers, and two of them had no number: how many
windows in place became residents for being hot (ff5832c), and how many
big buffers asked for a resident and got none, so kept a copy in the
card's memory (or stayed in place) and with it the relay's copy-back.
The second says directly whether the copy-back can go away: a covered
flight (Flight::covered) has nothing to fetch, compare or merge, and only
buffers that are not residents still bring a copy-back.

Checked on the way (no change needed): a resident has no card plan, no
snapshot, nothing pending and no back ranges (Shadow::in_place is true
for it: declared_writes leaves it out, writing returns before snapshots,
update only notes pages for the upload), so a flight whose writes are all
in residents or in place is covered, and the relay neither fetches nor
merges anything on the CPU for it.

The residents' line (new in this branch, VICTORY_INPLACE=4 only) ends
with two counts since the start:
"...; since the start N hot windows in place handed residents and M asks
for a new resident turned down (not in an arena, or over a budget)"
No other line changes.

Tests: victory-gpu 129 passed, 4 ignored; victory-hle 96 + 1.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SZC5U8SHMXUK5wS4AS2KxT
Stage 2 measured in game (RTX 4090, release @a7aff1a, VICTORY_INPLACE=4,
run 20261125-011526-inplace4-s2) ran 3x slower than the control: median
753 ms (control 267, Stage 1 247), the card 94% busy, 686 ms a frame on the
GPU against 100 in the control. Residents line:
"574.1 MB compared in 82 merge passes, 38.59 MB merged into arenas
(3093758 partial dwords)", i.e. some 10 million dwords merged a frame.
nvidia-smi showed the card at 87-100% SM with the bus nearly idle
(0.5 MB/s .. 4.7 GB/s) and less power than the control: the card was
waiting on the bus, not working.

The cause is the merge's layout. A thread took 16 bytes, so each store of
a group of 64 threads was 64 dwords 16 bytes apart, and every store and
atomic into the arena (the title's memory, over the bus) went as a
scattered partial write. On the card, 16 MB changed in every dword took
167 ms to merge whole and 327 ms in part (about 100 and 50 MB/s). Now a
group covers 1 KiB as four rows of 64 dwords side by side (the same 1 KiB
per group, so dispatches are unchanged): 0.7 and 1.6 ms. The partial-dword
atomics turn out cheap once they are in rows, so they stay (they keep the
CPU's bytes of a dword written while the merge runs, probe P3).

Checked on the way (no change): the 3.1 M partial dwords a frame are not a
stale twin. B is R as the submission's shaders found it (B <- R after
every upload, B <- R for each merged dword), so a partial mask is a dword
the shaders stored whole with some bytes unchanged (small integers, floats
whose high bytes stay). Their merge must not overwrite the other bytes, as
the CPU may have written them; at bus speed that costs 1.6 ms per 4 M.
The compare (574 MB a frame) reads R and B in the card's memory only: about
1 GB of reads a frame, a millisecond or so; the control's card hashes read
17,388 pieces of 64 KiB a frame (1.1 GB). Not a cost worth narrowing.

Expected in game: the card's time back near the control's, the residents
line unchanged in its counts (same bytes compared, merged and partial).

Tests: victory-gpu 130 passed, 5 ignored (was 130 / 4);
victory-hle 96 + 1.
- resident::tests::merge_on_hardware_runs_at_bus_speed (new, ignored: opens
  the card): 16 MB changed whole and in one byte per dword, merged with the
  right counts and the title's memory equal to R, each under 20 ms (0.7 and
  1.6 ms here; the old layout fails it at 167 and 327 ms).
- merge_on_hardware, warp_the_merge_stores_only_what_the_card_changed and
  warp_a_merge_lands_before_the_next_upload_of_its_page pass unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SZC5U8SHMXUK5wS4AS2KxT
Stage 2 in game (RTX 4090, release @a7aff1a, run
20261125-011526-inplace4-s2): "202.1 MB uploaded from arenas in 187
ranges ... 196.2 MB marked to go up again after writes through other
copies" per frame. Almost all that went up from the arenas over the bus
was cross-marking, not the title's writes.

Cross-marking (resident::cross_mark) sends up to a resident what another
copy of the same memory wrote in the submission: a buffer or window in
place in the arena (written by shaders directly), or another resident
whose merge wrote the arena (one replaced by a union and still held). It
rounded every declared range out to whole 64 KiB pages. But the title
wrote none of those bytes (its writes go up by write watching, whole
pages, in Resident::refresh, unchanged), so only the bytes the other
copy's shaders may have written can differ from the resident; the rest of
each page went up again for nothing. They now go up on 256 bytes: the
declared range widened to 256, cut at the resident's end. A whole page
held by the arena is no fresher than these bytes of it: the arena holds
the other copy's writes and the title's alike.

Which of the other copies does the writing could not be told from the
line, so it says it at the end (new fields only, the line's other words
unchanged):
"...; of the bytes marked per frame, X MB after writes in place and Y MB
after merges of other residents over the same memory"
X is buffers and windows in place in an arena over a resident's pages
(windows outside buffers looked up by other keys than the hot one that
became the resident, and buffers placed before a resident took their
pages: the tables keep handing those out); Y is residents a union
replaced that something still holds.

Expected in game: "marked" and "uploaded" fall by what the declared ranges
leave of their pages (unknown: 196 MB if they were all whole pages of
4 MiB windows, much less for small ranges); compared, merged and partial
unchanged.

Tests: victory-gpu 130 passed, 5 ignored; victory-hle 96 + 1.
- warp_a_buffer_outside_arenas_keeps_its_copy_and_nested_ones_share:
  a merged write of 8 bytes goes up to the other resident as 256 bytes,
  not its page; a write in place across a 256-byte line takes both units
  in both residents; one at a resident's end stops there; the two kinds
  are counted apart.
- warp_overlapping_residents_become_one: a write through the union goes up
  to the replaced resident as 256 bytes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SZC5U8SHMXUK5wS4AS2KxT
Stage 2 (VICTORY_INPLACE=4) latency work, behind the same switch; nothing
changes without it.

Card time (VICTORY_CARD_TIME=1, new cardtime.rs): timestamps around our
uploads to residents, the title's lists and the merge, read back each
submission. The frame-rate line says per frame: "upload to residents X ms,
title lists Y ms, merge Z ms, between our calls ..., from one submission's
end to the next one's start ...". Measurement switches that take one part
of the residents' work away, to time it: VICTORY_RESIDENT_PLAIN_STORES,
VICTORY_RESIDENT_NO_CROSS, VICTORY_RESIDENT_NO_MERGE.

Merge by store width (B5). The translator now tells, per pipeline, the
narrowest store its shaders make (pipeline::StoreWidth); it goes with each
declared write (shadow::writer, Step::GpuWrite, resident::Declared). Where
only whole-dword stores write a resident, the merge stores whole dwords;
elsewhere it keeps the atomics that leave the CPU's bytes of a dword alone.
VICTORY_RESIDENT_PARTIAL = flag (default) | atomics | cas | load | plain
picks the way for partial dwords. Merge card time: 165 -> ~10 ms a frame.

One owner per title range (B1; VICTORY_RESIDENT_ONE_OWNER=0 turns it off).
Residents that overlap were made into a union, but buffers still holding
the old ones kept them alive, taking uploads and merges every submission.
Now:
- make_over fails closed;
- resident::retargeted keeps the set of replaced residents and a generation;
- shadow::retarget_tables lets both tables' copies of unregistered residents
  go before an ask;
- HostHeap::mirror remakes descriptor slots that show a replaced buffer;
- the heap-pass cache and memory.rs's numbering follow;
- prepare releases what finished lists held first.
In game: zombies 0, overlap 0, re-uploads 199 -> 24 MB a frame.

Draw-time probes:
- VICTORY_PROBE_PIPELINES=<hashes> logs each probed pipeline's views
  (where each copy lives, Shadow::describe) and its store and atomic counts
  (Translated::store_counts);
- diagnostic timing runs tag commands +R/+W/+S;
- VICTORY_GPU_TIMING_TOP sets how many pipelines are listed;
- the slot-mismatch counter is split by kind.

Tests: victory-gpu 137 passed, 8 ignored (serially): merge with the CPU
writing for each partial way, overlap and retargeting.
With residents on, every bound slot was checked against its view's copy
(HostHeap::shows takes the heap's lock, once per view of every draw), and
every view set the +R/+W/+S tag bits, in every build and run. These are
measuring tools; they now run only with VICTORY_DRAW_PROBES=1 or when
VICTORY_PROBE_PIPELINES names pipelines. Off, the residents' line counts
no mismatched slots (0).
Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:50:47 +00:00
Author
Owner

@⁠Kanthon1209 on GitHub · 2026-11-25 07:16 UTC · original

UP NB

**@⁠Kanthon1209** on GitHub · 2026-11-25 07:16 UTC · [original](https://github.com/fxceless/victory-fork/pull/772#issuecomment-7155679966) UP NB
Author
Owner

@⁠alpz1000 on GitHub · 2026-11-25 17:40 UTC · original

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.

**@⁠alpz1000** on GitHub · 2026-11-25 17:40 UTC · [original](https://github.com/fxceless/victory-fork/pull/772#issuecomment-7169833519) 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.
Author
Owner

@⁠UwUCammie on GitHub · 2026-11-26 00:52 UTC · original

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

**@⁠UwUCammie** on GitHub · 2026-11-26 00:52 UTC · [original](https://github.com/fxceless/victory-fork/pull/772#issuecomment-7179203411) 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 has changes conflicting with the target branch.
  • crates/victory-gpu/src/descriptor/host.rs
  • crates/victory-gpu/src/draw.rs
  • crates/victory-gpu/src/host.rs
  • crates/victory-gpu/src/lib.rs
  • crates/victory-gpu/src/memory.rs
  • crates/victory-gpu/src/pipeline.rs
  • crates/victory-gpu/src/shadow.rs
  • crates/victory-hle/src/modules/xmem.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/772/head:github-bot/gh-772'
git switch 'github-bot/gh-772'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-772'
git switch 'github-bot/gh-772'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-772'
git switch 'github-bot/gh-772'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-772'
git switch 'main'
git merge --squash 'github-bot/gh-772'
git switch 'main'
git merge --ff-only 'github-bot/gh-772'
git switch 'main'
git merge 'github-bot/gh-772'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.