victory-shader: build the per-instruction read/write lists once (ir::build -13%) #1033

Manually merged
github merged 1 commit from gh-pr/1033/head into gh-pr/1033/base 2026-11-26 04:17:45 +00:00
Owner

@⁠pes7 on GitHub · 2026-11-24 15:14 UTC · original
pes7:perf/ir-pairs → main · +25 −25 · 1 files · 1 commits · merged 2026-11-25 21:49 UTC

ir::build allocates four times per instruction for lists of two to four registers. This builds them once, for 13% off the SSA pass and 4.7% off a translation, with byte-identical output.

effects() collects each instruction's register lists as Vec<Reg> - two allocations - and the caller immediately maps them into Vec<(Reg, Value)>, the shape the IR wants - two more allocations - and frees the first pair. On a 26k-instruction program that is ~100k allocations and ~50k copies that nothing reads.

What changes

effects(), add_regs(), the mask/indexed helpers and the branch arms push (Reg, NONE) directly, the placeholder the SSA pass fills in. Two allocations per instruction instead of four. Inst, Phi and everything downstream are untouched; the placeholder value is the same NONE it was mapped to a line later.

Measured

The bench is the one added in #1002 (crates/victory-shader/src/emit/bench_tests.rs, synthetic GFX10 compute programs, no game data). Ten interleaved rounds per arm, best of ten, nanoseconds per instruction:

instructions ir::build before after ratio
256 308 269 0.873
1 024 375 324 0.864
4 096 407 340 0.835
16 384 402 353 0.878
instructions whole translation before after ratio
256 898 872 0.971
1 024 898 825 0.919
4 096 951 875 0.920
16 384 956 912 0.954

gfx10::decode (105-113 ns), structure, resource, io and lower are unchanged, which is the check that the change did what it claims and nothing else.

The bench lives in #1002 and the numbers above were measured on top of it, but this branch is only the ir.rs change - one file, +25/-25 - and applies to main on its own; nothing here depends on #1002 landing first.

Correctness

  • DXIL byte-identical at all four sizes (FNV-1a over the emitted bytes, printed by the bench).
  • cargo test --workspace --locked: 342 passed, 0 failed, 7 ignored.
  • Both CI clippy configurations with -D warnings; cargo xtask policy: 173 files ok.

No game data used.

**@⁠pes7** on GitHub · 2026-11-24 15:14 UTC · [original](https://github.com/Marvisak/VIctory/pull/1033) `pes7:perf/ir-pairs` → `main` · +25 −25 · 1 files · 1 commits · merged 2026-11-25 21:49 UTC **`ir::build` allocates four times per instruction for lists of two to four registers.** This builds them once, for 13% off the SSA pass and 4.7% off a translation, with byte-identical output. `effects()` collects each instruction's register lists as `Vec<Reg>` - two allocations - and the caller immediately maps them into `Vec<(Reg, Value)>`, the shape the IR wants - two more allocations - and frees the first pair. On a 26k-instruction program that is ~100k allocations and ~50k copies that nothing reads. ## What changes `effects()`, `add_regs()`, the `mask`/`indexed` helpers and the branch arms push `(Reg, NONE)` directly, the placeholder the SSA pass fills in. Two allocations per instruction instead of four. `Inst`, `Phi` and everything downstream are untouched; the placeholder value is the same `NONE` it was mapped to a line later. ## Measured The bench is the one added in #1002 (`crates/victory-shader/src/emit/bench_tests.rs`, synthetic GFX10 compute programs, no game data). Ten interleaved rounds per arm, best of ten, nanoseconds per instruction: | instructions | `ir::build` before | after | ratio | |---:|---:|---:|---:| | 256 | 308 | 269 | **0.873** | | 1 024 | 375 | 324 | **0.864** | | 4 096 | 407 | 340 | **0.835** | | 16 384 | 402 | 353 | **0.878** | | instructions | whole translation before | after | ratio | |---:|---:|---:|---:| | 256 | 898 | 872 | **0.971** | | 1 024 | 898 | 825 | **0.919** | | 4 096 | 951 | 875 | **0.920** | | 16 384 | 956 | 912 | **0.954** | `gfx10::decode` (105-113 ns), `structure`, `resource`, `io` and `lower` are unchanged, which is the check that the change did what it claims and nothing else. The bench lives in #1002 and the numbers above were measured on top of it, but this branch is only the `ir.rs` change - one file, +25/-25 - and applies to `main` on its own; nothing here depends on #1002 landing first. ## Correctness - **DXIL byte-identical** at all four sizes (FNV-1a over the emitted bytes, printed by the bench). - `cargo test --workspace --locked`: 342 passed, 0 failed, 7 ignored. - Both CI clippy configurations with `-D warnings`; `cargo xtask policy`: 173 files ok. No game data used.
ir::build fills every instruction's register lists twice. `effects()`
collects `Vec<Reg>` (two allocations), and the caller immediately maps
each one into `Vec<(Reg, Value)>` (two more), freeing the first pair. For
lists that are almost always two to four entries, that is four
allocations and two copies per instruction, on every instruction of every
program.

Have `effects()` and its helpers collect the `(Reg, Value)` pairs
directly, with the placeholder the SSA pass fills in. Two allocations per
instruction instead of four; `Inst` and everything downstream are
unchanged.

Measured with the synthetic bench in #1002 (no game data), ten
interleaved rounds per arm, nanoseconds per instruction, at 256/1k/4k/16k
instructions:

  ir::build   308 -> 269, 375 -> 324, 407 -> 340, 402 -> 353  (0.835-0.878)
  translation 898 -> 872, 898 -> 825, 951 -> 875, 956 -> 912  (0.919-0.971)

gfx10::decode, structure, lower and the rest are unchanged. The emitted
DXIL is byte-identical at all four sizes.

cargo test --workspace --locked: 342 passed, 0 failed, 7 ignored.
Both clippy configurations clean; cargo xtask policy ok.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:17:43 +00:00
github manually merged commit d809fb701a into gh-pr/1033/base 2026-11-26 04:17:45 +00:00
Author
Owner

@⁠Zipettte on GitHub · 2026-11-24 16:30 UTC · original

Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at 94cc038: cargo test -p victory-shader passes, 120 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).

