GPU: per-list and per-submission sets hash with FxHash, not SipHash #2102
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!2102
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@0xkn0wh3r3 on GitHub · 2026-11-25 04:59 UTC · original
0xkn0wh3r3:gpu/fx-hash-per-list→main· +232 −6 · 6 files · 2 commits · openTwo 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.@0xkn0wh3r3 on GitHub · 2026-11-25 07:21 UTC · original
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.
@Marvisak on GitHub · 2026-11-25 10:39 UTC · original · edited 2026-11-26 01:21 UTC
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
@catminou4 on GitHub · 2026-11-25 05:02 UTC · original · reviewed
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 on GitHub · 2026-11-25 05:36 UTC · original · approved these changes
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).
@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):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.
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.