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

Manually merged
github merged 1 commit from gh-pr/2062/head into gh-pr/2062/base 2026-11-26 04:53:34 +00:00
Owner

@⁠0xkn0wh3r3 on GitHub · 2026-11-25 04:18 UTC · original
0xkn0wh3r3:shader/live-edges-inline → main · +41 −11 · 1 files · 1 commits · merged 2026-11-25 21:54 UTC

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

  • cargo test -p victory-shader --lib -- --test-threads=1 on an RTX 5070 Ti (driver 621.24): all pass except emit::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_zeros and emit::synthetic_tests::gathers_at_a_level_match_the_hardware. Those fail the same way on main on NVIDIA (the test host's views, #1835; #1887 fixes two of them here).
  • cargo clippy -p victory-shader --all-targets: clean.
  • The timings above come from a synthetic benchmark outside the tree (hand-encoded programs through the public stage functions). No game shaders here.

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

**@⁠0xkn0wh3r3** on GitHub · 2026-11-25 04:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/2062) `0xkn0wh3r3:shader/live-edges-inline` → `main` · +41 −11 · 1 files · 1 commits · merged 2026-11-25 21:54 UTC ## 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 - `cargo test -p victory-shader --lib -- --test-threads=1` on an RTX 5070 Ti (driver 621.24): all pass except `emit::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_zeros` and `emit::synthetic_tests::gathers_at_a_level_match_the_hardware`. Those fail the same way on `main` on NVIDIA (the test host's views, #1835; #1887 fixes two of them here). - `cargo clippy -p victory-shader --all-targets`: clean. - The timings above come from a synthetic benchmark outside the tree (hand-encoded programs through the public stage functions). No game shaders here. ## Related #999 changes `meet` itself and other parts of `lower.rs`. This change touches only `live_edges`.
`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).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:53:32 +00:00
github manually merged commit a0163c269b into gh-pr/2062/base 2026-11-26 04:53:34 +00:00
Author
Owner

@⁠sinan-cmyk on GitHub · 2026-11-25 09:22 UTC · original

Offline measurement on a retail dump

Result: no count change against main.

I merged head a0163c26 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).

**@⁠sinan-cmyk** on GitHub · 2026-11-25 09:22 UTC · [original](https://github.com/Marvisak/VIctory/pull/2062#issuecomment-7158245280) ### Offline measurement on a retail dump **Result: no count change against `main`.** I merged head a0163c26 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).
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 09:25 UTC · original

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

**@⁠Marvisak** on GitHub · 2026-11-25 09:25 UTC · [original](https://github.com/Marvisak/VIctory/pull/2062#issuecomment-7158316281) <!-- victory-triage v1 head=a0163c269b20fdff3ea8be7d9d9f34de9cbbf861 verdict=merge-candidate at=2026-11-25T09:25:35Z --> 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](https://claude.ai/code)_
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2062
No description provided.