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: 1 addition & 1 deletion docs/design.md

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions docs/shader_validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion runtime/test/shaders/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
49 changes: 49 additions & 0 deletions runtime/test/shaders/cs_pk_int16_i.asm
Original file line number Diff line number Diff line change
@@ -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
46 changes: 46 additions & 0 deletions runtime/test/shaders/cs_pk_int16_u.asm
Original file line number Diff line number Diff line change
@@ -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
6 changes: 5 additions & 1 deletion scripts/run_gpu_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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",
Expand Down
25 changes: 25 additions & 0 deletions tests/semantic/fixtures/disasm/cs_pk_int16_i.s
Original file line number Diff line number Diff line change
@@ -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
23 changes: 23 additions & 0 deletions tests/semantic/fixtures/disasm/cs_pk_int16_u.s
Original file line number Diff line number Diff line change
@@ -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
114 changes: 114 additions & 0 deletions tests/semantic/test_pk_int16_gpu_fixtures.py
Original file line number Diff line number Diff line change
@@ -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()
Loading