Tests: float-to-int conversions clamp and take NaN as 0 on the GPU #634
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/639"
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 ivall/xcl. Originally posted by acaracargo on 2026-11-24T02:47:22Z.
HLSL leaves an out-of-range or NaN float-to-int cast undefined. The ISA clamps and maps NaN to 0, which is what the
cvt_i32/cvt_u32helpers inemit.rsare for.This adds GPU coverage for
v_cvt_i32_f32,v_cvt_u32_f32,v_cvt_flr_i32_f32,v_cvt_rpi_i32_f32,v_cvt_u16_f16andv_cvt_i16_f16.The inputs cover NaN of both signs, infinities, integer range boundaries, negative halves, negative zero and a denormal. The reference uses Rust's
asconversion, which saturates and maps NaN to zero. The f16 sources carry another value in their high half.#515 covers the opposite conversion direction and does not overlap with this test.
What is in it
crates/xcl/src/gpu/recomp/tests.rs:gpu_float_to_int_conversions_clamp_and_take_nan_as_zero.Tested
x86_64-pc-windows-msvc; DXC 1.9.2602.17; debug.cargo test --workspace -- --test-threads=4onac0b845: 685 passed, 0 failed, 41 ignored (main9ce2070: 684 / 0 / 41).gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware(no wave64).cvt_i32causes the test to fail (checked locally, reverted).(int)cast already saturates and maps NaN to 0, so removing the helper altogether is not caught here.Regression run
Not tested
v_cvt_rpi_i32_f32of 0.49999997, wherefloor(x + 0.5)in f32 rounds up. The ISA text does not specify whether the addition is rounded.AI use
xcl pipelines) #750Imported from ivall/xcl. Originally posted by MesshM on 2026-11-24T03:18:24Z.
Test run of
ac0b845698d82b765b5436cd0151cef6feb0127con AMD RDNA4 (native wave64). I merged it onto currentmain63cdc25locally (clean merge) and tested that tree.Tested
stable-x86_64-pc-windows-msvc, debugcargo build --workspace+cargo test --workspace -- --test-threads=4on the merge: 693 passed, 0 failed, 41 ignored, exit code 0;xcllib tests 653 passed, 0 failed, 21 ignoredSKIPPED;gpu_float_to_int_conversions_clamp_and_take_nan_as_zeropasses.Review: NaN converts to 0 and out-of-range values (±inf included) clamp;
v_cvt_flr_i32_f32is floor(x) andv_cvt_rpi_i32_f32floor(x + 0.5) before the conversion, and the f16 sources carry another value in the high half, as the ISA describes. This is the first AMD run.Not tested: no retail title (not needed for a test-only change), release build; the PR's head on its old base was not run, only its merge onto
main.Run and review by Claude Code (Claude Opus 5.5) on this machine; the review points were checked against the code.
Imported from ivall/xcl. Originally posted by marquezinii on 2026-11-24T04:31:05Z.
Test run of
ac0b845698d82b765b5436cd0151cef6feb0127con NVIDIA Blackwell with a newer driver than the one in the description. I merged it onto currentmainf4ce27clocally (clean merge, 66 lines intests.rs) and tested that tree.Tested
stable-x86_64-pc-windows-msvc, debug; DXC 1.9.2602.17 (Windows SDK 10.0.26100.0)cargo test --workspace -- --test-threads=4: 702 passed, 0 failed, 41 ignored;--test-threads=1: the samegpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware(no wave64)gpu_float_to_int_conversions_clamp_and_take_nan_as_zeropassescvt_u32reduced toreturn (uint)f;, and separatelycvt_i32toreturn (int)f;(by hand, reverted), the test still passes. So on RTX 4060 / 610.88 and RTX 5070 / 621.24 a plain cast already saturates and maps NaN to 0, and only AMD (or another vendor) can show whether the helpers are needed.Not tested
AI use
upstream-sync referenced this pull request2026-11-24 07:06:51 +00:00
mainreaches on Windows; the obstacle is replaced vtables — proposal: proxies #172Imported from ivall/xcl. Originally posted by 4usphs on 2026-11-24T09:32:52Z.
Measured on RDNA2 hardware: this answers the
v_cvt_rpi_i32_f32question under Not tested, and shows a second difference. For NaN,v_cvt_flr_i32_f32andv_cvt_rpi_i32_f32do not give 0.Method. The Radeon iGPU of a Ryzen 7 9800X3D (
gfx1036, RDNA2), Windows 11 Pro 26200, display driver 32.0.21045.29003, AMD OpenCL3652.0 (PAL,LC). Each instruction runs as inline RDNA2 assembly in an OpenCL C kernel (the #518 / #772 method), one input per work-item, VDST preset to0xCAFEBABE, in wave32 and in wave64 (-Wf,-mwavefrontsize64). There are 3 runs with identical output. The NaN and rounding cases were also run with MODE.DX10_CLAMP / MODE.IEEE set to each of the 4 combinations withs_setreg_imm32_b32(read back withs_getreg_b32:0xf0to0x3f0), and they give the same results in all 4.1.
v_cvt_rpi_i32_f32rounds exactly. The hardware computesfloor(x + 0.5)without roundingx + 0.5to f32.floor(x + 0.5f)in f32 (the test's reference, andemit.rstoday)floor(x + 0.5)0x3EFFFFFF)0x4B000001)0x4B000003)0xCB000001)emit.rstranslates it ascvt_i32(floor(x + 0.5f))(line 3281 onmain077ce40). So it gives 1 for 0.49999997 and is off by one for odd integers from 2^23 up.2. NaN in
v_cvt_flr_i32_f32/v_cvt_rpi_i32_f32takes the sign of the NaN.v_cvt_i32_f32v_cvt_u32_f32v_cvt_flr_i32_f32v_cvt_rpi_i32_f320x7FC00000, +sNaN0x7F800001,0x7FFFFFFF0x7FFFFFFF0x7FFFFFFF0xFFC00000, -sNaN0xFF8000010x800000000x80000000v_cvt_i32_f32andv_cvt_u32_f32give 0 as the test expects. Forflrandrpi, the test's first two inputs (NAN,-NAN) expect 0, which is the opposite of the hardware.emit.rsgives 0 there too, throughcvt_i32'sisnanselect.Everything else in this test matches the hardware. These are the other 18 f32 inputs for all four f32 instructions, the 12 f16 inputs for
v_cvt_u16_f16/v_cvt_i16_f16(low 16 bits), and wave32 = wave64 everywhere. Side note for #638's open point: both f16 conversions left D[31:16] at the preset0xCAFE, so the high half is kept, not zeroed.What would match the hardware, as far as I can tell (not tried in
emit.rs): forflr/rpi, NaN givesselect(asuint(x) >> 31, 0x80000000, 0x7FFFFFFF).rpirounds without the f32 addition, e.g.r = floor(x); r + (x - r >= 0.5f)(x - floor(x)is exact in f32), then clamps.For comparison, an RX 9070 XT (
gfx1201, RDNA4, OpenCL3686.0) gives the same results for everything above: exactrpirounding, the NaN signs forflr/rpi, and D[31:16] kept.Not tested: the console itself (
gfx1036is a desktop RDNA2 APU of the same generation), RDNA1, this PR's test on this GPU (it does not run D3D12 tests in my setup; RDNA4 runs are above).Kernel (one of the cases)
AI use: Claude Code (Claude Opus 5.5) wrote the OpenCL probes, ran them on my PC and wrote this comment. I have not reviewed the code.
Imported from ivall/xcl. Originally posted by JJAutoCompare on 2026-11-25T06:30:21Z.
Empirical test report (
ac0b8456)Hardware / environment
ac0b845698d82b765b5436cd0151cef6feb0127c, verified on a clean detached HEAD.Commands and results
cargo test -p xcl --lib --no-runexited 0 outside the Arc lock. Cargo built the test executable in 30.59 s and emitted onefetch_updatedeprecation warning.$testExeis the executable printed by Cargo and$arcLockis the sharedInvoke-ArcTest.ps1script. The focused command ran withXCL_ADAPTER=A770andRUST_TEST_NOCAPTURE=1.The focused command exited 0. The log shows 1 passed, 0 failed, 0 ignored, 0 skipped, with 665 tests filtered out. The skip count is the number of case-sensitive log lines beginning with
SKIPPED. The test harness reported 0.19 s.Observed behavior
The translated compute shader matched the Rust expectations for all six conversion instructions across 20 checked lanes, including NaN to zero, clamping at integer bounds and for infinities, and the signed floor and nearest rounding with ties toward positive infinity. The two f16-source conversions also matched with nonzero bits in the high half of the source registers.
Not tested
Full GPU workspace suite and game smoke runs.
AI use
Verified with T3 Code / Codex (gpt-6.2-sol, reasoningEffort: high). Coordinator #2 (T3 Code / Antigravity, gemini-4-neon) verified counts against pr639-focused.log and published.
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T12:45:58Z.
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: 1038 passed, 1 failed in one parallel run; the failing test passes on a single-threaded rerun (1039/0). Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.Thanks!
Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-11-29T07:42:55Z.
Nothing has happened on this PR for 3 days, so it is marked
staleand will be closed in 4 days. A push or a comment takes the mark off: rebase it ontomainif it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.Imported from ivall/xcl. Originally posted by BBareth on 2026-11-30T09:30:31Z.
merge-check claim
head:
ac0b845698Imported from ivall/xcl. Originally posted by BBareth on 2026-11-30T09:39:21Z.
merge-check
base:
9dfbe3ea66head:
ac0b845698merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2886 passed, 1 failed, 51 ignored; failing: gpu::dxil::msaa_tests::gpu_direct_image_get_resinfo_d16, which fails on the base alone too (base: 2885 passed, 1 failed, 51 ignored). 28 SKIPPED lines, the same count as on the base. The new test
gpu_float_to_int_conversions_clamp_and_take_nan_as_zeropassed.review: no blocking finding; test-only, one file, every line read. One GPU test of six float-to-int conversions against Rust's saturating
ason 20 f32 and 12 f16 edge inputs (NaN of both signs, infinities, range boundaries, negative halves, -0, a denormal); it returns early throughgpu_ready()without a GPU. Not a duplicate of #515 (the other direction). #1020 (open) changes howv_cvt_rpirounds x + 0.5; none of this test's inputs is one where the f32 sum and the exact sum differ, so the two do not conflict in expected values.performance: none; tests only.
verdict: safe to merge
hardware / tool and model: RTX 5070 Ti 16 GB, driver 621.24 (32.0.16.2124); i7-12700K; Windows 11 26200. Claude Code, Claude Fable 5.2 read the diff, ran the build and the suite and wrote this check.
Imported from ivall/xcl. Originally posted by Blelle on 2026-11-30T10:22:12Z.
merge-check claim
head:
ac0b845698Imported from ivall/xcl. Originally posted by Blelle on 2026-11-30T10:31:48Z.
merge-check
base:
9dfbe3ea66head:
ac0b845698merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2878 passed, 10 failed, 51 ignored (9 unique failing tests; gpu_two_pass_cache_e2e spawns a child process that prints an inner FAILED summary); SKIPPED: 6 (no heap windows x2, cannot disable driver cache on Windows x1, no D3D12 debug layer / d3d12SDKLayers.dll x3); new test gpu::recomp::tests::gpu_float_to_int_conversions_clamp_and_take_nan_as_zero -> 1 passed (--exact --nocapture, 0 SKIPPED); failing: gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1, gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_3, gpu::dxil::msaa_tests::gpu_direct_image_get_resinfo_d16, gpu::recomp::heap_window_tests::gpu_smem_flat_descriptor_windows_and_limits, gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu, gpu::recomp::tests::gpu_f32_compares_with_nan, gpu::recomp::tests::gpu_float_compares_random, gpu::recomp::tests::gpu_ps_readfirstlane_loop_on_a_primitive_edge_ends, two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs (all 9 unique failures also fail on base
9dfbe3eaalone)review: blocking semantic bug in test expectations for v_cvt_flr_i32_f32 and v_cvt_rpi_i32_f32 on NaN: lines 10140-10142 and 10192-10193 expect 0 for f32::NAN and -f32::NAN (Rust
as i32 as u32), whereas RDNA2 (gfx1036) and RDNA4 (gfx1201) silicon measurements in this PR's thread show both instructions saturate NaN by sign (+NaN -> 0x7FFFFFFF, -NaN -> 0x80000000; only v_cvt_i32_f32 and v_cvt_u32_f32 return 0). It passes today only because emit.rs (3951-3952) and dxil/lower_valu.rs (449-460) route both through cvt_i32 (isnan -> 0), and it directly conflicts on NaN expectations with open PR #1020. Minor: the(x + 0.5).floor()reference in v_cvt_rpi_i32_f32 roundsx + 0.5in f32 instead of exactfloor(x + 0.5)(not triggered by the 20 chosen inputs); v_cvt_u16_f16 / v_cvt_i16_f16 mask& 0xFFFFon VDST so high-half preservation is not asserted here (#1115);runner::run_codecovers the HLSL backend only unlessXCL_DIRECT_DXIL=1is set. Scope is clean (+66/-0 in crates/xcl/src/gpu/recomp/tests.rs); no duplicate PR found.performance: none (test-only change)
verdict: not yet: asserts NaN -> 0 for v_cvt_flr_i32_f32 and v_cvt_rpi_i32_f32, contradicting RDNA2/RDNA4 hardware measurements (+NaN -> 0x7FFFFFFF, -NaN -> 0x80000000) and conflicting with open PR #1020; also uses f32-rounded (x + 0.5).floor() as reference instead of exact floor(x + 0.5)
hardware / tool and model: AMD Radeon RX 9060 XT 16 GB (driver 32.0.32029.2010), AMD Ryzen 5 9600X, 32 GB RAM, Windows build 26200.9974 (25H2), rustc 1.100.1 (20ddd0171 2026-11-25) MSVC, DXC 1.9.2602.17 / Antigravity, Gemini 4 Neon
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T03:51:01Z.
Triage (#1607) – head
ac0b845No open or merged PR makes the same change. #654 (same author) covers integer-to-float conversions, and #2620 / #1672 overlap only in part.
The test asserts that
v_cvt_flr_i32_f32andv_cvt_rpi_i32_f32give 0 for NaN and -NaN (Rustas). #1020 measured RDNA2 silicon (gfx1036) giving 0x7FFFFFFF for +NaN and 0x80000000 for -NaN for those two ops, and changes emit.rs to match. This test therefore asserts XCL's current output, not the hardware's, and will fail once #1020 merges. The NaN rows for flr / rpi should expect saturation by sign, or leave NaN out for those two ops.v_cvt_i32_f32/v_cvt_u32_f32giving 0 for NaN agrees with #1020.Recommendation: keep open.
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
Imported from ivall/xcl. Originally posted by Pipodi on 2026-12-02T11:45:50Z.
merge-check
base:
1c8b551475head:
ac0b845698merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2909 passed, 2 failed, 51 ignored; failing: two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs (
gpu_two_pass_cache_e2e; counted twice because its child process prints its own summary;releasing the title PSOs releases their two-pass state, left 1, right 0). It is intermittent on the base too: 1 failure in 6 runs of that test alone on1c8b5514with the same assertion, and the PR cannot reach it (it adds one#[cfg(test)]lib test). 25 SKIPPED lines: 22 "no wave64", 2 "no heap windows", 1 "cannot disable the driver cache". The new test passes on the direct DXIL path (default) and with XCL_DIRECT_DXIL=0 (HLSL); it ran on both and skipped on neither.review: 1) Blocking, the point the two checks disagree on: the NaN rows of
v_cvt_flr_i32_f32andv_cvt_rpi_i32_f32expect 0 (Rustas), but the RDNA2 (gfx1036) and RDNA4 (gfx1201) silicon measurements earlier in this thread give 0x7FFFFFFF for +NaN and 0x80000000 for -NaN for those two ops; onlyv_cvt_i32_f32/v_cvt_u32_f32give 0. The test asserts what XCL emits today (cvt_i32(floor(..))in emit.rs anddxil/lower_valu.rs), not the hardware. I checked this here: with #1020'scvt_flr/cvt_rpihelpers put into emit.rs on top of this merge (#1020 itself no longer merges into main), the test still passes on the direct path, which #1020 does not change, and on the HLSL path it fails on exactly four rows: flr(NaN) = 0x7fffffff, rpi(NaN) = 0x7fffffff, flr(-NaN) = 0x80000000, rpi(-NaN) = 0x80000000, all with "want 0x0". Every other row passes, and so does #1020's exactrpirounding. So the test is wrong for those rows and will fail once #1020 or anything else that matches the hardware lands. Fix: expect saturation by sign for flr/rpi NaN, or leave NaN out for those two ops. 2) Minor: the(x + 0.5).floor()reference rounds the sum to f32. None of the 20 inputs is a case where that differs from exact floor(x + 0.5), so nothing fails today. 3) The other expected values agree with the ISA: out of range and ±inf clamp to INT_MIN/INT_MAX, or to 0/UINT_MAX for unsigned; NaN gives 0 for i32/u32; and the f16 → i16/u16 rows. Both backends clamp with explicit selects (cvt_i32/cvt_u32in emit.rs anddxil/prelude.rs) and use the fptosi/fptoui result only in range, so the expected values do not depend on how NVIDIA handles out-of-range casts. That also means that on NVIDIA this test cannot catch a helper reduced to a plain cast (see the plain-cast note above). No f64 conversion is covered, despite the doc comment's wording. One correction to thenot yetcheck:runner::run_codetakes the direct DXIL path by default (kernel::enabled()), not only with XCL_DIRECT_DXIL=1.performance: none, test-only: the diff is +66/-0 in crates/xcl/src/gpu/recomp/tests.rs, a
#[cfg(test)]module, so no runtime code changes and no smoke run is needed.verdict: not yet: the NaN expectations for v_cvt_flr_i32_f32 / v_cvt_rpi_i32_f32 contradict the measured RDNA2/RDNA4 results (+NaN -> 0x7FFFFFFF, -NaN -> 0x80000000). Reproduced here: with those semantics in the HLSL path, exactly those four rows fail.
hardware / tool and model: NVIDIA GeForce RTX 4090 24 GB, driver 621.40; Intel Core i9-13900K, 32 GB; Windows 11 build 26300; rustc 1.100.0; debug. Claude Code, Claude Opus 5.5 read the diff, ran the build, the suite and the semantic checks, and wrote this check.
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.