Shaders: hash the translator's hot maps with the multiply-rotate hasher #2399

Open
github-bot wants to merge 6 commits from github-bot/gh-2399 into main AGit
Owner

@⁠borosf on GitHub · 2026-11-25 12:51 UTC · original
borosf:vibe/translate-hot-hash-842ca5 → main · +201 −76 · 8 files · 6 commits · open

Summary

  • The translator's hot maps — lower's value/PHI/bool caches, wave's section shapes, bitcode's constant and type dedup, structure's pass maps — hashed with the std default's SipHash, which profiling attributed ~10–12% of translation time.
  • Those maps now use the multiply-rotate hasher structure already used for its atom maps, moved to a shared hash.rs. No semantics change: iteration order converges anywhere order matters.
  • A stage-timed #[ignore]d benchmark (emit::translate_bench) drives a straight-line synthetic pixel program — 10,000 v_mad_f32 and 250 s_addk_i32, no control flow; a test asserts that exact shape (every instruction decodes under its own name, no branch opcodes, one IR block) — through ir → structure → resource → io → emit, so the stage times measure the straight-line passes only.

Numbers

Interleaved A/B in release mode, the fixture identical on both sides:

  • emit stage on a Ryzen 9 7900X: 5.55 → 3.93 ms (−29%), three runs per side; emitted DXIL identical in byte length and SHA-256 in every run.
  • emit stage on the authoring machine: 5.79/5.94 → 4.83/4.92 ms (−16–17%); every other stage flat within noise, so the attribution sits on the hasher alone.
  • structure now genuinely measured at ~0.34–0.40 ms on this fixture.

Verification

  • cargo test -p victory-shader --lib: 145 passed; the fixture-shape test among them.
  • cargo clippy -p victory-shader --all-targets: identical to pristine main 940d32f.
  • cargo check --target x86_64-pc-windows-msvc -p victory-shader --all-targets: clean.
  • Benchmark: cargo test --release -p victory-shader bench_translate --ignored --nocapture. No game data used.
**@⁠borosf** on GitHub · 2026-11-25 12:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/2399) `borosf:vibe/translate-hot-hash-842ca5` → `main` · +201 −76 · 8 files · 6 commits · open ## Summary - The translator's hot maps — `lower`'s value/PHI/bool caches, `wave`'s section shapes, `bitcode`'s constant and type dedup, `structure`'s pass maps — hashed with the std default's SipHash, which profiling attributed ~10–12% of translation time. - Those maps now use the multiply-rotate hasher `structure` already used for its atom maps, moved to a shared `hash.rs`. No semantics change: iteration order converges anywhere order matters. - A stage-timed `#[ignore]`d benchmark (`emit::translate_bench`) drives a **straight-line** synthetic pixel program — 10,000 `v_mad_f32` and 250 `s_addk_i32`, no control flow; a test asserts that exact shape (every instruction decodes under its own name, no branch opcodes, one IR block) — through ir → structure → resource → io → emit, so the stage times measure the straight-line passes only. ## Numbers Interleaved A/B in release mode, the fixture identical on both sides: - emit stage on a Ryzen 9 7900X: **5.55 → 3.93 ms (−29%)**, three runs per side; emitted DXIL identical in byte length and SHA-256 in every run. - emit stage on the authoring machine: 5.79/5.94 → 4.83/4.92 ms (−16–17%); every other stage flat within noise, so the attribution sits on the hasher alone. - `structure` now genuinely measured at ~0.34–0.40 ms on this fixture. ## Verification - `cargo test -p victory-shader --lib`: 145 passed; the fixture-shape test among them. - `cargo clippy -p victory-shader --all-targets`: identical to pristine main 940d32f. - `cargo check --target x86_64-pc-windows-msvc -p victory-shader --all-targets`: clean. - Benchmark: `cargo test --release -p victory-shader bench_translate --ignored --nocapture`. No game data used.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:04:42 +00:00
Author
Owner

@⁠borosf on GitHub · 2026-11-25 14:05 UTC · original

@⁠DrDarkDK

