Shaders: always-false and always-true float compares lower as constants #160

Open
github-bot wants to merge 1 commit from github-bot/gh-160 into main AGit
Owner

@⁠Peppacodes on GitHub · 2026-11-24 22:03 UTC · original
Peppacodes:vf/fcmp-false-true → main · +50 −2 · 3 files · 1 commits · open

v_cmp_f_{f32,f16} and v_cmp_tru_{f32,f16} lowered to fcmp false and fcmp true (predicates 0 and 15).

Why this matters

  • DXC folds those predicates away, so drivers never see them coming from it.
  • WARP removes its device at the first dispatch of a pipeline that has one ("The GPU device instance has been suspended"). A removed WARP device stays removed for the process, so everything after it fails too.
  • The hardware adapter (RTX 5080) runs them.

The fix. These compares are false and true whatever the operands, NaNs included (RDNA2 ISA). So they now lower as constants, as the integer v_cmp_f / v_cmp_t already do. FALSE and TRUE stay in the predicate table, unused.

How it was found. A sweep of every 32-bit VALU instruction on the hardware adapter against WARP. With this change, all 62 compares run and agree on both.

Tested on this branch's base (2119b0e, the same tree as 4e17478) plus this commit, on Windows 11 with an RTX 5080:

  • New test float_compares_that_are_always_false_or_true: f32 and f16, ordinary and NaN operands, on the hardware adapter and on WARP. On main, WARP's dispatch fails with the device suspended.
  • cargo clippy --workspace --all-targets --locked -- -D warnings, with and without --all-features: clean.
  • cargo test -p victory-shader -p victory-hle -p victory-loader --locked: 337 passed, 0 failed, 2 ignored. This was with the two other PRs from this account applied as well.

AI-assisted (Claude Code).

**@⁠Peppacodes** on GitHub · 2026-11-24 22:03 UTC · [original](https://github.com/fxceless/victory-fork/pull/160) `Peppacodes:vf/fcmp-false-true` → `main` · +50 −2 · 3 files · 1 commits · open `v_cmp_f_{f32,f16}` and `v_cmp_tru_{f32,f16}` lowered to `fcmp false` and `fcmp true` (predicates 0 and 15). **Why this matters** - DXC folds those predicates away, so drivers never see them coming from it. - WARP removes its device at the first dispatch of a pipeline that has one ("The GPU device instance has been suspended"). A removed WARP device stays removed for the process, so everything after it fails too. - The hardware adapter (RTX 5080) runs them. **The fix.** These compares are false and true whatever the operands, NaNs included (RDNA2 ISA). So they now lower as constants, as the integer `v_cmp_f` / `v_cmp_t` already do. `FALSE` and `TRUE` stay in the predicate table, unused. **How it was found.** A sweep of every 32-bit VALU instruction on the hardware adapter against WARP. With this change, all 62 compares run and agree on both. **Tested** on this branch's base (`2119b0e`, the same tree as `4e17478`) plus this commit, on Windows 11 with an RTX 5080: - New test `float_compares_that_are_always_false_or_true`: f32 and f16, ordinary and NaN operands, on the hardware adapter and on WARP. On `main`, WARP's dispatch fails with the device suspended. - `cargo clippy --workspace --all-targets --locked -- -D warnings`, with and without `--all-features`: clean. - `cargo test -p victory-shader -p victory-hle -p victory-loader --locked`: 337 passed, 0 failed, 2 ignored. This was with the two other PRs from this account applied as well. AI-assisted (Claude Code).
v_cmp_f_{f32,f16} and v_cmp_tru_{f32,f16} lowered to fcmp false and
fcmp true (predicates 0 and 15). DXC folds those away, so drivers never
see them from it, and WARP removes its device at the first dispatch of
a pipeline that has one ("The GPU device instance has been suspended").
The hardware adapter (RTX 5080) runs them. A removed WARP device stays
removed for the process, so everything after it fails too.

They are false and true whatever the operands, NaNs included (RDNA2
ISA), so they now lower as constants, as the integer v_cmp_f/v_cmp_t
already do. FALSE and TRUE stay in the predicate table, unused.

Found with a sweep of every 32-bit VALU instruction on the hardware
adapter against WARP: all 62 compares now run and agree on both.

Test: float_compares_that_are_always_false_or_true, f32 and f16 with
ordinary and NaN operands, on the hardware adapter and WARP. On main
WARP's dispatch fails with the device suspended.

(cherry picked from commit e04929d9d0c4815fc054f8793986894794b350dc)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:37:14 +00:00
Author
Owner

@⁠DovisLe on GitHub · 2026-11-24 23:43 UTC · original

Tested on a Radeon 860M (RDNA 3.5) and WARP, at 21ad2df (base 2119b0e).

build float_compares_that_are_always_false_or_true
this PR passes on the 860M and WARP
this PR's test with main's lower.rs and bitcode.rs the 860M gives the right answers; WARP fails with warp: dispatch failed: The GPU device instance has been suspended.

So AMD hardware, like the RTX 5080, runs fcmp false/fcmp true, and only WARP loses its device on them.

  • cargo test -p victory-shader --locked --lib: 211 passed, 0 failed, 2 ignored (main: 210 passed).
  • cargo clippy -p victory-shader --all-targets --locked -- -D warnings: clean.
  • The early return calls self.lane(inst, Some(op == "tru")), the same path the integer v_cmp_f/v_cmp_t already take, so v_cmpx_* still writes EXEC and the VOP3 forms still write their SGPR pair.

No game files used.

AI-assisted (Claude).

**@⁠DovisLe** on GitHub · 2026-11-24 23:43 UTC · [original](https://github.com/fxceless/victory-fork/pull/160#issuecomment-7147727022) Tested on a **Radeon 860M (RDNA 3.5)** and WARP, at `21ad2df` (base `2119b0e`). | build | `float_compares_that_are_always_false_or_true` | |---|---| | this PR | passes on the 860M and WARP | | this PR's test with `main`'s `lower.rs` and `bitcode.rs` | the 860M gives the right answers; WARP fails with `warp: dispatch failed: The GPU device instance has been suspended.` | So AMD hardware, like the RTX 5080, runs `fcmp false`/`fcmp true`, and only WARP loses its device on them. - `cargo test -p victory-shader --locked --lib`: 211 passed, 0 failed, 2 ignored (`main`: 210 passed). - `cargo clippy -p victory-shader --all-targets --locked -- -D warnings`: clean. - The early return calls `self.lane(inst, Some(op == "tru"))`, the same path the integer `v_cmp_f`/`v_cmp_t` already take, so `v_cmpx_*` still writes EXEC and the VOP3 forms still write their SGPR pair. No game files used. AI-assisted (Claude).
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/160/head:github-bot/gh-160'
git switch 'github-bot/gh-160'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-160'
git switch 'github-bot/gh-160'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-160'
git switch 'github-bot/gh-160'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-160'
git switch 'main'
git merge --squash 'github-bot/gh-160'
git switch 'main'
git merge --ff-only 'github-bot/gh-160'
git switch 'main'
git merge 'github-bot/gh-160'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.