shader: lower v_sat_pk_u8_i16 #85

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

@⁠lcg007xd-c on GitHub · 2026-11-25 22:12 UTC · original
lcg007xd-c:shader-sat-pk-u8 → main · +78 −0 · 2 files · 1 commits · open

What is broken

v_sat_pk_u8_i16 (VOP1 0x62, VOP3 0x1E2) decodes, but a program using it fails to translate with v_sat_pk_u8_i16 is not supported. I found it by translating a one-instruction program for every opcode the decoder names. It packs two signed 16-bit values into two bytes. Mesa's ACO also lists it for gfx10 (aco_opcodes.py, gfx10=0x62).

Semantics

AMD's RDNA2 ISA (§12.8, opcode 98) defines it as D.u32 = {16'b0, sat8(S0[31:16]), sat8(S0[15:0])}. Each half is a signed 16-bit value clamped to [0, 255]. The low half goes to byte 0, the high half to byte 1, and the top 16 bits are 0.

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

Each half is sign-extended, clamped to [0, 255] and placed in its byte.

Tests

  • emit::lower::tests::saturating_byte_pack_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: v_sat_pk_u8_i16 [7e00c501, 7e000000]: GFX10 code at 0x24: v_sat_pk_u8_i16 is not supported.
  • valu_tests::v_sat_pk_u8_i16_clamps_each_signed_half_to_a_byte (Windows/GPU): in-range halves, 255/256, −32768/−1, and 32767/128.
  • CPU run: I ran these on Linux through the CPU harness of #62, which runs the emitted DXIL with LLVM's lli. I compared both encodings against Rust's i16::clamp on 306 inputs (300 scrambled patterns 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. The top 16 bits follow the ISA's 16'b0. I could not check on RDNA2 hardware whether it keeps the destination's high half instead, as some 16-bit results do on GFX10.

🤖 Generated with Claude Code

**@⁠lcg007xd-c** on GitHub · 2026-11-25 22:12 UTC · [original](https://github.com/uiliannn/VItoriaBr/pull/85) `lcg007xd-c:shader-sat-pk-u8` → `main` · +78 −0 · 2 files · 1 commits · open ## What is broken `v_sat_pk_u8_i16` (VOP1 **0x62**, VOP3 **0x1E2**) decodes, but a program using it fails to translate with `v_sat_pk_u8_i16 is not supported`. I found it by translating a one-instruction program for every opcode the decoder names. It packs two signed 16-bit values into two bytes. Mesa's ACO also lists it for gfx10 (`aco_opcodes.py`, `gfx10=0x62`). ## Semantics AMD's RDNA2 ISA (§12.8, opcode 98) defines it as `D.u32 = {16'b0, sat8(S0[31:16]), sat8(S0[15:0])}`. Each half is a signed 16-bit value clamped to [0, 255]. The low half goes to byte 0, the high half to byte 1, and the top 16 bits are 0. ## The change (`emit/lower.rs`, in `integer`) Each half is sign-extended, clamped to [0, 255] and placed in its byte. ## Tests - **`emit::lower::tests::saturating_byte_pack_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: `v_sat_pk_u8_i16 [7e00c501, 7e000000]: GFX10 code at 0x24: v_sat_pk_u8_i16 is not supported`. - **`valu_tests::v_sat_pk_u8_i16_clamps_each_signed_half_to_a_byte`** (Windows/GPU): in-range halves, 255/256, −32768/−1, and 32767/128. - **CPU run:** I ran these on Linux through the CPU harness of #62, which runs the emitted DXIL with LLVM's `lli`. I compared both encodings against Rust's `i16::clamp` on 306 inputs (300 scrambled patterns 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. The top 16 bits follow the ISA's `16'b0`. I could not check on RDNA2 hardware whether it keeps the destination's high half instead, as some 16-bit results do on GFX10. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
VOP1 0x62 (VOP3 0x1E2) decoded but failed to translate
("v_sat_pk_u8_i16 is not supported"). AMD's RDNA2 ISA:
D.u32 = {16'b0, sat8(S0[31:16]), sat8(S0[15:0])}, each half a signed
16-bit value clamped to [0, 255].

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

Merge

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