Repository navigation
Docs: SHADER-135 on RDNA2 (gfx1036): f16 omod and clamp, v_fma_mix* constants, NaNs, denormals and single rounding - #1722
Conversation
…onstants, NaNs, denormals and rounding Raw kernels through the hardware oracle on a gfx1036 iGPU (AMD Windows driver 32.0.21044.64, HIP backend), 1,385 programs in wave32 and wave64, identical words in both: - an omod on an f16 result (v_add/mul/fma/fmac/cvt/exp/rcp_f16) acts only with IEEE 0 and denorm_mode_16_64 = 0; omod comes before clamp; clamp gives +0 for -0 and, with DX10_CLAMP 1, for a NaN; - v_fma_mix* operands: a float inline constant is f32 or the f16 constant (zero high half) by op_sel_hi, an integer constant its 32-bit integer; denormals follow the mode of their own width; NaN payloads are kept; - v_fma_mixlo/mixhi_f16 round once (fma_mix_probe --oracle hw, 7 of 7 ties); - v_exp_f16 / v_log_f16 repeat gfx1031's sweep counts exactly. The translator is compared word for word and differs in five ways, listed in docs/shader_validation.md; none is fixed here. Docs only. AI-assisted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PedroNunes11
left a comment
There was a problem hiding this comment.
Reviewed 0906a75f3df32cc24f46714504092ab987d516b5 as a code read only — nothing run on a GPU, and none of the measured words reproduced. Docs-only diff, so I checked internal consistency and the references. The ten tools and tests the PR cites all exist (tools/fma_mix_probe.py, tools/f16_trans_sweep.py, tools/hw_oracle/{runner,asm}.py, tests/test_{fma_mix_probe,f16_hw_words,mode_round,shader_meta,shader_index}.py), the new shader_validation.md section does not collide with anything on main, and a0acd33d is current main.
The substance looks good to me, and the omod finding is the valuable part: that an f16 omod acts only with IEEE 0 and denorm_mode_16_64 = 0 puts a real fork in front of the translator, and the PR is right to state it and change no code. Listing the five differences without fixing any keeps the measurement separable from the decision. Three things on the text, in order:
1. design.md claims more agreement than shader_validation.md supports. The f16 inline constants row ends with "an integer constant is its 32-bit integer. The translator gives the same words". The new section scopes it to "the integer constants as f16 halves", and difference 4 says the opposite for an f32 operand: the integer constants 1 and 64 used as f32 are f32 denormals (0x00000001, 0x00000040), which the hardware flushes to a zero of its sign and the translator keeps. As written, a reader of the contract table concludes the translator matches on integer constants generally. Since design.md is the file quoted most, could the sentence carry the same qualifier the section has — same words for the float constants in every op_sel/op_sel_hi combination and for the integer constants as f16 halves, differing for an f32-operand denormal (difference 4)?
2. The "Known approximations" row still says mix rounding is unmeasured. It reads "Nearest-mode v_fma_mix* still rounds twice (f32 Fma, then narrow): main's behaviour, unmeasured. tools/fma_mix_probe.py --oracle hw measures it on an AMD GPU, with seven inputs where the two rules differ by one f16 ulp". This PR is that measurement (gfx1036, 7 of 7 ties single-rounded), and it updates the f16 rounding row and the results table but leaves this one as "unmeasured". Worth updating in the same PR so the three places agree.
3. Nit. The neighbouring rows mark the distance from the console — "an RX 6700 XT (gfx1031, not the console's gfx1013)", "an RX 6800 (gfx1030, not the console's gfx1013)". The new text says "an RDNA2 iGPU, gfx1036" without it. (SHADER-135 asked for gfx1030; gfx1036 is RDNA2 too and the PR names the part, so that reads fine to me — just the house caveat missing.)
One question, not a defect. The 1,385 programs are scripts over tools/hw_oracle that aren't in the PR, so the words can't be re-run on another RDNA2 part or checked independently — and this is now the largest measurement in shader_validation.md. The neighbouring rows lean on versioned fixtures instead (ps_f16_const, f16_trans_sweep.py). You already offered to add them as a tool: I think that is worth doing, if only so the next RDNA2 part can confirm the omod rule, which is the one with a translator decision hanging off it.
Nothing here blocks the measurement itself; 1 is the one I would want before it lands in the contract table.
AI-assisted review (Claude Code).
… one still off PROC-96: the Known approximations row still listed mix ops with the packs that round to nearest because the mode says so. SHADER-135 (#1722) measured v_fma_mixlo/mixhi_f16 on gfx1036: they round the exact x*y+z once in every mode, 7 of 7 discriminating tie inputs. The toward-zero path already does that; the nearest-even path narrows an f32 Fma, which is 1 f16 ulp off on ties until #1774 (SHADER-296) lands, so the row now says which of the two is the approximation instead of implying both are correct by construction. The f16 inline constants row needed no change: #1722 already replaced its "Not measured" note with the measured per-operand rule.
SHADER-135 (claim). Docs only.
What
RDNA2 measurements the contract table took from the manual or left open, using raw kernels through the hardware oracle (FUZZ-23). There are 1,385 hand-written programs, each run in wave32 and wave64, and the two wave sizes give the same word everywhere. The MODE is set through the kernel descriptor (IEEE, DX10_CLAMP,
denorm_mode_32,denorm_mode_16_64).denorm_mode_16_64 = 0. This coversv_add/mul/fma_f16,v_fmac_f16_e64,v_cvt_f16_f32_e64and alsov_exp/rcp_f16. With f16 denormals kept the omod does nothing. Where it acts, omod comes before clamp. Clamp turns -0 into +0, and a NaN into +0 under DX10_CLAMP 1.v_fma_mix*operands. A float inline constant is read as f32 or as the f16 constant (zero high half), depending onop_sel_hi, soop_selreads +0.0. An integer constant is its 32-bit integer. This closes the "Not measured" note in the f16 inline constants row.denorm_mode_16_64, f32 operands followdenorm_mode_32. NaN payloads are kept.v_fma_mix_f32keeps a signalling NaN with IEEE 0, andmixloquiets every NaN.v_fma_mixlo/mixhi_f16round once.tools/fma_mix_probe.py --oracle hwgives the single-rounded word on 7 of the 7 tie inputs. This fills the emptyhwcolumn of that table.v_exp_f16/v_log_f16.tools/f16_trans_sweep.pygives gfx1031's counts exactly.Each program was also translated and run on
spirv_mini_interp, then compared with the hardware under the MODE the translator assumes for the game. The translator differs in five ways: f16 omod, clamp of a NaN, mix rounding, unflushed f32 denormals in mix operands, and NaN payloads. Each is listed indocs/shader_validation.md. None is fixed here. The first one bears on #718 (adding omod tov_cvt_f16_f32). It also raises a corpus question: either the game flushes f16 denormals, or its f16 omods do nothing.Tested
maina0acd33.python -I tools/fma_mix_probe.py --oracle hw: translator double, hw single (exit 1, the sides disagree as expected).python -I tools/f16_trans_sweep.py --ops v_exp_f16,v_log_f16: exit 0, wave32 = wave64.tools/hw_oracleand are not part of this PR. Every instruction and word needed to reproduce them is in the new section. I can add them as a tool if that's wanted.python -m pytest tests/test_fma_mix_probe.py tests/test_f16_hw_words.py tests/test_mode_round.py tests/test_shader_meta.py tests/test_shader_index.py: 133 passed.No game files were used. AI-assisted.
🤖 Generated with Claude Code