Shaders: a relative move's program is built at its full range only if no bound is proven #2077
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2079"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from Marvisak/VIctory. Originally posted by 0xkn0wh3r3 on 2026-11-25T04:25:35Z.
The problem
Translating a program with a relative move (
v_movrel*orv_swaprel) cost nearly three times as much inrange::buildas the same program without one.range::buildbuilt 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
ir::build_decodedtakes the decoded list, so a program without relative moves decodes and builds once as before, and each round saves a decode.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:
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), includingrange.rs's bound tests: 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, which fail the same way onmainon NVIDIA (the test host's views, #1835).cargo clippy -p victory-shader --all-targets: clean.v_movrels_b32indexed by a bounded M0).Not covered / Related
range.rs(operand access, shift bounds); this touches onlybuild.Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T04:31:04Z.
Review: APPROVED
Verified locally merged onto
origin/main(940d32f, Windows 11 x64, Rust 1.98.1 MSVC):cargo test -p victory-shader --lib range::— 3 passed, 0 failedcargo clippy -p victory-shader --all-targets— 0 warningscargo xtask policy— ok (183 files ok)Clean refinement avoiding full-range rebuilds when a relative move's index bound is already proven. Looks good.
AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T04:34:45Z.
Review: APPROVED
Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main
940d32f69b,cargo test -p victory-shader --locked.144 passed / 0 failed. Relative move's program built at its full range only when needed — movrel program-size fix.
Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-25T09:07:40Z.
Offline measurement on a retail dump
Result: no count change against
main.I merged head
955cde3dontomain940d32f(clean merge) and ranvictory translate --validate --listonshaders.rpf(1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result withmainprogram by program (25,889 programs). Validated: 23,918 onmain, 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).
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T10:30:33Z.
Automated triage for the maintainers.
Merge candidate (unchanged). The push since the last triage (
955cde3to99d33d4) is a rebase onto currentmain. The diff tocrates/victory-shader/src/range.rsandcrates/victory-shader/src/ir.rsis identical, and it merges cleanly.range::buildfinds relative moves in the decoded list and decodes once (ir::build_decoded, whichir::build/build_boundednow 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
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T19:50:47Z.
Review: APPROVED
Looks good to me — clean optimization avoiding unnecessary full-range IR/structure builds unless bound inference fails to prove a bound, while sharing a single
gfx10::decodeacross rounds.Verified locally on Windows 11 with head
99d33d41cleanly merged ontomain(63bcca43):crates/victory-shader/src/ir.rs:138-153andcrates/victory-shader/src/range.rs:41-99:range::buildscans the decoded instruction list once for relative moves, restrictsassumedto reached instructions on round0, preserves exact endpoint bounds (vgprs.min(u16::from(reg) + u16::from(m) + 1)), and falls back to full-rangeir::build_decoded(..., &HashMap::new())atrange.rs:97only when bounds cannot be proven.cargo run -p xtask -- policy(191 files ok) andcargo clippy --locked -p victory-shader --all-targets -- -D warnings(both default and--all-features) pass.cargo test --locked -p victory-shader --lib ir:::9 passed; 0 failed(0.12s).cargo test --locked -p victory-shader --lib range:::3 passed; 0 failed(0.00s).rustfmt --edition 2024 --checkpasses onrange.rs, and the newly added lines inir.rs(144-152) are formatting-clean (only pre-existing lines340and841inir.rsreport diffs).Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-26T22:14:01Z.
I repeated the #3357/#2079 comparison on Windows x64 (MSVC, locked release builds). I tested
99d33d4merged onto63bcca4(treea390ba8), #3357 atf389683, and63bcca4itself. Each build ran six fresh processes in balanced order. The inputs were the bounded M0 loop from #3357, repeated 1, 8 or 32 times with one finals_endpgm, paired with direct-move controls.All three builds produced identical generated IR and the checked structural fields for all six inputs. Direct-move medians were close. #2079 is faster on the one- and eight-motif relative inputs, consistent with the M4 Pro report. The 32-motif sample ranges overlap, so the median ranking there is weaker. These are CPU microbenchmarks of generated shaders.
For the two pending approaches, the Windows result supports the bounded-first change on the smaller relative-move cases.
Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-28T00:01:32Z.
I checked this range-analysis change at
99d33d4with the relative-source emitter change from #3630 on main63bcca4. The tested combination keeps both exact PR commits.With app-local WARP and required DXIL validation, the combined branch passed all 160 generated dispatches. Its eight generated DXIL containers were byte-identical to #3630 alone, including the 56-register and relative source/destination cases. The nine-register regression, two existing relative-move tests, and all three range-analysis tests also passed. Strict all-features shader Clippy and the asset policy check passed.
These results cover compatibility between the two changes. The earlier range-build benchmark remains the separate timing measurement for this PR.
If you reuse the emitter change, please retain the Git author on cherry-pick or rebase, or add Co-authored-by: andrewpozdnakov7-jpg [email protected] if folding it into another commit.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.