Both points taken and fixed in f383abd — thank you, the fixture was lying. You found the exact cause: this decoder's SOPP table numbers s_cbranch_scc0 as op 4 and s_branch as op 2, and my SOPK word carried the opcode at the wrong bit-field — so my "branch" word was s_cmp_eq_i32 and my "back edge" both wrong-coded and unreachable, exactly as you decoded. Since the program was straight-line in fact, I took your second option: the fake control words are gone, the fixture is documented as a straight-line workload (10,000 v_mad_f32 + 250 s_addk_i32), and a test asserts that shape — every instruction decodes under its own name, no branch opcodes, one IR block — so it can't drift again.

The structure timer now wraps the call (~0.40 ms here, matching your 0.38), and a fresh A/B with the honest fixture on both sides lands where your run did: emit 5.79 → 4.83 ms here, your 5.60 → 4.06 with an identical DXIL checksum. Stage-fair attribution to the hasher unchanged.

**@⁠borosf** on GitHub · 2026-11-25 14:05 UTC · [original](https://github.com/Marvisak/VIctory/pull/2399#issuecomment-7164732430) @⁠DrDarkDK Both points taken and fixed in f383abd — thank you, the fixture was lying. You found the exact cause: this decoder's SOPP table numbers `s_cbranch_scc0` as op 4 and `s_branch` as op 2, and my SOPK word carried the opcode at the wrong bit-field — so my "branch" word was `s_cmp_eq_i32` and my "back edge" both wrong-coded and unreachable, exactly as you decoded. Since the program was straight-line in fact, I took your second option: the fake control words are gone, the fixture is documented as a straight-line workload (10,000 `v_mad_f32` + 250 `s_addk_i32`), and a test asserts that shape — every instruction decodes under its own name, no branch opcodes, one IR block — so it can't drift again. The structure timer now wraps the call (~0.40 ms here, matching your 0.38), and a fresh A/B with the honest fixture on both sides lands where your run did: emit 5.79 → 4.83 ms here, your 5.60 → 4.06 with an identical DXIL checksum. Stage-fair attribution to the hasher unchanged.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 15:30 UTC · original · edited 2026-11-26 07:22 UTC

Automated triage for the maintainers.

Needs work (one line). Thanks for the rebase. 839ca90 merges cleanly. The hasher change is mechanical: crate::hash::{HashMap, HashSet} replaces the std maps in lower.rs, wave.rs, bitcode.rs and structure.rs, using the same Fx step structure already used. It does not change the output. The std default was already randomly seeded, so nothing could depend on iteration order before either.

One point from the earlier note is still open. In emit/translate_bench.rs bench_translate, the io stage reuses the timer started before resource::track, so io reports resource + io. Add let n = std::time::Instant::now(); before crate::io::raise.

I'm withdrawing the earlier pub(crate) request. structure::Structured's public fields (masks, active, discards, ...) now have the Fx-hashed map type, so hash and Fx need to be public.

CI: check passing.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 15:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/2399#issuecomment-7166955448) · edited 2026-11-26 07:22 UTC <!-- victory-triage v1 head=839ca9013b5a330cab83e0e8bd4b11fcfc0ea133 verdict=needs-work at=2026-11-26T07:22:06Z --> Automated triage for the maintainers. **Needs work (one line).** Thanks for the rebase. `839ca90` merges cleanly. The hasher change is mechanical: `crate::hash::{HashMap, HashSet}` replaces the std maps in `lower.rs`, `wave.rs`, `bitcode.rs` and `structure.rs`, using the same Fx step `structure` already used. It does not change the output. The std default was already randomly seeded, so nothing could depend on iteration order before either. One point from the earlier note is still open. In `emit/translate_bench.rs` `bench_translate`, the `io` stage reuses the timer started before `resource::track`, so `io` reports resource + io. Add `let n = std::time::Instant::now();` before `crate::io::raise`. I'm withdrawing the earlier `pub(crate)` request. `structure::Structured`'s public fields (`masks`, `active`, `discards`, ...) now have the Fx-hashed map type, so `hash` and `Fx` need to be public. CI: `check` passing. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠borosf on GitHub · 2026-11-25 17:15 UTC · original

Rebased onto current main (merge fd40df1): main's new entry/join handle maps in lower join the rest as multiply-rotate maps — same hasher, same one-line-swap pattern, no behavior change. One note for the Linux side: main's new lower.rs tests reference the Windows-gated validator without cfg gating, so cargo test -p victory-shader --lib doesn't build on Linux on pristine main either (pre-existing, not from this PR); the Windows-target check is clean, and CI is green.

Again, please check it out when you can :) @⁠Marvisak

