Skip to content

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

Merged
Marvisak merged 1 commit into
Marvisak:mainfrom
pes7:perf/instruction-name
Nov 25, 2026
Merged

Marvisak merged 1 commit into
Marvisak:mainfrom
pes7:perf/instruction-name

Conversation

@pes7

@pes7 pes7 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

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.

JMAN730 pushed a commit to JMAN730/project-flamingo that referenced this pull request Nov 24, 2026
@Zipettte

Copy link
Copy Markdown

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

@Aniseto

Aniseto commented Nov 24, 2026

Copy link
Copy Markdown

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.

mercuryVM added a commit to mercuryVM/VIctory that referenced this pull request Nov 24, 2026
… at decode time (translation -4..-8%)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@mercuryVM mercuryVM left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested 9e5c130 on Windows 11, RTX 5070, MSVC:

  • cargo test -p victory-shader -- --test-threads=1 passes 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).

github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 24, 2026
github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 24, 2026
github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 24, 2026
`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.
@pes7
pes7 force-pushed the perf/instruction-name branch from 9e5c130 to 146dfef Compare November 24, 2026 22:31
pes7 added a commit to pes7/VIctory that referenced this pull request Nov 24, 2026
`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.
nazmi added a commit to nazmi/VIctory that referenced this pull request Nov 24, 2026
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)
nazmi added a commit to nazmi/VIctory that referenced this pull request Nov 24, 2026
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).
pes7 added a commit to pes7/VIctory that referenced this pull request Nov 24, 2026
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.
@pes7

pes7 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

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>,

@Marvisak
Marvisak merged commit 82494a9 into Marvisak:main Nov 25, 2026
github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 25, 2026
MfDev0 pushed a commit to MfDev0/victory that referenced this pull request Nov 25, 2026
…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>
pes7 added a commit to pes7/VIctory that referenced this pull request Nov 25, 2026
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.
github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 25, 2026
pes7 added a commit to pes7/VIctory that referenced this pull request Nov 25, 2026
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.
github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants