GPU: reuse loose windows that hold a range (#402), 256 KiB windows opt-in (VICTORY_LOOSE_WINDOW_KIB) #2088

Open
github-bot wants to merge 10 commits from github-bot/gh-2088 into main AGit
Owner

@⁠desplmfao on GitHub · 2026-11-25 04:34 UTC · original
desplmfao:perf/loose-window-size → main · +253 −13 · 2 files · 10 commits · open

Stacked on #402 by @⁠kxiserino: its commit is the first one here, unchanged apart from resolving its conflict with current main (940d32f), and keeps its author. The second commit is the change below. If #402 lands first, this reduces to one line plus its comment.

Problem

Memory outside every buffer object (shadow::loose) gets host copies of the aligned windows that lookups touch, and those copies are never freed. A window was 4 MiB. While Grand Theft Auto VI loads its world (Series X 1.0.2.1), about 700 windows are live, 3.4 GB of host memory. They sit in MEMORY_POOL_L0 system memory, so it's RAM on top of the title memory they copy, and every page-table submission refreshes them.

Measured

I counted which parts of each window lookups ask for (64 KiB pieces, diagnostics build, temporary counters not part of this PR): at the same point of loading, 968 MB of 3,416 MB. That's about 30% of the bytes copied.

at the same point of loading 4 MiB windows (main + #402) 256 KiB windows (this PR)
loose windows 687, 3,416 MB 5,713, 2,168 MB
process RSS 17.3–20.4 GB 15.4 GB
no descriptor slots for a title memory copy's views 0 0

That's about 1.2 GB less while loading. Each window is a host buffer and an entry in the title-memory page table, so smaller windows mean more of them. 256 KiB was chosen to keep that count moderate. 64 KiB would cut more bytes but multiply the windows again.

In the open world

Added later, once the world loaded here (the hang was a single compute pass, skipped with VICTORY_SKIP_PIPELINES=72f552f4553fb5f9; see #844). Same stack otherwise (940d32f + other open PRs), same save, about 2 min into the open world. Host copies are counted from host copies of title memory on the heap views line; the world uses one page table, and it holds one view pair per copy.

in the open world 4 MiB windows (main) 256 KiB windows (this PR)
host copies = descriptor pairs 5,858 16,956
memory held in those copies 11.4 GB 6.5 GB
process RSS 29.2 GB (still growing after 3 min) ~15.8 GB

So in the world the smaller windows save about 5 GB of copies and about 13 GB of RSS. They cost about 3× the descriptor pairs, which is still far below the view heap's 2^21 slots.

Also tried, and not part of this PR: freeing windows no lookup has used for 5 s. During loading, almost all windows are used again within seconds (680 of 734), and others are held by lists or heap slots, so it barely freed anything.

Tested

  • RTX 5080, Linux, proton-cachyos 11.0 with vkd3d-proton 3.2.0, main + #1849 (without it the title hangs at world entry under Wine).
  • First runs: loading only. Under Wine they ended at world entry in the title's watchdog (+0x23cf683), the same as runs without this change. The open-world numbers above came later, with the one hanging pass skipped. Frame time is not measured.
  • cargo test -p victory-gpu -- --test-threads 1: 133 passed, 14 failed. Plain main on this machine fails the same 14 (129 passed). #402's four tests pass, and they are written against WINDOW, so they cover the new size.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: nothing new.
  • #880, #407, #1147: reading title memory in place instead of copying it, which would remove these copies entirely. This PR is only the smaller step.
  • #1979 also changes shadow.rs (pooling view copies). It might conflict textually, but the two change different things.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

**@⁠desplmfao** on GitHub · 2026-11-25 04:34 UTC · [original](https://github.com/Marvisak/VIctory/pull/2088) `desplmfao:perf/loose-window-size` → `main` · +253 −13 · 2 files · 10 commits · open Stacked on #402 by @⁠kxiserino: its commit is the first one here, unchanged apart from resolving its conflict with current `main` (`940d32f`), and keeps its author. The second commit is the change below. If #402 lands first, this reduces to one line plus its comment. ## Problem Memory outside every buffer object (`shadow::loose`) gets host copies of the aligned windows that lookups touch, and those copies are never freed. A window was 4 MiB. While Grand Theft Auto VI loads its world (Series X 1.0.2.1), about 700 windows are live, 3.4 GB of host memory. They sit in `MEMORY_POOL_L0` system memory, so it's RAM on top of the title memory they copy, and every page-table submission refreshes them. ## Measured I counted which parts of each window lookups ask for (64 KiB pieces, diagnostics build, temporary counters not part of this PR): at the same point of loading, **968 MB of 3,416 MB**. That's about 30% of the bytes copied. | at the same point of loading | 4 MiB windows (`main` + #402) | 256 KiB windows (this PR) | |---|---|---| | loose windows | 687, 3,416 MB | 5,713, 2,168 MB | | process RSS | 17.3–20.4 GB | 15.4 GB | | `no descriptor slots for a title memory copy's views` | 0 | 0 | That's about 1.2 GB less while loading. Each window is a host buffer and an entry in the title-memory page table, so smaller windows mean more of them. 256 KiB was chosen to keep that count moderate. 64 KiB would cut more bytes but multiply the windows again. ### In the open world Added later, once the world loaded here (the hang was a single compute pass, skipped with `VICTORY_SKIP_PIPELINES=72f552f4553fb5f9`; see #844). Same stack otherwise (`940d32f` + other open PRs), same save, about 2 min into the open world. Host copies are counted from `host copies of title memory` on the `heap views` line; the world uses one page table, and it holds one view pair per copy. | in the open world | 4 MiB windows (`main`) | 256 KiB windows (this PR) | |---|---|---| | host copies = descriptor pairs | 5,858 | 16,956 | | memory held in those copies | 11.4 GB | 6.5 GB | | process RSS | 29.2 GB (still growing after 3 min) | ~15.8 GB | So in the world the smaller windows save about 5 GB of copies and about 13 GB of RSS. They cost about 3× the descriptor pairs, which is still far below the view heap's 2^21 slots. Also tried, and not part of this PR: freeing windows no lookup has used for 5 s. During loading, almost all windows are used again within seconds (680 of 734), and others are held by lists or heap slots, so it barely freed anything. ## Tested - RTX 5080, Linux, proton-cachyos 11.0 with vkd3d-proton 3.2.0, `main` + #1849 (without it the title hangs at world entry under Wine). - First runs: loading only. Under Wine they ended at world entry in the title's watchdog (`+0x23cf683`), the same as runs without this change. The open-world numbers above came later, with the one hanging pass skipped. Frame time is not measured. - `cargo test -p victory-gpu -- --test-threads 1`: 133 passed, 14 failed. Plain `main` on this machine fails the same 14 (129 passed). #402's four tests pass, and they are written against `WINDOW`, so they cover the new size. - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: nothing new. ## Related - #880, #407, #1147: reading title memory in place instead of copying it, which would remove these copies entirely. This PR is only the smaller step. - #1979 also changes `shadow.rs` (pooling view copies). It might conflict textually, but the two change different things. AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
`shadow::find` looked at only the 64 buffers starting closest below an
address. A big buffer with more than 64 smaller buffers placed in it
before the address was missed, and the range fell through to `loose`,
which made a second 4 MiB host copy of memory the big buffer's copy
already had, not aliased with it. The search now goes back as far as the
longest buffer registered so far (`MAX_SPAN`): one starting further below
cannot hold the range.

`loose` reused a window only for the exact same (start, length), so a
range inside a window made for a range spanning two windows got another
copy. It now reuses any window holding the range. It also gives no copy
for null-page addresses, or for memory that is not committed when a new
window would be made, instead of 4 MiB of zeros.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`shadow::find` looked at only the 64 buffers starting closest below an
address. A big buffer with more than 64 smaller buffers placed in it
before the address was missed, and the range fell through to `loose`,
which made a second 4 MiB host copy of memory the big buffer's copy
already had, not aliased with it. The search now goes back as far as the
longest buffer registered so far (`MAX_SPAN`): one starting further below
cannot hold the range.

`loose` reused a window only for the exact same (start, length), so a
range inside a window made for a range spanning two windows got another
copy. It now reuses any window holding the range. It also gives no copy
for null-page addresses, or for memory that is not committed when a new
window would be made, instead of 4 MiB of zeros.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Memory outside every buffer object gets host copies of the aligned
windows lookups touch. While Grand Theft Auto VI loads its world, about
700 such 4 MiB windows (3.4 GB of host memory) were live; the lookups
touched about 30% of their bytes (in 64 KiB pieces). With 256 KiB
windows, at the same point of loading: 5,713 windows, 2.2 GB, and the
process 15.4 GB instead of 17.3 to 20.4 GB. No descriptor-slot warnings
for the extra windows' page-table entries.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A range in one window, then a range across its end, which gets a window
of its own over both: the title's writes reach both copies at their
refresh, and a shader's write through the spanning copy goes back to
title memory and into the first copy at its next refresh.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A miss in the buffer lookup scanned every buffer starting within the
longest buffer's length below the address (MAX_SPAN, 174 MB in the
world): about 480 entries per miss on average, at most 2,842, and some
330,000 misses every 5 s, all under BUFFERS' lock (measured in Grand
Theft Auto VI's world, RTX 5080 under Proton).

Buffers of 1 MiB or more are now also kept in a small map of their own.
A lookup scans BUFFERS only within the longest smaller buffer's length
below the address, then the big buffers further below, back to
MAX_SPAN. Only a big buffer can hold the range from further below, so
the result is the same innermost buffer.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This reverts commit b73bb8b. With it, Grand Theft Auto VI's world showed
spikes out of the player character's head and triangles stretched across
the scene in two runs; the same build without it is clean. A stale entry
in the map of big buffers (a key registered again shorter) explains the
spikes, but with that fixed the triangles stayed, so the change goes until
it is understood. The lookup cost it targeted is back as before (about 480
entries per miss).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Conflicts in crates/victory-gpu/src/shadow.rs: main's copies now come
back as Arc from Shadow::new and bump GENERATION through changed(); kept
that and added #402's MAX_SPAN search, the loose-window reuse
(LOOSE_SPAN, enclosing_window) and the committed/null-page checks on top.
#402's tests join main's `pub(crate) mod tests`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
update/402-main is #402 with main merged in. Its shadow.rs replaces this
branch's copy of #402's commit (same change on an older main); this
branch's own changes go on top: 256 KiB windows and the
overlapping-windows test. The two-step lookup stays reverted.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
r4tedx's in-game A/B of this branch (RTX 5070) measured the 256 KiB
windows at +428 ms median frame time: host copies grew from about 0.55 GB
to about 6 GB per frame in the open world, for about 2.9 GB of host
memory saved. Loose windows are 4 MiB again (main's size) unless
VICTORY_LOOSE_WINDOW_KIB asks for a power of two from 64 to 4096 KiB.
#402's window reuse stays as it is.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
No range: sizes far from the default are the user's own experiment. Only
a value that is not a power of two, or one whose bytes overflow, falls
back to 4 MiB.

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

@⁠jeremygold02 on GitHub · 2026-11-25 04:40 UTC · original

Triage verdict — Keep the window-size experiment stacked on #402 (b670a33)

Evidence

  • @⁠desplmfao’s second commit changes the window size. The first commit carries @⁠kxiserino’s #402 lookup and reuse work onto current main. The reported memory reduction trades fewer copied bytes for many more windows, each with its own descriptor pair. Stack commits · Pair allocation
  • The map test covers selecting a window that already encloses a range. If a new lookup crosses a boundary after a narrower window already exists, loose can allocate a spanning window that overlaps it. The page table prefers smaller complete-page copies, while a spanning buffer view can still use the larger copy. That leaves a coherence case worth checking at the new, more frequent boundaries. Window lookup · Page ownership

Checks and limits

  • Verified the two-commit ancestry and compared the lookup and page-table paths. The memory figures and the four passing stack tests are author-reported. I did not run the loading benchmark or reproduce a coherence failure.

Next step

  • Retain #402’s rebased commit and credit. Before judging the smaller window on bytes alone, add a synthetic case that looks up one side, then a range spanning the boundary, then reads both routes after a refresh. Record descriptor-pair pressure as well as copied bytes.

This verification was AI-assisted.

**@⁠jeremygold02** on GitHub · 2026-11-25 04:40 UTC · [original](https://github.com/Marvisak/VIctory/pull/2088#issuecomment-7153057094) **Triage verdict — Keep the window-size experiment stacked on #402** (`b670a33`) **Evidence** - @⁠desplmfao’s second commit changes the window size. The first commit carries @⁠kxiserino’s #402 lookup and reuse work onto current `main`. The reported memory reduction trades fewer copied bytes for many more windows, each with its own descriptor pair. [Stack commits](https://git.gtahub.st/github/Marvisak--VIctory/pulls/2088/commits) · [Pair allocation](https://github.com/Marvisak/VIctory/blob/b670a33fc49973b0dfae60840d425bbd0313dd9c/crates/victory-gpu/src/memory.rs#L277-L309) - The map test covers selecting a window that already encloses a range. If a new lookup crosses a boundary after a narrower window already exists, `loose` can allocate a spanning window that overlaps it. The page table prefers smaller complete-page copies, while a spanning buffer view can still use the larger copy. That leaves a coherence case worth checking at the new, more frequent boundaries. [Window lookup](https://github.com/Marvisak/VIctory/blob/b670a33fc49973b0dfae60840d425bbd0313dd9c/crates/victory-gpu/src/shadow.rs#L904-L951) · [Page ownership](https://github.com/Marvisak/VIctory/blob/b670a33fc49973b0dfae60840d425bbd0313dd9c/crates/victory-gpu/src/memory.rs#L203-L237) **Checks and limits** - Verified the two-commit ancestry and compared the lookup and page-table paths. The memory figures and the four passing stack tests are author-reported. I did not run the loading benchmark or reproduce a coherence failure. **Next step** - Retain #402’s rebased commit and credit. Before judging the smaller window on bytes alone, add a synthetic case that looks up one side, then a range spanning the boundary, then reads both routes after a refresh. Record descriptor-pair pressure as well as copied bytes. This verification was AI-assisted.
Author
Owner

@⁠desplmfao on GitHub · 2026-11-25 07:15 UTC · original

Thanks, good catch. I added the synthetic case you described (f83faa7, overlapping_windows_agree_through_title_memory):

  • A range inside one window gets window A. A range across A's end then gets its own window B over both, so A lies inside B.
  • A title write reaches both copies at their refresh.
  • A shader write through B goes back to title memory at copy-back, and A picks it up at its next refresh.

It passes on the RTX 5080 under Proton. The full victory-gpu suite gives 134 passed, with the same 13 NVIDIA/Wine failures as main here.

What the test can't make safe is two overlapping copies within one submission. If a shader writes through B and another reads the same bytes through A before the copy-back, it reads the old bytes. That's true of any two copies of the same memory, title buffers and windows included, and on main with 4 MiB windows too. Smaller windows put boundaries 16× as often, so a range crosses one more often. I haven't seen a symptom I could tie to it, but I haven't looked for one specifically.

On descriptor-pair pressure: in Grand Theft Auto VI's world with 256 KiB windows, I've seen 6,000–8,300 live windows in the host copies live lines, and one page table. I haven't logged pairs per table against the 4 MiB baseline yet. I'll add that number from the next world run.

**@⁠desplmfao** on GitHub · 2026-11-25 07:15 UTC · [original](https://github.com/Marvisak/VIctory/pull/2088#issuecomment-7155662022) Thanks, good catch. I added the synthetic case you described (`f83faa7`, `overlapping_windows_agree_through_title_memory`): - A range inside one window gets window A. A range across A's end then gets its own window B over both, so A lies inside B. - A title write reaches both copies at their refresh. - A shader write through B goes back to title memory at copy-back, and A picks it up at its next refresh. It passes on the RTX 5080 under Proton. The full `victory-gpu` suite gives 134 passed, with the same 13 NVIDIA/Wine failures as `main` here. What the test can't make safe is two overlapping copies within one submission. If a shader writes through B and another reads the same bytes through A before the copy-back, it reads the old bytes. That's true of any two copies of the same memory, title buffers and windows included, and on `main` with 4 MiB windows too. Smaller windows put boundaries 16× as often, so a range crosses one more often. I haven't seen a symptom I could tie to it, but I haven't looked for one specifically. On descriptor-pair pressure: in Grand Theft Auto VI's world with 256 KiB windows, I've seen 6,000–8,300 live windows in the `host copies live` lines, and one page table. I haven't logged pairs per table against the 4 MiB baseline yet. I'll add that number from the next world run.
Author
Owner

@⁠desplmfao on GitHub · 2026-11-25 09:02 UTC · original

@⁠jeremygold02 here's the number I promised: descriptor pairs per page table with 4 MiB windows (without this PR) vs. 256 KiB (with it). Upstream's page table writes one view pair per host copy of title memory, and the world uses one table, so pairs = host copies (host copies of title memory on the heap views diagnostics line).

Same stack otherwise (upstream 940d32f + our other open PRs), GTA VI Series X 1.0.2.1, same save, about 2 min into the open world, RTX 5080, Linux/Proton:

4 MiB windows (main) 256 KiB windows (#2088)
Host copies = descriptor pairs 5,858 16,956
Memory held in those copies 11.4 GB 6.5 GB
Game process RAM (RSS) 29.2 GB ~15.8 GB

So the smaller windows do cost about 3× the pairs, but 17k is still far below the view heap's 2^21 slots. In exchange, the copies hold about 5 GB less, and the process uses about 13 GB less RAM. Without this PR, the run was at 29 GB after 3 minutes and still growing, so I stopped it.

**@⁠desplmfao** on GitHub · 2026-11-25 09:02 UTC · [original](https://github.com/Marvisak/VIctory/pull/2088#issuecomment-7157790910) @⁠jeremygold02 here's the number I promised: descriptor pairs per page table with 4 MiB windows (without this PR) vs. 256 KiB (with it). Upstream's page table writes one view pair per host copy of title memory, and the world uses one table, so pairs = host copies (`host copies of title memory` on the `heap views` diagnostics line). Same stack otherwise (upstream `940d32f` + our other open PRs), GTA VI Series X 1.0.2.1, same save, about 2 min into the open world, RTX 5080, Linux/Proton: | | 4 MiB windows (main) | 256 KiB windows (#2088) | |---|---|---| | Host copies = descriptor pairs | 5,858 | 16,956 | | Memory held in those copies | 11.4 GB | 6.5 GB | | Game process RAM (RSS) | 29.2 GB | ~15.8 GB | So the smaller windows do cost about 3× the pairs, but 17k is still far below the view heap's 2^21 slots. In exchange, the copies hold about 5 GB less, and the process uses about 13 GB less RAM. Without this PR, the run was at 29 GB after 3 minutes and still growing, so I stopped it.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 10:33 UTC · original · edited 2026-11-26 02:16 UTC

Automated triage for the maintainers.

Merge candidate. 6ebed99 merges cleanly and keeps the 4 MiB default: in crates/victory-gpu/src/shadow.rs, window() reads VICTORY_LOOSE_WINDOW_KIB once (window_from accepts a power of two, else 4 MiB), and the README lists the switch. What changes by default is #402's part, carried here on current main: enclosing searches back by MAX_SPAN instead of a fixed 64 entries, loose reuses a window that already holds the range (enclosing_window), and refuses addresses below LOWEST_MAPPED or not committed (texture::committed). Tests cover the lookup past many placed buffers, window reuse, overlapping windows through title memory, the variable's parsing and uncommitted memory. CI check passes.

On your reply: making the small windows opt-in answers the open-world A/B (+428 ms median, ~6 GB copied per frame), so the default path no longer pays that cost. Two notes for the maintainer: the PR title still says "256 KiB windows instead of 4 MiB", which is now only the opt-in; and since this PR carries #402's commit, merging it makes #402 (which conflicts with main) redundant.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 10:33 UTC · [original](https://github.com/Marvisak/VIctory/pull/2088#issuecomment-7159863140) · edited 2026-11-26 02:16 UTC <!-- victory-triage v1 head=6ebed99283da64d5118705a26ecd28c980aab27c verdict=merge-candidate at=2026-11-26T02:19:00Z --> Automated triage for the maintainers. **Merge candidate.** `6ebed99` merges cleanly and keeps the 4 MiB default: in `crates/victory-gpu/src/shadow.rs`, `window()` reads `VICTORY_LOOSE_WINDOW_KIB` once (`window_from` accepts a power of two, else 4 MiB), and the README lists the switch. What changes by default is #402's part, carried here on current `main`: `enclosing` searches back by `MAX_SPAN` instead of a fixed 64 entries, `loose` reuses a window that already holds the range (`enclosing_window`), and refuses addresses below `LOWEST_MAPPED` or not committed (`texture::committed`). Tests cover the lookup past many placed buffers, window reuse, overlapping windows through title memory, the variable's parsing and uncommitted memory. CI `check` passes. On your reply: making the small windows opt-in answers the open-world A/B (+428 ms median, ~6 GB copied per frame), so the default path no longer pays that cost. Two notes for the maintainer: the PR title still says "256 KiB windows instead of 4 MiB", which is now only the opt-in; and since this PR carries #402's commit, merging it makes #402 (which conflicts with `main`) redundant. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠desplmfao on GitHub · 2026-11-25 10:59 UTC · original

On the triage's first point, unbounded misses in enclosing: measured, and addressed in b73bb8b.

Before (title's world, RTX 5080, Proton, our stack on top of this PR): every 5 s, about 1.4 million lookups hit after looking at 1 entry, and about 330,000 missed. Each miss scanned every buffer starting within MAX_SPAN below the address. MAX_SPAN was 174 MB, so a miss looked at 480 entries on average and up to 2,842, all under BUFFERS' lock.

Change: buffers of 1 MiB or more are also kept in a small map of their own. A lookup first scans BUFFERS only within the longest smaller buffer's length below the address (1008 KB here), then only the big buffers further below, back to MAX_SPAN. Only a big buffer can hold the range from further below, so the result is the same innermost buffer. A new test checks the two-step lookup against the one-step enclosing on a heap holding hundreds of placed buffers.

After, same place: misses look at 4.2 entries on average, at most 218. Hits are unchanged at 1. Frame time didn't move measurably (675 vs 725 ms, within run-to-run noise), so the lookups weren't a big share of a frame, but they no longer hold the lock long.

cargo test -p victory-gpu --lib shadow:: under Proton: 10 passed. Clippy is clean with and without --features diagnostics.

The second point (two overlapping copies within one submission can disagree, and smaller windows make boundary crossings more frequent) stands as described. overlapping_windows_agree_through_title_memory covers agreement across submissions, not within one.

**@⁠desplmfao** on GitHub · 2026-11-25 10:59 UTC · [original](https://github.com/Marvisak/VIctory/pull/2088#issuecomment-7160444996) On the triage's first point, unbounded misses in `enclosing`: measured, and addressed in `b73bb8b`. **Before** (title's world, RTX 5080, Proton, our stack on top of this PR): every 5 s, about 1.4 million lookups hit after looking at 1 entry, and about 330,000 missed. Each miss scanned every buffer starting within `MAX_SPAN` below the address. `MAX_SPAN` was 174 MB, so a miss looked at **480 entries on average and up to 2,842**, all under `BUFFERS`' lock. **Change:** buffers of 1 MiB or more are also kept in a small map of their own. A lookup first scans `BUFFERS` only within the longest smaller buffer's length below the address (1008 KB here), then only the big buffers further below, back to `MAX_SPAN`. Only a big buffer can hold the range from further below, so the result is the same innermost buffer. A new test checks the two-step lookup against the one-step `enclosing` on a heap holding hundreds of placed buffers. **After**, same place: misses look at **4.2 entries on average, at most 218**. Hits are unchanged at 1. Frame time didn't move measurably (675 vs 725 ms, within run-to-run noise), so the lookups weren't a big share of a frame, but they no longer hold the lock long. `cargo test -p victory-gpu --lib shadow::` under Proton: 10 passed. Clippy is clean with and without `--features diagnostics`. The second point (two overlapping copies within one submission can disagree, and smaller windows make boundary crossings more frequent) stands as described. `overlapping_windows_agree_through_title_memory` covers agreement across submissions, not within one.
Author
Owner

@⁠desplmfao on GitHub · 2026-11-25 12:48 UTC · original

A correction to my earlier comment: I've reverted the lookup change in 76cdef6 (a new commit, no force-push), so this PR is back to exactly what it was before b73bb8b.

In the title, the two-step lookup broke the picture: spikes out of the player character's head and triangles stretched across the scene, in two runs. The same build without it is clean. I found one real bug, a stale entry in the big-buffer map when a key is registered again shorter, and fixing it removed the spikes, but the stretched triangles stayed, so I don't understand the change well enough to keep it here.

The triage's first point (misses in enclosing scan every buffer within MAX_SPAN, about 480 entries per miss in the world) is therefore open again. It costs lock time but doesn't change results. If I come back to it, it'll be a separate PR that has been checked in the title first. Sorry for the noise.

**@⁠desplmfao** on GitHub · 2026-11-25 12:48 UTC · [original](https://github.com/Marvisak/VIctory/pull/2088#issuecomment-7162896479) A correction to my earlier comment: I've reverted the lookup change in `76cdef6` (a new commit, no force-push), so this PR is back to exactly what it was before `b73bb8b`. In the title, the two-step lookup broke the picture: spikes out of the player character's head and triangles stretched across the scene, in two runs. The same build without it is clean. I found one real bug, a stale entry in the big-buffer map when a key is registered again shorter, and fixing it removed the spikes, but the stretched triangles stayed, so I don't understand the change well enough to keep it here. The triage's first point (misses in `enclosing` scan every buffer within `MAX_SPAN`, about 480 entries per miss in the world) is therefore open again. It costs lock time but doesn't change results. If I come back to it, it'll be a separate PR that has been checked in the title first. Sorry for the noise.
Author
Owner

@⁠r4tedx on GitHub · 2026-11-25 21:22 UTC · original

@⁠desplmfao, an in-game A/B of this PR on an RTX 5070 (12 GB, Windows 11), for the memory/time trade-off. Our play build is main 940d32f plus a stack of open PRs. The two exes differ only by this PR's merge (head 76cdef61, so with your revert of b73bb8b). Same open-world save, same switches, about 200 world frames each. Local title data was used for the runs; only log figures are given here.

without this PR with this PR
frame, mean 1,218 ms 1,860 ms
frame, median difference +428 ms (95% CI 346 to 569)
preparing 377 ms 981 ms
host copies per frame ~0.55 GB, 83-146 ms ~6 GB, ~800 ms
page faults per frame 27.6 k 52.7 k
GPU / copying back 183 / 126 ms 196 / 132 ms

On memory, the PR does what it says. In an earlier, indoor scene, loose windows took 5,520 MB of host copies with 4 MiB windows; in this run they take 2,640 MB, so roughly 2.9 GB saved. But in the open world the copies per frame grow about tenfold, and that's what the frame time pays for. My guess, not checked in the code: the same loose ranges are now spread over many more windows, and each window that a page-table submission refreshes is copied whole, or a lookup that misses refills a window it just dropped. That would trade bytes held for bytes moved every frame. A diagnostics count of loose windows refreshed per frame, and their bytes, with 4 MiB against 256 KiB, would tell.

We've taken it out of our play build for now and kept the numbers for when there's a form that keeps the memory win.

AI-assisted

**@⁠r4tedx** on GitHub · 2026-11-25 21:22 UTC · [original](https://github.com/Marvisak/VIctory/pull/2088#issuecomment-7174996616) @⁠desplmfao, an in-game A/B of this PR on an RTX 5070 (12 GB, Windows 11), for the memory/time trade-off. Our play build is `main` 940d32f plus a stack of open PRs. The two exes differ only by this PR's merge (head `76cdef61`, so with your revert of `b73bb8b`). Same open-world save, same switches, about 200 world frames each. Local title data was used for the runs; only log figures are given here. | | without this PR | with this PR | |---|---:|---:| | frame, mean | 1,218 ms | 1,860 ms | | frame, median difference | | +428 ms (95% CI 346 to 569) | | preparing | 377 ms | 981 ms | | host copies per frame | ~0.55 GB, 83-146 ms | ~6 GB, ~800 ms | | page faults per frame | 27.6 k | 52.7 k | | GPU / copying back | 183 / 126 ms | 196 / 132 ms | On memory, the PR does what it says. In an earlier, indoor scene, loose windows took 5,520 MB of host copies with 4 MiB windows; in this run they take 2,640 MB, so roughly 2.9 GB saved. But in the open world the copies per frame grow about tenfold, and that's what the frame time pays for. My guess, not checked in the code: the same loose ranges are now spread over many more windows, and each window that a page-table submission refreshes is copied whole, or a lookup that misses refills a window it just dropped. That would trade bytes held for bytes moved every frame. A diagnostics count of loose windows refreshed per frame, and their bytes, with 4 MiB against 256 KiB, would tell. We've taken it out of our play build for now and kept the numbers for when there's a form that keeps the memory win. AI-assisted
Author
Owner

@⁠desplmfao on GitHub · 2026-11-26 01:27 UTC · original

@⁠r4tedx thanks for the A/B. +428 ms median, and ~6 GB copied per frame in the open world instead of ~0.55 GB, is far too much for the ~2.9 GB it saves. 2f0590a makes the 256 KiB windows opt-in: VICTORY_LOOSE_WINDOW_KIB=256 (a power of two from 64 to 4096) turns them on, and the default is 4 MiB, as on main. #402's reuse of a loose window that already holds the range stays on.

#402 has conflicted with main for about 20 hours, so this PR now builds on update/402-main (9f64779). That branch is #402's single commit, unchanged, with main (63bcca4) merged in. The only conflict was in shadow.rs, where main's Arc/changed() copies now carry #402's lookup and reuse.

shadow:: and watch:: give 31 passed under Wine (RTX 5080), including a new test of the variable's parsing. Clippy is clean with and without diagnostics. Next, I want to find out why the small windows copy so much more: a diagnostics count of loose windows refreshed per frame, and their bytes, at 4 MiB against 256 KiB, as you suggested.

**@⁠desplmfao** on GitHub · 2026-11-26 01:27 UTC · [original](https://github.com/Marvisak/VIctory/pull/2088#issuecomment-7179789766) @⁠r4tedx thanks for the A/B. +428 ms median, and ~6 GB copied per frame in the open world instead of ~0.55 GB, is far too much for the ~2.9 GB it saves. `2f0590a` makes the 256 KiB windows opt-in: `VICTORY_LOOSE_WINDOW_KIB=256` (a power of two from 64 to 4096) turns them on, and the default is 4 MiB, as on `main`. #402's reuse of a loose window that already holds the range stays on. #402 has conflicted with `main` for about 20 hours, so this PR now builds on [`update/402-main`](https://github.com/desplmfao/VIctory/tree/update/402-main) (`9f64779`). That branch is #402's single commit, unchanged, with `main` (`63bcca4`) merged in. The only conflict was in `shadow.rs`, where `main`'s `Arc`/`changed()` copies now carry #402's lookup and reuse. `shadow::` and `watch::` give 31 passed under Wine (RTX 5080), including a new test of the variable's parsing. Clippy is clean with and without diagnostics. Next, I want to find out why the small windows copy so much more: a diagnostics count of loose windows refreshed per frame, and their bytes, at 4 MiB against 256 KiB, as you suggested.
github-bot changed title from GPU: copy loose title memory in 256 KiB windows instead of 4 MiB (stacked on #402) to GPU: reuse loose windows that hold a range (#402), 256 KiB windows opt-in (VICTORY_LOOSE_WINDOW_KIB) 2026-11-26 08:07:25 +00:00
Author
Owner

@⁠DenRakEiw on GitHub · 2026-11-25 04:41 UTC · original · approved these changes

Verified locally merged onto origin/main (940d32f, Windows 11 x64, Rust 1.98.1 MSVC):

  • cargo test -p victory-gpu --lib shadow:: — 8 passed, 0 failed (including a_parent_is_found_past_many_children and registered_buffers_widen_the_search)
  • cargo clippy -p victory-gpu --all-targets — 0 warnings
  • cargo xtask policy — ok (183 files ok)

Clean 256 KiB loose title-memory copy windowing and enclosing-entry lookup with solid unit tests. Looks good.

AI-assisted (Gemini 4 Neon).

**@⁠DenRakEiw** on GitHub · 2026-11-25 04:41 UTC · [original](https://github.com/Marvisak/VIctory/pull/2088#pullrequestreview-6051958633) · **approved these changes** Verified locally merged onto `origin/main` (`940d32f`, Windows 11 x64, Rust 1.98.1 MSVC): - `cargo test -p victory-gpu --lib shadow::` — 8 passed, 0 failed (including `a_parent_is_found_past_many_children` and `registered_buffers_widen_the_search`) - `cargo clippy -p victory-gpu --all-targets` — 0 warnings - `cargo xtask policy` — ok (`183 files ok`) Clean 256 KiB loose title-memory copy windowing and enclosing-entry lookup with solid unit tests. Looks good. AI-assisted (Gemini 4 Neon).
Author
Owner

@⁠catminou4 on GitHub · 2026-11-25 05:02 UTC · original · reviewed

Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff.

Loose title memory copied in 256 KiB windows instead of 4 MiB — finer copy granularity, less over-copy; check the window loop's tail handling.

**@⁠catminou4** on GitHub · 2026-11-25 05:02 UTC · [original](https://github.com/Marvisak/VIctory/pull/2088#pullrequestreview-6052104837) · **reviewed** Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff. Loose title memory copied in 256 KiB windows instead of 4 MiB — finer copy granularity, less over-copy; check the window loop's tail handling.
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-26 03:01 UTC · original · approved these changes

LGTM — the delta over #402 (which I just reviewed: enclosing lookup + committed gate) is the window-size switch and its coherence test.

  • window_from enforces power-of-two before the align-down & !(window-1) can depend on it, checked_mul/checked_next_multiple_of cover the arithmetic edges, and the default stays 4 MiB.
  • changed() after LOOSE insert was missing in the base — needed now that more distinct windows appear.
  • overlapping_windows_agree_through_title_memory is the right test for the new overlapping-window possibility: title write → both copies see it; GPU write through the spanning window → copy-back → title → the enclosed copy picks it up next refresh. The comment honestly documents the intra-submission divergence, which is identical to any two copies of the same bytes.
  • The measured trade-off (256 KiB: GBs less host memory, ~10x copy bytes/frame in open world) is documented in both the code comment and README — default behavior unchanged.
**@⁠kotekompotek** on GitHub · 2026-11-26 03:01 UTC · [original](https://github.com/Marvisak/VIctory/pull/2088#pullrequestreview-6067976629) · **approved these changes** LGTM — the delta over #402 (which I just reviewed: enclosing lookup + committed gate) is the window-size switch and its coherence test. - `window_from` enforces power-of-two before the align-down `& !(window-1)` can depend on it, `checked_mul`/`checked_next_multiple_of` cover the arithmetic edges, and the default stays 4 MiB. - `changed()` after LOOSE insert was missing in the base — needed now that more distinct windows appear. - `overlapping_windows_agree_through_title_memory` is the right test for the new overlapping-window possibility: title write → both copies see it; GPU write through the spanning window → copy-back → title → the enclosed copy picks it up next refresh. The comment honestly documents the intra-submission divergence, which is identical to any two copies of the same bytes. - The measured trade-off (256 KiB: GBs less host memory, ~10x copy bytes/frame in open world) is documented in both the code comment and README — default behavior unchanged.
Author
Owner

@⁠pickles976 on GitHub · 2026-11-26 06:09 UTC · original

Wine11.0 / NVIDIA RTX4060 Laptop8GiB /16GiB system RAM, driver590.48.1, DXVK3.1.1, diagnostic relaxed vkd3d-proton3.2.0 2576c0b4adfae4a+ (assertions disabled and allocator/list from_iface vtable checks removed; null checks retained):

At 6ebed99283da64d5118705a26ecd28c980aab27c, VICTORY_LOOSE_WINDOW_KIB=256, four focused tests passed,0failed/ignored: window_sizes_are_any_power_of_two, loose_windows_are_reused_for_ranges_inside_them, loose_memory_must_be_committed, overlapping_windows_agree_through_title_memory. Fresh compile, NVIDIA enumerated. The only test change makes missing D3D12 host fail instead of return. The overlap fixture checks GPU-backed/title-memory copy coherence, not shader dispatch. Log verify-pr2088-wine-256k.log.

Then ran the full owner branch, not a granularity-only transplant, with a local diagnostics-only two-second try-lock probe of LOOSE count/backing bytes. Fresh release44.05s. No skip-pipeline or forced in-place flags. Same6,000MiB GPU /2,048MiB available-RAM /10GiB disk guard and9GiB/512MiB scope caps. 20261126T060451Z ended at its110s wall limit (exit137), not a resource stop. One Enter at57s moved the verified account picker to loading; the100s capture was still loading art. Last ownership sample109.9s:3,295loose buffers,1,171MiB backing,window262,144bytes. Last/min availableRAM2,437MiB; maxscope6,759MiB,scopeanon2,631MiB; maxGPU3,355MiB; mindisk19.176GiB.

This is only~53s after entering loading, not proof that loading completes or the RAM ceiling is solved. Earlier main+#2856 measured2,604MiB loose backing later in loading; source, timing and cache state differ, so that is not a matched-stage memory-saving claim. Compute host-pipeline refusals 0x80070057 (b68f0931f1f47e61, 13dfdd3b1136e407) remain. No controllable gameplay or world-FPS result; the documented small-window copy/frametime tradeoff is unmeasured here. Logs 20261126T060451Z-{console.log,resources.csv,guard-events.jsonl}; captures menu-20261126T060549361265Z.png (loading stars) and menu-20261126T060631047369Z.png (loading art).

**@⁠pickles976** on GitHub · 2026-11-26 06:09 UTC · [original](https://github.com/Marvisak/VIctory/pull/2088#issuecomment-7184152978) Wine11.0 / NVIDIA RTX4060 Laptop8GiB /16GiB system RAM, driver590.48.1, DXVK3.1.1, **diagnostic relaxed vkd3d-proton3.2.0 `2576c0b4adfae4a+`** (assertions disabled and allocator/list `from_iface` vtable checks removed; null checks retained): At `6ebed99283da64d5118705a26ecd28c980aab27c`, `VICTORY_LOOSE_WINDOW_KIB=256`, four focused tests passed,0failed/ignored: `window_sizes_are_any_power_of_two`, `loose_windows_are_reused_for_ranges_inside_them`, `loose_memory_must_be_committed`, `overlapping_windows_agree_through_title_memory`. Fresh compile, NVIDIA enumerated. The only test change makes missing D3D12 host fail instead of return. The overlap fixture checks GPU-backed/title-memory copy coherence, **not shader dispatch**. Log `verify-pr2088-wine-256k.log`. Then ran the **full owner branch**, not a granularity-only transplant, with a local diagnostics-only two-second try-lock probe of `LOOSE` count/backing bytes. Fresh release44.05s. No skip-pipeline or forced in-place flags. Same6,000MiB GPU /2,048MiB available-RAM /10GiB disk guard and9GiB/512MiB scope caps. `20261126T060451Z` ended at its110s wall limit (exit137), **not a resource stop**. One Enter at57s moved the verified account picker to loading; the100s capture was still loading art. Last ownership sample109.9s:3,295loose buffers,**1,171MiB backing**,window262,144bytes. Last/min availableRAM2,437MiB; maxscope6,759MiB,scopeanon2,631MiB; maxGPU3,355MiB; mindisk19.176GiB. This is only~53s after entering loading, **not proof that loading completes or the RAM ceiling is solved**. Earlier main+#2856 measured2,604MiB loose backing later in loading; source, timing and cache state differ, so that is not a matched-stage memory-saving claim. Compute host-pipeline refusals `0x80070057` (`b68f0931f1f47e61`, `13dfdd3b1136e407`) remain. No controllable gameplay or world-FPS result; the documented small-window copy/frametime tradeoff is unmeasured here. Logs `20261126T060451Z-{console.log,resources.csv,guard-events.jsonl}`; captures `menu-20261126T060549361265Z.png` (loading stars) and `menu-20261126T060631047369Z.png` (loading art).
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 12:39 UTC · original · approved these changes

Reviewed and verified at head 6ebed992 against origin/main (63bcca43) on Windows 11 (RTX 5090 + WARP, VICTORY_D3D12_DEBUG=1, both default 4 MiB and VICTORY_LOOSE_WINDOW_KIB=256):

  • Design & correctness:
    • Keeps the 4 MiB default unchanged while making smaller loose windows opt-in via VICTORY_LOOSE_WINDOW_KIB (crates/victory-gpu/src/shadow.rs:1082-1095, documented in README.md:220). window_from enforces is_power_of_two() and checked_mul(1 << 10) so alignment masks and end.checked_next_multiple_of(window)? - start (shadow.rs:1132) cannot overflow or underflow.
    • Carries #402's lookup improvements onto 63bcca43: enclosing (shadow.rs:1023-1032) searches back by MAX_SPAN instead of a fixed 64 entries, enclosing_window (shadow.rs:1108-1118) reuses existing loose windows containing [address, end), loose (shadow.rs:1124-1148) gates on LOWEST_MAPPED (0x10000) and texture::committed(address, 1), and changed() notifies page tables on LOOSE insertion. overlapping_windows_agree_through_title_memory (shadow.rs:1830-1869) verifies cross-submission coherence through title memory; structured-view arena/stride paths are untouched.
    • Note for maintainers: since this PR incorporates #402 and modifies shadow.rs::loose(), it supersedes #402 and overlaps #2856 in shadow.rs (only one should land, or they should be reconciled).
  • Verification:
    • Clean git merge-tree against origin/main (63bcca43); cargo xtask policy (191 files ok); cargo clippy -p victory-gpu --all-targets --locked -- -D warnings clean with default features and --all-features.
    • RTX 5090: shadow::tests 15/15 passed with both 4 MiB default and VICTORY_LOOSE_WINDOW_KIB=256; with --features diagnostics + VICTORY_D3D12_DEBUG=1, shadow::tests + draw::tests 35/35 (4 MiB) and shadow::tests 15/15 (256 KiB) passed with zero debug-layer errors.
    • WARP (VICTORY_D3D12_WARP=1, VICTORY_D3D12_DEBUG=1): shadow::tests 15/15 (256 KiB) and shadow::tests + draw::tests 35/35 (4 MiB) passed.

LGTM.

**@⁠fuzeofficlal** on GitHub · 2026-11-26 12:39 UTC · [original](https://github.com/Marvisak/VIctory/pull/2088#pullrequestreview-6074271291) · **approved these changes** Reviewed and verified at head `6ebed992` against `origin/main` (`63bcca43`) on Windows 11 (RTX 5090 + WARP, `VICTORY_D3D12_DEBUG=1`, both default 4 MiB and `VICTORY_LOOSE_WINDOW_KIB=256`): - **Design & correctness**: - Keeps the 4 MiB default unchanged while making smaller loose windows opt-in via `VICTORY_LOOSE_WINDOW_KIB` (`crates/victory-gpu/src/shadow.rs:1082-1095`, documented in `README.md:220`). `window_from` enforces `is_power_of_two()` and `checked_mul(1 << 10)` so alignment masks and `end.checked_next_multiple_of(window)? - start` (`shadow.rs:1132`) cannot overflow or underflow. - Carries `#402`'s lookup improvements onto `63bcca43`: `enclosing` (`shadow.rs:1023-1032`) searches back by `MAX_SPAN` instead of a fixed 64 entries, `enclosing_window` (`shadow.rs:1108-1118`) reuses existing loose windows containing `[address, end)`, `loose` (`shadow.rs:1124-1148`) gates on `LOWEST_MAPPED` (`0x10000`) and `texture::committed(address, 1)`, and `changed()` notifies page tables on `LOOSE` insertion. `overlapping_windows_agree_through_title_memory` (`shadow.rs:1830-1869`) verifies cross-submission coherence through title memory; structured-view arena/stride paths are untouched. - Note for maintainers: since this PR incorporates `#402` and modifies `shadow.rs::loose()`, it supersedes `#402` and overlaps `#2856` in `shadow.rs` (only one should land, or they should be reconciled). - **Verification**: - Clean `git merge-tree` against `origin/main` (`63bcca43`); `cargo xtask policy` (`191 files ok`); `cargo clippy -p victory-gpu --all-targets --locked -- -D warnings` clean with default features and `--all-features`. - **RTX 5090**: `shadow::tests` **15/15** passed with both 4 MiB default and `VICTORY_LOOSE_WINDOW_KIB=256`; with `--features diagnostics` + `VICTORY_D3D12_DEBUG=1`, `shadow::tests` + `draw::tests` **35/35** (4 MiB) and `shadow::tests` **15/15** (256 KiB) passed with zero debug-layer errors. - **WARP (`VICTORY_D3D12_WARP=1`, `VICTORY_D3D12_DEBUG=1`)**: `shadow::tests` **15/15** (256 KiB) and `shadow::tests` + `draw::tests` **35/35** (4 MiB) passed. LGTM.
This pull request can be merged automatically.
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/2088/head:github-bot/gh-2088'
git switch 'github-bot/gh-2088'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2088'
git switch 'github-bot/gh-2088'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2088'
git switch 'github-bot/gh-2088'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2088'
git switch 'main'
git merge --squash 'github-bot/gh-2088'
git switch 'main'
git merge --ff-only 'github-bot/gh-2088'
git switch 'main'
git merge 'github-bot/gh-2088'
git push origin 'main'
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/Marvisak--VIctory!2088
No description provided.