**@⁠borosf** on GitHub · 2026-11-25 17:15 UTC · [original](https://github.com/Marvisak/VIctory/pull/2399#issuecomment-7169245297) Rebased onto current main (merge fd40df1): main's new entry/join handle maps in lower join the rest as multiply-rotate maps — same hasher, same one-line-swap pattern, no behavior change. One note for the Linux side: main's new lower.rs tests reference the Windows-gated validator without cfg gating, so cargo test -p victory-shader --lib doesn't build on Linux on pristine main either (pre-existing, not from this PR); the Windows-target check is clean, and CI is green. Again, please check it out when you can :) @⁠Marvisak
Author
Owner

@⁠borosf on GitHub · 2026-11-26 06:59 UTC · original

Merged current main in at 839ca90 — live_edges' new Known lanes copy is kept and the Fx-hash maps follow it; translate_bench and the newly-landed census_tests coexist. CI green.

**@⁠borosf** on GitHub · 2026-11-26 06:59 UTC · [original](https://github.com/Marvisak/VIctory/pull/2399#issuecomment-7184985844) Merged current main in at 839ca90 — live_edges' new Known lanes copy is kept and the Fx-hash maps follow it; translate_bench and the newly-landed census_tests coexist. CI green.
The bench reused the timer started before resource::track for the io
stage, so 'io' reported resource + io together and the two could not be
read apart. One Instant::now() before crate::io::raise, found in review.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <[email protected]>
Author
Owner

@⁠DrDarkDK on GitHub · 2026-11-25 13:13 UTC · original · requested changes

I ran bench_translate in release mode on native Windows at 7dd429c. Two details affect how I’d interpret the benchmark:

  • The structuring timer starts after structure(&p) returns. The original run printed structure=0.00ms. Timing the call itself measured about 0.38 ms per translation.
  • The fixture decodes into one IR block with zero conditional branches. It contains 10,000 v_mad_f32 instructions, but the words marked as the conditional branch and back edge decode as s_cmp_eq_i32 and s_movk_i32 respectively.

In one local A/B against 510c2a2, emit time still fell from 5.60 ms to 4.06 ms, and the emitted DXIL had the same length and checksum. Could the benchmark move the timer before the call and either assert that the fixture contains the intended control flow or describe it as a straight-line workload?

AI-assisted with Codex.

**@⁠DrDarkDK** on GitHub · 2026-11-25 13:13 UTC · [original](https://github.com/Marvisak/VIctory/pull/2399#pullrequestreview-6058254012) · **requested changes** I ran `bench_translate` in release mode on native Windows at `7dd429c`. Two details affect how I’d interpret the benchmark: - The structuring timer starts after `structure(&p)` returns. The original run printed `structure=0.00ms`. Timing the call itself measured about 0.38 ms per translation. - The fixture decodes into one IR block with zero conditional branches. It contains 10,000 `v_mad_f32` instructions, but the words marked as the conditional branch and back edge decode as `s_cmp_eq_i32` and `s_movk_i32` respectively. In one local A/B against `510c2a2`, emit time still fell from 5.60 ms to 4.06 ms, and the emitted DXIL had the same length and checksum. Could the benchmark move the timer before the call and either assert that the fixture contains the intended control flow or describe it as a straight-line workload? *AI-assisted with Codex.*
Author
Owner

@⁠catminou4 on GitHub · 2026-11-25 13:25 UTC · original · approved these changes

Tested locally: merged into main 940d32f69b, cargo test -p victory-shader --locked on macOS arm64 — 144 passed, 0 failed, 3 ignored (Windows-gated hardware execution tests not run here). Approving — hot translator maps hashed with the multiplexer (perf; one extra ignored test is Windows-gated).

**@⁠catminou4** on GitHub · 2026-11-25 13:25 UTC · [original](https://github.com/Marvisak/VIctory/pull/2399#pullrequestreview-6058435936) · **approved these changes** Tested locally: merged into main 940d32f69b, `cargo test -p victory-shader --locked` on macOS arm64 — 144 passed, 0 failed, 3 ignored (Windows-gated hardware execution tests not run here). Approving — hot translator maps hashed with the multiplexer (perf; one extra ignored test is Windows-gated).
Author
Owner

@⁠DrDarkDK on GitHub · 2026-11-25 14:13 UTC · original · approved these changes

Rechecked f383abd on native Windows with the Ryzen 9 7900X. The fixture test passes and confirms one IR block with 10,000 v_mad_f32 instructions, 250 s_addk_i32 instructions, and no branches. Structuring now measures 0.34–0.38 ms across the valid runs.

I used the corrected fixture on both 510c2a2 and f383abd, with three interleaved release runs per revision. Mean emit time fell from 5.55 ms to 3.93 ms, about 29% on this synthetic workload. The emitted DXIL had the same byte length and SHA-256 in every run.

This resolves both points from my earlier review. Please update the PR description to call the fixture straight-line so it matches what the benchmark measures.

AI-assisted with Codex.

**@⁠DrDarkDK** on GitHub · 2026-11-25 14:13 UTC · [original](https://github.com/Marvisak/VIctory/pull/2399#pullrequestreview-6059210038) · **approved these changes** Rechecked `f383abd` on native Windows with the Ryzen 9 7900X. The fixture test passes and confirms one IR block with 10,000 `v_mad_f32` instructions, 250 `s_addk_i32` instructions, and no branches. Structuring now measures 0.34–0.38 ms across the valid runs. I used the corrected fixture on both `510c2a2` and `f383abd`, with three interleaved release runs per revision. Mean emit time fell from 5.55 ms to 3.93 ms, about 29% on this synthetic workload. The emitted DXIL had the same byte length and SHA-256 in every run. This resolves both points from my earlier review. Please update the PR description to call the fixture straight-line so it matches what the benchmark measures. *AI-assisted with Codex.*
Author
Owner

@⁠borosf on GitHub · 2026-11-26 13:53 UTC · original

The last open point is fixed at a19546d: let n = std::time::Instant::now(); now starts the io stage before crate::io::raise, so io no longer reports resource + io — exactly as asked. The resource stage keeps its own timer, and nothing else in the bench changed.

Verified on an Intel Arc B580, Windows 11:

  • cargo clippy -p victory-shader --all-targets -- --locked -- -D warnings clean.
  • cargo test -p victory-shader --lib --locked -- --test-threads=1 emit::translate_bench → the bench test passes.
  • rustfmt --edition 2024 --check on the touched file: one hunk, at line 66, which is the file's own pre-existing unformatted assert! — the same single hunk before and after this commit (checked against a stashed baseline), so nothing new. This tree is deliberately not cargo fmt clean.
**@⁠borosf** on GitHub · 2026-11-26 13:53 UTC · [original](https://github.com/Marvisak/VIctory/pull/2399#issuecomment-7193987952) The last open point is fixed at `a19546d`: `let n = std::time::Instant::now();` now starts the `io` stage before `crate::io::raise`, so `io` no longer reports resource + io — exactly as asked. The `resource` stage keeps its own timer, and nothing else in the bench changed. Verified on an Intel Arc B580, Windows 11: - `cargo clippy -p victory-shader --all-targets -- --locked -- -D warnings` clean. - `cargo test -p victory-shader --lib --locked -- --test-threads=1 emit::translate_bench` → the bench test passes. - `rustfmt --edition 2024 --check` on the touched file: one hunk, at line 66, which is the file's own pre-existing unformatted `assert!` — the same single hunk before and after this commit (checked against a stashed baseline), so nothing new. This tree is deliberately not `cargo fmt` clean.
This pull request can be merged automatically.
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/2399/head:github-bot/gh-2399'
git switch 'github-bot/gh-2399'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2399'
git switch 'github-bot/gh-2399'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2399'
git switch 'github-bot/gh-2399'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2399'
git switch 'main'
git merge --squash 'github-bot/gh-2399'
git switch 'main'
git merge --ff-only 'github-bot/gh-2399'
git switch 'main'
git merge 'github-bot/gh-2399'
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!2399
No description provided.