Shaders: v_cmp_f/v_cmp_tru on floats emit fcmp false/true, which removes the WARP device (fix on a fork) #832

Open
opened 2026-11-26 04:14:02 +00:00 by github-bot · 3 comments
Owner

@⁠Peppacodes on GitHub · 2026-11-24 11:49 UTC · original

What's wrong

The float compares that are always false or always true are lowered to LLVM's constant predicates. The four instructions are v_cmp_f_f32, v_cmp_tru_f32, v_cmp_f_f16 and v_cmp_tru_f16. In crates/victory-shader/src/emit/lower.rs, the compare lowering maps:

  • "f" to pred::FALSE, emitting fcmp false;
  • "tru" to pred::TRUE, emitting fcmp true.

DXC folds those predicates away, so drivers never see them from it. WARP removes its device at the first dispatch of a pipeline that contains one. The dispatch fails with "The GPU device instance has been suspended".

A removed device stays removed for the whole process, so every later pipeline and dispatch on WARP fails as well. The DXIL validator accepts the shader, and the hardware adapter runs it (RTX 5080, driver 616.92).

The integer forms v_cmp_f_* and v_cmp_t_* are already lowered as constants (self.lane(inst, Some(op == "t"))), and they run on both.

This may be one way WARP loses its device on real shaders. It could matter for #653, where WARP removes its device during world load, but I haven't checked whether the title's shaders contain these instructions.

Repro

v_cmp_f_f32_e64 s20, v1, v2, then v_cndmask_b32_e64 v0, 0, 1, s20, with any operands:

  • Hardware adapter: runs and gives 0.
  • WARP: device suspended.

v_cmp_tru_f32, v_cmp_f_f16 and v_cmp_tru_f16 behave the same, with 1 thread or many. v_cmp_f_i32, v_cmp_t_i32 and every other float compare run fine.

Fix

What changed:

  • Float f and tru are now constants, false and true, the same way the integer compares do it, before any operand is read. The RDNA2 ISA defines them as false and true whatever the operands, NaNs included.
  • pred::FALSE and pred::TRUE stay in the table, marked unused, with a note on why they aren't emitted.

Test

float_compares_that_are_always_false_or_true, in valu_tests.rs:

  • It runs the four instructions with ordinary and NaN operands, on the hardware adapter and WARP.
  • On main, WARP's dispatch fails: warp: dispatch failed: The GPU device instance has been suspended. With the fix it passes on both.

How it was found

I swept every 32-bit VALU instruction the translator lowers on the hardware adapter against WARP. Each ran on about 400 edge-case inputs, one per thread, and the results were compared bit for bit. 200 instructions ran. These four were the only ones that removed a device.

With the fix, all 62 compares run and agree on both. The other differences were small:

  • v_sin_f32 and v_sin_f16 on the tiniest inputs. For example, v_sin_f32(0x00800000) gives 0 on the RTX 5080 and 0x01c90fdb on WARP. Both are within D3D's tolerance for sin.
  • v_med3_f16(+0, −0, 1) gives +0 on the RTX 5080 and −0 on WARP. v_med3_f32 agreed on every case.
  • NaN payloads.

Results

On Windows 11 with Rust 1.98.1 and an RTX 5080 (driver 616.92), using the CI's own commands:

  • cargo test --workspace --locked: 343 passed, 0 failed, 6 ignored.
  • cargo clippy --workspace --all-targets --locked -- -D warnings, with and without --all-features: clean.
  • rustfmt --edition 2024 --check on the changed files: clean on our changes (lower.rs keeps the three diffs it already has on main, in its test module).
  • cargo xtask policy: 154 files ok.

PR creation is limited to collaborators right now, so this is an issue with the branch. I can open a PR when it reopens.

No game files used.

