GPU: VICTORY_LEAN_WINDOWS=1 — windows on the card with no CPU side, mapped in 64 KiB tiles (−0.8 GB commit, −2.1 GB memory in use) #265

Open
github-bot wants to merge 1 commit from github-bot/gh-265 into main AGit
Owner

@⁠CDR-0000 on GitHub · 2026-11-24 23:03 UTC · original
CDR-0000:perf/lean-windows → main · +639 −27 · 2 files · 1 commits · open

Opt-in. Windows of title memory go to the card with no CPU side, their buffers reserved and mapped in 64 KiB tiles as bytes are sent, through one 64 MiB upload ring. On an RTX 3080 Ti / 32 GB PC: private memory 0.8 GB lower once the world has settled (1.9 GB at the load), memory in use 2.1 GB lower, nothing seen to render differently.

Follow-up to #54, where the window and in-place switches moved private memory by at most ~0.3 GB.

Why

A window (4 MiB of title memory outside buffers, shadow.rs loose) was a whole CPU side in the PC's memory, plus a card side with VICTORY_CARD_WINDOWS_MB. In the world that was 2.1–3.0 GB, of which only 1.7–1.9 GB is ever sent. On a 32 GB PC with the page file Windows gave it, the commit ran out at ~23 GB private.

What it does (VICTORY_LEAN_WINDOWS=1, off by default)

  • No CPU side. A refresh only notes which bytes changed (Shadow::copy → card_changed). Host::card_before sends them from title memory to the card through one upload buffer used as a ring (Ring, VICTORY_LEAN_UPLOAD_MB, 64): each plan writes after the one before; a fence of our own is signalled behind each plan's copies, and a stretch is written over only once the card is done with it. A plan that would write over its own unsent bytes runs what it has and waits first (the world load). So lean windows hold 64 MiB of the PC's memory however many submissions fly with VICTORY_RELAY / VICTORY_LATE_WAIT. (A first version with one upload buffer per plan held 2.3 GB more write-combined memory with the relay; the ring replaced it.)
  • Tiles. Where the card reads unmapped tiles as zeros (tiled resources tier 2+), the window's buffer is reserved (Host::reserved_buffer). The 64 KiB tiles that bytes are sent to get tiles of a pool of 64 MiB heaps (Host::take_tiles, Shadow::tiles_to_map), mapped on the queue ahead of the copy (Host::map_tiles); a window let go gives its tiles back. A tile never sent reads as zeros, as a fresh buffer did. Below tier 2: a whole buffer. This is what lowers the commit — Windows charges the process for video memory too, so moving windows to the card with whole buffers (first version) saved memory in use but not commit.
  • Room. Windows default to 8 GB of the card under window_card_for's existing rule (a fifth of the budget stays free, so textures keep theirs); VICTORY_CARD_WINDOWS_MB still sets it. A window that finds no room stays as it was.
  • Writes. Shaders write no window (run 91: "0.0 MB compared in 0 ranges of windows"). A write declared for a lean window is counted (lean line), not compared or copied back. VICTORY_BVH_BUILDER=1, whose builder declares writes for every copy it reaches, turns lean windows off with a warning.
  • Lean line every 5 s: windows made, MB alive / MB in tiles mapped / MB of tile heaps, MB sent up, ring waits, writes left out.

Measured

RTX 3080 Ti 12 GB (driver 32.0.16.1742), Ryzen 7 7800X3D, 32 GB, Windows 11 Pro 26300. main 2119b0e + this, diag build, VICTORY_RELAY=2, same route (load into the prologue, no input), each run stopped by an outside guard at 20 GB private. Pairs run back to back.

seconds after the world load private, without private, VICTORY_LEAN_WINDOWS=1
+0 16.8 GB 15.0 GB −1.9 GB
+5 18.6 GB 17.4 GB −1.3 GB
+10 18.5 GB 17.8 GB −0.8 GB
+16 19.1 GB 18.2 GB −0.8 GB
+21 19.6 GB 18.9 GB −0.8 GB
memory in use at the stop 17.4 GB 15.3 GB −2.1 GB
  • Memory map: "windows of title memory and other 4 MiB allocations" 2,126 → 102 MB.
  • Lean line in the world: 815 windows, 2,932 MB alive, 1,865 MB in tiles mapped (1,920 MB of heaps); ~530 MB sent up per 5 s; 0 ring waits; 0 writes left out.
  • Frame rate about the same (2.6 vs 2.3 fps at 3,500–3,850 draws/frame; the two runs ended at different moments). No difference seen on screen.

Not fixed by this: the process still reaches ~19–20 GB private in the world (title heaps, texture copies, write-combined buffer copies); this takes ~0.8 GB of commit and ~2 GB of memory in use off it.

Checks

  • cargo clippy --release -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo test --release -p victory-gpu: 116 passed, 0 failed, 1 ignored, on the card — including new ring_tests (placement, wrap-around, long asks in pieces, overlap) and tiles_tests (tiles a range touches).
  • Not tested: AMD/Intel cards, tier-1 cards (they take the whole-buffer path), Linux/Proton, 8 GB cards (the room rule should keep windows off a full card, untried).

