Windows of title memory that grow from what is asked for, instead of 4 MiB each (VICTORY_WINDOW_GROW=1, off by default): about 0.9 GB less #477

Open
github-bot wants to merge 4 commits from github-bot/gh-477 into main AGit
Owner

@⁠wildheathen on GitHub · 2026-11-27 23:13 UTC · original
wildheathen:window-grow → main · +589 −23 · 4 files · 4 commits · open

What this changes

A read of title memory outside the known buffers gets a host copy, a "window". Today each window is a 4 MiB host buffer on the 4 MiB grid, whatever is read in it, and all of it is resident. On my machine, at the end of a three-minute run, 727 windows held 3,100 MB, while what was read in them lay within about 1,700 MB.

The finer grid that is already in main (VICTORY_WINDOW_KB=256 VICTORY_WINDOW_TAILS=1) saved nothing here: 3,060 MB of windows over 1,746 MB of title memory. The descriptor slots made on the shorter windows kept those windows alive beside the longer ones made later for the same memory.

With VICTORY_WINDOW_GROW=1, each 4 MiB cell has one window, from the lowest to the highest 256 KiB step asked for in it (to the cell's end for an ask without a length). When an ask goes past it, a longer window takes the place of the shorter one:

  • find returns the longer one from then on;
  • the pass over the heap makes the slots that show the shorter one again, on the longer one;
  • until no slot shows the shorter one, what is brought up to date or written through the longer one also goes to the shorter one (Shadow::forward, only to windows a slot still shows);
  • the shorter one waits in TAKEN_OVER until no slot, list or pass holds it, then goes with the idle windows.

Only the window that begins in the ask's own cell holds an ask, so the window find returns for an address changes only when one is replaced. Memory at a cell's edge can be in two windows.

The switch is off by default. When it is off, the behaviour is the same as before: the new paths return after one OnceLock read.

Measured

The same diagnostics build of this branch (on main 64d4931), the same 3-minute scripted run (Series X, 2560x1440, DLSS Quality, frame generation), switch off against on; memory line at the end:

off (4 MiB grid) VICTORY_WINDOW_GROW=1
Windows in all 3,216 MB 2,283 MB
... over title memory 2,856 MB 2,268 MB
Windows shown by descriptor slots 733, 3,116 MB 704, 2,235 MB
Windows replaced and still held 3, 2 MB
Process private memory, mean 120-180 s 26.06 GB 25.27 GB
GPU committed memory, mean 120-180 s 15.93 GB 15.01 GB
fps in the world, median (5 s lines) 24.2 28.7
5 s lines under 10 fps entering the world 3 1

One run each, so the fps rows only say it is not slower. Windows grew 3,739 times in the run; 62,106 slots of the heap and 7 of draws' tables were made again on the longer windows, none was left null. I saw no difference in the picture. Two earlier pairs of runs on the previous main gave the same window figures (3,204 against 2,177 and 2,184 MB).

PR #321 reaches for the same memory from the launcher side, with a finer grid on 16 GB PCs (3,400 to 2,598 MB there). On this 32 GB machine the finer grid did not help, for the reason given above. The two can be combined.

Slots and replaced windows

A slot that shows a replaced window is made again on the longer one where it is next used: by the pass over the heap (at once for the slots the pass keeps ranges for), and by a draw that reads its table. Until then Shadow::forward keeps the replaced window up to date, so nothing is lost; what shaders write through one window can reach a reader of the other a frame late. In the run above that was rare: 7 table slots in three minutes.

The diagnostics line "memory, heap slots elsewhere" (only with the switch on) says how often the pass finds a slot showing another copy than the one it brings up to date: 128 times in 2,490 passes (0.05 a pass; it was 0.33 a pass before these slots were made again), none still so after being made again.

Tests

The window choice, the overlap that forwarding uses and the chain of replaced windows are pure functions now (holding_in, overlap, chained), with seven new tests in shadow::window_tests: a window of the cell below does not hold an ask (this test fails if the lookup goes back to starting in the cell below), the cell's window holds an ask only up to its end, an ask without a length when the window already runs past the cell's end, each grown window holds the one before, overlaps (inside, across either end, disjoint, adjacent), and chains (windows gone are dropped, the old one comes last, the list it was taken from stays as it was).
cargo test -p victory-gpu: 443 passed; everything passes except indirect::tests::host_list_budget_starts_empty_at_each_submission and indirect::tests::warp_batch_charges_every_execution, which also fail on main.

Setup

RTX 5080 16 GB, driver 621.24, Ryzen 7 9800X3D, 32 GB, Windows 11 Pro. Series X profile, 2560x1440, DLSS Quality. My own dump. No game files are attached or quoted.

**@⁠wildheathen** on GitHub · 2026-11-27 23:13 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/477) `wildheathen:window-grow` → `main` · +589 −23 · 4 files · 4 commits · open ## What this changes A read of title memory outside the known buffers gets a host copy, a "window". Today each window is a 4 MiB host buffer on the 4 MiB grid, whatever is read in it, and all of it is resident. On my machine, at the end of a three-minute run, 727 windows held 3,100 MB, while what was read in them lay within about 1,700 MB. The finer grid that is already in `main` (`VICTORY_WINDOW_KB=256 VICTORY_WINDOW_TAILS=1`) saved nothing here: 3,060 MB of windows over 1,746 MB of title memory. The descriptor slots made on the shorter windows kept those windows alive beside the longer ones made later for the same memory. With `VICTORY_WINDOW_GROW=1`, each 4 MiB cell has **one** window, from the lowest to the highest 256 KiB step asked for in it (to the cell's end for an ask without a length). When an ask goes past it, a longer window takes the place of the shorter one: - `find` returns the longer one from then on; - the pass over the heap makes the slots that show the shorter one again, on the longer one; - until no slot shows the shorter one, what is brought up to date or written through the longer one also goes to the shorter one (`Shadow::forward`, only to windows a slot still shows); - the shorter one waits in `TAKEN_OVER` until no slot, list or pass holds it, then goes with the idle windows. Only the window that begins in the ask's own cell holds an ask, so the window `find` returns for an address changes only when one is replaced. Memory at a cell's edge can be in two windows. The switch is off by default. When it is off, the behaviour is the same as before: the new paths return after one `OnceLock` read. ## Measured The same diagnostics build of this branch (on `main` 64d4931), the same 3-minute scripted run (Series X, 2560x1440, DLSS Quality, frame generation), switch off against on; memory line at the end: | | off (4 MiB grid) | `VICTORY_WINDOW_GROW=1` | |---|---|---| | Windows in all | 3,216 MB | **2,283 MB** | | ... over title memory | 2,856 MB | 2,268 MB | | Windows shown by descriptor slots | 733, 3,116 MB | 704, 2,235 MB | | Windows replaced and still held | | 3, 2 MB | | Process private memory, mean 120-180 s | 26.06 GB | **25.27 GB** | | GPU committed memory, mean 120-180 s | 15.93 GB | 15.01 GB | | fps in the world, median (5 s lines) | 24.2 | 28.7 | | 5 s lines under 10 fps entering the world | 3 | 1 | One run each, so the fps rows only say it is not slower. Windows grew 3,739 times in the run; 62,106 slots of the heap and 7 of draws' tables were made again on the longer windows, none was left null. I saw no difference in the picture. Two earlier pairs of runs on the previous `main` gave the same window figures (3,204 against 2,177 and 2,184 MB). PR #321 reaches for the same memory from the launcher side, with a finer grid on 16 GB PCs (3,400 to 2,598 MB there). On this 32 GB machine the finer grid did not help, for the reason given above. The two can be combined. ## Slots and replaced windows A slot that shows a replaced window is made again on the longer one where it is next used: by the pass over the heap (at once for the slots the pass keeps ranges for), and by a draw that reads its table. Until then `Shadow::forward` keeps the replaced window up to date, so nothing is lost; what shaders write through one window can reach a reader of the other a frame late. In the run above that was rare: 7 table slots in three minutes. The diagnostics line "memory, heap slots elsewhere" (only with the switch on) says how often the pass finds a slot showing another copy than the one it brings up to date: 128 times in 2,490 passes (0.05 a pass; it was 0.33 a pass before these slots were made again), none still so after being made again. ## Tests The window choice, the overlap that forwarding uses and the chain of replaced windows are pure functions now (`holding_in`, `overlap`, `chained`), with seven new tests in `shadow::window_tests`: a window of the cell below does not hold an ask (this test fails if the lookup goes back to starting in the cell below), the cell's window holds an ask only up to its end, an ask without a length when the window already runs past the cell's end, each grown window holds the one before, overlaps (inside, across either end, disjoint, adjacent), and chains (windows gone are dropped, the old one comes last, the list it was taken from stays as it was). `cargo test -p victory-gpu`: 443 passed; everything passes except `indirect::tests::host_list_budget_starts_empty_at_each_submission` and `indirect::tests::warp_batch_charges_every_execution`, which also fail on `main`. ## Setup RTX 5080 16 GB, driver 621.24, Ryzen 7 9800X3D, 32 GB, Windows 11 Pro. Series X profile, 2560x1440, DLSS Quality. My own dump. No game files are attached or quoted.
A window outside buffers is a 4 MiB host buffer whatever is read, and all of
it is resident: on an RTX 5080 (run nv-1127-k) 727 windows held 3,100 MB while
what was asked for in them lay within 1,700 MB. A finer grid
(VICTORY_WINDOW_KB=256 VICTORY_WINDOW_TAILS=1, run nv-1127-l) saved nothing:
3,060 MB of windows over 1,746 MB of title memory, because the descriptor
slots made on the shorter windows kept them alive beside the longer ones.

