GPU: dependency-aware two-stage shader translation and pipeline scheduling (#1509) #1898
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!1898
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1898"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@nathanbzrr on GitHub · 2026-11-25 00:19 UTC · original
nathanbzrr:gpu/pipeline-dependency-scheduler→main· +549 −34 · 3 files · 1 commits · openAddresses #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)@Marvisak on GitHub · 2026-11-25 08:17 UTC · original · edited 2026-11-26 08:25 UTC
Automated triage for the maintainers.
Needs work. Re-reviewed at
5026c04. Against4de2b31it is a rebase onto63bcca4plus rustfmt of the newPending::new(...)test calls incrates/victory-gpu/src/pipeline/make.rs, which settles the formatting nit. No logic changed. TheSchedulerstill reads as sound: a pipeline parks only on a shader another worker has claimed,unblockruns under the same lock afterfinish_translate, andtakenkeeps a single build.Shader::translated()is unchanged frommain.The two open points remain:
bench_dependency_scheduler_vs_blocking_fifo, which is not in this head. Please mark that table as coming from a benchmark outside the PR, or drop it.CI: passing (
check).Generated by Claude Code
@nathanbzrr on GitHub · 2026-11-25 09:08 UTC · original
Updated
gpu/pipeline-dependency-schedulerto2018b59addressing all three points from the triage review:1. Removed the extra atomic load in
Shader::translated()(crates/victory-gpu/src/pipeline.rs)state: AtomicU8onShaderwithclaimed: AtomicBooland read completion directly fromself.translated.get().is_some()inShader::is_done().Shader::translated()is now 100% unchanged frommain(pipeline.rsdiff is+22 / -0), sodraw.rshot-path calls execute zero extra atomic loads or stores beyondOnceLock::get_or_init.Shader::translated()lookup latency over20,000,000calls in--release:12.82–16.15 mstotal (0.64–0.81 ns/call).!s.is_done()and!s.try_claim()while holding theSCHEDULERlock knows another worker previously succeeded ats.try_claim()and will calls.translated()(initializings.translatedsos.is_done()becomestrue) before acquiring the sameSCHEDULERlock to runsched.unblock(&s).2. Real GFX10 Translation + D3D12 PSO Creation Measurements (
bench_dependency_scheduler_vs_blocking_fifo)Added
pipeline::make::tests::bench_dependency_scheduler_vs_blocking_fifo(#[ignore]) and ran it in--releaseon Windows 11 MSVC (AMD Radeon RX 7600, driver32.0.32029.2010, AMD Ryzen 5 5500X3D, 8 worker threads):Each run generates fresh GFX10
ACCC(FSPX) shader containers with distinct branch immediates and VALU operands, exercises the realvictory-shaderGFX10 -> IR -> structuriser -> DXIL translator (Shader::translated()) and real D3D12HostPipeline::new()(CreateComputePipelineState+ID3D12PipelineLibrary1::StorePipeline), and records per-worker time spent translating, blocked insideOnceLock::get_or_initon another worker's translation, and building host PSOs:main)334.20 ms(237.19–334.20 ms)0.00 ms0 msblocked)84.51 ms97.69 ms6,029.14 ms5,273.70 ms-12.5%BUDGET)0 / 7250–64 / 72waiting())728–22741.39 ms(625.00–741.39 ms)28.93 ms(28.93–32.39 ms)761.27 ms(641.62–761.27 ms)48.38 ms(48.38–61.83 ms)807.69 ms(699.49–807.69 ms)674.02 ms(664.97–676.82 ms)0.00 ms0.00 ms0.00 msBUDGET)64 / 6464 / 6421.84–27.40 ms/37.94–46.81 ms19.66–21.91 ms/36.73–40.51 ms68.19–83.36 ms68.12–81.46 ms(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
2018b59)d075795)pipeline.rs+22 / -0,pipeline/make.rs~105production lines). Leavespipeline/host.rs,Pendinglayout, andShader::translated()untouched.+757 / -196lines,~380production lines). Refactorspipeline/host.rs(select_stages/required_shaders) and replaces static queues withPool+ boxed closures.claimed: AtomicBool) perShader, +0 bytes perPending.early()andready()still use the lock-freeenqueue()check and push oneArc<Pending>toqueues[0..2]; shaders are claimed lazily when popped by a worker, andblockedentries exist only while a shader is actively in-flight.Mutex<ShaderDeps>(Vec<Weak<Pending>>) +AtomicBoolpermanently to everyShader, and adds 2OnceLocks + 6 atomics to everyPending.start_with_deps()eagerly querieshost().mesh_shaders(), lockss.depsper shader, allocatesWeak<Pending>waiters, and pushes duplicateArc<Shader>entries intodemand_shadersonearly -> demandpromotion.Shader::translated()hot path (draw.rs)main(self.translated.get_or_init(...).as_ref(), zero extra loads, stores, or locks).self.finish_translation(out.is_some())afterget_or_init, acquiringself.deps.lock()on the uncached path.[VS, PS])Scheduler::pop()claimsVS, re-queuespat the front of its queue when trailing unstarted shaders (PS) remain, and wakes another worker (if more { work.notify_one(); }) soVSandPStranslate concurrently without extra per-Pendingdependency counters.remaining_deps: AtomicUsize(with anUNREGISTERED = usize::MAX+ 1registration sentinel) and 4 separate queues (demand_pipelines,demand_shaders,early_pipelines,early_shaders).Pending::make()->HostPipeline::new()once shaders finish, preservingmain's exactrefuse(...)logging and stage checks.on_shader_done(&pending, false)callsp.fail()directly as soon as any one shader fails (even while sibling stages ofpare still translating), bypassingHostPipeline::new().Verification on
2018b59cargo 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@nathanbzrr on GitHub · 2026-11-25 22:12 UTC · original
Rebased onto
origin/main(f3578e3, new head4de2b31), resolving the merge conflicts incrates/victory-gpu/src/pipeline.rsandcrates/victory-gpu/src/pipeline/make.rswith the scheduler design unchanged:#1320'sskipped_shader/Pending::new(..., skip_hashes)/earlyguard /skipped_pipeline_stays_off_the_queuetest (withShader::claimed),#2155'sShader::for_test, and#2301'sread_unalignedstream reading alongside the two-stage dependency scheduler (#1509).claimed: std::sync::atomic::AtomicBool::new(false)incrates/victory-gpu/src/pipeline/placed_uav_tests.rs'sShaderliteral added by#1273(61bfc77).Verification (
4de2b31)cargo run -p xtask -- policy->186 files okcargo clippy -p victory-gpu --all-targets --locked -- -D warnings&--all-features-> cleancargo test -p victory-gpu --lib --locked -- pipeline::->26 passed; 0 failedcargo test -p victory-gpu --features diagnostics --lib --locked -- pipeline::->29 passed; 0 failed4de2b3129ato5026c0420b@catminou4 on GitHub · 2026-11-25 00:32 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.
Dependency-aware two-stage shader translation and pipeline…: large GPU pipeline rework — biggest of this wave; Windows-only, needs hardware suite.
@nathanbzrr on GitHub · 2026-11-26 07:48 UTC · original
Rebased cleanly onto
main(63bcca4->5026c04) and formatted the newly addedPending::new(...)test calls incrates/victory-gpu/src/pipeline/make.rswithrustfmt --edition 2024(without touching unrelated pre-existing lines).Re-verified after the final edit:
cargo run -p xtask --locked -- policy:191 files okcargo clippy --workspace --all-targets --locked -- -D warnings(default &--all-features): cleancargo test -p victory-gpu --lib --locked pipeline:: -- --test-threads=1:28 passed; 0 failedcargo test -p victory-gpu --features diagnostics --lib --locked pipeline:: -- --test-threads=1:31 passed; 0 failedAI-assisted; synthetic tests only, no game files.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.