feat(shaders): add shareable shader/pipeline recording (.hints) and offline precompilation #530
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/gamingwithhomie--larp!530
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-530"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@Mvii7 on GitHub · 2026-12-06 01:55 UTC · original
Mvii7:feat/shader-recording-precompile→main· +2028 −9 · 15 files · 5 commits · openSummary
Adds chenxiao07/KytyPS5-style shareable shader/pipeline recordings (
.hints), automatic bundled.hintsimport on launch, and standalone offline precompilation (larp shaders precompile— translating shaders and compiling host D3D12 pipelines directly from<cache_dir>\pipelines\without loading or launchinggame_scarlett_master.exe, avoiding the game window and title RAM/VRAM footprint).Both paths write into the exact same
shaders\andpipelines\blobs*\cache:larp run --execute): Drop a.hintsfile inLarp\hints\(orLarp\/Larp\bin\), andlarpautomatically imports it before startup warmup so the normal startup precompile bar compiles everything with zero extra user steps.larp shaders precompile): Precompile shaders and host D3D12 pipelines ahead of time from the CLI without booting the game (e.g. after a GPU driver update or from a script).What's included
crates/larp-pipeline/src/recording.rs:LRPSHD01zlib-compressed, BLAKE3-checksummed recording format packingcreated-pipelines.bin+quad-pipelines.txt(zero copyrighted game shader bytecode — hashes and D3D12 state subobjects only), with--frommerging, validation, fast 48-byte header checksum reads (read_header_checksum), safequad-pipelines.txtnewline-boundary handling, andapply_to_cache_dir.crates/larp-gpu/src/pipeline/precompile.rs(plusblobs.rs,host.rs,make.rs,larp-hle/src/modules/d3d12x.rs): standalone shader translation + host D3D12 pipeline precompilation (no title executable loaded), skipping already-cached blobs (including compute viaWarmMode::All), suppressing theE_ABORTskip warning for compute pipelines, and flushing the async blob writer before exit.apps/larp/src/shaders_cmd.rs+apps/larp/src/run.rs+apps/larp/src/main.rs:.hintsdiscovery & import onlarp run --execute(before startup pipeline warmup) andlarp shaders precompile(when no file arg is passed), scanningLarp\hints\,Larp\,Larp\bin\hints\,Larp\bin\, orLARP_SHADERS_HINTS(0/offdisables). Deduplicates only after full decode and stamps<cache_dir>\pipelines\imported-hints.txtper-bundle only when all referenced shaders are resolved, so repeat launches skip in <1 ms while partial imports retry cleanly.larp shaders export <out.hints> [--from <file.hints>...] [--no-local] [--build <label>]larp shaders info <file.hints>larp shaders import <file.hints> [<game_path>...] [--jobs <N>]larp shaders precompile [<file.hints>] [--game <path>...] [--jobs <N>] [--shaders-only]docs/environment-variables.md: CLI andLARP_SHADERS_HINTSdocumentation.Release & Community Workflow (Building One Master
.hintsFile).hintsfile (~1 MB for ~88k pipelines, zero game code;--buildis optional and just stores an informational label forshaders info):.hintsfile (--from): Maintainers can deduplicate and combine any number of community-submitted.hintsfiles (plus the previous release's master.hints) into a single master file:.hintsfile intoLarp\hints\(orLarp\/Larp\bin\) in the release ZIP.larp run --execute),larpresolves the shader hashes against the user's own game files and feeds all recorded pipelines straight into the normal startup precompile bar. Repeat launches skip already-imported.hintsin <1 ms, and interrupted precompiles resume from already-cachedshaders\andblobs*\.Testing (Windows native,
x86_64-pc-windows-msvc, rebased onmain/ PR #376)cargo test -p larp-pipeline: 6/6 passed (including quad-mask newline-boundary and unreadable-catalog tests).cargo test -p larp shaders_cmd::tests: 4/4 passed (complete,partial,empty,duplicateretry/dedup cases).cargo build --release -p larp: clean build.54.7 MBcreated-pipelines.bin+10.1 KBquad-pipelines.txt):88,604→88,611) and +28 quad-mask variants (278→306).larp shaders export→1029.8 KiB.hintsfile (~53× compression, zero game shader code),19,059unique shaders (1,167VS,8,525PS,2,682CS,6,685MS).larp shaders info→ BLAKE3 checksum verified (checksum ok).importinto a clean cache against game files: matched 19,059 / 19,059 shaders in36.5 s, resolved 88,604 / 88,604 pipelines +278quad variants (0missing)..hintsimport + mixed 60-pipelineprecompile(20 graphics VS+PS + 20 mesh MS+PS + 20 compute CS +shader-replace.dxils):LARP_SHADERS_HINTS): matched40 / 40shaders, compiled60 / 60(0failed,3.6 s), stampedimported-hints.txt.imported-hints.txt,0new,60 / 60already cached (40from shader cache,0warnings,0.6 s).@Heliumrich on GitHub · 2026-12-06 02:02 UTC · original
Do these hints get outdated with code changes ?
Like will we get graphical bugs if we use old hints on a way more recent build of this project ?
Or at worst just useless garbage shader files polluting our disk of a few GBs
@Mvii7 on GitHub · 2026-12-06 02:51 UTC · original
No graphical bugs on newer larp builds: .hints files don't store any translated DXIL, replacement shaders, or GPU driver blobs — they only store the console shader hashes and D3D12 pipeline state recipes the game itself asks for. When larp's translator, shader-replace, or root signature changes, larp translates and compiles those pipelines using the new build's translator and replacement shaders (and shaders/ + blobs*/ are already keyed by translator output + host state + driver).
What actually invalidates a .hints file: Mainly a game update that changes shader binaries (unmatched hashes are cleanly skipped on import without error), or a future breaking change to created-pipelines.bin's wire format (VICPSOS1), which Recording::decode validates and rejects safely.
Disk usage: The .hints file itself is only ~1 MB for ~88k pipelines, and importing deduplicates against your existing created-pipelines.bin / created-shaders.bin — it only populates the same files larp would create as you play through those areas. If a major translator change ever leaves old cached shaders/ or blobs*/ files behind, you can wipe cache\ just like today and larp will automatically re-import the .hints file and rebuild cleanly on the next launch.
@christopear on GitHub · 2026-12-06 02:56 UTC · original
I reproduced two retry problems in bundled auto-import on
8fc37b836. Both can leave valid recipes out of the local catalog even when all the required inputs are available on the next run.Incomplete imports get a permanent success stamp. I made one valid recording with two compute recipes, each referencing a different synthetic container. On the first call I supplied only one container, then supplied both on calls two and three. The catalog stayed at 1, 1, 1. With neither container initially available it stayed at 0, 0, 0. Both runs wrote the checksum on the first call. The complete control gave 2, 2, 2 and correctly skipped subsequent work.
An earlier broken copy can hide a valid bundle. Put the first 48 bytes of a valid recording in
a.hintsand the complete file inb.hintsin the same discovery directory. With both containers available the catalog stayed empty. The first header reserves the checksum before payload validation, so the good copy is never tried.I ran each case three times using the PR's auto-import and discovery functions in a Linux test harness, with the real recording encoder, decoder and cache writer. Only the game scanner was replaced with a deterministic fixture lookup. The four existing recording tests also passed.
Two small changes confirmed the diagnosis. Deduplicate new candidates only after successful decoding, and withhold completion stamps while recipes are unresolved. All four cases then reached two recipes by the second call and skipped work on the third, in three repetitions each.
For production I'd distinguish a partial import from a completed one per bundle. A clear retry option for partial imports would avoid rescanning permanently unmatched game versions every launch. The fully resolved fast path can stay as it is. This is separate from invalidating translated shaders after a code change.
Standalone regression fixture for this revision
In a disposable checkout, save the Rust block as
crates/larp-pipeline/tests/retry.rs(create the tests directory if needed). Append the unmodified import and discovery functions from the CLI, then run each case in a fresh temporary directory. The printed tuples give the return value, catalog count and whether the stamp file exists.@Mvii7 on GitHub · 2026-12-06 03:03 UTC · original
Great catch @christopear — thanks for the detailed repro and regression harness! Fixed both in
0f084e6:auto_import_bundled_hints_withnow skips only checksums already inimported-hints.txtduring the header pass, and only records a checksum inseen_decodedafterRecording::read_fromsucceeds — so an earlier truncated/corrupt file with a valid 48-byte header can no longer shadow a valid bundle.imported-hints.txtwhen all of its referenced shaders are resolved (either already cached or matched in the scan). Unresolved/partial bundles remain unstamped so they retry when missing game files become available (with a message notingLARP_SHADERS_HINTS=0to skip rescanning if intentionally running against a mismatched game version).apps/larp/src/shaders_cmd.rs(shaders_cmd::tests) covering all four cases (complete,partial,empty, andduplicate) — all 4 pass (cargo test -p larp shaders_cmd::tests).@christopear on GitHub · 2026-12-06 03:09 UTC · original
Retested
0f084e6. Both of my earlier findings are resolved in the fixture tests. All four of your cases passed.I also tried overlapping bundles in the same import, with the incomplete one first. Bundle A needed shader a, bundle B needed a/b/c.
That covers the case where a successfully imported bundle shares a shader with one that needs a retry. I ran the CLI import functions and tests in a native Rust harness with the real recording/cache code and a fixture scanner. No game run or archive scanning involved. Thanks for fixing these!
@christopear on GitHub · 2026-12-06 03:15 UTC · original
One separate writer needs the same boundary handling as #575. That PR only changes the GPU runtime writer. This branch also appends to quad-pipelines.txt in
recording::apply_to_cache_dir.I started with a complete 32-character key A lacking its final newline, then auto-imported a valid one-recipe bundle containing key B. The import reported success, stamped the bundle and skipped the next call. Reading the catalog returned one 64-character AB entry. Neither exact key survived. I also checked an invalid UTF-8 catalog, where treating a read error as an empty file lets the append report success.
Here's an applicable patch against
0f084e6. It reuses the text already read for deduplication, preserves the existing bytes and propagates read errors other than absence. It assumes a single writer. It prevents new joins and leaves previously joined entries alone.Both new library tests failed on the original implementation in three runs. With the patch all six library tests passed three times. The stamped auto-import reproduction also passed in six native Rust fixture runs with the production import functions and a synthetic scanner. No gameplay testing.
Patch and regression tests
@Mvii7 on GitHub · 2026-12-06 03:20 UTC · original
Good catch again @christopear — applied your patch and both regression tests in
6d146aa. All 6larp-pipelinetests pass.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.