Raw buffer_load_format_xyzw, tbuffer_load_format_xyzw and buffer_store_format_xyzw / tbuffer_store_format_xyzw kernels per format on the AMD GPU (tools/hw_oracle), compared word for word with a CPU model. Formats are mapped by name because GFX11 numbers them differently; the twelve 10_11_11 / 11_11_10 non-FLOAT codes and the two SCALED 10_10_10_2 codes have no GFX11 spelling. On a Radeon 880M (gfx1150, RDNA3.5, not RDNA2): 1,264,744 elements over 63 formats, V# and tbuffer, loads and stores, 0 mismatches; --negative-control shows a wrong V# format is caught. docs/buffer_formats.md records the measured rules (SCALED stores convert as NORM, float stores round toward zero and saturate, a 2-bit SNORM half rounds away, NaN payloads, channel fill) and where the translator's older stores differ. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
12 KiB
Typed buffer formats: every GFX10 code a V# or MTBUF can name
What buffer_load_format_*, buffer_store_format_* and tbuffer_load_format_* do for each GFX10 buffer data format
(V# word 3 FORMAT [18:12], or the format: modifier of an MTBUF instruction), measured on a Radeon 880M and held
against the translator. The contract row is "Typed buffer formats" in design.md; the code is
Gen.FORMATS, Gen.decode_format and Gen.encode_format in tools/rdna2spirv.py; the oracle is
tools/buffer_format_fuzz.py.
Read this first: the GPU is not RDNA2. The only local AMD part is the Radeon 880M (gfx1150, RDNA3.5, GFX11). GFX11
numbers its formats differently (8_8_8_8_UNORM is 56 on GFX10 and 42 on GFX11), so every format is mapped by name
(GFX11_CODES in the tool, taken from what the AMD assembler encodes for format:[BUF_FMT_<name>]). A match supports
the model on RDNA3.5. Where this repository measured RDNA2 itself (UINT saturation and UNORM/SNORM rounding on gfx1036,
the xy/xyz stores on a Radeon 680M) the two agree; everything else is "GFX11, believed to carry over".
Which codes there are
GFX10's FORMAT is 7 bits, so a buffer can carry codes 1..77 (the table in tools/gfx10_formats.json goes to 292
because images use 9 bits; 128 and up are image-only: sRGB, BC, depth, 5_6_5, 1_5_5_5, 5_5_5_1, 4_4_4_4, 5_9_9_9, 6E4).
There are no 5_6_5-style formats for buffers. Of the 77:
- 65 are in
Gen.FORMATS: every f32/u32/i32 code, the 8/16-bit and 8_8/16_16/8_8_8_8/16_16_16_16 families in all of UNORM, SNORM, USCALED, SSCALED, UINT, SINT (and FLOAT for 16-bit), 10_11_11_FLOAT (36), 11_11_10_FLOAT (43) and the 10_10_10_2 (44..49) and 2_10_10_10 (50..55) families in all six numeric formats. - 12 are not: 10_11_11 and 11_11_10 with UNORM, SNORM, USCALED, SSCALED, UINT and SINT (codes 30..35 and 37..42). GFX11 has none of them (its 10_11_11 and 11_11_10 are FLOAT only), so there is nothing to measure them against, and a guess at what a 5-bit-exponent field "normalized" to would be worse than the 0 a shader gets now. They decode to 0 and store nothing, as every code outside the table does.
Of the 65, the 880M can run 63 (GFX11 has no 10_10_10_2_USCALED / SSCALED, codes 46 and 47; their layout is that of the measured 10_10_10_2 and 2_10_10_10 siblings, and their SCALED conversion is the measured one).
Names and bit order
Names list the component widths from the top bit down, so the last number is x in bit 0: 2_10_10_10 (50) is
R10G10B10A2 with x in bits 9:0 and a 2-bit alpha on top, 10_10_10_2 (44) has a 2-bit x. 10_11_11_FLOAT (36) is x =
11 bits [10:0], y = 11 bits [21:11], z = 10 bits [31:22]; 11_11_10_FLOAT (43) is x = 10 bits, y and z 11 bits each.
The 880M confirmed all of these.
Loads (measured)
Every result word of an xyzw load of 63 formats, through a V# (DST_SEL = XYZW) and through tbuffer's own format
(with a V# that names 32_FLOAT), equals the model below. Per format: every value of every field up to 12 bits (and all
65,536 half floats), edge values (0, 1, max, signed min and its neighbours), random values above that, and random bytes
past the element.
| Format class | Result |
|---|---|
| UNORM | correctly rounded f32 of x / (2ⁿ−1) |
| SNORM | correctly rounded x / (2ⁿ⁻¹−1); the most negative code is −1.0 |
| USCALED / SSCALED | the integer, as a float, not divided (exact: at most 16 bits) |
| UINT / SINT | the zero-extended / sign-extended integer, in the integer register |
| 16_FLOAT | the half as f32; a NaN keeps its sign and payload (0x7C01 gives 0x7F802000, not quieted) |
| 10_11_11 / 11_11_10 FLOAT | unsigned float, 5 exponent bits, bias 15, 6 (11-bit field) or 5 (10-bit field) mantissa bits, no sign. Exponent 0: m·2⁻²⁰ (m·2⁻¹⁹ for 5 bits), a denormal that is kept. Exponent 31: infinity, or a NaN whose payload is the mantissa shifted up (0x7C1 gives 0x7F820000), unquieted |
| channels the format lacks | through a V#: component c mod n repeats (the translator's existing rule, SHADER-86, now also measured on gfx1150); through tbuffer: 0 (the instruction names X000, XY00, XYZ0 or XYZW by the format's component count, and the V# DST_SEL is ignored) |
Stores (measured)
buffer_store_format_xyzw and tbuffer_store_format_xyzw of 63 formats into a buffer pre-filled with 0xDEAD0000, the
whole 16 bytes compared, so a byte written outside the element shows up.
| Format class | Result |
|---|---|
| UINT | saturates to the field width (min(x, 2ⁿ−1)) |
| SINT | saturates to the signed range of the field |
| UNORM | clamp to [0, 1], then the exact product x·(2ⁿ−1) rounded to nearest even; a NaN stores 0 |
| SNORM | clamp to [−1, 1], then the exact product x·(2ⁿ⁻¹−1) rounded to nearest even, except the 2-bit field (10_10_10_2 and 2_10_10_10 SNORM), where a half rounds away from zero (0.5 gives 1, −0.5 gives −1; nearest even would give 0) |
| USCALED / SSCALED | converted as UNORM / SNORM: storing 200.0 into 8_USCALED writes 255, storing 0.5 into 8_SSCALED writes 64. The SCALED formats are for loads; a store does not undo the "not divided" |
| 16_FLOAT, 10_11_11 / 11_11_10 FLOAT | round toward zero (not nearest): 0.49999997 gives 0x37FF, not 0x3800. A value too large for the format gives the largest finite value, not infinity: 65520.0 and 1e30 give 0x7BFF for halves; only a real +infinity stores infinity. Denormals are produced. The unsigned floats store 0 for every negative number, −0 and −infinity |
| NaN into a float format | stays a NaN: the sign (halves only) and the top mantissa bits of the payload, or 1 when those are all zero (0x7F800001 gives 0x7C01) |
| a format with two components | the 880M stores (x, w) for buffer_store_format_xyzw, not (x, y): 8_8_UINT of (0x11, 0x22, 0x33, 0x44) writes 0x11, 0x44; buffer_store_format_xy into it writes 0x11 and 0. 1-, 3- and 4-component formats take x, xyz and xyzw. The translator writes (x, y); RDNA2 has not been measured (see below) |
DST_SEL also reorders a store's channels on the 880M in a way that is not a plain swizzle (xzwy stores zxyw); only
the identity and the B/R swap (zyxw, the 8_8_8_8 and 2_10_10_10 UNORM case the translator already handles) are modelled.
What the 880M ran
python -I tools/buffer_format_fuzz.py --oracle hw --budget 200 --seed 7 on a Radeon 880M (gfx1150), 1,264,744 elements,
0 mismatches. --negative-control shows the harness is not vacuous (a kernel whose V# names another format differs on
all but one or two elements of five formats). --self-test checks the model without a GPU.
| Code | Format | Translator | V# loads | tbuffer loads | V# stores | tbuffer stores |
|---|---|---|---|---|---|---|
| 1 | 8_UNORM |
before | 658 | 658 | 1,512 | 1,512 |
| 2 | 8_SNORM |
before | 658 | 658 | 1,512 | 1,512 |
| 3 | 8_USCALED |
added | 658 | 658 | 932 | 932 |
| 4 | 8_SSCALED |
added | 658 | 658 | 932 | 932 |
| 5 | 8_UINT |
added | 658 | 658 | 844 | 844 |
| 6 | 8_SINT |
added | 658 | 658 | 844 | 844 |
| 7 | 16_UNORM |
before | 926 | 926 | 1,512 | 1,512 |
| 8 | 16_SNORM |
before | 926 | 926 | 1,512 | 1,512 |
| 9 | 16_USCALED |
added | 926 | 926 | 932 | 932 |
| 10 | 16_SSCALED |
added | 926 | 926 | 932 | 932 |
| 11 | 16_UINT |
added | 926 | 926 | 844 | 844 |
| 12 | 16_SINT |
added | 926 | 926 | 844 | 844 |
| 13 | 16_FLOAT |
before | 65,938 | 65,938 | 932 | 932 |
| 14 | 8_8_UNORM |
before | 914 | 914 | 1,512 | 1,512 |
| 15 | 8_8_SNORM |
before | 914 | 914 | 1,512 | 1,512 |
| 16 | 8_8_USCALED |
added | 914 | 914 | 932 | 932 |
| 17 | 8_8_SSCALED |
added | 914 | 914 | 932 | 932 |
| 18 | 8_8_UINT |
added | 914 | 914 | 844 | 844 |
| 19 | 8_8_SINT |
added | 914 | 914 | 844 | 844 |
| 20 | 32_UINT |
before | 677 | 677 | 844 | 844 |
| 21 | 32_SINT |
before | 677 | 677 | 844 | 844 |
| 22 | 32_FLOAT |
before | 677 | 677 | 932 | 932 |
| 23 | 16_16_UNORM |
before | 1,450 | 1,450 | 1,512 | 1,512 |
| 24 | 16_16_SNORM |
before | 1,450 | 1,450 | 1,512 | 1,512 |
| 25 | 16_16_USCALED |
added | 1,450 | 1,450 | 932 | 932 |
| 26 | 16_16_SSCALED |
added | 1,450 | 1,450 | 932 | 932 |
| 27 | 16_16_UINT |
before | 1,450 | 1,450 | 844 | 844 |
| 28 | 16_16_SINT |
added | 1,450 | 1,450 | 844 | 844 |
| 29 | 16_16_FLOAT |
before | 131,474 | 131,474 | 932 | 932 |
| 36 | 10_11_11_FLOAT |
added | 5,522 | 5,522 | 932 | 932 |
| 43 | 11_11_10_FLOAT |
added | 5,522 | 5,522 | 932 | 932 |
| 44 | 10_10_10_2_UNORM |
before | 3,478 | 3,478 | 1,612 | 1,612 |
| 45 | 10_10_10_2_SNORM |
added | 3,478 | 3,478 | 1,612 | 1,612 |
| 48 | 10_10_10_2_UINT |
added | 3,478 | 3,478 | 844 | 844 |
| 49 | 10_10_10_2_SINT |
added | 3,478 | 3,478 | 844 | 844 |
| 50 | 2_10_10_10_UNORM |
before | 3,478 | 3,478 | 1,612 | 1,612 |
| 51 | 2_10_10_10_SNORM |
added | 3,478 | 3,478 | 1,612 | 1,612 |
| 52 | 2_10_10_10_USCALED |
added | 3,478 | 3,478 | 932 | 932 |
| 53 | 2_10_10_10_SSCALED |
added | 3,478 | 3,478 | 932 | 932 |
| 54 | 2_10_10_10_UINT |
added | 3,478 | 3,478 | 844 | 844 |
| 55 | 2_10_10_10_SINT |
added | 3,478 | 3,478 | 844 | 844 |
| 56 | 8_8_8_8_UNORM |
before | 1,426 | 1,426 | 1,512 | 1,512 |
| 57 | 8_8_8_8_SNORM |
before | 1,426 | 1,426 | 1,512 | 1,512 |
| 58 | 8_8_8_8_USCALED |
added | 1,426 | 1,426 | 932 | 932 |
| 59 | 8_8_8_8_SSCALED |
added | 1,426 | 1,426 | 932 | 932 |
| 60 | 8_8_8_8_UINT |
before | 1,426 | 1,426 | 844 | 844 |
| 61 | 8_8_8_8_SINT |
added | 1,426 | 1,426 | 844 | 844 |
| 62 | 32_32_UINT |
before | 952 | 952 | 844 | 844 |
| 63 | 32_32_SINT |
before | 952 | 952 | 844 | 844 |
| 64 | 32_32_FLOAT |
before | 952 | 952 | 932 | 932 |
| 65 | 16_16_16_16_UNORM |
before | 2,498 | 2,498 | 1,512 | 1,512 |
| 66 | 16_16_16_16_SNORM |
before | 2,498 | 2,498 | 1,512 | 1,512 |
| 67 | 16_16_16_16_USCALED |
added | 2,498 | 2,498 | 932 | 932 |
| 68 | 16_16_16_16_SSCALED |
added | 2,498 | 2,498 | 932 | 932 |
| 69 | 16_16_16_16_UINT |
before | 2,498 | 2,498 | 844 | 844 |
| 70 | 16_16_16_16_SINT |
added | 2,498 | 2,498 | 844 | 844 |
| 71 | 16_16_16_16_FLOAT |
before | 262,546 | 262,546 | 932 | 932 |
| 72 | 32_32_32_UINT |
before | 1,227 | 1,227 | 844 | 844 |
| 73 | 32_32_32_SINT |
before | 1,227 | 1,227 | 844 | 844 |
| 74 | 32_32_32_FLOAT |
before | 1,227 | 1,227 | 932 | 932 |
| 75 | 32_32_32_32_UINT |
before | 1,502 | 1,502 | 844 | 844 |
| 76 | 32_32_32_32_SINT |
before | 1,502 | 1,502 | 844 | 844 |
| 77 | 32_32_32_32_FLOAT |
before | 1,502 | 1,502 | 932 | 932 |
"before" means the format was in Gen.FORMATS before this change. Codes 30..35, 37..42 (no GFX11 form), 46 and 47 (GFX11
has no SCALED 10_10_10_2) are not in the table.
Where the translator stood, and what changed
Decode of every format that was already in Gen.FORMATS matches the 880M word for word (the 32 old codes are in the
table above). Differences found in the older stores, left as they are (an existing format stays byte-identical in this
change; the first two are pinned by an expectedFailure in tests/semantic/test_buffer_formats_all.py, which starts to
fail when someone fixes them):
- 16_FLOAT, 16_16_FLOAT and 16_16_16_16_FLOAT stores round to nearest even and overflow to infinity (
Gen.f16_bitswithoutrtz); the 880M rounds toward zero and saturates to ±65504. In a 200-row sample of edge-heavy inputs, 89 of 200 (16_FLOAT), 132 of 200 and 174 of 200 differed (mostly by 1 ulp). This is the f16 format store, not the d16 data rounding of BUILD-161 (#1759). - UNORM and SNORM stores multiply in f32 and round that, which rounds twice. 0.3·65535 is 19660.5008 exactly and
19660.5 in f32, a tie that goes to 19660; the hardware stores 19661. In the same sample 0 of 200 differed for the 8-bit
one-component formats and between 1 and 13 of 200 for the others (8_8_8_8_UNORM 9, 16_16_UNORM 7, 16_16_16_16_UNORM 12,
10_10_10_2_UNORM 13, 2_10_10_10_UNORM 11). The new formats store with an exact integer product
(
Gen.norm_encode_exact). - A two-component format stored with
xyzwtakes (x, y) in the translator and (x, w) on the 880M (table above). The RDNA2 xy/xyz measurements incs_fmt_xy_xyz.asmdo not cover it. Unresolved: it needs an RDNA2 card.
Not measured
RDNA2 itself (gfx1013 is the target; no format has been run on any RDNA2 part in this change); the twelve codes above;
codes 46 and 47; d16 loads and stores of the new kinds (they use the same d16 path as the existing formats: SINT
saturates signed, UINT unsigned; BUILD-161 owns d16 rounding); formats on unaligned addresses beyond what the existing
tests cover; swizzled V#s.