Shaders: build Halves def/phi table lazily as a compact Vec<Def> in io::raise #2784

Open
github-bot wants to merge 1 commit from github-bot/gh-2784 into main AGit
Owner

@⁠RVZO6 on GitHub · 2026-11-25 20:23 UTC · original
RVZO6:rvzo/io-lazy-defs → main · +186 −65 · 1 files · 1 commits · open

Claimed in #1633: #1633

Summary

io::raise in crates/victory-shader/src/io.rs (+186/-65, including test and benchmark) previously built two full-program SipHash HashMaps (defs and phis) unconditionally on every shader, even though Halves is only ever used on pixel-shader v_interp_p2_f32 / v_interp_p2_f16 instructions (100% wasted work on every vertex, compute, and mesh shader, and on pixel shaders without v_interp_p2_*).

Changes (100% identical Io output):

  • Build a single compact Vec<Def> (enum Def { None, Phi(u32, u32), Inst(u32, u32) }) lazily inside Halves on the first v_interp_p2_* instruction.
  • Move inputs directly into Io without cloning, passing &io.inputs to barycentric_of.

Measured on 13f91ca (--release io::tests::bench_io_raise, median of 3×200 runs, 4,000 instructions)

Workload Before (13f91ca) After Speedup
Compute shader (no v_interp_p2_*) 180.0 µs/run 7.9 µs/run 22.8× (-95.6%)
Pixel shader (16 v_interp_p1/p2 pairs) 195.2 µs/run 44.6 µs/run 4.38× (-77.2%)

Not a duplicate of

  • Checked open PRs and #1633; no open PR or claim optimizes Halves / defs+phis construction in io.rs.

Verification

  • Verified on windows-latest MSVC + WARP SM 6.6 CI (both clippy -D warnings profiles, xtask policy 6/6, victory-shader 272/272 including new halves_defs_are_lazy_and_match_phi_and_inst_defs): https://github.com/RVZO6/VIctory/actions/runs/45693633259
  • Not run: the title; any hardware GPU.

AI-assisted: T3 Code (Antigravity, gemini-4-neon)

