Shaders: fold always-false and always-true compares to boolean constants #1326
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!1326
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1326/head"
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?
@fuzeofficlal on GitHub · 2026-11-24 17:28 UTC · original
fuzeofficlal:fix/shader-float-cmp-false-true-832→main· +79 −2 · 3 files · 1 commits · closed without mergingFixes #832.
Summary
v_cmp_{f,tru}_{f32,f16},v_cmpx_{f,tru}_{f32,f16}, and 64-bit integerv_cmp_{f,t}_{u64,i64}/v_cmpx_{f,t}_{u64,i64}directly to constant lane booleans (self.lane(inst, Some(...))) instead of emitting LLVMfcmp false/fcmp true.The GPU device instance has been suspended) on the first dispatch of a pipeline containingfcmp falseorfcmp true, while matching RDNA2 behavior across finite values,±0.0,±inf,qNaN, andsNaN.Verification
valu_tests::float_compares_that_are_always_false_or_truecovering all 8v_cmp_{f,tru}_{f32,f16}andv_cmpx_{f,tru}_{f32,f16}instructions across normal, signed-zero, infinity, quiet-NaN, and signaling-NaN inputs:dxil.dllvalidation: passed0device suspensions)cargo test -p victory-shader,cargo clippy --workspace --all-targets --all-features, andcargo xtask policy: passed.Lowering v_cmp_f_{f32,f16} and v_cmp_tru_{f32,f16} (plus v_cmpx_* forms) via LLVM fcmp false/true causes Microsoft D3D12 WARP to suspend and remove its device on the first dispatch. Fold constant float and 64-bit integer compares directly to boolean lane constants before reading operands, matching RDNA2 semantics across all inputs including qNaN and sNaN.@acetonahard-code on GitHub · 2026-11-24 19:19 UTC · original
Tested this on a GPU with SM 6.6 support (RTX 4070 SUPER, driver 621.14, Windows 11, repo toolchain), merged into current
main(ffe310e).cargo test -p victory-shadermainmain+ this PRmain,--all-featuresmain+ this PR,--all-features--nocapture, and no "no SM 6.6 ... device; skipped" lines were printed, so no GPU test skipped for lack of a device.cargo clippy --all-targets -- -D warnings, with and without--all-features: clean.cargo fmt --check: no new diffs from this PR (the ones it reports are already onmain).I didn't test with game data.
Tested locally with an AI-assisted script (Claude Code); I checked the results before posting.
@alexdeliu on GitHub · 2026-11-24 19:42 UTC · original
Extra evidence for this one: on
main@ffe310eb, the shader forv_cmp_f_f32,v_cmp_tru_f32(and the f16 pair) removes the WARP device, which is the device CI runs on. Lowered tofcmp false/fcmp true, the shader passesdxil.dllvalidation, and the first dispatch then returns "The GPU device instance has been suspended". D3D12 hands back that same removed device until every reference is released, so the GPU tests that come after it fail as well. Two AMD GPUs run it fine: an RX 9070 and a gfx1036 iGPU.With this PR (
75d919f3) merged ontoffe310eb, all 12 constant compares (f/t/tru, f16/f32/i32/u32 and so on) ran on the RX 9070, the iGPU and WARP, 16 inputs each. No device was lost and the three devices agree.Found with a cross-device VALU fuzzer (each lowered VOP3 opcode as a one-thread shader on every adapter and WARP).
@adamdotpy on GitHub · 2026-11-24 20:28 UTC · original
Reviewed at head
75d919f(worktree on the PR head, isolated target dir, Windows 11 / Rust 1.98.1). Findings, ranked:1. This is a correctness fix first, an optimization second — both hold.
v_cmp_f_*/v_cmp_tru_*(and the 64-bitf/tcompares) used to lower tofcmp false/fcmp true, which WARP suspends its device on. The PR lowers them directly to a boolean constant per lane viaself.lane(inst, Some(op == "tru" | "t"))in both the f32/f16 and u64/i64 arms (lower.rs:5333,:5365), so no constant-predicate fcmp is emitted at all;pred::FALSE/pred::TRUEbecome#[allow(dead_code)]. The EXEC-guardedv_cmpx_*path goes through the samelanewrite, so the narrowed-EXEC case is handled (the test's cmpx shader restores exec_lo around a guarded write).2. Hardware evidence on this machine. The new
float_compares_that_are_always_false_or_trueruns on the GPU throughrun_cases: f32 and f16f/truover +0/-0, ±1, ±inf, qNaN/sNaN inputs, plus the cmpx EXEC case — 1 passed / 0 failed (2 s, really dispatched). Fullcargo test -p victory-shader --lib121 passed / 0 failed / 1 ignored.3. Checks: clippy
--all-targets --all-features --locked -D warningsclean;cargo build --release -p victorybuilds; rustfmt on the three files shows only main's 3 pre-existinglower.rshunks (shifted +6).4. Relation to #1646 (emit-time constant folding), no conflict: #1646 folds
cmpwhen both operands are constants; this PR removes the always-false/true predicates before any cmp is emitted, whatever the operands. Complementary — after both, acmp FALSE/TRUEreaches the module only from paths neither covers.bitcode.rschanges here are just the two#[allow(dead_code)], so the merge is clean either order.Nothing found that would block this.
@Marvisak on GitHub · 2026-11-25 00:37 UTC · original
Automated triage for the maintainers. Closing because this change is already in
main, ormainhas since replaced the code it patches.Always-false/true compares as constants (WARP removes its device on fcmp false/true). The float forms are in main since today (lower.rs:6999, test constant_compares_run); the 64-bit v_cmp_{f,t} forms left over are the 4-line #1685.
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