Repository navigation
victory-shader: build the per-instruction read/write lists once (ir::build -13%) - #1033
Conversation
catminou4
left a comment
There was a problem hiding this comment.
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.
…lists once (ir::build -13%) Head 94cc038 (pes7). Merged without conflicts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Rebased onto today's 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 @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. |
`Instruction::words` is a `Vec<u32>` built with `collect()`, so every decoded instruction allocates for the one to five dwords it has and reads them back through a pointer. A counter over the pipeline put that at 1.17 allocations and 149 bytes per instruction in decode - the largest single allocation source there. The longest instruction the decoder produces is an MIMG with its three extra address dwords, five in all, so keep them in `[u32; 5]` with a length byte and return a slice from `words()`. The struct does not grow: `Vec` is 24 bytes, the array and the byte are 24 with padding. A longer instruction is now a clean `Isa` error rather than a silent truncation. Measured standalone against `ffe310e` with the synthetic bench from Marvisak#1002, twelve interleaved rounds per arm, nanoseconds per instruction: decode 48 -> 31, 99 -> 54, 105 -> 82, 104 -> 85 (0.55-0.82) whole 977 -> 934, 970 -> 921, 1001 -> 981, 1046 -> 1033 (0.949-0.988) The emitted DXIL is byte-identical at all four sizes. Honest about the shape: decode is 18-45% faster, the whole translation is 1-5%, and at 16k instructions that gap is inside this machine's run-to-run spread. Applied on top of Marvisak#1002 + Marvisak#1033 + Marvisak#1180 the same change measured 0.929-0.957 of the translation. cargo test --workspace --locked: 342 passed, 0 failed, 7 ignored. Both clippy configurations with -D warnings; cargo xtask policy.
|
Automated triage for the maintainers. Merge candidate. The head ( 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 |
…rite lists once (ir::build -13%)
DenRakEiw
left a comment
There was a problem hiding this comment.
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).
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 Marvisak#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.
|
Real corpus, same method as the note on #1002: the Xbox build's
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 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 |
…rite lists once (ir::build -13%)
ir::buildallocates 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 asVec<Reg>- two allocations - and the caller immediately maps them intoVec<(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(), themask/indexedhelpers and the branch arms push(Reg, NONE)directly, the placeholder the SSA pass fills in. Two allocations per instruction instead of four.Inst,Phiand everything downstream are untouched; the placeholder value is the sameNONEit 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:ir::buildbeforegfx10::decode(105-113 ns),structure,resource,ioandlowerare 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.rschange - one file, +25/-25 - and applies tomainon its own; nothing here depends on #1002 landing first.Correctness
cargo test --workspace --locked: 342 passed, 0 failed, 7 ignored.-D warnings;cargo xtask policy: 173 files ok.No game data used.