WIP: [pr-feature][startup][shaders] Preload window: share its mark across darner.exe copies with the same translator, card and driver (DARNER_WARM_SHARED, off by default) #153

Draft
Jesper-A wants to merge 3 commits from Jesper-A/Darner:up-preload-marks-shared into main
Contributor

Refs #128

Contributor role (optional)

  • Fluxer ID: not given

What it changes

Step 4 of #128 (the done marks keep the exe's bytes, so every new build or copy opens the preload window again). Steps so far: #140 (remember an unfinished preload), #142 (skip title files an earlier run finished); step 3 (separate draft).

With DARNER_WARM_SHARED=1 (off by default; the switch already exists for darner warm --used), the start's preload mark is warmed/shared-<first 16 hex of blake3(translator id, card, driver)> instead of warmed/<first 16 hex of blake3 of darner.exe>. A second build or copy of darner.exe with the same translator, card and driver then does not open the preload window.

  • Both the window's trigger (warmup_mark) and the mark a finished preload writes (preload_mark) use the shared file. They were one file before, so there is no way to share one and not the other without writing two files.
  • The "cache has no host pipelines" check (needs_pipelines) still opens the window when the library is empty.
  • With no translator id the old exe-keyed marks are used.
  • All other warm marks (warm-done.txt) keep the exe path, as before.
  • New pub fn adapter_driver() in crates/darner-shader/src/emit/host.rs: the driver version as CheckInterfaceSupport gives it (0 if unknown). Its doc comment names Host::driver (crates/darner-gpu/src/host.rs:2511), which pipeline/known.rs:447 and :462 hash into the warm marks. Both take hardware_adapter(); they differ only if device creation on it fails and the host falls back to the default adapter (host.rs:2353).
  • shared_marks() reads only the start's settings (darner-settings.txt or --set). prepare clears every DARNER_* variable that is not in KEPT, so an environment-only DARNER_WARM_SHARED used to make the window mark shared while the preload's warm::shared_on() saw it unset. Now both see the same value. This is a detail of the new switch only; with the switch off nothing changes. The test gained an assertion for it.
  • README row and docs/findings.md updated: they now say that a new exe that finds the shared mark skips the whole preload and gets only the shared pipeline library (the early and slow pipelines), and that the other pipelines are built in game on first use (NVIDIA keeps its driver cache per program path; possible hitches, not measured).

Off (the default) is unchanged.

Open question for the maintainer (why this is WIP)