With VICTORY_WINDOW_GROW=1 a 4 MiB cell has one window, from the lowest to
the highest 256 KiB step asked for (to the cell's end for an ask without a
length). An ask past it makes a longer window that takes the place of the
shorter one:
- find gives the longer one from then on;
- the pass over the heap makes again the slots that show the shorter one;
- until nothing holds the shorter one, what is brought up to date or
  written through the longer one is through it too (Shadow::forward);
- the shorter one is kept in TAKEN_OVER until no slot, list or pass
  holds it, then retired with the idle windows.

The memory line (diagnostics) says how many windows grew, how many taken
over are still held and their bytes, and how many heap slots moved.
Three faults of 129a821 found in review:
- A window was also looked for among those beginning in the cell below.
  find gave that one until the cell had a window of its own and this one
  from then on, without a takeover: a slot made on the first showed a
  window nothing brought up to date and what shaders wrote through it was
  lost. Now only the window beginning in the ask's cell holds an ask.
- forward went to every window taken over, which TAKEN_OVER holds until
  it is let go, and put it in the list too: a window in use every frame
  kept the one it took the place of for good. Now it forwards only to
  those a descriptor slot still shows.
- The takeover took the old window's chain (mem::take), so a thread that
  had the old window from find no longer forwarded to the ones before it.
  Now it is copied.
