mirror of
https://github.com/trustno1-coder/VIctory-NVIDIA.git
synced 2026-12-06 09:08:35 +00:00
GPU memory: record the audit of the memory split and the copy bridges
The previous two commits change where copies live and where they are made; this one writes down what they were measured against, what they removed, and what a real-hardware run still has to establish. - docs/memory-separation.md: the platform model (console unified memory vs the host's two domains), the heap classes as the API reports them, ownership rules, how a copy is admitted (card_admission / window_admission and the budget lines), the placement ledger and how to read it, the direct-access path and its switches, the transfer and synchronisation contract, what main already fixes from other forks and what this work adds, and what only an NVIDIA run can establish. - docs/memory-separation-window-budget.md: the window device-local budget (window_card_most, window_line, card_copy_fits, WINDOW_CARD_BYTES), what is charged to it - a second system-memory side is not (fixed here) - the by-address arena budget separation, the exception matrix, what the ledger shows for windows, and the hardware-only questions. - docs/copy-bridges.md: the inventory and classification of every copy bridge: title buffers, windows, view-byte copies, by-address arenas, textures, targets/depth/read-backs, D3D12 infrastructure, the title's own CPU steps and the experiment switches; the direct-access mechanism implemented in the previous commit (openability, SectionView, shared regions, place_fallback, declared placed writes, lifetime hooks, the switches); the copies that remain and why; the follow-ups; what a hardware run must establish; the verification record. No source change: documentation only.
This commit is contained in:
280
docs/copy-bridges.md
Normal file
280
docs/copy-bridges.md
Normal file
@ -0,0 +1,280 @@
|
||||
# Copy bridges: the host copies between title memory and GPU backing
|
||||
|
||||
The title's GPU memory was unified memory on the console: a GPU address is a CPU address, and the
|
||||
title's CPU steps and shaders touch the same bytes. On the PC the layer runs the title's code
|
||||
natively against host D3D12, and the host has two memory domains: system RAM and the card's local
|
||||
VRAM. Every place where the layer has to reproduce "the GPU sees this memory" with a copy or a
|
||||
mediating resource is a copy bridge. This document inventories them, classifies the ones are that
|
||||
removable and the ones that are not, records what this work placed directly over the title's own
|
||||
backing, and states what a real-hardware run still has to establish.
|
||||
|
||||
## 1. The model in one page
|
||||
|
||||
- The layer makes host copies of title memory for the host GPU. A copy can be single-sided (one
|
||||
buffer in the PC's memory that shaders read and write over the bus) or two-sided (a CPU-visible
|
||||
mirror plus a device-local side, with refresh, sends, compare and copy-back).
|
||||
- A copy exists because the host GPU cannot address the title's memory *unless the layer opens it as
|
||||
a host heap*. The title's memory is pagefile-backed sections mapped as views at the title's
|
||||
addresses, so part of it is openable: private allocations committed whole, and views of one
|
||||
contiguous run of one section. `crate::inplace::openability` decides which.
|
||||
- The decision to give a copy a device-local side is `shadow::card_admission` (title buffers) and
|
||||
`shadow::window_admission` (windows), made before anything is allocated. A refusal is why the
|
||||
copy stays in system memory, and it is counted in the placement ledger (`residency::Fallback`).
|
||||
- Where the policy refused a device-local side, the GPU's memory class is system memory either way.
|
||||
`crate::inplace::place_fallback` then places the copy directly over the title's own bytes
|
||||
instead of over a mirror of them, behind switches that are off by default. The mirror remains the
|
||||
fallback for every refusal.
|
||||
- Every remaining copy has a function the removal cannot provide: a device-local memory class, a
|
||||
layout or format conversion, address translation for raw-address shaders, or the D3D12
|
||||
infrastructure itself.
|
||||
|
||||
## 2. Method and evidence classes
|
||||
|
||||
Three kinds of evidence appear below:
|
||||
|
||||
- **[source]**: the copy exists in the tree at a named function; the entry states its source,
|
||||
destination, callers and why it exists, read from the source.
|
||||
- **[run]**: a measurement or a run observation recorded in the tree's docs or module comments.
|
||||
- **[warp]**: established by a test on the software adapter; it proves the mechanics of this layer,
|
||||
not a driver's or the hardware's behaviour.
|
||||
|
||||
No NVIDIA-hardware claim is made in this document. Section 9 lists what only such hardware can
|
||||
establish.
|
||||
|
||||
## 3. Title memory kinds (the backing side)
|
||||
|
||||
- **Private memory**: `XMemVirtualAlloc`'s allocations; committed whole and openable as a part of
|
||||
the allocation (`inplace::place_private`).
|
||||
- **Page-pool / view memory**: sections `xmem` makes for the title's physical pages, of which the
|
||||
title maps views at its addresses. A contiguous range in one run of one section is openable
|
||||
through our own view of the run (`inplace::SectionView`, `inplace::native_stretch`);
|
||||
scattered pages or holes are refused.
|
||||
- **Reserved, guarded, decommitted or otherwise unmapped memory**: not openable; a copy.
|
||||
- **The title's own view changes**: remapping, unmapping, protect changes and section closes are
|
||||
reported to the layer (`title_memory_view`, `title_memory_section`, `title_memory_changed`);
|
||||
the in-place tables and the placed copies are let go on those notifications.
|
||||
|
||||
## 4. Inventory
|
||||
|
||||
### 4.1 Title buffers (`shadow::lookup`)
|
||||
|
||||
A title buffer's host copy is one of:
|
||||
- two-sided, when `card_admission` admitted a device-local side: `Host::shared_buffer` (or the
|
||||
private `CardCpu` mirror, `VICTORY_CARD_CPU_HEAP`) as the CPU's side and
|
||||
`Host::uav_buffer` as the card's (`buffer_sides`), maintained by the copy machinery's refresh,
|
||||
sends, hash compare on the card and fetch/copy-back;
|
||||
- single-sided in system memory, when admission refused: one shared buffer, read and written by
|
||||
shaders over the bus;
|
||||
- directly placed, when admission refused and `place_fallback` found the backing openable and the
|
||||
switches ask for it: a buffer placed over the title's own memory, no host copy at all.
|
||||
|
||||
### 4.2 Windows outside buffers (`shadow::loose`, `made_window`)
|
||||
|
||||
Windows are title memory outside any buffer object: vertex/index streams, constants and everything
|
||||
else a draw reads from the title's allocator. Their side is chosen by `window_admission`
|
||||
(device-local) or by the CPU-mapped-VRAM experiment `window_mapped_for`, otherwise a shared
|
||||
buffer; a window's card side can be deliberately late (`card_late`). A window the policy refuses a
|
||||
device-local side is placed directly over the title's backing where openable. Their budget is
|
||||
`docs/memory-separation-window-budget.md`.
|
||||
|
||||
### 4.3 View-byte copies (`shadow::exact`)
|
||||
|
||||
A view's own bytes (a buffer view past its buffer's end, a raw view) get a copy of their own in
|
||||
system memory, pooled by size (`ExactStore`). They are system memory by design; moving them onto
|
||||
the direct path needs a change to the new exact pool and is left as a follow-up (section 8).
|
||||
|
||||
### 4.4 Memory by raw GPU address (`shadow::by_address`)
|
||||
|
||||
The title's memory addressed by raw shader addresses (the BVH/ray-tracing arenas): a two-sided copy
|
||||
with `changes_only` sends, capped by `ARENA_CARD_BYTES`/`arena_card_most`
|
||||
(`VICTORY_MEMORY_CARD_MB`); past the cap the side shaders see is in the PC's memory. Raw-address
|
||||
shaders need a GPU virtual address that a title CPU address cannot be, so this copy is required
|
||||
until a device-local by-address arena exists (unresolved, section 8).
|
||||
|
||||
### 4.5 Textures
|
||||
|
||||
Textures have no single bridge. `texture.rs` keeps host copies whose contents are detiled from the
|
||||
title's tiled layout into a staging buffer and copied into the host texture when the write watch (or
|
||||
a whole-memory hash for physical-page views) says they changed; a texture sampled by a descriptor
|
||||
table is brought up to date before the submission. The reasons are layout (the console's tiling),
|
||||
format stand-ins, depth/stencil restrictions and mip packing. A layout-equal linear subset could be
|
||||
placed directly over a section run, but that needs a layout census and a driver probe first; until
|
||||
then every texture bridge stays.
|
||||
|
||||
### 4.6 Render targets, depth and read-backs
|
||||
|
||||
Rendering into title memory needs a PC-compatible layout, format and target/depth semantics over an
|
||||
opened heap; the depth+UAV restriction and the missing PC formats mean the host copy is the
|
||||
authority for these. `texback` reads back what the GPU wrote to host copies of title textures, and
|
||||
the depth twins and the plane pass exist for the same reasons. Required, not migrated.
|
||||
|
||||
### 4.7 D3D12 infrastructure
|
||||
|
||||
Descriptor heaps and the CPU descriptor mirror, command allocators and lists, PSOs/root signatures/
|
||||
command signatures, the swap chain and present path, the indirect clamp, per-draw CPU-written
|
||||
scratch, the residency probe, the layer's own UI, frame generation and keep-awake. These are not
|
||||
copies of title memory; a direct-access migration cannot remove them.
|
||||
|
||||
### 4.8 The title's own CPU steps and fills (`host::send`, `host::copy`)
|
||||
|
||||
The title's own memory operations executed by the layer on its behalf, and the CPU fills the layer
|
||||
does for its own submissions. They are not redundant copies: only their ordering relative to
|
||||
placed writes is the layer's responsibility (section 6).
|
||||
|
||||
### 4.9 Look-ahead caches and experiments
|
||||
|
||||
`crate::ahead` makes buffers and shared buffers ahead of use; `window_mapped_for`,
|
||||
`VICTORY_SEND_BAR`/`VICTORY_WINDOWS_BAR_MB`/`VICTORY_WC_BAR` map VRAM into the process;
|
||||
`VICTORY_CARD_ALL` and `VICTORY_WINDOWS_OWN` add second system-memory sides. All are off by
|
||||
default (except the ahead cache, which is a performance layer behind its own switch). They are
|
||||
experiments superseded for openable memory by the direct path, kept as switches because removing
|
||||
them is a policy decision that needs a hardware A/B.
|
||||
|
||||
## 5. Classification
|
||||
|
||||
- **Removable for the refused class**: the system-memory mirrors of title buffers and windows the
|
||||
policy refuses a device-local side, and the machinery that maintains them (refresh, sends,
|
||||
compare, copy-back). Implemented in this work behind the direct switches, with the mirror as the
|
||||
fallback for every refusal.
|
||||
- **Required**: device-local sides (title buffers, windows, by-address arenas), textures and
|
||||
targets for layout/format reasons, read-backs, and the D3D12 infrastructure; the title's own CPU
|
||||
steps.
|
||||
- **Unresolved, kept on the copy path**: view-byte copies (exact pool integration); scattered/holed
|
||||
memory (multi-run composition); a layout-equal texture subset (needs a layout census and a
|
||||
driver probe); a device-local by-address arena; overlapping placed resources and D3D12 aliasing
|
||||
barriers; driver coherency and pinning of opened heaps; the PCIe cost of access in place; WDDM
|
||||
residency.
|
||||
- **Kept as experiments**: the second sides and CPU-mapped-VRAM paths above; legacy in-place levels
|
||||
1/2 and renderer port 1 keep their documented behaviour.
|
||||
|
||||
## 6. What this work implements
|
||||
|
||||
### 6.1 Admission and the placement ledger
|
||||
|
||||
`shadow::card_admission`/`window_admission` are the admission checks without the allocation;
|
||||
`card_for`/`window_card_for` use them as before. The copies that get no device-local side are
|
||||
counted in `residency` with the reason (`Fallback`), the host buffers made are counted by the
|
||||
heap class the API reports (`HeapClass`/`class_of`), and the directly backed copies and refused
|
||||
direct asks are counted too (`direct_add`/`direct_freed`/`direct_refused`,
|
||||
`NoDirect`). `residency::placement_line` prints the ledger every 5 seconds while a fallback copy
|
||||
lives (or `VICTORY_MEMORY_REPORT=1`); `host::say_separation_switches` names the switches in force
|
||||
at startup.
|
||||
|
||||
### 6.2 Opening the title's memory
|
||||
|
||||
`inplace::openability` classifies a range. For a section run, `SectionView` maps our own view,
|
||||
refcounted, one per run, and holds the section's pages alive; `OpenExistingHeapFromAddress1`
|
||||
(`ID3D12Device13`, probed once, `part_opening`) opens a heap; a placed buffer covers the range.
|
||||
`REGIONS` shares one view and one heap per title run of a section, up to `REGION_MOST` (512 MiB,
|
||||
because opening locks the pages); a run is forgotten when the title shows other pages there. For
|
||||
private memory, a committed part of the allocation is opened (the documented pinning exception).
|
||||
|
||||
### 6.3 The migration policy
|
||||
|
||||
`inplace::place_fallback(start, len, window)` is asked exactly where admission refused:
|
||||
`VICTORY_INPLACE_VIEW=1` places page-pool windows, `=2` title buffers too, and
|
||||
`VICTORY_INPLACE=3` places private memory. A placed copy makes no staging/mirror, no card side, no
|
||||
hash twin, no send/fetch/compare/copy-back; `Shadow::placed` shapes it as a copy so binding,
|
||||
descriptors and lifetime work unchanged, and `Shadow::place_keep` holds the view. Refusals are
|
||||
counted by reason in the ledger and the copy path proceeds.
|
||||
|
||||
### 6.4 Coherence and lifetime
|
||||
|
||||
- `Shadow::gpu_writes` for a placed copy declares the range through `HostList::defer_gpu_write`,
|
||||
so the late waits order a CPU reader behind a flight that may write it.
|
||||
- `watch::title_memory_freed` calls `inplace::title_memory_freeing` before the title's own
|
||||
`VirtualFree`/decommit/release; `xmem`'s `VirtualProtect` is intercepted unconditionally and
|
||||
does the same before forwarding; `XMemFreeDefault`'s raw `VirtualFree` for 32-bit allocations
|
||||
lets placed copies go first.
|
||||
- A mapping change lets go of exactly the placed copies over the range through the registry
|
||||
(`shadow::in_place_let_go`, `PLACED`), and a section close forgets the port's regions
|
||||
(`port::section_gone`).
|
||||
- The pre-existing shortcut is unchanged: a host copy of the same bytes written through a different
|
||||
copy is not told.
|
||||
|
||||
### 6.5 Switches
|
||||
|
||||
| Switch | Default | Effect |
|
||||
|---|---|---|
|
||||
| `VICTORY_INPLACE_VIEW` | 0 | 1: place page-pool windows over our view of their run; 2: title buffers too |
|
||||
| `VICTORY_INPLACE` | 0 | 3 and up: place the copies the policy refuses a device-local side (private memory); 1/2 keep their legacy meaning |
|
||||
| `VICTORY_INPLACE_MB` | 4096 | the most title bytes in place at once |
|
||||
| `VICTORY_INPLACE_PROBE` | 0 | 1: the probe and the openability census; 2: also opens one part |
|
||||
| `VICTORY_MEMORY_REPORT` | unset | forces (=1) or silences (=0) the placement ledger line |
|
||||
|
||||
## 7. The copies that remain, and why
|
||||
|
||||
1. **Device-local sides of title buffers and windows** (`Card`, `buffer_sides`,
|
||||
`window_card_for`): the VRAM memory class. Replacing them with system-memory access is a
|
||||
memory-class downgrade; not done without hardware measurement.
|
||||
2. **By-address arenas** (`shadow::by_address`): raw-address shaders need a GPU virtual address a
|
||||
title CPU address cannot be; a device-local arena design is unresolved.
|
||||
3. **Textures that are not layout-equal**: tiling, mip packing, format stand-ins, depth+UAV and
|
||||
missing PC formats require the detiling/staging or the twin; the layout-equal linear subset is
|
||||
future work.
|
||||
4. **Render targets and depth**: layout, format and target/depth semantics over an opened heap; the
|
||||
host copy is the authority.
|
||||
5. **Read-backs and texback**: what the GPU wrote to host copies of title textures, and the fault/
|
||||
compare channels documented in `docs/memory-separation.md`.
|
||||
6. **View-byte copies**: system memory by design; the exact pool would need a direct-aware change
|
||||
(follow-up).
|
||||
7. **D3D12 infrastructure**: not copies of title memory; cannot be removed by a memory migration.
|
||||
8. **The title's own CPU steps**: the title's commands; only their ordering is the layer's job.
|
||||
9. **Off-by-default experiments**: the second sides, CPU-mapped VRAM and the legacy in-place levels;
|
||||
kept as switches for their A/B.
|
||||
|
||||
## 8. Follow-ups
|
||||
|
||||
- Place view-byte copies over openable backing (needs the exact pool to hold a placed form).
|
||||
- Multi-run composition for scattered/holed view memory (needs a driver experiment opening several
|
||||
runs/heaps).
|
||||
- A layout census and a probe for the layout-equal texture subset.
|
||||
- A device-local by-address arena, or a documented reason it cannot exist.
|
||||
- Overlapping placed resources and D3D12 aliasing barriers.
|
||||
- Delete the experiment switches once a hardware A/B shows the direct path equal or better wherever
|
||||
the memory is openable.
|
||||
|
||||
## 9. What a hardware run must establish
|
||||
|
||||
Before any switch becomes a default, a run on the target NVIDIA driver must establish:
|
||||
|
||||
- that `OpenExistingHeapFromAddress1` is accepted for the title's 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: run the census (`VICTORY_INPLACE_PROBE=1`) and
|
||||
read the private/one-run/scattered split it prints;
|
||||
- that a placed copy's shader writes are seen by a CPU reader only after the wait, under the real
|
||||
relay and late waits (the declaration is unit-tested; the ordering under a live relay needs a
|
||||
run);
|
||||
- the PCIe cost of GPU access to title memory in place against the copies it replaces, per class
|
||||
(frame time plus GPUView/ETW), before deciding a default is worth it;
|
||||
- physical residency and WDDM paging (not queryable from D3D12), and device-removal/TDR behaviour
|
||||
of the direct paths.
|
||||
|
||||
## 10. Verification record
|
||||
|
||||
- Checks in this work: `cargo check --workspace --all-targets --locked` PASS after each
|
||||
commit (local and in the CI run); no new warnings in the changed files.
|
||||
- The all-features build fails identically at the base commit (`829188e`): the diagnostics
|
||||
feature's `copystat`/`timing` code, untouched here - inherited, reported in the PR, not caused
|
||||
by this branch.
|
||||
- Full `cargo test --workspace --locked` on GitHub Actions (Windows, WARP), from a temporary
|
||||
`ci/**` branch of the fork whose only extra file is the test workflow:
|
||||
- this branch: the focused in-place tests PASS (15 of 15); `victory-gpu` lib **924 passed,
|
||||
0 failed, 57 ignored**; every other test target passes; the only failures are the ones the
|
||||
base commit has too - three `bcpack::oracle_parity_*` tests in victory-formats, five
|
||||
`emit` tests in victory-shader, and `xtask`'s asset-policy
|
||||
`repository_passes_policy` (on a file this change does not touch).
|
||||
- baseline `829188e`, same workflow: the same nine failures (plus one flaky
|
||||
`host::card_steps` test in that run); `victory-gpu` lib 914 passed.
|
||||
- branch run: https://github.com/CwWwWwW/VIctory-NVIDIA/actions/runs/46269247875 ; baseline
|
||||
run: https://github.com/CwWwWwW/VIctory-NVIDIA/actions/runs/46267700603 . The documentation
|
||||
was amended after the tested source tip; no source changed after the run.
|
||||
- The tests added by this work cover the admission/openability/accounting decisions (unit tests) and
|
||||
the placement mechanics on the software adapter: the placed buffer reads and writes title bytes
|
||||
at the right offset, a title view reprotected and unmapped under the heap, the section's pages
|
||||
after the title lets go, the shared region and its forget, the exact placed-copy invalidation,
|
||||
the placed-write declaration, and the direct-backing counters.
|
||||
- Not established here: everything in section 9. WARP is not equivalent hardware, and
|
||||
`GetHeapProperties` reports the API's answer, not physical placement.
|
||||
everything in section 9. WARP is not equivalent hardware, and
|
||||
`GetHeapProperties` reports the API's answer, not physical placement.
|
||||
91
docs/memory-separation-window-budget.md
Normal file
91
docs/memory-separation-window-budget.md
Normal file
@ -0,0 +1,91 @@
|
||||
# Windows and the device-local budget, and the separation exceptions
|
||||
|
||||
Windows are copies of title memory outside any buffer object: vertex and index streams, constants
|
||||
and everything else a draw reads from the title's own allocator. This note is about their
|
||||
device-local budget, what is charged to it, and the exception switches that weaken the separation.
|
||||
|
||||
## 1. The budget
|
||||
|
||||
A window's device-local side is admitted by `shadow::window_admission`, before any buffer is
|
||||
allocated:
|
||||
|
||||
- `window_card_most`: `VICTORY_CARD_WINDOWS_MB` if set; unset, a share of the card's budget from
|
||||
`default_window_card_mb` (none below an 8 GiB local budget, 9% of it capped at 1024 MiB up to
|
||||
12 GiB, 2560 MiB above that, 5120 MiB from 20 GiB);
|
||||
- `window_line`: `window_card_percent(budget)` (`VICTORY_CARD_WINDOWS_PERCENT`, clamped 50..97;
|
||||
default 80/89/91 by card size) of the budget, less what the texture queue keeps free for card
|
||||
copies of title buffers and for render targets not yet made (`shadow::card_room_kept` +
|
||||
`resource::targets_room_kept`), capped at the texture queue's own line
|
||||
(`resource::room_line`), and never under four fifths of the budget (or the percent, if less);
|
||||
- `resource::card_copy_fits`: the card's use plus this side must fit under its line;
|
||||
- `WINDOW_CARD_BYTES`: the bytes of device-local window sides alive must stay under
|
||||
`window_card_most`.
|
||||
|
||||
A window gets no device-local side this frame when `card_late` is on and it has not been asked
|
||||
for in two or more frames; that is a performance policy, not a refusal, and it does not put the
|
||||
window on the direct path (the window stays a system-memory copy until the late policy decides).
|
||||
|
||||
## 2. What is charged to the budget
|
||||
|
||||
Only a device-local side is charged to `WINDOW_CARD_BYTES` and given back when the copy goes.
|
||||
This was a defect fixed in this work: a window's second system-memory side (`VICTORY_WINDOWS_OWN`)
|
||||
used to be charged to the same counter, so a system-memory fallback could consume the windows' VRAM
|
||||
budget and refuse later windows their device-local side. A second side is system memory: it is
|
||||
counted in the placement ledger (`residency::Fallback`), not against the device-local budget, and
|
||||
`Shadow::drop` only gives back what a device-local side took (`Shadow::fallback` marks the
|
||||
difference).
|
||||
|
||||
The by-address arenas (`shadow::by_address`, the title's memory addressed by raw shader
|
||||
addresses) keep their own counter `ARENA_CARD_BYTES` and cap `arena_card_most`
|
||||
(`VICTORY_MEMORY_CARD_MB`, 4096 MiB default). They are not charged to the windows' budget: this
|
||||
tree already had that separation before this work (`take_under`/`ARENA_CARD_BYTES`), and it is
|
||||
kept.
|
||||
|
||||
## 3. Exception matrix
|
||||
|
||||
| Switch | Default | What it weakens |
|
||||
|---|---|---|
|
||||
| `VICTORY_CARD_ALL` | off | every title buffer's copy gets a second system-memory side instead of a single side |
|
||||
| `VICTORY_WINDOWS_OWN` | off | windows get a second system-memory side (and now correctly do not consume the window VRAM budget) |
|
||||
| `VICTORY_WINDOWS_BAR_MB`, `VICTORY_SEND_BAR`, `VICTORY_WC_BAR` | off | CPU-mapped VRAM: the CPU writes GPU memory through the bus |
|
||||
| `VICTORY_WC_NO_BACK`, `VICTORY_WC_NO_BACK_MIN_KB` | off | write-combined title memory whose shader writes are not copied back |
|
||||
| `VICTORY_INPLACE` 1/2 | off | legacy in-place placement wherever the memory can be opened (not the migration policy) |
|
||||
| `VICTORY_INPLACE` 3+ | off | the migration policy: place only the copies the policy refused a device-local side |
|
||||
| `VICTORY_INPLACE_VIEW` 1/2 | off | place page-pool windows / title buffers over our own view of their section run |
|
||||
| `VICTORY_INPLACE_MB` | 4096 | the most title bytes in place at once (opening pins pages) |
|
||||
| `VICTORY_INPLACE_PROBE` | 0 | the openability probe and census (diagnostics) |
|
||||
| `VICTORY_PORT_CONSTANTS` | off | renderer port 1: the title's 32-bit graphics heap in place |
|
||||
| `VICTORY_MEMORY_REPORT` | unset | forces (`=1`) or silences (`=0`) the placement ledger line |
|
||||
|
||||
Every one of these is named at startup by `host::say_separation_switches`, with a warning for
|
||||
the combinations the code documents as unsupported or as placement weakening, so a log states
|
||||
which exceptions are in force. Nothing is enabled by default; with every switch unset the product
|
||||
path behaves as at the base commit.
|
||||
|
||||
## 4. What the ledger shows for windows
|
||||
|
||||
With `VICTORY_MEMORY_REPORT=1` the placement line reports:
|
||||
- the heap class of every host buffer made, including windows' shared CPU sides and any device-local
|
||||
side;
|
||||
- copies whose GPU-visible side is system memory, alive and total, by reason: a window refused a
|
||||
card side by budget, cap or host; a window deliberately late; a window placed directly (not a
|
||||
copy at all, reported under the directly-backed counts instead);
|
||||
- directly backed windows: alive, total, and the refused direct asks by reason.
|
||||
|
||||
## 5. What cannot be established here
|
||||
|
||||
The budget rules are static and were checked against the tree; WARP establishes the mechanics, not
|
||||
the arithmetic. Not established without the target NVIDIA hardware:
|
||||
- whether the card's budget and use the DXGI answer reports correspond to what the driver actually
|
||||
lets the process allocate and keep resident;
|
||||
- the real cost of giving windows a device-local side on a card under memory pressure, and the PCIe
|
||||
cost of the windows that stay in system memory (directly placed or copied);
|
||||
- whether opening a heap on a section run pins pages at a cost that changes the line, and how much
|
||||
of a real title's window memory is openable (the census).
|
||||
|
||||
## 6. Checks
|
||||
|
||||
The workspace check and the CI build/test runs cover the code; `docs/copy-bridges.md` section 10
|
||||
holds the record. No default was changed: with every switch unset the windows' admission, budget,
|
||||
line and second-side behaviour are those of the base tree, modulo the second-side accounting fix
|
||||
described in section 2.
|
||||
167
docs/memory-separation.md
Normal file
167
docs/memory-separation.md
Normal file
@ -0,0 +1,167 @@
|
||||
# System RAM and GPU VRAM: the separation the layer works with
|
||||
|
||||
This is the audit the placement ledger and the direct-access work were written from, updated to
|
||||
the tree they are in. It says which memory belongs to whom, which heap class the API reports for
|
||||
every host buffer the layer makes, why copies are admitted the way they are, and where the two
|
||||
memory domains meet.
|
||||
|
||||
## 1. The platform model
|
||||
|
||||
The title is an Xbox Series title. On the console its GPU memory is unified memory: a GPU virtual
|
||||
address is a CPU address, and the title's own CPU steps read and write exactly what its shaders
|
||||
read and write.
|
||||
|
||||
On the PC the layer runs the title natively with a host GPU behind it, and the host has two memory
|
||||
domains: system RAM (what the CPU owns) and the card's local VRAM (what the GPU owns). The D3D12
|
||||
copy machinery moves bytes between them:
|
||||
|
||||
- `D3D12_HEAP_TYPE_CUSTOM` + write-back + L0: host buffers in system memory that the CPU maps and
|
||||
shaders read and write over the bus (`Host::shared_buffer`, `CardCpu::allocate`);
|
||||
- `D3D12_HEAP_TYPE_DEFAULT`: device-local memory (`Host::uav_buffer`);
|
||||
- `UPLOAD` / `READBACK`: the CPU-visible staging kinds (`Host::upload_buffer`,
|
||||
`Host::read_back_buffer`);
|
||||
- `GPU_UPLOAD` (resizable BAR): VRAM the CPU maps (`Host::mapped_card_buffer`).
|
||||
|
||||
"The console's memory" is not one of these. The layer reproduces it: `xmem` makes pagefile-backed
|
||||
sections for the title's physical pages, maps views of them at the title's addresses through
|
||||
placeholders, and the title runs against those views. So a title address is a view of a section
|
||||
page, and the section keeps the page alive while anything of ours holds a view of it
|
||||
(`crate::inplace::SectionView`).
|
||||
|
||||
## 2. Heap classes, as the API reports them
|
||||
|
||||
The placement ledger (`crate::residency`) asks every host buffer it sees which heap class the API
|
||||
reports for it: `HeapClass` and `class_of` call `ID3D12Resource::GetHeapProperties`.
|
||||
`residency::placed` counts every buffer made by the copy and transfer machinery in
|
||||
`host.rs` (shared, upload, read-back, unordered-access and CPU-mapped card buffers) by class and
|
||||
bytes. The five-second line prints the counts.
|
||||
|
||||
This is deliberately the API's answer, not a claim about physical placement: a `DEFAULT`
|
||||
allocation is counted as device-local because that is the heap class the API reports, not because
|
||||
the bytes are proven resident. D3D12 has no per-resource residency query, and WDDM may page a
|
||||
`DEFAULT` resource out. Nothing in this tree claims physical residency.
|
||||
|
||||
## 3. Ownership
|
||||
|
||||
- **CPU-owned, stays in system memory**: the title's own allocations and their section views; host
|
||||
mirrors of title memory (`CardCpu` and the single-sided shared buffers); staging and read-back
|
||||
buffers; the descriptor-stride table and per-draw CPU-written scratch; the layer's UI and CPU
|
||||
bookkeeping.
|
||||
- **GPU-owned, device-local**: the card sides of title buffers and windows (`Card` with a
|
||||
`DEFAULT` buffer), the by-address arenas (`ARENA_CARD_BYTES`), textures and render targets the
|
||||
layer creates, depth twins, and the indirect-clamp buffers. Their contents are the card's; the
|
||||
layer keeps track of what changed and sends/fetches it.
|
||||
- **Cross-domain transfers, explicit**: every two-sided copy (`shadow`'s refresh, sends, compare
|
||||
and copy-back; texture detiling staging; read-backs) and every directly placed buffer (below).
|
||||
- **Directly placed title memory**: a buffer placed over the title's own section page or private
|
||||
allocation (`crate::inplace`), behind switches (section 6). The GPU reads and writes the
|
||||
title's bytes in place; there is no host copy for it at all.
|
||||
- **Not established from source**: the driver's actual placement and pinning decisions
|
||||
(`GetHeapProperties` reports what was asked for, not where the bytes are).
|
||||
|
||||
## 4. How a copy is admitted
|
||||
|
||||
Title buffers (`shadow::lookup`) and windows (`shadow::loose`) ask `shadow::card_admission` /
|
||||
`shadow::window_admission` before anything is allocated: the `cards` switch, `card_limits` /
|
||||
`window_card_most` sizes, `Host::card_ready`, the DXGI budget line (`card_room_kept_on` 97% or
|
||||
80% for buffers; `window_line` with the kept room and `resource::room_line` for windows;
|
||||
`resource::card_copy_fits`), and the path's own byte cap. A refusal is a reason
|
||||
(`residency::Fallback`), not silence, and the copy then stays in system memory.
|
||||
|
||||
The windows' device-local side is deliberately late for many windows: `card_late` gives a card
|
||||
side only to windows asked for in two or more frames, most asked first. A window that would get no
|
||||
card side this frame is not a refusal by the policy and is not placed directly before that
|
||||
decision; it is a copy in system memory until the late policy gives it a device-local side (or
|
||||
not).
|
||||
|
||||
The second memory sides are experiments, off by default: `VICTORY_CARD_ALL` gives every title
|
||||
buffer's copy a second system-memory side, and `VICTORY_WINDOWS_OWN` does it for windows. A
|
||||
second side is system memory. It is counted by the placement ledger, not against the device-local
|
||||
budget of its path (section 5).
|
||||
|
||||
## 5. The placement ledger
|
||||
|
||||
`residency::placement_line` prints, every 5 seconds while a copy in system memory is alive (or
|
||||
when `VICTORY_MEMORY_REPORT` is set; `=0` silences it):
|
||||
|
||||
- host buffers made since the start as the API reports them: count and MB by `HeapClass`;
|
||||
- copies whose GPU-visible side is system memory: alive count and MB by `Fallback` reason
|
||||
(switch off, not eligible, host unavailable, budget, cap, allocation failed, view copy), and the
|
||||
total made since the start;
|
||||
- directly backed copies: windows and title buffers alive, total made, and the refused direct asks
|
||||
by `NoDirect` reason (not openable, cap, host refused, host unavailable);
|
||||
- the system's DXGI local and shared usage/budget for comparison.
|
||||
|
||||
The line is the measurement the direct-access switches are evaluated with: run with the switches
|
||||
off, then on the same save, and compare what moved from the fallback classes to the directly
|
||||
backed counts and what still had to copy.
|
||||
|
||||
## 6. Direct access
|
||||
|
||||
`crate::inplace` opens the title's own memory as a host heap and places a buffer in it:
|
||||
|
||||
- `inplace::openability` classifies a range: private memory committed whole, one contiguous run
|
||||
of one section (`Openability::View`), or a refusal (`Unmapped`, `Scattered`, `Holes`);
|
||||
- for a section run, a refcounted `SectionView` maps our own view of the run,
|
||||
`OpenExistingHeapFromAddress1` opens a heap on that view, and a placed buffer covers the range;
|
||||
one view and one heap are shared per run (`REGIONS`, `REGION_MOST` 512 MiB), and the view keeps
|
||||
the section's pages alive after the title unmaps its own view and closes its handle;
|
||||
- for private memory, a committed part of the allocation is opened the same way. A heap over the
|
||||
title's private pages pins them, so the title's own `VirtualFree`/`VirtualProtect` there can
|
||||
fail while it stands; that is the documented private-placement exception, and why the page-pool
|
||||
view is the recommended route;
|
||||
- `inplace::part_opening` probes `ID3D12Device13` once per process; without it every placement
|
||||
is refused as `HostUnavailable` and copies are made as before.
|
||||
|
||||
`inplace::place_fallback` is the policy: exactly where `card_admission`/`window_admission`
|
||||
refused a device-local side, it tries page-pool view memory (`VICTORY_INPLACE_VIEW=1` windows,
|
||||
`=2` title buffers) and then private memory (`VICTORY_INPLACE=3`). A placed copy makes no
|
||||
staging buffer, no mirror, no card side, no hash twin and no send/fetch/compare/copy-back state; the
|
||||
mirror remains the fallback for every refusal. Legacy `VICTORY_INPLACE=1`/`=2` keep their old
|
||||
"place anywhere openable" meaning and renderer port 1 keeps `VICTORY_PORT_CONSTANTS`; those are
|
||||
not the migration policy and are unchanged.
|
||||
|
||||
## 7. Transfers and the synchronisation contract
|
||||
|
||||
For two-sided copies the contract is the copy machinery's: the CPU's mirror is refreshed before a
|
||||
submission, shader writes are declared (`Shadow::gpu_writes`), what changed goes up before the
|
||||
next submission, and what shaders wrote is found and copied back after the waits. For a directly
|
||||
placed copy:
|
||||
|
||||
- shader writes are declared via `HostList::defer_gpu_write`, so the copy machinery's late waits
|
||||
order a CPU reader of those title bytes behind the flight that may write them;
|
||||
- the title's own `VirtualFree`/decommit/release path (`watch::title_memory_freed`), its
|
||||
`VirtualProtect` (intercepted unconditionally in `xmem`) and `XMemFreeDefault`'s raw
|
||||
`VirtualFree` for 32-bit allocations let placed copies go before the kernel call;
|
||||
- a mapping change lets go of every placed copy over the range through the exact placed-copy
|
||||
registry (`shadow::in_place_let_go`), and the section view stays mapped while a placed buffer
|
||||
holds it;
|
||||
- the shortcut that predates this work stays: a host copy of the same bytes that a shader writes
|
||||
through a *different* copy is not told, because the card's writes are not seen by write watching.
|
||||
Placement does not widen it.
|
||||
|
||||
## 8. What this tree can and cannot establish
|
||||
|
||||
Local checks (`cargo check --workspace --all-targets --locked`, all features) and the software
|
||||
adapter (WARP) tests in CI establish the mechanics: the API's heap class for the buffers made, the
|
||||
placement data path both ways, the refcounted view's lifetime, the exact invalidation, the
|
||||
declaration of placed writes, and the fallback policy. They do not establish:
|
||||
|
||||
- whether the target NVIDIA driver accepts `OpenExistingHeapFromAddress1` on private allocations
|
||||
and on section views, what it pins and at what working-set cost;
|
||||
- physical residency, WDDM paging, and device-removal/TDR behaviour of the direct paths;
|
||||
- how much of the real title's memory is openable (the in-place census, `VICTORY_INPLACE_PROBE=1`,
|
||||
has not been recorded on a run);
|
||||
- the PCIe cost of GPU access to title memory in place against the copies it replaces.
|
||||
|
||||
Those need a run on the target hardware and driver; `docs/copy-bridges.md` section 9 states what
|
||||
to measure and what would make a switch a default.
|
||||
|
||||
## 9. Checks
|
||||
|
||||
- `cargo check --workspace --all-targets --locked`: PASS (see `docs/copy-bridges.md` section 10
|
||||
for the verification record, including the CI full-test run and its baseline comparison).
|
||||
- `cargo check --workspace --all-targets --all-features --locked`: the CI build check.
|
||||
- `cargo test --workspace --locked`: the CI test run.
|
||||
- `cargo clippy --workspace --all-targets --locked -- -D warnings`: the tree's own gate; its
|
||||
pre-existing failures are unchanged by this work (the same lints at `829188e`).
|
||||
Reference in New Issue
Block a user