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

Open
RVZO6 wants to merge 1 commit from upstream-pr/2941 into main
RVZO6 commented 2026-11-26 00:57:04 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by RVZO6 on 2026-11-26T00:57:04Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:issue:6617025684 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2941). Originally posted by [RVZO6](https://github.com/RVZO6) on 2026-11-26T00:57:04Z. --- ### 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).
fuzeofficlal commented 2026-11-26 02:06:53 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T01:08:19Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7179470869 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2941#issuecomment-7179470869). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T01:08:19Z. --- 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.
Marvisak commented 2026-11-26 05:04:11 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T04:27:48Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7182616987 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2941#issuecomment-7182616987). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-26T04:27:48Z. --- <!-- 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)_
RVZO6 commented 2026-11-26 06:03:46 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by RVZO6 on 2026-11-26T05:42:59Z.


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)

<!-- greyfinch-sync:Marvisak/VIctory:comment:7183740045 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2941#issuecomment-7183740045). Originally posted by [RVZO6](https://github.com/RVZO6) on 2026-11-26T05:42:59Z. --- 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)
Dukestar69 commented 2026-11-26 08:02:42 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T07:48:15Z.

Review: APPROVED


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

<!-- greyfinch-sync:Marvisak/VIctory:review:6070247403 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2941#pullrequestreview-6070247403). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T07:48:15Z. **Review:** APPROVED --- 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).
fuzeofficlal commented 2026-11-26 10:04:35 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T09:48:26Z.

Review: APPROVED


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.

<!-- greyfinch-sync:Marvisak/VIctory:review:6071828736 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2941#pullrequestreview-6071828736). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T09:48:26Z. **Review:** APPROVED --- 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 cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/2941:upstream-pr/2941'
git switch 'upstream-pr/2941'

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.

git switch 'main'
git merge --no-ff 'upstream-pr/2941'
git switch 'upstream-pr/2941'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2941'
git switch 'upstream-pr/2941'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2941'
git switch 'main'
git merge --squash 'upstream-pr/2941'
git switch 'main'
git merge --ff-only 'upstream-pr/2941'
git switch 'main'
git merge 'upstream-pr/2941'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!2939
No description provided.