upleb.uk

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

summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorAlxcBTW <187763517+AlxcBTW@users.noreply.github.com>2026-11-22 16:17:05 +0100
committerAlxcBTW <187763517+AlxcBTW@users.noreply.github.com>2026-11-22 16:29:16 +0100
commitf2ee6b57783b50ea5b4435cd2c41ea33b83c7747 (patch)
treea5c347dc70dfb6c010c24585fbda00118ac351ad /docs
parent4eb6155d3ac4f9d3fadb0d095c4ce13e76783615 (diff)
buffer_format_fuzz: a hardware oracle for every GFX10 buffer data format
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>
Diffstat (limited to 'docs')
-rw-r--r--docs/README.md1
-rw-r--r--docs/buffer_formats.md174
2 files changed, 175 insertions, 0 deletions
diff --git a/docs/README.md b/docs/README.md
index cb4a79cb9..3b2efcd1f 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -69,6 +69,7 @@ method, scope and caveats. No game data is included.
69| [shader_validation.md](shader_validation.md) | Differential CPU/GPU validation design and the current CPU interpreter prototype. | 69| [shader_validation.md](shader_validation.md) | Differential CPU/GPU validation design and the current CPU interpreter prototype. |
70| [isa_coverage.md](isa_coverage.md) | RDNA2 ISA coverage of the translator against AMD's machine-readable XML: which of its 1,153 instructions have a rule, and which matched names are not RDNA2. | 70| [isa_coverage.md](isa_coverage.md) | RDNA2 ISA coverage of the translator against AMD's machine-readable XML: which of its 1,153 instructions have a rule, and which matched names are not RDNA2. |
71| [buffer_bounds.md](buffer_bounds.md) | V# `OOB_SELECT` bounds measured natively: RDNA2 (gfx1036) follows Mesa's GFX11 column (729/732 cases), not GFX10; raw mode also counts `soffset`. | 71| [buffer_bounds.md](buffer_bounds.md) | V# `OOB_SELECT` bounds measured natively: RDNA2 (gfx1036) follows Mesa's GFX11 column (729/732 cases), not GFX10; raw mode also counts `soffset`. |
72| [buffer_formats.md](buffer_formats.md) | Every GFX10 buffer data format a V# or MTBUF can name, loaded and stored, measured on a Radeon 880M (RDNA3.5, not RDNA2): 1.26 million elements, 0 mismatches; SCALED stores convert as NORM, float stores round toward zero. |
72| [fssm_crosscheck.md](fssm_crosscheck.md) | FSSM/RDNA2 facts cross-checked against SCARAB; code starts at `code_off + 0x28`. | 73| [fssm_crosscheck.md](fssm_crosscheck.md) | FSSM/RDNA2 facts cross-checked against SCARAB; code starts at `code_off + 0x28`. |
73| [fspx.md](fspx.md) | `FSPX`, the FidelityFX DLL's native compute programs (its shaders' `ACCC` part): directory as the DLL reads it, kind-0 dispatch state, the hash prologue, `gfx1030` for its `v_dot4` code; 13 of 29 translate with `tools/fspx_unpack.py`. | 74| [fspx.md](fspx.md) | `FSPX`, the FidelityFX DLL's native compute programs (its shaders' `ACCC` part): directory as the DLL reads it, kind-0 dispatch state, the hash prologue, `gfx1030` for its `v_dot4` code; 13 of 29 translate with `tools/fspx_unpack.py`. |
74| [embedded_shaders.md](embedded_shaders.md) | DXBC containers embedded in the package's DLLs: 52 in `XboxBvhBuilder.dll` (console `FSSM` via the `XDAT`/`XBCH` record; 42/52 pass `spirv-val` today) and 29 `ACCC`/`FSPX` in the FidelityFX upscaler; the scan/extract tool and the four rules still missing. | 75| [embedded_shaders.md](embedded_shaders.md) | DXBC containers embedded in the package's DLLs: 52 in `XboxBvhBuilder.dll` (console `FSSM` via the `XDAT`/`XBCH` record; 42/52 pass `spirv-val` today) and 29 `ACCC`/`FSPX` in the FidelityFX upscaler; the scan/extract tool and the four rules still missing. |
diff --git a/docs/buffer_formats.md b/docs/buffer_formats.md
new file mode 100644
index 000000000..39ebbe9a4
--- /dev/null
+++ b/docs/buffer_formats.md
@@ -0,0 +1,174 @@
1# Typed buffer formats: every GFX10 code a V# or MTBUF can name
2
3What `buffer_load_format_*`, `buffer_store_format_*` and `tbuffer_load_format_*` do for each GFX10 buffer data format
4(V# word 3 `FORMAT` [18:12], or the `format:` modifier of an MTBUF instruction), measured on a Radeon 880M and held
5against the translator. The contract row is "Typed buffer formats" in [design.md](design.md); the code is
6`Gen.FORMATS`, `Gen.decode_format` and `Gen.encode_format` in `tools/rdna2spirv.py`; the oracle is
7`tools/buffer_format_fuzz.py`.
8
9**Read this first: the GPU is not RDNA2.** The only local AMD part is the Radeon 880M (gfx1150, RDNA3.5, GFX11). GFX11
10numbers its formats differently (8_8_8_8_UNORM is 56 on GFX10 and 42 on GFX11), so every format is mapped by name
11(`GFX11_CODES` in the tool, taken from what the AMD assembler encodes for `format:[BUF_FMT_<name>]`). A match supports
12the model on RDNA3.5. Where this repository measured RDNA2 itself (UINT saturation and UNORM/SNORM rounding on gfx1036,
13the xy/xyz stores on a Radeon 680M) the two agree; everything else is "GFX11, believed to carry over".
14
15## Which codes there are
16
17GFX10's `FORMAT` is 7 bits, so a buffer can carry codes 1..77 (the table in `tools/gfx10_formats.json` goes to 292
18because 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).
19There are no 5_6_5-style formats for buffers. Of the 77:
20
21- **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
22 UNORM, SNORM, USCALED, SSCALED, UINT, SINT (and FLOAT for 16-bit), 10_11_11_FLOAT (36), 11_11_10_FLOAT (43) and the
23 10_10_10_2 (44..49) and 2_10_10_10 (50..55) families in all six numeric formats.
24- **12 are not**: 10_11_11 and 11_11_10 with UNORM, SNORM, USCALED, SSCALED, UINT and SINT (codes 30..35 and 37..42).
25 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
26 guess at what a 5-bit-exponent field "normalized" to would be worse than the 0 a shader gets now. They decode to 0
27 and store nothing, as every code outside the table does.
28
29Of 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
30measured 10_10_10_2 and 2_10_10_10 siblings, and their SCALED conversion is the measured one).
31
32## Names and bit order
33
34Names list the component widths from the top bit down, so the **last** number is `x` in bit 0: `2_10_10_10` (50) is
35R10G10B10A2 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 =
3611 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.
37The 880M confirmed all of these.
38
39## Loads (measured)
40
41Every result word of an `xyzw` load of 63 formats, through a V# (`DST_SEL` = XYZW) and through tbuffer's own format
42(with a V# that names 32_FLOAT), equals the model below. Per format: every value of every field up to 12 bits (and all
4365,536 half floats), edge values (0, 1, max, signed min and its neighbours), random values above that, and random bytes
44past the element.
45
46| Format class | Result |
47|---|---|
48| UNORM | correctly rounded f32 of x / (2ⁿ−1) |
49| SNORM | correctly rounded x / (2ⁿ⁻¹−1); the most negative code is −1.0 |
50| USCALED / SSCALED | the integer, as a float, **not** divided (exact: at most 16 bits) |
51| UINT / SINT | the zero-extended / sign-extended integer, in the integer register |
52| 16_FLOAT | the half as f32; a NaN keeps its sign and payload (`0x7C01` gives `0x7F802000`, **not quieted**) |
53| 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 |
54| 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) |
55
56## Stores (measured)
57
58`buffer_store_format_xyzw` and `tbuffer_store_format_xyzw` of 63 formats into a buffer pre-filled with `0xDEAD0000`, the
59whole 16 bytes compared, so a byte written outside the element shows up.
60
61| Format class | Result |
62|---|---|
63| UINT | saturates to the field width (min(x, 2ⁿ−1)) |
64| SINT | saturates to the signed range of the field |
65| UNORM | clamp to [0, 1], then the **exact** product x·(2ⁿ−1) rounded to nearest even; a NaN stores 0 |
66| 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) |
67| **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" |
68| 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 |
69| 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`) |
70| 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) |
71
72`DST_SEL` also reorders a store's channels on the 880M in a way that is not a plain swizzle (`xzwy` stores `zxyw`); only
73the 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.
74
75## What the 880M ran
76
77`python -I tools/buffer_format_fuzz.py --oracle hw --budget 200 --seed 7` on a Radeon 880M (gfx1150), 1,264,744 elements,
780 mismatches. `--negative-control` shows the harness is not vacuous (a kernel whose V# names another format differs on
79all but one or two elements of five formats). `--self-test` checks the model without a GPU.
80
81| Code | Format | Translator | V# loads | tbuffer loads | V# stores | tbuffer stores |
82|---|---|---|---|---|---|---|
83| 1 | `8_UNORM` | before | 658 | 658 | 1,512 | 1,512 |
84| 2 | `8_SNORM` | before | 658 | 658 | 1,512 | 1,512 |
85| 3 | `8_USCALED` | added | 658 | 658 | 932 | 932 |
86| 4 | `8_SSCALED` | added | 658 | 658 | 932 | 932 |
87| 5 | `8_UINT` | added | 658 | 658 | 844 | 844 |
88| 6 | `8_SINT` | added | 658 | 658 | 844 | 844 |
89| 7 | `16_UNORM` | before | 926 | 926 | 1,512 | 1,512 |
90| 8 | `16_SNORM` | before | 926 | 926 | 1,512 | 1,512 |
91| 9 | `16_USCALED` | added | 926 | 926 | 932 | 932 |
92| 10 | `16_SSCALED` | added | 926 | 926 | 932 | 932 |
93| 11 | `16_UINT` | added | 926 | 926 | 844 | 844 |
94| 12 | `16_SINT` | added | 926 | 926 | 844 | 844 |
95| 13 | `16_FLOAT` | before | 65,938 | 65,938 | 932 | 932 |
96| 14 | `8_8_UNORM` | before | 914 | 914 | 1,512 | 1,512 |
97| 15 | `8_8_SNORM` | before | 914 | 914 | 1,512 | 1,512 |
98| 16 | `8_8_USCALED` | added | 914 | 914 | 932 | 932 |
99| 17 | `8_8_SSCALED` | added | 914 | 914 | 932 | 932 |
100| 18 | `8_8_UINT` | added | 914 | 914 | 844 | 844 |
101| 19 | `8_8_SINT` | added | 914 | 914 | 844 | 844 |
102| 20 | `32_UINT` | before | 677 | 677 | 844 | 844 |
103| 21 | `32_SINT` | before | 677 | 677 | 844 | 844 |
104| 22 | `32_FLOAT` | before | 677 | 677 | 932 | 932 |
105| 23 | `16_16_UNORM` | before | 1,450 | 1,450 | 1,512 | 1,512 |
106| 24 | `16_16_SNORM` | before | 1,450 | 1,450 | 1,512 | 1,512 |
107| 25 | `16_16_USCALED` | added | 1,450 | 1,450 | 932 | 932 |
108| 26 | `16_16_SSCALED` | added | 1,450 | 1,450 | 932 | 932 |
109| 27 | `16_16_UINT` | before | 1,450 | 1,450 | 844 | 844 |
110| 28 | `16_16_SINT` | added | 1,450 | 1,450 | 844 | 844 |
111| 29 | `16_16_FLOAT` | before | 131,474 | 131,474 | 932 | 932 |
112| 36 | `10_11_11_FLOAT` | added | 5,522 | 5,522 | 932 | 932 |
113| 43 | `11_11_10_FLOAT` | added | 5,522 | 5,522 | 932 | 932 |
114| 44 | `10_10_10_2_UNORM` | before | 3,478 | 3,478 | 1,612 | 1,612 |
115| 45 | `10_10_10_2_SNORM` | added | 3,478 | 3,478 | 1,612 | 1,612 |
116| 48 | `10_10_10_2_UINT` | added | 3,478 | 3,478 | 844 | 844 |
117| 49 | `10_10_10_2_SINT` | added | 3,478 | 3,478 | 844 | 844 |
118| 50 | `2_10_10_10_UNORM` | before | 3,478 | 3,478 | 1,612 | 1,612 |
119| 51 | `2_10_10_10_SNORM` | added | 3,478 | 3,478 | 1,612 | 1,612 |
120| 52 | `2_10_10_10_USCALED` | added | 3,478 | 3,478 | 932 | 932 |
121| 53 | `2_10_10_10_SSCALED` | added | 3,478 | 3,478 | 932 | 932 |
122| 54 | `2_10_10_10_UINT` | added | 3,478 | 3,478 | 844 | 844 |
123| 55 | `2_10_10_10_SINT` | added | 3,478 | 3,478 | 844 | 844 |
124| 56 | `8_8_8_8_UNORM` | before | 1,426 | 1,426 | 1,512 | 1,512 |
125| 57 | `8_8_8_8_SNORM` | before | 1,426 | 1,426 | 1,512 | 1,512 |
126| 58 | `8_8_8_8_USCALED` | added | 1,426 | 1,426 | 932 | 932 |
127| 59 | `8_8_8_8_SSCALED` | added | 1,426 | 1,426 | 932 | 932 |
128| 60 | `8_8_8_8_UINT` | before | 1,426 | 1,426 | 844 | 844 |
129| 61 | `8_8_8_8_SINT` | added | 1,426 | 1,426 | 844 | 844 |
130| 62 | `32_32_UINT` | before | 952 | 952 | 844 | 844 |
131| 63 | `32_32_SINT` | before | 952 | 952 | 844 | 844 |
132| 64 | `32_32_FLOAT` | before | 952 | 952 | 932 | 932 |
133| 65 | `16_16_16_16_UNORM` | before | 2,498 | 2,498 | 1,512 | 1,512 |
134| 66 | `16_16_16_16_SNORM` | before | 2,498 | 2,498 | 1,512 | 1,512 |
135| 67 | `16_16_16_16_USCALED` | added | 2,498 | 2,498 | 932 | 932 |
136| 68 | `16_16_16_16_SSCALED` | added | 2,498 | 2,498 | 932 | 932 |
137| 69 | `16_16_16_16_UINT` | before | 2,498 | 2,498 | 844 | 844 |
138| 70 | `16_16_16_16_SINT` | added | 2,498 | 2,498 | 844 | 844 |
139| 71 | `16_16_16_16_FLOAT` | before | 262,546 | 262,546 | 932 | 932 |
140| 72 | `32_32_32_UINT` | before | 1,227 | 1,227 | 844 | 844 |
141| 73 | `32_32_32_SINT` | before | 1,227 | 1,227 | 844 | 844 |
142| 74 | `32_32_32_FLOAT` | before | 1,227 | 1,227 | 932 | 932 |
143| 75 | `32_32_32_32_UINT` | before | 1,502 | 1,502 | 844 | 844 |
144| 76 | `32_32_32_32_SINT` | before | 1,502 | 1,502 | 844 | 844 |
145| 77 | `32_32_32_32_FLOAT` | before | 1,502 | 1,502 | 932 | 932 |
146
147"before" means the format was in `Gen.FORMATS` before this change. Codes 30..35, 37..42 (no GFX11 form), 46 and 47 (GFX11
148has no SCALED 10_10_10_2) are not in the table.
149
150## Where the translator stood, and what changed
151
152Decode of every format that was already in `Gen.FORMATS` matches the 880M word for word (the 32 old codes are in the
153table above). **Differences found in the older stores, left as they are** (an existing format stays byte-identical in this
154change; the first two are pinned by an `expectedFailure` in `tests/semantic/test_buffer_formats_all.py`, which starts to
155fail when someone fixes them):
156
1571. **16_FLOAT, 16_16_FLOAT and 16_16_16_16_FLOAT stores round to nearest even and overflow to infinity** (`Gen.f16_bits`
158 without `rtz`); the 880M rounds toward zero and saturates to ±65504. In a 200-row sample of edge-heavy inputs, 89 of
159 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
160 rounding of BUILD-161 (#1759).
1612. **UNORM and SNORM stores multiply in f32 and round that**, which rounds twice. 0.3·65535 is 19660.5008 exactly and
162 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
163 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,
164 10_10_10_2_UNORM 13, 2_10_10_10_UNORM 11). The new formats store with an exact integer product
165 (`Gen.norm_encode_exact`).
1663. **A two-component format stored with `xyzw`** takes (x, y) in the translator and (x, w) on the 880M (table above).
167 The RDNA2 xy/xyz measurements in `cs_fmt_xy_xyz.asm` do not cover it. Unresolved: it needs an RDNA2 card.
168
169## Not measured
170
171RDNA2 itself (gfx1013 is the target; no format has been run on any RDNA2 part in this change); the twelve codes above;
172codes 46 and 47; `d16` loads and stores of the new kinds (they use the same d16 path as the existing formats: SINT
173saturates signed, UINT unsigned; BUILD-161 owns d16 rounding); formats on unaligned addresses beyond what the existing
174tests cover; swizzled V#s.