Repository navigation
Shaders: fold always-false and always-true compares to boolean constants - #1326
fuzeofficlal wants to merge 1 commit into
Conversation
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.
|
Tested this on a GPU with SM 6.6 support (RTX 4070 SUPER, driver 621.14, Windows 11, repo toolchain), merged into current
I didn't test with game data. Tested locally with an AI-assisted script (Claude Code); I checked the results before posting. |
|
Extra evidence for this one: on With this PR ( Found with a cross-device VALU fuzzer (each lowered VOP3 opcode as a one-thread shader on every adapter and WARP). |
catminou4
left a comment
There was a problem hiding this comment.
Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (ffe310e), cargo test -p victory-shader --locked → 96 passed, 0 failed. Execution/valu tests are #[cfg(all(test, windows))] and only run on Windows; macOS covers lowering/structure/IR unit tests.
Folds always-false/always-true float compares (v_cmp_f/v_cmp_tru) directly to boolean constants instead of emitting fcmp false/true — the comment documents that WARP suspends its device on those, so this is a real portability fix. pred::FALSE/TRUE marked allow(dead_code) with the reason.
|
Reviewed at head 1. This is a correctness fix first, an optimization second — both hold. 2. Hardware evidence on this machine. The new 3. Checks: clippy 4. Relation to #1646 (emit-time constant folding), no conflict: #1646 folds Nothing found that would block this. |
|
Automated triage for the maintainers. Closing because this change is already in 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. |
Fixes #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.