Skip to content

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

Open
Xvania7 wants to merge 2 commits into
Marvisak:mainfrom
Xvania7:perf/dependency-aware-pipeline-scheduler
Open

Xvania7 wants to merge 2 commits into
Marvisak:mainfrom
Xvania7:perf/dependency-aware-pipeline-scheduler

Conversation

@Xvania7

@Xvania7 Xvania7 commented Nov 25, 2026 •

Copy link
Copy Markdown

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
Xvania7 force-pushed the perf/dependency-aware-pipeline-scheduler branch from 322c60e to d075795 Compare November 25, 2026 07:32

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

@FunWithFlagsDev

Copy link
Copy Markdown

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

@Xvania7

Xvania7 commented Nov 25, 2026

Copy link
Copy Markdown
Author

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.

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

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

@Xvania7

Xvania7 commented Nov 25, 2026

Copy link
Copy Markdown
Author

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

Xvania7 commented Nov 25, 2026

Copy link
Copy Markdown
Author

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GPU: pipeline workers can stall on shared shader translation dependencies — dependency-aware scheduling

4 participants