Tested with AI assistance (Claude).

**@⁠Zipettte** on GitHub · 2026-11-24 16:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/1033#issuecomment-7137774415) Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at 94cc038: `cargo test -p victory-shader` passes, 120 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed). _Tested with AI assistance (Claude)._
Author
Owner

@⁠pes7 on GitHub · 2026-11-24 22:03 UTC · original

Rebased onto today's main (70564ae), which conflicts on ir.rs: build became build_bounded and effects now takes m0_max: Option<u8> to bound relative moves (v_movrel*). Both survive - the pairs this PR returns are still pairs, and the bound still cuts the range:

let indexed = |op: &Operand, out: &mut Vec<(Reg, Value)>| match *op {
    Operand::Vector { reg, .. } if u16::from(reg) < vgprs => {
        let end = m0_max.map_or(vgprs, |m| vgprs.min(u16::from(reg) + u16::from(m) + 1));
        out.extend((u16::from(reg)..end).map(|r| (Reg::V(r as u8), NONE)));

Head is now 266f671. cargo test -p victory-shader --locked: 209 passed, 0 failed; both clippy configurations with -D warnings pass, as does cargo xtask policy. The diff against this PR is unchanged (+25/-25, one file).

@⁠catminou4 - your approval is still shown on the PR, but the head moved because of the rebase, so re-check if you want the approval to be for this exact tree; the change itself is the same one you reviewed.

**@⁠pes7** on GitHub · 2026-11-24 22:03 UTC · [original](https://github.com/Marvisak/VIctory/pull/1033#issuecomment-7145751728) Rebased onto today's `main` (`70564ae`), which conflicts on `ir.rs`: `build` became `build_bounded` and `effects` now takes `m0_max: Option<u8>` to bound relative moves (`v_movrel*`). Both survive - the pairs this PR returns are still pairs, and the bound still cuts the range: ```rust let indexed = |op: &Operand, out: &mut Vec<(Reg, Value)>| match *op { Operand::Vector { reg, .. } if u16::from(reg) < vgprs => { let end = m0_max.map_or(vgprs, |m| vgprs.min(u16::from(reg) + u16::from(m) + 1)); out.extend((u16::from(reg)..end).map(|r| (Reg::V(r as u8), NONE))); ``` Head is now `266f671`. `cargo test -p victory-shader --locked`: 209 passed, 0 failed; both clippy configurations with `-D warnings` pass, as does `cargo xtask policy`. The diff against this PR is unchanged (+25/-25, one file). @⁠catminou4 - your approval is still shown on the PR, but the head moved because of the rebase, so re-check if you want the approval to be for this exact tree; the change itself is the same one you reviewed.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 01:19 UTC · original · edited 2026-11-25 20:18 UTC

Automated triage for the maintainers.

Merge candidate. The head (d809fb7) has not changed since the last review and still merges cleanly. effects() and add_regs() in crates/victory-shader/src/ir.rs push (Reg, NONE) pairs directly, so build_bounded no longer converts each Vec<Reg> through the unset closure. The resulting IR is the same: NONE is the placeholder the closure added, the seen.contains dedup and the m0_max-bounded indexed range are unchanged, and both functions are private to this file.

Reply to the author: thanks for the corpus measurement (-3.2% wall time, output identical on all 26,084 programs). It confirms the earlier reading, so the verdict stays. #1623 is a separate decoder change and does not overlap.

CI: passing.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 01:19 UTC · [original](https://github.com/Marvisak/VIctory/pull/1033#issuecomment-7149427448) · edited 2026-11-25 20:18 UTC <!-- victory-triage v1 head=d809fb701ab45f8c8dc7c808a39019fa141bf875 verdict=merge-candidate at=2026-11-25T15:05:00Z --> Automated triage for the maintainers. **Merge candidate.** The head (`d809fb7`) has not changed since the last review and still merges cleanly. `effects()` and `add_regs()` in `crates/victory-shader/src/ir.rs` push `(Reg, NONE)` pairs directly, so `build_bounded` no longer converts each `Vec<Reg>` through the `unset` closure. The resulting IR is the same: `NONE` is the placeholder the closure added, the `seen.contains` dedup and the `m0_max`-bounded indexed range are unchanged, and both functions are private to this file. Reply to the author: thanks for the corpus measurement (-3.2% wall time, output identical on all 26,084 programs). It confirms the earlier reading, so the verdict stays. #1623 is a separate decoder change and does not overlap. CI: passing. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠pes7 on GitHub · 2026-11-25 16:26 UTC · original

Real corpus, same method as the note on #1002: the Xbox build's shaders.rpf - 26 084 programs, 40 601 701 IR instructions - victory translate <shaders.rpf> --list, three binaries running at the same time on one thread each (--jobs 1) on a 32-core machine, so they share identical conditions and the control is common:

binary wall against main
main 940d32f 600 s -
this PR d809fb7 581 s -3.2%
#1623 246c928 593 s -1.2%

So the claim holds on real programs and not only on the bench: -3.2% for the whole translation here, against the -4.7% the PR measured on synthetic programs (a real program is 1 557 instructions on average, so the SSA share is a little smaller there).

The output is identical to main on all 26 084 programs - every count in the summary and every emit:/resources: line matches; only the (e.g. ...) examples differ between runs, because the thread that finishes first supplies the example.

For the record, the same measurement says the earlier Fx-hasher change (#1002) is -0.3%, i.e. neutral, and I have closed it: whatever lower's tables cost on synthetic programs, on this corpus they are not what the translation spends its time on.

**@⁠pes7** on GitHub · 2026-11-25 16:26 UTC · [original](https://github.com/Marvisak/VIctory/pull/1033#issuecomment-7167996802) Real corpus, same method as the note on #1002: the Xbox build's `shaders.rpf` - **26 084 programs, 40 601 701 IR instructions** - `victory translate <shaders.rpf> --list`, three binaries running **at the same time on one thread each** (`--jobs 1`) on a 32-core machine, so they share identical conditions and the control is common: | binary | wall | against `main` | |---|---:|---:| | `main` `940d32f` | 600 s | - | | **this PR** `d809fb7` | **581 s** | **-3.2%** | | #1623 `246c928` | 593 s | -1.2% | So the claim holds on real programs and not only on the bench: -3.2% for the whole translation here, against the -4.7% the PR measured on synthetic programs (a real program is 1 557 instructions on average, so the SSA share is a little smaller there). The output is identical to `main` on all 26 084 programs - every count in the summary and every `emit:`/`resources:` line matches; only the `(e.g. ...)` examples differ between runs, because the thread that finishes first supplies the example. For the record, the same measurement says the earlier Fx-hasher change (#1002) is **-0.3%**, i.e. neutral, and I have closed it: whatever `lower`'s tables cost on synthetic programs, on this corpus they are not what the translation spends its time on.
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!1033
No description provided.