Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,19 @@ Your game folder is the one that holds `MicrosoftGame.Config` and the `.rpf` arc
- [Python 3.12+](https://www.python.org/downloads/) (tick "Add python.exe to PATH").
- [.NET 8 SDK](https://dotnet.microsoft.com/download/dotnet/8.0).
- [Vulkan SDK](https://vulkan.lunarg.com/), for `spirv-as` / `spirv-val`.
- [LLVM 21+](https://github.com/llvm/llvm-project/releases) with the **AMDGPU target** for `llvm-mc`. The official
- [LLVM 23+](https://github.com/llvm/llvm-project/releases) with the **AMDGPU target** for `llvm-mc`. LLVM 21
translates all 26,503 shaders of `shaders.rpf`, but 840 of the 2,684 pipeline-library compute programs come out of
its listings with 79,490 undecodable words and the translator refuses them, so the `shaders` stage keeps 1,844 of
2,684; LLVM 23.1.5 decodes those 840 cleanly and the stage translates 2,683 of 2,684. The official
Windows build has no AMDGPU target. On Windows, `scripts\build_llvm_mc.ps1` builds a native `llvm-mc.exe` with it
(no WSL; needs git and the Visual Studio C++ tools below) and sets `LLVM_MC`; it takes about 20-40 minutes. A faster
way, if you use [conda](https://docs.conda.io/): `conda install -c conda-forge llvm-tools` (its Windows build
includes the AMDGPU target; [docs/testing.md](docs/testing.md) used version 23.1.6), then set `LLVM_MC` to the full
path of the `llvm-mc.exe` it installs (`where.exe llvm-mc` shows it once the environment is active; in PowerShell a
bare `where` is `Where-Object`). Or install `llvm-21`
in WSL and set `LLVM_MC` to the whole command, `LLVM_MC="wsl -d Ubuntu -e /usr/lib/llvm-21/bin/llvm-mc"` (see
(LLVM 23.1.5 by default; no WSL; needs git and the Visual Studio C++ tools below) and sets `LLVM_MC`; it takes about
20-40 minutes. A faster way, if you use [conda](https://docs.conda.io/): `conda install -c conda-forge llvm-tools`
(its Windows build includes the AMDGPU target; [docs/testing.md](docs/testing.md) used version 23.1.6), then set
`LLVM_MC` to the full path of the `llvm-mc.exe` it installs (`where.exe llvm-mc` shows it once the environment is
active; in PowerShell a bare `where` is `Where-Object`). Or install `llvm-23`
in WSL and set `LLVM_MC` to the whole command, `LLVM_MC="wsl -d Ubuntu -e /usr/lib/llvm-23/bin/llvm-mc"` (see
[docs/design.md](docs/design.md#disassembling-shaders)). On Linux, `llvm-mc` on PATH is enough, and so is a
versioned distribution install such as Ubuntu's `llvm-21` (`llvm-mc-21`, `/usr/lib/llvm-21/bin/llvm-mc`).
versioned distribution install such as Ubuntu's `llvm-23` (`llvm-mc-23`, `/usr/lib/llvm-23/bin/llvm-mc`).
- Visual Studio 2022 with **Desktop development with C++** and the **Windows SDK 10.0.26100 or newer**, for the
runtime stage (the runtime uses version 1.2 root signatures, which older SDKs don't declare).
- [ffmpeg](https://ffmpeg.org/download.html) on PATH (optional: decodes the XMA2 streams, and required for `--wav`).
Expand Down
21 changes: 16 additions & 5 deletions docs/design.md
Original file line number Diff line number Diff line change
Expand Up @@ -589,10 +589,21 @@ cross-half code on 32-wide subgroups.

## Disassembling shaders

The AMDGPU disassembler needs LLVM 21+ built with the AMDGPU target (`llvm-mc`; on Linux the `llvm-21` package
installs it at `/usr/lib/llvm-21/bin/llvm-mc`). The official Windows LLVM build has no AMDGPU target and ships no
The AMDGPU disassembler needs LLVM 23+ built with the AMDGPU target (`llvm-mc`; on Linux the `llvm-23` package
installs it at `/usr/lib/llvm-23/bin/llvm-mc`). The official Windows LLVM build has no AMDGPU target and ships no
`llvm-mc.exe`. On Windows, either build a native one or run it from WSL.

23+ is the requirement because of the pipeline library: LLVM 21.1.8 decodes all 26,503 shaders of `shaders.rpf`, but
840 of the 2,684 compute programs there come out of its listings with 79,490 undecodable words and 8,310
`exp invalid_target_N` words, so the translator refuses them as `fall-through into undecodable words` and the stage
ends at 1,844 of 2,684.
Under LLVM 23.1.5 those 840 have no undecodable word, and the stage translates 2,683 of the 2,684 and passes
`spirv-val`; the 2,684th is refused for `s_sethalt`, which the translator does not implement, under either version.
1,674 of the 1,844 that already translated print differently under 23.1.5, because LLVM prints some operands
differently; re-translated from those listings all 1,674 pass, and the other 170 listings are byte-identical
(`-mcpu=gfx1013`, `--stages cs`, 1.0.2.1). `scripts/build_llvm_mc.ps1` builds 23.1.5 by default for this reason; keep
`LLVM_MC` on 23+ for the `shaders` stage.

Native: `scripts\build_llvm_mc.ps1` fetches the LLVM sources the tool needs (sparse, shallow), builds `llvm-mc` alone
with `LLVM_TARGETS_TO_BUILD=AMDGPU`, static CRT and the DIA SDK off (its headers need ATL, which the C++ build tools
don't always include), checks it disassembles an `s_endpgm` for `gfx1013`, keeps only `llvm-mc.exe` (by default in
Expand All @@ -608,10 +619,10 @@ powershell -ExecutionPolicy Bypass -File scripts\build_llvm_mc.ps1
python -I make_game.py --game "D:\path\to\your\package" --stages shaders
```

WSL: install `llvm-21` and give `LLVM_MC` the whole command:
WSL: install `llvm-23` and give `LLVM_MC` the whole command:

```
set LLVM_MC=wsl -d Ubuntu -e /usr/lib/llvm-21/bin/llvm-mc
set LLVM_MC=wsl -d Ubuntu -e /usr/lib/llvm-23/bin/llvm-mc
python -I make_game.py --game "D:\path\to\your\package" --stages shaders
```

Expand All @@ -623,7 +634,7 @@ on stdin, so a WSL command never receives a Windows file path.
with that reason instead of writing empty `.s` files. To disassemble by hand inside WSL:

```
LLVM_MC=/usr/lib/llvm-21/bin/llvm-mc python3 -I <repo>/tools/shader_disasm.py <work>/shaders/fssm
LLVM_MC=/usr/lib/llvm-23/bin/llvm-mc python3 -I <repo>/tools/shader_disasm.py <work>/shaders/fssm
```

Code starts at the u32 at FSSM offset 0xC0 (the code-section offset) plus 0x28 bytes into that section, and ends at the
Expand Down
7 changes: 5 additions & 2 deletions docs/linux.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,12 @@ default stages leave `runtime` out (`check,shaders,assets,pipelines`).

Notes:

- **llvm-mc**: Debian and Ubuntu's `llvm-21` installs it only as `llvm-mc-21` and `/usr/lib/llvm-21/bin/llvm-mc`.
- **llvm-mc**: the `shaders` stage needs LLVM 23 or newer, so install `llvm-23` where the distribution has it. Debian and Ubuntu's `llvm-21` installs `llvm-mc` only as `llvm-mc-21` and `/usr/lib/llvm-21/bin/llvm-mc`.
With `LLVM_MC` unset the tools use the plain `llvm-mc` when it is on `PATH` and otherwise the newest of those
versioned names (`tools/mc_command.py`). Set `LLVM_MC` to choose another one.
versioned names (`tools/mc_command.py`). Set `LLVM_MC` to choose another one. The `shaders` stage needs LLVM 23+
for its pipeline library: 21.1.8's listings of 840 of its 2,684 compute programs carry 79,490 undecodable words and
the translator refuses them, while 23.1.5 leaves none in those 840 and the stage translates 2,683 of 2,684
([design.md](design.md#disassembling-shaders)).
- **File names are case-sensitive.** The build opens the package's files by their exact names
(`MicrosoftGame.Config`, `Catalog000.bin`, ...). A copy whose names changed case on the way is reported with the
name it found and the one it needs; nothing is renamed for you.
Expand Down
9 changes: 8 additions & 1 deletion docs/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ This page collects the setup steps and the problems testers have run into so far

- **Python 3.12+**, which `make_game.py` requires (it stops with "Python 3.12 or newer is needed" on an older one, so
its tests fail there too). `scripts/run_gpu_tests.py` on its own runs on 3.10 or newer.
- **`llvm-mc` with the AMDGPU target** (LLVM 21+). The official LLVM Windows release has no AMDGPU target. On
- **`llvm-mc` with the AMDGPU target** (LLVM 21+ to assemble the test fixtures, 23+ for the `shaders` stage; see below). The official LLVM Windows release has no AMDGPU target. On
Windows, use one of:
- `scripts\build_llvm_mc.ps1`, which builds a native `llvm-mc.exe` (needs git and the Visual Studio C++ tools);
- conda-forge's `llvm-tools` package, whose Windows build includes the AMDGPU target;
Expand Down Expand Up @@ -45,6 +45,13 @@ This page collects the setup steps and the problems testers have run into so far

If it reports `not a valid operand`, point `LLVM_MC` at a build that accepts this instruction. The Windows
conda-forge `llvm-tools` 23.1.6 package assembled the same f16 programs.

The `shaders` stage needs LLVM 23+ as well, for reasons that have nothing to do with the tests above: 840 of the
2,684 compute programs in the pipeline library come out of LLVM 21.1.8's listings with 79,490 undecodable words, so
the translator refuses them (`fall-through into undecodable words`) and 1,844 of 2,684 reach the output. 23.1.5
decodes those 840 with no rejected word and the stage translates 2,683 of 2,684 (the last is refused for
`s_sethalt`, which the translator does not implement); `scripts\build_llvm_mc.ps1` builds 23.1.5 by default
([design.md](design.md), "Disassembling shaders").
- **SPIRV-Tools** (`spirv-as`, `spirv-val`): part of the Vulkan SDK, or a distribution package.
- **A C++20 compiler, CMake and the Vulkan headers** to build the test programs:
- Windows: the full runtime needs Visual Studio 2022 with "Desktop development with C++" and Windows SDK
Expand Down
2 changes: 1 addition & 1 deletion make_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,7 @@ def preflight(stages: list, work: str, wav: bool = False, runtime_build: str | N
if "shaders" in stages:
mc = mc_command()[0]
if not (os.path.isfile(mc) or shutil.which(mc)):
missing.append("llvm-mc (LLVM 21+ with the AMDGPU target). " + mc_install_hint().replace("\n", " ")
missing.append("llvm-mc (LLVM 23+ with the AMDGPU target). " + mc_install_hint().replace("\n", " ")
+ " (docs/design.md)." + appdata_hint(mc))
for t in ("spirv-as", "spirv-val"):
if not shutil.which(t):
Expand Down
8 changes: 7 additions & 1 deletion scripts/build_llvm_mc.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@
# powershell -ExecutionPolicy Bypass -File scripts\build_llvm_mc.ps1
# powershell -ExecutionPolicy Bypass -File scripts\build_llvm_mc.ps1 -Dest D:\tools\llvm-mc -NoEnv
#
# -Version defaults to 23.1.5, the release the shader corpus was measured with. LLVM 21.1.8's gfx1013 decoder
# cannot decode 840 of the 2,684 pipeline-library compute programs: their listings carry 79,490 undecodable words and
# the translator refuses them ("fall-through into undecodable words"), which leaves the shaders stage at 1,844 of
# 2,684. llvm-mc 23.1.5 disassembles those 840 with no rejected word, and the stage then translates 2,683 of 2,684
# (the last wants s_sethalt, which the translator does not implement). docs/design.md, "Disassembling shaders".
#
# The default -Dest is outside AppData on purpose: `python` from the Python install manager (the app execution alias
# in WindowsApps) doesn't see folders that other programs create under %LOCALAPPDATA% or %APPDATA%, so an llvm-mc.exe
# there looks missing to make_game.py and the tools, although LLVM_MC names it.
param(
[string]$Version = "21.1.8",
[string]$Version = "23.1.5",
[string]$Dest = (Join-Path $env:USERPROFILE ".leonida\llvm-mc"),
[string]$Temp = (Join-Path $env:TEMP "leonida-llvm-mc"),
[switch]$NoEnv, # don't set LLVM_MC for the current user
Expand Down
11 changes: 11 additions & 0 deletions tests/test_llvm_source_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@
SCRIPT = Path(__file__).resolve().parents[1] / "scripts" / "build_llvm_mc.ps1"


class DefaultVersionTest(unittest.TestCase):
"""The version the script builds when the caller names none: LLVM 23 for
the `shaders` stage (1844 of 2684 compute programs do not disassemble with
21's listings), so an accidental revert to 21 fails here instead of
silently in a translation run."""

def test_the_default_source_version_is_23(self):
text = SCRIPT.read_text(encoding="utf-8")
self.assertIn('[string]$Version = "23.1.5"', text)


@unittest.skipUnless(os.name == "nt" and shutil.which("git"), "Windows and Git required")
class SourceVersionTest(unittest.TestCase):
def setUp(self):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_make_game_pipeline_preflight.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def test_missing_checker_is_listed_with_other_missing_prerequisites(self):
mock.patch("shutil.which", side_effect=lambda t: None if t == "llvm-mc" else "/bin/tool"), \
mock.patch.object(make_game, "pipeline_check_exe", return_value=None):
err = self.assert_preflight_fails(["shaders", "pipelines"], "vk_pipeline_check")
self.assertIn("llvm-mc (LLVM 21+ with the AMDGPU target)", err)
self.assertIn("llvm-mc (LLVM 23+ with the AMDGPU target)", err)
self.assertEqual(err.count("vk_pipeline_check"), 1)


Expand Down
4 changes: 2 additions & 2 deletions tests/test_make_game_preflight.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ def test_preflight_aggregates_multiple_missing_tools_and_deduplicates(self):
err = self.assert_fails(make_game.preflight, ["shaders", "assets", "runtime"], tmp_work, wav=True,
match="Install these first, then run the build again:")
self.assertIn("ffmpeg (needed for --wav)", err)
self.assertIn("llvm-mc (LLVM 21+ with the AMDGPU target)", err)
self.assertIn("llvm-mc (LLVM 23+ with the AMDGPU target)", err)
self.assertIn("spirv-as:", err)
self.assertIn("spirv-val:", err)
self.assertIn(".NET 8 SDK", err)
Expand All @@ -578,7 +578,7 @@ def test_preflight_explains_llvm_mc_hidden_in_appdata(self):
mock.patch("shutil.which", side_effect=available.get), \
mock.patch("os.path.isfile", return_value=False):
err = self.assert_fails(make_game.preflight, ["shaders"], tmp_work,
match="llvm-mc (LLVM 21+ with the AMDGPU target)")
match="llvm-mc (LLVM 23+ with the AMDGPU target)")
self.assertIn("LLVM_MC points into %LOCALAPPDATA%", err)

def test_preflight_rejects_visual_studio_installer_without_cpp_tools(self):
Expand Down
6 changes: 3 additions & 3 deletions tests/test_mc_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Windows runs llvm-mc through WSL (the official Windows LLVM build has no AMDGPU target):

set LLVM_MC=wsl -d Ubuntu -e /usr/lib/llvm-21/bin/llvm-mc
set LLVM_MC=wsl -d Ubuntu -e /usr/lib/llvm-23/bin/llvm-mc

python -I tests/test_mc_command.py
"""
Expand Down Expand Up @@ -198,7 +198,7 @@ def test_llvm_mc_set_wins(self):
def test_the_message_names_the_distribution_package_off_windows(self):
with mock.patch.object(mc_command.sys, "platform", "linux"):
message = mc_command.not_found("llvm-mc", FileNotFoundError(2, "No such file"))
self.assertIn("apt install llvm-21", message)
self.assertIn("apt install llvm-23", message)
self.assertNotIn("build_llvm_mc.ps1", message)


Expand Down Expand Up @@ -230,7 +230,7 @@ def test_windows_keeps_the_build_script_and_wsl_advice(self):
with mock.patch.object(mc_command.os, "name", "nt"):
hint = mc_command.install_hint()
self.assertIn("build_llvm_mc.ps1", hint)
self.assertIn("LLVM_MC=wsl -d Ubuntu -e /usr/lib/llvm-21/bin/llvm-mc", hint)
self.assertIn("LLVM_MC=wsl -d Ubuntu -e /usr/lib/llvm-23/bin/llvm-mc", hint)

def test_run_names_the_tools_own_option(self):
with self.assertRaises(SystemExit) as cm:
Expand Down
14 changes: 7 additions & 7 deletions tools/mc_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
needs the command-line form when llvm-mc runs inside WSL, because the official Windows LLVM build has no AMDGPU
target:

set LLVM_MC=wsl -d Ubuntu -e /usr/lib/llvm-21/bin/llvm-mc
set LLVM_MC=wsl -d Ubuntu -e /usr/lib/llvm-23/bin/llvm-mc

On Windows, arguments follow the MSVC C runtime's quoting rules. Double a trailing backslash in a quoted
argument before the closing quote.
Expand Down Expand Up @@ -116,7 +116,7 @@ def default_command() -> str:


def mc_command(raw: str | None = None) -> list:
"""LLVM_MC is a path, or a command line: 'wsl -d Ubuntu -e /usr/lib/llvm-21/bin/llvm-mc'. Unset or empty,
"""LLVM_MC is a path, or a command line: 'wsl -d Ubuntu -e /usr/lib/llvm-23/bin/llvm-mc'. Unset or empty,
default_command()."""
if raw is None:
raw = os.environ.get("LLVM_MC", "")
Expand All @@ -127,14 +127,14 @@ def install_hint() -> str:
"""Where to get an llvm-mc with the AMDGPU target on this OS, for the messages that report a missing one."""
if os.name == "nt":
return ("The official Windows LLVM build has no AMDGPU target: build a native one with "
"scripts\\build_llvm_mc.ps1 (it sets LLVM_MC), or install llvm-21 in WSL and set LLVM_MC to the "
"whole command, e.g.\n LLVM_MC=wsl -d Ubuntu -e /usr/lib/llvm-21/bin/llvm-mc")
"scripts\\build_llvm_mc.ps1 (it sets LLVM_MC), or install llvm-23 in WSL and set LLVM_MC to the "
"whole command, e.g.\n LLVM_MC=wsl -d Ubuntu -e /usr/lib/llvm-23/bin/llvm-mc")
if sys.platform == "darwin":
return ("Homebrew's llvm has the AMDGPU target but is keg-only (not on PATH): brew install llvm, then\n"
" LLVM_MC=\"$(brew --prefix llvm)/bin/llvm-mc\"")
return ("Distribution LLVM packages include the AMDGPU target: on Debian or Ubuntu, sudo apt install llvm-21\n"
"(found as /usr/lib/llvm-21/bin/llvm-mc without further setup); elsewhere install your distribution's\n"
"LLVM 21+ package and put llvm-mc on PATH, or set LLVM_MC=/path/to/llvm-mc")
return ("Distribution LLVM packages include the AMDGPU target: on Debian or Ubuntu, sudo apt install llvm-23\n"
"(found as /usr/lib/llvm-23/bin/llvm-mc without further setup); elsewhere install your distribution's\n"
"LLVM 23+ package and put llvm-mc on PATH, or set LLVM_MC=/path/to/llvm-mc")


def not_found(exe: str, error: OSError, flag: str | None = None) -> str:
Expand Down
2 changes: 1 addition & 1 deletion tools/shader_disasm.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def probe(mcpu: str) -> None:
if p.returncode != 0 or "s_endpgm" not in p.stdout:
why = (p.stderr.strip().splitlines() or [f"exit code {p.returncode}"])[0]
fail(f"'{' '.join(MC)}' did not disassemble an s_endpgm: {why}\n"
f"The disassembler needs LLVM 21+ with the AMDGPU target (docs/design.md, 'Disassembling shaders').\n"
f"The disassembler needs LLVM 23+ with the AMDGPU target (LLVM 21 cannot decode some pipeline-library compute programs; docs/design.md, 'Disassembling shaders').\n"
f"{install_hint()}")


Expand Down
Loading