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

Merged
pes7 merged 1 commit from upstream-pr/1033 into main 2026-11-25 21:49:45 +00:00
pes7 commented 2026-11-24 15:14:12 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by pes7 on 2026-11-24T15:14:12Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6585021397 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1033). Originally posted by [pes7](https://github.com/pes7) on 2026-11-24T15:14:12Z. --- **`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.
catminou4 commented 2026-11-24 17:03:02 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T16:28:57Z.

Review: APPROVED


Pure refactor: effects() now returns (Reg, Value) pairs with NONE placeholders directly instead of Reg vecs + unset closure; the vector rule (VGPR writes auto-added to reads, 'lanes disabled in EXEC keep the old value') is preserved via .cloned(). No behavior change, existing 96 tests cover it. Local verification: macOS arm64, rustc 1.98.1, PR head merged into main ffe310e, cargo test -p <crate> --locked. Shader execution tests (valu_tests/host) are #[cfg(all(test, windows))], so macOS covers lowering/decode/unit tests only. victory-shader: 96 passed, 0 failed.

<!-- greyfinch-sync:Marvisak/VIctory:review:6043262498 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1033#pullrequestreview-6043262498). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T16:28:57Z. **Review:** APPROVED --- Pure refactor: effects() now returns (Reg, Value) pairs with NONE placeholders directly instead of Reg vecs + unset closure; the vector rule (VGPR writes auto-added to reads, 'lanes disabled in EXEC keep the old value') is preserved via .cloned(). No behavior change, existing 96 tests cover it. Local verification: macOS arm64, rustc 1.98.1, PR head merged into main ffe310e, `cargo test -p <crate> --locked`. Shader execution tests (valu_tests/host) are `#[cfg(all(test, windows))]`, so macOS covers lowering/decode/unit tests only. victory-shader: 96 passed, 0 failed.
Zipettte commented 2026-11-24 17:04:32 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Zipettte on 2026-11-24T16:30:31Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7137774415 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1033#issuecomment-7137774415). Originally posted by [Zipettte](https://github.com/Zipettte) on 2026-11-24T16:30:31Z. --- 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)._
pes7 commented 2026-11-24 23:05:44 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by pes7 on 2026-11-24T22:03:47Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7145751728 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1033#issuecomment-7145751728). Originally posted by [pes7](https://github.com/pes7) on 2026-11-24T22:03:47Z. --- 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.
Marvisak commented 2026-11-25 02:05:52 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T01:19:17Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7149427448 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1033#issuecomment-7149427448). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T01:19:17Z. --- <!-- 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)_
DenRakEiw commented 2026-11-25 12:02:12 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T11:54:22Z.

Review: APPROVED


Verified against origin/main (940d32f):

  • Building per-instruction read/write lists in a single pass merges cleanly and passes all IR tests.
  • cargo test -p victory-shader ir::tests: 9/9 passed.
  • cargo clippy -p victory-shader --all-targets -- -D warnings: 0 warnings.
  • cargo xtask policy: 183 files ok.

AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6057121305 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1033#pullrequestreview-6057121305). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-25T11:54:22Z. **Review:** APPROVED --- Verified against `origin/main` (`940d32f`): - Building per-instruction read/write lists in a single pass merges cleanly and passes all IR tests. - `cargo test -p victory-shader ir::tests`: 9/9 passed. - `cargo clippy -p victory-shader --all-targets -- -D warnings`: 0 warnings. - `cargo xtask policy`: 183 files ok. AI-assisted (Gemini 4 Neon).
pes7 commented 2026-11-25 17:05:05 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by pes7 on 2026-11-25T16:26:55Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7167996802 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1033#issuecomment-7167996802). Originally posted by [pes7](https://github.com/pes7) on 2026-11-25T16:26:55Z. --- 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.
upstream-sync closed this pull request 2026-11-25 22:02:47 +00:00
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!1033
No description provided.