Skip to content
Draft
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
4 changes: 2 additions & 2 deletions docs/design.md

Large diffs are not rendered by default.

17 changes: 14 additions & 3 deletions runtime/test/shaders/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,30 @@ def barycentric_fallback():
return False


def asm_mattr(path):
def asm_header_value(path, key):
"""The value of "; <key>: <value>" in a fixture's leading comment lines, or None."""
for ln in Path(path).read_text(encoding="utf-8").splitlines():
s = ln.strip()
if not s:
continue
if not s.startswith(";"):
break
m = re.match(r";\s*mattr:\s*(\S+)", s)
m = re.match(r";\s*" + key + r":\s*(\S+)", s)
if m:
return m.group(1)
return None


def asm_mattr(path):
return asm_header_value(path, "mattr")


def asm_mcpu(path):
"""llvm-mc's -mcpu for a fixture: gfx1013, or "; mcpu: <cpu>" for one that needs another target (GFX10.3-only
instructions such as global_atomic_csub, which gfx1013 rejects)."""
return asm_header_value(path, "mcpu") or "gfx1013"


CLIP_CASES = {"vs_clip": 1, "vs_clip_param4": 4, "vs_clip_undeclared": 1}


Expand Down Expand Up @@ -158,7 +169,7 @@ def translate_tests(work, names):
if shift and n.startswith("cs_"):
raw = shift_user_data(raw, shift)
mattr = asm_mattr(asm_path)
cmd = MC + ["-triple=amdgcn--amdpal", "-mcpu=gfx1013"]
cmd = MC + ["-triple=amdgcn--amdpal", f"-mcpu={asm_mcpu(asm_path)}"]
if n in CLIP_CASES:
cmd.append(f"-defsym=PARAM_SLOT={CLIP_CASES[n]}")
if mattr:
Expand Down
9 changes: 7 additions & 2 deletions runtime/test/shaders/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def not_found_message(build, missing):
"cs_barrier_divergent", "cs_barrier_early_end", "cs_barrier_loop", "cs_w32_lds_u8_d16", "cs_bpermute32",
"cs_w32_lds_subdword", "cs_w32_lds_wide",
"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_w32_salu64", "cs_w32_misc_ext", "cs_w32_new_ops", "cs_w32_dot_int", "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")
# Wave32 lane-mask dumps: their EXEC/VCC masks and lane selects cover 32 lanes, so a device whose widest subgroup is
Expand Down Expand Up @@ -147,6 +147,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]),
# the packed integer dot products, with clamp (derivations in cs_w32_dot_int.asm)
("cs_w32_dot_int", [0x00000081, 0xFFFF7F04, 0x00004288, 0xFFFFFFDA, 0x00000104, 0xFFFFFFFF, 0x7FFFFFFE, 0x7FFFFFFF]),
("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
Expand Down Expand Up @@ -341,7 +343,10 @@ def not_found_message(build, missing):
GLOBAL_OFFSET = [("cs_global_neg_offset", "40", [0x5EED1FFC, 0x8BAD1800, 0x5EED1FF0, 0x5EED1FF4,
0x0000009E, 0xFFFF8BAD, 0x57023FFC, 0xEEEEEEEE]),
# global/buffer atomics, 8/16-bit global stores and d16 loads with CPU-only checks until now
("cs_global_mem_ext", "40", [0x5, 0xC, 0x977, 0xFFF00000, 0xEDCB5678, 0xEF332211, 0x887766BE, 0xFF801234])]
("cs_global_mem_ext", "40", [0x5, 0xC, 0x977, 0xFFF00000, 0xEDCB5678, 0xEF332211, 0x887766BE, 0xFF801234]),
# global/buffer_atomic_csub: the clamp at 0, glc, and 32 lanes on one dword (cases in the .asm header)
("cs_global_csub", "40", [0x10070905, 0x0D070000, 0x00630064, 0x80000000, 0x00000000,
0xFFFFFFFE, 0x000C0500, 0x01D800D2])]
# cs_heap_init.asm: vk_compute_test's VKC_HEAP_INIT copies this file (zeros, then four words at 0x100) to the start
# of the heap; the shader copies the four words to 0, and out[4..7] are the file's zeros, not the 0xEE fill.
HEAP_INIT_WORDS = [0x1BADB002, 0xCAFEF00D, 0x80000001, 0x0000FFFF]
Expand Down
138 changes: 138 additions & 0 deletions runtime/test/shaders/cs_global_csub.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
; mcpu: gfx1030
; mattr: +wavefrontsize32,-wavefrontsize64
; global_atomic_csub and buffer_atomic_csub (GFX10.3): tmp = M; M = (DATA > tmp) ? 0 : tmp - DATA, unsigned, a
; subtract clamped at 0 that never wraps; with glc the old M comes back (docs/design.md, measured on gfx1036 by #3193).
; gfx1013 has neither instruction, so this file is assembled for gfx1030 (the "; mcpu:" line above). llvm-mc takes
; global_atomic_csub with a destination only with glc; without glc it has none.
; Run with 40 groups (vk_compute_test cs_global_csub.spv 40 dump): the heap is 40 * 256 = 0x2800 bytes, global
; addresses are heap offsets (s[20:21] = P = 0x2000, v30 = 0), as in cs_global_mem_ext. Wave32, 64 threads a group.
; 1. Group 0 thread 0 seeds 12 dwords through the V# in s[0:3]; then every thread meets at s_barrier.
; P+0x00 5 P+0x04 9 P+0x08 100 P+0x0c 0x80000000 P+0x10 0xffffffff P+0x14 7 P+0x18 0x10
; P+0x1c 2 P+0x20 20 P+0x24 0 P+0x28 0 P+0x2c 1000
; 2. Contention, the 32 lanes of group 0's first wave at once:
; global_atomic_csub glc of 1 at P+0x20 (20): the old values are 20, 19, ..., 1 and then 0 twelve times; M ends
; at 0. Each lane adds its old value to P+0x24 (sum 210) and adds 1 to P+0x28 when it got 0 (12).
; global_atomic_csub without glc of lane + 1 at P+0x2c (1000): 1 + ... + 32 = 528 never reaches 0, M = 472.
; A subtract that wraps would leave 0xfffffff4 at P+0x20; one that is not atomic would lose updates.
; Then every thread meets at s_barrier again.
; 3. Group 0 thread 0, one case each (old value with glc, then M after):
; A global glc 7 at P+0x00 (5): old 5, M 0 (DATA > M) B global glc 9 at P+0x04 (9): old 9, M 0 (DATA == M)
; C global glc 1 at P+0x08 (100): old 100, M 99 D global glc 0xffffffff at P+0x0c: old 0x80000000, M 0
; (a subtract without the clamp leaves 0x80000000 - 0xffffffff = 0x80000001)
; E global, no glc, 1 at P+0x10 (0xffffffff): M 0xfffffffe (a signed compare reads 1 > -1 and leaves 0)
; F global glc 0 at P+0x14 (7): old 7, M 7 G buffer glc 3 at 0x2018 (0x10): old 0x10, M 0xd
; H buffer, no glc, 5 at 0x201c (2): M 0, and its data register keeps 5
; vk_compute_test dumps out[0..7], so the small values are packed a byte or a half each (a wrong value spills into
; its neighbours, which still shows):
; out[0] = A old | B old << 8 | F old << 16 | G old << 24 = 0x10070905
; out[1] = A M | B M << 8 | F M << 16 | G M << 24 = 0x0d070000
; out[2] = C old | C M << 16 = 0x00630064
; out[3] = D old = 0x80000000
; out[4] = D M = 0x00000000
; out[5] = E M = 0xfffffffe
; out[6] = H M | H data register << 8 | lanes that got 0 << 16 | P+0x20 after << 24 = 0x000c0500
; out[7] = sum of the old values | P+0x2c after << 16 = 0x01d800d2
s_mov_b32 s40, exec_lo
v_or_b32_e32 v1, s4, v0
v_cmpx_eq_u32_e32 0, v1
v_mov_b32_e32 v2, 0x2000
v_mov_b32_e32 v1, 5
buffer_store_dword v1, v2, s[0:3], 0 offen offset:0
v_mov_b32_e32 v1, 9
buffer_store_dword v1, v2, s[0:3], 0 offen offset:4
v_mov_b32_e32 v1, 0x64
buffer_store_dword v1, v2, s[0:3], 0 offen offset:8
v_bfrev_b32_e32 v1, 1
buffer_store_dword v1, v2, s[0:3], 0 offen offset:12
v_mov_b32_e32 v1, -1
buffer_store_dword v1, v2, s[0:3], 0 offen offset:16
v_mov_b32_e32 v1, 7
buffer_store_dword v1, v2, s[0:3], 0 offen offset:20
v_mov_b32_e32 v1, 0x10
buffer_store_dword v1, v2, s[0:3], 0 offen offset:24
v_mov_b32_e32 v1, 2
buffer_store_dword v1, v2, s[0:3], 0 offen offset:28
v_mov_b32_e32 v1, 20
buffer_store_dword v1, v2, s[0:3], 0 offen offset:32
v_mov_b32_e32 v1, 0
buffer_store_dword v1, v2, s[0:3], 0 offen offset:36
buffer_store_dword v1, v2, s[0:3], 0 offen offset:40
v_mov_b32_e32 v1, 0x3e8
buffer_store_dword v1, v2, s[0:3], 0 offen offset:44
s_waitcnt vmcnt(0)
s_mov_b32 exec_lo, s40
s_barrier
s_mov_b32 s20, 0x2000
s_mov_b32 s21, 0
v_lshrrev_b32_e32 v1, 5, v0
v_or_b32_e32 v1, s4, v1
v_cmpx_eq_u32_e32 0, v1
v_mov_b32_e32 v30, 0
v_mov_b32_e32 v3, 1
global_atomic_csub v10, v30, v3, s[20:21] offset:32 glc
s_waitcnt vmcnt(0)
global_atomic_add v30, v10, s[20:21] offset:36
v_cmp_eq_u32_e32 vcc_lo, 0, v10
v_cndmask_b32_e64 v11, 0, 1, vcc_lo
global_atomic_add v30, v11, s[20:21] offset:40
v_add_nc_u32_e32 v12, 1, v0
global_atomic_csub v30, v12, s[20:21] offset:44
s_waitcnt vmcnt(0)
s_mov_b32 exec_lo, s40
s_barrier
v_or_b32_e32 v1, s4, v0
v_cmpx_eq_u32_e32 0, v1
v_mov_b32_e32 v30, 0
v_mov_b32_e32 v3, 7
global_atomic_csub v20, v30, v3, s[20:21] glc
v_mov_b32_e32 v3, 9
global_atomic_csub v21, v30, v3, s[20:21] offset:4 glc
v_mov_b32_e32 v3, 1
global_atomic_csub v22, v30, v3, s[20:21] offset:8 glc
v_mov_b32_e32 v3, -1
global_atomic_csub v23, v30, v3, s[20:21] offset:12 glc
v_mov_b32_e32 v3, 1
global_atomic_csub v30, v3, s[20:21] offset:16
v_mov_b32_e32 v3, 0
global_atomic_csub v24, v30, v3, s[20:21] offset:20 glc
v_mov_b32_e32 v25, 3
v_mov_b32_e32 v2, 0x2018
buffer_atomic_csub v25, v2, s[0:3], 0 offen glc
v_mov_b32_e32 v26, 5
v_mov_b32_e32 v2, 0x201c
buffer_atomic_csub v26, v2, s[0:3], 0 offen
s_waitcnt vmcnt(0)
global_load_dword v40, v30, s[20:21]
global_load_dword v41, v30, s[20:21] offset:4
global_load_dword v42, v30, s[20:21] offset:8
global_load_dword v43, v30, s[20:21] offset:12
global_load_dword v44, v30, s[20:21] offset:16
global_load_dword v45, v30, s[20:21] offset:20
global_load_dword v46, v30, s[20:21] offset:24
global_load_dword v47, v30, s[20:21] offset:28
global_load_dword v48, v30, s[20:21] offset:32
global_load_dword v49, v30, s[20:21] offset:36
global_load_dword v50, v30, s[20:21] offset:40
global_load_dword v51, v30, s[20:21] offset:44
s_waitcnt vmcnt(0)
v_lshl_or_b32 v60, v21, 8, v20
v_lshl_or_b32 v60, v24, 16, v60
v_lshl_or_b32 v60, v25, 24, v60
v_lshl_or_b32 v61, v41, 8, v40
v_lshl_or_b32 v61, v45, 16, v61
v_lshl_or_b32 v61, v46, 24, v61
v_lshl_or_b32 v62, v42, 16, v22
v_lshl_or_b32 v66, v26, 8, v47
v_lshl_or_b32 v66, v50, 16, v66
v_lshl_or_b32 v66, v48, 24, v66
v_lshl_or_b32 v67, v51, 16, v49
v_mov_b32_e32 v2, 0
buffer_store_dword v60, v2, s[0:3], 0 offen offset:0
buffer_store_dword v61, v2, s[0:3], 0 offen offset:4
buffer_store_dword v62, v2, s[0:3], 0 offen offset:8
buffer_store_dword v23, v2, s[0:3], 0 offen offset:12
buffer_store_dword v43, v2, s[0:3], 0 offen offset:16
buffer_store_dword v44, v2, s[0:3], 0 offen offset:20
buffer_store_dword v66, v2, s[0:3], 0 offen offset:24
buffer_store_dword v67, v2, s[0:3], 0 offen offset:28
s_endpgm
62 changes: 62 additions & 0 deletions runtime/test/shaders/cs_w32_dot_int.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
; mcpu: gfx1030
; The packed integer dot products (VOP3P), run on a GPU; until now CPU-checked by the semantic tests and measured with
; tools/hw_oracle, but no fixture ran the translation (docs/design.md, "Packed integer dot products"). D = the sum of
; the element products + S2, each element sign- (i) or zero-extended (u), wrapping at 32 bits; with clamp the exact sum
; saturates to [INT32_MIN, INT32_MAX] (i32) or [0, UINT32_MAX] (u32). gfx1013 has none of these instructions, so this
; file is assembled for gfx1030 (the "; mcpu:" line above). Elements are numbered from bit 0.
; out[0] v_dot2_i32_i16 0x0003fffe, 0x0005fff9, 100 (-2)(-7) + 3*5 + 100 = 129 0x00000081
; out[1] v_dot2_u32_u16 0xffff8001, 0xffff0003, 0xffffff00 32769*3 + 65535^2 + 0xffffff00 wraps once 0xffff7f04
; out[2] v_dot4_u32_u8 0x80ff0102, 0x7f02ff03, 5 2*3 + 1*255 + 255*2 + 128*127 + 5 = 17032 0x00004288
; out[3] v_dot8_i32_i4 0x8f01f7a3, 0x12345678, -3 signed nibbles: -35 - 3 = -38 0xffffffda
; out[4] v_dot8_u32_u4 0x8f01f7a3, 0x12345678, 7 unsigned nibbles: 253 + 7 = 260 0x00000104
; out[5] v_dot2_u32_u16 0xffffffff, 0xffffffff, 0xffffffff clamp 2*65535^2 + 0xffffffff > UINT32_MAX 0xffffffff
; out[6] v_dot2_i32_i16 0x80008000, 0x80008000, -2 clamp 2^31 - 2: the products overflow, the sum does not
; 0x7ffffffe
; out[7] v_dot2_i32_i16 0x80008000, 0x80008000, 0 clamp 2^31 > INT32_MAX 0x7fffffff
; group: 32,1,1
; Run: vk_compute_test cs_w32_dot_int.spv 1 dump -> out[0..7] = 129 4294934276 17032 4294967258 260 4294967295
; 2147483646 2147483647
; mattr: +wavefrontsize32,-wavefrontsize64
v_mov_b32_e32 v1, 0x0003fffe
v_mov_b32_e32 v2, 0x0005fff9
v_mov_b32_e32 v3, 0x64
v_dot2_i32_i16 v10, v1, v2, v3
v_mov_b32_e32 v1, 0xffff8001
v_mov_b32_e32 v2, 0xffff0003
v_mov_b32_e32 v3, 0xffffff00
v_dot2_u32_u16 v11, v1, v2, v3
v_mov_b32_e32 v1, 0x80ff0102
v_mov_b32_e32 v2, 0x7f02ff03
v_mov_b32_e32 v3, 5
v_dot4_u32_u8 v12, v1, v2, v3
v_mov_b32_e32 v1, 0x8f01f7a3
v_mov_b32_e32 v2, 0x12345678
v_mov_b32_e32 v3, -3
v_dot8_i32_i4 v13, v1, v2, v3
v_mov_b32_e32 v3, 7
v_dot8_u32_u4 v14, v1, v2, v3
v_mov_b32_e32 v1, -1
v_dot2_u32_u16 v15, v1, v1, v1 clamp
v_mov_b32_e32 v1, 0x80008000
v_mov_b32_e32 v3, -2
v_dot2_i32_i16 v16, v1, v1, v3 clamp
v_mov_b32_e32 v3, 0
v_dot2_i32_i16 v17, v1, v1, v3 clamp
v_cmpx_eq_u32_e32 0, v0
v_mov_b32_e32 v25, 0
buffer_store_dword v10, v25, s[0:3], 0 offen
v_mov_b32_e32 v25, 4
buffer_store_dword v11, v25, s[0:3], 0 offen
v_mov_b32_e32 v25, 8
buffer_store_dword v12, v25, s[0:3], 0 offen
v_mov_b32_e32 v25, 12
buffer_store_dword v13, v25, s[0:3], 0 offen
v_mov_b32_e32 v25, 16
buffer_store_dword v14, v25, s[0:3], 0 offen
v_mov_b32_e32 v25, 20
buffer_store_dword v15, v25, s[0:3], 0 offen
v_mov_b32_e32 v25, 24
buffer_store_dword v16, v25, s[0:3], 0 offen
v_mov_b32_e32 v25, 28
buffer_store_dword v17, v25, s[0:3], 0 offen
s_endpgm
Loading
Loading