Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/design.md
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ How the generated SPIR-V expects the runtime to work:
| `v_mqsad_u32_u8` | Four masked byte-SADs with full 32-bit accumulators: D[k] = S2[k] + `v_msad_u8` of the 32-bit window S0[8k+31:8k] of the 64-bit S0 against S1, wrapping at 32 bits (S2 and D are four VGPRs). Every source is read before the first write; `clamp` raises `Unsupported`. Source: RDNA ISA pseudocode. CPU-checked by `tests/semantic/test_alu_mqsad_u32.py`. **Hardware-verified on RDNA2** (`gfx1035`, wave32 and wave64 via `tools/int_hw_probe.py --oracle both`, SHADER-137). Measured on native gfx1036 (AMD Radeon Graphics, RDNA2) through tools/hw_oracle across 64-bit sliding window and masked byte values against the 32-bit accumulators: bit-exact with the ISA reference. |
| `s_sext_i32_i8`, `s_sext_i32_i16`, `s_flbit_i32` | The first two sign-extend the low byte or the low half of S0 to 32 bits (`OpBitFieldSExtract`). `s_flbit_i32` counts how many bits in a row from the MSB equal the sign bit, and gives −1 when all bits are the same (0 and −1); it is the scalar form of `v_ffbh_i32` and goes through the same code. None of the three writes SCC. Source: RDNA2 ISA SOP1 opcodes 23, 25 and 26. CPU-checked by `tests/semantic/test_salu_sext_flbit.py` (#549): edge words with SCC starting at 0 and at 1, and 30 seeded values with long runs of sign bits. Not in the translated corpus, not GPU-checked. **Hardware-verified on RDNA2** (`gfx1035`, wave32 and wave64 via `tools/int_hw_probe.py --oracle both`, SHADER-137, SCC kept). Measured on native gfx1036 (AMD Radeon Graphics, RDNA2) through tools/hw_oracle and tools/salu_diff.py (500 programs, --oracle translator,hw): 500 pass, 0 mismatches against the reference; confirmed s_flbit_i32 gives 0xFFFFFFFF for 0 and -1. |
| `v_lerp_u8` | Per byte i: `D.b[i] = (S0.b[i] + S1.b[i] + (S2.b[i] & 1)) >> 1`, an unsigned average where bit 0 of S2's byte decides whether 0.5 rounds up. The translator uses the per-byte identity `x + y = 2*(x & y) + (x ^ y)`. It clears each byte's low bit before shifting, then adds the rounding bit only to an odd sum. Each result fits in one byte, so the packed additions do not carry across bytes. The 9-bit sum shifted right by 1 fits back in its byte, so nothing carries between bytes. `clamp` raises `Unsupported` (the ISA doesn't define it for this op). Source: RDNA2 ISA VOP3 opcode 333. CPU-checked by `tests/semantic/test_alu_lerp_u8.py` (#577): a 9×9×5 grid of edge and rounding words, 40 seeded cases, an SGPR source with an inline S2, `clamp` rejected. The synthetic `tests/semantic/fixtures/lerp_packed_bytes.asm` gives exact words across a 64x64 draw on an RTX 3070 (NVIDIA 591.86). Not in the translated corpus, not GPU-checked. **Hardware-verified on RDNA2** (`gfx1035`, wave32 and wave64 via `tools/int_hw_probe.py --oracle both`, SHADER-137). Measured on native gfx1036 (AMD Radeon Graphics, RDNA2) through tools/hw_oracle across byte edge values and rounding bit variations: 0 mismatches against the ISA reference. |
| `v_sat_pk_u8_i16` | `D[15:0] = {sat_u8(S0[31:16].i16), sat_u8(S0[15:0].i16)}`: each signed i16 lane of S0 saturates to an unsigned byte and packs into the low 16 bits of D (AMD machine-readable ISA semantics, VOP1 0x62 / VOP3 0x1E2). The 16-bit result keeps the destination's high half, the same partial write as `v_cvt_f16_f32` (Mesa ACO `instr_is_16bit`); under `_sdwa` `dst_sel`/`dst_unused` decide instead. Source `neg`/`abs`, `clamp` and output modifiers raise `Unsupported` rather than being guessed. CPU-checked by `tests/semantic/test_alu_sat_pk_u8_i16.py` (hand-written `tests/semantic/fixtures/sat_pk_u8_i16.asm`, lane edge values, SGPR/literal/inline sources, `_sdwa` source and destination selects, refused modifiers) against a plain-Python reference. Not in the 26,503-shader corpus (listed in `docs/fssm_crosscheck.md`), not GPU-verified. |
| Scalar select and pack (`s_cmov_b32`, `s_cmovk_i32`, `s_cmov_b64`, `s_pack_ll/lh/hh_b32_b16`) | `s_cmov_b32` / `s_cmovk_i32`: D = SCC ? S0 : D (`s_cmovk_i32`'s S0 is the 16-bit immediate, sign-extended); SCC is read, not written; the destination must be an SGPR (a lane-mask destination stays `Unsupported`, #210). `s_cmov_b64`: D[63:0] = SCC ? S0[63:0] : D[63:0] on plain 64-bit data pairs (SGPR pair, immediate or `null`), SCC read and not written; a pair that is or has been a lane mask (EXEC, VCC or a mask SGPR) stays `Unsupported` (#210) — conservatively, because a CFG join can drop a register that is a mask on only one path — while 0/-1 EITHER constants are data; selecting a per-lane bit as data would silently return a bool instead of the wave's mask. D[63:0] on plain 64-bit data pairs (SGPR pair, immediate or `null`), SCC read and not written; a pair that is or has been a lane mask stays `Unsupported` (#210). D[63:0], SCC read and not written, on plain 64-bit data pairs (SGPR pair, immediate or `null`); any dword that is or has been a lane mask (EXEC, VCC or a mask SGPR) makes the pair `Unsupported` — conservatively, because a CFG join can drop a register that is a mask on only one path — while 0/-1 EITHER constants are data; selecting a per-lane bit as data would silently return a bool instead of the wave's mask (#210). `s_pack_*`: the low half of D from S0, the high half from S1, the letters naming the half of each (l = 15:0, h = 31:16), S0 first; GFX10 has no `s_pack_hl`; SCC not written. Source: RDNA2 ISA SOP1/SOP2/SOPK and LLVM AMDGPU `SOPInstructions.td` (`S_CMOV_B64 : RDNA2 ISA SOP1/SOP2/SOPK. CPU-checked by `tests/semantic/test_salu_cmov.py` and `test_salu_pack.py`; the translated shaders were run on NVIDIA by reviewers (`s_cmov*`: RDNA2 ISA SOP1/SOP2/SOPK and LLVM AMDGPU [SOPInstructions.td](https://github.com/llvm/llvm-project/blob/2bfedf3338162e2c841a73cd7cd9e98d00add608/llvm/lib/Target/AMDGPU/SOPInstructions.td) (`S_CMOV_B64 : SOP1_64` under `Uses = [SCC]`). CPU-checked by `tests/semantic/test_salu_cmov.py`, `tests/semantic/test_salu_cmov_b64.py` and `test_salu_pack.py`; no corpus count; **not GPU-verified, no corpus count**; the translated shaders were run on NVIDIA by reviewers (`s_cmov_b32/k_i32`: **no corpus count**; Hardware: on native `gfx1036` (Ryzen 9 9950X3D iGPU, Windows 11, driver 26.10.1) `tools/int_hw_probe.py --oracle both --wave both` matches the translator in wave32 and wave64 for all five `salu_cmov_pack` cases and for the 14 `s_cmov_b64` cases (`--group salu_cmov_b64`: GPU-checked for `s_cmov_b32` (`cs_w32_salu64.asm`, SCC = 1 selects S0) and `s_pack_lh_b32_b16` (`cs_w32_int_ext.asm`) on the Radeon iGPU of a Ryzen 9 9950X3D (RDNA2, `gfx1036`, driver 26.10.1) and an RTX 5080 (driver 616.92); `s_cmovk_i32`, `s_cmov_b64` and the other `s_pack_*` forms have no GPU test on main; the translated shaders were also run on NVIDIA by reviewers (`s_cmov_b32/k_i32`: RTX 5090, RTX 4050 and Radeon 740M in #613; `s_pack_*`: RTX 5090 in #449). **Hardware-verified on RDNA2** (`gfx1035`, wave32 and wave64 via `tools/int_hw_probe.py --oracle both`, SHADER-137, SCC kept), and on native gfx1036 (AMD Radeon Graphics, Windows 11, driver 26.10.1) through `tools/hw_oracle`: all five `salu_cmov_pack` cases and the 14 `s_cmov_b64` cases match the translator in wave32 and wave64 (SCC 0 and 1; an SGPR pair, the inline constants -1/-16/64, the literal 0x89abcdef, `null` and the destination itself; SCC = 1 takes S0, 0 keeps D, SCC is never written), `s_cmov_b32` matches under SCC=0 and SCC=1, and `s_pack_ll/lh/hh_b32_b16` is bit-exact on 500 random programs with 0 mismatches (`--oracle translator,hw`). **Hardware-verified on RDNA2** (`gfx1035`, wave32 and wave64 via `tools/int_hw_probe.py --oracle both`, SHADER-137, SCC kept). Also **measured on RDNA2 gfx1036** (Radeon iGPU of a Ryzen 9 9950X3D, Windows 11, driver 26.10.1, `tools/hw_oracle` HIP launcher, rocm-sdk-core clang): `tools/int_hw_probe.py --oracle both --wave both` gives the same words as the translator for all five `salu_cmov_pack` cases in wave32 and wave64, and the 14 `s_cmov_b64` cases of the `salu_cmov_b64` group (`python -I tools/int_hw_probe.py --oracle both --wave both --group salu_cmov_b64`; SCC 0 and 1; source an SGPR pair, the inline constants -1, -16 and 64, the literal 0x89abcdef, `null`, and the destination itself; SCC preset and read back after): SCC preset and read back after) match the translator in wave32 and wave64: SCC = 1 takes S0 (a literal zero-extended, an inline constant sign-extended, `null` gives 0), SCC = 0 keeps D, SCC is never written. Also on `gfx1035` via `int_hw_probe` (SHADER-137, SCC kept), and on `gfx1036` and an RTX 5080 through the fixtures `cs_w32_salu64.asm` (`s_cmov_b32`) and `cs_w32_int_ext.asm` (`s_pack_lh_b32_b16`). `tools/hw_oracle` + `tools/salu_diff.py` verify `s_cmov_b32` under SCC 0/1 and `s_pack_ll/lh/hh_b32_b16` bit-exact on 500 random programs with 0 mismatches. Reviewers ran `s_cmov*` on an RTX 5090, an RTX 4050 and a Radeon 740M (#613) and `s_pack_*` on an RTX 5090 (#449). Measured on native gfx1036 (AMD Radeon Graphics, RDNA2) through tools/hw_oracle and tools/salu_diff.py: s_cmov_b32 verified under SCC=0 and SCC=1 (preserving destination and updating respectively); s_pack_ll/lh/hh_b32_b16 verified bit-exact on 500 random programs with 0 mismatches (--oracle translator,hw). **Not measured on RDNA2.** |
| `v_bfi_b32` | `(S0 & S1) \| (~S0 & S2)` (RDNA2 ISA, VOP3 opcode 330). A literal or known same-block SGPR mask of zero or all ones selects S2 or S1 directly. A contiguous mask uses `OpBitFieldInsert` with S1 shifted down by the field offset, since RDNA2 reads the bits in place. For sparse constant masks the translator precomputes the complement. Runtime masks use the full bitwise expression. Checked by the hand-written `bfi_known_mask.asm` and `tests/semantic/test_bfi_known_mask.py`. |
| `v_bfm_b32` | The low five bits of S0 give the width and those of S1 give the offset. The result is the low 32 bits of `((1 << width) - 1) << offset` (RDNA2 ISA §12.12, VOP3 opcode 867). Literal and same-block SGPR constants are folded in the translator, including zero width and shifts that discard the high bits. Runtime operands keep their low-five-bit masks. Checked by `tests/semantic/test_bfm_known_operands.py` and `test_alu_int_misc.py`. |
Expand Down
2 changes: 1 addition & 1 deletion docs/fssm_crosscheck.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ distinguish the readings. SHADER-190 remains open.
| The walker is length-aware; base widths plus a literal dword for 1-dword families. | `rdna2_classify.instr_length()` | Base widths are right. Confirmed gaps: `s_setreg_imm32_b32` is 2 dwords but `instr_length()` returns 1; 68 of 100 sampled shaders contain it (150 occurrences), so the walk drifts at the first one. `v_add_f32_e64 v0, v1, 0x12345678` is 3 dwords but VOP3 is always 2. `mimg_nsa()` is a stub and MIMG is always 2 words. `fssm_parse.instructions()` does not use `instr_length()` at all; it uses base widths only. | **Incomplete** |
| Branch targets resolve in-range 12,786/12,789 (SCARAB's corpus). | `fssm_parse.branch_report()`, `docs/fssm-analysis.md` | The SOPP branch opcodes (2, 4-9) and `i + 1 + simm16` are correct for gfx10. The check is self-consistent but cannot detect a constant `+0x10` start shift; Leonida's CFG builder additionally rejects a branch target outside the code range. | **Verified logic; not a correctness proof** |
| The vendor disassembler (`XBSC_DisassembleRawShader`) is the oracle; all 25,321 streams disassemble with no fault. | `docs/isa/shader-isa-notes.md`, `tools/xbsc_probe_notes.md` | Cannot be re-run here (no vendor DLL in this workspace). The claim is plausible; the output header's `asic(CI)` label is not reconciled with gfx1013 and should not be read as a distinct ISA. | **Unknown (not re-run)** |
| The 1,542-name list documents opcodes the Leonida translator lacks. | `docs/isa/xbsc-isa-mnemonics.txt` | It documents names, not encodings. Names present in the list and **not handled** by `rdna2spirv.py`: `v_sat_pk_u8_i16`, `v_screen_partition_4se_b32`, `v_mad_mix_f32`, `v_dot2c_f32_f16`, `v_dot4c_i32_i8`, `v_mul_hi_i32_i24`, `v_mul_hi_u32_u24`, `s_absdiff_i32`, `v_add_i32`, `v_sub_i32`, `image_msaa_load`, `s_ttracedata_imm`, `s_cbranch_g_fork`, `s_cbranch_i_fork`, `s_cbranch_join`, `s_set_gpr_idx_on`, `s_set_gpr_idx_off`, `s_set_gpr_idx_mode`. None of these is in the translated 26,503-shader corpus (otherwise translation would have rejected the shader), so they are future-proofing, not current blockers. | **Names only; not actionable now** |
| The 1,542-name list documents opcodes the Leonida translator lacks. | `docs/isa/xbsc-isa-mnemonics.txt` | It documents names, not encodings. Names present in the list and **not handled** by `rdna2spirv.py`: `v_screen_partition_4se_b32`, `v_mad_mix_f32`, `v_dot2c_f32_f16`, `v_dot4c_i32_i8`, `v_mul_hi_i32_i24`, `v_mul_hi_u32_u24`, `s_absdiff_i32`, `v_add_i32`, `v_sub_i32`, `image_msaa_load`, `s_ttracedata_imm`, `s_cbranch_g_fork`, `s_cbranch_i_fork`, `s_cbranch_join`, `s_set_gpr_idx_on`, `s_set_gpr_idx_off`, `s_set_gpr_idx_mode`. None of these is in the translated 26,503-shader corpus (otherwise translation would have rejected the shader), so they are future-proofing, not current blockers. | **Names only; not actionable now** |
| SCARAB's `rdna2_sweep` locates the first decoder rejection and decodes VOP3 modifier fields. | `src/rdna2_sweep.cpp` | It is a front-end coverage/boundary diagnostic: opcode coverage, word length, VOP3 `abs`/`op_sel`/`clamp`/`omod`/`neg` legality. It does **not** check register liveness, dataflow, control-flow semantics or output values. `spirv-val` checks the output module, not the input stream; neither one proves the translation. The differential-validation plan on Leonida's in-progress `shader-val` branch (`docs/shader_validation.md`, `tools/cpu_ref.py`) is the stronger class of check. | **Useful triage; not a substitute for `spirv-val` or differential tests** |
| SCARAB's `rdna2_recompile` produces SPIR-V for the corpus. | `src/rdna2_recompile.cpp` | In practice it always builds a **compute** request (`numThreads 64x1x1`, no header, no memory) even when `--stage` is parsed; the `stage` variable is not used by `BuildComputeRequest`. It cannot validate the VS/PS/GS/mesh ABI. | **Incomplete for this corpus** |
| The prior-art note concludes FSSM is inside the DXIL container and is not a direct `rgxe`/`SGD2` descendant; `FSSM`/`0x101`/`0xDEADBEEF` have no public prior art. | `docs/shader-container-prior-art.md` | The nesting is confirmed: `DXBC` precedes `FSSM`, and `FSSM` is the decompressed `XBCH` payload inside the `DXIL` chunk. The lineage and negative prior-art claims were not re-run. | **Nesting verified; lineage unknown** |
Expand Down
16 changes: 16 additions & 0 deletions tests/semantic/fixtures/sat_pk_u8_i16.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
; Each signed i16 lane of SRC0 saturates to an unsigned byte and packs into D[15:0]; the
; destination's high half is kept (the GFX10 16-bit partial write, as v_cvt_f16_f32).
; Expected MRT0 words: cafeff00 dead00ff 00008000 abcdffff.
v_mov_b32 v1, 0x0100fed4
v_mov_b32 v2, 0xcafebabe
v_sat_pk_u8_i16 v2, v1
v_mov_b32 v3, 0x80407fff
v_mov_b32 v4, 0xdeadbeef
v_sat_pk_u8_i16 v4, v3
v_mov_b32 v5, 0x00000000
v_mov_b32 v6, 0x0080ff00
v_sat_pk_u8_i16_e64 v5, v6
v_mov_b32 v7, 0xabcd0000
v_sat_pk_u8_i16 v7, 0x00ff0100
exp mrt0 v2, v4, v5, v7 done vm
s_endpgm
94 changes: 94 additions & 0 deletions tests/semantic/test_alu_sat_pk_u8_i16.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
"""v_sat_pk_u8_i16: each signed i16 lane of SRC0 saturates into a u8, packed into D[15:0].
Semantics from the AMD machine-readable RDNA2 ISA specification: D.b16 = {SAT8(S0[31:16].i16),
SAT8(S0[15:0].i16)} with SAT8(n) = 0 for n <= 0, 255 for n >= 255 and n[7:0] otherwise. On GFX10 the
16-bit result keeps the destination's high half, the same partial write as v_cvt_f16_f32 (Mesa ACO
instr_is_16bit); under _sdwa the dst_sel/dst_unused rule decides instead. Hand-written pixel-shader
listings are translated by tools/rdna2spirv.py and run by spirv_mini_interp.py; expected words are
hand-computed and checked against a plain-Python reference.
"""

from pathlib import Path
import unittest

from support import HERE, mrt0_words, translate_lines, translate_listing # noqa: F401
import rdna2spirv # noqa: E402 (sys.path set by support above)


def ref_sat_pk_u8_i16(s0):
def sat8(x):
if x & 0x8000:
x -= 0x10000
return 0 if x <= 0 else (255 if x >= 255 else x)

return sat8(s0 & 0xFFFF) | (sat8((s0 >> 16) & 0xFFFF) << 8)


class SatPkU8I16(unittest.TestCase):
def test_fixture(self):
fixture = Path(HERE) / "fixtures" / "sat_pk_u8_i16.asm"
text = translate_listing("ps_sat_pk_u8_i16", fixture.read_bytes())
self.assertEqual(mrt0_words(text), [0xCAFEFF00, 0xDEAD00FF, 0x00008000, 0xABCDFFFF])
self.assertEqual(text.count("OpExtInst %int %glsl SClamp"), 8)

def test_saturates_each_signed_lane_to_u8_and_keeps_high_half(self):
def run(s0, seed):
lines = [
f"v_mov_b32 v1, 0x{s0:08x}",
f"v_mov_b32 v2, 0x{seed:08x}",
"v_sat_pk_u8_i16 v2, v1",
"exp mrt0 v2, v2, v2, v2 done vm",
"s_endpgm",
]
return mrt0_words(translate_lines("ps_sat_pk", lines))[0]

for s0 in (0x00000000, 0x00FF0080, 0x0100FE00, 0x80007FFF,
0x7FFF8000, 0x00FFFEFE, 0x12345678):
for seed in (0x00000000, 0xDEADBEEF):
self.assertEqual(run(s0, seed), (seed & 0xFFFF0000) | ref_sat_pk_u8_i16(s0),
f"s0={s0:#010x} seed={seed:#010x}")

def test_sgpr_and_literal_sources(self):
text = translate_lines("ps_sat_pk_sgpr", [
"s_mov_b32 s0, 0x8040ff00",
"s_mov_b32 s8, m0",
"v_mov_b32 v1, 0x11111111",
"v_mov_b32 v2, 0x22222222",
"v_sat_pk_u8_i16 v1, s0",
"v_sat_pk_u8_i16 v2, 0x00ff0100",
"v_sat_pk_u8_i16 v3, -1",
"v_sat_pk_u8_i16 v4, 5",
"exp mrt0 v1, v2, v3, v4 done vm",
"s_endpgm",
])
self.assertEqual(mrt0_words(text), [0x11110000, 0x2222FFFF, 0x00000000, 0x00000005])

def test_sdwa_source_and_destination(self):
text = translate_lines("ps_sat_pk_sdwa", [
"v_mov_b32 v1, 0x1234fed4",
"v_mov_b32 v2, 0x0008ff40",
"v_mov_b32 v3, 0x12345678",
"v_sat_pk_u8_i16_sdwa v4, v1 dst_sel:DWORD dst_unused:UNUSED_PAD src0_sel:WORD_1",
"v_sat_pk_u8_i16_sdwa v3, v2 dst_sel:WORD_1 dst_unused:UNUSED_PRESERVE src0_sel:DWORD",
"v_sat_pk_u8_i16_sdwa v5, v1 dst_sel:DWORD dst_unused:UNUSED_PAD src0_sel:BYTE_0",
"exp mrt0 v4, v3, v5, v5 done vm",
"s_endpgm",
])
# WORD_1 zero-extends 0x1234: {sat(0x1234)=255, sat(0)=0} into a full DWORD write.
# WORD_1 dst keeps v3's low half: {sat(8)=8, sat(-192)=0} -> 0x0800 into bits 31:16.
# BYTE_0 zero-extends 0xd4: {sat(212)=212, sat(0)=0} into a full DWORD write.
self.assertEqual(mrt0_words(text), [0x000000FF, 0x08005678, 0x000000D4, 0x000000D4])

def test_modifiers_are_refused_not_guessed(self):
for line in ("v_sat_pk_u8_i16_e64 v2, -v1",
"v_sat_pk_u8_i16_e64 v2, |v1|",
"v_sat_pk_u8_i16_e64 v2, v1 clamp",
"v_sat_pk_u8_i16_e64 v2, v1 mul:2",
"v_sat_pk_u8_i16_sdwa v2, v1 dst_sel:DWORD dst_unused:UNUSED_PAD "
"src0_sel:WORD_1 clamp"):
with self.assertRaises(rdna2spirv.Unsupported, msg=line):
translate_lines("ps_sat_pk_bad", [line, "exp mrt0 v2, v2, v2, v2 done vm", "s_endpgm"])


if __name__ == "__main__":
unittest.main()
2 changes: 1 addition & 1 deletion tests/test_f16_op_sel.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,4 @@ def test_translation_is_deterministic(tmp_path):

def test_other_unsupported_instructions_are_still_rejected(tmp_path):
with pytest.raises(rdna2spirv.Unsupported):
translate(tmp_path, "v_sat_pk_u8_i16 v3, v1")
translate(tmp_path, "v_mullit_f32 v3, v1, v1, v1")
Loading
Loading