diff options
Diffstat (limited to 'tools/shader_disasm.py')
| -rw-r--r-- | tools/shader_disasm.py | 26 |
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 | """ |
| 14 | import argparse | 14 | import argparse |
| 15 | import os | 15 | import os |
| 16 | import shlex | ||
| 17 | import struct | 16 | import struct |
| 18 | import subprocess | 17 | import subprocess |
| 19 | import sys | 18 | import sys |
| 20 | from concurrent.futures import ThreadPoolExecutor | 19 | from concurrent.futures import ThreadPoolExecutor |
| 21 | 20 | ||
| 21 | sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) | ||
| 22 | from mc_command import mc_command # noqa: E402 | ||
| 23 | |||
| 22 | TRIPLE = "amdgcn--amdpal" | 24 | TRIPLE = "amdgcn--amdpal" |
| 23 | ENDPGM = b"\x00\x00\x81\xbf" | 25 | ENDPGM = b"\x00\x00\x81\xbf" |
| 24 | PROBE = "0x00 0x00 0x81 0xbf" # s_endpgm: the one instruction every shader ends with | 26 | PROBE = "0x00 0x00 0x81 0xbf" # s_endpgm: the one instruction every shader ends with |
| 25 | FAILED = [] # (path, first stderr line) for shaders that produced no disassembly | 27 | FAILED = [] # (path, first stderr line) for shaders that produced no disassembly |
| 26 | 28 | ||
| 27 | 29 | ||
| 28 | def 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 | |||
| 36 | def 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 | |||
| 44 | MC = mc_command() | 30 | MC = 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 | ||