GPU memory: separate system RAM from VRAM, and use the title's own backing where it can be opened #916

Closed
github-bot wants to merge 16 commits from github-bot/gh-916 into main AGit
Owner

@⁠CwWwWwW on GitHub · 2026-11-28 09:02 UTC · original
CwWwWwW:feat/gpu-memory-separation → main · +3551 −242 · 11 files · 16 commits · closed without merging

What this is

This PR carries the whole GPU-memory project on top of 63b902f: 16 commits, 11 files,
+3551/-242
. Its first revision was the system-RAM/VRAM separation audit and the accounting
fixes. This revision continues it with the copy-bridge project - the part that finds which of
the layer's host copies exist only because the host cannot see the title's memory, and removes them
where the GPU can be given the title's own bytes instead.

One branch, one PR. No default changes anywhere: every direct-access path is opt-in and off by
default, and with the switches unset the product path is exactly the base behaviour.

  1. RAM/VRAM separation (commits 1-3, unchanged from the first revision): the explicit
    memory-domain model, the placement ledger, the verified accounting fixes, the window/texture
    budget audit, and the verification record (docs/memory-separation.md,
    docs/memory-separation-window-budget.md).
  2. Copy bridges (commits 4-16): the complete audit and classification of every copy
    (docs/copy-bridges.md), the backing/admission invariants that make a direct placement
    decidable on the same evidence as the fallback it replaces, the page-pool direct-access
    prototype, the migration of the copies the policy refuses, the coherence/lifetime wiring, and
    the removal plus the record of what remains.

How to proceed after this PR

This section is for reviewers and whoever picks the work up next. The PR is deliberately the
foundation, not the end state.

1. Merging this PR

This is safe to merge as-is:

  • every switch is off by default and no policy, threshold, budget, launcher default or rendering
    behaviour changes with them off (the base behaviour is unchanged);
  • required copies (carded VRAM copies, by-address shader memory, layout/format-dependent textures,
    D3D12 infrastructure) are untouched - the audit records each one and why it stays;
  • the added code is exercised by 18 new tests on the software adapter (WARP).

Two inherited CI conditions are not caused by this branch and should not block the merge: the
repository's clippy gate is already red at 63b902f for pre-existing lints, and the WARP test
suite has one baseline failure (depth_bounds_pipeline_loads_and_filters_draws). The build check
and all tests this branch adds pass; exact runs are in "Validation" below. Fixing the baseline
lints is a mechanical follow-up outside this change.

Concretely, the current head's CI run (46145621108) fails in its Clippy step on exactly two lints,
both of which fail identically on a clean 63b902f tree with the same command:
victory-shader/src/emit/mod.rs:2768 (let_and_return) and
victory-gpu/src/shadow.rs:1861 (manual_is_multiple_of, the base's shadow.rs:1708 moved by
this diff). Because the Clippy step fails first, the diagnostics build and Tests steps are
skipped, as in the first revision. Neither lint is added by this change.

2. Next: validate on the target NVIDIA hardware

Everything below needs a person with the target GPU, driver and game build. Run it after this PR
is merged (the switches exist on the base path, so validation can also be done on this branch).
Record the exact GPU, driver, game build/save, switch values and logs; open one follow-up PR with
the record in docs/copy-bridges.md §17 and one per resulting code change.

  1. Baseline ledger. Run the title save with VICTORY_MEMORY_REPORT=1 and no direct switches.
    Keep the placement ledger and the created-resource setup as the reference.
  2. Openability census. Run with VICTORY_INPLACE_PROBE=1 (level 2 also opens one part for a
    moment). The census reports which title memory is private/committed, one contiguous section
    run, or scattered/holed, and which part of it can be opened as a host heap. This number decides
    how much of the removable mirror class will actually go away.
  3. Direct path on, same save. VICTORY_INPLACE_VIEW=2 VICTORY_MEMORY_REPORT=1 (page pool
    windows, title buffers and view-byte copies), and separately VICTORY_INPLACE=3 (private
    memory). Check: visuals, save/load, no crash or device removal; the ledger shows direct-backed
    bytes per class and the refusal reasons that remain.
  4. Coherency under the real relay. With submissions in the air (the defaults), confirm that
    placed shader writes are visible to a CPU reader only after the wait, and that CPU writes before
    a dispatch are visible to the GPU. The declaration path is unit-tested; the ordering under a
    live relay needs the run.
  5. Cost A/B. Same save with the switches off and on: frame time plus a GPUView/ETW capture.
    Direct access is not automatically faster than a copy into local VRAM; only measurement decides
    whether a default is worth it.
  6. Failure and lifetime. Exercise title free/decommit/protect paths while placed, and a device
    removal/TDR, and confirm the fallback path takes over and no title-visible call fails in a way
    the code does not record.

If any step shows a defect, the answer is to keep the switches off and report it - not to lower
the evidence bar.

3. Decision gates after validation

Observation Decision
Census: large share of title memory openable, no defect in steps 3-6, A/B neutral or better enable VICTORY_INPLACE_VIEW per class (one class at a time, each its own commit/PR)
Driver refuses opened heaps, or opening pins too much / working-set cost is unacceptable keep off; record the refusal reason; the mirror path stays the product path
Coherency or lifetime defect fix as a defect first; do not enable
PCIe cost worse for a class leave that class carded as today (memory-class rule)
Physical residency/paging unmeasurable on the target do not claim it; do not default on it

