upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/docs/shader_validation.md
diff options
context:
space:
mode:
authorEremia Brinzoi Razvan Andrei <razvaneremia04@gmail.com>2026-11-22 13:25:04 +0200
committerEremia Brinzoi Razvan Andrei <razvaneremia04@gmail.com>2026-11-22 13:25:04 +0200
commit013cfb3966885cb6b7b81d5708d4e2e1dfd16fe6 (patch)
tree48f09ee2b0f53a2416c16e66a3a95a994a884a77 /docs/shader_validation.md
parentc2967a5e60060e4068fb992196d8f4b494a5046c (diff)
tools: fma_mix_probe tells single from double f16 rounding of v_fma_mix
docs/design.md leaves one f16 question open: in round-to-nearest mode, does v_fma_mixlo/hi_f16 round the exact x * y + z once to f16, or to f32 first and then narrow? The translator does the second (f32 Fma, then f16_res). The RX 6800 word behind the toward-zero rule can't settle it, because 1 * 2 - 2^-30 gives 0x4000 under both readings in nearest mode. tools/fma_mix_probe.py has seven inputs where the two rules differ by one f16 ulp, plus a control: - ties just above and below, for both signs; - the subnormal tie at 2^-25; - the overflow tie at 65520; - a tie made by the product; - the same with f16 operands. It reports which rule each side follows: - the translator, on the CPU interpreter; - --oracle hw: the native instruction on an AMD GPU, through tools/hw_oracle, under the game's inferred MODE; - --oracle vulkan: the translated compute shader through vk_compute_test, with operands in user SGPRs so the driver can't fold them. tests/test_fma_mix_probe.py checks: - the expected words against a derivation written out by hand; - that the translator follows the double rule today; - that the compute listing gives the pixel shader's words; - the verdict and exit codes. On an RTX 5060 (621.24) the translated shader follows the translator's rule on all eight inputs. A translator copy that uses fma_mix_odd in nearest mode gives the single-rounded words on the CPU and on the GPU. That is the fix if AMD hardware turns out to round once. The translator itself is unchanged. AI-assisted (Claude Code). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'docs/shader_validation.md')
-rw-r--r--docs/shader_validation.md43
1 files changed, 43 insertions, 0 deletions
diff --git a/docs/shader_validation.md b/docs/shader_validation.md
index 1f6719176..5447785fd 100644
--- a/docs/shader_validation.md
+++ b/docs/shader_validation.md
@@ -784,6 +784,49 @@ reset in the kernel log.
784 inputs is computed once and stored in its own half (`tests/test_f16_trans_sweep.py`). On a GPU the test checks 784 inputs is computed once and stored in its own half (`tests/test_f16_trans_sweep.py`). On a GPU the test checks
785 exp2 of integers and wave32 = wave64. 785 exp2 of integers and wave32 = wave64.
786 786
787### `v_fma_mix*` f16 rounding in nearest mode (`tools/fma_mix_probe.py`)
788
789`docs/design.md` leaves one f16 question open. In round-to-nearest mode, does `v_fma_mixlo_f16` / `v_fma_mixhi_f16`
790round the exact x · y + z once, straight to f16? Or does it round to f32 first and then narrow, which is what the
791translator does (f32 `Fma`, then `f16_res`)? The RX 6800 word behind the toward-zero rule can't answer this. For
7921 · 2 - 2^-30 both readings give 0x4000 in nearest mode, and toward zero two truncations equal one.
793
794The two readings only differ when the f32 rounding lands exactly on an f16 tie, or moves a value off one. The probe has
795seven such inputs, each one f16 ulp apart under the two rules, plus one control:
796- a tie just above and just below, for both signs;
797- the subnormal tie at 2^-25;
798- the overflow tie at 65520 (inf against 65504);
799- a tie made by the product rather than by z;
800- the same with f16 operands (`op_sel_hi:[1,1,1]`).
801
802Every side reports which rule its words follow:
803
804```
805python -I tools/fma_mix_probe.py # the translator, on the CPU interpreter
806python -I tools/fma_mix_probe.py --oracle hw # also the native instruction on an AMD GPU (hardware oracle)
807python -I tools/fma_mix_probe.py --oracle vulkan --build runtime/build # also the translated shader on this GPU
808```
809
810The `hw` side is the measurement. It runs one wave32 lane per input, under the MODE inferred for the game: IEEE 0,
811DX10_CLAMP 1, f32 denormals flushed, f16 denormals kept, nearest. The `vulkan` side only shows that a driver runs the
812translator's sequence as written. Its operands come in user SGPRs, so the driver can't fold them. Exit 0 means every
813side follows the same rule. Exit 1 means they differ, or a side follows neither rule. Exit 77 means a requested side
814is unavailable.
815
816`tests/test_fma_mix_probe.py` checks the expected words against a derivation written out by hand. It also checks that
817the translator follows the double rule today, and that the compute shader gives the pixel shader's words on the
818interpreter. If the hardware rounds once, the fix is to use `Gen.fma_mix_odd` in nearest mode as well. Round-to-odd at
819f32 then narrows exactly. With that change the translator gives the single-rounded word on all seven inputs.
820
821Results:
822
823| GPU | Driver | `translator` | `vulkan` | `hw` |
824|---|---|---|---|---|
825| NVIDIA GeForce RTX 5060 (Blackwell), Windows 11 | 621.24 | double | double, 8 of 8 words | not AMD |
826
827The `hw` column is still empty: the question needs an RDNA GPU. On the RTX 5060, a translator copy changed to use
828`fma_mix_odd` in nearest mode gave the single-rounded word for all seven inputs on the `vulkan` side as well.
829
787## Coverage plan and cost 830## Coverage plan and cost
788 831
789Start with straight-line scalar/vector ALU because it is deterministic, needs no descriptors and 832Start with straight-line scalar/vector ALU because it is deterministic, needs no descriptors and