Shaders: hash the translator's hot maps with the multiply-rotate hasher #2397
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2399"
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 borosf on 2026-11-25T12:51:00Z.
Summary
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.structurealready used for its atom maps, moved to a sharedhash.rs. No semantics change: iteration order converges anywhere order matters.#[ignore]d benchmark (emit::translate_bench) drives a straight-line synthetic pixel program — 10,000v_mad_f32and 250s_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:
structurenow genuinely measured at ~0.34–0.40 ms on this fixture.Caveat on the headline number
The fixture is one block of straight-line code, so it exercises only some of the maps this PR moves to
Fx:lower's value caches andbitcode's constant and type dedup. It cannot reach the maps that need control flow or console structure —lower's PHI, ballot, section and descriptor/handle tables,wave's section shapes (nos_or_saveexecsection ever appears), andstructure's lane-mask tables beyond proving one block has nothing to structure — so the −29% emit-stage figure measures the straight-line passes on this program, not what a title shader's translation would gain. The number holds for what it measures; it is not a translation-wide estimate, and the maps this fixture cannot reach are unmeasured here.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 main940d32f.cargo check --target x86_64-pc-windows-msvc -p victory-shader --all-targets: clean.cargo test --release -p victory-shader bench_translate --ignored --nocapture. No game data used.Imported from Marvisak/VIctory. Originally posted by DrDarkDK on 2026-11-25T13:13:13Z.
Review: CHANGES_REQUESTED
I ran
bench_translatein release mode on native Windows at7dd429c. Two details affect how I’d interpret the benchmark:structure(&p)returns. The original run printedstructure=0.00ms. Timing the call itself measured about 0.38 ms per translation.v_mad_f32instructions, but the words marked as the conditional branch and back edge decode ass_cmp_eq_i32ands_movk_i32respectively.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.
Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T13:25:24Z.
Review: APPROVED
Tested locally: merged into main
940d32f69b,cargo test -p victory-shader --lockedon 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).Imported from Marvisak/VIctory. Originally posted by borosf on 2026-11-25T14:05:06Z.
@DrDarkDK
Both points taken and fixed in
f383abd— thank you, the fixture was lying. You found the exact cause: this decoder's SOPP table numberss_cbranch_scc0as op 4 ands_branchas op 2, and my SOPK word carried the opcode at the wrong bit-field — so my "branch" word wass_cmp_eq_i32and 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,000v_mad_f32+ 250s_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.
Imported from Marvisak/VIctory. Originally posted by DrDarkDK on 2026-11-25T14:13:02Z.
Review: APPROVED
Rechecked
f383abdon native Windows with the Ryzen 9 7900X. The fixture test passes and confirms one IR block with 10,000v_mad_f32instructions, 250s_addk_i32instructions, and no branches. Structuring now measures 0.34–0.38 ms across the valid runs.I used the corrected fixture on both
510c2a2andf383abd, 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.
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T15:30:41Z.
Automated triage for the maintainers.
Needs work (one line). Thanks for the rebase.
839ca90merges cleanly. The hasher change is mechanical:crate::hash::{HashMap, HashSet}replaces the std maps inlower.rs,wave.rs,bitcode.rsandstructure.rs, using the same Fx stepstructurealready 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.rsbench_translate, theiostage reuses the timer started beforeresource::track, soioreports resource + io. Addlet n = std::time::Instant::now();beforecrate::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, sohashandFxneed to be public.CI:
checkpassing.Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by borosf on 2026-11-25T17:15:48Z.
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
Imported from Marvisak/VIctory. Originally posted by borosf on 2026-11-26T06:59:39Z.
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.Imported from Marvisak/VIctory. Originally posted by borosf on 2026-11-26T13:53:50Z.
The last open point is fixed at
a19546d:let n = std::time::Instant::now();now starts theiostage beforecrate::io::raise, soiono longer reports resource + io — exactly as asked. Theresourcestage 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 warningsclean.cargo test -p victory-shader --lib --locked -- --test-threads=1 emit::translate_bench→ the bench test passes.rustfmt --edition 2024 --checkon the touched file: one hunk, at line 66, which is the file's own pre-existing unformattedassert!— the same single hunk before and after this commit (checked against a stashed baseline), so nothing new. This tree is deliberately notcargo fmtclean.Imported from Marvisak/VIctory. Originally posted by borosf on 2026-11-27T10:52:09Z.
The one item from the triage is already in, on the head that has moved since it ran:
839ca90->a19546d2, commit "Shaders: the io stage's timer starts before io::raise".bench_translatenow starts a fresh timer beforecrate::io::raise, soiono longer reportsresource+io:Nothing else is outstanding from the earlier note, the
pub(crate)request is withdrawn, CI is green ona19546d2and the branch merges cleanly with currentmain. A re-triage against the current head would show that.Imported from Marvisak/VIctory. Originally posted by borosf on 2026-11-27T11:22:42Z.
Re-triage request: the single
needs-workitem is fixed at heada19546d2, and nothing has been pushed since.crates/victory-gpu/src/bin/translate_bench.rs:93now reads the clock beforeio::raise, so the time it reports is the work's and not the raise's. Everything else the triage liked is unchanged: the benchmark still drives the same translate path and prints the same columns.Local verification on Windows 11 x64 (Intel Arc B580):
cargo test -p victory-gpu --lib translate:: --lockedpasses,cargo clippy -p victory-gpu --all-targets -- -D warningsclean,cargo xtask policy191 files ok.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.