Shaders: invalid f32 sqrt, rsq and log inputs return negative quiet NaN #3612
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3612"
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?
Imported from Marvisak/VIctory. Originally posted by Moon0755 on 2026-11-27T21:09:56Z.
On RDNA2 (
gfx1030, measured by the Leonida project),v_sqrt_f32,v_rsq_f32, andv_log_f32return the negative quiet NaN0xffc00000for any invalid negative input, while-0.0remains valid (-0.0forv_sqrt_f32, and-infforv_rsq_f32andv_log_f32). Without a guard, D3D12 hosts return0x7fffffffon NVIDIA across all three instructions and0xffffffffon WARP forv_log_f32.Changes
crates/victory-shader/src/emit/lower.rs: in thev_rsq_f32/v_sqrt_f32/v_log_f32lowering arm (matches!(op, 23..=25)), select0xFFC0_0000whenpred::OLT(a, 0.0)holds, leaving-0.0, positive inputs, and NaNs untouched (lower.rssize:521,221 B<524,288 B).crates/victory-shader/src/emit/valu_tests.rs: addtranscendental_invalid_results_are_negative_qnancovering negative inputs (-1.0,-4.0,-1000.0,-inf) and valid-0.0control cases forv_sqrt_f32,v_rsq_f32, andv_log_f32.Verification
AMD Radeon(TM) Graphics,NVIDIA GeForce RTX 2060 with Max-Q Design,WARP):main(63bcca4): NVIDIA returned0x7ffffffffor all three operations (v_sqrt_f32,v_rsq_f32,v_log_f32), and WARP returned0xffffffffforv_log_f32.aa63053):cargo test --locked -p victory-shader --lib --features host -- transcendental_invalid_results_are_negative_qnan --nocapturepassed 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: bothcargo clippy --locked -p victory-shader --lib --tests -- -D warningsand--all-features -- -D warningspassed cleanly.gemini/ci-transcendental-invalid-qnan): https://github.com/Moon0755/VIctory/actions/runs/46067684463 (SUCCESS;victory-shader303 passed / 0 failed / 3 ignored,victory-gpu231 passed / 0 failed,xtask6/6, both Clippy checks clean).gemini/ci-transcendental-invalid-qnan-negative, test only on63bcca4): https://github.com/Moon0755/VIctory/actions/runs/46067684675 (FAILURE;victory-shader302 passed / 1 failed exclusively onemit::valu_tests::transcendental_invalid_results_are_negative_qnan:warp: v_log_f32(0xbf800000) = 0xffffffff, want 0xffc00000).— Devin & Neon
Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-27T22:03:46Z.
Independent verification of
aa6305357c3b90c6d64309c6c94bab3895df0547againstmainat63bcca43c6a00a758510398fa43096ce7e4f7df0. Clean merge. Native Windows x64, D3D12 WARP only, with both WARP switches set and SDKdxil.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 returned0xfffffffffor 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, andlower.rswas 521,221 bytes on head and after merging withmain, 3,067 bytes below the 524,288-byte limit.AI-assisted (Codex, gpt-6.2-sol).
Imported from Marvisak/VIctory. Originally posted by ColorMeBoom on 2026-11-27T23:48:52Z.
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
aa63053on63bcca4. The test fixture checks the hardware adapter and WARP in turn, and neither was skipped.transcendental_invalid_results_are_negative_qnanpasses on both.victory-shader --lib --features host: 303 passed, 0 failed, 3 ignored.AI use: Claude Code (Claude Opus 5.5).
Imported from Marvisak/VIctory. Originally posted by kilolimaVI on 2026-11-28T16:00:05Z.
AMD Radeon 780M (RDNA3) + WARP, Windows 11, head
aa63053.63bcca4+ this PR's test): the hardware adapter already returns the console's results for every case (0xffc00000for negativev_sqrt_f32,v_rsq_f32andv_log_f32inputs, and the -0.0 cases). The test fails only on WARP:v_log_f32(0xbf800000)=0xffffffff.victory-shader+victory-gpu --features diagnostics): 552 passed.So RDNA3 matches the RDNA2 measurement natively; the change matters for WARP and (per the description) NVIDIA.
AI-assisted (Claude).
Imported from Marvisak/VIctory. Originally posted by upipibi on 2026-11-28T17:37:17Z.
NVIDIA row for this PR: it passes on Ampere, and its test fails on this card without the fix. On main, the RTX 3070 returns
0x7ffffffffor every negative input of all three instructions, as the description says of the RTX 2060.RTX 3070 (desktop), driver 616.56, Windows 11 Pro 10.0.26100, debug. Head
aa63053on main63bcca4(one commit, clean).cargo test --locked -p victory-shader --lib -- transcendental_invalid_results_are_negative_qnan --nocapture: 1 passed, 0 failed, 0 ignored, in 3 of 3 runs. In each run the test checks this card and then WARP. Three more runs withVICTORY_WARP=1, where every device is WARP, also passed.Negative control: main's
emit/lower.rs, with the test kept invalu_tests.rs.git diff --stat HEAD: 1 file, 12 deletions.git diff --stat 63bcca4: onlyvalu_tests.rs(46 insertions). Result: 0 passed, 1 failed, in 3 of 3 runs on hardware and 3 of 3 withVICTORY_WARP=1:hardware: v_sqrt_f32(0xbf800000) = 0x7fffffff, want 0xffc00000(left: 2147483647,right: 4290772992). That is the first case checked, so the assertion stops there.VICTORY_WARP=1runs:hardware: v_log_f32(0xbf800000) = 0xffffffff, want 0xffc00000(left: 4294967295). The label ishardware, but that run is WARP too. WARP passes thev_sqrt_f32andv_rsq_f32cases before that. This is the description's fork CI control value.The test stops at its first wrong case, so I ran it 3 more times with the PR's code and 3 times with main's
lower.rs, with itsassert_eq!replaced by aneprintln!of every case. Then I restored the file. All three runs of each set printed the same values:v_sqrt_f32(-1.0),(-4.0)0x7fffffff0xffc000000xffc00000v_sqrt_f32(-0.0)0x800000000x800000000x80000000v_rsq_f32(-1.0)0x7fffffff0xffc000000xffc00000v_rsq_f32(-0.0)0xff8000000xff8000000xff800000v_log_f32(-1.0),(-1000.0),(-inf)0x7fffffff0xffffffff0xffc00000v_log_f32(-0.0)0xff8000000xff8000000xff800000So the 3070 gives
0x7ffffffffor all 6 invalid inputs, and WARP's only wrong results are the 3v_log_f32ones. The-0.0cases match RDNA2 on both with and without the PR. That is what the description reports for the RTX 2060 and WARP. The 780M passes every case on main, per kilolimaVI.cargo test --locked -p victory-shader --lib -- --skip heap_direct_texture_reads_mark_their_heap_index:63bcca4: 298 passed, 3 failed, 3 ignored (earlier run on this card).The PR adds one test. The 3 failures are the same on both:
stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride,stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zerosandsynthetic_tests::gathers_at_a_level_match_the_hardware. They come from the structured-view raw read on NVIDIA (#2178, #2323, issue #1835). The skipped test crashes the binary on this card (open issue #2571).The PR does not touch
victory-gpu, so I did not run its lib suite.NVIDIA-specific: Ampere, like Turing in the description, returns the positive NaN
0x7ffffffffor an invalidsqrt,rsqrtorlog2, where RDNA2 returns0xffc00000. So on this card the guard changes the result of all three instructions. On WARP it changes onlyv_log_f32.Not tested:
OLTleaves them alone, but I did not check what this card returns for them), other negative values;v_exp_f32,v_rcp_f32, the f16 and f64 forms);lower.rssize);AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this report.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.