Shaders: encoding-gated fast scans, zero-alloc wave::simulate, and dense range::relative_bounds #2941

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

@⁠RVZO6 on GitHub · 2026-11-26 00:57 UTC · original
RVZO6:rvzo/wave-range-fast → main · +530 −161 · 3 files · 1 commits · open

Summary

Eliminates per-instruction opcode name scans and per-VALU Vec<Sym> heap allocations in whole-wave section detection/simulation and relative-move range analysis (100% identical outputs):

  1. emit/wave.rs — sections(): gates detection on inst.machine.encoding == Encoding::Sop1 and the 4 s_{or,nand}_saveexec_b{32,64} opcodes (0x25, 0x3D, 0x29, 0x41) instead of string-matching inst.name() on every instruction of every block across all shaders.
  2. emit/wave.rs — simulate(): replaces per-operand and per-result Vec<Sym> clones (~6 heap allocations / ~9 KB per VALU op in wave64) with borrowed Lanes<'a>, stack [Sym; 64] buffers, a flat Vec<Sym> arena with Entry::Same(Sym) fast path for uniform results, and FxMap (preserving f3578e3 f16 inline float constants).
  3. range.rs — relative() & relative_bounds(): gates relative() on Encoding::Vop1 / VOP3-encoded VOP1 (0x180..0x200) opcodes 0x42..=0x44 | 0x48 | 0x68; replaces HashMap/HashSet (defs, memo, busy) with dense Vec tables indexed by Value.0; replaces heap Vecs in edge_hi() and op_hi() with stack arrays.

Measured (--release bench_wave_sections_and_simulate, median of 3 runs on 63bcca4)

Workload Before (63bcca4) After Speedup
simulate (20 wave64 sections) 286.10 µs 183.26 µs 1.56× (-35.9%)
scan (2,000 plain insts, no sections) 1.53 µs 1.28 µs 1.20× (-16.3%)

Verification

  • Added exhaustive opcode-equivalence unit tests (emit::wave::tests::saveexec_opcode_fast_path_matches_names and range::tests::relative_opcode_fast_path_matches_names).
  • Verified green on windows-latest MSVC + WARP SM 6.6 CI (clippy, xtask policy, full workspace tests): https://github.com/RVZO6/VIctory/actions/runs/45730729035

Not run: the title; any hardware GPU.
AI-assisted: T3 Code (Antigravity, gemini-4-neon).

