Shaders: a loop that branches back to the entry instruction translates #105

Open
github-bot wants to merge 1 commit from github-bot/gh-105 into main AGit
Owner

@⁠tedin7 on GitHub · 2026-11-24 00:32 UTC · original
tedin7:vic-loop-entry → main · +64 −10 · 1 files · 1 commits · open

What

Accept shader loops whose back edge targets byte offset zero. The IR builder now puts an empty entry block before the code when the first instruction is a jump or branch target, so the loop header has one edge for the initial register values and one for the loop-carried values.

Why

A valid shader whose first instruction is also its loop header was rejected with Unsupported { offset: 0, what: "a branch to the program entry" }, because block 0 was both the entry and a loop header and SSA had no edge to carry the initial values into its phis. Every other loop shape already works. Only the entry-block handling changes. Block indices shift by one only when the program branches to offset 0.

Tested

Linux x86_64 only, synthetic shader words only (no game files):

  • cargo test -j4 -p victory-shader ir::tests::loops_can_branch_to_offset_zero on origin/main plus only the new test: FAILED with Unsupported { offset: 0, what: "a branch to the program entry" }.
  • The same command with the fix: 1 passed. The test checks the block layout, both phi inputs (initial value and loop-carried value) and that structure::structure accepts the result.
  • cargo test -j4 -p victory-shader: 52 passed, 0 failed.
  • cargo clippy -j4 -p victory-shader --tests: no warnings in ir.rs; the 2 existing warnings elsewhere are unchanged.
  • rustfmt --check --edition 2024 crates/victory-shader/src/ir.rs: clean.

Not run: Windows runtime and any GPU execution. The emit path was not run on a real shader, only the IR and structuring steps.

