Shaders: O(|known|) BDD forced() sweep, read-only implies(), per-block reuse in finish(), and FxHash in meet_in() #2662

Open
github-bot wants to merge 1 commit from github-bot/gh-2662 into main AGit
Owner

@⁠RVZO6 on GitHub · 2026-11-25 17:43 UTC · original
RVZO6:rvzo/structure-bdd-fast → main · +225 −60 · 1 files · 1 commits · open

Claimed in #1633: #1633

Summary

Eliminates quadratic BDD node creation and repeated scans during CFG structurisation (crates/victory-shader/src/structure.rs, +225/-60), with identical reduced OBDD output:

  1. O(|known|) read-only Bools::forced() sweep: replaces Bools::given()'s O(|b| * |vars(b)|) mutating implies loop with a single bottom-up pass over reachable edges of the reduced OBDD.
  2. Read-only Bools::implies(): checks entailment directly without allocating temporary BDD nodes or evicting memo entries.
  3. Per-block reuse in finish(): computes forced(cond[n]) once per block and reuses it across guards and exits.
  4. FxHash in meet_in(): switches the refuted set from default SipHash to the existing Fx hasher.

Measured (--release structure::tests::bench_bools)

Workload Before (main) After Speedup
given() (n = 8) 20.43 µs 0.22 µs 93×
given() (n = 13) 655.25 µs 0.54 µs 1,213×

Not a duplicate of

  • Checked open PRs including #2627 (which fixes Structured::active reachability rather than Bools::given/implies/forced/meet_in). No open PR or #1633 claim overlaps Bools BDD evaluation.

Verification

  • Verified on windows-latest MSVC + WARP SM 6.6 CI (both clippy -D warnings profiles, xtask policy 6/6, victory-shader 281/281 including equivalence tests comparing forced()/implies() against the previous BDD implementations): https://github.com/RVZO6/VIctory/actions/runs/45666985023
  • Not run: the title; any hardware GPU.

AI-assisted: T3 Code (Antigravity, gemini-4-neon)

**@⁠RVZO6** on GitHub · 2026-11-25 17:43 UTC · [original](https://github.com/Marvisak/VIctory/pull/2662) `RVZO6:rvzo/structure-bdd-fast` → `main` · +225 −60 · 1 files · 1 commits · open Claimed in #1633: https://git.gtahub.st/github/Marvisak--VIctory/issues/1633 ### Summary Eliminates quadratic BDD node creation and repeated scans during CFG structurisation (`crates/victory-shader/src/structure.rs`, `+225/-60`), with identical reduced OBDD output: 1. **O(|known|) read-only `Bools::forced()` sweep:** replaces `Bools::given()`'s `O(|b| * |vars(b)|)` mutating `implies` loop with a single bottom-up pass over reachable edges of the reduced OBDD. 2. **Read-only `Bools::implies()`:** checks entailment directly without allocating temporary BDD nodes or evicting memo entries. 3. **Per-block reuse in `finish()`:** computes `forced(cond[n])` once per block and reuses it across guards and exits. 4. **FxHash in `meet_in()`:** switches the refuted set from default SipHash to the existing `Fx` hasher. ### Measured (`--release structure::tests::bench_bools`) | Workload | Before (`main`) | After | Speedup | |---|---:|---:|---:| | `given()` (`n = 8`) | `20.43 µs` | `0.22 µs` | **93×** | | `given()` (`n = 13`) | `655.25 µs` | `0.54 µs` | **1,213×** | ### Not a duplicate of - Checked open PRs including #2627 (which fixes `Structured::active` reachability rather than `Bools::given`/`implies`/`forced`/`meet_in`). No open PR or #1633 claim overlaps `Bools` BDD evaluation. ### Verification - Verified on `windows-latest` MSVC + WARP SM 6.6 CI (both clippy `-D warnings` profiles, `xtask` policy 6/6, `victory-shader` 281/281 including equivalence tests comparing `forced()`/`implies()` against the previous BDD implementations): https://github.com/RVZO6/VIctory/actions/runs/45666985023 - **Not run:** the title; any hardware GPU. AI-assisted: T3 Code (Antigravity, gemini-4-neon)
Replace Bools::given()'s O(|b| * |vars(b)|) mutating implies loop with an O(|known|) read-only forced() sweep over reduced OBDD edges, make Bools::implies() read-only without allocating BDD nodes or evicting memo entries, reuse forced(cond[n]) across guards and exits per block in finish(), and switch meet_in()'s refuted set from SipHash to FxHash.

Measured on bench_bools (--release): given() drops from 20.43 us -> 0.22 us (93x) at n=8 and 655.25 us -> 0.54 us (1,213x) at n=13.

Assisted-by: T3 Code (Antigravity, gemini-4-neon)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:11:28 +00:00
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-25 17:54 UTC · original

Reviewed: the read-only implies/implies_in (local proved set, no memo or node allocation) is sound — BDD implication is decidable by simultaneous top-variable descent. overflow returning true preserves the conservative direction. FxHash swap in the hot BDD maps is a straight win. CI green.

**@⁠kotekompotek** on GitHub · 2026-11-25 17:54 UTC · [original](https://github.com/Marvisak/VIctory/pull/2662#issuecomment-7170176173) Reviewed: the read-only `implies`/`implies_in` (local `proved` set, no memo or node allocation) is sound — BDD implication is decidable by simultaneous top-variable descent. `overflow` returning true preserves the conservative direction. FxHash swap in the hot BDD maps is a straight win. CI green.
Author
Owner

@⁠oni-swr on GitHub · 2026-11-25 18:21 UTC · original

Independent verification of #2662 (BDD forced() sweep, read-only implies(), given_with)

PR head 95f56a53f8ff90f700d74d102ad79538bad68771, merges cleanly onto origin/main 13f91caee25f2fdf2c062be5f7a27f058e51cbca (git merge-tree).

Environment: Windows 11 Pro 10.0.26200, rustc 1.98.1, VICTORY_WARP=1 + VICTORY_D3D12_WARP=1 on every run (WARP adapter only, no physical GPU created), DXC/dxil 1.8.2502.11 (Windows SDK 10.0.26100.0, via VICTORY_DXIL), cargo ... -j 4 --locked.

Tests/clippy vs baseline. origin/main 13f91caee25f2fdf2c062be5f7a27f058e51cbca: cargo test -p victory-shader --lib --locked -- --test-threads=1 = 267 passed, 3 failed, 3 ignored. The 3 failures are WARP limits and are the same 3 in every variant below: a_mask_joined_with_data_at_a_uniform_loop_is_its_number and permutes_read_the_lane_named_and_zero_from_lanes_left_out ("no pipeline for a wave of 32"), and gathers_at_a_level_match_the_hardware (WARP gather result differs). Clippy: cargo clippy -p victory-shader --all-targets --locked = 0 warnings.
With #2662: 269 passed, 3 failed (same 3), 3 ignored (+2 new tests: forced_matches_implies_across_disjunctive_skips_and_random_bdds, read_only_implies_matches_and_not_without_allocating_nodes). Clippy: 0 warnings.

Equivalence. I read the full diff. forced() (variable v is forced iff no reachable non-FALSE edge skips v and every reachable node testing v takes one polarity) is correct for reduced OBDDs; the TERMINAL far-edge correctly stops forcing past an edge into TRUE. implies() returns true on overflow like the old ite-based form (which yielded FALSE on overflow). given_with(known = FALSE) follows hi edges, matching the old "every atom implied true". Output check: a throwaway, uncommitted patch hashed every container Shader::finish emits during the lib test run: 650 containers (476 distinct), byte-identical to origin/main.

Perf (release, bench_bools, synthetic BDDs). given at n=8/10/12/13 on base: 15 / 55 / 240 / 465 us (its own fast path); with the three shader PRs combined: 0.25 / 0.44 / 0.44 / 0.45 us. Small n (2, 4) unchanged within noise. Caveat: this isolates given; the benchmark's known is cheap to walk, and the effect on real shaders was not measured.

Findings: no bugs. Observation: since implies/forced no longer allocate BDD nodes, the MAX_NODES overflow (TOO_LARGE) should be hit less often than before; that can only turn a TOO_LARGE into a success, not the reverse. Not measured on real shaders.

Limits: no physical GPU (WARP only), no game files; the 3 WARP-limited tests above are therefore not verified on hardware. Benchmarks are synthetic, release mode, one machine, two back-to-back rounds each for base and combined; they say nothing about real-title shaders.

AI-assisted: independent verification by Claude Code / Claude Sonnet 5.5, run on behalf of oni-swr. Claims for #1633.

**@⁠oni-swr** on GitHub · 2026-11-25 18:21 UTC · [original](https://github.com/Marvisak/VIctory/pull/2662#issuecomment-7170804388) **Independent verification of #2662** (BDD `forced()` sweep, read-only `implies()`, `given_with`) PR head `95f56a53f8ff90f700d74d102ad79538bad68771`, merges cleanly onto `origin/main` `13f91caee25f2fdf2c062be5f7a27f058e51cbca` (`git merge-tree`). **Environment:** Windows 11 Pro 10.0.26200, rustc 1.98.1, `VICTORY_WARP=1` + `VICTORY_D3D12_WARP=1` on every run (WARP adapter only, no physical GPU created), DXC/dxil 1.8.2502.11 (Windows SDK 10.0.26100.0, via `VICTORY_DXIL`), `cargo ... -j 4 --locked`. **Tests/clippy vs baseline.** `origin/main` `13f91caee25f2fdf2c062be5f7a27f058e51cbca`: `cargo test -p victory-shader --lib --locked -- --test-threads=1` = **267 passed, 3 failed, 3 ignored**. The 3 failures are WARP limits and are the same 3 in every variant below: `a_mask_joined_with_data_at_a_uniform_loop_is_its_number` and `permutes_read_the_lane_named_and_zero_from_lanes_left_out` ("no pipeline for a wave of 32"), and `gathers_at_a_level_match_the_hardware` (WARP gather result differs). Clippy: `cargo clippy -p victory-shader --all-targets --locked` = 0 warnings. With #2662: **269 passed, 3 failed (same 3), 3 ignored** (+2 new tests: `forced_matches_implies_across_disjunctive_skips_and_random_bdds`, `read_only_implies_matches_and_not_without_allocating_nodes`). Clippy: 0 warnings. **Equivalence.** I read the full diff. `forced()` (variable v is forced iff no reachable non-FALSE edge skips v and every reachable node testing v takes one polarity) is correct for reduced OBDDs; the `TERMINAL` far-edge correctly stops forcing past an edge into TRUE. `implies()` returns true on overflow like the old `ite`-based form (which yielded FALSE on overflow). `given_with(known = FALSE)` follows `hi` edges, matching the old "every atom implied true". Output check: a throwaway, uncommitted patch hashed every container `Shader::finish` emits during the lib test run: **650 containers (476 distinct), byte-identical to `origin/main`**. **Perf (release, `bench_bools`, synthetic BDDs).** `given` at n=8/10/12/13 on base: 15 / 55 / 240 / 465 us (its own fast path); with the three shader PRs combined: 0.25 / 0.44 / 0.44 / 0.45 us. Small n (2, 4) unchanged within noise. Caveat: this isolates `given`; the benchmark's `known` is cheap to walk, and the effect on real shaders was not measured. **Findings:** no bugs. Observation: since `implies`/`forced` no longer allocate BDD nodes, the `MAX_NODES` overflow (`TOO_LARGE`) should be hit less often than before; that can only turn a `TOO_LARGE` into a success, not the reverse. Not measured on real shaders. **Limits:** no physical GPU (WARP only), no game files; the 3 WARP-limited tests above are therefore not verified on hardware. Benchmarks are synthetic, release mode, one machine, two back-to-back rounds each for base and combined; they say nothing about real-title shaders. AI-assisted: independent verification by Claude Code / Claude Sonnet 5.5, run on behalf of oni-swr. Claims for #1633.
Author
Owner

@⁠oni-swr on GitHub · 2026-11-25 18:23 UTC · original

Composition check: #2662 + #2664 + #2665 together

Heads: #2662 95f56a53f8ff90f700d74d102ad79538bad68771, #2664 e6ab345e7b73be37a0741a54767e061aad35239c, #2665 8105fdcfb68ac99d79ea728847a0f555b7a41521, merged in that order onto origin/main 13f91caee25f2fdf2c062be5f7a27f058e51cbca as a local merge commit (31ed3543e4c18b978f7b0a699a71f8d18e52a81b, not pushed). No conflicts: the three touch disjoint files (structure.rs; gfx10/fields.rs + ir.rs; emit/bitcode.rs + emit/shader.rs).

Environment: Windows 11 Pro 10.0.26200, rustc 1.98.1, VICTORY_WARP=1 + VICTORY_D3D12_WARP=1 (WARP only), dxil 1.8.2502.11 (SDK 10.0.26100.0), -j 4 --locked.

  • cargo test -p victory-shader --lib --locked -- --test-threads=1: 276 passed, 3 failed, 5 ignored. That is exactly baseline 267 + 2 + 4 + 3 new tests; the 3 failures are the same WARP-limited ones as on origin/main (wave-of-32 x2, WARP gather).
  • cargo clippy -p victory-shader --all-targets --locked: 0 warnings.
  • Emitted containers over the lib test run: 650 byte-identical to origin/main, plus one extra from #2665's new test (throwaway hashing patch, not committed).
  • Perf (release, combined vs base, 2 rounds each): shader::op 4096 calls 2.84-2.94 ms -> 0.53-0.56 ms; ir::build 2048 insts 2.24-2.29 ms -> 1.80-1.84 ms; 64 movrel insts 426-456 us -> 88-103 us; bitcode writer, 256x512 synthetic module, 8.9-9.8 ms -> 7.0-7.1 ms; BDD given n=13 ~465 us -> ~0.45 us (synthetic).
  • No interaction bugs found. The merge order does not matter (disjoint files).

Limits: no physical GPU, no game files; synthetic benchmarks only.

AI-assisted: independent verification by Claude Code / Claude Sonnet 5.5, run on behalf of oni-swr. Claims for #1633.

**@⁠oni-swr** on GitHub · 2026-11-25 18:23 UTC · [original](https://github.com/Marvisak/VIctory/pull/2662#issuecomment-7170833609) **Composition check: #2662 + #2664 + #2665 together** Heads: #2662 `95f56a53f8ff90f700d74d102ad79538bad68771`, #2664 `e6ab345e7b73be37a0741a54767e061aad35239c`, #2665 `8105fdcfb68ac99d79ea728847a0f555b7a41521`, merged in that order onto `origin/main` `13f91caee25f2fdf2c062be5f7a27f058e51cbca` as a local merge commit (`31ed3543e4c18b978f7b0a699a71f8d18e52a81b`, not pushed). No conflicts: the three touch disjoint files (`structure.rs`; `gfx10/fields.rs` + `ir.rs`; `emit/bitcode.rs` + `emit/shader.rs`). Environment: Windows 11 Pro 10.0.26200, rustc 1.98.1, `VICTORY_WARP=1` + `VICTORY_D3D12_WARP=1` (WARP only), dxil 1.8.2502.11 (SDK 10.0.26100.0), `-j 4 --locked`. - `cargo test -p victory-shader --lib --locked -- --test-threads=1`: **276 passed, 3 failed, 5 ignored**. That is exactly baseline 267 + 2 + 4 + 3 new tests; the 3 failures are the same WARP-limited ones as on `origin/main` (wave-of-32 x2, WARP gather). - `cargo clippy -p victory-shader --all-targets --locked`: 0 warnings. - Emitted containers over the lib test run: 650 byte-identical to `origin/main`, plus one extra from #2665's new test (throwaway hashing patch, not committed). - Perf (release, combined vs base, 2 rounds each): `shader::op` 4096 calls 2.84-2.94 ms -> 0.53-0.56 ms; `ir::build` 2048 insts 2.24-2.29 ms -> 1.80-1.84 ms; 64 `movrel` insts 426-456 us -> 88-103 us; bitcode writer, 256x512 synthetic module, 8.9-9.8 ms -> 7.0-7.1 ms; BDD `given` n=13 ~465 us -> ~0.45 us (synthetic). - No interaction bugs found. The merge order does not matter (disjoint files). Limits: no physical GPU, no game files; synthetic benchmarks only. AI-assisted: independent verification by Claude Code / Claude Sonnet 5.5, run on behalf of oni-swr. Claims for #1633.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-25 19:27 UTC · original

Independent Windows 11 + NVIDIA GeForce RTX 5090 + WARP + dxil.dll verification, code review, and same-machine --release benchmark comparison of 95f56a53 (on 13f91ca):

Verification (rustc 1.98.1 MSVC, Windows SDK 10.0.26100.0 dxil.dll)

  • cargo xtask policy: 184 files ok.
  • cargo clippy --locked -p victory-shader --all-targets -- -D warnings and --features host: 0 warnings.
  • victory-shader (structure, ir, gfx10, emit::tests, emit::lower, emit::waterfall_tests on RTX 5090 + WARP + dxil.dll, emit::bitcode with unchanged FNV-1a): 99 passed, 0 failed, 2 ignored.
  • Merge compatibility with #2664 & #2665: clean zero-conflict 3-way git merge-tree across all three PRs (disjoint compiler stages: frontend #2664, mid-end #2662, backend #2665).

Same-Machine --release Benchmark (structure::tests::bench_bools)

Case 13f91ca 95f56a53 Speedup
n=2, nodes=9 0.37 µs 0.12 µs 3.1x
n=4, nodes=45 1.05 µs 0.13 µs 8.1x
n=8, nodes=765 8.91 µs 0.14 µs 63.6x
n=10, nodes=3069 29.49 µs 0.24 µs 122.9x
n=12, nodes=12285 142.57 µs 0.25 µs 570.3x
n=13, nodes=24573 335.56 µs 0.26 µs 1,290.6x

Code Review Notes

  • Read-only implies_in (no Bools::nodes growth or memo churn), O(|known|) forced() sweep (TRUE/FALSE edge handling, TERMINAL = u32::MAX ordering, append-only given_with safety with cached_forced), and bounded FxHash refuted set in meet_in are strictly equivalent with zero unsafe. Clean and ready to merge.
**@⁠fuzeofficlal** on GitHub · 2026-11-25 19:27 UTC · [original](https://github.com/Marvisak/VIctory/pull/2662#issuecomment-7172324681) Independent Windows 11 + NVIDIA GeForce RTX 5090 + WARP + `dxil.dll` verification, code review, and same-machine `--release` benchmark comparison of `95f56a53` (on `13f91ca`): ### Verification (`rustc 1.98.1` MSVC, Windows SDK `10.0.26100.0` `dxil.dll`) - `cargo xtask policy`: **184 files ok**. - `cargo clippy --locked -p victory-shader --all-targets -- -D warnings` and `--features host`: **0 warnings**. - `victory-shader` (`structure`, `ir`, `gfx10`, `emit::tests`, `emit::lower`, `emit::waterfall_tests` on RTX 5090 + WARP + `dxil.dll`, `emit::bitcode` with unchanged FNV-1a): **99 passed, 0 failed, 2 ignored**. - **Merge compatibility with #2664 & #2665:** clean zero-conflict 3-way `git merge-tree` across all three PRs (disjoint compiler stages: frontend `#2664`, mid-end `#2662`, backend `#2665`). ### Same-Machine `--release` Benchmark (`structure::tests::bench_bools`) | Case | `13f91ca` | `95f56a53` | Speedup | | --- | --- | --- | --- | | `n=2, nodes=9` | `0.37 µs` | `0.12 µs` | **3.1x** | | `n=4, nodes=45` | `1.05 µs` | `0.13 µs` | **8.1x** | | `n=8, nodes=765` | `8.91 µs` | `0.14 µs` | **63.6x** | | `n=10, nodes=3069` | `29.49 µs` | `0.24 µs` | **122.9x** | | `n=12, nodes=12285` | `142.57 µs` | `0.25 µs` | **570.3x** | | `n=13, nodes=24573` | `335.56 µs` | `0.26 µs` | **1,290.6x** | ### Code Review Notes - Read-only `implies_in` (no `Bools::nodes` growth or `memo` churn), `O(|known|)` `forced()` sweep (`TRUE`/`FALSE` edge handling, `TERMINAL = u32::MAX` ordering, append-only `given_with` safety with `cached_forced`), and bounded `FxHash` `refuted` set in `meet_in` are strictly equivalent with zero `unsafe`. Clean and ready to merge.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 22:21 UTC · original

Automated triage for the maintainers.

Merge candidate (performance, same output). In crates/victory-shader/src/structure.rs:

  • Bools::implies becomes a read-only simultaneous descent with no node allocation.
  • The new Bools::forced finds the variables known decides in one walk of known.
  • Lanes::finish computes that once per block and reuses it for guards and exits (given_with).
  • meet_in uses the existing Fx hasher.

I checked forced against the reduced-OBDD argument: a variable is forced only if no reachable non-FALSE edge skips it and all its nodes take one polarity, with an edge into TRUE skipping everything below it. Restricting by forced variables that b does not contain is a no-op, so the result equals the old per-variable loop. The known == FALSE path follows hi edges like before, and the memo in implies_in is sound because a false result short-circuits the whole walk. The new tests compare forced/implies with the old formulations on random BDDs, and a tester reports byte-identical DXIL for all lib-test shaders. It merges cleanly; CI check: passing.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 22:21 UTC · [original](https://github.com/Marvisak/VIctory/pull/2662#issuecomment-7176268626) <!-- victory-triage v1 head=95f56a53f8ff90f700d74d102ad79538bad68771 verdict=merge-candidate at=2026-11-25T22:24:00Z --> Automated triage for the maintainers. **Merge candidate** (performance, same output). In `crates/victory-shader/src/structure.rs`: - `Bools::implies` becomes a read-only simultaneous descent with no node allocation. - The new `Bools::forced` finds the variables `known` decides in one walk of `known`. - `Lanes::finish` computes that once per block and reuses it for guards and exits (`given_with`). - `meet_in` uses the existing Fx hasher. I checked `forced` against the reduced-OBDD argument: a variable is forced only if no reachable non-FALSE edge skips it and all its nodes take one polarity, with an edge into TRUE skipping everything below it. Restricting by forced variables that `b` does not contain is a no-op, so the result equals the old per-variable loop. The `known == FALSE` path follows `hi` edges like before, and the memo in `implies_in` is sound because a `false` result short-circuits the whole walk. The new tests compare `forced`/`implies` with the old formulations on random BDDs, and a tester reports byte-identical DXIL for all lib-test shaders. It merges cleanly; CI `check`: passing. --- _Generated by [Claude Code](https://claude.ai/code)_
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2662/head:github-bot/gh-2662'
git switch 'github-bot/gh-2662'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2662'
git switch 'github-bot/gh-2662'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2662'
git switch 'github-bot/gh-2662'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2662'
git switch 'main'
git merge --squash 'github-bot/gh-2662'
git switch 'main'
git merge --ff-only 'github-bot/gh-2662'
git switch 'main'
git merge 'github-bot/gh-2662'
git push origin 'main'
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!2662
No description provided.