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
6 changes: 4 additions & 2 deletions runtime/test/shaders/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,15 @@ 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_w32_saveexec_ext")
# 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
# otherwise pick a narrower size and return different words (#774).
WAVE32_LANE_ENV = {"VKC_SUBGROUP_SIZE": "32"}
WAVE32_LANE_DUMPS = ("cs_wqm_w32", "cs_w32_lane_wrap", "cs_w32_permute", "cs_bpermute32", "cs_w32_partial_scmp", "cs_w32_partial_permute", "cs_exec_const",
"cs_w32_mask_imm", "cs_lds_b64_cmpst", "cs_lds_xchg64_ext", "cs_lds_atomics_ext", "cs_w32_andn2_exec", "cs_mask_vgpr_exec", "cs_w32_permlane_fi",
"cs_w32_exec_computed")
"cs_w32_exec_computed", "cs_w32_saveexec_ext")
CS_DPP = [("cs_dpp", [1, 0, 3, 2, 5, 4, 7, 6]),
("cs_dpp_row", [0, 0, 1, 2, 3, 4, 5, 6]),
("cs_dpp_mask", [1, 0, 3, 2, 0xeeeeeeee, 0xeeeeeeee, 0xeeeeeeee, 0xeeeeeeee]),
Expand All @@ -138,6 +138,8 @@ def not_found_message(build, missing):
("cs_movrelsd_2", [11, 33, 33, 55, 1717, 77, 1515, 1717]),
# SHADER-90: ds_permute_b32, the forward (scatter) permute; unwritten lane 0, EXEC gates the destination
("cs_w32_permute", [218, 29, 8, 211, 0, 15, 99, 15]),
# #1657's saveexec / wrexec kinds: (lane count << 8) | first lane of the new EXEC (cs_w32_saveexec_ext.asm)
("cs_w32_saveexec_ext", [0x1000, 0xA00, 0x1A00, 0x160A, 0x1200, 0x21E, 0x100A, 0xA00]),
# integer ops with CPU-only checks until now (derivations in cs_w32_int_ext.asm)
("cs_w32_int_ext", [1, 27, 1, 0x33332222, 0xC0000000, 0x4000, 18, 0x20304050]),
# 64-bit scalar data ops and v_mad_u64_u32 (derivations in cs_w32_salu64.asm)
Expand Down
104 changes: 104 additions & 0 deletions runtime/test/shaders/cs_w32_saveexec_ext.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
; regen_fixtures: this source has a translator fixture in tests/semantic/fixtures/disasm
; The saveexec / wrexec kinds #1657 added (xor, andn1, orn1, orn2, nand, nor, xnor, andn1_wrexec), run on a GPU.
; One wave32 group. S0 = lanes 10..29 and each step's EXEC = lanes 0..23 come from compares (a lane mask held in an
; SGPR, as compiled code has it). Each step runs the op
; and records (s_bcnt1 << 8) | s_ff1 of the new EXEC (a whole-wave count and first lane, so the word does not depend
; on which lane stores it), then restores EXEC. Lane 0 stores the eight words. New EXEC per ISA (tools/cf_ref.py):
; out[0] xor S ^ E lanes 0..9, 24..29 16 lanes, first 0 = 0x1000
; out[1] andn1 ~S & E lanes 0..9 10 lanes, first 0 = 0xA00
; out[2] orn1 ~S | E lanes 0..23, 30..31 26 lanes, first 0 = 0x1A00
; out[3] orn2 S | ~E lanes 10..31 22 lanes, first 10 = 0x160A
; out[4] nand ~(S & E) all but 10..23 18 lanes, first 0 = 0x1200
; out[5] nor ~(S | E) lanes 30..31 2 lanes, first 30 = 0x21E
; out[6] xnor ~(S ^ E) lanes 10..23, 30..31 16 lanes, first 10 = 0x100A
; out[7] s_andn1_wrexec_b32, also ~S & E = 0xA00
; Lanes EXEC had off (24..31) turn on where f gives 1, as on hardware.
; group: 32,1,1
; Run: vk_compute_test cs_w32_saveexec_ext.spv 1 dump -> out[0..7] = 4096 2560 6656 5642 4608 542 4106 2560
; mattr: +wavefrontsize32,-wavefrontsize64
v_cmp_le_u32_e64 s20, 10, v0
v_cmp_gt_u32_e64 s21, 30, v0
s_and_b32 s20, s20, s21
s_mov_b32 exec_lo, -1
v_cmpx_gt_u32_e32 24, v0
s_xor_saveexec_b32 s6, s20
s_bcnt1_i32_b32 s7, exec_lo
s_ff1_i32_b32 s8, exec_lo
s_lshl_b32 s7, s7, 8
s_or_b32 s10, s7, s8
s_mov_b32 exec_lo, -1
v_cmpx_gt_u32_e32 24, v0
s_andn1_saveexec_b32 s6, s20
s_bcnt1_i32_b32 s7, exec_lo
s_ff1_i32_b32 s8, exec_lo
s_lshl_b32 s7, s7, 8
s_or_b32 s11, s7, s8
s_mov_b32 exec_lo, -1
v_cmpx_gt_u32_e32 24, v0
s_orn1_saveexec_b32 s6, s20
s_bcnt1_i32_b32 s7, exec_lo
s_ff1_i32_b32 s8, exec_lo
s_lshl_b32 s7, s7, 8
s_or_b32 s12, s7, s8
s_mov_b32 exec_lo, -1
v_cmpx_gt_u32_e32 24, v0
s_orn2_saveexec_b32 s6, s20
s_bcnt1_i32_b32 s7, exec_lo
s_ff1_i32_b32 s8, exec_lo
s_lshl_b32 s7, s7, 8
s_or_b32 s13, s7, s8
s_mov_b32 exec_lo, -1
v_cmpx_gt_u32_e32 24, v0
s_nand_saveexec_b32 s6, s20
s_bcnt1_i32_b32 s7, exec_lo
s_ff1_i32_b32 s8, exec_lo
s_lshl_b32 s7, s7, 8
s_or_b32 s14, s7, s8
s_mov_b32 exec_lo, -1
v_cmpx_gt_u32_e32 24, v0
s_nor_saveexec_b32 s6, s20
s_bcnt1_i32_b32 s7, exec_lo
s_ff1_i32_b32 s8, exec_lo
s_lshl_b32 s7, s7, 8
s_or_b32 s15, s7, s8
s_mov_b32 exec_lo, -1
v_cmpx_gt_u32_e32 24, v0
s_xnor_saveexec_b32 s6, s20
s_bcnt1_i32_b32 s7, exec_lo
s_ff1_i32_b32 s8, exec_lo
s_lshl_b32 s7, s7, 8
s_or_b32 s16, s7, s8
s_mov_b32 exec_lo, -1
v_cmpx_gt_u32_e32 24, v0
s_andn1_wrexec_b32 s6, s20
s_bcnt1_i32_b32 s7, exec_lo
s_ff1_i32_b32 s8, exec_lo
s_lshl_b32 s7, s7, 8
s_or_b32 s17, s7, s8
s_mov_b32 exec_lo, -1
v_cmpx_eq_u32_e32 0, v0
v_mov_b32_e32 v2, 0
v_mov_b32_e32 v1, s10
buffer_store_dword v1, v2, s[0:3], 0 offen
v_mov_b32_e32 v2, 4
v_mov_b32_e32 v1, s11
buffer_store_dword v1, v2, s[0:3], 0 offen
v_mov_b32_e32 v2, 8
v_mov_b32_e32 v1, s12
buffer_store_dword v1, v2, s[0:3], 0 offen
v_mov_b32_e32 v2, 12
v_mov_b32_e32 v1, s13
buffer_store_dword v1, v2, s[0:3], 0 offen
v_mov_b32_e32 v2, 16
v_mov_b32_e32 v1, s14
buffer_store_dword v1, v2, s[0:3], 0 offen
v_mov_b32_e32 v2, 20
v_mov_b32_e32 v1, s15
buffer_store_dword v1, v2, s[0:3], 0 offen
v_mov_b32_e32 v2, 24
v_mov_b32_e32 v1, s16
buffer_store_dword v1, v2, s[0:3], 0 offen
v_mov_b32_e32 v2, 28
v_mov_b32_e32 v1, s17
buffer_store_dword v1, v2, s[0:3], 0 offen
s_endpgm
6 changes: 4 additions & 2 deletions 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_w32_saveexec_ext", "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",
"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 All @@ -1224,6 +1224,8 @@ def run_suite(a, work: str) -> int:
"cs_movrelsd_2": [11, 33, 33, 55, 1717, 77, 1515, 1717],
# SHADER-90: ds_permute_b32 (cs_w32_permute.asm): scatter, unwritten lane = 0, EXEC gates the write
"cs_w32_permute": [218, 29, 8, 211, 0, 15, 99, 15],
# #1657's saveexec / wrexec kinds (cs_w32_saveexec_ext.asm header)
"cs_w32_saveexec_ext": [0x1000, 0xA00, 0x1A00, 0x160A, 0x1200, 0x21E, 0x100A, 0xA00],
# integer ops with CPU-only checks until now (cs_w32_int_ext.asm)
"cs_w32_int_ext": [1, 27, 1, 0x33332222, 0xC0000000, 0x4000, 18, 0x20304050],
# 64-bit scalar data ops and v_mad_u64_u32 (cs_w32_salu64.asm)
Expand Down Expand Up @@ -1338,7 +1340,7 @@ def run_suite(a, work: str) -> int:
"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_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_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_w32_saveexec_ext",
"cs_lds_b64_cmpst", "cs_lds_xchg64_ext", "cs_lds_atomics_ext", "cs_exec_const", "cs_w32_mask_imm", "cs_mask_vgpr_exec",
"cs_dpp", "cs_dpp_row", "cs_dpp_mask", "cs_dpp8",
"cs_dpp_ops", "cs_dpp_bound", "cs_dpp_bank", "cs_dpp_fi", "cs_dpp_cmp", "cs_w32_andn2_exec",
Expand Down
87 changes: 87 additions & 0 deletions tests/semantic/fixtures/disasm/cs_w32_saveexec_ext.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
; cs_w32_saveexec_ext test fixture generated by tests/semantic/regen_fixtures.py from runtime/test/shaders/cs_w32_saveexec_ext.asm
v_cmp_le_u32_e64 s20, 10, v0
v_cmp_gt_u32_e64 s21, 30, v0
s_and_b32 s20, s20, s21
s_mov_b32 exec_lo, -1
v_cmpx_gt_u32_e32 24, v0
s_xor_saveexec_b32 s6, s20
s_bcnt1_i32_b32 s7, exec_lo
s_ff1_i32_b32 s8, exec_lo
s_lshl_b32 s7, s7, 8
s_or_b32 s10, s7, s8
s_mov_b32 exec_lo, -1
v_cmpx_gt_u32_e32 24, v0
s_andn1_saveexec_b32 s6, s20
s_bcnt1_i32_b32 s7, exec_lo
s_ff1_i32_b32 s8, exec_lo
s_lshl_b32 s7, s7, 8
s_or_b32 s11, s7, s8
s_mov_b32 exec_lo, -1
v_cmpx_gt_u32_e32 24, v0
s_orn1_saveexec_b32 s6, s20
s_bcnt1_i32_b32 s7, exec_lo
s_ff1_i32_b32 s8, exec_lo
s_lshl_b32 s7, s7, 8
s_or_b32 s12, s7, s8
s_mov_b32 exec_lo, -1
v_cmpx_gt_u32_e32 24, v0
s_orn2_saveexec_b32 s6, s20
s_bcnt1_i32_b32 s7, exec_lo
s_ff1_i32_b32 s8, exec_lo
s_lshl_b32 s7, s7, 8
s_or_b32 s13, s7, s8
s_mov_b32 exec_lo, -1
v_cmpx_gt_u32_e32 24, v0
s_nand_saveexec_b32 s6, s20
s_bcnt1_i32_b32 s7, exec_lo
s_ff1_i32_b32 s8, exec_lo
s_lshl_b32 s7, s7, 8
s_or_b32 s14, s7, s8
s_mov_b32 exec_lo, -1
v_cmpx_gt_u32_e32 24, v0
s_nor_saveexec_b32 s6, s20
s_bcnt1_i32_b32 s7, exec_lo
s_ff1_i32_b32 s8, exec_lo
s_lshl_b32 s7, s7, 8
s_or_b32 s15, s7, s8
s_mov_b32 exec_lo, -1
v_cmpx_gt_u32_e32 24, v0
s_xnor_saveexec_b32 s6, s20
s_bcnt1_i32_b32 s7, exec_lo
s_ff1_i32_b32 s8, exec_lo
s_lshl_b32 s7, s7, 8
s_or_b32 s16, s7, s8
s_mov_b32 exec_lo, -1
v_cmpx_gt_u32_e32 24, v0
s_andn1_wrexec_b32 s6, s20
s_bcnt1_i32_b32 s7, exec_lo
s_ff1_i32_b32 s8, exec_lo
s_lshl_b32 s7, s7, 8
s_or_b32 s17, s7, s8
s_mov_b32 exec_lo, -1
v_cmpx_eq_u32_e32 0, v0
v_mov_b32_e32 v2, 0
v_mov_b32_e32 v1, s10
buffer_store_dword v1, v2, s[0:3], 0 offen
v_mov_b32_e32 v2, 4
v_mov_b32_e32 v1, s11
buffer_store_dword v1, v2, s[0:3], 0 offen
v_mov_b32_e32 v2, 8
v_mov_b32_e32 v1, s12
buffer_store_dword v1, v2, s[0:3], 0 offen
v_mov_b32_e32 v2, 12
v_mov_b32_e32 v1, s13
buffer_store_dword v1, v2, s[0:3], 0 offen
v_mov_b32_e32 v2, 16
v_mov_b32_e32 v1, s14
buffer_store_dword v1, v2, s[0:3], 0 offen
v_mov_b32_e32 v2, 20
v_mov_b32_e32 v1, s15
buffer_store_dword v1, v2, s[0:3], 0 offen
v_mov_b32_e32 v2, 24
v_mov_b32_e32 v1, s16
buffer_store_dword v1, v2, s[0:3], 0 offen
v_mov_b32_e32 v2, 28
v_mov_b32_e32 v1, s17
buffer_store_dword v1, v2, s[0:3], 0 offen
s_endpgm
70 changes: 70 additions & 0 deletions tests/semantic/test_saveexec_ext_fixture.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
"""cs_w32_saveexec_ext: the GPU test of #1657's saveexec / wrexec kinds, run here on the CPU too.

Standard library only; no GPU, no LLVM, no game files.

runtime/test/shaders/cs_w32_saveexec_ext.asm runs s_xor/andn1/orn1/orn2/nand/nor/xnor_saveexec_b32 and
s_andn1_wrexec_b32 with EXEC = lanes 0..23 and S0 = lanes 10..29 (both from compares) and stores, per op,
(s_bcnt1 << 8) | s_ff1 of the new EXEC. This runs its fixture (tests/semantic/regen_fixtures.py) as one wave32 group
through spirv_mini_interp, checks the words against tools/cf_ref.py's _SAVEEXEC (the FUZZ-8 ISA model), and checks
that check.py and scripts/run_gpu_tests.py expect the same words on the GPU.
"""
import os
import re
import struct
import sys
import unittest

