Shaders: compute Module::plan once in Shader::finish and reuse for uses and bitcode write #3152
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!3152
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3152"
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?
@reeledMarek on GitHub · 2026-11-26 10:27 UTC · original
reeledMarek:fix/shader-single-plan-in-finish→main· +43 −8 · 2 files · 1 commits · openSummary
Shader::finish()incrates/victory-shader/src/emit/shader.rsranself.m.uses()(which executes fullModule::plan(): worklist liveness, RPO DFS, predecessor lists, empty-block folding, and block layout) and then ranself.m.write()(which computed the exact sameModule::plan()a second time from scratch).uses()andwrite(),Shader::finish()only appends metadata and constants and never adds or modifies blocks, instructions, or terminators, soPlanis invariant.pub(crate) fn plan,uses_of(&Plan), andwrite_with(&Plan)incrates/victory-shader/src/emit/bitcode.rs, computelet plan = self.m.plan();once inShader::finish(), and addreused_plan_matches_fresh_uses_and_writeverifying byte-identical bitcode and identicalUses.@cloph-dsp on GitHub · 2026-11-26 11:25 UTC · original
Independent local verification of head
86eb516on Windows 11, Rust 1.100.0/MSVC:cargo test --locked -p victory-shader --lib reused_plan_matches_fresh_uses_and_write— 1 passed, 0 failed.git diff --check origin/main HEAD— clean.CPU-only lowering test; no D3D12 device or game assets used. Worktree-local
CARGO_TARGET_DIR. AI-assisted (Hy4 flash). GPU/driver: N/A (CPU-only). No game data.@Dukestar69 on GitHub · 2026-11-26 11:31 UTC · original · approved these changes
Verified against
origin/main(63bcca4):cargo test -p victory-shader --lib emit::bitcode:: -- --test-threads=1: 13/13 passed (1 ignored bench; includingreused_plan_matches_fresh_uses_and_write).cargo test -p victory-shader --lib emit::tests:: -- --test-threads=1: 17/17 passed.cargo clippy -p victory-shader --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Cleanly computes
Module::planonce inShader::finishand reuses it for bothusesand bitcode emission.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
@rezioliver-collab on GitHub · 2026-11-26 18:01 UTC · original
Timing the full Shader::finish() call on Apple M1 showed where reusing the plan pays off. On a compute graph with 256 branch-and-join stages, finalization went from 888 to 776 µs. Building and finalizing that graph together went from 2.98 to 2.85 ms.
finish()finish()I compared
63bcca43and86eb5162in release mode on macOS 14.7 (Rust 1.98.1). Each arm had eight dependent integer operations, followed by a phi at the join. I timed graph construction and finalization separately over 12 alternating pairs. The complete DXBC containers matched byte for byte at all three sizes (2,416, 9,784 and 78,692 bytes).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.