Repository navigation
Shaders: find the written instructions with a worklist, not repeated passes - #104
Merged
Merged
Conversation
…passes Module::write dropped unread phis by sweeping every instruction until a sweep changed nothing, allocating an operand Vec per instruction per sweep. A chain of merges needs one sweep per merge, so the cost grew with instructions x merges. A worklist now visits each instruction once and reads operands through a callback; the block DFS, latch folding and the call/phi/gep records stop allocating too. The written bytes are the same (pinned by a test against the previous writer's output). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
|
Verified
AI-assisted. |
|
Tested
|
edsuuu
referenced
this pull request
in edsuuu/VI-BR-PORT
Nov 24, 2026
…, not repeated passes Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Closed
mercuryVM
added a commit
to mercuryVM/VIctory
that referenced
this pull request
Nov 24, 2026
Sync requested by the user. 17 files conflicted; resolutions: - Same-spot additions on both sides kept both (13 hunks). - bitcode.rs, bcpack.rs: kept the fork's rewrites (Marvisak#697 DCE writer, Marvisak#703 streaming decoder) over upstream's Marvisak#104/Marvisak#93; removed upstream's now duplicate or unused helpers (second `live`, `for_each_operand`, Succs/successors, bcpack bucket table) and adapted upstream's tests. - xasync.rs: fork's per-queue terminate plus upstream's wake of waiters. - emit/mod.rs: fork's spill-table build plus upstream's structure-first resource tracking; watch.rs: fork's absent-block clear plus saturating_add. - net.rs, draw.rs: upstream's side. - Test helpers adjusted to the merged signatures (track(.., st), heap_handle(.., nonuniform, ..), lowers_with, Config::resolve(paths(..))). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
mercuryVM
added a commit
to mercuryVM/VIctory
that referenced
this pull request
Nov 24, 2026
worklist_liveness_matches_passes, unread_phis_are_dropped and written_bytes_unchanged pin upstream's writer (Marvisak#104), which the sync kept the fork's Marvisak#697 dead-code-eliminating writer over; that writer's own liveness tests cover the property. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
suirentakamura
referenced
this pull request
in suirentakamura/victory-suiren
Nov 24, 2026
Shaders: find the written instructions with a worklist, not repeated passes
itsonlysimbo
pushed a commit
to itsonlysimbo/VIctory
that referenced
this pull request
Nov 24, 2026
…eness Shaders: find the written instructions with a worklist, not repeated passes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Module::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