Run, GPU: save the pipeline cache on normal title exit #3044

Open
fuzeofficlal wants to merge 1 commit from upstream-pr/3046 into main
fuzeofficlal commented 2026-11-26 05:13:48 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T05:13:48Z.


Problem

victory_gpu::pipeline::library::save(false) throttles disk writes to once every 20 seconds (SAVE_EVERY). lifecycle::end() flushes the cache via victory_gpu::pipeline::save_pipeline_cache() on window-close / suspend exits, but when a title's main thread returns normally in apps/victory/src/run.rs (main.join()), run returns Ok(code) without calling save_pipeline_cache(). Any pipelines compiled or early-start keys recorded in the final save interval are lost on normal exit.

Fix

  • Call victory_gpu::pipeline::save_pipeline_cache() in apps/victory/src/run.rs right after main.join() completes cleanly.
  • Hoist LIBRARY in crates/victory-gpu/src/pipeline/library.rs and short-circuit save() when LIBRARY was never initialized and USED_CHANGED is false, so flushing on exit for a title that never touched D3D12 does not lazily spin up a host D3D12 device.

Verification

  • cargo test --locked -p victory-gpu --lib pipeline::library::tests:: (11 passed)
  • cargo test --locked -p victory (14 unit tests + 4 integration tests passed)
  • cargo clippy --locked -p victory-gpu -p victory --all-targets -- -D warnings
  • cargo xtask policy (191 files ok)
<!-- greyfinch-sync:Marvisak/VIctory:issue:6620020322 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3046). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T05:13:48Z. --- ### Problem `victory_gpu::pipeline::library::save(false)` throttles disk writes to once every 20 seconds (`SAVE_EVERY`). `lifecycle::end()` flushes the cache via `victory_gpu::pipeline::save_pipeline_cache()` on window-close / suspend exits, but when a title's main thread returns normally in `apps/victory/src/run.rs` (`main.join()`), `run` returns `Ok(code)` without calling `save_pipeline_cache()`. Any pipelines compiled or early-start keys recorded in the final save interval are lost on normal exit. ### Fix - Call `victory_gpu::pipeline::save_pipeline_cache()` in `apps/victory/src/run.rs` right after `main.join()` completes cleanly. - Hoist `LIBRARY` in `crates/victory-gpu/src/pipeline/library.rs` and short-circuit `save()` when `LIBRARY` was never initialized and `USED_CHANGED` is false, so flushing on exit for a title that never touched D3D12 does not lazily spin up a host D3D12 device. ### Verification - `cargo test --locked -p victory-gpu --lib pipeline::library::tests::` (11 passed) - `cargo test --locked -p victory` (14 unit tests + 4 integration tests passed) - `cargo clippy --locked -p victory-gpu -p victory --all-targets -- -D warnings` - `cargo xtask policy` (191 files ok)
kotekompotek commented 2026-11-26 06:03:28 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-26T05:25:28Z.

Review: APPROVED


Verified: the exit-time save_pipeline_cache() would previously force library() to initialize just to discover there is nothing to write — the LIBRARY.get().is_none() && !USED_CHANGED guard skips exactly the never-touched case, while a used-but-unsaved run still initializes and writes. Throttling and DIR-less early returns unchanged.

<!-- greyfinch-sync:Marvisak/VIctory:review:6068965494 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3046#pullrequestreview-6068965494). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-26T05:25:28Z. **Review:** APPROVED --- Verified: the exit-time `save_pipeline_cache()` would previously force `library()` to initialize just to discover there is nothing to write — the `LIBRARY.get().is_none() && !USED_CHANGED` guard skips exactly the never-touched case, while a used-but-unsaved run still initializes and writes. Throttling and DIR-less early returns unchanged.
Dukestar69 commented 2026-11-26 07:01:25 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T06:56:23Z.

Review: APPROVED


Tested locally merged onto origin/main (63bcca4) on Windows 11 x64 (NVIDIA GeForce RTX 5090):

  • Diff review: Calling victory_gpu::pipeline::save_pipeline_cache() on normal title exit in apps/victory/src/run.rs and short-circuiting save() when LIBRARY was never initialized and !USED_CHANGED cleanly preserves recently compiled pipelines and early-start keys without initializing D3D12 unnecessarily.
  • cargo test -p victory-gpu pipeline::library::tests -- --test-threads=1: 11 passed, 0 failed.
  • cargo test -p victory run::: all tests passed.
  • cargo clippy -p victory-gpu -p victory --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6069744226 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3046#pullrequestreview-6069744226). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T06:56:23Z. **Review:** APPROVED --- Tested locally merged onto `origin/main` (`63bcca4`) on Windows 11 x64 (NVIDIA GeForce RTX 5090): - Diff review: Calling `victory_gpu::pipeline::save_pipeline_cache()` on normal title exit in `apps/victory/src/run.rs` and short-circuiting `save()` when `LIBRARY` was never initialized and `!USED_CHANGED` cleanly preserves recently compiled pipelines and early-start keys without initializing D3D12 unnecessarily. - `cargo test -p victory-gpu pipeline::library::tests -- --test-threads=1`: 11 passed, 0 failed. - `cargo test -p victory run::`: all tests passed. - `cargo clippy -p victory-gpu -p victory --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
oni-swr commented 2026-11-26 07:01:43 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-26T06:06:47Z.


Independent Windows x64 verification of d1e9043b622f843887ea784f79e91805df1d5414 against its exact parent 63bcca43c6a00a758510398fa43096ce7e4f7df0.

