Repository navigation
Shaders: lane conditions along live phi edges are values, and each set is met once - #2062
Conversation
…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
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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 failedcargo clippy -p victory-shader --all-targets— 0 warningscargo 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).
Offline measurement on a retail dumpResult: no count change against I merged head a0163c2 onto 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). |
|
Automated triage for the maintainers. This is a performance-only change to I checked that it behaves the same as before:
The author reports byte-identical DXIL and about 5–10% faster 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 |
… and each set is met o) into demo
The problem
Translating shaders with control flow spends time and allocations in one step that keeps repeating the same work.
Lower::live_edgeswalks every phi a lane reads, back through its incoming edges, carrying the last few branch conditions known along the path. Two costs:Vecfor those conditions, cloned for every edge and for the seen list.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
Copyvalue (Known), not aVec.The walk and its answers are unchanged.
Measured with synthetic wave32 compute programs (divergent ifs, uniform loops, gathers) through
range::build,resource::track,io::raiseandemit_with, release build, two rounds each:emit_withon mainAllocations in
emit_withare down about 40%. The DXIL is byte-identical for every program (FNV hash of the output).Testing
cargo test -p victory-shader --lib -- --test-threads=1on an RTX 5070 Ti (driver 621.24): all pass exceptemit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride,emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zerosandemit::synthetic_tests::gathers_at_a_level_match_the_hardware. Those fail the same way onmainon NVIDIA (the test host's views, NVIDIA D3D12 (70564ae): stride_tests & synthetic_tests fail due to HEAP_VIEWS (2M > 1M NVIDIA limit) and Stride::Structured with rawBufferLoad #1835; Shader tests: the test host's structured buffer views are raw (#1835) #1887 fixes two of them here).cargo clippy -p victory-shader --all-targets: clean.Related
#999 changes
meetitself and other parts oflower.rs. This change touches onlylive_edges.