**@⁠Peppacodes** on GitHub · 2026-11-24 11:49 UTC · [original](https://github.com/Marvisak/VIctory/issues/832) ## What's wrong The float compares that are always false or always true are lowered to LLVM's constant predicates. The four instructions are `v_cmp_f_f32`, `v_cmp_tru_f32`, `v_cmp_f_f16` and `v_cmp_tru_f16`. In `crates/victory-shader/src/emit/lower.rs`, the compare lowering maps: - `"f"` to `pred::FALSE`, emitting `fcmp false`; - `"tru"` to `pred::TRUE`, emitting `fcmp true`. DXC folds those predicates away, so drivers never see them from it. **WARP removes its device at the first dispatch of a pipeline that contains one.** The dispatch fails with "The GPU device instance has been suspended". A removed device stays removed for the whole process, so every later pipeline and dispatch on WARP fails as well. The DXIL validator accepts the shader, and the hardware adapter runs it (RTX 5080, driver 616.92). The integer forms `v_cmp_f_*` and `v_cmp_t_*` are already lowered as constants (`self.lane(inst, Some(op == "t"))`), and they run on both. This may be one way WARP loses its device on real shaders. It could matter for #653, where WARP removes its device during world load, but I haven't checked whether the title's shaders contain these instructions. ## Repro `v_cmp_f_f32_e64 s20, v1, v2`, then `v_cndmask_b32_e64 v0, 0, 1, s20`, with any operands: - **Hardware adapter:** runs and gives 0. - **WARP:** device suspended. `v_cmp_tru_f32`, `v_cmp_f_f16` and `v_cmp_tru_f16` behave the same, with 1 thread or many. `v_cmp_f_i32`, `v_cmp_t_i32` and every other float compare run fine. ## Fix - **Branch:** https://github.com/Peppacodes/VIctory/tree/fix/fcmp-false-true - **Compare:** https://github.com/Marvisak/VIctory/compare/main...Peppacodes:VIctory:fix/fcmp-false-true - **Commit:** `e04929d`, on `main` (`ffe310e`), 0 commits behind it. Three files: `lower.rs`, `bitcode.rs` and `valu_tests.rs`. What changed: - Float `f` and `tru` are now constants, false and true, the same way the integer compares do it, before any operand is read. The RDNA2 ISA defines them as false and true whatever the operands, NaNs included. - `pred::FALSE` and `pred::TRUE` stay in the table, marked unused, with a note on why they aren't emitted. ## Test `float_compares_that_are_always_false_or_true`, in `valu_tests.rs`: - It runs the four instructions with ordinary and NaN operands, on the hardware adapter and WARP. - On `main`, WARP's dispatch fails: `warp: dispatch failed: The GPU device instance has been suspended`. With the fix it passes on both. ## How it was found I swept every 32-bit VALU instruction the translator lowers on the hardware adapter against WARP. Each ran on about 400 edge-case inputs, one per thread, and the results were compared bit for bit. 200 instructions ran. These four were the only ones that removed a device. With the fix, all 62 compares run and agree on both. The other differences were small: - `v_sin_f32` and `v_sin_f16` on the tiniest inputs. For example, `v_sin_f32(0x00800000)` gives 0 on the RTX 5080 and `0x01c90fdb` on WARP. Both are within D3D's tolerance for sin. - `v_med3_f16(+0, −0, 1)` gives +0 on the RTX 5080 and −0 on WARP. `v_med3_f32` agreed on every case. - NaN payloads. ## Results On Windows 11 with Rust 1.98.1 and an RTX 5080 (driver 616.92), using the CI's own commands: - `cargo test --workspace --locked`: 343 passed, 0 failed, 6 ignored. - `cargo clippy --workspace --all-targets --locked -- -D warnings`, with and without `--all-features`: clean. - `rustfmt --edition 2024 --check` on the changed files: clean on our changes (`lower.rs` keeps the three diffs it already has on `main`, in its test module). - `cargo xtask policy`: 154 files ok. PR creation is limited to collaborators right now, so this is an issue with the branch. I can open a PR when it reopens. No game files used.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:14:02 +00:00
Author
Owner

@⁠26dwh7yy8g-rgb on GitHub · 2026-11-24 12:10 UTC · original

Reproduced and fixed on an RTX 4060 desktop (driver 616.92), Windows 11 Pro 26200, Rust 1.98.1, WARP 10.0.26100.9818.

  • main (ffe310e) with only your valu_tests.rs: the new test fails 3/3 on WARP (dispatch failed, device suspended). The hardware part passes.
  • e04929d: passes 3/3 on both. cargo test --workspace --locked: 343 passed, 0 failed, 6 ignored (4 of the passes are diff_tests, which skip themselves here). Both clippy variants and cargo xtask policy are clean.
  • Cherry-picks onto main together with #830 without conflict: victory-shader lib tests 122 passed, 0 failed, 1 ignored, both clippy variants clean.

No game data used. AI-assisted (Claude Code).

**@⁠26dwh7yy8g-rgb** on GitHub · 2026-11-24 12:10 UTC · [original](https://github.com/Marvisak/VIctory/issues/832#issuecomment-7131059332) Reproduced and fixed on an RTX 4060 desktop (driver 616.92), Windows 11 Pro 26200, Rust 1.98.1, WARP 10.0.26100.9818. - `main` (`ffe310e`) with only your `valu_tests.rs`: the new test fails 3/3 on WARP (dispatch failed, device suspended). The hardware part passes. - `e04929d`: passes 3/3 on both. `cargo test --workspace --locked`: 343 passed, 0 failed, 6 ignored (4 of the passes are `diff_tests`, which skip themselves here). Both clippy variants and `cargo xtask policy` are clean. - Cherry-picks onto `main` together with #830 without conflict: `victory-shader` lib tests 122 passed, 0 failed, 1 ignored, both clippy variants clean. No game data used. AI-assisted (Claude Code).
Author
Owner

@⁠MamaLeVrai on GitHub · 2026-11-24 19:42 UTC · original

@⁠Peppacodes your fix for this issue is now in a pull request, #1603, together with the three others of yours (#762, #764, #765, #832): the branches are merged as they are, with your commits and your name unchanged, onto main ffe310e. Clippy (both runs) and cargo test --workspace pass on the result. If you would rather open your own pull request for this one, say so and I will take it out of #1603. AI-assisted (Claude Code); no game data.

**@⁠MamaLeVrai** on GitHub · 2026-11-24 19:42 UTC · [original](https://github.com/Marvisak/VIctory/issues/832#issuecomment-7142474355) @⁠Peppacodes your fix for this issue is now in a pull request, #1603, together with the three others of yours (#762, #764, #765, #832): the branches are merged as they are, with your commits and your name unchanged, onto `main` `ffe310e`. Clippy (both runs) and `cargo test --workspace` pass on the result. If you would rather open your own pull request for this one, say so and I will take it out of #1603. AI-assisted (Claude Code); no game data.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 03:49 UTC · original

Automated triage for the maintainers. This is fixed on main. Commit 77053a0 ("Shaders: accuracy fixes for discards, f16 rounding, denormals, med3 and signed zeros", now on main) changed Lower::compare in crates/victory-shader/src/emit/lower.rs: float f and tru compares now emit constant false/true (self.s.m.bool(op == "tru")) instead of fcmp false / fcmp true. The branch's regression test (float_compares_that_are_always_false_or_true) could still be sent as a PR if wanted.

This issue will be closed in 48 hours unless the reporter replies or a maintainer removes the triage: proposed close label.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 03:49 UTC · [original](https://github.com/Marvisak/VIctory/issues/832#issuecomment-7152270003) <!-- victory-issue-triage v1 verdict=proposed-close seen=2026-11-24T19:42:23Z at=2026-11-25T03:49:09Z --> Automated triage for the maintainers. This is fixed on `main`. Commit 77053a0 ("Shaders: accuracy fixes for discards, f16 rounding, denormals, med3 and signed zeros", now on `main`) changed `Lower::compare` in `crates/victory-shader/src/emit/lower.rs`: float `f` and `tru` compares now emit constant false/true (`self.s.m.bool(op == "tru")`) instead of `fcmp false` / `fcmp true`. The branch's regression test (`float_compares_that_are_always_false_or_true`) could still be sent as a PR if wanted. This issue will be closed in 48 hours unless the reporter replies or a maintainer removes the `triage: proposed close` label. --- _Generated by [Claude Code](https://claude.ai/code)_
This discussion has been locked. Commenting is limited to contributors.
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory#832
No description provided.