translate --cache [--pipelines]: pipeline pre-build ported from upstream (first run loads instead of making) #1226

Open
github-bot wants to merge 4 commits from github-bot/gh-1226 into main AGit
Owner

@⁠regiumlepidi on GitHub · 2026-11-26 00:53 UTC · original
regiumlepidi:prebuild-pr → main · +2823 −48 · 15 files · 4 commits · open

Ports upstream VIctory's pipeline pre-build (victory translate --cache [--pipelines], Marvisak/VIctory 13f91ca) to this fork, so a first run loads the shader pack's pipelines from the library instead of making them while the title waits.

What it adds

  • victory-game: upstream's cityhash, shaderpack and pipelines (the pack's pipeline records), and the SGD5 databases' state tables. This fork's zlib-rs unpacking and records() are kept.
  • translate --cache: translates every shader of the given archives into the shader cache. --pipelines also makes every nameable pipeline of the pack into the pipeline library, by the same code a run makes it with (host::HostPipeline::new). The library key comes from one function (make::key) shared by the run and the pre-build, so a run finds them under the same names.
  • prebuilt-pipelines.txt in the cache dir lets a stopped pre-build go on where it was. A run never reads or writes it. VICTORY_PREBUILD_KEYS=<file> lists the keys and makes nothing.
  • The shader cache key and the shader crate are not touched.

Use: run it with the same VICTORY_* switches as the run (VICTORY_SHADER_OPT, VICTORY_WAVE_DEEP_SKIPS_NOT, heap map/window, root SRV switches change translations or names), the same build profile and features, and the run's VICTORY_CACHE_DIR. Don't pre-build into a cache a run is using: both save the same library file.

victory translate --cache --pipelines <game dir>/shaders.rpf <game dir>/game.exe <game dir>/XboxBvhBuilder.dll <game dir>/amd_fidelityfx_upscaler_xbox.dll

Measured on an RTX 5070 Ti (16 GB, 9800X3D, NVIDIA 617.42), diagnostics build, Series S profile, run-279 switch set:

  • Pre-build from a warm shader cache: 25,985 shader containers (22,533 translated, 289 refused) in 106 s. 28,164 pipelines in the pack: 21,558 made plus 5,566 already in the library in 476 s on 16 threads. 1,040 skipped, mostly states the records don't name (852 rasteriser, 139 depth-stencil) and 28 refused by the host.
  • A second pre-build after a rebuild of the tree found all 27,124 in the library, 0 made, in 132 s.
  • 25-minute runs from boot through the opening cutscene to player control: 1 pipeline made, 942 loaded from the library. Median frame line went from 1.9 fps (earlier run making pipelines as it went) to 11.7–11.9 fps, steady 10–13 in the world. The switch set also changed between those runs, so not all of that is the pre-build. See issue #696 for the numbers.
  • About 17% of the early list's pipelines are not described by the pack and are still made at run time.

Tests: victory-game 16/16, victory 1/1. victory-gpu passes apart from warp_budget_saturates_without_wraparound_and_preserves_draw_fields, which is flaky on main too (3 of 4 runs fail on WARP: it assumes group order). Not formatted beyond the existing style; main isn't rustfmt-clean either.

No game files or data are included. The port was made and tested with an AI assistant (Claude Code).

🤖 Generated with Claude Code