**@⁠RVZO6** on GitHub · 2026-11-25 20:23 UTC · [original](https://github.com/Marvisak/VIctory/pull/2784) `RVZO6:rvzo/io-lazy-defs` → `main` · +186 −65 · 1 files · 1 commits · open Claimed in #1633: https://git.gtahub.st/github/Marvisak--VIctory/issues/1633 ### Summary `io::raise` in `crates/victory-shader/src/io.rs` (`+186/-65`, including test and benchmark) previously built two full-program SipHash `HashMap`s (`defs` and `phis`) unconditionally on every shader, even though `Halves` is only ever used on pixel-shader `v_interp_p2_f32` / `v_interp_p2_f16` instructions (100% wasted work on every vertex, compute, and mesh shader, and on pixel shaders without `v_interp_p2_*`). Changes (100% identical `Io` output): - Build a single compact `Vec<Def>` (`enum Def { None, Phi(u32, u32), Inst(u32, u32) }`) lazily inside `Halves` on the first `v_interp_p2_*` instruction. - Move `inputs` directly into `Io` without cloning, passing `&io.inputs` to `barycentric_of`. ### Measured on `13f91ca` (`--release io::tests::bench_io_raise`, median of 3×200 runs, 4,000 instructions) | Workload | Before (`13f91ca`) | After | Speedup | |---|---:|---:|---:| | Compute shader (no `v_interp_p2_*`) | `180.0 µs/run` | `7.9 µs/run` | **22.8× (-95.6%)** | | Pixel shader (16 `v_interp_p1/p2` pairs) | `195.2 µs/run` | `44.6 µs/run` | **4.38× (-77.2%)** | ### Not a duplicate of - Checked open PRs and #1633; no open PR or claim optimizes `Halves` / `defs`+`phis` construction in `io.rs`. ### Verification - Verified on `windows-latest` MSVC + WARP SM 6.6 CI (both clippy `-D warnings` profiles, `xtask` policy 6/6, `victory-shader` 272/272 including new `halves_defs_are_lazy_and_match_phi_and_inst_defs`): https://github.com/RVZO6/VIctory/actions/runs/45693633259 - **Not run:** the title; any hardware GPU. AI-assisted: T3 Code (Antigravity, gemini-4-neon)
Avoid unconditionally building two full-program SipHash HashMaps (defs and
phis) in io::raise when Halves is only used for pixel-shader v_interp_p2_*
instructions. Build a single compact Vec<Def> lazily on the first
v_interp_p2_* instruction instead, and move inputs directly into Io without
cloning.

Measured on 13f91ca (--release io::tests::bench_io_raise, median of 3x200
runs, 4,000 instructions, identical Io output):
- CS (no v_interp_p2_*):          180.0 ->  7.9 us/run (22.8x, -95.6%)
- PS (16 v_interp_p1/p2 pairs):   195.2 -> 44.6 us/run ( 4.4x, -77.2%)

Assisted-by: T3 Code (Antigravity, gemini-4-neon)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:14:08 +00:00
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-25 20:40 UTC · original

Lazy Halves construction removes the upfront defs+phis HashMaps from every io::raise call - a real win since most programs never query halves at all. Moving them behind a build-on-first-use keeps the lookup semantics identical.

**@⁠kotekompotek** on GitHub · 2026-11-25 20:40 UTC · [original](https://github.com/Marvisak/VIctory/pull/2784#issuecomment-7174032853) Lazy Halves construction removes the upfront defs+phis HashMaps from every io::raise call - a real win since most programs never query halves at all. Moving them behind a build-on-first-use keeps the lookup semantics identical.
Author
Owner

@⁠oni-swr on GitHub · 2026-11-25 20:57 UTC · original

Independent WARP/CPU verification of head 09c4783f3bab56bc3af74fd4adf8d5c0d132cd5f merged cleanly onto origin/main 13f91caee25f2fdf2c062be5f7a27f058e51cbca.

Environment: Windows 11 x64, WARP/CPU only (VICTORY_WARP=1, VICTORY_D3D12_WARP=1), no physical GPU, no game files; Windows SDK 10.0.26100.0 x64 dxil.dll 1.8.2502.11.

Tests (cargo test --no-fail-fast): victory-shader: 268 passed, 3 failed, 4 ignored (baseline 267 passed, 3 failed, 3 ignored; +1 new test, +1 ignored benchmark). victory-shader baseline on origin/main: 267 passed, 3 failed, 3 ignored; the 3 failures (synthetic_tests::a_mask_joined_with_data_at_a_uniform_loop_is_its_number, gathers_at_a_level_match_the_hardware, permutes_read_the_lane_named_and_zero_from_lanes_left_out) fail identically on origin/main under WARP, so they are not caused by this PR.

Negative control: mapping phis to Def::Inst in ensure_defs makes halves_defs_are_lazy_and_match_phi_and_inst_defs fail; restored afterwards. The existing interpolation tests (7) still pass.

Clippy: cargo clippy -p <affected crates> --all-targets -- -D warnings clean (exit 0).
fmt: cargo fmt --check is not clean on origin/main itself (891 diff hunks across many files); this PR: 894 hunks (+3 vs main, in the touched file).

Review: The dense Vec<Def> is equivalent to the two HashMaps (SSA values have one definition) and out-of-range ids resolve to Def::None, as the old map lookups missed; behaviour is preserved. Diff contains no game files, dumps, shader names or retail hashes.

AI disclosure: this verification was done by Claude Code (Claude Sonnet 5.5).

**@⁠oni-swr** on GitHub · 2026-11-25 20:57 UTC · [original](https://github.com/Marvisak/VIctory/pull/2784#issuecomment-7174416914) Independent WARP/CPU verification of head `09c4783f3bab56bc3af74fd4adf8d5c0d132cd5f` merged cleanly onto `origin/main` `13f91caee25f2fdf2c062be5f7a27f058e51cbca`. **Environment:** Windows 11 x64, WARP/CPU only (`VICTORY_WARP=1`, `VICTORY_D3D12_WARP=1`), no physical GPU, no game files; Windows SDK 10.0.26100.0 x64 `dxil.dll` 1.8.2502.11. **Tests** (`cargo test --no-fail-fast`): victory-shader: 268 passed, 3 failed, 4 ignored (baseline 267 passed, 3 failed, 3 ignored; +1 new test, +1 ignored benchmark). victory-shader baseline on `origin/main`: 267 passed, 3 failed, 3 ignored; the 3 failures (`synthetic_tests::a_mask_joined_with_data_at_a_uniform_loop_is_its_number`, `gathers_at_a_level_match_the_hardware`, `permutes_read_the_lane_named_and_zero_from_lanes_left_out`) fail identically on `origin/main` under WARP, so they are not caused by this PR. **Negative control:** mapping phis to `Def::Inst` in `ensure_defs` makes `halves_defs_are_lazy_and_match_phi_and_inst_defs` fail; restored afterwards. The existing interpolation tests (7) still pass. **Clippy:** `cargo clippy -p <affected crates> --all-targets -- -D warnings` clean (exit 0). **fmt:** `cargo fmt --check` is not clean on `origin/main` itself (891 diff hunks across many files); this PR: 894 hunks (+3 vs main, in the touched file). **Review:** The dense `Vec<Def>` is equivalent to the two HashMaps (SSA values have one definition) and out-of-range ids resolve to `Def::None`, as the old map lookups missed; behaviour is preserved. Diff contains no game files, dumps, shader names or retail hashes. AI disclosure: this verification was done by Claude Code (Claude Sonnet 5.5).
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-25 21:13 UTC · original

Reviewed and benchmarked 09c4783f on Windows 11 (RTX 5090 + WARP + Windows SDK 10.0.26100.0 dxil.dll) against main (13f91ca).

Code review

  • Replacing the two unconditionally allocated SipHash HashMaps with a lazily constructed compact Vec<Def> (ensure_defs() only on v_interp_p2_f32/v_interp_p2_f16 pair() calls) and moving inputs directly into Io is cleanly equivalent: out-of-range / input IDs return Def::None via .get(), matching prior defs.get() == None && phis.get() == None.

Verification & same-machine --release benchmark (rustc 1.98.1 MSVC)

  • io::tests: 5/5 passed (including halves_defs_are_lazy_and_match_phi_and_inst_defs); WARP + dxil.dll full victory-shader --features host: 268 passed, 0 failed (skipping only the 3 hardware-only synthetic_tests); RTX 5090 + dxil.dll: 255 passed, 0 failed (0 regressions).
  • cargo clippy --locked -p victory-shader --all-targets -- -D warnings (default & --features host): 0 warnings; cargo xtask policy: 184 files ok.
  • io::tests::bench_io_raise (--release, 3-run median × 200 iters, 4,000 insts, vs 13f91ca):
    • cs (no v_interp_p2_*): 198.3 µs/run -> 3.5 µs/run (56.7× / -98.2%)
    • ps_16interp (16 interp pairs): 204.7 µs/run -> 13.3 µs/run (15.4× / -93.5%)
  • Clean git merge-tree against 13f91ca, #2664, and the full 4-way merge #2784 + #2785 + #2786 + #2787.
**@⁠fuzeofficlal** on GitHub · 2026-11-25 21:13 UTC · [original](https://github.com/Marvisak/VIctory/pull/2784#issuecomment-7174774507) Reviewed and benchmarked `09c4783f` on Windows 11 (RTX 5090 + WARP + Windows SDK `10.0.26100.0` `dxil.dll`) against `main` (`13f91ca`). ### Code review - Replacing the two unconditionally allocated SipHash `HashMap`s with a lazily constructed compact `Vec<Def>` (`ensure_defs()` only on `v_interp_p2_f32`/`v_interp_p2_f16` `pair()` calls) and moving `inputs` directly into `Io` is cleanly equivalent: out-of-range / input IDs return `Def::None` via `.get()`, matching prior `defs.get() == None && phis.get() == None`. ### Verification & same-machine `--release` benchmark (`rustc 1.98.1` MSVC) - `io::tests`: **5/5 passed** (including `halves_defs_are_lazy_and_match_phi_and_inst_defs`); WARP + `dxil.dll` full `victory-shader --features host`: **268 passed, 0 failed** (skipping only the 3 hardware-only `synthetic_tests`); RTX 5090 + `dxil.dll`: **255 passed, 0 failed** (0 regressions). - `cargo clippy --locked -p victory-shader --all-targets -- -D warnings` (default & `--features host`): **0 warnings**; `cargo xtask policy`: **184 files ok**. - `io::tests::bench_io_raise` (`--release`, 3-run median × 200 iters, 4,000 insts, vs `13f91ca`): - `cs` (no `v_interp_p2_*`): `198.3 µs/run` -> **`3.5 µs/run`** (**56.7× / -98.2%**) - `ps_16interp` (16 interp pairs): `204.7 µs/run` -> **`13.3 µs/run`** (**15.4× / -93.5%**) - Clean `git merge-tree` against `13f91ca`, `#2664`, and the full 4-way merge `#2784 + #2785 + #2786 + #2787`.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 23:24 UTC · original

Automated triage for the maintainers.

In io::raise (crates/victory-shader/src/io.rs), the two whole-program defs/phis HashMaps were built for every shader. They are replaced by a dense Vec<Def> inside Halves, built only on the first v_interp_p2_*, and inputs is moved into Io instead of cloned. I compared Halves::joined and Halves::sites with the old lookups: each SSA value has one definition, and an unknown id resolves to Def::None just as a missing map entry did, so the output is the same. The gain is per-shader translation time (about 0.2 ms each on a large synthetic program). A maintainer may want the ignored bench_io_raise test, which only prints timings, left out. CI passes.

This is a recommendation for a maintainer to look, not an approval.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 23:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/2784#issuecomment-7177523347) <!-- victory-triage v1 head=09c4783f3bab56bc3af74fd4adf8d5c0d132cd5f verdict=merge-candidate at=2026-11-25T23:24:36Z --> Automated triage for the maintainers. In `io::raise` (`crates/victory-shader/src/io.rs`), the two whole-program `defs`/`phis` HashMaps were built for every shader. They are replaced by a dense `Vec<Def>` inside `Halves`, built only on the first `v_interp_p2_*`, and `inputs` is moved into `Io` instead of cloned. I compared `Halves::joined` and `Halves::sites` with the old lookups: each SSA value has one definition, and an unknown id resolves to `Def::None` just as a missing map entry did, so the output is the same. The gain is per-shader translation time (about 0.2 ms each on a large synthetic program). A maintainer may want the ignored `bench_io_raise` test, which only prints timings, left out. CI passes. This is a recommendation for a maintainer to look, not an approval. --- _Generated by [Claude Code](https://claude.ai/code)_
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/2784/head:github-bot/gh-2784'
git switch 'github-bot/gh-2784'

Merge

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