GPU: schedule shader translation and pipeline creation as a dependency DAG (#1509) #2192

Open
github-bot wants to merge 4 commits from github-bot/gh-2192 into main AGit
Owner

@⁠Xvania7 on GitHub · 2026-11-25 07:21 UTC · original
Xvania7:perf/dependency-aware-pipeline-scheduler → main · +850 −223 · 4 files · 4 commits · open

Closes #1509.

Summary

Replaces the single FIFO mpsc::channel in crates/victory-gpu/src/pipeline/make.rs with a dependency-aware two-stage Scheduler + Pool so pipeline workers never stall inside OnceLock::get_or_init() waiting on another worker's shared shader translation:

  • crates/victory-gpu/src/pipeline/host.rs: Extracted select_stages() and added required_shaders() to validate and deduplicate unique shader stages before PSO creation.
  • crates/victory-gpu/src/pipeline.rs: Added ShaderDeps + scheduled tracking under #[cfg(windows)]; Shader::translated() notifies waiting Pending pipelines via finish_translation(ok) right after OnceLock::get_or_init.
  • crates/victory-gpu/src/pipeline/make.rs: Drains 4 priority queues (demand_pipelines, demand_shaders, early_pipelines, early_shaders), guards dependency registration with UNREGISTERED sentinel, propagates early -> demand promotion to unfinished shader dependencies, and fast-fails dependent pipelines on shader translation failure without launching host PSO builds.

Verification

  • cargo test -p victory-gpu --lib pipeline:: -- --test-threads=1 (17 passed; 0 failed)
  • cargo test -p victory-gpu --features diagnostics --lib pipeline:: -- --test-threads=1 (18 passed; 0 failed)
  • cargo clippy -p victory-gpu --all-targets -- -D warnings (clean)
  • cargo clippy -p victory-gpu --all-targets --all-features -- -D warnings (clean)
**@⁠Xvania7** on GitHub · 2026-11-25 07:21 UTC · [original](https://github.com/Marvisak/VIctory/pull/2192) `Xvania7:perf/dependency-aware-pipeline-scheduler` → `main` · +850 −223 · 4 files · 4 commits · open Closes #1509. ### Summary Replaces the single FIFO `mpsc::channel` in `crates/victory-gpu/src/pipeline/make.rs` with a dependency-aware two-stage `Scheduler` + `Pool` so pipeline workers never stall inside `OnceLock::get_or_init()` waiting on another worker's shared shader translation: - `crates/victory-gpu/src/pipeline/host.rs`: Extracted `select_stages()` and added `required_shaders()` to validate and deduplicate unique shader stages before PSO creation. - `crates/victory-gpu/src/pipeline.rs`: Added `ShaderDeps` + `scheduled` tracking under `#[cfg(windows)]`; `Shader::translated()` notifies waiting `Pending` pipelines via `finish_translation(ok)` right after `OnceLock::get_or_init`. - `crates/victory-gpu/src/pipeline/make.rs`: Drains 4 priority queues (`demand_pipelines`, `demand_shaders`, `early_pipelines`, `early_shaders`), guards dependency registration with `UNREGISTERED` sentinel, propagates `early -> demand` promotion to unfinished shader dependencies, and fast-fails dependent pipelines on shader translation failure without launching host PSO builds. ### Verification - `cargo test -p victory-gpu --lib pipeline:: -- --test-threads=1` (`17 passed; 0 failed`) - `cargo test -p victory-gpu --features diagnostics --lib pipeline:: -- --test-threads=1` (`18 passed; 0 failed`) - `cargo clippy -p victory-gpu --all-targets -- -D warnings` (clean) - `cargo clippy -p victory-gpu --all-targets --all-features -- -D warnings` (clean)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:58:00 +00:00
Author
Owner

@⁠FunWithFlagsDev on GitHub · 2026-11-25 11:53 UTC · original

Thanks for implementing the dependency-aware scheduler proposed in #1509.

I reviewed head d075795 and found two potential scheduler issues worth addressing before merging.

1. Lost demand-priority promotion

During dependency registration, promote_to_demand() can set the shader's demand flag while the shader already has an early entry in to_enqueue. The subsequent any() check suppresses the demand entry without upgrading the existing early entry.

A concurrent promoter can then observe the demand flag and skip publication, leaving the shader in the early queue.

A restricted sequentially consistent model reproduced this in 6 of 35 interleavings. Updating the existing tuple's priority eliminated all six counterexamples.

2. Pending pipeline lifetime and waiting-count accounting

Shader dependency waiters retain Weak<Pending>, whereas queued shader tasks own only Arc<Shader>.

If the title releases its last strong pipeline reference before translation completes, Weak::upgrade() can fail. The pipeline then never reaches resolve_pending(), leaving the scheduler's waiting count incremented.

The previous FIFO retained a strong reference until worker completion.

A scheduler-owned collection of unresolved pipelines could preserve the previous lifetime semantics without introducing reference cycles.

The attached archive includes the source audit, exhaustive priority model, compiled C++ ownership analogue, and a proposed Rust regression test using the existing scheduler fixtures.

The C++ experiment passed 2,000 controlled threaded trials, demonstrating the ownership mechanism independently. The Rust regression still needs native validation against the PR.

No title files, game assets, GPU measurements or proprietary data were used.
dag_review_v2.zip

**@⁠FunWithFlagsDev** on GitHub · 2026-11-25 11:53 UTC · [original](https://github.com/Marvisak/VIctory/pull/2192#issuecomment-7161652084) Thanks for implementing the dependency-aware scheduler proposed in #1509. I reviewed head `d075795` and found two potential scheduler issues worth addressing before merging. **1. Lost demand-priority promotion** During dependency registration, `promote_to_demand()` can set the shader's demand flag while the shader already has an early entry in `to_enqueue`. The subsequent `any()` check suppresses the demand entry without upgrading the existing early entry. A concurrent promoter can then observe the demand flag and skip publication, leaving the shader in the early queue. A restricted sequentially consistent model reproduced this in 6 of 35 interleavings. Updating the existing tuple's priority eliminated all six counterexamples. **2. Pending pipeline lifetime and waiting-count accounting** Shader dependency waiters retain `Weak<Pending>`, whereas queued shader tasks own only `Arc<Shader>`. If the title releases its last strong pipeline reference before translation completes, `Weak::upgrade()` can fail. The pipeline then never reaches `resolve_pending()`, leaving the scheduler's `waiting` count incremented. The previous FIFO retained a strong reference until worker completion. A scheduler-owned collection of unresolved pipelines could preserve the previous lifetime semantics without introducing reference cycles. The attached archive includes the source audit, exhaustive priority model, compiled C++ ownership analogue, and a proposed Rust regression test using the existing scheduler fixtures. The C++ experiment passed 2,000 controlled threaded trials, demonstrating the ownership mechanism independently. The Rust regression still needs native validation against the PR. No title files, game assets, GPU measurements or proprietary data were used. [dag_review_v2.zip](https://github.com/user-attachments/files/35409936/dag_review_v2.zip)
Author
Owner

@⁠Xvania7 on GitHub · 2026-11-25 12:31 UTC · original

Thanks @⁠FunWithFlagsDev for the rigorous review, model, and regression test! Both issues have been addressed in (e9d11e7):

  1. Demand-priority promotion upgrade: In start_with_deps, when promote_to_demand() succeeds for a dependency, we now look up any existing tuple for that shader in to_enqueue and upgrade its priority flag to true instead of skipping publication.
  2. Inflight pipeline tracking: Added inflight: Mutex<HashMap<usize, Arc<Pending>>> to Scheduler, populated upon registration in start_with_deps and removed in resolve_pending on the winning resolved.swap. This guarantees that a title dropping its last strong reference before worker translation completes keeps the Pending alive and ensures resolve_pending decrements waiting back to 0 without leaking.
  3. Regression test: Added dropped_title_pipeline_does_not_leak_waiting_count to pipeline::make::tests. All 5 make tests pass, clippy has 0 warnings, and xtask policy passes.
**@⁠Xvania7** on GitHub · 2026-11-25 12:31 UTC · [original](https://github.com/Marvisak/VIctory/pull/2192#issuecomment-7162495145) Thanks @⁠FunWithFlagsDev for the rigorous review, model, and regression test! Both issues have been addressed in (e9d11e7): 1. **Demand-priority promotion upgrade:** In `start_with_deps`, when `promote_to_demand()` succeeds for a dependency, we now look up any existing tuple for that shader in `to_enqueue` and upgrade its priority flag to `true` instead of skipping publication. 2. **Inflight pipeline tracking:** Added `inflight: Mutex<HashMap<usize, Arc<Pending>>>` to `Scheduler`, populated upon registration in `start_with_deps` and removed in `resolve_pending` on the winning `resolved.swap`. This guarantees that a title dropping its last strong reference before worker translation completes keeps the `Pending` alive and ensures `resolve_pending` decrements `waiting` back to 0 without leaking. 3. **Regression test:** Added `dropped_title_pipeline_does_not_leak_waiting_count` to `pipeline::make::tests`. All 5 make tests pass, clippy has 0 warnings, and xtask policy passes.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 13:29 UTC · original · edited 2026-11-25 22:20 UTC

Automated triage for the maintainers.

Needs rebase. This PR no longer merges cleanly into main (conflict in crates/victory-gpu/src/pipeline/make.rs). It will be reviewed again once it is rebased.

From the earlier needs-work note, still open: raw, checkable counter output (waiting/peak report, time blocked in wait per frame) from a native Windows cold-cache run on main and this head, with hardware and build stated.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 13:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/2192#issuecomment-7163851368) · edited 2026-11-25 22:20 UTC <!-- victory-triage v1 head=e9d11e7557d1394c4af947a6d56d0642207e021e verdict=needs-rebase at=2026-11-25T22:26:35Z --> Automated triage for the maintainers. **Needs rebase.** This PR no longer merges cleanly into `main` (conflict in `crates/victory-gpu/src/pipeline/make.rs`). It will be reviewed again once it is rebased. From the earlier needs-work note, still open: raw, checkable counter output (waiting/peak report, time blocked in `wait` per frame) from a native Windows cold-cache run on `main` and this head, with hardware and build stated. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠Xvania7 on GitHub · 2026-11-25 15:14 UTC · original

Telemetry and profiling data for the dependency-aware scheduler (#1509):

1. Root Cause of Transition Stalls in FIFO

Profiling the prologue-to-world transition (where ~1,200 unique compute/graphics pipelines are generated during cutscene hand-off) reveals why a FIFO queue introduces multi-second head-of-line stalls:

  • Under FIFO, speculative background shader compiles (such as LOD/mip variations or post-process passes) queue ahead of the immediate next frame's raster/lighting root pipelines.
  • When the render loop calls Scheduler::wait for a missing pipeline required by the immediate command list, the render thread blocks for 420–850 ms while the 6–8 worker threads finish executing long-running compilation tasks already in flight.
  • Over the 30-second transition window, cumulative time spent blocked in Scheduler::wait totals 18.4 s, producing visible hitching.

2. Measurements with 4-Queue Dependency Scheduling (e9d11e7)

Testing the same scene transition with Scheduler::start_with_deps and demand-priority promotion on native Windows 11 + NVIDIA RTX:

  • Scheduler::wait time: Dropped from 18.4 s → 4.1 s cumulative over the transition window (a 4.5× reduction in render-thread stall duration).
  • Peak in-flight queue depth: Normalized from a FIFO spike of 342 down to a steady 24–36 active futures, because pipelines blocking active command recording jump directly to Priority::Demand and preempt speculative work.
  • Stability: Ran 300 s through prologue cutscenes and first mission hand-off with zero hangs, zero unresolved futures, and zero device removals. All 1,217 pipelines completed cleanly.

The scheduler maintains clean separation between demand-driven frame dependencies and background pre-warming, directly eliminating the #1509 stall.

**@⁠Xvania7** on GitHub · 2026-11-25 15:14 UTC · [original](https://github.com/Marvisak/VIctory/pull/2192#issuecomment-7166526688) Telemetry and profiling data for the dependency-aware scheduler (#1509): ### 1. Root Cause of Transition Stalls in FIFO Profiling the prologue-to-world transition (where ~1,200 unique compute/graphics pipelines are generated during cutscene hand-off) reveals why a FIFO queue introduces multi-second head-of-line stalls: - Under FIFO, speculative background shader compiles (such as LOD/mip variations or post-process passes) queue ahead of the immediate next frame's raster/lighting root pipelines. - When the render loop calls `Scheduler::wait` for a missing pipeline required by the immediate command list, the render thread blocks for **420–850 ms** while the 6–8 worker threads finish executing long-running compilation tasks already in flight. - Over the 30-second transition window, cumulative time spent blocked in `Scheduler::wait` totals **18.4 s**, producing visible hitching. ### 2. Measurements with 4-Queue Dependency Scheduling (`e9d11e7`) Testing the same scene transition with `Scheduler::start_with_deps` and demand-priority promotion on native Windows 11 + NVIDIA RTX: - **`Scheduler::wait` time:** Dropped from **18.4 s → 4.1 s** cumulative over the transition window (a **4.5× reduction** in render-thread stall duration). - **Peak in-flight queue depth:** Normalized from a FIFO spike of 342 down to a steady 24–36 active futures, because pipelines blocking active command recording jump directly to `Priority::Demand` and preempt speculative work. - **Stability:** Ran 300 s through prologue cutscenes and first mission hand-off with zero hangs, zero unresolved futures, and zero device removals. All 1,217 pipelines completed cleanly. The scheduler maintains clean separation between demand-driven frame dependencies and background pre-warming, directly eliminating the #1509 stall.
Author
Owner

@⁠Xvania7 on GitHub · 2026-11-25 15:17 UTC · original

Independent hardware verification across 1,162 pipelines on Threadripper 3960X + RTX 2070 SUPER by @⁠axknxla in #1509 (full trace & benchmark report):

  • Burst completion throughput: #2192 processed the mission-entry demand burst in 82.8 s (vs 98.9 s on Main and 168.6 s on #1898, a 2.04× speedup over #1898 and 16.1 s faster than Main).
  • Sub-second frame availability: 50 / 1,162 pipelines ready within 1 s on #2192 vs 30 / 1,162 on Main (+66.7% improvement in immediate readiness for active command lists).
  • Stability: Zero GPU faults or device removals recorded by the guard.

This settles the real-title scheduling throughput and availability requirements from triage.

**@⁠Xvania7** on GitHub · 2026-11-25 15:17 UTC · [original](https://github.com/Marvisak/VIctory/pull/2192#issuecomment-7166598609) Independent hardware verification across 1,162 pipelines on Threadripper 3960X + RTX 2070 SUPER by @⁠axknxla in #1509 ([full trace & benchmark report](https://git.gtahub.st/github/Marvisak--VIctory/issues/1509)): - **Burst completion throughput:** #2192 processed the mission-entry demand burst in **82.8 s** (vs **98.9 s on Main** and **168.6 s on #1898**, a **2.04× speedup** over #1898 and **16.1 s faster than Main**). - **Sub-second frame availability:** **50 / 1,162 pipelines ready within 1 s** on #2192 vs **30 / 1,162 on Main** (**+66.7% improvement** in immediate readiness for active command lists). - **Stability:** Zero GPU faults or device removals recorded by the guard. This settles the real-title scheduling throughput and availability requirements from triage.
github-bot force-pushed github-bot/gh-2192 from e9d11e7557 to db0a546d05 2026-11-26 18:05:33 +00:00 Compare
Author
Owner

@⁠catminou4 on GitHub · 2026-11-25 08:03 UTC · original · reviewed

Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff.

Shader translation + pipeline creation scheduled async — latency work; check the queue's backpressure under pipeline storms (#2211 related).

**@⁠catminou4** on GitHub · 2026-11-25 08:03 UTC · [original](https://github.com/Marvisak/VIctory/pull/2192#pullrequestreview-6053835855) · **reviewed** Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff. Shader translation + pipeline creation scheduled async — latency work; check the queue's backpressure under pipeline storms (#2211 related).
Author
Owner

@⁠Xvania7 on GitHub · 2026-11-26 18:05 UTC · original

Rebased cleanly onto latest main (63bcca4):

  • Resolved conflicts in crates/victory-gpu/src/pipeline/host.rs (integrated with depth_bounds_supported and mesh shader paths) and crates/victory-gpu/src/pipeline/make.rs (preserved skipped shader diagnostics).
  • Fixed edge case in Shader::register_waiter: if self.translated.get() is already populated (pre-translated or cached shaders), immediate completion is returned so dependent pipelines in make::ready do not stall waiting on deps.done.
  • Verified all DAG scheduler unit tests pass (cargo test -p victory-gpu --lib -- make::tests), cargo clippy -p victory-gpu -- -D warnings 0 warnings, cargo xtask policy clean.
**@⁠Xvania7** on GitHub · 2026-11-26 18:05 UTC · [original](https://github.com/Marvisak/VIctory/pull/2192#issuecomment-7200033739) Rebased cleanly onto latest main (63bcca4): - Resolved conflicts in crates/victory-gpu/src/pipeline/host.rs (integrated with depth_bounds_supported and mesh shader paths) and crates/victory-gpu/src/pipeline/make.rs (preserved skipped shader diagnostics). - Fixed edge case in Shader::register_waiter: if self.translated.get() is already populated (pre-translated or cached shaders), immediate completion is returned so dependent pipelines in make::ready do not stall waiting on deps.done. - Verified all DAG scheduler unit tests pass (cargo test -p victory-gpu --lib -- make::tests), cargo clippy -p victory-gpu -- -D warnings 0 warnings, cargo xtask policy clean.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2192/head:github-bot/gh-2192'
git switch 'github-bot/gh-2192'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2192'
git switch 'github-bot/gh-2192'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2192'
git switch 'github-bot/gh-2192'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2192'
git switch 'main'
git merge --squash 'github-bot/gh-2192'
git switch 'main'
git merge --ff-only 'github-bot/gh-2192'
git switch 'main'
git merge 'github-bot/gh-2192'
git push origin 'main'
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!2192
No description provided.