4. Then remove code (the remaining deletion tasks, in order)

  1. Unify the port's own region bookkeeping with the shared registry (port.rs). No hardware
    needed; pure refactor with the existing WARP tests. Removes the last duplicate mapping-lifetime
    code; documented as a follow-up, not a copy bridge.
  2. Legacy in-place levels 1/2 and the write-combined / second-side experiments
    (VICTORY_CARD_ALL, VICTORY_WINDOWS_OWN, VICTORY_SEND_BAR, VICTORY_WINDOWS_BAR_MB,
    VICTORY_WC_BAR). Delete only after the hardware A/B shows the fallback substitution is equal
    or better wherever the memory is openable; today they are the A/B apparatus.
  3. Per-class default enablement of VICTORY_INPLACE_VIEW after §2/§3. Once a class is on by
    default, its mirror branch is provably unreachable and can be deleted with the release note.
  4. Multi-run composition for scattered/holed view memory. Needs a driver experiment opening
    several runs/heaps; only then can the scattered-memory mirror class go.
  5. Texture/target/depth subset after a layout census and probe (row-major, single-level linear
    subset first). Only that subset's mirror and staging are deleted.
  6. Carded copies stay. Replacing a device-local side with system-memory access is a
    memory-class downgrade; only a measured PCIe-vs-VRAM study could justify it, and this project
    does not.

Do not delete a bridge because its source and destination hold similar bytes; every removal above
has a stated replacement, a test, and a fallback. The current required/unresolved list, with the
reasons, is docs/copy-bridges.md §10 and §16.2.


The change in detail

The audit: which copies are avoidable, and which are not

docs/copy-bridges.md inventories every copy and intermediate allocation with its source,
destination, callers, why it exists, whether the title's backing is openable, and what a removal
must preserve. The classification:

  • Removable now: the look-ahead buffer cache and the write-combined/mapped-VRAM experiments
    (switch-controlled shortcuts) and the second system-memory sides. Kept as switches until §4.2.
  • Removable after a prerequisite: the system-memory mirrors of title buffers, windows and
    view-byte copies (the largest class by bytes), plus the layout-compatible texture subset and the
    target/depth class after separate evidence.
  • Required: carded copies, by-address shader memory, textures/targets that exist for
    layout/format/depth reasons, and the D3D12 infrastructure. None is touched.
  • Unresolved: overlapping placed resources and D3D12 aliasing barriers, driver coherency and
    pinning, multi-run composition, a device-local by-address arena, WDDM residency and PCIe cost.

What the copy-bridge project changes

Direct access instead of a copy, only for the copies the policy already refuses a VRAM side.
inplace::place_fallback is asked by the buffer, window and view-byte copy paths exactly where
the device-local admission has already refused the copy (a carded copy is never replaced by a
memory-class downgrade). It opens the title's own memory as a host heap:

  • page-pool/view memory: our own view of one contiguous committed run of one section,
    OpenExistingHeapFromAddress1 on that view, a cross-adapter UAV buffer placed over it - at any
    address, not just the old sub-4-GiB port range. One view and one heap are shared per section
    run, not per copy.
  • private memory: a committed part of the title's own allocation, opened the same way.

A placed copy has no staging buffer, no mirror, no card side, no hash twin, no send/fetch state,
no refresh, no snapshot and no copy-back: the GPU reads and writes the title's pages.

Switches (all off by default)

Switch Default Effect
VICTORY_INPLACE_VIEW 0 1: place page-pool windows over our view of their run; 2: title buffers and view-byte copies too
VICTORY_INPLACE 0 3 and up: substitute the fallback placements for copies that would stay in system memory (levels 1/2 keep their old "place anywhere openable" meaning)
VICTORY_INPLACE_MB 4096 cap on title bytes in place at once (opening pins pages)
VICTORY_INPLACE_PROBE 0 1: probe plus the openability census; 2: also opens one part

Every refusal (not openable, scattered, holes, cap, host refused, no ID3D12Device13) is counted
with its reason in the placement ledger and falls back to exactly the old copy path.

Coherence and lifetime

  • A placed copy's shader writes are declared through the existing HostList::defer_gpu_write
    path, so the late waits and settles order a CPU reader behind the flight that may write them.
  • The title's free/decommit/release path, VirtualProtect (intercepted unconditionally) and
    XMemFreeDefault's raw VirtualFree let placed copies go before the kernel call.
  • The section view is refcounted and keeps the section's pages alive after the title unmaps its
    view and closes its handle (WARP test). Scattered or uncommitted ranges are refused, never
    guessed.
  • ID3D12Device13 is probed once per process; without it every placement is refused as
    HostUnavailable and copies are made as before.

Validation

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

Check Result
cargo check --workspace --all-targets --locked PASS (58.6 s, no warnings)
cargo check --workspace --all-targets --all-features --locked PASS (49.8 s, no warnings)
cargo clippy -p victory-gpu -p victory-hle --all-targets --locked -- -D warnings only the pre-existing clippy::manual_is_multiple_of in shadow.rs (same at base)
cargo test locally not runnable here (GNU raw-dylib needs a working dlltool; no MSVC in this VM)

