Shaders: intersect compare bounds with existing range bounds in Ranges::edge_hi #2491
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!2491
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@reeledMarek on GitHub · 2026-11-25 14:48 UTC · original
reeledMarek:fix/shader-range-unbounded-compare→main· +42 −1 · 1 files · 1 commits · openProblem
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)@cloph-dsp on GitHub · 2026-11-25 15:41 UTC · original
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.@Marvisak on GitHub · 2026-11-25 15:59 UTC · original · edited 2026-11-25 20:21 UTC
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
@reeledMarek on GitHub · 2026-11-25 20:05 UTC · original
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.@oni-swr on GitHub · 2026-11-25 15:08 UTC · original · reviewed
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)
@fuzeofficlal on GitHub · 2026-11-26 18:42 UTC · original · approved these changes
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.@Dukestar69 on GitHub · 2026-11-26 19:51 UTC · original · approved these changes
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.