Skip to content

Translator: make FP32-only shaders usable without FP16 denormal support - #4296

Open
ligmaSec wants to merge 3 commits into
ItsNotRexed:mainfrom
ligmaSec:shader/denorm16-when-used
Open

ligmaSec wants to merge 3 commits into
ItsNotRexed:mainfrom
ligmaSec:shader/denorm16-when-used

Conversation

@ligmaSec

@ligmaSec ligmaSec commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Coordination claim · Comparison with the half-float work · Linux reproduction

The translator currently adds DenormPreserve 16 to every module. On llvmpipe 25.0.7, that makes shaders with no half-float operations fail Vulkan validation and makes vk_pipeline_check skip them. The change emits the mode and its capability when the completed SPIR-V contains a half conversion, quantization, or an FP16 type. The shader index derives its requirements from the emitted capabilities, and FP32 signed-zero and NaN handling is preserved. Inspecting the completed module includes conversions generated in epilogues.

Verification on the original base

  • All three synthetic shaders assembled and passed spirv-val with LLVM 21.1.8. The native checker on Mesa 25.0.7 llvmpipe compiled both FP32 pipelines after the change. Previously it skipped both. It still reports that the half-float regression shader requires shaderDenormPreserveFloat16.
  • The mapped M1.5 draw under Wine 10 matched all 4,096 expected pixels using the retranslated shaders. Linux-side Khronos validation loaded and emitted zero validation errors. The original FP16 regression shader ps_sdwa_f16_const.spv was byte-for-byte identical.
  • tests/test_translate.py reported 581 passed and four skips. All seven targeted FP16 semantic tests passed. The new FP32 regression fails against the unmodified translator as expected.
  • The full semantic comparison completed with 7,456 tests on baseline aa2988c and 7,457 with the new regression test. Both runs reported the same eight failures, two errors, one skip and one expected failure. The failure and error case names match exactly.

AI-assisted. Software Vulkan, Xvfb, and synthetic shaders only.

Current integration check

Translator and runtime verified together on synthetic shaders from this checkout. Rebuilt against main 561b65a8 with CI’s Python 3.12 (3.12.16), LLVM AMDGPU 21.1.8, SPIRV-Tools v2026.4, and the project’s Vulkan-Headers tag vulkan-sdk-1.4.363.0. The Windows runtime was cross-built with clang-cl 21.1.8.

  • 652 targeted Python tests passed, including the mixed FP16/FP64 case. The native shader-library CTest passed.
  • Mesa llvmpipe 25.0.7 compiled the two FP32 pipelines and the FP64 pipeline. The FP16 fixture was skipped with the missing property named. Mesa RADV 26.3.1 under its GFX1201 DRM shim compiled all four pipelines, including the FP16 fixture (compiler coverage only).
  • Under Wine 10 on llvmpipe, the runtime rejected the original M1.5 and M4 fixtures by name. With the regenerated fixtures, the draw test accepted all 4,096 pixels, including its 32 edge pixels, and the compute test matched all 1,924 reference words. The Khronos validation layer was active with synchronization validation, with zero validation errors in either path.
  • The Windows compute test also passed under Wine and exercised rejection of an unknown float control. Its native Microsoft D3D12 CachedPSO reference comparison was skipped on Wine.

Full synthetic GPU fixture comparison

Compared main 561b65a8 with translator eaaa04e2, using the same LLVM 21.1.8, SPIRV-Tools v2026.4, runtime checker and driver for each pair. Each translation produced the same 237 shader names from 238 inputs, and all 237 passed spirv-val in both runs.

Pipeline checker Original translations Revised translations
Mesa 25.0.7 llvmpipe 0 compiled, 237 skipped 164 compiled, 73 skipped
Mesa 26.1.6 llvmpipe 0 compiled, 237 skipped 166 compiled, 71 skipped
Mesa 26.3.1 RADV GFX1201 DRM shim 237 compiled 237 compiled

All three configurations completed without a pipeline creation failure. The 73 remaining Mesa 25.0.7 skips name the missing feature (67 FP16 denormal preservation, four fragment barycentrics, two minimum LOD). All 67 modules that retain the FP16 requirement are byte-for-byte identical. The RADV results cover driver compilation only.

The separate native GPU execution harness returned the same result for every case on llvmpipe before and after. It reported 153 passed, 78 skipped, and one failure in ms_wave_info_s3, which has identical SPIR-V on both revisions. With WineHQ Stable 11.0 and Khronos validation, the revised M1.5 graphics and M4 compute fixtures also passed, and the runtime rejected the original overdeclared fixtures before pipeline creation.

