WIP: Preload controls: a limit below Max no longer stops a step from finishing (DARNER_PRELOAD_CONTROLS) #458

Draft
Jesper-A wants to merge 1 commit from Jesper-A/Darner:up-preload-controls-gate-fix into Main
Collaborator

Refs #395
Refs #128

Contributor role (optional)

  • Fluxer ID:

What it changes

Follow-up to #395 (merged at 02a0edf85). #395 is merged, so this is a new PR. It carries the fix that andrewpozdnakov7-jpg reported on #395: #395 (comment). That fix is not in the merged #395.

  • The problem on main: with DARNER_PRELOAD_CONTROLS=1 and a preset below Max, a preload step can fail to finish. Workers were parked by slot number. In the translation and child-process steps, the parked workers stayed in the gate after the admitted ones had emptied the queue. In the library step, the parked workers also own fixed slices of the work, so the step waited for them for ever. This is from andrewpozdnakov7-jpg's report (he ran it with a test of the gate on Windows) and from reading the code. I did not run a full preload to see the hang.
  • What this does: the gate is now a counting limit on concurrent operations (apps/darner/src/preload_gate.rs). A worker takes a permit before each operation and gives it back after (when the permit is dropped). An operation is one shader, one chunk of child processes with its retries, or one library pipeline. The number of permits is ceil(percent x threads / 100), at least one. Any worker may take a free permit, so no worker owns a slot and every slice still gets done, only more slowly.
    • Pause hands out no new permit. A lowered limit or a pause applies to the next permit; work in progress finishes (as before).
    • translate.rs and warm.rs (run and into_library) ask for the permit before they take their next piece of work.
    • Controls off: wait_turn returns at once with nothing to hold, as before.
  • Also adds the missing SAFETY: comment on the unsafe block in preload_ui::small.
  • Tests: the gate tests were rewritten for permits, and two are new. translate::a_limit_below_max_still_finishes_the_step (4 workers, 8 shaders, 50 %) must finish within 10 s with every shader done once and no more than 2 at a time. preload_gate::fixed_slices_all_get_done_below_max does the same for the library's fixed slices. The commit message says the first test timed out before the change; I did not re-run the old code for this post.

Credit: the counting gate with a permit given back on drop is andrewpozdnakov7-jpg's commit f088d7d (andrewpozdnakov7-jpg/Darner@f088d7d525), as he asked. Our commit has his Co-authored-by: trailer. The code here is adapted to main.

Please check the warm.rs hunk. It conflicted with #266's chunk queue (merged), and I resolved it by hand. In into_library the callback is now let mut each (it is FnMut: it keeps a turn for the pipeline in progress) and is passed as &mut each. In run the loop takes its permit first and the chunk second (let _turn = wait_turn(threads), then chunks.get(next...)), so a worker that waits has taken no chunk. Please read these two places against #266's queue.

Merge check: this branch is on main 47d21cd3b. Main is now d91d8e4d6. git merge-tree --write-tree trustno1/main <branch> gives a clean tree, no conflicts.

How it was tested

  • Tested revision: branch up-preload-controls-gate-fix @ 935c00915, based on main 47d21cd3b.
  • Commands and results, as reported by the porter (scoped to -p darner; the three workspace gates were not run):
    • clippy -D warnings, plain and --all-features (-p darner), as reported by the porter: clean.
    • cargo test -p darner --bin darner: 195 passed, 1 ignored, in the porter's run on 935c00915.
    • cargo xtask policy through the pre-commit hook: ok.
  • Changes a default: no. DARNER_PRELOAD_CONTROLS stays off by default; with it off the gate does nothing, as before.
  • A/B result: none. A switch that is off by default; no speed claim.
  • Gates run on that revision: only the scoped ones above. Not run: the workspace clippy (with and without --all-features) and cargo test --workspace --locked. There is no CI.
  • Gameplay: not run in game. Not run here: a full darner preload with a preset below Max, and the controls window.
  • Shader wave sizes tested: no shader change.
  • Hardware dependence: see "Spec dependence".
  • Coverage gaps, to check in a real run before WIP: comes off:
    • A full preload at a preset below Max (for example 50 %) finishes all three steps, also the library step, and the window follows the preset live.
    • Pause then resume lets the work in progress finish and the step still ends.
    • Whether the step stays near the limit in real use: the tests count operations, not CPU load.

