Shaders: invalid f32 sqrt, rsq and log inputs return negative quiet NaN #3612

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

@⁠Moon0755 on GitHub · 2026-11-27 21:09 UTC · original
Moon0755:fix/transcendental-invalid-qnan → main · +58 −0 · 2 files · 1 commits · open

On RDNA2 (gfx1030, measured by the Leonida project), v_sqrt_f32, v_rsq_f32, and v_log_f32 return the negative quiet NaN 0xffc00000 for any invalid negative input, while -0.0 remains valid (-0.0 for v_sqrt_f32, and -inf for v_rsq_f32 and v_log_f32). Without a guard, D3D12 hosts return 0x7fffffff on NVIDIA across all three instructions and 0xffffffff on WARP for v_log_f32.

Changes

  • crates/victory-shader/src/emit/lower.rs: in the v_rsq_f32 / v_sqrt_f32 / v_log_f32 lowering arm (matches!(op, 23..=25)), select 0xFFC0_0000 when pred::OLT(a, 0.0) holds, leaving -0.0, positive inputs, and NaNs untouched (lower.rs size: 521,221 B < 524,288 B).
  • crates/victory-shader/src/emit/valu_tests.rs: add transcendental_invalid_results_are_negative_qnan covering negative inputs (-1.0, -4.0, -1000.0, -inf) and valid -0.0 control cases for v_sqrt_f32, v_rsq_f32, and v_log_f32.

Verification

  • Local 3-host D3D12 verification (AMD Radeon(TM) Graphics, NVIDIA GeForce RTX 2060 with Max-Q Design, WARP):
    • Before this fix on main (63bcca4): NVIDIA returned 0x7fffffff for all three operations (v_sqrt_f32, v_rsq_f32, v_log_f32), and WARP returned 0xffffffff for v_log_f32.
    • After this fix (aa63053): cargo test --locked -p victory-shader --lib --features host -- transcendental_invalid_results_are_negative_qnan --nocapture passed on AMD Radeon(TM) Graphics, NVIDIA GeForce RTX 2060 with Max-Q Design, and WARP (1 passed; 0 failed).
  • cargo xtask policy: 191 files ok.
  • cargo clippy: both cargo clippy --locked -p victory-shader --lib --tests -- -D warnings and --all-features -- -D warnings passed cleanly.
  • Fork CI positive (gemini/ci-transcendental-invalid-qnan): https://github.com/Moon0755/VIctory/actions/runs/46067684463 (SUCCESS; victory-shader 303 passed / 0 failed / 3 ignored, victory-gpu 231 passed / 0 failed, xtask 6/6, both Clippy checks clean).
  • Fork CI negative (gemini/ci-transcendental-invalid-qnan-negative, test only on 63bcca4): https://github.com/Moon0755/VIctory/actions/runs/46067684675 (FAILURE; victory-shader 302 passed / 1 failed exclusively on emit::valu_tests::transcendental_invalid_results_are_negative_qnan: warp: v_log_f32(0xbf800000) = 0xffffffff, want 0xffc00000).

— Devin & Neon