With #5741 applied on top, the mesh regression also passed. All 232 GPU cases completed without an unexpected failure on both software drivers (154 passed and 78 skipped on Mesa 25.0.7, 157 passed and 75 skipped on Mesa 26.1.6). The new Mesa driver also passed the M1.5 and M4 Windows runtime checks under WineHQ Stable 11.0. Independent reproduction for the Arc report.

The complete semantic suite ran under Python 3.12.16 with the SPIRV-Tools v2026.4 assembler, validator, optimizer and disassembler. Baseline 561b65a8 ran 6,150 tests. Translator 27667711 ran 6,151. Both finished with zero unexpected failures and the same one expected failure. The updated integer-to-double test still checks the exact output words after optimization.

@Kam471 Kam471 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ran this at 6e5f46eb on Windows 11 with LLVM 21 and the SDK tools:

  • python tests/semantic/test_f16_denorm_preserve.py -> 7 tests, OK.
  • pytest tests/test_translate.py -q -> 581 passed, 4 skipped (53.8 s).
  • compileall and git diff --check clean.

The translator now requires DenormPreserve 16/the FP16 denormal feature only for modules that actually use 16-bit float, so an FP32-only shader is usable on a device without FP16 denormal support; the existing translation suite and the new semantic cases pass. No blocking issue.

@tylerstraub

Copy link
Copy Markdown
Contributor

Tested 6e5f46eb7634535294732ffb34654455d3307779 on NVIDIA GeForce RTX 5090, 595.99.02 (Linux).

At 6e5f46eb on Linux I drew three synthetic fragment shaders on the RTX 5090 (595.99.02), disassembled their generated SPIR-V, and compared every RGBA word with the fixture expectations.

Fragment shader DenormPreserve 16 and capability RTX 5090 readback
ps_fma_literal, FP32 multiply-add absent 4,096/4,096 exact
ps_f32_mods, includes v_cvt_f32_f16 present 4,096/4,096 exact
ps_sdwa_f16_const, half-denormal regression present 4,096/4,096 exact

All three retained SignedZeroInfNanPreserve 32 and passed spirv-val. I then drew ps_fma_literal on llvmpipe (Mesa 26.0.8, LLVM 21.1.8), which reports shaderDenormPreserveFloat16=false. Its entire 65,536-byte frame matched the RTX 5090 frame. This covers fragment output on the PR head, including a mixed-precision fixture whose conversion still needs the FP16 mode.

AI-assisted (Codex).

AI-assisted verification.

@shdann

shdann commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 6e5f46e on Windows 11 with AMD Radeon(TM) Graphics (driver 32.0.21043.5001) and NVIDIA GeForce RTX 4090 (driver 32.0.16.2101): pass. This adds an AMD result and a Windows result to the RTX 5090 result above. The build has no validation layers.

I rendered a plain fragment shader and the ps_sdwa_f16_const fixture with vk_harness.exe vs.spv fs.spv out.raw, with a synthetic full-screen vertex shader and LEONIDA_VK_DEVICE set to each GPU.
On the two GPUs, each draw matches all four expected words in all 4096 pixels.

The translator of main 03b09a08 lists shaderDenormPreserveFloat16 for the plain shader. This head does not list it.
These GPUs do not show the behaviour on llvmpipe. AI-assisted.

@Flyander Flyander left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The conditional mode detection examines completed SPIR-V, including generated epilogues, and keeps the FP32 signed-zero/NaN mode intact. Current evidence covers FP32-only, mixed and FP16-regression shaders across llvmpipe, NVIDIA and AMD, with the translation suites passing. No blocking issue found.

@fromthemoonx

Copy link
Copy Markdown

Tested 6e5f46e (merged onto main 03b09a0) on NVIDIA GeForce RTX 3060 12 GB (Ampere), driver 610.88, Windows 11 Pro 26300, MSVC (VS 2022 Build Tools, scripts\build_runtime.ps1, RelWithDebInfo), Vulkan loader 1.4.363, SPIRV-Tools 2026.4, llvm-mc 23.1.6 (conda-forge): pass. This is a whole-suite regression check, to go with the targeted draws above.

  • py -3.12 -I scripts\run_gpu_tests.py: 214/214 translated, 214 pass spirv-val. GPU: 164/210 passed, 0 failed, 46 skipped. All 46 skips are the expected ones on a 32-wide device: 31 need a native 64-wide subgroup, and 15 are run by the d3d12_* ctest programs instead.
  • ctest --test-dir runtime\build: 154/154 passed. The 10 that don't run need game files or an optional setup: corpus, bink, fsr, bvh_builder, gameinput, vk_sync_validation, rgb9e5, first_light.
  • Same pass/skip counts as my baseline of plain main (aa2988c) on this machine, so nothing regressed on Ampere. One caveat: this GPU supports shaderDenormPreserveFloat16, so it doesn't exercise the llvmpipe case the PR fixes.

