gfx10: resolve the opcode name once, at decode time (translation -4..-8%) #1180

Manually merged
github merged 1 commit from gh-pr/1180/head into gh-pr/1180/base 2026-11-26 04:22:39 +00:00
Owner

@⁠pes7 on GitHub · 2026-11-24 16:21 UTC · original
pes7:perf/instruction-name → main · +8 −2 · 1 files · 1 commits · merged 2026-11-25 00:21 UTC

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() does binary_search_by_key over 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), io and lower. Measured with a counter in name(): exactly 8 calls per instruction, flat across program sizes.

What changes

Instruction carries the resolved Option<&'static str>, filled where the instruction is built (decode, one construction site), and name() 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:

instructions stage before after ratio
256 resource 17 9 0.53
1 024 resource 15 7 0.47
4 096 resource 24 16 0.67
16 384 resource 23 15 0.65
256 lower 511 479 0.94
16 384 lower 477 428 0.90
16 384 io 30 22 0.73
instructions whole translation
256 926 881 0.951
1 024 920 874 0.950
4 096 958 921 0.961
16 384 1 019 939 0.921

decode pays 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::build re-decodes internally, so it is neutral.

Correctness

Instruction is 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.
  • Both CI clippy configurations with -D warnings; cargo xtask policy ok.

No game data used. Independent of #1002 and #1033 - one file, +8/-2.

**@⁠pes7** on GitHub · 2026-11-24 16:21 UTC · [original](https://github.com/Marvisak/VIctory/pull/1180) `pes7:perf/instruction-name` → `main` · +8 −2 · 1 files · 1 commits · merged 2026-11-25 00:21 UTC **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()` does `binary_search_by_key` over 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), `io` and `lower`. Measured with a counter in `name()`: exactly **8 calls per instruction**, flat across program sizes. ## What changes `Instruction` carries the resolved `Option<&'static str>`, filled where the instruction is built (`decode`, one construction site), and `name()` 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: | instructions | stage | before | after | ratio | |---:|---|---:|---:|---:| | 256 | `resource` | 17 | 9 | **0.53** | | 1 024 | `resource` | 15 | 7 | **0.47** | | 4 096 | `resource` | 24 | 16 | **0.67** | | 16 384 | `resource` | 23 | 15 | **0.65** | | 256 | `lower` | 511 | 479 | **0.94** | | 16 384 | `lower` | 477 | 428 | **0.90** | | 16 384 | `io` | 30 | 22 | **0.73** | | instructions | whole translation | | | |---:|---:|---:|---:| | 256 | 926 | 881 | **0.951** | | 1 024 | 920 | 874 | **0.950** | | 4 096 | 958 | 921 | **0.961** | | 16 384 | 1 019 | 939 | **0.921** | `decode` pays 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::build` re-decodes internally, so it is neutral. ## Correctness `Instruction` is 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. - Both CI clippy configurations with `-D warnings`; `cargo xtask policy` ok. No game data used. Independent of #1002 and #1033 - one file, +8/-2.
`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 #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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:22:36 +00:00
github manually merged commit 146dfef67a into gh-pr/1180/base 2026-11-26 04:22:39 +00:00
Author
Owner

@⁠Zipettte on GitHub · 2026-11-24 18:00 UTC · original

Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at 9e5c130: 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 18:00 UTC · [original](https://github.com/Marvisak/VIctory/pull/1180#issuecomment-7140026424) Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at 9e5c130: `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

@⁠Aniseto on GitHub · 2026-11-24 18:02 UTC · original

Ran the victory-shader crate at 9e5c130. The PR adds no test of its own (it resolves the opcode name once at decode time), so this is a regression check:

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 rust-toolchain.toml), MSVC 14.44.35207, DXC 1.9.2609.5, debug build.

cargo test -p victory-shader
120 passed; 0 failed; 1 ignored      (exit 0)

Same as main on this machine (ffe310e), so decoding behaviour is unchanged on the existing synthetic corpus. The PR claims a 4-8% translation speed-up; I did not measure timings, and with no retail shader pack here there is nothing meaningful to time.

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.

**@⁠Aniseto** on GitHub · 2026-11-24 18:02 UTC · [original](https://github.com/Marvisak/VIctory/pull/1180#issuecomment-7140082553) Ran the `victory-shader` crate at `9e5c130`. The PR adds no test of its own (it resolves the opcode name once at decode time), so this is a regression check: 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 `rust-toolchain.toml`), MSVC 14.44.35207, DXC 1.9.2609.5, debug build. ``` cargo test -p victory-shader 120 passed; 0 failed; 1 ignored (exit 0) ``` Same as `main` on this machine (`ffe310e`), so decoding behaviour is unchanged on the existing synthetic corpus. The PR claims a 4-8% translation speed-up; I did not measure timings, and with no retail shader pack here there is nothing meaningful to time. 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.
Author
Owner

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

One thing to know before this is merged, because it decides the order: #1623 conflicts with this PR, not with main. I merged my seven branches together locally to check, and #1623 (Instruction.words inline) and this one (opcode name cached) touch the same two places in gfx10/mod.rs - the struct and what decode fills in - so the second one to land would not apply.

#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 146dfef, +8/-2.

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>,
**@⁠pes7** on GitHub · 2026-11-24 22:56 UTC · [original](https://github.com/Marvisak/VIctory/pull/1180#issuecomment-7146817391) One thing to know before this is merged, because it decides the order: **#1623 conflicts with this PR**, not with `main`. I merged my seven branches together locally to check, and #1623 (`Instruction.words` inline) and this one (opcode `name` cached) touch the same two places in `gfx10/mod.rs` - the struct and what `decode` fills in - so the second one to land would not apply. **#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 `146dfef`, +8/-2. For the record, the resolution on the other side keeps both, since they are independent wins: ```rust words: [u32; Instruction::MAX_WORDS], len: u8, /// [`name`] of `encoding` and `opcode`, resolved once at decode time. name: Option<&'static str>, ```
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!1180
No description provided.