GitHub Actions windows-latest (WARP), on temporary ci/** workflow branches of the fork (the
workflow file is the only extra file; nothing is pushed to this repository):

Run Result
Baseline 63b902f (run 46122898345) build check PASS; tests 452 passed, 1 failed, 36 ignored
RAM/VRAM separation (run 46128591582) build check PASS; tests 460 passed, 1 failed, 36 ignored
Copy-bridge final (run 46139316939, source tip d04af6e) build check PASS; tests 470 passed, 1 failed, 36 ignored

The one failure is the same at baseline and here:
pipeline::host::tests::depth_bounds_pipeline_loads_and_filters_draws - WARP does not implement
depth bounds. All 18 tests added by this project pass; the run's overall conclusion is "failure"
only because of that inherited baseline test. The three commits after the tested source tip
(966569d, d55612c, 4fb7197) change documentation and comments only.

What is not claimed

WARP and GetHeapProperties prove the creation heap class the API reports, not physical
residency. Not established here: opened-heap acceptance and pinning on the target driver, physical
residency and WDDM paging, coherency of GPU access to title system memory under the real relay,
PCIe cost against the copies replaced, the openable share of the real title memory, and
device-removal/TDR behaviour. Section 2 above is the run that establishes them.

Commits

  • 8dae978 audit and ownership rules (docs)
  • 48b9888 separation implementation, accounting fixes, tests
  • 60e8281 separation verification and window-budget audit (docs)
  • a7f0bcc copy-bridge audit and plan (docs)
  • a2539df backing/admission invariants, exact placed-copy invalidation, ledger
  • da24c3f page-pool direct-access prototype
  • 7791fa5 migration of the refused copies (buffers, windows, view bytes)
  • 65930a4 placed-write declarations and lifecycle hooks
  • 72ae9a9 shared page-pool regions and the record of remaining copies (docs)
  • 6ec7534, f3ee38f, f108638, d04af6e test fixes found by CI
  • 966569d final verification record (docs)
  • d55612c restore the phase records the copy-bridge document lost (docs)
  • 4fb7197 in-place notes no longer claim a removed flight gate (comments)
**@⁠CwWwWwW** on GitHub · 2026-11-28 09:02 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/916) `CwWwWwW:feat/gpu-memory-separation` → `main` · +3551 −242 · 11 files · 16 commits · closed without merging ## What this is This PR carries the whole GPU-memory project on top of `63b902f`: **16 commits, 11 files, +3551/-242**. Its first revision was the system-RAM/VRAM separation audit and the accounting fixes. This revision continues it with the **copy-bridge project** - the part that finds which of the layer's host copies exist only because the host cannot see the title's memory, and removes them where the GPU can be given the title's own bytes instead. One branch, one PR. **No default changes anywhere**: every direct-access path is opt-in and off by default, and with the switches unset the product path is exactly the base behaviour. 1. **RAM/VRAM separation** (commits 1-3, unchanged from the first revision): the explicit memory-domain model, the placement ledger, the verified accounting fixes, the window/texture budget audit, and the verification record (`docs/memory-separation.md`, `docs/memory-separation-window-budget.md`). 2. **Copy bridges** (commits 4-16): the complete audit and classification of every copy (`docs/copy-bridges.md`), the backing/admission invariants that make a direct placement decidable on the same evidence as the fallback it replaces, the page-pool direct-access prototype, the migration of the copies the policy refuses, the coherence/lifetime wiring, and the removal plus the record of what remains. --- # How to proceed after this PR This section is for reviewers and whoever picks the work up next. The PR is deliberately the foundation, not the end state. ## 1. Merging this PR This is safe to merge as-is: - every switch is off by default and no policy, threshold, budget, launcher default or rendering behaviour changes with them off (the base behaviour is unchanged); - required copies (carded VRAM copies, by-address shader memory, layout/format-dependent textures, D3D12 infrastructure) are untouched - the audit records each one and why it stays; - the added code is exercised by 18 new tests on the software adapter (WARP). Two inherited CI conditions are *not* caused by this branch and should not block the merge: the repository's clippy gate is already red at `63b902f` for pre-existing lints, and the WARP test suite has one baseline failure (`depth_bounds_pipeline_loads_and_filters_draws`). The build check and all tests this branch adds pass; exact runs are in "Validation" below. Fixing the baseline lints is a mechanical follow-up outside this change. Concretely, the current head's CI run (46145621108) fails in its Clippy step on exactly two lints, both of which fail identically on a clean `63b902f` tree with the same command: `victory-shader/src/emit/mod.rs:2768` (`let_and_return`) and `victory-gpu/src/shadow.rs:1861` (`manual_is_multiple_of`, the base's `shadow.rs:1708` moved by this diff). Because the Clippy step fails first, the diagnostics build and Tests steps are skipped, as in the first revision. Neither lint is added by this change. ## 2. Next: validate on the target NVIDIA hardware Everything below needs a person with the target GPU, driver and game build. Run it after this PR is merged (the switches exist on the base path, so validation can also be done on this branch). Record the exact GPU, driver, game build/save, switch values and logs; open one follow-up PR with the record in `docs/copy-bridges.md` §17 and one per resulting code change. 1. **Baseline ledger.** Run the title save with `VICTORY_MEMORY_REPORT=1` and no direct switches. Keep the placement ledger and the created-resource setup as the reference. 2. **Openability census.** Run with `VICTORY_INPLACE_PROBE=1` (level 2 also opens one part for a moment). The census reports which title memory is private/committed, one contiguous section run, or scattered/holed, and which part of it can be opened as a host heap. This number decides how much of the removable mirror class will actually go away. 3. **Direct path on, same save.** `VICTORY_INPLACE_VIEW=2 VICTORY_MEMORY_REPORT=1` (page pool windows, title buffers and view-byte copies), and separately `VICTORY_INPLACE=3` (private memory). Check: visuals, save/load, no crash or device removal; the ledger shows direct-backed bytes per class and the refusal reasons that remain. 4. **Coherency under the real relay.** With submissions in the air (the defaults), confirm that placed shader writes are visible to a CPU reader only after the wait, and that CPU writes before a dispatch are visible to the GPU. The declaration path is unit-tested; the ordering under a live relay needs the run. 5. **Cost A/B.** Same save with the switches off and on: frame time plus a GPUView/ETW capture. Direct access is not automatically faster than a copy into local VRAM; only measurement decides whether a default is worth it. 6. **Failure and lifetime.** Exercise title free/decommit/protect paths while placed, and a device removal/TDR, and confirm the fallback path takes over and no title-visible call fails in a way the code does not record. If any step shows a defect, the answer is to keep the switches off and report it - not to lower the evidence bar. ## 3. Decision gates after validation | Observation | Decision | |---|---| | Census: large share of title memory openable, no defect in steps 3-6, A/B neutral or better | enable `VICTORY_INPLACE_VIEW` per class (one class at a time, each its own commit/PR) | | Driver refuses opened heaps, or opening pins too much / working-set cost is unacceptable | keep off; record the refusal reason; the mirror path stays the product path | | Coherency or lifetime defect | fix as a defect first; do not enable | | PCIe cost worse for a class | leave that class carded as today (memory-class rule) | | Physical residency/paging unmeasurable on the target | do not claim it; do not default on it | ## 4. Then remove code (the remaining deletion tasks, in order) 1. **Unify the port's own region bookkeeping with the shared registry** (`port.rs`). No hardware needed; pure refactor with the existing WARP tests. Removes the last duplicate mapping-lifetime code; documented as a follow-up, not a copy bridge. 2. **Legacy in-place levels 1/2 and the write-combined / second-side experiments** (`VICTORY_CARD_ALL`, `VICTORY_WINDOWS_OWN`, `VICTORY_SEND_BAR`, `VICTORY_WINDOWS_BAR_MB`, `VICTORY_WC_BAR`). Delete only after the hardware A/B shows the fallback substitution is equal or better wherever the memory is openable; today they are the A/B apparatus. 3. **Per-class default enablement** of `VICTORY_INPLACE_VIEW` after §2/§3. Once a class is on by default, its mirror branch is provably unreachable and can be deleted with the release note. 4. **Multi-run composition** for scattered/holed view memory. Needs a driver experiment opening several runs/heaps; only then can the scattered-memory mirror class go. 5. **Texture/target/depth subset** after a layout census and probe (row-major, single-level linear subset first). Only that subset's mirror and staging are deleted. 6. **Carded copies stay.** Replacing a device-local side with system-memory access is a memory-class downgrade; only a measured PCIe-vs-VRAM study could justify it, and this project does not. Do not delete a bridge because its source and destination hold similar bytes; every removal above has a stated replacement, a test, and a fallback. The current required/unresolved list, with the reasons, is `docs/copy-bridges.md` §10 and §16.2. --- # The change in detail ## The audit: which copies are avoidable, and which are not `docs/copy-bridges.md` inventories every copy and intermediate allocation with its source, destination, callers, why it exists, whether the title's backing is openable, and what a removal must preserve. The classification: - **Removable now**: the look-ahead buffer cache and the write-combined/mapped-VRAM experiments (switch-controlled shortcuts) and the second system-memory sides. Kept as switches until §4.2. - **Removable after a prerequisite**: the system-memory mirrors of title buffers, windows and view-byte copies (the largest class by bytes), plus the layout-compatible texture subset and the target/depth class after separate evidence. - **Required**: carded copies, by-address shader memory, textures/targets that exist for layout/format/depth reasons, and the D3D12 infrastructure. None is touched. - **Unresolved**: overlapping placed resources and D3D12 aliasing barriers, driver coherency and pinning, multi-run composition, a device-local by-address arena, WDDM residency and PCIe cost. ## What the copy-bridge project changes **Direct access instead of a copy, only for the copies the policy already refuses a VRAM side.** `inplace::place_fallback` is asked by the buffer, window and view-byte copy paths exactly where the device-local admission has already refused the copy (a carded copy is never replaced by a memory-class downgrade). It opens the title's own memory as a host heap: - **page-pool/view memory**: our own view of one contiguous committed run of one section, `OpenExistingHeapFromAddress1` on that view, a cross-adapter UAV buffer placed over it - at any address, not just the old sub-4-GiB port range. One view and one heap are shared per section run, not per copy. - **private memory**: a committed part of the title's own allocation, opened the same way. A placed copy has no staging buffer, no mirror, no card side, no hash twin, no send/fetch state, no refresh, no snapshot and no copy-back: the GPU reads and writes the title's pages. **Switches (all off by default)** | Switch | Default | Effect | |---|---|---| | `VICTORY_INPLACE_VIEW` | 0 | 1: place page-pool windows over our view of their run; 2: title buffers and view-byte copies too | | `VICTORY_INPLACE` | 0 | 3 and up: substitute the fallback placements for copies that would stay in system memory (levels 1/2 keep their old "place anywhere openable" meaning) | | `VICTORY_INPLACE_MB` | 4096 | cap on title bytes in place at once (opening pins pages) | | `VICTORY_INPLACE_PROBE` | 0 | 1: probe plus the openability census; 2: also opens one part | Every refusal (not openable, scattered, holes, cap, host refused, no `ID3D12Device13`) is counted with its reason in the placement ledger and falls back to exactly the old copy path. **Coherence and lifetime** - A placed copy's shader writes are declared through the existing `HostList::defer_gpu_write` path, so the late waits and settles order a CPU reader behind the flight that may write them. - The title's free/decommit/release path, `VirtualProtect` (intercepted unconditionally) and `XMemFreeDefault`'s raw `VirtualFree` let placed copies go **before** the kernel call. - The section view is refcounted and keeps the section's pages alive after the title unmaps its view and closes its handle (WARP test). Scattered or uncommitted ranges are refused, never guessed. - `ID3D12Device13` is probed once per process; without it every placement is refused as `HostUnavailable` and copies are made as before. ## Validation Local, Windows, Rust 1.98.1 x86_64-pc-windows-gnu (2026-11-28): | Check | Result | |---|---| | `cargo check --workspace --all-targets --locked` | **PASS** (58.6 s, no warnings) | | `cargo check --workspace --all-targets --all-features --locked` | **PASS** (49.8 s, no warnings) | | `cargo clippy -p victory-gpu -p victory-hle --all-targets --locked -- -D warnings` | only the **pre-existing** `clippy::manual_is_multiple_of` in `shadow.rs` (same at base) | | `cargo test` locally | not runnable here (GNU raw-dylib needs a working `dlltool`; no MSVC in this VM) | GitHub Actions `windows-latest` (WARP), on temporary `ci/**` workflow branches of the fork (the workflow file is the only extra file; nothing is pushed to this repository): | Run | Result | |---|---| | Baseline `63b902f` (run 46122898345) | build check PASS; tests **452 passed, 1 failed, 36 ignored** | | RAM/VRAM separation (run 46128591582) | build check PASS; tests **460 passed, 1 failed, 36 ignored** | | Copy-bridge final (run 46139316939, source tip `d04af6e`) | build check PASS; tests **470 passed, 1 failed, 36 ignored** | The one failure is the same at baseline and here: `pipeline::host::tests::depth_bounds_pipeline_loads_and_filters_draws` - WARP does not implement depth bounds. All 18 tests added by this project pass; the run's overall conclusion is "failure" only because of that inherited baseline test. The three commits after the tested source tip (`966569d`, `d55612c`, `4fb7197`) change documentation and comments only. ## What is not claimed WARP and `GetHeapProperties` prove the creation heap class the API reports, not physical residency. Not established here: opened-heap acceptance and pinning on the target driver, physical residency and WDDM paging, coherency of GPU access to title system memory under the real relay, PCIe cost against the copies replaced, the openable share of the real title memory, and device-removal/TDR behaviour. Section 2 above is the run that establishes them. ## Commits - `8dae978` audit and ownership rules (docs) - `48b9888` separation implementation, accounting fixes, tests - `60e8281` separation verification and window-budget audit (docs) - `a7f0bcc` copy-bridge audit and plan (docs) - `a2539df` backing/admission invariants, exact placed-copy invalidation, ledger - `da24c3f` page-pool direct-access prototype - `7791fa5` migration of the refused copies (buffers, windows, view bytes) - `65930a4` placed-write declarations and lifecycle hooks - `72ae9a9` shared page-pool regions and the record of remaining copies (docs) - `6ec7534`, `f3ee38f`, `f108638`, `d04af6e` test fixes found by CI - `966569d` final verification record (docs) - `d55612c` restore the phase records the copy-bridge document lost (docs) - `4fb7197` in-place notes no longer claim a removed flight gate (comments)
docs/memory-separation.md is the Phase 1 audit of where the layer's memory lives
and how the two domains are crossed. It records, with file:line evidence from
63b902f:

- the heap classes the layer creates: device-local DEFAULT (textures, targets,
  depth twins, pooled textures, card sides and hash twins, by-address arenas,
  indirect scratch), system-memory CUSTOM/WRITE_BACK/L0 (single-side copies, CPU
  staging, the GPU-to-CPU channels), UPLOAD staging, READBACK, CPU-mapped VRAM and
  opened title memory (both opt-in), and driver-managed memory that D3D12 does
  not let the application place;
- the resource classification: CPU-owned title memory and staging; GPU-owned
  device-local resources; explicit cross-domain transfers in both directions
  (write-watch and send snapshots for CPU->GPU, on-card compare/fetch/merge and
  texback for GPU->CPU); the justified CPU-visible exceptions; and placement that
  cannot be established from source;
- the budget rules that decide whether a title buffer gets a VRAM side
  (card_limits, the admission line, the window and by-address caps), including
  the launcher's VICTORY_CARD_BUFFERS_MIN_KB=64;
- the verified remaining gaps: single-side buffer/window copies and their
  permanent refusals, the by-address lifetime-cap accounting defect, unreported
  fallbacks and the absence of any heap-property check, the GPU-to-CPU channels
  kept in system memory, device-removal waits without a completed-value re-check,
  no room test for render targets/depth/twins, latching texture refusals, and
  WDDM paging of DEFAULT resources that only real hardware can show.

No behaviour change: allocation, transfer and synchronization paths are untouched.
The ported title's GPU memory is console unified memory: the host copies the layer
makes decide what the GPU actually reads. This commit audits that boundary and
makes it explicit and measurable, without changing the placement policy.

Placement ledger (residency.rs): every host buffer made by the copy and transfer
machinery is classified from the heap ID3D12Resource::GetHeapProperties reports
(device-local, CPU-visible, staging, readback, CPU-mapped VRAM, other) and
counted; every shadow copy without a device-local side is counted while it lives
and when it goes, by reason (budget line, byte cap, allocation failure, host
unavailable, not eligible, switch off, a view's own bytes). A "memory placement"
line every five seconds (VICTORY_MEMORY_REPORT=1 forces it, =0 silences it)
compares those figures with the DXGI local/non-local budget and usage. That is
the measurement base; its class figures are creation totals of buffers only, and
the docs say so.

Verified fixes, no allocation-policy change:
- shadow::by_address reserved its lifetime cap before testing it and never
  released it on drop: after enough raw-address memory, new arenas silently
  stayed in system memory although VRAM was free. The cap is now taken atomically
  only when the whole size fits, rolled back on allocation failure, and released
  by Shadow::drop.
- The windows' device-local cap (WINDOW_CARD_BYTES) no longer takes system-memory
  fallbacks or by-address arenas: a VICTORY_WINDOWS_OWN second side, a by-address
  fallback and a by-address device-local arena no longer leak or misuse the
  window budget; each copy records what it added and gives it back, and
  by-address bytes count only against their own cap while still appearing in the
  reported live total.
- card_back, relay_card_back and the settle wait re-check the fence's completed
  value instead of trusting an INFINITE wait on a device that may be removed: a
  removed device fails the run instead of merging stale bytes.
- Windows refused a device-local side are counted (the five-second line prints
  them); the texture queue's room line prints the alive window and by-address
  device-local bytes beside its weighing (not in it); the host-pressure warning
  reports VRAM copies and system-memory fallback copies separately.
- One startup line lists the separation-relevant VICTORY_* switches this run has
  set, and warns for the documented unsafe or weakening ones: a parsed
  VICTORY_INPLACE level 1/2, level 2 with submissions in the air, the port and
  in-place paths, CPU-mapped VRAM, VICTORY_CARD_ALL and VICTORY_WINDOWS_OWN
  second sides, VICTORY_RELAY_COPY without VICTORY_FETCH_CHECK, VICTORY_SEND_OWN=0
  or a failed send snapshot, and VICTORY_INDIRECT_CARD_BUDGET=0. Nothing is
  gated; the warnings make the exceptions visible in every log.
- The stale comments for the window budget, relay default, Card::before, the
  in-place level-2 reachability and the texture-room reservation are corrected
  to what the code does.

Tests: eight unit/device tests cover the API-reported heap classes
(GetHeapProperties), fallback live/total counts, the MiB conversion, the
by-address cap fit and release, the window side's release, and the parsed INPLACE
level the warning uses. Local cargo check passes with default and all features;
clippy fails only on the pre-existing manual_is_multiple_of lint that fails the
same way at 63b902f. On GitHub Actions windows-latest (WARP) the workspace tests
ran 460 passed, 1 failed, 36 ignored; the one failure is the pre-existing
depth-bounds test that also fails at baseline (452/1/36). WARP and
GetHeapProperties prove creation heap class, not physical residency: the docs
state the limitation and the hardware runs needed.
docs/memory-separation.md gains the Phase 3 record: the exact local and CI checks
and outcomes, the comparison with baseline 63b902f, what they prove
(compilation, API-reported creation heap classes, accounting units and release
paths, no new test failures, default placement policy unchanged) and what only
NVIDIA hardware can show (physical residency, WDDM paging, PCIe fallback cost,
budget-move effects, GPU_UPLOAD and opened heaps, torn fetches, device removal);
every Phase 1 gap now carries its status at the final code.

docs/memory-separation-window-budget.md is the focused follow-up report: how
window buffers are admitted and accounted against textures, render targets,
depth resources and card copies, which budget sources are live, whether windows
can starve them (they cannot by themselves; the real budget gaps are named),
failure and recovery behaviour, the counter defects fixed in this branch, the
exception matrix for every separation-relevant switch and path, the changes
made, the validation table, the hardware limitations and the deferred
recommendations that need measurement before any policy change.
Phase 1 of the direct-backing work: a complete audit of the copies and
intermediate allocations between title memory and the host GPU, from every
constructor and copy site backwards to the resource it serves.

The document inventories the title-memory kinds and their openability, the
buffer/window mirror and card machinery, the texture path, and the D3D12
infrastructure that only looks like a copy. It records for each bridge the
source and destination, why it exists, what requires it, whether direct
access to the original backing is possible and under which bounded
prerequisite, the synchronisation/lifetime guarantees a removal must
preserve, and the evidence still needed; it classifies each as removable now,
removable after a prerequisite, required, or unresolved.

The ranked plan it states: Phase 2 backing-storage and admission invariants;
Phase 3 a page-pool window placement prototype through our own section view;
Phase 4 migration of the refused system-memory copies (windows, buffers,
view bytes) with the mirror as fallback; Phase 5 placed-write declarations,
overlap policy and synchronous revoke before the title's free/protect;
Phase 6 removal of the superseded mechanisms and documentation of the copies
that remain.

The audit is source analysis plus the repository's own WARP evidence; no
NVIDIA hardware was available and no physical-residency, PCIe-cost or
target-driver claim is made. docs/copy-bridges.md is the deliverable.
Phase 2 of the copy-bridge work: the invariants a direct placement needs,
without changing any allocation policy.

- Split the device-local-side decision from its allocation (card_admission /
  window_admission, card_allocate / window_allocate, card_side / window_side).
  lookup and loose ask the admission first, so a direct placement can replace
  exactly the copies the policy would have kept in system memory, before any
  host buffer is made for them. Same rules, counters and logs as before.
- Add inplace::openability: private committed whole, one run of one section
  (the opening the page pool needs), or refused with a reason (unmapped,
  scattered, holes), classified without opening anything. place_for uses it.
- Keep the placed copies in a weak registry and let a mapping change invalidate
  them exactly. The old bounded table scans could miss a covering placed copy
  (a big title buffer starting far below, with more copies in between than the
  scan looks at).
- Give our own section views one owner: inplace::SectionView, refcounted by the
  placed buffers that hold it, unmapped after the last of them and its heap.
  The port's regions use it, and a section close now forgets the port's regions.
  The port WARP test now really exercises "the title's views may change under
  the heap" (protect, unmap, read, section close) instead of skipping it.
- Count directly backed copies (live and total, windows and title buffers) and
  the refused direct asks by reason in the placement ledger; the memory
  placement line prints them and is printed while a direct copy lives.
- Tests for the openability predicate, the section view's last-holder unmap,
  the placed-copy invalidation among many copies, and the direct accounting.

No default, threshold, budget or rendering change; with the direct switches off
the same buffers are made in the same order as at the base.
Phase 3 of the copy-bridge work: the first direct-access prototype for the
memory the port could not reach - the page pool's view memory, at any address.

inplace::place_view_part maps our own view of the one contiguous section run
that holds a window, checks its pages committed, opens a heap on the view with
OpenExistingHeapFromAddress1 and places a cross-adapter UAV buffer over the run;
Shadow::placed then binds it like any copy with refresh, snapshot, declaration
and copy-back no-ops for it. inplace::place_view is the policy: the new
VICTORY_INPLACE_VIEW switch (1 windows, 2 also title buffers), the in-place byte
cap measured on the pinned view bytes, and a gate that only tries while no
submission can be in the air (a placed copy declares no shader writes yet, so
the layer's own CPU reads of title memory cannot be ordered against a flight's
writes through it; Phase 5 replaces the gate with declarations).

shadow::loose tries it only after the device-local admission refused the
window, so no VRAM-carded copy is replaced by system-memory access; a placed
window makes no staging buffer, no card side and no copy machinery, and the GPU
reads and writes the title's own pages over PCIe, the same memory class the
refused window stayed in. Refusals are counted with their reason.

Tests: a WARP test over a placeholder above 4 GiB with two title views - the
card reads the title's bytes across both, writes show in the title's views, the
title's views may be protected or unmapped under the heap, and our view is
unmapped with the last holder; a scattered range and private memory are
refused. Check and clippy as at the base.
Phase 4 of the copy-bridge work: migration of the copy class the audit ranked
removable - the copies the policy kept in system memory - behind switches, with
the mirror as the fallback.

inplace::place_fallback is asked by lookup (title buffers), loose (windows) and
exact (view bytes) exactly where the device-local admission has already refused
the copy. It tries the page pool's view memory (VICTORY_INPLACE_VIEW: windows at
1, title buffers and view-byte copies at 2) through the Phase 3 mechanism, then
private memory (VICTORY_INPLACE=3 and more) through the first mechanism's part
opening. A placed copy makes no staging buffer, no card side, no hash twin and
no send/fetch state; the GPU reads and writes the title's own pages, i.e. the
memory class the refused copy would have been in, so no VRAM-carded copy is ever
replaced.

VICTORY_INPLACE 1 and 2 keep their old meaning and are no longer taken from 3
on: from 3 the placement only substitutes the refused copies. Both paths are
refused while a submission can be in the air (the placed-write declarations that
will lift that are Phase 5). The decision is the pure fallback_paths function,
unit-tested over the switch matrix; every refusal is counted with its reason and
the startup line names the switches and why they may be inert.

Check and clippy as at the base.
Phase 5 of the copy-bridge work: coherence and lifecycle safety for the direct
placements.

- A placed copy's shader writes are declared through the copy machinery's
  existing defer_gpu_write path (Shadow::gpu_writes marks the copy written and
  records the range). The late waits and settles then order a CPU reader of
  those title bytes behind the flight that may write them, which is what the
  old "unsupported with submissions in the air" note was about; the fallback
  placements' flight gate is removed with it. The pre-existing shortcut for a
  host copy of the same bytes written through a different copy is unchanged and
  stays documented.
- The title's free/decommit/release hook now lets placed copies go before the
  kernel call; VirtualProtect is intercepted unconditionally and does the same;
  XMemFreeDefault's raw VirtualFree for 32-bit title allocations too.
- The part-opening call is probed once per process; a run without it refuses
  placements as HostUnavailable (counted) and copies as before.
- The page-pool route is the safe migration: a heap on our own section view
  leaves the title's own views, placeholders, frees and protects alone, and our
  view keeps the section's pages alive. A WARP test proves the pattern survives
  the title unmapping its view and closing the section handle; the private-page
  placement keeps its documented exception and the startup warning says so.
- Tests: the placed declaration reaching a host list's deferred steps (WARP) and
  the section lifetime (WARP).

Check and clippy as at the base.
Phase 6 of the copy-bridge work: the removal and the record of what stays.

- The page-pool placement no longer opens one view and one heap per placed
  copy: inplace keeps one SectionView and one heap per title run of a section
  and the placements in it place their buffers into that heap. The run is
  forgotten when the title shows other pages there, and the view stays mapped
  while a placed buffer holds it. A run over 512 MiB is still cut to the
  placement that asked, since opening a heap locks its pages. The WARP test now
  asserts the sharing and the forget.
- docs/copy-bridges.md section 16 records every copy bridge that remains and why
  (the VRAM class, memory that cannot be opened, by-address shader memory,
  textures and targets for layout and format reasons, depth twins, the D3D12
  infrastructure, the title's own CPU steps, and the off-by-default experiments
  the direct path supersedes wherever the memory can be opened), and states the
  end state and what a hardware-validated run must establish before any switch
  becomes a default.

Check and clippy as at the base.
The test asserted the pages were freed right after the invalidation, but host::retire keeps the copy for the bury lag even when nothing runs; assert only the invalidation (the table is cleared), which is what the test is about. The direct-copy accounting test moves to the window slot no other test places into.
The fallback substitution at VICTORY_INPLACE=3 and more declares its writes and is not the early mechanisms' unsupported combination with submissions in the air, which the test still asserted.
The new tests that map sections and placeholders touch process-wide memory mappings; running them concurrently with the software-adapter device tests is the one difference from the serial run that passes, so they take the same test turn.
The test unmapped the title's view and then compared the card's bytes against that title range on the CPU: reading an unmapped placeholder faults, which killed the test process with an access violation. Read the bytes before the unmap and compare the saved copy. Record the verification: a local Windows experiment shows a section page's commit is shared by its views and survives unmapping one, and the WARP test now proves the placed buffer keeps reading the section's pages under a title view change and a section close.
The CI run of the final source tip (46139316939, WARP) passes the build check and the workspace tests with the one baseline failure: 470 passed, 1 failed, 36 ignored, against the recorded baseline of 452 passed, 1 failed, 36 ignored. The added tests are the ones this branch documents.
The document lost the tail of the Phase 3 record (13.2-13.4) when the Phase 4
record was written over it, then lost the Phase 4 record to Phase 5's, the
Phase 5 record to Phase 6's, and the Phase 6 record to the verification section:
every phase edit after section 13.1 started at the same line ("memory, at any
address. It is behind its own switch, off by default.") and replaced everything
to the end of the file.

This restores the Phase 3 tail and the Phase 4, 5 and 6 records from the commits
that wrote them (da24c3f/7791fa5, 65930a4, 72ae9a9), reconciled with the final
code: the flight gate and shadow::flights_air no longer exist, NoDirect::InFlight
was removed with them, the fallback-policy test lost its gate cases and is no
longer named for them, and the source tip the CI run tested is now recorded next
to the results. The document runs 12-17 without a gap, so section 17's reference
to 16.3 resolves, and its closing sentence points at the hardware list in
sections 11 and 16.3.

docs/copy-bridges.md only.
Phase 5 removed shadow::flights_air and the placement gate and declared the
placed copies' shader writes, but five notes still described the gate: the
VICTORY_INPLACE_VIEW switch's comment, place_private's "no switch or flight
gate", place_view_checked's path note, shadow::loose's placement comment, and
inplace_notes' reason for excluding level 3 from the unsupported combination
(which still said a level-3 placement was gated off). They now say what the code
does.

Comment-only; no compiled behaviour changes, and the workspace check result is
unchanged.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-28 14:30:14 +00:00
github-bot closed this pull request 2026-11-28 19:31:19 +00:00
Author
Owner

@⁠trustno1-coder on GitHub · 2026-11-28 19:28 UTC · original

Thanks for this. I'm closing it without merging: at about 3,500 lines it conflicts with the current main in 12 places across host.rs, shadow.rs, residency.rs and resource.rs, the core of the memory code, and I can't resolve that safely on your behalf. If you'd still like it in, please rebase it on the current main, ideally split into smaller steps, and open a new pull request.

**@⁠trustno1-coder** on GitHub · 2026-11-28 19:28 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/916#issuecomment-7244572497) Thanks for this. I'm closing it without merging: at about 3,500 lines it conflicts with the current main in 12 places across host.rs, shadow.rs, residency.rs and resource.rs, the core of the memory code, and I can't resolve that safely on your behalf. If you'd still like it in, please rebase it on the current main, ideally split into smaller steps, and open a new pull request.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/trustno1-coder--VIctory-NVIDIA!916
No description provided.