Add the shared pipeline list: mesh pipelines players met are built at the shader preparation, before the first start.

The preparation translates every shader and builds each one's stage library, so a pipeline a draw meets for the first time is linked in 2 to 6 ms. A mesh pipeline has no stage libraries: on an install that never drew it, it compiles whole in play, 0.2 to 1.1 s with its draws left out of the picture (18 of them on a first visit of Kokiri Forest). Whole pipelines were built ahead only from the folder's own pipeline-keys.bin.

tools/pipeline_list.py merge folds the pipeline-keys.bin and shader-answers.bin of game folders that were played into one list file: every key record once, with the answers record of each shader it names. A record names its shaders by input id, which depends on the game's code and the answers alone, and holds the game's pipeline state; what depends on the GPU is derived when the pipeline is built, so a record made on one machine is good on another with the same game version and runtime. Four folders on this PC give 5,432 records, 317 of them mesh pipelines (147 KB of keys).

tools/prepare_shaders.py reads the list (tools/data/pipeline_list.bin, data/pipeline_list.bin in a release folder, or --pipeline-list), adds its shader variants to the seed and writes its records as seed-pipeline-keys.bin. nx2navi.exe --prepare-shaders builds the mesh pipelines among them after the seed is translated and saves the pipeline cache before the stage libraries are built (NX2NAVI_PREPARE_PIPELINES=all builds the vertex pipelines too); --warm-shaders does it again after an update or a new driver, and --prepare-pipelines is that step alone. The pipelines go into the caches and are not kept or added to the folder's own key file, so they cost no start-up time or video memory until a draw meets them. A marker file keeps a driver that crashes on one of them from failing every preparation.

The list is derived from game data and stays out of the repository: check_content.py refuses files recorded from a game folder by their first bytes, and make_kit.py, make_launcher.py and make_release.py carry a list given with --pipeline-list. All three now also carry pipeline_list.py, which prepare_shaders.py imports.

Checked without the game: tests/pipeline_list_test.py, and prepare_shaders.py --no-run on the game files with a list of 317 mesh pipelines (all 266 shader variants found in this game version, 177 new to the seed). The build step in nx2navi.exe compiles and links and has not been run.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
chrg6
2026-11-10 14:52:46 -05:00
parent 682d9c5c50
commit 918d399d55
15 changed files with 627 additions and 14 deletions

View File

@@ -91,6 +91,23 @@ def compiled_shader(path: Path) -> bool:
return path.suffix.lower() == ".spv" or path.name.lower().endswith("_spv.h")
# What a game folder records in play and what tools/pipeline_list.py folds from it: the game's shader code, the
# answers it was translated for, the pipelines it drew. All of it is derived from game data.
RECORD_MAGICS = (b"NX2NSPRG", b"NX2NSANS", b"NX2NPKEY", b"NX2NPLST")
def recorded_in_play(path: Path, data: bytes | None) -> bool:
"""A shader-programs.bin, shader-answers.bin, pipeline-keys.bin or a pipeline list, by its first bytes. A build kit
or a release folder may carry a pipeline list (data/pipeline_list.bin), so make_kit.py and make_release.py, which
call problems_for, are not held to this."""
if data is None:
if not path.is_file():
return False
with open(path, "rb") as f:
data = f.read(8)
return data[:8] in RECORD_MAGICS
def main() -> int:
parser = argparse.ArgumentParser(description=__doc__.splitlines()[0])
parser.add_argument("--staged", action="store_true", help="check staged files only")
@@ -100,9 +117,12 @@ def main() -> int:
for path in list_files(args.staged):
# --staged checks what the commit takes: a marker staged and then removed from the working copy alone
# passed when the file on disk was read
problems = problems_for(path, data=staged_bytes(path) if args.staged else None)
data = staged_bytes(path) if args.staged else None
problems = problems_for(path, data=data)
if compiled_shader(path):
problems.append("compiled shader: the repository holds the source, tools/build_shaders.py builds this")
if recorded_in_play(path, data):
problems.append("recorded from a game folder (shaders, answers, pipeline keys or a pipeline list)")
for problem in problems:
print(f"{path}: {problem}")
failed = True