**@⁠tedin7** on GitHub · 2026-11-24 00:32 UTC · [original](https://github.com/Marvisak/VIctory/pull/105) `tedin7:vic-loop-entry` → `main` · +64 −10 · 1 files · 1 commits · open ## What Accept shader loops whose back edge targets byte offset zero. The IR builder now puts an empty entry block before the code when the first instruction is a jump or branch target, so the loop header has one edge for the initial register values and one for the loop-carried values. ## Why A valid shader whose first instruction is also its loop header was rejected with `Unsupported { offset: 0, what: "a branch to the program entry" }`, because block 0 was both the entry and a loop header and SSA had no edge to carry the initial values into its phis. Every other loop shape already works. Only the entry-block handling changes. Block indices shift by one only when the program branches to offset 0. ## Tested Linux x86_64 only, synthetic shader words only (no game files): - `cargo test -j4 -p victory-shader ir::tests::loops_can_branch_to_offset_zero` on origin/main plus only the new test: FAILED with `Unsupported { offset: 0, what: "a branch to the program entry" }`. - The same command with the fix: 1 passed. The test checks the block layout, both phi inputs (initial value and loop-carried value) and that `structure::structure` accepts the result. - `cargo test -j4 -p victory-shader`: 52 passed, 0 failed. - `cargo clippy -j4 -p victory-shader --tests`: no warnings in ir.rs; the 2 existing warnings elsewhere are unchanged. - `rustfmt --check --edition 2024 crates/victory-shader/src/ir.rs`: clean. Not run: Windows runtime and any GPU execution. The emit path was not run on a real shader, only the IR and structuring steps.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:50:24 +00:00
Author
Owner

@⁠lordon1a on GitHub · 2026-11-24 00:51 UTC · original

Verified 6e6d3fc02 on Windows 11 (x86_64-pc-windows-gnullvm, rustc 1.100.0, applied cleanly to main@4c0bb89): pass.

  • cargo xtask policy: 151 files ok
  • cargo test -p victory-shader -- --skip v_med3_f32_matches_rdna2_with_nan: 69 passed, 0 failed.

AI-assisted.

**@⁠lordon1a** on GitHub · 2026-11-24 00:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/105#issuecomment-7118513224) Verified `6e6d3fc02` on Windows 11 (`x86_64-pc-windows-gnullvm`, `rustc 1.100.0`, applied cleanly to `main@4c0bb89`): **pass**. - `cargo xtask policy`: 151 files ok - `cargo test -p victory-shader -- --skip v_med3_f32_matches_rdna2_with_nan`: **69 passed, 0 failed**. AI-assisted.
Author
Owner

@⁠DaviTostes on GitHub · 2026-11-24 01:09 UTC · original

Tested 6e6d3fc on Arch Linux x86_64, rustc 1.98.1: pass.

  • cargo test -p victory-shader: 52 passed, 0 failed (2 test binaries), including the 1 test this PR adds.
  • The full workspace still needs #112 for the victory-gpu E0425.
**@⁠DaviTostes** on GitHub · 2026-11-24 01:09 UTC · [original](https://github.com/Marvisak/VIctory/pull/105#issuecomment-7118823048) Tested `6e6d3fc` on **Arch Linux x86_64, rustc 1.98.1**: **pass**. - `cargo test -p victory-shader`: **52 passed, 0 failed** (2 test binaries), including the 1 test this PR adds. - The full workspace still needs #112 for the `victory-gpu` E0425.
Author
Owner

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

Automated triage for the maintainers.

Merge candidate. ir::build_bounded in crates/victory-shader/src/ir.rs rejected any program that branches to offset 0 ("a branch to the program entry"); it now puts an empty entry block in front of the code, giving SSA a separate edge for the initial register values (a standard preheader). Block indices (block_at, the partition_point mapping) shift consistently, programs that never target offset 0 are unchanged, and exit in emit/lower.rs handles an empty block. The test checks the block layout, both phi inputs and that structure::structure accepts the result.

CI: no check runs on the head commit.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 00:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/105#issuecomment-7148480088) <!-- victory-triage v1 head=6e6d3fc027d097afcad8db1807f76a203cca7a50 verdict=merge-candidate at=2026-11-25T00:18:46Z --> Automated triage for the maintainers. **Merge candidate.** `ir::build_bounded` in `crates/victory-shader/src/ir.rs` rejected any program that branches to offset 0 ("a branch to the program entry"); it now puts an empty entry block in front of the code, giving SSA a separate edge for the initial register values (a standard preheader). Block indices (`block_at`, the `partition_point` mapping) shift consistently, programs that never target offset 0 are unchanged, and `exit` in `emit/lower.rs` handles an empty block. The test checks the block layout, both phi inputs and that `structure::structure` accepts the result. CI: no check runs on the head commit. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 01:11 UTC · original

Code review and RTX 5090 + WARP + DXIL verification at head 6e6d3fc027d0 merged cleanly onto main (63bcca43c6a0; emit/lower.rs untouched):

  • Code review (crates/victory-shader/src/ir.rs:165-198):
    • Inserting an empty preheader block at blocks[0] (offset: 0, preds: [], exit: Exit::Jump(1)) when any Flow::Jump(0) | Flow::Branch(0) targets offset 0 shifts machine block indices cleanly while keeping machine.offset == 0 intact for s_getpc_b64.
    • Checked downstream lowering (lower.rs:1302-1345): self.block[0] maps to self.s.entry (including mesh shaders updating order[0]), and the loop header at blocks[1] receives initial p.inputs, loop counter 0, and active EXEC along the 0 -> 1 edge cleanly.
  • Verified (Windows 11, NVIDIA RTX 5090 + WARP, dxil.dll 10.0.26100.0, VICTORY_D3D12_DEBUG=1, Rust 1.98.1):
    • cargo xtask policy: 191 files ok; cargo clippy -p victory-shader --all-targets --locked -- -D warnings (default + --features diagnostics): 0 warnings
    • ir::tests (10/10, including loops_can_branch_to_offset_zero), structure::tests (13/13, 1 ignored), and emit::tests (17/17 on both RTX 5090 and WARP) all passed.

LGTM.

**@⁠fuzeofficlal** on GitHub · 2026-11-26 01:11 UTC · [original](https://github.com/Marvisak/VIctory/pull/105#issuecomment-7179521547) Code review and RTX 5090 + WARP + DXIL verification at head `6e6d3fc027d0` merged cleanly onto `main` (`63bcca43c6a0`; `emit/lower.rs` untouched): - **Code review (`crates/victory-shader/src/ir.rs:165-198`)**: - Inserting an empty preheader block at `blocks[0]` (`offset: 0, preds: [], exit: Exit::Jump(1)`) when any `Flow::Jump(0) | Flow::Branch(0)` targets offset 0 shifts machine block indices cleanly while keeping `machine.offset == 0` intact for `s_getpc_b64`. - Checked downstream lowering (`lower.rs:1302-1345`): `self.block[0]` maps to `self.s.entry` (including mesh shaders updating `order[0]`), and the loop header at `blocks[1]` receives initial `p.inputs`, loop counter `0`, and active `EXEC` along the `0 -> 1` edge cleanly. - **Verified (Windows 11, NVIDIA RTX 5090 + WARP, `dxil.dll` 10.0.26100.0, `VICTORY_D3D12_DEBUG=1`, Rust 1.98.1)**: - `cargo xtask policy`: `191 files ok`; `cargo clippy -p victory-shader --all-targets --locked -- -D warnings` (default + `--features diagnostics`): 0 warnings - `ir::tests` (10/10, including `loops_can_branch_to_offset_zero`), `structure::tests` (13/13, 1 ignored), and `emit::tests` (17/17 on both RTX 5090 and WARP) all passed. LGTM.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/105/head:github-bot/gh-105'
git switch 'github-bot/gh-105'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-105'
git switch 'github-bot/gh-105'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-105'
git switch 'github-bot/gh-105'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-105'
git switch 'main'
git merge --squash 'github-bot/gh-105'
git switch 'main'
git merge --ff-only 'github-bot/gh-105'
git switch 'main'
git merge 'github-bot/gh-105'
git push origin 'main'
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!105
No description provided.