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

Closed
github-bot wants to merge 1 commit from gh-pr/1551/head into gh-pr/1551/base
Owner

@⁠Sakura-Byte on GitHub · 2026-11-24 19:03 UTC · original
Sakura-Byte:pr/repeat-demand-pipeline-priority → main · +434 −37 · 1 files · 1 commits · closed without merging

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.

**@⁠Sakura-Byte** on GitHub · 2026-11-24 19:03 UTC · [original](https://github.com/Marvisak/VIctory/pull/1551) `Sakura-Byte:pr/repeat-demand-pipeline-priority` → `main` · +434 −37 · 1 files · 1 commits · closed without merging ## 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.*
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:36:05 +00:00
github-bot closed this pull request 2026-11-26 04:36:05 +00:00
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 00:42 UTC · original

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.

**@⁠Marvisak** on GitHub · 2026-11-25 00:42 UTC · [original](https://github.com/Marvisak/VIctory/pull/1551#issuecomment-7148791516) 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

This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!1551
No description provided.