diff options
| author | Vonsek <45567075+Vonsek@users.noreply.github.com> | 2026-11-22 17:59:18 +0100 |
|---|---|---|
| committer | Vonsek <45567075+Vonsek@users.noreply.github.com> | 2026-11-22 17:59:18 +0100 |
| commit | d3fab00a78967adf357596996190afdf33dc09d5 (patch) | |
| tree | 031945fa8bf52a74033db421631478f4674c5b92 /tools/first_light.py | |
| parent | 49475796c226c8511b9470bf97a4daf57b8af323 (diff) | |
fix(build): preserve first-light shader identities
Vertex and pixel shaders can share a display name while having distinct carved files. Carry the selected stage and exact file through translation lookup and publication.
Diffstat (limited to 'tools/first_light.py')
| -rw-r--r-- | tools/first_light.py | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/tools/first_light.py b/tools/first_light.py index 6fe7899ce..c81c1d6d7 100644 --- a/tools/first_light.py +++ b/tools/first_light.py | |||
| @@ -72,13 +72,14 @@ def ensure_carve(game: str, work: str) -> str: | |||
| 72 | def choose(index_path: str, vs: str, ps: str) -> list[dict]: | 72 | def choose(index_path: str, vs: str, ps: str) -> list[dict]: |
| 73 | with open(index_path, encoding="utf-8") as f: | 73 | with open(index_path, encoding="utf-8") as f: |
| 74 | entries = json.load(f) | 74 | entries = json.load(f) |
| 75 | by_name = {e["name"]: e for e in entries} | 75 | by_stage_and_name = {(entry["stage"], entry["name"]): entry for entry in entries} |
| 76 | missing = [n for n in (vs, ps) if n not in by_name] | 76 | requested = (("vs", vs), ("ps", ps)) |
| 77 | missing = [f"{stage} {name}" for stage, name in requested if (stage, name) not in by_stage_and_name] | ||
| 77 | if missing: | 78 | if missing: |
| 78 | raise SystemExit( | 79 | raise SystemExit( |
| 79 | f"shader not in the carve index: {', '.join(missing)} (use --list)" | 80 | f"shader not in the carve index: {', '.join(missing)} (use --list)" |
| 80 | ) | 81 | ) |
| 81 | return [by_name[vs], by_name[ps]] | 82 | return [by_stage_and_name[key] for key in requested] |
| 82 | 83 | ||
| 83 | 84 | ||
| 84 | def translate(work: str, picked: list[dict]) -> dict: | 85 | def translate(work: str, picked: list[dict]) -> dict: |
| @@ -121,12 +122,10 @@ def translate(work: str, picked: list[dict]) -> dict: | |||
| 121 | meta = json.load(f) | 122 | meta = json.load(f) |
| 122 | result = {} | 123 | result = {} |
| 123 | for entry in picked: | 124 | for entry in picked: |
| 124 | key = entry["name"] | 125 | stem = os.path.splitext(entry["file"])[0] |
| 125 | item = meta.get(key) | 126 | item = meta.get(stem) |
| 126 | if item is None: # a duplicate name gets a ~1 suffix | ||
| 127 | item = next((v for k, v in meta.items() if k.startswith(key)), None) | ||
| 128 | if item is None or item.get("stage") != entry["stage"]: | 127 | if item is None or item.get("stage") != entry["stage"]: |
| 129 | raise SystemExit(f"translator has no {entry['stage']} result for {key}") | 128 | raise SystemExit(f"translator has no {entry['stage']} result for {stem}") |
| 130 | result[entry["stage"]] = item | 129 | result[entry["stage"]] = item |
| 131 | return result | 130 | return result |
| 132 | 131 | ||
| @@ -454,14 +453,13 @@ def main(argv=None) -> int: | |||
| 454 | picked = choose(index, a.vs, a.ps) | 453 | picked = choose(index, a.vs, a.ps) |
| 455 | meta = translate(work, picked) | 454 | meta = translate(work, picked) |
| 456 | os.makedirs(out_dir, exist_ok=True) | 455 | os.makedirs(out_dir, exist_ok=True) |
| 457 | shutil.copy( | 456 | for entry in picked: |
| 458 | os.path.join(work, "first_light", "spirv", f"{picked[0]['name']}.spv"), | 457 | stem = os.path.splitext(entry["file"])[0] |
| 459 | os.path.join(out_dir, "vs.spv"), | 458 | stage = entry["stage"] |
| 460 | ) | 459 | shutil.copy( |
| 461 | shutil.copy( | 460 | os.path.join(work, "first_light", "spirv", f"{stem}.spv"), |
| 462 | os.path.join(work, "first_light", "spirv", f"{picked[1]['name']}.spv"), | 461 | os.path.join(out_dir, f"{stage}.spv"), |
| 463 | os.path.join(out_dir, "ps.spv"), | 462 | ) |
| 464 | ) | ||
| 465 | vertices, indices = read_obj(a.obj) if a.obj else ([], []) | 463 | vertices, indices = read_obj(a.obj) if a.obj else ([], []) |
| 466 | obj_sha256 = None | 464 | obj_sha256 = None |
| 467 | if a.obj: | 465 | if a.obj: |