GPU: placement by what the card may do: buffers in memory read-only to the card (VICTORY_RO_BAR, RO_TILES, RO_INPLACE; all off) #3401

Closed
banaanpapa wants to merge 15 commits from upstream-pr/3401 into main
banaanpapa commented 2026-11-29 22:49:12 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by banaanpapa on 2026-11-29T22:49:12Z.


Stacked on #3268: the first four commits here are that pull request's (its bench is what measures this one). The six after them are new. Everything new is behind switches that are off; with them off the tree behaves as before. No game was run: every figure is from a synthetic bench on one PC (Ryzen 9 9950X3D, RTX 5080 16 GB, driver 621.24).

The idea

The other layers guess which memory comes back from the card. This title says it: memory it asks for with read-only GPU page protection is memory the console's card cannot write (title_memory_gpu_readonly), and VICTORY_GPU_RO_SKIP already takes such pages out of what shaders are declared to write. So for such memory nothing is ever found, fetched or merged, and a copy's CPU side has no use left there: it is a second copy of every byte in the PC's memory, a second copy of every changed byte on its way up, and a CopyBufferRegion for each run. Placement can follow that declaration.

What is added (all off)

  • VICTORY_RO_BAR=1: a title buffer that lies whole in such memory, where its copy would have had two sides, gets one copy in card memory the CPU maps (what VICTORY_WC_BAR makes for write-combined memory, but from the title's declaration and not from a guess about its CPU).
  • VICTORY_RO_TILES=1: a buffer that lies in such memory in part (the 174 MiB heap: a ring the CPU writes beside pools shaders write) keeps two sides, and its card's side becomes one sparse buffer over two heaps (host/mixed.rs): the read-only stretch in card memory the CPU maps, written by the refresh and never sent. The host is asked once whether a sparse buffer shows what the CPU wrote beside it; where it does not, the copy is made as before.
  • VICTORY_RO_INPLACE=1: such a buffer whose copy would be in the PC's memory is opened in place. What VICTORY_INPLACE=2 must assume of shader writes, this memory has none of.
  • VICTORY_RO_CENSUS=1: the frame-rate line says how many MB a frame went up to card sides and how many of them lay in such memory.
  • A log line in every run, with or without the switches: how many buffers lie whole in such memory and what copy they got.
  • A copy made for read-only memory leaves the table when the title makes any of that memory writable to the card, or gives it up.
  • The title's VirtualProtect, and a commit at an address, tell the card first (title_memory_protecting).

Figures (host::placement, a 64 MiB buffer, 16 MiB written by the title before each submission)

A submission Prepared and sent The card's run
Read-only whole, two sides (today) 3.14-3.17 ms 2.28-2.35 ms 0.62 ms
The same, one mapped copy (RO_BAR) 1.20-1.24 ms 0.85-0.87 ms 0.17 ms
Read-only past 4 MiB that shaders write, two sides 3.60 ms 2.12 ms 1.26 ms (with landing)
The same, that stretch in mapped tiles (RO_TILES) 1.95 ms 0.98 ms 0.77 ms
Read-only whole, kept off the card, a copy in the PC's memory 0.70-0.87 ms 2.1-3.4 ms
The same, in place (RO_INPLACE) 0.05-0.07 ms 2.0-3.8 ms

In every round the title's last written page was read back from the card, and what shaders wrote was in title memory.

What was run

  • New tests, each of which fails when what it covers is broken on purpose: the range rules; copies leaving the table when memory is made writable or freed (600 buffers in one region too); a refresh over a copy with a mapped stretch on a view and on write-watched memory (the stretch reaches the tiles, the CPU's side is not written there, nothing of it is told to go up); a buffer of two kinds read back from the card.
  • host::membench (the title's own calls), memory_bench_reclaims_and_regrows_with_correct_bytes, with its source said read-only by the new VICTORY_MEMBENCH_RO=whole|half: the 32 MiB copied on the card and fetched back match the source with RO_BAR, with RO_TILES and with RO_INPLACE, with and without the relay.
  • cargo test -p victory-gpu --release --lib: 916 pass; the six that fail are those that fail on main beside it (three of pipeline::host, shader_cache's key test, two of texback). Clippy says nothing of a line this branch writes. The all-features build does not compile on main (copystat.rs, host.rs:9231), so that gate was not run.

Limits and risks

  • No title run. How many of the title's buffers lie whole in such memory is not known here; the log line and VICTORY_RO_CENSUS are there to say.
  • VICTORY_RO_TILES leans on what Direct3D's documents do not speak of (tiles of a sparse buffer in a GPU_UPLOAD heap, written through a second buffer placed in it). It works on the one driver asked. A driver that refuses may remove the device at the first such copy.
  • VICTORY_RO_INPLACE carries in place's old risk, and the bench now shows it: after the buffer is let go its heap closes VICTORY_BURY_LAG submissions later, and a VirtualProtect or VirtualFree of the title's within that time is still refused. The same holds for title_memory_freeing. Section 11.4 of the audit has the measurement.
  • A copy on the card into such memory, which the console would refuse, stays on the card and is said in the log.

The audit's section 11.4 lists five runs that say what each switch is worth in the title, and the line each is read off.

Merged with main again (2026-11-30, c71899d9)

Merged, not rebased; four files conflicted with what main did since, and each is fitted to main's form:

  • The buffers' lookup (shadow.rs): main now splits a copy's admission from its making and answers with a BufferHit. This branch's three placements come before the admission, and a copy placed is noted as main notes its own (remember_placed). The table is Buffers now, and ro_let_go walks its map.
  • shader_writes: a copy made for read-only memory leaves before main's copy-back by memory class (VICTORY_UNIFIED_BACK). The two rest on the same declaration: main's class gpu-ro says such memory needs no copy-back, and this branch says it then needs no CPU side either.
  • inplace.rs: main's place_private is what this branch's place_if_it_can_be was; place_read_only calls it.
  • host/send.rs: main plans all copies' runs in one function that does not know the copies; the census is taken before it.
  • xmem.rs: main lets go of what is in place before the title's VirtualProtect already, so this branch's call there is gone.

Run again on the merged branch, RTX 5080:

  • This branch's 11 tests pass. cargo test -p victory-gpu --release --lib, five runs: 1,121 pass and the two that fail are main's (shader_cache's key test, list::thin::tests::bindings_record_no_work); in two of the five the card_steps and uav_pool timing tests failed as well, and both pass alone. Run with #4115 applied and not committed here.
  • host::placement, 16 MiB written before each submission: read-only whole, two sides 2.94 ms and one mapped copy 1.15 ms; read-only past what shaders write, two sides 3.79 ms and that part in mapped tiles 1.85 ms; in place the preparing 0.04 ms against 0.79.
  • host::membench's byte check passes with RO_BAR, RO_TILES and RO_INPLACE, with and without the relay.

What main's document on memory classes does not say is how much of the title's memory is gpu-ro; VICTORY_UNIFIED_STATS=1 and this branch's log line would. Until a run says, these switches stay what they were: off.

🤖 Generated with Claude Code

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5555992874 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3401). Originally posted by [banaanpapa](https://github.com/banaanpapa) on 2026-11-29T22:49:12Z. --- Stacked on #3268: the first four commits here are that pull request's (its bench is what measures this one). The six after them are new. Everything new is behind switches that are off; with them off the tree behaves as before. No game was run: every figure is from a synthetic bench on one PC (Ryzen 9 9950X3D, RTX 5080 16 GB, driver 621.24). ## The idea The other layers guess which memory comes back from the card. This title says it: memory it asks for with read-only GPU page protection is memory the console's card cannot write (`title_memory_gpu_readonly`), and `VICTORY_GPU_RO_SKIP` already takes such pages out of what shaders are declared to write. So for such memory nothing is ever found, fetched or merged, and a copy's CPU side has no use left there: it is a second copy of every byte in the PC's memory, a second copy of every changed byte on its way up, and a `CopyBufferRegion` for each run. Placement can follow that declaration. ## What is added (all off) - **`VICTORY_RO_BAR=1`**: a title buffer that lies whole in such memory, where its copy would have had two sides, gets one copy in card memory the CPU maps (what `VICTORY_WC_BAR` makes for write-combined memory, but from the title's declaration and not from a guess about its CPU). - **`VICTORY_RO_TILES=1`**: a buffer that lies in such memory in part (the 174 MiB heap: a ring the CPU writes beside pools shaders write) keeps two sides, and its card's side becomes one sparse buffer over two heaps (`host/mixed.rs`): the read-only stretch in card memory the CPU maps, written by the refresh and never sent. The host is asked once whether a sparse buffer shows what the CPU wrote beside it; where it does not, the copy is made as before. - **`VICTORY_RO_INPLACE=1`**: such a buffer whose copy would be in the PC's memory is opened in place. What `VICTORY_INPLACE=2` must assume of shader writes, this memory has none of. - **`VICTORY_RO_CENSUS=1`**: the frame-rate line says how many MB a frame went up to card sides and how many of them lay in such memory. - A log line in every run, with or without the switches: how many buffers lie whole in such memory and what copy they got. - A copy made for read-only memory leaves the table when the title makes any of that memory writable to the card, or gives it up. - The title's `VirtualProtect`, and a commit at an address, tell the card first (`title_memory_protecting`). ## Figures (`host::placement`, a 64 MiB buffer, 16 MiB written by the title before each submission) | | A submission | Prepared and sent | The card's run | |---|---|---|---| | Read-only whole, two sides (today) | 3.14-3.17 ms | 2.28-2.35 ms | 0.62 ms | | The same, one mapped copy (`RO_BAR`) | 1.20-1.24 ms | 0.85-0.87 ms | 0.17 ms | | Read-only past 4 MiB that shaders write, two sides | 3.60 ms | 2.12 ms | 1.26 ms (with landing) | | The same, that stretch in mapped tiles (`RO_TILES`) | 1.95 ms | 0.98 ms | 0.77 ms | | Read-only whole, kept off the card, a copy in the PC's memory | | 0.70-0.87 ms | 2.1-3.4 ms | | The same, in place (`RO_INPLACE`) | | 0.05-0.07 ms | 2.0-3.8 ms | In every round the title's last written page was read back from the card, and what shaders wrote was in title memory. ## What was run - New tests, each of which fails when what it covers is broken on purpose: the range rules; copies leaving the table when memory is made writable or freed (600 buffers in one region too); a refresh over a copy with a mapped stretch on a view and on write-watched memory (the stretch reaches the tiles, the CPU's side is not written there, nothing of it is told to go up); a buffer of two kinds read back from the card. - `host::membench` (the title's own calls), `memory_bench_reclaims_and_regrows_with_correct_bytes`, with its source said read-only by the new `VICTORY_MEMBENCH_RO=whole|half`: the 32 MiB copied on the card and fetched back match the source with `RO_BAR`, with `RO_TILES` and with `RO_INPLACE`, with and without the relay. - `cargo test -p victory-gpu --release --lib`: 916 pass; the six that fail are those that fail on `main` beside it (three of `pipeline::host`, `shader_cache`'s key test, two of `texback`). Clippy says nothing of a line this branch writes. The all-features build does not compile on `main` (`copystat.rs`, `host.rs:9231`), so that gate was not run. ## Limits and risks - No title run. How many of the title's buffers lie whole in such memory is not known here; the log line and `VICTORY_RO_CENSUS` are there to say. - `VICTORY_RO_TILES` leans on what Direct3D's documents do not speak of (tiles of a sparse buffer in a `GPU_UPLOAD` heap, written through a second buffer placed in it). It works on the one driver asked. A driver that refuses may remove the device at the first such copy. - `VICTORY_RO_INPLACE` carries in place's old risk, and the bench now shows it: after the buffer is let go its heap closes `VICTORY_BURY_LAG` submissions later, and a `VirtualProtect` or `VirtualFree` of the title's within that time is still refused. The same holds for `title_memory_freeing`. Section 11.4 of the audit has the measurement. - A copy on the card into such memory, which the console would refuse, stays on the card and is said in the log. The audit's section 11.4 lists five runs that say what each switch is worth in the title, and the line each is read off. ## Merged with `main` again (2026-11-30, `c71899d9`) Merged, not rebased; four files conflicted with what `main` did since, and each is fitted to `main`'s form: - **The buffers' lookup** (`shadow.rs`): `main` now splits a copy's admission from its making and answers with a `BufferHit`. This branch's three placements come before the admission, and a copy placed is noted as `main` notes its own (`remember_placed`). The table is `Buffers` now, and `ro_let_go` walks its map. - **`shader_writes`**: a copy made for read-only memory leaves before `main`'s copy-back by memory class (`VICTORY_UNIFIED_BACK`). The two rest on the same declaration: `main`'s class `gpu-ro` says such memory needs no copy-back, and this branch says it then needs no CPU side either. - **`inplace.rs`**: `main`'s `place_private` is what this branch's `place_if_it_can_be` was; `place_read_only` calls it. - **`host/send.rs`**: `main` plans all copies' runs in one function that does not know the copies; the census is taken before it. - **`xmem.rs`**: `main` lets go of what is in place before the title's `VirtualProtect` already, so this branch's call there is gone. Run again on the merged branch, RTX 5080: - This branch's 11 tests pass. `cargo test -p victory-gpu --release --lib`, five runs: 1,121 pass and the two that fail are `main`'s (`shader_cache`'s key test, `list::thin::tests::bindings_record_no_work`); in two of the five the `card_steps` and `uav_pool` timing tests failed as well, and both pass alone. Run with #4115 applied and not committed here. - `host::placement`, 16 MiB written before each submission: read-only whole, two sides 2.94 ms and one mapped copy 1.15 ms; read-only past what shaders write, two sides 3.79 ms and that part in mapped tiles 1.85 ms; in place the preparing 0.04 ms against 0.79. - `host::membench`'s byte check passes with `RO_BAR`, `RO_TILES` and `RO_INPLACE`, with and without the relay. What `main`'s document on memory classes does not say is how much of the title's memory is `gpu-ro`; `VICTORY_UNIFIED_STATS=1` and this branch's log line would. Until a run says, these switches stay what they were: off. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
trustno1-coder commented 2026-12-01 18:52:37 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by trustno1-coder on 2026-12-01T18:52:37Z.


Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7321723875 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3401#issuecomment-7321723875). Originally posted by [trustno1-coder](https://github.com/trustno1-coder) on 2026-12-01T18:52:37Z. --- Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.

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!3401
No description provided.