diff --git a/runtime/test/shaders/check.py b/runtime/test/shaders/check.py index f0ddf2f315..c60a41f7c1 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_w32_pk_rel_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 @@ -150,6 +150,8 @@ def not_found_message(build, missing): # ds_cmpst_f32 and buffer_atomic_fcmpswap: float compare (cs_w32_fcmpswap.asm) ("cs_w32_fcmpswap", [0, 0x3F800000, 0x7FC00000, 0x3F800000, 0x80000000, 0x40400000, 0x3F800000, 0x7FC00000]), ("cs_w32_new_ops", [0x55, 0x8001, 0xC0000000, 0x80014000, 0x4000FFFF, 0x77, 0x99, 0x1234]), + # packed 16-bit ints, v_swaprel, s_movrels, ds_or/xor_b64 (derivations in cs_w32_pk_rel_ext.asm) + ("cs_w32_pk_rel_ext", [0xFFFF0003, 0x7FFFFFFE, 0x00110012, 0x00010000, 0x105, 0x102, 0x203, 0x00F0FF00]), ("cs_w32_misc_ext", [0x0FFF0FFF, 0xE2C4A688, 0x0007FFFF, 0x7FFF8000, 0xFFFE0002, 0xFFFF0005, 0x509, 0xCAFEF00D]), ("cs_w32_salu64", [0x1E6A2C48, 0x1234, 0xFFFFFFFF, 0x100, 47, 48, 0xFFFF8000, 0xFFFFFFFE]), # SHADER-85: 8-bit LDS reads into one half of a VGPR, the other half kept diff --git a/runtime/test/shaders/cs_w32_pk_rel_ext.asm b/runtime/test/shaders/cs_w32_pk_rel_ext.asm new file mode 100644 index 0000000000..1da3e18dbb --- /dev/null +++ b/runtime/test/shaders/cs_w32_pk_rel_ext.asm @@ -0,0 +1,78 @@ +; Ops merged with CPU-only checks (#1649 packed 16-bit integer ops, #1673 v_swaprel_b32, #1598 s_movrels_b32, +; #1539 ds_or/xor_b64), run once on a GPU. Lane 0 of a wave32 group stores eight dwords: +; out[0] = v_pk_add_u16(0xFFFF0001, 0x00010002) clamp = 0xFFFF0003 (high half saturates) +; out[1] = v_pk_sub_i16(0x80000005, 0x00010007) = 0x7FFFFFFE (wraps: -32768-1, 5-7) +; out[2] = v_pk_mad_u16(0x00030002, 0x00050004, 0x00070006) op_sel:[1,0,0] op_sel_hi:[0,1,1] = 0x00110012 +; (low half: S0.hi * S1.lo + S2.lo = 3*4+6; high half: S0.lo * S1.hi + S2.hi = 2*5+7) +; out[3] = v_pk_max_i16(0x8000FFFF, 0x00010000) = 0x00010000 +; out[4], out[5] = v12, v15 after v_swaprel_b32 v10, v11 with M0 = (2 << 16) | 4: swaps v12 and v15 +; (v10..v15 = 0x100..0x105) = 0x105, 0x102 +; out[6] = s_movrels_b32 s30, s20 with M0 = 3 (s20..s23 = 0x200..0x203) = 0x203 +; out[7] = ds_or_rtn_b64 old high dword ^ the LDS high dword after ds_xor_b64 (lane 0 only: EXEC is cut to +; lane 0 before the LDS ops, since 32 lanes on one address would cancel the XOR in pairs): (0x11110000) ^ ((0x11110000 | +; 0x0000FF00) ^ 0x00F00000) = 0x00F0FF00 +; group: 32,1,1 +; Run: vk_compute_test cs_w32_pk_rel_ext.spv 1 dump -> out[0..7] = 4294901763 2147483646 1114130 65536 261 258 515 15793920 +; mattr: +wavefrontsize32,-wavefrontsize64 +; regen_fixtures: this source has a translator fixture in tests/semantic/fixtures/disasm +v_mov_b32_e32 v1, 0xffff0001 +v_mov_b32_e32 v2, 0x10002 +v_pk_add_u16 v3, v1, v2 clamp +v_mov_b32_e32 v1, 0x80000005 +v_mov_b32_e32 v2, 0x10007 +v_pk_sub_i16 v4, v1, v2 +v_mov_b32_e32 v1, 0x30002 +v_mov_b32_e32 v2, 0x50004 +v_mov_b32_e32 v5, 0x70006 +v_pk_mad_u16 v5, v1, v2, v5 op_sel:[1,0,0] op_sel_hi:[0,1,1] +v_mov_b32_e32 v1, 0x8000ffff +v_mov_b32_e32 v2, 0x10000 +v_pk_max_i16 v6, v1, v2 +v_mov_b32_e32 v10, 0x100 +v_mov_b32_e32 v11, 0x101 +v_mov_b32_e32 v12, 0x102 +v_mov_b32_e32 v13, 0x103 +v_mov_b32_e32 v14, 0x104 +v_mov_b32_e32 v15, 0x105 +s_mov_b32 m0, 0x20004 +v_swaprel_b32 v10, v11 +s_mov_b32 s20, 0x200 +s_mov_b32 s21, 0x201 +s_mov_b32 s22, 0x202 +s_mov_b32 s23, 0x203 +s_mov_b32 m0, 3 +s_movrels_b32 s30, s20 +v_cmpx_eq_u32_e32 0, v0 +v_mov_b32_e32 v16, 0x40 +v_mov_b32_e32 v18, 0 +v_mov_b32_e32 v19, 0x11110000 +ds_write_b64 v16, v[18:19] +s_waitcnt lgkmcnt(0) +v_mov_b32_e32 v20, 0 +v_mov_b32_e32 v21, 0xff00 +ds_or_rtn_b64 v[22:23], v16, v[20:21] +s_waitcnt lgkmcnt(0) +v_mov_b32_e32 v21, 0xf00000 +ds_xor_b64 v16, v[20:21] +s_waitcnt lgkmcnt(0) +ds_read_b64 v[24:25], v16 +s_waitcnt lgkmcnt(0) +v_xor_b32_e32 v7, v23, v25 +v_mov_b32_e32 v26, 0 +buffer_store_dword v3, v26, s[0:3], 0 offen +v_mov_b32_e32 v26, 4 +buffer_store_dword v4, v26, s[0:3], 0 offen +v_mov_b32_e32 v26, 8 +buffer_store_dword v5, v26, s[0:3], 0 offen +v_mov_b32_e32 v26, 12 +buffer_store_dword v6, v26, s[0:3], 0 offen +v_mov_b32_e32 v26, 16 +buffer_store_dword v12, v26, s[0:3], 0 offen +v_mov_b32_e32 v26, 20 +buffer_store_dword v15, v26, s[0:3], 0 offen +v_mov_b32_e32 v26, 24 +v_mov_b32_e32 v27, s30 +buffer_store_dword v27, v26, s[0:3], 0 offen +v_mov_b32_e32 v26, 28 +buffer_store_dword v7, v26, s[0:3], 0 offen +s_endpgm diff --git a/scripts/run_gpu_tests.py b/scripts/run_gpu_tests.py index 8ba62104d8..ee4436a13a 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_w32_pk_rel_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", @@ -1236,6 +1236,8 @@ def run_suite(a, work: str) -> int: # ds_cmpst_f32 and buffer_atomic_fcmpswap: float compare (cs_w32_fcmpswap.asm) "cs_w32_fcmpswap": [0, 0x3F800000, 0x7FC00000, 0x3F800000, 0x80000000, 0x40400000, 0x3F800000, 0x7FC00000], "cs_w32_new_ops": [0x55, 0x8001, 0xC0000000, 0x80014000, 0x4000FFFF, 0x77, 0x99, 0x1234], + # packed 16-bit ints, v_swaprel, s_movrels, ds_or/xor_b64 (cs_w32_pk_rel_ext.asm) + "cs_w32_pk_rel_ext": [0xFFFF0003, 0x7FFFFFFE, 0x00110012, 0x00010000, 0x105, 0x102, 0x203, 0x00F0FF00], "cs_w32_misc_ext": [0x0FFF0FFF, 0xE2C4A688, 0x0007FFFF, 0x7FFF8000, 0xFFFE0002, 0xFFFF0005, 0x509, 0xCAFEF00D], "cs_w32_salu64": [0x1E6A2C48, 0x1234, 0xFFFFFFFF, 0x100, 47, 48, 0xFFFF8000, 0xFFFFFFFE], # SHADER-85: ds_read_u8/i8_d16[_hi] (cs_w32_lds_u8_d16.asm header) @@ -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_pk_rel_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", diff --git a/tests/semantic/fixtures/disasm/cs_w32_pk_rel_ext.s b/tests/semantic/fixtures/disasm/cs_w32_pk_rel_ext.s new file mode 100644 index 0000000000..2d64dc4c61 --- /dev/null +++ b/tests/semantic/fixtures/disasm/cs_w32_pk_rel_ext.s @@ -0,0 +1,62 @@ +; cs_w32_pk_rel_ext test fixture generated by tests/semantic/regen_fixtures.py from runtime/test/shaders/cs_w32_pk_rel_ext.asm + v_mov_b32_e32 v1, 0xffff0001 + v_mov_b32_e32 v2, 0x10002 + v_pk_add_u16 v3, v1, v2 clamp + v_mov_b32_e32 v1, 0x80000005 + v_mov_b32_e32 v2, 0x10007 + v_pk_sub_i16 v4, v1, v2 + v_mov_b32_e32 v1, 0x30002 + v_mov_b32_e32 v2, 0x50004 + v_mov_b32_e32 v5, 0x70006 + v_pk_mad_u16 v5, v1, v2, v5 op_sel:[1,0,0] op_sel_hi:[0,1,1] + v_mov_b32_e32 v1, 0x8000ffff + v_mov_b32_e32 v2, 0x10000 + v_pk_max_i16 v6, v1, v2 + v_mov_b32_e32 v10, 0x100 + v_mov_b32_e32 v11, 0x101 + v_mov_b32_e32 v12, 0x102 + v_mov_b32_e32 v13, 0x103 + v_mov_b32_e32 v14, 0x104 + v_mov_b32_e32 v15, 0x105 + s_mov_b32 m0, 0x20004 + v_swaprel_b32 v10, v11 + s_mov_b32 s20, 0x200 + s_mov_b32 s21, 0x201 + s_mov_b32 s22, 0x202 + s_mov_b32 s23, 0x203 + s_mov_b32 m0, 3 + s_movrels_b32 s30, s20 + v_cmpx_eq_u32_e32 0, v0 + v_mov_b32_e32 v16, 0x40 + v_mov_b32_e32 v18, 0 + v_mov_b32_e32 v19, 0x11110000 + ds_write_b64 v16, v[18:19] + s_waitcnt lgkmcnt(0) + v_mov_b32_e32 v20, 0 + v_mov_b32_e32 v21, 0xff00 + ds_or_rtn_b64 v[22:23], v16, v[20:21] + s_waitcnt lgkmcnt(0) + v_mov_b32_e32 v21, 0xf00000 + ds_xor_b64 v16, v[20:21] + s_waitcnt lgkmcnt(0) + ds_read_b64 v[24:25], v16 + s_waitcnt lgkmcnt(0) + v_xor_b32_e32 v7, v23, v25 + v_mov_b32_e32 v26, 0 + buffer_store_dword v3, v26, s[0:3], 0 offen + v_mov_b32_e32 v26, 4 + buffer_store_dword v4, v26, s[0:3], 0 offen + v_mov_b32_e32 v26, 8 + buffer_store_dword v5, v26, s[0:3], 0 offen + v_mov_b32_e32 v26, 12 + buffer_store_dword v6, v26, s[0:3], 0 offen + v_mov_b32_e32 v26, 16 + buffer_store_dword v12, v26, s[0:3], 0 offen + v_mov_b32_e32 v26, 20 + buffer_store_dword v15, v26, s[0:3], 0 offen + v_mov_b32_e32 v26, 24 + v_mov_b32_e32 v27, s30 + buffer_store_dword v27, v26, s[0:3], 0 offen + v_mov_b32_e32 v26, 28 + buffer_store_dword v7, v26, s[0:3], 0 offen + s_endpgm diff --git a/tests/semantic/test_pk_rel_ext_fixture.py b/tests/semantic/test_pk_rel_ext_fixture.py new file mode 100644 index 0000000000..3bc44b7de3 --- /dev/null +++ b/tests/semantic/test_pk_rel_ext_fixture.py @@ -0,0 +1,105 @@ +"""cs_w32_pk_rel_ext: the GPU test of packed 16-bit ints, v_swaprel_b32, s_movrels_b32 and ds_or/xor_b64, on the CPU. + +Standard library only; no GPU, no LLVM, no game files. + +runtime/test/shaders/cs_w32_pk_rel_ext.asm (derivations in its header) has lane 0 of a wave32 group store +v_pk_add_u16 clamp, v_pk_sub_i16, v_pk_mad_u16 with op_sel, v_pk_max_i16, the two registers v_swaprel_b32 swapped, +an s_movrels_b32 result and an LDS word from ds_or_rtn_b64 / ds_xor_b64. This runs its fixture as one wave32 group +through spirv_mini_interp, checks the words against values computed here, and checks that check.py and +scripts/run_gpu_tests.py expect the same words. + +spirv_mini_interp gives every invocation its own LDS, so this cannot see lanes racing on one LDS address. The first +version ran the LDS ops in all 32 lanes, which passed here and failed on GPUs (an even number of ds_xor_b64 cancel; +found by @borislisandro and @tumbione on #1850); the .asm now cuts EXEC to lane 0 first, and +test_lds_ops_run_in_lane_0_only checks that order in the source. +""" +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 + +ROOT = os.path.dirname(os.path.dirname(HERE)) +M32 = 0xFFFFFFFF + +FSSM = bytearray(0x148) +struct.pack_into("<4I", FSSM, 0x138, 0x8088, 32, 1, 1) # 4 user SGPRs, wg id in s4, 512 bytes of LDS, 32x1x1 +FSSM = bytes(FSSM) +VSHARP = [0, 0, 0x1000, 0x31016FAC] + + +def halves(x): + return x & 0xFFFF, x >> 16 + + +def s16(x): + return x - 0x10000 if x & 0x8000 else x + + +def pack(lo, hi): + return (lo & 0xFFFF) | (hi & 0xFFFF) << 16 + + +a0, a1 = halves(0xFFFF0001), halves(0x00010002) +b0, b1 = halves(0x80000005), halves(0x00010007) +m0, m1, m2 = halves(0x00030002), halves(0x00050004), halves(0x00070006) +x0, x1 = halves(0x8000FFFF), halves(0x00010000) +regs = {10 + k: 0x100 + k for k in range(6)} +d, s = 10 + 2, 11 + 4 # M0 = (2 << 16) | 4 +regs[d], regs[s] = regs[s], regs[d] +lds_hi = 0x11110000 +old_hi = lds_hi +lds_hi |= 0x0000FF00 # ds_or_rtn_b64, high dword of DATA +lds_hi ^= 0x00F00000 # ds_xor_b64 + +EXPECTED = [ + pack(min(a0[0] + a1[0], 0xFFFF), min(a0[1] + a1[1], 0xFFFF)), # v_pk_add_u16 clamp + pack(s16(b0[0]) - s16(b1[0]), s16(b0[1]) - s16(b1[1])), # v_pk_sub_i16 + pack(m0[1] * m1[0] + m2[0], m0[0] * m1[1] + m2[1]), # v_pk_mad_u16 op_sel [1,0,0] / hi [0,1,1] + pack(max(s16(x0[0]), s16(x1[0])), max(s16(x0[1]), s16(x1[1]))), # v_pk_max_i16 + regs[12], regs[15], # v_swaprel_b32 + 0x200 + 3, # s_movrels_b32 s30, s20 with M0 = 3 + old_hi ^ lds_hi, # ds_or_rtn_b64 old ^ LDS after xor +] + + +class PkRelExtFixture(unittest.TestCase): + def test_reference(self): + self.assertEqual(EXPECTED, [0xFFFF0003, 0x7FFFFFFE, 0x00110012, 0x00010000, 0x105, 0x102, 0x203, 0x00F0FF00]) + + def test_translated_shader(self): + spv = support.translate_fixture("cs_w32_pk_rel_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): + self.assertEqual(mem[4 * k], want) + + def test_lds_ops_run_in_lane_0_only(self): + with open(os.path.join(ROOT, "runtime", "test", "shaders", "cs_w32_pk_rel_ext.asm"), encoding="utf-8") as f: + lines = [ln.strip() for ln in f if ln.strip() and not ln.startswith(";")] + cmpx = lines.index("v_cmpx_eq_u32_e32 0, v0") + first_ds = min(i for i, ln in enumerate(lines) if ln.startswith("ds_")) + self.assertLess(cmpx, first_ds) + + 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_pk_rel_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()