gfx10: keep an instruction's words inline instead of in a heap vector (decode -18..-45%, translation -1..-5%) #1622
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1623"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from Marvisak/VIctory. Originally posted by pes7 on 2026-11-24T19:55:17Z.
Every GFX10 instruction owns a heap vector for its one or two dwords. They fit inline - the longest instruction here is five dwords - which takes 18-45% off
decodeand 1-5% off a whole translation, with byte-identical output.Instruction::words: Vec<u32>is built withcollect()in the decoder, so every decoded instruction makes one allocation for one to five words of data, and reads them back through a pointer. #1002's counter put it at 1.17 allocations and 149 bytes per instruction - the single largest allocation source in decode.What changes
words: [u32; Instruction::MAX_WORDS]pluslen: u8, andwords()returns the slice.MAX_WORDSis 5 because that is the longest instruction the decoder produces: an MIMG with its three extra address dwords (2 + ((w >> 1) & 3)); VOP3/VOP3P with a literal is 3, everything else 2 or 1. A longer instruction is now a cleanIsaerror rather than a silent truncation.The struct does not grow:
Vecis 24 bytes,[u32; 5]+u8+ padding is 24.Call sites move from the field to the accessor (8 in
gfx10/mod.rs, 1 insp3.rs, 2 infields.rs).Measured
Bench from #1002, standalone against
mainffe310e(not stacked on the other PRs), twelve interleaved rounds per arm, best of each, nanoseconds per instruction:decodebeforeHonest about the shape:
decodeitself is 18-45% faster, but the whole translation is 1.2-5.1%, and the gain shrinks with program size - at 16 k instructions it is inside the run-to-run spread of this machine. What it buys beyond the CPU time is one allocation and one indirection per instruction gone.Applied on top of #1002 + #1033 + #1180 the same change measured 0.929-0.957 of the translation, because the per-instruction constant those three leave behind is smaller and the removed allocation is a larger share of it. Both numbers are real; this one is the one that stands alone.
Correctness
cargo test --workspace --locked: 342 passed, 0 failed, 7 ignored.-D warnings;cargo xtask policy.No game data used. Four files, +38/-16; independent of #1002, #1033, #1180 and #1556.
What it gives (to decide the merge): an instruction's words are kept inline (
[u32; 5]) instead of in a heap vector: decode -18..-45 %, translation -1..-5 % (the numbers in the description).State: MERGEABLE, CI
checkgreen, rebased onto today'smain(f3578e3).Risk: rebased for #2143 (
words().len()through the accessor); 302victory-shadertests pass.Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T20:05:30Z.
Review: APPROVED
gfx10::Instruction.wordsmoves from a heapVec<u32>to an inline[u32; MAX_WORDS=5]+len, with a decode-time guard rejecting instructions longer than the budget. All call sites (fields.rs,sp3.rs,apps/victorydisasm) converted towords(); the public field removal is workspace-internal. Existing gfx10 decode tests stay green on macOS (96 passed). Nice allocation win for shader-heavy paths — consider a quickcargo bench-style before/after if you have one.Imported from Marvisak/VIctory. Originally posted by pes7 on 2026-11-24T22:56:06Z.
Heads up before merging: this PR and #1180 conflict with each other in
gfx10/mod.rs. Both change theInstructionstruct and both change whatdecodeputs in it, so whichever is merged second does not apply - I checked by merging my own branches together, not just each againstmain.This branch is stacked on
perf/instruction-name(#1180) to fix that, so:wordschange alone.The resolution keeps both wins, since they are independent:
wordsis the inline[u32; MAX_WORDS]withlen(#1623) andnameis the opcode name resolved once at decode (#1180), so an instruction carries both.Verified on the stack:
cargo test --workspace --locked476 passed, 0 failed; both clippy configurations with-D warnings;cargo xtask policy. The old head was72eff75, this is13eece9(three commits: #1180's, mine, and the merge that resolves the conflict - they collapse once #1180 is inmain).Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T03:31:51Z.
Automated triage for the maintainers.
Merge candidate. Re-reviewed at
cc2a2bd, rebased onto currentmain.Instruction::wordsbecomes an inline[u32; 5]pluslen, read throughwords()(crates/victory-shader/src/gfx10/mod.rs); five is the decoder's longest instruction (MIMG,2 + ((w >> 1) & 3)), and a longer one is now anIsaerror instead of a truncation. The only new hunk is the one the second look asked for:code_table_startincrates/victory-shader/src/emit/lower.rsnow readsi.machine.words().len(). I checked the merged tree: no other read of the old field and no other construction ofInstructionremains outside the files this PR changes.On your reply: confirmed, that was the one change needed. CI:
checkpassing on this head.Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by pes7 on 2026-11-25T16:26:58Z.
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:mainmain940d32f246c928d809fb7-1.2% is at the bottom of the -1..-5% the PR claimed on synthetic programs, which is what one would expect: the allocation it removes is one per instruction, and decode is a small part of a translation.
The output is identical to
mainon all 26 084 programs (every summary count and everyemit:/resources:line; only the(e.g. ...)examples differ, supplied by whichever thread finishes first).That the two PRs are -3.2% and -1.2% rather than overlapping noise is also a check on the method: they were measured in the same window as the control.
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T22:03:06Z.
Automated triage for the maintainers, second look (a review against
main, with the PR built and tested).This is right as reviewed (an instruction's words fit inline; the tests pass). It no longer builds on
main, though: #2143, merged today, readsi.machine.words.len()incode_table_start(crates/victory-shader/src/emit/lower.rs), andwordsbecomes an accessor here. GitHub shows no conflict because the two touch different lines. Please rebase and change that call toi.machine.words().len(); with that one change the two were built and tested together.Push the change and it will be reviewed again. Thank you for the contribution.
Imported from Marvisak/VIctory. Originally posted by pes7 on 2026-11-25T22:16:21Z.
Rebased onto today's
mainand fixed the one thing the triage found in #2143:code_table_startreadsi.machine.words.len(), which the inline array makes a private field. It now goes through the accessor (words().len(), the same slice length), the branch is rebased (4ca9bc1->cc2a2bd), andcargo test --release -p victory-shaderpasses (302 tests, 3 ignored).No other file needed a change: the rest of the branch applies as it was.
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T19:06:49Z.
Review: APPROVED
Verified locally merged onto
origin/main(63bcca43, Windows 11 x64, Rust 1.98.1 MSVC):cargo test --locked -p victory-shader --lib gfx10::— 16 passed, 0 failedcargo test --locked -p victory-shader --lib emit::lower::tests::the_code_table_starts_after_the_instructions— 1 passed, 0 failedcargo test --locked -p victory— 18 passed, 0 failed (14 unit + 4 integration)cargo clippy --locked -p victory-shader -p victory --all-targets -- -D warnings(default and--all-features) — 0 warningscargo xtask policy— ok (191 files ok)Review notes
instruction(): every supported encoding produces 1-5 words (MIMG maxes out at 5), and thelen > Instruction::MAX_WORDSguard prevents silent truncation or lossylen as u8conversion.decode_alignedingfx10/mod.rsuses.words.len(), which would still compile against the private[u32; 5]array inside the same module and silently evaluate to5instead ofwords().len().crates/victory-shader/src/gfx10/mod.rs:137(control) exceeds therustfmtline width after switching towords().len().Imported from Marvisak/VIctory. Originally posted by neonbyte1 on 2026-11-27T22:55:41Z.
A silent conflict between this PR and #2012, found while merging all
triage: merge candidatePRs together on one branch (details on #3347).words: [u32; Instruction::MAX_WORDS]plus a length, read throughInstruction::words().inst.words.len()(crates/victory-shader/src/gfx10/mod.rs, thenextoffset and the overlap check).Each PR is correct on its own and both merge cleanly into
main. Merged together,words.len()is always 5, so every instruction is walked as five dwords and the decoder refuses most programs. In the combined tree that took victory-shader's lib tests from 214 to 146 passed (335 failed). Usingwords()in those two places (inst.words().len(),w[0].words().len()) brings it to 344 passed / 137 failed; the remaining failures are unrelated (47 are "no SM 6.6 device" under Wine).Whichever of the two lands second needs that two-line change. Reference commit on the integration branch:
github.com/neonbyte1/VIctory@17c7845dd(merge resolution only).Measured with CPU tests under Wine on Linux; no game data involved.
AI-assisted (Claude); measured on my machine, no game data shared.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.