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:
authorYaBulochka <157796093+YaBulochka@users.noreply.github.com>2026-11-23 06:19:54 +0300
committerYaBulochka <157796093+YaBulochka@users.noreply.github.com>2026-11-23 06:19:54 +0300
commit79dfd24a30f78e725427cc57962a873d2904919b (patch)
treedf9b2e2ae776d0eb5a0c239982221843faf64453 /docs/shader_validation.md
parent03b09a086592a197db64d91655c6e65c30764d96 (diff)
Typed buffer loads keep a half NaN's payload, measured on gfx1036
mem_diff found one class of mismatch: a 16_FLOAT/16_16_FLOAT/16_16_16_16_FLOAT typed buffer load of a half NaN. Measured natively on RDNA2 (gfx1036) with the new tools/f16_widen_probe.py, wave32 and wave64, MUBUF and MTBUF, formats 13, 29 and 71: the hardware widens a half NaN to f32 as sign | 0x7F800000 | (payload << 13), keeping the sign and the quiet bit exactly as the half has them (0x7ddb -> 0x7fbb6000, 0x7fe6 -> 0x7ffcc000, 0xffb2 -> 0xfff64000). Gen.decode_format decoded every half with UnpackHalf2x16, whose NaN result is undefined and which the interpreter canonicalises to 0x7fc00000, so the payload was lost. It now uses UnpackHalf2x16 for the non-NaN halves (an exact widening) and builds the NaN word from the bits with integer ops. v_cvt_f32_f16 was measured too: it quiets an sNaN with the payload kept (0x7ffb6000), which the typed load does not. mem_diff's reference used struct's '<e', which keeps the payload only from Python 3.14; f16_to_f32 pins the measured rule so the fuzzer is version independent. tests/semantic/test_buffer_f16_widen_hw.py pins the ten measured words for MUBUF and MTBUF and formats 13/29/71; tests/test_f16_widen_probe.py covers the probe (models, fake oracle, CLI); mem_diff --self-test now pins the rule too.
Diffstat (limited to 'docs/shader_validation.md')
-rw-r--r--docs/shader_validation.md47
1 files changed, 46 insertions, 1 deletions
diff --git a/docs/shader_validation.md b/docs/shader_validation.md
index b7fad4106..27b09a8ed 100644
--- a/docs/shader_validation.md
+++ b/docs/shader_validation.md
@@ -608,7 +608,10 @@ instruction. The reference decodes elements from the GFX10 format *name* in `too
608MUBUF repeats missing channels (*c* mod *n*) and DST_SEL 1 gives integer 1 for UINT/SINT and 1.0f 608MUBUF repeats missing channels (*c* mod *n*) and DST_SEL 1 gives integer 1 for UINT/SINT and 1.0f
609otherwise (SHADER-86, RX 6700). MTBUF loads return instruction-format channels in order, zero-fill 609otherwise (SHADER-86, RX 6700). MTBUF loads return instruction-format channels in order, zero-fill
610missing channels and return zero for an INVALID V# format (native gfx1036, wave32 and wave64). 610missing channels and return zero for an INVALID V# format (native gfx1036, wave32 and wave64).
611Elements are naturally aligned. 611Elements are naturally aligned. A half NaN widens to f32 with its payload shifted into the f32 mantissa
612and its sign and quiet bit unchanged (`f16_to_f32`, bit-level so the Python version cannot change it);
613the translator used to canonicalise it, which is the one class this fuzzer found
614(`docs/shader_validation.md`, "Widening a 16-bit float NaN in a typed buffer load").
612 615
613Over 5,000 programs the reference and translator match bit for bit; breaking the `16_16_SNORM` kind, the 616Over 5,000 programs the reference and translator match bit for bit; breaking the `16_16_SNORM` kind, the
614`8_8_8_8_UINT` widths or the DST_SEL order in the translator makes 33, 37 and 191 of 300 programs fail. 617`8_8_8_8_UINT` widths or the DST_SEL order in the translator makes 33, 37 and 191 of 300 programs fail.
@@ -1341,6 +1344,48 @@ Measured on an RX 6700 (gfx1031, AMD Windows driver 32.0.21045.29003, ROCm wheel
1341each value is staged once, and that the kernels assemble for gfx1031. A fake oracle plays the GPU to check the exit 1344each value is staged once, and that the kernels assemble for gfx1031. A fake oracle plays the GPU to check the exit
1342codes. On a GFX10 GPU the test runs UNORM8 and checks the controls. 1345codes. On a GFX10 GPU the test runs UNORM8 and checks the controls.
1343 1346
1347### Widening a 16-bit float NaN in a typed buffer load (`tools/f16_widen_probe.py`)
1348
1349A typed buffer load of a half NaN had never been measured: `tools/mem_diff.py` decoded 16_FLOAT with
1350`struct`'s `'<e'` (payload kept from Python 3.14, canonical before) while the translator decoded it with
1351`UnpackHalf2x16`, whose result for a NaN is undefined and which the mini interpreter canonicalises to
13520x7FC00000. The probe stages one half word with an untyped `buffer_store_dword`, waits, loads it with
1353`buffer_load_format_*` / `tbuffer_load_format_*`, waits, and stores the f32 lanes back.
1354
1355```
1356python -I tools/f16_widen_probe.py --json f16_widen.json # 380 kernels of one thread (190 per wave); exit 77 without the oracle
1357python -I tools/f16_widen_probe.py --self-test # the three candidate rules, no GPU
1358```
1359
1360- Formats 13 (`16_FLOAT`), 29 (`16_16_FLOAT`) and 71 (`16_16_16_16_FLOAT`), `buffer_` and `tbuffer_`
1361 forms, `_x`/`_xy`/`_xyzw`, wave32 and wave64. Every NaN word came back the same in every component of
1362 every format and form:
1363
1364 | half | f32 | |
1365 | --- | --- | --- |
1366 | 0x7ddb | 0x7fbb6000 | sNaN, payload kept, quiet bit still 0 |
1367 | 0x7fe6 | 0x7ffcc000 | qNaN |
1368 | 0x7fbb | 0x7ff76000 | |
1369 | 0xffb2 | 0xfff64000 | negative, sign kept |
1370 | 0x7fcb | 0x7ff96000 | |
1371 | 0xff96 | 0xfff2c000 | |
1372 | 0x7c01 | 0x7f802000 | sNaN, smallest payload |
1373 | 0xfc01 | 0xff802000 | |
1374 | 0x3c00 | 0x3f800000 | 1.0 |
1375 | 0xc000 | 0xc0000000 | −2.0 |
1376
1377- The rule is `sign | 0x7F800000 | (payload << 13)`: the sign is kept, the 10-bit payload moves into the
1378 f32 mantissa unchanged, and the quiet bit is **not** forced, so an sNaN stays signalling. The
1379 negative NaNs (for example 0xffb2 and 0xff96) keep their sign.
1380- `v_cvt_f32_f16` on the same halves (the instruction a driver lowers `UnpackHalf2x16` to) differs on an
1381 sNaN: 0x7ddb gives 0x7ffb6000 (quieted, payload kept) and 0x7c01 gives 0x7fc02000, while every qNaN is
1382 the same as the typed load. The translator therefore builds the NaN case from the bits with integer ops
1383 and uses `UnpackHalf2x16` only for the other halves, whose conversion is exact.
1384- Verdict: the hardware keeps the payload, so `mem_diff`'s Python 3.14 reference was right and the
1385 canonicalising translator was wrong. `mem_diff` now pins the rule in `f16_to_f32` (bit-level, Python
1386 version independent) and `tests/semantic/test_buffer_f16_widen_hw.py` pins the ten measured words for
1387 MUBUF and MTBUF, formats 13/29/71.
1388
1344### `image_get_resinfo` and `image_get_lod` (`tools/image_query_probe.py`, SHADER-388) 1389### `image_get_resinfo` and `image_get_lod` (`tools/image_query_probe.py`, SHADER-388)
1345 1390
1346`docs/design.md` ("Image atomics, size and LOD queries") took resinfo's depth word, the clamped LOD under a linear mip 1391`docs/design.md` ("Image atomics, size and LOD queries") took resinfo's depth word, the clamped LOD under a linear mip