vkback: idle sweep walks an age queue per memory instead of sorting every unnamed texture #132
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/vktory6--VKtory!132
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-132"
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?
@Flezzonkeys on GitHub · 2026-12-01 19:55 UTC · original
Flezzonkeys:idle-sweep-queue→main· +265 −35 · 7 files · 1 commits · merged 2026-12-01 20:07 UTCWhat
let_go(residency.rs) ran at almost every present while the card was over its line. Each time it collected every unnamed texture (one clock read each), sorted the idle ones, and then skipped the ones in the other memory. So the VRAM sweep sorted and skipped all textures spilled to GTT, every frame, to let go about two textures. In one 6-minute session with ~35k textures in GTT this cost 17.2 s of renderer time (7,289 sweeps, 2.36 ms each, ~3.6 ms a present late in the run). The renderer waited only 4.3 s for remaps at presents in the same run. The cost grows with what sits in GTT, not with what is let go.unnamedis nowidle::Unnamed: the same id map, plus one queue per memory in entry order. Entries are entered atInstant::now(), so entry order is age order (asserted). Removing an entry or entering it again leaves a stale queue entry, which a walk drops when it reaches it. A queue is compacted once it holds more than twice the live entries plus 4,096. The sweep walks the oldest entries of its own memory that are idle long enough and stops once enough is freed. It still checks the image's memory at each visit, as before.Every texture image now goes in through
image_made, which files the entry under the image's memory. The three creation sites (ensure_image_or, the placed write in slotwrite.rs, object creation in lib.rs) can therefore not forget it.Behaviour is unchanged: the same textures go, in the same order, under the same rules (idle time, 4 frames, evictable, not named, the image's memory). The keep rule, the lines and
back_to_vramare untouched.The reference
The D3D12 path's counterpart is
let_go_idleincrates/victory-gpu/src/resource.rs(parity.md row "Residency line, idle let-go, target reserve"). I could not read it for this change: the Marvisak/VIctory repository answers HTTP 451 for me. This PR does not change what the sweep decides, only how it finds the candidates, so the parity row stays as it is. vkd3d-proton has no idle sweep of this kind.Same pattern checked elsewhere (rule 22): I found no other per-present path in vkback that collects and sorts a large map.
source_sweepwalks a bounded part (PART) oftex_keysper present, and thertsize/rtcheck/dumpsorts are diagnostics.Evidence
idle::tests, calling the productionUnnamed): under 30k steps of enter, touch and remove churn, with compactions, the walk returns the same ids in the same order as a model of the old scan-and-sort, for both memories and several cuts. Further tests cover re-entry into the other memory, touch keeping the memory, removal during a walk, and the queue length staying bounded.cargo test -p umem -p frame -p vkback --lib,cargo test -p vkback --test policy,cargo test -p xtaskandcargo clippy --workspace --all-targets -- -D warnings(greenfield) pass on this branch.31c20c7plus local-only changes that do not touch residency (present sharpening, a resolution patch left off, trace fields):tex: let go idle (sweep)30,466 ms over 13,260 sweeps, ~128 ms per 60 presents.image_maderefactor, 206 windows, EXIT 0): the label never appears among the profile line's 24 costliest (the 24th is at a median of 4 ms per 60 presents). 29,502 textures were still let go, and the memory line looked as before (VRAM ~11.5 of 14.5 GB, ~26-38k textures in GTT).Checklist (docs/AGENTS.md)
docs/TASKS.mdnot editedunsafeblock has a// SAFETY:comment (rule 36): no newunsafeLearnings: new entry "The sweep's own cost" in
docs/learnings/tex-letgo.md.oversize.txt: lib.rs 4254 -> 4250.@vktory6 on GitHub · 2026-12-01 20:07 UTC · original
Merged, thanks. This is a clean find. The sweep cost grew with what sits in GTT rather than with what it frees, which also fits the "frames get slower the longer the session runs" creep we see in the house scene. The model test against the old sort is exactly the evidence a "same decisions, cheaper" change needs.
Two things I checked, for the record: the age assert holds because every caller is on the renderer thread and passes
Instant::now(); and ties at the same instant now go by entry order instead of by id, which changes nothing in practice. No validation run was needed: no Vulkan call changed.