Shaders: reuse decoded instructions across range rebuilds #3357
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3357"
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 borosf on 2026-11-26T20:24:03Z.
Summary
range::buildand reuse its decoded instructions across M0-bound induction rebuilds.v_movrel*, avoiding clone overhead in the common case.v_movreld_b32loop regression. The cached path accepts an already-decoded stream; the legacy reference takes more than one decode/build round, and the test compares their IR and structured output.Claim: https://github.com/Marvisak/VIctory/issues/1633#issuecomment-7202146756
Census timing
Warmed binaries, wall-clock median of five on this machine (
CARGO_TARGET_DIR=C:\\Users\\bkora\\VIctory\\target):mainThis all-opcode synthetic census completes its test body in 0.03–0.04 s, so Cargo/process startup dominates these wall-clock samples; it does not include a loop-heavy title shader. The change specifically removes repeated decode work for M0-bounded relative-move loops.
Verification
Result: 301 passed, 2 failed, 3 ignored. The two failures match pristine-main Intel Arc B580 baseline failures:
emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zerosemit::valu_tests::fspx_programs_run_with_the_hardwares_dot_productsAll passed.
cargo xtask policy: 191 files OK.Formatting was checked without
cargo fmt:ir.rs: 2/2 rustfmt diff hunks versusorigin/main;range.rs: 0/0.Synthetic tests only; no game data used.
Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T20:29:29Z.
Review: APPROVED
LGTM — verified on Windows against
origin/main(63bcca4).cargo test -p victory-shader --lib ir:: -- --test-threads=1: 9 passed, 0 failed.cargo test -p victory-shader --lib range:: -- --test-threads=1: 4 passed, 0 failed (includingan_m0_bounded_loop_decodes_once_and_keeps_its_ir_and_structure).cargo clippy -p victory-shader --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by borosf on 2026-11-26T20:38:16Z.
Independent local verification at head
f389683on Windows 11 x64, Intel Arc B580 12 GB:emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros,emit::valu_tests::fspx_programs_run_with_the_hardwares_dot_products), pristine main fails them too. New regression testrange::tests::an_m0_bounded_loop_decodes_once_and_keeps_its_ir_and_structurepasses.-D warnings.range.rs; the non-movrel path is untouched.Synthetic tests only; no game data used.
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T21:02:16Z.
Review: APPROVED
LGTM — verified against
origin/main(63bcca43) on Windows x64.range::buildand passing it throughir::build_bounded_decodedpreserves identical IR and structured control flow across M0-bounded rebuilds, while leaving non-v_movrel*programs on the existing move-only path without extra cloning.range::tests::an_m0_bounded_loop_decodes_once_and_keeps_its_ir_and_structure(crates/victory-shader/src/range.rs),legacy_decodescounts the legacy reference passes in the test closure rather than directly instrumentingrange::build.cargo test --locked -p victory-shader --lib -- --test-threads=1 ir:: range:: structure:: resource::: 61 passed, 0 failed, 1 ignored (includingan_m0_bounded_loop_decodes_once_and_keeps_its_ir_and_structure).cargo clippy -p victory-shader --all-targets --locked -- -D warnings(default and--all-features): clean.cargo xtask policy: 191 files ok;rustfmt --edition 2024: clean on changed hunks.Synthetic tests only; no game data used.
Imported from Marvisak/VIctory. Originally posted by evan-kolberg on 2026-11-26T21:42:08Z.
Independent M4 Pro ARM64 release timings favor 0xkn0wh3r3’s bounded-first #2079 over decode reuse alone on the generated relative-move path. I used borosf’s #3357 bounded M0 loop at 1, 8, and 32 motifs, with matched direct-move controls, and applied the two PR patches separately to the same Mac composition (
5addf0f, based on Macbf99e728). borosf’s exact #3357 · 0xkn0wh3r3’s exact #2079 · Mac baseAcross all six process orderings, median paired relative-loop time fell 0.5–1.9% with decode reuse alone and 6.3–30.9% with bounded-first. At 32 motifs, medians were 3.748 / 3.723 / 3.511 ms for current / #3357 / #2079. Direct controls were within 2% on paired medians. IR, structure, and emitted-DXIL fingerprints matched for all six generated inputs. Timings cover in-process
range::buildand result destruction, with process startup and DXIL emission outside the timer.Prepared and tested with Codex.
Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-26T22:16:36Z.
I repeated the #2079 comparison on Windows with this exact head and the same generated M0 loop, using 1, 8 and 32 relative-move motifs and matched direct-move controls. The checked IR and structure fingerprints matched main and #2079 for all six inputs. Six fresh release processes per variant ran in balanced order.
For 1 and 8 relative motifs, the median was 93.11 and 957.46 µs on
f389683, versus 65.69 and 747.32 µs with #2079 merged onto63bcca4. The 32-motif ranges overlap. Full setup and Windows results in #2079. This adds a Windows data point to the M4 Pro comparison above.Imported from Marvisak/VIctory. Originally posted by borosf on 2026-11-27T06:38:41Z.
Thank you — this is the comparison that decides it, and it does not favour this PR. On the same inputs, #2079 is faster than
f389683: 65.69 vs 93.11 µs at 1 relative-move motif and 747.32 vs 957.46 µs at 8, with the 32-motif ranges overlapping.That matches the mechanism: #2079 avoids building the program at its full range when no bound is proven, whereas this PR reuses decoded instructions across a rebuild that #2079 doesn't do in the first place. So the honest summary is that #2079 subsumes this one for the motifs you measured, and I'd rather the maintainer take the faster change than have both land.
For the record, my own numbers on
f389683(Intel Arc B580, Windows 11): 301 passed / 2 failed = the known B580 baseline, and the opcode census through decode → ir → structure → resource → lower → write is 355.4 µs against 354.8 on main — i.e. this PR's win is only on real relative-move loops, exactly where your fixtures and #2079 live.@KainanP / @AurumCarlos — unless someone wants this as a smaller, orthogonal step, I'll close #3357 in favour of #2079 when the author of #2079 is ready. Synthetic tests only, no game data.
Imported from Marvisak/VIctory. Originally posted by futurepro62 on 2026-11-27T07:07:28Z.
NVIDIA full-suite run, to go with the reports above by Dukestar69, fuzeofficlal, since none of them names a GPU run. Tested exact head
f389683(on its base63bcca4).Tested
dxil.dllfrom Windows SDK 10.0.26100 (the loader's default), debug.cargo build --workspace --locked, thencargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware: 867 passed, 0 failed, 10 ignored.an_m0_bounded_loop_decodes_once_and_keeps_its_ir_and_structure.--skipleaves out tests that fail on main63bcca4on this card too, not because of this PR:heap_direct_texture_reads_mark_their_heap_indexends thevictory-shadertest process with0xc0000005(#2571), so without the skip the rest of that crate never reports;dynamic_slots_are_held_until_released,lists_share_a_table_and_copies_keep_their_viewsand the twostride_testshit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317);gathers_at_a_level_match_the_hardwarefails on lane 0 (#1744).Not tested
AI use
Imported from Marvisak/VIctory. Originally posted by borosf on 2026-11-27T07:33:14Z.
Closing in favour of #2079, on the evidence in @andrewpozdnakov7-jpg's Windows run above: on the same generated M0 loops, #2079 is 65.69 vs 93.11 µs at 1 relative-move motif and 747.32 vs 957.46 µs at 8, with the 32-motif ranges overlapping. That is the mechanism, not noise — #2079 does not build the program at its full range when no bound is proven, so the rebuild this PR memoises does not happen there at all.
For the record, my own numbers at
f389683(Arc B580, Windows 11): 301 passed / 2 failed (the known B580 baseline), and the opcode census through decode → ir → structure → resource → lower → write was 355.4 µs against 354.8 on main — this PR's win existed only on real relative-move loops, exactly where #2079 is better.Pull request closed