Spec dependence

  • Likely general: a counter and a wait loop over threads, with no GPU specifics.
  • May depend on our specs: how long a step takes at a low preset (it depends on the thread count of the CPU).
  • Untested elsewhere: every CPU other than the one the tests ran on, and andrewpozdnakov7-jpg's PC (his fixture ran on Windows; his hardware is not stated in his comment).

Checklist

  • I ran this change in the game, or say below why it can't be (docs, tests only). Not run in game; the tests cover the gate and the step loops only.
  • This PR contains one change based on main: the gate limit (with the SAFETY: comment beside it in the same commit).
  • The diff follows docs/asset-policy.md. (Code and tests only; cargo xtask policy ok on the commit through the pre-commit hook.)
  • 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: #450 (ours, WIP) also changes preload_gate.rs (+63/-10), warm.rs and preload_ui.rs, so expect textual conflicts: whichever lands second is rebased. Which lands first is the maintainer's call; we will rebase ours on request. #234, #270, #365, #165 touch warm.rs, and #165, #379 and #394 touch translate.rs. None touches the gate. Open PRs are searched through the API (220 open on 2026-12-05).
  • Replaces or overlaps: none found.

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

Refs #395 Refs #128 ## Contributor role (optional) - Fluxer ID: ## What it changes Follow-up to #395 (merged at `02a0edf85`). #395 is merged, so this is a new PR. It carries the fix that andrewpozdnakov7-jpg reported on #395: https://git.gtahub.st/TrustNo1/Darner/pulls/395#issuecomment-871533. That fix is not in the merged #395. - The problem on main: with `DARNER_PRELOAD_CONTROLS=1` and a preset below Max, a preload step can fail to finish. Workers were parked by slot number. In the translation and child-process steps, the parked workers stayed in the gate after the admitted ones had emptied the queue. In the library step, the parked workers also own fixed slices of the work, so the step waited for them for ever. This is from andrewpozdnakov7-jpg's report (he ran it with a test of the gate on Windows) and from reading the code. I did not run a full preload to see the hang. - What this does: the gate is now a counting limit on concurrent operations (`apps/darner/src/preload_gate.rs`). A worker takes a permit before each operation and gives it back after (when the permit is dropped). An operation is one shader, one chunk of child processes with its retries, or one library pipeline. The number of permits is `ceil(percent x threads / 100)`, at least one. Any worker may take a free permit, so no worker owns a slot and every slice still gets done, only more slowly. - Pause hands out no new permit. A lowered limit or a pause applies to the next permit; work in progress finishes (as before). - `translate.rs` and `warm.rs` (`run` and `into_library`) ask for the permit before they take their next piece of work. - Controls off: `wait_turn` returns at once with nothing to hold, as before. - Also adds the missing `SAFETY:` comment on the `unsafe` block in `preload_ui::small`. - Tests: the gate tests were rewritten for permits, and two are new. `translate::a_limit_below_max_still_finishes_the_step` (4 workers, 8 shaders, 50 %) must finish within 10 s with every shader done once and no more than 2 at a time. `preload_gate::fixed_slices_all_get_done_below_max` does the same for the library's fixed slices. The commit message says the first test timed out before the change; I did not re-run the old code for this post. Credit: the counting gate with a permit given back on drop is andrewpozdnakov7-jpg's commit `f088d7d` (https://git.gtahub.st/andrewpozdnakov7-jpg/Darner/commit/f088d7d525bd8d72b1269d576c2eb9b947527f02), as he asked. Our commit has his `Co-authored-by:` trailer. The code here is adapted to main. **Please check the `warm.rs` hunk.** It conflicted with #266's chunk queue (merged), and I resolved it by hand. In `into_library` the callback is now `let mut each` (it is `FnMut`: it keeps a `turn` for the pipeline in progress) and is passed as `&mut each`. In `run` the loop takes its permit first and the chunk second (`let _turn = wait_turn(threads)`, then `chunks.get(next...)`), so a worker that waits has taken no chunk. Please read these two places against #266's queue. Merge check: this branch is on main `47d21cd3b`. Main is now `d91d8e4d6`. `git merge-tree --write-tree trustno1/main <branch>` gives a clean tree, no conflicts. ## How it was tested - Tested revision: branch `up-preload-controls-gate-fix` @ `935c00915`, based on main `47d21cd3b`. - Commands and results, as reported by the porter (scoped to `-p darner`; the three workspace gates were not run): - clippy -D warnings, plain and --all-features (-p darner), as reported by the porter: clean. - `cargo test -p darner --bin darner`: 195 passed, 1 ignored, in the porter's run on `935c00915`. - `cargo xtask policy` through the pre-commit hook: ok. - Changes a default: no. `DARNER_PRELOAD_CONTROLS` stays off by default; with it off the gate does nothing, as before. - A/B result: none. A switch that is off by default; no speed claim. - Gates run on that revision: only the scoped ones above. Not run: the workspace clippy (with and without `--all-features`) and `cargo test --workspace --locked`. There is no CI. - Gameplay: not run in game. Not run here: a full `darner preload` with a preset below Max, and the controls window. - Shader wave sizes tested: no shader change. - Hardware dependence: see "Spec dependence". - Coverage gaps, to check in a real run before `WIP:` comes off: - A full preload at a preset below Max (for example 50 %) finishes all three steps, also the library step, and the window follows the preset live. - Pause then resume lets the work in progress finish and the step still ends. - Whether the step stays near the limit in real use: the tests count operations, not CPU load. ## Spec dependence - Likely general: a counter and a wait loop over threads, with no GPU specifics. - May depend on our specs: how long a step takes at a low preset (it depends on the thread count of the CPU). - Untested elsewhere: every CPU other than the one the tests ran on, and andrewpozdnakov7-jpg's PC (his fixture ran on Windows; his hardware is not stated in his comment). ## Checklist - [ ] I ran this change in the game, or say below why it can't be (docs, tests only). Not run in game; the tests cover the gate and the step loops only. - [x] This PR contains one change based on `main`: the gate limit (with the `SAFETY:` comment beside it in the same commit). - [ ] The diff follows `docs/asset-policy.md`. (Code and tests only; `cargo xtask policy` ok on the commit through the pre-commit hook.) - [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: #450 (ours, WIP) also changes `preload_gate.rs` (+63/-10), `warm.rs` and `preload_ui.rs`, so expect textual conflicts: whichever lands second is rebased. Which lands first is the maintainer's call; we will rebase ours on request. #234, #270, #365, #165 touch `warm.rs`, and #165, #379 and #394 touch `translate.rs`. None touches the gate. Open PRs are searched through the API (220 open on 2026-12-05). - Replaces or overlaps: none found. This change was made with AI assistance (Claude Code).
A preset below Max could stop a preload step from finishing: workers parked
by slot index stayed inside the gate after the admitted ones drained the
queue (translation, child processes), and in the library step the parked
workers owned fixed slices of the work, so the join waited for them forever.

