diff --git a/README.md b/README.md index 0860ff63f3..42aba29e31 100644 --- a/README.md +++ b/README.md @@ -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`). diff --git a/docs/design.md b/docs/design.md index 7bff52e7f9..1153e21a17 100644 --- a/docs/design.md +++ b/docs/design.md @@ -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 @@ -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 ``` @@ -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 /tools/shader_disasm.py /shaders/fssm +LLVM_MC=/usr/lib/llvm-23/bin/llvm-mc python3 -I /tools/shader_disasm.py /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 diff --git a/docs/linux.md b/docs/linux.md index c9ea03b84c..ff1001c718 100644 --- a/docs/linux.md +++ b/docs/linux.md @@ -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. diff --git a/docs/testing.md b/docs/testing.md index 671c5548c9..f88f553659 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -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; @@ -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 diff --git a/make_game.py b/make_game.py index f1af5a172d..0c7badfe37 100644 --- a/make_game.py +++ b/make_game.py @@ -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): diff --git a/scripts/build_llvm_mc.ps1 b/scripts/build_llvm_mc.ps1 index acaa4718e7..781cfa6e93 100644 --- a/scripts/build_llvm_mc.ps1 +++ b/scripts/build_llvm_mc.ps1 @@ -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 diff --git a/tests/test_llvm_source_version.py b/tests/test_llvm_source_version.py index c68fc81604..64c35d8660 100644 --- a/tests/test_llvm_source_version.py +++ b/tests/test_llvm_source_version.py @@ -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): diff --git a/tests/test_make_game_pipeline_preflight.py b/tests/test_make_game_pipeline_preflight.py index 227f52bbcf..390e61a0d5 100644 --- a/tests/test_make_game_pipeline_preflight.py +++ b/tests/test_make_game_pipeline_preflight.py @@ -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) diff --git a/tests/test_make_game_preflight.py b/tests/test_make_game_preflight.py index 8c816a09f3..159e7e409d 100644 --- a/tests/test_make_game_preflight.py +++ b/tests/test_make_game_preflight.py @@ -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) @@ -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): diff --git a/tests/test_mc_command.py b/tests/test_mc_command.py index d3baf56826..bcc3fc3178 100644 --- a/tests/test_mc_command.py +++ b/tests/test_mc_command.py @@ -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 """ @@ -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) @@ -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: diff --git a/tools/mc_command.py b/tools/mc_command.py index 762008d7ad..17fde84376 100644 --- a/tools/mc_command.py +++ b/tools/mc_command.py @@ -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. @@ -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", "") @@ -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: diff --git a/tools/shader_disasm.py b/tools/shader_disasm.py index a81ae1871f..b3cd50a2c1 100644 --- a/tools/shader_disasm.py +++ b/tools/shader_disasm.py @@ -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()}")