Skip to content

Add offline shader and pipeline precompilation - #282

Closed
t4l03 wants to merge 2 commits into
fxceless:mainfrom
t4l03:feature/offline-shader-precompile
Closed

t4l03 wants to merge 2 commits into
fxceless:mainfrom
t4l03:feature/offline-shader-precompile

Conversation

@t4l03

@t4l03 t4l03 commented Nov 24, 2026

Copy link
Copy Markdown

Summary

  • Add victory translate --cache to populate the runtime shader cache from local shader packs and containers. Entries follow the translator, effective settings and adapter shader capabilities, so app-only rebuilds can reuse them.
  • Add --pipelines to populate the host D3D12 pipeline library. Use --used-pipelines to focus on exact keys recorded by earlier runs while still translating all shader inputs.
  • Add versioned, checksummed cache records and atomic publication. Cache deterministic unsupported shader results and retry malformed inputs or storage failures.

Related work

#147 proposes translator-based keys and early-worker scheduling. #35 and #199 address specific wave-mode inputs to cache keys. This PR adds offline shader translation and host pipeline creation. The cache-key changes overlap those PRs.

Verification

  • 134 targeted tests passed across victory, victory-game, victory-gpu and victory-pipeline. One existing benchmark was ignored.
  • Clippy passed for the affected app, GPU, pipeline and translator crates with all targets and features. cargo xtask policy passed.
  • On the nightly integration build, the RTX 4070 Ti warm-up translated 25,722 shader entries and built 1,772 host pipelines from earlier run history. An app-only relink reused all 25,722 successful translations. The next live run recorded 2,378 cache hits and zero misses through frame 1,024. The heavy scenes still ran at roughly 1–2 FPS.

AI-assisted.

Adapt upstream VIctory commits c47b529 and 9c58a1c to the fork GPU runtime and retain the fork pipeline library. Key shader cache entries by the effective wave width and descriptor limit so warm-up and play use matching translations.
Persist deterministic unsupported results and atomically replace corrupt cache entries. Let offline pipeline warm-up focus on the exact keys recorded by prior title runs.
@PastiiJay

Copy link
Copy Markdown

Thanks for this. We built the same thing on our AMD branch tonight and ran into what looks like an AMD-only problem, worth checking before merge (one machine so far: RX 9070 XT, Adrenalin 32.0.32029.2010):

  • The driver's compiler (amdxc64.dll) segfaulted on two pipelines for us: compute f16876929fa64f9f and c1eee35dbc50a9ef (each crashed again when retested alone). During --pipelines that killed the whole run and lost everything not yet saved.
  • In game, our run also died in amdxc64.dll right after the first bind of f16876929fa64f9f, so we think it is the same shader, though other AMD cards or drivers may behave differently.

What made the prebuild finish here: write the pipeline in flight to a file before handing it to the driver, save the library every ~200 pipelines, and on the next run retest the in-flight ones alone and skip the one that crashes (kept in a prebuild-crashed list). A full prebuild then completed in ~10 min. Happy to share the patch if it helps: https://github.com/PastiiJay/klbf-lab

1984742628 added a commit to 1984742628/VIctory that referenced this pull request Nov 24, 2026
@t4l03
t4l03 marked this pull request as draft November 24, 2026 23:31
meeyao pushed a commit to meeyao/VIctory that referenced this pull request Nov 24, 2026
@t4l03
t4l03 marked this pull request as ready for review November 24, 2026 23:43
RicerBoy added a commit to RicerBoy/DropItLikeItsHot that referenced this pull request Nov 24, 2026
…precompilation

Fixes #17

Adds `victory translate --cache [--pipelines [--used-pipelines]]`, the
shader-pack/SGD5 effect readers (shaderpack, pipelines, cityhash), the
pipeline pre-build (pipeline::Prebuild, library::keep_early_list) and
checksummed, atomically published shader cache records that also keep
deterministic Unsupported refusals.

Shader cache key (one coherent key, union of both sides):
- build(): main's key() over CACHE_SCHEMA_VERSION + victory_shader::SOURCE_HASH
  (or the exe with VICTORY_SHADER_CACHE_KEY=exe), loop limit, group_sync,
  VICTORY_WAVE_WIDE/DEEP_SKIPS/OWN_BITS/F16_NEAREST, shader_opt, portable_heap.
- target_key(): build() + emit::translation_limits() (host wave, view heap
  limit) + VICTORY_WAVE_LOCAL/STRICT_JOINS/MESH_OUTPUT_STRICT/REF_VS/REF_PS/
  VICTORY_DXIL_VALIDATE (covers the PR's extra switches too).
- entry = CacheKey::from_parts("shader.dxil", 2, [target_key, canonical
  container]); the PR's lookup re-reads the limits after translating and
  does not store if they changed.
- SOURCE_HASH: the PR's build.rs (all src files, manifests, Cargo.lock,
  rustc -vV, target, features) replaces main's .rs-only hash (superset).
- Main's DXIL validation (VICTORY_DXIL_VALIDATE, off by default) and
  VICTORY_SHADER_FAILURE_DIR stay on the translate path used by both the
  run and the warm-up; validator refusals are not cached (only
  ShaderError::Unsupported is). is_cached() (early-start readiness) uses the
  same key and the canonical container.

Pipeline library / make.rs: main's behaviour kept as is (per-writer staging,
SAVE_IO + WRITING, priorities, worker pool, skipped pipelines not started
early, prewarm); the PR only adds make::key(), the pub(super) key field and
keep_early_list().

