diff --git a/docs/design.md b/docs/design.md index 5f4245056c..9a06b3365f 100644 --- a/docs/design.md +++ b/docs/design.md @@ -274,7 +274,7 @@ How the generated SPIR-V expects the runtime to work: | Printed encodings | A listing is LLVM's text for what it decoded, not the bytes it read, so the translator checks the two against each other: the re-anchoring above for listings with undecodable words, and, for every other listing whose header names its code range and whose blob sits next to it (`fssm/`, or `fspx/` for FSPX), each instruction's printed encoding against the bytes at its offset, with the same exceptions (`same_encoding`). A difference is `Unsupported`, naming the instruction, its offset and both byte strings, instead of a translation of the field as 0. The case that prompted it: llvm-mc's gfx1013 decoder (LLVM 21.1.8) drops the VOP3 `op_sel` bits (word 0, bits 14:11) of a 16-bit VOPC compare: `0a 08 a9 d4 01 05 02 00` disassembles as `v_cmp_lt_u16_e64 s10, v1, v2` and re-encodes with the bits cleared (its assembler rejects `op_sel` on VOPC for gfx1013 and gfx1030 alike). Counted over the 1.0.2.1 corpus: the 25,030 clean listings hold 30,335,381 instructions, and none differs from its bytes beyond those exceptions (754); the 166 16-bit VOPC compares (154 shaders, all `f16`) have `op_sel` clear. Hand-written listings, `run_gpu_tests.py`'s `code 0x0..0x0 (synthetic)` listings and a blob that doesn't hold the listing's code range (the tests' header-only FSSM) are not checked. `tests/semantic/test_printed_encoding.py` (a dropped VOPC `op_sel`, a later instruction, the SRC2 exception, and the unchecked cases). One difference is repaired instead of refused: a `v_fma_mix*` literal that llvm-mc prints cut to its low 16 bits (and re-encodes with a zero high half). llvm-mc 23.1.5 prints some of these literals in full as `lit(V)` (an f32 source, or a low half that is an inline constant; LLVM 21 printed the inline constant and dropped the literal word) and still re-encodes only the low half: `tools/shader_ir.py` reads `lit(V)` as V, and the same repair applies (5,733 such operands in the pipeline library, [shader_library.md](shader_library.md)). When the 8 instruction bytes match (`same_encoding` with all three sources counted as used, so a live `s0` can't pass as an inline 0) and the printed literal is the stored one's low half, every source the bytes encode as the literal (SRC field `0xff`) takes the stored 32 bits, so a source with `op_sel_hi` and `op_sel` set reads the high half instead of +0.0. Seen in one program of the FidelityFX DLL's `FSPX` code ([fspx.md](fspx.md)): src0 the low half, src2 the high half; the game's clean listings have no such difference (the count above). That the hardware gives op_sel's high half of the literal to that source is not measured; it is what Mesa's ACO compiler relies on (public: `optimize_constants()` in `src/amd/compiler/aco_optimizer.cpp`, Mesa `main` at `bb986060`, packs two constants as the two f16 halves of one literal, read through `v_fma_mix`'s `op_sel_hi` with the second source extracting the high half), and what the console compiler emitted here. `tools/fma_mix_literal_probe.py --oracle hw` measures it on an AMD GPU (the instruction's exact bytes through `tools/hw_oracle`; not run on one yet). `tests/semantic/test_fma_mix_literal.py` (the value through the interpreter, the re-anchoring path, an inline constant with the literal's printed value left alone, and the refused cases, a live source printed as inline 0 among them). A second shape is repaired too (`mix_inline_literal`): LLVM 21's form above. llvm-mc 21.1.8 (`-mcpu=gfx1013`) prints a `v_fma_mix*` literal whose low 16 bits are the f16 value of an inline constant as that constant and re-encodes the instruction in **8** bytes: every SRC field that held `0xff` holds the inline code, and the literal word is gone (`0x3f800000`, 1.0 as an f32 source, prints as `0`; `0x3c003800` as `0.5`, losing the high half 1.0). Swept with llvm-mc 21.1.8 over all 65,536 low halves under three high halves: exactly 90 low halves print this way (0..64, -1..-16, ±0.5, ±1.0, ±2.0, ±4.0, 1/(2π) as f16: `MIX_INLINE_F16`), whatever the high half; llvm-mc 23.1.6 prints all of them as `lit(V)`. The printed 8 bytes are 4 short of what the decoder read, so the later offsets of a clean listing were 4 low and its first such instruction was refused as a dropped field (one FSPX program, `tupacfan04`'s count in #8683). When every differing SRC field is `0xff` in the blob and the inline code of the stored literal's low half in the print, and the rest of the 8 bytes match exactly (`same_encoding`, all three sources live), each such source reads the stored 32 bits with the stored neg and abs (`NEG_HI`) bits, the instruction takes the 12 stored bytes, and the following offsets move up by 4 (also on the re-anchoring path). Any other difference stays `Unsupported`. CPU-checked by `tests/semantic/test_fma_mix_literal.py` (`FmaMixInlineLiteralTest`: an f32 source, two f16 halves, neg and abs, all 90 codes, both listing paths, the refused cases). | | Global memory | `global_load/store_dword*`: address = (64-bit SGPR base + zero-extended 32-bit VGPR offset, or a 64-bit VGPR address) + the instruction offset, translated through the heap base. Inactive lanes don't access memory, and loads merge their previous values with OpPhi. The offset is the **signed 12-bit** byte value as llvm-mc prints it, -2048..2047 (`offset:-4` is the field 0xffc; llvm-mc rejects `offset:0xffc` and disassembles that field as `offset:-4`, so no repo path delivers the raw unsigned field), added to the address as is; a tool that printed the raw field (`0xffc`) would mean the same offset, and a value outside 12 bits is rejected. Measured on an AMD Radeon RX 6800 (gfx1030) running `global_load_dword` as a raw compute kernel, wave32 and wave64 alike, with the dword at byte n = 0x10000000+n and the pointer at 0x1000: offset 0 reads 0x10001000, -4 0x10000ffc, -2048 0x10000800, 2044 0x100017fc, -1024 0x10000c00. The translator used to subtract 0x1000 from an already negative value (4096 bytes too low). Checked by `tests/semantic/test_global_mem_offset.py` (both addressing modes, dword/x2/x4, byte/short loads and stores at -4, -2048, 2047 and 0) and the GPU test `runtime/test/shaders/cs_global_neg_offset.asm` (`vk_compute_test ... 40 dump`). | | Global atomics (`global_atomic_*`, 32-bit) | `add`, `sub`, `smin/umin`, `smax/umax`, `and`, `or`, `xor`, `swap` and `cmpswap` at the `global_load/store` address (same `Gen.global_address`: saddr pair plus zero-extended vaddr, or a 64-bit vaddr with `off`, plus the signed 12-bit offset), as one `OpAtomic*` on the PhysicalStorageBuffer dword, device scope, guarded so inactive lanes don't touch memory. `fmin` and `fmax` (32-bit float) lower to a structured `OpAtomicCompareExchange` CAS loop using GLSL.std.450 `NMin`/`NMax` (no Vulkan float-atomic extension needed; NaN returns the non-NaN operand, `-0.0 < +0.0`). `inc` and `dec` (32-bit unsigned wrapping against `DATA`: `inc` gives `(M >= DATA) ? 0 : M + 1`, `dec` gives `(M == 0 \|\| M > DATA) ? DATA : M + 1`, `dec` gives `(M == 0 With `glc` the pre-op value lands in `vdst`, the first operand; without `glc` there is no `vdst`, and the first-read analysis counts operand 0 as the address (a source). `cmpswap` takes `vdata` as the pair {DATA, CMP}: `M = (M == CMP) ? DATA : M`, as `buffer_atomic_cmpswap`. Still `Unsupported`: the `_x2` 64-bit forms, `inc`/`dec`, the float atomics, and `slc`/`dlc`. `and/or/xor/swap_x2` work on a 64-bit element (two dwords, low first) as one 32-bit atomic per dword, with no Int64 atomics: a bitwise op leaves the same memory that way, since its bits are independent. **Approximation:** an exchange can tear, since two lanes swapping into one element at once can leave one's low dword with the other's high dword (A.lo, B.lo, B.hi, A.hi), and the returned pair comes from two reads, so another lane's 64-bit op on the same element between them can show up half done (as for `ds_and/or/xor_b64`). **Approximation:** the returned pair comes from two reads, so another lane's 64-bit op on the same element between them can show up half done (as for `ds_and/or/xor_b64`). Still `Unsupported`: the other `_x2` forms (`add/sub/min/max/fmin/fmax_x2` carry or compare across the dwords, and `cmpswap_x2` compares all 64 bits), `inc`/`dec`, `fcmpswap`, and `slc`/`dlc`. Until 2026-11-22 every global atomic was rejected. CPU-checked by `tests/semantic/test_global_atomics.py` (all ten ops on a value grid with and without `glc`, `cmpswap`, offsets from -2048 to 2044, `off` addressing, seeded values, rejected forms, the first-read analysis). CPU-checked by `tests/semantic/test_global_atomics.py` (all ten integer ops plus `fmin`/`fmax` on a value grid with and without `glc`, NaN/±0/±inf, multi-lane CAS contention, `cmpswap`, offsets from -2048 to 2044, `off` addressing, seeded values, rejected forms, the first-read analysis) and `tests/semantic/test_global_atomics_x2.py` (the four `_x2` forms with and without `glc`, an offset, seeded values, the carrying forms rejected), and validated with `spirv-val` (native and `--wave64-emulate`). **Not GPU-verified.** \|\| M > DATA) ? DATA : M - 1`, RDNA2 ISA) also lower to a structured `OpAtomicCompareExchange` CAS loop via `Gen.atomic_inc_dec_cas` for both `global_atomic_{inc,dec}` and MUBUF `buffer_atomic_{inc,dec}` (preserving MUBUF bounds checks: OOB/inactive lanes leave memory untouched and return 0 with `glc`). With `glc` the pre-op value lands in `vdst`, the first operand; without `glc` there is no `vdst`, and the first-read analysis counts operand 0 as the address (a source). `cmpswap` takes `vdata` as the pair {DATA, CMP}: `M = (M == CMP) ? DATA : M`, as `buffer_atomic_cmpswap`. `and/or/xor/swap_x2` work on a 64-bit element (two dwords, low first) as one 32-bit atomic per dword: a bitwise op or an exchange leaves the same memory that way, with no Int64 atomics. **Approximation:** the returned pair comes from two reads, so another lane's 64-bit op on the same element between them can show up half done (as for `ds_and/or/xor_b64`). Still `Unsupported`: the other `_x2` forms (`add/sub/min/max/inc/dec/fmin/fmax_x2` carry or compare across the dwords, and `cmpswap_x2` compares all 64 bits), `fcmpswap`, and `slc`/`dlc`. Until 2026-11-22 every global atomic was rejected. CPU-checked by `tests/semantic/test_global_atomics.py` (all ten integer ops plus `fmin`/`fmax` on a value grid with and without `glc`, NaN/±0/±inf, multi-lane CAS contention, `cmpswap`, offsets from -2048 to 2044, `off` addressing, seeded values, rejected forms, the first-read analysis), `tests/semantic/test_atomic_inc_dec.py` (`global_atomic_{inc,dec}` and `buffer_atomic_{inc,dec}` edge grid, wraparound, `glc` vs non-`glc`, signed offsets, `off` addressing, MUBUF bounds/OOB, inactive lanes, multi-lane CAS contention, first-read analysis, rejected `_x2`/`slc`/`dlc` forms), and `tests/semantic/test_global_atomics_x2.py` (the four `_x2` forms with and without `glc`, an offset, seeded values, the carrying forms rejected), and validated with `spirv-val` (native and `--wave64-emulate`). **Not GPU-verified.** | -| `global_atomic_csub`, `buffer_atomic_csub` (GFX10.3) | `tmp = M; M = (DATA > tmp) ? 0 : tmp - DATA`, unsigned: a subtract clamped at 0 that never wraps; with `glc` the old M comes back. Measured on gfx1036 by @Vonsek (#3193): 162/162 (memory, data) pairs over both forms. Same `OpAtomicCompareExchange` loop as `inc`/`dec` (`Gen.atomic_inc_dec_cas`), so exact under contention; operands, inactive lanes, buffer bounds and `glc` as `inc`/`dec`. Until 2026-11-22 both raised `Unsupported`. CPU-checked by `tests/semantic/test_atomic_csub.py` (a 9×9 value grid, no `glc`, buffer bounds, 32 lanes on one dword against 32 sequential subtracts, seeded values). The translation is not GPU-verified. | +| `global_atomic_csub`, `buffer_atomic_csub` (GFX10.3) | `tmp = M; M = (DATA > tmp) ? 0 : tmp - DATA`, unsigned: a subtract clamped at 0 that never wraps; with `glc` the old M comes back. Measured on gfx1036 by @Vonsek (#3193): 162/162 (memory, data) pairs over both forms. Same `OpAtomicCompareExchange` loop as `inc`/`dec` (`Gen.atomic_inc_dec_cas`), so exact under contention; operands, inactive lanes, buffer bounds and `glc` as `inc`/`dec`. Until 2026-11-22 both raised `Unsupported`. CPU-checked by `tests/semantic/test_atomic_csub.py` (a 9×9 value grid, no `glc`, buffer bounds, 32 lanes on one dword against 32 sequential subtracts, seeded values). GPU-checked by `runtime/test/shaders/cs_global_csub.asm` (assembled for gfx1030 through its `; mcpu:` line, since gfx1013 has neither instruction): both forms, `DATA` above, equal to and below `M`, `0xffffffff` on `0x80000000`, no `glc` (the data register kept), and 32 lanes of one wave subtracting 1 from 20 at once (old values 20..1, then 0 twelve times; `M` ends at 0); passes on an RTX 4060 (NVIDIA 621.01). The translator with the clamp removed, or with a signed compare, fails it. | | Sub-dword MUBUF loads and `GFX10_FORMAT_8_UINT` | `buffer_load_ubyte`, `buffer_load_sbyte`, `buffer_load_ushort` and `buffer_load_sshort` read 1 or 2 bytes at `Gen.buffer_address(..., elem=1 \| 2)` (same `OOB_SELECT` end check with element size 1 or 2 bytes; out-of-bounds returns 0 without reading memory; inactive lanes preserve `vdst`), zero- or sign-extending to 32 bits; 16-bit loads at byte offset 3 within a dword merge byte 0 of the next dword (`idx1 = (b3 == 3) ? 1 : 0`) without over-reading past the buffer. `FORMATS` adds code 5 (`GFX10_FORMAT_8_UINT`, 1-byte unsigned integer) for `tbuffer_load_format_*` / `buffer_load_format_*` (with `DST_SEL` integer 1). Needed by `XboxBvhBuilder.dll` (#1813 follow-ups: `Box16Rehydration`, `Box32Rehydration`, `ReloadTriangles`, `LeafRehydration`). CPU-checked by `tests/semantic/test_buffer_load_sub.py` and validated with `spirv-val` (native and `--wave64-emulate`). GPU-checked (TEST-510) through Vulkan by `runtime/test/shaders/cs_buf_load_sub.asm` (ubyte/sbyte/ushort/sshort zero- and sign-extended, the dword-crossing ushort at offset 3, and the RAW end check by element size: a ushort at 7 of 8 bytes reads 0, where a start-only check would read the next bytes) and `cs_buf_fmt8.asm` (`BUF_FMT_8_UINT` at offsets 0..3, out of range, an INVALID V# format, `DST_SEL` integer 1), both in `scripts/run_gpu_tests.py`: pass on an NVIDIA GeForce RTX 3070 Ti (driver 610.88) and, with the same eight words, on an AMD RX 7600 (`gfx1102`) and a Ryzen 5 9600X iGPU (`gfx1036`, RDNA2, RADV Mesa 27.0.0-devel), so the `vdst` preservation, the sign/zero extension, the ushort load across a dword and the element-size end check are GPU-checked on AMD too. `tools/hw_oracle` was not used for this; the Vulkan path above is what the translator runs. Not measured on AMD hardware (`tools/hw_oracle`). **Not GPU-verified.** Measured on an AMD Radeon RX 7900 XTX (`gfx1100`, driver 26.10.1) by running the instructions as a raw compute kernel (`tools/hw_oracle`, wave32, seeded synthetic bytes): the four loads zero-/sign-extend at byte offsets 0..7, the ushort at byte offset 3 merges byte 0 of the next dword, and with `NUM_RECORDS` = 8 the end check uses the element size (a ubyte at 7 reads where one at 8 returns 0, a ushort at 6 reads 0x5eee where one at 7 returns 0, an sshort at 7 returns 0 where an sbyte at 7 reads). `buffer_load_format_x` with `FORMAT` code 5 and `tbuffer_load_format_x format:[BUF_FMT_8_UINT]` return that byte zero-extended with the same 1-byte end check (at `NUM_RECORDS` 8, offset 7 reads 0x5e and 8 returns 0), and a V# whose `DST_SEL`s are 1/2/3/4 returns the integer 1 in all four components, not the fetched byte. The inactive-lane clause rests on the NVIDIA run. **Not GPU-verified.** | | 8/16-bit global stores and d16 loads | `global_store_byte`/`short` write the low 8/16 bits of the data VGPR (the `_d16_hi` forms its high half). `global_load_{u,s}byte_d16` and `global_load_short_d16` write the low 16 bits of `vdst` (the `_hi` forms the high 16) and keep the other half; `ubyte` zero-extends and `sbyte` sign-extends the byte to 16 bits. The address is the `global_load/store` one (`Gen.global_address`). The access goes one byte at a time, so a 16-bit access that crosses a dword (at byte 3) is exact too. A store merges each byte into its dword with atomic and/or, which keeps neighbouring bytes even when another lane writes them, as buffer byte stores do. A load reads each byte. Inactive lanes neither store nor load. The first-read analysis counts a d16 load's `vdst` as read, for the half it keeps. `global_load/store_dword_addtid` (lane-id and M0 addressing) raise `Unsupported`; until 2026-11-22 they crashed with `IndexError`, and the ten sub-dword ops raised `Unsupported`. CPU-checked by `tests/semantic/test_global_sub_dword.py` (every byte offset 0 to 7 for each op, an inactive lane, rejected forms, the first-read analysis). **Not GPU-verified.** Hardware-measured natively on `gfx1100`** (RX 7900 XTX, driver 26.10.1) with `tools/hw_oracle`, 16 cases that use the output buffer as scratch memory (seven stores, nine d16 loads), all matching: `b8`/`b16` change only the addressed bytes (`0x11223344` with `0xbeef` stored at offset 2 reads back `0xbeef3344`), `_d16_hi` stores take the data VGPR's high half (`0x12340000` at offset 0 gives `0x11221234`), a 16-bit store at offset 3 splits across the dword exactly (`0xfe223344` then `0x556677ca`), `ubyte`/`sbyte` d16 loads fill the low 16 bits of `vdst` and keep the other half (`0x85` gives `0xbeefff85` from a `0xbeef0000` vdst, `0x7f` gives `0xbeef007f`), `short`/`short_hi` d16 loads fill the low/high 16 and keep the rest, and both dword-crossing loads at offset 3 are exact (`0xbeef8811`, `0x88110000`). Not measured: an inactive lane. **Not GPU-verified.** | | Literal samplers | Some shaders build their S# from immediates (for example `0x92, 0xC00000, 0x14500000, 0`). The runtime registers those in the descriptor hash table too, by scanning the translated shaders' constant S# values, not only S#s the game binds. The translator lists them per shader (`literal_samplers` in the index). `CreateGraphicsPipelineState` and `CreateComputePipelineState` register each stage's list in the descriptor hash table, since no heap slot names these S#s. Until 2026-11-22 nothing called `register_samplers` (#1169) outside its test, so such a shader's lookup found the fallback sampler and sampled with the wrong filter. The game's `$PS_PassthroughCopy` drew a coordinate ramp point-sampled: worst error 0.0078, against 0.00049 once registered. Checked by `d3d12_m2_textured_test` (`ps_m2_literal.asm`: no key before the PSO, a sampler index after it). | @@ -307,7 +307,7 @@ How the generated SPIR-V expects the runtime to work: | Packed 16-bit integer ops (`v_pk_add/sub_u16/i16`, `v_pk_mul_lo_u16`, `v_pk_mad_u16/i16`, `v_pk_max/min_u16/i16`) | VOP3P: result half 0 takes each source's half from `op_sel[i]`, result half 1 from `op_sel_hi[i]` (defaults `[0,..]` and `[1,..]`), as for `v_pk_lshlrev_b16`. Each half is computed on its own and wraps to 16 bits. `clamp` (add, sub, mad) saturates the half to its type's range (the exact value fits in 32 bits), whereas on `v_pk_mul_lo_u16` and `v_pk_max/min_u16/i16` VOP3P `clamp` is a hardware no-op (`v_pk_mul_lo_u16 clamp` wraps modulo 2^16 rather than saturating to `0xFFFF`, and `max`/`min` results are unchanged; until 2026-11-23 `clamp` on those five ops raised `Unsupported`). `neg_lo`/`neg_hi` are float-only and unsupported modifiers (such as `mul:*`/`div:*`) raise `Unsupported`. `clamp` (add, sub, mad) saturates the half to its type's range; the exact value fits in 32 bits. `neg_lo`/`neg_hi` are float-only and raise `Unsupported`, as does `clamp` on the other ops. A constant operand is treated as a 32-bit dword `C`: `op_sel[i] == 0` selects bits `[15:0]`, `op_sel[i] == 1` selects bits `[31:16]`. Positive inline constants zero-extend (`5` → `0x00000005`), negative inline constants sign-extend (`-1` → `0xFFFFFFFF`, `-16` → `0xFFFFFFF0`), and 32-bit literals retain their full dword (`0x12345678`). Lowered via `OpBitField*Extract` at `16 * sl[i]` (the packed 16-bit *shifts* read their halves with a shift and a mask instead, like every other high-half reader: see the 16-bit high-half reads row). Lowered via `OpBitField*Extract` at `16 * sl[i]`. Until 2026-11-22 reading the high half of a constant raised `Unsupported`. A constant operand reads as its low 16 bits. Its high half under `op_sel`/`op_sel_hi` is **not measured** for integer ops (for f16 constants it reads +0.0, see the row above), so a constant whose high half would be read raises `Unsupported` instead of guessing; the compiler's usual form, `op_sel_hi:[1,0]` with the constant second, reads only the low half. Until 2026-11-22 all eleven ops raised `Unsupported`. CPU-checked by `tests/semantic/test_alu_pk_int16.py` (value grids, seeded `mad`, `op_sel`/`op_sel_hi` combinations, `clamp` including the unsigned `sub` floor, inline and literal constants, rejected forms) and `tests/semantic/test_pk_int16_clamp.py` (all 26 probe cases plain vs `clamp`, SPIR-V non-saturation assertion, inactive `EXEC` preservation, `spirv-val` Vulkan 1.2 validation, rejected modifiers), plus `tests/test_pk_int16_clamp_probe.py`. **Hardware-verified on RDNA2** (`gfx1035`, Windows 11, driver `26.5.1`, wave32 & wave64 via `tools/int_hw_probe.py --oracle both --group valu_pk_int16`, and independently on `gfx1036` desktop APU, Windows 11, driver `32.0.21045.29003`, across 380 raw compute kernels covering all 11 ops, constants under `op_sel`/`op_sel_hi`, `clamp`, and wave32/wave64 parity with 0 wave diffs and 0 mismatches, and via `tools/pk_int16_clamp_probe.py --hw-arch gfx1036` across 624 wave32 & wave64 evaluations with `mismatches=0, wave_diffs=0, target_clamp_diffs=0, control_clamp_diffs=34`, plus a 96-word wave32 Vulkan compute check under `VK_LAYER_KHRONOS_validation` passing with 0 mismatches on `AMD Radeon RX 9070 XT` driver `26.11.2` and `AMD Radeon(TM) Graphics` driver `26.11.2`): all eleven ops (wrap, `clamp` saturation on add/sub/mad, `clamp` no-op on `mul_lo`/`max`/`min`, and constant `op_sel`/`op_sel_hi`) match bit-for-bit. CPU-checked by `tests/semantic/test_alu_pk_int16.py` (value grids, seeded `mad`, `op_sel`/`op_sel_hi` combinations, `clamp` including the unsigned `sub` floor, inline and literal constants, rejected forms). **Hardware-verified on RDNA2** (`gfx1035`, Windows 11, driver `26.5.1`, wave32 & wave64 via `tools/int_hw_probe.py --oracle both --group valu_pk_int16`, and independently on `gfx1036` desktop APU, Windows 11, driver `32.0.21045.29003`, across 380 raw compute kernels covering all 11 ops, constants under `op_sel`/`op_sel_hi`, `clamp`, and wave32/wave64 parity with 0 wave diffs and 0 mismatches): all eleven ops (wrap, `clamp` saturation on add/sub/mad, and constant `op_sel`/`op_sel_hi`) match bit-for-bit. **Not GPU-verified.** **Hardware-verified on RDNA2** (`gfx1035`, Windows 11, driver `26.5.1`, wave32 & wave64 via `tools/int_hw_probe.py --oracle both --group valu_pk_int16`): all eleven ops (wrap, `clamp` saturation on add/sub/mad, and `op_sel`/`op_sel_hi`) match bit-for-bit. **`v_pk_mul_lo_u16` low 16 bits (found with `pk16_diff --oracle hw,vk`, GPU test `cs_pk_mul_lo_const`):** each half is `((x << 16) * y) >> 16`, not `(x * y) & 0xffff`: with a constant half of 0 in the other half of the result the AMD Windows driver (Radeon iGPU gfx1036, 26.10.1) dropped the mask (`0x1234 * 0xaaaa` gave `0x0c229e88`, hardware `0x00009e88`); the RTX 5080 was right either way. Words measured on the same gfx1036 in `runtime/test/shaders/cs_pk_mul_lo_const.asm`. | | `v_sin_f32`, `v_cos_f32`, `v_sin_f16`, `v_cos_f16` | The operand is an angle in turns (the ISA says valid over +-256; the measurement below finds no such limit on gfx1030). `turn_angle` reduces it in turns first, `x - RoundEven(x)` (exact in binary32, in [-0.5, 0.5]), then scales by `2*pi` and calls `Sin`/`Cos`, so the angle stays in [-pi, pi], the only range where GLSL guarantees them (2^-11 absolute). Scaling first rounded the fractional turn away (about 1.2e-4 rad near 255 turns, #594); the first fix (#1283) reduced with `Fract`, which rounds `1 - \| x \| ` for a negative x and lost `-2^-26` (it returned +0; absolute errors up to ~1.7e-7 at -0.1 turns), so the reduction is `RoundEven`-centred. `RoundEven` rather than `Round` so +-0.5 turn reduce symmetrically. inf and NaN still give NaN, and a zero operand is passed through unreduced so `sin(-0)` stays -0. CPU-checked by `tests/semantic/test_alu_sincos.py` against `sin`/`cos(2*pi*x)` in double (large angles, tiny arguments, whole turns of either sign, +-0, inf/NaN, modifiers, f16) and `tests/semantic/test_valu_sin_cos_turns.py` (#1283). GPU test `cs_w32_sincos` (large angles within 1e-3, since the driver `Sin` is only good to 2^-11) is a regression guard, not proof the old form failed on a given driver. Measured on an AMD Radeon RX 6800 (gfx1030, not the console's gfx1013) by @shelbykb2 (#616): whole and half turns of either sign give +0 (only `sin(-0)` is -0, so no sign needs copying onto a zero result, as here); there is no +-256 limit on that card (any finite x reduces exactly: `sin(300.25)` = 1, `sin(2^24)` = +0); the f16 forms reduce the same way as the f32 ones; +-inf gives a NaN and a NaN passes through, quieted with IEEE mode on. Re-measured natively on gfx1036 (RDNA2, SHADER-134) for f32 and f16 over every quarter turn from 0.25 to 2^24 of either sign and around +-256: the same rules. At an odd half turn `sin`, and at an odd quarter turn `cos`, is exactly +0 (either sign of x), where `Sin`/`Cos` of the rounded 2*pi give about -+8.7e-8 (f32) or a +-1-ulp f16 denormal; since 2026-11-22 the translator selects +0 there (`Gen.trig_exact_zero`), checked against 500 measured words by `tests/semantic/test_alu_sincos_turns_hw.py`. Known differences from this translation: for Known differences from this translation: at half turns `Sin` of the rounded pi gives about -+8.7e-8 where the hardware returns exactly 0, likewise `cos` at quarter turns; for \| x \| <= 2^-12 the hardware multiplies by `0x40c90fd5`, not the rounded 2*pi; the inf/NaN words are whatever the host driver returns. Not checked on gfx1013. | | `v_pack_b32_f16` source modifiers | A VOP3 `abs` or `neg` on an operand of this instruction acts on **the 16-bit half that operand contributes**, not on the whole 32-bit source, and only on that half: `abs` clears bit 15 and `neg` flips it, `abs` first, both as plain bit moves — the operand is not converted to a float. Until 2026-11-22 any such operand was rejected as `Unsupported`. **`neg` is measured** on gfx1036 (RDNA2 iGPU, AMD Windows driver 32.0.21044.64) with 192 raw kernels: `0x7c01` gives `0xfc01` under IEEE mode 0 and `0xfe01` under mode 1, in either half and with `op_sel`, so the sign move does not depend on the mode. **`neg`, `abs`, and `neg_abs` are hardware-verified on RDNA2** across both `gfx1035` (Windows 11, driver 26.5.1, wave32 & wave64 via `tools/int_hw_probe.py --oracle both --group valu_pack_b32_f16_abs` and raw `ieee=0` kernels) and `gfx1036` (Windows 11, driver 32.0.21045.29003, 1,088 raw kernels across wave32 and wave64, 0 mismatches): **`abs` and `- **`neg`, `abs`, and `- **`abs` rests on the ISA's definition of ABS on a float operand as the sign clear, applied before `neg`; no hardware run of this instruction with `abs` exists yet**, and `abs` on a NaN half is therefore unmeasured too. **Not modelled: IEEE mode 1 also quiets a signalling-NaN half** (`0x7c01` → `0x7e01`); which mode the game's shaders run in is SHADER-190, and under mode 0, where the bits move unchanged, the translation is exact. Checked by `tests/test_values.py`, `tests/semantic/test_vop3_const_mods.py`, `tests/semantic/test_pack_b32_f16_mods.py` (exact bits through the interpreter) and the GPU fixture `ps_f16_pack_mods` (words derived from the rule, not a readback); the gfx1036 measurement above is @Sanonymous01's, not repeated here. \| x src \| ` are hardware-verified on RDNA2** across both `gfx1035` (Windows 11, driver 26.5.1, wave32 & wave64 via `tools/int_hw_probe.py --oracle both --group valu_pack_b32_f16_abs` and raw `ieee=0` kernels) and `gfx1036` (Windows 11, driver 32.0.21045.29003, 1,088 raw kernels across wave32 and wave64): ` (neg+abs) are measured** on gfx1036 (RDNA2 iGPU, AMD Windows driver 32.0.21045.29003) with 1,088 raw kernels across wave32 and wave64 (0 mismatches): `abs` clears bit 15 (`& 0x7FFF`), `neg` flips it (`^ 0x8000`), and `neg_abs` sets bit 15 across all normal numbers, zeros, infinities, subnormals, quiet NaNs, and signaling NaNs, in either half and with `op_sel`. Under IEEE mode 0, signaling NaN payloads are preserved untouched (`0x7c01` gives `0xfc01` under `neg` and `0x7c01` under `abs`); under IEEE mode 1, a signaling-NaN half is quieted (bit 9 set: `0x7c01` gives `0xfe01` under `neg` and `0x7e01` under `abs`). ` are hardware-verified on RDNA2** (`gfx1035`, Windows 11, driver `26.5.1`, wave32 & wave64 via `tools/int_hw_probe.py --oracle both --group valu_pack_b32_f16_abs` and raw `ieee=0` kernels): On `gfx1035`, `abs` clears bit 15 and applies before `neg` on `-1.0`, `-0.0`, `-qNaN` (`0xfe05` → `0x7e05`), and `-sNaN` (`0xfc01` → `0x7c01` under `ieee=0`), with and without `op_sel`. **Not modelled: IEEE mode 1 also quiets a signalling-NaN half** (`0x7c01` → `0x7e01`); which mode the game's shaders run in is SHADER-190, and under mode 0, where the bits move unchanged, the translation is exact. Checked by `tests/test_values.py`, `tests/semantic/test_vop3_const_mods.py`, `tests/semantic/test_pack_b32_f16_mods.py` (exact bits through the interpreter) and the GPU fixture `ps_f16_pack_mods` (words derived from the rule, not a readback); the gfx1036 measurement above is @Sanonymous01's, not repeated here. | -| Packed integer dot products (`v_dot2_i32_i16`, `v_dot2_u32_u16`, `v_dot4_u32_u8`, `v_dot8_i32_i4`, `v_dot8_u32_u4`, plus VOP2 accumulating `v_dot2c_i32_i16`, `v_dot2c_u32_u16`, `v_dot4c_u32_u8`, `v_dot8c_i32_i4`, `v_dot8c_u32_u4`), `v_dot2_f32_f16` / `v_dot2c_f32_f16`, and `v_pk_fmac_f16` | RDNA2 ISA: `v_dot2_i32_i16`/`u16` (2×16-bit), `v_dot4_u32_u8` (4×8-bit unsigned), and `v_dot8_i32_i4`/`u4` (8×4-bit) — and their VOP2 accumulating `v_dot*c_*` forms (reading old `vdst` as `acc`) — extract each element with `OpBitFieldSExtract`/`OpBitFieldUExtract`, sum the elementwise products with `S2` (or old `vdst`) wrapping at 32 bits, and saturate to `[INT32_MIN, INT32_MAX]` / `[0, UINT32_MAX]` under `clamp` (signed carry tracking handles the `v_dot2_i32_i16` `(-32768)^2 + (-32768)^2 + acc` overflow/cancellation edge). For VOP3P `v_dot*_*`, the hardware default `op_sel:[0,0,0]` and `op_sel_hi:[1,1,1]` is accepted and any other `op_sel`/`op_sel_hi`, `neg_lo`/`neg_hi`, DPP/SDWA, or source `neg`/`abs` raises `Unsupported`; for VOP2 `v_dot*c_*`, only optional `clamp` and VGPR `vdst` are accepted. `v_dot2_f32_f16` (VOP3P) and `v_dot2c_f32_f16` (VOP2) compute `a0*b0 + a1*b1 + acc` in f32 (`f16_in` per half, `flush_f32` on `acc`, optional `clamp`, and for `v_dot2_f32_f16` `op_sel`/`op_sel_hi`/`neg_lo`/`neg_hi` on the inputs and `neg_lo[2]` on `acc`). All 6 new `v_dot*c_*` ops mark `vdst` as read-before-write in `read_before_write_vgprs` and `reg_reads_writes`. (`v_dot4_i32_i8` and `v_dot4c_i32_i8` are covered separately in the Signed-byte dot products row, #1754.) `v_pk_fmac_f16` (VOP2) unpacks `src0`, `vsrc1` and `vdst` as `f16x2` (`Gen.src_h`, so inline float constants apply in the low half with `+0.0` high), computes `fma(src0[k], vsrc1[k], vdst[k])` per half with single f16 rounding (`Gen.fma_f16_odd`, SHADER-55), and packs with `Gen.f16_pack2`; any modifier outside `_dpp` or non-VGPR `vdst` raises `Unsupported`, and `v_pk_fmac_f16` marks `vdst` as read before write in `read_before_write_vgprs` and `reg_reads_writes`. **Hardware-confirmed on RDNA2** for the 5 VOP3P integer forms and `v_pk_fmac_f16`: on `gfx1036` (Ryzen 9 7950X3D iGPU, `tools/hw_oracle`, @aslan2142), all 60 integer dot-product sets and all 22 `v_pk_fmac_f16` default-MODE words match; independently confirmed on `gfx1035` (Radeon 680M, @Youssefrah16) across 18 cases × wave32/wave64 (36/36 bit-exact), pinned by `tests/semantic/test_alu_dot_pk_fmac.py`. The 5 VOP2 `v_dot*c_*` integer forms and `v_dot2_f32_f16` / `v_dot2c_f32_f16` are CPU-checked by `tests/semantic/test_alu_dot_complete.py` and not yet hardware-measured on RDNA2. Non-default f16 MODEs (denormal flush, RTZ) are not modelled on `v_pk_fmac_f16` while the translator has no MODE input. | +| Packed integer dot products (`v_dot2_i32_i16`, `v_dot2_u32_u16`, `v_dot4_u32_u8`, `v_dot8_i32_i4`, `v_dot8_u32_u4`, plus VOP2 accumulating `v_dot2c_i32_i16`, `v_dot2c_u32_u16`, `v_dot4c_u32_u8`, `v_dot8c_i32_i4`, `v_dot8c_u32_u4`), `v_dot2_f32_f16` / `v_dot2c_f32_f16`, and `v_pk_fmac_f16` | RDNA2 ISA: `v_dot2_i32_i16`/`u16` (2×16-bit), `v_dot4_u32_u8` (4×8-bit unsigned), and `v_dot8_i32_i4`/`u4` (8×4-bit) — and their VOP2 accumulating `v_dot*c_*` forms (reading old `vdst` as `acc`) — extract each element with `OpBitFieldSExtract`/`OpBitFieldUExtract`, sum the elementwise products with `S2` (or old `vdst`) wrapping at 32 bits, and saturate to `[INT32_MIN, INT32_MAX]` / `[0, UINT32_MAX]` under `clamp` (signed carry tracking handles the `v_dot2_i32_i16` `(-32768)^2 + (-32768)^2 + acc` overflow/cancellation edge). For VOP3P `v_dot*_*`, the hardware default `op_sel:[0,0,0]` and `op_sel_hi:[1,1,1]` is accepted and any other `op_sel`/`op_sel_hi`, `neg_lo`/`neg_hi`, DPP/SDWA, or source `neg`/`abs` raises `Unsupported`; for VOP2 `v_dot*c_*`, only optional `clamp` and VGPR `vdst` are accepted. `v_dot2_f32_f16` (VOP3P) and `v_dot2c_f32_f16` (VOP2) compute `a0*b0 + a1*b1 + acc` in f32 (`f16_in` per half, `flush_f32` on `acc`, optional `clamp`, and for `v_dot2_f32_f16` `op_sel`/`op_sel_hi`/`neg_lo`/`neg_hi` on the inputs and `neg_lo[2]` on `acc`). All 6 new `v_dot*c_*` ops mark `vdst` as read-before-write in `read_before_write_vgprs` and `reg_reads_writes`. (`v_dot4_i32_i8` and `v_dot4c_i32_i8` are covered separately in the Signed-byte dot products row, #1754.) `v_pk_fmac_f16` (VOP2) unpacks `src0`, `vsrc1` and `vdst` as `f16x2` (`Gen.src_h`, so inline float constants apply in the low half with `+0.0` high), computes `fma(src0[k], vsrc1[k], vdst[k])` per half with single f16 rounding (`Gen.fma_f16_odd`, SHADER-55), and packs with `Gen.f16_pack2`; any modifier outside `_dpp` or non-VGPR `vdst` raises `Unsupported`, and `v_pk_fmac_f16` marks `vdst` as read before write in `read_before_write_vgprs` and `reg_reads_writes`. **Hardware-confirmed on RDNA2** for the 5 VOP3P integer forms and `v_pk_fmac_f16`: on `gfx1036` (Ryzen 9 7950X3D iGPU, `tools/hw_oracle`, @aslan2142), all 60 integer dot-product sets and all 22 `v_pk_fmac_f16` default-MODE words match; independently confirmed on `gfx1035` (Radeon 680M, @Youssefrah16) across 18 cases × wave32/wave64 (36/36 bit-exact), pinned by `tests/semantic/test_alu_dot_pk_fmac.py`. The 5 VOP2 `v_dot*c_*` integer forms and `v_dot2_f32_f16` / `v_dot2c_f32_f16` are CPU-checked by `tests/semantic/test_alu_dot_complete.py` and not yet hardware-measured on RDNA2. Non-default f16 MODEs (denormal flush, RTZ) are not modelled on `v_pk_fmac_f16` while the translator has no MODE input. **GPU fixture:** `cs_w32_dot_int` (a wave32 dump, `; mcpu: gfx1030`) runs `v_dot2_i32_i16`, `v_dot2_u32_u16`, `v_dot4_u32_u8`, `v_dot8_i32_i4` and `v_dot8_u32_u4` through the translator, with the 32-bit wrap and `clamp` (u32 saturation, i32 saturation, and the `(-32768)^2 * 2 - 2` sum whose products overflow but which stays below INT32_MAX); all eight words exact on an NVIDIA RTX 3070 (621.01). The VOP2 `v_dot*c_*` forms do not assemble with llvm-mc for gfx1013 or gfx1030, so no fixture covers them. | | Packed integer dot products (`v_dot2_i32_i16`, `v_dot2_u32_u16`, `v_dot4_u32_u8`, `v_dot8_i32_i4`, `v_dot8_u32_u4`) and `v_pk_fmac_f16` | RDNA2 ISA: `v_dot2_i32_i16`/`u16` (2×16-bit), `v_dot4_u32_u8` (4×8-bit unsigned), and `v_dot8_i32_i4`/`u4` (8×4-bit) extract each element with `OpBitFieldSExtract`/`OpBitFieldUExtract`, sum the elementwise products with `S2` wrapping at 32 bits, and saturate to `[INT32_MIN, INT32_MAX]` / `[0, UINT32_MAX]` under VOP3P `clamp` (signed carry tracking handles the `v_dot2_i32_i16` `(-32768)^2 + (-32768)^2 + S2` overflow/cancellation edge). The hardware default `op_sel:[0,0,0]` and `op_sel_hi:[1,1,1]` (whether omitted or written explicitly) is accepted; any other `op_sel`/`op_sel_hi` (such as `op_sel_hi:[0,0,0]` or `[0,1,1]`, which select the low half for lane 1 on `v_dot2_*`), `neg_lo`/`neg_hi`, DPP/SDWA forms, and source `neg`/`abs` raise `Unsupported`. (`v_dot4_i32_i8` and `v_dot4c_i32_i8` are covered separately in the Signed-byte dot products row, #1754.) `v_pk_fmac_f16` (VOP2) unpacks `src0`, `vsrc1` and `vdst` as `f16x2` (`Gen.src_h`, so inline float constants apply in the low half with `+0.0` high), computes `fma(src0[k], vsrc1[k], vdst[k])` per half with single f16 rounding (`Gen.fma_f16_odd`, SHADER-55), and packs with `Gen.f16_pack2`; any modifier outside `_dpp` or non-VGPR `vdst` raises `Unsupported`, and `v_pk_fmac_f16` marks `vdst` as read before write in `read_before_write_vgprs` and `reg_reads_writes`. Until 2026-11-22 all six ops raised `Unsupported`. **Hardware-confirmed on RDNA2:** on `gfx1036` (Ryzen 9 7950X3D iGPU, `tools/hw_oracle`, @aslan2142), all 60 integer dot-product sets (plain, swapped/SGPR sources, and `clamp`) match bit-for-bit, all measured `op_sel`/`neg_*` variants are refused, and all 22 `v_pk_fmac_f16` default-MODE (`0x000003C0`: round-to-nearest-even, f16 denormals kept, IEEE and DX10_CLAMP on) words match in both source orders (all 34 non-NaN halves bit-exact; the 10 NaN halves yield quiet f16 NaN, as SPIR-V does not preserve NaN payload bits or sign); independently confirmed on `gfx1035` (Radeon 680M, `tools/hw_oracle`, @Youssefrah16) across 18 cases × wave32/wave64 (36/36 bit-exact). Pinned by `tests/semantic/test_alu_dot_pk_fmac.py` (all 82 `gfx1036` measured tables plus hand-written `.asm` fixture, boundary/clamp cases, default/non-default `op_sel`/`op_sel_hi`, `read_before_write_vgprs`/`reg_reads_writes`, DPP, seeded sweeps, and rejected forms). Non-default f16 MODEs (denormal flush, RTZ) are not modelled on `v_pk_fmac_f16` while the translator has no MODE input. | | `v_med3_f32` output modifiers | The translator applies `mul:2`, `mul:4` or `div:2` to the median before clamping to [0, 1], following [LLVM’s modifier order](https://llvm.org/docs/AMDGPUModifierSyntax.html#omod). The finite-input fixture `ps_med3_mods.asm` produced 4,096 exact pixels on an Apple M3 Max with MoltenVK and on Mesa llvmpipe (software Vulkan); it also passes (4,096/4,096) on an NVIDIA RTX 4050 Laptop and an AMD Radeon 740M (RADV), both Linux, and on an RTX 2060 SUPER per #634. This uses the existing float MODE assumptions described above. | | `v_div_fmas_f32`, `v_div_fmas_f64` | Scaled FMA for IEEE-754 division (VOP3): `D = fma(S0, S1, S2)` when `VCC[lane] == 0`; when `VCC[lane] == 1`, `D = (exp(S2) > bias ? 2^+S : 2^-S) * fma_exact(S0, S1, S2)` where `(bias, S)` is `(127, 64)` for f32 and `(1023, 128)` for f64 (`OpCapability Float64`, no `Int64`), i.e. `\|S2\| >= 2.0` scales up and `\|S2\| < 2.0` scales down. Scale-up uses `fma(S0, S1, S2) * 2^S` (any non-zero cancellation residual against `\|S2\| >= 2.0` stays well above normal minimum). Scale-down pre-scales `S0`/`S1` only when `\|S0*S1\|` can overflow (`\|S0\| >= 2^S` and `\|S1\| >= 1`, symmetric, or both `>= 2^(S/2)`), with a raw-bit sticky value `copysign(min_normal, S2)` whenever `0 < \|S2\| < 2^(Emin + S)` so half-ULP tie-breaking stays exact; otherwise it post-scales `fma(S0, S1, S2) * 2^-S`, with a TwoSum + product-error half-ULP tie adjustment in f64 when `\|fma\|` falls in `[2^-947, 2^-894)` so f64 subnormal outputs single-round. For f32 under the game MODE (`denorm32=0`), subnormal inputs and intermediate products are kept while subnormal outputs flush to signed zero before (and after) output modifiers; for f64 (`denorm16_64=3`), subnormals are kept throughout. VOP3 input (`abs`/`neg`) and output (`mul:2`/`mul:4`/`div:2`, then `clamp`) modifiers apply via `clamp_mods` / `clamp_mods_f64`. **Until 2026-11-22 the translator scaled unconditionally by `2^32` (f32) / `2^64` (f64) whenever `VCC[lane] == 1`, omitting the `exp(S2) > bias` branch and using half the hardware exponent shift.** **Hardware-verified on RDNA2** (`gfx1036`, AMD Radeon Graphics, Windows driver 32.0.21042.62, `tools/hw_oracle`, wave32 and wave64, game MODE `ieee=0`/`dx10_clamp=1`/`denorm32=0`/`denorm16_64=3`): 150/150 f32 and 153/153 f64 stress cases match bit-for-bit, including the `\|S2\| = 2.0` vs `nextbelow(2.0)` threshold, scale-down overflow prevention, sticky-bit tie-breaking, f32 output denormal flushing, and f64 subnormal single rounding. Checked bit-for-bit on the CPU (`spirv_mini_interp` for f32, SSA `%double` evaluator for f64) and assembled with `tools/spirv_asm.py` (plus `spirv-val` when present) by `tests/semantic/test_alu_div_fmas.py`; not run on the shader corpus. | diff --git a/runtime/test/shaders/build.py b/runtime/test/shaders/build.py index c9fd70e4a0..1e0ec62f63 100644 --- a/runtime/test/shaders/build.py +++ b/runtime/test/shaders/build.py @@ -73,19 +73,30 @@ def barycentric_fallback(): return False -def asm_mattr(path): +def asm_header_value(path, key): + """The value of "; : " in a fixture's leading comment lines, or None.""" for ln in Path(path).read_text(encoding="utf-8").splitlines(): s = ln.strip() if not s: continue if not s.startswith(";"): break - m = re.match(r";\s*mattr:\s*(\S+)", s) + m = re.match(r";\s*" + key + r":\s*(\S+)", s) if m: return m.group(1) return None +def asm_mattr(path): + return asm_header_value(path, "mattr") + + +def asm_mcpu(path): + """llvm-mc's -mcpu for a fixture: gfx1013, or "; mcpu: " for one that needs another target (GFX10.3-only + instructions such as global_atomic_csub, which gfx1013 rejects).""" + return asm_header_value(path, "mcpu") or "gfx1013" + + CLIP_CASES = {"vs_clip": 1, "vs_clip_param4": 4, "vs_clip_undeclared": 1} @@ -158,7 +169,7 @@ def translate_tests(work, names): if shift and n.startswith("cs_"): raw = shift_user_data(raw, shift) mattr = asm_mattr(asm_path) - cmd = MC + ["-triple=amdgcn--amdpal", "-mcpu=gfx1013"] + cmd = MC + ["-triple=amdgcn--amdpal", f"-mcpu={asm_mcpu(asm_path)}"] if n in CLIP_CASES: cmd.append(f"-defsym=PARAM_SLOT={CLIP_CASES[n]}") if mattr: diff --git a/runtime/test/shaders/check.py b/runtime/test/shaders/check.py index a677a9de9b..c0a1d22877 100644 --- a/runtime/test/shaders/check.py +++ b/runtime/test/shaders/check.py @@ -107,7 +107,7 @@ def not_found_message(build, missing): "cs_barrier_divergent", "cs_barrier_early_end", "cs_barrier_loop", "cs_w32_lds_u8_d16", "cs_bpermute32", "cs_w32_lds_subdword", "cs_w32_lds_wide", "cs_w32_partial_scmp", "cs_w32_partial_permute", "cs_exec_const", "cs_w32_mask_imm", "cs_w32_int_ext", - "cs_w32_salu64", "cs_w32_misc_ext", "cs_w32_new_ops", "cs_w32_sincos", "cs_lds_b64_cmpst", "cs_lds_xchg64_ext", "cs_lds_atomics_ext", "cs_w32_andn2_exec", + "cs_w32_salu64", "cs_w32_misc_ext", "cs_w32_new_ops", "cs_w32_dot_int", "cs_w32_sincos", "cs_lds_b64_cmpst", "cs_lds_xchg64_ext", "cs_lds_atomics_ext", "cs_w32_andn2_exec", "cs_mask_vgpr_exec", "cs_w32_buffer_sub16", "cs_w32_buffer_store_sub", "cs_w32_fcmpswap", "cs_w32_permlane_fi", "cs_w32_exec_computed") # Wave32 lane-mask dumps: their EXEC/VCC masks and lane selects cover 32 lanes, so a device whose widest subgroup is @@ -147,6 +147,8 @@ def not_found_message(build, missing): # ds_cmpst_f32 and buffer_atomic_fcmpswap: float compare (cs_w32_fcmpswap.asm) ("cs_w32_fcmpswap", [0, 0x3F800000, 0x7FC00000, 0x3F800000, 0x80000000, 0x40400000, 0x3F800000, 0x7FC00000]), ("cs_w32_new_ops", [0x55, 0x8001, 0xC0000000, 0x80014000, 0x4000FFFF, 0x77, 0x99, 0x1234]), + # the packed integer dot products, with clamp (derivations in cs_w32_dot_int.asm) + ("cs_w32_dot_int", [0x00000081, 0xFFFF7F04, 0x00004288, 0xFFFFFFDA, 0x00000104, 0xFFFFFFFF, 0x7FFFFFFE, 0x7FFFFFFF]), ("cs_w32_misc_ext", [0x0FFF0FFF, 0xE2C4A688, 0x0007FFFF, 0x7FFF8000, 0xFFFE0002, 0xFFFF0005, 0x509, 0xCAFEF00D]), ("cs_w32_salu64", [0x1E6A2C48, 0x1234, 0xFFFFFFFF, 0x100, 47, 48, 0xFFFF8000, 0xFFFFFFFE]), # SHADER-85: 8-bit LDS reads into one half of a VGPR, the other half kept @@ -341,7 +343,10 @@ def not_found_message(build, missing): GLOBAL_OFFSET = [("cs_global_neg_offset", "40", [0x5EED1FFC, 0x8BAD1800, 0x5EED1FF0, 0x5EED1FF4, 0x0000009E, 0xFFFF8BAD, 0x57023FFC, 0xEEEEEEEE]), # global/buffer atomics, 8/16-bit global stores and d16 loads with CPU-only checks until now - ("cs_global_mem_ext", "40", [0x5, 0xC, 0x977, 0xFFF00000, 0xEDCB5678, 0xEF332211, 0x887766BE, 0xFF801234])] + ("cs_global_mem_ext", "40", [0x5, 0xC, 0x977, 0xFFF00000, 0xEDCB5678, 0xEF332211, 0x887766BE, 0xFF801234]), + # global/buffer_atomic_csub: the clamp at 0, glc, and 32 lanes on one dword (cases in the .asm header) + ("cs_global_csub", "40", [0x10070905, 0x0D070000, 0x00630064, 0x80000000, 0x00000000, + 0xFFFFFFFE, 0x000C0500, 0x01D800D2])] # cs_heap_init.asm: vk_compute_test's VKC_HEAP_INIT copies this file (zeros, then four words at 0x100) to the start # of the heap; the shader copies the four words to 0, and out[4..7] are the file's zeros, not the 0xEE fill. HEAP_INIT_WORDS = [0x1BADB002, 0xCAFEF00D, 0x80000001, 0x0000FFFF] diff --git a/runtime/test/shaders/cs_global_csub.asm b/runtime/test/shaders/cs_global_csub.asm new file mode 100644 index 0000000000..8e3964b57e --- /dev/null +++ b/runtime/test/shaders/cs_global_csub.asm @@ -0,0 +1,138 @@ +; mcpu: gfx1030 +; mattr: +wavefrontsize32,-wavefrontsize64 +; global_atomic_csub and buffer_atomic_csub (GFX10.3): tmp = M; M = (DATA > tmp) ? 0 : tmp - DATA, unsigned, a +; subtract clamped at 0 that never wraps; with glc the old M comes back (docs/design.md, measured on gfx1036 by #3193). +; gfx1013 has neither instruction, so this file is assembled for gfx1030 (the "; mcpu:" line above). llvm-mc takes +; global_atomic_csub with a destination only with glc; without glc it has none. +; Run with 40 groups (vk_compute_test cs_global_csub.spv 40 dump): the heap is 40 * 256 = 0x2800 bytes, global +; addresses are heap offsets (s[20:21] = P = 0x2000, v30 = 0), as in cs_global_mem_ext. Wave32, 64 threads a group. +; 1. Group 0 thread 0 seeds 12 dwords through the V# in s[0:3]; then every thread meets at s_barrier. +; P+0x00 5 P+0x04 9 P+0x08 100 P+0x0c 0x80000000 P+0x10 0xffffffff P+0x14 7 P+0x18 0x10 +; P+0x1c 2 P+0x20 20 P+0x24 0 P+0x28 0 P+0x2c 1000 +; 2. Contention, the 32 lanes of group 0's first wave at once: +; global_atomic_csub glc of 1 at P+0x20 (20): the old values are 20, 19, ..., 1 and then 0 twelve times; M ends +; at 0. Each lane adds its old value to P+0x24 (sum 210) and adds 1 to P+0x28 when it got 0 (12). +; global_atomic_csub without glc of lane + 1 at P+0x2c (1000): 1 + ... + 32 = 528 never reaches 0, M = 472. +; A subtract that wraps would leave 0xfffffff4 at P+0x20; one that is not atomic would lose updates. +; Then every thread meets at s_barrier again. +; 3. Group 0 thread 0, one case each (old value with glc, then M after): +; A global glc 7 at P+0x00 (5): old 5, M 0 (DATA > M) B global glc 9 at P+0x04 (9): old 9, M 0 (DATA == M) +; C global glc 1 at P+0x08 (100): old 100, M 99 D global glc 0xffffffff at P+0x0c: old 0x80000000, M 0 +; (a subtract without the clamp leaves 0x80000000 - 0xffffffff = 0x80000001) +; E global, no glc, 1 at P+0x10 (0xffffffff): M 0xfffffffe (a signed compare reads 1 > -1 and leaves 0) +; F global glc 0 at P+0x14 (7): old 7, M 7 G buffer glc 3 at 0x2018 (0x10): old 0x10, M 0xd +; H buffer, no glc, 5 at 0x201c (2): M 0, and its data register keeps 5 +; vk_compute_test dumps out[0..7], so the small values are packed a byte or a half each (a wrong value spills into +; its neighbours, which still shows): +; out[0] = A old | B old << 8 | F old << 16 | G old << 24 = 0x10070905 +; out[1] = A M | B M << 8 | F M << 16 | G M << 24 = 0x0d070000 +; out[2] = C old | C M << 16 = 0x00630064 +; out[3] = D old = 0x80000000 +; out[4] = D M = 0x00000000 +; out[5] = E M = 0xfffffffe +; out[6] = H M | H data register << 8 | lanes that got 0 << 16 | P+0x20 after << 24 = 0x000c0500 +; out[7] = sum of the old values | P+0x2c after << 16 = 0x01d800d2 +s_mov_b32 s40, exec_lo +v_or_b32_e32 v1, s4, v0 +v_cmpx_eq_u32_e32 0, v1 +v_mov_b32_e32 v2, 0x2000 +v_mov_b32_e32 v1, 5 +buffer_store_dword v1, v2, s[0:3], 0 offen offset:0 +v_mov_b32_e32 v1, 9 +buffer_store_dword v1, v2, s[0:3], 0 offen offset:4 +v_mov_b32_e32 v1, 0x64 +buffer_store_dword v1, v2, s[0:3], 0 offen offset:8 +v_bfrev_b32_e32 v1, 1 +buffer_store_dword v1, v2, s[0:3], 0 offen offset:12 +v_mov_b32_e32 v1, -1 +buffer_store_dword v1, v2, s[0:3], 0 offen offset:16 +v_mov_b32_e32 v1, 7 +buffer_store_dword v1, v2, s[0:3], 0 offen offset:20 +v_mov_b32_e32 v1, 0x10 +buffer_store_dword v1, v2, s[0:3], 0 offen offset:24 +v_mov_b32_e32 v1, 2 +buffer_store_dword v1, v2, s[0:3], 0 offen offset:28 +v_mov_b32_e32 v1, 20 +buffer_store_dword v1, v2, s[0:3], 0 offen offset:32 +v_mov_b32_e32 v1, 0 +buffer_store_dword v1, v2, s[0:3], 0 offen offset:36 +buffer_store_dword v1, v2, s[0:3], 0 offen offset:40 +v_mov_b32_e32 v1, 0x3e8 +buffer_store_dword v1, v2, s[0:3], 0 offen offset:44 +s_waitcnt vmcnt(0) +s_mov_b32 exec_lo, s40 +s_barrier +s_mov_b32 s20, 0x2000 +s_mov_b32 s21, 0 +v_lshrrev_b32_e32 v1, 5, v0 +v_or_b32_e32 v1, s4, v1 +v_cmpx_eq_u32_e32 0, v1 +v_mov_b32_e32 v30, 0 +v_mov_b32_e32 v3, 1 +global_atomic_csub v10, v30, v3, s[20:21] offset:32 glc +s_waitcnt vmcnt(0) +global_atomic_add v30, v10, s[20:21] offset:36 +v_cmp_eq_u32_e32 vcc_lo, 0, v10 +v_cndmask_b32_e64 v11, 0, 1, vcc_lo +global_atomic_add v30, v11, s[20:21] offset:40 +v_add_nc_u32_e32 v12, 1, v0 +global_atomic_csub v30, v12, s[20:21] offset:44 +s_waitcnt vmcnt(0) +s_mov_b32 exec_lo, s40 +s_barrier +v_or_b32_e32 v1, s4, v0 +v_cmpx_eq_u32_e32 0, v1 +v_mov_b32_e32 v30, 0 +v_mov_b32_e32 v3, 7 +global_atomic_csub v20, v30, v3, s[20:21] glc +v_mov_b32_e32 v3, 9 +global_atomic_csub v21, v30, v3, s[20:21] offset:4 glc +v_mov_b32_e32 v3, 1 +global_atomic_csub v22, v30, v3, s[20:21] offset:8 glc +v_mov_b32_e32 v3, -1 +global_atomic_csub v23, v30, v3, s[20:21] offset:12 glc +v_mov_b32_e32 v3, 1 +global_atomic_csub v30, v3, s[20:21] offset:16 +v_mov_b32_e32 v3, 0 +global_atomic_csub v24, v30, v3, s[20:21] offset:20 glc +v_mov_b32_e32 v25, 3 +v_mov_b32_e32 v2, 0x2018 +buffer_atomic_csub v25, v2, s[0:3], 0 offen glc +v_mov_b32_e32 v26, 5 +v_mov_b32_e32 v2, 0x201c +buffer_atomic_csub v26, v2, s[0:3], 0 offen +s_waitcnt vmcnt(0) +global_load_dword v40, v30, s[20:21] +global_load_dword v41, v30, s[20:21] offset:4 +global_load_dword v42, v30, s[20:21] offset:8 +global_load_dword v43, v30, s[20:21] offset:12 +global_load_dword v44, v30, s[20:21] offset:16 +global_load_dword v45, v30, s[20:21] offset:20 +global_load_dword v46, v30, s[20:21] offset:24 +global_load_dword v47, v30, s[20:21] offset:28 +global_load_dword v48, v30, s[20:21] offset:32 +global_load_dword v49, v30, s[20:21] offset:36 +global_load_dword v50, v30, s[20:21] offset:40 +global_load_dword v51, v30, s[20:21] offset:44 +s_waitcnt vmcnt(0) +v_lshl_or_b32 v60, v21, 8, v20 +v_lshl_or_b32 v60, v24, 16, v60 +v_lshl_or_b32 v60, v25, 24, v60 +v_lshl_or_b32 v61, v41, 8, v40 +v_lshl_or_b32 v61, v45, 16, v61 +v_lshl_or_b32 v61, v46, 24, v61 +v_lshl_or_b32 v62, v42, 16, v22 +v_lshl_or_b32 v66, v26, 8, v47 +v_lshl_or_b32 v66, v50, 16, v66 +v_lshl_or_b32 v66, v48, 24, v66 +v_lshl_or_b32 v67, v51, 16, v49 +v_mov_b32_e32 v2, 0 +buffer_store_dword v60, v2, s[0:3], 0 offen offset:0 +buffer_store_dword v61, v2, s[0:3], 0 offen offset:4 +buffer_store_dword v62, v2, s[0:3], 0 offen offset:8 +buffer_store_dword v23, v2, s[0:3], 0 offen offset:12 +buffer_store_dword v43, v2, s[0:3], 0 offen offset:16 +buffer_store_dword v44, v2, s[0:3], 0 offen offset:20 +buffer_store_dword v66, v2, s[0:3], 0 offen offset:24 +buffer_store_dword v67, v2, s[0:3], 0 offen offset:28 +s_endpgm diff --git a/runtime/test/shaders/cs_w32_dot_int.asm b/runtime/test/shaders/cs_w32_dot_int.asm new file mode 100644 index 0000000000..882b83519e --- /dev/null +++ b/runtime/test/shaders/cs_w32_dot_int.asm @@ -0,0 +1,62 @@ +; mcpu: gfx1030 +; The packed integer dot products (VOP3P), run on a GPU; until now CPU-checked by the semantic tests and measured with +; tools/hw_oracle, but no fixture ran the translation (docs/design.md, "Packed integer dot products"). D = the sum of +; the element products + S2, each element sign- (i) or zero-extended (u), wrapping at 32 bits; with clamp the exact sum +; saturates to [INT32_MIN, INT32_MAX] (i32) or [0, UINT32_MAX] (u32). gfx1013 has none of these instructions, so this +; file is assembled for gfx1030 (the "; mcpu:" line above). Elements are numbered from bit 0. +; out[0] v_dot2_i32_i16 0x0003fffe, 0x0005fff9, 100 (-2)(-7) + 3*5 + 100 = 129 0x00000081 +; out[1] v_dot2_u32_u16 0xffff8001, 0xffff0003, 0xffffff00 32769*3 + 65535^2 + 0xffffff00 wraps once 0xffff7f04 +; out[2] v_dot4_u32_u8 0x80ff0102, 0x7f02ff03, 5 2*3 + 1*255 + 255*2 + 128*127 + 5 = 17032 0x00004288 +; out[3] v_dot8_i32_i4 0x8f01f7a3, 0x12345678, -3 signed nibbles: -35 - 3 = -38 0xffffffda +; out[4] v_dot8_u32_u4 0x8f01f7a3, 0x12345678, 7 unsigned nibbles: 253 + 7 = 260 0x00000104 +; out[5] v_dot2_u32_u16 0xffffffff, 0xffffffff, 0xffffffff clamp 2*65535^2 + 0xffffffff > UINT32_MAX 0xffffffff +; out[6] v_dot2_i32_i16 0x80008000, 0x80008000, -2 clamp 2^31 - 2: the products overflow, the sum does not +; 0x7ffffffe +; out[7] v_dot2_i32_i16 0x80008000, 0x80008000, 0 clamp 2^31 > INT32_MAX 0x7fffffff +; group: 32,1,1 +; Run: vk_compute_test cs_w32_dot_int.spv 1 dump -> out[0..7] = 129 4294934276 17032 4294967258 260 4294967295 +; 2147483646 2147483647 +; mattr: +wavefrontsize32,-wavefrontsize64 +v_mov_b32_e32 v1, 0x0003fffe +v_mov_b32_e32 v2, 0x0005fff9 +v_mov_b32_e32 v3, 0x64 +v_dot2_i32_i16 v10, v1, v2, v3 +v_mov_b32_e32 v1, 0xffff8001 +v_mov_b32_e32 v2, 0xffff0003 +v_mov_b32_e32 v3, 0xffffff00 +v_dot2_u32_u16 v11, v1, v2, v3 +v_mov_b32_e32 v1, 0x80ff0102 +v_mov_b32_e32 v2, 0x7f02ff03 +v_mov_b32_e32 v3, 5 +v_dot4_u32_u8 v12, v1, v2, v3 +v_mov_b32_e32 v1, 0x8f01f7a3 +v_mov_b32_e32 v2, 0x12345678 +v_mov_b32_e32 v3, -3 +v_dot8_i32_i4 v13, v1, v2, v3 +v_mov_b32_e32 v3, 7 +v_dot8_u32_u4 v14, v1, v2, v3 +v_mov_b32_e32 v1, -1 +v_dot2_u32_u16 v15, v1, v1, v1 clamp +v_mov_b32_e32 v1, 0x80008000 +v_mov_b32_e32 v3, -2 +v_dot2_i32_i16 v16, v1, v1, v3 clamp +v_mov_b32_e32 v3, 0 +v_dot2_i32_i16 v17, v1, v1, v3 clamp +v_cmpx_eq_u32_e32 0, v0 +v_mov_b32_e32 v25, 0 +buffer_store_dword v10, v25, s[0:3], 0 offen +v_mov_b32_e32 v25, 4 +buffer_store_dword v11, v25, s[0:3], 0 offen +v_mov_b32_e32 v25, 8 +buffer_store_dword v12, v25, s[0:3], 0 offen +v_mov_b32_e32 v25, 12 +buffer_store_dword v13, v25, s[0:3], 0 offen +v_mov_b32_e32 v25, 16 +buffer_store_dword v14, v25, s[0:3], 0 offen +v_mov_b32_e32 v25, 20 +buffer_store_dword v15, v25, s[0:3], 0 offen +v_mov_b32_e32 v25, 24 +buffer_store_dword v16, v25, s[0:3], 0 offen +v_mov_b32_e32 v25, 28 +buffer_store_dword v17, v25, s[0:3], 0 offen +s_endpgm diff --git a/scripts/run_gpu_tests.py b/scripts/run_gpu_tests.py index 483287fbd3..9aeef69921 100644 --- a/scripts/run_gpu_tests.py +++ b/scripts/run_gpu_tests.py @@ -93,21 +93,39 @@ def make_ms_psv0(threads_x: int, maxv: int, maxp: int, topology: int = 2, group_ return struct.pack(" None: - """Assemble raw RDNA2 .asm with llvm-mc -show-encoding into .s format for rdna2spirv.py.""" - with open(asm_path, encoding="utf-8") as source: - raw = source.read() - cmd = mc_command.mc_command(llvm_mc) + ["-triple=amdgcn--amdpal", "-mcpu=gfx1013"] +# cs_global_csub.asm: out[0..7], the packed results derived in its header (old value and M after each case, the +# contention on one dword). +CSUB_WORDS = [0x10070905, 0x0D070000, 0x00630064, 0x80000000, 0x00000000, 0xFFFFFFFE, 0x000C0500, 0x01D800D2] + + +def asm_target(raw: str) -> tuple[str, str | None]: + """The llvm-mc -mcpu and -mattr of a fixture: "; mcpu: " and "; mattr: " in its leading comment + lines (gfx1013 and none when absent).""" + mcpu, mattr = "gfx1013", None for ln in raw.splitlines(): s = ln.strip() if not s: continue if not s.startswith(";"): break - m = re.match(r";\s*mattr:\s*(\S+)", s) - if m: - cmd.append(f"-mattr={m.group(1)}") - break + m = re.match(r";\s*(mcpu|mattr):\s*(\S+)", s) + if m and m.group(1) == "mcpu": + mcpu = m.group(2) + elif m and mattr is None: + mattr = m.group(2) + return mcpu, mattr + + +def assemble_to_s(llvm_mc: str, asm_path: str, s_path: str, name: str) -> None: + """Assemble raw RDNA2 .asm with llvm-mc -show-encoding into .s format for rdna2spirv.py.""" + with open(asm_path, encoding="utf-8") as source: + raw = source.read() + # The fixtures are written for gfx1013; "; mcpu: gfx1030" in the leading comment assembles one for another target + # (GFX10.3-only instructions such as global_atomic_csub, which gfx1013 rejects). + mcpu, mattr = asm_target(raw) + cmd = mc_command.mc_command(llvm_mc) + ["-triple=amdgcn--amdpal", f"-mcpu={mcpu}"] + if mattr: + cmd.append(f"-mattr={mattr}") if name in CLIP_CASES: cmd.append(f"-defsym=PARAM_SLOT={CLIP_CASES[name]}") cmd.append("-show-encoding") @@ -120,7 +138,7 @@ def assemble_to_s(llvm_mc: str, asm_path: str, s_path: str, name: str) -> None: ) if p.returncode != 0: raise RuntimeError(f"llvm-mc failed on {name}:\n{p.stderr}") - lines = [f"; {name} code 0x0..0x0 (synthetic), gfx1013, 0 invalid words"] + lines = [f"; {name} code 0x0..0x0 (synthetic), {mcpu}, 0 invalid words"] for ln in p.stdout.splitlines(): if ln.startswith("\t.") or ln.strip().startswith("."): continue @@ -1059,14 +1077,16 @@ def run_suite(a, work: str) -> int: # d16_xyz / d16_xy typed-buffer loads and d16_xyz stores (cs_fmt_d16_xyz.asm header) problem = fmt_d16_xyz_test(a.build, spirv_dir, cs_env) results.append((name, not problem, problem or "80/80 dumped words exact")) - elif name in ("cs_global_neg_offset", "cs_global_mem_ext"): + elif name in ("cs_global_neg_offset", "cs_global_mem_ext", "cs_global_csub"): # Negative global_load/global_store offsets (cs_global_neg_offset.asm): 40 groups give a 0x2800-byte # heap holding both the right addresses and the 4096-lower ones. One thread, no wave64 requirement. # cs_global_mem_ext.asm: global/buffer atomics, 8/16-bit global stores and d16 loads in the same heap. rc, msg = run_cmd([vk_compute, spv, "40", "dump"], env=cs_env) want = {"cs_global_neg_offset": [0x5EED1FFC, 0x8BAD1800, 0x5EED1FF0, 0x5EED1FF4, 0x9E, 0xFFFF8BAD, 0x57023FFC, 0xEEEEEEEE], - "cs_global_mem_ext": [0x5, 0xC, 0x977, 0xFFF00000, 0xEDCB5678, 0xEF332211, 0x887766BE, 0xFF801234]}[name] + "cs_global_mem_ext": [0x5, 0xC, 0x977, 0xFFF00000, 0xEDCB5678, 0xEF332211, 0x887766BE, 0xFF801234], + # cs_global_csub.asm: global/buffer_atomic_csub, the clamp at 0, glc, and 32 lanes on one dword + "cs_global_csub": CSUB_WORDS}[name] ok, detail = judge_cs_dump(rc, msg, want, wave64=False, partial=False, emulated=False, hexwords=True) results.append((name, ok, detail)) elif name == "cs_heap_init": @@ -1149,7 +1169,7 @@ def run_suite(a, work: str) -> int: # Whole-wave mask test, as in check.py: needs a 64-wide subgroup, skipped where the device has none. # With LEONIDA_W64_EMULATE=1 it was translated with --wave64-emulate and runs on any subgroup size. results.append((name,) + wavemask_check(vk_compute, spv, cs_env, w64_emulated())) - elif name in ("cs_store", "cs_signed_zero_nan", "cs_smem_soffset_imm", "cs_w32_lane_wrap", "cs_movrelsd_2", "cs_w32_permute", "cs_w32_sincos", "cs_w32_buffer_sub16", "cs_w32_buffer_store_sub", "cs_w32_fcmpswap", "cs_w32_permlane_fi", "cs_exec_const", "cs_w32_mask_imm", "cs_w64_mask_imm", "cs_w32_lds_u8_d16", "cs_w32_lds_subdword", "cs_w32_lds_wide", "cs_w32_int_ext", "cs_w32_salu64", "cs_w32_misc_ext", "cs_w32_new_ops", "cs_wave64_ballot", "cs_wm_half_ops", "cs_wm_half_cmp", "cs_wm_bfm64", "cs_wm_scc_rfl", "cs_wqm_w64", "cs_wqm_w32", "cs_wqm_w64_half", + elif name in ("cs_store", "cs_signed_zero_nan", "cs_smem_soffset_imm", "cs_w32_lane_wrap", "cs_movrelsd_2", "cs_w32_permute", "cs_w32_sincos", "cs_w32_buffer_sub16", "cs_w32_buffer_store_sub", "cs_w32_fcmpswap", "cs_w32_permlane_fi", "cs_exec_const", "cs_w32_mask_imm", "cs_w64_mask_imm", "cs_w32_lds_u8_d16", "cs_w32_lds_subdword", "cs_w32_lds_wide", "cs_w32_int_ext", "cs_w32_salu64", "cs_w32_misc_ext", "cs_w32_new_ops", "cs_w32_dot_int", "cs_wave64_ballot", "cs_wm_half_ops", "cs_wm_half_cmp", "cs_wm_bfm64", "cs_wm_scc_rfl", "cs_wqm_w64", "cs_wqm_w32", "cs_wqm_w64_half", "cs_dpp", "cs_dpp_row", "cs_dpp_mask", "cs_dpp8", "cs_dpp_ops", "cs_dpp_bank", "cs_dpp_fi", "cs_dpp_bound", "cs_dpp_w64", "cs_w64_mask_detect", @@ -1183,6 +1203,8 @@ def run_suite(a, work: str) -> int: # ds_cmpst_f32 and buffer_atomic_fcmpswap: float compare (cs_w32_fcmpswap.asm) "cs_w32_fcmpswap": [0, 0x3F800000, 0x7FC00000, 0x3F800000, 0x80000000, 0x40400000, 0x3F800000, 0x7FC00000], "cs_w32_new_ops": [0x55, 0x8001, 0xC0000000, 0x80014000, 0x4000FFFF, 0x77, 0x99, 0x1234], + # the packed integer dot products: signedness, element widths, 32-bit wrap and clamp (cs_w32_dot_int.asm) + "cs_w32_dot_int": [0x00000081, 0xFFFF7F04, 0x00004288, 0xFFFFFFDA, 0x00000104, 0xFFFFFFFF, 0x7FFFFFFE, 0x7FFFFFFF], "cs_w32_misc_ext": [0x0FFF0FFF, 0xE2C4A688, 0x0007FFFF, 0x7FFF8000, 0xFFFE0002, 0xFFFF0005, 0x509, 0xCAFEF00D], "cs_w32_salu64": [0x1E6A2C48, 0x1234, 0xFFFFFFFF, 0x100, 47, 48, 0xFFFF8000, 0xFFFFFFFE], # SHADER-85: ds_read_u8/i8_d16[_hi] (cs_w32_lds_u8_d16.asm header) @@ -1281,7 +1303,7 @@ def run_suite(a, work: str) -> int: partial = name in ("cs_w64x_partial", "cs_w64x_partial_scmp") wave64 = name not in ("cs_store", "cs_signed_zero_nan", "cs_smem_soffset_imm", "cs_wqm_w32", "cs_w32_lane_wrap", "cs_movrelsd_2", "cs_w32_permute", "cs_barrier_divergent", "cs_barrier_early_end", "cs_barrier_loop", - "cs_w32_lds_u8_d16", "cs_w32_int_ext", "cs_w32_salu64", "cs_w32_misc_ext", "cs_w32_new_ops", + "cs_w32_lds_u8_d16", "cs_w32_int_ext", "cs_w32_salu64", "cs_w32_misc_ext", "cs_w32_new_ops", "cs_w32_dot_int", "cs_w32_lds_subdword", "cs_w32_lds_wide", "cs_bpermute32", "cs_w32_partial_scmp", "cs_w32_partial_permute", "cs_w32_permlane_fi", "cs_w32_sincos", "cs_w32_buffer_sub16", "cs_w32_buffer_store_sub", "cs_w32_fcmpswap", "cs_lds_b64_cmpst", "cs_lds_xchg64_ext", "cs_lds_atomics_ext", "cs_exec_const", "cs_w32_mask_imm", "cs_mask_vgpr_exec", diff --git a/tests/conftest.py b/tests/conftest.py index 1152827615..4f55d69d1d 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -167,17 +167,23 @@ def __init__(self, workdir, name, asm, cs_header=DEFAULT_CS_HEADER, dxbc=EMPTY_D rsrc2, (lx, ly, lz) = cs_header (workdir / "fssm").mkdir(exist_ok=True) (workdir / "fssm" / f"{name}.fssm").write_bytes(bytes(0x138) + struct.pack("<4I", rsrc2, lx, ly, lz)) - cmd = LLVM_MC + ["-triple=amdgcn--amdpal", "-mcpu=gfx1013"] + # gfx1013 unless the leading comment names another target ("; mcpu: gfx1030" for GFX10.3-only instructions, + # as runtime/test/shaders/build.py and scripts/run_gpu_tests.py read it), plus an optional "; mattr:". + mcpu, mattr = "gfx1013", None for ln in asm.splitlines(): s = ln.strip() if not s: continue if not s.startswith(";"): break - m = re.match(r";\s*mattr:\s*(\S+)", s) - if m: - cmd.append(f"-mattr={m.group(1)}") - break + m = re.match(r";\s*(mcpu|mattr):\s*(\S+)", s) + if m and m.group(1) == "mcpu": + mcpu = m.group(2) + elif m and mattr is None: + mattr = m.group(2) + cmd = LLVM_MC + ["-triple=amdgcn--amdpal", f"-mcpu={mcpu}"] + if mattr: + cmd.append(f"-mattr={mattr}") cmd.append("-show-encoding") r = subprocess.run(cmd, input=asm, capture_output=True, text=True) assert r.returncode == 0, r.stderr diff --git a/tests/test_rdna2_decode.py b/tests/test_rdna2_decode.py index 9eede0d0d3..a93d3bb51f 100644 --- a/tests/test_rdna2_decode.py +++ b/tests/test_rdna2_decode.py @@ -384,7 +384,9 @@ def norm_arg(a, op=""): m = re.search(r"^;\s*mattr:\s*(\S+)", txt, re.M) mattr = m.group(1) if m else "" wave32 = "-wavefrontsize32" not in mattr and "+wavefrontsize64" not in mattr - cmd = [mc, "-triple=amdgcn--amdpal", "-mcpu=gfx1013", "-show-encoding"] + m = re.search(r"^;\s*mcpu:\s*(\S+)", txt, re.M) # a fixture with GFX10.3-only instructions + mcpu = m.group(1) if m else "gfx1013" + cmd = [mc, "-triple=amdgcn--amdpal", f"-mcpu={mcpu}", "-show-encoding"] if mattr: cmd.append("-mattr=" + mattr) if os.path.basename(path) == "vs_clip.asm": @@ -399,7 +401,7 @@ def norm_arg(a, op=""): ins = shader_ir.parse_line(ln) if ins and ins["enc"]: raw.extend(bytes.fromhex(ins["enc"])) - dcmd = [mc, "-disassemble", "-triple=amdgcn--amdpal", "-mcpu=gfx1013", "-show-encoding"] + dcmd = [mc, "-disassemble", "-triple=amdgcn--amdpal", f"-mcpu={mcpu}", "-show-encoding"] if mattr: dcmd.append("-mattr=" + mattr) dr = subprocess.run(dcmd, input=" ".join(f"0x{b:02x}" for b in raw), text=True, capture_output=True)