Repository navigation
Conversation
A placed-texture read asked a texture for its swizzle by building the whole console layout: three allocations and the full mip chain, under a lock, to answer with one `u32`. Two paths did it per draw — `memory_key`, which `current()` and `texture_at` reach for every placed texture a heap slot reads, and `alias_source`'s row geometry, which every texture view of every draw reaches. The resource now works the swizzle out once at creation, where `footprint` already called the same function, and both paths read the word. `Deferred`'s two dedup sets are lists. A list asks a few dozen times, and a linear scan over three words beats SipHash over a tuple plus a set probe at that length; `first_use` and both `defer_refresh`/`defer_heap` keep their answers. `memory::note_use` becomes an atomic count, and the per-pipeline map that names the busiest shaders is diagnostics only — nothing but the frame line reads it, and filling it cost a global lock, a `String` allocation and a `BTreeMap` descent per draw per memory-reading stage. The release line still prints the same count, from `USES`. `memory::log_frame` asks whether the info level is enabled before it sorts the map and formats up to 32 `String`s, so a run logging above it no longer builds them for nothing. Measured on an Intel Arc B580, `cargo test --release -p victory-gpu --lib -- --exact --ignored --nocapture resource::tests::a_swizzle_costs_no_layout_per_placed_texture`: deriving a 2048x2048 12-mip texture's swizzle costs 290 ns, a 1920x1080 render target's 263 ns; reading the kept word costs nothing measurable. Synthetic descriptions only, no game data. Synthetic tests only; no game data.
Dukestar69
left a comment
There was a problem hiding this comment.
Reviewed the diff and verified locally on Windows 11 x64 (RTX 5090):
- Caching layout_swizzle on Resource at creation avoids rebuilding the full console mip layout per memory_key / �lias_source lookup; gating Stats::uses behind diagnostics with an atomic USES counter and racing::enabled!(INFO) guard removes per-draw global lock/allocation overhead in non-diagnostics builds; small Vec lookups for Deferred::{refreshed, textures} are clean.
- cargo test -p victory-gpu --lib resource:: -- --test-threads=1 (RTX 5090): 18 passed, 0 failed, 1 ignored (�_swizzle_costs_no_layout_per_placed_texture).
- cargo test -p victory-gpu --lib memory::tests:: -- --test-threads=1 --skip lists_share_a_table_and_copies_keep_their_views (RTX 5090): 7 passed, 0 failed (pre-existing #1744 test skipped).
- cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
- cargo clippy -p victory-gpu --features diagnostics --all-targets -- -D warnings: clean.
- cargo xtask policy: 191 files ok.
Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
|
Measured on main 63bcca4 with this PR merged (RTX 4060 Laptop, release, median of 7 interleaved runs; method in #2586 (comment)):
AI use: Claude Code (Claude Opus 5.5) ran the measurements and drafted this comment. |
Reviewer measurement on Marvisak#3238 (RTX 4060 Laptop): the Vec scan kept the alias_source win but a draw sequence that binds a new constant-ring position each draw cost 2388 ns against 1966 ns bare, because the scan is O(n) per refresh and O(n^2) per list, while a world frame's lists refresh thousands of distinct ranges. SipHash over the tuple was the original cost. `Deferred::refreshed` and `Deferred::textures` are now `FastSet` — a `HashSet` with an in-tree FxHash (the same multiply-rotate step victory-shader's structure.rs uses; no new dependency), keeping insert at O(1) regardless of list length. Synthetic tests only; no game data.
|
Fixed at |
Four 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(Test report: RTX 5070 (Blackwell), Windows 11, 70564ae: 471 passed, 5 failed, 7 ignored (4 from the 1,000,000 view heap cap) #1744/Test report: Intel UHD (Raptor Lake Xe-LP), 70564ae: victory-shader 201 passed, 8 failed (3 missing-feature skips, 5 different results) #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.