Slot eviction: look for victims off the submitting thread (VICTORY_SLOT_EVICT_ASIDE) #3750
No reviewers
Labels
No labels
AMD
audio
bug
confirmed
crash
cutscene
dlss
documentation
duplicate
enhancement
fixed-on-main
frame-generation
good first issue
help wanted
input
INTEL
invalid
lighting
linux-proton
memory
needs-info
needs-logs
needs-rebase
NVIDIA
performance
pr-diagnostics
pr-docs
pr-feature
pr-fix
pr-performance
pr-refactor
pr-tests
question
RAYTRACING
rendering
report
series-s
shaders
spam
startup
upstream
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/trustno1-coder--VIctory-NVIDIA!3750
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3750"
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?
@Mikey970 on GitHub · 2026-11-30 05:57 UTC · original
Mikey970:pr/slot-evict-aside→main· +664 −77 · 4 files · 2 commits · closed without merging[pr-performance] Slot eviction: look for victims off the submitting thread (VICTORY_SLOT_EVICT_ASIDE)
Fixes #1644
What it changes
With
VICTORY_SLOT_EVICT=1and the card over its line, every sweep (once a second, on the submitting thread, before a submission) ranslot_evict's whole look: every title texture under the textures table's lock (amadelock for each idle one), thendescriptor::evictable_slotsover every slot of every heap (HostHeap::slots_showing, a slot lock each). #1644 measured 28–79 ms a second for it on an 8 GB card; on our RTX 4080 16 GB at 4K output with about 58,000 title textures it was 57–104 ms a sweep, about once a second.This moves the look, not the eviction:
slot_evictkeeps everything cheap on the submitting thread (the frame ring, the two lines,need,cutoff). The look (slot_lookover the table,slot_choosewithevictable_slotsandoldest_covering) then runs on a thread of its own (victory-slot-look), one look at a time, holding the table 4,096 entries at a time (table_part) instead of all at once. The slots are looked at after the table is let go, as now (a thread making a slot takes the table under the slot's lock).slot_evict_ready, at the top ofhost::sweep). Each texture is looked at again first (slot_still_victim): still in the table, still unused for the idle time, the same host copy held by its texture alone, and every one of its slots still showing that copy and still of the kind it was found to be (descriptor::slots_still_evictable→HostHeap::slot_still_evictable, which repeatsslots_showing's rules for that one slot; withVICTORY_SAMPLED_EVICT=1, also no shader mark sincecutoff). Anything that changed is kept and counted. A slot made of the copy in between is a use of it (hostedstampsused), so it fails the second check.SLOT_EVICT,SLOT_STATE,sampled::COLD) are the same; only where and when the look runs moves. The carrying out is the loop that was already there (slot_apply), unchanged but for the second look and a check that the copy taken is still the one chosen.VICTORY_SLOT_EVICT_ASIDE=0(read withtoggled!): the whole pass on the submitting thread, as before. Nothing changes withoutVICTORY_SLOT_EVICT=1.Files:
crates/victory-gpu/src/resource.rs(slot_evictsplit intoslot_look/slot_choose/slot_apply, the aside machinery, two tests),descriptor.rs(slots_still_evictable),descriptor/host.rs(HostHeap::slot_still_evictable),host.rs(one call insweep). The GPL attribution of the slot-eviction code (memory stack by skornuta, skornuta/victory-memory-stack 57fb136, GPL-3.0) is kept and carried onto the new function indescriptor/host.rs.How it was tested
In game on this branch's base (
main41adb551+ this change): the full 375 s route completed with no errors and no lost device.slot eviction aside (VICTORY_SLOT_EVICT_ASIDE), since the start: 16 looks off the submitting thread, 37.2 ms each, the longest 52.8— that is 16 stalls of 37–53 ms each that the submitting thread no longer takes. Build:mainat41adb551with this change, release, RTX 4080 16 GB, Ryzen 7 9800X3D, 32 GB RAM, Series X profile, DLSS Performance through Streamline (1080p rendered, 3840x2160 output), ray tracing off, frame generation off, warm pipeline cache from an earlier run, the 375 s Chapter 1 route (interrogation, therapist, flyover, boat, shore) driven byVICTORY_KEYS.GPU and profile: RTX 4080 16 GB, Series X profile, 1080p → 4K DLSS, no frame generation, no ray tracing. The same 375 s route each time,
VICTORY_SLOT_EVICT=1, the card over its high line.The numbers below are from our fork's build, where this change was first written. This branch is a hand port onto current
main(41adb551), whoseslot_evicthas changed a good deal since (the table is already let go beforeevictable_slots, the sampled-marks path, flushes); the in-game check of the rebased build is the first item above.Before (run R12): 237 frame intervals over 100 ms, p99 126 ms; boat segment 21 over 100 ms, shore 16. The slow sweeps were all in "host copies of textures": 57–104 ms a sweep, 200 sweeps of 20 ms or more, while
let_go_idle's own look stayed under 2.7 ms.After, four full runs (R14, R19, R20, R21): 89–97 frame intervals over 100 ms, p99 87 ms in R14; boat segment 0 (against 21), shore 0. Those runs carry other changes of the fork too; an earlier isolated A/B on one exe (room line lowered so the look never ran) went 237 → 28, which is the part this hitch accounts for.
New unit tests:
resource::tests::the_table_is_walked_in_parts_every_entry_once(every entry once, in order, for any part size; empty table; the top address),resource::tests::a_texture_freed_since_the_look_aside_is_left_alone(a choice for a texture no longer in the table is kept, counted, and never read).CI-equivalent commands on this branch (
5a1c053fon41adb551; offline,--locked):cargo clippy -p victory-gpu --all-targets --locked -- -D warnings: does not get as far asvictory-gpu.victory-shaderfails on currentmainwithout this PR (unused importPAIR_MEETINGSandanalysis::lane_regions,while_immutable_conditioninemit/lower/analysis.rs). So CI's clippy steps are red onmainas it stands.cargo clippy -p victory-gpu --all-targets --lockedand the same with--all-features: exit 0. No warning in the lines this adds. The one warning near them,unused variable: busyatresource.rsslot_apply, ismain's own line (let (reset, busy) = evict_slots(..)inslot_evict), moved, not changed.evict_slotsdocuments that a busy slot means the copy must stay, andmainnever reads it. Worth a look, but left out of this PR on purpose.cargo test -p victory-gpu --lib --locked(withVICTORY_WARP=1): 922 passed, 2 failed, 60 ignored. Both failures are the same on41adb551without this PR:shader_cache::tests::every_switch_of_the_translator_is_in_the_key("VICTORY_SCALAR_SPLITS is not read by the translator any more"), andhost::menu::tests::a_change_is_saved_at_once_however_the_game_was_started, which fails whenever the menu tests run together and passes alone, on both.cargo test -p victory-gpu --lib -- slot, and the two by name): all pass.cargo xtask policy --staged: "asset policy: 4 files ok". (cargo xtask policyover the tree fails onmainatcrates/victory-loader/src/heap_sites/frame_users.rs, a run of 2022 hex digits. This PR does not touch that file.)cargo testpassed for the crates it touches: yes, apart from the two failures above, which fail the same way onmain.Checked for overlap
HostHeap::slots_showingcheaper with an atomic occupancy bitmap. That is one of the two walks; it leaves the walk of every title texture under the table's lock on the submitting thread. This PR moves both walks off that thread and does not touchslots_showing, so the two compose: with #2720 the look aside is simply shorter. #2720 moveskeptbehindKeptSlots;HostHeap::slot_still_evictablehere readsself.kept.get(i)and the slot lock, so whichever lands second needs a one-line change there (raw_at).host::retireas before.🤖 Generated with Claude Code
@Mikey970 on GitHub · 2026-11-30 06:00 UTC · original
Holding this as a draft while I check a possible regression. In two in-game runs of
main41adb551+ this PR + #3749/#3750/#3751 together (RTX 4080, Series X, DLSS Performance via Streamline), the run ended near the end of the 375 s route witha host command list did not close (The parameter is incorrect. (0x80070057)); a run of plainmainwith the same settings finished clean. The slot-eviction look let go of no texture in either run, and the trim fired 1–3 times, so neither is an obvious cause yet. I am running each change on its own and will mark this ready again (or fix it) with the result.🤖 Generated with Claude Code
@Mikey970 on GitHub · 2026-11-30 06:16 UTC · original
Update: with this PR's look-aside switched off (
VICTORY_SLOT_EVICT_ASIDE=0) the same route completed cleanly, while both runs with it on ended at the shore witha host command list did not close (0x80070057), even though the look let go of no texture in either. Two runs each is not proof either way (upstream has open reports of the same error onmain), but it is enough that I am keeping this a draft until a diagnostics build withVICTORY_D3D12_DEBUG=1names the failing command.🤖 Generated with Claude Code
@Mikey970 on GitHub · 2026-11-30 07:18 UTC · original
Cleared: with the twin-copy fix (#3792, the
CopyTextureRegioninto a held copy) in the same build,main+ this PR + #3749 completed the whole 375 s route with nodid not closeerror (the look ran 16 times, 37.8 ms each, off the submitting thread). The debug layer had named the failing command as that out-of-bounds BC7 copy, which this PR does not touch, so the earlier ends were the copy bug, not this change. Marking ready.🤖 Generated with Claude Code
@Yoruiopz on GitHub · 2026-11-30 07:38 UTC · original
I reproduced the cost this targets on an RTX 5070 Laptop GPU with 8 GB. The measured descriptor lock walk took 16.53 ms median in a busy Series X segment and yielded zero texture evictions in 38 passes. The breakdown is on #1644.
One correctness case to cover for the worker path. In
5a1c053,slot_still_victimchecks that a slot still holds the planned host copy. Later,evict_slotscallstexture_slot_evicted, which takes the per-slotMadelock but only tests for a nonzero current key before clearing the slot. A slot rewrite from A to B could finish in that gap. The eviction would then acquire the lock uncontended and clear B. Checking only the returnedbusyflag would miss a completed rewrite.Could the commit path validate the expected view identity under the same
Madeguard that protects the clear, and decline the victim on mismatch or a busy slot? A focused test could validate a slot showing A, install B before the clear, then check that the stale plan leaves B and its waiting state intact. This is a source-review finding. I have not reproduced the race in gameplay.@tyr0nsur on GitHub · 2026-11-30 07:47 UTC · original
I reproduced the busy-descriptor half of the concern above with a real Direct3D 12 heap and a synthetic 4×4 texture on
5a1c053. The fixture holds the slot'sMadelock whileslot_applyruns.evict_slotsreports that the slot is busy, and the current loop still retires one host copy (4,096 bytes in this fixture). The ignoredbusyresult is inherited from main.Cherry-pickable
8c82f6euses the existing keep-and-restore path when a slot is busy, including when earlier slots in the same pass were already reset. The regression test preserves the exact host copy and reports zero evictions. Windows WARPcargo test --locked -p victory-gpu --lib slotpassed 46 tests (2 ignored). The regression also passed with the normal adapter selection and with #3697 applied alongside this PR. Staged asset policy passed. The locked-slot reproduction and patch were built with Codex assistance.The completed descriptor rewrite described in the preceding comment would need the identity checked under the
Madelock at the clear. The test here exercises an actual failed try-lock.@tyr0nsur on GitHub · 2026-11-30 07:59 UTC · original
I reproduced the completed rewrite from Yoruiopz's review with live D3D12 descriptors and synthetic textures. The fixture captures the slot showing A, writes and mirrors B, then calls the real apply loop with the old plan. With
8c82f6ealone, the loop retired A and cleared B's host descriptor.Commit
846517f, on top of8c82f6e, carries the heap ID and view key through the scan and validates the view key and expected host texture under the sameMadelock as the clear. It also keeps a texture whenmake_againhas cleared the key while the old resource remains in the slot.The regression checks replacement by another texture, replacement by another mip view of the same texture, an invalidated key with a live view, and the successful clear of a matching descriptor. It passed in Windows WARP and with normal adapter selection. The 46 tests selected by
--lib slot, the diagnostics feature check and staged asset policy also passed. The tests use synthetic textures. In-game impact remains unmeasured. Implemented and verified with Codex assistance.@Yoruiopz on GitHub · 2026-11-30 08:11 UTC · original
Following up on the completed-rewrite case from my earlier comment. I tested
56c1294on top of5a1c053and @tyr0nsur's original busy-slot fix8c82f6e.The patch carries the planned heap identity and made key, then checks the key and retained resource under the same
Madelock as the clear. A mismatch or busy slot preserves the texture and uses the existing recovery path for slots already reset.The deterministic synthetic test publishes B after validating A. It exercises a different resource under the same key and a different key for the same resource. Both cases preserve the new slot and its waiting state. The focused
slot_eviction_filter passed four tests on the RTX 5070 Laptop GPU, including the distinct busy-slot regression. Dino's WARP runtime exposed Shader Model 6.2, so these results use the native D3D12 adapter.The identity commit is available to cherry-pick if useful. These tests cover completed replacements of the planned slot. They leave exact same-key/same-resource republication and newly added references in other slots outside the validation scope.
github-bot referenced this pull request2026-11-30 09:34:54 +00:00
@Mikey970 on GitHub · 2026-11-30 13:54 UTC · original
@Yoruiopz @tyr0nsur thank you both; the analysis is right on both counts.
evict_slotsreported a busy slot and the loop ignored it (that is inherited frommain), andtexture_slot_evictedonly tested for a nonzero key, so a rewrite A→B completing between the plan and the clear would have cleared B.This branch now carries @tyr0nsur's two commits unchanged (fast-forward, authorship kept):
8c82f6e: a busy slot keeps the texture, through the existing restore path for slots already reset.846517f: the plan carries heap ID and view key, and the clear checks key and host texture under the sameMadelock; an invalidated key that still shows the old resource also keeps the texture.@Yoruiopz, your
56c1294does the same check (sampling the key under the lock at plan time too); the two conflict, so I took one. I went with846517fbecause it builds directly on8c82f6eand its test runs the real apply loop on texture SRVs, including the same-texture/other-mip andmake_againcases. Your report is what found this, thanks.Tested at
846517f(VICTORY_WARP=1):cargo test -p victory-gpu --lib -- descriptor:: resource::152 passed, 0 failed;--lib slot50 passed; the busy-slot and stale-rewrite tests pass.cargo check --all-features --all-targetsis clean, and clippy adds no warnings (it drops the old unusedbusyone). The CIcheckfailure is the pre-existingunwind_copyone onmain41adb551.🤖 Generated with Claude Code
@Mikey970 on GitHub · 2026-11-30 14:44 UTC · original
Follow-up
b23c0c40on top of846517f:slots_showingread the slot'sMadekey with?, butMadeholds keys only for the title'scountslots whilekeptalso has the dynamic ones. A host texture shown by a dynamic slot was therefore dropped from the answer and no longer counted as blocked, so it could be chosen (freeing nothing, since the dynamic slot holds a reference). Dynamic slots are reported again with key 0, as onmain, which also restores theVICTORY_SLOT_EVICT_ASIDE=0path. New test:a_dynamic_slot_showing_a_texture_still_blocks_its_eviction.SLOT_LOOKINGis now cleared by a drop guard, so a look thread that panics no longer stops all later looks.Tested (WARP):
cargo test -p victory-gpu --lib -- descriptor:: resource::153 passed, 0 failed. Clippy warnings are unchanged.🤖 Generated with Claude Code
c71899d9) into slot eviction aside aa8873afd7@Mikey970 on GitHub · 2026-11-30 15:05 UTC · original
Merged current
main(c71899d9) into this branch:aa8873af. Conflicts were resolved against #3848,2fb0d44d,156e3567and5bae53c3:mainis kept as-is; this PR only moves the look aside and checks slots at the clear.slot_evict_backoff_ms) now gates both the inline look and the look aside. It is set after an inline pass, after a look aside that chose nothing, and after a choice carried out at the sweep.main'sif busy { continue }in the apply loop is dropped. Here a busy or changed slot already keeps the texture, and that path also re-makes slots reset earlier in the pass (texture_made), which thecontinueskipped.main'stexture_slot_evicted(index, expected_raw)stays for the dead render-target reclaim. Planned slot eviction usestexture_slot_evicted_as_planned, which checks heap id, view key and host texture under theMadelock.Tested (WARP):
cargo test -p victory-gpu --lib -- descriptor:: resource::185 passed, 0 failed;cargo check --all-features --all-targetsclean; clippy adds no warnings. To run the tests I had to patch twocard_passtest calls inhost.rslocally: onmainc71899d9they do not compile because they lack the newcaptureargument. That patch is not pushed.🤖 Generated with Claude Code
@Aniseto on GitHub · 2026-11-30 16:31 UTC · original
Attempted the two new unit tests and the slot tests at
aa8873af; they could not run at this head.System
rust-toolchain.toml), MSVC 14.44.35207, DXC 1.9.2609.5VICTORY_D3D12_ADAPTER=NVIDIAResults
VICTORY_D3D12_ADAPTER=NVIDIA cargo test -p victory-gpu --lib --locked: exit 101,error[E0061]twice. The same error appears forresource::tests::the_table_is_walked_in_parts_every_entry_once,resource::tests::a_texture_freed_since_the_look_aside_is_left_alone, andcargo test -p victory-gpu --lib --locked -- slot --test-threads=1.card_pass(...)is called with 5 arguments atcrates/victory-gpu/src/host.rs:20305and:20331but takes 6 (the[u32; 3]capture argument), declared at:4248. Thevictory-gpulib test target does not compile, so no test result was emitted.What this adds
This run confirms the same compile blocker on a second NVIDIA host with 16 GB of VRAM: the two new unit tests and the slot tests are unreachable at this head without editing test fixtures, which I did not do. The author's WARP run at
41adb551and the 922/2/60 counts were on a different tree; nothing here exercises slot eviction or the descriptor lock walk.Not tested
The two new unit tests, the slot tests, the full suite, slot eviction, a retail title, paired smoke runs, AMD and Intel GPUs, native wave64 hosts, Wine, release profile, game data.
AI-assisted (OpenCode), model: MiMo-V2.6-Flash Free - ran the commands above at the exact head on this machine and wrote this report; no game data was used.
@trustno1-coder on GitHub · 2026-12-01 18:49 UTC · original
Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.
Pull request closed