The gate is now a counting limit on concurrent operations. A worker takes a
permit before each operation (one shader, one chunk of child processes with
its retries, one library pipeline) and gives it back after; ceil(pct x
threads / 100) permits, at least one. Pause hands out no new permit, a
changed limit applies to the next permit, work in progress finishes, and no
worker owns a slot. A regression test (4 workers, 8 shaders, 50 %) timed
out before this change.

Also adds the SAFETY comment on the unsafe block in preload_ui::small.

Reported by andrewpozdnakov7-jpg on the PR, and based on his commit
f088d7d: the counting gate with a permit given back on drop comes from it.

Co-authored-by: andrewpozdnakov7-jpg <[email protected]>
This change was made with AI assistance (Claude Code).
Contributor

I checked the hand merge with #266 on 935c00915. In warm::run, the permit is acquired before the chunk index and held across child retries. In into_library, a queued range can be reserved before a permit is available, but known::make acquires the permit in its before-pipeline callback and releases it in its completion callback. The fixed-slice path uses the same callback.

On Windows with an RTX 3060 Laptop GPU, I ran darner preload --all --jobs 4 on 256 distinct project-generated compute pipelines at 50%, with DARNER_PRELOAD_SCHEDULE off and on. Both runs exited successfully and saved a library with made=256 loaded=0. A separate fixture exercising the production warm::run loop also finished all 205 records exactly once at 50%, with a peak of two chunks in progress.