Written with Claude Code (Claude Opus 5.5); the runs are mine.

**@⁠CDR-0000** on GitHub · 2026-11-24 23:03 UTC · [original](https://github.com/fxceless/victory-fork/pull/265) `CDR-0000:perf/lean-windows` → `main` · +639 −27 · 2 files · 1 commits · open **Opt-in. Windows of title memory go to the card with no CPU side, their buffers reserved and mapped in 64 KiB tiles as bytes are sent, through one 64 MiB upload ring. On an RTX 3080 Ti / 32 GB PC: private memory 0.8 GB lower once the world has settled (1.9 GB at the load), memory in use 2.1 GB lower, nothing seen to render differently.** Follow-up to #54, where the window and in-place switches moved private memory by at most ~0.3 GB. ### Why A window (4 MiB of title memory outside buffers, `shadow.rs` `loose`) was a whole CPU side in the PC's memory, plus a card side with `VICTORY_CARD_WINDOWS_MB`. In the world that was 2.1–3.0 GB, of which only 1.7–1.9 GB is ever sent. On a 32 GB PC with the page file Windows gave it, the commit ran out at ~23 GB private. ### What it does (`VICTORY_LEAN_WINDOWS=1`, off by default) - **No CPU side.** A refresh only notes which bytes changed (`Shadow::copy` → `card_changed`). `Host::card_before` sends them from title memory to the card through **one upload buffer used as a ring** (`Ring`, `VICTORY_LEAN_UPLOAD_MB`, 64): each plan writes after the one before; a fence of our own is signalled behind each plan's copies, and a stretch is written over only once the card is done with it. A plan that would write over its own unsent bytes runs what it has and waits first (the world load). So lean windows hold 64 MiB of the PC's memory however many submissions fly with `VICTORY_RELAY` / `VICTORY_LATE_WAIT`. (A first version with one upload buffer per plan held 2.3 GB more write-combined memory with the relay; the ring replaced it.) - **Tiles.** Where the card reads unmapped tiles as zeros (tiled resources tier 2+), the window's buffer is reserved (`Host::reserved_buffer`). The 64 KiB tiles that bytes are sent to get tiles of a pool of 64 MiB heaps (`Host::take_tiles`, `Shadow::tiles_to_map`), mapped on the queue ahead of the copy (`Host::map_tiles`); a window let go gives its tiles back. A tile never sent reads as zeros, as a fresh buffer did. Below tier 2: a whole buffer. This is what lowers the commit — Windows charges the process for video memory too, so moving windows to the card with whole buffers (first version) saved memory in use but not commit. - **Room.** Windows default to 8 GB of the card under `window_card_for`'s existing rule (a fifth of the budget stays free, so textures keep theirs); `VICTORY_CARD_WINDOWS_MB` still sets it. A window that finds no room stays as it was. - **Writes.** Shaders write no window (run 91: "0.0 MB compared in 0 ranges of windows"). A write declared for a lean window is counted (lean line), not compared or copied back. `VICTORY_BVH_BUILDER=1`, whose builder declares writes for every copy it reaches, turns lean windows off with a warning. - **Lean line** every 5 s: windows made, MB alive / MB in tiles mapped / MB of tile heaps, MB sent up, ring waits, writes left out. ### Measured RTX 3080 Ti 12 GB (driver 32.0.16.1742), Ryzen 7 7800X3D, 32 GB, Windows 11 Pro 26300. `main` `2119b0e` + this, diag build, `VICTORY_RELAY=2`, same route (load into the prologue, no input), each run stopped by an outside guard at 20 GB private. Pairs run back to back. | seconds after the world load | private, without | private, `VICTORY_LEAN_WINDOWS=1` | | |---|---|---|---| | +0 | 16.8 GB | 15.0 GB | −1.9 GB | | +5 | 18.6 GB | 17.4 GB | −1.3 GB | | +10 | 18.5 GB | 17.8 GB | −0.8 GB | | +16 | 19.1 GB | 18.2 GB | −0.8 GB | | +21 | 19.6 GB | 18.9 GB | −0.8 GB | | memory in use at the stop | 17.4 GB | 15.3 GB | −2.1 GB | - Memory map: "windows of title memory and other 4 MiB allocations" 2,126 → 102 MB. - Lean line in the world: 815 windows, 2,932 MB alive, **1,865 MB in tiles mapped** (1,920 MB of heaps); ~530 MB sent up per 5 s; **0 ring waits**; 0 writes left out. - Frame rate about the same (2.6 vs 2.3 fps at 3,500–3,850 draws/frame; the two runs ended at different moments). No difference seen on screen. **Not fixed by this:** the process still reaches ~19–20 GB private in the world (title heaps, texture copies, write-combined buffer copies); this takes ~0.8 GB of commit and ~2 GB of memory in use off it. ### Checks - `cargo clippy --release -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo test --release -p victory-gpu`: 116 passed, 0 failed, 1 ignored, on the card — including new `ring_tests` (placement, wrap-around, long asks in pieces, overlap) and `tiles_tests` (tiles a range touches). - Not tested: AMD/Intel cards, tier-1 cards (they take the whole-buffer path), Linux/Proton, 8 GB cards (the room rule should keep windows off a full card, untried). *Written with Claude Code (Claude Opus 5.5); the runs are mine.*
A window of title memory kept a whole 4 MiB CPU side in the PC's memory
(and, with VICTORY_CARD_WINDOWS_MB, a card side as well). In the world the
windows were 2.1-3.0 GB of a 32 GB PC's memory (#54), and only part of each
is ever sent (1.7-1.9 of 2.9 GB).

With the switch, a window on the card has no CPU side:

- A refresh only notes which bytes changed (Shadow::copy). Before the
  submission Host::card_before sends them from title memory through one
  upload buffer of VICTORY_LEAN_UPLOAD_MB (64) used as a ring (Ring): each
  plan writes after the one before, a fence of our own is signalled behind
  its copies, and a stretch is written over only once the card is done with
  it. A plan that would write over its own unsent bytes runs what it has and
  waits first (world load). So the PC holds 64 MiB for lean windows however
  many submissions are in the air with VICTORY_RELAY / VICTORY_LATE_WAIT.
- Where the card reads unmapped tiles as zeros (tiled resources tier 2), the
  window's buffer is reserved (Host::reserved_buffer): the 64 KiB tiles bytes
  are sent to get tiles of a pool of 64 MiB heaps (Host::take_tiles,
  Shadow::tiles_to_map), mapped on the queue ahead of the copy
  (Host::map_tiles); a window let go gives them back. A tile never sent
  reads as zeros, as a fresh buffer did. Below tier 2 a whole buffer.
- Windows default to 8 GB of the card under window_card_for's existing room
  rule (VICTORY_CARD_WINDOWS_MB still sets it); a window that finds no room
  stays as it was.

Shaders write no window (run 91: "0.0 MB compared in 0 ranges of
windows"); a write declared for a lean window is counted in the lean line,
not compared or copied back, and VICTORY_BVH_BUILDER=1 (whose builder writes
every copy it reaches) turns lean windows off. Off by default.

Measured (RTX 3080 Ti, 32 GB, on 2119b0e, diag build, same route, matched
seconds after the world load): private memory 0.8 GB lower once settled
(1.9 GB at the load), memory in use 2.1 GB lower, 0 ring waits in the world.
Windows charge the process for video memory too, so moving windows to the
card alone saved the PC's memory in use but not its commit; the tiles are
what lower the commit.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:39:30 +00:00
Author
Owner

@⁠SkillIssueXO on GitHub · 2026-11-24 23:06 UTC · original

Baseline data for the memory window change from a longer 2119b0e Series X run at 1080p with VICTORY_RELAY=2 and VICTORY_TEXTURE_BUDGET_MB=3072 on an RTX 5070 Ti / 32 GiB system.

  • Over the last 29 seconds of the renderer census, windows outside buffers rose from 5,744 to 6,364 MiB while title-filled texture copies stayed near the cap (3,115 → 3,081 MiB). The final census showed 6,184 MiB of windows referenced by descriptor slots and 4,352 MiB of pages ever copied.
  • The runner stopped at 2.95 GiB of free Windows commit during the first mission. All 584 CPU comparison reports through that poll showed zero window ranges.

This gives a later-scene baseline for the opt-in path, in particular for checking peak commit, upload-ring waits and declared writes left out. AI-assisted log analysis.

**@⁠SkillIssueXO** on GitHub · 2026-11-24 23:06 UTC · [original](https://github.com/fxceless/victory-fork/pull/265#issuecomment-7147031285) Baseline data for the memory window change from a longer `2119b0e` Series X run at 1080p with `VICTORY_RELAY=2` and `VICTORY_TEXTURE_BUDGET_MB=3072` on an RTX 5070 Ti / 32 GiB system. - Over the last 29 seconds of the renderer census, windows outside buffers rose from 5,744 to 6,364 MiB while title-filled texture copies stayed near the cap (3,115 → 3,081 MiB). The final census showed 6,184 MiB of windows referenced by descriptor slots and 4,352 MiB of pages ever copied. - The runner stopped at 2.95 GiB of free Windows commit during the first mission. All 584 CPU comparison reports through that poll showed zero window ranges. This gives a later-scene baseline for the opt-in path, in particular for checking peak commit, upload-ring waits and declared writes left out. AI-assisted log analysis.
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-25 00:56 UTC · original

To use Codex here, create a Codex account and connect to github.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-25 00:56 UTC · [original](https://github.com/fxceless/victory-fork/pull/265#issuecomment-7149039367) To use Codex here, [create a Codex account and connect to github](https://chatgpt.com/codex/cloud/settings/connectors).
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/host.rs
  • crates/victory-gpu/src/shadow.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

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

Merge

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