GPU: a draw ensures its targets once per states generation, and clones a texture only when a barrier is owed #3249
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!3249
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3249"
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?
@borosf on GitHub · 2026-11-26 14:31 UTC · original
borosf:vibe/ensure-state-once-842ca5→main· +84 −9 · 2 files · 4 commits · openEvery draw called
list::ensure_statefor each of its render targets and its depth target, and each call paid for the answer "nothing changed" in full.What one call cost
HostList::transitiondid, unconditionally:host_copy(a lock and anArcclone),copy.texture.clone(), a twin check,legal_state(twoGetDescs on some hosts), and astateslock plus hash entry — then returnedNonebecause the state was already right. A world frame makes ~8,000 draws, most binding the same targets.What changes
HostListcarries astates_generation: AtomicU64, bumped wheneverstatesgains or changes an entry, and when it is cleared at a reset.State::bindremembers the targets and depth it last ensured along with that generation, and skips the whole loop while the generation, the depth and the target list are all unchanged.transitionclones the texture only whentrackreports a barrier is owed, instead of on every call.The generation is the soundness argument: any transition the list itself records (targets, or a texture view in
readable) bumps it, so a draw re-ensures exactly when something it named could have moved. A texture released and re-made is a newArcpointer, hence a newstatesentry, hence a bump.Verification
cargo clippy -p victory-gpu --all-targets --locked -- -D warnings— clean;--all-featurestoo.cargo test -p victory-gpu --lib --locked --no-fail-fast— 230 passed, 2 failed, both the known Intel baseline failures pristinemainalso fails (descriptor::host::tests::dynamic_slots_are_held_until_released,memory::tests::lists_share_a_table_and_copies_keep_their_views, #1744/#1829). The draw tests that drive barriers throughensure_statepass.rustfmt --edition 2024 --checkhunk counts againstmain:draw.rs84/84,host.rs85/85.Per-call cost is arithmetic from the code (one lock + one Arc clone + two
GetDescs + one hash entry ≈ 145–200 ns per call, 40k–130k calls a frame), not a title measurement; the frame line's existing counters are the way to see the delta in a run.Synthetic tests only; no game data.
Part of the fifteen gaps claimed for this sweep on #1633. AI-assisted.
@Bj0rnis on GitHub · 2026-11-26 14:42 UTC · original
Verified head
8b09e2fdon Windows 11 (x64, Rust 1.98.1, NVIDIA GeForce RTX 5070 Ti + WARP):origin/main(63bcca43): cleancargo test -p victory-gpu --lib --features diagnostics): 244 passed, 2 failed, 1 ignored (2.95s) — the 2 failures are the pre-existing #1744 NVIDIA 1M view-heap cap failures onmain(descriptor::host::tests::dynamic_slots_are_held_until_released,memory::tests::lists_share_a_table_and_copies_keep_their_views); no regressionsVICTORY_D3D12_WARP=1): 246 passed, 0 failed, 1 ignored (1.97s)-p victory-gpu --lib --tests --features diagnostics -- -D warnings): clean (0 warnings)cargo xtask policy: 191 files okNot tested: live title workload / draw-loop performance under gameplay.
AI-assisted test run and summary.
@Dukestar69 on GitHub · 2026-11-26 14:50 UTC · original · reviewed
Reviewed the diff and ran local verification on Windows 11 x64 (cargo test -p victory-gpu --lib draw:: -- --test-threads=1: 20/20 passed; cargo clippy -p victory-gpu --all-targets -- -D warnings: clean; cargo xtask policy: 191 files ok).
Deferring copy.texture.clone() in HostList::transition until self.track() actually returns a barrier looks great, but the self.ensured fast path in draw.rs currently never hits whenever at least one target/depth is bound:
To make the cache actually hit, self.ensured should store list.states_generation() after the ensure_state calls (and HostList::track should only bump states_generation when an entry is inserted or its state actually changes, matching the doc comment). Also consider whether a HostList cut/replacement in State::bind or a depth win::route switch can occur without bumping states_generation.
Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
@borosf on GitHub · 2026-11-26 14:59 UTC · original
Fixed at
d4903faff4be45b0d597357ebebfe904d0d7d7c: both halves of the never-hits bug.HostList::tracknow bumpsstates_generationonly when an entry is inserted or its state actually changes (not on every call),transitionbumps when a twin route moves the texture's side, andState::bindstores the generation read after the ensure loop — so a draw that rebinds the same targets with nothing moved skips the loop. On your cut/replacement question: the only mutators ofstatesaretrackand the reset-clear, both of which bump; a HostList cut goes through reset. Clippy clean both feature sets, 229/2 (known baseline), draw:: 20/20 locally. Synthetic tests only; no game data.@TheGrayOrange on GitHub · 2026-11-26 18:22 UTC · original
I reproduced a remaining segment-cut cache issue at
6654fb7.Two host lists can have identical state-generation counters despite having different state maps. After
State::cutreplays the target binding,prepare_forcan incorrectly skip enrolling the target in the new segment's state map.A focused WARP test reproduced this. The subsequent transition to COPY_SOURCE reported no previous state.
Adding
self.ensured = None;at the start ofState::set_targetsrestored the expected RENDER_TARGET state. Both versions still performed only one target check across 1,023 same-segment preparations.I have a focused reproduction and can provide the correction and regression test if useful.
@borosf on GitHub · 2026-11-26 18:39 UTC · original
Thanks @TheGrayOrange — reproduced and fixed at
fd2eb57:State::cutnow clearsself.ensured, since a fresh host list can read the samestates_generationcounter with a different state map.cut(list.rs:213) is the only place aStatemoves to a fresh list, so this covers the case exactly; regression testdraw::tests::a_cut_to_a_fresh_list_forgets_the_ensured_targetsencodes the equal-counters scenario (two fresh lists both read 0).Local verification on Windows 11 x64, Intel Arc B580, head
fd2eb57:cargo test -p victory-gpu --lib --locked -- --test-threads=1 draw::— 21/21 passedcargo test -p victory-gpu --lib --locked --no-fail-fast— 230 passed, only the 2 known B580 baseline failures (#1744/#1829)cargo clippy -p victory-gpu --all-targets --locked -- -D warningsand--all-features— exit 0Synthetic tests only; no game data used.
@TheGrayOrange on GitHub · 2026-11-26 19:33 UTC · original
@borosf confirmed the fix at
fd2eb57independently on WARP. Both your regression test and my original reproduction passed. The new segment correctly tracks the render target, and the same-segment fast path remains intact.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.