Skip to content

Tests: GPU checks for v_med3_f32/f16 with a NaN in S2 or in two operands (TEST-444) - #2646

Open
dandasma wants to merge 1 commit into
ItsNotRexed:mainfrom
dandasma:gpu-test-med3-nan
Open

dandasma wants to merge 1 commit into
ItsNotRexed:mainfrom
dandasma:gpu-test-med3-nan

Conversation

@dandasma

@dandasma dandasma commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: TEST-444 (#2300 (comment))

Rebased on main f847748: tests/semantic/regen_fixtures.py conflicted with the new ps_sdwa_dword_hi line, and both lines are kept. The numbers below are from that base unless noted.

What and why

#2029 (SHADER-361) changed how v_med3_f32 / v_med3_f16 handle a NaN in S2 or in two operands, but no GPU test fed those cases: ps_fnan_med3 only puts its NaN in S0, as @borislisandro noted in the #2029 review.

  • runtime/test/shaders/ps_fnan_med3_s2.asm (f32) and ps_f16_fnan_med3.asm (f16): four rows each, with the inputs read from memory at run time (5.0, 7.0, a quiet NaN, -2.5): med3(5, 7, NaN) and med3(NaN, NaN, 5), the two rows suggested in that review, then med3(NaN, -2.5, NaN) and med3(7, NaN, NaN). The expected words follow the rule measured on RDNA2 in docs/design.md ("Float min/max/med3 with NaN": with any NaN operand, med3 is min3 with the NaNs ignored); they are derived from that rule, not measured themselves. The all-NaN case is left out, since its payload is not modelled. The f16 destinations start as 0xaaaa5555, as in ps_f16_med3_opsel, so the kept high half shows.
  • Registered next to ps_fnan_fract in check.py and scripts/run_gpu_tests.py (expected words and the seeded heap), in tests/semantic/regen_fixtures.py with the generated fixtures, and in GpuFixtures of tests/semantic/test_float_nan_fract.py, which runs both through the translator and the interpreter. tests/semantic/README.md lists the two fixtures.
  • docs/design.md is unchanged.

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; test programs built from this branch (no C++ change), with LEONIDA_VK_DEVICE=9070.

  • run_gpu_tests.py --filter med3: 6/6 in three runs; ps_fnan_med3_s2 and ps_f16_fnan_med3 4096/4096 pixels exact each time, and the four existing med3 tests still pass.
  • build.py: 226 shaders translated, all pass spirv-val (main f847748: 224). check.py: 173 of 176 pass, 3 skipped (main: 171 of 174, the same skips).
  • Full run_gpu_tests.py: 187/201 passed, 14 skipped, 0 failed (main f847748: 185/199, the same 14 skips); the only difference is the two new tests.
  • Negative control (run before the rebase, on main 4947579): with rdna2spirv: avoid undefined FClamp on NaN in v_med3_f32 / v_med3_f16 #2029's tools/rdna2spirv.py change reverted, the two new GpuFixtures tests fail on the CPU (UnsupportedConstruct: GLSL.std.450 FClamp with these operands (undefined)), while test_ps_fnan_med3 passes. On the RX 9070 the GPU runs pass with the reverted translator too (3/3): its NaN select already discarded the undefined FClamp result on this driver. So these GPU tests pin the behaviour on hardware, but on this GPU they do not catch the pre-rdna2spirv: avoid undefined FClamp on NaN in v_med3_f32 / v_med3_f16 #2029 code; the CPU tests do.
  • CPU: python -I -m unittest discover -s tests/semantic 7324 tests OK (4 skipped, 1 expected failure; main: 7322), tests/test_shader_checks.py 70 OK, tests/test_run_gpu_tests.py 38 OK, tests/test_docs_links.py OK, regen_fixtures.py --check clean on Python 3.14.2 (WSL); test_float_nan_fract.py, test_shader_checks.py, test_run_gpu_tests.py and regen_fixtures.py --check also on 3.12.10 (Windows). git diff --check clean.

Note: #2437 (SHADER-186) adds ps_fnan_clamp at the same places in check.py, run_gpu_tests.py and regen_fixtures.py; whichever lands second needs a one-line rebase.

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

@tylerstraub

Copy link
Copy Markdown
Contributor

Tested 0dc4899dca45baa5a36ac1a5349039aa1da4f7d5 on NVIDIA GeForce RTX 5090, 595.99.02 (Linux).

Independent synthetic Vulkan check of 0dc4899dca45baa5a36ac1a5349039aa1da4f7d5 on Linux 7.0.0-43 (RTX 5090, NVIDIA 595.99.02, LLVM 21.1.8, SPIRV-Tools 2026.1).

  • All six --filter med3 cases passed. Each new fixture matched all 4,096 pixels: ps_fnan_med3_s2 gave 40a00000 40a00000 c0200000 40e00000, and ps_f16_fnan_med3 gave aaaa4500 aaaa4500 aaaac100 aaaa4700.
  • Reversing only rdna2spirv: avoid undefined FClamp on NaN in v_med3_f32 / v_med3_f16 #2029's translator changes still gave identical GPU readbacks and 6/6 passes on this NVIDIA driver, consistent with the AMD result in the PR. Both new CPU tests rejected the reverted shader's undefined FClamp operands. The earlier ps_fnan_med3 CPU case still passed.
  • SPIR-V validation passed in both runs. All three focused CPU tests and fixture regeneration passed on the PR head.

AI-assisted verification.

@Marukooh

Copy link
Copy Markdown
Contributor

Tested 0dc4899 on NVIDIA GeForce RTX 5070 Ti (Blackwell), NVIDIA 620.73.04, CachyOS Linux. Built the harness from this PR and ran scripts/run_gpu_tests.py --filter fnan_med3 with LEONIDA_W64_EMULATE=0 and =1. All three synthetic modules validated and matched 4,096/4,096 pixels in both runs, including the two new fixtures. The 21 test_float_nan_fract.py tests passed. AI-assisted.

@KiryaAfimin

KiryaAfimin commented Nov 22, 2026 •

Copy link
Copy Markdown

Tested 90f399e on Windows 11 with CMake 4.4.5. With Vulkan headers missing, the default configure warned and LEONIDA_REQUIRE_VULKAN=ON failed as expected.

After setting VULKAN_SDK, I reran CMake in the same build directory without deleting CMakeCache.txt. CMake found the headers on the next configure. This worked after both the warning and the strict-mode error. I then built and ran d3d12_vulkan_device on an RTX 4070 with Vulkan validation enabled, and it passed.

AI-assisted

@Yourrespawn

Copy link
Copy Markdown
Contributor

Tested 0dc4899d on NVIDIA GeForce RTX 4080 (Ada, subgroup 32..32), driver 617.14, Vulkan API 1.4.351, Windows 11 Pro 10.0.26200: pass.

  • run_gpu_tests.py: the two new fixtures pass on real hardware — ps_fnan_med3_s2 4096/4096 pixels exact (NaN in S2, the case rdna2spirv: avoid undefined FClamp on NaN in v_med3_f32 / v_med3_f16 #2029's review noted was GPU-untested) and ps_f16_fnan_med3 4096/4096 pixels exact (f16 two-operand NaN) — alongside the existing ps_fnan_med3 and ps_fnan_fract still exact; suite 141/187 passed, 46 skipped (native wave64, expected on this 32-lane GPU)
  • Semantic suite: 2569 OK (Python 3.12.10)

This closes the GPU-coverage gap left by #2029 (SHADER-361) cross-vendor on NVIDIA.

AI-assisted (ZCode agent): builds and runs executed by a coding agent on this machine.

@Rainmaker33

Copy link
Copy Markdown

Tested 0dc4899 on NVIDIA GeForce RTX 3090 (Ampere, subgroup 32..32), driver 610.88 (Vulkan 1.4.341), Windows 11 Pro 26300: pass.

The PR's diff applied cleanly to main 4947579. VS 2022, Vulkan SDK 1.4.363.0, llvm-mc 21.1.8; harness programs from a CMake build of that main; overlay layers off.

  • scripts/run_gpu_tests.py: 141/187 pass, 46 skipped (wave64), no failures (main: 139/185). ps_fnan_med3_s2 and ps_f16_fnan_med3: 4096/4096 pixels exact.
  • tests/semantic/test_float_nan_fract.py: OK.

@TurboSosiska304

Copy link
Copy Markdown

Tested 0dc4899 on AMD Radeon RX 570 (Polaris 10, gfx803), RADV Mesa 26.2.6-arch3.1, Vulkan 1.4.354, CachyOS; native 64-wide compute subgroups (64..64).

python3 -I scripts/run_gpu_tests.py --build runtime/build/linux --filter ps_fnan_med3
  PASS  ps_fnan_med3          4096/4096 pixels exact
  PASS  ps_fnan_med3_s2       4096/4096 pixels exact
2/2 passed

NaN in S2 and NaN in two operands both behave as the fixtures derive on GCN4, which is an older med3 unit than the RDNA2 the rule was measured on.

@dandasma

Copy link
Copy Markdown
Contributor Author

Rebased on main f847748, which conflicted in tests/semantic/regen_fixtures.py (the new ps_sdwa_dword_hi line; both kept). Re-run on the RX 9070 with programs built from that base: --filter med3 6/6 in three runs, the two new tests 4096/4096 pixels exact; full run_gpu_tests.py 187/201 with 14 skipped, against main's 185/199 with the same skips; semantic suite 7324 OK. Thanks @Yourrespawn, @Rainmaker33 and @TurboSosiska304 for the RTX 4080, RTX 3090 and RX 570 (GCN4) runs.

ps_fnan_med3 puts its NaN in S0 only, so no GPU test reached the cases
ps_fnan_med3_s2 (f32) and ps_f16_fnan_med3 (f16), with inputs read from
memory at run time and words derived from the measured rule in
docs/design.md (with any NaN operand, med3 is min3 with the NaNs
ignored). The all-NaN case is left out: its payload is not modelled.

Registered in check.py and run_gpu_tests.py; the semantic fixtures and
GpuFixtures tests run them through the interpreter, where the
translator before ItsNotRexed#2029 fails them (undefined FClamp on a NaN).

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

Copy link
Copy Markdown
Contributor Author

Rebased on main aa2988c, which conflicted in runtime/test/shaders/check.py and scripts/run_gpu_tests.py: main added the ps_vcmp_f32_nan / ps_vcmp_64 heap seeds right after ps_fnan_fract, where this PR adds its two; both are kept. Re-run on the RX 9070 with runtime/ rebuilt from that base: --filter med3 6/6 in three runs, the two new tests 4096/4096 pixels exact; regen_fixtures.py --check clean, test_float_nan_fract.py 26 OK, tests/test_shader_checks.py 75 OK (Python 3.12.10 and 3.14.2).

@throny

throny commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested ed91cd2 on NVIDIA RTX 4080, driver 610.88, Windows 11: pass

This is the head rebased on aa2988cc. Ran (MSVC 19.44 / VS 2022 BuildTools, Ninja, RelWithDebInfo, Vulkan SDK 1.4.363.0, native llvm-mc 23.1.6; test programs built from this branch):

  • python -I scripts/run_gpu_tests.py --filter med3, three runs: 6/6 each, with ps_fnan_med3_s2 and ps_f16_fnan_med3 4096/4096 pixels exact every time.
  • Full run_gpu_tests.py: 166/212 passed, 46 skipped, 0 failed.
  • python -I runtime/test/shaders/check.py <that work dir> <build>: 152 of 186 pass, 34 skipped, 0 failed; ps_fnan_med3, ps_fnan_med3_s2 and ps_f16_fnan_med3 ok.
  • CPU: test_float_nan_fract (run from tests/semantic), tests/test_run_gpu_tests.py and tests/test_shader_checks.py: OK.

Not run: the negative control with #2029's translator change reverted.

AI-assisted.

@TreXito

TreXito commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested ed91cd25 on NVIDIA GeForce RTX 3060 Ti (subgroup 32..32), driver 580.173.02, Linux (kernel 6.18), Python 3.14: pass.

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

@tunczzz

tunczzz commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested ed91cd25 (merge base aa2988cc) on an NVIDIA GeForce RTX 5070 Ti (Blackwell, subgroup 32..32), driver 616.56, Windows 11 10.0.26300. Translator and fixtures from this head; runtime test programs built from main aa2988cc (MSVC 19.44, Vulkan-Headers fetched by CMake, loader from the NVIDIA driver); spirv-as/spirv-val and llvm-mc 21 from WSL Ubuntu: pass.

  • scripts/run_gpu_tests.py: 166/212 passed, 46 skipped (wave64 programs on a 32-wide GPU), 0 failed.
  • Diffed test by test against main aa2988cc (164/210, 46 skipped): every main result is the same here.
  • New: ps_f16_fnan_med3 PASS (4096/4096 pixels exact).
  • New: ps_fnan_med3_s2 PASS (4096/4096 pixels exact).

Not run: LEONIDA_W64_EMULATE=1, other vendors, Linux. No game files.

AI-assisted (Claude Code).

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.

10 participants