Step 4 of #128 says "key the done marks without the exe path"; the code has the window mark and the preload mark as one file, so the shared mark also records that the preload finished. What that changes, from reading the code (not measured):

  • darner preload --all (what the window runs) does three things: translates the shaders, warm::run (makes every known pipeline in worker processes, which fills the driver's cache), and warm::into_library (stores only the early and slow pipelines in host-pipelines.bin).
  • The library is named by content, so a second exe can use it. The driver's cache is not: warm.rs says the driver keeps what it makes by program path and card (we assume NVIDIA does; not measured by us).
  • So a new exe that finds the shared mark skips all three. It gets the early and slow pipelines from the library, but the rest of the known pipelines are not in its driver cache, and are made in the game when first used.
  • I do not know whether a missing pipeline only costs a hitch: warm.rs:183-189 mentions black parts in the picture when a pipeline was not made for the program or card. Not tested. At best it is a start-time and hitch trade: the window does not open, but the new exe has not been warmed. The README row and docs/findings.md still say only "possible hitches" and do not mention the black-parts possibility; see the open box at the end.
  • With the switch turned off again, the exe's own mark is missing, so the window opens once.
  • Interaction with #140: its partial record is keyed by the mark path. With a shared mark, a partial preload by one exe would be read as "resume" by another exe whose driver cache is empty.

Question: is skipping the whole preload for a new exe, with possible in-game hitches on NVIDIA from the per-exe driver cache, the trade step 4 of #128 wants? Or should a new exe still run warm::run without the window? I can change it either way.

How it was tested

  • Tested revision: f2fe5bebe (two commits, 22abbecd7 and f2fe5bebe), on main 57dea7f23.
  • Commands and results:
    • cargo test --locked -j 4 -p darner --bin darner -- shared warmup two_exes: 7 passed.
    • cargo clippy --workspace --all-targets --locked -j 4 -- -D warnings (AGENTS.md gate 1): clean.
    • cargo xtask policy: 553 ok.
    • Not run: gate 2 (cargo clippy --workspace --all-targets --all-features --locked -- -D warnings) and gate 3 (cargo test --workspace --locked).
    • There is no CI.
  • Gameplay, when relevant: not run.
  • Before and after, when relevant: not measured.
  • Shader wave sizes tested, when relevant: not relevant (no shader output changes).
  • Coverage gaps:
    • No real second darner.exe was started; the tests use two temporary files as exes.
    • The start-time effect, and the hitches of a new exe that skips the preload, are unmeasured.
    • adapter_driver() and Host::driver take the same adapter except in the device-creation fallback described above; I did not check this on a PC with two cards.
    • The env-versus-settings fix is covered by one unit assertion; not tried with a real start.
    • adapter_driver() is a new public function in darner-shader; if AGENTS.md or you want public functions named or kept private, I will change it.
    • Not tried on AMD, Intel, Series X or Linux/Proton.

Spec dependence

Likely general: the mark logic is in the launcher and does not depend on the GPU. What it saves, and what it costs, may depend on the GPU: the cost described above comes from the driver keeping compiled pipelines per program path (we assume this holds on NVIDIA; not measured). Written on an RTX 2070 SUPER 8 GB (Turing), driver 621.40, Resizable BAR off, Ryzen 7 5800X, 32 GB, Windows 11 Pro Insider 26320. Untested on other cards.

Checklist

  • 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
  • README row and docs/findings.md wording to align with the open question (they still say "NVIDIA" and "possible hitches" and do not mention the black-parts possibility, warm.rs:183-189). Open until the maintainer answers.

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches.
  • Related PRs:
    • #140 and #142 (steps 1 and 2 of #128). I trial-merged this branch with git merge-tree --write-tree: #142 merges cleanly; #140 has one conflict in apps/darner/src/play.rs, where both add tests at the same place in the test module (the code does not overlap). #140's partial record is keyed by the mark, see the open question. Whichever merges second needs a small rebase.
    • #130, #132, #125: merge cleanly (#125 touches warm.rs, #130 and #132 touch play.rs, in other places).
    • No other open PR touches warm.rs or emit/host.rs. Other PRs that touch play.rs or the README (#36, #59, #75, #80) also merge cleanly.

Drafted with AI assistance (Claude Code).

Refs #128 ## Contributor role (optional) - Fluxer ID: not given ## What it changes Step 4 of #128 (the done marks keep the exe's bytes, so every new build or copy opens the preload window again). Steps so far: #140 (remember an unfinished preload), #142 (skip title files an earlier run finished); step 3 (separate draft). With `DARNER_WARM_SHARED=1` (off by default; the switch already exists for `darner warm --used`), the start's preload mark is `warmed/shared-<first 16 hex of blake3(translator id, card, driver)>` instead of `warmed/<first 16 hex of blake3 of darner.exe>`. A second build or copy of darner.exe with the same translator, card and driver then does not open the preload window. - Both the window's trigger (`warmup_mark`) and the mark a finished preload writes (`preload_mark`) use the shared file. They were one file before, so there is no way to share one and not the other without writing two files. - The "cache has no host pipelines" check (`needs_pipelines`) still opens the window when the library is empty. - With no translator id the old exe-keyed marks are used. - All other warm marks (`warm-done.txt`) keep the exe path, as before. - New `pub fn adapter_driver()` in `crates/darner-shader/src/emit/host.rs`: the driver version as `CheckInterfaceSupport` gives it (0 if unknown). Its doc comment names `Host::driver` (`crates/darner-gpu/src/host.rs:2511`), which `pipeline/known.rs:447` and `:462` hash into the warm marks. Both take `hardware_adapter()`; they differ only if device creation on it fails and the host falls back to the default adapter (`host.rs:2353`). - `shared_marks()` reads only the start's settings (`darner-settings.txt` or `--set`). `prepare` clears every `DARNER_*` variable that is not in `KEPT`, so an environment-only `DARNER_WARM_SHARED` used to make the window mark shared while the preload's `warm::shared_on()` saw it unset. Now both see the same value. This is a detail of the new switch only; with the switch off nothing changes. The test gained an assertion for it. - README row and `docs/findings.md` updated: they now say that a new exe that finds the shared mark skips the whole preload and gets only the shared pipeline library (the early and slow pipelines), and that the other pipelines are built in game on first use (NVIDIA keeps its driver cache per program path; possible hitches, not measured). Off (the default) is unchanged. ### Open question for the maintainer (why this is WIP) Step 4 of #128 says "key the done marks without the exe path"; the code has the window mark and the preload mark as one file, so the shared mark also records that the preload finished. What that changes, from reading the code (not measured): - `darner preload --all` (what the window runs) does three things: translates the shaders, `warm::run` (makes every known pipeline in worker processes, which fills the driver's cache), and `warm::into_library` (stores only the early and slow pipelines in `host-pipelines.bin`). - The library is named by content, so a second exe can use it. The driver's cache is not: `warm.rs` says the driver keeps what it makes by program path and card (we assume NVIDIA does; not measured by us). - So a new exe that finds the shared mark skips all three. It gets the early and slow pipelines from the library, but the rest of the known pipelines are not in its driver cache, and are made in the game when first used. - I do not know whether a missing pipeline only costs a hitch: `warm.rs:183-189` mentions black parts in the picture when a pipeline was not made for the program or card. Not tested. At best it is a start-time and hitch trade: the window does not open, but the new exe has not been warmed. The README row and `docs/findings.md` still say only "possible hitches" and do not mention the black-parts possibility; see the open box at the end. - With the switch turned off again, the exe's own mark is missing, so the window opens once. - Interaction with #140: its partial record is keyed by the mark path. With a shared mark, a partial preload by one exe would be read as "resume" by another exe whose driver cache is empty. Question: is skipping the whole preload for a new exe, with possible in-game hitches on NVIDIA from the per-exe driver cache, the trade step 4 of #128 wants? Or should a new exe still run `warm::run` without the window? I can change it either way. ## How it was tested - Tested revision: `f2fe5bebe` (two commits, `22abbecd7` and `f2fe5bebe`), on `main` 57dea7f23. - Commands and results: - `cargo test --locked -j 4 -p darner --bin darner -- shared warmup two_exes`: 7 passed. - `cargo clippy --workspace --all-targets --locked -j 4 -- -D warnings` (AGENTS.md gate 1): clean. - `cargo xtask policy`: 553 ok. - Not run: gate 2 (`cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`) and gate 3 (`cargo test --workspace --locked`). - There is no CI. - Gameplay, when relevant: not run. - Before and after, when relevant: not measured. - Shader wave sizes tested, when relevant: not relevant (no shader output changes). - Coverage gaps: - No real second darner.exe was started; the tests use two temporary files as exes. - The start-time effect, and the hitches of a new exe that skips the preload, are unmeasured. - `adapter_driver()` and `Host::driver` take the same adapter except in the device-creation fallback described above; I did not check this on a PC with two cards. - The env-versus-settings fix is covered by one unit assertion; not tried with a real start. - `adapter_driver()` is a new public function in `darner-shader`; if AGENTS.md or you want public functions named or kept private, I will change it. - Not tried on AMD, Intel, Series X or Linux/Proton. ## Spec dependence Likely general: the mark logic is in the launcher and does not depend on the GPU. What it saves, and what it costs, may depend on the GPU: the cost described above comes from the driver keeping compiled pipelines per program path (we assume this holds on NVIDIA; not measured). Written on an RTX 2070 SUPER 8 GB (Turing), driver 621.40, Resizable BAR off, Ryzen 7 5800X, 32 GB, Windows 11 Pro Insider 26320. Untested on other cards. ## Checklist - [ ] This PR contains one change based on `main`. - [ ] The diff follows `docs/asset-policy.md`. - [x] I recorded this PR's dependencies below. - Depends on: none - [ ] README row and docs/findings.md wording to align with the open question (they still say "NVIDIA" and "possible hitches" and do not mention the black-parts possibility, warm.rs:183-189). Open until the maintainer answers. ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. - Related PRs: - #140 and #142 (steps 1 and 2 of #128). I trial-merged this branch with `git merge-tree --write-tree`: #142 merges cleanly; #140 has one conflict in `apps/darner/src/play.rs`, where both add tests at the same place in the test module (the code does not overlap). #140's partial record is keyed by the mark, see the open question. Whichever merges second needs a small rebase. - #130, #132, #125: merge cleanly (#125 touches `warm.rs`, #130 and #132 touch `play.rs`, in other places). - No other open PR touches `warm.rs` or `emit/host.rs`. Other PRs that touch `play.rs` or the README (#36, #59, #75, #80) also merge cleanly. Drafted with AI assistance (Claude Code).
With the switch on, the start's preload mark is warmed/shared-<hash of
translator id, card, driver> instead of one by this darner.exe's bytes, so a
new build or folder on the same translator does not open the window again.
Off (default) is unchanged. The other warm marks keep the exe path, because
NVIDIA keeps compiled pipelines per program path. Adds
darner_shader::emit::host::adapter_driver().

This change was made with AI assistance (Claude Code).
adapter_driver's comment now names Host::driver and the warm marks in
pipeline/known.rs (HostPipelines does not exist). README and findings say
that a new darner.exe finding the shared mark skips the whole preload and
gets only the shared pipeline library; NVIDIA's per-program driver cache
means the other pipelines are built in game on first use (not measured).

shared_marks no longer falls back to the environment: prepare clears every
DARNER_* variable not in the settings, so an environment-only value made
the window mark shared while warm::shared_on read false afterwards.

This change was made with AI assistance (Claude Code).
First-time contributor

Tested f2fe5be on Windows, RTX 5080 (driver 32.0.16.2140):

  • play::tests 56 passed (incl. the 3 new mark tests); darner-shader adapter tests 3 passed.
  • Two darner.exe copies with different bytes, --set DARNER_WARM_SHARED=1: the first wrote warmed\shared-0b26aad2235ce5e2 and the second skipped the preload window; with the switch off the second opened the window and wrote its own mark. An environment-only DARNER_WARM_SHARED=1 (no --set) was ignored.
  • In a real launch of the game (same card/driver, the shared mark seeded into the real warmed folder): no preload window appeared, and the first frame came at launch+10.6 s. Without the mark, the window builds 76,721 pipelines (measured 1,400 in 82 s).

Not tested: the in-game hitch benefit, other cards/drivers.

Drafted with AI assistance (OpenCode).

Tested f2fe5be on Windows, RTX 5080 (driver 32.0.16.2140): - `play::tests` 56 passed (incl. the 3 new mark tests); `darner-shader` adapter tests 3 passed. - Two darner.exe copies with different bytes, `--set DARNER_WARM_SHARED=1`: the first wrote `warmed\shared-0b26aad2235ce5e2` and the second skipped the preload window; with the switch off the second opened the window and wrote its own mark. An environment-only `DARNER_WARM_SHARED=1` (no `--set`) was ignored. - In a real launch of the game (same card/driver, the shared mark seeded into the real warmed folder): no preload window appeared, and the first frame came at launch+10.6 s. Without the mark, the window builds 76,721 pipelines (measured 1,400 in 82 s). Not tested: the in-game hitch benefit, other cards/drivers. Drafted with AI assistance (OpenCode).
Owner

Second-opinion review: merge after a small fix. The shared mark (warmed/shared-<blake3(translator, card, driver)>) is keyed right, and a tester confirmed f2fe5be with two exes and a real launch (first frame at 10.6 s). Two small points:

  • The new docs/findings.md paragraph lands just before the unrelated DARNER_KEY_STICK_MENU bullet; move it to its own place.
  • warm::shared_on became pub(crate) but nothing new uses it.
    The trade-off is documented: a new exe skips the whole preload, so the driver's cache for its path is built during play. Drop WIP when ready. It conflicts with #140 in play.rs; whichever goes second resolves it.
Second-opinion review: merge after a small fix. The shared mark (`warmed/shared-<blake3(translator, card, driver)>`) is keyed right, and a tester confirmed f2fe5be with two exes and a real launch (first frame at 10.6 s). Two small points: - The new docs/findings.md paragraph lands just before the unrelated `DARNER_KEY_STICK_MENU` bullet; move it to its own place. - `warm::shared_on` became `pub(crate)` but nothing new uses it. The trade-off is documented: a new exe skips the whole preload, so the driver's cache for its path is built during play. Drop WIP when ready. It conflicts with #140 in play.rs; whichever goes second resolves it.
Move the DARNER_WARM_SHARED preload-mark paragraph out from before the
unrelated DARNER_KEY_STICK_MENU bullet into its own section, and revert
warm::shared_on to its previous (private) visibility, as nothing outside
the module uses it.

This change was made with AI assistance (Claude Code).
Author
Contributor

Thanks for the review and for the test on f2fe5be. Both points are fixed in 3854be8df:

  • docs/findings.md: the paragraph now has its own heading, "Preload window mark shared (DARNER_WARM_SHARED=1, off by default)". It sits before "NIS sharpening after DLSS". The DARNER_KEY_STICK_MENU bullet is back where it was.
  • apps/darner/src/warm.rs: shared_on is a private fn again, as on main. Nothing outside the module calls it.

The commit changes 2 files (+5/-2). No logic changed.

Checked on 3854be8df: cargo test --locked -p darner --bin darner warm (16 passed). The asset-policy check passed in the pre-commit hook.

Not re-run on 3854be8df: cargo clippy --workspace --all-targets --locked -- -D warnings, the same with --all-features, and cargo test --workspace --locked. Not tested: the in-game hitch benefit, other cards or drivers.

On the conflict with #140 in play.rs: I will resolve it on whichever of the two goes second.

I will rebase onto main, re-run the three gates and drop WIP once you are happy with this.

This reply was drafted with AI assistance (Claude Code).

Thanks for the review and for the test on f2fe5be. Both points are fixed in 3854be8df: - `docs/findings.md`: the paragraph now has its own heading, "Preload window mark shared (DARNER_WARM_SHARED=1, off by default)". It sits before "NIS sharpening after DLSS". The `DARNER_KEY_STICK_MENU` bullet is back where it was. - `apps/darner/src/warm.rs`: `shared_on` is a private `fn` again, as on main. Nothing outside the module calls it. The commit changes 2 files (+5/-2). No logic changed. Checked on 3854be8df: `cargo test --locked -p darner --bin darner warm` (16 passed). The asset-policy check passed in the pre-commit hook. Not re-run on 3854be8df: `cargo clippy --workspace --all-targets --locked -- -D warnings`, the same with `--all-features`, and `cargo test --workspace --locked`. Not tested: the in-game hitch benefit, other cards or drivers. On the conflict with #140 in `play.rs`: I will resolve it on whichever of the two goes second. I will rebase onto main, re-run the three gates and drop WIP once you are happy with this. This reply was drafted with AI assistance (Claude Code).
This pull request is marked as a work in progress.
This branch is out-of-date with the base branch
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'up-preload-marks-shared:Jesper-A-up-preload-marks-shared'
git switch 'Jesper-A-up-preload-marks-shared'

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 'Jesper-A-up-preload-marks-shared'
git switch 'Jesper-A-up-preload-marks-shared'
git rebase 'main'
git switch 'main'
git merge --ff-only 'Jesper-A-up-preload-marks-shared'
git switch 'Jesper-A-up-preload-marks-shared'
git rebase 'main'
git switch 'main'
git merge --no-ff 'Jesper-A-up-preload-marks-shared'
git switch 'main'
git merge --squash 'Jesper-A-up-preload-marks-shared'
git switch 'main'
git merge --ff-only 'Jesper-A-up-preload-marks-shared'
git switch 'main'
git merge 'Jesper-A-up-preload-marks-shared'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
3 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!153
No description provided.