holding_in (the cell's window that holds an ask), overlap (the part
forward hands to a window taken over) and chained (the chain a takeover
gives the new window) are free functions now, with tests in window_tests.
No change in behaviour.
Two faults of the growing windows, both with VICTORY_WINDOW_GROW=1 only:

- A slot made on a window a longer one took the place of went on showing
  it: a slot of a draw's table until the title wrote it again, a slot the
  pass over the heap keeps until its turn in the round (up to 16 passes).
  Root views, vertex buffers and newer slots use the longer window, so
  what shaders wrote through one reached the other a frame late. Now the
  draw makes its table's slot again (State::table_entry), and the pass
  looks at once at the slots it keeps on a window taken over
  (HeapRanges::slots_where). TAKEN_OVER is a RwLock: every slot of a
  draw's table reads it while any window is held.

- The pass brought one copy up to date while the slot showed another: for
  a view's own bytes when the window's start moved down (view_home counts
  from it), the slot then read a copy nothing brought up to date. The pass
  now makes such a slot again, once.

A list recorded before the takeover and run after a slot is made again may
find the longer window not filled yet there; nothing copies the bytes over
and nothing counts it.

The memory lines (diagnostics) say how many slots of draws' tables moved,
and a new one ("heap slots elsewhere") by which kinds of copy the slots
disagreed, how many still did after being made again, and how often a pass.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 23:17:39 +00:00
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

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

Merge

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