Skip to content

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

Open
desplmfao wants to merge 10 commits into
Marvisak:mainfrom
desplmfao:perf/loose-window-size
Open

desplmfao wants to merge 10 commits into
Marvisak:mainfrom
desplmfao:perf/loose-window-size

Conversation

@desplmfao

@desplmfao desplmfao commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

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

Related

AI-assisted (Claude Code).

🤖 Generated with Claude Code

kxiserino and others added 3 commits November 24, 2026 02:56
…oose windows that hold a range

`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 <noreply@anthropic.com>
…oose windows that hold a range

`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 <noreply@anthropic.com>
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 <noreply@anthropic.com>
@jeremygold02

Copy link
Copy Markdown
Contributor

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

Evidence

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

This verification was AI-assisted.

@DenRakEiw DenRakEiw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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 <noreply@anthropic.com>
@desplmfao

Copy link
Copy Markdown
Contributor Author

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

Copy link
Copy Markdown
Contributor Author

@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.

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

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

… ones

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 <noreply@anthropic.com>
@desplmfao

Copy link
Copy Markdown
Contributor Author

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.

… the big ones"

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 <noreply@anthropic.com>
@desplmfao

Copy link
Copy Markdown
Contributor Author

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 added a commit to desplmfao/VIctory that referenced this pull request Nov 25, 2026
desplmfao added a commit to desplmfao/VIctory that referenced this pull request Nov 25, 2026
desplmfao added a commit to desplmfao/VIctory that referenced this pull request Nov 25, 2026
The previous main (old upstream base) is the first parent; the second is
upstream main with the current heads of our pull requests merged in:
Marvisak#2143, Marvisak#1849 (carried onto main's per-region runtime_pages), Marvisak#259, Marvisak#491,
Marvisak#2153, Marvisak#2099, Marvisak#2071 (main covers it), Marvisak#2162, Marvisak#2218, Marvisak#2088, Marvisak#2389, Marvisak#177's
element-type key on main's three handle maps, and the README. Marvisak#2112
(opt-in, in place) stays in the renderer branch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@r4tedx

r4tedx commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

@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 added a commit to r4tedx/VIctory that referenced this pull request Nov 25, 2026
…#2088 76cdef6: loose title memory in 256 KiB windows, with Marvisak#402's window reuse) into play/main"

This reverts merge 75b3f75 (Marvisak#2088) on play/main, with the mainline
kept (git revert -m 1).

The user's same-save A/B runs in the safehouse, on the RTX 5070: PM1
(play/main 75b3f75, with Marvisak#2088) against PM0 (404c7e0, without it).
With Marvisak#2088's 256 KiB windows, host copies of title memory went to about
6 GB a frame, against about 0.55 GB without. Preparing averaged 981 ms
against 377 ms, and the median frame was 428 ms longer: PM0 - PM1 95%
bootstrap CI [-569, -346] ms. Page faults were 52.7k against 27.6k a
frame. Marvisak#2088 did save about 2.9 GB of memory. That win is kept for a
later, fixed form, one that does not copy that much more each frame.

Everything else on play/main stays, including the read_only: false fix
the merge carried (it was in Marvisak#2088's own test, so it goes with it).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 25, 2026
r4tedx added a commit to r4tedx/VIctory that referenced this pull request Nov 25, 2026
…_VRAM), on play/main

Fork gpu/tables-in-vram 2a2a602 (F1), ported onto play/main as one
commit so it reverts alone. A variant for the GPU thread's A/B (unset,
=1, =copy); not part of play/main.

Only 2a2a602's own change is taken (a cherry-pick). Its base, upstream
main da82e44, is 81 commits past play/main's 940d32f; merging the
branch would have brought all of them in, victory-shader too (a new
shader cache key), with conflicts in 23 files.

Conflicts and how they were resolved:
- descriptor/host.rs, the view addresses: F1 was written for upstream
  main's layout (16 bytes a title slot, texture size words). play/main
  keeps layer 4's layout, which its shaders read: 8 bytes (the address)
  for every title AND dynamic slot (address_slots), ray tracing
  acceleration structures' addresses included (view_address), resident
  per frame. So: F1's crate::tables::Table for the field, made with
  address_slots() * 8 bytes and keep_resident(table.resource(), Frame);
  layer 4's dynamic-slot fill, index check and write_address() words,
  written through Table::write(2 * index, ..). The test reader
  address_at() reads through a new test-only Table::read(). The stride
  and mark tables merged cleanly.
- memory.rs: layer 4's D3D12 imports kept (zeros() still uses
  ID3D12Resource); layer 4's test helpers pipeline() / pipeline_of()
  kept, pipeline_of() made pub(crate), and tables.rs's test calls
  memory::tests::pipeline_of(READ) where F1 called upstream's
  pipeline(source).