**@⁠Moon0755** on GitHub · 2026-11-27 21:09 UTC · [original](https://github.com/Marvisak/VIctory/pull/3612) `Moon0755:fix/transcendental-invalid-qnan` → `main` · +58 −0 · 2 files · 1 commits · open On RDNA2 (`gfx1030`, measured by the Leonida project), `v_sqrt_f32`, `v_rsq_f32`, and `v_log_f32` return the negative quiet NaN `0xffc00000` for any invalid negative input, while `-0.0` remains valid (`-0.0` for `v_sqrt_f32`, and `-inf` for `v_rsq_f32` and `v_log_f32`). Without a guard, D3D12 hosts return `0x7fffffff` on NVIDIA across all three instructions and `0xffffffff` on WARP for `v_log_f32`. ### Changes - **`crates/victory-shader/src/emit/lower.rs`**: in the `v_rsq_f32` / `v_sqrt_f32` / `v_log_f32` lowering arm (`matches!(op, 23..=25)`), select `0xFFC0_0000` when `pred::OLT(a, 0.0)` holds, leaving `-0.0`, positive inputs, and NaNs untouched (`lower.rs` size: `521,221 B` < `524,288 B`). - **`crates/victory-shader/src/emit/valu_tests.rs`**: add `transcendental_invalid_results_are_negative_qnan` covering negative inputs (`-1.0`, `-4.0`, `-1000.0`, `-inf`) and valid `-0.0` control cases for `v_sqrt_f32`, `v_rsq_f32`, and `v_log_f32`. ### Verification - **Local 3-host D3D12 verification** (`AMD Radeon(TM) Graphics`, `NVIDIA GeForce RTX 2060 with Max-Q Design`, `WARP`): - Before this fix on `main` (`63bcca4`): NVIDIA returned `0x7fffffff` for all three operations (`v_sqrt_f32`, `v_rsq_f32`, `v_log_f32`), and WARP returned `0xffffffff` for `v_log_f32`. - After this fix (`aa63053`): `cargo test --locked -p victory-shader --lib --features host -- transcendental_invalid_results_are_negative_qnan --nocapture` passed on **AMD Radeon(TM) Graphics**, **NVIDIA GeForce RTX 2060 with Max-Q Design**, and **WARP** (1 passed; 0 failed). - **`cargo xtask policy`**: `191 files ok`. - **`cargo clippy`**: both `cargo clippy --locked -p victory-shader --lib --tests -- -D warnings` and `--all-features -- -D warnings` passed cleanly. - **Fork CI positive (`gemini/ci-transcendental-invalid-qnan`)**: https://github.com/Moon0755/VIctory/actions/runs/46067684463 (`SUCCESS`; `victory-shader` 303 passed / 0 failed / 3 ignored, `victory-gpu` 231 passed / 0 failed, `xtask` 6/6, both Clippy checks clean). - **Fork CI negative (`gemini/ci-transcendental-invalid-qnan-negative`, test only on `63bcca4`)**: https://github.com/Moon0755/VIctory/actions/runs/46067684675 (`FAILURE`; `victory-shader` 302 passed / 1 failed exclusively on `emit::valu_tests::transcendental_invalid_results_are_negative_qnan`: `warp: v_log_f32(0xbf800000) = 0xffffffff, want 0xffc00000`). — Devin & Neon
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 21:12:58 +00:00
Author
Owner

@⁠oni-swr on GitHub · 2026-11-27 22:03 UTC · original

Independent verification of aa6305357c3b90c6d64309c6c94bab3895df0547 against main at 63bcca43c6a00a758510398fa43096ce7e4f7df0. Clean merge. Native Windows x64, D3D12 WARP only, with both WARP switches set and SDK dxil.dll. Tests (passed / failed / ignored, unit and integration combined) were 301 / 4 / 4 on base and 302 / 4 / 4 on head. Both runs had the same four WARP failures (three wave-32 pipeline checks and one texture gather check). The backported regression returned 0xffffffff for a negative logarithm input on base and passed on head. Signed-zero cases passed, and 30 sampled outputs for inputs the guard leaves unchanged matched bit for bit. Clippy passed with all targets, all features, and -D warnings. Review found no blocking defects. Asset policy passed, and lower.rs was 521,221 bytes on head and after merging with main, 3,067 bytes below the 524,288-byte limit.

AI-assisted (Codex, gpt-6.2-sol).

**@⁠oni-swr** on GitHub · 2026-11-27 22:03 UTC · [original](https://github.com/Marvisak/VIctory/pull/3612#issuecomment-7228993924) Independent verification of `aa6305357c3b90c6d64309c6c94bab3895df0547` against `main` at `63bcca43c6a00a758510398fa43096ce7e4f7df0`. Clean merge. Native Windows x64, D3D12 WARP only, with both WARP switches set and SDK `dxil.dll`. Tests (passed / failed / ignored, unit and integration combined) were **301 / 4 / 4** on base and **302 / 4 / 4** on head. Both runs had the same four WARP failures (three wave-32 pipeline checks and one texture gather check). The backported regression returned `0xffffffff` for a negative logarithm input on base and passed on head. Signed-zero cases passed, and 30 sampled outputs for inputs the guard leaves unchanged matched bit for bit. Clippy passed with all targets, all features, and `-D warnings`. Review found no blocking defects. Asset policy passed, and `lower.rs` was **521,221 bytes** on head and after merging with `main`, **3,067 bytes** below the 524,288-byte limit. AI-assisted (Codex, gpt-6.2-sol).
Author
Owner

@⁠ColorMeBoom on GitHub · 2026-11-27 23:48 UTC · original

Hardware run on AMD, since the report so far is WARP only: RX 5700 XT (Navi 10, RDNA1, driver 32.0.21045.29003, Windows 11 26200), head aa63053 on 63bcca4. The test fixture checks the hardware adapter and WARP in turn, and neither was skipped.

  • transcendental_invalid_results_are_negative_qnan passes on both.
  • Full victory-shader --lib --features host: 303 passed, 0 failed, 3 ignored.

AI use: Claude Code (Claude Opus 5.5).

**@⁠ColorMeBoom** on GitHub · 2026-11-27 23:48 UTC · [original](https://github.com/Marvisak/VIctory/pull/3612#issuecomment-7230428246) Hardware run on AMD, since the report so far is WARP only: RX 5700 XT (Navi 10, RDNA1, driver 32.0.21045.29003, Windows 11 26200), head `aa63053` on `63bcca4`. The test fixture checks the hardware adapter and WARP in turn, and neither was skipped. - `transcendental_invalid_results_are_negative_qnan` passes on both. - Full `victory-shader --lib --features host`: 303 passed, 0 failed, 3 ignored. AI use: Claude Code (Claude Opus 5.5).
This pull request can be merged automatically.
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/3612/head:github-bot/gh-3612'
git switch 'github-bot/gh-3612'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3612'
git switch 'github-bot/gh-3612'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3612'
git switch 'github-bot/gh-3612'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3612'
git switch 'main'
git merge --squash 'github-bot/gh-3612'
git switch 'main'
git merge --ff-only 'github-bot/gh-3612'
git switch 'main'
git merge 'github-bot/gh-3612'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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!3612
No description provided.