upleb.uk

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

summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorDiesel <dev.diesel@proton.me>2026-11-21 22:44:07 +0100
committerDiesel <dev.diesel@proton.me>2026-11-21 22:44:07 +0100
commit5c1a1fbb6bf6f609eb4e61baa4961ce382743a4e (patch)
treeac8ad90058b97ab241fdc65edae3d4628d20ee1e /scripts
parentc45309e29f21c1d5b75678db0e2dc2dd11cff25b (diff)
parent4e390e0871d7265e629b51aca8ff99a15a6a6845 (diff)
Merge main to include the compute Y/Z harness test fix
Diffstat (limited to 'scripts')
-rw-r--r--scripts/build_llvm_mc.ps182
-rw-r--r--scripts/build_runtime.ps13
-rw-r--r--scripts/run_gpu_tests.py28
3 files changed, 105 insertions, 8 deletions
diff --git a/scripts/build_llvm_mc.ps1 b/scripts/build_llvm_mc.ps1
new file mode 100644
index 000000000..ea72db26f
--- /dev/null
+++ b/scripts/build_llvm_mc.ps1
@@ -0,0 +1,82 @@
1# Builds a native Windows llvm-mc.exe with the AMDGPU target, for the shader disassembler, without WSL.
2# The official Windows LLVM build ships no llvm-mc.exe and no AMDGPU target. This fetches only the LLVM sources the
3# tool needs (sparse, shallow), builds llvm-mc alone with AMDGPU as the only target, keeps llvm-mc.exe (static CRT,
4# so it runs without the VC++ redistributable) and deletes the rest. Needs git, Python 3 and Visual Studio with the
5# C++ x64 tools; uses VS's CMake + Ninja, or the ones on PATH. About 2 GB of temporary space, 20-40 minutes.
6#
7# powershell -ExecutionPolicy Bypass -File scripts\build_llvm_mc.ps1
8# powershell -ExecutionPolicy Bypass -File scripts\build_llvm_mc.ps1 -Dest D:\tools\llvm-mc -NoEnv
9param(
10 [string]$Version = "21.1.8",
11 [string]$Dest = (Join-Path $env:LOCALAPPDATA "Leonida\llvm-mc"),
12 [string]$Temp = (Join-Path $env:TEMP "leonida-llvm-mc"),
13 [switch]$NoEnv, # don't set LLVM_MC for the current user
14 [switch]$Keep # keep the sources and build folder (faster rebuilds)
15)
16$ErrorActionPreference = "Stop"
17
18foreach ($t in "git", "python") {
19 if (-not (Get-Command $t -ErrorAction SilentlyContinue)) { throw "$t wasn't found on PATH." }
20}
21$installer = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer"
22$vs = & "$installer\vswhere.exe" -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath
23if (-not $vs) { throw "Visual Studio with the C++ x64 tools wasn't found." }
24$vcvars = Join-Path $vs "VC\Auxiliary\Build\vcvars64.bat"
25$jobs = [Math]::Max(1, [int]([Environment]::ProcessorCount / 2))
26
27$cmakeDir = Join-Path $vs "Common7\IDE\CommonExtensions\Microsoft\CMake"
28$cmake = Join-Path $cmakeDir "CMake\bin\cmake.exe"
29$ninja = Join-Path $cmakeDir "Ninja\ninja.exe"
30if (-not ((Test-Path $cmake) -and (Test-Path $ninja))) {
31 $cmake = (Get-Command cmake -ErrorAction SilentlyContinue).Source
32 $ninja = (Get-Command ninja -ErrorAction SilentlyContinue).Source
33 if (-not ($cmake -and $ninja)) { throw "CMake and Ninja weren't found (install VS's 'C++ CMake tools' or put them on PATH)." }
34}
35
36$src = Join-Path $Temp "src"
37$out = Join-Path $Temp "build"
38if (-not (Test-Path (Join-Path $src "llvm\CMakeLists.txt"))) {
39 if (Test-Path $src) { Remove-Item -Recurse -Force $src }
40 New-Item -ItemType Directory -Force $Temp | Out-Null
41 & git clone --quiet --depth 1 --branch "llvmorg-$Version" --filter=blob:none --sparse https://github.com/llvm/llvm-project $src
42 if ($LASTEXITCODE -ne 0) { throw "git clone of llvmorg-$Version failed." }
43 & git -C $src sparse-checkout set llvm cmake third-party
44 if ($LASTEXITCODE -ne 0) { throw "git sparse-checkout failed." }
45}
46
47# DIA SDK off: its headers need ATL, which the C++ build tools don't always include, and llvm-mc doesn't use it.
48$body = @"
49"$cmake" -S "$src\llvm" -B "$out" -G Ninja "-DCMAKE_MAKE_PROGRAM=$ninja" -DCMAKE_BUILD_TYPE=Release ^
50 -DLLVM_TARGETS_TO_BUILD=AMDGPU -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded -DLLVM_ENABLE_DIA_SDK=OFF ^
51 -DLLVM_INCLUDE_TESTS=OFF -DLLVM_INCLUDE_BENCHMARKS=OFF -DLLVM_INCLUDE_EXAMPLES=OFF -DLLVM_INCLUDE_DOCS=OFF ^
52 -DLLVM_ENABLE_ZLIB=OFF -DLLVM_ENABLE_ZSTD=OFF -DLLVM_ENABLE_LIBXML2=OFF || exit /b 1
53"$cmake" --build "$out" --target llvm-mc -j $jobs || exit /b 1
54"@
55New-Item -ItemType Directory -Force $out | Out-Null
56# A .cmd file avoids cmd.exe's quote stripping on paths with spaces.
57$bat = Join-Path $Temp "_build.cmd"
58"@echo off`r`nset `"PATH=$installer;%PATH%`"`r`ncall `"$vcvars`" >nul || exit /b 1`r`n$body" | Set-Content -Encoding ascii $bat
59
60$p = Start-Process cmd.exe -ArgumentList "/c", "`"$bat`"" -NoNewWindow -PassThru
61$null = $p.Handle # keeps the exit code readable after WaitForExit
62try { $p.PriorityClass = "BelowNormal" } catch {}
63$p.WaitForExit()
64if ($p.ExitCode -ne 0) { throw "build failed ($($p.ExitCode)); the build folder is kept in $out" }
65
66# Same check shader_disasm.py makes before a run: one s_endpgm on the console's GPU.
67$exe = Join-Path $out "bin\llvm-mc.exe"
68# Through a file: a PowerShell pipe can prepend a BOM, which llvm-mc rejects as an invalid token.
69$probeFile = Join-Path $Temp "probe.txt"
70[IO.File]::WriteAllText($probeFile, "0x00 0x00 0x81 0xbf`n")
71$probe = & $exe --disassemble -triple=amdgcn -mcpu=gfx1013 $probeFile
72if ($LASTEXITCODE -ne 0 -or -not ($probe -match "s_endpgm")) { throw "the built llvm-mc didn't disassemble an s_endpgm" }
73
74New-Item -ItemType Directory -Force $Dest | Out-Null
75$final = Join-Path $Dest "llvm-mc.exe"
76Copy-Item -Force $exe $final
77if (-not $Keep) { Remove-Item -Recurse -Force $Temp }
78if (-not $NoEnv) {
79 [Environment]::SetEnvironmentVariable("LLVM_MC", $final, "User")
80 Write-Host "LLVM_MC set for this user (open a new terminal to pick it up)."
81}
82Write-Host "built $final"
diff --git a/scripts/build_runtime.ps1 b/scripts/build_runtime.ps1
index c5c8d760c..b480763cb 100644
--- a/scripts/build_runtime.ps1
+++ b/scripts/build_runtime.ps1
@@ -33,7 +33,10 @@ cd /d "$out" || exit /b 1
33cl /nologo /std:c++20 /EHsc /W4 /permissive- /utf-8 /Zi $opt /MP$jobs /DWIN32_LEAN_AND_MEAN /DNOMINMAX /DUNICODE /D_UNICODE $($files -join ' ') /Fe:gta6rt.exe /link /OPT:NOREF psapi.lib || exit /b 1 33cl /nologo /std:c++20 /EHsc /W4 /permissive- /utf-8 /Zi $opt /MP$jobs /DWIN32_LEAN_AND_MEAN /DNOMINMAX /DUNICODE /D_UNICODE $($files -join ' ') /Fe:gta6rt.exe /link /OPT:NOREF psapi.lib || exit /b 1
34cl /nologo /std:c++20 /EHsc /W4 /permissive- /utf-8 /O2 /DWIN32_LEAN_AND_MEAN /DNOMINMAX /I "$src\shims" "$src\shims\d3d12_xs_rootsig.cpp" "$src\shims\registry.cpp" "$src\shims\d3d12_xs.cpp" "$src\shims\d3d12_xs_device.cpp" "$src\test\root_sig_test.cpp" /Fe:root_sig_test.exe /link d3d12.lib || exit /b 1 34cl /nologo /std:c++20 /EHsc /W4 /permissive- /utf-8 /O2 /DWIN32_LEAN_AND_MEAN /DNOMINMAX /I "$src\shims" "$src\shims\d3d12_xs_rootsig.cpp" "$src\shims\registry.cpp" "$src\shims\d3d12_xs.cpp" "$src\shims\d3d12_xs_device.cpp" "$src\test\root_sig_test.cpp" /Fe:root_sig_test.exe /link d3d12.lib || exit /b 1
35cl /nologo /std:c++20 /EHsc /W4 /permissive- /utf-8 /O2 /DWIN32_LEAN_AND_MEAN /DNOMINMAX /I "$src\shims" "$src\shims\d3d12_xs_rootsig.cpp" "$src\shims\registry.cpp" "$src\shims\d3d12_xs.cpp" "$src\shims\d3d12_xs_device.cpp" "$src\test\device_proxy_test.cpp" /Fe:device_proxy_test.exe /link d3d12.lib dxgi.lib || exit /b 1 35cl /nologo /std:c++20 /EHsc /W4 /permissive- /utf-8 /O2 /DWIN32_LEAN_AND_MEAN /DNOMINMAX /I "$src\shims" "$src\shims\d3d12_xs_rootsig.cpp" "$src\shims\registry.cpp" "$src\shims\d3d12_xs.cpp" "$src\shims\d3d12_xs_device.cpp" "$src\test\device_proxy_test.cpp" /Fe:device_proxy_test.exe /link d3d12.lib dxgi.lib || exit /b 1
36cl /nologo /std:c++20 /EHsc /W4 /permissive- /utf-8 /O2 /DWIN32_LEAN_AND_MEAN /DNOMINMAX /I "$src\src" "$src\test\descriptor_table_test.cpp" /Fe:descriptor_table_test.exe /link /OPT:NOREF || exit /b 1
37cl /nologo /std:c++20 /EHsc /W4 /permissive- /utf-8 /O2 /DWIN32_LEAN_AND_MEAN /DNOMINMAX /I "$src\src" "$src\test\command_list_test.cpp" /Fe:command_list_test.exe /link /OPT:NOREF || exit /b 1
36if defined VULKAN_SDK cl /nologo /std:c++20 /EHsc /O2 /DWIN32_LEAN_AND_MEAN /DNOMINMAX /I "%VULKAN_SDK%\Include" "$src\test\vk_pipeline_check.cpp" /Fe:vk_pipeline_check.exe || exit /b 1 38if defined VULKAN_SDK cl /nologo /std:c++20 /EHsc /O2 /DWIN32_LEAN_AND_MEAN /DNOMINMAX /I "%VULKAN_SDK%\Include" "$src\test\vk_pipeline_check.cpp" /Fe:vk_pipeline_check.exe || exit /b 1
39if defined VULKAN_SDK cl /nologo /std:c++20 /EHsc /O2 /DWIN32_LEAN_AND_MEAN /DNOMINMAX /I "%VULKAN_SDK%\Include" /I "$src\src" "$src\test\vk_texture_test.cpp" /Fe:vk_texture_test.exe || exit /b 1
37"@ 40"@
38} 41}
39 42
diff --git a/scripts/run_gpu_tests.py b/scripts/run_gpu_tests.py
index 38047321c..edd5cad19 100644
--- a/scripts/run_gpu_tests.py
+++ b/scripts/run_gpu_tests.py
@@ -1,7 +1,9 @@
1"""Assemble, translate, and run the synthetic RDNA2->SPIR-V GPU test suite on Vulkan. 1"""Assemble, translate, and run the synthetic RDNA2->SPIR-V GPU test suite on Vulkan.
2 2
3Usage: 3Usage:
4 python -I scripts/run_gpu_tests.py [--llvm-mc PATH] [--build DIR] [--work DIR] [--filter SUBSTR] 4 python -I scripts/run_gpu_tests.py [--llvm-mc CMD] [--build DIR] [--work DIR] [--filter SUBSTR]
5
6--llvm-mc (or LLVM_MC) is a path or a whole command, e.g. "wsl -d Ubuntu -e /usr/lib/llvm-21/bin/llvm-mc".
5""" 7"""
6import argparse 8import argparse
7import json 9import json
@@ -16,6 +18,8 @@ import tempfile
16ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 18ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
17SHADER_DIR = os.path.join(ROOT, "runtime", "test", "shaders") 19SHADER_DIR = os.path.join(ROOT, "runtime", "test", "shaders")
18TRANSLATOR = os.path.join(ROOT, "tools", "rdna2spirv.py") 20TRANSLATOR = os.path.join(ROOT, "tools", "rdna2spirv.py")
21sys.path.insert(0, os.path.join(ROOT, "tools"))
22import mc_command # noqa: E402
19sys.path.insert(0, SHADER_DIR) 23sys.path.insert(0, SHADER_DIR)
20from compute_fixture import compute_header 24from compute_fixture import compute_header
21 25
@@ -61,7 +65,7 @@ def make_ms_psv0(threads_x: int, maxv: int, maxp: int, topology: int = 2) -> byt
61def assemble_to_s(llvm_mc: str, asm_path: str, s_path: str, name: str) -> None: 65def assemble_to_s(llvm_mc: str, asm_path: str, s_path: str, name: str) -> None:
62 """Assemble raw RDNA2 .asm with llvm-mc -show-encoding into .s format for rdna2spirv.py.""" 66 """Assemble raw RDNA2 .asm with llvm-mc -show-encoding into .s format for rdna2spirv.py."""
63 raw = open(asm_path, encoding="utf-8").read() 67 raw = open(asm_path, encoding="utf-8").read()
64 cmd = [llvm_mc, "-triple=amdgcn--amdpal", "-mcpu=gfx1013"] 68 cmd = mc_command.mc_command(llvm_mc) + ["-triple=amdgcn--amdpal", "-mcpu=gfx1013"]
65 for ln in raw.splitlines(): 69 for ln in raw.splitlines():
66 s = ln.strip() 70 s = ln.strip()
67 if not s: 71 if not s:
@@ -338,7 +342,8 @@ def check_clip_half(raw_path: str, want_b: float, want_a: float) -> tuple[bool,
338 342
339def main() -> int: 343def main() -> int:
340 ap = argparse.ArgumentParser() 344 ap = argparse.ArgumentParser()
341 ap.add_argument("--llvm-mc", default=os.environ.get("LLVM_MC", "llvm-mc")) 345 ap.add_argument("--llvm-mc", default=os.environ.get("LLVM_MC", "llvm-mc"),
346 help="llvm-mc path, or a whole command such as 'wsl -d Ubuntu -e /usr/lib/llvm-21/bin/llvm-mc'")
342 ap.add_argument("--build", default=os.path.join(ROOT, "runtime", "build")) 347 ap.add_argument("--build", default=os.path.join(ROOT, "runtime", "build"))
343 ap.add_argument("--work", default=None) 348 ap.add_argument("--work", default=None)
344 ap.add_argument("--filter", default="") 349 ap.add_argument("--filter", default="")
@@ -372,9 +377,13 @@ def run_suite(a, work: str) -> int:
372 asm_files = sorted(f for f in os.listdir(SHADER_DIR) if f.endswith(".asm")) 377 asm_files = sorted(f for f in os.listdir(SHADER_DIR) if f.endswith(".asm"))
373 if a.filter: 378 if a.filter:
374 asm_files = [f for f in asm_files if a.filter in f] 379 asm_files = [f for f in asm_files if a.filter in f]
380 # Shaders a selected test draws with are built even when the filter leaves them out (#192): ps_flat uses vs_ids.
381 build_files = list(asm_files)
382 if any(f.startswith("ps_flat") for f in asm_files) and "vs_ids.asm" not in build_files:
383 build_files.append("vs_ids.asm")
375 384
376 # 1. Create synthetic DXBC / FSSM metadata + assemble .asm -> .s 385 # 1. Create synthetic DXBC / FSSM metadata + assemble .asm -> .s
377 for fname in asm_files: 386 for fname in build_files:
378 name = os.path.splitext(fname)[0] 387 name = os.path.splitext(fname)[0]
379 if name == "gs_tri": 388 if name == "gs_tri":
380 dxbc = make_dxbc([ 389 dxbc = make_dxbc([
@@ -461,12 +470,15 @@ def run_suite(a, work: str) -> int:
461 results.append((name, False, "64-wide subgroup was not confirmed (rebuild vk_compute_test)")) 470 results.append((name, False, "64-wide subgroup was not confirmed (rebuild vk_compute_test)"))
462 else: 471 else:
463 results.append((name, rc == 0, msg.splitlines()[-1] if msg else "")) 472 results.append((name, rc == 0, msg.splitlines()[-1] if msg else ""))
464 elif name in ("cs_store", "cs_wave64_ballot", "cs_wm_half_ops", "cs_wm_half_cmp", "cs_wm_bfm64", "cs_wm_scc_rfl", 473 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",
465 "cs_w64x_readlane", "cs_w64x_writelane", "cs_w64x_readfirstlane", "cs_w64x_bpermute", 474 "cs_w64x_readlane", "cs_w64x_writelane", "cs_w64x_readfirstlane", "cs_w64x_bpermute",
466 "cs_w64x_branch", "cs_w64x_ballot", "cs_w64x_wg128_branches", "cs_w64x_lds_raw", 475 "cs_w64x_branch", "cs_w64x_ballot", "cs_w64x_wg128_branches", "cs_w64x_lds_raw",
467 "cs_w64x_lds_war", "cs_w64x_partial", "cs_w64x_sbarrier", "cs_w64x_load_ballot_load"): 476 "cs_w64x_lds_war", "cs_w64x_partial", "cs_w64x_sbarrier", "cs_w64x_load_ballot_load"):
468 cs_dump_wants = { 477 cs_dump_wants = {
469 "cs_store": [0x400080FF, 0xE00003FF, 0x3C004000, 0xEEEEEEEE, 0x40003C00, 0xBC003800], 478 "cs_store": [0x400080FF, 0xE00003FF, 0x3C004000, 0xEEEEEEEE, 0x40003C00, 0xBC003800],
479 # base + soffset + imm (cs_smem_soffset_imm.asm); out[4..7] are seeds the shader leaves alone
480 "cs_smem_soffset_imm": [0x5EED0024, 0x5EED0028, 0x5EED002C, 0x5EED0030,
481 0x5EED0010, 0x5EED0014, 0x5EED0018, 0x5EED001C],
470 "cs_wave64_ballot": [32, 16, 24, 40, 8, 48], 482 "cs_wave64_ballot": [32, 16, 24, 40, 8, 48],
471 "cs_wm_half_ops": [32, 16, 16, 0, 16], 483 "cs_wm_half_ops": [32, 16, 16, 0, 16],
472 "cs_wm_half_cmp": [1, 0, 1, 1], 484 "cs_wm_half_cmp": [1, 0, 1, 1],
@@ -487,13 +499,13 @@ def run_suite(a, work: str) -> int:
487 "cs_w64x_load_ballot_load": [43, 74, 75, 42, 42, 18, 41, 32], 499 "cs_w64x_load_ballot_load": [43, 74, 75, 42, 42, 18, 41, 32],
488 } 500 }
489 want = cs_dump_wants[name] 501 want = cs_dump_wants[name]
490 # Every dump but cs_store is a whole-wave (wave64) mask test: ask for a 64-wide subgroup and skip, as 502 # 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
491 # check.py does, where the device has none (vk_compute_test exits 77) instead of reporting a failure. 503 # check.py does, where the device has none (vk_compute_test exits 77) instead of reporting a failure.
492 # With LEONIDA_W64_EMULATE=1 they were translated with --wave64-emulate and run on any subgroup size. 504 # With LEONIDA_W64_EMULATE=1 they were translated with --wave64-emulate and run on any subgroup size.
493 # cs_w64x_partial (a 40-thread group) can't have full subgroups: it asks for size 64 without them. 505 # cs_w64x_partial (a 40-thread group) can't have full subgroups: it asks for size 64 without them.
494 emulated = os.environ.get("LEONIDA_W64_EMULATE") == "1" 506 emulated = os.environ.get("LEONIDA_W64_EMULATE") == "1"
495 partial = name == "cs_w64x_partial" 507 partial = name == "cs_w64x_partial"
496 wave64 = name != "cs_store" and not emulated and not partial 508 wave64 = name not in ("cs_store", "cs_smem_soffset_imm") and not emulated and not partial
497 if partial and not emulated: 509 if partial and not emulated:
498 cs_env = dict(os.environ, VKC_SUBGROUP_SIZE="64") 510 cs_env = dict(os.environ, VKC_SUBGROUP_SIZE="64")
499 rc, msg = run_cmd([vk_compute, spv, "1", "dump"] + (["--require-wave64"] if wave64 else []), env=cs_env) 511 rc, msg = run_cmd([vk_compute, spv, "1", "dump"] + (["--require-wave64"] if wave64 else []), env=cs_env)
@@ -504,7 +516,7 @@ def run_suite(a, work: str) -> int:
504 elif rc == 0 and dump_line: 516 elif rc == 0 and dump_line:
505 vals = [int(x) for x in dump_line.split("=")[1].split()[:len(want)]] 517 vals = [int(x) for x in dump_line.split("=")[1].split()[:len(want)]]
506 ok = vals == want 518 ok = vals == want
507 fmt = hex if name == "cs_store" else str 519 fmt = hex if name in ("cs_store", "cs_smem_soffset_imm") else str
508 results.append((name, ok, " ".join(fmt(x) for x in vals))) 520 results.append((name, ok, " ".join(fmt(x) for x in vals)))
509 else: 521 else:
510 results.append((name, False, msg)) 522 results.append((name, False, msg))