shader: lower v_lerp_u8 #86

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

@⁠lcg007xd-c on GitHub · 2026-11-25 22:14 UTC · original
lcg007xd-c:shader-lerp-u8 → main · +85 −0 · 2 files · 1 commits · open

What is broken

v_lerp_u8 (VOP3 0x14D) decodes, but a program using it fails to translate with v_lerp_u8 is not supported. I found it by translating a one-instruction program for every VOP3 opcode the decoder names. It averages packed unsigned bytes, the usual way to blend two RGBA8 values.

Semantics

AMD's RDNA2 ISA (§12.12, opcode 333) defines it as an "unsigned 8-bit pixel average on packed unsigned bytes": D.u[8i+7:8i] = (S0.u[8i+7:8i] + S1.u[8i+7:8i] + S2.u[8i]) >> 1. Bit 0 of each byte of S2 is the rounding bit: set rounds a .5 up, clear truncates it.

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

Per byte: extract both bytes, add them plus the rounding bit, shift right by one, and place the result back. No byte can carry into the next: the most is (255 + 255 + 1) >> 1 = 255.

Tests

  • emit::lower::tests::byte_average_translates (every host): the encoding decodes to the name, and a program that stores the result translates, with src2 a VGPR or an SGPR. Without the lower.rs change it fails: v_lerp_u8 [d54d0000, 040e0501]: GFX10 code at 0x24: v_lerp_u8 is not supported.
  • valu_tests::v_lerp_u8_averages_bytes_rounding_by_s2 (Windows/GPU): exact averages, .5 truncated and rounded up, 0xFF+0xFF with S2 bytes 0xFE/0xFF (only bit 0 counts), and mixed bytes.
  • CPU run: I ran these on Linux through the CPU harness of #62, which runs the emitted DXIL with LLVM's lli. I compared against a Rust reference on 203 inputs (200 scrambled triples plus edges). 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:14 UTC · [original](https://github.com/uiliannn/VItoriaBr/pull/86) `lcg007xd-c:shader-lerp-u8` → `main` · +85 −0 · 2 files · 1 commits · open ## What is broken `v_lerp_u8` (VOP3 **0x14D**) decodes, but a program using it fails to translate with `v_lerp_u8 is not supported`. I found it by translating a one-instruction program for every VOP3 opcode the decoder names. It averages packed unsigned bytes, the usual way to blend two RGBA8 values. ## Semantics AMD's RDNA2 ISA (§12.12, opcode 333) defines it as an "unsigned 8-bit pixel average on packed unsigned bytes": `D.u[8i+7:8i] = (S0.u[8i+7:8i] + S1.u[8i+7:8i] + S2.u[8i]) >> 1`. Bit 0 of each byte of S2 is the rounding bit: set rounds a .5 up, clear truncates it. ## The change (`emit/lower.rs`, in `integer`) Per byte: extract both bytes, add them plus the rounding bit, shift right by one, and place the result back. No byte can carry into the next: the most is `(255 + 255 + 1) >> 1 = 255`. ## Tests - **`emit::lower::tests::byte_average_translates`** (every host): the encoding decodes to the name, and a program that **stores** the result translates, with src2 a VGPR or an SGPR. Without the `lower.rs` change it fails: `v_lerp_u8 [d54d0000, 040e0501]: GFX10 code at 0x24: v_lerp_u8 is not supported`. - **`valu_tests::v_lerp_u8_averages_bytes_rounding_by_s2`** (Windows/GPU): exact averages, .5 truncated and rounded up, `0xFF+0xFF` with S2 bytes `0xFE`/`0xFF` (only bit 0 counts), and mixed bytes. - **CPU run:** I ran these on Linux through the CPU harness of #62, which runs the emitted DXIL with LLVM's `lli`. I compared against a Rust reference on 203 inputs (200 scrambled triples plus edges). 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)
VOP3 0x14D decoded but failed to translate ("v_lerp_u8 is not
supported"). AMD's RDNA2 ISA: each byte of the result is the average of
S0's and S1's bytes, rounded up when bit 0 of S2's byte is set:
(S0.u8 + S1.u8 + S2.u[8i]) >> 1.

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:36 +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/86/head:github-bot/gh-86'
git switch 'github-bot/gh-86'

Merge

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