upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/test/shaders
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/test/shaders')
-rw-r--r--runtime/test/shaders/build.py24
-rw-r--r--runtime/test/shaders/check.py6
-rw-r--r--runtime/test/shaders/cs_smem_soffset_imm.asm61
3 files changed, 81 insertions, 10 deletions
diff --git a/runtime/test/shaders/build.py b/runtime/test/shaders/build.py
index 180d48ec5..09730a2b0 100644
--- a/runtime/test/shaders/build.py
+++ b/runtime/test/shaders/build.py
@@ -3,8 +3,9 @@
3 python3 -I runtime/test/shaders/build.py <out dir> [name ...] 3 python3 -I runtime/test/shaders/build.py <out dir> [name ...]
4 4
5Each .asm is RDNA2 assembly. It is assembled with llvm-mc (LLVM 21+ with the AMDGPU target; set LLVM_MC to its 5Each .asm is RDNA2 assembly. It is assembled with llvm-mc (LLVM 21+ with the AMDGPU target; set LLVM_MC to its
6path, as for the shaders stage). Listings, synthetic FSSM headers and DXBC containers are staged in a temporary 6path or to a whole command, as for the shaders stage). Listings, synthetic FSSM headers and DXBC containers are
7directory. After validation, the build writes <out>/spirv/<name>.spv and the translator metadata. 7staged in a temporary directory. After validation, the build writes <out>/spirv/<name>.spv and the translator
8metadata.
8 9
9Compute shaders can override the default header with leading "; group: X,Y,Z" and "; rsrc2: 0x..." comments. 10Compute shaders can override the default header with leading "; group: X,Y,Z" and "; rsrc2: 0x..." comments.
10The stage comes from the name's prefix. Mesh and geometry shaders (ms_, gs_) also need a DXBC container with 11The stage comes from the name's prefix. Mesh and geometry shaders (ms_, gs_) also need a DXBC container with
@@ -20,10 +21,15 @@ import tempfile
20from pathlib import Path 21from pathlib import Path
21 22
22HERE = os.path.dirname(os.path.abspath(__file__)) 23HERE = os.path.dirname(os.path.abspath(__file__))
23TRANSLATOR = os.path.join(HERE, "..", "..", "..", "tools", "rdna2spirv.py") 24TOOLS = os.path.join(HERE, "..", "..", "..", "tools")
24LLVM_MC = os.environ.get("LLVM_MC", "llvm-mc") 25TRANSLATOR = os.path.join(TOOLS, "rdna2spirv.py")
26sys.path.insert(0, TOOLS)
27import mc_command # noqa: E402
28
29MC = mc_command.mc_command()
30RSRC2, GROUP = 0x8088, (64, 1, 1)
25sys.path.insert(0, HERE) # this script is also run with python -I 31sys.path.insert(0, HERE) # this script is also run with python -I
26from compute_fixture import compute_header 32from compute_fixture import compute_header # noqa: E402
27 33
28 34
29def asm_mattr(path): 35def asm_mattr(path):
@@ -45,12 +51,14 @@ def translate_tests(work, names):
45 fssm.mkdir() 51 fssm.mkdir()
46 for n in names: 52 for n in names:
47 asm_path = os.path.join(HERE, n + ".asm") 53 asm_path = os.path.join(HERE, n + ".asm")
54 raw = Path(asm_path).read_text(encoding="utf-8")
48 mattr = asm_mattr(asm_path) 55 mattr = asm_mattr(asm_path)
49 cmd = [LLVM_MC, "-triple=amdgcn--amdpal", "-mcpu=gfx1013"] 56 cmd = MC + ["-triple=amdgcn--amdpal", "-mcpu=gfx1013"]
50 if mattr: 57 if mattr:
51 cmd.append(f"-mattr={mattr}") 58 cmd.append(f"-mattr={mattr}")
52 cmd += ["-show-encoding", asm_path] 59 cmd.append("-show-encoding")
53 r = subprocess.run(cmd, capture_output=True, text=True) 60 # Feed the text on stdin: an LLVM_MC command that runs in WSL cannot open a Windows path argument.
61 r = subprocess.run(cmd, input=raw, capture_output=True, text=True)
54 if r.returncode or "error:" in r.stderr: 62 if r.returncode or "error:" in r.stderr:
55 sys.exit(f"{n}.asm did not assemble:\n{r.stderr}") 63 sys.exit(f"{n}.asm did not assemble:\n{r.stderr}")
56 # rdna2spirv.py rejects assembler directives such as the "\t.text" llvm-mc prints first. 64 # rdna2spirv.py rejects assembler directives such as the "\t.text" llvm-mc prints first.
diff --git a/runtime/test/shaders/check.py b/runtime/test/shaders/check.py
index 15c2a0c60..75f9a2d50 100644
--- a/runtime/test/shaders/check.py
+++ b/runtime/test/shaders/check.py
@@ -29,7 +29,9 @@ UNSUPPORTED = 77 # a test tool exits with
29COMPUTE = [("cs_lds", "4", "mirror64"), ("cs_exec64", "1", "exec64"), ("cs_bvh", "1", "bvh"), 29COMPUTE = [("cs_lds", "4", "mirror64"), ("cs_exec64", "1", "exec64"), ("cs_bvh", "1", "bvh"),
30 ("cs_workgroup_yz", "2x3x4", "workgroup_yz")] 30 ("cs_workgroup_yz", "2x3x4", "workgroup_yz")]
31CS_STORE = [0x400080ff, 0xe00003ff, 0x3c004000, 0xeeeeeeee, 0x40003c00, 0xbc003800] 31CS_STORE = [0x400080ff, 0xe00003ff, 0x3c004000, 0xeeeeeeee, 0x40003c00, 0xbc003800]
32CS_DUMPS = [("cs_store", CS_STORE), ("cs_wave64_ballot", [32, 16, 24, 40, 8, 48]), 32CS_SMEM = [0x5eed0024, 0x5eed0028, 0x5eed002c, 0x5eed0030, 0x5eed0010, 0x5eed0014, 0x5eed0018, 0x5eed001c]
33WAVE32_DUMPS = ("cs_store", "cs_smem_soffset_imm")
34CS_DUMPS = [("cs_store", CS_STORE), ("cs_smem_soffset_imm", CS_SMEM), ("cs_wave64_ballot", [32, 16, 24, 40, 8, 48]),
33 ("cs_wm_half_ops", [32, 16, 16, 0, 16]), ("cs_wm_half_cmp", [1, 0, 1, 1]), 35 ("cs_wm_half_ops", [32, 16, 16, 0, 16]), ("cs_wm_half_cmp", [1, 0, 1, 1]),
34 ("cs_wm_bfm64", [16, 8, 8, 40]), ("cs_wm_scc_rfl", [55, 48])] 36 ("cs_wm_bfm64", [16, 8, 8, 40]), ("cs_wm_scc_rfl", [55, 48])]
35# Cross-half wave64 tests (x = cross-half): exact results need 64 lanes, or an emulation of them on narrower subgroups. 37# Cross-half wave64 tests (x = cross-half): exact results need 64 lanes, or an emulation of them on narrower subgroups.
@@ -229,7 +231,7 @@ def main():
229 require_wave64=not W64_EMULATED))) 231 require_wave64=not W64_EMULATED)))
230 for name, want in CS_DUMPS: # all but cs_store need a 64-wide subgroup unless wave64 is emulated 232 for name, want in CS_DUMPS: # all but cs_store need a 64-wide subgroup unless wave64 is emulated
231 results.append((name, compute_test(tools, spirv, name, "1", "dump", 233 results.append((name, compute_test(tools, spirv, name, "1", "dump",
232 require_wave64=name != "cs_store" and not W64_EMULATED, 234 require_wave64=name not in WAVE32_DUMPS and not W64_EMULATED,
233 expected_words=want))) 235 expected_words=want)))
234 for name, want in W64X_DUMPS: # without --require-wave64 when LEONIDA_W64_EMULATE=1 236 for name, want in W64X_DUMPS: # without --require-wave64 when LEONIDA_W64_EMULATE=1
235 results.append((name, compute_test(tools, spirv, name, "1", "dump", require_wave64=not W64_EMULATED, 237 results.append((name, compute_test(tools, spirv, name, "1", "dump", require_wave64=not W64_EMULATED,
diff --git a/runtime/test/shaders/cs_smem_soffset_imm.asm b/runtime/test/shaders/cs_smem_soffset_imm.asm
new file mode 100644
index 000000000..399de1860
--- /dev/null
+++ b/runtime/test/shaders/cs_smem_soffset_imm.asm
@@ -0,0 +1,61 @@
1; SMEM loads that carry a register offset AND an immediate (llvm-mc: "sOFF offset:IMM"): address = base + soffset + imm.
2; Measured on an AMD Radeon RX 6800 (gfx1030) by running s_buffer_load_dword/x2/x4/x8 as a raw compute kernel:
3; soffset 8 + imm 4 reads the dword at +12. s_load_dword shares the SMEM encoding; applying the rule to it is an inference.
4; Thread 0 seeds heap bytes 0x10..0x30 with 0x5eed0000 + byte offset, then loads with s8 = 0x10:
5; s_buffer_load_dword s9, s[0:3], s8 offset:0x14 -> byte 0x24 (imm dropped: 0x10, s8 dropped: 0x14)
6; s_load_dword s10, s[4:5], s8 offset:0x18 -> byte 0x28 (imm dropped: 0x10, s8 dropped: 0x18)
7; s_buffer_load_dwordx2 s[12:13], s[0:3], s8 offset:0x1c -> bytes 0x2c, 0x30 (imm dropped: 0x10, 0x14; s8 dropped: 0x1c, 0x20)
8; and writes s9, s10, s12, s13 to out[0..3]; out[4..7] keep the seeds of bytes 0x10..0x1c.
9; All offsets are multiples of 4 and inside the buffer, so alignment and num_records play no part.
10; Run: vk_compute_test cs_smem_soffset_imm.spv 1 dump -> out[0..7] = 0x5eed0024 0x5eed0028 0x5eed002c 0x5eed0030
11; 0x5eed0010 0x5eed0014 0x5eed0018 0x5eed001c (1592590372 1592590376 1592590380 1592590384 1592590352 1592590356
12; 1592590360 1592590364). Same FSSM header as cs_lds.
13v_cmpx_eq_u32_e32 0, v0
14v_mov_b32 v1, 0x5eed0010
15v_mov_b32 v2, 0x10
16buffer_store_dword v1, v2, s[0:3], 0 offen
17v_mov_b32 v1, 0x5eed0014
18v_mov_b32 v2, 0x14
19buffer_store_dword v1, v2, s[0:3], 0 offen
20v_mov_b32 v1, 0x5eed0018
21v_mov_b32 v2, 0x18
22buffer_store_dword v1, v2, s[0:3], 0 offen
23v_mov_b32 v1, 0x5eed001c
24v_mov_b32 v2, 0x1c
25buffer_store_dword v1, v2, s[0:3], 0 offen
26v_mov_b32 v1, 0x5eed0020
27v_mov_b32 v2, 0x20
28buffer_store_dword v1, v2, s[0:3], 0 offen
29v_mov_b32 v1, 0x5eed0024
30v_mov_b32 v2, 0x24
31buffer_store_dword v1, v2, s[0:3], 0 offen
32v_mov_b32 v1, 0x5eed0028
33v_mov_b32 v2, 0x28
34buffer_store_dword v1, v2, s[0:3], 0 offen
35v_mov_b32 v1, 0x5eed002c
36v_mov_b32 v2, 0x2c
37buffer_store_dword v1, v2, s[0:3], 0 offen
38v_mov_b32 v1, 0x5eed0030
39v_mov_b32 v2, 0x30
40buffer_store_dword v1, v2, s[0:3], 0 offen
41s_waitcnt vmcnt(0)
42s_mov_b32 s4, 0
43s_mov_b32 s5, 0
44s_mov_b32 s8, 0x10
45s_buffer_load_dword s9, s[0:3], s8 offset:0x14
46s_load_dword s10, s[4:5], s8 offset:0x18
47s_buffer_load_dwordx2 s[12:13], s[0:3], s8 offset:0x1c
48s_waitcnt lgkmcnt(0)
49v_mov_b32 v1, s9
50v_mov_b32 v2, 0
51buffer_store_dword v1, v2, s[0:3], 0 offen
52v_mov_b32 v1, s10
53v_mov_b32 v2, 4
54buffer_store_dword v1, v2, s[0:3], 0 offen
55v_mov_b32 v1, s12
56v_mov_b32 v2, 8
57buffer_store_dword v1, v2, s[0:3], 0 offen
58v_mov_b32 v1, s13
59v_mov_b32 v2, 12
60buffer_store_dword v1, v2, s[0:3], 0 offen
61s_endpgm