- host.rs Meter: layer 4's dynamic-slot drop line, then F1's table-copy
  line.
- lib.rs: mod tables and mod threads, each #[cfg(windows)].
- README.md: play/main's VICTORY_SHADER_LOOP_LIMIT row (2^14, as
  lower.rs's LOOP_LIMIT here) plus F1's VICTORY_TABLES_VRAM row.

Merged cleanly, checked by hand: host.rs submit, where the table copy
list goes first in `lists` and the later runs' `firsts` move up by one,
so the per-run groups VICTORY_GPU_TIMING times (built from firsts)
still name whole runs, the copy list joining the first.

Also ported, missed in the first form (it did not build): layer 4's
resident-table loop in HostHeap::new and the tests
view_heap_tables_are_kept_resident,
an_acceleration_structures_view_address_is_its_location and
view_addresses_cover_tables_made_afresh still took the tables as
(buffer, mapping) tuples. They now use Table::resource(), a Table in
system memory, and a test-only Table::mapped() (the buffer the host's
mapping is of, the staging buffer in =copy mode), so the past-the-end
check still looks at the mapped buffer in every mode.

Rebased onto play/main aeeaed5 (Marvisak#2088 reverted, 7d9a846's dynamic
tables, the test fix): it applied cleanly. host.rs Meter now has 7d9a846's longer
dynamic-slot line, then F1's table-copy line. The first form of this
commit was 001945d, on play/main 75b3f75.

(cherry picked from commit 2a2a602)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
r4tedx added a commit to r4tedx/VIctory that referenced this pull request Nov 25, 2026
…c tables, runs PM0/PM1/PM2, three variants

Parts 4 to 7: Marvisak#2088 reverted (64136f6) with the PM0/PM1 numbers, the
GPU-cost report fix (e92714a), the dynamic tables (99d3e30) and their
test fix (aeeaed5). The runs PM0, PM1 and PM2 side by side. The WARP
lib results at each head. The current build (victory-99d3e306.exe), and
the variants play/main-tables-vram c49ef67, play/main-shaders f965f80
and play/main-copyback a4ed2b0, each with its exe, sha256 and tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
desplmfao and others added 3 commits November 25, 2026 19:57
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 Marvisak#402's MAX_SPAN search, the loose-window reuse
(LOOSE_SPAN, enclosing_window) and the committed/null-page checks on top.
Marvisak#402's tests join main's `pub(crate) mod tests`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
update/402-main is Marvisak#402 with main merged in. Its shadow.rs replaces this
branch's copy of Marvisak#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 <noreply@anthropic.com>
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.
Marvisak#402's window reuse stays as it is.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
desplmfao added a commit to desplmfao/VIctory that referenced this pull request Nov 26, 2026
…ICTORY_LOOSE_WINDOW_KIB), default 4 MiB

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
desplmfao added a commit to desplmfao/VIctory that referenced this pull request Nov 26, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@desplmfao

Copy link
Copy Markdown
Contributor Author

@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.

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 <noreply@anthropic.com>
desplmfao added a commit to desplmfao/VIctory that referenced this pull request Nov 26, 2026
…_KIB

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
desplmfao added a commit to desplmfao/VIctory that referenced this pull request Nov 26, 2026
…_KIB

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
desplmfao added a commit to desplmfao/VIctory that referenced this pull request Nov 26, 2026
…n place, opt-in)

A plain merge would have dropped Marvisak#2112: the old fork main merged an
earlier Marvisak#2112 head (cd079af), so it is a merge base, and the current
main left Marvisak#2112 out, which reads as a deletion. Merged against the right
base instead: upstream main (67e8ae1) with Marvisak#2088's two commits Marvisak#2112
stacks on (b670a33), and Marvisak#2112's head applied over that file by file
(README, host.rs, memory.rs, shadow.rs, watch.rs; no conflicts). Marvisak#2088's
reverted two-step lookup is not in Marvisak#2112 and stays out.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
desplmfao added a commit to desplmfao/VIctory that referenced this pull request Nov 26, 2026
…ICTORY_LOOSE_WINDOW_KIB), default 4 MiB

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
desplmfao added a commit to desplmfao/VIctory that referenced this pull request Nov 26, 2026
…_KIB

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
desplmfao added a commit to desplmfao/VIctory that referenced this pull request Nov 26, 2026
The previous renderer (old upstream base 940d32f) is the first parent and
is also kept as the branch renderer-2026-11-25-oldbase; the second parent
is the rebuild: fork main (upstream main 63bcca4 + our pull requests) with
the renderer stack merged on it: Marvisak#439 (on main: update/439-main's
resolution), Marvisak#2309, Marvisak#2167, Marvisak#2118, Marvisak#2311, Marvisak#1722, Marvisak#1751, Marvisak#688, Marvisak#1872, Marvisak#2292,
Marvisak#2310, Marvisak#2112 (opt-in), Marvisak#2230 (latch on by default), Marvisak#2389, Marvisak#2088 (small
windows opt-in), Marvisak#2099's new head, and tonight's Marvisak#491 journal fixes.
Merged upstream since: Marvisak#2143, Marvisak#2162, Marvisak#158, Marvisak#1906, Marvisak#1152; superseded by
main: Marvisak#1769, Marvisak#1763, Marvisak#2366.

