upleb.uk

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

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com>2026-11-22 23:15:30 -0500
committerItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com>2026-11-22 23:15:30 -0500
commita90289cbb4dd9761edbf0c44553aa5a4eead2c8d (patch)
tree619ff2119689dfeab6a440a9240fd3a29f0c8a0b
parent4c4cb16bbf2dc642e74e4496bfb8f227adae7465 (diff)
parentdbe5070d185d1c216e21e1f23b80156e7f2b3ad8 (diff)
Merge pull request #4519 from Størm
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
-rw-r--r--docs/shader_validation.md16
-rw-r--r--tests/test_lds_fuzz_hw.py48
-rw-r--r--tools/hw_oracle/asm.py34
-rw-r--r--tools/lds_fuzz.py23
4 files changed, 98 insertions, 23 deletions
diff --git a/docs/shader_validation.md b/docs/shader_validation.md
index 9699b46a9..57efa5228 100644
--- a/docs/shader_validation.md
+++ b/docs/shader_validation.md
@@ -517,9 +517,19 @@ python -I tools/lds_fuzz.py --oracle hw --programs 50 --seed 1 --wave 32 --only
517 **`ds_cmpstore_rtn_b32` takes the value to store before the compare value**, the reverse of GFX10's 517 **`ds_cmpstore_rtn_b32` takes the value to store before the compare value**, the reverse of GFX10's
518 `ds_cmpst_rtn_b32 vdst, vaddr, cmp, store`; llvm-mc encodes both spellings of the same text identically, so only 518 `ds_cmpst_rtn_b32 vdst, vaddr, cmp, store`; llvm-mc encodes both spellings of the same text identically, so only
519 the operand order says which. Unswapped, every program with a `cmpst` failed on gfx1150 (each minimized to that one 519 the operand order says which. Unswapped, every program with a `cmpst` failed on gfx1150 (each minimized to that one
520 op); swapped, none does. This is measured on GFX11 only: on gfx12xx the programs with a `cmpst` are skipped with 520 op); swapped, none does. GFX12 takes the same order (measured on an RX 9070 XT, gfx1201: with 7 in the dword and
521 that reason. The model keeps the GFX10 order. Nothing else the generator emits is missing on GFX11, so no other 521 data `v1 = 9`, `v2 = 7` it becomes 9, with `v1 = 7`, `v2 = 9` it stays 7, for `ds_cmpstore_rtn_b32` and
522 program is skipped for its semantics; an assembler rejection is counted as `rejected`, never as a pass. 522 `ds_cmpstore_b32`; gfx1036's `ds_cmpst` does the opposite), and with `--perturb cmpst_swap` 275 of 1,000 wave32
523 programs mismatch there. The model keeps the GFX10 order. Nothing else the generator emits is missing on GFX11, so
524 no other program is skipped for its semantics; an assembler rejection is counted as `rejected`, never as a pass.
525- **GFX12** (`hw_oracle/asm.py` `sync_lines`): there is no `s_barrier` (a workgroup barrier is
526 `s_barrier_signal -1` then `s_barrier_wait -1`), and the LDS wait is `s_wait_dscnt 0` instead of the legacy
527 `s_waitcnt lgkmcnt(0)`. **A wave64 `ds_bpermute_b32` reaches all 64 lanes on GFX12**, while RDNA2 (and gfx1150)
528 keep each 32-lane half separate: with every lane asking for lane `(l + 32) mod 64`, the RX 9070 XT returns lane
529 `l ^ 32` and a gfx1036 iGPU returns lane `l`. The model describes RDNA2, so on gfx12xx a wave64 program with a
530 `ds_bpermute` is skipped with that reason; under `--perturb bpermute_wave64_cross` all 1,000 wave64 programs of
531 seed 1 match there. RX 9070 XT, AMD 26.11.2, `--programs 1000`, seeds 1 and 2: wave32 1,000/1,000 match; wave64
532 537 and 506 match, 0 mismatch, the rest skipped for that reason. The gfx1036 iGPU gives 1,000/1,000 in both.
523- **Wider op mix**, opt-in so that a seed keeps its programs: `--permute` (`ds_permute_b32`), `--swizzle-exec` 533- **Wider op mix**, opt-in so that a seed keeps its programs: `--permute` (`ds_permute_b32`), `--swizzle-exec`
524 (`ds_swizzle_b32` under EXEC masks), `--threads`, `--extended` (all three). `ds_permute_b32` and a masked 534 (`ds_swizzle_b32` under EXEC masks), `--threads`, `--extended` (all three). `ds_permute_b32` and a masked
525 `ds_swizzle_b32` carry a hypothesis (the model's reading of the ISA text); on the hardware a failing one is a 535 `ds_swizzle_b32` carry a hypothesis (the model's reading of the ISA text); on the hardware a failing one is a
diff --git a/tests/test_lds_fuzz_hw.py b/tests/test_lds_fuzz_hw.py
index 94f1226a3..8ab5df8cb 100644
--- a/tests/test_lds_fuzz_hw.py
+++ b/tests/test_lds_fuzz_hw.py
@@ -39,10 +39,24 @@ class DsSpelling(unittest.TestCase):
39 def test_cmpstore_takes_the_store_value_first_on_gfx11(self): 39 def test_cmpstore_takes_the_store_value_first_on_gfx11(self):
40 line = "ds_cmpst_rtn_b32 v22, v6, v28, v35 offset:12" # vdst, vaddr, compare, store 40 line = "ds_cmpst_rtn_b32 v22, v6, v28, v35 offset:12" # vdst, vaddr, compare, store
41 self.assertEqual(asm.ds_line(line, "gfx1150"), "ds_cmpstore_rtn_b32 v22, v6, v35, v28 offset:12") 41 self.assertEqual(asm.ds_line(line, "gfx1150"), "ds_cmpstore_rtn_b32 v22, v6, v35, v28 offset:12")
42 self.assertEqual(asm.ds_line(line, "gfx1201"), "ds_cmpstore_rtn_b32 v22, v6, v35, v28 offset:12")
42 self.assertEqual(asm.ds_line(line, "gfx1030"), line) 43 self.assertEqual(asm.ds_line(line, "gfx1030"), line)
44 nortn = "ds_cmpst_b32 v6, v28, v35" # vaddr, compare, store
45 for arch in ("gfx1150", "gfx1201"): # measured on gfx1100 and gfx1201
46 self.assertEqual(asm.ds_line(nortn, arch), "ds_cmpstore_b32 v6, v35, v28")
47 self.assertEqual(asm.ds_line(nortn, "gfx1030"), nortn)
43 with self.assertRaises(ValueError): 48 with self.assertRaises(ValueError):
44 asm.ds_line("ds_cmpst_rtn_b32 v22, v6, 5", "gfx1150") 49 asm.ds_line("ds_cmpst_rtn_b32 v22, v6, 5", "gfx1150")
45 50
51 def test_gfx12_spells_the_barrier_and_the_lds_wait_its_own_way(self):
52 self.assertEqual(asm.sync_lines("s_barrier", "gfx1201"), ["s_barrier_signal -1", "s_barrier_wait -1"])
53 self.assertEqual(asm.sync_lines("s_waitcnt lgkmcnt(0)", "gfx1201"), ["s_wait_dscnt 0"])
54 for arch in ("gfx1030", "gfx1150"):
55 for line in ("s_barrier", "s_waitcnt lgkmcnt(0)"):
56 self.assertEqual(asm.sync_lines(line, arch), [line])
57 for line in ("s_waitcnt vmcnt(0)", "ds_bpermute_b32 v1, v2, v3", "s_endpgm"):
58 self.assertEqual(asm.sync_lines(line, "gfx1201"), [line])
59
46 def test_kernel_carries_its_lds_size_and_registers(self): 60 def test_kernel_carries_its_lds_size_and_registers(self):
47 k = asm.Kernel(["s_endpgm"], 64, 64, 8, raw=True, lds=4096, vgprs=40) 61 k = asm.Kernel(["s_endpgm"], 64, 64, 8, raw=True, lds=4096, vgprs=40)
48 text, names, _ = asm.module_text([k, asm.Kernel(["s_endpgm"], 64, 64, 8, raw=True)], "gfx1150", wave=64) 62 text, names, _ = asm.module_text([k, asm.Kernel(["s_endpgm"], 64, 64, 8, raw=True)], "gfx1150", wave=64)
@@ -299,10 +313,38 @@ class RunHw(unittest.TestCase):
299 with self.assertRaises(RuntimeError): 313 with self.assertRaises(RuntimeError):
300 self.run_hw(Broken(progs), progs) 314 self.run_hw(Broken(progs), progs)
301 315
302 def test_gfx12_skips_cmpst_programs(self): 316 def test_gfx12_runs_cmpst_programs(self):
317 # The ds_cmpstore operand order is measured on gfx1201 too, so these are no longer skipped there.
303 with_cmpst = next(p for p in f.programs(1, 60, (32,)) if any(o["kind"] == "cmpst" for o in p.ops)) 318 with_cmpst = next(p for p in f.programs(1, 60, (32,)) if any(o["kind"] == "cmpst" for o in p.ops))
304 self.assertIn("GFX11", f.hw_skip_reason(with_cmpst, "gfx1201")) 319 for arch in ("gfx1201", "gfx1150", "gfx1030"):
305 self.assertIsNone(f.hw_skip_reason(with_cmpst, "gfx1150")) 320 self.assertIsNone(f.hw_skip_reason(with_cmpst, arch), arch)
321
322 def test_gfx12_skips_only_wave64_programs_with_a_bpermute(self):
323 has_bp = lambda p: any(o["kind"] == "bpermute" for o in p.ops)
324 w64 = next(p for p in f.programs(1, 60, (64,)) if has_bp(p))
325 w32 = next(p for p in f.programs(1, 60, (32,)) if has_bp(p))
326 plain = next(p for p in f.programs(1, 60, (64,)) if not has_bp(p))
327 self.assertIn("all 64 lanes", f.hw_skip_reason(w64, "gfx1201"))
328 self.assertIsNone(f.hw_skip_reason(w32, "gfx1201"))
329 self.assertIsNone(f.hw_skip_reason(plain, "gfx1201"))
330 for arch in ("gfx1150", "gfx1030"): # halves stay separate there (measured)
331 self.assertIsNone(f.hw_skip_reason(w64, arch), arch)
332 f.PERTURB.add("bpermute_wave64_cross") # the model that crosses halves can run them
333 try:
334 self.assertIsNone(f.hw_skip_reason(w64, "gfx1201"))
335 finally:
336 f.PERTURB.discard("bpermute_wave64_cross")
337
338 def test_gfx12_kernels_use_its_barrier_and_lds_wait(self):
339 p = f.programs(1, 1, (64,))[0] # every kernel waits and barriers after each op
340 g12, g11 = p.hw_lines("gfx1201"), p.hw_lines("gfx1150")
341 self.assertIn("s_barrier", g11)
342 self.assertNotIn("s_barrier", g12)
343 self.assertNotIn("s_waitcnt lgkmcnt(0)", g12)
344 self.assertEqual(g12.count("s_barrier_signal -1"), g11.count("s_barrier"))
345 self.assertEqual(g12.count("s_barrier_wait -1"), g11.count("s_barrier"))
346 self.assertEqual(g12.count("s_wait_dscnt 0"), g11.count("s_waitcnt lgkmcnt(0)"))
347 self.assertEqual(p.hw_lines("gfx1030").count("s_barrier"), g11.count("s_barrier"))
306 348
307 def test_a_flipped_word_is_a_mismatch(self): 349 def test_a_flipped_word_is_a_mismatch(self):
308 progs = f.programs(1, 4, (32,)) 350 progs = f.programs(1, 4, (32,))
diff --git a/tools/hw_oracle/asm.py b/tools/hw_oracle/asm.py
index f39cf47a5..c6a9dd872 100644
--- a/tools/hw_oracle/asm.py
+++ b/tools/hw_oracle/asm.py
@@ -314,7 +314,7 @@ GFX11_VALU_RENAMED = {
314# the GFX10 spelling of all of them on gfx1150 except ds_cmpst_rtn_b32 ("instruction not supported on this GPU"), and 314# the GFX10 spelling of all of them on gfx1150 except ds_cmpst_rtn_b32 ("instruction not supported on this GPU"), and
315# takes the GFX11 spelling on gfx1030 for none. The new spelling is used on GFX11/GFX12 so the program text is what 315# takes the GFX11 spelling on gfx1030 for none. The new spelling is used on GFX11/GFX12 so the program text is what
316# the target names, not what an alias happens to accept. ds_cmpstore_rtn_b32 also takes its two data operands in the 316# the target names, not what an alias happens to accept. ds_cmpstore_rtn_b32 also takes its two data operands in the
317# other order (ds_line). 317# other order (ds_line), and GFX12 spells the barrier and the LDS wait differently (sync_lines).
318DS_RENAMED_GFX11 = { 318DS_RENAMED_GFX11 = {
319 "ds_wrxchg_rtn_b32": "ds_storexchg_rtn_b32", 319 "ds_wrxchg_rtn_b32": "ds_storexchg_rtn_b32",
320 "ds_cmpst_rtn_b32": "ds_cmpstore_rtn_b32", 320 "ds_cmpst_rtn_b32": "ds_cmpstore_rtn_b32",
@@ -337,24 +337,26 @@ def ds_mnemonic(op, arch):
337 337
338 338
339def ds_line(line, arch): 339def ds_line(line, arch):
340 """A whole instruction line (GFX10 spelling and operand order in) respelled for the architecture. On GFX11 340 """A whole instruction line (GFX10 spelling and operand order in) respelled for the architecture. On GFX11 and
341 (measured on gfx1150; GFX12 is not measured, lds_fuzz skips it) ds_cmpstore_rtn_b32 takes the value to store first and the compare value second, the reverse of GFX10's 341 GFX12 ds_cmpstore_rtn_b32 takes the value to store first and the compare value second, the reverse of GFX10's
342 ds_cmpst_rtn_b32 vdst, vaddr, cmp, store (measured on gfx1150: tools/lds_fuzz.py --oracle hw, and it is what LLVM's 342 ds_cmpst_rtn_b32 vdst, vaddr, cmp, store (measured on gfx1150: tools/lds_fuzz.py --oracle hw, and it is what LLVM's
343 cmpxchg selection does for GFX11); llvm-mc encodes both spellings of the same text identically, so only the 343 cmpxchg selection does for GFX11; measured on gfx1201, an RX 9070 XT: with M = 7 at the address, data v1 = 9 and
344 v2 = 7 the dword becomes 9 and with v1 = 7, v2 = 9 it stays 7, for the rtn and the non-returning form, while
345 gfx1036's ds_cmpst does the opposite); llvm-mc encodes both spellings of the same text identically, so only the
344 operand order tells them apart.""" 346 operand order tells them apart."""
345 op, sep, rest = line.partition(" ") 347 op, sep, rest = line.partition(" ")
346 if op == "ds_cmpst_rtn_b32" and family(arch) == "gfx11": 348 if op == "ds_cmpst_rtn_b32" and family(arch) in ("gfx11", "gfx12"):
347 m = re.fullmatch(r"(v\d+),\s*(v\d+),\s*(v\d+),\s*(v\d+)(.*)", rest) 349 m = re.fullmatch(r"(v\d+),\s*(v\d+),\s*(v\d+),\s*(v\d+)(.*)", rest)
348 if not m: 350 if not m:
349 raise ValueError(f"cannot swap the operands of {line!r}") 351 raise ValueError(f"cannot swap the operands of {line!r}")
350 dst, addr, cmp_, store, tail = m.groups() 352 dst, addr, cmp_, store, tail = m.groups()
351 rest = f"{dst}, {addr}, {store}, {cmp_}{tail}" 353 rest = f"{dst}, {addr}, {store}, {cmp_}{tail}"
352 elif op == "ds_cmpst_b32" and family(arch) == "gfx11": 354 elif op == "ds_cmpst_b32" and family(arch) in ("gfx11", "gfx12"):
353 # The non-returning form is renamed as well, and its two data operands swap the same way: GFX10's 355 # The non-returning form is renamed as well, and its two data operands swap the same way: GFX10's
354 # ds_cmpst_b32 vaddr, cmp, store is GFX11's ds_cmpstore_b32 vaddr, store, cmp (measured on gfx1100: with 356 # ds_cmpst_b32 vaddr, cmp, store is GFX11's ds_cmpstore_b32 vaddr, store, cmp (measured on gfx1100: with
355 # M = 7, vaddr = 0 and data v1 = 9, v2 = 7 the dword becomes 9, so the store operand is v1). The rename is 357 # M = 7, vaddr = 0 and data v1 = 9, v2 = 7 the dword becomes 9, so the store operand is v1; the same on
356 # done here rather than in DS_RENAMED_GFX11 because the swap is only measured on GFX11, and renaming 358 # gfx1201). The rename is done here rather than in DS_RENAMED_GFX11 so that it never happens without the
357 # without swapping on GFX12 would silently compare and store the wrong way round. 359 # swap, which would silently compare and store the wrong way round.
358 m = re.fullmatch(r"(v\d+),\s*(v\d+),\s*(v\d+)(.*)", rest) 360 m = re.fullmatch(r"(v\d+),\s*(v\d+),\s*(v\d+)(.*)", rest)
359 if not m: 361 if not m:
360 raise ValueError(f"cannot swap the operands of {line!r}") 362 raise ValueError(f"cannot swap the operands of {line!r}")
@@ -363,6 +365,20 @@ def ds_line(line, arch):
363 return ds_mnemonic(op, arch) + sep + rest 365 return ds_mnemonic(op, arch) + sep + rest
364 366
365 367
368def sync_lines(line, arch):
369 """A wait or barrier line (GFX10/GFX11 spelling in) as the instructions that do it on this architecture. GFX12 has
370 no s_barrier (AMD LLVM 23: "instruction not supported on this GPU (gfx1201)"); a workgroup barrier there is
371 s_barrier_signal -1 then s_barrier_wait -1. It also split lgkmcnt into dscnt (LDS) and kmcnt (scalar memory), so
372 a wait for the LDS is s_wait_dscnt 0 rather than the legacy s_waitcnt encoding the assembler still takes."""
373 if family(arch) == "gfx12":
374 text = line.strip()
375 if text == "s_barrier":
376 return ["s_barrier_signal -1", "s_barrier_wait -1"]
377 if text == "s_waitcnt lgkmcnt(0)":
378 return ["s_wait_dscnt 0"]
379 return [line]
380
381
366def valu_skip_reason(op, arch): 382def valu_skip_reason(op, arch):
367 """Why an f32 VALU opcode cannot be run on this architecture, or None.""" 383 """Why an f32 VALU opcode cannot be run on this architecture, or None."""
368 if op in VALU_REMOVED and arch not in ("gfx1010", "gfx1011", "gfx1012", "gfx1013"): 384 if op in VALU_REMOVED and arch not in ("gfx1010", "gfx1011", "gfx1012", "gfx1013"):
diff --git a/tools/lds_fuzz.py b/tools/lds_fuzz.py
index 44a7df23a..ed9bccc6b 100644
--- a/tools/lds_fuzz.py
+++ b/tools/lds_fuzz.py
@@ -424,11 +424,11 @@ class Program:
424 def hw_lines(self, arch, ops=None): 424 def hw_lines(self, arch, ops=None):
425 """The program as a native kernel body for tools/hw_oracle: the entry EXEC is saved and restored (a partial 425 """The program as a native kernel body for tools/hw_oracle: the entry EXEC is saved and restored (a partial
426 wave has fewer lanes than -1), the stores go through the output pointer in s[2:3], and the ds_* mnemonics are 426 wave has fewer lanes than -1), the stores go through the output pointer in s[2:3], and the ds_* mnemonics are
427 the ones the architecture names them.""" 427 the ones the architecture names them, and so are the barrier and the LDS waits (GFX12, asm.sync_lines)."""
428 from hw_oracle import asm 428 from hw_oracle import asm
429 ops = self.ops if ops is None else ops 429 ops = self.ops if ops is None else ops
430 lines = self.body(ops, hw=True, arch=arch) 430 lines = self.body(ops, hw=True, arch=arch)
431 return [asm.ds_line(ln, arch) for ln in lines] 431 return [out for ln in lines for out in asm.sync_lines(asm.ds_line(ln, arch), arch)]
432 432
433 def body(self, ops, hw=False, arch="gfx1150"): 433 def body(self, ops, hw=False, arch="gfx1150"):
434 w64 = self.wave == 64 434 w64 = self.wave == 64
@@ -922,13 +922,20 @@ def run_translator(progs, a, work, tally):
922 922
923def hw_skip_reason(p, arch): 923def hw_skip_reason(p, arch):
924 """Why a program cannot run natively on this GPU, or None. GFX11 renamed the ds_* loads and stores, which 924 """Why a program cannot run natively on this GPU, or None. GFX11 renamed the ds_* loads and stores, which
925 asm.ds_line respells, and swaps ds_cmpstore's data operands (measured on gfx1150). The swap is not measured on 925 asm.ds_line respells, and swaps ds_cmpstore's data operands (measured on gfx1150 and on gfx1201); GFX12 also
926 GFX12, so a program with a ds_cmpst is skipped there; everything else the generator emits is spelled the same 926 spells the barrier and the LDS wait differently, which asm.sync_lines respells. Everything else the generator
927 on GFX10, GFX11 and GFX12 (assembled for gfx1030, gfx1100, gfx1150 and gfx1201), so the other skips are the 927 emits is spelled the same on GFX10, GFX11 and GFX12 (assembled for gfx1030, gfx1100, gfx1150 and gfx1201), so
928 assembler's own rejections, which the runner reports.""" 928 the other skips are the assembler's own rejections, which the runner reports.
929
930 One behaviour differs on GFX12: a wave64 ds_bpermute_b32 reaches all 64 lanes there, while RDNA2 (the console's
931 generation, and what this model describes) keeps each 32-lane half separate. Measured with every lane asking for
932 lane (l + 32) mod 64: an RX 9070 XT (gfx1201) returns lane l ^ 32, a gfx1036 iGPU returns lane l, and on gfx1201
933 300 of 300 wave64 programs match --perturb bpermute_wave64_cross. So those programs can't check the RDNA2 model on
934 GFX12 and are skipped there; wave32 and every other wave64 program still run."""
929 from hw_oracle import asm 935 from hw_oracle import asm
930 if asm.family(arch) == "gfx12" and any(op["kind"] == "cmpst" for op in p.ops): 936 if asm.family(arch) == "gfx12" and p.wave == 64 and "bpermute_wave64_cross" not in PERTURB \
931 return "ds_cmpstore_rtn_b32 operand order is only measured on GFX11 (gfx1150)" 937 and any(op["kind"] == "bpermute" for op in p.ops):
938 return "a wave64 ds_bpermute_b32 reaches all 64 lanes on GFX12 (measured on gfx1201), not each 32-lane half"
932 return None 939 return None
933 940
934 941