Skip to content
Open
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
2 changes: 2 additions & 0 deletions docs/design.md
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,8 @@ 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 translator writes the 16-bit result with `write_lo16`, which keeps the destination's high half, the same partial write as `v_cvt_f16_f32`; under `_sdwa` `dst_sel`/`dst_unused` decide instead. Keeping the high half is the translator's choice, **not measured** on RDNA2: neither Mesa ACO nor LLVM says what GFX10 does with it (next row, **References**). 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. |
| `v_sat_pk_u8_i16` on the wave64 halves path (SHADER-SATPK-HALVES) | `tools/wave64_halves.py` reads the old destination of `v_sat_pk_u8_i16` wherever the translator keeps its high half: the `_e32`, `_e64` and DPP forms (the 16-bit rule of `_preserves_dst`, and `partial_write`, which had taken the op's first type, `u8`, for an 8-bit result), and SDWA with a `BYTE`/`WORD` `dst_sel` and `UNUSED_PRESERVE`; SDWA with `dst_sel:DWORD`, `UNUSED_PAD` or `UNUSED_SEXT` writes the whole register. The op used to be in `_FULL32_V16_PREFIXES`, so a high half that depends on the lane lost its taint and the shader passed as tier A (or tier B through `readlane-uniform`), though its export changes when the wave is cut in two. The rule follows what the translator emits (`write_lo16`, row above); if RDNA2 turns out to zero the high half, calling the op a partial write stays safe and costs tier A at most. **References:** neither compiler says the high half is kept on GFX10. Mesa ACO's `instr_is_16bit` is false for the op before GFX11: it is not in the function's list, and `can_use_opsel` falls through to `get_gfx11_true16_mask`, which gives it 0x8 (the destination bit, as for `v_cvt_f16_f32`) for GFX11 and later only (`src/amd/compiler/aco_ir.cpp`, Mesa `99abc485`). LLVM defines it with `VOP1Inst_t16` (`VOP1Instructions.td`), which on GFX10 is the plain VOP1 instruction with an i16 result (`VOP_I16_I32`; the `_t16`/`_fake16` forms are GFX11 and later), and `GCNSubtarget::zeroesHigh16BitsOfDest` does not list it, so LLVM assumes neither a kept nor a zeroed high half (`llvm/lib/Target/AMDGPU`, LLVM `e2b0a1e1`). What the RDNA2 instruction does with the high half is **not measured**. CPU-checked by `tests/semantic/test_wave64_halves_sat_pk.py` (the hand-written `fixtures/w64_sat_pk_hi.asm`, whose high half is the lane id, run on the strict wave interpreter as 64 lanes and as two waves of 32 in every encoding, plus the `readlane-uniform` case) and by `tests/test_wave64_halves_fixtures.py` (`ps_w64_c_sat_pk_hi` must be tier C, `lane-id`). GPU: `ps_w64_a_sat_pk_hi` (tier A: the four encodings that keep the high half, a different high half per pixel, both halves of SRC0 saturating below 0 and above 255 across the target) gives its derived words on an NVIDIA RTX 4070 Ti (driver 620.70.06, Linux). NVIDIA runs the translated SPIR-V, so this confirms the translator's semantics, not the AMD instruction: the expected low half is the ISA pseudocode's SAT8 packing, the expected high half is the translator's rule. `ps_w64_c_sat_pk_hi` is a `SKIP` there (32 is the only fragment subgroup size; tier C needs a device that can require both 64 and 32, or `W64G_REF`). |
| 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
49 changes: 49 additions & 0 deletions runtime/test/shaders/ps_w64_a_sat_pk_hi.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
; SHADER-SATPK-HALVES tier A (docs/design.md, "v_sat_pk_u8_i16"): v_sat_pk_u8_i16 writes the low half of its VGPR and
; keeps the high half, in each encoding that keeps it (e32, e64, DPP, SDWA dst_sel:WORD_0 with UNUSED_PRESERVE). Every
; word is a function of the pixel, x = floor(u * 64), y = floor(v * 64) on the 64x64 target of vs_ids, so the shader
; gives the same exports when its 64 lanes are cut into two 32-lane subgroups (tools/wave64_halves.py: tier A).
; SRC0 = hi << 16 | lo with lo = 8x - 128 (-128..376 across x) and hi = 300 - 8y (300..-204 across y), 16 bits each:
; both signed halves saturate below 0 and above 255 across the target. s = sat8(hi) << 8 | sat8(lo), where sat8 clamps
; a signed 16-bit value to 0..255 (the ISA pseudocode). p = 64 * y + x. Each destination is seeded with its own high
; half (and a low half the write must replace):
; r0 = v_sat_pk_u8_i16_e32 into p << 16 | 0xa5a5: p << 16 | s
; r1 = v_sat_pk_u8_i16_e64 into (0xff00 - p) << 16 | 0x1234: (0xff00 - p) << 16 | s
; r2 = v_sat_pk_u8_i16_dpp (quad_perm identity, all rows and banks)
; into (p ^ 0x5555) << 16 | 0x0f0f: (p ^ 0x5555) << 16 | s
; r3 = v_sat_pk_u8_i16_sdwa dst_sel:WORD_0 dst_unused:UNUSED_PRESERVE
; into x << 24 | y << 16 | 0xffff: x << 24 | y << 16 | s
; The high halves are what the translator's write_lo16 keeps; expected on any Vulkan GPU, since the GPU runs the
; translated SPIR-V (this checks the translator, not the RDNA2 instruction itself).
; Run: vk_harness vs_ids.spv ps_w64_a_sat_pk_hi.spv out.raw, with VKH_SUBGROUP_SIZE=64 and 32 where both can be
; required: the two images equal each other and the words above.
; mattr: +wavefrontsize64,-wavefrontsize32
v_interp_p1_f32_e32 v2, v0, attr0.x
v_interp_p2_f32_e32 v2, v1, attr0.x
v_interp_p1_f32_e32 v3, v0, attr0.y
v_interp_p2_f32_e32 v3, v1, attr0.y
v_mul_f32_e32 v2, 0x42800000, v2
v_mul_f32_e32 v3, 0x42800000, v3
v_cvt_u32_f32_e32 v2, v2
v_cvt_u32_f32_e32 v3, v3
s_mov_b64 s[10:11], exec
v_lshlrev_b32_e32 v4, 3, v2
v_subrev_nc_u32_e32 v4, 0x80, v4
v_and_b32_e32 v4, 0xffff, v4
v_lshlrev_b32_e32 v5, 3, v3
v_sub_nc_u32_e32 v5, 0x12c, v5
v_lshl_or_b32 v4, v5, 16, v4
v_lshl_add_u32 v10, v3, 6, v2
v_lshl_or_b32 v6, v10, 16, 0xa5a5
v_sub_nc_u32_e32 v7, 0xff00, v10
v_lshl_or_b32 v7, v7, 16, 0x1234
v_xor_b32_e32 v8, 0x5555, v10
v_lshl_or_b32 v8, v8, 16, 0xf0f
v_lshlrev_b32_e32 v9, 8, v2
v_or_b32_e32 v9, v9, v3
v_lshl_or_b32 v9, v9, 16, 0xffff
v_sat_pk_u8_i16_e32 v6, v4
v_sat_pk_u8_i16_e64 v7, v4
v_sat_pk_u8_i16_dpp v8, v4 quad_perm:[0,1,2,3] row_mask:0xf bank_mask:0xf bound_ctrl:1
v_sat_pk_u8_i16_sdwa v9, v4 dst_sel:WORD_0 dst_unused:UNUSED_PRESERVE src0_sel:DWORD
exp mrt0 v6, v7, v8, v9 done vm
s_endpgm
Loading
Loading