upleb.uk

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

summaryrefslogtreecommitdiff
path: root/scripts/run_gpu_tests.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/run_gpu_tests.py')
-rw-r--r--scripts/run_gpu_tests.py501
1 files changed, 427 insertions, 74 deletions
diff --git a/scripts/run_gpu_tests.py b/scripts/run_gpu_tests.py
index 124bdeeb1..9693b6ac2 100644
--- a/scripts/run_gpu_tests.py
+++ b/scripts/run_gpu_tests.py
@@ -7,6 +7,7 @@ Usage:
7""" 7"""
8import argparse 8import argparse
9import json 9import json
10import math
10import os 11import os
11import re 12import re
12import shutil 13import shutil
@@ -18,12 +19,22 @@ from pathlib import Path
18 19
19ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 20ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
20SHADER_DIR = os.path.join(ROOT, "runtime", "test", "shaders") 21SHADER_DIR = os.path.join(ROOT, "runtime", "test", "shaders")
22
21TRANSLATOR = os.path.join(ROOT, "tools", "rdna2spirv.py") 23TRANSLATOR = os.path.join(ROOT, "tools", "rdna2spirv.py")
22sys.path.insert(0, os.path.join(ROOT, "tools")) 24sys.path.insert(0, os.path.join(ROOT, "tools"))
23import mc_command # noqa: E402 25import mc_command # noqa: E402
24sys.path.insert(0, SHADER_DIR) 26sys.path.insert(0, SHADER_DIR)
27from build import CLIP_CASES, clip_container, shader_source
28from check import Skip, clip_test, fmt_1010102_test
25from compute_fixture import compute_header 29from compute_fixture import compute_header
26from check import SAMPLER_CASES, Skip, mesh_v5_test, sampler_test 30from check import SAMPLER_CASES, sampler_test # ps_ssharp: the S#/T# mip fields (vk_sampler_test)
31from check import (CMPX_CLASS_WORDS, CVT_F32_SAT_CASES, GRADIENT_TESTS, TEST_PROGRAMS, TEXTURE_MIP_DEPENDENCIES,
32 TEXTURE_MIP_TEST, GATHER_LOD_TEST, MIP_TEST_PASSES, GATHER_WRAP, USER_SGPRS_ENV, USER_SGPRS_WORDS, Skip, mesh_v5_test, not_found_message,
33 pick_build_dir, start_failure, texture_gradient_a16_test, texture_mip_test)
34from check import TEXOFF_ARGS, texoff_problem # ps_texoff's expected words and arguments live in check.py
35from check import TEXOFF_FALLBACK, texoff_env # LEONIDA_TEXOFF_FALLBACK=1: texel offsets without maintenance8
36from check import gpu_test_timeout, timed_out # per-program time limit (LEONIDA_GPU_TEST_TIMEOUT)
37from check import WAVE32_LANE_DUMPS, WAVE32_LANE_ENV, narrow_subgroup_skip, wave32_lane_skip # as in check.py
27 38
28 39
29def make_dxbc(chunks: list[tuple[bytes, bytes]]) -> bytes: 40def make_dxbc(chunks: list[tuple[bytes, bytes]]) -> bytes:
@@ -79,6 +90,8 @@ def assemble_to_s(llvm_mc: str, asm_path: str, s_path: str, name: str) -> None:
79 if m: 90 if m:
80 cmd.append(f"-mattr={m.group(1)}") 91 cmd.append(f"-mattr={m.group(1)}")
81 break 92 break
93 if name in CLIP_CASES:
94 cmd.append(f"-defsym=PARAM_SLOT={CLIP_CASES[name]}")
82 cmd.append("-show-encoding") 95 cmd.append("-show-encoding")
83 p = subprocess.run( 96 p = subprocess.run(
84 cmd, 97 cmd,
@@ -215,11 +228,67 @@ def unsupported_skip(msg: str) -> str:
215 return f"SKIP ({m.group(0) if m else 'unsupported device'})" 228 return f"SKIP ({m.group(0) if m else 'unsupported device'})"
216 229
217 230
218def run_cmd(cmd: list[str], env: dict | None = None) -> tuple[int, str]: 231def run_cmd(cmd: list[str], env: dict | None = None, gpu: bool = True) -> tuple[int, str]:
219 p = subprocess.run(cmd, capture_output=True, text=True, env=env) 232 # A hung GPU test program fails its test instead of stalling the suite (check.py, LEONIDA_GPU_TEST_TIMEOUT).
233 # gpu=False (the translator over the whole suite) runs without a limit.
234 limit = gpu_test_timeout() if gpu else None
235 try:
236 p = subprocess.run(cmd, capture_output=True, text=True, env=env, timeout=limit)
237 except subprocess.TimeoutExpired:
238 return 1, timed_out(cmd[0], limit)
239 except OSError as e: # e.g. Smart App Control blocked a fresh build: fail this test, keep running the others
240 return 1, start_failure(cmd[0], e)
220 return p.returncode, (p.stdout + "\n" + p.stderr).strip() 241 return p.returncode, (p.stdout + "\n" + p.stderr).strip()
221 242
222 243
244def bary_fallback() -> bool:
245 """LEONIDA_BARY_FALLBACK=1: pixel shaders that read raw barycentrics are translated with --bary-fallback and drawn
246 through their pass-through geometry shader (tools/bary_fallback_gs.py), so they run on a device without
247 VK_KHR_fragment_shader_barycentric (NVIDIA Pascal, for one)."""
248 return (os.environ.get("LEONIDA_BARY_FALLBACK") or "").strip().lower() in ("1", "true", "yes", "on")
249
250
251def w64_emulated() -> bool:
252 # Wave64 emulation on: the suite runs every wave64 check without asking for a 64-wide
253 # subgroup, matching check.py (W64_EMULATED). Accepts "1"/"true"/"yes"/"on" and tolerates
254 # the trailing space cmd.exe's `set VAR=1 &` leaves in the value.
255 return (os.environ.get("LEONIDA_W64_EMULATE") or "").strip().lower() in ("1", "true", "yes", "on")
256def wavemask_check(vk_compute: str, spv: str, env: dict | None, emulated: bool) -> tuple[bool | None, str]:
257 """cs_wavemask, as in check.py: (passed, detail), passed None for a skip. The native build needs a 64-wide
258 subgroup and skips where the device has none; with LEONIDA_W64_EMULATE=1 it was translated with
259 --wave64-emulate and runs on any subgroup size, so it asks for none."""
260 cmd = [vk_compute, spv, "1", "wavemask"] + ([] if emulated else ["--require-wave64"])
261 rc, msg = run_cmd(cmd, env=env)
262 if not emulated and rc == 77:
263 return None, "SKIP (no 64-wide compute subgroup on this device)"
264 if not emulated and rc == 0 and "compute subgroup size: 64" not in msg.splitlines():
265 return False, "64-wide subgroup was not confirmed (rebuild vk_compute_test)"
266 return rc == 0, msg.splitlines()[-1] if msg else ""
267def dump_words(msg: str) -> list[int] | None:
268 """The eight words of vk_compute_test's "out[0..7] = ..." line, or None unless it is eight decimal words (as in
269 check.py): trailing text, a missing word or a non-number is a malformed dump, not a result."""
270 m = re.search(r"^out\[0\.\.7\] = ((?:[0-9]+ ){7}[0-9]+)$", msg, re.MULTILINE)
271 return [int(x) for x in m.group(1).split()] if m else None
272
273
274def judge_cs_dump(rc: int, msg: str, want: list[int], *, wave64: bool, partial: bool, emulated: bool,
275 hexwords: bool = False) -> tuple[bool | None, str]:
276 """Judge one vk_compute_test "dump" run: (True, words), (False, why), or (None, why) when the device can't run it.
277 wave64: it was run with --require-wave64, so exit 77 is a skip and the 64-wide confirmation must be printed.
278 partial: a group smaller than a wave, run at subgroup size 64 without full subgroups; skipped when the device
279 reports no subgroup size of 64. emulated: translated with --wave64-emulate, runs on any subgroup size."""
280 no64 = partial and not emulated and not any(int(x) >= 64 for x in re.findall(r"subgroup \d+\.\.(\d+)", msg))
281 if (wave64 and rc == 77) or (no64 and rc == 0):
282 return None, "SKIP (no 64-wide compute subgroup on this device)"
283 if rc == 0 and wave64 and "compute subgroup size: 64" not in msg.splitlines():
284 return False, "64-wide subgroup was not confirmed (rebuild vk_compute_test)"
285 words = dump_words(msg)
286 if rc != 0 or words is None:
287 return False, msg
288 vals = words[:len(want)]
289 return vals == want, " ".join((hex if hexwords else str)(x) for x in vals)
290
291
223def check_pixel_const(raw_path: str, want: tuple[int, int, int, int]) -> tuple[bool, str]: 292def check_pixel_const(raw_path: str, want: tuple[int, int, int, int]) -> tuple[bool, str]:
224 px = read_raw_u32(raw_path) 293 px = read_raw_u32(raw_path)
225 if len(px) != 64 * 64: 294 if len(px) != 64 * 64:
@@ -231,8 +300,17 @@ def check_pixel_const(raw_path: str, want: tuple[int, int, int, int]) -> tuple[b
231 return True, "4096/4096 pixels exact" 300 return True, "4096/4096 pixels exact"
232 301
233 302
303def frame_problem(px) -> str:
304 """Why a 64x64 frame can't be judged: a short frame or a NaN passes every tolerance test (check.py rejects both)."""
305 if len(px) != 64 * 64:
306 return f"expected 4096 pixels, got {len(px)}"
307 return "" if all(math.isfinite(v) for p in px for v in p) else "non-finite values in the frame"
308
309
234def check_bary(raw_path: str) -> tuple[bool, str]: 310def check_bary(raw_path: str) -> tuple[bool, str]:
235 px = read_raw_rgba32f(raw_path) 311 px = read_raw_rgba32f(raw_path)
312 if problem := frame_problem(px):
313 return False, problem
236 bad = 0 314 bad = 0
237 first = "" 315 first = ""
238 for i, (ax, ay, bi, bj) in enumerate(px): 316 for i, (ax, ay, bi, bj) in enumerate(px):
@@ -261,9 +339,15 @@ def check_bitmask_perm(raw_path: str) -> tuple[bool, str]:
261 return (bad == 0 and judged > 0), (first if bad else f"{judged}/{judged} pixels in lanes 0-31 exact") 339 return (bad == 0 and judged > 0), (first if bad else f"{judged}/{judged} pixels in lanes 0-31 exact")
262 340
263 341
264# Test shaders that need memory or push constants only the semantic-test interpreter sets up (tests/semantic). 342# Pixel shaders that read memory: vk_harness puts this V# in s[0:3] and seeds the heap it points at, as
265# On the GPU harness they would read an unset descriptor; ps_vcc_x2 loses the device that way. 343# tests/semantic/test_value_semantics.py does for the interpreter (same table as check.py).
266INTERPRETER_ONLY = {"ps_vcc_x2": "needs the seeded V# memory of tests/semantic; checked there"} 344PIXEL_ENV = {"ps_vcc_x2": {"VKH_SGPRS": "0x1000,0,16,0", "VKH_HEAP": "0x1000=0x11223344,0x1004=0x55667788"},
345 # float NaN / fract rows measured on RDNA2 hardware (see the .asm headers)
346 "ps_fnan_med3": {"VKH_SGPRS": "0x1000,0,32,0",
347 "VKH_HEAP": "0x1000=0x7fc10001,0x1004=0x40e00000,0x1008=0x40a00000,"
348 "0x100c=0x7fc10001,0x1010=0x40600000,0x1014=0xc0200000"},
349 "ps_fnan_fract": {"VKH_SGPRS": "0x1000,0,16,0",
350 "VKH_HEAP": "0x1000=0xaedbe6ff,0x1004=0x00008800,0x1008=0x7fc10001,0x100c=0xc0200000"}}
267 351
268 352
269def check_flat(raw_path: str) -> tuple[bool, str]: 353def check_flat(raw_path: str) -> tuple[bool, str]:
@@ -278,14 +362,31 @@ def check_flat(raw_path: str) -> tuple[bool, str]:
278 f"{wrong} pixels without the first vertex's value, uv off by {err:.3g}") 362 f"{wrong} pixels without the first vertex's value, uv off by {err:.3g}")
279 363
280 364
365def check_wqm(raw_path: str) -> tuple[bool, str]:
366 """ps_wqm.asm: per pixel (wqm, own, wqm, own); wqm iff x%4 < 2 and y%4 >= 2, own iff x%4 == 1 and y%4 == 2."""
367 px = read_raw_u32(raw_path)
368 if problem := frame_problem(px):
369 return False, problem
370 w = int(len(px) ** 0.5)
371 wrong = sum(tuple(p) != (a, b, a, b)
372 for i, p in enumerate(px)
373 for a, b in [(int(i % w % 4 < 2 and i // w % 4 >= 2), int(i % w % 4 == 1 and i // w % 4 == 2))])
374 return wrong == 0, "whole-quad mask exact on every pixel" if not wrong else f"{wrong} of {len(px)} pixels differ"
375
376
281def check_uniform_branch(raw_path: str) -> tuple[bool, str]: 377def check_uniform_branch(raw_path: str) -> tuple[bool, str]:
282 px = read_raw_rgba32f(raw_path) 378 px = read_raw_rgba32f(raw_path)
283 u32 = read_raw_u32(raw_path) 379 u32 = read_raw_u32(raw_path)
380 """ps_uniform_branch / ps_scc_mask32: s5 = 8 wherever the lane's own bit is set; a lane with bit 0 gets 8 when
381 another lane of its wave has the bit (the wave-wide vote), else 7. All three kinds must occur, as in check.py:
382 without a (8, bit 0) pixel the vote is not shown, and a translator that decides per lane would pass."""
284 bad = 0 383 bad = 0
285 n8 = 0 384 n8 = 0
286 n7 = 0 385 n7 = 0
386 n80 = 0
287 first = "" 387 first = ""
288 for i, ((_, _, bary_i, _), (s5, bit, _, _)) in enumerate(zip(px, u32)): 388 for i, ((_, _, bary_i, _), (s5, bit, _, _)) in enumerate(zip(px, u32)):
389 n80 += s5 == 8 and bit == 0
289 if bit == 1: 390 if bit == 1:
290 if bary_i <= 0.27 or s5 != 8: 391 if bary_i <= 0.27 or s5 != 8:
291 if not bad: 392 if not bad:
@@ -304,11 +405,18 @@ def check_uniform_branch(raw_path: str) -> tuple[bool, str]:
304 n8 += 1 405 n8 += 1
305 elif s5 == 7: 406 elif s5 == 7:
306 n7 += 1 407 n7 += 1
307 return (bad == 0 and n8 > 0 and n7 > 0), (first if bad else f"s5==8: {n8}, s5==7: {n7} (4096 px)") 408 if bad:
409 return False, first
410 detail = f"s5==8: {n8} ({n80} of them with bit 0), s5==7: {n7} ({len(u32)} px)"
411 if not n80:
412 return False, "no bit=0 pixel got s5=8: the branch was decided per lane, not by the wave; " + detail
413 return (n8 - n80 > 0 and n7 > 0), detail
308 414
309 415
310def check_grad(raw_path: str, want_b: float, want_a: float) -> tuple[bool, str]: 416def check_grad(raw_path: str, want_b: float, want_a: float) -> tuple[bool, str]:
311 px = read_raw_rgba32f(raw_path) 417 px = read_raw_rgba32f(raw_path)
418 if problem := frame_problem(px):
419 return False, problem
312 bad = 0 420 bad = 0
313 first = "" 421 first = ""
314 for i, (r, g, b, a) in enumerate(px): 422 for i, (r, g, b, a) in enumerate(px):
@@ -352,23 +460,83 @@ def check_clip_half(raw_path: str, want_b: float, want_a: float) -> tuple[bool,
352 return ok, detail 460 return ok, detail
353 461
354 462
463# Shaders a selected test draws with, built even when the filter leaves them out (#192).
464DRAWN_WITH = {GATHER_LOD_TEST: "vs_ids.asm", "ps_flat": "vs_ids.asm", "ps_texture_sample": "vs_ids.asm", "ps_cube_sample": "vs_ids.asm",
465 "ps_texture_sample_d16": "vs_ids.asm", "ps_sample_c_lz": "vs_ids.asm", "ps_sample_c_lz_a16": "vs_ids.asm",
466 "ps_gather_wrap": "vs_ids.asm", "ps_ssharp": "vs_ids.asm",
467 **{name: "vs_ids.asm" for name in GRADIENT_TESTS}, "vs_clip": "ps_ops.asm"}
468
469
470def with_draw_shaders(asm_files: list[str]) -> list[str]:
471 build = list(asm_files)
472 for f in asm_files:
473 extra = DRAWN_WITH.get(shader_source(os.path.splitext(f)[0]))
474 if extra and extra not in build:
475 build.append(extra)
476 if TEXTURE_MIP_TEST + ".asm" in asm_files:
477 for name in TEXTURE_MIP_DEPENDENCIES:
478 if name + ".asm" not in build:
479 build.append(name + ".asm")
480 return build
481
482
483REQUIRED_TEST_PROGRAMS = ("vk_compute_test", "vk_store_test", "vk_harness")
484BUILD_CONFIGS = ("RelWithDebInfo", "Release")
485
486
487def find_test_programs(build: str, ext: str) -> str | None:
488 """Return the directory containing all required GPU test programs.
489
490 Single-configuration generators (Ninja, Makefiles) put executables directly
491 in the build directory. Visual Studio and other multi-configuration
492 generators put them in a configuration subdirectory.
493 """
494 candidates = [build, *(os.path.join(build, config) for config in BUILD_CONFIGS)]
495 for directory in candidates:
496 if all(os.path.isfile(os.path.join(directory, name + ext)) for name in REQUIRED_TEST_PROGRAMS):
497 return directory
498 return None
499
500
355def main() -> int: 501def main() -> int:
356 ap = argparse.ArgumentParser() 502 ap = argparse.ArgumentParser()
357 ap.add_argument("--llvm-mc", default=os.environ.get("LLVM_MC", "llvm-mc"), 503 ap.add_argument("--llvm-mc", default=os.environ.get("LLVM_MC", "llvm-mc"),
358 help="llvm-mc path, or a whole command such as 'wsl -d Ubuntu -e /usr/lib/llvm-21/bin/llvm-mc'") 504 help="llvm-mc path, or a whole command such as 'wsl -d Ubuntu -e /usr/lib/llvm-21/bin/llvm-mc'")
359 ap.add_argument("--build", default=os.path.join(ROOT, "runtime", "build")) 505 ap.add_argument("--build", default=os.path.join(ROOT, "runtime", "build"),
506 help="CMake build folder; with the Visual Studio generator the RelWithDebInfo/Release/... "
507 "subfolder that has the test programs is found by itself")
360 ap.add_argument("--work", default=None) 508 ap.add_argument("--work", default=None)
361 ap.add_argument("--filter", default="") 509 ap.add_argument("--filter", default="")
362 a = ap.parse_args() 510 a = ap.parse_args()
511 # Some test programs run with their working directory in <work>/spirv (vk_texture_test), so a relative path
512 # given here would point somewhere else for them.
513 a.build = os.path.abspath(a.build)
514 if a.work:
515 a.work = os.path.abspath(a.work)
363 516
364 ext = ".exe" if os.name == "nt" else "" 517 ext = ".exe" if os.name == "nt" else ""
365 missing = [t + ext for t in ("vk_compute_test", "vk_store_test", "vk_harness") 518 required = tuple(t + ext for t in TEST_PROGRAMS)
366 if not os.path.isfile(os.path.join(a.build, t + ext))] 519 a.build = pick_build_dir(a.build, required)
520 missing = [t for t in required if not os.path.isfile(os.path.join(a.build, t))]
367 if missing: 521 if missing:
368 sys.exit(f"Test programs not found in {os.path.abspath(a.build)}: {', '.join(missing)}\n" 522 sys.exit(not_found_message(a.build, missing))
523 requested_build = a.build
524 resolved_build = find_test_programs(requested_build, ext)
525 if resolved_build is None:
526 searched = [requested_build, *(os.path.join(requested_build, config) for config in BUILD_CONFIGS)]
527 details = []
528 for directory in searched:
529 missing = [name + ext for name in REQUIRED_TEST_PROGRAMS
530 if not os.path.isfile(os.path.join(directory, name + ext))]
531 details.append(f" {directory}: {', '.join(missing)}")
532 sys.exit("Required GPU test programs were not found together in one build directory.\n"
533 "Missing files by searched directory:\n" + "\n".join(details) + "\n"
369 "Build them with cmake -S runtime -B runtime/build, then cmake --build runtime/build.\n" 534 "Build them with cmake -S runtime -B runtime/build, then cmake --build runtime/build.\n"
535 "For Visual Studio, use: cmake --build <build-dir> --config RelWithDebInfo "
536 "--target vk_compute_test vk_store_test vk_harness.\n"
370 "CMake only builds them when it finds Vulkan. If it printed \"Vulkan SDK not found\", install the " 537 "CMake only builds them when it finds Vulkan. If it printed \"Vulkan SDK not found\", install the "
371 "Vulkan headers (vulkan-headers on Arch) and configure again.") 538 "Vulkan headers (vulkan-headers on Arch) and configure again.")
539 a.build = resolved_build
372 540
373 work = a.work or tempfile.mkdtemp(prefix="leonida_gpu_tests_") 541 work = a.work or tempfile.mkdtemp(prefix="leonida_gpu_tests_")
374 try: 542 try:
@@ -379,6 +547,14 @@ def main() -> int:
379 547
380 548
381def run_suite(a, work: str) -> int: 549def run_suite(a, work: str) -> int:
550 asm_files = sorted({f for f in os.listdir(SHADER_DIR) if f.endswith(".asm")} | {n + ".asm" for n in CLIP_CASES})
551 if a.filter:
552 asm_files = [f for f in asm_files if a.filter in f]
553 if not asm_files:
554 print(f"error: --filter {a.filter!r} matched no GPU test cases", file=sys.stderr)
555 return 2
556 build_files = with_draw_shaders(asm_files)
557
382 fssm_dir = os.path.join(work, "fssm") 558 fssm_dir = os.path.join(work, "fssm")
383 disasm_dir = os.path.join(work, "disasm") 559 disasm_dir = os.path.join(work, "disasm")
384 spirv_dir = os.path.join(work, "spirv") 560 spirv_dir = os.path.join(work, "spirv")
@@ -386,23 +562,18 @@ def run_suite(a, work: str) -> int:
386 for d in (fssm_dir, disasm_dir, spirv_dir, raw_dir): 562 for d in (fssm_dir, disasm_dir, spirv_dir, raw_dir):
387 os.makedirs(d, exist_ok=True) 563 os.makedirs(d, exist_ok=True)
388 564
389 asm_files = sorted(f for f in os.listdir(SHADER_DIR) if f.endswith(".asm"))
390 if a.filter:
391 asm_files = [f for f in asm_files if a.filter in f]
392 # Shaders a selected test draws with are built even when the filter leaves them out (#192): ps_flat and ps_ssharp use vs_ids.
393 build_files = list(asm_files)
394 if any(f.startswith(("ps_flat", "ps_ssharp")) for f in asm_files) and "vs_ids.asm" not in build_files:
395 build_files.append("vs_ids.asm")
396
397 # 1. Create synthetic DXBC / FSSM metadata + assemble .asm -> .s 565 # 1. Create synthetic DXBC / FSSM metadata + assemble .asm -> .s
566 disasm_files = []
398 for fname in build_files: 567 for fname in build_files:
399 name = os.path.splitext(fname)[0] 568 name = os.path.splitext(fname)[0]
400 if name == "gs_tri": 569 if name in CLIP_CASES and name != "vs_clip_undeclared":
570 dxbc = clip_container()
571 elif name == "gs_tri":
401 dxbc = make_dxbc([ 572 dxbc = make_dxbc([
402 (b"ISG1", make_sig_chunk([(1, 3, 0, 0xF, 0xF), (0, 3, 1, 0xF, 0xF)])), 573 (b"ISG1", make_sig_chunk([(1, 3, 0, 0xF, 0xF), (0, 3, 1, 0xF, 0xF)])),
403 (b"OSG1", make_sig_chunk([(1, 3, 0, 0xF, 0xF), (0, 3, 1, 0xF, 0xF)])), 574 (b"OSG1", make_sig_chunk([(1, 3, 0, 0xF, 0xF), (0, 3, 1, 0xF, 0xF)])),
404 ]) 575 ])
405 elif name in ("ms_tri", "ms_w64x_ballot"): 576 elif name in ("ms_tri", "ms_w64x_ballot", "ms_wave_info_s3"):
406 dxbc = make_dxbc([(b"PSV0", make_ms_psv0(128, 64, 64, 2))]) 577 dxbc = make_dxbc([(b"PSV0", make_ms_psv0(128, 64, 64, 2))])
407 elif name == "ms_v5_workgroup": 578 elif name == "ms_v5_workgroup":
408 dxbc = make_dxbc([(b"PSV0", make_ms_psv0(32, 3, 1, group_shared=128))]) 579 dxbc = make_dxbc([(b"PSV0", make_ms_psv0(32, 3, 1, group_shared=128))])
@@ -419,19 +590,33 @@ def run_suite(a, work: str) -> int:
419 if name.startswith("cs_"): 590 if name.startswith("cs_"):
420 with open(os.path.join(fssm_dir, f"{name}.fssm"), "wb") as f: 591 with open(os.path.join(fssm_dir, f"{name}.fssm"), "wb") as f:
421 f.write(compute_header(os.path.join(SHADER_DIR, fname))) 592 f.write(compute_header(os.path.join(SHADER_DIR, fname)))
422 assemble_to_s(a.llvm_mc, os.path.join(SHADER_DIR, fname), os.path.join(disasm_dir, f"{name}.s"), name) 593 fname = shader_source(name) + ".asm"
594 disasm_path = os.path.join(disasm_dir, f"{name}.s")
595 assemble_to_s(a.llvm_mc, os.path.join(SHADER_DIR, fname), disasm_path, name)
596 disasm_files.append(disasm_path)
423 # A failed translation must not run an old binary left in a reused --work directory. 597 # A failed translation must not run an old binary left in a reused --work directory.
424 Path(spirv_dir, f"{name}.spv").unlink(missing_ok=True) 598 Path(spirv_dir, f"{name}.spv").unlink(missing_ok=True)
425 599
426 # 2. Translate all .s -> .spv 600 # 2. Translate this run's inputs only. The translator looks for metadata one level above the input directory.
427 cmd = [sys.executable, "-I", TRANSLATOR, disasm_dir, "--out", spirv_dir] 601 with tempfile.TemporaryDirectory(prefix="disasm-", dir=work) as selected_disasm:
428 if os.environ.get("LEONIDA_W64_EMULATE") == "1": # wave64 compute/mesh exact on any subgroup size 602 for path in disasm_files:
429 cmd.append("--wave64-emulate") 603 shutil.copyfile(path, os.path.join(selected_disasm, os.path.basename(path)))
430 rc, out = run_cmd(cmd) 604 cmd = [sys.executable, "-I", TRANSLATOR, selected_disasm, "--out", spirv_dir]
605 if w64_emulated(): # wave64 compute/mesh exact on any subgroup size
606 cmd.append("--wave64-emulate")
607 if bary_fallback(): # raw barycentrics from an interpolated input, fed by a pass-through GS
608 cmd.append("--bary-fallback")
609 if TEXOFF_FALLBACK: # image_sample*_o: offset folded into the coordinate, no VK_KHR_maintenance8
610 cmd.append("--texel-offset-fallback")
611 rc, out = run_cmd(cmd, gpu=False)
431 print("=== rdna2spirv.py ===") 612 print("=== rdna2spirv.py ===")
432 print(out) 613 print(out)
433 if rc != 0: 614 if rc != 0:
434 return 1 615 return 1
616 if bary_fallback():
617 import bary_fallback_gs
618 for gs in bary_fallback_gs.build_for_index(spirv_dir):
619 print("bary fallback GS:", os.path.basename(gs))
435 620
436 # 3. Build helper SPIR-V shaders 621 # 3. Build helper SPIR-V shaders
437 vs_tri = os.path.join(spirv_dir, "vs_tri.spv") 622 vs_tri = os.path.join(spirv_dir, "vs_tri.spv")
@@ -455,9 +640,6 @@ def run_suite(a, work: str) -> int:
455 results: list[tuple[str, bool, str]] = [] 640 results: list[tuple[str, bool, str]] = []
456 for fname in asm_files: 641 for fname in asm_files:
457 name = os.path.splitext(fname)[0] 642 name = os.path.splitext(fname)[0]
458 if name in INTERPRETER_ONLY:
459 results.append((name, None, "SKIP (" + INTERPRETER_ONLY[name] + ")"))
460 continue
461 spv = os.path.join(spirv_dir, f"{name}.spv") 643 spv = os.path.join(spirv_dir, f"{name}.spv")
462 if not os.path.isfile(spv): 644 if not os.path.isfile(spv):
463 results.append((name, False, "missing .spv (translation failed)")) 645 results.append((name, False, "missing .spv (translation failed)"))
@@ -466,7 +648,10 @@ def run_suite(a, work: str) -> int:
466 cs_env = dict(os.environ, VKC_SUBGROUP_SIZE=str(sg)) if sg else None 648 cs_env = dict(os.environ, VKC_SUBGROUP_SIZE=str(sg)) if sg else None
467 gfx_env = dict(os.environ, VKH_SUBGROUP_SIZE=str(sg)) if sg else None 649 gfx_env = dict(os.environ, VKH_SUBGROUP_SIZE=str(sg)) if sg else None
468 650
469 if name == "cs_workgroup_yz": 651 if name in CLIP_CASES:
652 detail = clip_test(a.build, spirv_dir, name)
653 results.append((name, None if isinstance(detail, Skip) else not detail, detail or "four pixel masks exact"))
654 elif name == "cs_workgroup_yz":
470 rc, msg = run_cmd([vk_compute, spv, "2x3x4", "workgroup_yz"], env=cs_env) 655 rc, msg = run_cmd([vk_compute, spv, "2x3x4", "workgroup_yz"], env=cs_env)
471 results.append((name, rc == 0 and "2x3x4 workgroup Y/Z: 0 mismatches" in msg.splitlines(), msg)) 656 results.append((name, rc == 0 and "2x3x4 workgroup Y/Z: 0 mismatches" in msg.splitlines(), msg))
472 elif name == "cs_lds": 657 elif name == "cs_lds":
@@ -478,95 +663,213 @@ def run_suite(a, work: str) -> int:
478 elif name == "cs_bvh": 663 elif name == "cs_bvh":
479 rc, msg = run_cmd([vk_compute, spv, "1", "bvh"], env=cs_env) 664 rc, msg = run_cmd([vk_compute, spv, "1", "bvh"], env=cs_env)
480 results.append((name, rc == 0, msg.splitlines()[-1] if msg else "")) 665 results.append((name, rc == 0, msg.splitlines()[-1] if msg else ""))
481 elif name == "cs_bounds": 666 elif name in ("cs_bounds", "cs_smem_bounds", "cs_smem_stride_align", "cs_smem_sload_neg", "cs_buf_tail", "cs_oob_select", "cs_oob_tail",
667 "cs_cmpx_class_f32"):
482 # num_records bounds check (cs_bounds.asm): the out-of-bounds store is dropped and the out-of-bounds 668 # num_records bounds check (cs_bounds.asm): the out-of-bounds store is dropped and the out-of-bounds
483 # load reads 0, so thread 0's four output words are fixed. One thread, no wave64 requirement. 669 # load reads 0, so thread 0's four output words are fixed. One thread, no wave64 requirement.
670 # cs_cmpx_class_f32 is per-lane and needs no particular subgroup width either.
671 # The other four pin the SMEM and raw MUBUF rules measured on an RX 6800 (derivations in each .asm).
484 rc, msg = run_cmd([vk_compute, spv, "1", "dump"], env=cs_env) 672 rc, msg = run_cmd([vk_compute, spv, "1", "dump"], env=cs_env)
485 want = [0x12345678, 0x12345678, 0, 0xEEEEEEEE] 673 want = {
486 dump = next((ln for ln in msg.splitlines() if "out[0..7] =" in ln), "") 674 "cs_bounds": [0x12345678, 0x12345678, 0, 0xEEEEEEEE],
487 vals = [int(x) for x in dump.partition("=")[2].split()[:len(want)]] if dump else [] 675 "cs_smem_bounds": [0, 0x5EED0010, 0x5EED000C, 0, 0x5EED000C, 0x5EED0010, 0, 0],
676 "cs_smem_stride_align": [0x5EED0010, 0, 0, 0x5EED0000, 0x5EED0000, 0x5EED0000, 0x5EED0000,
677 0x5EED0004],
678 # never run with a translator that zero-extends the s_load immediate (reads 4 GiB past the heap)
679 "cs_smem_sload_neg": [0x5EED0004, 0x5EED0000, 0x5EED0004, 0x5EED0004, 0x5EED0008, 0x5EED000C,
680 0xEEEEEEEE, 0xEEEEEEEE],
681 "cs_buf_tail": [0, 0x5EED000C, 0x5EED0008, 0x5EED000C, 0, 0, 0x5EED0010, 0],
682 "cs_oob_select": [0x5EED000C, 0, 0x5EED0014, 0, 0x5EED0018, 0xEEEEEEEE, 0, 0],
683 "cs_oob_tail": [0, 0, 0x5EED0010, 0, 0xBEEF0000, 0xEEEEEEEE, 0, 0x5EED0010],
684 "cs_cmpx_class_f32": CMPX_CLASS_WORDS,
685 }[name]
686 words = dump_words(msg)
687 vals = words[:len(want)] if words else []
488 results.append((name, rc == 0 and vals == want, 688 results.append((name, rc == 0 and vals == want,
489 " ".join(hex(x) for x in vals) if vals else msg)) 689 " ".join(hex(x) for x in vals) if vals else msg))
690 elif name == "cs_fmt_1010102":
691 problem = fmt_1010102_test(a.build, spirv_dir, cs_env)
692 results.append((name, not problem, problem or "64/64 dumped words exact"))
693 elif name == "cs_global_neg_offset":
694 # Negative global_load/global_store offsets (cs_global_neg_offset.asm): 40 groups give a 0x2800-byte
695 # heap holding both the right addresses and the 4096-lower ones. One thread, no wave64 requirement.
696 rc, msg = run_cmd([vk_compute, spv, "40", "dump"], env=cs_env)
697 want = [0x5EED1FFC, 0x8BAD1800, 0x5EED1FF0, 0x5EED1FF4, 0x9E, 0xFFFF8BAD, 0x57023FFC, 0xEEEEEEEE]
698 ok, detail = judge_cs_dump(rc, msg, want, wave64=False, partial=False, emulated=False, hexwords=True)
699 results.append((name, ok, detail))
700 elif name == "cs_user_sgprs":
701 # vk_compute_test seeds s4..s7 from VKC_SGPRS; the shader stores them back.
702 rc, msg = run_cmd([vk_compute, spv, "1", "dump"], env=dict(cs_env or os.environ, **USER_SGPRS_ENV))
703 words = dump_words(msg)
704 vals = words[:len(USER_SGPRS_WORDS)] if words else []
705 results.append((name, rc == 0 and vals == USER_SGPRS_WORDS,
706 " ".join(hex(x) for x in vals) if vals else msg))
707 elif name == "cs_cvt_f32_sat":
708 # #300's saturating float -> int conversions: one dispatch per input word in s4 (VKC_SGPRS).
709 wrong = []
710 for bits, unsigned, signed in CVT_F32_SAT_CASES:
711 rc, msg = run_cmd([vk_compute, spv, "1", "dump"],
712 env=dict(cs_env or os.environ, VKC_SGPRS=f"{bits:#010x}"))
713 words = dump_words(msg)
714 if rc != 0 or not words or words[:2] != [unsigned, signed]:
715 got = " ".join(hex(x) for x in words[:2]) if words else msg.splitlines()[-1] if msg else "no output"
716 wrong.append(f"{bits:#010x} gave {got}, want {unsigned:#x} {signed:#x}")
717 n = len(CVT_F32_SAT_CASES)
718 results.append((name, not wrong, f"{n}/{n} inputs exact" if not wrong
719 else f"{len(wrong)}/{n} inputs wrong, first {wrong[0]}"))
490 elif name == "cs_wavemask": 720 elif name == "cs_wavemask":
491 # Whole-wave mask test, as in check.py: needs a 64-wide subgroup, skipped where the device has none. 721 # Whole-wave mask test, as in check.py: needs a 64-wide subgroup, skipped where the device has none.
492 # With LEONIDA_W64_EMULATE=1 it was translated with --wave64-emulate and runs on any subgroup size. 722 # With LEONIDA_W64_EMULATE=1 it was translated with --wave64-emulate and runs on any subgroup size.
493 emulated = os.environ.get("LEONIDA_W64_EMULATE") == "1" 723 results.append((name,) + wavemask_check(vk_compute, spv, cs_env, w64_emulated()))
494 args = [] if emulated else ["--require-wave64"] 724 elif name in ("cs_store", "cs_smem_soffset_imm", "cs_w32_lane_wrap", "cs_movrelsd_2", "cs_w32_permute", "cs_exec_const", "cs_w32_lds_u8_d16", "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",
495 rc, msg = run_cmd([vk_compute, spv, "1", "wavemask", *args], env=cs_env) 725
496 if not emulated and rc == 77:
497 results.append((name, None, "SKIP (no 64-wide compute subgroup on this device)"))
498 elif not emulated and rc == 0 and "compute subgroup size: 64" not in msg.splitlines():
499 results.append((name, False, "64-wide subgroup was not confirmed (rebuild vk_compute_test)"))
500 else:
501 results.append((name, rc == 0, msg.splitlines()[-1] if msg else ""))
502 elif name in ("cs_store", "cs_smem_soffset_imm", "cs_wave64_ballot", "cs_wm_half_ops", "cs_wm_half_cmp", "cs_wm_bfm64", "cs_wm_scc_rfl",
503 "cs_w64_mask_detect", 726 "cs_w64_mask_detect",
504 "cs_w64x_readlane", "cs_w64x_writelane", "cs_w64x_readfirstlane", "cs_w64x_bpermute", 727 "cs_w64x_readlane", "cs_w64x_writelane", "cs_w64x_readfirstlane", "cs_w64x_bpermute", "cs_w64x_permute",
505 "cs_w64x_branch", "cs_w64x_ballot", "cs_w64x_wg128_branches", "cs_w64x_lds_raw", 728 "cs_w64x_branch", "cs_w64x_ballot", "cs_w64x_wg128_branches", "cs_w64x_lds_raw",
506 "cs_w64x_lds_war", "cs_w64x_partial", "cs_w64x_sbarrier", "cs_w64x_load_ballot_load"): 729 "cs_w64x_lds_war", "cs_w64x_partial", "cs_w64x_sbarrier", "cs_w64x_load_ballot_load",
730 "cs_w64x_mask_reuse", "cs_w64x_mask_reuse2", "cs_w64x_chain_barrier", "cs_barrier_divergent",
731 "cs_bpermute32", "cs_w64x_partial_scmp", "cs_w32_partial_scmp", "cs_barrier_early_end",
732 "cs_barrier_loop"):
507 cs_dump_wants = { 733 cs_dump_wants = {
508 "cs_store": [0x400080FF, 0xE00003FF, 0x3C004000, 0xEEEEEEEE, 0x40003C00, 0xBC003800], 734 "cs_store": [0x400080FF, 0xE00003FF, 0x3C004000, 0xEEEEEEEE, 0x40003C00, 0xBC003800],
509 # base + soffset + imm (cs_smem_soffset_imm.asm); out[4..7] are seeds the shader leaves alone 735 # base + soffset + imm (cs_smem_soffset_imm.asm); out[4..7] are seeds the shader leaves alone
510 "cs_smem_soffset_imm": [0x5EED0024, 0x5EED0028, 0x5EED002C, 0x5EED0030, 736 "cs_smem_soffset_imm": [0x5EED0024, 0x5EED0028, 0x5EED002C, 0x5EED0030,
511 0x5EED0010, 0x5EED0014, 0x5EED0018, 0x5EED001C], 737 0x5EED0010, 0x5EED0014, 0x5EED0018, 0x5EED001C],
738 # SHADER-52: wave32 lane select & 31 (40 → 8)
739 "cs_w32_lane_wrap": [25, 16, 777, 777],
740 # v_movrelsd_2_b32: VGPR[D + M0[25:16]] = VGPR[S0 + M0[9:0]] (cs_movrelsd_2.asm)
741 "cs_movrelsd_2": [11, 33, 33, 55, 1717, 77, 1515, 1717],
742 # SHADER-90: ds_permute_b32 (cs_w32_permute.asm): scatter, unwritten lane = 0, EXEC gates the write
743 "cs_w32_permute": [218, 29, 8, 211, 0, 15, 99, 15],
744 # SHADER-85: ds_read_u8/i8_d16[_hi] (cs_w32_lds_u8_d16.asm header)
745 "cs_w32_lds_u8_d16": [0xBEEF00FF, 0x00FF1234, 0xBEEFFF80, 0xFF801234, 0xBEEF007F, 0x007F1234, 0xBEEF0080, 0xFFFF1234],
746 # constant EXEC masks (cs_exec_const.asm): each lane takes its own bit of the constant
747 "cs_exec_const": [16, 8, 2, 16, 0, 16],
512 "cs_wave64_ballot": [32, 16, 24, 40, 8, 48], 748 "cs_wave64_ballot": [32, 16, 24, 40, 8, 48],
513 "cs_wm_half_ops": [32, 16, 16, 0, 16], 749 "cs_wm_half_ops": [32, 16, 16, 0, 16],
514 "cs_wm_half_cmp": [1, 0, 1, 1], 750 "cs_wm_half_cmp": [1, 0, 1, 1],
515 "cs_wm_bfm64": [16, 8, 8, 40], 751 "cs_wm_bfm64": [16, 8, 8, 40],
516 "cs_wm_scc_rfl": [55, 48], 752 "cs_wm_scc_rfl": [55, 48],
517 "cs_w64_mask_detect": [48], 753 "cs_w64_mask_detect": [48],
754 "cs_wqm_w64": [20, 4, 12, 8, 1, 0, 15728895, 20], # cs_wqm_w64.asm / cs_wqm_w32.asm headers
755 "cs_wqm_w32": [12, 1, 4, 0, 8, 15728880, 4, 32],
756 "cs_wqm_w64_half": [11, 14, 0, 1, 6, 8, 12, 2],
518 # cross-half tests (derivations in each .asm); need exact wave64 or its emulation 757 # cross-half tests (derivations in each .asm); need exact wave64 or its emulation
519 "cs_w64x_readlane": [121, 121, 16, 97, 16, 100, 100, 121], 758 "cs_w64x_readlane": [121, 121, 16, 97, 16, 100, 100, 121],
520 "cs_w64x_writelane": [4660, 77, 99, 2748, 0, 0, 4660, 99], 759 "cs_w64x_writelane": [4660, 77, 99, 2748, 0, 0, 4660, 99],
521 "cs_w64x_readfirstlane": [140, 140, 163, 132, 100, 105, 133, 48], 760 "cs_w64x_readfirstlane": [140, 140, 163, 132, 100, 105, 133, 48],
522 "cs_w64x_bpermute": [36, 316, 253, 218, 435, 225, 0, 442], 761 "cs_w64x_bpermute": [36, 316, 253, 218, 435, 225, 0, 442],
762 "cs_w64x_permute": [218, 442, 435, 239, 0, 99, 239, 232], # SHADER-90, cs_w64x_permute.asm
523 "cs_w64x_branch": [0, 0, 0, 0, 5, 5, 9, 9], 763 "cs_w64x_branch": [0, 0, 0, 0, 5, 5, 9, 9],
764 "cs_w64x_mask_reuse": [8, 40, 8, 40, 2, 20, 10, 64],
765 "cs_w64x_mask_reuse2": [10, 20, 8, 8, 5, 2, 132, 131],
766 "cs_w64x_chain_barrier": [564, 563, 500, 627],
524 "cs_w64x_ballot": [2053, 2061, 2069, 2077, 2085, 2093, 2101, 2109], 767 "cs_w64x_ballot": [2053, 2061, 2069, 2077, 2085, 2093, 2101, 2109],
525 "cs_w64x_wg128_branches": [121, 121, 343, 343, 14, 31, 19812, 22728], 768 "cs_w64x_wg128_branches": [121, 121, 343, 343, 14, 31, 19812, 22728],
526 "cs_w64x_lds_raw": [132, 137, 100, 108, 131, 101, 149, 118], 769 "cs_w64x_lds_raw": [132, 137, 100, 108, 131, 101, 149, 118],
527 "cs_w64x_lds_war": [1032, 1063, 1000, 1031, 2032, 2063, 2000, 2031], 770 "cs_w64x_lds_war": [1032, 1063, 1000, 1031, 2032, 2063, 2000, 2031],
528 "cs_w64x_partial": [40, 40, 528, 0, 0, 532, 539, 524820], 771 "cs_w64x_partial": [40, 40, 528, 0, 0, 532, 539, 524820],
772 "cs_w64x_partial_scmp": [0, 1, 0, 1, 1, 1, 1, 0], # s_cmp mask, -1 in a partial wave
773 "cs_w32_partial_scmp": [0, 1, 1, 0, 1, 1, 1, 1], # the same in a 20-thread wave32
529 "cs_w64x_sbarrier": [605, 605, 686, 686, 3032, 3013, 3032, 3031], 774 "cs_w64x_sbarrier": [605, 605, 686, 686, 3032, 3013, 3032, 3031],
530 "cs_w64x_load_ballot_load": [43, 74, 75, 42, 42, 18, 41, 32], 775 "cs_w64x_load_ballot_load": [43, 74, 75, 42, 42, 18, 41, 32],
776 "cs_bpermute32": [0, 50, 162, 99, 36, 218, 183, 15], # wave32: needs 32 lanes
777 # SHADER-91: s_barrier sites in different wave-uniform branches meet (cs_barrier_divergent.asm)
778 "cs_barrier_divergent": [127, 126, 125, 124, 123, 122, 121, 120],
779 # SHADER-91: other waves end without s_barrier (cs_barrier_early_end.asm); a loop whose trip count
780 # differs per wave (cs_barrier_loop.asm)
781 "cs_barrier_early_end": [127, 126, 125, 124, 123, 122, 121, 120],
782 "cs_barrier_loop": [128, 96, 64, 32, 128, 96, 64, 0xEEEEEEEE],
531 } 783 }
532 want = cs_dump_wants[name] 784 want = cs_dump_wants[name]
533 # Every dump but cs_store and cs_smem_soffset_imm is a whole-wave (wave64) mask test: ask for a 64-wide subgroup and skip, as 785 # Every dump but cs_store / cs_smem_soffset_imm / cs_w32_lane_wrap / cs_movrelsd_2 / cs_w32_permute /
534 # check.py does, where the device has none (vk_compute_test exits 77) instead of reporting a failure. 786 # cs_w32_lds_u8_d16 and the wave32 cs_wqm_w32 / cs_bpermute32 is a whole-wave (wave64) mask test:
535 # With LEONIDA_W64_EMULATE=1 they were translated with --wave64-emulate and run on any subgroup size. 787 # ask for a 64-wide subgroup and skip, as check.py does, where the device has none (vk_compute_test
536 # cs_w64x_partial (a 40-thread group) can't have full subgroups: it asks for size 64 without them. 788 # exits 77) instead of reporting a failure. With LEONIDA_W64_EMULATE=1 they were translated with
537 emulated = os.environ.get("LEONIDA_W64_EMULATE") == "1" 789 # --wave64-emulate and run on any subgroup size.
538 partial = name == "cs_w64x_partial" 790 # cs_w64x_partial and cs_w64x_partial_scmp (40-thread groups) can't have full subgroups: they ask for
539 wave64 = name not in ("cs_store", "cs_smem_soffset_imm") and not emulated and not partial 791 # size 64 without them.
792 emulated = w64_emulated()
793 partial = name in ("cs_w64x_partial", "cs_w64x_partial_scmp")
794 wave64 = name not in ("cs_store", "cs_smem_soffset_imm", "cs_wqm_w32", "cs_w32_lane_wrap", "cs_movrelsd_2",
795 "cs_w32_permute", "cs_barrier_divergent", "cs_barrier_early_end", "cs_barrier_loop",
796 "cs_w32_lds_u8_d16", "cs_bpermute32", "cs_w32_partial_scmp",
797 "cs_exec_const") and not emulated and not partial
798
540 if partial and not emulated: 799 if partial and not emulated:
541 cs_env = dict(os.environ, VKC_SUBGROUP_SIZE="64") 800 cs_env = dict(os.environ, VKC_SUBGROUP_SIZE="64")
801 if name in WAVE32_LANE_DUMPS: # 32 lanes even without index.json, as check.py requests (#774)
802 cs_env = dict(os.environ, **WAVE32_LANE_ENV)
542 rc, msg = run_cmd([vk_compute, spv, "1", "dump"] + (["--require-wave64"] if wave64 else []), env=cs_env) 803 rc, msg = run_cmd([vk_compute, spv, "1", "dump"] + (["--require-wave64"] if wave64 else []), env=cs_env)
543 dump_line = next((ln for ln in msg.splitlines() if "out[0..7] =" in ln), "") 804 skip = wave32_lane_skip(msg) if name in WAVE32_LANE_DUMPS else None
544 no64 = partial and not emulated and not any(int(x) >= 64 for x in re.findall(r"subgroup \d+\.\.(\d+)", msg)) 805 if skip: # e.g. Mesa llvmpipe's 8-wide subgroups: these 32-lane masks can't come out right
545 if (wave64 and rc == 77) or (no64 and rc == 0): 806 ok, detail = None, str(skip)
546 results.append((name, None, "SKIP (no 64-wide compute subgroup on this device)"))
547 elif rc == 0 and dump_line:
548 vals = [int(x) for x in dump_line.split("=")[1].split()[:len(want)]]
549 ok = vals == want
550 fmt = hex if name in ("cs_store", "cs_smem_soffset_imm") else str
551 results.append((name, ok, " ".join(fmt(x) for x in vals)))
552 else: 807 else:
553 results.append((name, False, msg)) 808 ok, detail = judge_cs_dump(rc, msg, want, wave64=wave64, partial=partial, emulated=emulated,
809 hexwords=name in ("cs_store", "cs_smem_soffset_imm", "cs_w32_lds_u8_d16"))
810 results.append((name, ok, detail))
554 elif name == "cs_imgstore": 811 elif name == "cs_imgstore":
555 rc, msg = run_cmd([vk_store, spv]) 812 rc, msg = run_cmd([vk_store, spv])
556 results.append((name, rc == 0, msg.splitlines()[-1] if msg else "")) 813 results.append((name, rc == 0, msg.splitlines()[-1] if msg else ""))
557 elif name == "cs_imgload": 814 elif name in ("cs_imgload", "cs_imgload_d16"):
558 rc, msg = run_cmd([vk_store, spv, "load"]) 815 rc, msg = run_cmd([vk_store, spv, "load"])
559 results.append((name, rc == 0, msg.splitlines()[-1] if msg else "")) 816 results.append((name, rc == 0, msg.splitlines()[-1] if msg else ""))
560 elif name == "ps_texture_sample": 817 elif name in MIP_TEST_PASSES:
561 # #167's bindless texture test: vk_texture_test finds vs_ids.spv and this shader in its working directory. 818 problem = texture_mip_test(a.build, spirv_dir, name)
819 ok = None if isinstance(problem, Skip) else not problem
820 results.append((name, ok, problem or "two passes, 4096 RGBA32F pixels each exact; wrong mip and UV rejected"))
821 elif name in GRADIENT_TESTS:
822 problem = texture_gradient_a16_test(a.build, spirv_dir, name)
823 ok = None if isinstance(problem, Skip) else not problem
824 results.append((name, ok, problem or "4096 RGBA pixels matched"))
825 elif name in ("ps_texture_sample", "ps_cube_sample", "ps_texture_sample_d16", "ps_sample_c_lz",
826 "ps_sample_c_lz_a16"):
827 # Bindless texture tests: vk_texture_test finds vs_ids.spv and the shader in its working directory.
828 tool = os.path.join(a.build, "vk_texture_test" + ext)
829 raw = os.path.join(raw_dir, f"{name}.raw")
830 if name == "ps_texture_sample_d16":
831 cmd = [tool, os.path.join(spirv_dir, "vs_ids.spv"), spv, raw, "0", "0", "0", "0", "0"]
832 else:
833 mode = {"ps_cube_sample": ["cube"], "ps_sample_c_lz": ["dref"],
834 "ps_sample_c_lz_a16": ["dref_a16"]}.get(name, [])
835 cmd = [tool, *mode, raw]
836 try:
837 p = subprocess.run(cmd, capture_output=True, text=True, cwd=spirv_dir)
838 rc, msg = p.returncode, (p.stdout + "\n" + p.stderr).strip()
839 except FileNotFoundError:
840 rc, msg = 1, f"missing {tool}"
841 except OSError as e:
842 rc, msg = 1, start_failure(tool, e)
843 if rc == UNSUPPORTED: # e.g. fewer push constant bytes than the texture tests need
844 results.append((name, None, unsupported_skip(msg)))
845 elif name == "ps_texture_sample_d16" and rc == 0 and os.path.isfile(raw):
846 with open(raw, "rb") as f:
847 f.seek((32 * 64 + 32) * 16)
848 r, g, b, alpha = struct.unpack("<4f", f.read(16))
849 exp_b = struct.unpack("<e", struct.pack("<e", 128.0 / 255.0))[0]
850 ok = abs(r - exp_b) <= 0.05 and abs(g - exp_b) <= 0.05 and abs(b - exp_b) == 0.0 and alpha == 1.0
851 results.append((name, ok, f"center(32,32)=({r:.6f}, {g:.6f}, {b:.6f}, {alpha:.1f})"))
852 else:
853 results.append((name, rc == 0 and "PASSED" in msg, msg.splitlines()[-1] if msg else ""))
854 elif name == "ps_gather_wrap":
855 # SHADER-36: image_gather4_l_o under wrap/mirror/clamp/mirror-once S#s; every pixel holds GATHER_WRAP.
562 tool = os.path.join(a.build, "vk_texture_test" + ext) 856 tool = os.path.join(a.build, "vk_texture_test" + ext)
563 raw = os.path.join(raw_dir, f"{name}.raw") 857 raw = os.path.join(raw_dir, f"{name}.raw")
564 try: 858 try:
565 p = subprocess.run([tool, raw], capture_output=True, text=True, cwd=spirv_dir) 859 p = subprocess.run([tool, os.path.join(spirv_dir, "vs_ids.spv"), spv, raw, "0", "92", "c00000",
860 "14500000", "0"], capture_output=True, text=True, cwd=spirv_dir)
566 rc, msg = p.returncode, (p.stdout + "\n" + p.stderr).strip() 861 rc, msg = p.returncode, (p.stdout + "\n" + p.stderr).strip()
567 except FileNotFoundError: 862 except FileNotFoundError:
568 rc, msg = 1, f"missing {tool}" 863 rc, msg = 1, f"missing {tool}"
569 results.append((name, rc == 0 and "PASSED" in msg, msg.splitlines()[-1] if msg else "")) 864 bad = 4096
865 if rc == 0 and os.path.isfile(raw):
866 data = Path(raw).read_bytes()
867 bad = 4096 if len(data) != 64 * 64 * 16 else sum(q != GATHER_WRAP for q in struct.iter_unpack("<4f", data))
868 if rc == UNSUPPORTED:
869 results.append((name, None, unsupported_skip(msg)))
870 else:
871 results.append((name, rc == 0 and bad == 0, "4096/4096 pixels exact" if bad == 0 else
872 f"{bad} pixels differ from {GATHER_WRAP}: {msg.splitlines()[-1] if msg else ''}"))
570 elif name == "ps_tex": 873 elif name == "ps_tex":
571 # A texture through the descriptor hash table and the bindless set. vk_bindless_test compares the 874 # A texture through the descriptor hash table and the bindless set. vk_bindless_test compares the
572 # pixels itself, and exits 77 where the device lacks a feature the set or the shader needs. 875 # pixels itself, and exits 77 where the device lacks a feature the set or the shader needs.
@@ -582,12 +885,30 @@ def run_suite(a, work: str) -> int:
582 problem = sampler_test(a.build, spirv_dir) 885 problem = sampler_test(a.build, spirv_dir)
583 results.append((name, None if isinstance(problem, Skip) else not problem, 886 results.append((name, None if isinstance(problem, Skip) else not problem,
584 problem or f"{len(SAMPLER_CASES)} S#/T# cases, 4096 pixels each exact")) 887 problem or f"{len(SAMPLER_CASES)} S#/T# cases, 4096 pixels each exact"))
888 elif name in ("ps_texoff", "ps_texoff_implicit"):
889 # Texel offsets: needs vk_texture_test's texture, sampler and descriptor table (vk_harness binds none),
890 # and VK_KHR_maintenance8 for the non-constant Offset; the tool exits 77 without it.
891 raw = os.path.join(raw_dir, f"{name}.raw")
892 rc, msg = run_cmd([os.path.join(a.build, "vk_texture_test" + ext), vs_tri, spv, raw, *TEXOFF_ARGS],
893 env=texoff_env())
894 if rc == UNSUPPORTED:
895 results.append((name, None, unsupported_skip(msg)))
896 elif rc != 0:
897 results.append((name, False, msg))
898 else:
899 with open(raw, "rb") as f:
900 problem, covered = texoff_problem(f.read(), msg)
901 results.append((name, not problem, problem or f"4096/4096 pixels exact ({covered})"))
585 elif name.startswith("ps_"): 902 elif name.startswith("ps_"):
586 raw = os.path.join(raw_dir, f"{name}.raw") 903 raw = os.path.join(raw_dir, f"{name}.raw")
587 vs = os.path.join(spirv_dir, "vs_ids.spv") if name == "ps_flat" else vs_tri # check.py draws ps_flat with vs_ids 904 vs = os.path.join(spirv_dir, "vs_ids.spv") if name == "ps_flat" else vs_tri # check.py draws ps_flat with vs_ids
588 rc, msg = run_cmd([vk_harness, vs, spv, raw], env=gfx_env) 905 env = dict(gfx_env or os.environ, **PIXEL_ENV[name]) if name in PIXEL_ENV else gfx_env
906 bary_gs = os.path.join(spirv_dir, f"{name}.bary_gs.spv")
907 if bary_fallback() and os.path.isfile(bary_gs): # --bary-fallback PS: barycentrics from this GS
908 env = dict(env or os.environ, VKH_GS=bary_gs, VKH_GS_HELPER="1")
909 rc, msg = run_cmd([vk_harness, vs, spv, raw], env=env)
589 if rc == 77: # vk_harness: the device lacks a feature this shader needs (e.g. barycentrics) 910 if rc == 77: # vk_harness: the device lacks a feature this shader needs (e.g. barycentrics)
590 results.append((name, None, "SKIP (unsupported device)")) 911 results.append((name, None, unsupported_skip(msg)))
591 continue 912 continue
592 if rc != 0: 913 if rc != 0:
593 results.append((name, False, msg)) 914 results.append((name, False, msg))
@@ -604,6 +925,25 @@ def run_suite(a, work: str) -> int:
604 "ps_ops6": (0xF800FFFF, 0x01000010, 0x00800800, 0x8000FFF0), 925 "ps_ops6": (0xF800FFFF, 0x01000010, 0x00800800, 0x8000FFF0),
605 "ps_ops7": (0x00FF8077, 0xFF0000FF, 0x89ABCDEF, 0x00070003), 926 "ps_ops7": (0x00FF8077, 0xFF0000FF, 0x89ABCDEF, 0x00070003),
606 "ps_ops8": (0x80000000, 0xFFFFFFFF, 0x000F100E, 0x0F0F0F1F), 927 "ps_ops8": (0x80000000, 0xFFFFFFFF, 0x000F100E, 0x0F0F0F1F),
928 "ps_f32_mods": (0xC0256A01, 0x3F800000, 0x41E00000, 0x3FC00000),
929 "ps_vcc_x2": (0x11223344, 0x55667788, 0, 0),
930 "ps_med3_mods": (0x3F800000, 0x40400000, 0x40C00000, 0x3F400000),
931 "ps_scc_minmax": (0x00030205, 0x00030207, 0x00030209, 0x00030203),
932 "ps_fma_literal": (0x41B80000, 0x41800000, 0x40E00000, 0x41A40000),
933 "ps_f64_mods": (0x40040000, 0x3FF00000, 0x3FE40000, 0x3FF00000), # needs shaderFloat64
934 # f16 op_sel / partial writes / inline constants: RDNA2 hardware words (see the .asm headers)
935 "ps_f16_med3_opsel": (0xAAAA4100, 0xAAAA4200, 0xAAAA3E00, 0x40005555),
936 "ps_f16_med3_mods": (0x41005555, 0x3C005555, 0x41003800, 0xAAAABA00),
937 "ps_f16_vop2": (0xAAAA4000, 0xAAAAC000, 0xAAAA3A00, 0x42003F00),
938 "ps_f16_vop2b": (0xAAAA3E00, 0xAAAAB800, 0xAAAA3C00, 0x42003400),
939 "ps_f16_vop1": (0xAAAA4000, 0xAAAABC00, 0xAAAAC000, 0xAAAA8000),
940 "ps_f16_vop1b": (0xAAAA3400, 0xAAAA4000, 0xAAAAB400, 0xAAAA3800),
941 "ps_f16_const": (0xAAAA3D00, 0x38005555, 0xAAAA3800, 0x3F000000),
942 "ps_f16_const2": (0x42003D00, 0x3D004200, 0xAAAABC00, 3),
943 "ps_f16_pack": (0x34003C00, 0x38003400, 0x34000000, 0x44004200),
944 "ps_sff_imm": (2, 1, 20, 16), # SHADER-46: s_ff0/s_ff1 of an immediate
945 "ps_fnan_med3": (0x40A00000, 0xC0200000, 0xC0200000, 0x40600000), # measured on RDNA2 hardware
946 "ps_fnan_fract": (0x3F7FFFFF, 0x00003BFF, 0xC0200000, 0xC0200000),
607 } 947 }
608 if name in const_wants: 948 if name in const_wants:
609 ok, detail = check_pixel_const(raw, const_wants[name]) 949 ok, detail = check_pixel_const(raw, const_wants[name])
@@ -615,8 +955,10 @@ def run_suite(a, work: str) -> int:
615 ok, detail = None, f"SKIP (subgroup {m.group(1)} is narrower than 32 lanes)" 955 ok, detail = None, f"SKIP (subgroup {m.group(1)} is narrower than 32 lanes)"
616 else: 956 else:
617 ok, detail = check_bitmask_perm(raw) 957 ok, detail = check_bitmask_perm(raw)
618 elif name == "ps_uniform_branch": 958 elif name in ("ps_uniform_branch", "ps_scc_mask32"): # same expected pattern (see the .asm headers)
619 ok, detail = check_uniform_branch(raw) 959 ok, detail = check_uniform_branch(raw)
960 elif name == "ps_wqm":
961 ok, detail = check_wqm(raw)
620 elif name == "ps_flat": 962 elif name == "ps_flat":
621 ok, detail = check_flat(raw) 963 ok, detail = check_flat(raw)
622 else: 964 else:
@@ -641,13 +983,13 @@ def run_suite(a, work: str) -> int:
641 problem = mesh_v5_test(a.build, spirv_dir, Path(raw_dir) / f"{name}.raw") 983 problem = mesh_v5_test(a.build, spirv_dir, Path(raw_dir) / f"{name}.raw")
642 results.append((name, None if isinstance(problem, Skip) else not problem, 984 results.append((name, None if isinstance(problem, Skip) else not problem,
643 problem or "24/24 workgroup coordinates exact (2 x 3 x 4)")) 985 problem or "24/24 workgroup coordinates exact (2 x 3 x 4)"))
644 elif name in ("ms_tri", "ms_w64x_ballot"): 986 elif name in ("ms_tri", "ms_w64x_ballot", "ms_wave_info_s3"):
645 raw = os.path.join(raw_dir, f"{name}.raw") 987 raw = os.path.join(raw_dir, f"{name}.raw")
646 env = dict(gfx_env or os.environ, VKH_MESH="1") 988 env = dict(gfx_env or os.environ, VKH_MESH="1")
647 rc, msg = run_cmd([vk_harness, spv, fs_passthru, raw], env=env) 989 rc, msg = run_cmd([vk_harness, spv, fs_passthru, raw], env=env)
648 # ms_w64x_ballot needs exact wave64 (a 64-wide subgroup, or --wave64-emulate): skip it elsewhere, as 990 # ms_w64x_ballot needs exact wave64 (a 64-wide subgroup, or --wave64-emulate): skip it elsewhere, as
649 # the wave64 compute dumps are. 991 # the wave64 compute dumps are.
650 no64 = (name == "ms_w64x_ballot" and os.environ.get("LEONIDA_W64_EMULATE") != "1" and 992 no64 = (name == "ms_w64x_ballot" and not w64_emulated() and
651 not any(int(x) >= 64 for x in re.findall(r"subgroup \d+\.\.(\d+)", msg))) 993 not any(int(x) >= 64 for x in re.findall(r"subgroup \d+\.\.(\d+)", msg)))
652 if rc == UNSUPPORTED: 994 if rc == UNSUPPORTED:
653 results.append((name, None, unsupported_skip(msg))) 995 results.append((name, None, unsupported_skip(msg)))
@@ -670,6 +1012,17 @@ def run_suite(a, work: str) -> int:
670 ok, detail = check_clip_half(raw, 0.5, 1.0) 1012 ok, detail = check_clip_half(raw, 0.5, 1.0)
671 results.append((name, ok, detail)) 1013 results.append((name, ok, detail))
672 1014
1015 if a.filter and not results: # the filter matched only inputs/partners: say so rather than "0/0 passed"
1016 names = [os.path.splitext(f)[0] for f in asm_files]
1017 partners = {os.path.splitext(f)[0] for f in DRAWN_WITH.values()} | set(TEXTURE_MIP_DEPENDENCIES)
1018 shown = ", ".join(names[:5]) + (", ..." if len(names) > 5 else "")
1019 role = "partners built for other tests" if partners.issuperset(names) else "inputs without a GPU test row"
1020 hint = ("; cs_bench_* shaders are benchmark inputs, run them with the benchmark tool"
1021 if all(n.startswith("cs_bench_") for n in names) else "")
1022 print(f"error: --filter {a.filter!r} selected {shown} but no runnable GPU test cases ({role}){hint}",
1023 file=sys.stderr)
1024 return 2
1025
673 print("\n=== GPU TEST RESULTS ===") 1026 print("\n=== GPU TEST RESULTS ===")
674 passed = skipped = 0 1027 passed = skipped = 0
675 for name, ok, detail in results: 1028 for name, ok, detail in results: