Shaders: BDD meet rejects a node held both ways and takes one condition as met #2480

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

@⁠liandraraiane on GitHub · 2026-11-25 14:30 UTC · original
liandraraiane:perf/bdd-meet-benchmark → main · +100 −3 · 1 files · 1 commits · open

Bools::meet (crates/victory-shader/src/structure.rs) searches by splitting on variables until every condition is decided. Two cases now end that search early, at every level of it:

  • A node held both ways. Equal functions are equal nodes, so after the sort and dedup such a pair is adjacent and can never be met. Before, the search split the node's whole diagram, and past MAX_MEET it gave up and answered yes. The check also catches functions that only become the same node after a split.
  • One condition left. A node of a reduced diagram is no constant, so it is true in some lane and false in another. One condition alone is always met. The search used to walk down to a terminal to find that out.

The refuted set now uses the module's Fx hasher like the other tables. It was the only one still on SipHash.

The case main gets wrong

meet_rejects_opposite_facts_about_the_same_function now uses 15 pairs instead of 8. That runs main past MAX_MEET, so it fails on main (answers true) and passes here. Its second half covers two different nodes that become the same one only after a split.

Measurement

cargo test --release -p victory-shader bench_meet -- --ignored --nocapture --test-threads=1, synthetic diagrams, median of 3 runs. For "main", main's meet/meet_in was copied into this branch, so both columns run the same benchmark:

n case main this PR
8 one 0.35 µs 0.04 µs
8 four 0.73 µs 0.64 µs
8 eight 1.81 µs 1.13 µs
8 contradiction 114.71 µs 0.04 µs
10 one 0.44 µs 0.04 µs
10 four 0.45 µs 0.37 µs
10 eight 2.98 µs 1.79 µs
10 contradiction 458.84 µs 0.04 µs
12 one 0.52 µs 0.04 µs
12 four 0.46 µs 0.45 µs
12 eight 18.09 µs 9.45 µs
12 contradiction 1947.23 µs 0.04 µs

All runs gave the same answers on both sides.

bench_bools (same command, bench_bools; median of 3 runs, current implementation's column) measures vars and given, which this PR does not touch, so it is unchanged within noise:

n nodes vars main vars this PR given main given this PR
8 765 12.03 µs 11.59 µs 12.47 µs 11.93 µs
10 3,069 48.78 µs 47.53 µs 49.74 µs 48.04 µs
12 12,285 215.23 µs 208.05 µs 212.52 µs 207.75 µs
13 24,573 411.99 µs 405.30 µs 410.89 µs 406.78 µs

Do these cases reach meet in translation? I counted the search steps (calls of meet_in) over the crate's own lib tests, which lower synthetic shaders. The counters were temporary and are not in the diff. The meet_* tests themselves were skipped.

meet calls search steps
main 426 1,734
this PR 426 1,250 (−28 %)

Of those, 50 steps ended on a node held both ways, and 93 calls had a single condition.

Correctness

  • A temporary differential test (not in the diff) built 400 random diagrams of 4 to 10 atoms, including pairs that only meet after a split. It asked 24,000 random 1–4-condition queries and compared meet against brute force over every assignment: all equal.
  • cargo test -p victory-shader: 174 passed, 3 ignored (lib), plus resource_tracking 3 passed, 1 ignored.
  • cargo xtask policy: 190 files ok.

Not tested

  • Real title shaders: I have none, so the gain on a whole translation is not measured, only the synthetic tests above.
  • Windows and GPU: everything ran on Linux (Ubuntu 24.04, rustc 1.98.1). To build the crate's tests off Windows, the three validator blocks in emit/lower.rs were gated locally as in #2766; that change is not part of this PR. clippy -D warnings shows nothing in structure.rs; its other findings off Windows are already on main (emit/mod.rs, emit/lower.rs).

AI use

Claude Code (Claude Opus 5.5) wrote the change, the tests and the measurements, and drafted this description. A person reviewed it and opened the PR.

🤖 Generated with Claude Code

**@⁠liandraraiane** on GitHub · 2026-11-25 14:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/2480) `liandraraiane:perf/bdd-meet-benchmark` → `main` · +100 −3 · 1 files · 1 commits · open `Bools::meet` (`crates/victory-shader/src/structure.rs`) searches by splitting on variables until every condition is decided. Two cases now end that search early, at every level of it: - **A node held both ways.** Equal functions are equal nodes, so after the sort and dedup such a pair is adjacent and can never be met. Before, the search split the node's whole diagram, and past `MAX_MEET` it gave up and answered **yes**. The check also catches functions that only become the same node after a split. - **One condition left.** A node of a reduced diagram is no constant, so it is true in some lane and false in another. One condition alone is always met. The search used to walk down to a terminal to find that out. The `refuted` set now uses the module's Fx hasher like the other tables. It was the only one still on SipHash. ## The case `main` gets wrong `meet_rejects_opposite_facts_about_the_same_function` now uses 15 pairs instead of 8. That runs `main` past `MAX_MEET`, so it **fails on `main`** (answers `true`) and passes here. Its second half covers two different nodes that become the same one only after a split. ## Measurement `cargo test --release -p victory-shader bench_meet -- --ignored --nocapture --test-threads=1`, synthetic diagrams, median of 3 runs. For "main", `main`'s `meet`/`meet_in` was copied into this branch, so both columns run the same benchmark: | n | case | main | this PR | |---|---|---:|---:| | 8 | one | 0.35 µs | 0.04 µs | | 8 | four | 0.73 µs | 0.64 µs | | 8 | eight | 1.81 µs | 1.13 µs | | 8 | contradiction | 114.71 µs | 0.04 µs | | 10 | one | 0.44 µs | 0.04 µs | | 10 | four | 0.45 µs | 0.37 µs | | 10 | eight | 2.98 µs | 1.79 µs | | 10 | contradiction | 458.84 µs | 0.04 µs | | 12 | one | 0.52 µs | 0.04 µs | | 12 | four | 0.46 µs | 0.45 µs | | 12 | eight | 18.09 µs | 9.45 µs | | 12 | contradiction | 1947.23 µs | 0.04 µs | All runs gave the same answers on both sides. `bench_bools` (same command, `bench_bools`; median of 3 runs, current implementation's column) measures `vars` and `given`, which this PR does not touch, so it is unchanged within noise: | n | nodes | `vars` main | `vars` this PR | `given` main | `given` this PR | |---|---:|---:|---:|---:|---:| | 8 | 765 | 12.03 µs | 11.59 µs | 12.47 µs | 11.93 µs | | 10 | 3,069 | 48.78 µs | 47.53 µs | 49.74 µs | 48.04 µs | | 12 | 12,285 | 215.23 µs | 208.05 µs | 212.52 µs | 207.75 µs | | 13 | 24,573 | 411.99 µs | 405.30 µs | 410.89 µs | 406.78 µs | **Do these cases reach `meet` in translation?** I counted the search steps (calls of `meet_in`) over the crate's own lib tests, which lower synthetic shaders. The counters were temporary and are not in the diff. The `meet_*` tests themselves were skipped. | | `meet` calls | search steps | |---|---:|---:| | main | 426 | 1,734 | | this PR | 426 | 1,250 (−28 %) | Of those, 50 steps ended on a node held both ways, and 93 calls had a single condition. ## Correctness - A temporary differential test (not in the diff) built 400 random diagrams of 4 to 10 atoms, including pairs that only meet after a split. It asked 24,000 random 1–4-condition queries and compared `meet` against brute force over every assignment: all equal. - `cargo test -p victory-shader`: 174 passed, 3 ignored (lib), plus `resource_tracking` 3 passed, 1 ignored. - `cargo xtask policy`: 190 files ok. ## Not tested - Real title shaders: I have none, so the gain on a whole translation is not measured, only the synthetic tests above. - Windows and GPU: everything ran on Linux (Ubuntu 24.04, rustc 1.98.1). To build the crate's tests off Windows, the three validator blocks in `emit/lower.rs` were gated locally as in #2766; that change is not part of this PR. `clippy -D warnings` shows nothing in `structure.rs`; its other findings off Windows are already on `main` (`emit/mod.rs`, `emit/lower.rs`). ## AI use Claude Code (Claude Opus 5.5) wrote the change, the tests and the measurements, and drafted this description. A person reviewed it and opened the PR. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Bools::meet searched by splitting on variables until every condition was
decided. Two cases end that search early:

- A node held both ways (adjacent after the sort and dedup, since equal
  functions are equal nodes) is a contradiction. Before, the search split
  the node's whole diagram, and past MAX_MEET it gave up and answered that
  some lane meets both. The check runs at every split, so it also prunes
  functions that only become the same node after a split.
- One condition left, other than a constant, is met: a node of a reduced
  diagram is true in some lane and false in another.

The refuted set uses the module's Fx hasher, as the other tables do.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:07:03 +00:00
Author
Owner

@⁠liandraraiane on GitHub · 2026-11-25 14:39 UTC · original

Summary

  • Short-circuit Bools::meet_in when it finds contradictory facts about the same canonical BDD.
  • Add a regression test for opposite facts and an ignored benchmark for the contradiction case.