I ran victory run --execute with a temporary import-free PE whose entry point returns 37. A temporary harness seeded the real cache before spawning the PE and logged pipeline-library and D3D12 host initialization. Separate processes used isolated cache directories, except for the deliberate reload. Every run returned 37.

  • On the PR head, the harness stored one synthetic compute PSO and recorded one early-start key inside the background-save throttle window. It verified the pipeline-cache directory was absent before spawning the PE. Normal exit wrote a 996-byte host-pipelines.bin and the expected key to early-pipelines.txt. A fresh process loaded the stored PSO and found the key without recreating the PSO.
  • On the exact parent, the same pre-exit seed and normal return left the pipeline-cache directory absent.
  • In the early-key-only case, the PR head first initialized the library and D3D12 during the exit flush, then wrote the key and an 872-byte library with zero PSOs created. The parent returned without initializing either or writing the pipeline cache.
  • In the idle case, the PR head returned without attempting either initialization and without creating the pipeline-cache directory. As a separate control, calling the same save function after join on the exact parent triggered both initialization probes and still wrote no cache.

Built with cargo build --locked -j 4 -p victory --features diagnostics. Device-creating runs confirmed Microsoft Basic Render Driver (vendor 0x1414, device 0x008c, software flag 0x2) before creation with VICTORY_D3D12_WARP=1. The compute fixture used Windows SDK 10.0.26100.0 tooling with its x64 dxil.dll.

AI-assisted (Codex, gpt-6.2-sol).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7184103937 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3046#issuecomment-7184103937). Originally posted by [oni-swr](https://github.com/oni-swr) on 2026-11-26T06:06:47Z. --- Independent Windows x64 verification of `d1e9043b622f843887ea784f79e91805df1d5414` against its exact parent `63bcca43c6a00a758510398fa43096ce7e4f7df0`. I ran `victory run --execute` with a temporary import-free PE whose entry point returns 37. A temporary harness seeded the real cache before spawning the PE and logged pipeline-library and D3D12 host initialization. Separate processes used isolated cache directories, except for the deliberate reload. Every run returned 37. - On the PR head, the harness stored one synthetic compute PSO and recorded one early-start key inside the background-save throttle window. It verified the pipeline-cache directory was absent before spawning the PE. Normal exit wrote a 996-byte `host-pipelines.bin` and the expected key to `early-pipelines.txt`. A fresh process loaded the stored PSO and found the key without recreating the PSO. - On the exact parent, the same pre-exit seed and normal return left the pipeline-cache directory absent. - In the early-key-only case, the PR head first initialized the library and D3D12 during the exit flush, then wrote the key and an 872-byte library with zero PSOs created. The parent returned without initializing either or writing the pipeline cache. - In the idle case, the PR head returned without attempting either initialization and without creating the pipeline-cache directory. As a separate control, calling the same save function after join on the exact parent triggered both initialization probes and still wrote no cache. Built with `cargo build --locked -j 4 -p victory --features diagnostics`. Device-creating runs confirmed Microsoft Basic Render Driver (vendor `0x1414`, device `0x008c`, software flag `0x2`) before creation with `VICTORY_D3D12_WARP=1`. The compute fixture used Windows SDK `10.0.26100.0` tooling with its x64 `dxil.dll`. AI-assisted (Codex, gpt-6.2-sol).
Marvisak commented 2026-11-26 07:01:47 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T06:17:47Z.


Automated triage for the maintainers.

On main, the pipeline cache is saved at the end of a run only from lifecycle::end (crates/victory-hle/src/modules/lifecycle.rs). When the title's main thread returns normally, run::run (apps/victory/src/run.rs, a function under cfg(windows)) skips that, and library::save(false) throttles writes to one every 20 s. Pipelines and early-start keys from the last interval are lost. The PR calls save_pipeline_cache() after a clean join, in the same way lifecycle::end and prebuild.rs already do.

In crates/victory-gpu/src/pipeline/library.rs, save now returns early when LIBRARY was never initialized and USED_CHANGED is clear. Without that, the exit save would create a D3D12 device just to write nothing. If early keys were recorded, the library is still initialized and saved. I read it as correct. The independent Windows run above confirms the before and after behaviour. CI: check passing.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7184288809 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3046#issuecomment-7184288809). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-26T06:17:47Z. --- <!-- victory-triage v1 head=d1e9043b622f843887ea784f79e91805df1d5414 verdict=merge-candidate at=2026-11-26T06:42:00Z --> Automated triage for the maintainers. On `main`, the pipeline cache is saved at the end of a run only from `lifecycle::end` (`crates/victory-hle/src/modules/lifecycle.rs`). When the title's main thread returns normally, `run::run` (`apps/victory/src/run.rs`, a function under `cfg(windows)`) skips that, and `library::save(false)` throttles writes to one every 20 s. Pipelines and early-start keys from the last interval are lost. The PR calls `save_pipeline_cache()` after a clean `join`, in the same way `lifecycle::end` and `prebuild.rs` already do. In `crates/victory-gpu/src/pipeline/library.rs`, `save` now returns early when `LIBRARY` was never initialized and `USED_CHANGED` is clear. Without that, the exit save would create a D3D12 device just to write nothing. If early keys were recorded, the library is still initialized and saved. I read it as correct. The independent Windows run above confirms the before and after behaviour. CI: `check` passing. --- _Generated by [Claude Code](https://claude.ai/code)_
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3046:upstream-pr/3046'
git switch 'upstream-pr/3046'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3046'
git switch 'upstream-pr/3046'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3046'
git switch 'upstream-pr/3046'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3046'
git switch 'main'
git merge --squash 'upstream-pr/3046'
git switch 'main'
git merge --ff-only 'upstream-pr/3046'
git switch 'main'
git merge 'upstream-pr/3046'
git push origin 'main'
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
Marvisak/VIctory!3044
No description provided.