HERE = os.path.dirname(os.path.abspath(__file__))
if HERE not in sys.path:
sys.path.insert(0, HERE) # python -I leaves the script's folder off sys.path

import support # noqa: E402 (support puts tools/ on sys.path, honouring LEONIDA_TOOLS_DIR)
import spirv_mini_interp as si # noqa: E402
import cf_ref # noqa: E402

ROOT = os.path.dirname(os.path.dirname(HERE))
M32 = 0xFFFFFFFF

FSSM = bytearray(0x148)
struct.pack_into("<4I", FSSM, 0x138, 0x88, 32, 1, 1) # 4 user SGPRs (the V#), workgroup id in s4, 32x1x1
FSSM = bytes(FSSM)
VSHARP = [0, 0, 0x1000, 0x31016FAC]

S0 = sum(1 << i for i in range(10, 30))
EXEC = sum(1 << i for i in range(24))
KINDS = ("xor", "andn1", "orn1", "orn2", "nand", "nor", "xnor", "andn1") # the last is s_andn1_wrexec_b32


def word(mask):
return bin(mask).count("1") << 8 | ((mask & -mask).bit_length() - 1)


EXPECTED = [word(cf_ref._SAVEEXEC[k](S0, EXEC, M32) & M32) for k in KINDS]


class SaveexecExtFixture(unittest.TestCase):
def test_reference(self):
self.assertEqual(EXPECTED, [0x1000, 0xA00, 0x1A00, 0x160A, 0x1200, 0x21E, 0x100A, 0xA00])

def test_translated_shader(self):
spv = support.translate_fixture("cs_w32_saveexec_ext", fssm=FSSM)
mem = si.run_workgroup(spv, 32, 32, inputs_for=lambda i: {"%wg_id": (0, 0, 0), "%local_id": (i, 0, 0),
"%sg_lane": i},
push_constants=VSHARP + [0] * 28, memory={})
self.assertEqual(sorted(mem), [4 * k for k in range(8)])
for k, want in enumerate(EXPECTED):
with self.subTest(word=k, op=KINDS[k]):
self.assertEqual(mem[4 * k], want)

def test_gpu_runners_expect_the_same_words(self):
for rel in (("runtime", "test", "shaders", "check.py"), ("scripts", "run_gpu_tests.py")):
with open(os.path.join(ROOT, *rel), encoding="utf-8") as f:
text = f.read()
m = re.search(r'"cs_w32_saveexec_ext"\)?[,:]\s*\[([^\]]*)\]', text)
with self.subTest(file="/".join(rel)):
self.assertIsNotNone(m)
self.assertEqual([int(v, 0) for v in m.group(1).split(",")], EXPECTED)


if __name__ == "__main__":
unittest.main()
Loading