Shader tests: the GFX10 decoder against llvm-mc on every opcode (checked-in fixture, no LLVM needed) #87

Open
github-bot wants to merge 0 commits from github-bot/gh-87 into main AGit
Owner

@⁠lcg007xd-c on GitHub · 2026-11-25 22:18 UTC · original
lcg007xd-c:test/llvm-decoder-oracle → main · +7649 −0 · 3 files · 1 commits · open

What

This checks the GFX10 decoder against LLVM's, on every opcode, without needing LLVM to run the tests.

  • The fixture. gfx10/llvm-mc-gfx1030.txt (264 KB, plain text) records what llvm-mc -triple=amdgcn -mcpu=gfx1030 --disassemble makes of one encoding of every opcode of every family. The families are SOP1/2/C/K/P, VOP1/2/3/3P/C, SMEM, DS, MUBUF, MTBUF, MIMG, FLAT/GLOBAL/SCRATCH, VINTRP and EXP. The ALU forms also come with a literal, and VOP3 with a literal in either the first or the third source. That is 7,093 cases, 2,393 of which LLVM decodes.
  • The test. decoder_agrees_with_llvm decodes each case and compares the name (ignoring LLVM's _e32/_e64) and the length in dwords. A wrong length is the bad one, because every later instruction is then read out of step. It takes 0.02 s.
  • Known cases. Today's disagreements are listed in KNOWN, each with a reason, and anything else fails. One pattern is skipped without listing: 0xFF in a source field the instruction doesn't have (e.g. a third source on a two-source op). LLVM reads no literal there and real code never writes one.
  • Regenerating. cargo test -p victory-shader regenerate_llvm_fixture -- --ignored rewrites the fixture. It needs llvm-mc, which can be set with LLVM_MC.

What it found

The 48 listed cases:

  • #69's names. image_sample_cd_g16 (all 8) and image_gather4h have no name; #69 adds them.
  • #70's length. The VOP3 interpolation forms with 0xFF in the attribute field are decoded as having a literal; #70 fixes that.
  • The legacy multiply-adds are named differently. VOP2 0x06 / VOP3 0x106 and VOP3 0x140 are v_mac_legacy_f32 / v_mad_legacy_f32 here, the GFX10.1 names. LLVM's gfx1030 has v_fmac_legacy_f32 / v_fma_legacy_f32 there, the fused forms. Which one the console's GPU implements decides whether these round like an FMA. That is left for whoever owns the lowering. The test only records it.
  • Register-only operands. These have a literal in an operand that must be a register: source 0 of v_movrels*, v_readlane, v_swap* and the permlanes, or the lane mask of v_cndmask and the carry ops. LLVM doesn't read a literal there, and the compiler can't encode one.
  • A test artifact. s_call_b64's branch target lies past the end of the test program.

So nothing in today's decoder misreads real code that I can see. The test is there to keep it that way.

Tests

  • The test passes.
  • I removed the first-source literal check from the VOP3 length rule: 381 cases fail. Removing the third-source check fails 67.
  • The portable CI commands and Windows-target clippy (--target x86_64-pc-windows-msvc) pass locally. The fixture is within the asset policy's size limit.

Not covered: operand text (styles differ from LLVM's), and DS/SMEM/MUBUF encodings beyond the one template each, which LLVM refuses for many opcodes.

🤖 Generated with Claude Code

**@⁠lcg007xd-c** on GitHub · 2026-11-25 22:18 UTC · [original](https://github.com/uiliannn/VItoriaBr/pull/87) `lcg007xd-c:test/llvm-decoder-oracle` → `main` · +7649 −0 · 3 files · 1 commits · open ## What This checks the GFX10 decoder against LLVM's, on every opcode, without needing LLVM to run the tests. - **The fixture.** `gfx10/llvm-mc-gfx1030.txt` (264 KB, plain text) records what `llvm-mc -triple=amdgcn -mcpu=gfx1030 --disassemble` makes of one encoding of every opcode of every family. The families are SOP1/2/C/K/P, VOP1/2/3/3P/C, SMEM, DS, MUBUF, MTBUF, MIMG, FLAT/GLOBAL/SCRATCH, VINTRP and EXP. The ALU forms also come with a literal, and VOP3 with a literal in either the first or the third source. That is 7,093 cases, 2,393 of which LLVM decodes. - **The test.** `decoder_agrees_with_llvm` decodes each case and compares the name (ignoring LLVM's `_e32`/`_e64`) and the length in dwords. A wrong length is the bad one, because every later instruction is then read out of step. It takes 0.02 s. - **Known cases.** Today's disagreements are listed in `KNOWN`, each with a reason, and anything else fails. One pattern is skipped without listing: `0xFF` in a source field the instruction doesn't have (e.g. a third source on a two-source op). LLVM reads no literal there and real code never writes one. - **Regenerating.** `cargo test -p victory-shader regenerate_llvm_fixture -- --ignored` rewrites the fixture. It needs `llvm-mc`, which can be set with `LLVM_MC`. ## What it found The 48 listed cases: - **#69's names.** `image_sample_cd_g16` (all 8) and `image_gather4h` have no name; #69 adds them. - **#70's length.** The VOP3 interpolation forms with `0xFF` in the attribute field are decoded as having a literal; #70 fixes that. - **The legacy multiply-adds are named differently.** VOP2 0x06 / VOP3 0x106 and VOP3 0x140 are `v_mac_legacy_f32` / `v_mad_legacy_f32` here, the GFX10.1 names. LLVM's gfx1030 has `v_fmac_legacy_f32` / `v_fma_legacy_f32` there, the fused forms. Which one the console's GPU implements decides whether these round like an FMA. That is left for whoever owns the lowering. The test only records it. - **Register-only operands.** These have a literal in an operand that must be a register: source 0 of `v_movrels*`, `v_readlane`, `v_swap*` and the permlanes, or the lane mask of `v_cndmask` and the carry ops. LLVM doesn't read a literal there, and the compiler can't encode one. - **A test artifact.** `s_call_b64`'s branch target lies past the end of the test program. So nothing in today's decoder misreads real code that I can see. The test is there to keep it that way. ## Tests - The test passes. - I removed the first-source literal check from the VOP3 length rule: 381 cases fail. Removing the third-source check fails 67. - The portable CI commands and Windows-target clippy (`--target x86_64-pc-windows-msvc`) pass locally. The fixture is within the asset policy's size limit. Not covered: operand text (styles differ from LLVM's), and DS/SMEM/MUBUF encodings beyond the one template each, which LLVM refuses for many opcodes. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
gfx10/llvm-mc-gfx1030.txt holds what `llvm-mc -mcpu=gfx1030
--disassemble` makes of one encoding of every opcode of every encoding
family, with and without a literal (7,093 cases, 2,393 that LLVM
decodes). decoder_agrees_with_llvm decodes each and compares the name
(without _e32/_e64) and the length in dwords: a wrong length puts every
later instruction out of step. Disagreements known today are listed in
KNOWN with why (the image and interpolation names and lengths other PRs
fix, the GFX10.1 names of the legacy multiply-adds, and literals in
register-only operands that LLVM does not read); anything else fails.
0xFF in a source field the instruction does not have is skipped: LLVM
reads no literal there and real code never writes one.

The fixture regenerates with the ignored regenerate_llvm_fixture test,
which runs llvm-mc; the test itself needs no LLVM.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:43:37 +00:00
Author
Owner

@⁠lmouz823-lang on GitHub · 2026-11-28 05:31 UTC · original

I can take native Windows validation and skip-accounting review at exact head b7104dbd13a005ff4a3942aef795d0fb7c85e15f. I will run the checked-in fixture test, independently count its accepted, known and unused-literal cases, and inspect whether the exception rules can hide meaningful name/length regressions. Any justified small regression or fix will include a negative control, restored-source runs and explicit coverage limits. Local LLVM fixture regeneration will be reported separately according to tool availability. AI-assisted with Codex.

**@⁠lmouz823-lang** on GitHub · 2026-11-28 05:31 UTC · [original](https://github.com/uiliannn/VItoriaBr/pull/87#issuecomment-7234720326) I can take native Windows validation and skip-accounting review at exact head `b7104dbd13a005ff4a3942aef795d0fb7c85e15f`. I will run the checked-in fixture test, independently count its accepted, known and unused-literal cases, and inspect whether the exception rules can hide meaningful name/length regressions. Any justified small regression or fix will include a negative control, restored-source runs and explicit coverage limits. Local LLVM fixture regeneration will be reported separately according to tool availability. AI-assisted with Codex.
Author
Owner

@⁠lmouz823-lang on GitHub · 2026-11-28 05:42 UTC · original

Native Windows validation completed for exact head b7104dbd13a005ff4a3942aef795d0fb7c85e15f. The original gfx10::llvm_tests::decoder_agrees_with_llvm executes exactly one test and passes.

I audited the checked-in fixture and temporarily counted the comparison paths. The 7,093 data rows contain 2,393 stored LLVM acceptances and 4,700 stored rejections. The accepted rows divide into 2,095 exact name/length agreements, 250 unused-source literal exclusions, and 48 observed KNOWN disagreements. Family/encoding keys and KNOWN keys are unique.

The 250 exclusions require a literal-family case, the same decoded name, a decoder length exactly one dword longer, and a literal field beyond the decoder's reported source count. The 48 KNOWN keys consist of two branch-target artifacts, 23 register-only literal forms, nine missing image names, eight legacy fused-name differences and six attribute/literal cases. The KNOWN gate matches family and first word, so each matching key admits any mismatch for that key. The unused-source rule depends on the decoder's source count. These allowances bound the semantic regression's coverage.

The original comparison silently continues past rows with fewer than four columns and only checks a fixture-size lower bound. I added a 21-line test-only integrity regression that pairs every fixture row with cases() in order, checks equal row counts, exactly four columns, the family and canonical encoding, a nonempty name, the -/zero-length relation, and a length within the supplied input. The generator appends one S_ENDPGM word. Five existing encodings consume that extra word, so the length bound includes it.

Two temporary fixture mutations demonstrate the new coverage.

Temporary fixture change Existing decoder exact test New integrity exact test
Delete the first accepted row, leaving 7,092 rows 1 passed 1 failed, exit 101, row-count mismatch
Truncate that row to its family and encoding columns 1 passed 1 failed, exit 101, 2 columns versus 4

I restored the fixture byte-for-byte to SHA256 cef83c381ac1edd37c7850143dff989563fe69d11196b7df19a9d3d5e83f2f96, removed the temporary counting diagnostic, cleaned only the isolated shader package target, and confirmed a fresh 12.38-second compilation. On the final formatted source, both exact tests each execute one test and pass. The complete LLVM test group reports 2 passed, 0 failed, 1 ignored.

The ignored test is regenerate_llvm_fixture. It requires llvm-mc, and this environment has neither LLVM_MC configured nor llvm-mc on PATH. All LLVM judgments above come from the committed fixture. Local regeneration, a live LLVM comparison, GPU/DXIL execution, game behavior, other platforms and the remaining shader/workspace suites remain unverified.

Environment was Windows 11 build 26200, Rust 1.98.1 MSVC, default test profile and an isolated target. Package Clippy with --all-targets -- -D warnings, whole-file rustfmt on the original and final source, git diff --check, and asset policy (198 files) pass. The final patch adds only the integrity test. The fixture and the original comparison source match their initial contents after removing that added test and normalizing source newlines.

Reproduce after applying the attached patch.

cargo test --locked -p victory-shader --lib gfx10::llvm_tests::decoder_agrees_with_llvm -- --exact --nocapture --test-threads=1
cargo test --locked -p victory-shader --lib gfx10::llvm_tests::fixture_covers_every_generated_case -- --exact --nocapture --test-threads=1
cargo test --locked -p victory-shader --lib gfx10::llvm_tests:: -- --nocapture --test-threads=1

AI assistance from Codex covered the audit, regression, execution and this report.

Fixture integrity regression against this PR head
diff --git a/crates/victory-shader/src/gfx10/llvm_tests.rs b/crates/victory-shader/src/gfx10/llvm_tests.rs
index f480bac..dbdd9f7 100644
--- a/crates/victory-shader/src/gfx10/llvm_tests.rs
+++ b/crates/victory-shader/src/gfx10/llvm_tests.rs
@@ -465,6 +465,27 @@ fn disagreements() -> Vec<String> {
     out
 }
 
+#[test]
+fn fixture_covers_every_generated_case() {
+    let rows: Vec<_> = FIXTURE
+        .lines()
+        .filter(|line| !line.starts_with('#'))
+        .collect();
+    let generated = cases();
+    assert_eq!(rows.len(), generated.len(), "fixture case count");
+    for (line, (family, words)) in rows.into_iter().zip(generated) {
+        let fields: Vec<_> = line.split('\t').collect();
+        assert_eq!(fields.len(), 4, "fixture columns: {line}");
+        assert_eq!(fields[0], family, "fixture family: {line}");
+        assert_eq!(fields[1], hex(&words), "fixture encoding: {line}");
+        assert!(!fields[2].is_empty(), "fixture name: {line}");
+        let len: usize = fields[3].parse().expect("fixture dword count");
+        assert_eq!(fields[2] == "-", len == 0, "fixture name/length: {line}");
+        // The generator gives LLVM one trailing S_ENDPGM word as well.
+        assert!(len <= words.len() + 1, "fixture length: {line}");
+    }
+}
+
 #[test]
 fn decoder_agrees_with_llvm() {
     assert!(FIXTURE.lines().count() > 3000, "the fixture is missing");
**@⁠lmouz823-lang** on GitHub · 2026-11-28 05:42 UTC · [original](https://github.com/uiliannn/VItoriaBr/pull/87#issuecomment-7234834771) Native Windows validation completed for exact head `b7104dbd13a005ff4a3942aef795d0fb7c85e15f`. The original `gfx10::llvm_tests::decoder_agrees_with_llvm` executes exactly one test and passes. I audited the checked-in fixture and temporarily counted the comparison paths. The 7,093 data rows contain 2,393 stored LLVM acceptances and 4,700 stored rejections. The accepted rows divide into **2,095 exact name/length agreements**, **250 unused-source literal exclusions**, and **48 observed KNOWN disagreements**. Family/encoding keys and KNOWN keys are unique. The 250 exclusions require a literal-family case, the same decoded name, a decoder length exactly one dword longer, and a literal field beyond the decoder's reported source count. The 48 KNOWN keys consist of two branch-target artifacts, 23 register-only literal forms, nine missing image names, eight legacy fused-name differences and six attribute/literal cases. The KNOWN gate matches family and first word, so each matching key admits any mismatch for that key. The unused-source rule depends on the decoder's source count. These allowances bound the semantic regression's coverage. The original comparison silently continues past rows with fewer than four columns and only checks a fixture-size lower bound. I added a **21-line test-only integrity regression** that pairs every fixture row with `cases()` in order, checks equal row counts, exactly four columns, the family and canonical encoding, a nonempty name, the `-`/zero-length relation, and a length within the supplied input. The generator appends one `S_ENDPGM` word. Five existing encodings consume that extra word, so the length bound includes it. Two temporary fixture mutations demonstrate the new coverage. | Temporary fixture change | Existing decoder exact test | New integrity exact test | | --- | --- | --- | | Delete the first accepted row, leaving 7,092 rows | 1 passed | 1 failed, exit 101, row-count mismatch | | Truncate that row to its family and encoding columns | 1 passed | 1 failed, exit 101, 2 columns versus 4 | I restored the fixture byte-for-byte to SHA256 `cef83c381ac1edd37c7850143dff989563fe69d11196b7df19a9d3d5e83f2f96`, removed the temporary counting diagnostic, cleaned only the isolated shader package target, and confirmed a fresh 12.38-second compilation. On the final formatted source, both exact tests each execute one test and pass. The complete LLVM test group reports **2 passed, 0 failed, 1 ignored**. The ignored test is `regenerate_llvm_fixture`. It requires `llvm-mc`, and this environment has neither `LLVM_MC` configured nor `llvm-mc` on PATH. All LLVM judgments above come from the committed fixture. Local regeneration, a live LLVM comparison, GPU/DXIL execution, game behavior, other platforms and the remaining shader/workspace suites remain unverified. Environment was Windows 11 build 26200, Rust 1.98.1 MSVC, default test profile and an isolated target. Package Clippy with `--all-targets -- -D warnings`, whole-file rustfmt on the original and final source, `git diff --check`, and asset policy (**198 files**) pass. The final patch adds only the integrity test. The fixture and the original comparison source match their initial contents after removing that added test and normalizing source newlines. Reproduce after applying the attached patch. ```powershell cargo test --locked -p victory-shader --lib gfx10::llvm_tests::decoder_agrees_with_llvm -- --exact --nocapture --test-threads=1 cargo test --locked -p victory-shader --lib gfx10::llvm_tests::fixture_covers_every_generated_case -- --exact --nocapture --test-threads=1 cargo test --locked -p victory-shader --lib gfx10::llvm_tests:: -- --nocapture --test-threads=1 ``` AI assistance from Codex covered the audit, regression, execution and this report. <details> <summary>Fixture integrity regression against this PR head</summary> ```diff diff --git a/crates/victory-shader/src/gfx10/llvm_tests.rs b/crates/victory-shader/src/gfx10/llvm_tests.rs index f480bac..dbdd9f7 100644 --- a/crates/victory-shader/src/gfx10/llvm_tests.rs +++ b/crates/victory-shader/src/gfx10/llvm_tests.rs @@ -465,6 +465,27 @@ fn disagreements() -> Vec<String> { out } +#[test] +fn fixture_covers_every_generated_case() { + let rows: Vec<_> = FIXTURE + .lines() + .filter(|line| !line.starts_with('#')) + .collect(); + let generated = cases(); + assert_eq!(rows.len(), generated.len(), "fixture case count"); + for (line, (family, words)) in rows.into_iter().zip(generated) { + let fields: Vec<_> = line.split('\t').collect(); + assert_eq!(fields.len(), 4, "fixture columns: {line}"); + assert_eq!(fields[0], family, "fixture family: {line}"); + assert_eq!(fields[1], hex(&words), "fixture encoding: {line}"); + assert!(!fields[2].is_empty(), "fixture name: {line}"); + let len: usize = fields[3].parse().expect("fixture dword count"); + assert_eq!(fields[2] == "-", len == 0, "fixture name/length: {line}"); + // The generator gives LLVM one trailing S_ENDPGM word as well. + assert!(len <= words.len() + 1, "fixture length: {line}"); + } +} + #[test] fn decoder_agrees_with_llvm() { assert!(FIXTURE.lines().count() > 3000, "the fixture is missing"); ``` </details>
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/87/head:github-bot/gh-87'
git switch 'github-bot/gh-87'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-87'
git switch 'github-bot/gh-87'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-87'
git switch 'github-bot/gh-87'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-87'
git switch 'main'
git merge --squash 'github-bot/gh-87'
git switch 'main'
git merge --ff-only 'github-bot/gh-87'
git switch 'main'
git merge 'github-bot/gh-87'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.