play: preload pipeline books recorded after an empty-cache start #4485

Closed
nidea1 wants to merge 6 commits from upstream-pr/4485 into main
nidea1 commented 2026-11-30 21:05:01 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by nidea1 on 2026-11-30T21:05:01Z.


Related: #4176

What it changes

Starting from an empty cache (or after clearing the shader cache via F1 -> CLEAR SHADER CACHE / manual deletion):

  1. On Start 1, warmup_mark runs victory preload before known-pipelines.bin exists, so warm::run sees 0 known pipelines, creates a 0-byte warm-done.txt, and finish_preload writes %LOCALAPPDATA%\victory\warmed\<exe-hash>. The first play session then populates known-pipelines.bin, early-pipelines.txt, and a partial adapters/<gpu>/host-pipelines.bin while warm-done.txt stays empty/missing.
  2. On Start 2, warmup_mark is already written, so preload_needed() falls back to needs_pipelines(). Because needs_pipelines() only checked known-pipelines.bin.is_file() && !made_in(pipelines), Session 1's partial host-pipelines.bin caused it to return false, so the newly recorded pipeline book was never preloaded.
  3. In addition, needs_pipelines() walked all of adapters/ (so a library built for gpu0 suppressed preload when running on gpu1), ignored VICTORY_LIBRARY_DIR, and could loop indefinitely when a tiny book with empty early/slow lists produced no host-pipelines.bin.

This PR fixes those gaps without adding new dependencies, environment variables, or forcing --all:

  • Single source of truth for adapter directory names (crates/victory-gpu/src/pipeline/library.rs, known.rs): extracts adapter_dir_name(&DXGI_ADAPTER_DESC1) for adapter_dir() and exposes known::adapter_dir_name() via a pure DXGI hardware_adapter() + GetDesc1() query (respects VICTORY_ADAPTER, no D3D12 device created).
  • Per-adapter cache preload stamp (apps/victory/src/play.rs, main.rs): adds pipelines/preloaded.txt (<adapter_key> <book_bytes> <0|1>) removed alongside adapters/, warm-done.txt, warm-bad.txt, and host-pipelines.* on translator updates (is_stale_pipeline_entry) while keeping known-pipelines.bin. play::record_preloaded() runs at the end of Command::Preload only after translate::precompile, warm::run, and warm::into_library all succeed, and skips writing when known-pipelines.bin is missing or 0 bytes (empty-cache Start 1).
  • Adapter- and VICTORY_LIBRARY_DIR-aware needs_pipelines_for() (apps/victory/src/play.rs):
    • Checks host-pipelines.bin* / host-pipelines.next only in the active adapter directory + legacy top-level fallback under VICTORY_LIBRARY_DIR (or pipelines), ignoring other adapters and lock/temp files.
    • When a preloaded.txt record exists for the active adapter, re-triggers only if a previously created library was deleted (had_library && !has_library) or known-pipelines.bin grew >= 2x, preventing infinite preload loops on tiny books or empty early/slow lists.
    • When no preloaded.txt record exists yet for the active adapter and a host library is present, checks whether warm-done.txt has at least one non-empty line — triggering Start-2 preload after an un-preloaded empty-cache first session while avoiding spurious re-preloads on already-warmed caches from earlier builds.

