Shaders: a relative move's program is built at its full range only if no bound is proven #2079

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

@⁠0xkn0wh3r3 on GitHub · 2026-11-25 04:25 UTC · original
0xkn0wh3r3:shader/range-build-lazy → main · +48 −14 · 2 files · 1 commits · open

The problem

Translating a program with a relative move (v_movrel* or v_swaprel) cost nearly three times as much in range::build as the same program without one.

range::build built the program with every relative move at its full range, and its structure, before trying to prove bounds. It uses that full-range program only where no bound is proven (and to give up at once where its structure fails). The bounded rounds then build the program and its structure again, so the first build was mostly wasted work.

Synthetic 256-block program: 20.7 ms with a relative move against 7.2 ms without.

The fix

  • The moves are now found in the decoded instructions, not in the built program.
  • The program at full range is built only after the rounds prove nothing.
  • The code is decoded once. ir::build_decoded takes the decoded list, so a program without relative moves decodes and builds once as before, and each round saves a decode.
  • On the first round only the moves the program reaches are kept, as when they were taken from the built program.

One case changes: a program whose full-range structure fails but whose bounded form proves every bound now translates instead of being refused. The bounds hold by the same induction; only the fallback was refused.

Measured with synthetic wave32 compute programs, release build, three rounds each:

program before after
256 blocks, with a relative move 20.7-22.9 ms 14.8-15.7 ms
64 blocks, with a relative move 3.5-4.4 ms 2.3-2.8 ms
without one unchanged (same allocations, times within noise)

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), including range.rs's bound tests: 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, which fail the same way on main on NVIDIA (the test host's views, #1835).
  • cargo clippy -p victory-shader --all-targets: clean.
  • Timings are from a synthetic benchmark outside the tree (hand-encoded programs, one variant with a v_movrels_b32 indexed by a bounded M0).
  • No game shaders here, so how many of the title's programs have relative moves is not known.
  • #1757 and #1802 edit other parts of range.rs (operand access, shift bounds); this touches only build.
**@⁠0xkn0wh3r3** on GitHub · 2026-11-25 04:25 UTC · [original](https://github.com/Marvisak/VIctory/pull/2079) `0xkn0wh3r3:shader/range-build-lazy` → `main` · +48 −14 · 2 files · 1 commits · open ## The problem Translating a program with a relative move (`v_movrel*` or `v_swaprel`) cost nearly three times as much in `range::build` as the same program without one. `range::build` built the program with every relative move at its full range, and its structure, before trying to prove bounds. It uses that full-range program only where no bound is proven (and to give up at once where its structure fails). The bounded rounds then build the program and its structure again, so the first build was mostly wasted work. Synthetic 256-block program: 20.7 ms with a relative move against 7.2 ms without. ## The fix - The moves are now found in the decoded instructions, not in the built program. - The program at full range is built only after the rounds prove nothing. - The code is decoded once. `ir::build_decoded` takes the decoded list, so a program without relative moves decodes and builds once as before, and each round saves a decode. - On the first round only the moves the program reaches are kept, as when they were taken from the built program. One case changes: a program whose full-range structure fails but whose bounded form proves every bound now translates instead of being refused. The bounds hold by the same induction; only the fallback was refused. Measured with synthetic wave32 compute programs, release build, three rounds each: | program | before | after | |---|---|---| | 256 blocks, with a relative move | 20.7-22.9 ms | 14.8-15.7 ms | | 64 blocks, with a relative move | 3.5-4.4 ms | 2.3-2.8 ms | | without one | | unchanged (same allocations, times within noise) | 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), including `range.rs`'s bound tests: 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`, which fail the same way on `main` on NVIDIA (the test host's views, #1835). - `cargo clippy -p victory-shader --all-targets`: clean. - Timings are from a synthetic benchmark outside the tree (hand-encoded programs, one variant with a `v_movrels_b32` indexed by a bounded M0). ## Not covered / Related - No game shaders here, so how many of the title's programs have relative moves is not known. - #1757 and #1802 edit other parts of `range.rs` (operand access, shift bounds); this touches only `build`.
`range::build` built the program with every relative move at its full
range, and its structure, before trying to prove bounds, though it uses
them only where no bound is proven (and to give up at once where that
structure fails). For any program with a `v_movrel*` or `v_swaprel`, that
made `range::build` nearly three times the work of the same program
without one, since the bounded rounds build the program and its structure
again (synthetic 256-block program: 20.7 ms against 7.2 ms).

The moves are now found in the decoded instructions, and the program at
full range is built only after the rounds prove nothing. The code is
decoded once: `ir::build_decoded` takes the decoded list, so a program
without relative moves decodes and builds once as before, and each round
saves a decode. On the first round only the moves the program reaches
are kept, as when they were taken from the built program.

One case changes: a program whose full-range structure fails but whose
bounded form proves every bound now translates instead of being refused
(the bounds hold by the same induction; only the fallback was refused).

Measured with synthetic wave32 compute programs, release build, three
rounds each: range::build with a relative move 20.7-22.9 ms -> 14.8-15.7
ms (256 blocks), 3.5-4.4 -> 2.3-2.8 ms (64 blocks); without one,
unchanged (same allocations, times within noise). 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:54:16 +00:00
Author
Owner

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

Offline measurement on a retail dump

Result: no count change against main.

I merged head 955cde3d 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:07 UTC · [original](https://github.com/Marvisak/VIctory/pull/2079#issuecomment-7157911172) ### Offline measurement on a retail dump **Result: no count change against `main`.** I merged head 955cde3d 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 10:30 UTC · original · edited 2026-11-26 01:20 UTC

Automated triage for the maintainers.

Merge candidate (unchanged). The push since the last triage (955cde3 to 99d33d4) is a rebase onto current main. The diff to crates/victory-shader/src/range.rs and crates/victory-shader/src/ir.rs is identical, and it merges cleanly. range::build finds relative moves in the decoded list and decodes once (ir::build_decoded, which ir::build/build_bounded now delegate to with the same arguments). It builds the full-range program only when the bounded rounds prove nothing. The one behaviour change, translating a program whose bounds are all proven even though its full-range structure fails, follows from the induction in the function's doc comment. The retail census in the comments showed no change in validated counts.

CI: passing (check).

Recommending a look, not approving.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 10:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/2079#issuecomment-7159791316) · edited 2026-11-26 01:20 UTC <!-- victory-triage v1 head=99d33d41679076941778d17fc016f39530803625 verdict=merge-candidate at=2026-11-26T01:20:52Z --> Automated triage for the maintainers. **Merge candidate (unchanged).** The push since the last triage (`955cde3` to `99d33d4`) is a rebase onto current `main`. The diff to `crates/victory-shader/src/range.rs` and `crates/victory-shader/src/ir.rs` is identical, and it merges cleanly. `range::build` finds relative moves in the decoded list and decodes once (`ir::build_decoded`, which `ir::build`/`build_bounded` now delegate to with the same arguments). It builds the full-range program only when the bounded rounds prove nothing. The one behaviour change, translating a program whose bounds are all proven even though its full-range structure fails, follows from the induction in the function's doc comment. The retail census in the comments showed no change in validated counts. CI: passing (`check`). Recommending a look, not approving. --- _Generated by [Claude Code](https://claude.ai/code)_
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/2079/head:github-bot/gh-2079'
git switch 'github-bot/gh-2079'

Merge

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