Validation

  • cargo test -p victory-shader — 145 passed, 3 ignored.
  • cargo clippy -p victory-shader --all-targets — passed.
  • git diff --check — passed.
  • cargo fmt --all -- --check reports formatting differences in existing workspace files.
**@⁠liandraraiane** on GitHub · 2026-11-25 14:39 UTC · [original](https://github.com/Marvisak/VIctory/pull/2480#issuecomment-7165610010) ## Summary - Short-circuit `Bools::meet_in` when it finds contradictory facts about the same canonical BDD. - Add a regression test for opposite facts and an ignored benchmark for the contradiction case. ## Validation - `cargo test -p victory-shader` — 145 passed, 3 ignored. - `cargo clippy -p victory-shader --all-targets` — passed. - `git diff --check` — passed. - `cargo fmt --all -- --check` reports formatting differences in existing workspace files.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 15:55 UTC · original · edited 2026-11-26 00:23 UTC

Automated triage for the maintainers.

Merge candidate. Re-reviewed at 7dec75e. Bools::meet_in (crates/victory-shader/src/structure.rs) now returns false when one node is held both ways and true when only one condition is left. Both rules are exact for this diagram. mk never builds a node with lo == hi and hash-conses through unique, so equal functions are equal ids and every non-constant node is satisfiable both ways. Under overflow the callers already fail. refuted moves to the module's Fx Set.

On your reply: both requests are answered. With 15 pairs, meet_rejects_opposite_facts_about_the_same_function runs main past MAX_MEET, so main answers true there and this branch answers false. The second case covers nodes that only become equal after a split. bench_meet numbers are in the description, and the search steps over the crate's lowering tests drop by 28 %. The gain on real title shaders is still unmeasured, but the change is small and sound, and it makes meet more precise. CI: check passing.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 15:55 UTC · [original](https://github.com/Marvisak/VIctory/pull/2480#issuecomment-7167428011) · edited 2026-11-26 00:23 UTC <!-- victory-triage v1 head=7dec75e31fd64105efb145bcb7306c72b1f6a648 verdict=merge-candidate at=2026-11-26T00:23:54Z --> Automated triage for the maintainers. **Merge candidate.** Re-reviewed at `7dec75e`. `Bools::meet_in` (`crates/victory-shader/src/structure.rs`) now returns `false` when one node is held both ways and `true` when only one condition is left. Both rules are exact for this diagram. `mk` never builds a node with `lo == hi` and hash-conses through `unique`, so equal functions are equal ids and every non-constant node is satisfiable both ways. Under `overflow` the callers already fail. `refuted` moves to the module's Fx `Set`. On your reply: both requests are answered. With 15 pairs, `meet_rejects_opposite_facts_about_the_same_function` runs `main` past `MAX_MEET`, so `main` answers `true` there and this branch answers `false`. The second case covers nodes that only become equal after a split. `bench_meet` numbers are in the description, and the search steps over the crate's lowering tests drop by 28 %. The gain on real title shaders is still unmeasured, but the change is small and sound, and it makes `meet` more precise. CI: `check` passing. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

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

Thanks for the review. Updated to 7dec75e. Point by point:

  • Test that main fails. meet_rejects_opposite_facts_about_the_same_function now uses 15 pairs, which runs main past MAX_MEET, so main answers true and the test fails there; it passes here. A second case covers two different nodes that become the same one only after a split (on main that answers true as well).
  • Numbers. bench_meet and bench_bools before/after are in the description (median of 3). Contradictions drop from 115 / 459 / 1,947 µs to 0.04 µs (n = 8 / 10 / 12). bench_bools is unchanged within noise, as expected: it measures vars and given, which this PR does not touch.
  • Do contradictions reach meet in translation? I have no title shaders, so I could not measure a real translation. Over the crate's own lib tests, which lower synthetic shaders, 50 of main's 1,734 search steps ended on a node held both ways. The PR also adds a second early exit (one non-constant condition left is always met) and moves refuted to the Fx hasher. Together they bring those 426 meet calls from 1,734 to 1,250 search steps (−28 %), with the same answers. A differential test against brute force (24,000 random queries, not in the diff) agreed on every one.

If a count on real shaders is needed before this can go in, I would welcome a run from someone who has the title files.

AI-assisted (Claude Code, Claude Opus 5.5).

**@⁠liandraraiane** on GitHub · 2026-11-25 22:25 UTC · [original](https://github.com/Marvisak/VIctory/pull/2480#issuecomment-7176348202) Thanks for the review. Updated to `7dec75e`. Point by point: - **Test that `main` fails.** `meet_rejects_opposite_facts_about_the_same_function` now uses 15 pairs, which runs `main` past `MAX_MEET`, so `main` answers `true` and the test fails there; it passes here. A second case covers two different nodes that become the same one only after a split (on `main` that answers `true` as well). - **Numbers.** `bench_meet` and `bench_bools` before/after are in the description (median of 3). Contradictions drop from 115 / 459 / 1,947 µs to 0.04 µs (n = 8 / 10 / 12). `bench_bools` is unchanged within noise, as expected: it measures `vars` and `given`, which this PR does not touch. - **Do contradictions reach `meet` in translation?** I have no title shaders, so I could not measure a real translation. Over the crate's own lib tests, which lower synthetic shaders, 50 of `main`'s 1,734 search steps ended on a node held both ways. The PR also adds a second early exit (one non-constant condition left is always met) and moves `refuted` to the Fx hasher. Together they bring those 426 `meet` calls from 1,734 to 1,250 search steps (−28 %), with the same answers. A differential test against brute force (24,000 random queries, not in the diff) agreed on every one. If a count on real shaders is needed before this can go in, I would welcome a run from someone who has the title files. AI-assisted (Claude Code, Claude Opus 5.5).
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 00:46 UTC · original

Code review and RTX 5090 + WARP + DXIL verification at head 7dec75e31fd6 merged cleanly onto main (63bcca43c6a0):

  • Code review (crates/victory-shader/src/structure.rs:295-342):
    • After filtering constant contradictions (fails) and tautologies and sorting/deduping, all.windows(2).any(|pair| pair[0].0 == pair[1].0) catches opposite polarity (b, false) / (b, true) in O(n log n) before expanding into MAX_MEET budget exhaustion.
    • if all.len() <= 1 { return true; } holds strictly under the ROBDD reduction invariant (Bools::mk eliminates lo == hi and overflow returns constant Bool::FALSE, already filtered out), so any single non-constant node is satisfiable for both polarities.
    • Memoizing refuted normalized Vec<(Bool, bool)> keys only when !met guarantees budget-exhaustion optimistic true returns never poison refuted.
  • Verified (Windows 11, NVIDIA RTX 5090 + WARP, dxil.dll 10.0.26100.0, Rust 1.98.1):
    • cargo xtask policy: 191 files ok; cargo clippy --locked -p victory-shader --tests -- -D warnings: 0 warnings
    • structure::: 15/15 passed (2 ignored benchmarks), including meet_rejects_opposite_facts_about_the_same_function and meet_takes_one_condition_as_met
    • flow_tests (1/1) and --test resource_tracking (3/3, 1 ignored): passed on both RTX 5090 and WARP.

Sound and clean; LGTM.

**@⁠fuzeofficlal** on GitHub · 2026-11-26 00:46 UTC · [original](https://github.com/Marvisak/VIctory/pull/2480#issuecomment-7179101018) Code review and RTX 5090 + WARP + DXIL verification at head `7dec75e31fd6` merged cleanly onto `main` (`63bcca43c6a0`): - **Code review (`crates/victory-shader/src/structure.rs:295-342`)**: - After filtering constant contradictions (`fails`) and tautologies and sorting/deduping, `all.windows(2).any(|pair| pair[0].0 == pair[1].0)` catches opposite polarity `(b, false)` / `(b, true)` in `O(n log n)` before expanding into `MAX_MEET` budget exhaustion. - `if all.len() <= 1 { return true; }` holds strictly under the ROBDD reduction invariant (`Bools::mk` eliminates `lo == hi` and `overflow` returns constant `Bool::FALSE`, already filtered out), so any single non-constant node is satisfiable for both polarities. - Memoizing refuted normalized `Vec<(Bool, bool)>` keys only when `!met` guarantees budget-exhaustion optimistic `true` returns never poison `refuted`. - **Verified (Windows 11, NVIDIA RTX 5090 + WARP, `dxil.dll` 10.0.26100.0, Rust 1.98.1)**: - `cargo xtask policy`: `191 files ok`; `cargo clippy --locked -p victory-shader --tests -- -D warnings`: 0 warnings - `structure::`: **15/15 passed** (2 ignored benchmarks), including `meet_rejects_opposite_facts_about_the_same_function` and `meet_takes_one_condition_as_met` - `flow_tests` (1/1) and `--test resource_tracking` (3/3, 1 ignored): passed on both RTX 5090 and WARP. Sound and clean; LGTM.
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/2480/head:github-bot/gh-2480'
git switch 'github-bot/gh-2480'

Merge

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