Shaders: search lane conditions once and redo a lowering once #999

Closed
TG0000 wants to merge 1 commit from upstream-pr/999 into main
TG0000 commented 2026-11-24 14:48:19 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by TG0000 on 2026-11-24T14:48:19Z.


Summary

Translating the shaders the opening scene binds spent most of its time on answers it already had. Three changes, in structure.rs and emit/lower.rs only:

  1. Bools::meet remembers failed states. It split cases without remembering the ones that failed, up to 65,536 allocating steps per question; the waterfall proofs asking it were about 38% of all translation time.
  2. The diagrams' tables. The node table is an open table of node numbers and the result table a direct-mapped cache, instead of hash maps of three-word keys; an implication is decided without building nodes.
  3. Lowering restarts once. A phi reached by a value with no DXIL form restarted the whole lowering, one phi at a time. One pass now finds every such phi.

Measured (RX 6800, Ryzen 9 5900X, Windows 11)

main this PR
Title, cold VIctory caches: pipeline backlog on entering the world cleared (2 runs each) 36.8 / 36.9 s 14.4 / 12.8 s
Title: 1,000th pipeline made after world entry 28.4 / 28.1 s 11.1 / 11.4 s
The 2,061 shaders that scene binds, 8 threads (median of 3) 35.2 s 12.0 s
Whole corpus, 16 threads (one run each, other jobs running) 79.3 s 31.3 s

Runs alternated with the new build first, so driver-cache warming favoured main. Main's second title run was stopped early by a memory watchdog, after its backlog had cleared. No device removal in these runs. This helps a cold cache only: with a warm cache and in steady state, frame rate does not change.

Correctness

  • Of 25,889 distinct programs, none goes from translating to refused. 196 of the 22,081 that translate give different output: the old search gave up at its step cap and answered "yes", and now it finishes. All 536 changed results (those 196 and 340 refusal messages) match an independent exact check, conjoining the diagrams.
  • With the old search swapped back in, all 22,081 outputs are byte-identical to main.
  • Behaviour change: 340 already-refused shaders report a different reason.

Verification

Rust 1.98.1 MSVC, base ffe310e: cargo test --workspace --locked 344 passed, 0 failed; cargo clippy --workspace --all-targets --locked -- -D warnings clean with and without --all-features; policy passes.

Overlap

  • #947 replaces Bools::meet too, with forced-variable propagation and memoised failures. Only one of the two searches is needed, and the two conflict. Items 2 and 3 here do not depend on which one is taken; I am happy to rebase onto #947 and keep only those.
  • #288 caps the memo table this replaces, and conflicts textually.
  • #126 (ours), #617 and #660 merge cleanly; they edit structure.rs as well.

AI-assisted: written and measured by Claude Opus 5.5. No game data is in this PR.

