Shaders: decode the VOP3 interpolation forms (attr63.w is no literal) #70

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

@⁠lcg007xd-c on GitHub · 2026-11-25 21:34 UTC · original
lcg007xd-c:fix/vop3-interp-decode → main · +83 −2 · 5 files · 2 commits · open

What

The VOP3 interpolation instructions put an attribute and its channel in the first source field, not an operand code. That covers v_interp_p1ll_f16, v_interp_p1lv_f16, v_interp_p2_f16, and the 64-bit encodings of v_interp_p1/p2/mov_f32. attr63.w encodes as 0xFF, and the decoder's length rule read that as "a 32-bit literal follows". The instruction then swallowed the next dword, and everything after it decoded out of step. llvm-mc reads all of them as two dwords. For these opcodes, the first source no longer counts toward a literal.

VOP3 0x200–0x202 also get their names: v_interp_p1_f32, v_interp_p2_f32 and v_interp_mov_f32, LLVM's _e64 forms. Before, they decoded with no name. Each takes two sources, and v_interp_mov_f32's parameter prints as p10/p20/p0, as in VINTRP. The input pass only understands the VINTRP pair, so translation refuses these VOP3 forms with an error instead of misreading them. A test pins that.

Upstream has an open PR for the same length bug (Marvisak/VIctory#2515). This is an independent fix on VItoriaBr's decoder.

Tests

  • vop3_interpolation_attributes_are_not_literals checks six encodings from llvm-mc -triple=amdgcn -mcpu=gfx1030: the three f32 _e64 forms with attr31.w, and the three f16 forms with attr63.w. Each must decode as one two-dword instruction with LLVM's operands (without the _e64 suffix). With the length change reverted, the test fails.
  • vop3_encoded_f32_interpolation_is_refused checks that a VOP3-encoded p1/p2 pair decodes with its names and that io::raise refuses it.
  • The portable CI commands and Windows-target clippy (--target x86_64-pc-windows-msvc) pass locally.

Not tested: Windows runtime, GPU, and the game. Real shaders have fewer than 33 attributes, so attr63.w should not appear in practice. The length bug matters for disassembly and for decoding data or garbage as code.

Note: the Windows check job fails on current main for an unrelated reason (5668b8b, missing Layout::bytes_from), which #64 fixes.

🤖 Generated with Claude Code

**@⁠lcg007xd-c** on GitHub · 2026-11-25 21:34 UTC · [original](https://github.com/uiliannn/VItoriaBr/pull/70) `lcg007xd-c:fix/vop3-interp-decode` → `main` · +83 −2 · 5 files · 2 commits · open ## What The VOP3 interpolation instructions put an attribute and its channel in the first source field, not an operand code. That covers `v_interp_p1ll_f16`, `v_interp_p1lv_f16`, `v_interp_p2_f16`, and the 64-bit encodings of `v_interp_p1/p2/mov_f32`. `attr63.w` encodes as `0xFF`, and the decoder's length rule read that as "a 32-bit literal follows". The instruction then swallowed the next dword, and everything after it decoded out of step. `llvm-mc` reads all of them as two dwords. For these opcodes, the first source no longer counts toward a literal. VOP3 0x200–0x202 also get their names: `v_interp_p1_f32`, `v_interp_p2_f32` and `v_interp_mov_f32`, LLVM's `_e64` forms. Before, they decoded with no name. Each takes two sources, and `v_interp_mov_f32`'s parameter prints as `p10`/`p20`/`p0`, as in VINTRP. The input pass only understands the VINTRP pair, so translation refuses these VOP3 forms with an error instead of misreading them. A test pins that. Upstream has an open PR for the same length bug (Marvisak/VIctory#2515). This is an independent fix on VItoriaBr's decoder. ## Tests - `vop3_interpolation_attributes_are_not_literals` checks six encodings from `llvm-mc -triple=amdgcn -mcpu=gfx1030`: the three f32 `_e64` forms with `attr31.w`, and the three f16 forms with `attr63.w`. Each must decode as one two-dword instruction with LLVM's operands (without the `_e64` suffix). With the length change reverted, the test fails. - `vop3_encoded_f32_interpolation_is_refused` checks that a VOP3-encoded p1/p2 pair decodes with its names and that `io::raise` refuses it. - The portable CI commands and Windows-target clippy (`--target x86_64-pc-windows-msvc`) pass locally. Not tested: Windows runtime, GPU, and the game. Real shaders have fewer than 33 attributes, so `attr63.w` should not appear in practice. The length bug matters for disassembly and for decoding data or garbage as code. Note: the Windows `check` job fails on current main for an unrelated reason (5668b8b, missing `Layout::bytes_from`), which #64 fixes. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The VOP3 interpolation instructions (v_interp_p1ll/p1lv/p2_f16, and the
64-bit encodings of v_interp_p1/p2/mov_f32) take an attribute and its
channel in the first source field. attr63.w encodes as 0xFF, which the
length rule read as "a 32-bit literal follows", so the instruction
swallowed the next dword and the rest of the program decoded out of
step. llvm-mc reads each of them as two dwords; the first source of
these opcodes no longer counts toward a literal.

VOP3 0x200-0x202 get their names (v_interp_p1_f32, v_interp_p2_f32,
v_interp_mov_f32, as LLVM's _e64 forms), two sources each, and
v_interp_mov_f32's parameter prints as p10/p20/p0 as in VINTRP. The
input pass understands only the VINTRP pair, so the VOP3 f32 forms are
refused, and a test checks that.

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:02 +00:00
Author
Owner

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

I can take native Windows decoder validation at exact head aed8519e0807f2fa6d7f748130d59e5443816b4e. This follows the interpolation cases recorded among the #87 fixture disagreements. I will run the existing decoding/refusal regressions and check concatenated instruction-stream alignment, attribute fields and genuine literal controls. Any focused additional regression will include a targeted negative control and fresh restored-source runs, with explicit LLVM/GPU/game limits. AI-assisted with Codex.

**@⁠lmouz823-lang** on GitHub · 2026-11-28 06:11 UTC · [original](https://github.com/uiliannn/VItoriaBr/pull/70#issuecomment-7235141628) I can take native Windows decoder validation at exact head `aed8519e0807f2fa6d7f748130d59e5443816b4e`. This follows the interpolation cases recorded among the #87 fixture disagreements. I will run the existing decoding/refusal regressions and check concatenated instruction-stream alignment, attribute fields and genuine literal controls. Any focused additional regression will include a targeted negative control and fresh restored-source runs, with explicit LLVM/GPU/game limits. AI-assisted with Codex.
Author
Owner

@⁠lmouz823-lang on GitHub · 2026-11-28 06:21 UTC · original

Native Windows decoding and input-pass validation completed for exact head aed8519e0807f2fa6d7f748130d59e5443816b4e. Both original regressions each execute exactly one test and pass. The original GFX10 group passes 13/13, and the input-pass group passes 6/6.

I added one 48-line test-only stream regression using the six interpolation pairs from this PR's existing SP3 test. Each interpolation follows a real s_nop, so it starts at byte offset 4. A normal v_fma_f32 with a real src2 literal follows it, then another nop and the end instruction. The test checks offsets 0,4,12,24,28, lengths 1,2,3,1,1, the full ordinary-literal instruction words, and the decoded interpolation attribute index/channel/high flag. The f32 pairs use attr31.w and the f16 pairs attr63.w. These synthetic encodings and the ordinary VOP3 literal control come from the existing repository tests. Local llvm-mc assembly was outside this validation.

A temporary negative control incorrectly restricts the interpolation length exception to offset == 0. The original 13 GFX10 tests and all six input-pass tests still pass. The new exact test fails with exit 101 on the non-leading v_interp_p1ll_f16, which is wrongly read as three dwords. The following FMA is then split into instructions at offsets 16 and 20 instead of remaining a three-dword instruction at offset 12.

After restoring the implementation, I cleaned only the isolated shader package target and confirmed an actual 11.97-second compilation. The final GFX10 group passes 14/14 and the input-pass group 6/6. The original two exact regressions and the new exact regression each execute one test and pass. The f32 input-pass regression continues to require refusal of the named VOP3 forms, preserving the explicit unsupported path. Removing the added function reproduces the complete head source after newline normalization.

On 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 both original and final gfx10/mod.rs, and git diff --check pass. The rustfmt check uses skip_children=true to check this file. Asset policy reports 196 files ok.

The selected GFX10 and input-pass groups have zero failed or ignored tests and no runtime skip diagnostics. Scope is decoding, field/text metadata and the existing input-pass refusal checks. A live LLVM comparison, GPU/DXIL execution, game behavior, other platforms and the remaining shader/workspace suites remain unverified.

Reproduce the final checks after applying the attached patch.

cargo test --locked -p victory-shader --lib gfx10:: -- --nocapture --test-threads=1
cargo test --locked -p victory-shader --lib io::tests:: -- --nocapture --test-threads=1
cargo test --locked -p victory-shader --lib gfx10::tests::interpolation_keeps_following_instructions_aligned -- --exact --nocapture --test-threads=1

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

Stream alignment regression against this head
diff --git a/crates/victory-shader/src/gfx10/mod.rs b/crates/victory-shader/src/gfx10/mod.rs
index 896c622..c26c1c4 100644
--- a/crates/victory-shader/src/gfx10/mod.rs
+++ b/crates/victory-shader/src/gfx10/mod.rs
@@ -421,6 +421,54 @@ mod tests {
         );
     }
 
+    #[test]
+    fn interpolation_keeps_following_instructions_aligned() {
+        for (op, second, name, index) in [
+            (0x200, 0x0202_02DF, "v_interp_p1_f32", 31),
+            (0x201, 0x0202_02DF, "v_interp_p2_f32", 31),
+            (0x202, 0x0200_04DF, "v_interp_mov_f32", 31),
+            (0x342, 0x0202_02FF, "v_interp_p1ll_f16", 63),
+            (0x343, 0x040A_02FF, "v_interp_p1lv_f16", 63),
+            (0x35A, 0x040A_02FF, "v_interp_p2_f16", 63),
+        ] {
+            // The interpolation pairs come from the existing SP3 regression.
+            // Follow them with an ordinary VOP3 that has a real src2 literal.
+            let words = [
+                0xBF80_0000,
+                0xD400_0000 | op << 16,
+                second,
+                0xD54B_0000,
+                0x03FE_0000,
+                0x4000_0000,
+                0xBF80_0000,
+                S_ENDPGM,
+            ];
+            assert_eq!(
+                summary(&words),
+                [
+                    (0, 1, "s_nop"),
+                    (4, 2, name),
+                    (12, 3, "v_fma_f32"),
+                    (24, 1, "s_nop"),
+                    (28, 1, "s_endpgm"),
+                ]
+            );
+            let instructions = decode(&bytes(&words)).unwrap();
+            let Fields::Valu(v) = instructions[1].fields(false) else {
+                panic!("expected interpolation fields");
+            };
+            assert_eq!(
+                v.src[0],
+                Operand::Attr {
+                    index,
+                    chan: 3,
+                    high: false
+                }
+            );
+            assert_eq!(instructions[2].words, words[3..6]);
+        }
+    }
+
     #[test]
     fn follows_branches_and_skips_data() {
         let code = [
**@⁠lmouz823-lang** on GitHub · 2026-11-28 06:21 UTC · [original](https://github.com/uiliannn/VItoriaBr/pull/70#issuecomment-7235245902) Native Windows decoding and input-pass validation completed for exact head `aed8519e0807f2fa6d7f748130d59e5443816b4e`. Both original regressions each execute exactly one test and pass. The original GFX10 group passes **13/13**, and the input-pass group passes **6/6**. I added one **48-line test-only stream regression** using the six interpolation pairs from this PR's existing SP3 test. Each interpolation follows a real `s_nop`, so it starts at byte offset 4. A normal `v_fma_f32` with a real src2 literal follows it, then another nop and the end instruction. The test checks offsets `0,4,12,24,28`, lengths `1,2,3,1,1`, the full ordinary-literal instruction words, and the decoded interpolation attribute index/channel/high flag. The f32 pairs use attr31.w and the f16 pairs attr63.w. These synthetic encodings and the ordinary VOP3 literal control come from the existing repository tests. Local `llvm-mc` assembly was outside this validation. A temporary negative control incorrectly restricts the interpolation length exception to `offset == 0`. The original 13 GFX10 tests and all six input-pass tests still pass. The new exact test fails with exit 101 on the non-leading `v_interp_p1ll_f16`, which is wrongly read as three dwords. The following FMA is then split into instructions at offsets 16 and 20 instead of remaining a three-dword instruction at offset 12. After restoring the implementation, I cleaned only the isolated shader package target and confirmed an actual **11.97-second compilation**. The final GFX10 group passes **14/14** and the input-pass group **6/6**. The original two exact regressions and the new exact regression each execute one test and pass. The f32 input-pass regression continues to require refusal of the named VOP3 forms, preserving the explicit unsupported path. Removing the added function reproduces the complete head source after newline normalization. On 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 both original and final `gfx10/mod.rs`, and `git diff --check` pass. The rustfmt check uses `skip_children=true` to check this file. Asset policy reports **196 files ok**. The selected GFX10 and input-pass groups have zero failed or ignored tests and no runtime skip diagnostics. Scope is decoding, field/text metadata and the existing input-pass refusal checks. A live LLVM comparison, GPU/DXIL execution, game behavior, other platforms and the remaining shader/workspace suites remain unverified. Reproduce the final checks after applying the attached patch. ```powershell cargo test --locked -p victory-shader --lib gfx10:: -- --nocapture --test-threads=1 cargo test --locked -p victory-shader --lib io::tests:: -- --nocapture --test-threads=1 cargo test --locked -p victory-shader --lib gfx10::tests::interpolation_keeps_following_instructions_aligned -- --exact --nocapture --test-threads=1 ``` AI assistance from Codex covered the regression, execution and this report. <details> <summary>Stream alignment regression against this head</summary> ```diff diff --git a/crates/victory-shader/src/gfx10/mod.rs b/crates/victory-shader/src/gfx10/mod.rs index 896c622..c26c1c4 100644 --- a/crates/victory-shader/src/gfx10/mod.rs +++ b/crates/victory-shader/src/gfx10/mod.rs @@ -421,6 +421,54 @@ mod tests { ); } + #[test] + fn interpolation_keeps_following_instructions_aligned() { + for (op, second, name, index) in [ + (0x200, 0x0202_02DF, "v_interp_p1_f32", 31), + (0x201, 0x0202_02DF, "v_interp_p2_f32", 31), + (0x202, 0x0200_04DF, "v_interp_mov_f32", 31), + (0x342, 0x0202_02FF, "v_interp_p1ll_f16", 63), + (0x343, 0x040A_02FF, "v_interp_p1lv_f16", 63), + (0x35A, 0x040A_02FF, "v_interp_p2_f16", 63), + ] { + // The interpolation pairs come from the existing SP3 regression. + // Follow them with an ordinary VOP3 that has a real src2 literal. + let words = [ + 0xBF80_0000, + 0xD400_0000 | op << 16, + second, + 0xD54B_0000, + 0x03FE_0000, + 0x4000_0000, + 0xBF80_0000, + S_ENDPGM, + ]; + assert_eq!( + summary(&words), + [ + (0, 1, "s_nop"), + (4, 2, name), + (12, 3, "v_fma_f32"), + (24, 1, "s_nop"), + (28, 1, "s_endpgm"), + ] + ); + let instructions = decode(&bytes(&words)).unwrap(); + let Fields::Valu(v) = instructions[1].fields(false) else { + panic!("expected interpolation fields"); + }; + assert_eq!( + v.src[0], + Operand::Attr { + index, + chan: 3, + high: false + } + ); + assert_eq!(instructions[2].words, words[3..6]); + } + } + #[test] fn follows_branches_and_skips_data() { let code = [ ``` </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/70/head:github-bot/gh-70'
git switch 'github-bot/gh-70'

Merge

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