Skip to content

Tests: GPU check for v_floor/ceil/fract_f32 and v_cvt_flr_i32_f32 of a denormal (TEST-515) - #3299

Open
dandasma wants to merge 1 commit into
ItsNotRexed:mainfrom
dandasma:gpu-test-round-f32-denorm-main
Open

dandasma wants to merge 1 commit into
ItsNotRexed:mainfrom
dandasma:gpu-test-round-f32-denorm-main

Conversation

@dandasma

@dandasma dandasma commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: TEST-515 (#2516 (comment))

Rebased on main f847748: scripts/run_gpu_tests.py conflicted with TEST-510's cs_buf_load_sub / cs_buf_fmt8 entries and tests/test_shader_checks.py with vs_base_ids; both sides are kept, so the fixture count there is now + 13. The numbers below are from that base unless noted.

What and why

#2139's change, on main as 0fe4e45 and f0ea562, makes v_floor_f32, v_ceil_f32, v_fract_f32 and v_cvt_flr_i32_f32 read an f32 denormal as a zero of its sign, as gfx1036 does in the game's MODE. No GPU test fed these ops a denormal: ps_fnan_fract gives v_fract_f32 a normal -1e-10, and nothing used floor, ceil or cvt_flr. This was claimed as stacked on #2139; that change is on main now, so the branch is based on main.

  • runtime/test/shaders/cs_round_f32_denorm.asm: 8 lanes (wave32). Each lane gets one operand picked per lane at run time (v_cndmask on the lane id, so the driver cannot fold it) and stores one of the four results to memory (a buffer store, so no export path can canonicalise the NaN words). The 8 words are rows measured natively on gfx1036 in tests/semantic/test_alu_floor_ceil_fract_hw.py: floor(-1e-45) = -0, ceil(+1e-45) = +0, fract(±1e-45) = 0, fract(±inf) = 0xffc00000, cvt_flr_i32(-1e-45) = 0, and floor of the signalling NaN 0x7fa00000 unchanged.
  • Registered like cs_cvt_pk_u8: ROUND_F32_DENORM_WORDS and a compute_test in check.py, the per-lane dump list in scripts/run_gpu_tests.py, tests/semantic/regen_fixtures.py with the generated fixture, tests/semantic/test_round_f32_denorm.py (each lane through the interpreter), and the fake vk_compute_test words plus the fixture count in tests/test_shader_checks.py (the same change 9df5969 made for cs_cvt_pk_u8).

Tested

AMD Radeon RX 9070 (RDNA4, subgroup 32..64), AMD 26.10.1 (LLPC), Vulkan 1.4.359, Windows 11 26300, Python 3.12.10, llvm-mc 21.1.8, Vulkan SDK 1.4.363.0; this branch on main f847748 (no C++ change), with LEONIDA_VK_DEVICE=9070.

  • run_gpu_tests.py --filter cs_round_f32_denorm: 1/1 in three runs, 0x80000000 0x0 0x0 0x0 0xffc00000 0xffc00000 0x0 0x7fa00000 each time.
  • build.py: 225 shaders translated, all pass spirv-val (main f847748: 224). check.py: 172 of 175 pass, 3 skipped (main: 171 of 174, the same skips).
  • Full run_gpu_tests.py: 186/200 passed, 14 skipped, 0 failed (main f847748: 185/199, the same 14 skips); the only difference is the new test.
  • Negative control with the translator from before Translator: v_floor/ceil/fract_f32 and v_cvt_flr_i32_f32 read an f32 denormal as zero, as RDNA2 does #2139 (main 4947579): the CPU test fails seven of the eight lanes with the "before" words of Translator: v_floor/ceil/fract_f32 and v_cvt_flr_i32_f32 read an f32 denormal as zero, as RDNA2 does #2139's table (floor -1.0, ceil +1.0, fract 0x3f7fffff and 0x00000001, fract(±inf) 0x7fc00000, cvt_flr -1); lane 7 passes on the CPU (the same on this base). On the RX 9070 (run before the rebase) the GPU test fails three lanes, in three runs: fract(±inf) gives 0x3f7fffff and the signalling NaN comes back quieted (0x7fe00000). The denormal lanes already match there because this driver flushes f32 denormals itself; Translator: v_floor/ceil/fract_f32 and v_cvt_flr_i32_f32 read an f32 denormal as zero, as RDNA2 does #2139 notes that NVIDIA keeps them by default, which is where those lanes differ.
  • CPU: python -I -m unittest discover -s tests/semantic 7323 tests OK (4 skipped, 1 expected failure; main: 7322), tests/test_shader_checks.py 70 OK, tests/test_run_gpu_tests.py 38 OK, regen_fixtures.py --check clean, on Python 3.14.2 (WSL), and test_round_f32_denorm.py, test_shader_checks.py, test_run_gpu_tests.py and regen_fixtures.py --check on 3.12.10 (Windows). git diff --check clean.

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (Not applicable: no translator change.)

AI-assisted (Claude Code).

🤖 Generated with Claude Code

@bobcatchris

Copy link
Copy Markdown
Contributor

Apple M2 data point for the new denormal/special-value fixture. Tested head 469cebe on Apple M2 (Mac14,3), macOS 26.4 (25E246), MoltenVK 1.4.2 (direct), subgroup 4..32, llvm-mc 23.1.6, Python 3.13.18.

python -I scripts/run_gpu_tests.py --filter cs_round_f32_denorm --build runtime/build/linux: 1 shader translated, 1 pass spirv-val; 1/1 passed — 0x80000000 0x0 0x0 0x0 0xffc00000 0xffc00000 0x0 0x7fa00000, exactly the gfx1036-derived words in the PR body, with 0 mismatches. In particular this MoltenVK run preserves the signalling NaN word 0x7fa00000 (the RX 9070 result in the PR body quieted it to 0x7fe00000) and returns the ±inf fract words 0xffc00000.

Build note: full build fails on AppleClang 17 at vk_pipeline_check.cpp:567 (BUILD-822, fixed by open PR #2927); GPU binaries built, so the run above is valid. Head fetched unchanged into a separate worktree; no rebase/edit/push. Synthetic shader and counts only; no game files.

AI-assisted.

@dandasma

Copy link
Copy Markdown
Contributor Author

Rebased on main f847748, which conflicted in scripts/run_gpu_tests.py (TEST-510's cs_buf_load_sub / cs_buf_fmt8) and tests/test_shader_checks.py (vs_base_ids, so the fixture count is now + 13); both sides are kept. Re-run on the RX 9070 with programs built from that base: cs_round_f32_denorm 1/1 in three runs, full run_gpu_tests.py 186/200 with 14 skipped, against main's 185/199 with the same skips; semantic suite 7323 OK.

Thanks @bobcatchris for the M2 run. One clarification: with this PR the RX 9070 also returns 0x7fa00000 for the signalling NaN and 0xffc00000 for fract(±inf), in every run, before and after the rebase. The 0x7fe00000 and 0x3f7fffff in the description come from the negative control, with the translator from before #2139.

@vibryxcx

Copy link
Copy Markdown

Tested 02df6ef on AMD Radeon RX 6800 (RDNA2, Navi 21, subgroup 32..64), AMD 26.8.1 (Windows 32.0.21045.5002), Vulkan 1.4.315, Windows 11 Pro 25H2 (build 26200): pass

As far as I can see in this thread, this is the first run of the new fixture on a discrete RDNA2 card (the expected words come from gfx1036).

  • run_gpu_tests.py --filter cs_round_f32_denorm --require-pass: 1/1 in three runs, 0x80000000 0x0 0x0 0x0 0xffc00000 0xffc00000 0x0 0x7fa00000 each time, the words in the PR body.
  • Full run_gpu_tests.py: 185/200 passed, 15 skipped, 0 failed; 205 shaders translated, all pass spirv-val.
  • main f847748, built and run the same way: 184/199 passed, the same 15 skipped, 0 failed; 204 shaders. The only difference is cs_round_f32_denorm.
  • CPU: test_round_f32_denorm 1/1 OK, tests/test_shader_checks.py 70/70 OK.

Built with scripts\build_runtime.ps1 (MSVC 14.44, VS 2022 17.14), Vulkan SDK 1.4.363, llvm-mc 23.1.6 (conda-forge), Python 3.12.10. Wave64 ran natively, without LEONIDA_W64_EMULATE. No game files.

AI-assisted (Claude Code): it built both commits and ran the tests.

@sds-228

sds-228 commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested 02df6ef0 on NVIDIA RTX 3080 Laptop (Ampere), driver 621.24, Vulkan 1.4.357, Windows 11:

  • run_gpu_tests.py --filter cs_round_f32_denorm: 1/1, exact words 0x80000000 0x0 0x0 0x0 0xffc00000 0xffc00000 0x0 0x7fa00000. The denormal lanes match here too, despite the note about NVIDIA keeping f32 denormals.
  • Full suite: 154/200 passed, 46 skipped, 0 failed (the one earlier ps_array_resinfo failure was a stale runtime binary; rebuilding main first cleared it).

llvm-mc 21.1.8, SPIRV-Tools via WSL forwarders, Python 3.13. Synthetic fixtures only, no game files. AI-assisted (OpenCode).

@ttd0x

ttd0x commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested 02df6ef0 on NVIDIA GeForce RTX 2080 Ti (Turing, subgroup 32..32, driver 610.88), Windows 11: pass.

  • tests/semantic/test_round_f32_denorm.py: 1 test OK; tests/test_shader_checks.py: 74 tests OK.
  • scripts/run_gpu_tests.py (default, no emulation), 205 shaders translated, all pass spirv-val: 153/200 passed, 46 skipped (native wave64, expected on a 32-wide device), 1 failed. The new cs_round_f32_denorm passes on this device. Compared with main f847748c (152/199) the only difference in the result lines is that new test; the one failure (ps_sdwa_f16_const) also fails on main.
  • Not checked: whether the check also holds on a GPU that keeps denormals (this card's driver result is the one reported here).

Synthetic fixtures only, no game data. AI-assisted (Claude Code).

@sperm

sperm commented Nov 22, 2026

Copy link
Copy Markdown

Tested 02df6ef on AMD Radeon RX 9070 XT (RADV GFX1201) and the Ryzen 7 9800X3D iGPU (RADV RAPHAEL_MENDOCINO, gfx1036), Mesa 26.2.6, Linux 7.3.4: pass, no regressions.

  • Full python -I scripts/run_gpu_tests.py (Linux build of this branch's runtime/, LEONIDA_VK_DEVICE per GPU): 186/200 passed, 14 skipped, 0 failed on both GPUs. Compared with the same suite at the merge base f847748 on the same machine, every shared test has the same result, and the test this PR adds (cs_round_f32_denorm) passes on both GPUs.
  • python -m unittest discover -s tests/semantic: 7323 run, OK (expected failures=1)
  • tests/test_shader_checks.py: 70 run, OK

No game files. AI-assisted.

@MKmajster

Copy link
Copy Markdown

Tested 02df6ef on NVIDIA GeForce RTX 3070 (Ampere, subgroup 32..32), driver 617.42, Windows 11 24H2 (26100): pass, plus the negative control nobody has run on NVIDIA yet.

  • run_gpu_tests.py --filter cs_round_f32_denorm: 1/1 in three runs, 0x80000000 0x0 0x0 0x0 0xffc00000 0xffc00000 0x0 0x7fa00000 each time.
  • Full run_gpu_tests.py: 154/200 passed, 46 skipped (wave64), 0 failed (main f847748 on the same machine: 153/199, the only difference is the new test).
  • CPU: test_round_f32_denorm OK, tests/test_shader_checks.py 70 OK, tests/test_run_gpu_tests.py 38 OK, regen_fixtures.py --check clean.
  • Negative control on NVIDIA: this branch with tools/ from 49475796 (before Translator: v_floor/ceil/fract_f32 and v_cvt_flr_i32_f32 read an f32 denormal as zero, as RDNA2 does #2139), same GPU, three runs: 0/1, every run
    0xbf800000 0x3f800000 0x3f7fffff 0x0 0x7fffffff 0x7fffffff 0xffffffff 0x7fffffff.
    So on NVIDIA 7 of the 8 lanes catch the old translator: floor(-1e-45) = -1.0, ceil(+1e-45) = +1.0, fract(-1e-45) = 0x3f7fffff, cvt_flr_i32(-1e-45) = -1 (the driver keeps f32 denormals, as Translator: v_floor/ceil/fract_f32 and v_cvt_flr_i32_f32 read an f32 denormal as zero, as RDNA2 does #2139 says), and the NaN lanes come back as NVIDIA's canonical 0x7fffffff. Only fract(+1e-45) = 0 matches either way. This answers the "not checked on a GPU that keeps denormals" point above: the fixture discriminates there, more than on the RX 9070 (3 lanes).

Toolchain: llvm-mc 23.1.6 and SPIRV-Tools 2026.4 from conda-forge, Python 3.14.2. Synthetic fixtures only, no game files. AI-assisted (Claude).

@kapitche

Copy link
Copy Markdown
Contributor

Tested on Windows 11 with two GPUs on one machine (head merged with main f847748, MSVC 14.51, Python 3.13.1):

  • tests/test_shader_checks.py and tests/semantic/test_round_f32_denorm.py pass.
  • RTX 4080 SUPER: run_gpu_tests.py --filter round_f32_denorm: cs_round_f32_denorm PASS (0x80000000 0x0 0x0 0x0 0xffc00000 0xffc00000 0x0 0x7fa00000), 1/1.
  • Intel UHD 770 (VK_LOADER_DRIVERS_DISABLE=*nv*): the same words, PASS, 1/1.
  • Negative control: this PR adds a test and no translator change, so there is no fix to revert. With scripts/run_gpu_tests.py reverted to main the program is simply no longer run (0 programs matched), which shows the registration is what makes the fixture run.

The vk_* programs came from a runtime built from main. No concerns.

@crastinator

Copy link
Copy Markdown
Contributor

Tested 02df6ef merged into main f847748c (clean merge) on AMD Radeon RX 6700 XT (Navi 22, gfx1031, subgroup 32..64), RADV Mesa 26.3.1, CachyOS, Linux 7.3.5, GCC 16.2.1, llvm-mc 23.1.5: pass.

  • New test passes natively: cs_round_f32_denorm (0x80000000 0x0 0x0 0x0 0xffc00000 0xffc00000 0x0 0x7fa00000).
  • Whole run_gpu_tests.py: 186/200 native, 186/200 with LEONIDA_W64_EMULATE=1 (the skips are the D3D12-only fixtures and ps_w64x_readlane, as on main). ctest 41/41.
  • tests/semantic/test_round_f32_denorm.py, tests/test_shader_checks.py: 75 passed, 228 subtests passed.

No game files. AI-assisted (Claude Code).

…a denormal

No GPU test fed these ops an f32 denormal: ps_fnan_fract gives
v_fract_f32 a normal -1e-10, and nothing used floor, ceil or cvt_flr.
cs_round_f32_denorm runs eight of the rows measured natively on gfx1036
for ItsNotRexed#2139 (a denormal operand is a zero of its sign, fract(+-inf) is
0xffc00000, a signalling NaN passes through), one per lane, with the
operand picked per lane at run time and the result stored to memory.

Registered in check.py and run_gpu_tests.py, with a semantic fixture and
test_round_f32_denorm.py; test_shader_checks.py's fake vk_compute_test
knows its words. ItsNotRexed#2139's change is on main (0fe4e45, f0ea562). With
the translator from before it (4947579) the CPU test fails seven of
the eight lanes, with the "before" words of ItsNotRexed#2139's table, and an
RX 9070 fails three: fract(+-inf) and the signalling NaN (its driver
already flushes f32 denormals).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dandasma

Copy link
Copy Markdown
Contributor Author

Rebased on main aa2988c, which conflicted in tests/semantic/regen_fixtures.py (ps_vcmp_f32_nan, ps_vcmp_64, cs_w32_andn2_exec) and tests/test_shader_checks.py (main now counts the standalone cs_fmt_d16_xyz / cs_heap_init dumps, so the fixture count is now + 14); both sides are kept. Re-run on the RX 9070 with runtime/ rebuilt from that base: cs_round_f32_denorm 1/1 in three runs, the same words; regen_fixtures.py --check clean, test_round_f32_denorm.py OK, tests/test_shader_checks.py 75 OK (Python 3.12.10 and 3.14.2).

Thanks @vibryxcx, @sds-228, @ttd0x, @sperm, @MKmajster, @kapitche and @crastinator for the runs. @MKmajster's negative control on the RTX 3070 covers what the RX 9070 can't: that driver keeps f32 denormals, so 7 of the 8 lanes catch the translator from before #2139, where on the RX 9070 only 3 do (fract(±inf) and the signalling NaN).

@Etr0p

Etr0p commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 94381e1 (the head rebased on main aa2988cc) on NVIDIA GeForce RTX 5070 Ti Laptop GPU (Blackwell, 621.24, subgroup 32..32) and AMD Radeon 610M (RDNA2 iGPU, AMD 26.11.2 / 32.0.21045.29003, subgroup 32..64), Windows 11 Home 26200: pass.

Same laptop, one GPU at a time through LEONIDA_VK_DEVICE. Test programs rebuilt from this head with llvm-mingw 23.1.6; llvm-mc 23.1.6 (conda-forge), SPIRV-Tools v2026.4 (Vulkan SDK 1.4.363.0), Python 3.13.14.

scripts/run_gpu_tests.py Result cs_round_f32_denorm
RTX 5070 Ti Laptop, native 165/211 passed, 46 skipped, 0 failed PASS 0x80000000 0x0 0x0 0x0 0xffc00000 0xffc00000 0x0 0x7fa00000
RTX 5070 Ti Laptop, LEONIDA_W64_EMULATE=1 196/211 passed, 15 skipped, 0 failed PASS, the same words
Radeon 610M, native 190/211 passed, 21 skipped, 0 failed PASS, the same words

So an RDNA2 GPU on AMD's Windows driver and a Blackwell GPU give the eight words the fixture expects. 215 shaders translated, 215 pass spirv-val in each run. I did not run the CPU tests of this PR. One run of each. No game files. AI-assisted (Claude Code).

@Kev-Ball

Copy link
Copy Markdown

Tested 94381e15 on an NVIDIA GeForce RTX 3080 Ti (32-lane subgroups), driver 620.73.04, CachyOS Linux 7.3.5-2-cachyos. I rebuilt the Vulkan harnesses from this revision and selected the NVIDIA device explicitly.

Ran the PR’s synthetic fixture through scripts/run_gpu_tests.py --build runtime/build/linux --filter <fixture> --require-pass. The shader translated and passed Vulkan SPIR-V validation. GPU readback passed:

  • cs_round_f32_denorm — 0x80000000 0x0 0x0 0x0 0xffc00000 0xffc00000 0x0 0x7fa00000.

AI-assisted verification with synthetic inputs.

@lunarminus

Copy link
Copy Markdown

Tested 94381e15 merged onto main d0835dd9 on an AMD Radeon 760M (RDNA3 iGPU, gfx1103, subgroup 32..64), RADV Mesa 26.3.1, CachyOS Linux: pass

  • The merge was clean. The PR has no C++/CMake change, so the test programs (runtime/build/linux) come from a build of d0835dd9.
  • CPU tests:
    • python -m unittest discover -s tests/semantic -p 'test_round_f32_denorm.py': 1 OK
    • tests/test_shader_checks.py: 75 OK
    • tests/test_run_gpu_tests.py: 40 OK
    • tests/semantic/regen_fixtures.py --check: exit 0
  • Full scripts/run_gpu_tests.py, 215 shaders translated, all 215 pass spirv-val:
    • native: 197/211 passed, 14 skipped, 0 failed
    • LEONIDA_W64_EMULATE=1: 197/211 passed, 14 skipped, 0 failed
  • d0835dd9 without the PR, same machine: 196/210 with the same 14 skips in both modes (214 shaders). I compared every result line in both modes. The only difference is the new cs_round_f32_denorm, which passes in both modes with 0x80000000 0x0 0x0 0x0 0xffc00000 0xffc00000 0x0 0x7fa00000.
  • run_gpu_tests.py --filter cs_round_f32_denorm --require-pass: 1/1 in each of three runs, with the same eight words every time.
  • Negative control: on top of the merge I reverted Translator: v_floor/ceil/fract_f32 and v_cvt_flr_i32_f32 read an f32 denormal as zero, as RDNA2 does #2139 (0fe4e45 and f0ea562) in tools/rdna2spirv.py (its unit test test_alu_floor_ceil_fract_hw.py went with it) and ran native only.
    • GPU, three runs: 0/1 every time, with 0x80000000 0x0 0x3f7fffff 0x0 0xffc00000 0xffc00000 0x0 0x7fa00000. On this GPU only lane 2, fract(-1e-45), catches the old translator.
    • CPU, test_round_f32_denorm: 7 of the 8 lanes fail; lane 7 passes.

Synthetic fixtures only, no game files. AI-assisted (Claude Code).

DaniSBR1 added a commit to DaniSBR1/Leonida that referenced this pull request Nov 23, 2026
v_floor_f32, v_ceil_f32 and v_fract_f32 go through Gen.round_f32_flushed, which gives RDNA2's results for denormal
operands, Fract's round-up to 1.0, NaNs and infinities on any driver. That costs about six instructions per
v_fract on an RX 5700 XT and keeps the driver from folding them: a pixel shader of 2000 ops with v_fract among them
takes 1.71 ms against 0.33 ms for the same program in native SPIR-V.

On AMD the driver's own Floor/Ceil/Fract are the hardware instructions, so they already give those words. With
--native-rounding (opt-in; make_game.py --native-rounding, LEONIDA_NATIVE_ROUNDING=1 for the GPU test runners) the
three ops are plain GLSL Floor/Ceil/Fract. On an RX 5700 XT (RADV, Mesa 26.0.8):
- 48 of 48 edge-case words in compute (16 operands: denormals of both signs, -1e-10 and -1e-7 that round up,
  +-0, +-inf, quiet and signalling NaNs, large and ordinary values, through each op) and 16 of 16 v_fract words in
  a pixel shader equal the default translation;
- run_gpu_tests.py and check.py match the default per test (ps_fnan_fract passes), and so does ItsNotRexed#3299's
  cs_round_f32_denorm (gfx1036-measured words);
- the 2000-op shader goes from 1.71 ms to 0.53 ms, a v_fract-only one from 0.53 ms to 0.045 ms (= native).
On llvmpipe 5 of the 16 compute words differ, and ps_fnan_fract and cs_round_f32_denorm fail under the flag, which is
why it stays opt-in.

tests/semantic/test_native_rounding.py checks that the flag leaves only the GLSL function in the module and the
same words on ordinary operands.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@memorypressure

Copy link
Copy Markdown

Verified against main 3faac55: the branch merges with one trivial conflict — scripts/run_gpu_tests.py, where both sides append to the same test-name tuple (union resolves it). compileall is clean, tests/test_shader_checks.py passes, and the semantic cross-check test_round_f32_denorm.py runs green — one small fix first: it imports support before adjusting sys.path, so it fails under python -I on Python 3.14 until the usual insert line moves above the import. The cs_round_f32_denorm words come from RDNA2 hardware and could not be re-measured on this CPU-only host; the fixture chain (.asm -> regen_fixtures -> .s) is self-generated and clean. Overlap note: #3302 touches the same plumbing files. CI pending. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.