GPU: a draw ensures its targets once per states generation, and clones a texture only when a barrier is owed #3247
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/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?
Imported from Marvisak/VIctory. Originally posted by borosf on 2026-11-26T14:31:42Z.
Every 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.
Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T14:50:44Z.
Review: COMMENTED
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).
Imported from Marvisak/VIctory. Originally posted by Bj0rnis on 2026-11-26T14:42:40Z.
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.
Imported from Marvisak/VIctory. Originally posted by borosf on 2026-11-26T14:59:12Z.
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.Imported from Marvisak/VIctory. Originally posted by TheGrayOrange on 2026-11-26T18:22:09Z.
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.
Imported from Marvisak/VIctory. Originally posted by borosf on 2026-11-26T18:39:27Z.
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.
Imported from Marvisak/VIctory. Originally posted by TheGrayOrange on 2026-11-26T19:33:17Z.
@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.Imported from Marvisak/VIctory. Originally posted by borosf on 2026-11-27T06:38:46Z.
Confirmed independently on WARP at
fd2eb57— thank you. That closes theState::cutsegment-memo hole you reproduced at6654fb7:set_targetsclearsensured, so a new segment's state map is enrolled again, and the same-segment fast path still holds (one target check across 1,023 same-segment preparations).One cross-reference worth having on this PR: @KainanP's stack in #2586 names #3249 as the place that answers the target transitions' texture clones on the 5-thread path, which is what
ensuredwas added for.Also noting @Bj0rnis's RTX 5070 Ti run above (244 passed / 2 failed = the #1744 heap-cap baseline, WARP 246/0, clippy clean) so the three reports sit together. Head unchanged at
fd2eb57; synthetic only, no game data.Imported from Marvisak/VIctory. Originally posted by KainanP on 2026-11-27T12:02:12Z.
List-call numbers for this PR (head
fd2eb57), ns per draw:Method.
pipeline::list_benchfrom #2586 (fork branchperf/list-call-bench) withVICTORY_LIST_BENCH_SCALING=1: the draw sequence (root CBV, 4 root constants, index buffer, indexed draw that reads 6 textures through a table and 3 root CBVs). Each thread records its own list, best of 5 × 20,000 draws. Each row is the median of 7 interleaved runs, and there were two separate batches of 7 in opposite config order (shown as batch 1 / batch 2). Release--libtest build, RTX 4060 Laptop, Windows 11. Nothing else heavy was running (an editor and a browser, CPU 7–41 % between rounds, no game). The 5-thread row onmainis noisy (single runs from 7.4 to 12.8 µs), so deltas under ~5 % there are not resolvable.Bases.
main=63bcca4+ bench commits. Stack =main+ #1978 + #2821 + #3258 + #3274 + #3275 + rebased #1356 + #3405 (the stack in #2586).Reading it. This bench binds no render or depth targets, so it does not exercise the
ensuredmemo. What it does measure is the other half, the texture clone thattransitionno longer makes, because every texture a draw reads goes throughensure_state→transition. Onmainthat is worth 85–127 ns a draw on one thread. On the stack it is worth nothing, because #3258 already moves draw reads totransition_held, which clones only when a barrier is owed. Merging onto the stack conflicts inhost.rswith #3258 (transition/transition_held). The resolution keeps #3258's split and adds this PR's twin-route bump andstates_generation()there. The 5-thread row onmaindoes not move, because it is bound by shared locks that this PR doesn't touch.Correctness.
cargo test -p victory-gpu --lib(release) on the RTX: 230 passed, 2 failed. The 2 failures are the #1744 heap-cap pair thatmainalso fails here (229 + this PR's new test). On the stack: 238 passed, 3 failed, the same 3 as the stack without this PR (the stack itself fails 3: the #1744 pair, plusa_list_lends_a_read_copy_only_while_it_is_the_texturesin the stack's port of #3405. That test passes on #3405's own head, 232/2 here). I read the memo againstmain.stateschanges only throughtrack(which now bumps on insert or a real move) andreset(which bumps). AStatemoves to another host list only throughcut(which clearsensured) or a titleReset(State::reset→ default). A depth target with a twin goes back totrackfor the DEPTH side, and the UAV side bumps. I found no path that skips a needed transition.Not measured. The targets memo itself (needs a bench row that binds targets), and any game frame.
AI use: Claude Code (Claude Opus 5.5).
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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.