GPU: per-list and per-submission sets hash with FxHash, not SipHash #2100
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2102"
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 0xkn0wh3r3 on 2026-11-25T04:59:27Z.
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, #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
13f91ca23a4b62removedBatch'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.Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T05:02:24Z.
Review: COMMENTED
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.
Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T05:36:55Z.
Review: APPROVED
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
FxHashfor per-list and per-submission GPU sets. Looks good.AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by 0xkn0wh3r3 on 2026-11-25T07:21:18Z.
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.
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T10:39:03Z.
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
main.crates/victory-gpu/src/fx.rsadds FxHash-basedSet/Mapaliases, using the multiply-rotate stepvictory_shader::structure::Fxalready uses, plus a final rotation. They replace SipHash inDeferred::refreshed/texturesandBatch::pending/current(host.rs) and inShadow::pendingand the snapshot's compared set (shadow.rs). The keys are internal addresses, and the only ordered use (busyinShadow::update) is sorted first. The ignored benchmarkdraw::tests::dispatch_binding_costand the test-onlypipeline::translated_for_testadd no runtime code.The branch merges cleanly. CI:
checkpassing.Generated by Claude Code
upstream-sync referenced this pull request2026-11-25 13:02:56 +00:00
Imported from Marvisak/VIctory. Originally posted by KainanP on 2026-11-26T14:50:18Z.
Measured on main
63bcca4with this PR merged (RTX 4060 Laptop, release, median of 7 interleaved runs; method in https://github.com/Marvisak/VIctory/issues/2586#issuecomment-7195391455):Shadow::refreshof a range the list already has goes from 21 to 12 ns. An indexed draw reading six textures and three root constant buffers goes from 2713 to 2663 ns, and the same draws on five threads from 10526 to 9897 ns per draw per thread. It's a small gain, and it holds over long lists, unlike #3238's linear scan.AI use: Claude Code (Claude Opus 5.5) ran the measurements and drafted this comment.
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T15:04:40Z.
Review: APPROVED
Reviewed all 6 files at
29408fe3merged ontoorigin/main(63bcca43) and verified on RTX 5090, WARP (VICTORY_D3D12_WARP=1),VICTORY_D3D12_DEBUG=1, and a--releasebenchmark run.Code & safety audit
#[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.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().#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.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).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.