**@⁠RVZO6** on GitHub · 2026-11-26 00:57 UTC · [original](https://github.com/Marvisak/VIctory/pull/2941) `RVZO6:rvzo/wave-range-fast` → `main` · +530 −161 · 3 files · 1 commits · open ### Summary Eliminates per-instruction opcode name scans and per-VALU `Vec<Sym>` heap allocations in whole-wave section detection/simulation and relative-move range analysis (100% identical outputs): 1. **`emit/wave.rs` — `sections()`**: gates detection on `inst.machine.encoding == Encoding::Sop1` and the 4 `s_{or,nand}_saveexec_b{32,64}` opcodes (`0x25, 0x3D, 0x29, 0x41`) instead of string-matching `inst.name()` on every instruction of every block across all shaders. 2. **`emit/wave.rs` — `simulate()`**: replaces per-operand and per-result `Vec<Sym>` clones (~6 heap allocations / ~9 KB per VALU op in wave64) with borrowed `Lanes<'a>`, stack `[Sym; 64]` buffers, a flat `Vec<Sym>` arena with `Entry::Same(Sym)` fast path for uniform results, and `FxMap` (preserving `f3578e3` f16 inline float constants). 3. **`range.rs` — `relative()` & `relative_bounds()`**: gates `relative()` on `Encoding::Vop1` / VOP3-encoded VOP1 (`0x180..0x200`) opcodes `0x42..=0x44 | 0x48 | 0x68`; replaces `HashMap`/`HashSet` (`defs`, `memo`, `busy`) with dense `Vec` tables indexed by `Value.0`; replaces heap `Vec`s in `edge_hi()` and `op_hi()` with stack arrays. ### Measured (`--release bench_wave_sections_and_simulate`, median of 3 runs on `63bcca4`) | Workload | Before (`63bcca4`) | After | Speedup | |---|---:|---:|---:| | `simulate` (20 wave64 sections) | 286.10 µs | **183.26 µs** | **1.56× (-35.9%)** | | `scan` (2,000 plain insts, no sections) | 1.53 µs | **1.28 µs** | **1.20× (-16.3%)** | ### Verification - Added exhaustive opcode-equivalence unit tests (`emit::wave::tests::saveexec_opcode_fast_path_matches_names` and `range::tests::relative_opcode_fast_path_matches_names`). - Verified green on `windows-latest` MSVC + WARP SM 6.6 CI (clippy, `xtask policy`, full workspace tests): https://github.com/RVZO6/VIctory/actions/runs/45730729035 **Not run:** the title; any hardware GPU. AI-assisted: T3 Code (Antigravity, gemini-4-neon).
Eliminate per-instruction string scans and per-VALU heap allocations in
whole-wave section detection/simulation and relative-move range analysis:
- emit/wave.rs: gate sections() on Encoding::Sop1 + saveexec opcodes
  (0x25, 0x3D, 0x29, 0x41) instead of running inst.name() string matches
  on every instruction of every block; replace per-VALU Vec<Sym> clones
  in simulate() with borrowed Lanes<'a>, stack [Sym; 64] scratch buffers,
  flat arena + Entry::Same fast path, and FxHash maps.
- range.rs: gate relative() on Encoding::Vop1 / VOP3-encoded VOP1 opcodes
  (0x42..=0x44, 0x48, 0x68); replace HashMap/HashSet in relative_bounds()
  with dense Vec tables indexed by Value.0 and stack buffers in edge_hi()
  and op_hi().

Measured (--release bench_wave_sections_and_simulate, median of 3 runs):
- simulate (20 wave64 sections): 286.10 -> 183.26 us/run (1.56x, -35.9%)
- scan (2,000 plain insts):        1.53 ->   1.28 us/run (1.20x, -16.3%)

Assisted-by: T3 Code (Antigravity, gemini-4-neon)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:18:05 +00:00
github-bot force-pushed github-bot/gh-2941 from 33ba3c643d to c58177e08e 2026-11-26 06:30:37 +00:00 Compare
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 01:08 UTC · original

Code review and RTX 5090 + WARP + DXIL + release benchmark verification at head 33ba3c643d0a merged cleanly onto main (63bcca43c6a0; emit/lower.rs untouched):

  • Code review (wave.rs, range.rs):
    • Both encoding-gated opcode matchers (saveexec_all_const on Encoding::Sop1 and relative_opcode on Encoding::Vop1/Encoding::Vop3 0x180..0x200) are exhaustively checked against the decoder name tables (saveexec_opcode_fast_path_matches_names, relative_opcode_fast_path_matches_names).
    • Zero-alloc wave::simulate (Entry::{Same, Slab} + single arena + stack buffers + FxMap) preserves v_add_f16 inline constant handling and partial-write fallback to old.get(l).
    • Dense Vec range::relative_bounds guards out-of-range value indices (idx >= self.defs.len() -> u32::MAX, .get(c.0 as usize).copied().flatten(), src.len() > 3 -> u32::MAX).
  • Verified (Windows 11, NVIDIA RTX 5090 + WARP, dxil.dll 10.0.26100.0, VICTORY_D3D12_DEBUG=1, Rust 1.98.1):
    • cargo xtask policy: 191 files ok; cargo clippy (default + --all-features): 0 warnings
    • range:: wave:: structure::tests emit::lower::tests: 58/58 passed (2 ignored) on both RTX 5090 and WARP
    • --release bench_wave_sections_and_simulate: scan(2000 insts) = 0.59 us, simulate(20 wave64 sections) = 90.57 us.

LGTM.

**@⁠fuzeofficlal** on GitHub · 2026-11-26 01:08 UTC · [original](https://github.com/Marvisak/VIctory/pull/2941#issuecomment-7179470869) Code review and RTX 5090 + WARP + DXIL + release benchmark verification at head `33ba3c643d0a` merged cleanly onto `main` (`63bcca43c6a0`; `emit/lower.rs` untouched): - **Code review (`wave.rs`, `range.rs`)**: - Both encoding-gated opcode matchers (`saveexec_all_const` on `Encoding::Sop1` and `relative_opcode` on `Encoding::Vop1`/`Encoding::Vop3` `0x180..0x200`) are exhaustively checked against the decoder name tables (`saveexec_opcode_fast_path_matches_names`, `relative_opcode_fast_path_matches_names`). - Zero-alloc `wave::simulate` (`Entry::{Same, Slab}` + single `arena` + stack buffers + `FxMap`) preserves `v_add_f16` inline constant handling and partial-write fallback to `old.get(l)`. - Dense `Vec` `range::relative_bounds` guards out-of-range value indices (`idx >= self.defs.len() -> u32::MAX`, `.get(c.0 as usize).copied().flatten()`, `src.len() > 3 -> u32::MAX`). - **Verified (Windows 11, NVIDIA RTX 5090 + WARP, `dxil.dll` 10.0.26100.0, `VICTORY_D3D12_DEBUG=1`, Rust 1.98.1)**: - `cargo xtask policy`: `191 files ok`; `cargo clippy` (default + `--all-features`): 0 warnings - `range:: wave:: structure::tests emit::lower::tests`: **58/58 passed** (2 ignored) on both RTX 5090 and WARP - `--release` `bench_wave_sections_and_simulate`: `scan(2000 insts) = 0.59 us`, `simulate(20 wave64 sections) = 90.57 us`. LGTM.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-26 04:27 UTC · original · edited 2026-11-26 07:23 UTC

Automated triage for the maintainers.

Merge candidate. Both requested changes are in c58177e:

  • emit/wave.rs now uses the shared structure::Fx.
  • The saveexec and v_movrel*/v_swaprel opcode constants are derived at compile time from gfx10::opcodes::{SOP1, VOP1}, so they cannot drift.

I re-read the rewritten simulate: Entry::Same maps to the same Shape that per_lane gives for uniform lanes, partial writes still take old, and v_readlane keeps its out-of-range guard. The outputs look unchanged. The gain is in translation time, not per frame, which is for the maintainer to weigh against the size of the rewrite.

CI: passing.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-26 04:27 UTC · [original](https://github.com/Marvisak/VIctory/pull/2941#issuecomment-7182616987) · edited 2026-11-26 07:23 UTC <!-- victory-triage v1 head=c58177e08e7bc60d29e4c1cf72ed78a7e6ffd3f0 verdict=merge-candidate at=2026-11-26T07:23:56Z --> Automated triage for the maintainers. **Merge candidate.** Both requested changes are in `c58177e`: - `emit/wave.rs` now uses the shared `structure::Fx`. - The saveexec and `v_movrel*`/`v_swaprel` opcode constants are derived at compile time from `gfx10::opcodes::{SOP1, VOP1}`, so they cannot drift. I re-read the rewritten `simulate`: `Entry::Same` maps to the same `Shape` that `per_lane` gives for uniform lanes, partial writes still take `old`, and `v_readlane` keeps its out-of-range guard. The outputs look unchanged. The gain is in translation time, not per frame, which is for the maintainer to weigh against the size of the rewrite. CI: passing. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠RVZO6 on GitHub · 2026-11-26 05:42 UTC · original

Addressed both code-cleanliness items in c58177e:

  • Shared pub(crate) struct Fx from structure.rs in emit/wave.rs instead of duplicating the hasher.
  • Derived the saveexec_all_const (SOP1) and relative_opcode (VOP1) constants at compile time directly from crate::gfx10::opcodes::{SOP1, VOP1} so they cannot drift from the opcode tables.

Verified green on windows-latest MSVC + WARP SM 6.6 CI (clippy default + --all-features, xtask policy, full workspace tests): https://github.com/RVZO6/VIctory/actions/runs/45762903919

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

**@⁠RVZO6** on GitHub · 2026-11-26 05:42 UTC · [original](https://github.com/Marvisak/VIctory/pull/2941#issuecomment-7183740045) Addressed both code-cleanliness items in `c58177e`: - Shared `pub(crate) struct Fx` from `structure.rs` in `emit/wave.rs` instead of duplicating the hasher. - Derived the `saveexec_all_const` (`SOP1`) and `relative_opcode` (`VOP1`) constants at compile time directly from `crate::gfx10::opcodes::{SOP1, VOP1}` so they cannot drift from the opcode tables. Verified green on `windows-latest` MSVC + WARP SM 6.6 CI (clippy default + `--all-features`, `xtask policy`, full workspace tests): https://github.com/RVZO6/VIctory/actions/runs/45762903919 AI-assisted: T3 Code (Antigravity, gemini-4-neon)
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 07:48 UTC · original · approved these changes

Tested locally merged onto origin/main (63bcca4) on Windows 11 x64:

  • cargo test -p victory-shader range::: 4 passed, 0 failed (including relative_opcode_fast_path_matches_names).
  • cargo test -p victory-shader wave::: 8 passed, 0 failed (including saveexec_opcode_fast_path_matches_names).
  • cargo test -p victory-shader resource::tests: 35 passed, 0 failed.
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

**@⁠Dukestar69** on GitHub · 2026-11-26 07:48 UTC · [original](https://github.com/Marvisak/VIctory/pull/2941#pullrequestreview-6070247403) · **approved these changes** Tested locally merged onto `origin/main` (`63bcca4`) on Windows 11 x64: - `cargo test -p victory-shader range::`: 4 passed, 0 failed (including `relative_opcode_fast_path_matches_names`). - `cargo test -p victory-shader wave::`: 8 passed, 0 failed (including `saveexec_opcode_fast_path_matches_names`). - `cargo test -p victory-shader resource::tests`: 35 passed, 0 failed. - `cargo clippy -p victory-shader --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 09:48 UTC · original · approved these changes

I checked the encoding gates against the decoder tables, including the VOP3 aliases (SOP1 and VOP1/VOP3 0x180..0x200), and verified git merge-tree against #2942 merges cleanly on structure.rs. The wave::simulate rewrite preserves partial-write merging (old.get(l)), the out-of-range v_readlane_b32 result, v_add_f16 inline float constants, and full-mask reduction recognition, while range::relative_bounds continues to treat missing and out-of-range values as unbounded.

Verified locally on Windows 11 x64 (c58177e0):

  • cargo run --locked -p xtask -- policy: passed (191 files ok)
  • cargo clippy -p victory-shader --all-targets --locked -- -D warnings (default and --all-features): clean
  • cargo test -p victory-shader --lib --locked wave:: / range:: / structure::tests: 8 / 4 / 13 passed, 0 failed (2 ignored benchmarks)

(Minor nit: rustfmt --edition 2024 --check flags three line-wrapping diffs in crates/victory-shader/src/emit/wave.rs at lines 536, 1267, 1347.)

LGTM.

**@⁠fuzeofficlal** on GitHub · 2026-11-26 09:48 UTC · [original](https://github.com/Marvisak/VIctory/pull/2941#pullrequestreview-6071828736) · **approved these changes** I checked the encoding gates against the decoder tables, including the VOP3 aliases (`SOP1` and `VOP1`/`VOP3` `0x180..0x200`), and verified `git merge-tree` against `#2942` merges cleanly on `structure.rs`. The `wave::simulate` rewrite preserves partial-write merging (`old.get(l)`), the out-of-range `v_readlane_b32` result, `v_add_f16` inline float constants, and full-mask reduction recognition, while `range::relative_bounds` continues to treat missing and out-of-range values as unbounded. Verified locally on Windows 11 x64 (`c58177e0`): - `cargo run --locked -p xtask -- policy`: passed (`191 files ok`) - `cargo clippy -p victory-shader --all-targets --locked -- -D warnings` (default and `--all-features`): clean - `cargo test -p victory-shader --lib --locked wave::` / `range::` / `structure::tests`: 8 / 4 / 13 passed, 0 failed (2 ignored benchmarks) (Minor nit: `rustfmt --edition 2024 --check` flags three line-wrapping diffs in `crates/victory-shader/src/emit/wave.rs` at lines 536, 1267, 1347.) LGTM.
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/2941/head:github-bot/gh-2941'
git switch 'github-bot/gh-2941'

Merge

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