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

Merged
yyc160 merged 1 commit from upstream-pr/617 into main 2026-11-25 00:11:45 +00:00
yyc160 commented 2026-11-24 05:42:06 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by yyc160 on 2026-11-24T05:42:06Z.


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.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6575467921 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/617). Originally posted by [yyc160](https://github.com/yyc160) on 2026-11-24T05:42:06Z. --- ## 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.
LAKSHYA-cmd-tech commented 2026-11-24 06:54:00 +00:00 (Migrated from github.com)

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).

  • Verified Lanes::finish guard caching: consecutively guarded vector instructions under identical EXEC within a basic block safely reuse the BDD guard query result, avoiding repeated redundant evaluations.
  • Scalar instructions properly bypass guard calculation.
  • Unit test guards_follow_exec_and_block_reachability passes.
  • cargo test -p victory-shader: 70 passed, 0 failed.
  • cargo clippy -p victory-shader --lib -- -D warnings: 0 warnings.
  • cargo xtask policy: 152 files clean.
<!-- greyfinch-sync:Marvisak/VIctory:review:6034293176 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/617#pullrequestreview-6034293176). Originally posted by [LAKSHYA-cmd-tech](https://github.com/LAKSHYA-cmd-tech) on 2026-11-24T05:45:46Z. **Review:** APPROVED --- Tested and verified on Windows 11 x64 (D3D12). - Verified Lanes::finish guard caching: consecutively guarded vector instructions under identical EXEC within a basic block safely reuse the BDD guard query result, avoiding repeated redundant evaluations. - Scalar instructions properly bypass guard calculation. - Unit test guards_follow_exec_and_block_reachability passes. - cargo test -p victory-shader: 70 passed, 0 failed. - cargo clippy -p victory-shader --lib -- -D warnings: 0 warnings. - cargo xtask policy: 152 files clean.
catminou4 commented 2026-11-24 11:03:44 +00:00 (Migrated from github.com)

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_guard is 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.

<!-- greyfinch-sync:Marvisak/VIctory:review:6037404597 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/617#pullrequestreview-6037404597). Originally posted by [catminou4](https://github.com/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_guard` is 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.
geiyiliyabumo commented 2026-11-24 11:04:21 +00:00 (Migrated from github.com)

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, 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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7129276624 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/617#issuecomment-7129276624). Originally posted by [geiyiliyabumo](https://github.com/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`, 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.*
mercuryVM commented 2026-11-24 12:04:04 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T11:26:17Z.

Review: APPROVED


Tested 81b81df on Windows 11, RTX 5070, MSVC: cargo test -p victory-shader -- --test-threads=1 70 passed, including guards_follow_exec_and_block_reachability. cargo clippy -p victory-shader --all-targets is clean. victory translate --validate --pipelines on the local title executable reports 12 of 12 emitted, validated and built into pipelines. cargo bench --bench guard_runs runs and prints its three medians.

  • Safety check: the Cargo.toml change only adds a [[bench]] entry with harness = false. There are no new dependencies, and the bench uses synthetic words only.
  • The cache is sound: cond[n] is fixed within the block and last_guard is reset per block. For the same e, implies/given returns the same answer, so caching it (including None) can't change a guard.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:review:6038360789 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/617#pullrequestreview-6038360789). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-24T11:26:17Z. **Review:** APPROVED --- Tested 81b81df on Windows 11, RTX 5070, MSVC: `cargo test -p victory-shader -- --test-threads=1` 70 passed, including `guards_follow_exec_and_block_reachability`. `cargo clippy -p victory-shader --all-targets` is clean. `victory translate --validate --pipelines` on the local title executable reports 12 of 12 emitted, validated and built into pipelines. `cargo bench --bench guard_runs` runs and prints its three medians. - Safety check: the `Cargo.toml` change only adds a `[[bench]]` entry with `harness = false`. There are no new dependencies, and the bench uses synthetic words only. - The cache is sound: `cond[n]` is fixed within the block and `last_guard` is reset per block. For the same `e`, `implies`/`given` returns the same answer, so caching it (including `None`) can't change a guard. AI-assisted (Claude Code).
upstream-sync closed this pull request 2026-11-25 01:04:29 +00:00
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!617
No description provided.