Skip to content

Shaders: lane conditions along live phi edges are values, and each set is met once - #2062

Merged
Marvisak merged 1 commit into
Marvisak:mainfrom
0xkn0wh3r3:shader/live-edges-inline
Nov 25, 2026
Merged

Marvisak merged 1 commit into
Marvisak:mainfrom
0xkn0wh3r3:shader/live-edges-inline

Conversation

@0xkn0wh3r3

@0xkn0wh3r3 0xkn0wh3r3 commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

The problem

Translating shaders with control flow spends time and allocations in one step that keeps repeating the same work.

Lower::live_edges walks every phi a lane reads, back through its incoming edges, carrying the last few branch conditions known along the path. Two costs:

  • Each step allocated a Vec for those conditions, cloned for every edge and for the seen list.
  • Each step asked the lane-condition diagram (meet) whether some lane meets the conditions. Paths into one join ask again for the same sets.

On a synthetic program of 256 blocks, 4,915 work items asked 3,047 times for 883 distinct sets.

The fix

  • The conditions (at most four) are now a small Copy value (Known), not a Vec.
  • Whether a set is met is kept per set for the walk, so each set is asked once.

The walk and its answers are unchanged.

Measured with synthetic wave32 compute programs (divergent ifs, uniform loops, gathers) through range::build, resource::track, io::raise and emit_with, release build, two rounds each:

program emit_with on main with the change
256 blocks 4.67-4.74 ms 4.15-4.27 ms
64 blocks 1.28-1.31 ms 1.19-1.21 ms
512 small blocks 3.50-3.52 ms 3.26-3.30 ms

Allocations in emit_with are down about 40%. The DXIL is byte-identical for every program (FNV hash of the output).

Testing

Related

#999 changes meet itself and other parts of lower.rs. This change touches only live_edges.

…t is met once

`Lower::live_edges` walks every phi a lane reads back through its
incoming edges, carrying the last few branch conditions known along the
path. Each step allocated a `Vec` for those conditions (cloned for every
edge and for the seen list) and asked the lane-condition diagram whether
some lane meets them, though paths into one join ask again for the same
sets: on a synthetic program of 256 blocks, 4,915 work items asked 3,047
times for 883 distinct sets.

The conditions (at most four) are now a small `Copy` value, and whether a
set is met is kept per set for the walk. The walk and its answers are
unchanged.

Measured with synthetic wave32 compute programs (divergent ifs, uniform
loops, gathers) through range::build, resource::track, io::raise and
emit_with, release build, two rounds each:
- emit_with: 4.67-4.74 ms -> 4.15-4.27 ms (256 blocks), 1.28-1.31 ->
  1.19-1.21 ms (64 blocks), 3.50-3.52 -> 3.26-3.30 ms (512 small
  blocks); allocations in emit_with down about 40%.
- The DXIL is byte-identical for every program (FNV hash of the output).

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f, cargo test -p victory-shader --locked.

144 passed / 0 failed / 2 ignored. Lane conditions along live phi edges as values — phi-edge condition lowering fix.

@DenRakEiw DenRakEiw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified locally merged onto origin/main (940d32f, Windows 11 x64, Rust 1.98.1 MSVC):

  • cargo test -p victory-shader --lib emit::lower::tests:: — 21 passed, 0 failed
  • cargo clippy -p victory-shader --all-targets — 0 warnings
  • cargo xtask policy — ok (183 files ok)

Clean memoization and value-based handling of lane conditions along live phi edges. Looks good.

AI-assisted (Gemini 4 Neon).

@sinan-cmyk

Copy link
Copy Markdown

Offline measurement on a retail dump

Result: no count change against main.

I merged head a0163c2 onto main 940d32f (clean merge) and ran victory translate --validate --list on shaders.rpf (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with main program by program (25,889 programs). Validated: 23,918 on main, 23,918 with this PR.

No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right.

No shader names or data are included, per the asset policy. AI-assisted (Claude Code).

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.
Merge candidate.

This is a performance-only change to Lower::live_edges in crates/victory-shader/src/emit/lower.rs. The list of known branch conditions becomes a fixed Copy array (Known, at most MAX_KNOWN) instead of a Vec. The result of Bools::meet is also cached per condition set for the walk.

I checked that it behaves the same as before:

  • Known::and drops the oldest condition just as the old drain did.
  • Slots beyond len always keep their initial value, so the derived Eq/Hash match the old Vec contents.
  • meet (structure.rs) takes &self and starts a fresh budget on each call, so caching its answer cannot change results.

The author reports byte-identical DXIL and about 5–10% faster emit_with. A separate offline run in the thread found no change in validation counts. No other open PR changes live_edges.

CI: not run (no check runs on this head). A maintainer may need to approve the workflow run.

Recommending a look, not approving.


Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants