Shaders: reuse lane guards for unchanged EXEC within a block #617

Manually merged
github merged 1 commit from gh-pr/617/head into gh-pr/617/base 2026-11-26 04:10:14 +00:00
Owner

@⁠yyc160 on GitHub · 2026-11-24 05:42 UTC · original
yyc160:perf/reuse-shader-guards → main · +96 −2 · 3 files · 1 commits · merged 2026-11-25 00:11 UTC

Change

Lanes::finish used to ask whether the block implies EXEC and, if not, simplify
EXEC 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) to 81b81df.
Microseconds per synthetic program, timing only structure on 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.

Input Before (us) After (us)
512 unmasked vector adds 33.626 31.589
8 mask changes, 1 add each 14.295 11.610
8 mask changes, 64 adds each 201.159 34.295

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_DXIL pointed to the installed
    Windows SDK's x64 validator. A parallel baseline run had exited in
    d3d10warp.dll before 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 policy and cargo xtask policy --staged: passed.
**@⁠yyc160** on GitHub · 2026-11-24 05:42 UTC · [original](https://github.com/Marvisak/VIctory/pull/617) `yyc160:perf/reuse-shader-guards` → `main` · +96 −2 · 3 files · 1 commits · merged 2026-11-25 00:11 UTC ## Change `Lanes::finish` used to ask whether the block implies EXEC and, if not, simplify EXEC 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) to `81b81df`. Microseconds per synthetic program, timing only `structure` on 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. | Input | Before (us) | After (us) | | --- | ---: | ---: | | 512 unmasked vector adds | 33.626 | 31.589 | | 8 mask changes, 1 add each | 14.295 | 11.610 | | 8 mask changes, 64 adds each | 201.159 | 34.295 | 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_DXIL` pointed to the installed Windows SDK's x64 validator. A parallel baseline run had exited in `d3d10warp.dll` before 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 policy` and `cargo xtask policy --staged`: passed.
An instruction guard depends on its EXEC and the reachability of its block. Keep the most recent result, including an elided guard, rather than repeating the same BDD queries for consecutive vector instructions. Scalar instructions still bypass guard selection.

Cover EXEC changes across and within a branch with a synthetic shader. Add a CPU-only guard_runs benchmark for unmasked, short, and long masked runs.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:10:12 +00:00
github manually merged commit 81b81df351 into gh-pr/617/base 2026-11-26 04:10:14 +00:00
Author
Owner

@⁠geiyiliyabumo on GitHub · 2026-11-24 10:48 UTC · original

Independent verification & code review on Windows 11 Pro (build 26100) + AMD Radeon RX 9060 XT (RDNA4, driver 32.0.32029.2010, Rust 1.98.1), cleanly merged onto main (ffe310e):

  • cargo xtask policy: PASS (155 files ok)
  • cargo clippy -p victory-shader --all-targets --locked -- -D warnings: PASS (includes new benches/guard_runs.rs)
  • cargo clippy -p victory-shader --all-targets --features diagnostics --locked -- -D warnings: PASS
  • cargo test -p victory-shader --locked: 121 passed, 0 failed, 1 ignored (including new structure::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, Bool IDs are append-only interned handles, and intervening scalar ops do not clobber last_guard when e stays identical.

AI-assisted; synthetic tests only, no game files.

**@⁠geiyiliyabumo** on GitHub · 2026-11-24 10:48 UTC · [original](https://github.com/Marvisak/VIctory/pull/617#issuecomment-7129276624) Independent verification & code review on Windows 11 Pro (build 26100) + AMD Radeon RX 9060 XT (RDNA4, driver `32.0.32029.2010`, Rust `1.98.1`), cleanly merged onto `main` (`ffe310e`): - `cargo xtask policy`: PASS (`155 files ok`) - `cargo clippy -p victory-shader --all-targets --locked -- -D warnings`: PASS (includes new `benches/guard_runs.rs`) - `cargo clippy -p victory-shader --all-targets --features diagnostics --locked -- -D warnings`: PASS - `cargo test -p victory-shader --locked`: **121 passed, 0 failed, 1 ignored** (including new `structure::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, `Bool` IDs are append-only interned handles, and intervening scalar ops do not clobber `last_guard` when `e` stays identical. *AI-assisted; synthetic tests only, no game files.*
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!617
No description provided.