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

Open
github-bot wants to merge 1 commit from github-bot/gh-3046 into main AGit
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 05:13 UTC · original
fuzeofficlal:fix/run-save-pipeline-cache-on-exit → main · +9 −2 · 2 files · 1 commits · open

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)
**@⁠fuzeofficlal** on GitHub · 2026-11-26 05:13 UTC · [original](https://github.com/Marvisak/VIctory/pull/3046) `fuzeofficlal:fix/run-save-pipeline-cache-on-exit` → `main` · +9 −2 · 2 files · 1 commits · open ### 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)
`lifecycle::end` already flushes the pipeline library cache via
`victory_gpu::pipeline::save_pipeline_cache()`, and background saves run
at most every 20 seconds (`SAVE_EVERY`), but `victory run` returned the
title's exit code directly after `main.join()` without saving. A title
that creates or uses pipelines and exits normally within the save
interval could lose newly compiled pipelines and early-start keys.

Flush `victory_gpu::pipeline::save_pipeline_cache()` after `main.join()`
in `apps/victory/src/run.rs`, and guard `library::save` so calling it
when neither the pipeline library nor the early-start list was touched
returns immediately without lazily initializing a host D3D12 device.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:27:27 +00:00
Author
Owner

@⁠oni-swr on GitHub · 2026-11-26 06:06 UTC · original

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).

**@⁠oni-swr** on GitHub · 2026-11-26 06:06 UTC · [original](https://github.com/Marvisak/VIctory/pull/3046#issuecomment-7184103937) 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).
Author
Owner

@⁠Marvisak on GitHub · 2026-11-26 06:17 UTC · original

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

**@⁠Marvisak** on GitHub · 2026-11-26 06:17 UTC · [original](https://github.com/Marvisak/VIctory/pull/3046#issuecomment-7184288809) <!-- 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 can be merged automatically.
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/3046/head:github-bot/gh-3046'
git switch 'github-bot/gh-3046'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3046'
git switch 'github-bot/gh-3046'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3046'
git switch 'github-bot/gh-3046'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3046'
git switch 'main'
git merge --squash 'github-bot/gh-3046'
git switch 'main'
git merge --ff-only 'github-bot/gh-3046'
git switch 'main'
git merge 'github-bot/gh-3046'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!3046
No description provided.