Repository navigation
gfx10: resolve the opcode name once, at decode time (translation -4..-8%) - #1180
Conversation
|
Ran the Environment: Windows 11 Pro build 26200 x64, Intel Core i5-12400F, 64 GB RAM, NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only) driver 32.0.16.2124, Rust 1.98.1 (pinned by Same as Not tested: translation timing on a retail shader pack (no game data), the title, RDNA2/RDNA4 and Intel GPUs. AI-assisted (OpenCode), model: DeepSeek V4.1 Flash 1017 - checked out the PR's head commit in a detached worktree, built it, ran the crate's tests, wrote this report; no game data was used. |
… at decode time (translation -4..-8%) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
mercuryVM
left a comment
There was a problem hiding this comment.
Tested 9e5c130 on Windows 11, RTX 5070, MSVC:
cargo test -p victory-shader -- --test-threads=1passes on the head (120 passed, 1 ignored).- Merged into our fork: workspace tests, shader tests and
clippy -D warnings(default and all features) are all clean.
The change is right. Nothing rewrites encoding or opcode after decode (git grep finds no assignment), so the cached name can't go stale. On a full game package, translate --validate --list output is identical before and after: every program keeps the same result (counts only compared).
AI-assisted (Claude Code).
…ime (translation -4..-8%)
…ime (translation -4..-8%)
…ime (translation -4..-8%)
`Instruction::name()` binary-searches the opcode table, and the pipeline asks about every instruction eight times per translation: `ir::build`, `structure`, `resource` (which has the most call sites), `io` and `lower`. The answer cannot change - the encoding and opcode are decoded from the words and never rewritten - so resolve it once when the instruction is built and read the field after that. Measured with the synthetic bench from Marvisak#1002 (no game data), sixteen interleaved rounds per arm, best of each, nanoseconds per instruction, at 256/1k/4k/16k instructions: resource 17 -> 9, 15 -> 7, 24 -> 16, 23 -> 15 (0.47-0.67) lower 511 -> 479, 428 -> 411, 440 -> 401, 477 -> 428 (0.90-0.96) io 27 -> 23, 26 -> 21, 26 -> 22, 30 -> 22 (0.73-0.85) whole 926 -> 881, 920 -> 874, 958 -> 921, 1019 -> 939 (0.92-0.96) `decode` pays the one search it used to be spared (112 -> 115 at 16k, inside the run-to-run spread); every stage after it reads a field. 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.
9e5c130 to
146dfef
Compare
`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.
Regression test for the decode-time name cache from upstream PR Marvisak#1180 (head 9e5c130): the name is resolved once from `encoding` and `opcode`, so `Instruction::name()` must still equal the table's answer for the instruction's own fields. Poisoning the cache makes it fail. cargo test -p victory-shader --locked: 227 passed, 0 failed, 2 ignored. Both clippy configurations clean; cargo fmt clean. (cherry picked from commit dfee3a8ad6c357138feb14b20c02ddfb7bafbe5e)
Three review workers over ~30 PRs against the freshly merged upstream tree, plus three of our features the merge had discarded, re-applied with their tests: f32_to_half NaN/nearest-even (Marvisak#843), unique-temp atomic library writes (Marvisak#1660), VICTORY_PIPELINE_WORKERS (Marvisak#1728). Integrated: Marvisak#1146, Marvisak#1161, Marvisak#1474, Marvisak#1592, Marvisak#1058, Marvisak#1505, Marvisak#1177, Marvisak#1507, Marvisak#1236, Marvisak#1180 (with a new regression test for the cached opcode name). Duplicates confirmed against upstream's own code: Marvisak#957, Marvisak#1103, Marvisak#1057, Marvisak#299. Obsolete: Marvisak#513 (title_args no longer exists), Marvisak#1507's sibling Marvisak#334 covers it. Refused: Marvisak#1030 (zip dump of game data), Marvisak#962 (deletes .gitignore). Verified before this merge: fmt 0 differing, both Clippy gates exit 0, xtask policy 220 files ok, workspace 662 passed / 0 failed (10 GPU tests skipped that fail identically on upstream/main itself on this host).
Marvisak#1180 and Marvisak#1623 both change `Instruction`, so they conflict with each other in `gfx10/mod.rs`: this branch is stacked on `perf/instruction-name` (Marvisak#1180) so that whichever lands second still applies. The two are independent in what they save and compose without a trade: `words` stays the inline `[u32; MAX_WORDS]` with `len` (Marvisak#1623), and `name` stays resolved once at decode (Marvisak#1180), so an instruction carries both and neither costs the other its win. Merge Marvisak#1180 first; this diff then shrinks to the `words` change alone.
|
One thing to know before this is merged, because it decides the order: #1623 conflicts with this PR, not with #1623 is now stacked on this branch and carries a merge that resolves it, so merge this one first and #1623 after. Nothing in this PR changed: head is still For the record, the resolution on the other side keeps both, since they are independent wins: words: [u32; Instruction::MAX_WORDS],
len: u8,
/// [`name`] of `encoding` and `opcode`, resolved once at decode time.
name: Option<&'static str>, |
…nly with VICTORY_TRY_UPSTREAM=1; build fixes for the ported fxceless commits Build returned cargo's output lines together with its $false, which PowerShell treats as true: the fallback build never ran, built_key was saved and the old victory.exe kept running (the 2026-11-25 reports: the build failed on upstream Marvisak#1180's private Instruction field against this fork's ir.rs, and the game log shows none of the 3.9/4.0 lines). relay_fetch_merge takes the plans' last send instead of the plans; the card test sets in_pc. Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
One `Vec<u32>` per instruction was one allocation and one cache miss for the dword or two most instructions have. The words live in a fixed `[u32; MAX_WORDS]` with a length now: five dwords covers the longest instruction here (an MIMG with its three extra address dwords), and the decoder refuses anything longer rather than truncating it. Decode -18..45% depending on program size; whole translation -1..5%, since decode is a small part of it. Now that Marvisak#1180 is in `main`, this applies on its own: an `Instruction` carries both the inline `words`/`len` and the cached `name`, and neither costs the other its win. cargo test --workspace --locked; both clippy configurations with -D warnings; cargo xtask policy.
One `Vec<u32>` per instruction was one allocation and one cache miss for the dword or two most instructions have. The words live in a fixed `[u32; MAX_WORDS]` with a length now: five dwords covers the longest instruction here (an MIMG with its three extra address dwords), and the decoder refuses anything longer rather than truncating it. Decode -18..45% depending on program size; whole translation -1..5%, since decode is a small part of it. Now that Marvisak#1180 is in `main`, this applies on its own: an `Instruction` carries both the inline `words`/`len` and the cached `name`, and neither costs the other its win. cargo test --workspace --locked; both clippy configurations with -D warnings; cargo xtask policy.
The translator asks every instruction for its opcode name eight times, and every answer is a binary search. Resolving it once at decode time takes 4-8% off a translation.
Instruction::name()doesbinary_search_by_keyover the opcode table of its encoding. The encoding and opcode are decoded from the instruction words and never rewritten, so the answer cannot change, but five stages each ask again:ir::build,structure,resource(the most call sites by far),ioandlower. Measured with a counter inname(): exactly 8 calls per instruction, flat across program sizes.What changes
Instructioncarries the resolvedOption<&'static str>, filled where the instruction is built (decode, one construction site), andname()returns the field. Eight table searches per instruction become one.Measured
Bench from #1002 (
emit/bench_tests.rs, synthetic GFX10 compute programs, no game data), sixteen interleaved rounds per arm, best of each, nanoseconds per instruction:resourceresourceresourceresourcelowerloweriodecodepays the one search it used to be spared and grows the struct by two words (112 -> 115 ns at 16k, inside the run-to-run spread);ir::buildre-decodes internally, so it is neutral.Correctness
Instructionis built in exactly one place, so there is no second initialiser to keep in step. The emitted DXIL is byte-identical at all four sizes.cargo test --workspace --locked: 342 passed, 0 failed, 7 ignored.-D warnings;cargo xtask policyok.No game data used. Independent of #1002 and #1033 - one file, +8/-2.