Sampled eviction under pressure: let unread textures picked by index go when the card is full #4580
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4580"
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?
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by mcozcan on 2026-11-30T23:12:02Z.
What it changes
On a 12 GB card in Series X mode the card stays over its budget for most of a session, and new textures stay at their small levels ("textures never load" for the player). Slot eviction can free almost nothing, because most idle textures are shown by slots that shaders pick by index.
VICTORY_SAMPLED_MARKS=1already knows which of those slots no shader read.VICTORY_SAMPLED_EVICT=1used to act on that, butvictory playturned it off on 2026-11-28 because foliage flickered: foliage that is read every few seconds was let go within the idle time and came back a frame late.This adds a third value,
VICTORY_SAMPLED_EVICT=pressure, and makes itvictory play's default:sampled::PRESSURE_PERCENT). With room on the card, indexed textures are left alone, as with0.sampled::PRESSURE_COLD_FRAMES, about a minute at 30 fps), or for the pass's own idle time if that is longer. Foliage read every few seconds never qualifies.slots_still_evictable(the aside path) asks again just before the eviction, so a decision made with the card full is not carried out after it has room again.evict_on()stays true in this mode).1behaves exactly as before. The card's memory is only queried inpressuremode.What it trades: the room it frees goes to the textures that were waiting for room, so they reach their full levels. It does not lower the card's use (see @DoubleD17's like-for-like A/B below).
How it was tested
VICTORY_SAMPLED_EVICT=0):5fabb46ewith this PR, Series X 2560x1440 DLAA, frame generation and ray tracing off; idle camera, 150 s, four runs per arm alternated, onlyVICTORY_SAMPLED_EVICT=pressureagainst0differing; the card at 10.3-11.0 GB of a 10.74 GB budget:0, 2 to 5 % grew to their levels; withpressure, all of them did (30,934 to 50,213 a run);=1was turned off for), other cards, Series S, frame generation on.VICTORY_VRAM_BUDGET_MB=8192standing in for an 8 GB card, Series X 1440p DLSS Quality, a 12-minute scripted walk, two runs each against main5fabb46e:981dd225by @andrewpozdnakov7-jpg: pressure mode leaves textures picked by index alone until a full 1,800-frame window has passed (cutoff_forchecked at frames 1,799 / 1,800 / 1,801:None/Some(0)/Some(1)). Not run in the game on the new head yet.VICTORY_SAMPLED_EVICT=pressure, the rest as before). Not the same route or length as the 50-minute run:cargo test -p victory-gpu --libpassed for this branch, with two new tests (the_evict_switch_reads_its_modes,pressure_trusts_the_marks_only_with_the_card_full_and_a_minute_back).981dd225adds the frame-1,800 boundary to the second. The two failureslist::thin::tests::bindings_record_no_workandshader_cache::tests::every_switch_of_the_translator_is_in_the_keyfail onmaintoo (#4296 fixes them).Checked for overlap
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by DoubleD17 on 2026-12-01T07:40:37Z.
A like-for-like A/B of this PR on the card it targets, in case it helps.
Setup
5fabb46ewith this PR (02fe88f6) merged. The two arms differ only by--set VICTORY_SAMPLED_EVICT=pressureagainst--set VICTORY_SAMPLED_EVICT=0.VICTORY_TEXTURE_ROOM_PERCENT=80.pressurerun. Both arms logged "no room, new textures wait" in 28 to 30 of the ~30 texture-queue lines of every run.Textures made from their small levels for want of room, at 150 s:
0, 4 runspressure, 4 runspressureruns this PR put 30,860 to 33,227 slots picked by index back to null, and 27,561 to 28,490 were still null at the end of each run.e1251c31, and 5fabb46e-based builds whose one extra change was switched off or never acted;VRAM: no change on average.
pressureagainst 10,619 MB with0.pressure: 10,354 / 10,320 / 10,803 / 11,004 MB.0: 10,586 / 10,496 / 10,629 / 10,764 MB.Frame rate: no difference beyond our run-to-run noise.
pressure: 16.71 / 15.60 / 15.25 / 15.53.0: 15.96 / 7.70 / 17.08 / 16.54.0) spent 136 ms a frame in CPU preparation from the start while under its budget, so it is unrelated to eviction.0averages 16.53 andpressure15.77 (-4.6 %), inside the 15.25 to 17.08 spread of the runs.Picture: 800 frames per arm. We looked at every frame a frame-to-frame check flagged.
pressureruns.0: one frame with foliage missing, the one-frame vegetation gap we also see on main.pressure: three frames where the whole picture is drawn from a slightly different camera position for one frame. The same kind shows in our main runs without this PR (4 in 1,840 frames tonight), so we don't attribute it to this change.Not tested: movement (idle camera only), other cards, Series S, frame generation on, runs longer than 150 s.
AI Assisted
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by mcozcan on 2026-12-01T11:01:41Z.
@DoubleD17 thank you, that's the like-for-like run this PR was missing.
My reading: the main claim holds. The PR is for textures stuck at their small levels, and in your pressure runs every texture made small grew to its levels (all of 30,934 to 50,213, against 2 to 5 % with 0), with no flicker in 800 frames. The second claim does not hold: my "after" run had the card under its budget, but that run was not like-for-like and carried other PRs too. In yours, VRAM is the same in both arms, because the room this frees goes to the textures that were waiting. I'll correct the description to say so: this trades cold indexed textures for full levels of the ones in view, and does not lower the card's use. The frame rate difference is inside your run-to-run spread.
The gap is movement. =1 was turned off for foliage flicker while moving, and with an idle camera the 1,800-frame rule is never tested against textures that come back into view. If you can, a run of the same length while driving or walking a fixed route, both arms, would settle it.
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Lyrnc on 2026-12-01T11:37:06Z.
Test of this pull request in game (head
02fe88f6, cherry-picked unchanged onto main5fabb46e), against main5fabb46e.victory playdefaults otherwise:VICTORY_SAMPLED_MARKS=1andVICTORY_SLOT_EVICT=1, plusVICTORY_SAMPLED_EVICT=pressureon this branch.VICTORY_VRAM_BUDGET_MB=8192stands in for an 8 GB card. It is not one: the driver still has 16 GB, so nothing is paged when use goes past 8,192 MB. Read "card MB in use" as what a real 8 GB card would have to page.VICTORY_SAMPLED_SHRINK=0, which is this PR's code exactly.Columns are world+30-330 s / 330-630 s / 630-690 s (the last one is short). Where a cell has two values separated by ";", they are the two runs.
5fabb46eWhat I read from it:
frame - PRESSURE_COLD_FRAMESsaturates to 0, so any slot not marked since the start counts as a minute cold. Holding the trust back until frame 1,800 might avoid it.PRESSURE_PERCENT, so this PR changes nothing there (seen in a run of #4850's build, which has this commit).We built on this PR in #4850 (draft, depends on this one). Textures picked by index whose copy takes more than one 64 KiB piece of the texture pool are cut to their small levels instead of put to null, so their slots never show the neutral texture. Textures of one piece, which are most of them, go this PR's way.
AI use: Claude Code (Claude Opus 5.5) ran the comparison from our bench logs and wrote this comment.
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by andrewpozdnakov7-jpg on 2026-12-01T11:42:23Z.
The startup observation from Lyrnc matches the current cutoff in
02fe88f6: before frame 1,800, the saturating subtraction returns 0. A slot with no mark can therefore be considered cold even though there have been fewer than 1,800 frames.981dd22555makes pressure mode wait for the full 1,800-frame window. At the boundary the cutoff is 0, and after that the existing budget threshold and idle-time rules apply. Mode1is unchanged. Review commitI ran the existing cutoff test with boundary checks at frames 1,799, 1,800, and 1,801, using the exact selector on Rust 1.98.1. The author version returned
Some(0)at 1,799 and failed. The fix returnedNonethere, thenSome(0)andSome(1); the rest of that test and the one-file staged policy passed. A repeat of the same startup route on this change would show whether it reduces the early reupload warnings.Please keep the Git author on cherry-pick or rebase, or add
Co-authored-by: andrewpozdnakov7-jpg <[email protected]>if folding the change in.AI-assisted with OpenAI Codex.
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by mcozcan on 2026-12-01T12:08:42Z.
@andrewpozdnakov7-jpg thanks, confirmed. A slot never marked has stamp 0 and
seen_since(0, _)is false, so before frame 1,800 pressure mode took every unmarked slot for a minute cold, including slots the title had just written and no shader had read yet. A minute without a read can't be judged before a minute has passed. I took981dd225as is (a fast-forward, your authorship kept), and checkedcutoff_forat frames 1,799, 1,800 and 1,801 on its own:None,Some(0),Some(1).@Lyrnc thanks for the bench. This fits the ~200 early "uploaded again" warnings; a repeat of the startup route on the new head would confirm it. The ~27,000 slots read again while null are the cost of putting slots to null under pressure. #4850's cut to small levels covers the textures of more than one piece, and I'll watch for the neutral texture on screen in real 8 GB runs.
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Lyrnc on 2026-12-01T13:08:20Z.
Startup route on the new head (
981dd225), as asked. Built as this PR's two commits on main5fabb46e, the same base as my earlier runs. Same PC, profile (Series X 1440p, DLSS Quality, frame generation off), route and warm cache,VICTORY_VRAM_BUDGET_MB=8192, 300 s runs.This counts "a texture picked by index changed after its upload with nothing to tell of it" in the first 120 s after start. The line is logged only for the first 200, so 200 means at least 200.
981dd225981dd22502fe88f602fe88f65fabb46eSo on this route the fix does not remove it. In both new runs, the first slots were put to null 36-47 s after start, while the loading screen was still up. The low-slot warnings began within a few seconds of that, as in the earlier run that had them. The loading screen runs at 600-970 fps here, so frame 1,800 comes about 3 s after it starts and the history window is full long before the world. A guard counted from the world's first frame, or in seconds, would cover this. So would leaving alone slots that were never marked. We can run whichever you pick.
A correction to my earlier comment: only one of my two earlier runs had this burst. The other reached the 200-line cap later, spread over minutes 1-6 on high slots. Main at the 16 GB budget also reached that cap once, at minute 3. What sets this branch apart is the burst on low slots right after the first evictions during loading. It appeared in 4 of 5 runs of builds with
02fe88f6at 8 GB (two of this PR alone, three with #4850 on top), in 2 of 2 with981dd225, and in 0 of 2 main runs.AI use: Claude Code (Claude Opus 5.5) ran these from our bench and wrote this comment.
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by mcozcan on 2026-12-01T13:17:07Z.
@Lyrnc thanks, that settles it: at 600-970 fps the loading screen fills the 1,800-frame window in about 3 s, so
981dd225only moved the start.A guard in seconds wouldn't fix the cause either. The slots that go are ones the title has just written during loading and no shader has read yet. A slot's mark stamp is only set by a mark and never reset by a write, so "never read since it was written" looked the same as "unread for a minute". A slot read once in a menu and then rewritten has the same problem. A guard from the world's first frame would only move it again.
e0f562decounts the window from a slot's last write as well as its last mark, in pressure mode only:crate::sampledkeeps a write stamp per slot next to the mark stamp. The texture queue notes it with every write it records (written_returning, so also the re-queue after a slot read while null).trust_keeps, used by bothevictable_slotsandslots_still_evictable).1is unchanged, and so is the 1,800-frame floor.Slots left unwritten and unread for a whole window still go, so the memory it frees should stay close to what you measured. A new test (
a_slot_written_within_the_window_is_kept_unread) covers four cases: read before the window, written within it and unread, written before it and unread, and read again after a write. It and the existing history test pass when run on their own; not built on Windows or run in the game yet.If you can, the same startup route on
e0f562dewould show whether the low-slot burst is gone. The other numbers from your first table (MB freed, oldest due texture, slots read again while null) would show whether it costs any of the memory.Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by andrewpozdnakov7-jpg on 2026-12-01T13:19:09Z.
The startup replay on 981dd225 still hit the warning cap in both runs. The first nulls appeared at 36–47 s. The loading screen can accumulate 1,800 frames in about three seconds, so even the per-slot write timestamp added in
e0f562decan age out quickly there.84313ebf keeps the new per-slot write check and limits pressure eviction to marks or writes at least 60 elapsed seconds and 1,800 frames old. It uses the eviction sweep's existing frame/time ring, and keeps indexed textures until that history exists. The selected cutoff is the oldest of the elapsed-time, frame-count, and pass cutoffs.
I ran the exact decision and history functions at a synthetic 960 FPS.
e0f562deallowed pressure eviction at 45 s. The patch kept it disabled then, selected frame 1 at 60 s and frame 961 at 61 s, and kept the original 95% budget and 1,800-frame gates. Mode1still uses the pass cutoff without querying the card budget. The staged check passed for both files.The next replay should use the current PR head,
e0f562de, to isolate the per-slot write fix. If the same early burst persists there, 84313ebf is a follow-up that guards the elapsed window as well.Please keep the Git author on cherry-pick or rebase, or add
Co-authored-by: andrewpozdnakov7-jpg <[email protected]>if folding the change in.AI-assisted with OpenAI Codex.
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by mcozcan on 2026-12-01T13:20:54Z.
@andrewpozdnakov7-jpg thanks. I read 84313ebf and agree with it. A minute should be a minute of time and not only of frames, and the two fixes cover different things:
e0f562dekeeps slots written within the window.record_frame_ring(one point a second, 120 s kept). With the oldest of the three cutoffs, and no eviction of indexed textures until the ring holds 60 s, a slot written during a fast loading screen stays until it has been both unread and unwritten for a real minute.I'll follow your order: the next startup replay on
e0f562dealone, so the write stamp is measured by itself. Then 84313ebf on top, with your authorship kept. I'll take it whatever that replay shows, since the frame-only window is wrong at loading-screen frame rates either way; the replay tells us how much of the burst each part removes. If the ring is empty (slot eviction off), pressure mode keeps indexed textures, which is the safe side.Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Jesper-Andersson on 2026-12-01T16:35:42Z.
Test on a real 8 GB card, head
732ee452(withe0f562de; without 84313ebf). One session, so read it as one data point.Setup: our fork's diagnostics build with this PR (all four commits, to
732ee452) and #4581 (tocef63b9c) cherry-picked onto it, not your branch on main.victory play's memory defaults (VICTORY_SLOT_EVICT=1,VICTORY_SAMPLED_MARKS=1), plusVICTORY_SAMPLED_EVICT=pressure,VICTORY_COMPACT_SPARSE=1,VICTORY_COMPACT_WHOLE=1. RTX 2070 SUPER 8 GB (driver 621.40, ReBAR off), Ryzen 7 5800X, 32 GB RAM, Windows 11 Pro Insider 10.0.26320. Series S, DLSS Performance, FSR 3 frame generation. Free play on my own save, 24 minutes in the world before the crash. GPU clocks locked at 1890 MHz in this run only. The session ended in a device hang and a PC crash (details on #4581; compaction never acted there).Baseline: the census run from #4462 (comment): our build before these picks (this PR's first commit was in it, but with
SAMPLED_EVICTunset its sampled line reports no eviction; #4581's first commit was in it withCOMPACT_SPARSE=0), same defaults otherwise, 31.2 minutes, clocks not locked. Different route and length, so the comparison is rough.e0f562de: nothing was put to null until 4.5 minutes into the world, so no slots went during loading.Picture: screenshots every 46 s (baseline: every 91 s); I looked at all 20 and all 21. My worst ones show black sign boards and a black pole, neon-green blobs on foliage and a fence, white washed-out roads and grey shard-shaped tree LODs. The baseline run shows the same kinds: a black flag, black bollards and furniture, small green patches in trees, white ground and the same shard LODs. The worst shot of this run was also taken at world + 3.9 min, about 30 s before the eviction step, when only 5 textures had gone (as in the baseline). So I don't think these come from this PR.
A question: a slot put back to null shows "the neutral texture" until the next readback and upload (Lyrnc's bench didn't look at it on screen). Is the neutral texture all-zero black? If so, a nulled slot on screen would look the same as the black boards above, and only shots at the same spot with and without the PR would tell them apart.
Spec dependence:
Not tested: a
VICTORY_SAMPLED_EVICT=0control on the same build and route; 84313ebf; release build; Series X; other cards; ray tracing; DLSS frame generation; flicker while moving (stills only).Drafted with AI assistance (Claude Code).
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by mcozcan on 2026-12-01T17:03:13Z.
@Jesper-Andersson thanks, a real 8 GB card is what this PR needed.
On your question: no, a slot put back to null shows gray, not black.
texture_slot_evicted(descriptor/host.rs:4702) callsunmake(:4758-4778), which writes the slot throughneutral_for(:576). For 2D textures and 2D arrays, that is a view of a 1x1R8G8B8A8_UNORMtexture filled with0x80in every channel, alpha included (make_neutral,:505). WithVICTORY_NEUTRAL_ALL_KINDSon, which is the default, 1D, 3D and cube views get a gray stand-in of their own kind too. A slot gets a real null view, which reads as zeros (black), only when its view description can't be found or it is of some other kind.So a nulled slot on screen should look mid-gray, or whatever the material does with 0.5 in every channel. It shouldn't look like the black boards. Your baseline run had those too, and the worst one in this run was taken before the eviction step. That fits with them not coming from this PR. Your line also caps how much could show: of the 11,598 slots put to null, 424 were read again. Only those could have shown gray, each one until its texture was uploaded again.
I can't explain the colour cast on the pause-menu backdrop from the code. Gray in a texture the blur reads would make the picture duller, not magenta or green. Still, 7 shots after the step and none before it is worth checking. The cleanest check is a pause-menu shot at the same spot with
VICTORY_SAMPLED_EVICT=0on the same build.The burst you saw is how this mode works: nothing goes until the card reaches 95 % of its budget, and then everything picked by index that is idle for the window goes at once. 84313ebf, which isn't in your build, changes the window and not that.
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by trustno1-coder on 2026-12-01T18:37:04Z.
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