Repository navigation
rdna2spirv: declare DenormPreserve 16 so a driver keeps f16 denormals (SHADER-526) - #3040
Conversation
… (SHADER-526) ps_sdwa_f16_const read mrt0 lane y as 0x0000 instead of 0x1c00 on NVIDIA: the _sdwa src0_sel:BYTE_1 selects the f16 denormal 0x0040 (2^-18), and the driver flushed it on the way into f32 because the module declared no 16-bit denormal mode. The translator models f16 arithmetic in f32 with integer narrowing, so no f32 denormal is involved and that conversion is what the 16-bit mode governs. Every module now also emits OpExecutionMode %main DenormPreserve 16 with the matching capability (core since SPIR-V 1.4, so no extension), and the index lists shaderDenormPreserveFloat16, which vk_pipeline_check requires and --no-float-controls still drops along with the 32-bit mode. Tested on an RTX 4070 SUPER (driver 610.88, validation layers on): the GPU test goes from 4096/4096 mismatches to 4096/4096 pixels exact, and the full GPU suite from 142/189 to 143/189 passed with 0 failures and the same 46 skips. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
|
Tested Independent Linux Vulkan check of Both fragment modules passed AI-assisted verification. |
|
Tested
gfx1151 is RDNA 3.5, not RDNA2: this shows the translated SPIR-V gives the modelled words on a real driver, not that RDNA2 hardware does. AI-assisted (Claude Code). |
|
Independent Windows/NVIDIA confirmation of SHADER-526 on a GeForce RTX 4060 Ti, driver 610.88: on upstream main Reference-only fork branch: https://github.com/pmilewsskiedu-gif/Leonida/tree/alternative/f16-subnormal-integer-widening (single commit On RTX 4060 Ti: 144 targeted CPU tests pass; 10 focused Vulkan fixtures match 40,960/40,960 pixels; complete synthetic suite 194/194 SPIR-V modules validated, 143 GPU pass, 46 skip, 0 fail, validation on. Independent review exhaustively checked all 2,048 signed exponent-zero half values. Limit: this alternative only changes |
|
Tested a094bd2 on the machine from the finding: NVIDIA GeForce RTX 3090 (Ampere, subgroup 32..32), driver 610.88 (Vulkan 1.4.341), Windows 11 Pro 26300. pass: it fixes The PR's diff applied cleanly to
|
|
Tested
The root-cause reasoning holds on this machine: without the declaration the driver flushes the f16 denormal on the load path, with it the bits survive end to end. AI-assisted (ZCode agent): builds and runs executed by a coding agent on this machine. |
|
Tested a094bd2 on NVIDIA RTX 5060 Ti (Blackwell), subgroup 32..32, NVIDIA 621.01 (Vulkan 1.4.357), Windows 11: pass.
Tools: llvm-mc 23.1.6 (conda-forge, native Windows), Vulkan SDK 1.4.363.0 ( AI-assisted (Qoder): I built the tools, ran the GPU suite and the CPU test. |
|
I confirmed this on a driver that flushes: GTX 1050 Ti (Pascal), NVIDIA 582.78, Windows 11. The driver reports
In both runs, Synthetic shaders only. AI-assisted (Claude Code). |
Kam471
left a comment
There was a problem hiding this comment.
Verified on the PR head: tests/semantic/test_f16_denorm_preserve.py -> 6/6 passed; test_translate.py -k float_controls -> 3 passed, 542 deselected. On current main the new test fails 3/6 (capability + mode, index property, mode + words). The assembled binary carries OpCapability DenormPreserve and OpExecutionMode %main DenormPreserve with the single literal 0x10 = 16, no 32/64 preserve, and the existing SignedZeroInfNanPreserve 32 is unchanged; spirv-val --target-env vulkan1.2 passes. Across 33 translated fixtures, deleting only the two *DenormPreserve* lines leaves the output byte-identical, so f32/f64 behavior is unchanged. No game data or absolute paths. Approve.
|
Tested The device reports
AI-assisted (Claude Code). Synthetic test shaders only, no game files. |
|
Tested
Synthetic fixtures only, no game data. AI-assisted (Claude Code). |
Claim: SHADER-526 — claimed in the coordination issue #2891, from @Rainmaker33's finding.
Root cause
Since #2209,
ps_sdwa_f16_constreads lane y ofmrt0as0xaaaa0000instead of0xaaaa1c00on some NVIDIA builds: 4096/4096 pixels wrong, the other three lanes right.The instruction is
v_mul_f16_sdwa v3, 2.0, v1 src0_sel:BYTE_1 src1_sel:WORD_1.2.0as an f16 inline constant is0x00004000, soBYTE_1selects0x0040, the f16 denormal 2^-18; times1024.0that is 2^-8 =0x1c00. The SDWA select itself is right — the same lanes match on AMD RDNA2 and on NVIDIA builds that do not flush — so the value reaching the multiply is the only thing that differs.The translator models f16 arithmetic in f32 (
Gen.f16_bits: the halves are unpacked withUnpackHalf2x16, the op runs in f32, and the result is narrowed with integer shifts and adds), so no f32 denormal is involved anywhere in the module. What the driver decides is the float-controls mode of the 16-bit conversion it emits for the unpack. Every module declaredSignedZeroInfNanPreserve 32only; with no 16-bit denormal mode, NVIDIA flushed that conversion to +0 and the multiply returned +0.DenormPreserve 16is the mode that governs it.Assembling the same translated module with only the two
DenormPreservelines removed puts0xaaaa0000back, so it is the mode the driver honours, not anything in the generated code (see Testing).Changes
tools/rdna2spirv.py: the float-controls block now addsOpCapability DenormPreservenext toSignedZeroInfNanPreserveand emitsOpExecutionMode %main DenormPreserve 16next toSignedZeroInfNanPreserve 32. Both are core since SPIR-V 1.4, so no extension is needed at--target-env vulkan1.2. The index entry'sfloat_controlslist gains"shaderDenormPreserveFloat16", the device property the mode needs.--no-float-controlsstill drops both, and its help text now says so.runtime/test/vk_pipeline_check.cpp: the property loop knowsshaderDenormPreserveFloat16, so a device that reports it false skips the shader (rather than failing pipeline creation) exactly as it does forshaderSignedZeroInfNanPreserveFloat32. Unknown names still fail.make_game.py: the--no-float-controlshelp text names both properties.tests/test_translate.py: the declared-modes test expects both capability/mode pairs and both index properties (ps and cs).tests/semantic/test_f16_denorm_preserve.py(new, standard library only): pins the capability and the execution mode, the index property, the--no-float-controlsfallback, that the mode changes nothing but the header, the fourps_sdwa_f16_constwords through the interpreter, and that SPIRV-Tools accepts the module atvulkan1.2.docs/design.md: a "Float controls (f16 denormals) (SHADER-526)" contract row with the measurement, the fallback, and what was verified on which device.No new
.asmfixture: the rule is a module-header rule, and the value side already has the GPU fixture it protects (runtime/test/shaders/ps_sdwa_f16_const.asm, measured on gfx1036 and already atests/semanticfixture). The new test module pins mode and words together instead.Fallback where the device cannot preserve:
vk_pipeline_checkskips such a shader, and--no-float-controlstranslates without either mode. The module then has no f16 denormal guarantee, so an f16 denormal read can come back +0 — which is exactly the lane above on the NVIDIA builds that flush, and it is a difference in the shader's values, not something the translator can repair.Not every NVIDIA build flushes (so the test passing on
mainis not a contradiction): onmainwithout the mode, an RTX 4060 Ti (621.24), an RTX 5070 Ti (620.73.04, Linux) and an RTX 5080 (616.92) pass the test (data points from @airp1ane and @Marukooh). This change does not make those worse: they already keep the denormal, and the mode is a no-op there.Testing
Hardware: NVIDIA GeForce RTX 4070 SUPER, driver 610.88, Windows 11,
apiVersion 1.4.341(Vulkan SDK 1.4.363); AMD Radeon iGPU (Ryzen 5 7600, RDNA2), Windows driver 24.10.24,apiVersion 1.3.280.ps_sdwa_f16_const:origin/maintranslator, before the change0xaaaa0000, want0xaaaa1c00LEONIDA_VK_VALIDATION=1(no validation errors)Isolation, on the same module and the same harness (the three variants differ only in which float-controls lines the header carries): no modes at all → lane y
0x0000;SignedZeroInfNanPreserve 32only (whatmainemits) →0x0000; both modes →0x1c00. So the 16-bit mode is the operative part.Full GPU suite on the RTX 4070 SUPER with validation on: 143/189 passed, 46 skipped, 0 failed with the change (on the same build and GPU with the
origin/main(1628210) translator: 142/189 passed, 46 skipped (the one failure beingps_sdwa_f16_const), so the change moves exactly one test from fail to pass and changes nothing else).The new module alone,
python -I -m unittest discover -s tests/semantic -p test_f16_denorm_preserve.py:Ran 6 tests ... OK. The wholetests/semanticdiscovery run did not finish before this PR was opened: the machine was shared with other agents' builds and it was still running after 25 minutes, so it is not claimed here.3 passed, 542 deselected—test_float_controls_declared[ps],[cs]andtest_no_float_controls_leaves_them_out.vk_pipeline_checkon the AMD Radeon iGPU (which accepts the new module and pipeline even though itsdenormBehaviorIndependenceis32_BIT_ONLY):The GPU test itself skips on that iGPU (it needs 144 push-constant bytes; the device has 128), so no pixel result is claimed from AMD hardware.
spirv-val --target-env vulkan1.2passes on the translated module, which the new semantic test checks.Not verified: an NVIDIA build that actually flushes is only available to me as the RTX 4070 SUPER (which does flush); I could not run an RTX 3090, 4060 Ti or 5070 Ti myself.
🤖 Generated with Capy (DeepSeek V4.1 Flash)