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

Manually merged
TrustNo1 merged 1 commit from Skanzinho/Darner:preload-grava-marca into main 2026-12-05 04:51:35 +00:00
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).
Skanzinho force-pushed preload-grava-marca from 34384568d0 to df195a201e 2026-12-05 01:35:51 +00:00 Compare
Author
Contributor

Thanks for the review. Both points are addressed in df195a2, rebased on main 47d21cd (with #153, #140, #264, #267, #215 and #395 in).

1. The mark. record_preload now writes done_mark(home, program, by_content), which prepare also takes its preload_mark from: the shared mark with DARNER_WARM_SHARED=1, else the exe's. The switch is given to it as a bool (warm::shared_on(), from the environment, in the CLI; the window's child gets it in its environment from the start's settings), so the helper does not read it itself. New test: a_preload_from_a_shell_writes_the_mark_the_next_start_waits_for.

2. A subfolder. A folder now counts as the whole title only when it holds the game's executable (GAME, which prepare looks for next to darner.exe; the window passes exe.parent()), or when it is the configured game_dir (both canonicalised). No folder given is still the whole title (default_paths). I kept the executable check next to the game_dir one because the window's folder comes from the executable's location, not from game_dir: here there is no darner.toml and no DARNER_GAME_DIR, so a game_dir check alone would never record. New test: only_the_title_folder_is_the_whole_title (the title folder, a subfolder, a file, the configured folder, the same folder written another way, another folder).

Tested on df195a2 (diagnostics build, a new test DARNER_HOME with only the settings and the known-pipeline lists copied in; same PC and settings as in the description):

  • darner preload --all <game folder> with DARNER_WARM_SHARED=1 in the environment: exit 0, 43.4 min. warmed\ afterwards holds only shared-f2ebcd8bd0fd9a87, written when the preload ended.
  • The next start, scripts/bench.ps1 -Label pr435-shared-play -Switches 'DARNER_WARM_SHARED=1' (other options as in the description): no "not fully preloaded" and no "Shaders preloaded in" line in its darner.out.txt; the summary says "world after 77 s" and lists the switch.
  • With the switch off, done_mark is mark_path as before; that path is covered by the unit tests, and its in-game run is the one in the description (3438456).

Gates on df195a2:

  • 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, from darner-shader's emit::waterfall_tests::sampled_marks_restore_early_depth_only_when_safe_in_pixel_shaders only (#389). Every crate before it passed, darner-gpu included this time (1790 passed, 81 ignored), darner 195 passed, 1 ignored. The run stops at that failure, so the crates after darner-shader did not run here.
  • cargo test -p darner --locked: 195 passed, 1 ignored, with the two new tests and a_preload_mark_can_be_written_twice.
  • cargo xtask policy: "asset policy: 564 files ok".

Open PRs in the same code (#450 and #451, both WIP, read the old head 3438456): since df195a2 record_preload writes done_mark, the helper prepare takes its preload_mark from, so with #451 the second to land changes that one call to #451's helpers. #450's point stands: record_preload runs after into_library, so a stopped step 3 must not record, and the second to land adds the warm::stop::requested() check. If either lands first, I'll rebase this one.

Thanks for the review. Both points are addressed in df195a2, rebased on `main` 47d21cd (with #153, #140, #264, #267, #215 and #395 in). **1. The mark.** `record_preload` now writes `done_mark(home, program, by_content)`, which `prepare` also takes its `preload_mark` from: the shared mark with `DARNER_WARM_SHARED=1`, else the exe's. The switch is given to it as a bool (`warm::shared_on()`, from the environment, in the CLI; the window's child gets it in its environment from the start's settings), so the helper does not read it itself. New test: `a_preload_from_a_shell_writes_the_mark_the_next_start_waits_for`. **2. A subfolder.** A folder now counts as the whole title only when it holds the game's executable (`GAME`, which `prepare` looks for next to darner.exe; the window passes `exe.parent()`), or when it is the configured `game_dir` (both canonicalised). No folder given is still the whole title (`default_paths`). I kept the executable check next to the `game_dir` one because the window's folder comes from the executable's location, not from `game_dir`: here there is no `darner.toml` and no `DARNER_GAME_DIR`, so a `game_dir` check alone would never record. New test: `only_the_title_folder_is_the_whole_title` (the title folder, a subfolder, a file, the configured folder, the same folder written another way, another folder). **Tested on df195a2** (diagnostics build, a new test DARNER_HOME with only the settings and the known-pipeline lists copied in; same PC and settings as in the description): - `darner preload --all <game folder>` with `DARNER_WARM_SHARED=1` in the environment: exit 0, 43.4 min. `warmed\` afterwards holds only `shared-f2ebcd8bd0fd9a87`, written when the preload ended. - The next start, `scripts/bench.ps1 -Label pr435-shared-play -Switches 'DARNER_WARM_SHARED=1'` (other options as in the description): no "not fully preloaded" and no "Shaders preloaded in" line in its `darner.out.txt`; the summary says "world after 77 s" and lists the switch. - With the switch off, `done_mark` is `mark_path` as before; that path is covered by the unit tests, and its in-game run is the one in the description (3438456). **Gates on df195a2:** - `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, from `darner-shader`'s `emit::waterfall_tests::sampled_marks_restore_early_depth_only_when_safe_in_pixel_shaders` only (#389). Every crate before it passed, `darner-gpu` included this time (1790 passed, 81 ignored), `darner` 195 passed, 1 ignored. The run stops at that failure, so the crates after `darner-shader` did not run here. - `cargo test -p darner --locked`: 195 passed, 1 ignored, with the two new tests and `a_preload_mark_can_be_written_twice`. - `cargo xtask policy`: "asset policy: 564 files ok". **Open PRs in the same code** (#450 and #451, both WIP, read the old head 3438456): since df195a2 `record_preload` writes `done_mark`, the helper `prepare` takes its `preload_mark` from, so with #451 the second to land changes that one call to #451's helpers. #450's point stands: `record_preload` runs after `into_library`, so a stopped step 3 must not record, and the second to land adds the `warm::stop::requested()` check. If either lands first, I'll rebase this one.
TrustNo1 manually merged commit 2aefa48fc6 into main 2026-12-05 04:51:35 +00:00
Sign in to join this conversation.
No reviewers
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.