diff --git a/docs/design.md b/docs/design.md index daeb4eb425..bf9ce1a612 100644 --- a/docs/design.md +++ b/docs/design.md @@ -330,7 +330,7 @@ How the generated SPIR-V expects the runtime to work: | `v_fmamk_f16`, `v_fmaak_f16` | VOP2 with a literal K: `fmamk` computes `D = S0 * K + S1` (printed `vdst, src0, K, vsrc1`), `fmaak` computes `D = S0 * S1 + K` (printed `vdst, src0, vsrc1, K`). In print order both are `a[1] * a[2] + a[3]`, as for `v_fmamk/fmaak_f32`. K is the f16 in the literal's low 16 bits; a float literal is converted to f16 (`src_h`). One rounding to f16, as `v_fmac_f16` (SHADER-55). The GFX10 f16 VOP2 write puts the result in the low half and keeps the high half. Until 2026-11-22 both raised `Unsupported`. CPU-checked by `tests/semantic/test_valu_fmamk_fmaak_f16.py`, against `v_fma_f16` with K in a VGPR (value grids, a float literal, the operand order, seeded values). **Hardware-measured natively on `gfx1100`** (RX 7900 XTX, driver 26.10.1) with `tools/hw_oracle`, 17 cases: the print order, the one-rounding rule and the kept high half hold (`1*2+3`, `1.5*2+0.5`, both orders, `(1+2^-10)*3` rounding the exact 3.0029296875 to the tie's even `0x4202`, `65504*2` overflowing to `+inf`); f16 VALU keeps denormals, unlike the LDS float adder, so `0x0001*1+0x0001` gives `0x0002`; an sNaN is quieted with its payload kept (`0x7c01` gives `0x7e01`) and `inf + -inf` gives the negative default `0xfe00`. **Not GPU-verified.** | | SDWA select on an f16 inline constant | In an `_sdwa` 16-bit float op, an inline float constant is first the f16 value over a zero high half (row above) and `src0_sel`/`src1_sel` then narrows those 32 bits like a register's, zero-extended, before neg/abs and the op: `1.0` under `WORD_1` reads +0.0, `2.0` under `BYTE_1` reads the f16 denormal `0x0040`. An SGPR source, and an integer op reading the f32 bits of a float constant (`v_cvt_f16_u16_sdwa d, 1.0 src0_sel:WORD_1` converts 0x3f80), are narrowed the same way. **Until 2026-11-22 the translator used the whole f16 constant** (`v_add_f16_sdwa d, 1.0, v src0_sel:WORD_1` with v = 0.5 gave 1.5). Measured on an AMD Radeon iGPU (gfx1036, Ryzen 9 9950X3D, driver 26.10.1) with `tools/hw_oracle` (raw HIP kernel, wave32): the four words of `runtime/test/shaders/ps_sdwa_f16_const.asm`; found with `python -I tools/sdwa_diff.py --oracle hw` (#2113). GPU test `ps_sdwa_f16_const`, 4096/4096 pixels on an NVIDIA GeForce RTX 5080 (driver 616.92) and the same Radeon iGPU through Vulkan; both fail without the fix. Also executed by `tests/semantic/test_value_semantics.py`. | | `v_pack_b32_f16` input `neg` | A VOP3 `neg` on an operand of this instruction flips the sign bit of **the 16-bit half that operand contributes**, not of the whole 32-bit source, and only that half: measured on gfx1036 (RDNA2 iGPU, AMD Windows driver 32.0.21044.64) with 192 raw kernels, `0x7c01` gives `0xfc01` under IEEE mode 0 and `0xfe01` under mode 1, in either half and with `op_sel`. The translator moved the bits unchanged and refused every modifier; it now XORs `0x8000` into the selected half. `abs` is implemented too: it clears bit 15 of the selected half before `neg` is applied, and the rule is measured on gfx1036 (1,088 raw kernels across wave32 and wave64, 0 mismatches; SHADER-260). The mode-1 quieting of a signalling-NaN half is not modelled while SHADER-190 is open; under mode 0, where the bits move unchanged, the translation is exact. Checked on the CPU by `tests/test_values.py` and `tests/semantic/test_vop3_const_mods.py`; the gfx1036 measurement above is @Sanonymous01's, not repeated here. | -| Packed 16-bit integer ops (`v_pk_add/sub_u16/i16`, `v_pk_mul_lo_u16`, `v_pk_mad_u16/i16`, `v_pk_max/min_u16/i16`) | VOP3P: result half 0 takes each source's half from `op_sel[i]`, result half 1 from `op_sel_hi[i]` (defaults `[0,..]` and `[1,..]`), as for `v_pk_lshlrev_b16`. Each half is computed on its own and wraps to 16 bits. `clamp` (add, sub, mad) saturates the half to its type's range (the exact value fits in 32 bits), whereas on `v_pk_mul_lo_u16` and `v_pk_max/min_u16/i16` VOP3P `clamp` is a hardware no-op (`v_pk_mul_lo_u16 clamp` wraps modulo 2^16 rather than saturating to `0xFFFF`, and `max`/`min` results are unchanged; until 2026-11-23 `clamp` on those five ops raised `Unsupported`). `neg_lo`/`neg_hi` are float-only and unsupported modifiers (such as `mul:*`/`div:*`) raise `Unsupported`. `clamp` (add, sub, mad) saturates the half to its type's range; the exact value fits in 32 bits. `neg_lo`/`neg_hi` are float-only and raise `Unsupported`, as does `clamp` on the other ops. A constant operand is treated as a 32-bit dword `C`: `op_sel[i] == 0` selects bits `[15:0]`, `op_sel[i] == 1` selects bits `[31:16]`. Positive inline constants zero-extend (`5` → `0x00000005`), negative inline constants sign-extend (`-1` → `0xFFFFFFFF`, `-16` → `0xFFFFFFF0`), and 32-bit literals retain their full dword (`0x12345678`). Lowered via `OpBitField*Extract` at `16 * sl[i]` (the packed 16-bit *shifts* read their halves with a shift and a mask instead, like every other high-half reader: see the 16-bit high-half reads row). Lowered via `OpBitField*Extract` at `16 * sl[i]`. Until 2026-11-22 reading the high half of a constant raised `Unsupported`. A constant operand reads as its low 16 bits. Its high half under `op_sel`/`op_sel_hi` is **not measured** for integer ops (for f16 constants it reads +0.0, see the row above), so a constant whose high half would be read raises `Unsupported` instead of guessing; the compiler's usual form, `op_sel_hi:[1,0]` with the constant second, reads only the low half. Until 2026-11-22 all eleven ops raised `Unsupported`. CPU-checked by `tests/semantic/test_alu_pk_int16.py` (value grids, seeded `mad`, `op_sel`/`op_sel_hi` combinations, `clamp` including the unsigned `sub` floor, inline and literal constants, rejected forms) and `tests/semantic/test_pk_int16_clamp.py` (all 26 probe cases plain vs `clamp`, SPIR-V non-saturation assertion, inactive `EXEC` preservation, `spirv-val` Vulkan 1.2 validation, rejected modifiers), plus `tests/test_pk_int16_clamp_probe.py`. **Hardware-verified on RDNA2** (`gfx1035`, Windows 11, driver `26.5.1`, wave32 & wave64 via `tools/int_hw_probe.py --oracle both --group valu_pk_int16`, and independently on `gfx1036` desktop APU, Windows 11, driver `32.0.21045.29003`, across 380 raw compute kernels covering all 11 ops, constants under `op_sel`/`op_sel_hi`, `clamp`, and wave32/wave64 parity with 0 wave diffs and 0 mismatches, and via `tools/pk_int16_clamp_probe.py --hw-arch gfx1036` across 624 wave32 & wave64 evaluations with `mismatches=0, wave_diffs=0, target_clamp_diffs=0, control_clamp_diffs=34`, plus a 96-word wave32 Vulkan compute check under `VK_LAYER_KHRONOS_validation` passing with 0 mismatches on `AMD Radeon RX 9070 XT` driver `26.11.2` and `AMD Radeon(TM) Graphics` driver `26.11.2`): all eleven ops (wrap, `clamp` saturation on add/sub/mad, `clamp` no-op on `mul_lo`/`max`/`min`, and constant `op_sel`/`op_sel_hi`) match bit-for-bit. CPU-checked by `tests/semantic/test_alu_pk_int16.py` (value grids, seeded `mad`, `op_sel`/`op_sel_hi` combinations, `clamp` including the unsigned `sub` floor, inline and literal constants, rejected forms). **Hardware-verified on RDNA2** (`gfx1035`, Windows 11, driver `26.5.1`, wave32 & wave64 via `tools/int_hw_probe.py --oracle both --group valu_pk_int16`, and independently on `gfx1036` desktop APU, Windows 11, driver `32.0.21045.29003`, across 380 raw compute kernels covering all 11 ops, constants under `op_sel`/`op_sel_hi`, `clamp`, and wave32/wave64 parity with 0 wave diffs and 0 mismatches): all eleven ops (wrap, `clamp` saturation on add/sub/mad, and constant `op_sel`/`op_sel_hi`) match bit-for-bit. **Not GPU-verified.** **Hardware-verified on RDNA2** (`gfx1035`, Windows 11, driver `26.5.1`, wave32 & wave64 via `tools/int_hw_probe.py --oracle both --group valu_pk_int16`): all eleven ops (wrap, `clamp` saturation on add/sub/mad, and `op_sel`/`op_sel_hi`) match bit-for-bit. **`v_pk_mul_lo_u16` low 16 bits (found with `pk16_diff --oracle hw,vk`, GPU test `cs_pk_mul_lo_const`):** each half is `((x << 16) * y) >> 16`, not `(x * y) & 0xffff`: with a constant half of 0 in the other half of the result the AMD Windows driver (Radeon iGPU gfx1036, 26.10.1) dropped the mask (`0x1234 * 0xaaaa` gave `0x0c229e88`, hardware `0x00009e88`); the RTX 5080 was right either way. Words measured on the same gfx1036 in `runtime/test/shaders/cs_pk_mul_lo_const.asm`. | +| Packed 16-bit integer ops (`v_pk_add/sub_u16/i16`, `v_pk_mul_lo_u16`, `v_pk_mad_u16/i16`, `v_pk_max/min_u16/i16`) | VOP3P: result half 0 takes each source's half from `op_sel[i]`, result half 1 from `op_sel_hi[i]` (defaults `[0,..]` and `[1,..]`), as for `v_pk_lshlrev_b16`. Each half is computed on its own and wraps to 16 bits. `clamp` (add, sub, mad) saturates the half to its type's range (the exact value fits in 32 bits), whereas on `v_pk_mul_lo_u16` and `v_pk_max/min_u16/i16` VOP3P `clamp` is a hardware no-op (`v_pk_mul_lo_u16 clamp` wraps modulo 2^16 rather than saturating to `0xFFFF`, and `max`/`min` results are unchanged; until 2026-11-23 `clamp` on those five ops raised `Unsupported`). `neg_lo`/`neg_hi` are float-only and unsupported modifiers (such as `mul:*`/`div:*`) raise `Unsupported`. `clamp` (add, sub, mad) saturates the half to its type's range; the exact value fits in 32 bits. `neg_lo`/`neg_hi` are float-only and raise `Unsupported`, as does `clamp` on the other ops. A constant operand is treated as a 32-bit dword `C`: `op_sel[i] == 0` selects bits `[15:0]`, `op_sel[i] == 1` selects bits `[31:16]`. Positive inline constants zero-extend (`5` → `0x00000005`), negative inline constants sign-extend (`-1` → `0xFFFFFFFF`, `-16` → `0xFFFFFFF0`), and 32-bit literals retain their full dword (`0x12345678`). Lowered via `OpBitField*Extract` at `16 * sl[i]` (the packed 16-bit *shifts* read their halves with a shift and a mask instead, like every other high-half reader: see the 16-bit high-half reads row). Lowered via `OpBitField*Extract` at `16 * sl[i]`. Until 2026-11-22 reading the high half of a constant raised `Unsupported`. A constant operand reads as its low 16 bits. Its high half under `op_sel`/`op_sel_hi` is **not measured** for integer ops (for f16 constants it reads +0.0, see the row above), so a constant whose high half would be read raises `Unsupported` instead of guessing; the compiler's usual form, `op_sel_hi:[1,0]` with the constant second, reads only the low half. Until 2026-11-22 all eleven ops raised `Unsupported`. CPU-checked by `tests/semantic/test_alu_pk_int16.py` (value grids, seeded `mad`, `op_sel`/`op_sel_hi` combinations, `clamp` including the unsigned `sub` floor, inline and literal constants, rejected forms) and `tests/semantic/test_pk_int16_clamp.py` (all 26 probe cases plain vs `clamp`, SPIR-V non-saturation assertion, inactive `EXEC` preservation, `spirv-val` Vulkan 1.2 validation, rejected modifiers), plus `tests/test_pk_int16_clamp_probe.py`. **Hardware-verified on RDNA2** (`gfx1035`, Windows 11, driver `26.5.1`, wave32 & wave64 via `tools/int_hw_probe.py --oracle both --group valu_pk_int16`, and independently on `gfx1036` desktop APU, Windows 11, driver `32.0.21045.29003`, across 380 raw compute kernels covering all 11 ops, constants under `op_sel`/`op_sel_hi`, `clamp`, and wave32/wave64 parity with 0 wave diffs and 0 mismatches, and via `tools/pk_int16_clamp_probe.py --hw-arch gfx1036` across 624 wave32 & wave64 evaluations with `mismatches=0, wave_diffs=0, target_clamp_diffs=0, control_clamp_diffs=34`, plus a 96-word wave32 Vulkan compute check under `VK_LAYER_KHRONOS_validation` passing with 0 mismatches on `AMD Radeon RX 9070 XT` driver `26.11.2` and `AMD Radeon(TM) Graphics` driver `26.11.2`): all eleven ops (wrap, `clamp` saturation on add/sub/mad, `clamp` no-op on `mul_lo`/`max`/`min`, and constant `op_sel`/`op_sel_hi`) match bit-for-bit. CPU-checked by `tests/semantic/test_alu_pk_int16.py` (value grids, seeded `mad`, `op_sel`/`op_sel_hi` combinations, `clamp` including the unsigned `sub` floor, inline and literal constants, rejected forms). **Hardware-verified on RDNA2** (`gfx1035`, Windows 11, driver `26.5.1`, wave32 & wave64 via `tools/int_hw_probe.py --oracle both --group valu_pk_int16`, and independently on `gfx1036` desktop APU, Windows 11, driver `32.0.21045.29003`, across 380 raw compute kernels covering all 11 ops, constants under `op_sel`/`op_sel_hi`, `clamp`, and wave32/wave64 parity with 0 wave diffs and 0 mismatches): all eleven ops (wrap, `clamp` saturation on add/sub/mad, and constant `op_sel`/`op_sel_hi`) match bit-for-bit. **Not GPU-verified.** **Hardware-verified on RDNA2** (`gfx1035`, Windows 11, driver `26.5.1`, wave32 & wave64 via `tools/int_hw_probe.py --oracle both --group valu_pk_int16`): all eleven ops (wrap, `clamp` saturation on add/sub/mad, and `op_sel`/`op_sel_hi`) match bit-for-bit. **`v_pk_mul_lo_u16` low 16 bits (found with `pk16_diff --oracle hw,vk`, GPU test `cs_pk_mul_lo_const`):** each half is `((x << 16) * y) >> 16`, not `(x * y) & 0xffff`: with a constant half of 0 in the other half of the result the AMD Windows driver (Radeon iGPU gfx1036, 26.10.1) dropped the mask (`0x1234 * 0xaaaa` gave `0x0c229e88`, hardware `0x00009e88`); the RTX 5080 was right either way. Words measured on the same gfx1036 in `runtime/test/shaders/cs_pk_mul_lo_const.asm`. GPU-checked through Vulkan on an RDNA2 iGPU (`gfx1036`, RADV `RAPHAEL_MENDOCINO`, Mesa 27.0.0-devel): `runtime/test/shaders/cs_pk_int16_u.asm` (the six u16 ops, `op_sel`/`op_sel_hi`, `clamp` on add and sub) and `cs_pk_int16_i.asm` (the five i16 ops, `op_sel`/`op_sel_hi`, `clamp` on add, sub and mad) each store their eight words, derived in the headers, 8/8 exact (16/16 words in all); `tests/semantic/test_pk_int16_gpu_fixtures.py` runs the same fixtures through the translator and the interpreter and keeps their headers, `CS_DUMPS` in `check.py` and `scripts/run_gpu_tests.py` in step. | | `v_sin_f32`, `v_cos_f32`, `v_sin_f16`, `v_cos_f16` | The operand is an angle in turns (the ISA says valid over +-256; the measurement below finds no such limit on gfx1030). `turn_angle` reduces it in turns first, `x - RoundEven(x)` (exact in binary32, in [-0.5, 0.5]), then scales by `2*pi` and calls `Sin`/`Cos`, so the angle stays in [-pi, pi], the only range where GLSL guarantees them (2^-11 absolute). Scaling first rounded the fractional turn away (about 1.2e-4 rad near 255 turns, #594); the first fix (#1283) reduced with `Fract`, which rounds `1 - \| x \| ` for a negative x and lost `-2^-26` (it returned +0; absolute errors up to ~1.7e-7 at -0.1 turns), so the reduction is `RoundEven`-centred. `RoundEven` rather than `Round` so +-0.5 turn reduce symmetrically. inf and NaN still give NaN, and a zero operand is passed through unreduced so `sin(-0)` stays -0. CPU-checked by `tests/semantic/test_alu_sincos.py` against `sin`/`cos(2*pi*x)` in double (large angles, tiny arguments, whole turns of either sign, +-0, inf/NaN, modifiers, f16) and `tests/semantic/test_valu_sin_cos_turns.py` (#1283). GPU test `cs_w32_sincos` (large angles within 1e-3, since the driver `Sin` is only good to 2^-11) is a regression guard, not proof the old form failed on a given driver. Measured on an AMD Radeon RX 6800 (gfx1030, not the console's gfx1013) by @shelbykb2 (#616): whole and half turns of either sign give +0 (only `sin(-0)` is -0, so no sign needs copying onto a zero result, as here); there is no +-256 limit on that card (any finite x reduces exactly: `sin(300.25)` = 1, `sin(2^24)` = +0); the f16 forms reduce the same way as the f32 ones; +-inf gives a NaN and a NaN passes through, quieted with IEEE mode on. Re-measured natively on gfx1036 (RDNA2, SHADER-134) for f32 and f16 over every quarter turn from 0.25 to 2^24 of either sign and around +-256: the same rules. At an odd half turn `sin`, and at an odd quarter turn `cos`, is exactly +0 (either sign of x), where `Sin`/`Cos` of the rounded 2*pi give about -+8.7e-8 (f32) or a +-1-ulp f16 denormal; since 2026-11-22 the translator selects +0 there (`Gen.trig_exact_zero`), checked against 500 measured words by `tests/semantic/test_alu_sincos_turns_hw.py`. Known differences from this translation: for Known differences from this translation: at half turns `Sin` of the rounded pi gives about -+8.7e-8 where the hardware returns exactly 0, likewise `cos` at quarter turns; for \| x \| <= 2^-12 the hardware multiplies by `0x40c90fd5`, not the rounded 2*pi; the inf/NaN words are whatever the host driver returns. Not checked on gfx1013. | | `v_pack_b32_f16` source modifiers | A VOP3 `abs` or `neg` on an operand of this instruction acts on **the 16-bit half that operand contributes**, not on the whole 32-bit source, and only on that half: `abs` clears bit 15 and `neg` flips it, `abs` first, both as plain bit moves — the operand is not converted to a float. Until 2026-11-22 any such operand was rejected as `Unsupported`. **`neg` is measured** on gfx1036 (RDNA2 iGPU, AMD Windows driver 32.0.21044.64) with 192 raw kernels: `0x7c01` gives `0xfc01` under IEEE mode 0 and `0xfe01` under mode 1, in either half and with `op_sel`, so the sign move does not depend on the mode. **`neg`, `abs`, and `neg_abs` are hardware-verified on RDNA2** across both `gfx1035` (Windows 11, driver 26.5.1, wave32 & wave64 via `tools/int_hw_probe.py --oracle both --group valu_pack_b32_f16_abs` and raw `ieee=0` kernels) and `gfx1036` (Windows 11, driver 32.0.21045.29003, 1,088 raw kernels across wave32 and wave64, 0 mismatches): **`abs` and `- **`neg`, `abs`, and `- **`abs` rests on the ISA's definition of ABS on a float operand as the sign clear, applied before `neg`; no hardware run of this instruction with `abs` exists yet**, and `abs` on a NaN half is therefore unmeasured too. **Not modelled: IEEE mode 1 also quiets a signalling-NaN half** (`0x7c01` → `0x7e01`); which mode the game's shaders run in is SHADER-190, and under mode 0, where the bits move unchanged, the translation is exact. Checked by `tests/test_values.py`, `tests/semantic/test_vop3_const_mods.py`, `tests/semantic/test_pack_b32_f16_mods.py` (exact bits through the interpreter) and the GPU fixture `ps_f16_pack_mods` (words derived from the rule, not a readback); the gfx1036 measurement above is @Sanonymous01's, not repeated here. \| x src \| ` are hardware-verified on RDNA2** across both `gfx1035` (Windows 11, driver 26.5.1, wave32 & wave64 via `tools/int_hw_probe.py --oracle both --group valu_pack_b32_f16_abs` and raw `ieee=0` kernels) and `gfx1036` (Windows 11, driver 32.0.21045.29003, 1,088 raw kernels across wave32 and wave64): ` (neg+abs) are measured** on gfx1036 (RDNA2 iGPU, AMD Windows driver 32.0.21045.29003) with 1,088 raw kernels across wave32 and wave64 (0 mismatches): `abs` clears bit 15 (`& 0x7FFF`), `neg` flips it (`^ 0x8000`), and `neg_abs` sets bit 15 across all normal numbers, zeros, infinities, subnormals, quiet NaNs, and signaling NaNs, in either half and with `op_sel`. Under IEEE mode 0, signaling NaN payloads are preserved untouched (`0x7c01` gives `0xfc01` under `neg` and `0x7c01` under `abs`); under IEEE mode 1, a signaling-NaN half is quieted (bit 9 set: `0x7c01` gives `0xfe01` under `neg` and `0x7e01` under `abs`). ` are hardware-verified on RDNA2** (`gfx1035`, Windows 11, driver `26.5.1`, wave32 & wave64 via `tools/int_hw_probe.py --oracle both --group valu_pack_b32_f16_abs` and raw `ieee=0` kernels): On `gfx1035`, `abs` clears bit 15 and applies before `neg` on `-1.0`, `-0.0`, `-qNaN` (`0xfe05` → `0x7e05`), and `-sNaN` (`0xfc01` → `0x7c01` under `ieee=0`), with and without `op_sel`. **Not modelled: IEEE mode 1 also quiets a signalling-NaN half** (`0x7c01` → `0x7e01`); which mode the game's shaders run in is SHADER-190, and under mode 0, where the bits move unchanged, the translation is exact. Checked by `tests/test_values.py`, `tests/semantic/test_vop3_const_mods.py`, `tests/semantic/test_pack_b32_f16_mods.py` (exact bits through the interpreter) and the GPU fixture `ps_f16_pack_mods` (words derived from the rule, not a readback); the gfx1036 measurement above is @Sanonymous01's, not repeated here. | | Packed integer dot products (`v_dot2_i32_i16`, `v_dot2_u32_u16`, `v_dot4_u32_u8`, `v_dot8_i32_i4`, `v_dot8_u32_u4`, plus VOP2 accumulating `v_dot2c_i32_i16`, `v_dot2c_u32_u16`, `v_dot4c_u32_u8`, `v_dot8c_i32_i4`, `v_dot8c_u32_u4`), `v_dot2_f32_f16` / `v_dot2c_f32_f16`, and `v_pk_fmac_f16` | RDNA2 ISA: `v_dot2_i32_i16`/`u16` (2×16-bit), `v_dot4_u32_u8` (4×8-bit unsigned), and `v_dot8_i32_i4`/`u4` (8×4-bit) — and their VOP2 accumulating `v_dot*c_*` forms (reading old `vdst` as `acc`) — extract each element with `OpBitFieldSExtract`/`OpBitFieldUExtract`, sum the elementwise products with `S2` (or old `vdst`) wrapping at 32 bits, and saturate to `[INT32_MIN, INT32_MAX]` / `[0, UINT32_MAX]` under `clamp` (signed carry tracking handles the `v_dot2_i32_i16` `(-32768)^2 + (-32768)^2 + acc` overflow/cancellation edge). For VOP3P `v_dot*_*`, the hardware default `op_sel:[0,0,0]` and `op_sel_hi:[1,1,1]` is accepted and any other `op_sel`/`op_sel_hi`, `neg_lo`/`neg_hi`, DPP/SDWA, or source `neg`/`abs` raises `Unsupported`; for VOP2 `v_dot*c_*`, only optional `clamp` and VGPR `vdst` are accepted. `v_dot2_f32_f16` (VOP3P) and `v_dot2c_f32_f16` (VOP2) compute `a0*b0 + a1*b1 + acc` in f32 (`f16_in` per half, `flush_f32` on `acc`, optional `clamp`, and for `v_dot2_f32_f16` `op_sel`/`op_sel_hi`/`neg_lo`/`neg_hi` on the inputs and `neg_lo[2]` on `acc`). All 6 new `v_dot*c_*` ops mark `vdst` as read-before-write in `read_before_write_vgprs` and `reg_reads_writes`. (`v_dot4_i32_i8` and `v_dot4c_i32_i8` are covered separately in the Signed-byte dot products row, #1754.) `v_pk_fmac_f16` (VOP2) unpacks `src0`, `vsrc1` and `vdst` as `f16x2` (`Gen.src_h`, so inline float constants apply in the low half with `+0.0` high), computes `fma(src0[k], vsrc1[k], vdst[k])` per half with single f16 rounding (`Gen.fma_f16_odd`, SHADER-55), and packs with `Gen.f16_pack2`; any modifier outside `_dpp` or non-VGPR `vdst` raises `Unsupported`, and `v_pk_fmac_f16` marks `vdst` as read before write in `read_before_write_vgprs` and `reg_reads_writes`. **Hardware-confirmed on RDNA2** for the 5 VOP3P integer forms and `v_pk_fmac_f16`: on `gfx1036` (Ryzen 9 7950X3D iGPU, `tools/hw_oracle`, @aslan2142), all 60 integer dot-product sets and all 22 `v_pk_fmac_f16` default-MODE words match; independently confirmed on `gfx1035` (Radeon 680M, @Youssefrah16) across 18 cases × wave32/wave64 (36/36 bit-exact), pinned by `tests/semantic/test_alu_dot_pk_fmac.py`. The 5 VOP2 `v_dot*c_*` integer forms and `v_dot2_f32_f16` / `v_dot2c_f32_f16` are CPU-checked by `tests/semantic/test_alu_dot_complete.py` and not yet hardware-measured on RDNA2. Non-default f16 MODEs (denormal flush, RTZ) are not modelled on `v_pk_fmac_f16` while the translator has no MODE input. | diff --git a/docs/shader_validation.md b/docs/shader_validation.md index ac33debfaf..8b39f9bcac 100644 --- a/docs/shader_validation.md +++ b/docs/shader_validation.md @@ -2054,6 +2054,8 @@ Hardware validation was executed via `tools/hw_oracle` and `tools/salu_diff.py` - **Constant operands under `op_sel` / `op_sel_hi`:** Integer constants under VOP3P are uniformly treated as 32-bit dwords `C`. When `op_sel[i] == 0`, bits `[15:0]` are selected; when `op_sel[i] == 1`, bits `[31:16]` are selected. Positive inline constants zero-extend (`5` → `0x00000005`: lo=`0x0005`, hi=`0x0000`; `64` → `0x00000040`: lo=`0x0040`, hi=`0x0000`). Negative inline constants sign-extend (`-1` → `0xFFFFFFFF`: lo=`0xFFFF`, hi=`0xFFFF`; `-16` → `0xFFFFFFF0`: lo=`0xFFF0`, hi=`0xFFFF`). 32-bit literals preserve their full dword (`0x12345678`: lo=`0x5678`, hi=`0x1234`; `0x80017fff`: lo=`0x7fff`, hi=`0x8001`). Float inline tokens (`0.5`, `1.0`, `-2.0`, `4.0`) assemble as their 32-bit IEEE 754 bit patterns (`1.0` → `0x3f800000`: lo=`0x0000`, hi=`0x3f80`). - **`clamp` saturation:** Unsigned add/mad saturate to `0xFFFF`; unsigned sub saturates underflow to `0x0000`; signed add/sub/mad saturate to `[-32768, 32767]`. - **Silicon vs Translator parity:** 380 of 380 kernels match bit-for-bit between native hardware and `tools/rdna2spirv.py` lowered to SPIR-V (0 mismatches, 0 wave32/wave64 differences). + +On the Vulkan path, `runtime/test/shaders/cs_pk_int16_u.asm` and `cs_pk_int16_i.asm` (wave32; the six u16 and the five i16 forms with `op_sel`/`op_sel_hi` and `clamp`; the eight words derived in each header) pass on the RDNA2 iGPU `gfx1036` through RADV (`RAPHAEL_MENDOCINO`, Mesa 27.0.0-devel): 8/8 and 8/8 words. `tests/semantic/test_pk_int16_gpu_fixtures.py` runs the same disassembly in the interpreter and checks the header, `CS_DUMPS` and the `scripts/run_gpu_tests.py` table against it. ### Pixel-shader ISA on the hardware (`tools/ps_oracle.py`, EGEN-TOOL-PS-ORACLE) `tools/hw_oracle` only launches compute kernels, so what only a pixel shader has (`v_interp_*` and the parameter diff --git a/runtime/test/shaders/check.py b/runtime/test/shaders/check.py index f0ddf2f315..e9a939c69a 100644 --- a/runtime/test/shaders/check.py +++ b/runtime/test/shaders/check.py @@ -110,7 +110,7 @@ def not_found_message(build, missing): "cs_w32_partial_scmp", "cs_w32_partial_permute", "cs_exec_const", "cs_w32_mask_imm", "cs_w32_int_ext", "cs_w32_salu64", "cs_w32_misc_ext", "cs_w32_new_ops", "cs_w32_sincos", "cs_lds_b64_cmpst", "cs_lds_xchg64_ext", "cs_lds_atomics_ext", "cs_w32_andn2_exec", "cs_mask_vgpr_exec", "cs_w32_buffer_sub16", "cs_w32_buffer_store_sub", "cs_w32_fcmpswap", "cs_w32_permlane_fi", - "cs_w32_exec_computed") + "cs_w32_exec_computed", "cs_pk_int16_u", "cs_pk_int16_i") # Wave32 lane-mask dumps: their EXEC/VCC masks and lane selects cover 32 lanes, so a device whose widest subgroup is # narrower (Mesa llvmpipe: 8) can't produce their words. They are skipped there, as ps_bitmask_perm is. They run with # 32 lanes requested (WAVE32_LANE_ENV), as run_gpu_tests.py does: a device with a range like 8..32 (Intel ANV) may @@ -152,6 +152,10 @@ def not_found_message(build, missing): ("cs_w32_new_ops", [0x55, 0x8001, 0xC0000000, 0x80014000, 0x4000FFFF, 0x77, 0x99, 0x1234]), ("cs_w32_misc_ext", [0x0FFF0FFF, 0xE2C4A688, 0x0007FFFF, 0x7FFF8000, 0xFFFE0002, 0xFFFF0005, 0x509, 0xCAFEF00D]), ("cs_w32_salu64", [0x1E6A2C48, 0x1234, 0xFFFFFFFF, 0x100, 47, 48, 0xFFFF8000, 0xFFFFFFFE]), + # packed 16-bit integer ops (derivations in each .asm header): the six u16 forms with op_sel and + # clamp, then the five i16 forms with op_sel and clamp + ("cs_pk_int16_u", [0xFFFF0007, 0x0005FFFD, 0xFFFA0004, 0x0000000D, 0xFFFE0004, 0x00030001, 0xFFFF0005, 0x00000000]), + ("cs_pk_int16_i", [0x00018000, 0x00038002, 0x80010001, 0x0002FFFF, 0xFFFF8001, 0x80008000, 0x7FFF8000, 0x7FFF7FFF]), # SHADER-85: 8-bit LDS reads into one half of a VGPR, the other half kept ("cs_w32_lds_u8_d16", [0xBEEF00FF, 0x00FF1234, 0xBEEFFF80, 0xFF801234, 0xBEEF007F, 0x007F1234, 0xBEEF0080, 0xFFFF1234]), # 8/16-bit LDS writes (incl. _d16_hi) and sign/zero-extending reads diff --git a/runtime/test/shaders/cs_pk_int16_i.asm b/runtime/test/shaders/cs_pk_int16_i.asm new file mode 100644 index 0000000000..0fddf0a0aa --- /dev/null +++ b/runtime/test/shaders/cs_pk_int16_i.asm @@ -0,0 +1,49 @@ +; regen_fixtures: this source has a translator fixture in tests/semantic/fixtures/disasm +; Packed 16-bit signed integer ops (VOP3P), the five i16 forms plus op_sel and clamp, run once on a GPU. +; Lane 0 of a wave32 group computes one result per op and stores eight dwords. Sources are +; v1 = 0x00028001 (lo -32767, hi 2), v2 = 0xFFFFFFFF (lo -1, hi -1), v3 = 0x00030002 (lo 2, hi 3), +; v4 = 0x80010002 (lo 2, hi -32767), v5 = 0x80018001 (both halves -32767). +; Result half 0 takes each source's half from op_sel[i], half 1 from op_sel_hi[i]; each half wraps to 16 bits. +; out[0] = v_pk_add_i16 v1, v2 = 0x00018000 +; half 0: -32767 - 1 = -32768; half 1: 2 - 1 = 1 +; out[1] = v_pk_sub_i16 v1, v2 = 0x00038002 +; half 0: -32767 + 1 = -32766; half 1: 2 + 1 = 3 +; out[2] = v_pk_mad_i16 v1, v2, v3 op_sel:[1,0,1] op_sel_hi:[0,1,0] = 0x80010001 +; half 0: v1.hi 2 * v2.lo -1 + v3.hi 3 = 1; half 1: v1.lo -32767 * v2.hi -1 + v3.lo 2 = 32769 -> -32767 +; out[3] = v_pk_max_i16 v1, v2 = 0x0002FFFF +; half 0: max(-32767, -1) = -1; half 1: max(2, -1) = 2 +; out[4] = v_pk_min_i16 v1, v2 = 0xFFFF8001 +; half 0: min(-32767, -1) = -32767; half 1: min(2, -1) = -1 +; out[5] = v_pk_add_i16 v5, v5 clamp = 0x80008000 +; both halves: -32767 + -32767 = -65534 saturates to -32768 +; out[6] = v_pk_sub_i16 v1, v4 clamp = 0x7FFF8000 +; half 0: -32767 - 2 = -32769 saturates to -32768; half 1: 2 - -32767 = 32769 saturates to 32767 +; out[7] = v_pk_mad_i16 v5, v2, v3 clamp = 0x7FFF7FFF +; half 0: -32767 * -1 + 2 = 32769 saturates to 32767; half 1: -32767 * -1 + 3 = 32770 saturates to 32767 +; group: 32,1,1 +; Run: vk_compute_test cs_pk_int16_i.spv 1 dump -> out[0..7] = 00018000 00038002 80010001 0002FFFF FFFF8001 80008000 7FFF8000 7FFF7FFF (hex) +; mattr: +wavefrontsize32,-wavefrontsize64 +v_mov_b32_e32 v1, 0x00028001 +v_mov_b32_e32 v2, 0xffffffff +v_mov_b32_e32 v3, 0x00030002 +v_mov_b32_e32 v4, 0x80010002 +v_mov_b32_e32 v5, 0x80018001 +v_pk_add_i16 v20, v1, v2 +v_pk_sub_i16 v21, v1, v2 +v_pk_mad_i16 v22, v1, v2, v3 op_sel:[1,0,1] op_sel_hi:[0,1,0] +v_pk_max_i16 v23, v1, v2 +v_pk_min_i16 v24, v1, v2 +v_pk_add_i16 v25, v5, v5 clamp +v_pk_sub_i16 v26, v1, v4 clamp +v_pk_mad_i16 v27, v5, v2, v3 clamp +v_cmpx_eq_u32_e32 0, v0 +v_mov_b32_e32 v10, 0 +buffer_store_dword v20, v10, s[0:3], 0 offen offset:0 +buffer_store_dword v21, v10, s[0:3], 0 offen offset:4 +buffer_store_dword v22, v10, s[0:3], 0 offen offset:8 +buffer_store_dword v23, v10, s[0:3], 0 offen offset:12 +buffer_store_dword v24, v10, s[0:3], 0 offen offset:16 +buffer_store_dword v25, v10, s[0:3], 0 offen offset:20 +buffer_store_dword v26, v10, s[0:3], 0 offen offset:24 +buffer_store_dword v27, v10, s[0:3], 0 offen offset:28 +s_endpgm diff --git a/runtime/test/shaders/cs_pk_int16_u.asm b/runtime/test/shaders/cs_pk_int16_u.asm new file mode 100644 index 0000000000..9c06493dc4 --- /dev/null +++ b/runtime/test/shaders/cs_pk_int16_u.asm @@ -0,0 +1,46 @@ +; regen_fixtures: this source has a translator fixture in tests/semantic/fixtures/disasm +; Packed 16-bit unsigned integer ops (VOP3P), the six u16 forms, run once on a GPU. +; Lane 0 of a wave32 group computes one result per op and stores eight dwords. Sources are +; v1 = 0x00030001 (lo 1, hi 3), v2 = 0xFFFE0004 (lo 4, hi 0xFFFE), v3 = 0x00060009 (lo 9, hi 6). +; Result half 0 takes each source's half from op_sel[i], half 1 from op_sel_hi[i]; each half wraps to 16 bits. +; out[0] = v_pk_add_u16 op_sel:[1,0] op_sel_hi:[0,1] = 0xFFFF0007 +; half 0: v1.hi 3 + v2.lo 4 = 7; half 1: v1.lo 1 + v2.hi 0xFFFE = 0xFFFF +; out[1] = v_pk_sub_u16 v1, v2 = 0x0005FFFD +; half 0: 1 - 4 underflows to 0xFFFD; half 1: 3 - 0xFFFE = 0x10005 -> 5 +; out[2] = v_pk_mul_lo_u16 v1, v2 = 0xFFFA0004 +; half 0: 1 * 4 = 4; half 1: 3 * 0xFFFE = 0x2FFFA -> low 16 bits 0xFFFA +; out[3] = v_pk_mad_u16 v1, v2, v3 = 0x0000000D +; half 0: 1 * 4 + 9 = 13; half 1: 3 * 0xFFFE + 6 = 0x30000 -> 0 +; out[4] = v_pk_max_u16 v1, v2 = 0xFFFE0004 +; half 0: max(1, 4) = 4; half 1: max(3, 0xFFFE) = 0xFFFE +; out[5] = v_pk_min_u16 v1, v2 = 0x00030001 +; half 0: min(1, 4) = 1; half 1: min(3, 0xFFFE) = 3 +; out[6] = v_pk_add_u16 v1, v2 clamp = 0xFFFF0005 +; half 0: 1 + 4 = 5; half 1: 3 + 0xFFFE = 0x10001 saturates to 0xFFFF +; out[7] = v_pk_sub_u16 v1, v2 clamp = 0x00000000 +; both halves are below zero and saturate to 0 (unclamped: 0xFFFD and 5) +; group: 32,1,1 +; Run: vk_compute_test cs_pk_int16_u.spv 1 dump -> out[0..7] = FFFF0007 0005FFFD FFFA0004 0000000D FFFE0004 00030001 FFFF0005 00000000 (hex) +; mattr: +wavefrontsize32,-wavefrontsize64 +v_mov_b32_e32 v1, 0x00030001 +v_mov_b32_e32 v2, 0xfffe0004 +v_mov_b32_e32 v3, 0x00060009 +v_pk_add_u16 v20, v1, v2 op_sel:[1,0] op_sel_hi:[0,1] +v_pk_sub_u16 v21, v1, v2 +v_pk_mul_lo_u16 v22, v1, v2 +v_pk_mad_u16 v23, v1, v2, v3 +v_pk_max_u16 v24, v1, v2 +v_pk_min_u16 v25, v1, v2 +v_pk_add_u16 v26, v1, v2 clamp +v_pk_sub_u16 v27, v1, v2 clamp +v_cmpx_eq_u32_e32 0, v0 +v_mov_b32_e32 v10, 0 +buffer_store_dword v20, v10, s[0:3], 0 offen offset:0 +buffer_store_dword v21, v10, s[0:3], 0 offen offset:4 +buffer_store_dword v22, v10, s[0:3], 0 offen offset:8 +buffer_store_dword v23, v10, s[0:3], 0 offen offset:12 +buffer_store_dword v24, v10, s[0:3], 0 offen offset:16 +buffer_store_dword v25, v10, s[0:3], 0 offen offset:20 +buffer_store_dword v26, v10, s[0:3], 0 offen offset:24 +buffer_store_dword v27, v10, s[0:3], 0 offen offset:28 +s_endpgm diff --git a/scripts/run_gpu_tests.py b/scripts/run_gpu_tests.py index 8ba62104d8..90517f4c8a 100644 --- a/scripts/run_gpu_tests.py +++ b/scripts/run_gpu_tests.py @@ -1201,7 +1201,7 @@ def run_suite(a, work: str) -> int: # Whole-wave mask test, as in check.py: needs a 64-wide subgroup, skipped where the device has none. # With LEONIDA_W64_EMULATE=1 it was translated with --wave64-emulate and runs on any subgroup size. results.append((name,) + wavemask_check(vk_compute, spv, cs_env, w64_emulated())) - elif name in ("cs_smem_vcc_base", "cs_store", "cs_signed_zero_nan", "cs_smem_soffset_imm", "cs_w32_lane_wrap", "cs_movrelsd_2", "cs_w32_permute", "cs_w32_sincos", "cs_w32_buffer_sub16", "cs_w32_buffer_store_sub", "cs_w32_fcmpswap", "cs_w32_permlane_fi", "cs_exec_const", "cs_w32_mask_imm", "cs_w64_mask_imm", "cs_w32_lds_u8_d16", "cs_w32_lds_subdword", "cs_w32_lds_wide", "cs_w32_int_ext", "cs_w32_salu64", "cs_w32_misc_ext", "cs_w32_new_ops", "cs_wave64_ballot", "cs_wm_half_ops", "cs_wm_half_cmp", "cs_wm_bfm64", "cs_wm_scc_rfl", "cs_wqm_w64", "cs_wqm_w32", "cs_wqm_w64_half", + elif name in ("cs_smem_vcc_base", "cs_store", "cs_signed_zero_nan", "cs_smem_soffset_imm", "cs_w32_lane_wrap", "cs_movrelsd_2", "cs_w32_permute", "cs_w32_sincos", "cs_w32_buffer_sub16", "cs_w32_buffer_store_sub", "cs_w32_fcmpswap", "cs_w32_permlane_fi", "cs_exec_const", "cs_w32_mask_imm", "cs_w64_mask_imm", "cs_w32_lds_u8_d16", "cs_w32_lds_subdword", "cs_w32_lds_wide", "cs_w32_int_ext", "cs_w32_salu64", "cs_w32_misc_ext", "cs_w32_new_ops", "cs_pk_int16_u", "cs_pk_int16_i", "cs_wave64_ballot", "cs_wm_half_ops", "cs_wm_half_cmp", "cs_wm_bfm64", "cs_wm_scc_rfl", "cs_wqm_w64", "cs_wqm_w32", "cs_wqm_w64_half", "cs_dpp", "cs_dpp_row", "cs_dpp_mask", "cs_dpp8", "cs_dpp_ops", "cs_dpp_bank", "cs_dpp_fi", "cs_dpp_bound", "cs_dpp_cmp", "cs_dpp_w64", "cs_w64_mask_detect", @@ -1238,6 +1238,9 @@ def run_suite(a, work: str) -> int: "cs_w32_new_ops": [0x55, 0x8001, 0xC0000000, 0x80014000, 0x4000FFFF, 0x77, 0x99, 0x1234], "cs_w32_misc_ext": [0x0FFF0FFF, 0xE2C4A688, 0x0007FFFF, 0x7FFF8000, 0xFFFE0002, 0xFFFF0005, 0x509, 0xCAFEF00D], "cs_w32_salu64": [0x1E6A2C48, 0x1234, 0xFFFFFFFF, 0x100, 47, 48, 0xFFFF8000, 0xFFFFFFFE], + # packed 16-bit integer ops (derivations in each .asm header) + "cs_pk_int16_u": [0xFFFF0007, 0x0005FFFD, 0xFFFA0004, 0x0000000D, 0xFFFE0004, 0x00030001, 0xFFFF0005, 0x00000000], + "cs_pk_int16_i": [0x00018000, 0x00038002, 0x80010001, 0x0002FFFF, 0xFFFF8001, 0x80008000, 0x7FFF8000, 0x7FFF7FFF], # SHADER-85: ds_read_u8/i8_d16[_hi] (cs_w32_lds_u8_d16.asm header) "cs_w32_lds_u8_d16": [0xBEEF00FF, 0x00FF1234, 0xBEEFFF80, 0xFF801234, 0xBEEF007F, 0x007F1234, 0xBEEF0080, 0xFFFF1234], # 8/16-bit and 64/96/128-bit LDS accesses (cs_w32_lds_subdword.asm / cs_w32_lds_wide.asm headers) @@ -1337,6 +1340,7 @@ def run_suite(a, work: str) -> int: wave64 = name not in ("cs_store", "cs_signed_zero_nan", "cs_smem_soffset_imm", "cs_wqm_w32", "cs_w32_lane_wrap", "cs_movrelsd_2", "cs_w32_permute", "cs_barrier_divergent", "cs_barrier_early_end", "cs_barrier_loop", "cs_w32_lds_u8_d16", "cs_w32_int_ext", "cs_w32_salu64", "cs_w32_misc_ext", "cs_w32_new_ops", + "cs_pk_int16_u", "cs_pk_int16_i", "cs_w32_lds_subdword", "cs_w32_lds_wide", "cs_bpermute32", "cs_w32_partial_scmp", "cs_w32_partial_permute", "cs_w32_permlane_fi", "cs_w32_sincos", "cs_w32_buffer_sub16", "cs_w32_buffer_store_sub", "cs_w32_fcmpswap", "cs_lds_b64_cmpst", "cs_lds_xchg64_ext", "cs_lds_atomics_ext", "cs_exec_const", "cs_w32_mask_imm", "cs_mask_vgpr_exec", diff --git a/tests/semantic/fixtures/disasm/cs_pk_int16_i.s b/tests/semantic/fixtures/disasm/cs_pk_int16_i.s new file mode 100644 index 0000000000..cd312b1e4c --- /dev/null +++ b/tests/semantic/fixtures/disasm/cs_pk_int16_i.s @@ -0,0 +1,25 @@ +; cs_pk_int16_i test fixture generated by tests/semantic/regen_fixtures.py from runtime/test/shaders/cs_pk_int16_i.asm + v_mov_b32_e32 v1, 0x00028001 + v_mov_b32_e32 v2, 0xffffffff + v_mov_b32_e32 v3, 0x00030002 + v_mov_b32_e32 v4, 0x80010002 + v_mov_b32_e32 v5, 0x80018001 + v_pk_add_i16 v20, v1, v2 + v_pk_sub_i16 v21, v1, v2 + v_pk_mad_i16 v22, v1, v2, v3 op_sel:[1,0,1] op_sel_hi:[0,1,0] + v_pk_max_i16 v23, v1, v2 + v_pk_min_i16 v24, v1, v2 + v_pk_add_i16 v25, v5, v5 clamp + v_pk_sub_i16 v26, v1, v4 clamp + v_pk_mad_i16 v27, v5, v2, v3 clamp + v_cmpx_eq_u32_e32 0, v0 + v_mov_b32_e32 v10, 0 + buffer_store_dword v20, v10, s[0:3], 0 offen offset:0 + buffer_store_dword v21, v10, s[0:3], 0 offen offset:4 + buffer_store_dword v22, v10, s[0:3], 0 offen offset:8 + buffer_store_dword v23, v10, s[0:3], 0 offen offset:12 + buffer_store_dword v24, v10, s[0:3], 0 offen offset:16 + buffer_store_dword v25, v10, s[0:3], 0 offen offset:20 + buffer_store_dword v26, v10, s[0:3], 0 offen offset:24 + buffer_store_dword v27, v10, s[0:3], 0 offen offset:28 + s_endpgm diff --git a/tests/semantic/fixtures/disasm/cs_pk_int16_u.s b/tests/semantic/fixtures/disasm/cs_pk_int16_u.s new file mode 100644 index 0000000000..9c130e719b --- /dev/null +++ b/tests/semantic/fixtures/disasm/cs_pk_int16_u.s @@ -0,0 +1,23 @@ +; cs_pk_int16_u test fixture generated by tests/semantic/regen_fixtures.py from runtime/test/shaders/cs_pk_int16_u.asm + v_mov_b32_e32 v1, 0x00030001 + v_mov_b32_e32 v2, 0xfffe0004 + v_mov_b32_e32 v3, 0x00060009 + v_pk_add_u16 v20, v1, v2 op_sel:[1,0] op_sel_hi:[0,1] + v_pk_sub_u16 v21, v1, v2 + v_pk_mul_lo_u16 v22, v1, v2 + v_pk_mad_u16 v23, v1, v2, v3 + v_pk_max_u16 v24, v1, v2 + v_pk_min_u16 v25, v1, v2 + v_pk_add_u16 v26, v1, v2 clamp + v_pk_sub_u16 v27, v1, v2 clamp + v_cmpx_eq_u32_e32 0, v0 + v_mov_b32_e32 v10, 0 + buffer_store_dword v20, v10, s[0:3], 0 offen offset:0 + buffer_store_dword v21, v10, s[0:3], 0 offen offset:4 + buffer_store_dword v22, v10, s[0:3], 0 offen offset:8 + buffer_store_dword v23, v10, s[0:3], 0 offen offset:12 + buffer_store_dword v24, v10, s[0:3], 0 offen offset:16 + buffer_store_dword v25, v10, s[0:3], 0 offen offset:20 + buffer_store_dword v26, v10, s[0:3], 0 offen offset:24 + buffer_store_dword v27, v10, s[0:3], 0 offen offset:28 + s_endpgm diff --git a/tests/semantic/test_pk_int16_gpu_fixtures.py b/tests/semantic/test_pk_int16_gpu_fixtures.py new file mode 100644 index 0000000000..88cee0ab41 --- /dev/null +++ b/tests/semantic/test_pk_int16_gpu_fixtures.py @@ -0,0 +1,114 @@ +"""CPU checks for the packed 16-bit integer GPU fixtures (cs_pk_int16_u, cs_pk_int16_i). + +Each fixture runs the translator on its generated disassembly (tests/semantic/fixtures/disasm, made by +regen_fixtures.py) and executes all 32 invocations in the mini interpreter: lane 0 alone passes the fixture's EXEC +cut and stores the eight results, so the memory holds exactly the words its header derives. The same words are +asserted against the three places that state them: the .asm header, check.py's CS_DUMPS and +scripts/run_gpu_tests.py's table. A GPU run of either runner then compares them with what the device writes. +""" + +import os +import re +import sys +import unittest + +HERE = os.path.dirname(os.path.abspath(__file__)) +ROOT = os.path.dirname(os.path.dirname(HERE)) +SHADERS = os.path.join(ROOT, "runtime", "test", "shaders") +sys.path.insert(0, HERE) +sys.path.insert(0, SHADERS) + +import support # noqa: E402 +import spirv_mini_interp as si # noqa: E402 +import check # noqa: E402 (importing runtime/test/shaders/check.py runs nothing) +from compute_fixture import compute_header # noqa: E402 + +FIXTURES = { + "cs_pk_int16_u": ( + 0xFFFF0007, + 0x0005FFFD, + 0xFFFA0004, + 0x0000000D, + 0xFFFE0004, + 0x00030001, + 0xFFFF0005, + 0x00000000, + ), + "cs_pk_int16_i": ( + 0x00018000, + 0x00038002, + 0x80010001, + 0x0002FFFF, + 0xFFFF8001, + 0x80008000, + 0x7FFF8000, + 0x7FFF7FFF, + ), +} +# The output V# in s[0:3]: base 0, 32 bytes, FORMAT 32_FLOAT, DST_SEL xyzw (as in cs_cvt_pk_u8.asm). +OUT_V = [0, 0, 32, 0x31016FAC] + + +def read(name): + with open(os.path.join(SHADERS, name + ".asm"), encoding="utf-8") as f: + return f.read() + + +def header_words(name): + """The eight hex words of the fixture's "; Run:" line.""" + m = re.search(r"Run:.*?out\[0\.\.7\] = (.*?) \(hex\)", read(name)) + if not m: + raise AssertionError(f"{name}.asm has no '; Run:' words") + return tuple(int(w, 16) for w in m.group(1).split()) + + +def runner_words(name): + """The tuple scripts/run_gpu_tests.py expects for `name` (its table is local to the run loop, so read the source).""" + with open(os.path.join(ROOT, "scripts", "run_gpu_tests.py"), encoding="utf-8") as f: + m = re.search(r'"%s": \[([^\]]*)\]' % re.escape(name), f.read()) + return tuple(int(w, 0) for w in m.group(1).split(",")) if m else None + + +def interpreter_words(name): + spv = support.translate_fixture( + name, fssm=bytes(compute_header(os.path.join(SHADERS, name + ".asm"))) + ) + memory = {} + si.run_workgroup( + spv, + 32, + 32, + inputs_for=lambda i: {"%wg_id": (0, 0, 0), "%local_id": (i, 0, 0)}, + push_constants=OUT_V + [0] * 28, + memory=memory, + ) + return memory + + +class PkInt16GpuFixtureTests(unittest.TestCase): + def test_interpreter_stores_the_header_words(self): + for name, want in FIXTURES.items(): + with self.subTest(name=name): + memory = interpreter_words(name) + self.assertEqual( + sorted(memory), [4 * i for i in range(8)] + ) # lane 0 stored, the other 31 did not + self.assertEqual(tuple(memory[4 * i] for i in range(8)), want) + + def test_header_check_and_runner_agree(self): + cs_dumps = dict(check.CS_DUMPS) + for name, want in FIXTURES.items(): + with self.subTest(name=name): + self.assertEqual(header_words(name), want) + self.assertEqual(cs_dumps.get(name), list(want)) + self.assertEqual(runner_words(name), want) + + def test_wave32_registration(self): + for name in FIXTURES: + with self.subTest(name=name): + self.assertIn(name, check.WAVE32_DUMPS) + self.assertNotIn(name, check.WAVE32_LANE_DUMPS) + + +if __name__ == "__main__": + unittest.main()