upleb.uk

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

summaryrefslogtreecommitdiff
path: root/tools/shader_disasm.py
diff options
context:
space:
mode:
Diffstat (limited to 'tools/shader_disasm.py')
-rw-r--r--tools/shader_disasm.py26
1 files changed, 7 insertions, 19 deletions
diff --git a/tools/shader_disasm.py b/tools/shader_disasm.py
index 942d44dac..5923ee66c 100644
--- a/tools/shader_disasm.py
+++ b/tools/shader_disasm.py
@@ -13,34 +13,20 @@ Set LLVM_MC to llvm-mc's path, or to a whole command such as
13""" 13"""
14import argparse 14import argparse
15import os 15import os
16import shlex
17import struct 16import struct
18import subprocess 17import subprocess
19import sys 18import sys
20from concurrent.futures import ThreadPoolExecutor 19from concurrent.futures import ThreadPoolExecutor
21 20
21sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
22from mc_command import mc_command # noqa: E402
23
22TRIPLE = "amdgcn--amdpal" 24TRIPLE = "amdgcn--amdpal"
23ENDPGM = b"\x00\x00\x81\xbf" 25ENDPGM = b"\x00\x00\x81\xbf"
24PROBE = "0x00 0x00 0x81 0xbf" # s_endpgm: the one instruction every shader ends with 26PROBE = "0x00 0x00 0x81 0xbf" # s_endpgm: the one instruction every shader ends with
25FAILED = [] # (path, first stderr line) for shaders that produced no disassembly 27FAILED = [] # (path, first stderr line) for shaders that produced no disassembly
26 28
27 29
28def split_command(raw: str) -> list:
29 """Split LLVM_MC without eating the backslashes of a Windows path (POSIX shlex would)."""
30 if os.name != "nt":
31 return shlex.split(raw)
32 parts = shlex.split(raw, posix=False)
33 return [p[1:-1] if len(p) > 1 and p[0] == p[-1] == '"' else p for p in parts]
34
35
36def mc_command() -> list:
37 """LLVM_MC is a path, or a command line: 'wsl -d Ubuntu -e /usr/lib/llvm-21/bin/llvm-mc'."""
38 raw = os.environ.get("LLVM_MC", "llvm-mc").strip()
39 if os.path.isfile(raw):
40 return [raw] # a plain path, spaces and all
41 return split_command(raw) or ["llvm-mc"]
42
43
44MC = mc_command() 30MC = mc_command()
45 31
46 32
@@ -56,13 +42,15 @@ def probe(mcpu: str) -> None:
56 input=PROBE, capture_output=True, text=True, 42 input=PROBE, capture_output=True, text=True,
57 creationflags=getattr(subprocess, "BELOW_NORMAL_PRIORITY_CLASS", 0)) 43 creationflags=getattr(subprocess, "BELOW_NORMAL_PRIORITY_CLASS", 0))
58 except OSError as e: 44 except OSError as e:
59 fail(f"'{MC[0]}' could not be started: {e}. Put llvm-mc on PATH or set LLVM_MC to it, e.g.\n" 45 fail(f"'{MC[0]}' could not be started: {e}. Put llvm-mc on PATH or set LLVM_MC to it (on Windows,\n"
46 f"scripts\\build_llvm_mc.ps1 builds one and sets it), e.g.\n"
60 f" LLVM_MC=wsl -d Ubuntu -e /usr/lib/llvm-21/bin/llvm-mc") 47 f" LLVM_MC=wsl -d Ubuntu -e /usr/lib/llvm-21/bin/llvm-mc")
61 if p.returncode != 0 or "s_endpgm" not in p.stdout: 48 if p.returncode != 0 or "s_endpgm" not in p.stdout:
62 why = (p.stderr.strip().splitlines() or [f"exit code {p.returncode}"])[0] 49 why = (p.stderr.strip().splitlines() or [f"exit code {p.returncode}"])[0]
63 fail(f"'{' '.join(MC)}' did not disassemble an s_endpgm: {why}\n" 50 fail(f"'{' '.join(MC)}' did not disassemble an s_endpgm: {why}\n"
64 f"The disassembler needs LLVM 21+ with the AMDGPU target. The official Windows LLVM build has no\n" 51 f"The disassembler needs LLVM 21+ with the AMDGPU target. The official Windows LLVM build has no\n"
65 f"AMDGPU target; run it from WSL instead (docs/design.md, 'Disassembling shaders'), e.g.\n" 52 f"AMDGPU target: build a native one with scripts\\build_llvm_mc.ps1, or run it from WSL\n"
53 f"(docs/design.md, 'Disassembling shaders'), e.g.\n"
66 f" LLVM_MC=wsl -d Ubuntu -e /usr/lib/llvm-21/bin/llvm-mc") 54 f" LLVM_MC=wsl -d Ubuntu -e /usr/lib/llvm-21/bin/llvm-mc")
67 55
68 56