GPU memory: split the copy admission from its allocation, and use the title's own backing where it can be opened #2538

Closed
CwWwWwW wants to merge 0 commits from upstream-pr/2538 into main
CwWwWwW commented 2026-11-29 13:59:19 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by CwWwWwW on 2026-11-29T13:59:19Z.


GPU memory: split the copy admission from its allocation, and use the title's own backing where it can be opened

This is the rebased successor of the closed #916, split into three commits as its closing comment
asked. The code was re-derived on the current main (829188e), not applied as the old diff: main had
already evolved the same memory code through other forks, and the parts this branch would have
duplicated (the by-address cap, the checked device-removal waits, the window/arena budget
separation) are kept from main and recorded as such in the docs.

What it fixes

  1. The placement of a copy was invisible. Whether a host copy got a device-local side or stayed
    in system memory was decided inside the allocation, and a refused copy left no trace. The first
    commit makes that decision explicit (card_admission / window_admission), counts every host
    buffer by the heap class the API reports, and counts the copies that stay in system memory by the
    reason they did. It also fixes an accounting defect: a window's second system-memory side was
    charged to the window device-local budget.
  2. Some copies are redundant because the GPU can reach the title's bytes. When the policy refuses
    a device-local side, the copy stays in system memory either way; opening the title's own backing
    (private allocation, or one run of one section through our own view) and placing the buffer
    there removes the mirror and all its machinery. This is the second commit, behind switches that
    are off by default, with the existing copy path as the fallback for every refusal. It never
    replaces a copy that would have been device-local (that would be a memory-class downgrade).
  3. Coherence and lifetime for the direct path. A placed copy's shader writes are declared so the
    late waits order CPU readers behind the flight; the title's free/decommit/protect and the raw
    32-bit free path let placed copies go before the kernel call; a mapping change lets go of
    exactly the copies over the range through an exact registry; a section view keeps the section's
    pages alive after the title unmaps its own view.
  4. The record of what remains. The third commit documents the copy-bridge inventory and
    classification, what this work removed, the copies that are required and why, the unresolved
    classes, and what only a real NVIDIA run can establish.

The three commits

  1. c9887c4b GPU memory: split the copy admission from its allocation and add the placement
    ledger
    — 3 files, +526/-7. shadow::card_admission/window_admission; the placement ledger
    in residency (HeapClass/class_of from GetHeapProperties, Fallback reasons,
    fallback_add/fallback_freed, placement_line every 5 s or with
    VICTORY_MEMORY_REPORT); host.rs counts every buffer made; the window second-side budget
    fix; say_separation_switches; tests for the decisions, the heap classes and the counter
    balance.
  2. 53094eba GPU memory: use the title's own backing where it can be opened — 6 files,
    +973/-83. inplace::openability, refcounted SectionView, shared regions per section run
    (REGION_MOST 512 MiB), place_view_part, place_fallback with VICTORY_INPLACE_VIEW=1/2
    and VICTORY_INPLACE=3; shadow places only where admission refused, keeps placed copies in
    the exact registry, declares their shader writes, and gives no placed copy a staging/mirror/card
    side/refresh/snapshot/compare/copy-back; xmem intercepts VirtualProtect unconditionally and
    the raw 32-bit XMemFreeDefault path lets placed copies go first; port uses the shared
    SectionView; the ledger counts directly backed copies and refused direct asks; WARP tests for
    the placement mechanics, the section lifetime, the shared region, the exact invalidation and the
    counters.
  3. 56dd8d81 GPU memory: record the audit of the memory split and the copy bridges — the three
    docs: the platform model, the heap classes, ownership, admission, the ledger and how to read it,
    the window budget and the exception matrix, the copy inventory and classification, the
    implementation records, the copies that remain, the follow-ups and the verification record.

What does not change

  • Every direct-access switch is off by default (VICTORY_INPLACE, VICTORY_INPLACE_VIEW,
    VICTORY_INPLACE_MB, VICTORY_INPLACE_PROBE); with them unset the product path behaves as at
    829188e - no policy, threshold, budget, launcher default or rendering change.
  • Required copies stay: carded VRAM sides, by-address shader memory, textures/targets for
    layout/format/depth reasons, read-backs and the D3D12 infrastructure.
  • No new dependency; the workspace lockfile is untouched.

Validation

Local (Windows, Rust 1.98.1 x86_64-pc-windows-gnu):

