Shaders: intersect compare bounds with existing range bounds in Ranges::edge_hi #2489
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2491"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from Marvisak/VIctory. Originally posted by reeledMarek on 2026-11-25T14:48:18Z.
Problem
In
crates/victory-shader/src/range.rs,Ranges::compare_bound()computes:When
otheris unbounded (h == u32::MAX) andbelowistrue(e.g.a < unknownor!(a >= unknown)),compare_bound()returnsSome(u32::MAX - 1)instead ofNone.In
Ranges::edge_hi(),bestthen becomesu32::MAX - 1 != u32::MAX, so the fallbackif best == u32::MAX { self.hi(a) } else { best }skipsself.hi(a)and discards any tighter upper bound already proven ona(for examples0 = s2 & 3), causing relative moves (v_movrel*) to lose their proven index bound and fall back to the full VGPR range.Fix
NonefromRanges::compare_bound()whenh == u32::MAX(unbounded compare operand).range::tests::compare_against_unbounded_operand_preserves_existing_boundcovering boths_cmp_lt_u32(taken edge) ands_cmp_ge_u32(not-taken edge).Verification
cargo test -p victory-shader --locked(145 passed, 0 failed)cargo test -p xtask --locked(repository_passes_policypassed)cargo clippy -p victory-shader --all-targets --locked --target x86_64-pc-windows-msvc -- -D warnings(0 warnings)Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-25T15:08:48Z.
Review: COMMENTED
Independent verification on Windows,
VICTORY_D3D12_WARP=1(WARP only, no hardware GPU touched). Tested commit98c0e07d45b914276940cacf216cdf8a2163ec15(clean detached checkout).cargo test -p victory-shader --locked --lib compare_against_unbounded— 1 passed, 0 failed, 0 ignored.h == u32::MAXearly return disabled, the test fails, so it guards the change.cargo test -p victory-shader --locked --lib— 248 passed, 0 failed, 3 ignored (the ignored ones are pre-existing).Code read: before this change, an unbounded operand (
u32::MAX) gaveSome(u32::MAX - 1)forlt/ge-false. That is aSome, so it bypassed the existingself.hi(a)bound inedge_hi. ReturningNonefalls back to the tighter bound. The only precision lost is age-false orltcompare against a literal0xFFFFFFFF, which gaveMAX-1before. That is conservative and not meaningful. The test covers both polarities (lt/scc1 andge/scc0). No problems found.AI-assisted (Claude Code / Claude Sonnet 5.5)
Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-25T15:41:45Z.
Independent local validation for PR #2491 (Windows, Rust 1.100.0/MSVC, head
98b0e07, no game data):cargo test --locked -p victory-shader --lib-> 249 passed, 0 failed, 3 ignored, exit 0;git diff --checkclean. CPU-only regression run; synthetic compare-range scenario not replayed. AI-assisted (Hy4 flash). GPU/driver N/A for CPU tests.Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T15:59:53Z.
Automated triage for the maintainers.
Merge candidate.
Ranges::edge_hi(crates/victory-shader/src/range.rs) now returnsbest.min(self.hi(a))instead of falling back toself.hi(a)only when no compare fact was found.self.hi(a)boundsaon every edge, so taking the minimum is always sound. A compare against an unbounded or looser operand can no longer hide a tighter bound already proven ona, andv_movrel*indexing keeps its narrow VGPR range. The new test checkss_cmp_lt_u32(taken edge) ands_cmp_ge_u32(not-taken edge) against both an unboundeds3ands3 = s4 & 255, withs0 = s2 & 3. I checked the instruction encodings by hand. The looser case would read far more than v8–v11 onmain.Reply to the author: this is the change the last triage asked for, including the bounded-but-looser test case. One small thing: the PR description still describes the earlier
compare_boundchange, so it's worth updating before merge.CI:
checkpassing.Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by reeledMarek on 2026-11-25T20:05:19Z.
Updated to address the triage feedback:
u32::MAXsentinel check inRanges::edge_hiwithbest.min(self.hi(a))and removed theh == u32::MAXspecial case incompare_bound, so both unbounded and bounded-but-looser compare operands preserve tighter existing bounds.s3and bounded-but-loosers3 = s4 & 255compared againsts0 = s2 & 3.[PR #2491] Shaders: do not let unbounded compare operands override tighter range boundsto [PR #2491] Shaders: intersect compare bounds with existing range bounds in Ranges::edge_hiImported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T18:42:38Z.
Review: APPROVED
Verified
b7d4f762918c358ae5043debc40e4f664a80317amerged ontomain(63bcca43) on Windows 11 x64:best.min(self.hi(a))inRanges::edge_hi(crates/victory-shader/src/range.rs:212) soundly intersects existing upper bounds with proven unsigned compare facts across all predicates (lt/le/gt/ge/eq), operand orders, and saturating arithmetic, without letting looser or unbounded compare operands mask tighter bounds.rustfmt --edition 2024 --check crates/victory-shader/src/range.rs: clean (exit 0).cargo test -p xtask --locked policy::tests::repository_passes_policy:1 passed(asset policy: 191 files ok).cargo clippy --locked -p victory-shader --all-targets -- -D warnings: clean.cargo test --locked -p victory-shader --lib range:::4 passed, 0 failed(compare_against_looser_or_unbounded_operand_preserves_existing_boundpasses).Minor doc note: worth updating the PR description to match the
edge_hibest.min(self.hi(a))change. Ready to merge.Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T19:51:58Z.
Review: APPROVED
LGTM — verified on Windows against
origin/main(63bcca4).hibounds inRanges::edge_hipreserves tighter outer bounds when nested comparisons yield a looser bound.cargo test -p victory-shader --lib range:: -- --test-threads=1: all passed.cargo clippy -p victory-shader --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.