🤖 Generated with Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:issue:5474438031 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/999). Originally posted by [TG0000](https://github.com/TG0000) on 2026-11-24T14:48:19Z. --- ## Summary Translating the shaders the opening scene binds spent most of its time on answers it already had. Three changes, in `structure.rs` and `emit/lower.rs` only: 1. **`Bools::meet` remembers failed states.** It split cases without remembering the ones that failed, up to 65,536 allocating steps per question; the waterfall proofs asking it were about 38% of all translation time. 2. **The diagrams' tables.** The node table is an open table of node numbers and the result table a direct-mapped cache, instead of hash maps of three-word keys; an implication is decided without building nodes. 3. **Lowering restarts once.** A phi reached by a value with no DXIL form restarted the whole lowering, one phi at a time. One pass now finds every such phi. ## Measured (RX 6800, Ryzen 9 5900X, Windows 11) | | main | this PR | |---|---|---| | Title, cold VIctory caches: pipeline backlog on entering the world cleared (2 runs each) | 36.8 / 36.9 s | 14.4 / 12.8 s | | Title: 1,000th pipeline made after world entry | 28.4 / 28.1 s | 11.1 / 11.4 s | | The 2,061 shaders that scene binds, 8 threads (median of 3) | 35.2 s | 12.0 s | | Whole corpus, 16 threads (one run each, other jobs running) | 79.3 s | 31.3 s | Runs alternated with the new build first, so driver-cache warming favoured main. Main's second title run was stopped early by a memory watchdog, after its backlog had cleared. No device removal in these runs. This helps a cold cache only: with a warm cache and in steady state, **frame rate does not change**. ## Correctness - Of 25,889 distinct programs, none goes from translating to refused. 196 of the 22,081 that translate give different output: the old search gave up at its step cap and answered "yes", and now it finishes. All 536 changed results (those 196 and 340 refusal messages) match an independent exact check, conjoining the diagrams. - With the old search swapped back in, all 22,081 outputs are byte-identical to main. - **Behaviour change:** 340 already-refused shaders report a different reason. ## Verification Rust 1.98.1 MSVC, base `ffe310e`: `cargo test --workspace --locked` 344 passed, 0 failed; `cargo clippy --workspace --all-targets --locked -- -D warnings` clean with and without `--all-features`; policy passes. ## Overlap - **#947** replaces `Bools::meet` too, with forced-variable propagation and memoised failures. Only one of the two searches is needed, and the two conflict. Items 2 and 3 here do not depend on which one is taken; I am happy to rebase onto #947 and keep only those. - #288 caps the memo table this replaces, and conflicts textually. - #126 (ours), #617 and #660 merge cleanly; they edit `structure.rs` as well. AI-assisted: written and measured by Claude Opus 5.5. No game data is in this PR. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
catminou4 commented 2026-11-24 15:41:44 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T15:41:44Z.

Review: APPROVED


The lane-condition engine rewrite is verified the right way: lane_conditions_agree_with_their_truth_tables checks ite/implies/meet against brute-force truth tables over 512 lanes with 9 atoms and 1500 random diagrams (plus a uniqueness check on nodes), and conditions_that_exclude_each_other... exercises the 2^40 case-split that the old meet_in budget could never finish — the state-dedup (failed set over sorted State) is what makes it tractable, and the test proves the semantics survive. The implies rewrite building no nodes is asserted explicitly (b.nodes.len() unchanged). The lower.rs side batches Stop::Retry phis so one redo pass collects all missing joins instead of one per pass — same fixpoint, fewer passes.

Verified locally: test-merge with main clean; cargo test -p victory-shader --locked (macOS arm64, rustc 1.98.1) → 98 passed / 0 failed / 1 ignored, including both new structure tests. Approving.

<!-- greyfinch-sync:Marvisak/VIctory:review:6042461349 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/999#pullrequestreview-6042461349). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T15:41:44Z. **Review:** APPROVED --- The lane-condition engine rewrite is verified the right way: `lane_conditions_agree_with_their_truth_tables` checks `ite`/`implies`/`meet` against brute-force truth tables over 512 lanes with 9 atoms and 1500 random diagrams (plus a uniqueness check on nodes), and `conditions_that_exclude_each_other...` exercises the 2^40 case-split that the old `meet_in` budget could never finish — the state-dedup (`failed` set over sorted `State`) is what makes it tractable, and the test proves the semantics survive. The `implies` rewrite building no nodes is asserted explicitly (`b.nodes.len()` unchanged). The lower.rs side batches `Stop::Retry` phis so one redo pass collects all missing joins instead of one per pass — same fixpoint, fewer passes. Verified locally: test-merge with main clean; `cargo test -p victory-shader --locked` (macOS arm64, rustc 1.98.1) → **98 passed / 0 failed / 1 ignored**, including both new structure tests. Approving.
Zipettte commented 2026-11-24 16:05:05 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Zipettte on 2026-11-24T15:12:57Z.


Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at 3ca9456: cargo test -p victory-shader passes, 122 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).

Tested with AI assistance (Claude).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7135648495 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/999#issuecomment-7135648495). Originally posted by [Zipettte](https://github.com/Zipettte) on 2026-11-24T15:12:57Z. --- Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at 3ca9456: `cargo test -p victory-shader` passes, 122 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed). _Tested with AI assistance (Claude)._
Marvisak commented 2026-11-25 01:07:59 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:31:45Z.


Automated triage for the maintainers.

Needs rebase. This PR does not merge cleanly into current main (ac2525d). Conflicting files: crates/victory-shader/src/emit/lower.rs, crates/victory-shader/src/structure.rs.

The content has not been reviewed yet; it will be once the branch is rebased onto main.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148600322 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/999#issuecomment-7148600322). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:31:45Z. --- <!-- victory-triage v1 head=3ca94561506c876ab3da38a32c936025a583c6f8 verdict=needs-rebase at=2026-11-25T00:13:20Z --> Automated triage for the maintainers. **Needs rebase.** This PR does not merge cleanly into current `main` (ac2525d). Conflicting files: `crates/victory-shader/src/emit/lower.rs`, `crates/victory-shader/src/structure.rs`. The content has not been reviewed yet; it will be once the branch is rebased onto `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
TG0000 commented 2026-11-28 01:14:31 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by TG0000 on 2026-11-28T01:14:31Z.


Closing: main now remembers refuted conditions in Bools::meet, which was the largest part of this change. The other two parts (the diagram tables and the single lowering restart) are not on main, but the branch conflicts in both files and would need rewriting and measuring again; I would rather open them fresh than leave this one stale. Thanks to @Zipettte for testing it. (AI-assisted comment.)

<!-- greyfinch-sync:Marvisak/VIctory:comment:7231524186 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/999#issuecomment-7231524186). Originally posted by [TG0000](https://github.com/TG0000) on 2026-11-28T01:14:31Z. --- Closing: `main` now remembers refuted conditions in `Bools::meet`, which was the largest part of this change. The other two parts (the diagram tables and the single lowering restart) are not on `main`, but the branch conflicts in both files and would need rewriting and measuring again; I would rather open them fresh than leave this one stale. Thanks to @Zipettte for testing it. (AI-assisted comment.)

Pull request closed

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!999
No description provided.