WIP: [pr-feature][startup][shaders] Preload window: live CPU-load presets and pause/resume (DARNER_PRELOAD_CONTROLS) #395

Manually merged
TrustNo1 merged 0 commits from Jesper-A/Darner:up-preload-controls into main 2026-12-04 22:17:36 +00:00
Collaborator

Refs #288

Contributor role (optional)

  • Fluxer ID:

What it changes

  • The problem on main: read from the code only. #288 (tarakanovalexey) is a request, not a bug report: the preload window has no way to lower the preload's CPU use or pause it while it runs.

#288 (tarakanovalexey) asks for two things the preload window cannot do today: lower how much of the PC the preload uses while it runs, and pause and resume it. This adds both, behind a new switch that is off by default. (The third part of #288, moving the cache folder, is already answered in the thread, so this is Refs, not Fixes.)

With DARNER_PRELOAD_CONTROLS=1:

  • The preload window (darner play) gets a row of buttons: 10 %, 50 %, 80 %, Max, and Pause / Resume, plus a line saying what is in force. The window is 46 px taller (96 dpi) to fit them. A preset button does not close the window.
  • DARNER_PRELOAD_LOAD=<1 to 100> sets the preset the preload starts with (default 100 = no limit). It is not read without the controls.
  • The window writes one line at a time to the stdin of its darner preload child: limit <pct>, pause, go. Lines not understood are ignored. If the window goes away, the last state stays.

How a limit works (apps/darner/src/preload_gate.rs, a new file): each of the three steps asks wait_turn(slot, threads) before it takes its next piece of work. A thread whose slot index is at or above max(1, ceil(p x threads / 100)) sleeps (100 ms steps) until the limit goes up. A pause parks every thread. Slots are numbered per step when each worker starts, so the same percentage works for steps with different thread counts.

Where the gate sits (on trustno1/main f3840d73d plus this commit, 50ed5a933):

  • Step 1, translating shaders: apps/darner/src/translate.rs:527 (single job) and :539 (before each shader).
  • Step 2, building pipelines in child processes: apps/darner/src/warm.rs:277, before a thread takes its next 40-pipeline chunk and starts a child.
  • Step 3, pipeline library: apps/darner/src/warm.rs:592, in the callback that known::make calls before each pipeline.

Unchanged with the switch off: wait_turn returns at once, no stdin pipe is created for the child, no thread is started, the window keeps its old height. The only code that runs is one cached env read.

Why a cooperative gate and not a job-object CPU cap: a hard CPU cap cannot pause. warm::run_child kills a child that prints nothing for 180 s, and a stopped child would be killed and blamed. Here a parked thread has no child running, so the watchdog has nothing to time.

Limits (please read)

  • A running piece of work finishes first. After Pause or a lower limit, a step 2 child finishes its 40-pipeline chunk, a step 1 shader finishes, a step 3 pipeline finishes. So a lower limit takes effect "within about that time", not at once. How long a child takes to drain is not measured.
  • The retry loop inside step 2 (while !rest.is_empty(), restarting a child after a failed start) is not gated. A thread already in it can start another child while paused.
  • The limit counts threads, not CPU percent. 50 % means half the threads may take new work; real CPU use will differ.
  • Not measured: how far a limit lowers the CPU use of a real preload.
  • Buttons are drawn with GDI like the rest of the window; there is no keyboard shortcut.

Credit: the request is tarakanovalexey's in #288. The design is our own; nothing is ported.

Docs: README table rows for both switches, a note in docs/findings.md, six new strings in locales/en.json and locales/zh-CN.json (zh-CN strings not checked by a native speaker).

A // SAFETY: comment will be added to the new unsafe block in preload_ui.rs::small before WIP comes off.

