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

Open
github-bot wants to merge 2 commits from github-bot/gh-2102 into main AGit
Owner

@⁠0xkn0wh3r3 on GitHub · 2026-11-25 04:59 UTC · original
0xkn0wh3r3:gpu/fx-hash-per-list → main · +232 −6 · 6 files · 2 commits · open

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, #1835).
  • cargo clippy -p victory-gpu --all-targets, with and without --features diagnostics: clean.
  • #1002 makes the same hasher change for victory-shader's lowering tables. This one is victory-gpu only and has its own copy of the hasher.

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.
**@⁠0xkn0wh3r3** on GitHub · 2026-11-25 04:59 UTC · [original](https://github.com/Marvisak/VIctory/pull/2102) `0xkn0wh3r3:gpu/fx-hash-per-list` → `main` · +232 −6 · 6 files · 2 commits · open 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, #1835). - `cargo clippy -p victory-gpu --all-targets`, with and without `--features diagnostics`: clean. ## Related - #1002 makes the same hasher change for `victory-shader`'s lowering tables. This one is `victory-gpu` only and has its own copy of the hasher. ### 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.
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).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:54:52 +00:00
Author
Owner

@⁠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.

**@⁠0xkn0wh3r3** on GitHub · 2026-11-25 07:21 UTC · [original](https://github.com/Marvisak/VIctory/pull/2102#issuecomment-7155767229) 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.
Author
Owner

@⁠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.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

**@⁠Marvisak** on GitHub · 2026-11-25 10:39 UTC · [original](https://github.com/Marvisak/VIctory/pull/2102#issuecomment-7159986568) · edited 2026-11-26 01:21 UTC <!-- victory-triage v1 head=29408fe3bcb8709ad3223b1742827710add01004 verdict=merge-candidate at=2026-11-26T01:21:15Z --> 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](https://claude.ai/code)_
Author
Owner

@⁠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.

**@⁠catminou4** on GitHub · 2026-11-25 05:02 UTC · [original](https://github.com/Marvisak/VIctory/pull/2102#pullrequestreview-6052105525) · **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.
Author
Owner

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

**@⁠DenRakEiw** on GitHub · 2026-11-25 05:36 UTC · [original](https://github.com/Marvisak/VIctory/pull/2102#pullrequestreview-6052374645) · **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 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).
Author
Owner

@⁠KainanP on GitHub · 2026-11-26 14:50 UTC · original

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

**@⁠KainanP** on GitHub · 2026-11-26 14:50 UTC · [original](https://github.com/Marvisak/VIctory/pull/2102#issuecomment-7195403097) Measured on main 63bcca4 with this PR merged (RTX 4060 Laptop, release, median of 7 interleaved runs; method in https://git.gtahub.st/github/Marvisak--VIctory/issues/2586): `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._
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2102/head:github-bot/gh-2102'
git switch 'github-bot/gh-2102'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2102'
git switch 'github-bot/gh-2102'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2102'
git switch 'github-bot/gh-2102'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2102'
git switch 'main'
git merge --squash 'github-bot/gh-2102'
git switch 'main'
git merge --ff-only 'github-bot/gh-2102'
git switch 'main'
git merge 'github-bot/gh-2102'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2102
No description provided.