diff --git a/scripts/windows-boot/README.md b/scripts/windows-boot/README.md index 8fbba6182f..2b3a4116aa 100644 --- a/scripts/windows-boot/README.md +++ b/scripts/windows-boot/README.md @@ -38,9 +38,9 @@ Only when your shell has not set them already (`-DryRun` prints the final list): | `LEONIDA_PIPELINE_CACHE_BYTES` | `4294967296` | pipeline cache size limit | | `LEONIDA_STARTUP_CACHE_CHECKPOINTS` | `1` | save the pipeline cache during startup | | `LEONIDA_PIPELINE_CACHE_DIR` | `\pipeline-cache` | one warmed cache shared by every build you boot | -| `LEONIDA_PIPELINE_JOURNAL_SEED_DIR` | `pipeline_cache.d` beside `gta6rt.exe`, when it exists | the journal `gta6rt --precompile-pipelines` fills there when it runs without `LEONIDA_PIPELINE_CACHE_DIR`, read-only, so its pipelines are not compiled again. Not set when the boot's own journal (`\pipeline_cache.d`, or beside `gta6rt.exe` when the cache folder is empty) is that folder or one holds the other, compared through Windows' final paths (so a junction, symbolic link, substituted or mapped drive, 8.3 name or `\\?\` / `\\.\` prefix counts as the same folder), or when the cache folder is a relative path. `LEONIDA_PIPELINE_JOURNAL_SEED_DIR=` (empty) turns the seed off. If the runtime still logs `[rt] d3d12: invalid or overlapping compute journal directories; journal disabled`, set it so. On NVIDIA, run the pre-compile with the same `LEONIDA_DEVICE_FAULT` as the boot (this script sets `1`): the diagnostics config is part of the journal's file names | +| `LEONIDA_PIPELINE_JOURNAL_SEED_DIR` | `pipeline_cache.d` beside `gta6rt.exe`, when it exists | the journal `gta6rt --precompile-pipelines` fills there when it runs without `LEONIDA_PIPELINE_CACHE_DIR`, read-only, so its pipelines are not compiled again. Not set when the boot's own journal (`\pipeline_cache.d`, or beside `gta6rt.exe` when the cache folder is empty) is that folder or one holds the other, compared through Windows' final paths (so a junction, symbolic link, substituted or mapped drive, 8.3 name or `\\?\` / `\\.\` prefix counts as the same folder), or when the cache folder is a relative path. `LEONIDA_PIPELINE_JOURNAL_SEED_DIR=` (empty) turns the seed off. If the runtime still logs `[rt] d3d12: invalid or overlapping compute journal directories; journal disabled`, set it so. On NVIDIA, `LEONIDA_DEVICE_FAULT=1` puts the diagnostics config into the journal's file names, so the pre-compile and the boot have to agree on it; this script sets `2`, which names them as a pre-compile without the variable does, except with `LEONIDA_AFTERMATH=1` (see `LEONIDA_DEVICE_FAULT`) | | `LEONIDA_PEEK` / `_SECONDS` | the game-state and session-state RVAs from `LEONIDA_GAME_STATE_RVA` and `LEONIDA_SESSION_STATE_RVA` (measured locally, not kept here; unset: no peek) / `5` | game state and session state (low dword), the two numbers every RESULT reports | -| `LEONIDA_DEVICE_FAULT` | `1` | on device loss: `VK_EXT_device_fault` info, checkpoints, last replay steps | +| `LEONIDA_DEVICE_FAULT` | `2` | on device loss: `VK_EXT_device_fault` info, NVIDIA checkpoints, last replay steps, without NVIDIA's diagnostics config, so a pre-compiled compute journal still matches (that config is part of every compute journal file name). `1` adds the config (shader debug info in a crash dump); `LEONIDA_DEVICE_FAULT=1` turns it on for a boot, and the script uses `1` by itself when `LEONIDA_AFTERMATH=1` and you did not set this variable. Under `2`, "NVIDIA diagnostics config unavailable" in the runtime's `[rt] device-fault: enabled` line means it was not requested, not a driver problem | | `LEONIDA_KEYBOARD_PAD` | `always` (with an input script) | keyboard as a pad even unfocused, so the script's presses arrive | | `LEONIDA_CAPTURE_EVERY` / `_LIMIT` | `60` / `40` | a swapchain read-back every 60 presents, at most 40 | | `DISABLE_RTSS_LAYER`, `DISABLE_VULKAN_OBS_CAPTURE` | `1` | keep third-party Vulkan overlay layers out of the process | diff --git a/scripts/windows-boot/boot.ps1 b/scripts/windows-boot/boot.ps1 index 801867f113..d232bb3d4b 100644 --- a/scripts/windows-boot/boot.ps1 +++ b/scripts/windows-boot/boot.ps1 @@ -231,7 +231,8 @@ if ($Shaders) { # ------------------------------------------------------------------------------------------ environment -# Defaults: used only when this shell has not set the variable. They match the Linux harness (scripts/linux-boot/). +# Defaults: used only when this shell has not set the variable. Some are the Linux harness's too (scripts/linux-boot/); it +# does not set LEONIDA_DEVICE_FAULT. $defaults = [ordered]@{ LEONIDA_D3D12 = "vulkan" LEONIDA_DEVICE_TYPE = "6" # Series S identity; the runtime answers the ConsoleMode registry read with it @@ -242,7 +243,10 @@ $defaults = [ordered]@{ # LEONIDA_PEEK: the game-state and session-state RVAs (measured locally, not kept in the repository) when # LEONIDA_GAME_STATE_RVA and LEONIDA_SESSION_STATE_RVA name them; see below. LEONIDA_PEEK_SECONDS = "5" - LEONIDA_DEVICE_FAULT = "1" # device-loss report (VK_EXT_device_fault, checkpoints) + # 2: the device-loss report and checkpoints without NVIDIA's diagnostics config. =1 adds that config, which is part + # of every compute journal file name, so a journal pre-compiled without it would not match. LEONIDA_AFTERMATH=1 + # gets 1 (below). + LEONIDA_DEVICE_FAULT = "2" # device-loss report (VK_EXT_device_fault, checkpoints) LEONIDA_CAPTURE_EVERY = "60" LEONIDA_CAPTURE_LIMIT = "40" DISABLE_RTSS_LAYER = "1" # third-party Vulkan overlay layers off @@ -266,20 +270,25 @@ if ($Shaders) { $perRun["LEONIDA_SHADERS"] = $Shaders } if ($Stacks) { $perRun["LEONIDA_STACKS"] = $Stacks } $bootEnv = [ordered]@{} +$given = @{} # the variables this shell, -SetEnv or KEY=VALUE set, as opposed to the defaults above foreach ($k in $defaults.Keys) { $cur = [Environment]::GetEnvironmentVariable($k) - if ($cur) { $bootEnv[$k] = $cur } else { $bootEnv[$k] = $defaults[$k] } + if ($cur) { $bootEnv[$k] = $cur; $given[$k] = $true } else { $bootEnv[$k] = $defaults[$k] } } foreach ($k in $perRun.Keys) { $bootEnv[$k] = $perRun[$k] } # Other LEONIDA_* switches already set in this shell are passed through as they are; they are listed below. foreach ($item in (Get-ChildItem Env: | Where-Object { $_.Name -like "LEONIDA_*" })) { if (-not $bootEnv.Contains($item.Name)) { $bootEnv[$item.Name] = $item.Value } } -foreach ($k in $SetEnv.Keys) { $bootEnv[[string]$k] = [string]$SetEnv[$k] } +foreach ($k in $SetEnv.Keys) { $bootEnv[[string]$k] = [string]$SetEnv[$k]; $given[[string]$k] = $true } foreach ($pair in $EnvPairs) { if ($pair -notmatch '^([A-Za-z_][A-Za-z0-9_]*)=(.*)$') { throw "not a parameter and not KEY=VALUE: '$pair' (Get-Help $PSCommandPath -Full)" } - $bootEnv[$Matches[1]] = $Matches[2] + $bootEnv[$Matches[1]] = $Matches[2]; $given[$Matches[1]] = $true } +# LEONIDA_AFTERMATH=1 wants NVIDIA's diagnostics config (shader debug info in the crash dump). The runtime reads +# LEONIDA_DEVICE_FAULT first and leaves the config out for 2 (d3d12_vulkan_device.cpp), so the default becomes 1 then; +# a value the user gave is kept. +if ($bootEnv["LEONIDA_AFTERMATH"] -eq "1" -and -not $given["LEONIDA_DEVICE_FAULT"]) { $bootEnv["LEONIDA_DEVICE_FAULT"] = "1" } if ($bootEnv["LEONIDA_CAPTURE"]) { $Capture = $bootEnv["LEONIDA_CAPTURE"] } # The journal `gta6rt --precompile-pipelines` fills beside gta6rt.exe (when it runs without LEONIDA_PIPELINE_CACHE_DIR) # is read here as the runtime's read-only seed (LEONIDA_PIPELINE_JOURNAL_SEED_DIR, docs/d3d12_vulkan.md), so the pipelines diff --git a/tests/test_windows_boot_journal_seed.py b/tests/test_windows_boot_journal_seed.py index 21d20c4726..7775215bb8 100644 --- a/tests/test_windows_boot_journal_seed.py +++ b/tests/test_windows_boot_journal_seed.py @@ -4,9 +4,16 @@ LEONIDA_PIPELINE_JOURNAL_SEED_DIR a boot compiled again every pipeline the pre-compile had built. These cases run `boot.ps1 -DryRun` (nothing is launched, no game files are needed) against a temporary runtime folder and read the `[boot] env` lines it prints. Windows only: the script is Windows PowerShell. + +They also pin its LEONIDA_DEVICE_FAULT default, 2. With 1 the runtime also turns on NVIDIA's diagnostics config, which is +part of every compute journal file name, so a boot read none of a journal pre-compiled without it; 2 keeps the +device-fault report and checkpoints without that config. LEONIDA_AFTERMATH=1 gets 1 unless the user chose a value: the +runtime reads LEONIDA_DEVICE_FAULT before LEONIDA_AFTERMATH, and only 1 gives the dump its diagnostics config. The +README's table is read as text, on any system. """ import os +import re import shutil import subprocess import sys @@ -18,6 +25,9 @@ BOOT = REPO / "scripts" / "windows-boot" / "boot.ps1" POWERSHELL = shutil.which("powershell") or shutil.which("pwsh") SEED = "LEONIDA_PIPELINE_JOURNAL_SEED_DIR" +DEVICE_FAULT = "LEONIDA_DEVICE_FAULT" +AFTERMATH = "LEONIDA_AFTERMATH" +README = REPO / "scripts" / "windows-boot" / "README.md" @unittest.skipUnless(sys.platform == "win32" and POWERSHELL, "boot.ps1 is a Windows PowerShell script") @@ -32,18 +42,23 @@ def setUp(self): self.game.mkdir() self.out = self.tmp / "runs" - def env_lines(self, *pairs, shell=None, runtime=None, command_in=None): + def env_lines(self, *pairs, shell=None, set_env=None, runtime=None, command_in=None): env = {k: v for k, v in os.environ.items() if not k.startswith("LEONIDA_") and k not in ("GTA6RT",)} env.update(shell or {}) runtime = runtime or str(self.runtime / "gta6rt.exe") args = ["-DryRun", "-NoInput", "-Runtime", runtime, "-GameDir", str(self.game), "-OutDir", str(self.out), *pairs] - if command_in: - # Set-Location inside the session moves $PWD but not the process's current directory, as in an interactive shell. - # Parameter names stay bare (quoted, '-DryRun' would be a KEY=VALUE pair); every value is quoted. - quoted = " ".join(a if a.startswith("-") else "'" + a.replace("'", "''") + "'" for a in args) + if command_in or set_env: + # -SetEnv takes a hashtable, which only -Command can pass. Set-Location inside the session moves $PWD but not + # the process's current directory, as in an interactive shell. Parameter names stay bare (quoted, '-DryRun' + # would be a KEY=VALUE pair); every value is quoted. + def q(text): + return "'" + text.replace("'", "''") + "'" + quoted = " ".join(a if a.startswith("-") else q(a) for a in args) + if set_env: + quoted += " -SetEnv @{" + "; ".join(f"{q(k)} = {q(v)}" for k, v in set_env.items()) + "}" + location = f"Set-Location -LiteralPath {q(command_in)}; " if command_in else "" cmd = [POWERSHELL, "-NoProfile", "-ExecutionPolicy", "Bypass", "-Command", - f"Set-Location -LiteralPath '{command_in.replace(chr(39), chr(39) * 2)}'; " - f"& '{str(BOOT).replace(chr(39), chr(39) * 2)}' {quoted}"] + f"{location}& {q(str(BOOT))} {quoted}"] else: cmd = [POWERSHELL, "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", str(BOOT), *args] # Windows PowerShell writes the console's OEM code page when its output is redirected. @@ -143,6 +158,60 @@ def test_a_relative_runtime_is_resolved_from_the_shell_location(self): lines = self.env_lines(runtime="port\\gta6rt.exe", command_in=str(self.tmp)) self.assertEqual(os.path.normcase(lines.get(SEED, "")), os.path.normcase(str(self.runtime / "pipeline_cache.d"))) + def test_device_fault_default_leaves_the_journal_names_alone(self): + self.assertEqual(self.env_lines().get(DEVICE_FAULT), "2") + + def test_device_fault_given_on_the_command_line_wins(self): + self.assertEqual(self.env_lines(f"{DEVICE_FAULT}=1").get(DEVICE_FAULT), "1") + + def test_key_with_no_value_removes_device_fault(self): + self.assertNotIn(DEVICE_FAULT, self.env_lines(f"{DEVICE_FAULT}=")) + + def test_device_fault_set_in_the_shell_is_kept(self): + self.assertEqual(self.env_lines(shell={DEVICE_FAULT: "1"}).get(DEVICE_FAULT), "1") + + def test_device_fault_given_with_set_env_wins(self): + self.assertEqual(self.env_lines(set_env={DEVICE_FAULT: "1"}).get(DEVICE_FAULT), "1") + + def test_aftermath_gets_the_diagnostics_config(self): + # The runtime reads LEONIDA_DEVICE_FAULT first; with 2 a crash dump would have no shader debug info. + for how in ("argument", "shell", "set_env"): + with self.subTest(how=how): + pairs, kwargs = self.given(how, {AFTERMATH: "1"}) + lines = self.env_lines(*pairs, **kwargs) + self.assertEqual(lines.get(AFTERMATH), "1") + self.assertEqual(lines.get(DEVICE_FAULT), "1") + + def test_aftermath_keeps_a_device_fault_the_user_gave(self): + for how in ("argument", "shell", "set_env"): + with self.subTest(how=how): + pairs, kwargs = self.given(how, {DEVICE_FAULT: "2"}) + self.assertEqual(self.env_lines(f"{AFTERMATH}=1", *pairs, **kwargs).get(DEVICE_FAULT), "2") + + def test_aftermath_off_keeps_the_default(self): + # No LEONIDA_AFTERMATH at all is test_device_fault_default_leaves_the_journal_names_alone. + self.assertEqual(self.env_lines(f"{AFTERMATH}=0").get(DEVICE_FAULT), "2") + + @staticmethod + def given(how, values): + """The values as KEY=VALUE arguments, or as env_lines' shell= or set_env=, the three ways a user sets them.""" + if how == "argument": + return [f"{k}={v}" for k, v in values.items()], {} + return [], {how: values} + + +class DeviceFaultReadmeTest(unittest.TestCase): + def test_readme_gives_the_default_2(self): + # Markdown marks (backticks, bold) are dropped, so a change of formatting alone does not fail this. + text = re.sub(r"[`*]", "", README.read_text(encoding="utf-8")) + rows = [cells for cells in (line.split("|") for line in text.splitlines() if line.startswith("|")) + if len(cells) > 3 and cells[1].strip() == DEVICE_FAULT] + self.assertEqual(len(rows), 1, rows) + self.assertEqual(rows[0][2].strip(), "2", rows[0]) + # No prose says the script sets 1 (the row of LEONIDA_PIPELINE_JOURNAL_SEED_DIR said so before). + said_1 = re.findall(rf"script\s+sets\s+(?:{DEVICE_FAULT}\s*=\s*)?1\b[^|]*", text) + self.assertEqual(said_1, []) + if __name__ == "__main__": unittest.main()