diff --git a/docs/design.md b/docs/design.md index daeb4eb425..40755af622 100644 --- a/docs/design.md +++ b/docs/design.md @@ -301,7 +301,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. `runtime/test/shaders/cs_w32_csub_ext.asm` adds what that file leaves out: for each form, the 16 even lanes of a wave32 on one dword while the odd lanes are inactive and aimed at a trap word (both trap words unchanged, the inactive lanes' `vdst`/`vdata` kept, the active lanes' old values returned), and `buffer_atomic_csub` through a V# with `num_records` 8: offset 4 is in range; offsets 8 (`glc`) and 12 (no `glc`) are past it, so memory is untouched and `vdata` is 0 with `glc` and kept without. Both files pass on an RTX 4070 Ti (NVIDIA 620.70.06) and a Radeon 610M (gfx1036, RADV Mesa 26.2.6), natively and with `LEONIDA_W64_EMULATE=1`. On both GPUs, removing the clamp or comparing signed fails `cs_global_csub`; dropping the `glc` return or ignoring EXEC fails both files; ignoring the V# bounds, or giving a dropped `glc` lane its `DATA` instead of 0, fails `cs_w32_csub_ext`. Not GPU-checked: an unaligned address, and `slc`/`dlc` (the global form raises `Unsupported` for them). | | 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). **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. GPU-checked by `runtime/test/shaders/cs_global_mem_ext.asm` for two of the ten ops (one lane, `saddr` addressing, on a Radeon 610M (gfx1036, RADV, Mesa 26.2.6) and an RTX 4070 Ti (NVIDIA 620.70.06), Linux): `global_store_short` at byte 3 of a dword changes only its two bytes, across both dwords, and `global_load_sbyte_d16_hi` sign-extends a byte into the high half of `vdst` and keeps the low half. **Not GPU-verified:** the other eight ops and an inactive lane. | | 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). | diff --git a/runtime/test/shaders/build.py b/runtime/test/shaders/build.py index 03a7ecd229..d64386b62b 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} @@ -156,7 +167,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 f0ddf2f315..8eb68a9fc0 100644 --- a/runtime/test/shaders/check.py +++ b/runtime/test/shaders/check.py @@ -110,7 +110,7 @@ def not_found_message(build, missing): "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_mask_vgpr_exec", "cs_w32_buffer_sub16", "cs_w32_buffer_store_sub", "cs_w32_fcmpswap", "cs_w32_permlane_fi", - "cs_w32_exec_computed") + "cs_w32_exec_computed", "cs_w32_csub_ext") # Wave32 lane-mask dumps: their EXEC/VCC masks and lane selects cover 32 lanes, so a device whose widest subgroup is # narrower (Mesa llvmpipe: 8) can't produce their words. They are skipped there, as ps_bitmask_perm is. They run with # 32 lanes requested (WAVE32_LANE_ENV), as run_gpu_tests.py does: a device with a range like 8..32 (Intel ANV) may @@ -118,7 +118,7 @@ def not_found_message(build, missing): WAVE32_LANE_ENV = {"VKC_SUBGROUP_SIZE": "32"} WAVE32_LANE_DUMPS = ("cs_wqm_w32", "cs_w32_lane_wrap", "cs_w32_permute", "cs_bpermute32", "cs_w32_partial_scmp", "cs_w32_partial_permute", "cs_exec_const", "cs_w32_mask_imm", "cs_lds_b64_cmpst", "cs_lds_xchg64_ext", "cs_lds_atomics_ext", "cs_w32_andn2_exec", "cs_mask_vgpr_exec", "cs_w32_permlane_fi", - "cs_w32_exec_computed") + "cs_w32_exec_computed", "cs_w32_csub_ext") CS_DPP = [("cs_dpp", [1, 0, 3, 2, 5, 4, 7, 6]), ("cs_dpp_row", [0, 0, 1, 2, 3, 4, 5, 6]), ("cs_dpp_mask", [1, 0, 3, 2, 0xeeeeeeee, 0xeeeeeeee, 0xeeeeeeee, 0xeeeeeeee]), @@ -149,6 +149,8 @@ def not_found_message(build, missing): ("cs_w32_buffer_sub16", [0xBEEF00AA, 0x00AA1234, 0xBEEFFFAA, 0xFFAA1234, 0xBEEF8899, 0x88991234, 0x1122CD44, 0xABCD7788]), # ds_cmpst_f32 and buffer_atomic_fcmpswap: float compare (cs_w32_fcmpswap.asm) ("cs_w32_fcmpswap", [0, 0x3F800000, 0x7FC00000, 0x3F800000, 0x80000000, 0x40400000, 0x3F800000, 0x7FC00000]), + # global/buffer_atomic_csub: inactive lanes on a trap word, buffer elements past the V# range (cs_w32_csub_ext.asm) + ("cs_w32_csub_ext", [0xAAAAAAAA, 0x77770054, 0x023005C8, 0xAAAAAAAA, 0x55550012, 0x0019001E, 0x00990000, 0x00AB0003]), ("cs_w32_new_ops", [0x55, 0x8001, 0xC0000000, 0x80014000, 0x4000FFFF, 0x77, 0x99, 0x1234]), ("cs_w32_misc_ext", [0x0FFF0FFF, 0xE2C4A688, 0x0007FFFF, 0x7FFF8000, 0xFFFE0002, 0xFFFF0005, 0x509, 0xCAFEF00D]), ("cs_w32_salu64", [0x1E6A2C48, 0x1234, 0xFFFFFFFF, 0x100, 47, 48, 0xFFFF8000, 0xFFFFFFFE]), @@ -344,7 +346,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_csub_ext.asm b/runtime/test/shaders/cs_w32_csub_ext.asm new file mode 100644 index 0000000000..762bbcd12c --- /dev/null +++ b/runtime/test/shaders/cs_w32_csub_ext.asm @@ -0,0 +1,140 @@ +; mcpu: gfx1030 +; mattr: +wavefrontsize32,-wavefrontsize64 +; group: 32,1,1 +; global_atomic_csub and buffer_atomic_csub (GFX10.3), the cases cs_global_csub.asm leaves out: inactive lanes aimed +; at a trap word, and buffer_atomic_csub on an element past the V# range. The operation is +; tmp = M; M = (DATA > tmp) ? 0 : tmp - DATA, unsigned, with glc returning tmp (docs/design.md, global_atomic_csub +; row). A dropped atomic leaves memory alone; an active glc lane then gets 0 and an inactive lane keeps vdst/vdata +; (docs/design.md, "Atomic natural alignment" row, measured on gfx1036). An element is in range when +; O + 4 <= num_records under OOB_SELECT 3 (docs/design.md, "Buffer bounds checking" row). +; gfx1013 has neither instruction, so this file is assembled for gfx1030. One wave32 group (32 threads); the heap is +; the 256-byte output buffer and global addresses are heap offsets (s[20:21] = 0x40). +; 1. Lane 0 seeds through the V# in s[0:3]: +; 0x40 A_g 100 0x44 T_g 0x7777 0x48 S_g 0 0x4c S_b 0 0x50 A_b 50 0x54 T_b 0x5555 +; 0x58 K_g 0 0x5c K_b 0 0x80 0 0x84 30 0x88 0x99 0x8c 0xab +; 2. All 32 lanes set up their operands; even lanes aim at A_g/A_b and odd lanes at the trap words T_g/T_b +; (address + 4 * (lane & 1)). Then EXEC = 0x55555555 (the 16 even lanes): +; global_atomic_csub glc, DATA 1, vdst preset to 0xc5b00000 | lane: A_g 100 -> 84, old values 100..85 in some +; order, sum 1480 = 0x5c8, added to S_g by the same lanes. +; buffer_atomic_csub glc, DATA 2 (vdata = 2): A_b 50 -> 18, old values 50, 48, ..., 20, sum 560 = 0x230, added +; to S_b. +; The odd lanes do nothing: T_g and T_b keep their seeds, and their vdst / vdata keep 0xc5b00000 | lane / 2. +; With EXEC back to all 32 lanes, each lane whose register still holds its preset value ORs 1 << lane into K_g +; (global vdst) or K_b (buffer vdata): only the odd lanes, 0xaaaaaaaa, for both forms. A lane whose old value were +; not returned would set its even bit too (0xffffffff); an inactive lane given 0 would clear its odd bit. (An +; atomic OR, not VCC copied into a VGPR: the translator keeps a lane mask as one bit per lane, so v_mov_b32 of it +; reads this lane's bit; docs/design.md, "Whole-wave masks" row.) +; 3. Lane 0, through a V# in s[8:11] of base 0x80, stride 0, num_records 8, word3 0x31016fac (OOB_SELECT 3, as +; cs_bounds.asm), so offsets 0 and 4 are in range and 8 and 12 are not: +; B1 offset 4, glc, DATA 5: in range, M at 0x84 30 -> 25, vdata 30 +; B2 offset 8, glc, DATA 1: out of range, 0x88 keeps 0x99, vdata 0 +; B3 offset 12, no glc, DATA 3: out of range, 0x8c keeps 0xab, vdata keeps 3 +; out[0..7] (two values a word where they fit, so a wrong one still shows): +; out[0] = K_g, the lanes whose vdst still holds its preset = 0xaaaaaaaa +; out[1] = A_g after | T_g after << 16 = 0x77770054 +; out[2] = S_g | S_b << 16 = 0x023005c8 +; out[3] = K_b, the lanes whose vdata still holds its preset = 0xaaaaaaaa +; out[4] = A_b after | T_b after << 16 = 0x55550012 +; out[5] = B1 vdata | 0x84 after << 16 = 0x0019001e +; out[6] = B2 vdata | 0x88 after << 16 = 0x00990000 +; out[7] = B3 vdata | 0x8c after << 16 = 0x00ab0003 +; Run: vk_compute_test cs_w32_csub_ext.spv 1 dump -> out[0..7] = 2863311530 2004287572 36701640 2863311530 +; 1431633938 1638430 10027008 11206659 +s_mov_b32 s40, exec_lo +v_cmpx_eq_u32_e32 0, v0 +v_mov_b32_e32 v2, 0 +v_mov_b32_e32 v1, 0x64 +buffer_store_dword v1, v2, s[0:3], 0 offen offset:64 +v_mov_b32_e32 v1, 0x7777 +buffer_store_dword v1, v2, s[0:3], 0 offen offset:68 +v_mov_b32_e32 v1, 0 +buffer_store_dword v1, v2, s[0:3], 0 offen offset:72 +buffer_store_dword v1, v2, s[0:3], 0 offen offset:76 +buffer_store_dword v1, v2, s[0:3], 0 offen offset:128 +v_mov_b32_e32 v1, 0x32 +buffer_store_dword v1, v2, s[0:3], 0 offen offset:80 +v_mov_b32_e32 v1, 0x5555 +buffer_store_dword v1, v2, s[0:3], 0 offen offset:84 +v_mov_b32_e32 v1, 0 +buffer_store_dword v1, v2, s[0:3], 0 offen offset:88 +buffer_store_dword v1, v2, s[0:3], 0 offen offset:92 +v_mov_b32_e32 v1, 30 +buffer_store_dword v1, v2, s[0:3], 0 offen offset:132 +v_mov_b32_e32 v1, 0x99 +buffer_store_dword v1, v2, s[0:3], 0 offen offset:136 +v_mov_b32_e32 v1, 0xab +buffer_store_dword v1, v2, s[0:3], 0 offen offset:140 +s_waitcnt vmcnt(0) +s_mov_b32 exec_lo, s40 +s_barrier +s_mov_b32 s20, 0x40 +s_mov_b32 s21, 0 +v_and_b32_e32 v1, 1, v0 +v_lshlrev_b32_e32 v2, 2, v1 +v_add_nc_u32_e32 v4, 0x50, v2 +v_mov_b32_e32 v3, 1 +v_or_b32_e32 v10, 0xc5b00000, v0 +v_mov_b32_e32 v11, 2 +s_mov_b32 exec_lo, 0x55555555 +global_atomic_csub v10, v2, v3, s[20:21] glc +buffer_atomic_csub v11, v4, s[0:3], 0 offen glc +s_waitcnt vmcnt(0) +global_atomic_add v2, v10, s[20:21] offset:8 +global_atomic_add v2, v11, s[20:21] offset:12 +s_waitcnt vmcnt(0) +s_mov_b32 exec_lo, s40 +v_mov_b32_e32 v30, 0 +v_or_b32_e32 v12, 0xc5b00000, v0 +v_cmp_eq_u32_e32 vcc_lo, v12, v10 +v_cndmask_b32_e64 v13, 0, 1, vcc_lo +v_lshlrev_b32_e32 v13, v0, v13 +global_atomic_or v30, v13, s[20:21] offset:24 +v_cmp_eq_u32_e32 vcc_lo, 2, v11 +v_cndmask_b32_e64 v14, 0, 1, vcc_lo +v_lshlrev_b32_e32 v14, v0, v14 +global_atomic_or v30, v14, s[20:21] offset:28 +s_waitcnt vmcnt(0) +s_barrier +v_cmpx_eq_u32_e32 0, v0 +s_mov_b32 s8, 0x80 +s_mov_b32 s9, 0 +s_mov_b32 s10, 8 +s_mov_b32 s11, 0x31016fac +v_mov_b32_e32 v5, 4 +v_mov_b32_e32 v20, 5 +buffer_atomic_csub v20, v5, s[8:11], 0 offen glc +v_mov_b32_e32 v5, 8 +v_mov_b32_e32 v21, 1 +buffer_atomic_csub v21, v5, s[8:11], 0 offen glc +v_mov_b32_e32 v5, 12 +v_mov_b32_e32 v22, 3 +buffer_atomic_csub v22, v5, s[8:11], 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:68 +global_load_dword v47, v30, s[20:21] offset:72 +global_load_dword v48, v30, s[20:21] offset:76 +global_load_dword v60, v30, s[20:21] offset:24 +global_load_dword v63, v30, s[20:21] offset:28 +s_waitcnt vmcnt(0) +v_lshl_or_b32 v61, v41, 16, v40 +v_lshl_or_b32 v62, v43, 16, v42 +v_lshl_or_b32 v64, v45, 16, v44 +v_lshl_or_b32 v65, v46, 16, v20 +v_lshl_or_b32 v66, v47, 16, v21 +v_lshl_or_b32 v67, v48, 16, v22 +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 v63, v2, s[0:3], 0 offen offset:12 +buffer_store_dword v64, v2, s[0:3], 0 offen offset:16 +buffer_store_dword v65, 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/scripts/run_gpu_tests.py b/scripts/run_gpu_tests.py index 8ba62104d8..3e8311d28d 100644 --- a/scripts/run_gpu_tests.py +++ b/scripts/run_gpu_tests.py @@ -98,10 +98,32 @@ def make_ms_psv0(threads_x: int, maxv: int, maxp: int, topology: int = 2, group_ return struct.pack(" 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*(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: @@ -115,17 +137,12 @@ def assemble_to_s(llvm_mc: str, asm_path: str, s_path: str, name: str) -> None: with open(s_path, "w", encoding="utf-8", newline="\n") as f: f.write("\n".join(lines) + "\n") return - cmd = mc_command.mc_command(llvm_mc) + ["-triple=amdgcn--amdpal", "-mcpu=gfx1013"] - 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 + # 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") @@ -138,7 +155,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 @@ -1104,14 +1121,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": @@ -1201,7 +1220,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_smem_vcc_base", "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_smem_vcc_base", "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_csub_ext", "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", "cs_dpp", "cs_dpp_row", "cs_dpp_mask", "cs_dpp8", "cs_dpp_ops", "cs_dpp_bank", "cs_dpp_fi", "cs_dpp_bound", "cs_dpp_cmp", "cs_dpp_w64", "cs_w64_mask_detect", @@ -1235,6 +1254,9 @@ def run_suite(a, work: str) -> int: "cs_w32_buffer_sub16": [0xBEEF00AA, 0x00AA1234, 0xBEEFFFAA, 0xFFAA1234, 0xBEEF8899, 0x88991234, 0x1122CD44, 0xABCD7788], # ds_cmpst_f32 and buffer_atomic_fcmpswap: float compare (cs_w32_fcmpswap.asm) "cs_w32_fcmpswap": [0, 0x3F800000, 0x7FC00000, 0x3F800000, 0x80000000, 0x40400000, 0x3F800000, 0x7FC00000], + # global/buffer_atomic_csub: inactive lanes on a trap word, buffer elements past the V# range + # (cs_w32_csub_ext.asm) + "cs_w32_csub_ext": [0xAAAAAAAA, 0x77770054, 0x023005C8, 0xAAAAAAAA, 0x55550012, 0x0019001E, 0x00990000, 0x00AB0003], "cs_w32_new_ops": [0x55, 0x8001, 0xC0000000, 0x80014000, 0x4000FFFF, 0x77, 0x99, 0x1234], "cs_w32_misc_ext": [0x0FFF0FFF, 0xE2C4A688, 0x0007FFFF, 0x7FFF8000, 0xFFFE0002, 0xFFFF0005, 0x509, 0xCAFEF00D], "cs_w32_salu64": [0x1E6A2C48, 0x1234, 0xFFFFFFFF, 0x100, 47, 48, 0xFFFF8000, 0xFFFFFFFE], @@ -1339,7 +1361,7 @@ def run_suite(a, work: str) -> int: "cs_w32_lds_u8_d16", "cs_w32_int_ext", "cs_w32_salu64", "cs_w32_misc_ext", "cs_w32_new_ops", "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", + "cs_w32_csub_ext", "cs_lds_b64_cmpst", "cs_lds_xchg64_ext", "cs_lds_atomics_ext", "cs_exec_const", "cs_w32_mask_imm", "cs_mask_vgpr_exec", "cs_dpp", "cs_dpp_row", "cs_dpp_mask", "cs_dpp8", "cs_dpp_ops", "cs_dpp_bound", "cs_dpp_bank", "cs_dpp_fi", "cs_dpp_cmp", "cs_w32_andn2_exec", "cs_w32_exec_computed") and not emulated and not partial 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 c1f48fd462..0d3e5dedef 100644 --- a/tests/test_rdna2_decode.py +++ b/tests/test_rdna2_decode.py @@ -443,7 +443,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": @@ -460,7 +462,7 @@ def norm_arg(a, op=""): if ins and ins["enc"]: assembled.append(ins) 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)