GPU: prioritize repeat-demanded pipelines with non-mesh tie-breaking and anti-starvation #1550

Closed
Sakura-Byte wants to merge 1 commit from upstream-pr/1551 into main
Sakura-Byte commented 2026-11-24 19:03:43 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Sakura-Byte on 2026-11-24T19:03:43Z.


Summary

Replaces the single FIFO mpsc::channel in crates/victory-gpu/src/pipeline/make.rs with a repeat-demand priority WorkQueue so pipelines requested repeatedly by active draws and dispatches compile ahead of single-hit entries, mesh ties, and speculative early pre-warms, while preserving bounded forward progress for 1-hit pipelines.

Changes (crates/victory-gpu/src/pipeline/make.rs)

  • Early-to-demand promotion (UNQUEUED -> EARLY -> DEMAND): ready() promotes unstarted early entries into the demand lane via CAS without double-counting WAITING or PEAK, and Pending::claim() ensures each pipeline is compiled at most once even if present in both lanes or re-pushed on a tier upgrade.
  • Repeat-demand priority tiering (demand_tier, MAX_TIER = 10): Tracks demand hits atomically and buckets them into logarithmic tiers (1..=3, then 33 - hits.leading_zeros() capped at tier 10 for hits >= 256). A WorkItem is pushed to the demand BinaryHeap only when tier_queued.fetch_max(tier) < tier, bounding extra heap entries to at most 10 per pipeline.
  • Non-mesh tie-breaking & FIFO order (WorkItem::cmp): Within the same tier, non-mesh pipelines (!shaders.iter().any(|s| s.stage == "mesh")) sort ahead of mesh pipelines, with submission sequence seq preserving FIFO order within (tier, non_mesh).
  • Bounded anti-starvation (FAIR_STRIDE = 16, fair_fifo): After 16 consecutive higher-tier (tier >= 2) pops, pop_claimed() drains one oldest unclaimed demand entry from fair_fifo so 1-hit pipelines cannot starve under sustained repeat demand.
  • Inline fallback: If worker threads cannot be spawned (!workers_alive), make_inline compiles once via claim() while maintaining WAITING / PEAK accounting.
  • Overlap note: Complementary to 2-lane FIFO queue PRs (#546, #1013) which treat all requested pipelines equally FIFO, as well as wait-budget / library / worker-config PRs (#275, #994, #1000, #1203, #1439, #1505). Keeps main's existing wait() budget and worker thread setup untouched in this PR for a minimal single-file diff.

Verification

Tested cleanly on 2fc9b94 (based on ffe310e) on Windows with WARP (VICTORY_D3D12_WARP=1, VICTORY_WARP=1):

  • git diff --check: pass
  • cargo xtask policy: pass (154 files ok)
  • cargo clippy --workspace --all-targets --locked -- -D warnings: pass (0 warnings)
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: pass (0 warnings)
  • cargo test -p victory-gpu --features diagnostics --locked -- pipeline::make::: 4 passed; 0 failed; 0 ignored
    • first_use_is_made_by_a_worker
    • priority_queue_runs_ready_and_promoted_before_early
    • repeated_demand_jumps_ahead_of_hundreds_of_single_hit_pipelines
    • tie_breaks_favor_non_mesh_and_fair_stride_prevents_starvation
  • cargo test -p victory-gpu --features diagnostics --locked -- --test-threads=1: 56 passed; 0 failed; 1 ignored (existing texture_checks_per_submission benchmark)
  • cargo test -p victory-gpu --locked -- --test-threads=1: 53 passed; 0 failed; 1 ignored

AI-assisted; synthetic tests only, zero game assets.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6589268397 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1551). Originally posted by [Sakura-Byte](https://github.com/Sakura-Byte) on 2026-11-24T19:03:43Z. --- ## Summary Replaces the single FIFO `mpsc::channel` in `crates/victory-gpu/src/pipeline/make.rs` with a repeat-demand priority `WorkQueue` so pipelines requested repeatedly by active draws and dispatches compile ahead of single-hit entries, `mesh` ties, and speculative `early` pre-warms, while preserving bounded forward progress for 1-hit pipelines. ### Changes (`crates/victory-gpu/src/pipeline/make.rs`) - **Early-to-demand promotion (`UNQUEUED -> EARLY -> DEMAND`)**: `ready()` promotes unstarted `early` entries into the demand lane via CAS without double-counting `WAITING` or `PEAK`, and `Pending::claim()` ensures each pipeline is compiled at most once even if present in both lanes or re-pushed on a tier upgrade. - **Repeat-demand priority tiering (`demand_tier`, `MAX_TIER = 10`)**: Tracks demand `hits` atomically and buckets them into logarithmic tiers (`1..=3`, then `33 - hits.leading_zeros()` capped at tier `10` for `hits >= 256`). A `WorkItem` is pushed to the demand `BinaryHeap` only when `tier_queued.fetch_max(tier) < tier`, bounding extra heap entries to at most 10 per pipeline. - **Non-mesh tie-breaking & FIFO order (`WorkItem::cmp`)**: Within the same tier, non-mesh pipelines (`!shaders.iter().any(|s| s.stage == "mesh")`) sort ahead of mesh pipelines, with submission sequence `seq` preserving FIFO order within `(tier, non_mesh)`. - **Bounded anti-starvation (`FAIR_STRIDE = 16`, `fair_fifo`)**: After 16 consecutive higher-tier (`tier >= 2`) pops, `pop_claimed()` drains one oldest unclaimed demand entry from `fair_fifo` so 1-hit pipelines cannot starve under sustained repeat demand. - **Inline fallback**: If worker threads cannot be spawned (`!workers_alive`), `make_inline` compiles once via `claim()` while maintaining `WAITING` / `PEAK` accounting. - **Overlap note**: Complementary to 2-lane FIFO queue PRs (#546, #1013) which treat all requested pipelines equally FIFO, as well as wait-budget / library / worker-config PRs (#275, #994, #1000, #1203, #1439, #1505). Keeps `main`'s existing `wait()` budget and worker thread setup untouched in this PR for a minimal single-file diff. ## Verification Tested cleanly on `2fc9b94` (based on `ffe310e`) on Windows with WARP (`VICTORY_D3D12_WARP=1`, `VICTORY_WARP=1`): - `git diff --check`: pass - `cargo xtask policy`: pass (`154 files ok`) - `cargo clippy --workspace --all-targets --locked -- -D warnings`: pass (0 warnings) - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: pass (0 warnings) - `cargo test -p victory-gpu --features diagnostics --locked -- pipeline::make::`: **4 passed; 0 failed; 0 ignored** - `first_use_is_made_by_a_worker` - `priority_queue_runs_ready_and_promoted_before_early` - `repeated_demand_jumps_ahead_of_hundreds_of_single_hit_pipelines` - `tie_breaks_favor_non_mesh_and_fair_stride_prevents_starvation` - `cargo test -p victory-gpu --features diagnostics --locked -- --test-threads=1`: **56 passed; 0 failed; 1 ignored** (existing `texture_checks_per_submission` benchmark) - `cargo test -p victory-gpu --locked -- --test-threads=1`: **53 passed; 0 failed; 1 ignored** *AI-assisted; synthetic tests only, zero game assets.*
upstream-sync closed this pull request 2026-11-25 01:06:50 +00:00
Marvisak commented 2026-11-25 01:08:15 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:42:25Z.


Automated triage for the maintainers. Closing because this change is already in main, or main has since replaced the code it patches.

Replaces 'the single FIFO channel' with a repeat-demand priority queue; main already replaced that channel with a draws-first queue and early-entry promotion (make.rs). The extra repeat counts, mesh tie-breaks and anti-starvation come with no measurement.

If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148791516 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1551#issuecomment-7148791516). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:42:25Z. --- Automated triage for the maintainers. Closing because this change is already in `main`, or `main` has since replaced the code it patches. Replaces 'the single FIFO channel' with a repeat-demand priority queue; main already replaced that channel with a draws-first queue and early-entry promotion (make.rs). The extra repeat counts, mesh tie-breaks and anti-starvation come with no measurement. If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

Pull request closed

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!1550
No description provided.