[pr-fix][startup][shaders] darner preload records a finished preload, so the next start does not preload again #435

Open
Skanzinho wants to merge 1 commit from Skanzinho/Darner:preload-grava-marca into main
First-time contributor

Refs #128

Contributor role (optional)

  • Fluxer ID: 1578057944262520834

What it changes

  • The problem on main: a darner preload <game folder> --all that finishes with exit code 0 leaves no warmed\<hash> mark, so the next darner play of the same darner.exe prints "The shaders are not fully preloaded for this version of darner.exe: preloading them before the game starts." and runs the whole preload again. Seen on 2026-12-04 with diagnostics builds (--profile diag --features diagnostics) of v2026.12.03.01 and v2026.12.03.02, each in its own DARNER_HOME, started by a script:

    darner preload <game folder> --all next darner play (scripts/bench.ps1) second preload
    v2026.12.03.01 diag exit 0, 42 min "not fully preloaded" "Shaders preloaded in 30.6 min."
    v2026.12.03.02 diag exit 0, 65 min "not fully preloaded" "Shaders preloaded in 30.6 min."

    The warmed folder of each home got its mark only when that second preload ended.

Three paths write the mark on main: the start's preload window (play::preload → finish_preload), which play --preload and F1's PRELOAD SHADERS use too, and the warm-up restart (menu.rs). Command::Preload in main.rs runs the same steps as the window's child (translate::precompile, warm::run, warm::into_library) but writes no mark. So anyone who preloads with darner preload before playing (a script, a launcher, the README's darner.exe preload) pays for the preload twice.

This change:

  • darner preload writes the same mark as the window, for the same darner.exe bytes (mark_path), when it warmed every known pipeline (not --used) of the whole title: folders given (the window passes the game folder), or none given (the configured ones). One file given is part of the title, so no mark.
  • No mark with a named DARNER_CACHE_DIR: play does not read the mark then either.
  • The mark write moves out of finish_preload into write_mark, shared by both. The window's child now writes it too, then the window writes it again; the second write keeps it (new test a_preload_mark_can_be_written_twice).
  • README: one sentence where it describes the mark.

