shader: lower v_cvt_off_f32_i4 #84

Open
github-bot wants to merge 1 commit from github-bot/gh-84 into main AGit
Owner

@⁠lcg007xd-c on GitHub · 2026-11-25 22:09 UTC · original
lcg007xd-c:shader-cvt-off-f32-i4 → main · +64 −0 · 2 files · 1 commits · open

What is broken

v_cvt_off_f32_i4 (VOP1 0x0E, VOP3 0x18E) decodes, but a program using it fails to translate with v_cvt_off_f32_i4 is not supported. I found it by translating a one-instruction program for every opcode the decoder names. AMD's ISA describes it as "used for interpolation in shader": it turns a 4-bit sample offset into a float.

Semantics

AMD's RDNA2 ISA (§12.8, opcode 14) gives a table. S0[3:0], read as a signed nibble, maps to nibble/16: 1000 → −0.5, 1111 → −0.0625, 0000 → 0, and 0111 → 0.4375. The other bits of S0 do not count.

The change (emit/lower.rs, in valu_op)

  • Conversion: the nibble is sign-extended (shift left 28, arithmetic right 28), converted to f32, and multiplied by 1/16. Both steps are exact for every nibble.
  • Modifiers: omod and clamp apply through write_f, as for any f32 result.

Tests

  • emit::lower::tests::nibble_offset_conversion_translates (every host): the VOP1 and VOP3 forms decode to the name, and a program that stores the result translates. Without the lower.rs change it fails with v_cvt_off_f32_i4 is not supported.
  • valu_tests::v_cvt_off_f32_i4_matches_the_isa_table (Windows/GPU): all 16 nibbles, with junk in bits 31:4.
  • CPU run: I ran the ISA's table, typed in literally, on Linux through the CPU harness of #62, which runs the emitted DXIL with LLVM's lli. I checked both encodings, plus omod ×4 (0.4375 → 1.75) and clamp (−0.5 → 0). All match.

Run here (Linux, Rust 1.98.1):

  • cargo test -p victory-shader --lib --locked: 188 passed, 0 failed, 2 ignored.
  • Portable clippy and CARGO_FEATURE_PURE=1 cargo clippy -p victory-shader --all-targets --target x86_64-pc-windows-msvc -- -D warnings: clean.

Not run here: the GPU case, since I have no Windows machine.

🤖 Generated with Claude Code

**@⁠lcg007xd-c** on GitHub · 2026-11-25 22:09 UTC · [original](https://github.com/uiliannn/VItoriaBr/pull/84) `lcg007xd-c:shader-cvt-off-f32-i4` → `main` · +64 −0 · 2 files · 1 commits · open ## What is broken `v_cvt_off_f32_i4` (VOP1 **0x0E**, VOP3 **0x18E**) decodes, but a program using it fails to translate with `v_cvt_off_f32_i4 is not supported`. I found it by translating a one-instruction program for every opcode the decoder names. AMD's ISA describes it as "used for interpolation in shader": it turns a 4-bit sample offset into a float. ## Semantics AMD's RDNA2 ISA (§12.8, opcode 14) gives a table. `S0[3:0]`, read as a signed nibble, maps to nibble/16: `1000` → −0.5, `1111` → −0.0625, `0000` → 0, and `0111` → 0.4375. The other bits of S0 do not count. ## The change (`emit/lower.rs`, in `valu_op`) - **Conversion:** the nibble is sign-extended (shift left 28, arithmetic right 28), converted to f32, and multiplied by 1/16. Both steps are exact for every nibble. - **Modifiers:** `omod` and clamp apply through `write_f`, as for any f32 result. ## Tests - **`emit::lower::tests::nibble_offset_conversion_translates`** (every host): the VOP1 and VOP3 forms decode to the name, and a program that **stores** the result translates. Without the `lower.rs` change it fails with `v_cvt_off_f32_i4 is not supported`. - **`valu_tests::v_cvt_off_f32_i4_matches_the_isa_table`** (Windows/GPU): all 16 nibbles, with junk in bits 31:4. - **CPU run:** I ran the ISA's table, typed in literally, on Linux through the CPU harness of #62, which runs the emitted DXIL with LLVM's `lli`. I checked both encodings, plus `omod ×4` (0.4375 → 1.75) and clamp (−0.5 → 0). All match. **Run here** (Linux, Rust 1.98.1): - `cargo test -p victory-shader --lib --locked`: 188 passed, 0 failed, 2 ignored. - Portable clippy and `CARGO_FEATURE_PURE=1 cargo clippy -p victory-shader --all-targets --target x86_64-pc-windows-msvc -- -D warnings`: clean. **Not run here:** the GPU case, since I have no Windows machine. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
VOP1 0x0E (VOP3 0x18E) decoded but failed to translate
("v_cvt_off_f32_i4 is not supported"). AMD's RDNA2 ISA gives it as a
table: S0[3:0] read as a signed nibble, over 16 (1000 -> -0.5, 0111 ->
0.4375), "used for interpolation". It lowers as the sign-extended nibble
converted to f32 times 1/16, which is exact; omod and clamp apply as for
any f32 result.

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:33 +00:00
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/84/head:github-bot/gh-84'
git switch 'github-bot/gh-84'

Merge

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