memory: memo fast path for the builder (VICTORY_MEMO=0 turns it off) #533
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/lobomfz--VIctory-xmem!533
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-533"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@cerealfordinner on GitHub · 2026-12-04 23:28 UTC · original
cerealfordinner:upstream-pr-memo-fastpath→main· +187 −1 · 2 files · 2 commits · openMemo fast path for the hardware BVH builder: skips the builder's repeated work. On by default;
VICTORY_MEMO=0turns it off.Repeated A/B benches: 1% lows +12% (10.2 -> 11.5), average unchanged.
cargo check -p victory-gpu -p victory-shader --lib --target x86_64-pc-windows-gnu: clean (one pre-existing dead-code warning).Signed-off-by: cerealfordinner [email protected]
@Kal0s-design on GitHub · 2026-12-05 00:35 UTC · original
Checked
8e770e7on native Windows with MSVC (one NVIDIA desktop card plus WARP, didn't run the game).Builds clean.
cargo test -p victory-gpu --libgives the same failures on this branch with the memo on, withVICTORY_MEMO=0and on main (only the known native ones). I also ran it with diagnostics andVICTORY_D3D12_DEBUG=1. On NVIDIA I only ran the branch, and it had the same known failures. On WARP the branch and main fail the same tests, includingviews_are_made_beside_the_heap_and_copied_in, which fails on main too. Clippy with and without diagnostics shows the same warning count as main. Nothing in the lib tests callsmemory::ready, though, so equal results don't say much. I didn't measure the 1% lows.For other reviewers, this isn't a cache of BVH results or of any data. It memoizes
memory::readyper host list. What it hands back (directory address, faults address, heap base) is fixed for the life ofMemoryand the heap anyway. The memo is dropped onHostList::reset, so it lives for one recording and costs one small struct per list. The fast path skips theMEMORYlock and the rest of the body when everyfirst_usekey the body would set is already set and the globalEPOCHhasn't moved. Main already skips the keyed work on repeat calls. Title writes recorded in the list clear the key set, and frees reach memory throughLET_GO_PENDING, whichmemoedchecks first (memory.rs:1904). So from reading I don't see a new path to stale contents or freed memory. Lock order doesn't change either. The slow path stores the memo while holdingMEMORYand then the list lock, the same orderfirst_usealready uses, and the fast path only takes the list lock.I wrote a throwaway test (not pushed) that calls
readyon a real list and heap and counts the slow calls. With the memo on, a second call with the same arguments is answered from the memo with the same values. A pendingLET_GOforces the slow path and gets drained, and afterresetthe next call is slow again. When I bump the frame counter between two calls, the memo still answers andMemory.framestays on the old frame. WithVICTORY_MEMO=0the frame turn runs.That frame turn is the real difference from main. The
m.frame != frameblock (memory.rs:1665) isn't part of the memo check. That block runs take_faults, plus look_again, which goes back over a sample of held pages each frame, and that's this code's per-frame check for title memory changing under it. With the memo it waits for the next slow call by any list. That's usually soon because new lists start with no keys, but it's still a change. Keeping the frame inMemoand comparing it withcrate::frame::current()would close it cheaply.Smaller things.
memoedcopies every key formula fromreadyby hand (memory.rs:1893 on, plus a secondREADconst at 1886). If a key inreadychanges and nobody mirrors it, the fast path silently skips the new work.stats.uses, and with diagnosticstrace.dispatch, so the memory line and traces undercount.heap.dynamic(COPIES + 1)?fails at memory.rs:1806 the call returns before the EPOCH bump. Pending ranges it drained, or copies it added just before, then don't invalidate other lists' memos.VICTORY_MEMO=1(memory.rs:341, host.rs:2360, host.rs:6351), but the memo is on unless set to0. It also coversUse::Readsdraws, not only the builder.VICTORY_MEMO=0behaves the same as main apart from a few extra atomics. Because of the frame turn and the hand-copied keys I'd lean to off by default until it has been run in game with a frame check added, but that's the maintainers' call.AI-assisted: yes
@cerealfordinner on GitHub · 2026-12-05 03:14 UTC · original
Addressed the review items:
Frame turn gap closed — added
framefield toMemostruct, capturecrate::frame::current()when creating the memo, and check it inmemoed(memory.rs:340, 1874, 1918). The per-frametake_faults/look_againcheck now runs on every list's first call each frame.Default changed to off — memo now requires
VICTORY_MEMO=1to enable (was on unlessVICTORY_MEMO=0). Updated the env var check and all three doc references (memory.rs:341, 1621; host.rs:2360, 6351).EPOCH bump on heap.dynamic failure — bump
EPOCHbefore theheap.dynamic(COPIES + 1)?call so pending drains and copies added before the failure still invalidate other lists' memos (memory.rs:1810).Hand-copied keys warning — added a comment in
memoednoting that key formulas are hand-copied from the slow path and must be mirrored if changed (memory.rs:1898).Build verification will run in CI.
@Kal0s-design on GitHub · 2026-12-05 04:30 UTC · original
Re-checked
73f6835on native Windows (one NVIDIA desktop card plus WARP).cargo test -p victory-gpu --libgives the same 352 passed and 5 failed as main, both withVICTORY_MEMOunset and withVICTORY_MEMO=1. The 5 are the known native ones (two indirect host_list tests, two pipeline::host library loads, and the watch test). Clippy, with and without diagnostics, shows the same warning count as main, and none of the warnings are in the changed lines.The frame check works. I rebuilt my throwaway test that calls
readyon a real list and heap and counts slow calls, and this time it bumps the frame counter between calls. With the memo on, the second call is a memo hit. The first call after the bump takes the slow path andMemory.framemoves to the new frame, then the next call is a hit again. With it unset every call is slow, as on main. One small thing. The memo stores a freshcrate::frame::current()(memory.rs:1873) rather than theframelocal the turn compared at 1665. If the frame moves on while a slow call is running, the memo is stamped with a frame whose turn never ran. That's from reading only and a narrow window, but storing the local would close it for free. The lib suite itself never callsready, so the throwaway test is the real evidence here and the suite results are not.Default off now really matches main. When the flag isn't set,
memoednever runs and no memo is stored. What's left is thedirtyflag, twosigtuples and a few EPOCHfetch_adds, including the one in the deferred land closure. That's no behaviour change, just a few atomics.The EPOCH bump before
heap.dynamic(COPIES + 1)?covers the failure case, and that?is the only early exit between the pending drains and the end bump. It fires once per new heap even when nothing else changed. That costs an extra invalidation per heap, which is harmless. The success path still gets the end bump at 1867 when something changed. The hand-copied keys only got a comment, which is fine as long as it stays opt-in. A memo hit still skips the spare page top-up,stats.usesand the diagnostics trace, and the memo still coversUse::Readstoo.AI-assisted: yes
@luisaugustz on GitHub · 2026-12-05 13:30 UTC · original
Measured on RX 9070 XT + Ryzen 7 5800X (RADV, 4K output, FSR 4 Performance, ray tracing on), on the
downtownroute from #554:VICTORY_MEMO=0So about +0.7 fps, and better lows.
Details are in #591.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.