Shaders: find the written instructions with a worklist, not repeated passes #104
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!104
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/104/head"
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?
@TG0000 on GitHub · 2026-11-24 00:32 UTC · original
TG0000:perf/bitcode-worklist-liveness→main· +258 −50 · 1 files · 1 commits · merged 2026-11-24 07:49 UTCModule::write(crates/victory-shader/src/emit/bitcode.rs) drops the phis nothing reads before numbering values. It did that by sweeping every instruction until a sweep changed nothing, and each sweep built an operandVecfor every live instruction. A use reached through a chain of merges is found one merge per sweep: the last merge's phis read the previous merge's phis, which have lower indices, so a forward sweep finds one more level each time. The cost grew as instructions × merges, and every DXIL shader the translator writes goes through this.Change
Module::live: a worklist over instructions, seeded with every body instruction and branch condition. Each instruction is visited once, and its operands are read throughfor_each_operand, a callback with no allocation. The result is the same set: the smallest one closed under operands.successorsreturns a two-slot inline slice instead of aVec. It is called once per DFS step and in latch folding.The output is byte-for-byte the same.
written_bytes_unchangedpins the length and FNV-1a hash of two synthetic modules to what the writer produced before this change.Tests (synthetic only, no game data)
worklist_liveness_matches_passes: the new liveness equals the old sweep algorithm, kept in the tests as the reference, on several module shapes (diamond chains with one phi per register, plus a loop whose empty latch is folded).unread_phis_are_dropped: an unread phi and a cycle of phis that only read each other stay dead; a read phi stays live.successors_of_each_terminator.written_bytes_unchanged: see above.Benchmark
cargo test --release -p victory-shader bitcode -- --ignored --nocapture(bench_write, average of 5write()calls on a synthetic module):The written bytes were identical before and after in all three cases (same length and hash).
Checked
cargo +stable-x86_64-pc-windows-msvc test --workspace: all pass.cargo +stable-x86_64-pc-windows-msvc clippy --workspace --all-targets: no new warnings (the ones that remain are in files this PR does not touch).cargo +stable-x86_64-pc-windows-msvc xtask policy: ok.bitcode.rschanged, and rustfmt ran on that file alone. No open PR touches it.AI-assisted (Claude Code).
🤖 Generated with Claude Code
@lordon1a on GitHub · 2026-11-24 00:51 UTC · original
Verified
24480a73fon Windows 11 (x86_64-pc-windows-gnullvm,rustc 1.100.0, applied cleanly tomain@4c0bb89): pass.cargo xtask policy: 151 files okcargo test -p victory-shader -- --skip v_med3_f32_matches_rdna2_with_nan: 72 passed, 0 failed, 1 ignored (+4 new worklist tests).AI-assisted.
@DaviTostes on GitHub · 2026-11-24 01:09 UTC · original
Tested
24480a7on Arch Linux x86_64, rustc 1.98.1: pass.cargo test -p victory-shader: 55 passed, 0 failed, 1 ignored (2 test binaries), including the 5 tests this PR adds.emit::bitcode::tests::bench_write(benchmark).victory-gpuE0425.