GPU: schedule slow-compiling early pipelines in their own bounded queue #3296

Open
pushkarreddyy wants to merge 2 commits from upstream-pr/3296 into main
pushkarreddyy commented 2026-11-26 16:17:23 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by pushkarreddyy on 2026-11-26T16:17:23Z.


Summary

Tracks host pipelines that take >= 1000 ms to compile in slow-pipelines.txt and caps concurrent early compilation of slow pipelines to a quarter of the worker pool (VICTORY_PIPELINE_SLOW=0 to disable), leaving the remaining workers free for fast early pipelines and draw-requested pipelines.

Root Cause

When the pipeline library is cold or invalidated after a translator/driver update, early pipelines that take several seconds each can occupy all background pipeline workers simultaneously, starving fast pipelines needed by early draws.

Changes

  • crates/victory-gpu/src/pipeline/library.rs:
    • Added SLOW_FILE (slow-pipelines.txt), SLOW_MS (1000), slow(key), and note_time(key, ms), persisted atomically alongside early-pipelines.txt.
  • crates/victory-gpu/src/pipeline/make.rs:
    • Recorded compile duration via super::library::note_time in Pending::make.
    • Split QUEUES into a Queues struct with lists[0] (requested), lists[1] (early normal), and lists[2] (early slow), capping concurrent slow_now workers to (workers / 4).max(1) unless VICTORY_PIPELINE_SLOW=0.
    • Added pipelines_known_to_take_long_leave_workers_for_the_others unit test.

Testing & Verification

  • Added unit test pipelines_known_to_take_long_leave_workers_for_the_others in crates/victory-gpu/src/pipeline/make.rs.
  • Testers on untested GPU models and drivers are welcome to verify pipeline compilation responsiveness on cold/warm runs.

No game files used.

AI-assisted: yes (Gemini 4 Neon)