How it was tested

  • GPU and profile (Series X or S, resolution, DLSS, frame generation, ray tracing): Unit and regression tests only (not tested in a live title run)
  • Before: Starting from an empty cache left Start 2 seeing Session 1's partial host-pipelines.bin and skipping preload; switching adapters saw another adapter's host-pipelines.bin; VICTORY_LIBRARY_DIR was ignored; tiny books producing no library looped needs_pipelines() == true.
  • After: Empty-cache Start 2 detects the unwarmed book and triggers preload once, stamps pipelines/preloaded.txt per adapter upon completion, preserves legacy preloaded caches (non-empty warm-done.txt) without re-preloading, handles multi-adapter switching and VICTORY_LIBRARY_DIR, re-triggers on deleted libraries or >= 2x book growth, and wipes preloaded.txt on translator updates.
  • For shader changes, the wave sizes tested (32 and/or 64 lanes): N/A (no shader changes)
  • cargo test passed for the crates it touches: yes
    • cargo test -j 4 -p victory: 96 unit + 1 cache_paths + 2 census = 99 passed, 0 failed (updated a_book_without_made_pipelines_is_preloaded + 5 new regression tests).
    • cargo test -j 4 -p victory-gpu --lib -- pipeline::library: 21 passed, 0 failed (including adapter_dir_name_matches_adapter_dir_layout).
    • cargo clippy -j 4 -p victory -p victory-gpu --all-targets and --all-features: 0 warnings in victory and 0 warnings in touched victory-gpu files.
    • cargo run -j 4 -p xtask -- policy --staged: asset policy: 4 files ok.

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches. Related: #4176, #4231, #3588, #4256
    • #4231 (merged) preserved the pipeline book across translator updates; this PR closes the remaining empty-cache Start-2 gap on #4176.
    • #3588 surfaces I/O errors reading known-pipelines.bin in warm.rs/known.rs (orthogonal).
    • #4256 adds opt-in victory warm --waited (VICTORY_WARM_WAITED=1, orthogonal).
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5573735625 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4485). Originally posted by [nidea1](https://github.com/nidea1) on 2026-11-30T21:05:01Z. --- Related: #4176 ## What it changes Starting from an empty cache (or after clearing the shader cache via `F1 -> CLEAR SHADER CACHE` / manual deletion): 1. On **Start 1**, `warmup_mark` runs `victory preload` before `known-pipelines.bin` exists, so `warm::run` sees 0 known pipelines, creates a 0-byte `warm-done.txt`, and `finish_preload` writes `%LOCALAPPDATA%\victory\warmed\<exe-hash>`. The first play session then populates `known-pipelines.bin`, `early-pipelines.txt`, and a partial `adapters/<gpu>/host-pipelines.bin` while `warm-done.txt` stays empty/missing. 2. On **Start 2**, `warmup_mark` is already written, so `preload_needed()` falls back to `needs_pipelines()`. Because `needs_pipelines()` only checked `known-pipelines.bin.is_file() && !made_in(pipelines)`, Session 1's partial `host-pipelines.bin` caused it to return `false`, so the newly recorded pipeline book was never preloaded. 3. In addition, `needs_pipelines()` walked all of `adapters/` (so a library built for `gpu0` suppressed preload when running on `gpu1`), ignored `VICTORY_LIBRARY_DIR`, and could loop indefinitely when a tiny book with empty `early`/`slow` lists produced no `host-pipelines.bin`. This PR fixes those gaps without adding new dependencies, environment variables, or forcing `--all`: - **Single source of truth for adapter directory names (`crates/victory-gpu/src/pipeline/library.rs`, `known.rs`):** extracts `adapter_dir_name(&DXGI_ADAPTER_DESC1)` for `adapter_dir()` and exposes `known::adapter_dir_name()` via a pure DXGI `hardware_adapter()` + `GetDesc1()` query (respects `VICTORY_ADAPTER`, no D3D12 device created). - **Per-adapter cache preload stamp (`apps/victory/src/play.rs`, `main.rs`):** adds `pipelines/preloaded.txt` (`<adapter_key> <book_bytes> <0|1>`) removed alongside `adapters/`, `warm-done.txt`, `warm-bad.txt`, and `host-pipelines.*` on translator updates (`is_stale_pipeline_entry`) while keeping `known-pipelines.bin`. `play::record_preloaded()` runs at the end of `Command::Preload` only after `translate::precompile`, `warm::run`, and `warm::into_library` all succeed, and skips writing when `known-pipelines.bin` is missing or 0 bytes (empty-cache Start 1). - **Adapter- and `VICTORY_LIBRARY_DIR`-aware `needs_pipelines_for()` (`apps/victory/src/play.rs`):** - Checks `host-pipelines.bin*` / `host-pipelines.next` only in the active adapter directory + legacy top-level fallback under `VICTORY_LIBRARY_DIR` (or `pipelines`), ignoring other adapters and lock/temp files. - When a `preloaded.txt` record exists for the active adapter, re-triggers only if a previously created library was deleted (`had_library && !has_library`) or `known-pipelines.bin` grew `>= 2x`, preventing infinite preload loops on tiny books or empty `early`/`slow` lists. - When no `preloaded.txt` record exists yet for the active adapter and a host library is present, checks whether `warm-done.txt` has at least one non-empty line — triggering Start-2 preload after an un-preloaded empty-cache first session while avoiding spurious re-preloads on already-warmed caches from earlier builds. ## How it was tested - GPU and profile (Series X or S, resolution, DLSS, frame generation, ray tracing): Unit and regression tests only (not tested in a live title run) - Before: Starting from an empty cache left Start 2 seeing Session 1's partial `host-pipelines.bin` and skipping preload; switching adapters saw another adapter's `host-pipelines.bin`; `VICTORY_LIBRARY_DIR` was ignored; tiny books producing no library looped `needs_pipelines() == true`. - After: Empty-cache Start 2 detects the unwarmed book and triggers preload once, stamps `pipelines/preloaded.txt` per adapter upon completion, preserves legacy preloaded caches (non-empty `warm-done.txt`) without re-preloading, handles multi-adapter switching and `VICTORY_LIBRARY_DIR`, re-triggers on deleted libraries or `>= 2x` book growth, and wipes `preloaded.txt` on translator updates. - For shader changes, the wave sizes tested (32 and/or 64 lanes): N/A (no shader changes) - `cargo test` passed for the crates it touches: yes - `cargo test -j 4 -p victory`: 96 unit + 1 `cache_paths` + 2 `census` = 99 passed, 0 failed (updated `a_book_without_made_pipelines_is_preloaded` + 5 new regression tests). - `cargo test -j 4 -p victory-gpu --lib -- pipeline::library`: 21 passed, 0 failed (including `adapter_dir_name_matches_adapter_dir_layout`). - `cargo clippy -j 4 -p victory -p victory-gpu --all-targets` and `--all-features`: 0 warnings in `victory` and 0 warnings in touched `victory-gpu` files. - `cargo run -j 4 -p xtask -- policy --staged`: `asset policy: 4 files ok`. ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. Related: #4176, #4231, #3588, #4256 - `#4231` (merged) preserved the pipeline book across translator updates; this PR closes the remaining empty-cache Start-2 gap on `#4176`. - `#3588` surfaces I/O errors reading `known-pipelines.bin` in `warm.rs`/`known.rs` (orthogonal). - `#4256` adds opt-in `victory warm --waited` (`VICTORY_WARM_WAITED=1`, orthogonal).
andrewpozdnakov7-jpg commented 2026-12-01 11:52:31 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by andrewpozdnakov7-jpg on 2026-12-01T11:52:31Z.


Two preloads can finish on different adapters against the same pipeline book. On 02f2fa3e, both can read the same preloaded.txt and then each replace the whole file. Whichever writes last drops the other adapter's mark, which can trigger another preload at its next launch.

d9a7ad44c50bc6d016862de1c53407cda51725b3 appends a complete record. The existing reader already uses the latest valid line for each adapter, so older records continue to work. Review commit

I used a two-writer Windows fixture with the exact marker functions. A barrier after the original snapshot reads reproduced the lost row deterministically. With the patch both adapter rows and the existing row survived, and a later complete record took precedence after an interrupted line. cargo xtask policy --staged passed for play.rs.

Please keep the Git author on cherry-pick or rebase, or add Co-authored-by: andrewpozdnakov7-jpg <[email protected]> if folding the change in.

AI-assisted with OpenAI Codex.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7310280553 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4485#issuecomment-7310280553). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-12-01T11:52:31Z. --- Two preloads can finish on different adapters against the same pipeline book. On `02f2fa3e`, both can read the same `preloaded.txt` and then each replace the whole file. Whichever writes last drops the other adapter's mark, which can trigger another preload at its next launch. d9a7ad44c50bc6d016862de1c53407cda51725b3 appends a complete record. The existing reader already uses the latest valid line for each adapter, so older records continue to work. [Review commit](https://github.com/andrewpozdnakov7-jpg/VIctory-NVIDIA/commit/d9a7ad44c50bc6d016862de1c53407cda51725b3) I used a two-writer Windows fixture with the exact marker functions. A barrier after the original snapshot reads reproduced the lost row deterministically. With the patch both adapter rows and the existing row survived, and a later complete record took precedence after an interrupted line. `cargo xtask policy --staged` passed for `play.rs`. Please keep the Git author on cherry-pick or rebase, or add `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>` if folding the change in. AI-assisted with OpenAI Codex.
nidea1 commented 2026-12-01 14:44:09 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by nidea1 on 2026-12-01T14:44:09Z.


Thanks @andrewpozdnakov7-jpg for catching the cross-adapter overwrite race and providing the append-only fix!

Cherry-picked d9a7ad44c5 onto this branch as b7ef87fc80 with your original Git author preserved, hardened read_preloaded_record to decode preloaded.txt line-by-line from raw bytes (90a7ebb0cf) so an interrupted/corrupted non-UTF-8 byte in an earlier append cannot poison newer valid appends into an infinite preload loop, and added appending_preloaded_records_preserves_multiple_adapters_and_recovers_from_partial_line (ed8945ade0, 90a7ebb0cf) covering 4-thread x 16-append multi-adapter contention, partial trailing lines, and non-UTF-8 corruption recovery.

Verified on 90a7ebb0cf with cargo test --locked -p victory (97 unit + 1 cache_paths + 2 census passed, 0 failed), cargo clippy --locked -p victory --all-targets -- -D warnings (0 warnings), and cargo xtask policy (464 files ok).

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7314742112 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4485#issuecomment-7314742112). Originally posted by [nidea1](https://github.com/nidea1) on 2026-12-01T14:44:09Z. --- Thanks @andrewpozdnakov7-jpg for catching the cross-adapter overwrite race and providing the append-only fix! Cherry-picked `d9a7ad44c5` onto this branch as `b7ef87fc80` with your original Git author preserved, hardened `read_preloaded_record` to decode `preloaded.txt` line-by-line from raw bytes (`90a7ebb0cf`) so an interrupted/corrupted non-UTF-8 byte in an earlier append cannot poison newer valid appends into an infinite preload loop, and added `appending_preloaded_records_preserves_multiple_adapters_and_recovers_from_partial_line` (`ed8945ade0`, `90a7ebb0cf`) covering 4-thread x 16-append multi-adapter contention, partial trailing lines, and non-UTF-8 corruption recovery. Verified on `90a7ebb0cf` with `cargo test --locked -p victory` (97 unit + 1 `cache_paths` + 2 `census` passed, 0 failed), `cargo clippy --locked -p victory --all-targets -- -D warnings` (0 warnings), and `cargo xtask policy` (464 files ok).
andrewpozdnakov7-jpg commented 2026-12-01 15:42:24 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by andrewpozdnakov7-jpg on 2026-12-01T15:42:24Z.


A related caller on 90a7ebb0 still looks only at the shared root. When VICTORY_WARM_SHARED=1, warm --used discards its existing completion marks if the library is under adapters/<selected adapter>/. That can compile the same pipelines again even when their library is present.

1bc46671 reuses this PR’s adapter-aware library check. It accepts the current adapter’s installed or pending library and the legacy root file. Only the actual cache file names count.

A focused Windows fixture exercised the real file checks with a stub adapter name. The selected adapter’s installed and pending files changed from rejected to recognized. The other adapter’s file and a backup stayed outside the warm decision, and the legacy file still worked. The staged asset policy passed. The patch combined cleanly with the #3895 marker follow-up and #4958.

Please keep the Git author on cherry-pick or rebase, or add Co-authored-by: andrewpozdnakov7-jpg <[email protected]> if folding the change in.

AI-assisted with OpenAI Codex.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7316369060 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4485#issuecomment-7316369060). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-12-01T15:42:24Z. --- A related caller on `90a7ebb0` still looks only at the shared root. When `VICTORY_WARM_SHARED=1`, `warm --used` discards its existing completion marks if the library is under `adapters/<selected adapter>/`. That can compile the same pipelines again even when their library is present. [1bc46671](https://github.com/andrewpozdnakov7-jpg/VIctory-NVIDIA/commit/1bc46671c8d58638611655e700b4569882537ca4) reuses this PR’s adapter-aware library check. It accepts the current adapter’s installed or pending library and the legacy root file. Only the actual cache file names count. A focused Windows fixture exercised the real file checks with a stub adapter name. The selected adapter’s installed and pending files changed from rejected to recognized. The other adapter’s file and a backup stayed outside the warm decision, and the legacy file still worked. The staged asset policy passed. The patch combined cleanly with the #3895 marker follow-up and #4958. Please keep the Git author on cherry-pick or rebase, or add `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>` if folding the change in. AI-assisted with OpenAI Codex.
nidea1 commented 2026-12-01 18:31:06 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by nidea1 on 2026-12-01T18:31:06Z.


Thanks @andrewpozdnakov7-jpg for catching the VICTORY_WARM_SHARED=1 shared-root check and tightening is_library_file!

Cherry-picked 1bc46671c8 onto this branch as 99a2e5b009 with your original Git author preserved, then in f7aadea3b0 extracted warm::shared_library_present (reusing play::made_in_flat for the unidentified-adapter legacy root fallback so zero-byte legacy files are rejected and pending host-pipelines.next files at the legacy root are recognized, matching pipeline/library.rs::load_cache) and added unit tests in play.rs (made_in_for_matches_exact_non_empty_library_files_for_selected_adapter) and warm.rs (shared_library_present_follows_selected_adapter_and_legacy_root) covering installed/pending adapter libraries, legacy root fallback, backup files, zero-byte files, directories, and other adapters.

Verified on f7aadea3b0 with cargo test -j 4 --locked -p victory (99 unit + 1 cache_paths + 2 census passed, 0 failed), cargo clippy -j 4 --locked -p victory --all-targets -- -D warnings and --all-features (0 warnings), and cargo xtask policy (464 files ok; --staged 2 files ok).

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7321073858 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4485#issuecomment-7321073858). Originally posted by [nidea1](https://github.com/nidea1) on 2026-12-01T18:31:06Z. --- Thanks @andrewpozdnakov7-jpg for catching the `VICTORY_WARM_SHARED=1` shared-root check and tightening `is_library_file`! Cherry-picked `1bc46671c8` onto this branch as `99a2e5b009` with your original Git author preserved, then in `f7aadea3b0` extracted `warm::shared_library_present` (reusing `play::made_in_flat` for the unidentified-adapter legacy root fallback so zero-byte legacy files are rejected and pending `host-pipelines.next` files at the legacy root are recognized, matching `pipeline/library.rs::load_cache`) and added unit tests in `play.rs` (`made_in_for_matches_exact_non_empty_library_files_for_selected_adapter`) and `warm.rs` (`shared_library_present_follows_selected_adapter_and_legacy_root`) covering installed/pending adapter libraries, legacy root fallback, backup files, zero-byte files, directories, and other adapters. Verified on `f7aadea3b0` with `cargo test -j 4 --locked -p victory` (99 unit + 1 `cache_paths` + 2 `census` passed, 0 failed), `cargo clippy -j 4 --locked -p victory --all-targets -- -D warnings` and `--all-features` (0 warnings), and `cargo xtask policy` (464 files ok; `--staged` 2 files ok).
trustno1-coder commented 2026-12-01 18:40:01 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by trustno1-coder on 2026-12-01T18:40:01Z.


Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7321302496 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4485#issuecomment-7321302496). Originally posted by [trustno1-coder](https://github.com/trustno1-coder) on 2026-12-01T18:40:01Z. --- Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
trustno1-coder/VIctory-NVIDIA!4485
No description provided.