diff options
| author | Aslan2142 <jan.trencansky@protonmail.com> | 2026-11-26 15:41:00 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-11-26 15:41:00 +0100 |
| commit | fbf100b1b10e391625585fe6a8bf4e653662ca9a (patch) | |
| tree | 497fe3bc8ef8b45d1ac8c68fa9f85196d08f11ad /scripts | |
| parent | 73516a2902a9872e4d21d1bdbbde4e26059497c5 (diff) | |
| parent | 484b21262a21f9a99148b89ad2458b389faf7bd1 (diff) | |
Merge pull request #2350 from aslan2142/linux-amd-world
Self-merge by a maintainer, on purpose: current main does not get through the world on Linux/AMD, and this brings the regression fixes (the single-wave round-loop fallback of 9f98dcc61, the wave64 choice driven by llvmpipe) together with eleven PRs the world run needed. Tested on main 73516a290: translator suite 500 files / 6,365 tests, 0 failed; 513 standard-library test files pass; check_no_game_data clean on 80 files; Linux ctest 112/112; Wine suite (clang-cl + xwin, RDNA2 iGPU, RADV) with no test going from pass to fail. Not tested: native Windows, NVIDIA. The included PRs are closed in favour of this one with credit to their authors. AI-assisted (Claude Code, Claude Opus 5.5 and Claude Fable 5.2).
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/build_runtime.ps1 | 2 | ||||
| -rw-r--r-- | scripts/run_address_guard_gpu_test.py | 133 | ||||
| -rw-r--r-- | scripts/windows-boot/boot.ps1 | 3 |
3 files changed, 136 insertions, 2 deletions
diff --git a/scripts/build_runtime.ps1 b/scripts/build_runtime.ps1 index 5dd8bd389..bb25cccd7 100644 --- a/scripts/build_runtime.ps1 +++ b/scripts/build_runtime.ps1 | |||
| @@ -86,7 +86,7 @@ $build || exit /b 1 | |||
| 86 | Write-Warning "CMake and Ninja weren't found (neither VS C++ CMake tools nor native PATH tools): building with cl.exe directly, without the GameInput shim (SDL3) and without the Rust XMA2 decoder (XMA voices are silent). Install CMake + Ninja or VS's CMake tools component to get it." | 86 | Write-Warning "CMake and Ninja weren't found (neither VS C++ CMake tools nor native PATH tools): building with cl.exe directly, without the GameInput shim (SDL3) and without the Rust XMA2 decoder (XMA voices are silent). Install CMake + Ninja or VS's CMake tools component to get it." |
| 87 | $xtaskqueueDir = Join-Path $root "third_party\xtaskqueue" | 87 | $xtaskqueueDir = Join-Path $root "third_party\xtaskqueue" |
| 88 | $xtaskqueueFiles = "Source\Task\TaskQueue.cpp", "Source\Task\AsyncLib.cpp", "Source\Task\ThreadPool_win32.cpp", "Source\Task\WaitTimer_win32.cpp" | ForEach-Object { "`"$xtaskqueueDir\$_`"" } | 88 | $xtaskqueueFiles = "Source\Task\TaskQueue.cpp", "Source\Task\AsyncLib.cpp", "Source\Task\ThreadPool_win32.cpp", "Source\Task\WaitTimer_win32.cpp" | ForEach-Object { "`"$xtaskqueueDir\$_`"" } |
| 89 | $files = "src\main.cpp", "src\thread_stacks.cpp", "src\bcpack.cpp", "src\host_cpu.cpp", "src\pe_loader.cpp", "shims\registry.cpp", "shims\console_registry.cpp", "shims\file_system.cpp", "shims\xmem.cpp", "shims\xg_xs.cpp", "shims\acphal.cpp", "shims\d3d12_xs.cpp", "shims\d3d12_xs_device.cpp", "shims\d3d12_xs_pso_stream.cpp", "shims\d3d12_xs_rootsig.cpp", "shims\xgameruntime.cpp", "shims\xgameruntime_user.cpp", "shims\xgameruntime_gamesave.cpp", "shims\xgameruntime_store.cpp", "shims\xgameruntime_offline.cpp", "shims\winhttp_offline.cpp", "shims\ws2_offline.cpp", "shims\library_loader.cpp", "shims\process.cpp", "shims\lifecycle.cpp", "shims\xbox_bvh_builder.cpp", "shims\com_shim.cpp", "shims\silent_audio.cpp", "shims\bcrypt_rng.cpp", "shims\xapu_chad.cpp", "shims\dstorage.cpp" | ForEach-Object { "`"$src\$_`"" } | 89 | $files = "src\main.cpp", "src\thread_stacks.cpp", "src\bcpack.cpp", "src\host_cpu.cpp", "src\pe_loader.cpp", "shims\registry.cpp", "shims\console_registry.cpp", "shims\file_system.cpp", "shims\xmem.cpp", "shims\xg_xs.cpp", "shims\acphal.cpp", "shims\d3d12_xs.cpp", "shims\d3d12_xs_device.cpp", "shims\d3d12_xs_pso_stream.cpp", "shims\d3d12_xs_rootsig.cpp", "shims\xgameruntime.cpp", "shims\xgameruntime_user.cpp", "shims\xgameruntime_gamesave.cpp", "shims\xgameruntime_store.cpp", "shims\xgameruntime_offline.cpp", "shims\winhttp_offline.cpp", "shims\ws2_offline.cpp", "shims\library_loader.cpp", "shims\process.cpp", "shims\lifecycle.cpp", "shims\xbox_bvh_builder.cpp", "shims\com_shim.cpp", "shims\silent_audio.cpp", "shims\bcrypt_rng.cpp", "shims\xapu_queue.cpp", "shims\xapu_chad.cpp", "shims\dstorage.cpp" | ForEach-Object { "`"$src\$_`"" } |
| 90 | $includes = "/I `"$src\src`" /I `"$src\shims`" /I `"$src\shims\xtaskqueue`" /I `"$xtaskqueueDir\Include`" /I `"$xtaskqueueDir\Source\Task`" /I `"$xtaskqueueDir\Source\Common`"" | 90 | $includes = "/I `"$src\src`" /I `"$src\shims`" /I `"$src\shims\xtaskqueue`" /I `"$xtaskqueueDir\Include`" /I `"$xtaskqueueDir\Source\Task`" /I `"$xtaskqueueDir\Source\Common`"" |
| 91 | $opt = if ($Debug) { "/Od /MDd" } else { "/O2 /MD" } | 91 | $opt = if ($Debug) { "/Od /MDd" } else { "/O2 /MD" } |
| 92 | $body = @" | 92 | $body = @" |
diff --git a/scripts/run_address_guard_gpu_test.py b/scripts/run_address_guard_gpu_test.py new file mode 100644 index 000000000..f7aa53366 --- /dev/null +++ b/scripts/run_address_guard_gpu_test.py | |||
| @@ -0,0 +1,133 @@ | |||
| 1 | """GPU test of the address guard (rdna2spirv.py --address-guard; docs/d3d12_vulkan.md, "Address guard"). | ||
| 2 | |||
| 3 | Assembles runtime/test/shaders/cs_address_guard.asm, translates it with --address-guard and runs it with | ||
| 4 | vk_compute_test twice on a 2 MiB heap: once with the guard's header (the page table backs the arena and the page at | ||
| 5 | 0x90000), once without its magic (the guard off). Every address the program uses is inside the heap's buffer, so | ||
| 6 | neither run can fault, whatever the guard does: the guard-on run shows that the refused accesses read 0 and left | ||
| 7 | memory alone although memory was there, and the guard-off run that the same module then reads it. | ||
| 8 | |||
| 9 | python -I scripts/run_address_guard_gpu_test.py --build runtime/build [--llvm-mc CMD] [--work DIR] | ||
| 10 | |||
| 11 | Pin the GPU (MESA_VK_DEVICE_SELECT, VK_DRIVER_FILES) as for scripts/run_gpu_tests.py. Exit 0 when both runs give | ||
| 12 | the expected words, 1 otherwise, 77 when vk_compute_test or llvm-mc is missing. | ||
| 13 | """ | ||
| 14 | import argparse | ||
| 15 | import os | ||
| 16 | import shutil | ||
| 17 | import struct | ||
| 18 | import subprocess | ||
| 19 | import sys | ||
| 20 | import tempfile | ||
| 21 | |||
| 22 | ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | ||
| 23 | sys.path.insert(0, os.path.join(ROOT, "tools")) | ||
| 24 | import address_guard as ag # noqa: E402 | ||
| 25 | |||
| 26 | NAME = "cs_address_guard" | ||
| 27 | HEAP_BYTES = 2 << 20 | ||
| 28 | LIMIT = ag.RESERVED_END # the "arena": offsets below it pass without a lookup | ||
| 29 | TABLE = 0x100000 # the page table, inside the buffer but past the arena | ||
| 30 | BACKED = [(0x90000, 0x91000)] # the one page outside the arena the table backs | ||
| 31 | SEEDS = {0x90000: 0xA11CE000, 0x90004: 0xA11CE004, 0x90FFC: 0xF00DF00D, 0x91000: 0xF00DF00E, | ||
| 32 | 0xA0000: 0xBADBAD00, 0xA0004: 0xBADBAD04, 0xA0008: 0xBADBAD08} | ||
| 33 | # out[0..7] (cs_address_guard.asm's header) and other words after the run. | ||
| 34 | EXPECTED_ON = [0xA11CE000, 0, 0, 0, 0, 0, 0xA11CE004, 0] | ||
| 35 | EXPECTED_OFF = [0xA11CE000, 0xBADBAD00, 0xBADBAD08, 0xF00DF00D, 0xF00DF00E, 0xBADBAD00, 0xA11CE004, 0xBADBAD00] | ||
| 36 | MEMORY_ON = {0xA0004: 0xBADBAD04, 0xA0008: 0xBADBAD08, # untouched | ||
| 37 | ag.DUMP + 4: 0x5707, ag.DUMP + 8: 1, # where the refused store and atomic went | ||
| 38 | ag.HEADER + 24: 6, # six refused accesses | ||
| 39 | ag.HEADER + 32: 0xA0000, ag.HEADER + 36: 0} # the last one, the s_load at 0xa0000 | ||
| 40 | MEMORY_OFF = {0xA0004: 0x5707, 0xA0008: 0xBADBAD09, ag.DUMP + 4: 0, ag.HEADER + 24: 0} | ||
| 41 | |||
| 42 | |||
| 43 | def heap(guard_on): | ||
| 44 | """The heap's bytes: header (without the magic when not `guard_on`), seeds and page table; zero elsewhere.""" | ||
| 45 | words = ag.table_words(BACKED) | ||
| 46 | end = TABLE + 4 * len(words) | ||
| 47 | assert end <= HEAP_BYTES | ||
| 48 | buf = bytearray(end) | ||
| 49 | hdr = bytearray(ag.header(LIMIT, TABLE)) | ||
| 50 | if not guard_on: | ||
| 51 | hdr[0:8] = bytes(8) | ||
| 52 | buf[ag.HEADER:ag.HEADER + len(hdr)] = hdr | ||
| 53 | for at, value in SEEDS.items(): | ||
| 54 | struct.pack_into("<I", buf, at, value) | ||
| 55 | struct.pack_into(f"<{len(words)}I", buf, TABLE, *words) | ||
| 56 | return bytes(buf) | ||
| 57 | |||
| 58 | |||
| 59 | def find_tool(build, name): | ||
| 60 | for sub in ("", "RelWithDebInfo", "Release", "Debug"): | ||
| 61 | for ext in ("", ".exe"): | ||
| 62 | path = os.path.join(build, sub, name + ext) | ||
| 63 | if os.path.isfile(path): | ||
| 64 | return path | ||
| 65 | return None | ||
| 66 | |||
| 67 | |||
| 68 | def main(argv=None): | ||
| 69 | ap = argparse.ArgumentParser(description=__doc__.split("\n\n")[0]) | ||
| 70 | ap.add_argument("--build", default=os.path.join(ROOT, "runtime", "build"), help="folder with vk_compute_test") | ||
| 71 | ap.add_argument("--llvm-mc", default=os.environ.get("LLVM_MC", "llvm-mc")) | ||
| 72 | ap.add_argument("--work", default=None, help="keep the intermediate files here") | ||
| 73 | a = ap.parse_args(argv) | ||
| 74 | vk_compute = find_tool(a.build, "vk_compute_test") | ||
| 75 | if not vk_compute: | ||
| 76 | print(f"SKIP: no vk_compute_test under {a.build}") | ||
| 77 | return 77 | ||
| 78 | if not shutil.which(a.llvm_mc.split()[0]): | ||
| 79 | print(f"SKIP: {a.llvm_mc} not found") | ||
| 80 | return 77 | ||
| 81 | sys.path.insert(0, os.path.join(ROOT, "runtime", "test", "shaders")) | ||
| 82 | sys.path.insert(0, os.path.join(ROOT, "scripts")) | ||
| 83 | from compute_fixture import compute_header | ||
| 84 | import run_gpu_tests | ||
| 85 | work = a.work or tempfile.mkdtemp(prefix="leonida-guard-") | ||
| 86 | asm = os.path.join(ROOT, "runtime", "test", "shaders", NAME + ".asm") | ||
| 87 | for sub in ("disasm", "fssm", "spirv"): | ||
| 88 | os.makedirs(os.path.join(work, sub), exist_ok=True) | ||
| 89 | run_gpu_tests.assemble_to_s(a.llvm_mc, asm, os.path.join(work, "disasm", NAME + ".s"), NAME) | ||
| 90 | with open(os.path.join(work, NAME + ".dxbc"), "wb") as f: | ||
| 91 | f.write(run_gpu_tests.make_dxbc([])) | ||
| 92 | with open(os.path.join(work, "fssm", NAME + ".fssm"), "wb") as f: | ||
| 93 | f.write(compute_header(asm)) | ||
| 94 | spirv = os.path.join(work, "spirv") | ||
| 95 | p = subprocess.run([sys.executable, "-I", os.path.join(ROOT, "tools", "rdna2spirv.py"), | ||
| 96 | os.path.join(work, "disasm"), "--out", spirv, "--address-guard"], | ||
| 97 | capture_output=True, text=True) | ||
| 98 | spv = os.path.join(spirv, NAME + ".spv") | ||
| 99 | if p.returncode != 0 or not os.path.isfile(spv): | ||
| 100 | print(p.stdout + p.stderr) | ||
| 101 | print("FAIL: translation") | ||
| 102 | return 1 | ||
| 103 | failures = 0 | ||
| 104 | for guard_on, expected, memory in ((True, EXPECTED_ON, MEMORY_ON), (False, EXPECTED_OFF, MEMORY_OFF)): | ||
| 105 | label = "guard on" if guard_on else "guard off" | ||
| 106 | init, dump = os.path.join(work, f"heap_{label[6:]}.bin"), os.path.join(work, f"dump_{label[6:]}.bin") | ||
| 107 | with open(init, "wb") as f: | ||
| 108 | f.write(heap(guard_on)) | ||
| 109 | env = dict(os.environ, VKC_HEAP_INIT=init, VKC_OUT_WORDS=str(HEAP_BYTES // 4), VKC_DUMP=dump) | ||
| 110 | r = subprocess.run([vk_compute, spv, "1", "dump"], capture_output=True, text=True, env=env, timeout=120) | ||
| 111 | if r.returncode != 0 or not os.path.isfile(dump): | ||
| 112 | print(f"FAIL ({label}): vk_compute_test exit {r.returncode}\n{r.stdout}{r.stderr}") | ||
| 113 | failures += 1 | ||
| 114 | continue | ||
| 115 | with open(dump, "rb") as f: | ||
| 116 | data = f.read() | ||
| 117 | word = lambda at: struct.unpack_from("<I", data, at)[0] # noqa: E731 | ||
| 118 | got = [word(4 * k) for k in range(8)] | ||
| 119 | bad = [f"out[{k}] = {g:#x}, want {w:#x}" for k, (g, w) in enumerate(zip(got, expected)) if g != w] | ||
| 120 | bad += [f"[{at:#x}] = {word(at):#x}, want {w:#x}" for at, w in memory.items() if word(at) != w] | ||
| 121 | print(f"{'PASS' if not bad else 'FAIL'} ({label}): out = {' '.join(f'{g:#x}' for g in got)}") | ||
| 122 | for line in bad: | ||
| 123 | print(" " + line) | ||
| 124 | failures += bool(bad) | ||
| 125 | return 1 if failures else 0 | ||
| 126 | |||
| 127 | |||
| 128 | if __name__ == "__main__": | ||
| 129 | try: # a redirected stdout is strict ANSI code page under -I; write '?' for what it cannot encode | ||
| 130 | sys.stdout.reconfigure(errors="replace") | ||
| 131 | except (AttributeError, ValueError, OSError): | ||
| 132 | pass | ||
| 133 | sys.exit(main()) | ||
diff --git a/scripts/windows-boot/boot.ps1 b/scripts/windows-boot/boot.ps1 index 7863054b3..4a80dedfd 100644 --- a/scripts/windows-boot/boot.ps1 +++ b/scripts/windows-boot/boot.ps1 | |||
| @@ -50,7 +50,8 @@ | |||
| 50 | 50 | ||
| 51 | .PARAMETER InputScript | 51 | .PARAMETER InputScript |
| 52 | LEONIDA_INPUT_SCRIPT: timed pad presses, seconds since the pad's first poll (button@seconds, comma-separated; | 52 | LEONIDA_INPUT_SCRIPT: timed pad presses, seconds since the pad's first poll (button@seconds, comma-separated; |
| 53 | buttons a b x y start back lb rb up down left right). Sets LEONIDA_KEYBOARD_PAD=always. Builds older than | 53 | buttons a b x y start back lb rb up down left right). Each press is held 300 ms; button@seconds:hold holds it |
| 54 | longer, e.g. b@1100:3 for a title that reads its pad only every few seconds. Sets LEONIDA_KEYBOARD_PAD=always. Builds older than | ||
| 54 | main @ 8146ef690 ignore a script longer than 63 characters. Default 'a@45,a@60,a@75,a@90'. | 55 | main @ 8146ef690 ignore a script longer than 63 characters. Default 'a@45,a@60,a@75,a@90'. |
| 55 | 56 | ||
| 56 | .PARAMETER NoInput | 57 | .PARAMETER NoInput |