How it was tested

  • Tested revision: branch up-preload-controls @ 50ed5a933 (off trustno1/main f3840d73d).

  • Commands and results (taken from the porter's run on that revision; nothing here is CI):

    • cargo clippy --workspace --all-targets --locked -- -D warnings: clean
    • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: clean
    • cargo test -p darner --locked preload: 13 passed, 1 ignored (6 of them new, in preload_gate: line parsing, percent to slots, parked slots, a parked thread resuming, the listener, switch off)
    • cargo test -p darner --locked --bin darner translate: 7 passed
    • cargo xtask policy: ok
  • Changes a default: no. Both switches are off by default.

  • A/B result: the switch is off by default; that was checked by unit tests only (the_controls_are_off_unless_asked_for). No in-game run, no timing, no CPU measurement.

    A (off) B (on)
    not measured not run not run
  • Gates run on that revision: clippy workspace: yes. Clippy workspace with --all-features: yes. Full cargo test --workspace --locked: not run (only the two -p darner filters above). There is no CI upstream.

  • Gameplay, when relevant: not run in game, and the preload was not run with this change. The window was not opened. Machine for any later run: RTX 2070 SUPER 8 GB (Turing), driver 621.40, ReBAR off, Ryzen 7 5800X (8 cores, 16 threads), 32 GB, Windows 11 Pro Insider 26320, Series S, DLSS Performance.

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

  • Hardware dependence: likely general (thread parking and a stdin line protocol, no GPU or shader code). How much CPU a preset frees may depend on the CPU and its thread count. Details in "Spec dependence" below.

  • Coverage gaps: UI layout with the extra row (and at higher dpi), the real CPU effect of 10 / 50 / 80 / Max, Pause in all three steps, the 180 s watchdog after a long pause, the zh-CN strings, the full workspace tests. All of these need a real preload and are to be checked before WIP comes off. Not tested on other CPUs, Wine/Proton, AMD/Intel, Series X.

Checklist

  • I ran this change in the game, or say below why it can't be (docs, tests only).
    • Not ticked: not run in game yet. The PR stays a draft (WIP) until it has been.
  • This PR contains one change based on main.
  • The diff follows docs/asset-policy.md (cargo xtask policy: ok).
  • I recorded this PR's dependencies below.
    • Depends on: none

Spec dependence

  • Likely general (helps any card): the gate is plain thread parking and a stdin line protocol; it does not touch the GPU, shaders or translation.
  • May depend on our specs (RTX 2070 SUPER Turing wave32, 8 GB VRAM near budget, ReBAR off, Ryzen 7 5800X, 32 GB RAM, Series S + DLSS Performance): how much CPU a given preset frees depends on the thread count (the slot count is computed from it) and on the CPU. Only unit tests ran, with example thread counts; nothing was run on the 5800X's 16 threads.
  • Untested elsewhere (other CPUs and core counts, AMD/Intel GPUs, Wine/Proton, Series X): all of it. Wine/Proton in particular: the stdin pipe and the Windows window are only on the Windows build path.

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches.
  • Related PRs: #215, #165, #234, #266, #140, #142, #264, #267, #270, #293, #235 (related by files or topic, not the same change). Conflicts are expected with #215 (preload_ui.rs layout and run, locales/*.json), #165 and #234 (translate.rs / warm.rs), #266 (into_library workers). Whichever lands second rebases; the gate calls are single lines and the UI hunk is the part that needs care.
  • Replaces or overlaps: none found (searched open PRs for preload, pause, throttle, load). Nobody claimed #288.

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

Refs #288 ## Contributor role (optional) - Fluxer ID: ## What it changes - The problem on main: read from the code only. #288 (tarakanovalexey) is a request, not a bug report: the preload window has no way to lower the preload's CPU use or pause it while it runs. #288 (tarakanovalexey) asks for two things the preload window cannot do today: lower how much of the PC the preload uses while it runs, and pause and resume it. This adds both, behind a new switch that is off by default. (The third part of #288, moving the cache folder, is already answered in the thread, so this is `Refs`, not `Fixes`.) With `DARNER_PRELOAD_CONTROLS=1`: - The preload window (`darner play`) gets a row of buttons: **10 %**, **50 %**, **80 %**, **Max**, and **Pause / Resume**, plus a line saying what is in force. The window is 46 px taller (96 dpi) to fit them. A preset button does not close the window. - `DARNER_PRELOAD_LOAD=<1 to 100>` sets the preset the preload starts with (default 100 = no limit). It is not read without the controls. - The window writes one line at a time to the stdin of its `darner preload` child: `limit <pct>`, `pause`, `go`. Lines not understood are ignored. If the window goes away, the last state stays. How a limit works (`apps/darner/src/preload_gate.rs`, a new file): each of the three steps asks `wait_turn(slot, threads)` before it takes its next piece of work. A thread whose slot index is at or above `max(1, ceil(p x threads / 100))` sleeps (100 ms steps) until the limit goes up. A pause parks every thread. Slots are numbered per step when each worker starts, so the same percentage works for steps with different thread counts. Where the gate sits (on `trustno1/main` f3840d73d plus this commit, 50ed5a933): - Step 1, translating shaders: `apps/darner/src/translate.rs:527` (single job) and `:539` (before each shader). - Step 2, building pipelines in child processes: `apps/darner/src/warm.rs:277`, before a thread takes its next 40-pipeline chunk and starts a child. - Step 3, pipeline library: `apps/darner/src/warm.rs:592`, in the callback that `known::make` calls before each pipeline. **Unchanged with the switch off:** `wait_turn` returns at once, no stdin pipe is created for the child, no thread is started, the window keeps its old height. The only code that runs is one cached env read. **Why a cooperative gate and not a job-object CPU cap:** a hard CPU cap cannot pause. `warm::run_child` kills a child that prints nothing for 180 s, and a stopped child would be killed and blamed. Here a parked thread has no child running, so the watchdog has nothing to time. ### Limits (please read) - A running piece of work finishes first. After Pause or a lower limit, a step 2 child finishes its 40-pipeline chunk, a step 1 shader finishes, a step 3 pipeline finishes. So a lower limit takes effect "within about that time", not at once. How long a child takes to drain is not measured. - The retry loop inside step 2 (`while !rest.is_empty()`, restarting a child after a failed start) is not gated. A thread already in it can start another child while paused. - The limit counts threads, not CPU percent. 50 % means half the threads may take new work; real CPU use will differ. - Not measured: how far a limit lowers the CPU use of a real preload. - Buttons are drawn with GDI like the rest of the window; there is no keyboard shortcut. Credit: the request is tarakanovalexey's in #288. The design is our own; nothing is ported. Docs: README table rows for both switches, a note in `docs/findings.md`, six new strings in `locales/en.json` and `locales/zh-CN.json` (zh-CN strings not checked by a native speaker). A `// SAFETY:` comment will be added to the new `unsafe` block in `preload_ui.rs::small` before WIP comes off. ## How it was tested - Tested revision: branch `up-preload-controls` @ 50ed5a933 (off `trustno1/main` f3840d73d). - Commands and results (taken from the porter's run on that revision; nothing here is CI): - `cargo clippy --workspace --all-targets --locked -- -D warnings`: clean - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: clean - `cargo test -p darner --locked preload`: 13 passed, 1 ignored (6 of them new, in `preload_gate`: line parsing, percent to slots, parked slots, a parked thread resuming, the listener, switch off) - `cargo test -p darner --locked --bin darner translate`: 7 passed - `cargo xtask policy`: ok - Changes a default: no. Both switches are off by default. - A/B result: the switch is off by default; that was checked by unit tests only (`the_controls_are_off_unless_asked_for`). No in-game run, no timing, no CPU measurement. | | A (off) | B (on) | |---|---|---| | not measured | not run | not run | - Gates run on that revision: clippy workspace: yes. Clippy workspace with `--all-features`: yes. Full `cargo test --workspace --locked`: **not run** (only the two `-p darner` filters above). There is no CI upstream. - Gameplay, when relevant: not run in game, and the preload was not run with this change. The window was not opened. Machine for any later run: RTX 2070 SUPER 8 GB (Turing), driver 621.40, ReBAR off, Ryzen 7 5800X (8 cores, 16 threads), 32 GB, Windows 11 Pro Insider 26320, Series S, DLSS Performance. - Shader wave sizes tested, when relevant: not relevant (no shader translation change). - Hardware dependence: likely general (thread parking and a stdin line protocol, no GPU or shader code). How much CPU a preset frees may depend on the CPU and its thread count. Details in "Spec dependence" below. - Coverage gaps: UI layout with the extra row (and at higher dpi), the real CPU effect of 10 / 50 / 80 / Max, Pause in all three steps, the 180 s watchdog after a long pause, the zh-CN strings, the full workspace tests. All of these need a real preload and are to be checked before WIP comes off. Not tested on other CPUs, Wine/Proton, AMD/Intel, Series X. ## Checklist - [ ] I ran this change in the game, or say below why it can't be (docs, tests only). - Not ticked: not run in game yet. The PR stays a draft (WIP) until it has been. - [x] This PR contains one change based on `main`. - [x] The diff follows `docs/asset-policy.md` (`cargo xtask policy`: ok). - [x] I recorded this PR's dependencies below. - Depends on: none ## Spec dependence - Likely general (helps any card): the gate is plain thread parking and a stdin line protocol; it does not touch the GPU, shaders or translation. - May depend on our specs (RTX 2070 SUPER Turing wave32, 8 GB VRAM near budget, ReBAR off, Ryzen 7 5800X, 32 GB RAM, Series S + DLSS Performance): how much CPU a given preset frees depends on the thread count (the slot count is computed from it) and on the CPU. Only unit tests ran, with example thread counts; nothing was run on the 5800X's 16 threads. - Untested elsewhere (other CPUs and core counts, AMD/Intel GPUs, Wine/Proton, Series X): all of it. Wine/Proton in particular: the stdin pipe and the Windows window are only on the Windows build path. ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. - Related PRs: #215, #165, #234, #266, #140, #142, #264, #267, #270, #293, #235 (related by files or topic, not the same change). Conflicts are expected with #215 (`preload_ui.rs` layout and `run`, `locales/*.json`), #165 and #234 (`translate.rs` / `warm.rs`), #266 (`into_library` workers). Whichever lands second rebases; the gate calls are single lines and the UI hunk is the part that needs care. - Replaces or overlaps: none found (searched open PRs for preload, pause, throttle, load). Nobody claimed #288. This change was made with AI assistance (Claude Code).
Refs #288. Behind DARNER_PRELOAD_CONTROLS=1 (off by default): the preload
window gets 10 / 50 / 80 / Max and Pause/Resume buttons. Each step asks a
cooperative gate before taking new work (next shader, next warm chunk,
next library pipeline); work that has begun finishes, so the silent-child
watchdog never times a pause. The window talks to `darner preload` over
its stdin. DARNER_PRELOAD_LOAD sets the start preset.

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

At 50ed5a93, a preset below Max can stop a step from finishing. In the translation and child stages, workers parked by slot number stay inside the gate after the admitted workers drain the queue. In the library stage, those parked workers also own fixed slices of the work, so the step waits for them.

f088d7d limits simultaneous operations and lets any worker use a free slot. A slot is held for one shader, one child process (including a retry), or one library pipeline. Pause still lets work in progress finish.

A Windows fixture used the gate from both revisions with four workers, eight operations and the 50% preset. The original timed out waiting for the step to join. The follow-up completed all eight operations exactly once, with two active at peak. All seven gate tests, scoped app Clippy and asset policy passed. The full preload and the window remain to be checked.

If you cherry-pick or rebase this commit, please keep the Git author. If you fold it into another commit, please add this trailer.

Co-authored-by: andrewpozdnakov7-jpg <[email protected]>

At `50ed5a93`, a preset below Max can stop a step from finishing. In the translation and child stages, workers parked by slot number stay inside the gate after the admitted workers drain the queue. In the library stage, those parked workers also own fixed slices of the work, so the step waits for them. [f088d7d](https://git.gtahub.st/andrewpozdnakov7-jpg/Darner/commit/f088d7d525bd8d72b1269d576c2eb9b947527f02) limits simultaneous operations and lets any worker use a free slot. A slot is held for one shader, one child process (including a retry), or one library pipeline. Pause still lets work in progress finish. A Windows fixture used the gate from both revisions with four workers, eight operations and the 50% preset. The original timed out waiting for the step to join. The follow-up completed all eight operations exactly once, with two active at peak. All seven gate tests, scoped app Clippy and asset policy passed. The full preload and the window remain to be checked. If you cherry-pick or rebase this commit, please keep the Git author. If you fold it into another commit, please add this trailer. `Co-authored-by: andrewpozdnakov7-jpg <296776509+[email protected]>`
TrustNo1 manually merged commit 02a0edf851 into main 2026-12-04 22:17:36 +00:00
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!395
No description provided.