Check Result
cargo check --workspace --all-targets --locked PASS after each commit
cargo check --workspace --all-targets --all-features --locked fails identically at plain 829188e (diagnostics feature: copystat's mb, a timing local shadowing the function) - inherited, not caused by this branch
warnings in changed files none

GitHub Actions (Windows/WARP), from a temporary ci/** branch of the fork (test workflow only,
not part of this branch; the branch itself is feat/gpu-memory-rebased):

Run Result
Build check, default features PASS
Build check, all features fails at 829188e too (inherited)
Tests (workspace, every test target), this branch 924 passed, 0 failed, 57 ignored for the victory-gpu lib (914 passed on the baseline); the focused in-place tests 15/15 PASS; every other test target passes; the only failures are the nine the baseline has too
Tests (workspace, every test target), 829188e baseline the same nine inherited failures (three bcpack::oracle_parity_*, five emit tests, xtask's asset-policy repository_passes_policy); victory-gpu lib 914 passed, 1 failed (a flaky card-steps test)

The branch adds ten passing tests to the victory-gpu lib (924 against 914) and introduces no
failure: the nine failures are identical on plain 829188e with the same workflow, in files this
change does not touch. The tested source tip is 53094eba; the third commit (docs only) was amended
after the run, so the source is unchanged after it.

What must be established on real NVIDIA hardware

Nothing here claims the direct path is ready to be a default: WARP proves the mechanics, not the
driver or the hardware. Before any switch becomes a default:

  • that OpenExistingHeapFromAddress1 is accepted by the target driver for private allocations and
    for our section views, what it pins and at what working-set cost;
  • the openable share of the real title's memory (the in-place census, VICTORY_INPLACE_PROBE=1);
  • that a placed copy's shader writes are ordered correctly under the real relay and late waits;
  • the PCIe cost of access in place against the copies it replaces, per class, plus physical
    residency/WDDM paging and device-removal/TDR behaviour.

Note on #916

This is the rebased successor of the closed #916: the same memory work, re-derived on the current
main and split into three commits as its closing comment asked, so it can be reviewed commit by
commit.

Follow-ups

  • View-byte copies (shadow::exact) over openable backing: needs the exact pool to hold a placed
    form.
  • Multi-run composition for scattered/holed view memory (needs a driver experiment).
  • A layout census and probe for the layout-equal texture subset.
  • A device-local by-address arena, or a documented reason it cannot exist.
  • Delete the experiment switches once a hardware A/B shows the direct path equal or better wherever
    the memory is openable.
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5551428834 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2538). Originally posted by [CwWwWwW](https://github.com/CwWwWwW) on 2026-11-29T13:59:19Z. --- # GPU memory: split the copy admission from its allocation, and use the title's own backing where it can be opened This is the rebased successor of the closed #916, split into three commits as its closing comment asked. The code was re-derived on the current main (829188e), not applied as the old diff: main had already evolved the same memory code through other forks, and the parts this branch would have duplicated (the by-address cap, the checked device-removal waits, the window/arena budget separation) are kept from main and recorded as such in the docs. ## What it fixes 1. **The placement of a copy was invisible.** Whether a host copy got a device-local side or stayed in system memory was decided inside the allocation, and a refused copy left no trace. The first commit makes that decision explicit (`card_admission` / `window_admission`), counts every host buffer by the heap class the API reports, and counts the copies that stay in system memory by the reason they did. It also fixes an accounting defect: a window's second *system-memory* side was charged to the window *device-local* budget. 2. **Some copies are redundant because the GPU can reach the title's bytes.** When the policy refuses a device-local side, the copy stays in system memory either way; opening the title's own backing (private allocation, or one run of one section through our own view) and placing the buffer there removes the mirror and all its machinery. This is the second commit, behind switches that are off by default, with the existing copy path as the fallback for every refusal. It never replaces a copy that would have been device-local (that would be a memory-class downgrade). 3. **Coherence and lifetime for the direct path.** A placed copy's shader writes are declared so the late waits order CPU readers behind the flight; the title's free/decommit/protect and the raw 32-bit free path let placed copies go before the kernel call; a mapping change lets go of exactly the copies over the range through an exact registry; a section view keeps the section's pages alive after the title unmaps its own view. 4. **The record of what remains.** The third commit documents the copy-bridge inventory and classification, what this work removed, the copies that are required and why, the unresolved classes, and what only a real NVIDIA run can establish. ## The three commits 1. **`c9887c4b` GPU memory: split the copy admission from its allocation and add the placement ledger** — 3 files, +526/-7. `shadow::card_admission`/`window_admission`; the placement ledger in `residency` (`HeapClass`/`class_of` from `GetHeapProperties`, `Fallback` reasons, `fallback_add`/`fallback_freed`, `placement_line` every 5 s or with `VICTORY_MEMORY_REPORT`); `host.rs` counts every buffer made; the window second-side budget fix; `say_separation_switches`; tests for the decisions, the heap classes and the counter balance. 2. **`53094eba` GPU memory: use the title's own backing where it can be opened** — 6 files, +973/-83. `inplace::openability`, refcounted `SectionView`, shared regions per section run (`REGION_MOST` 512 MiB), `place_view_part`, `place_fallback` with `VICTORY_INPLACE_VIEW=1/2` and `VICTORY_INPLACE=3`; `shadow` places only where admission refused, keeps placed copies in the exact registry, declares their shader writes, and gives no placed copy a staging/mirror/card side/refresh/snapshot/compare/copy-back; `xmem` intercepts `VirtualProtect` unconditionally and the raw 32-bit `XMemFreeDefault` path lets placed copies go first; `port` uses the shared `SectionView`; the ledger counts directly backed copies and refused direct asks; WARP tests for the placement mechanics, the section lifetime, the shared region, the exact invalidation and the counters. 3. **`56dd8d81` GPU memory: record the audit of the memory split and the copy bridges** — the three docs: the platform model, the heap classes, ownership, admission, the ledger and how to read it, the window budget and the exception matrix, the copy inventory and classification, the implementation records, the copies that remain, the follow-ups and the verification record. ## What does not change - Every direct-access switch is off by default (`VICTORY_INPLACE`, `VICTORY_INPLACE_VIEW`, `VICTORY_INPLACE_MB`, `VICTORY_INPLACE_PROBE`); with them unset the product path behaves as at `829188e` - no policy, threshold, budget, launcher default or rendering change. - Required copies stay: carded VRAM sides, by-address shader memory, textures/targets for layout/format/depth reasons, read-backs and the D3D12 infrastructure. - No new dependency; the workspace lockfile is untouched. ## Validation Local (Windows, Rust 1.98.1 x86_64-pc-windows-gnu): | Check | Result | |---|---| | `cargo check --workspace --all-targets --locked` | **PASS** after each commit | | `cargo check --workspace --all-targets --all-features --locked` | fails identically at plain `829188e` (diagnostics feature: `copystat`'s `mb`, a `timing` local shadowing the function) - **inherited**, not caused by this branch | | warnings in changed files | none | GitHub Actions (Windows/WARP), from a temporary `ci/**` branch of the fork (test workflow only, not part of this branch; the branch itself is `feat/gpu-memory-rebased`): | Run | Result | |---|---| | Build check, default features | **PASS** | | Build check, all features | fails at `829188e` too (inherited) | | Tests (workspace, every test target), this branch | **924 passed, 0 failed, 57 ignored** for the `victory-gpu` lib (914 passed on the baseline); the focused in-place tests 15/15 PASS; every other test target passes; the only failures are the nine the baseline has too | | Tests (workspace, every test target), `829188e` baseline | the same nine inherited failures (three `bcpack::oracle_parity_*`, five `emit` tests, `xtask`'s asset-policy `repository_passes_policy`); `victory-gpu` lib 914 passed, 1 failed (a flaky card-steps test) | The branch adds ten passing tests to the `victory-gpu` lib (924 against 914) and introduces no failure: the nine failures are identical on plain `829188e` with the same workflow, in files this change does not touch. The tested source tip is `53094eba`; the third commit (docs only) was amended after the run, so the source is unchanged after it. - branch run: https://github.com/CwWwWwW/VIctory-NVIDIA/actions/runs/46269247875 - baseline run: https://github.com/CwWwWwW/VIctory-NVIDIA/actions/runs/46267700603 ## What must be established on real NVIDIA hardware Nothing here claims the direct path is ready to be a default: WARP proves the mechanics, not the driver or the hardware. Before any switch becomes a default: - that `OpenExistingHeapFromAddress1` is accepted by the target driver for private allocations and for our section views, what it pins and at what working-set cost; - the openable share of the real title's memory (the in-place census, `VICTORY_INPLACE_PROBE=1`); - that a placed copy's shader writes are ordered correctly under the real relay and late waits; - the PCIe cost of access in place against the copies it replaces, per class, plus physical residency/WDDM paging and device-removal/TDR behaviour. ## Note on #916 This is the rebased successor of the closed #916: the same memory work, re-derived on the current main and split into three commits as its closing comment asked, so it can be reviewed commit by commit. ## Follow-ups - View-byte copies (`shadow::exact`) over openable backing: needs the exact pool to hold a placed form. - Multi-run composition for scattered/holed view memory (needs a driver experiment). - A layout census and probe for the layout-equal texture subset. - A device-local by-address arena, or a documented reason it cannot exist. - Delete the experiment switches once a hardware A/B shows the direct path equal or better wherever the memory is openable.
futurepro62 commented 2026-11-29 20:07:27 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by futurepro62 on 2026-11-29T20:07:27Z.


The placement line never prints: its 5-second timer is reset on every check.

READ IN CODE (PR head 56dd8d81, host.rs around line 13888): Meter::frame reaches the placement block about once a second (after frame_times_line). The block does

let last = LAST_PLACEMENT.swap(now, Ordering::Relaxed);
if now.saturating_sub(last) >= 5_000 {

so now is stored on every call and the gap is never more than about 1,000 ms. The first check doesn't print either: now_ms() starts its clock at its first call, so now is near 0 there. The result is no memory placement line, with VICTORY_MEMORY_REPORT=1 or without it.

A fix that prints at the first check and then every 5 s:

let last = LAST_PLACEMENT.load(Ordering::Relaxed);
if last == 0 || now.saturating_sub(last) >= 5_000 {
    LAST_PLACEMENT.store(now.max(1), Ordering::Relaxed);
    crate::residency::placement_line(host().and_then(Host::video_memory_groups));
}

MEASURED: with VICTORY_MEMORY_REPORT=1, a 6.4-min session printed 0 memory placement lines (the startup memory separation: placement switches set: ... VICTORY_MEMORY_REPORT=1 line shows the switch was seen). With the fix, a 7.0-min session printed 86 lines, a 17-min one 194.

What the ledger then showed (MEASURED, one run each, not the same route, so read it as direction, not effect size):

Run Windows' line / cap Hitches > 100 ms Texture-room lines with no room Copies with a system-memory GPU side, at the end VRAM peak (DXGI local)
7.0 min 80 % / 1024 MB (this tree's defaults) 32.6/min 78 of 85 3,268 MB: budget 1,812, cap 1,456 13,187 of 14,823 MB
17.0 min 89 % / 1024 MB 9.5/min 68 of 194 2,368 MB: budget 240, cap 2,128 13,306 of 14,798 MB
19.7 min 89 % / 2048 MB 27.0/min 148 of 227 2,989 MB: budget 2,597, cap 392 14,449 of 14,831 MB
  • The budget refusals are windows. The title-buffer path logs every refusal (no card copy for a title buffer), and there are none in the first two runs. The 2048 MB run has 21, totalling 6 MB, all near the end with the card at 14,405 of 14,826 MB.
  • The cap is the windows' 1,024 MB. Title-buffer card copies made in the 17-min run sum to about 1,005 MB of their 2,048 MB cap (from the a buffer's host copy is in the card's memory lines).
  • 89 % (main's value for budgets over 12 GiB) moved the windows' budget refusals onto the cap. Raising the cap to 2048 MB moved them back onto the budget and pushed VRAM to 97 %, and texture no-room went up. On this card the room is shared, so it doesn't add up to a free win.

Method

  • Build: not the PR head. I ported the measuring part of c9887c4b by hand onto an older tree: fork main 9300875 plus local picks (#339, #348, #638, #1074/#1145, #1551, main's 25b3b5c) and a 3619 port. The port takes residency's ledger verbatim, plus placed(), the meter block, say_separation_switches, and card_admission/window_admission written against that tree's card_room_for/window_room_for. It leaves out the VICTORY_WINDOWS_OWN budget change and commits 2–3. The timer code above is the same in the port and at the PR head. The 80 %/89 % line is a local switch (VICTORY_CARD_WINDOWS_PERCENT), and the cap is the existing VICTORY_CARD_WINDOWS_MB.
  • Numbers: the memory placement lines (last line, and peaks per minute), the texture queue's room lines (count of no room), and frame_times windows with a median over 20 ms (in the world; frames are the game's before frame generation, with a 71.4 ms pacing cap). Hitches are the windows' over 100 ms counts per minute in the world.
  • Settings: 4K output, DLSS Performance, frame generation 4x, launcher mode 6.
  • Hardware: RTX 5070 Ti 16 GB, driver 621.40; Ryzen 7 9800X3D; 32 GB RAM; Windows 11 Home 26300.
  • Not tested: the PR head itself, its in-place switches (commit 2), other cards.

Written with Claude Code (Claude Opus 5.5) from our own runs; I checked it before posting.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7261825574 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2538#issuecomment-7261825574). Originally posted by [futurepro62](https://github.com/futurepro62) on 2026-11-29T20:07:27Z. --- **The placement line never prints: its 5-second timer is reset on every check.** READ IN CODE (PR head `56dd8d81`, `host.rs` around line 13888): `Meter::frame` reaches the placement block about once a second (after `frame_times_line`). The block does ```rust let last = LAST_PLACEMENT.swap(now, Ordering::Relaxed); if now.saturating_sub(last) >= 5_000 { ``` so `now` is stored on every call and the gap is never more than about 1,000 ms. The first check doesn't print either: `now_ms()` starts its clock at its first call, so `now` is near 0 there. The result is no `memory placement` line, with `VICTORY_MEMORY_REPORT=1` or without it. A fix that prints at the first check and then every 5 s: ```rust let last = LAST_PLACEMENT.load(Ordering::Relaxed); if last == 0 || now.saturating_sub(last) >= 5_000 { LAST_PLACEMENT.store(now.max(1), Ordering::Relaxed); crate::residency::placement_line(host().and_then(Host::video_memory_groups)); } ``` MEASURED: with `VICTORY_MEMORY_REPORT=1`, a 6.4-min session printed 0 `memory placement` lines (the startup `memory separation: placement switches set: ... VICTORY_MEMORY_REPORT=1` line shows the switch was seen). With the fix, a 7.0-min session printed 86 lines, a 17-min one 194. **What the ledger then showed** (MEASURED, one run each, not the same route, so read it as direction, not effect size): | Run | Windows' line / cap | Hitches > 100 ms | Texture-room lines with no room | Copies with a system-memory GPU side, at the end | VRAM peak (DXGI local) | |---|---|---|---|---|---| | 7.0 min | 80 % / 1024 MB (this tree's defaults) | 32.6/min | 78 of 85 | 3,268 MB: budget 1,812, cap 1,456 | 13,187 of 14,823 MB | | 17.0 min | 89 % / 1024 MB | 9.5/min | 68 of 194 | 2,368 MB: budget 240, cap 2,128 | 13,306 of 14,798 MB | | 19.7 min | 89 % / 2048 MB | 27.0/min | 148 of 227 | 2,989 MB: budget 2,597, cap 392 | 14,449 of 14,831 MB | - The budget refusals are windows. The title-buffer path logs every refusal (`no card copy for a title buffer`), and there are none in the first two runs. The 2048 MB run has 21, totalling 6 MB, all near the end with the card at 14,405 of 14,826 MB. - The cap is the windows' 1,024 MB. Title-buffer card copies made in the 17-min run sum to about 1,005 MB of their 2,048 MB cap (from the `a buffer's host copy is in the card's memory` lines). - 89 % (main's value for budgets over 12 GiB) moved the windows' budget refusals onto the cap. Raising the cap to 2048 MB moved them back onto the budget and pushed VRAM to 97 %, and texture no-room went up. On this card the room is shared, so it doesn't add up to a free win. **Method** - Build: not the PR head. I ported the measuring part of `c9887c4b` by hand onto an older tree: fork main `9300875` plus local picks (#339, #348, #638, #1074/#1145, #1551, main's `25b3b5c`) and a 3619 port. The port takes residency's ledger verbatim, plus `placed()`, the meter block, `say_separation_switches`, and `card_admission`/`window_admission` written against that tree's `card_room_for`/`window_room_for`. It leaves out the `VICTORY_WINDOWS_OWN` budget change and commits 2–3. The timer code above is the same in the port and at the PR head. The 80 %/89 % line is a local switch (`VICTORY_CARD_WINDOWS_PERCENT`), and the cap is the existing `VICTORY_CARD_WINDOWS_MB`. - Numbers: the `memory placement` lines (last line, and peaks per minute), the `texture queue's room` lines (count of `no room`), and `frame_times` windows with a median over 20 ms (in the world; frames are the game's before frame generation, with a 71.4 ms pacing cap). Hitches are the windows' `over 100 ms` counts per minute in the world. - Settings: 4K output, DLSS Performance, frame generation 4x, launcher mode 6. - Hardware: RTX 5070 Ti 16 GB, driver 621.40; Ryzen 7 9800X3D; 32 GB RAM; Windows 11 Home 26300. - Not tested: the PR head itself, its in-place switches (commit 2), other cards. Written with Claude Code (Claude Opus 5.5) from our own runs; I checked it before posting.

Pull request closed

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
trustno1-coder/VIctory-NVIDIA!2538
No description provided.