How it was tested

  • Tested revision: 3438456 (on main f3840d7, v2026.12.03.02).

  • Commands and results, in the v2026.12.03.02 diagnostics test home (DARNER_HOME set, not my normal one), Windows 11:

    • cargo build --locked --profile diag -p darner --features diagnostics: ok.
    • darner preload --all <game folder>: exit 0, 51.7 min. warmed\ before: only main's mark (338ec62e29f44481, from the night before). After: also 7f656d3d846bc757, written when the preload ended.
    • First darner play of this build, through scripts/bench.ps1 -Label pr-preload-play -Dlss performance -FrameGen 2 -RayTracing off -AllowMenuFile -Warmup 45 -Seconds 60 -BootTimeout 900 -CaptureEvery 0: exit 0; no "not fully preloaded" and no "Shaders preloaded in" line in its darner.out.txt; the summary says "world after 74 s".
  • Changes a default: no. No switch; darner preload of the whole title now leaves the mark the window leaves.

  • A/B result: same home, game folder, settings and PC, one run each; A is main's v2026.12.03.02 diagnostics build (the night before), B is this PR's diagnostics build:

    A (main, f3840d7) B (this PR, 3438456)
    darner preload <game folder> --all exit 0, 65 min (from an empty cache) exit 0, 51.7 min (main's pipelines already in the cache)
    mark after it none warmed\7f656d3d846bc757
    next darner play "not fully preloaded", preloads again: "Shaders preloaded in 30.6 min." no preload
    world after (bench summary) 1919 s 74 s
  • Gates run on 3438456:

    • cargo clippy --workspace --all-targets --locked -- -D warnings: passed.
    • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: passed.
    • cargo test --workspace --locked: exit 101. Every crate before darner-gpu passed: darner 149 passed, 1 ignored (with play::tests::a_preload_mark_can_be_written_twice), its tests cache_paths 2, census 2, picked_folders 8; darner-core 31; darner-formats 87 (7 ignored); darner-game 67. darner-gpu: 1772 passed, 1 failed, host::refresh_tests::refresh_front_zero_arc_matches_and_runs_due ("sift_indexed kept wrong dirty subset"). A second run with --no-fail-fast hung in darner-gpu instead (eight host::refresh_tests / host::watch_pipe tests over 60 s; I stopped its process after 10 min). This PR touches no file in crates/; that test passed 3 of 3 runs alone on f3840d7 (cargo test -p darner-gpu --lib --locked refresh_front_zero_arc_matches_and_runs_due). This is #389 (gate 3 not green on f3840d7, darner-gpu failing in half of the parallel runs), not fixed here. That --no-fail-fast run then went on: every other crate passed except darner-shader, 557 passed, 1 failed, emit::waterfall_tests::sampled_marks_restore_early_depth_only_when_safe_in_pixel_shaders, the test #389 reports failing every time on f3840d7 (that crate's run took 28 min).
    • cargo xtask policy: "asset policy: 555 files ok".
  • Gameplay, when relevant: RTX 4070 SUPER 12 GB, driver 617.42 (32.0.16.1742), Series S profile (the F1 menu file's choice), 1080 to 1440, DLSS performance, frame generation 2x, ray tracing off. Only the start matters here.

  • Shader wave sizes tested, when relevant: not relevant (no shader change).

  • Hardware dependence: likely general (no GPU code; only when a file is written).

  • Coverage gaps: diagnostics build only, not a release build. The start's own preload window (no darner preload before) was not run again with this build; it writes the mark through the same write_mark and the unit test covers two writes. darner preload with a single file (no mark expected) not run. Not run under Linux/Proton. Without --all, on a home that has a list of used pipelines, darner preload warms only those and writes no mark, as before.

Hardware: i9-12900F, 32 GB DDR4-3200, RTX 4070 SUPER 12 GB, Windows 11 (pt-BR).

Checklist

  • I ran this change in the game, or say below why it can't be (docs, tests only).
  • This PR contains one change based on main.
  • The diff follows docs/asset-policy.md.
  • I recorded this PR's dependencies below.
    • Depends on: none

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches.
  • Related PRs: #153 and #264 change the mark's name (shared by content, kept across a translator change) in the same play.rs code; this writes through mark_path, so if one of them merges first I will rebase and write their mark here too. #140, #267 and #270 change what the preload does, not when the mark is written. #128 is the issue about the window opening again; its causes (a stopped preload, a new exe, a translator change) are different, and this is one more.
  • Replaces or overlaps: none found.
Refs #128 ## Contributor role (optional) - Fluxer ID: 1578057944262520834 ## What it changes - The problem on main: a `darner preload <game folder> --all` that finishes with exit code 0 leaves no `warmed\<hash>` mark, so the next `darner play` of the same darner.exe prints "The shaders are not fully preloaded for this version of darner.exe: preloading them before the game starts." and runs the whole preload again. Seen on 2026-12-04 with diagnostics builds (`--profile diag --features diagnostics`) of v2026.12.03.01 and v2026.12.03.02, each in its own DARNER_HOME, started by a script: | | `darner preload <game folder> --all` | next `darner play` (scripts/bench.ps1) | second preload | |---|---|---|---| | v2026.12.03.01 diag | exit 0, 42 min | "not fully preloaded" | "Shaders preloaded in 30.6 min." | | v2026.12.03.02 diag | exit 0, 65 min | "not fully preloaded" | "Shaders preloaded in 30.6 min." | The `warmed` folder of each home got its mark only when that second preload ended. Three paths write the mark on main: the start's preload window (`play::preload` → `finish_preload`), which `play --preload` and F1's PRELOAD SHADERS use too, and the warm-up restart (`menu.rs`). `Command::Preload` in `main.rs` runs the same steps as the window's child (`translate::precompile`, `warm::run`, `warm::into_library`) but writes no mark. So anyone who preloads with `darner preload` before playing (a script, a launcher, the README's `darner.exe preload`) pays for the preload twice. This change: - `darner preload` writes the same mark as the window, for the same darner.exe bytes (`mark_path`), when it warmed every known pipeline (not `--used`) of the whole title: folders given (the window passes the game folder), or none given (the configured ones). One file given is part of the title, so no mark. - No mark with a named `DARNER_CACHE_DIR`: `play` does not read the mark then either. - The mark write moves out of `finish_preload` into `write_mark`, shared by both. The window's child now writes it too, then the window writes it again; the second write keeps it (new test `a_preload_mark_can_be_written_twice`). - README: one sentence where it describes the mark. ## How it was tested - Tested revision: 3438456 (on `main` f3840d7, v2026.12.03.02). - Commands and results, in the v2026.12.03.02 diagnostics test home (DARNER_HOME set, not my normal one), Windows 11: - `cargo build --locked --profile diag -p darner --features diagnostics`: ok. - `darner preload --all <game folder>`: exit 0, 51.7 min. `warmed\` before: only main's mark (`338ec62e29f44481`, from the night before). After: also `7f656d3d846bc757`, written when the preload ended. - First `darner play` of this build, through `scripts/bench.ps1 -Label pr-preload-play -Dlss performance -FrameGen 2 -RayTracing off -AllowMenuFile -Warmup 45 -Seconds 60 -BootTimeout 900 -CaptureEvery 0`: exit 0; no "not fully preloaded" and no "Shaders preloaded in" line in its `darner.out.txt`; the summary says "world after 74 s". - Changes a default: no. No switch; `darner preload` of the whole title now leaves the mark the window leaves. - A/B result: same home, game folder, settings and PC, one run each; A is main's v2026.12.03.02 diagnostics build (the night before), B is this PR's diagnostics build: | | A (main, f3840d7) | B (this PR, 3438456) | |---|---|---| | `darner preload <game folder> --all` | exit 0, 65 min (from an empty cache) | exit 0, 51.7 min (main's pipelines already in the cache) | | mark after it | none | `warmed\7f656d3d846bc757` | | next `darner play` | "not fully preloaded", preloads again: "Shaders preloaded in 30.6 min." | no preload | | world after (bench summary) | 1919 s | 74 s | - Gates run on 3438456: - `cargo clippy --workspace --all-targets --locked -- -D warnings`: passed. - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: passed. - `cargo test --workspace --locked`: exit 101. Every crate before `darner-gpu` passed: `darner` 149 passed, 1 ignored (with `play::tests::a_preload_mark_can_be_written_twice`), its tests `cache_paths` 2, `census` 2, `picked_folders` 8; `darner-core` 31; `darner-formats` 87 (7 ignored); `darner-game` 67. `darner-gpu`: 1772 passed, 1 failed, `host::refresh_tests::refresh_front_zero_arc_matches_and_runs_due` ("sift_indexed kept wrong dirty subset"). A second run with `--no-fail-fast` hung in `darner-gpu` instead (eight `host::refresh_tests` / `host::watch_pipe` tests over 60 s; I stopped its process after 10 min). This PR touches no file in `crates/`; that test passed 3 of 3 runs alone on f3840d7 (`cargo test -p darner-gpu --lib --locked refresh_front_zero_arc_matches_and_runs_due`). This is #389 (gate 3 not green on f3840d7, `darner-gpu` failing in half of the parallel runs), not fixed here. That `--no-fail-fast` run then went on: every other crate passed except `darner-shader`, 557 passed, 1 failed, `emit::waterfall_tests::sampled_marks_restore_early_depth_only_when_safe_in_pixel_shaders`, the test #389 reports failing every time on f3840d7 (that crate's run took 28 min). - `cargo xtask policy`: "asset policy: 555 files ok". - Gameplay, when relevant: RTX 4070 SUPER 12 GB, driver 617.42 (32.0.16.1742), Series S profile (the F1 menu file's choice), 1080 to 1440, DLSS performance, frame generation 2x, ray tracing off. Only the start matters here. - Shader wave sizes tested, when relevant: not relevant (no shader change). - Hardware dependence: likely general (no GPU code; only when a file is written). - Coverage gaps: diagnostics build only, not a release build. The start's own preload window (no `darner preload` before) was not run again with this build; it writes the mark through the same `write_mark` and the unit test covers two writes. `darner preload` with a single file (no mark expected) not run. Not run under Linux/Proton. Without `--all`, on a home that has a list of used pipelines, `darner preload` warms only those and writes no mark, as before. Hardware: i9-12900F, 32 GB DDR4-3200, RTX 4070 SUPER 12 GB, Windows 11 (pt-BR). ## Checklist - [x] I ran this change in the game, or say below why it can't be (docs, tests only). - [x] This PR contains one change based on `main`. - [x] The diff follows `docs/asset-policy.md`. - [x] I recorded this PR's dependencies below. - Depends on: none ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. - Related PRs: #153 and #264 change the mark's name (shared by content, kept across a translator change) in the same `play.rs` code; this writes through `mark_path`, so if one of them merges first I will rebase and write their mark here too. #140, #267 and #270 change what the preload does, not when the mark is written. #128 is the issue about the window opening again; its causes (a stopped preload, a new exe, a translator change) are different, and this is one more. - Replaces or overlaps: none found.
A `darner preload <game folder> --all` that finished left no warmed mark, so
the next `darner play` of the same darner.exe ran the whole preload again
(30.6 min here, right after the script's own preload). `darner preload` now
writes the mark the preload window writes, when it warmed every known
pipeline of the whole title and the cache is not a named DARNER_CACHE_DIR.

Refs #128

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Collaborator

Thank you, this is a useful fix, and the numbers are convincing: the world after 74 s instead of 1919 s on the next start.

Two things I found reading the diff against main. I have only read the code, not built or run it.

1. The mark it writes is only the byte-hash one. record_preload writes mark_path(&home, &program), the warmed\<hash of darner.exe> file (play.rs, record_preload). That is the mark the window waits for today. My open PR #153 (DARNER_WARM_SHARED=1) changes this: with the switch on, prepare picks shared_mark(&home) (warmed\shared-<hash>, by translator, card and driver), and window_mark then looks only at that file and ignores the exe's own mark (play.rs at #153 head 3854be8df, window_mark and the by_content lines in prepare). So with #153 and the switch on, a darner preload ... --all from a shell would still be followed by the full preload window.

Suggestion: let record_preload write the mark the window would choose, by calling the same code prepare uses (a small helper that takes the settings and returns the mark path), instead of calling mark_path directly. Then it keeps working whichever of the two lands first. shared_mark only needs the translator id and the DXGI adapter and driver, which the CLI process already has. One thing to watch: the CLI preload sees the switch only in the environment (warm::shared_on), while prepare sees it in the start's settings (shared_marks(&s)), so the helper should be given the switch as a bool rather than read it itself, or the two can disagree.

2. A subfolder counts as the whole title. whole_title = paths.iter().all(|p| p.is_dir()) is true for any folder. translate::precompile scans every folder it is given (scan_entries(root)), so darner preload <game>\<subfolder> --all would translate only that subfolder and still write the mark. An empty paths is fine: default_paths then uses game_dir and test_titles from the config.

Suggestion: compare the given paths with the configured title folder(s) (Config::load(), game_dir), after canonicalising both, and only record when they match.

(My open PR #140, DARNER_PRELOAD_RESUME, is not affected: its resume record is only read when the mark is not there yet, so a mark written by the CLI wins.)

Written with AI assistance (Claude Code).

Thank you, this is a useful fix, and the numbers are convincing: the world after 74 s instead of 1919 s on the next start. Two things I found reading the diff against `main`. I have only read the code, not built or run it. **1. The mark it writes is only the byte-hash one.** `record_preload` writes `mark_path(&home, &program)`, the `warmed\<hash of darner.exe>` file (`play.rs`, `record_preload`). That is the mark the window waits for today. My open PR #153 (`DARNER_WARM_SHARED=1`) changes this: with the switch on, `prepare` picks `shared_mark(&home)` (`warmed\shared-<hash>`, by translator, card and driver), and `window_mark` then looks only at that file and ignores the exe's own mark (`play.rs` at #153 head 3854be8df, `window_mark` and the `by_content` lines in `prepare`). So with #153 and the switch on, a `darner preload ... --all` from a shell would still be followed by the full preload window. Suggestion: let `record_preload` write the mark the window would choose, by calling the same code `prepare` uses (a small helper that takes the settings and returns the mark path), instead of calling `mark_path` directly. Then it keeps working whichever of the two lands first. `shared_mark` only needs the translator id and the DXGI adapter and driver, which the CLI process already has. One thing to watch: the CLI preload sees the switch only in the environment (`warm::shared_on`), while `prepare` sees it in the start's settings (`shared_marks(&s)`), so the helper should be given the switch as a bool rather than read it itself, or the two can disagree. **2. A subfolder counts as the whole title.** `whole_title = paths.iter().all(|p| p.is_dir())` is true for any folder. `translate::precompile` scans every folder it is given (`scan_entries(root)`), so `darner preload <game>\<subfolder> --all` would translate only that subfolder and still write the mark. An empty `paths` is fine: `default_paths` then uses `game_dir` and `test_titles` from the config. Suggestion: compare the given paths with the configured title folder(s) (`Config::load()`, `game_dir`), after canonicalising both, and only record when they match. (My open PR #140, `DARNER_PRELOAD_RESUME`, is not affected: its resume record is only read when the mark is not there yet, so a mark written by the CLI wins.) Written with AI assistance (Claude Code).
This pull request has changes conflicting with the target branch.
  • apps/darner/src/main.rs
  • apps/darner/src/play.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'preload-grava-marca:Skanzinho-preload-grava-marca'
git switch 'Skanzinho-preload-grava-marca'

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 'Skanzinho-preload-grava-marca'
git switch 'Skanzinho-preload-grava-marca'
git rebase 'main'
git switch 'main'
git merge --ff-only 'Skanzinho-preload-grava-marca'
git switch 'Skanzinho-preload-grava-marca'
git rebase 'main'
git switch 'main'
git merge --no-ff 'Skanzinho-preload-grava-marca'
git switch 'main'
git merge --squash 'Skanzinho-preload-grava-marca'
git switch 'main'
git merge --ff-only 'Skanzinho-preload-grava-marca'
git switch 'main'
git merge 'Skanzinho-preload-grava-marca'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
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
TrustNo1/Darner!435
No description provided.