shader: lower s_pack_*_b32_b16, s_bfm_b64, s_bitreplicate_b64_b32 and v_mad_u32_u16 #84

Manually merged
github merged 2 commits from github-bot/gh-84 into main 2026-11-26 15:11:45 +00:00 AGit
Owner

@⁠Olima34 on GitHub · 2026-11-26 13:52 UTC · original
Olima34:fix/shader-six-opcodes → main · +216 −3 · 4 files · 2 commits · merged 2026-11-26 15:08 UTC

What this changes

In the tester logs of #66 and #68, 10 title shaders are first refused on s_pack_ll_b32_b16 (3), s_pack_hh_b32_b16 (1), s_bitreplicate_b64_b32 (4), s_bfm_b64 (1) or v_mad_u32_u16 (1). They were decoded but had no lowering. This lowers them, with s_pack_lh_b32_b16 for the family, from the RDNA2 ISA reference (cross-checked with LLVM's SOPInstructions.td and VOP3Instructions.td):

Opcode Result SCC
s_pack_ll_b32_b16 S1[15:0] << 16 | S0[15:0] no
s_pack_lh_b32_b16 S1[31:16] << 16 | S0[15:0] no
s_pack_hh_b32_b16 S1[31:16] << 16 | S0[31:16] no
s_bfm_b64 ((1 << S0[5:0]) - 1) << S1[5:0] in 64 bits no
s_bitreplicate_b64_b32 bit i of S0 to bits 2i and 2i+1 no
v_mad_u32_u16 S0.u16 * S1.u16 + S2.u32, wrapping; op_sel bits 0 and 1 pick the high halves n/a

ir::writes_scc already agrees that the scalar ones write no SCC. v_mad_u32_u16's op_sel bits 2 and 3 (the 32-bit S2 and D) are undefined in the manual, so they are refused rather than guessed, as are integer source modifiers. The manual's summary table gives s_bfm_b64 5-bit fields, its opcode entry 6-bit ones; the entry is followed.

Tests: a hand-assembled translation test (llvm-mc -mcpu=gfx1030) in gfx_refusal_tests.rs covering all six, with op_sel combinations and wave32 on and off (fails on main with "s_pack_ll_b32_b16 is not supported"), and value probes in semantics_tests.rs for the Windows CI (edge values, s_bfm_b64 widths and offsets 0 to 65, the four op_sel combinations, a wrapping sum). Whether these 10 shaders now translate end to end still needs a live run: they may meet another refusal next.

How it was tested

  • cargo test -p victory-shader (the value probes run only in the Windows CI)
  • cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings, also with --all-features
  • arm64 cargo test --workspace and cargo xtask policy
  • Ran the game: not done, no copy of it here

Checklist

  • No game files, game code, disassembly listings or SDK files are included
  • Guesses about undocumented console behaviour are marked in the code and in docs/native-host.md
  • New diagnostics are behind a VICTORY_* variable and documented (none added)
**@⁠Olima34** on GitHub · 2026-11-26 13:52 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/84) `Olima34:fix/shader-six-opcodes` → `main` · +216 −3 · 4 files · 2 commits · merged 2026-11-26 15:08 UTC ## What this changes In the tester logs of #66 and #68, 10 title shaders are first refused on `s_pack_ll_b32_b16` (3), `s_pack_hh_b32_b16` (1), `s_bitreplicate_b64_b32` (4), `s_bfm_b64` (1) or `v_mad_u32_u16` (1). They were decoded but had no lowering. This lowers them, with `s_pack_lh_b32_b16` for the family, from the RDNA2 ISA reference (cross-checked with LLVM's `SOPInstructions.td` and `VOP3Instructions.td`): | Opcode | Result | SCC | |---|---|---| | `s_pack_ll_b32_b16` | `S1[15:0] << 16 \| S0[15:0]` | no | | `s_pack_lh_b32_b16` | `S1[31:16] << 16 \| S0[15:0]` | no | | `s_pack_hh_b32_b16` | `S1[31:16] << 16 \| S0[31:16]` | no | | `s_bfm_b64` | `((1 << S0[5:0]) - 1) << S1[5:0]` in 64 bits | no | | `s_bitreplicate_b64_b32` | bit i of S0 to bits 2i and 2i+1 | no | | `v_mad_u32_u16` | `S0.u16 * S1.u16 + S2.u32`, wrapping; op_sel bits 0 and 1 pick the high halves | n/a | `ir::writes_scc` already agrees that the scalar ones write no SCC. `v_mad_u32_u16`'s op_sel bits 2 and 3 (the 32-bit S2 and D) are undefined in the manual, so they are refused rather than guessed, as are integer source modifiers. The manual's summary table gives `s_bfm_b64` 5-bit fields, its opcode entry 6-bit ones; the entry is followed. Tests: a hand-assembled translation test (`llvm-mc -mcpu=gfx1030`) in `gfx_refusal_tests.rs` covering all six, with op_sel combinations and wave32 on and off (fails on `main` with "s_pack_ll_b32_b16 is not supported"), and value probes in `semantics_tests.rs` for the Windows CI (edge values, `s_bfm_b64` widths and offsets 0 to 65, the four op_sel combinations, a wrapping sum). Whether these 10 shaders now translate end to end still needs a live run: they may meet another refusal next. ## How it was tested - [x] `cargo test -p victory-shader` (the value probes run only in the Windows CI) - [x] `cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings`, also with `--all-features` - [x] arm64 `cargo test --workspace` and `cargo xtask policy` - [ ] Ran the game: not done, no copy of it here ## Checklist - [x] No game files, game code, disassembly listings or SDK files are included - [x] Guesses about undocumented console behaviour are marked in the code and in docs/native-host.md - [x] New diagnostics are behind a `VICTORY_*` variable and documented (none added)
Ten title shaders in the tester logs of issues #66 and #68 were first
refused on one of these decoded-but-unlowered opcodes.

Semantics from the AMD RDNA2 ISA reference guide (opcode tables):
- s_pack_ll/lh/hh_b32_b16 (SOP2 50-52): D = {S1 half, S0 half}
- s_bfm_b64 (SOP2 37): ((1 << S0[5:0]) - 1) << S1[5:0], in 64 bits
- s_bitreplicate_b64_b32 (SOP1 59): bit i of S0 to bits 2i and 2i+1
- v_mad_u32_u16 (VOP3 883): S0.u16 * S1.u16 + S2.u32, wrapping;
  op_sel bits 0/1 pick the high halves (table 21, opcodes usable with
  OPSEL). Bits 2/3 and source modifiers are refused, not guessed.
None of them writes SCC (ISA summary table; LLVM SOPInstructions.td
gives them no SCC def), which ir::writes_scc already agrees with.

Tests: hand-assembled pixel-shader programs (llvm-mc -mcpu=gfx1030) in
gfx_refusal_tests.rs that fail without the change, and Windows value
probes in semantics_tests.rs (count edges 32+ for s_bfm_b64, all op_sel
combinations and wrapping carries for v_mad_u32_u16).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 14:45:28 +00:00
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-26 14:54 UTC · original · approved these changes

Thanks, the opcode numbers and semantics check out, and refusing op_sel bits 2-3 is the right call.

**@⁠LakshanSivakumar** on GitHub · 2026-11-26 14:54 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/84#pullrequestreview-6076249342) · **approved these changes** Thanks, the opcode numbers and semantics check out, and refusing op_sel bits 2-3 is the right call.
github manually merged commit 515f5a8da2 into main 2026-11-26 15:11:45 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.