<!-- greyfinch-sync:Marvisak/VIctory:issue:5513518767 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3296). Originally posted by [pushkarreddyy](https://github.com/pushkarreddyy) on 2026-11-26T16:17:23Z. --- ## Summary Tracks host pipelines that take `>= 1000 ms` to compile in `slow-pipelines.txt` and caps concurrent early compilation of slow pipelines to a quarter of the worker pool (`VICTORY_PIPELINE_SLOW=0` to disable), leaving the remaining workers free for fast early pipelines and draw-requested pipelines. ## Root Cause When the pipeline library is cold or invalidated after a translator/driver update, early pipelines that take several seconds each can occupy all background pipeline workers simultaneously, starving fast pipelines needed by early draws. ## Changes - `crates/victory-gpu/src/pipeline/library.rs`: - Added `SLOW_FILE` (`slow-pipelines.txt`), `SLOW_MS` (`1000`), `slow(key)`, and `note_time(key, ms)`, persisted atomically alongside `early-pipelines.txt`. - `crates/victory-gpu/src/pipeline/make.rs`: - Recorded compile duration via `super::library::note_time` in `Pending::make`. - Split `QUEUES` into a `Queues` struct with `lists[0]` (requested), `lists[1]` (early normal), and `lists[2]` (early slow), capping concurrent `slow_now` workers to `(workers / 4).max(1)` unless `VICTORY_PIPELINE_SLOW=0`. - Added `pipelines_known_to_take_long_leave_workers_for_the_others` unit test. ## Testing & Verification - Added unit test `pipelines_known_to_take_long_leave_workers_for_the_others` in `crates/victory-gpu/src/pipeline/make.rs`. - Testers on untested GPU models and drivers are welcome to verify pipeline compilation responsiveness on cold/warm runs. No game files used. AI-assisted: yes (Gemini 4 Neon)
yumaste commented 2026-11-26 16:19:43 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by yumaste on 2026-11-26T16:19:43Z.


I reproduced a case where the slow-worker cap leaks on 30dd0df (deterministic queue test, no GPU needed). With cap = 1, queue slow A and B. A draw passes the !p.taken check for A in enqueue but has not pushed its urgent entry yet. A worker pops A from the slow queue, sets taken and starts compiling. The draw now pushes the urgent duplicate. A second worker discards that duplicate, but its p.was_slow.swap(false) also releases the slot owned by the first worker. The next Queues::pop(1) then returns B while A is still compiling.

Could Queues::pop return the queue class with the entry, e.g. (Arc<Pending>, bool), and the worker use that local value when decrementing slow_now? A discarded slow entry would still release the reservation it took at pop time. A discarded urgent entry would never release another worker's reservation. The test is to freeze this interleaving and assert that B cannot be popped until A releases its slot.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7197495915 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3296#issuecomment-7197495915). Originally posted by [yumaste](https://github.com/yumaste) on 2026-11-26T16:19:43Z. --- I reproduced a case where the slow-worker cap leaks on `30dd0df` (deterministic queue test, no GPU needed). With cap = 1, queue slow A and B. A draw passes the `!p.taken` check for A in `enqueue` but has not pushed its urgent entry yet. A worker pops A from the slow queue, sets `taken` and starts compiling. The draw now pushes the urgent duplicate. A second worker discards that duplicate, but its `p.was_slow.swap(false)` also releases the slot owned by the first worker. The next `Queues::pop(1)` then returns B while A is still compiling. Could `Queues::pop` return the queue class with the entry, e.g. `(Arc<Pending>, bool)`, and the worker use that local value when decrementing `slow_now`? A discarded slow entry would still release the reservation it took at pop time. A discarded urgent entry would never release another worker's reservation. The test is to freeze this interleaving and assert that B cannot be popped until A releases its slot.
andrewpozdnakov7-jpg commented 2026-11-26 16:50:46 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-26T16:50:46Z.


I reproduced @yumaste's interleaving with a deterministic queue test on 30dd0df. One slow compile holds the only slot. The urgent duplicate is discarded while that compile is still in progress. The original logic releases its reservation at that point and admits the second slow compile too early.

Follow-up 8dff2d5 carries the reservation with the popped entry, as suggested. A worker releases exactly the slot its entry reserved. With the same interleaving, the second slow entry stays queued until the first compile completes. The new regression and all five pipeline::make::tests passed. Strict GPU Clippy passed with default and all features, and policy passed. The queue test uses synthetic entries and does not measure cold-start time.

@pushkarreddyy this is directly on your exact head if you want to cherry-pick it. Please retain its Git author, or add Co-authored-by: andrewpozdnakov7-jpg <[email protected]> if folding it into another commit. AI-assisted with Codex.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7198169295 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3296#issuecomment-7198169295). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-26T16:50:46Z. --- I reproduced @yumaste's [interleaving](https://github.com/Marvisak/VIctory/pull/3296#issuecomment-7197495915) with a deterministic queue test on `30dd0df`. One slow compile holds the only slot. The urgent duplicate is discarded while that compile is still in progress. The original logic releases its reservation at that point and admits the second slow compile too early. [Follow-up `8dff2d5`](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/8dff2d51aeaffe031ee2103ed125ab32784aec89) carries the reservation with the popped entry, as suggested. A worker releases exactly the slot its entry reserved. With the same interleaving, the second slow entry stays queued until the first compile completes. The new regression and all five `pipeline::make::tests` passed. Strict GPU Clippy passed with default and all features, and policy passed. The queue test uses synthetic entries and does not measure cold-start time. @pushkarreddyy this is directly on your exact head if you want to cherry-pick it. Please retain its Git author, or add `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>` if folding it into another commit. AI-assisted with Codex.
Dukestar69 commented 2026-11-26 17:10:10 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T17:10:10Z.

Review: APPROVED


Reviewed the diff and verified locally on Windows 11 x64 (RTX 5090):

  • Recording compile durations in the pipeline library (note_time) and scheduling known-slow early pipelines onto a bounded slow queue keeps worker threads free for normal draws and faster early compiles.
  • cargo test -p victory-gpu --lib pipeline:: -- --test-threads=1 (RTX 5090): 24 passed, 0 failed (including pipelines_known_to_take_long_leave_workers_for_the_others).
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6078110761 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3296#pullrequestreview-6078110761). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T17:10:10Z. **Review:** APPROVED --- Reviewed the diff and verified locally on Windows 11 x64 (RTX 5090): - Recording compile durations in the pipeline library (`note_time`) and scheduling known-slow early pipelines onto a bounded slow queue keeps worker threads free for normal draws and faster early compiles. - `cargo test -p victory-gpu --lib pipeline:: -- --test-threads=1` (RTX 5090): 24 passed, 0 failed (including `pipelines_known_to_take_long_leave_workers_for_the_others`). - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
pushkarreddyy commented 2026-11-27 04:02:39 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by pushkarreddyy on 2026-11-27T04:02:39Z.


@yumaste @andrewpozdnakov7-jpg Thank you for reproducing the slow_now reservation leak on urgent duplicate discards and providing the clean fix (8dff2d5). I have cherry-picked 8dff2d5 (preserving Git authorship) onto the PR branch so each popped entry owns and releases its own slow-slot reservation.

@Marvisak Please review and merge this PR once CI is green. Testers on untested GPU models are welcome to test.

AI-assisted: yes (Gemini 4 Neon)

<!-- greyfinch-sync:Marvisak/VIctory:comment:7209473175 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3296#issuecomment-7209473175). Originally posted by [pushkarreddyy](https://github.com/pushkarreddyy) on 2026-11-27T04:02:39Z. --- @yumaste @andrewpozdnakov7-jpg Thank you for reproducing the `slow_now` reservation leak on urgent duplicate discards and providing the clean fix (`8dff2d5`). I have cherry-picked `8dff2d5` (preserving Git authorship) onto the PR branch so each popped entry owns and releases its own slow-slot reservation. @Marvisak Please review and merge this PR once CI is green. Testers on untested GPU models are welcome to test. AI-assisted: yes (Gemini 4 Neon)
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3296:upstream-pr/3296'
git switch 'upstream-pr/3296'

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 'upstream-pr/3296'
git switch 'upstream-pr/3296'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3296'
git switch 'upstream-pr/3296'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3296'
git switch 'main'
git merge --squash 'upstream-pr/3296'
git switch 'main'
git merge --ff-only 'upstream-pr/3296'
git switch 'main'
git merge 'upstream-pr/3296'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
Marvisak/VIctory!3296
No description provided.