Skip to content

GPU: per-list and per-submission sets hash with FxHash, not SipHash - #2102

Open
0xkn0wh3r3 wants to merge 2 commits into
Marvisak:mainfrom
0xkn0wh3r3:gpu/fx-hash-per-list
Open

0xkn0wh3r3 wants to merge 2 commits into
Marvisak:mainfrom
0xkn0wh3r3:gpu/fx-hash-per-list

Conversation

@0xkn0wh3r3

@0xkn0wh3r3 0xkn0wh3r3 commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

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:

  • the list's refreshed ranges and textures (host.rs, Deferred),
  • the submission batch's pending and current ranges by copy (Batch),
  • a copy's pending ranges and compared pieces (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, with fx::Set and fx::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.
  • The refreshed-range set alone (4,000 inserts of that shape):
hasher ns per insert
SipHash 22.4
this hasher 7.6
this hasher without the final rotation 8.6

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

  • New ignored benchmark draw::tests::dispatch_binding_cost: 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). 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 with cargo test --release -p victory-gpu -- --ignored --nocapture dispatch_binding_cost. Synthetic (no game data here).
  • cargo test -p victory-gpu on an RTX 5070 Ti (driver 621.24): all pass except descriptor::host::tests::dynamic_slots_are_held_until_released and memory::tests::lists_share_a_table_and_copies_keep_their_views, which fail the same way on main (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

Rebased onto 13f91ca

  • Upstream 23a4b62 removed Batch's texture set (a texture is now uploaded once per submission, when its bytes changed). So in Batch only the pending and current maps switch to FxHash; the list's refreshed and textures sets and the copy's pending set and snapshot pieces still do.
  • The hasher (fx.rs) and the benchmark commit are unchanged.

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 DenRakEiw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 failed
  • cargo clippy -p victory-gpu --all-targets — 0 warnings
  • cargo 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).

triippywhale pushed a commit to triippywhale/victory-fork that referenced this pull request Nov 25, 2026
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
triippywhale pushed a commit to triippywhale/victory-fork that referenced this pull request Nov 25, 2026
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
@0xkn0wh3r3

Copy link
Copy Markdown
Contributor Author

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 commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

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.rs adds FxHash-based Set/Map aliases, using the multiply-rotate step victory_shader::structure::Fx already uses, plus a final rotation. They replace SipHash in Deferred::refreshed/textures and Batch::pending/current (host.rs) and in Shadow::pending and the snapshot's compared set (shadow.rs). The keys are internal addresses, and the only ordered use (busy in Shadow::update) is sorted first. The ignored benchmark draw::tests::dispatch_binding_cost and the test-only pipeline::translated_for_test add no runtime code.

The branch merges cleanly. CI: check passing.


Generated by Claude Code

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).
@KainanP

KainanP commented Nov 26, 2026

Copy link
Copy Markdown

Measured on main 63bcca4 with this PR merged (RTX 4060 Laptop, release, median of 7 interleaved runs; method in #2586 (comment)): Shadow::refresh of 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.

@fuzeofficlal fuzeofficlal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-39 is gated under #[cfg(windows)] (lib.rs:37) and pipeline::translated_for_test (pipeline.rs:112) is gated under #[cfg(all(test, windows))], keeping non-Windows builds clean. The rotate_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,1016 Deferred::refreshed/textures, host.rs:2403,2406 Batch::pending/current, and shadow.rs:79,96 Shadow::pending/Snapshot) are purely internal membership/lookup tables; the only ordered consumer (busy in Shadow::update) explicitly runs sort_unstable().
  • Disjoint from #2940: #2940 only touches bindless.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 on main) and 246/246 passed on WARP (--features diagnostics, zero skips).
  • host:: shadow:: draw:: with VICTORY_D3D12_DEBUG=1: 64/64 passed on RTX 5090 (skipping dynamic_slots_are_held_until_released) and 65/65 passed on WARP (--features diagnostics, skipping the pre-existing main compositor_failure_presents_primary_in_the_same_frame Debug 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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants