Repository navigation
Conversation
…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>
|
Triage verdict — Keep the window-size experiment stacked on #402 ( Evidence
Checks and limits
Next step
This verification was AI-assisted. |
DenRakEiw
left a comment
There was a problem hiding this comment.
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 (includinga_parent_is_found_past_many_childrenandregistered_buffers_widen_the_search)cargo clippy -p victory-gpu --all-targets— 0 warningscargo 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
left a comment
There was a problem hiding this comment.
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>
|
Thanks, good catch. I added the synthetic case you described (
It passes on the RTX 5080 under Proton. The full 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 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 |
|
@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 ( Same stack otherwise (upstream
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. |
|
Automated triage for the maintainers. Merge candidate. Still carries #402 rebased (author kept) plus the On your reply: the new commit One small edge case: if a 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>
|
On the triage's first point, unbounded misses in 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 Change: buffers of 1 MiB or more are also kept in a small map of their own. A lookup first scans 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.
The second point (two overlapping copies within one submission can disagree, and smaller windows make boundary crossings more frequent) stands as described. |
… 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>
|
A correction to my earlier comment: I've reverted the lookup change in 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 |
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 inMEMORY_POOL_L0system 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.
main+ #402)no descriptor slots for a title memory copy's viewsThat'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 fromhost copies of title memoryon theheap viewsline; the world uses one page table, and it holds one view pair per copy.main)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
main+ GPU: free memory is not the runtime's to watch (fixes a world-load deadlock under Wine) #1849 (without it the title hangs at world entry under Wine).+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. Plainmainon this machine fails the same 14 (129 passed). GPU: find a buffer holding an address past many smaller ones; reuse loose windows that hold a range #402's four tests pass, and they are written againstWINDOW, so they cover the new size.cargo clippy -p victory-gpu --all-targets -- -D warnings: nothing new.Related
shadow.rs(pooling view copies). It might conflict textually, but the two change different things.AI-assisted (Claude Code).
🤖 Generated with Claude Code