Shaders: a deep block's reach no longer hides a waterfall's proof #1549

Closed
EduAzevedo wants to merge 1 commit from upstream-pr/1550 into main
EduAzevedo commented 2026-11-24 19:03:41 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by EduAzevedo on 2026-11-24T19:03:41Z.


Title: Shaders: a deep block's reach no longer hides a waterfall's proof

What

15 programs (12 mesh, 3 vertex) were refused with "a waterfall loop whose compares do not select the access's lanes", although their loops are the plain LLVM waterfall:

  • two v_cmp_eq_u64 (the first in the VOPC form, into VCC);
  • s_and_b64 and s_and_saveexec_b64;
  • the access, then s_xor_b64 exec and s_cbranch_execnz.

Moving those loops into the unit tests (a sampler compared per lane, the image loaded inside the loop, VCC, inside a divergent if, as Vs, Ps and Cs) doesn't reproduce the refusal: they all prove.

The cause is in Bools::meet (crates/victory-shader/src/structure.rs). It answers yes when its search exceeds MAX_MEET case splits. In these programs the loop sits deep, around block 145, so its reach is large. A local census in waterfall() showed the solver's answers:

  • without reach, meet(&[(selected, true), (matched, false)]) is false: the proof holds;
  • with reach, it is true: the search gave up.

Adding a condition can only lower what meets, so that yes is the budget running out, not a lane.

Fix

Bools::meet_beside(aside, others) asks meet(others) first. A no from meet is exact, and fewer conditions are met at least as often, so a no there settles it. Only when the others can meet does it ask again with aside. waterfall() uses it with the block's reach as aside. No other caller changes.

Tests

  • New structure::tests::a_large_condition_aside_does_not_hide_that_the_others_never_meet. It builds a condition the search gives up on (the parity of 20 atoms) and checks:
    • plain meet answers yes;
    • meet_beside answers no for conditions that never meet;
    • meet_beside still answers yes for conditions that do.
  • cargo test -p victory-shader: 121 passed, 1 ignored (as on main).
  • cargo clippy -p victory-shader --all-targets: clean.

Measured

victory translate --jobs 8 --list, offline, on my own retail dump (26,148 programs), main ffe310e vs this branch:

main this branch
refused programs 4,003 4,003
"a waterfall loop whose compares do not select the access's lanes" 15 0
no longer refused / newly refused 0 / 0
reason changed 15 (12 Ms, 3 Vs)

