Repository navigation
GPU: per-list and per-submission sets hash with FxHash, not SipHash - #2102
0xkn0wh3r3 wants to merge 2 commits into
Conversation
catminou4
left a comment
There was a problem hiding this comment.
Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff.
Per-list/per-submission sets hashed with FxHash — hash-fn change for perf; FxHash is non-cryptographic, fine for internal sets but note collision behavior under adversarial titles.
DenRakEiw
left a comment
There was a problem hiding this comment.
Verified locally merged onto origin/main (940d32f, Windows 11 x64, Rust 1.98.1 MSVC):
cargo test -p victory-gpu --lib shadow::— 4 passed, 0 failedcargo clippy -p victory-gpu --all-targets— 0 warningscargo xtask policy— ok (184 files ok)
Clean replacement of SipHash with FxHash for per-list and per-submission GPU sets. Looks good.
AI-assisted (Gemini 4 Neon).
Ported from Marvisak/VIctory#2102 (2e34e02, by 0xkn0wh3r3): `fx.rs` as is, and the sets and maps it changed that this tree has in that shape. A sampling profile there put about 13% of a dispatch's bind in SipHash and the inserts into the list's refreshed-range set; FxHash took a bind from 1.68 to 1.56 microseconds, 22.4 to 7.6 ns per insert. The keys are our own host objects and title addresses, so SipHash's resistance to chosen collisions buys nothing. Here: the list's refreshed ranges and textures, the submission batch's index and textures (as in the PR), and also the landing's maps of pushed parts on the relay thread (`pushed`, `last`, `merged`, `seen` and `flagged_parts`), which run main 9e6137f fills with some 118,000 parts a frame on the thread the submitting thread waits for. A copy's pending ranges are a `Vec` in this tree; left as they are. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017V7WBB9Mgcxkr8YRW4LAzi
In run main 9e6137f the title's recording threads spent 22-25 microseconds on each dispatch (list.rs:1605) and each indirect execution (list.rs:1721), some 15,000 a frame and 345 ms over the threads; a bind in the PR benchmark of Marvisak/VIctory#2102 takes under 2. The stats line now says, for every bind of a draw or dispatch, how long it took in all and in the parts that may cost: textures picked by index ahead of asking, the descriptor tables with their refreshes, title memory by address (`memory::ready`, under one lock for every thread), and the heap's buffer views. Diagnostics builds only. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017V7WBB9Mgcxkr8YRW4LAzi
|
On FxHash under adversarial input: the keys are the title's GPU addresses and ids within one list or submission. A crafted collision set could make a set slower, never wrong. The title also runs as native code in our process, so it doesn't need a hash collision to slow us down. SipHash's flooding resistance buys nothing here. |
|
Automated triage for the maintainers. Merge candidate (a recommendation to look, not an approval). The new head is the same two commits rebased onto current The branch merges cleanly. CI: Generated by Claude Code |
2e34e02 to
9278b45
Compare
…h, not SipHash) into demo
An ignored benchmark, `draw::tests::dispatch_binding_cost`, for the CPU cost of a draw-side bind, which nothing measured: a compute stage whose translation reads four descriptor tables of four buffer views each through user data, bound through `State::bind` 2,000 times in 8 lists with the tables moving between dispatches (512 materials), then submitted. The host code is a shader with no resources, which any root signature takes, so `HostPipeline::new` builds the root signature and pipeline the translation defines (`pipeline::translated_for_test` sets a shader's translation without a console program). RTX 5070 Ti host, release build: about 1.7 us per dispatch to bind and record, about 1.2 ms to submit the 2,000.
A sampling profile of `dispatch_binding_cost` put about 13% of binding in SipHash and the inserts into the list's refreshed-range set (host copy, address, bytes per buffer view a draw reads). These sets and maps (the list's refreshed ranges and textures, the submission batch's, a copy's pending ranges and compared pieces) are keyed by our own host object and title addresses, so SipHash's resistance to chosen collisions buys nothing. They now hash with FxHash's multiply-rotate step, finished with a rotation as rustc-hash 2 does, so that aligned addresses (low bits zero) do not depend on the multiply's weakest bits for their bucket. Measured on an RTX 5070 Ti host, release build: - `dispatch_binding_cost`, the two builds' test binaries alternated 20 times each: median 1.680 -> 1.555 us per dispatch; FxHash faster in 18 of 20 pairs (sign test p = 0.0004); bootstrap 95% interval for the ratio of medians 0.882-0.943. - The refreshed-range set alone (4,000 inserts of that shape): 22.4 ns per insert with SipHash, 7.6 ns with this hasher (8.6 ns without the final rotation).
9278b45 to
29408fe
Compare
…s hash with FxHash, not SipHash
|
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. |
fuzeofficlal
left a comment
There was a problem hiding this comment.
Reviewed all 6 files at 29408fe3 merged onto origin/main (63bcca43) and verified on RTX 5090, WARP (VICTORY_D3D12_WARP=1), VICTORY_D3D12_DEBUG=1, and a --release benchmark run.
Code & safety audit
- Zero-dependency FxHash &
#[cfg]hygiene:crates/victory-gpu/src/fx.rs:11-39is gated under#[cfg(windows)](lib.rs:37) andpipeline::translated_for_test(pipeline.rs:112) is gated under#[cfg(all(test, windows))], keeping non-Windows builds clean. Therotate_left(26)finalizer (fx.rs:21) spreads aligned host/title addresses across hash buckets. - No order-sensitive regressions: all replaced sets/maps (
host.rs:1014,1016Deferred::refreshed/textures,host.rs:2403,2406Batch::pending/current, andshadow.rs:79,96Shadow::pending/Snapshot) are purely internal membership/lookup tables; the only ordered consumer (busyinShadow::update) explicitly runssort_unstable(). - Disjoint from
#2940:#2940only touchesbindless.rs, so the two merge without conflict.
Verification
cargo run -p xtask -- policy: 192 files ok.cargo clippy -p victory-gpu --all-targets -- -D warnings(default and--all-features): clean.- Full
victory-gpu --lib: 229/229 passed on RTX 5090 (skipping the 2 pre-existing NVIDIA 1M-cap tests onmain) and 246/246 passed on WARP (--features diagnostics, zero skips). host:: shadow:: draw::withVICTORY_D3D12_DEBUG=1: 64/64 passed on RTX 5090 (skippingdynamic_slots_are_held_until_released) and 65/65 passed on WARP (--features diagnostics, skipping the pre-existingmaincompositor_failure_presents_primary_in_the_same_frameDebug Layer mismatch).cargo test --release -p victory-gpu --lib -- --ignored --nocapture dispatch_binding_cost(draw.rs:2713) on Ryzen 9 9950X + RTX 5090: median 1.77 us/dispatch (1.75–1.83 us), submit 1.21–1.46 ms (2,000 dispatches).
Two commits: a benchmark for the CPU cost of binding a dispatch, and the change it measured.
The problem
Binding a draw or dispatch spent a noticeable share of its CPU time hashing. Nothing measured that cost, so the first commit adds a benchmark for it (see Testing).
A sampling profile of that benchmark,
dispatch_binding_cost, put about 13% of binding in SipHash and the inserts into the list's refreshed-range set (host copy, address, bytes per buffer view a draw reads).These sets and maps are keyed by our own host objects and title addresses:
host.rs,Deferred),Batch),shadow.rs).No key comes from outside, so SipHash's resistance to chosen collisions buys nothing there.
The fix
They now hash with FxHash's multiply-rotate step (new
fx.rs, withfx::Setandfx::Map). The hash is finished with a rotation, as rustc-hash 2 does, so that aligned addresses (low bits zero) do not depend on the multiply's weakest bits for their bucket.Measured on an RTX 5070 Ti host, release build:
dispatch_binding_cost, the two builds' test binaries alternated 20 times each: median 1.680 -> 1.555 us per dispatch. FxHash faster in 18 of 20 pairs (sign test p = 0.0004); bootstrap 95% interval for the ratio of medians 0.882-0.943.Binding is about 1.7 us per dispatch, roughly 5 ms per frame at the world's ~3,000 draws, so this is a small gain (~0.4 ms per frame), not a bottleneck fix. Only these per-list and per-submission sets change; other hash maps keep SipHash.
Testing
draw::tests::dispatch_binding_cost: a compute stage whose translation reads four descriptor tables of four buffer views each through user data, bound throughState::bind2,000 times in 8 lists, with the tables moving between dispatches (512 materials), then submitted. The host code is a shader with no resources, which any root signature takes, soHostPipeline::newbuilds the root signature and pipeline the translation defines (pipeline::translated_for_testsets a shader's translation without a console program). On an RTX 5070 Ti host, release build: about 1.7 us per dispatch to bind and record, about 1.2 ms to submit the 2,000. Run withcargo test --release -p victory-gpu -- --ignored --nocapture dispatch_binding_cost. Synthetic (no game data here).cargo test -p victory-gpuon an RTX 5070 Ti (driver 621.24): all pass exceptdescriptor::host::tests::dynamic_slots_are_held_until_releasedandmemory::tests::lists_share_a_table_and_copies_keep_their_views, which fail the same way onmain(the NVIDIA 1,000,000-descriptor heap cap, NVIDIA D3D12 (70564ae): stride_tests & synthetic_tests fail due to HEAP_VIEWS (2M > 1M NVIDIA limit) and Stride::Structured with rawBufferLoad #1835).cargo clippy -p victory-gpu --all-targets, with and without--features diagnostics: clean.Related
victory-shader's lowering tables. This one isvictory-gpuonly and has its own copy of the hasher.Rebased onto 13f91ca
Batch's texture set (a texture is now uploaded once per submission, when its bytes changed). So inBatchonly thependingandcurrentmaps switch to FxHash; the list'srefreshedandtexturessets and the copy'spendingset and snapshot pieces still do.fx.rs) and the benchmark commit are unchanged.