Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions docs/experiments.md
Original file line number Diff line number Diff line change
Expand Up @@ -4993,11 +4993,11 @@ The compute store profile lowers `buffer_store_format_x`, `_xy`, `_xyz` and `_xy

FORMAT is bits 18:12. The remaining bits must be the GFX10 identity value `0x01000FAC` (RESOURCE_LEVEL set, DST_SEL XYZW, index stride, ADD_TID, OOB and type clear) or the legacy identity value `0x00000FAC`. Legacy programs store DFMT in bits 18:15 and NFMT in bits 14:12. Any other fixed bits skip the store.

The handled GFX10 formats are 32-bit UINT and FLOAT for one to four channels, `16_16_FLOAT`, `16_16_16_16_FLOAT`, `8_8_8_8_UNORM`, `16_16_UNORM`, `10_10_10_2_UNORM`, and the single-channel 16-bit UNORM, SNORM, UINT, SINT and FLOAT forms. The opcode width has to match the format. A d16 opcode converts each packed binary16 half with `f16tof32` before that packing. d16 combined with 16-bit UINT or SINT does not store. Every other format does not store. UNORM and SNORM follow the Direct3D float conversion (scale, add or subtract 0.5, then drop the fraction). The fixture includes one exact binary32 unorm8 tie, where that rule yields 3 and ties-to-even would yield 2. The RDNA buffer-format unit's tie break is unverified: the ISA text checked here does not state it, and LLVM's AMDGPU packed conversions are ties-to-even on a different unit. The profile does not write raw dwords in place of an unknown format.
The handled GFX10 formats are 32-bit UINT and FLOAT for one to four channels, `16_16_FLOAT`, `16_16_16_16_FLOAT`, `8_8_8_8_UNORM`, `16_16_UNORM`, `2_10_10_10_UNORM`, and the single-channel 16-bit UNORM, SNORM, UINT, SINT and FLOAT forms. The opcode width has to match the format. A d16 opcode converts each packed binary16 half with `f16tof32` before that packing. d16 combined with 16-bit UINT or SINT does not store. Every other format does not store. UNORM and SNORM follow the Direct3D float conversion (scale, add or subtract 0.5, then drop the fraction). The fixture includes one exact binary32 unorm8 tie, where that rule yields 3 and ties-to-even would yield 2. The RDNA buffer-format unit's tie break is unverified: the ISA text checked here does not state it, and LLVM's AMDGPU packed conversions are ties-to-even on a different unit. The profile does not write raw dwords in place of an unknown format.

A 32-bit result is a raw UAV store of one to four dwords. Packed UNORM and FLOAT16 results occupy one or two dwords. A single 16-bit channel clears its half of the containing dword with `InterlockedAnd` and inserts it with `InterlockedOr`. The reservation is four bytes per channel, so `d16_xyzw` reserves sixteen bytes rather than the two data VGPRs. Overlapping reservations are refused. The address stays 2-byte aligned, the element stays inside the stride, and the indexed layout keeps a single writer for each dword.

The gfx1013 fixture uses a group of 4 and a 112-byte record. One dispatch writes all eight opcodes, thirteen formats, a legacy `32_32_32_FLOAT` xyz store and a legacy `16_16_FLOAT` xy store. WARP and the hardware adapter compare all 320 words for one group and for two. Replacing the first format with `BUF_FMT_8_SNORM`, or binding `16_UINT` to the `d16_x` store, leaves that element at the sentinel. Changing the 32-bit payload must fail at word 14. LLVM 15 assembles the fixture and `lower` of the disassembly matches `lower` of the source. The Windows LLVM 15.0.7 installer has no `llvm-mc.exe`; that round trip uses the same package's clang integrated assembler and `LLVM-C.dll`.
The gfx1013 fixture uses a group of 4 and a 112-byte record. One dispatch writes all eight opcodes, thirteen formats, a legacy `32_32_32_FLOAT` xyz store and a legacy `16_16_FLOAT` xy store. WARP and the hardware adapter compare all 320 words for one group and for two. Replacing the first format with `BUF_FMT_8_SNORM`, the `2_10_10_10_UNORM` store's format with `10_10_10_2_UNORM`, or binding `16_UINT` to the `d16_x` store, leaves that element at the sentinel. Changing the 32-bit payload must fail at word 14. LLVM 15 assembles the fixture and `lower` of the disassembly matches `lower` of the source. The Windows LLVM 15.0.7 installer has no `llvm-mc.exe`; that round trip uses the same package's clang integrated assembler and `LLVM-C.dll`.

```powershell
cmake --build --preset dev --target offscreen_check
Expand All @@ -5008,6 +5008,12 @@ ctest --preset dev --no-tests=error -R '^compute_store_aot_descriptor_store_form
python3 -B tests/compute_store_check.py binary llvm-mc-15 llvm-objcopy-15 libLLVM-15.so.1
```

#### 2_10_10_10 and 10_10_10_2

AMD format names list the fields from the most significant bit. Mesa's `gfx10_format_table.py` reverses each name into little-endian channel sizes, and radeonsi and radv map R10G10B10A2 (x in bits 9:0, w in bits 31:30) to `2_10_10_10`. So the 10-bit-x layout is `BUF_FMT_2_10_10_10_UNORM` (gfx10 code 50, legacy DFMT 9). `BUF_FMT_10_10_10_2_UNORM` (code 44, legacy DFMT 8) has a 2-bit x in bits 1:0 and 10-bit y, z and w.

The descriptor-format stores and loads first used the 10-bit-x packer for code 44 and legacy DFMT 8, which would have read and written the wrong fields. They now use it for code 50 and legacy DFMT 9 only, and refuse code 44 and legacy DFMT 8. A store with that format is skipped, and a load with it is invalid, so nothing is published. The store and load fixtures use code 50, and each adds a GPU run with code 44 that must leave its output at the sentinel.

### Descriptor-format buffer loads

The gfx1013 compute store profile lowers `buffer_load_format_x`, `_xy`, `_xyz` and `_xyzw` through the t0 source binding. The format is read at run time from V# word 3. Repeat `--load-format-constant` once per formatted load, in program order. Each index names a ready `s_buffer_load` word of the constant descriptor.
Expand All @@ -5024,7 +5030,7 @@ The caller-format gfx1030 path and the static raw reads are unchanged.

The fixed bits and the format set are those of the descriptor-format stores. The fixed bits must be the GFX10 identity `0x01000FAC` or the legacy identity `0x00000FAC`. The formats are:
- 32-bit UINT and FLOAT, one to four channels;
- `8_8_8_8_UNORM`, `16_16_UNORM` and `10_10_10_2_UNORM`;
- `8_8_8_8_UNORM`, `16_16_UNORM` and `2_10_10_10_UNORM`;
- `16_16_FLOAT` and `16_16_16_16_FLOAT`;
- 16-bit UNORM, SNORM, UINT, SINT and FLOAT.

Expand Down Expand Up @@ -5053,11 +5059,12 @@ A `--compute-store-case` file may now end with 320 t0 words; without them, t0 ke

Threads 4 to 7 are pseudo-random. The expected words come from a Python model that rounds with `Fraction`. WARP and the hardware adapter compare all 320 words for one group and for two.

Four more runs each make one load invalid, and each must leave all 320 words at the sentinel:
Five more runs each make one load invalid, and each must leave all 320 words at the sentinel:
- `8_SNORM`;
- an `xyz` opcode on `32_32_32_32_UINT`;
- an `xy` opcode on `32_FLOAT`;
- a non-identity `DST_SEL`.
- a non-identity `DST_SEL`;
- `10_10_10_2_UNORM` in place of `2_10_10_10_UNORM`.

References that publish placeholder words must fail on those runs: zeros for the invalid load, and the D3D (0, 0, 0, 1) fill for the `xy` opcode on `32_FLOAT`.

Expand Down
4 changes: 3 additions & 1 deletion tests/compute_load_format_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
LOADS = (
("xyzw", 0, 56, False, 0), # 8_8_8_8_UNORM
("xy", 4, 23, False, 16), # 16_16_UNORM
("xyzw", 8, 44, False, 24), # 10_10_10_2_UNORM
("xyzw", 8, 50, False, 24), # 2_10_10_10_UNORM: x in bits 9:0, w in bits 31:30
("xy", 12, 29, True, 40), # 16_16_FLOAT, legacy DFMT/NFMT
("xyzw", 16, 71, False, 48), # 16_16_16_16_FLOAT
("x", 24, 7, False, 64), # 16_UNORM
Expand All @@ -43,6 +43,8 @@
("xyz opcode on a four-channel format", 10, aot.descriptor_format_word(75)),
("xy opcode on a one-channel format", 13, aot.descriptor_format_word(22)),
("non-identity DST_SEL", 12, IDENTITY_32_UINT ^ 1),
# 10_10_10_2_UNORM has a 2-bit x in bits 1:0; only the 2_10_10_10 layout is handled.
("10_10_10_2_UNORM", 2, aot.DESCRIPTOR_GFX10_FIXED | (44 << 12)),
)
# Thread 0-3 t0 words: edge values per field. Threads 4-7 are pseudo-random.
CURATED = (
Expand Down
16 changes: 13 additions & 3 deletions tests/compute_store_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -8293,7 +8293,7 @@ def draw(directory, compiler, renderer, backend, cases=None):
("buffer_store_format_x", 56, 20, False, (("xor", UINT_PAYLOAD),)),
("buffer_store_format_d16_xy", 60, 23, False, (PACKED_25_75,)),
("buffer_store_format_d16_xyz", 68, 74, False, (PACKED_25_75, H25)),
("buffer_store_format_xyzw", 80, 44, False, (F25, F75, 0, F75)),
("buffer_store_format_xyzw", 80, 50, False, (F25, F75, 0, F75)),
("buffer_store_format_x", 96, 7, False, (F25,)),
("buffer_store_format_x", 100, 11, False, (UINT16_BITS,)),
("buffer_store_format_x", 104, 8, False, (F75,)),
Expand Down Expand Up @@ -8518,7 +8518,7 @@ def descriptor_store_round_trip(directory, lines, binding, kind, tool, objcopy,
PINNED_LEGACY_WORDS = {
20: 0x00024FAC, 22: 0x00027FAC, 62: 0x0005CFAC, 64: 0x0005FFAC,
72: 0x0006CFAC, 74: 0x0006FFAC, 75: 0x00074FAC, 77: 0x00077FAC,
56: 0x00050FAC, 23: 0x00028FAC, 44: 0x00040FAC, 29: 0x0002FFAC,
56: 0x00050FAC, 23: 0x00028FAC, 50: 0x00048FAC, 29: 0x0002FFAC,
71: 0x00067FAC, 7: 0x00010FAC, 8: 0x00011FAC, 11: 0x00014FAC,
12: 0x00015FAC, 13: 0x00017FAC,
}
Expand Down Expand Up @@ -8710,7 +8710,9 @@ def descriptor_store_controls():
assert aot.descriptor_format_word(code, legacy=True) == word
assert aot.decode_buffer_descriptor_format(word)[0] == code
handled = 0x01038FAC
for word in (aot.DESCRIPTOR_GFX10_FIXED | (2 << 12), aot.DESCRIPTOR_GFX10_FIXED | (9 << 12),
# 10_10_10_2_UNORM (44, legacy DFMT 8) puts a 2-bit x in bits 1:0, not the 2_10_10_10 layout unorm10 packs.
for word in (aot.DESCRIPTOR_GFX10_FIXED | (44 << 12), 0x00040FAC,
aot.DESCRIPTOR_GFX10_FIXED | (2 << 12), aot.DESCRIPTOR_GFX10_FIXED | (9 << 12),
handled | (1 << 23), handled | (1 << 21), handled | (1 << 28), handled | (1 << 30),
handled & ~0xFFF, 0):
rejects("Unsupported buffer descriptor format", aot.decode_buffer_descriptor_format, word)
Expand Down Expand Up @@ -8798,6 +8800,14 @@ def descriptor_store_draw(directory, compiler, renderer, backend):
+ struct.pack("<16I", *descriptor_constants(
{0: aot.DESCRIPTOR_GFX10_FIXED | (2 << 12)})))
result = subprocess.run(run)
if result.returncode:
return result.returncode
print("refused 10_10_10_2_UNORM", flush=True)
xyzw = next(index for index, store in enumerate(DESCRIPTOR_STORES) if store[1] == 80)
case.write_bytes(struct.pack("<321I", 1, *descriptor_words(1, refuse={xyzw}))
+ struct.pack("<16I", *descriptor_constants(
{xyzw: aot.DESCRIPTOR_GFX10_FIXED | (44 << 12)})))
result = subprocess.run(run)
if result.returncode:
return result.returncode
print("refused d16 16_UINT", flush=True)
Expand Down
10 changes: 7 additions & 3 deletions tools/compute_store_aot.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,17 +339,21 @@ def labelled(decoded):
# raw VGPR bits for raw32 and the 16-bit integer forms. A d16 opcode converts each half to
# binary32 first. 16-bit UINT/SINT with d16 is not a defined conversion, so those stores
# are skipped rather than guessed. Codes absent from this table are refused the same way.
# AMD format names list the fields from the most significant bit: Mesa's gfx10_format_table.py reverses
# them ("Keep the bit sizes in little-endian order"), and radeonsi and radv map R10G10B10A2 (x in bits
# 9:0, w in bits 31:30) to 2_10_10_10. So unorm10 is BUF_FMT_2_10_10_10_UNORM (50, legacy DFMT 9), and
# BUF_FMT_10_10_10_2_UNORM (44, legacy DFMT 8), whose x is the 2-bit field in bits 1:0, is not handled.
DESCRIPTOR_STORE_FORMATS = {
20: ("raw32", 1), 22: ("raw32", 1),
62: ("raw32", 2), 64: ("raw32", 2),
72: ("raw32", 3), 74: ("raw32", 3),
75: ("raw32", 4), 77: ("raw32", 4),
56: ("unorm8", 4), 23: ("unorm16x2", 2), 44: ("unorm10", 4),
56: ("unorm8", 4), 23: ("unorm16x2", 2), 50: ("unorm10", 4),
29: ("f16x2", 2), 71: ("f16x4", 4),
7: ("unorm16", 1), 8: ("snorm16", 1),
11: ("uint16", 1), 12: ("sint16", 1), 13: ("f16", 1),
}
# Legacy (DFMT << 3) | NFMT for the same packers. DFMT: 16=2, 32=4, 16_16=5, 10_10_10_2=8,
# Legacy (DFMT << 3) | NFMT for the same packers. DFMT: 16=2, 32=4, 16_16=5, 2_10_10_10=9,
# 8_8_8_8=10, 32_32=11, 16_16_16_16=12, 32_32_32=13, 32_32_32_32=14.
# NFMT: UNORM=0, SNORM=1, UINT=4, SINT=5, FLOAT=7.
def _legacy_field(dfmt, nfmt):
Expand All @@ -361,7 +365,7 @@ def _legacy_field(dfmt, nfmt):
_legacy_field(11, 4): 62, _legacy_field(11, 7): 64,
_legacy_field(13, 4): 72, _legacy_field(13, 7): 74,
_legacy_field(14, 4): 75, _legacy_field(14, 7): 77,
_legacy_field(10, 0): 56, _legacy_field(5, 0): 23, _legacy_field(8, 0): 44,
_legacy_field(10, 0): 56, _legacy_field(5, 0): 23, _legacy_field(9, 0): 50,
_legacy_field(5, 7): 29, _legacy_field(12, 7): 71,
_legacy_field(2, 0): 7, _legacy_field(2, 1): 8,
_legacy_field(2, 4): 11, _legacy_field(2, 5): 12, _legacy_field(2, 7): 13,
Expand Down
Loading