One boundary case affects the promise that Pause hands out no new permits. In an instrumented run with both permits held, I stopped a waiting worker just after it read paused=false, applied pause, and let one active chunk finish. Releasing that worker started a new chunk before go in 3/3 runs; this was its first child call, not a retry. A fresh request started after Pause was rejected. The checkpoint only controlled timing; this does not estimate how often it happens in normal use.

If applying Pause should close admission immediately, making the control update and permit grant mutually exclusive would cover that case. I did not run a game or measure CPU load.

I checked the hand merge with #266 on `935c00915`. In `warm::run`, the permit is acquired before the chunk index and held across child retries. In `into_library`, a queued range can be reserved before a permit is available, but `known::make` acquires the permit in its before-pipeline callback and releases it in its completion callback. The fixed-slice path uses the same callback. On Windows with an RTX 3060 Laptop GPU, I ran `darner preload --all --jobs 4` on 256 distinct project-generated compute pipelines at 50%, with `DARNER_PRELOAD_SCHEDULE` off and on. Both runs exited successfully and saved a library with `made=256 loaded=0`. A separate fixture exercising the production `warm::run` loop also finished all 205 records exactly once at 50%, with a peak of two chunks in progress. One boundary case affects the promise that Pause hands out no new permits. In an instrumented run with both permits held, I stopped a waiting worker just after it read `paused=false`, applied `pause`, and let one active chunk finish. Releasing that worker started a **new** chunk before `go` in 3/3 runs; this was its first child call, not a retry. A fresh request started after Pause was rejected. The checkpoint only controlled timing; this does not estimate how often it happens in normal use. If applying Pause should close admission immediately, making the control update and permit grant mutually exclusive would cover that case. I did not run a game or measure CPU load.
Jesper-A force-pushed up-preload-controls-gate-fix from 935c00915a to de0cce9a25 2026-12-05 16:39:56 +00:00 Compare
Author
Collaborator

Closing this old-engine PR because post-merge replaced the preload controls and load limit it fixes (preload.rs:16-21). It can be redone on post-merge if they come back and the problem shows there.

Written with AI assistance (Claude Code).

Closing this old-engine PR because post-merge replaced the preload controls and load limit it fixes (`preload.rs:16-21`). It can be redone on post-merge if they come back and the problem shows there. Written with AI assistance (Claude Code).
Jesper-A closed this pull request 2026-12-06 01:26:11 +00:00
Jesper-A reopened this pull request 2026-12-06 01:51:47 +00:00
Author
Collaborator

Reopened: Main is the default branch again, so the close note above no longer applies.

Written with AI assistance (Claude Code).

Reopened: Main is the default branch again, so the close note above no longer applies. Written with AI assistance (Claude Code).
TrustNo1 changed title from WIP: [pr-fix][startup][shaders] Preload controls: a limit below Max no longer stops a step from finishing (DARNER_PRELOAD_CONTROLS) to WIP: Preload controls: a limit below Max no longer stops a step from finishing (DARNER_PRELOAD_CONTROLS) 2026-12-06 03:28:45 +00:00
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-controls-gate-fix:Jesper-A-up-preload-controls-gate-fix'
git switch 'Jesper-A-up-preload-controls-gate-fix'

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-controls-gate-fix'
git switch 'Jesper-A-up-preload-controls-gate-fix'
git rebase 'Main'
git switch 'Main'
git merge --ff-only 'Jesper-A-up-preload-controls-gate-fix'
git switch 'Jesper-A-up-preload-controls-gate-fix'
git rebase 'Main'
git switch 'Main'
git merge --no-ff 'Jesper-A-up-preload-controls-gate-fix'
git switch 'Main'
git merge --squash 'Jesper-A-up-preload-controls-gate-fix'
git switch 'Main'
git merge --ff-only 'Jesper-A-up-preload-controls-gate-fix'
git switch 'Main'
git merge 'Jesper-A-up-preload-controls-gate-fix'
git push origin 'Main'
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!458
No description provided.