The picture on this base still shows the overlay that plain upstream main
shows too; that is being looked into.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@kotekompotek kotekompotek left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

crashbashash added a commit to crashbashash/VIctory-proton that referenced this pull request Nov 26, 2026
…B=256 for machines short on memory

256 KiB loose windows: the GPU's system memory 5.6-5.8 GiB instead of 8.7-8.9 GiB in the prison scene, frames no slower; one crash in eight runs with it, none without, so it stays opt-in.
crashbashash added a commit to crashbashash/VIctory-proton that referenced this pull request Nov 26, 2026
…ash link is ruled out

Both title crashes of the night came from builds with Marvisak#402/Marvisak#2088 in: a null
read in title code entering the world (256 KiB windows) and one while
loading (default 4 MiB windows, dstorage debug log on), 2 of 17 runs,
against none in about 30 runs without them. Marvisak#402 changes, by default,
which copy a lookup finds. Not proven, but players pull this branch, so the
code goes back to b25fd9a's until an A/B says otherwise.

Reverts 1669715, dee9e0d, 2cbfd20, ce1351d, 9c29e6a, dce3ee8.
crashbashash added a commit to crashbashash/VIctory-proton that referenced this pull request Nov 26, 2026
…rash is not theirs

Reverts c73cbee. An A/B with the DirectStorage debug log on (which slows
the submit path) crashed once in five runs on each side, with and without
these commits, the same way as before: title code reading a null pointer
in its job system (thread entry +0x2215eca, dispatch +0x2570xxx), while
loading or entering the world. All four such crashes of the night share
that path. Without the debug log: 1 in 16 runs with these commits (with
256 KiB windows), 0 in about 30 without; with it, 3 in 11 across both
builds. So it looks like a timing race around DirectStorage, not these
commits. The docs say so; 256 KiB windows stay opt-in.
@pickles976

Copy link
Copy Markdown

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).

@desplmfao desplmfao changed the title GPU: copy loose title memory in 256 KiB windows instead of 4 MiB (stacked on #402) GPU: reuse loose windows that hold a range (#402), 256 KiB windows opt-in (VICTORY_LOOSE_WINDOW_KIB) Nov 26, 2026
crashbashash added a commit to crashbashash/VIctory-proton that referenced this pull request Nov 26, 2026
…B=256 for machines short on memory

256 KiB loose windows: the GPU's system memory 5.6-5.8 GiB instead of 8.7-8.9 GiB in the prison scene, frames no slower; one crash in eight runs with it, none without, so it stays opt-in.
crashbashash added a commit to crashbashash/VIctory-proton that referenced this pull request Nov 26, 2026
…ash link is ruled out

Both title crashes of the night came from builds with Marvisak#402/Marvisak#2088 in: a null
read in title code entering the world (256 KiB windows) and one while
loading (default 4 MiB windows, dstorage debug log on), 2 of 17 runs,
against none in about 30 runs without them. Marvisak#402 changes, by default,
which copy a lookup finds. Not proven, but players pull this branch, so the
code goes back to b25fd9a's until an A/B says otherwise.

Reverts 1669715, dee9e0d, 2cbfd20, ce1351d, 9c29e6a, dce3ee8.
crashbashash added a commit to crashbashash/VIctory-proton that referenced this pull request Nov 26, 2026
…rash is not theirs

Reverts c73cbee. An A/B with the DirectStorage debug log on (which slows
the submit path) crashed once in five runs on each side, with and without
these commits, the same way as before: title code reading a null pointer
in its job system (thread entry +0x2215eca, dispatch +0x2570xxx), while
loading or entering the world. All four such crashes of the night share
that path. Without the debug log: 1 in 16 runs with these commits (with
256 KiB windows), 0 in about 30 without; with it, 3 in 11 across both
builds. So it looks like a timing race around DirectStorage, not these
commits. The docs say so; 256 KiB windows stay opt-in.

@fuzeofficlal fuzeofficlal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

BastienRodz added a commit to BastienRodz/VIctory that referenced this pull request Nov 26, 2026
… range (Marvisak#402), 256 KiB windows opt-in (VICTORY_LOOSE_WINDOW_KIB)
BastienRodz added a commit to BastienRodz/VIctory that referenced this pull request Nov 26, 2026
… range (Marvisak#402), 256 KiB windows opt-in (VICTORY_LOOSE_WINDOW_KIB)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants