Repository navigation
fract_f16_probe: v_fract_f16 rounds first, then the omod (SHADER-338) - #2198
Sanonymous01 wants to merge 2 commits into
Conversation
|
Tested fe42df5 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
|
|
Tested llvm-mc 21.1.8, Vulkan SDK 1.4.363.0. Test programs built with
No game data involved. AI-assisted (Claude Code): it ran everything above on this machine. |
On RDNA2 an omod (mul:2 / mul:4 / div:2) on an f16 result acts only with IEEE 0 and f16 denormals flushed. With f16 denormals kept, the MODE the translator assumes, the hardware leaves the result as it is (gfx1036 raw kernels, ItsNotRexed#1722). The translator scaled every f16 result anyway. Gen.clamp_f16 keeps the clamp and drops the omod. It replaces clamp_mods for the f16 results: v_fmac/fma_f16, v_med3/min3/max3_f16, the f16 VOP2 and VOP1 ops, v_sin/cos_f16, v_interp_p2_f16 and the mix ops (clamp only there). v_fract_f16 now always gets its 0x3c00 -> 0x3bff fix-up. The game decides nothing here. Over the 26,503 shaders of 1.0.2.1, none of the 201,864 f16-result instructions carries an omod (102,365 f32 ones do), and the only MODE writes are the 9,417 FP_ROUND ones. Translating the whole corpus before and after gives 26,503 byte-identical modules, all passing spirv-val. New GPU fixture ps_f16_omod: four words, the same as the gfx1036 raw kernel gives with f16 denormals kept (the scaled words with them flushed). The tests that expected the omod now follow the hardware. design.md also loses a stale duplicate of the v_fmac_f16 output-modifier row. AI-assisted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
docs/design.md left open in which order v_fract_f16 rounds and applies mul:2 / mul:4 / div:2. Measured on gfx1036 (RDNA2, raw kernels) over all 65,536 f16 inputs, no modifier, the three omods and each with clamp, in the four MODEs IEEE 0/1 x f16 denormals flushed/kept, wave32 plus a wave64 block each: 2,129,920 words, all reproduced by fract_f16_probe.rule(). - The fract is rounded to f16 first (with 0x3c00 -> 0x3bff), and the omod scales that: -2^-14 mul:2 gives 0x3fff, not 0x4000. - The omod acts only under IEEE 0 with f16 denormals flushed, as for the other f16 results; its product flushes below 2^-14 before rounding (0x07ff div:2 is +0). clamp comes last; a NaN gives +0. - fract(+-inf) is 0xfe00; an sNaN is quieted only under IEEE 1. In the MODE the translator assumes (f16 denormals kept) the omod is ignored, so with SHADER-297 (ItsNotRexed#1970, the first commit here) the translator gives every non-NaN word the hardware gives. tools/fract_f16_probe.py checks the rule against the translator and, with --oracle hw, the GPU; tests/test_fract_f16_probe.py runs without one. No translator change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
fe42df5 to
5653b18
Compare
|
Rebased on #1970's new head The conflicts were documentation only. In Tested on an RDNA2 iGPU (gfx1036), AMD driver 32.0.21044.64, Windows 11: pass.
|
SHADER-338 (claimed in #1902, listed in #2078). Depends on: #1970 (its commit is the first one here; this PR adds
fe42df58).docs/design.md("Float min/max/med3 with NaN,v_fract") left open in which orderv_fract_f16rounds and appliesmul:2/mul:4/div:2. This measures it exhaustively on RDNA2 and records the rule. There is no translator change: in the MODE the translator assumes, the modifier is ignored, which #1970 already implements.Measured (gfx1036, raw kernels through
tools/hw_oracle)All 65,536 f16 inputs × 8 forms (no modifier,
mul:2,mul:4,div:2, each also withclamp) × 4 MODEs (IEEE 0/1 ×denorm_mode_16_640/3, DX10_CLAMP 1), in wave32, plus one 1,024-input block per MODE and form in wave64. That is 2,129,920 words, andrule()in the newtools/fract_f16_probe.pyreproduces all of them:0x8400) gives0x3fff,0x43ffand0x37ffwithmul:2,mul:4anddiv:2. Scaling the exact 1 - 2^-15 and rounding once would give0x4000,0x4400and0x3800. 2,049 inputs tell the two orders apart.clampword for theclampforms.0x07ffwithdiv:2gives +0, not0x0400.clampcomes last and gives +0 for a NaN.0xfe00.The translator against the rule
The translator side runs in the MODE the translator assumes (IEEE 0, f16 denormals kept) through
spirv_mini_interp. With #1970,--allgives 516,096/516,096 words that follow the rule. Two kinds of words are not compared bit for bit:clampare left out, because the interpreter refusesFClampon a NaN (difference 2 indocs/shader_validation.md).Without #1970 (upstream
main), the translator scales the f32 fract before narrowing. That differs from the hardware on 51,199 inputs per modifier in the translator's MODE. Even against the MODE where the modifier acts, it differs on 4,095 to 5,118 non-NaN inputs.tests/test_fract_f16_probe.pyfails against that translator and passes with #1970.Files
tools/fract_f16_probe.py: the measured rule, with three sides:rule: 21 hand-worked rows.translator: a sample of inputs, or--all.hw: with--oracle hw, the full sweep above.tests/test_fract_f16_probe.py: the rule against hand-worked words, and the translator on one block of inputs (the negative denormals). It needs no GPU and runs in about 8 s.docs/design.md: the "not measured" sentence is replaced by the rule.docs/shader_validation.md: a new section "v_fract_f16with an output modifier on RDNA2 (SHADER-338)".#2139 edits the same
design.mdrow, on the f32 side. Whichever lands second needs a one-line rebase, and I'll do it here if needed.Testing
AI-assisted (Claude Code). No game files.
python -I tools/fract_f16_probe.py --oracle hw: rule 21/21, translator 26,208/26,208, hw 2,129,920/2,129,920, exit 0. Run on an AMD RDNA2 iGPU (gfx1036), AMD Windows driver 32.0.21044.64, Windows 11.python -I tools/fract_f16_probe.py --all: translator 516,096/516,096, exit 0.python -I tests/test_fract_f16_probe.py -v: 6/6. Against upstream's translator without Translator: no omod on f16 results, clamp kept, as RDNA2 with f16 denormals kept (SHADER-297) #1970 it fails, as intended.python -I -m unittest discover -s tests/semantic: 1,671 OK.pytest tests/test_f16_hw_words.py tests/test_fract_f16_probe.py tests/test_fma_mix_probe.py tests/test_docs_repo_paths.py: 69 passed.regen_fixtures.py --checkandcompileall: clean.🤖 Generated with Claude Code