GPU: a draw reads the swizzle it already has, and the release frame line costs nothing #3238
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!3238
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3238"
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:14 UTC · original
borosf:vibe/frame-waste-cluster-842ca5→main· +161 −27 · 3 files · 2 commits · openFour pieces of per-draw waste found by a sweep of the world frame, all of them work that is computed and then thrown away. No behaviour change: the same values, read instead of rebuilt.
What each one cost
A placed texture's swizzle was derived by building the whole console layout.
texture_layoutbuilds atexture::Texture— three heap allocations plus oneMipper level — to answer with a singleu32. Two per-draw paths did it:memory_key, whichcurrent()reaches for every placed texture a heap slot reads (texture_at→current→memory_key) andshared_texturereaches for every title texture of one memory;alias_source'sbytesclosure, reached fromdraw.rs'sreadablefor every texture view of every draw, and again for every candidate it compares against.footprintalready calledtexture_layoutonce at creation and threw the result away. The resource now keeps the swizzle from that point and both paths read the word.Deferred's two dedup sets were hash sets. A list asksdefer_refresha few dozen times; SipHash over a 24-byte tuple plus a set probe is ~20 ns where a linear scan of three words is under 5.refreshedandtexturesare now lists, withfirst_useand bothdefer_refresh/defer_heapkeeping their answers.memory::note_usefilled a diagnostics-only map in release builds.Stats::uses(aBTreeMap<String, u64>) is read by exactly one place: the once-a-frame line that names the busiest shaders. Filling it cost a global mutex, aStringallocation and aBTreeMapdescent per draw per memory-reading stage, in every build. It is now#[cfg(feature = "diagnostics")], and anAtomicU64(USES) carries the count the release line prints, so the line reads the same.memory::log_framebuilt its output before asking whether to write it. It drained the stats, sorted the map and formatted up to 32Strings, then calledtracing::info!. It now checkstracing::enabled!(Level::INFO)first.Measured
Intel Arc B580, Windows 11,
--release:Synthetic descriptions only. The per-frame total is that cost times the number of placed-texture reads and texture views a world frame makes, which this PR does not attempt to count — the counters for it belong to the follow-ups claimed for the same sweep.
Verification
cargo clippy -p victory-gpu --all-targets --locked -- -D warnings— clean.cargo clippy -p victory-gpu --all-targets --all-features --locked -- -D warnings— clean.cargo test -p victory-gpu --lib --locked --no-fail-fast— 229 passed, 2 failed. Both failures are this card's known baseline failures that pristinemainalso fails:descriptor::host::tests::dynamic_slots_are_held_until_releasedandmemory::tests::lists_share_a_table_and_copies_keep_their_views(#1744/#1829, the Intel view-heap cap).rustfmt --edition 2024 --checkper file, hunk counts againstmain:resource.rs64/64,host.rs85/85,memory.rs30/30 — no new formatting hunks (the tree is deliberately notrustfmt-clean).Synthetic tests only; no game data was used, and none enters the repo.
Part of the fifteen gaps claimed for this sweep on #1633. AI-assisted.
@Dukestar69 on GitHub · 2026-11-26 14:34 UTC · original · approved these changes
Reviewed the diff and verified locally on Windows 11 x64 (RTX 5090):
Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
@KainanP on GitHub · 2026-11-26 14:50 UTC · original
Measured on main
63bcca4with this PR merged (RTX 4060 Laptop, release, median of 7 interleaved runs; method in #2586):alias_source: 120 → 14 ns, and an indexed draw reading six textures: 2713 → 1966 ns. Good.Deferred::refreshedas aVecwithcontainsgrows with the list. In a sequence where each draw binds a new constant-ring position (root CBV, 4 root constants, index buffer, draw; lists reset every 2,000 calls), the sequence costs 2388 ns per draw, against 1966 for the bare draw. On main and on every other build measured, the setters add ~70 ns. A world frame's lists refresh thousands of distinct ranges, so the scan is O(n) per refresh and O(n²) per list. A set with a cheap hash (#2102's FxHash) keeps the gain without that cost. #1978 has the samealias_sourcechange alone.AI use: Claude Code (Claude Opus 5.5) ran the measurements and drafted this comment.
@borosf on GitHub · 2026-11-26 14:59 UTC · original
Fixed at
b5e79ab9b7999caef232e4025e17397f0919080a:Deferred::refreshedandDeferred::texturesare nowFastSet— aHashSetwith an in-tree FxHash (the same multiply-rotate step as victory-shader'sstructure.rs; no new dependency) — so insert is O(1) at any list length instead of the O(n) Vec scan your sequence measured (2388 ns vs 1966 ns bare draw). The alias_source change is untouched and keeps your 120 → 14 ns. Clippy clean on both feature sets, 229 passed / 2 failed (the known #1744/#1829 baseline), rustfmt hunks host.rs 85/85. Synthetic tests only; no game data.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.