All 15 now pass resource tracking and stop at "a scalar memory read as data" (the #979 area), so DXIL emitted counts don't move on main alone.

With #979. I cherry-picked Machad3x's bc2b1b5 on main, with and without this branch:

#979 only #979 + this branch
VS/PS emitted 12,321 12,323 (+2)
mesh emitted 8,380 8,386 (+6)
refused programs 3,749 3,741
newly refused 0
  • 8 of the 15 are emitted.
  • The other 7 stop at "a descriptor read only as data" (the #180 / #329 area).

No shader names, disassembly or game data are included here, only counts.

AI-assisted. The measurement is offline, so no GPU was needed. Built and tested on Windows 11 (Ryzen 7 5700G, RTX 2070 SUPER, driver 610.88).

<!-- greyfinch-sync:Marvisak/VIctory:issue:6589267916 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1550). Originally posted by [EduAzevedo](https://github.com/EduAzevedo) on 2026-11-24T19:03:41Z. --- **Title:** Shaders: a deep block's reach no longer hides a waterfall's proof ## What 15 programs (12 mesh, 3 vertex) were refused with "a waterfall loop whose compares do not select the access's lanes", although their loops are the plain LLVM waterfall: - two `v_cmp_eq_u64` (the first in the VOPC form, into VCC); - `s_and_b64` and `s_and_saveexec_b64`; - the access, then `s_xor_b64 exec` and `s_cbranch_execnz`. Moving those loops into the unit tests (a sampler compared per lane, the image loaded inside the loop, VCC, inside a divergent `if`, as Vs, Ps and Cs) doesn't reproduce the refusal: they all prove. The cause is in `Bools::meet` (`crates/victory-shader/src/structure.rs`). It answers **yes** when its search exceeds `MAX_MEET` case splits. In these programs the loop sits deep, around block 145, so its `reach` is large. A local census in `waterfall()` showed the solver's answers: - without `reach`, `meet(&[(selected, true), (matched, false)])` is **false**: the proof holds; - with `reach`, it is **true**: the search gave up. Adding a condition can only lower what meets, so that yes is the budget running out, not a lane. ## Fix `Bools::meet_beside(aside, others)` asks `meet(others)` first. A no from `meet` is exact, and fewer conditions are met at least as often, so a no there settles it. Only when the others can meet does it ask again with `aside`. `waterfall()` uses it with the block's reach as `aside`. No other caller changes. ## Tests - New `structure::tests::a_large_condition_aside_does_not_hide_that_the_others_never_meet`. It builds a condition the search gives up on (the parity of 20 atoms) and checks: - plain `meet` answers yes; - `meet_beside` answers no for conditions that never meet; - `meet_beside` still answers yes for conditions that do. - `cargo test -p victory-shader`: 121 passed, 1 ignored (as on main). - `cargo clippy -p victory-shader --all-targets`: clean. ## Measured `victory translate --jobs 8 --list`, offline, on my own retail dump (26,148 programs), main `ffe310e` vs this branch: | | main | this branch | |---|---|---| | refused programs | 4,003 | 4,003 | | "a waterfall loop whose compares do not select the access's lanes" | 15 | 0 | | no longer refused / newly refused | | 0 / 0 | | reason changed | | 15 (12 Ms, 3 Vs) | All 15 now pass resource tracking and stop at "a scalar memory read as data" (the #979 area), so DXIL emitted counts don't move on main alone. **With #979.** I cherry-picked Machad3x's `bc2b1b5` on main, with and without this branch: | | #979 only | #979 + this branch | |---|---|---| | VS/PS emitted | 12,321 | 12,323 (+2) | | mesh emitted | 8,380 | 8,386 (+6) | | refused programs | 3,749 | 3,741 | | newly refused | | 0 | - 8 of the 15 are emitted. - The other 7 stop at "a descriptor read only as data" (the #180 / #329 area). No shader names, disassembly or game data are included here, only counts. AI-assisted. The measurement is offline, so no GPU was needed. Built and tested on Windows 11 (Ryzen 7 5700G, RTX 2070 SUPER, driver 610.88).
copilot-pull-request-reviewer[bot commented 2026-11-24 20:02:32 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-24T19:03:49Z.

Review: COMMENTED


Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

<!-- greyfinch-sync:Marvisak/VIctory:review:6045543699 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1550#pullrequestreview-6045543699). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/copilot-pull-request-reviewer%5Bbot%5D) on 2026-11-24T19:03:49Z. **Review:** COMMENTED --- Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
catminou4 commented 2026-11-24 20:02:32 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T19:20:52Z.

Review: APPROVED


Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (ffe310e), cargo test -p victory-shader --locked → 97. Execution/valu tests are #[cfg(all(test, windows))] and were not run here.

Bools::meet_beside asks the cheap question first: if the conditions without the block-reach aside already meet in no lane, the answer is exactly false — so a huge reach condition can no longer make the budget run out and return a wrong yes (same failure shape as #1491, which this complements). Conditions that do meet still go through the full meet. The structure test reproduces the give-up case on macOS (97 passed, +1).

<!-- greyfinch-sync:Marvisak/VIctory:review:6045810218 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1550#pullrequestreview-6045810218). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T19:20:52Z. **Review:** APPROVED --- Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (ffe310e), `cargo test -p victory-shader --locked` → 97. Execution/valu tests are `#[cfg(all(test, windows))]` and were not run here. `Bools::meet_beside` asks the cheap question first: if the conditions *without* the block-reach aside already meet in no lane, the answer is exactly false — so a huge reach condition can no longer make the budget run out and return a wrong yes (same failure shape as #1491, which this complements). Conditions that do meet still go through the full `meet`. The structure test reproduces the give-up case on macOS (97 passed, +1).
sinan-cmyk commented 2026-11-24 20:03:12 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-24T19:33:43Z.


Offline measurement on a retail dump, and the shader tests on Ada

Result: no count changes against main, and the tests pass on Ada.

Offline. I merged head 6c9e0ec onto main ffe310e (clean merge) and ran victory translate --validate --list on shaders.rpf (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with main program by program (25,889 programs). Validated: 21,724 on both, 0 gained, 0 lost. 15 programs that already fail move from "resources: a waterfall loop whose compares do not select the access's lanes" to "emit: a scalar memory read as data". So this PR gets them through resource tracking, and they now stop at the later scalar-read gap that #953, #1103 and #1319 address.

This is the expected result for a correctness fix whose instructions sit behind the earlier failures on main. The count shows that the change rejects nothing. It does not show whether the output is right.

Tests. With the same merge, cargo test --locked -p victory-shader --lib passed 121, failed 0. The bitcode benchmark is ignored, as on main, where 120 pass. The run was on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, with VICTORY_WARP unset.

No shader names or data are included, per the asset policy. AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7142273774 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1550#issuecomment-7142273774). Originally posted by [sinan-cmyk](https://github.com/sinan-cmyk) on 2026-11-24T19:33:43Z. --- ### Offline measurement on a retail dump, and the shader tests on Ada **Result: no count changes against `main`, and the tests pass on Ada.** **Offline.** I merged head 6c9e0ec onto `main` ffe310e (clean merge) and ran `victory translate --validate --list` on `shaders.rpf` (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with `main` program by program (25,889 programs). Validated: 21,724 on both, 0 gained, 0 lost. 15 programs that already fail move from "resources: a waterfall loop whose compares do not select the access's lanes" to "emit: a scalar memory read as data". So this PR gets them through resource tracking, and they now stop at the later scalar-read gap that #953, #1103 and #1319 address. This is the expected result for a correctness fix whose instructions sit behind the earlier failures on `main`. The count shows that the change rejects nothing. It does not show whether the output is right. **Tests.** With the same merge, `cargo test --locked -p victory-shader --lib` passed 121, failed 0. The bitcode benchmark is ignored, as on `main`, where 120 pass. The run was on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, with `VICTORY_WARP` unset. No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
upstream-sync closed this pull request 2026-11-25 01:06:49 +00:00
Marvisak commented 2026-11-25 01:08:15 +00:00 (Migrated from github.com)

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


Automated triage for the maintainers. Closing because this change is already in main, or main has since replaced the code it patches.

Waterfall proofs hidden by a deep block's reach exhausting Bools::meet: main fixed this in resource.rs meet (small conditions first) and the refuted memo; that refusal class is 0.

If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148790067 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1550#issuecomment-7148790067). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:42:20Z. --- Automated triage for the maintainers. Closing because this change is already in `main`, or `main` has since replaced the code it patches. Waterfall proofs hidden by a deep block's reach exhausting `Bools::meet`: main fixed this in resource.rs `meet` (small conditions first) and the refuted memo; that refusal class is 0. If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

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