AI-assisted (Claude). No game files.

@theswiss24

Copy link
Copy Markdown

Tested 6e5f46eb (contains main 03b09a08) on NVIDIA GeForce RTX 4070 (Ada), driver 621.24, Windows 11 (26300), Python 3.14.2, Vulkan SDK 1.4.363.1, llvm-mc 21.1.8, with test programs built from main 03b09a08: pass. This device supports FP16 denormals, so this run checks that nothing regresses where DenormPreserve 16 was already fine.

  • python -I -m unittest discover -s tests/semantic -p test_f16_denorm_preserve.py: 7 tests, OK.
  • LEONIDA_W64_EMULATE=1 python -I scripts/run_gpu_tests.py --build <main build>: 195/210 passed, 15 skipped, 0 failed, the same result on every test as main 03b09a08.

I did not run tests/test_translate.py, which needs pytest. No game files.

AI-assisted (Claude Code).

@tylerstraub

Copy link
Copy Markdown
Contributor

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

Both synthetic fragment draws matched all 4,096 pixels. The unmodified FP32 fixture ps_fma_literal declared only SignedZeroInfNanPreserve 32 among the inspected float-control modes.

For the mixed-width draw I added two operations with observable outputs: binary64 -0 + -0 and conversion of the smallest positive binary16 subnormal to binary32. The disassembly retained SignedZeroInfNanPreserve 32, SignedZeroInfNanPreserve 64, and DenormPreserve 16. Every pixel contained the double's low/high words 0x00000000 / 0x80000000 and the converted value 0x33800000 (2⁻²⁴). Both modules passed SPIR-V validation.

This checks the emitted requirements and readbacks on hardware supporting the modes. Device-side rejection when FP16 denormal preservation is unavailable was outside this run.

AI-assisted verification.

@tylerstraub

Copy link
Copy Markdown
Contributor

Tested 276677115206a9b4baf8af83ad8e197107617b44 on NVIDIA GeForce RTX 5090, 595.99.02 (Linux).

I passed the same two synthetic fragment modules to vk_pipeline_check on both Linux drivers. The FP32-only module compiled on the RTX 5090 and on llvmpipe (LLVM 21.1.8, subgroup 8). The mixed FP16/FP32/FP64 module compiled on the RTX 5090. On llvmpipe the checker skipped that pipeline with the specific reason no shaderDenormPreserveFloat16. Neither driver reported a pipeline compilation failure.

Both RTX draws matched all 4,096 expected pixels. The mixed draw preserved the sign of binary64 negative zero and converted the smallest positive binary16 subnormal to binary32 bits 0x33800000. The revised test_int32_to_f64.py also passed all three tests.

AI-assisted verification.

@kapitche

Copy link
Copy Markdown
Contributor

Tested 2766771 merged with main 1cc6e3c on Linux/Python 3.12.16: concern (conflicts with current main)

Against 1cc6e3c the merge is clean. Ran tests/test_f64_float_controls.py (OK) and the semantic tests test_f16_denorm_preserve, test_int32_to_f64, test_f64_round, test_cmp_class_f32_mods and test_f32_valu (OK; four of them have one skipped case because spirv-as/spirv-val are not installed here). Negative control: restoring tools/rdna2spirv.py from 1cc6e3c makes test_f16_denorm_preserve fail (1 failure) and test_f64_float_controls fail (2 failures); restored, they pass. test_translate.py skips entirely here (638 skipped). The full semantic suite did not finish inside my 20 minute limit, so it was not run to completion. Nothing GPU-bound was run.

Concern: against current main a66e6e3 the merge conflicts in docs/design.md (the float controls rows, around line 359). Needs a rebase.

Redundancy: not superseded. It narrows the DenormPreserve 16 mode introduced by #3040 (a094bd2); #4988 (open) also touches DenormPreserve 16 in the GPU runners, so the two should be checked against each other.

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.

8 participants