diff --git a/make_game.py b/make_game.py index 03d93a2b8b..2583023815 100644 --- a/make_game.py +++ b/make_game.py @@ -1931,7 +1931,8 @@ def wave64_settings(mode: str, *, mesh_compute: bool = False) -> tuple[bool, boo if exe: try: r = subprocess.run([exe], capture_output=True, text=True, errors="replace", timeout=120) - size = smallest_max_subgroup(r.stdout) + if r.returncode == 0: + size = smallest_max_subgroup(r.stdout) except (OSError, subprocess.SubprocessError): size = None if size is None: @@ -2524,6 +2525,11 @@ def wine_launcher(out: str, work: str, image: str) -> str: here=$(dirname "$(readlink -f "$0")") if [ "$#" -eq 1 ] && {{ [ "$1" = --dry-run ] || [ "$1" = --init ] || [ "$1" = --run ]; }}; then game=$(cat "$here/game_path.txt" && printf .) || exit 1 + # A relative WINE (a Proton build's files/bin/wine) names a file from the caller's folder, not the game's. + case ${{WINE-}} in + /*) ;; + */*) WINE=$PWD/$WINE ;; + esac cd "${{game%.}}" || exit 1 image={shlex.quote(image)} if [ ! -f "./$image" ]; then @@ -2738,7 +2744,12 @@ def pipelines(work: str, out: str, jobs: "int | None" = None, *, runtime_build: inflight = os.path.join(out, "pipeline_inflight.txt") skip = os.path.join(out, "pipeline_crashes.txt") report = os.path.join(out, "pipeline_crashes.json") - drop(inflight, skip, report) # every module gets a fresh chance on each run (a new translator may have fixed it) + drop(inflight, skip) # every module gets a fresh chance on each run (a new translator may have fixed it) + try: + drop(report) + except OSError as error: + log(f"pipelines: cannot remove old pipeline_crashes.json ({error.strerror or error}). " + "That report may be stale.") # --jobs: make_game.py's own; without it vk_pipeline_check uses half the hardware threads whatever was asked jobs_args = ["--jobs", str(jobs)] if jobs else [] base = [exe, spirv, cache, *jobs_args] @@ -2825,20 +2836,20 @@ def check_range(start: int = 0, count: "int | None" = None) -> int: break if crashed and not code: code = 1 - if crashed: - record_crashes(out, spirv, crashed) + report_written = bool(crashed) and record_crashes(out, spirv, crashed) drop(inflight) if code != 0: - why = f"; {len(crashed)} module(s) took the driver down and were counted as failed (with their SPIR-V " \ - f"hashes in pipeline_crashes.json): " + ", ".join(crashed) if crashed else "" + report_note = " (with their SPIR-V hashes in pipeline_crashes.json)" if report_written else "" + why = f"; {len(crashed)} module(s) took the driver down and were counted as failed{report_note}: " \ + + ", ".join(crashed) if crashed else "" fail(f"vk_pipeline_check exited with {exit_label(code)}{why}") seed_bvh() log("pipelines: done") -def record_crashes(out: str, spirv: str, crashed: "list[str]") -> None: - """pipeline_crashes.json: name and SHA-256 of each module that took the driver down, so a report names the - exact translation without attaching the shader. OSError (a missing .spv) leaves that module's hash null.""" +def record_crashes(out: str, spirv: str, crashed: "list[str]") -> bool: + """Write name and SHA-256 of each module that took the driver down to pipeline_crashes.json and return whether + it was written. OSError (a missing .spv) leaves that module's hash null.""" def digest(name: str) -> "str | None": try: with open(os.path.join(spirv, name + ".spv"), "rb") as f: @@ -2850,11 +2861,12 @@ def digest(name: str) -> "str | None": with open(os.path.join(out, "pipeline_crashes.json"), "w", encoding="utf-8", newline="\n") as f: json.dump(doc, f, indent=1) f.write("\n") + return True except OSError as error: # The durable record is best-effort. A report path that cannot be written must not # replace the checker diagnostic that names the modules which took the driver down. log(f"pipelines: cannot write pipeline_crashes.json: {error.strerror or error}") - + return False # How many times the pipelines stage restarts vk_pipeline_check after a module takes it down (each costs at most the # 10 minutes since the last cache checkpoint, plus loading the cache). Looked up when pipelines() runs. diff --git a/tests/test_make_game_pipelines.py b/tests/test_make_game_pipelines.py index e0f15ba6fc..1002de4b07 100644 --- a/tests/test_make_game_pipelines.py +++ b/tests/test_make_game_pipelines.py @@ -316,6 +316,26 @@ def script(args, n): self.assertIn("vk_pipeline_check", err.getvalue()) self.assertIn("b_mod", err.getvalue()) self.assertTrue(any("cannot write pipeline_crashes.json" in line for line in logs)) + self.assertNotIn("hashes in pipeline_crashes.json", err.getvalue()) + + def test_a_locked_old_crash_report_does_not_stop_the_check(self): + os.makedirs(self.out) + report = os.path.join(self.out, "pipeline_crashes.json") + with open(report, "w", encoding="utf-8") as f: + f.write('{"modules": []}') + real_remove = os.remove + + def locked_report(path): + if path == report: + raise PermissionError(13, "another process has the report open") + return real_remove(path) + + with mock.patch.object(make_game.os, "remove", locked_report): + failed, logs = self.stage(lambda args, n: 0) + self.assertIsNone(failed) + self.assertTrue(any("cannot remove old pipeline_crashes.json" in line and "may be stale" in line + for line in logs), logs) + self.assertTrue(os.path.exists(report)) def test_a_clean_run_drops_an_old_crash_report(self): os.makedirs(self.out) diff --git a/tests/test_make_game_platform.py b/tests/test_make_game_platform.py index 9da2133677..d90ea810c4 100644 --- a/tests/test_make_game_platform.py +++ b/tests/test_make_game_platform.py @@ -278,6 +278,15 @@ def real(path): result = subprocess.check_output([launcher, "--run", "other.exe", "--", "two words"], cwd=self.root, env=env) self.assertEqual(json.loads(result)[:2], [real(self.root), ["--run", "other.exe", "--", "two words"]]) + # A relative WINE names a file from the caller's folder, although the packaged modes start in the game's. + proton = os.path.join(self.root, "Proton 9.0", "files", "bin") + os.makedirs(proton) + os.symlink(sys.executable, os.path.join(proton, "wine")) + relative = dict(env, WINE=os.path.join("Proton 9.0", "files", "bin", "wine")) + result = subprocess.check_output([launcher, "--dry-run"], cwd=self.root, env=relative) + self.assertEqual(json.loads(result)[:2], [real(self.game), ["--dry-run", "./" + image, "--overlay", + "Z:" + real(self.out) + "/overlay"]]) + work = os.path.join(self.out, "Shader cache '$HOME'") make_game.runtime(self.game, self.out, {"expected_exe": image}, self.build, work=work) moved = self.out + " moved" diff --git a/tests/test_make_game_wave64.py b/tests/test_make_game_wave64.py index 74d36ecbbc..59e4dad20f 100644 --- a/tests/test_make_game_wave64.py +++ b/tests/test_make_game_wave64.py @@ -52,11 +52,11 @@ def test_no_subgroup_size_gives_none(self): class Wave64EmulateTest(unittest.TestCase): """wave64_emulate(): on and off are taken as given; auto asks vulkaninfo and falls back to on.""" - def decide(self, mode, which="vulkaninfo", stdout="", error=None): + def decide(self, mode, which="vulkaninfo", stdout="", error=None, returncode=0): def fake_run(args, **kw): if error: raise error - return subprocess.CompletedProcess(args, 0, stdout=stdout, stderr="") + return subprocess.CompletedProcess(args, returncode, stdout=stdout, stderr="") with mock.patch.object(make_game.shutil, "which", return_value=which), \ mock.patch.object(make_game.subprocess, "run", side_effect=fake_run) as run, \ mock.patch.object(make_game, "log", lambda *a: None): @@ -84,6 +84,10 @@ def test_auto_when_vulkaninfo_cannot_run_turns_it_on(self): self.assertTrue(self.decide("auto", error=OSError("cannot start"))[0]) self.assertTrue(self.decide("auto", error=subprocess.TimeoutExpired("vulkaninfo", 120))[0]) + def test_auto_ignores_partial_stdout_when_vulkaninfo_fails(self): + partial = real_format(("First adapter", 64, [])) + self.assertEqual(self.decide("auto", stdout=partial, returncode=1), (True, True)) + def test_auto_when_vulkaninfo_prints_no_subgroup_size_turns_it_on(self): self.assertTrue(self.decide("auto", stdout="ERROR: no Vulkan device\n")[0])