From 7811ea868f7d9b2ccb8e140a54b8e6632c55c8e6 Mon Sep 17 00:00:00 2001 From: x2Tweek Date: Tue, 24 Nov 2026 09:25:18 +0100 Subject: [PATCH 1/5] Translator: --shader-list to translate only a subset of shaders Add --shader-list FILE to rdna2spirv.py and make_game.py so only the shaders whose stems are listed in FILE are translated, instead of all 26,503. This cuts retranslation time for testing translator changes on a small subset of the corpus. make_game.py skips verify_translation_completeness() when --shader-list is given (the subset index is intentionally incomplete) and drops any previous full index before re-translating. rdna2spirv.py reads the list of shader stems (one per line) and filters the .s files from the disassembly directory before translation, after the existing --limit and --shard filters. Tested on a 5-shader subset: exactly 5 translated, index.json has 5 entries. No game data, no translator rule changed. Co-Authored-By: Claude Code --- make_game.py | 28 ++++++++++++++++++++-------- tools/rdna2spirv.py | 11 +++++++++++ 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/make_game.py b/make_game.py index 3eb089945..d230b8619 100644 --- a/make_game.py +++ b/make_game.py @@ -1233,7 +1233,7 @@ def translated_index_is_empty(index: str) -> bool: def shaders(game: str, work: str, jobs: int, emulate: bool = False, keep_emulated: bool = False, - fallbacks: tuple[str, ...] = ()) -> None: + fallbacks: tuple[str, ...] = (), shader_list: str | None = None) -> None: src = os.path.join(game, "shaders.rpf") sh = os.path.join(work, "shaders") dxbc = os.path.join(sh, "dxbc") @@ -1341,8 +1341,14 @@ def shaders(game: str, work: str, jobs: int, emulate: bool = False, keep_emulate f.write(want_flags + "\n") with open(sources_file, "w", encoding="utf-8", newline="\n") as f: f.write(sources + "\n") - translate(disasm, spirv, jobs, emulate=emulate, fallbacks=fallbacks) - verify_translation_completeness(dxbc, spirv) + if shader_list is not None: + # A subset translation never reuses a previous full index: drop it so only the listed shaders + # are translated and the merged index names just them. + drop(translated) + translate(disasm, spirv, jobs, emulate=emulate, fallbacks=fallbacks, + shader_list=shader_list) + if shader_list is None: + verify_translation_completeness(dxbc, spirv) native_pso_hashes(dxbc, spirv) fspx_shaders(game, work, signature, emulate=emulate, fallbacks=fallbacks) bvh_shaders(game, work, signature, jobs, emulate=emulate, fallbacks=fallbacks) @@ -2035,7 +2041,7 @@ def _stop_procs(procs: list) -> None: def translate(disasm: str, spirv: str, jobs: int, emulate: bool = False, - fallbacks: tuple[str, ...] = ()) -> None: + fallbacks: tuple[str, ...] = (), shader_list: str | None = None) -> None: """rdna2spirv.py runs on one core: start one --shard per job side by side, then merge their index parts. A shard publishes shard.json and then index.part.json. Both are needed to reuse it. A run stopped @@ -2069,6 +2075,8 @@ def translate(disasm: str, spirv: str, jobs: int, emulate: bool = False, tool = os.path.join(TOOLS, "rdna2spirv.py") extra = ["--wave64-emulate"] if emulate else [] extra.extend(fallbacks) + if shader_list is not None: + extra.extend(["--shader-list", shader_list]) if todo: which = f"0..{jobs - 1}" if len(todo) == jobs else ",".join(str(i) for i in todo) log(f" rdna2spirv.py {disasm} --out {spirv} --shard {which}/{jobs}" + "".join(" " + e for e in extra)) @@ -2884,7 +2892,7 @@ def _invoke_stage(name: str, fn) -> None: def run_build_stages(stages: list, *, game: str, work: str, out: str, v: dict, wav: bool, jobs: int, runtime_build: str | None, emulate: bool, keep_emulated: bool, - fallbacks: tuple[str, ...], overlap: bool = True) -> None: + fallbacks: tuple[str, ...], shader_list: str | None, overlap: bool = True) -> None: """Run build stages after check. With overlap=True (default), shaders/assets/runtime share the machine and pipelines starts once shaders (and a selected runtime rebuild) are ready. With overlap=False, stages run in order.""" cpu_heavy = [s for s in ("shaders", "assets") if s in stages] @@ -2894,7 +2902,8 @@ def run_build_stages(stages: list, *, game: str, work: str, out: str, v: dict, w progress = StageBoard([s for s in ("shaders", "assets", "runtime", "pipelines") if s in stages]) def fn_shaders(): - shaders(game, work, shader_jobs, emulate=emulate, keep_emulated=keep_emulated, fallbacks=fallbacks) + shaders(game, work, shader_jobs, emulate=emulate, keep_emulated=keep_emulated, + fallbacks=fallbacks, shader_list=shader_list) def fn_assets(): assets(game, work, wav, jobs, dump_jobs=dump_jobs) @@ -3039,6 +3048,9 @@ def main() -> int: help="keep s0..s31 in 128 push-constant bytes and move heap/code base to a set-1 uniform " "block; on by itself when the runtime's GPU reports maxPushConstantsSize below what " "the shaders need (144, or 152 with --mesh-compute)") + ap.add_argument("--shader-list", metavar="FILE", type=nonempty_path, + help="translate only shaders whose stem is listed in FILE (one stem per line); " + "skips the completeness check, for testing on a subset instead of all 26,503") ap.add_argument("--no-tui", action="store_true", help="plain console logs (default when stdout is not a TTY); skip the LEONIDA setup screen " "and per-stage log view") @@ -3173,12 +3185,12 @@ def main() -> int: tui_board.set_summary(f"build 0% ยท {', '.join(build_stages)}") run_build_stages(stages, game=game, work=work, out=out, v=v, wav=a.wav, jobs=a.jobs, runtime_build=runtime_build, emulate=emulate, keep_emulated=keep_emulated, - fallbacks=fallbacks, overlap=overlap) + fallbacks=fallbacks, shader_list=a.shader_list, overlap=overlap) tui_board.set_summary(f"finished in {(time.time() - t0) / 60:.0f} min") else: run_build_stages(stages, game=game, work=work, out=out, v=v, wav=a.wav, jobs=a.jobs, runtime_build=runtime_build, emulate=emulate, keep_emulated=keep_emulated, - fallbacks=fallbacks, overlap=overlap) + fallbacks=fallbacks, shader_list=a.shader_list, overlap=overlap) log(f"finished in {(time.time() - t0) / 60:.0f} min") return 0 diff --git a/tools/rdna2spirv.py b/tools/rdna2spirv.py index 936de535a..5f62b9bf4 100644 --- a/tools/rdna2spirv.py +++ b/tools/rdna2spirv.py @@ -19445,6 +19445,9 @@ def main(): ap.add_argument("--shard", type=_shard_arg, help="i/n: translate every n-th shader starting at i (run n processes in parallel, " "then merge the index.part*.json files with --merge)") + ap.add_argument("--shader-list", default=None, + help="only translate shaders whose stem is in this file (one stem per line); " + "used to translate a subset of the corpus without rebuilding all 26,503") ap.add_argument("--no-asm", action="store_true", help="delete each .spvasm once its .spv is written (the text is ~2.7x the binary: 35 GB for the corpus)") ap.add_argument("--assembler", choices=("spirv-as", "python"), default="spirv-as", @@ -19608,6 +19611,14 @@ def main(): files = files[:a.limit] if shard is not None: files = files[shard::sn] + if a.shader_list is not None: + wanted = set() + with open(a.shader_list, encoding="utf-8") as f: + for line in f: + name = line.strip() + if name: + wanted.add(name) + files = [p for p in files if os.path.splitext(os.path.basename(p))[0] in wanted] why, ok, valid = Counter(), 0, 0 meta = {} invalid = set() From 3fd9e04dedbba352e4359faf085ddc0c2a05b222 Mon Sep 17 00:00:00 2001 From: x2Tweek Date: Tue, 24 Nov 2026 09:30:39 +0100 Subject: [PATCH 2/5] Translator: --shader-list writes subset to separate dir, never touches full index When --shader-list is given, write the subset translation to /subset/ instead of the main / directory. Never drop or overwrite the existing full index.json. The full index always survives a subset translation run. verify_translation_completeness() is only called for full translations. Co-Authored-By: Claude Code --- make_game.py | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/make_game.py b/make_game.py index d230b8619..d8039bb91 100644 --- a/make_game.py +++ b/make_game.py @@ -1320,12 +1320,14 @@ def shaders(game: str, work: str, jobs: int, emulate: bool = False, keep_emulate log(f"shaders: the fallback flags are now {want_flags or 'none'} (the shaders were translated with " f"{had_flags or 'none'}): translating again") drop(translated) - if os.path.isfile(translated) and translated_index_is_empty(translated): - # An empty merge, or an index that cannot be read, is not a finished translation. The shard plan goes with it: - # its parts are what the empty merge read, so a retry has to translate them again rather than reuse them. - log("shaders: the saved translated index names no shaders: translating again") - drop(translated, shard_plan) - if not os.path.isfile(translated): + if shader_list is not None: + # Subset translation: write to a separate directory, never touch the full index. + subset_spirv = os.path.join(spirv, "subset") + os.makedirs(subset_spirv, exist_ok=True) + log(f"shaders: translating listed shaders to {subset_spirv}") + translate(disasm, subset_spirv, jobs, emulate=emulate, fallbacks=fallbacks, + shader_list=shader_list) + elif not os.path.isfile(translated): need("spirv-as", "Install the Vulkan SDK (it includes spirv-as and spirv-val) and reopen the terminal.") need("spirv-val", "Install the Vulkan SDK and reopen the terminal.") if "--compact-spirv" in fallbacks: @@ -1341,13 +1343,7 @@ def shaders(game: str, work: str, jobs: int, emulate: bool = False, keep_emulate f.write(want_flags + "\n") with open(sources_file, "w", encoding="utf-8", newline="\n") as f: f.write(sources + "\n") - if shader_list is not None: - # A subset translation never reuses a previous full index: drop it so only the listed shaders - # are translated and the merged index names just them. - drop(translated) - translate(disasm, spirv, jobs, emulate=emulate, fallbacks=fallbacks, - shader_list=shader_list) - if shader_list is None: + translate(disasm, spirv, jobs, emulate=emulate, fallbacks=fallbacks) verify_translation_completeness(dxbc, spirv) native_pso_hashes(dxbc, spirv) fspx_shaders(game, work, signature, emulate=emulate, fallbacks=fallbacks) From 6f18bc09d2dfcb1cef3fb6e05bcf12862fe9ec83 Mon Sep 17 00:00:00 2001 From: x2Tweek Date: Tue, 24 Nov 2026 09:41:06 +0100 Subject: [PATCH 3/5] Translator: --shader-list never touches the full index; add tests When --shader-list is given, write the subset to /subset/ and skip all full-index fingerprint checks (translator digest, wave64 mode, fallback flags). The existing spirv/index.json is never read, dropped, or overwritten by a subset run. Carving/unpacking/disassembly no longer drop the full index when a subset is requested. Adds tests: - tests/test_make_game_empty_translation.py: full index survives a subset translation run; translate() is called with the subset dir and the shader list. - tests/test_rdna2spirv_cli.py: --shader-list filters .s files by stem, only listed shaders are translated and indexed. Co-Authored-By: Claude Code --- make_game.py | 126 ++++++++++++---------- tests/test_make_game_empty_translation.py | 58 ++++++++++ tests/test_rdna2spirv_cli.py | 30 ++++++ 3 files changed, 157 insertions(+), 57 deletions(-) diff --git a/make_game.py b/make_game.py index d8039bb91..bc45604c9 100644 --- a/make_game.py +++ b/make_game.py @@ -1249,11 +1249,14 @@ def shaders(game: str, work: str, jobs: int, emulate: bool = False, keep_emulate signature = llvm_mc_signature() if not os.path.isfile(carved): log("shaders: carving shaders.rpf") - drop(translated, shard_plan, disassembled, disassembly_started, unpacked) + # A subset translation writes to its own directory and never touches the full index, so don't drop it. + if shader_list is None: + drop(translated, shard_plan, disassembled, disassembly_started, unpacked) py("shader_carve.py", src, dxbc) if unpacked_shader_stems(dxbc) is None: log("shaders: unpacking native code") - drop(translated, shard_plan, disassembled, disassembly_started) + if shader_list is None: + drop(translated, shard_plan, disassembled, disassembly_started) py("fssm_unpack.py", dxbc, "--carve-index", carved) # rdna2spirv.py finds index.json, the .dxbc files and fssm/ in the parent of the .s files' folder, so the # disassembly must sit inside the carve folder: next to it, every stage reads as "?" and is rejected. @@ -1263,7 +1266,8 @@ def shaders(game: str, work: str, jobs: int, emulate: bool = False, keep_emulate if os.path.isfile(disassembled) or os.path.isfile(translated): log("shaders: llvm-mc changed or the saved disassembly could not be verified") log("shaders: resuming disassembly (gfx1013)" if resume else "shaders: disassembling (gfx1013)") - drop(translated, shard_plan) + if shader_list is None: + drop(translated, shard_plan) if not resume: drop(disassembly_started, disassembled) prepare_shader_disassembly(work, disasm, resume) @@ -1286,65 +1290,73 @@ def shaders(game: str, work: str, jobs: int, emulate: bool = False, keep_emulate f.write("\n") os.replace(marker, disassembled) drop(disassembly_started) - # The translation also depends on the translator's own files, so their digest is kept beside it. A folder without - # it (from before the file existed), with an unreadable one or with another one is translated again; carving, unpacking and - # disassembly stay current. - sources_file = os.path.join(spirv, "translation_sources.sha256") - sources = translation_sources_digest() - if os.path.isfile(translated) and read_shader_setting(sources_file) != sources: - log("shaders: no matching translator fingerprint for the existing shaders: translating again") - drop(translated) - # The translation depends on --wave64-emulate, so the mode it was made with is kept beside it. A folder from - # before the file existed was translated without emulation. - mode_file = os.path.join(spirv, "wave64_emulate.txt") - had = read_shader_setting(mode_file, default="off") - want = requested_shader_mode(had, emulate, keep_emulated) - if want == "on" and not emulate: - # auto answers differently from run to run (a GPU asleep or hidden, vulkaninfo missing); emulated shaders are - # exact on every GPU, so they are kept rather than translating the whole corpus again. When they are - # translated again for another reason, or a stopped translation is retried, they stay emulated. - log("shaders: the shaders were translated with wave64 emulation and it stays on (exact on every GPU); " - "--wave64-emulate off translates them natively") - emulate = True - elif had != want and os.path.isfile(translated): - log(f"shaders: wave64 emulation is now {want} (the shaders were translated with it {had}): " - "translating again") - drop(translated) - # The translation also depends on the fallback flags (--no-float-controls, --bary-fallback, - # --texel-offset-fallback, --mesh-compute), so they are kept beside it like the wave64 mode. A folder from - # before the file existed was translated without them. - flags_file = os.path.join(spirv, "translator_flags.txt") - want_flags = translator_flags_setting(fallbacks) - had_flags = read_shader_setting(flags_file) - if had_flags != want_flags and os.path.isfile(translated): - log(f"shaders: the fallback flags are now {want_flags or 'none'} (the shaders were translated with " - f"{had_flags or 'none'}): translating again") - drop(translated) if shader_list is not None: - # Subset translation: write to a separate directory, never touch the full index. + # Subset translation: write to a separate directory, never touch the full index. None of the full-index + # fingerprint checks (translator digest, wave64 mode, fallback flags) apply: we never read or overwrite + # spirv/index.json, and we never call verify_translation_completeness(). subset_spirv = os.path.join(spirv, "subset") os.makedirs(subset_spirv, exist_ok=True) log(f"shaders: translating listed shaders to {subset_spirv}") translate(disasm, subset_spirv, jobs, emulate=emulate, fallbacks=fallbacks, shader_list=shader_list) - elif not os.path.isfile(translated): - need("spirv-as", "Install the Vulkan SDK (it includes spirv-as and spirv-val) and reopen the terminal.") - need("spirv-val", "Install the Vulkan SDK and reopen the terminal.") - if "--compact-spirv" in fallbacks: - need("spirv-opt", "Install SPIRV-Tools with spirv-opt to use --compact-spirv.") - log(f"shaders: translating RDNA2 to SPIR-V on {jobs} processes (the longest step)") - # The mode and the translator's digest go down before the translation starts, while there is no index.json: - # a stop at any point then leaves either no index (translated again) or an index with the right mode and - # digest, never a guessed one. rdna2spirv.py --merge writes index.json last, after the stubs. - os.makedirs(spirv, exist_ok=True) - with open(mode_file, "w", encoding="utf-8", newline="\n") as f: - f.write(want + "\n") - with open(flags_file, "w", encoding="utf-8", newline="\n") as f: - f.write(want_flags + "\n") - with open(sources_file, "w", encoding="utf-8", newline="\n") as f: - f.write(sources + "\n") - translate(disasm, spirv, jobs, emulate=emulate, fallbacks=fallbacks) - verify_translation_completeness(dxbc, spirv) + else: + # Full translation with fingerprint checks: the translator's own files, wave64 mode and fallback flags + # all gate reuse of the saved index. + sources_file = os.path.join(spirv, "translation_sources.sha256") + sources = translation_sources_digest() + if os.path.isfile(translated) and read_shader_setting(sources_file) != sources: + log("shaders: no matching translator fingerprint for the existing shaders: translating again") + drop(translated) + # The translation depends on --wave64-emulate, so the mode it was made with is kept beside it. A folder from + # before the file existed was translated without emulation. + mode_file = os.path.join(spirv, "wave64_emulate.txt") + had = read_shader_setting(mode_file, default="off") + want = requested_shader_mode(had, emulate, keep_emulated) + if want == "on" and not emulate: + # auto answers differently from run to run (a GPU asleep or hidden, vulkaninfo missing); emulated + # shaders are exact on every GPU, so they are kept rather than translating the whole corpus again. + # When they are translated again for another reason, or a stopped translation is retried, they stay + # emulated. + log("shaders: the shaders were translated with wave64 emulation and it stays on (exact on every GPU); " + "--wave64-emulate off translates them natively") + emulate = True + elif had != want and os.path.isfile(translated): + log(f"shaders: wave64 emulation is now {want} (the shaders were translated with it {had}): " + "translating again") + drop(translated) + # The translation also depends on the fallback flags (--no-float-controls, --bary-fallback, + # --texel-offset-fallback, --mesh-compute), so they are kept beside it like the wave64 mode. A folder from + # before the file existed was translated without them. + flags_file = os.path.join(spirv, "translator_flags.txt") + want_flags = translator_flags_setting(fallbacks) + had_flags = read_shader_setting(flags_file) + if had_flags != want_flags and os.path.isfile(translated): + log(f"shaders: the fallback flags are now {want_flags or 'none'} (the shaders were translated with " + f"{had_flags or 'none'}): translating again") + drop(translated) + if os.path.isfile(translated) and translated_index_is_empty(translated): + # An empty merge, or an index that cannot be read, is not a finished translation. The shard plan goes + # with it: its parts are what the empty merge read, so a retry has to translate them again rather than + # reuse them. + log("shaders: the saved translated index names no shaders: translating again") + drop(translated, shard_plan) + if not os.path.isfile(translated): + need("spirv-as", "Install the Vulkan SDK (it includes spirv-as and spirv-val) and reopen the terminal.") + need("spirv-val", "Install the Vulkan SDK and reopen the terminal.") + log(f"shaders: translating RDNA2 to SPIR-V on {jobs} processes (the longest step)") + # The mode and the translator's digest go down before the translation starts, while there is no + # index.json: a stop at any point then leaves either no index (translated again) or an index with the + # right mode and digest, never a guessed one. rdna2spirv.py --merge writes index.json last, after the + # stubs. + os.makedirs(spirv, exist_ok=True) + with open(mode_file, "w", encoding="utf-8", newline="\n") as f: + f.write(want + "\n") + with open(flags_file, "w", encoding="utf-8", newline="\n") as f: + f.write(want_flags + "\n") + with open(sources_file, "w", encoding="utf-8", newline="\n") as f: + f.write(sources + "\n") + translate(disasm, spirv, jobs, emulate=emulate, fallbacks=fallbacks) + verify_translation_completeness(dxbc, spirv) native_pso_hashes(dxbc, spirv) fspx_shaders(game, work, signature, emulate=emulate, fallbacks=fallbacks) bvh_shaders(game, work, signature, jobs, emulate=emulate, fallbacks=fallbacks) @@ -2888,7 +2900,7 @@ def _invoke_stage(name: str, fn) -> None: def run_build_stages(stages: list, *, game: str, work: str, out: str, v: dict, wav: bool, jobs: int, runtime_build: str | None, emulate: bool, keep_emulated: bool, - fallbacks: tuple[str, ...], shader_list: str | None, overlap: bool = True) -> None: + fallbacks: tuple[str, ...] = (), shader_list: str | None = None, overlap: bool = True) -> None: """Run build stages after check. With overlap=True (default), shaders/assets/runtime share the machine and pipelines starts once shaders (and a selected runtime rebuild) are ready. With overlap=False, stages run in order.""" cpu_heavy = [s for s in ("shaders", "assets") if s in stages] diff --git a/tests/test_make_game_empty_translation.py b/tests/test_make_game_empty_translation.py index 0d310226b..15ce89dce 100644 --- a/tests/test_make_game_empty_translation.py +++ b/tests/test_make_game_empty_translation.py @@ -171,6 +171,64 @@ def test_a_stale_index_after_a_failed_shard_that_cannot_be_removed(self): self.assertIn("rdna2spirv.py: shard 0 exited with 1.", self.failure('{"old": {}}', shard_code=1)) +class ShadersStageSubsetTest(unittest.TestCase): + """shaders() with --shader-list: writes to a separate subset directory, never touches the full index.""" + + def setUp(self): + tmp = tempfile.TemporaryDirectory() + self.addCleanup(tmp.cleanup) + self.work = tmp.name + self.dxbc = os.path.join(self.work, "shaders", "dxbc") + self.spirv = os.path.join(self.work, "shaders", "spirv") + os.makedirs(self.dxbc) + os.makedirs(self.spirv) + # Pre-populate a full index that must survive the subset run. + write(self.index(), json.dumps({"shader_full": {"stage": "ps", "fssm_sha256": "deadbeef"}})) + + def index(self): + return os.path.join(self.spirv, "index.json") + + def run_stage(self, shader_list=None): + calls = [] + + def fake_py(tool, *args): + if tool == "shader_carve.py": + write(os.path.join(self.dxbc, "index.json"), json.dumps([{"file": "shader.dxbc"}])) + elif tool == "fssm_unpack.py": + write(os.path.join(self.dxbc, "fssm_index.json"), json.dumps([{"name": "shader"}])) + elif tool == "shader_disasm.py": + write(os.path.join(self.dxbc, "disasm", "shader.s"), "synthetic listing\n") + + def fake_translate(disasm, spirv, jobs, emulate=False, fallbacks=(), shader_list=None): + calls.append((spirv, shader_list)) + os.makedirs(spirv, exist_ok=True) + write(os.path.join(spirv, "index.json"), json.dumps({"shader_subset": {"stage": "ps"}})) + + with mock.patch.object(make_game, "py", fake_py), \ + mock.patch.object(make_game, "need", lambda *a: None), \ + mock.patch.object(make_game, "translate", fake_translate), \ + mock.patch.object(make_game, "llvm_mc_signature", return_value="test llvm-mc 21"), \ + mock.patch.object(make_game, "log", lambda *a: None): + make_game.shaders(os.path.join(self.work, "game"), self.work, 2, shader_list=shader_list) + return calls + + def test_subset_translates_to_subset_dir_and_full_index_survives(self): + calls = self.run_stage(shader_list=["shader_subset"]) + # translate() was called once, with the subset directory and the shader list + self.assertEqual(len(calls), 1) + spirv_dir, sl = calls[0] + self.assertEqual(spirv_dir, os.path.join(self.spirv, "subset")) + self.assertEqual(sl, ["shader_subset"]) + # The full index is untouched. + with open(self.index(), encoding="utf-8") as f: + self.assertEqual(json.load(f), {"shader_full": {"stage": "ps", "fssm_sha256": "deadbeef"}}) + # The subset index exists with just the subset entry. + subset_index = os.path.join(self.spirv, "subset", "index.json") + self.assertTrue(os.path.exists(subset_index)) + with open(subset_index, encoding="utf-8") as f: + self.assertEqual(json.load(f), {"shader_subset": {"stage": "ps"}}) + + class RequireTranslatedShadersTest(unittest.TestCase): def setUp(self): tmp = tempfile.TemporaryDirectory() diff --git a/tests/test_rdna2spirv_cli.py b/tests/test_rdna2spirv_cli.py index 6ce0777e6..c991c53c8 100644 --- a/tests/test_rdna2spirv_cli.py +++ b/tests/test_rdna2spirv_cli.py @@ -164,6 +164,36 @@ def test_a_new_output_folder_with_missing_parents_still_works(self): self.assertIn("1 pass spirv-val", stdout) self.assertTrue((out / "ps_ok.spv").is_file()) + def test_shader_list_filters_translated_shaders(self): + # Only stems listed in --shader-list are translated; others in the folder are skipped. + with tempfile.TemporaryDirectory() as tmp: + src = os.path.join(tmp, "disasm") + os.mkdir(src) + with open(os.path.join(src, "ps_keep.s"), "w", encoding="utf-8") as f: + f.write("\ts_endpgm\n") + with open(os.path.join(src, "ps_skip.s"), "w", encoding="utf-8") as f: + f.write("\ts_endpgm\n") + with open(os.path.join(tmp, "ps_keep.dxbc"), "wb") as f: + f.write(b"DXBC" + bytes(28)) + with open(os.path.join(tmp, "ps_skip.dxbc"), "wb") as f: + f.write(b"DXBC" + bytes(28)) + list_file = os.path.join(tmp, "list.txt") + with open(list_file, "w", encoding="utf-8", newline="\n") as f: + f.write("ps_keep\n") + out = os.path.join(tmp, "spirv") + p = subprocess.run([sys.executable, "-I", TOOL, src, "--out", out, + "--shader-list", list_file, + "--no-asm", "--no-validate", "--assembler", "python"], + capture_output=True, text=True, errors="replace") + self.assertEqual(p.returncode, 0, p.stderr) + self.assertIn("1 translated", p.stdout) + self.assertTrue(os.path.exists(os.path.join(out, "ps_keep.spv"))) + self.assertFalse(os.path.exists(os.path.join(out, "ps_skip.spv"))) + # The index names only the listed shader. + with open(os.path.join(out, "index.json"), encoding="utf-8") as f: + index = json.load(f) + self.assertEqual(set(index), {"ps_keep"}) + def test_non_s_file_as_src_is_refused_with_usage_error(self): with tempfile.TemporaryDirectory() as tmp: src = os.path.join(tmp, "notes.txt") From c3d151561145efeae4a33a91a58fc854031f05be Mon Sep 17 00:00:00 2001 From: x2Tweek Date: Wed, 25 Nov 2026 00:38:16 +0100 Subject: [PATCH 4/5] make_game: include shader list content in shard plan identity When --shader-list is used, the shard plan (shards.json) did not hash the list file's contents, so overwriting the same list with a different selection and reusing the output folder kept the old shards instead of re-translating the newly requested entries. Add a sha256 of the list contents to the plan so a changed list is detected as a plan mismatch, dropping the old parts and starting only the missing shards. Adds SubsetListIdentityTest covering: same list reuses finished shards, changed list re-translates, and overwriting the same file path with new content re-translates. Co-Authored-By: Claude Code --- make_game.py | 9 ++++- tests/test_shader_stage_resume.py | 63 +++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 2 deletions(-) diff --git a/make_game.py b/make_game.py index bc45604c9..9c3280e71 100644 --- a/make_game.py +++ b/make_game.py @@ -2054,12 +2054,17 @@ def translate(disasm: str, spirv: str, jobs: int, emulate: bool = False, A shard publishes shard.json and then index.part.json. Both are needed to reuse it. A run stopped part-way, or during the merge, keeps those parts when it resumes with the same --jobs, wave64 mode, fallback - flags and translator source, and starts only the shards that have none. shaders() drops the plan whenever an - earlier step reruns.""" + flags, translator source and shader list, and starts only the shards that have none. shaders() drops the plan + whenever an earlier step reruns.""" os.makedirs(spirv, exist_ok=True) plan_path = os.path.join(spirv, SHARD_PLAN) plan = {"jobs": jobs, "wave64_emulate": bool(emulate), "fallbacks": list(fallbacks), "translator": translator_digest()} + if shader_list is not None: + # The list content is part of the plan identity: overwriting the same list file with a different + # selection must not reuse shards translated for the old list. + with open(shader_list, "rb") as f: + plan["shader_list"] = hashlib.sha256(f.read()).hexdigest() try: with open(plan_path, encoding="utf-8") as f: same = json.load(f) == plan diff --git a/tests/test_shader_stage_resume.py b/tests/test_shader_stage_resume.py index e3645dbc5..aec1319d1 100644 --- a/tests/test_shader_stage_resume.py +++ b/tests/test_shader_stage_resume.py @@ -531,6 +531,69 @@ def test_a_kill_right_after_a_merge_for_new_sources_keeps_the_translation(self): self.assertEqual(self.run_stage(), []) # hours of translation are not redone +class SubsetListIdentityTest(unittest.TestCase): + """The shard plan's identity must include the shader list content, so changing the list + (even overwriting the same file) re-translates instead of reusing stale shards.""" + + def setUp(self): + self.tmp = tempfile.TemporaryDirectory() + self.addCleanup(self.tmp.cleanup) + self.spirv = os.path.join(self.tmp.name, "spirv") + os.makedirs(self.spirv) + self.list_path = os.path.join(self.tmp.name, "shaders.txt") + self.write_list("s0\ns1\n") + self.popen_calls = [] + self.popen_patch = mock.patch.object(make_game.subprocess, "Popen", self.fake_popen) + self.popen_patch.start() + self.addCleanup(self.popen_patch.stop) + self.py_patch = mock.patch.object(make_game, "py", lambda *a, **k: None) + self.py_patch.start() + self.addCleanup(self.py_patch.stop) + + def write_list(self, content): + with open(self.list_path, "w", encoding="utf-8", newline="\n") as f: + f.write(content) + + def fake_popen(self, cmd, **kw): + self.popen_calls.append(list(cmd)) + proc = mock.Mock() + proc.wait.return_value = 0 + proc.poll.return_value = 0 + return proc + + def finish_shards(self, jobs=2): + """Simulate finished shards from a previous translation.""" + for i in range(jobs): + with open(os.path.join(self.spirv, f"index.part{i}.json"), "w", encoding="utf-8", newline="\n") as f: + json.dump({}, f) + with open(os.path.join(self.spirv, f"shard{i}.json"), "w", encoding="utf-8", newline="\n") as f: + json.dump({}, f) + + def test_same_list_reuses_finished_shards(self): + make_game.translate("disasm", self.spirv, 2, shader_list=self.list_path) + self.popen_calls.clear() + self.finish_shards() + make_game.translate("disasm", self.spirv, 2, shader_list=self.list_path) + self.assertEqual(self.popen_calls, [], "same list and finished shards: nothing to translate") + + def test_changed_list_retranslates(self): + make_game.translate("disasm", self.spirv, 2, shader_list=self.list_path) + self.popen_calls.clear() + self.finish_shards() + self.write_list("s2\ns3\n") + make_game.translate("disasm", self.spirv, 2, shader_list=self.list_path) + self.assertNotEqual(self.popen_calls, [], "changed list: plan mismatch, re-translate") + + def test_overwriting_same_file_retranslates(self): + make_game.translate("disasm", self.spirv, 2, shader_list=self.list_path) + self.popen_calls.clear() + self.finish_shards() + # Overwrite the same file with different content + self.write_list("s2\ns3\n") + make_game.translate("disasm", self.spirv, 2, shader_list=self.list_path) + self.assertNotEqual(self.popen_calls, [], "same path, new content: plan mismatch, re-translate") + + class TranslationSourcesTest(unittest.TestCase): def test_the_list_covers_the_translator_and_native_catalog_imports(self): seen, todo = set(), ["rdna2spirv", "native_pso_hashes"] From e89c29128b37cfd5a0a6cd7190dccd4a017309cb Mon Sep 17 00:00:00 2001 From: x2Tweek Date: Wed, 25 Nov 2026 09:18:55 +0100 Subject: [PATCH 5/5] Restore the full translation spirv-opt preflight --- make_game.py | 2 ++ tests/test_make_game_empty_translation.py | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/make_game.py b/make_game.py index 9c3280e71..55ae31e8b 100644 --- a/make_game.py +++ b/make_game.py @@ -1343,6 +1343,8 @@ def shaders(game: str, work: str, jobs: int, emulate: bool = False, keep_emulate if not os.path.isfile(translated): need("spirv-as", "Install the Vulkan SDK (it includes spirv-as and spirv-val) and reopen the terminal.") need("spirv-val", "Install the Vulkan SDK and reopen the terminal.") + if "--compact-spirv" in fallbacks: + need("spirv-opt", "Install SPIRV-Tools with spirv-opt to use --compact-spirv.") log(f"shaders: translating RDNA2 to SPIR-V on {jobs} processes (the longest step)") # The mode and the translator's digest go down before the translation starts, while there is no # index.json: a stop at any point then leaves either no index (translated again) or an index with the diff --git a/tests/test_make_game_empty_translation.py b/tests/test_make_game_empty_translation.py index 15ce89dce..7cbaa2504 100644 --- a/tests/test_make_game_empty_translation.py +++ b/tests/test_make_game_empty_translation.py @@ -280,7 +280,7 @@ def index(self): def plan(self): return os.path.join(self.spirv, make_game.SHARD_PLAN) - def run_stage(self): + def run_stage(self, fallbacks=(), need_tool=lambda *a: None): ran = [] def fake_py(tool, *args): @@ -296,11 +296,11 @@ def fake_translate(disasm, spirv, jobs, emulate=False, fallbacks=()): write(os.path.join(self.spirv, "index.json"), json.dumps({"shader_0": {"stage": "ps"}})) with mock.patch.object(make_game, "py", fake_py), \ - mock.patch.object(make_game, "need", lambda *a: None), \ + mock.patch.object(make_game, "need", need_tool), \ mock.patch.object(make_game, "translate", fake_translate), \ mock.patch.object(make_game, "llvm_mc_signature", return_value="test llvm-mc 21"), \ mock.patch.object(make_game, "log", lambda *a: None): - make_game.shaders(os.path.join(self.work, "game"), self.work, 2) + make_game.shaders(os.path.join(self.work, "game"), self.work, 2, fallbacks=fallbacks) return ran def test_an_empty_saved_index_is_translated_again_without_its_plan(self): @@ -310,6 +310,15 @@ def test_an_empty_saved_index_is_translated_again_without_its_plan(self): self.assertEqual(self.run_stage(), ["translate"]) self.assertFalse(os.path.exists(self.plan())) + def test_full_compact_translation_checks_for_spirv_opt_before_starting(self): + def need_tool(name, _hint): + if name == "spirv-opt": + raise SystemExit(1) + + with self.assertRaises(SystemExit): + self.run_stage(fallbacks=("--compact-spirv",), need_tool=need_tool) + self.assertFalse(os.path.exists(self.index())) + def test_a_saved_index_that_names_a_shader_is_kept(self): self.run_stage() self.assertEqual(self.run_stage(), [])