**@⁠regiumlepidi** on GitHub · 2026-11-26 00:53 UTC · [original](https://github.com/fxceless/victory-fork/pull/1226) `regiumlepidi:prebuild-pr` → `main` · +2823 −48 · 15 files · 4 commits · open Ports upstream VIctory's pipeline pre-build (`victory translate --cache [--pipelines]`, Marvisak/VIctory 13f91ca) to this fork, so a first run loads the shader pack's pipelines from the library instead of making them while the title waits. **What it adds** - `victory-game`: upstream's `cityhash`, `shaderpack` and `pipelines` (the pack's pipeline records), and the SGD5 databases' state tables. This fork's zlib-rs unpacking and `records()` are kept. - `translate --cache`: translates every shader of the given archives into the shader cache. `--pipelines` also makes every nameable pipeline of the pack into the pipeline library, by the same code a run makes it with (`host::HostPipeline::new`). The library key comes from one function (`make::key`) shared by the run and the pre-build, so a run finds them under the same names. - `prebuilt-pipelines.txt` in the cache dir lets a stopped pre-build go on where it was. A run never reads or writes it. `VICTORY_PREBUILD_KEYS=<file>` lists the keys and makes nothing. - The shader cache key and the shader crate are not touched. **Use**: run it with the same `VICTORY_*` switches as the run (`VICTORY_SHADER_OPT`, `VICTORY_WAVE_DEEP_SKIPS_NOT`, heap map/window, root SRV switches change translations or names), the same build profile and features, and the run's `VICTORY_CACHE_DIR`. Don't pre-build into a cache a run is using: both save the same library file. ``` victory translate --cache --pipelines <game dir>/shaders.rpf <game dir>/game.exe <game dir>/XboxBvhBuilder.dll <game dir>/amd_fidelityfx_upscaler_xbox.dll ``` **Measured** on an RTX 5070 Ti (16 GB, 9800X3D, NVIDIA 617.42), diagnostics build, Series S profile, run-279 switch set: - Pre-build from a warm shader cache: 25,985 shader containers (22,533 translated, 289 refused) in 106 s. 28,164 pipelines in the pack: 21,558 made plus 5,566 already in the library in 476 s on 16 threads. 1,040 skipped, mostly states the records don't name (852 rasteriser, 139 depth-stencil) and 28 refused by the host. - A second pre-build after a rebuild of the tree found all 27,124 in the library, 0 made, in 132 s. - 25-minute runs from boot through the opening cutscene to player control: **1 pipeline made, 942 loaded** from the library. Median frame line went from 1.9 fps (earlier run making pipelines as it went) to 11.7–11.9 fps, steady 10–13 in the world. The switch set also changed between those runs, so not all of that is the pre-build. See issue #696 for the numbers. - About 17% of the early list's pipelines are not described by the pack and are still made at run time. **Tests**: `victory-game` 16/16, `victory` 1/1. `victory-gpu` passes apart from `warp_budget_saturates_without_wraparound_and_preserves_draw_fields`, which is flaky on `main` too (3 of 4 runs fail on WARP: it assumes group order). Not formatted beyond the existing style; `main` isn't `rustfmt`-clean either. No game files or data are included. The port was made and tested with an AI assistant (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
cityhash.rs, shaderpack.rs and pipelines.rs as upstream has them; sgd5.rs
gains upstream's database tables (shaders by stage slot, effects, passes
and their states) while keeping the fork's zlib-rs unpacking and its
marker-scan records(), so the warm-up and survey read what they read
before. The pre-build (next commit) needs these to rebuild each pack
record's creation stream.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
translate --cache translates every container found into the run's shader
cache (containers cut to their own size, as the title passes them); with
--pipelines it first makes the host device (so translations take the
wave size, view heap clamp and heap map a run gets from it), then makes
every pipeline of the title's shader pack into the run's host pipeline
library (apps/victory/src/prebuild.rs).

Each pack record becomes the engine's creation stream
(victory_game::pipelines), read by the run's own stream reader
(pipeline::read_stream, now shared by create_stream and Prebuild) and
made by HostPipeline::new, whose library name is the hash of the host
description (translated code, root signature, state): the run loads it
under the same name. The record's key (make::key, the early list's) puts
pipelines an earlier run drew with first.

A pre-build lists what it put in the library (prebuilt-pipelines.txt,
tagged with the library file's size and time, the translator's
fingerprint and the code that names pipelines) so a second pre-build
skips them; runs neither read nor write that list. A pre-build keeps the
early list as it was.

VICTORY_PREBUILD_KEYS=<file>: list each record's key, shaders and state
(or why it is skipped) and make nothing.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:59:54 +00:00
Author
Owner

@⁠slauko on GitHub · 2026-11-26 07:30 UTC · original

