Shaders: reuse lane guards for unchanged EXEC within a block #617
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/617"
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 yyc160 on 2026-11-24T05:42:06Z.
Change
Lanes::finishused to ask whether the block implies EXEC and, if not, simplifyEXEC under the block condition for every guarded vector instruction. Within a
block that condition is fixed. Reuse the previous result (including
None)when the instruction has the same EXEC. Scalar instructions still bypass this
logic, and the cache starts empty at each block. This avoids repeated calls;
it does not change how any individual BDD query is evaluated.
The regression test covers a branch where the same EXEC goes from requiring a
guard to requiring none, a second comparison that changes EXEC within the
fallthrough, and a scalar instruction between guarded vector instructions.
Measurements
cargo bench --locked -p victory-shader --bench guard_runs, Windows x64,Rust 1.98.1, comparing
d2a4bae(with the benchmark only) to81b81df.Microseconds per synthetic program, timing only
structureon prebuilt IR.Each binary reports the median of 9 batches of 64 calls; the table gives the
median of five process runs per binary, alternating which binary ran first.
The last case spends 83% less time in this pass. It is not an end-to-end
compilation, frame-rate, or visual-correctness measurement. No title files or
GPU are required to run the benchmark. To reproduce the baseline, apply just
the benchmark file and its Cargo manifest entry to a separate checkout of
d2a4bae, then run the same command.Verification
cargo test --workspace --locked -- --test-threads=1: 265 passed, 4 ignored.Both WARP switches were enabled;
VICTORY_DXILpointed to the installedWindows SDK's x64 validator. A parallel baseline run had exited in
d3d10warp.dllbefore the optimisation; this PR does not address that failure.cargo build --locked --release -p victory: passed.cargo clippy --locked -p victory-shader --all-targets: passed.cargo xtask policyandcargo xtask policy --staged: passed.Imported from Marvisak/VIctory. Originally posted by LAKSHYA-cmd-tech on 2026-11-24T05:45:46Z.
Review: APPROVED
Tested and verified on Windows 11 x64 (D3D12).
Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T10:18:19Z.
Review: APPROVED
Merges cleanly; merged into current main
ffe310e(post-#566), macOS arm64, rustc 1.98.1,cargo test -p victory-shader --locked→ 97 passed / 0 failed / 1 ignored.The guard memoization is sound: within a block, reachability (
cond[n]) is fixed and the guard depends only on the EXEC value and that reachability, so reusing the guard for an unchanged EXEC is exact — the test asserts node equality across instructions and across the fallthrough block, and the scalar-move case correctly stays unguarded. The bench (harness = false, structuration only, no GPU) is a nice addition for a perf-motivated change; it compiles as part of the workspace.One small note:
last_guardis per-block as intended; if a future change makes guards depend on anything mutable mid-block (e.g. BDD node ordering), this cache would need the same revisit.Imported from Marvisak/VIctory. Originally posted by geiyiliyabumo on 2026-11-24T10:48:45Z.
Independent verification & code review on Windows 11 Pro (build 26100) + AMD Radeon RX 9060 XT (RDNA4, driver
32.0.32029.2010, Rust1.98.1), cleanly merged ontomain(ffe310e):cargo xtask policy: PASS (155 files ok)cargo clippy -p victory-shader --all-targets --locked -- -D warnings: PASS (includes newbenches/guard_runs.rs)cargo clippy -p victory-shader --all-targets --features diagnostics --locked -- -D warnings: PASScargo test -p victory-shader --locked: 121 passed, 0 failed, 1 ignored (including newstructure::tests::guards_follow_exec_and_block_reachability)VICTORY_D3D12_DEBUG=1 cargo test -p victory-shader --locked -- diff_tests: 4/4 PASS on RX 9060 XT and 4/4 PASS on WARP (VICTORY_WARP=1)Diff review (
structure.rs,benches/guard_runs.rs,Cargo.toml): clean and exact —cond[n]is invariant within a block,BoolIDs are append-only interned handles, and intervening scalar ops do not clobberlast_guardwhenestays identical.AI-assisted; synthetic tests only, no game files.
Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T11:26:17Z.
Review: APPROVED
Tested
81b81dfon Windows 11, RTX 5070, MSVC:cargo test -p victory-shader -- --test-threads=170 passed, includingguards_follow_exec_and_block_reachability.cargo clippy -p victory-shader --all-targetsis clean.victory translate --validate --pipelineson the local title executable reports 12 of 12 emitted, validated and built into pipelines.cargo bench --bench guard_runsruns and prints its three medians.Cargo.tomlchange only adds a[[bench]]entry withharness = false. There are no new dependencies, and the bench uses synthetic words only.cond[n]is fixed within the block andlast_guardis reset per block. For the samee,implies/givenreturns the same answer, so caching it (includingNone) can't change a guard.AI-assisted (Claude Code).