Repository navigation
GPU: dependency-aware two-stage shader translation and pipeline scheduling (#1509) - #1898
nathanbzrr wants to merge 1 commit into
Conversation
catminou4
left a comment
There was a problem hiding this comment.
Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff.
Dependency-aware two-stage shader translation and pipeline…: large GPU pipeline rework — biggest of this wave; Windows-only, needs hardware suite.
5a96f44 to
95eaa30
Compare
|
Automated triage for the maintainers. Needs work. Re-reviewed at The two open points remain:
CI: passing ( Generated by Claude Code |
|
Updated 1. Removed the extra atomic load in
|
| Workload (8 workers, 100% cold GFX10 translation + cold D3D12 PSOs) | Metric | Blocking FIFO (main) |
Dependency Scheduler (this PR) | Change |
|---|---|---|---|---|
| 1. Shared heavy shader + independent pipelines (8 pipelines sharing 1 heavy shader + 64 independent pipelines = 72 total) | Worker time blocked on another worker's translation | 334.20 ms (237.19–334.20 ms) |
0.00 ms |
-100% (0 ms blocked) |
| Active shader translation time (summed across workers) | 84.51 ms |
97.69 ms |
overlaps with PSO builds | |
| Host D3D12 PSO creation time (summed across workers) | 6,029.14 ms |
5,273.70 ms |
-12.5% |
|
Pipelines ready within 500 ms frame wait budget (BUDGET) |
0 / 72 |
50–64 / 72 |
+50..64 ready in budget | |
Pipelines still waiting at 500 ms budget (waiting()) |
72 |
8–22 |
-69%..-89% dropped/waiting | |
| Time to first 16 ready D3D12 PSOs | 741.39 ms (625.00–741.39 ms) |
28.93 ms (28.93–32.39 ms) |
19.3x–25.6x faster | |
| Time to first 32 ready D3D12 PSOs | 761.27 ms (641.62–761.27 ms) |
48.38 ms (48.38–61.83 ms) |
10.4x–15.7x faster | |
| Total batch wall time (all 72 D3D12 PSOs built) | 807.69 ms (699.49–807.69 ms) |
674.02 ms (664.97–676.82 ms) |
-16.5% | |
| 2. Unique-shader control (64 distinct cold D3D12 pipelines, 0 shared shaders) | Worker time blocked on another worker's translation | 0.00 ms |
0.00 ms |
0.00 ms |
Pipelines ready within 500 ms frame wait budget (BUDGET) |
64 / 64 |
64 / 64 |
identical | |
| Time to first 16 / 32 ready D3D12 PSOs | 21.84–27.40 ms / 37.94–46.81 ms |
19.66–21.91 ms / 36.73–40.51 ms |
no regression | |
| Total batch wall time (all 64 D3D12 PSOs built) | 68.19–83.36 ms |
68.12–81.46 ms |
within noise (~0–3%) |
(Note: this environment has no local game files per docs/asset-policy.md, so measurements use self-contained GFX10 containers compiled into real D3D12 PSOs on the RX 7600.)
3. Comparison with Competing PR #2192
| Dimension | This PR (#1898, head 2018b59) |
PR #2192 (d075795) |
|---|---|---|
| Scope & diff size | 2 files (pipeline.rs +22 / -0, pipeline/make.rs ~105 production lines). Leaves pipeline/host.rs, Pending layout, and Shader::translated() untouched. |
3 files (+757 / -196 lines, ~380 production lines). Refactors pipeline/host.rs (select_stages / required_shaders) and replaces static queues with Pool + boxed closures. |
| Per-object memory & startup-storm overhead (~60,000 pipelines) | +1 byte (claimed: AtomicBool) per Shader, +0 bytes per Pending. early() and ready() still use the lock-free enqueue() check and push one Arc<Pending> to queues[0..2]; shaders are claimed lazily when popped by a worker, and blocked entries exist only while a shader is actively in-flight. |
Adds Mutex<ShaderDeps> (Vec<Weak<Pending>>) + AtomicBool permanently to every Shader, and adds 2 OnceLocks + 6 atomics to every Pending. start_with_deps() eagerly queries host().mesh_shaders(), locks s.deps per shader, allocates Weak<Pending> waiters, and pushes duplicate Arc<Shader> entries into demand_shaders on early -> demand promotion. |
Shader::translated() hot path (draw.rs) |
Identical to main (self.translated.get_or_init(...).as_ref(), zero extra loads, stores, or locks). |
Calls self.finish_translation(out.is_some()) after get_or_init, acquiring self.deps.lock() on the uncached path. |
Multi-shader pipeline dispatch ([VS, PS]) |
Scheduler::pop() claims VS, re-queues p at the front of its queue when trailing unstarted shaders (PS) remain, and wakes another worker (if more { work.notify_one(); }) so VS and PS translate concurrently without extra per-Pending dependency counters. |
Tracks remaining_deps: AtomicUsize (with an UNREGISTERED = usize::MAX + 1 registration sentinel) and 4 separate queues (demand_pipelines, demand_shaders, early_pipelines, early_shaders). |
| Failure & refusal semantics | Always runs Pending::make() -> HostPipeline::new() once shaders finish, preserving main's exact refuse(...) logging and stage checks. |
on_shader_done(&pending, false) calls p.fail() directly as soon as any one shader fails (even while sibling stages of p are still translating), bypassing HostPipeline::new(). |
Verification on 2018b59
cargo run -p xtask -- policy --staged:asset policy: 2 files okcargo clippy --workspace --all-targets --locked -- -D warnings&--all-features: cleancargo test -p victory-gpu pipeline --locked&--all-features: 21 / 22 passed, 0 failed, 1 ignoredcargo test --release -p victory-gpu --lib pipeline::make::tests::bench_dependency_scheduler_vs_blocking_fifo -- --ignored --nocapture: 1 passed
0891d1b to
4de2b31
Compare
|
Rebased onto
Verification (
|
4de2b31 to
5026c04
Compare
|
Rebased cleanly onto Re-verified after the final edit:
AI-assisted; synthetic tests only, no game files. |
Addresses #1509.
Summary
crates/victory-gpu/src/pipeline.rs(+22 / -0) andcrates/victory-gpu/src/pipeline/make.rs:Shaderadds a singleclaimed: AtomicBool(is_unstarted,is_done,try_claim,finish_translate), reading completion directly fromself.translated.get().is_some().Shader::translated()is 100% unchanged frommain(zero extra atomic loads or stores ondraw.rshot paths). Direct synchronous callers ofShader::translated()(workers == 0,Prebuild::make, tests) initializeOnceLockwithout settingclaimed, so workertry_claim+finish_translatejoinsOnceLockand callsScheduler::unblockwithout deadlocks or lost wakeups.Schedulerseparates shader translation (Work::Translate) from ready PSO creation (Work::Build), parking dependentPendingpipelines byArc<Shader>pointer untilunblockre-queues them while preservingnow(first-use) vs early priority and single-buildtakensemantics.Scheduler::pop()scansp.shadersfor a claimable shader before parking on an in-flight shader, re-queuespat the front of its queue when trailing unstarted shaders remain, andwork()wakes another worker whensched.has_queued()is true—allowing multi-shader pipelines (e.g.[VS, PS]) and pipelines sharing an in-flight shader to dispatch remaining stages concurrently without blockingPSbehindVS.shared_in_flight_shader_does_not_block_independent_pipelines), wakeup races (no_lost_wakeup_when_shader_finishes_around_pop,direct_translated_race_with_scheduler_pop_never_deadlocks),early -> nowpromotion (early_to_now_promotion_of_blocked_pipeline_builds_once), concurrent multi-shader pipeline dispatch (multi_shader_pipeline_dispatches_shaders_concurrently), and an end-to-end GFX10 translation + D3D12 PSO creation benchmark (bench_dependency_scheduler_vs_blocking_fifo,#[ignore]).Real GFX10 Translation + D3D12 PSO Measurements (
--release, AMD Radeon RX 7600 + Ryzen 5 5500X3D)Command:
cargo test --release -p victory-gpu --lib pipeline::make::tests::bench_dependency_scheduler_vs_blocking_fifo -- --ignored --nocaptureACCCtranslation + cold D3D12HostPipeline::new)main)334.20 ms0.00 msBUDGET)0 / 7250–64 / 72waiting())728–22741.39 ms28.93 ms761.27 ms48.38 ms807.69 ms674.02 ms0.00 ms0.00 ms0.00 msBUDGET)64 / 6464 / 6427.40 / 46.81 ms21.91 / 40.51 ms83.36 ms81.46 msShader::translated()cached lookup (20,000,000calls,draw.rspath)0.64–0.81 ns/call0.64–0.81 ns/callVerification
cargo clippy --workspace --all-targets --locked -- -D warnings: passedcargo clippy --workspace --all-targets --all-features --locked -- -D warnings: passedcargo test -p victory-gpu pipeline --locked: 21 passed, 0 failed, 1 ignoredcargo test -p victory-gpu --all-features pipeline --locked: 22 passed, 0 failed, 1 ignoredcargo run -p xtask -- policy --staged:asset policy: 2 files ok(crates/victory-gpu/src/pipeline.rs,crates/victory-gpu/src/pipeline/make.rs)