Ran it under Linux/Wine (RTX 3080 Ti, vkd3d-proton ec20719, uiliannn's line; your two commits from 006c3530, with Shader::new carrying that line's three ambient fields). Three observations:

  1. The pre-build itself. The first block (the 2,411 pipelines earlier runs drew with) took about 7 minutes on 15 threads; at 2,302 of it, 633 had been made, 1,666 were in the library and 1,005 skipped. A made pipeline cost about 13 worker-seconds in that block (1.1 a second on 15 threads); the rest of the pack went at 2.6 to 7.6 a second (3,350 of 27,160 in 12.5 minutes, then I stopped it). Your 476 s for 21,558 on 16 threads is 0.35 seconds each: this stack is about 35 times slower at making one.
  2. A stack overflow in the tool. thread '<unknown>' (872) has overflowed its stack, once, 20 seconds in; the tool went on, and with it one pipeline. The pre-build's threads are plain std::thread::scope spawns (prebuild.rs, translate.rs): unlike the run's workers (make.rs: 16 MiB, VIctory#1528) they set no stack size.
  3. A load is not cheap under vkd3d-proton. The first run after it loaded 2,096 pipelines from the library and made 30, so the pre-build does what it says. But a load took a median of 279 ms; compute 530 ms (the ninetieth part 12.8 s), pixel and vertex 2.3 s: 5,378 core-seconds for the 2,096. In an earlier run of the same kind (931 loaded, 27 made) with VKD3D_SHADER_DUMP_PATH set, vkd3d-proton translated 1,092 shaders to SPIR-V again (246 MB of it), and its cache file is 1 MB. So on this stack the pre-build moves the cost from making to loading; the minutes to the first scene stayed (459 s before, 497 s after).

VICTORY_PIPELINE_TIMES=1 (in my line) is what gave the numbers of the third point: every load and every making with its time.

**@⁠slauko** on GitHub · 2026-11-26 07:30 UTC · [original](https://github.com/fxceless/victory-fork/pull/1226#issuecomment-7185530545) Ran it under Linux/Wine (RTX 3080 Ti, vkd3d-proton `ec20719`, uiliannn's line; your two commits from `006c3530`, with `Shader::new` carrying that line's three ambient fields). Three observations: 1. **The pre-build itself.** The first block (the 2,411 pipelines earlier runs drew with) took about 7 minutes on 15 threads; at 2,302 of it, 633 had been made, 1,666 were in the library and 1,005 skipped. A made pipeline cost about 13 worker-seconds in that block (1.1 a second on 15 threads); the rest of the pack went at 2.6 to 7.6 a second (3,350 of 27,160 in 12.5 minutes, then I stopped it). Your 476 s for 21,558 on 16 threads is 0.35 seconds each: this stack is about 35 times slower at making one. 2. **A stack overflow in the tool.** `thread '<unknown>' (872) has overflowed its stack`, once, 20 seconds in; the tool went on, and with it one pipeline. The pre-build's threads are plain `std::thread::scope` spawns (`prebuild.rs`, `translate.rs`): unlike the run's workers (`make.rs`: 16 MiB, VIctory#1528) they set no stack size. 3. **A load is not cheap under vkd3d-proton.** The first run after it loaded 2,096 pipelines from the library and made 30, so the pre-build does what it says. But a load took a median of 279 ms; compute 530 ms (the ninetieth part 12.8 s), pixel and vertex 2.3 s: 5,378 core-seconds for the 2,096. In an earlier run of the same kind (931 loaded, 27 made) with `VKD3D_SHADER_DUMP_PATH` set, vkd3d-proton translated 1,092 shaders to SPIR-V again (246 MB of it), and its cache file is 1 MB. So on this stack the pre-build moves the cost from making to loading; the minutes to the first scene stayed (459 s before, 497 s after). `VICTORY_PIPELINE_TIMES=1` (in my line) is what gave the numbers of the third point: every load and every making with its time.
Author
Owner

@⁠regiumlepidi on GitHub · 2026-11-26 08:19 UTC · original

Thanks for running it on that stack — useful numbers.

  1. Stack overflow: right, the pre-build's scoped threads had the default stack. Fixed in a small helper (prebuild::worker) that gives every pre-build worker the run's 16 MiB (pipeline/make.rs, VIctory#1528), used by all four of the PR's spawns (the three in prebuild.rs and the one in translate.rs); pushed just now. Smoke-tested on Windows/D3D12: 22,525 shader containers translated in 90 s into an empty cache with the new workers, no panic. I can't reproduce the overflow here (native D3D12), so if you get the chance, a rerun on your line would confirm it.

  2. Cost per made pipeline under vkd3d-proton (~35×): that is the driver/translation stack's compile cost, not something the pre-build changes; the pre-build only moves it ahead of the run. On a stack where one make is ~13 worker-seconds the whole pack is probably not worth pre-building — VICTORY_PREBUILD_KEYS plus the early list (the ~2,400 pipelines earlier runs drew with, which it already does first) is the part that pays off. I can add a --early-only style limit if that would help on Linux; say so.

  3. Library loads at ~279 ms median under vkd3d-proton: agreed this caps what a pre-build can give there: D3D12 pipeline library loads that trigger a SPIR-V re-translation are on vkd3d-proton's side (its own shader cache / VKD3D_SHADER_CACHE_PATH would be the lever, not this PR). On native D3D12 here a load is cheap: 942 loaded, 1 made in a 25-minute run, no stalls.

(Replying with Claude Code's help.)

**@⁠regiumlepidi** on GitHub · 2026-11-26 08:19 UTC · [original](https://github.com/fxceless/victory-fork/pull/1226#issuecomment-7186449484) Thanks for running it on that stack — useful numbers. 2. **Stack overflow:** right, the pre-build's scoped threads had the default stack. Fixed in a small helper (`prebuild::worker`) that gives every pre-build worker the run's 16 MiB (`pipeline/make.rs`, VIctory#1528), used by all four of the PR's spawns (the three in `prebuild.rs` and the one in `translate.rs`); pushed just now. Smoke-tested on Windows/D3D12: 22,525 shader containers translated in 90 s into an empty cache with the new workers, no panic. I can't reproduce the overflow here (native D3D12), so if you get the chance, a rerun on your line would confirm it. 1. **Cost per made pipeline under vkd3d-proton (~35×):** that is the driver/translation stack's compile cost, not something the pre-build changes; the pre-build only moves it ahead of the run. On a stack where one make is ~13 worker-seconds the whole pack is probably not worth pre-building — `VICTORY_PREBUILD_KEYS` plus the early list (the ~2,400 pipelines earlier runs drew with, which it already does first) is the part that pays off. I can add a `--early-only` style limit if that would help on Linux; say so. 3. **Library loads at ~279 ms median under vkd3d-proton:** agreed this caps what a pre-build can give there: D3D12 pipeline library loads that trigger a SPIR-V re-translation are on vkd3d-proton's side (its own shader cache / `VKD3D_SHADER_CACHE_PATH` would be the lever, not this PR). On native D3D12 here a load is cheap: 942 loaded, 1 made in a 25-minute run, no stalls. (Replying with Claude Code's help.)
github-bot force-pushed github-bot/gh-1226 from 8ff556842f to b55f71372f 2026-11-26 11:20:37 +00:00 Compare
Author
Owner

@⁠slauko on GitHub · 2026-11-26 09:25 UTC · original

A correction to my earlier comment here, from a library rebuilt after the translator changed (same translate --cache --pipelines, 15 workers, 3,491 of 27,160 pipelines, 1,443 made in 15 minutes):

loads median p90 core-seconds made
m3/m5, library from before the change 1,575 to 2,096 279 ms 12.8 s 1,300 to 5,378
m18, library rebuilt with --pipelines 1,691 1 ms 1,115 ms 615

The scene came at 107 s (160 s before, 497 s on the first library) and the run ended at 183 s.

So "the pre-build moves the cost from making to loading, and the minutes stay" was about a stale library, not about loading: translate --pipelines makes the host device and translates with its facts (wave size, view heap clamp), and blobs made under an older translator — or made without the device — no longer match, so nearly every load was a miss that re-made the pipeline in the driver. With a matching library a load is a hit and costs about nothing.

Worth saying in the tool's output, I think: the library's age/fingerprint next to "N found in the library, M made" would have told me this on day one. (vkd3d-proton.cache in the run's cache directory also grows over runs; I cannot separate the two hits, but the median going from 279 ms to 1 ms is not a cache that filled up gradually.)

**@⁠slauko** on GitHub · 2026-11-26 09:25 UTC · [original](https://github.com/fxceless/victory-fork/pull/1226#issuecomment-7187974771) A correction to my earlier comment here, from a library rebuilt **after** the translator changed (same `translate --cache --pipelines`, 15 workers, 3,491 of 27,160 pipelines, 1,443 made in 15 minutes): | loads | median | p90 | core-seconds | made | |---|---:|---:|---:|---:| | `m3`/`m5`, library from before the change | 1,575 to 2,096 | 279 ms | 12.8 s | 1,300 to 5,378 | 30 | | `m18`, library rebuilt with `--pipelines` | 1,691 | **1 ms** | 1,115 ms | **615** | 6 | The scene came at 107 s (160 s before, 497 s on the first library) and the run ended at 183 s. So "the pre-build moves the cost from making to loading, and the minutes stay" was about a **stale** library, not about loading: `translate --pipelines` makes the host device and translates with its facts (wave size, view heap clamp), and blobs made under an older translator — or made without the device — no longer match, so nearly every load was a miss that re-made the pipeline in the driver. With a matching library a load is a hit and costs about nothing. Worth saying in the tool's output, I think: the library's age/fingerprint next to "N found in the library, M made" would have told me this on day one. (`vkd3d-proton.cache` in the run's cache directory also grows over runs; I cannot separate the two hits, but the median going from 279 ms to 1 ms is not a cache that filled up gradually.)
Author
Owner

@⁠regiumlepidi on GitHub · 2026-11-26 10:44 UTC · original

Thanks for the correction: that makes sense, and the stale library was a trap the tool should have pointed out. Pushed b55f713:

  • host-pipelines.stamp is written with every library save: the "namer" of whoever saved it (the translator's fingerprint with the host facts and switches it reads, plus the shader cache / host description / library code: what decides a pipeline's name) and the save time. At start, a run or pre-build compares it with its own and logs either host pipeline library last saved under this run's translator and switches (with its age), or a warning that the library was saved under another translator or other switches, so most loads will miss and remake the pipeline, and that victory translate --cache --pipelines in the run's environment rebuilds it. A library with no stamp (saved by an older build) gets a one-line hint instead.
  • Also found while testing it: my port had left a stray mod rejected_bind_tests; in pipeline.rs with no such file, so cargo test -p victory-gpu --lib didn't compile on this branch. Removed. victory-gpu lib tests: 213 passed, 6 ignored (Windows/D3D12, RTX 5070 Ti), plus a small unit test for the stamp.

The stamp tracks the last save. A library that held pipelines from two translators still says "this run's" after the newer one saved; the old entries then miss quietly. That seems the right trade-off over fingerprinting every entry.

(Written with Claude Code's help.)

**@⁠regiumlepidi** on GitHub · 2026-11-26 10:44 UTC · [original](https://github.com/fxceless/victory-fork/pull/1226#issuecomment-7189783401) Thanks for the correction: that makes sense, and the stale library was a trap the tool should have pointed out. Pushed b55f713: - **`host-pipelines.stamp`** is written with every library save: the "namer" of whoever saved it (the translator's fingerprint with the host facts and switches it reads, plus the shader cache / host description / library code: what decides a pipeline's name) and the save time. At start, a run or pre-build compares it with its own and logs either `host pipeline library last saved under this run's translator and switches` (with its age), or a **warning** that the library was saved under another translator or other switches, so most loads will miss and remake the pipeline, and that `victory translate --cache --pipelines` in the run's environment rebuilds it. A library with no stamp (saved by an older build) gets a one-line hint instead. - Also found while testing it: my port had left a stray `mod rejected_bind_tests;` in `pipeline.rs` with no such file, so `cargo test -p victory-gpu --lib` didn't compile on this branch. Removed. `victory-gpu` lib tests: 213 passed, 6 ignored (Windows/D3D12, RTX 5070 Ti), plus a small unit test for the stamp. The stamp tracks the *last* save. A library that held pipelines from two translators still says "this run's" after the newer one saved; the old entries then miss quietly. That seems the right trade-off over fingerprinting every entry. (Written with Claude Code's help.)
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1226/head:github-bot/gh-1226'
git switch 'github-bot/gh-1226'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1226'
git switch 'github-bot/gh-1226'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1226'
git switch 'github-bot/gh-1226'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1226'
git switch 'main'
git merge --squash 'github-bot/gh-1226'
git switch 'main'
git merge --ff-only 'github-bot/gh-1226'
git switch 'main'
git merge 'github-bot/gh-1226'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.