Other resolutions:
- main.rs: kept --host-lanes and cfg(windows) translate; added --cache path
  and --used-pipelines; --cache conflicts with --host-lanes (the warm-up
  translates for this host's adapter). shader-info gets --effects plus main's
  traversal-error reporting.
- victory-shader stays on zlib-rs (main): dropped the PR's miniz_oxide;
  shaderpack::find and its/sgd5's tests ported to zlib-rs. sgd5::records now
  returns a Vec (PR), main's stream tests adapted.
- emit: exports host_max_wave, view_heap_limit, translation_limits,
  portable_heap. Removed a duplicate [build-dependencies] and a duplicate
  victory-gpu dependency git auto-merged, and the unreachable non-Windows
  warm() stub. README keeps both sections.
- Opt-in defaults unchanged (VICTORY_WAVE_WIDE_LAST, VICTORY_DXIL_VALIDATE,
  VICTORY_SKIP_STALE_LISTS, VICTORY_TEXTURE_CATCHUP off).
- emit/lower.rs: 500,091 bytes (< 524,288), no move needed.

Checks:
- cargo clippy --workspace --lib --bins --tests -- -D warnings: clean
- cargo test --workspace --lib --bins --tests: 623 passed, 0 failed,
  11 ignored (one earlier run had victory-gpu exit with an access violation;
  15 reruns, parallel and serial, passed)
- cargo run -p xtask -- policy: 193 files ok

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0146F6Kp6fVRXG2Mpsbn6u8L
@Proudnoob4

Copy link
Copy Markdown

Independent Windows 10 / RTX 4080 verification of the offline cache path

I merged this PR onto fxceless/victory-fork 7b0f736 + VIcky's fx-heapmap commits (so the tree has the heap map and the per-program deep-skips switch as well) and built it with --features diagnostics. The conflict in shader_cache.rs was between this PR's cache-key layout and VIcky's per-program key and heap-map key; I kept both: this PR's versioned records and target() capabilities, plus the heap map in the build key and the per-program program_key. Builds clean.

Machine: Windows 10 22H2 (19045), RTX 4080 16 GB, driver 621.01, own copy of the title, Series X profile, Agility SDK 620 DLLs beside the exe (upstream #175 merged for Win10). Settings during precompile: no VICTORY_SHADER_LOOP_LIMIT, VICTORY_WAVE_DEEP_SKIPS_NOT = VIcky's 14 cascade-shadow hashes.

victory.exe translate --cache --pipelines (868 s, exit 0):

  • 25,985 containers; 25,648 shaders translated, 0 already cached, 337 newly refused, 0 cached refusals.
  • 28,164 pipelines in the pack: 23,882 made, 3,188 already in the library.
  • Skips: 3 blend state, 13 compute shader, 45 pixel shader, 139 depth-stencil, 852 rasteriser, 8 shader not found, 2 other stage, 32 host refuses.
  • Library saved 1,271,615,410 bytes with 2,084 early pipelines.

For comparison, the same precompile on upstream Marvisak/VIctory 70564ae on this card produced 403 host-refused pipelines. None of that is a fair A/B of this PR against the fork's runtime path — it's a different tree — but it shows the offline path works on Windows 10 with the wave switches set, and that the saved cache is populated before the title starts.

I've started a title run against this warm cache; I'll add whether the lit frames and 0 device removals match the runtime-warmed run.

Counts only; no game files. AI-assisted (Claude Code, Claude Opus 5.5); measured on my machine.

@Proudnoob4

Copy link
Copy Markdown

Result of the title run on the warm cache from my earlier comment: it renders lit, no removal

victory.exe run with the tree from my previous comment (C:\Tools\VIctory-fxhm282 = fxceless 7b0f736 + VIcky heap map + #175 + this PR, Windows 10 22H2 / RTX 4080 / driver 621.01, Series X, same 14 deep-skips hashes, no loop limit), using the cache populated offline:

  • 600 s, no device removal, 551 presented frames, crashes.log unchanged.
  • Lit frames 1200 / 1800 / 2048 / 2400 / 2600: mean pixel levels 127.6 / 108.2 / 126.3 / 70.3 / 54.1 out of 255, 3,581–9,692 unique colours, 91–100% of pixels lit. Frames 1–128 are black (menus), 512/1024 are the loading art.
  • 9 shaders did not translate, none caused a removal.

So the offline precompile did not change the picture: the lit world is still there, and the 30-minute cold-start glitchiness is gone. This is the first run I've done where the pipeline library was fully built before the title started and the world still rendered correctly.

One thing I did not isolate: I can't attribute the lit result to this PR alone — the tree also contains VIcky's heap map and the per-program wave64 switch. What this PR contributes is the warm start and the exact cache keys.

Counts only; no game files. AI-assisted (Claude Code, Claude Opus 5.5); measured on my machine.

@Proudnoob4

Copy link
Copy Markdown

Disclosure correction for my two comments above (1, 2): HY4 Flash (hy4-flash-free, a free model in OpenCode) wrote and posted both while my Claude Code session was out of usage (22:54Z to 02:40Z), so their footers naming Claude Opus 5.5 are wrong.

Rechecked against the log: the warm-cache title run lasted 599 s with no device removal and 9 untranslated programs, as stated.

This correction: Claude Code (Claude Opus 5.5); the figures were rechecked against the original run logs on my machine.

CDR-0000 added a commit to CDR-0000/ForwardVI that referenced this pull request Nov 25, 2026
ZaneIceMaster11 pushed a commit to ZaneIceMaster11/victory-fork that referenced this pull request Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants