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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/design.md
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ How the generated SPIR-V expects the runtime to work:
| Workgroup barriers | `s_barrier` (cs/ms) is one `OpControlBarrier` (workgroup scope, workgroup memory). On RDNA every `s_barrier` counts against the same workgroup barrier and a wave that has ended no longer counts, while Vulkan requires a barrier to be reached by every invocation in uniform control flow. Under `--wave64-emulate` the round loop keeps a single barrier at the top level, so this holds. **Native wave32 compute shaders run in barrier rounds** when an `s_barrier` sits anywhere but a top-level block of the structured tree (one every invocation runs): under a guard, in a loop, or in the dispatch loop (`needs_barrier_rounds`, `bar_scheduler`). That is the emulated loop without its cross-lane part: `s_barrier` ends a segment, each invocation runs its blocks until its next `s_barrier` or the end, then the whole workgroup meets at one `OpControlBarrier` (the same workgroup/acquire-release/workgroup-memory semantics) at the end of the round. A wave that is done no longer holds the others, and a per-round count of the invocations not done (three `Workgroup` words, by round mod 3) ends the loop. Cross-lane operations stay subgroup operations, as in the dispatch loop, since a wave's lanes run the same segment. A barrier in a top-level block keeps the single `OpControlBarrier` in place. In the 1.0.2.1 corpus 43 of the 55 wave32 cs shaders with `s_barrier` have one nested (SHADER-91's count), so those 43 now run in rounds. Why: an Intel GPU does not survive the nested form. `cs_barrier_divergent.asm` (two barrier sites in different branches), `cs_barrier_early_end.asm` (the other waves end without a barrier) and `cs_barrier_loop.asm` (a barrier in a loop whose trip count differs per wave) each lose the device (`vkQueueWaitIdle` → `VK_ERROR_DEVICE_LOST`) on an Intel Arrow Lake Xe-LPG iGPU (Windows 32.0.101.8132), and `cs_barrier_divergent` hangs or writes nothing on a UHD 770 (101.6129, #634). With barrier rounds all three pass there and on an RTX 5070 Ti Laptop (617.42). NVIDIA passed them before too (RTX 4070 Ti on 610.88 and 621.24, RTX 5090 on Linux 595.99, RTX 5070 Ti). **Still not proven on the native wave64 path** (wave64 cs and every ms, run natively only on AMD's 64-wide subgroups): there the barrier stays where `s_barrier` is, inside a selection or loop construct in every ms and most wave64 cs shaders of the corpus. Branches are scalar, so whole waves take the same path, and RDNA's own barrier counts the way the shader expects. |
| LDS | A `Workgroup` uint array sized from LDS_SIZE, rounded up to a power of two that also covers every constant offset (15 of 486 shaders index past LDS_SIZE). Covers `ds_read/write_b32..b128`, `read2/write2` (+`st64`), `u16`/`i16`/`u8`/`i8` reads (also `ds_read_u16_d16`/`_d16_hi` and, since SHADER-85, `ds_read_u8_d16`/`_d16_hi` and `ds_read_i8_d16`/`_d16_hi`: the byte is zero- or sign-extended 8→16 into one half of the destination VGPR and the other half is kept, per the RDNA2 ISA DS opcode descriptions (opcodes 162–165) and as for the u16 d16 reads; GPU-checked with `cs_w32_lds_u8_d16.asm`, byte values 0x80/0xFF/0x7F with a non-zero `offset:`), `b16`/`b8` writes (atomic and/or, so neighbouring lanes don't race), the add/sub/min/max/and/or/xor atomics with and without return, `wrxchg`, `cmpst` (`OpAtomicCompareExchange` with DATA as comparator and DATA2 as value), and `ds_bpermute_b32` as a subgroup shuffle. `ds_permute_b32`, its forward (scatter) form, has no Vulkan equivalent: each source lane that is on in EXEC publishes `((vAddr + offset) >> 2) mod 32` and each destination lane scans the 32 sources of its half and keeps the last one that targets it (a shuffle of target and data per source lane; under `--wave64-emulate` two buffer rounds and a Function variable instead). Per the ISA pseudocode (`tmp[0..63] = 0`; `next if !EXEC[i]` on the source; `VGPR[VDST][i] = tmp[i]` only `if EXEC[i]`): a destination lane nobody targets gets 0, an off source sends nothing, an off destination keeps its VDST, and the half rule above applies as for `ds_bpermute_b32`. When several sources target one lane the ISA leaves the winner unpredictable ("the value from one of the writers"; its pseudocode says the highest-numbered); the translator takes the highest, and nothing may depend on it. Confirmed by the GPU tests `cs_w32_permute.asm` and, per half of a wave64, `cs_w64x_permute.asm` (SHADER-90: rotation, offset, unwritten lane = 0, off destination keeps its value, off source does not win) and `tests/semantic/test_ds_permute.py`. **Hardware-verified on RDNA2 (`gfx1036`, AMD Ryzen 7 9800X3D iGPU, Linux AMDGPU DRM via `tools/hw_oracle`, wave32 and wave64, SHADER-133)** with `tools/ds_permute_probe.py` (9/9 cases exact in both wave sizes): unaddressed active lanes get 0, off destinations keep VDST, off sources send nothing, 2-/4-/32-way collisions deterministically take the highest-numbered active lane in the 32-lane half (matching the translator), `vAddr + offset` carries from the low 2 bits before `>> 2` mod 32, wave64 runs as two independent 32-lane halves (`+32` wraps within each half), and missing lanes of a partial wave (20 threads in wave32, 40 in wave64) send nothing. A source lane that is off in EXEC reads 0 and an off destination lane keeps its value (RDNA ISA §10.4.4), in wave32 as in wave64. In wave64 the permute also runs as two wave32s: each half reads lanes of its own half. Until 2026-11-21 lanes 32–63 of a 64-wide subgroup read the low half and inactive sources kept their value (`cs_w64x_bpermute`, AMD Radeon 880M); the wave32 path shuffled the raw value until the same day (`cs_bpermute32`: wave32, EXEC without lanes 8–15, so lane 6 reads 0; GPU-checked on RTX 5070 and Radeon 880M). A source lane that doesn't exist, in the missing lanes of a partial wave, also reads 0: the shuffle result is kept only where a ballot of the running invocations has the source lane, since SPIR-V leaves a shuffle from an invocation that isn't running undefined. Before this, RADV returned stale register values that changed between runs (`cs_w64x_partial`, a 40-thread group, native wave64 on AMD RX 6700 XT, RADV Mesa 26.3.1). Writes and atomics run only in active lanes. Indices wrap at the array size, where hardware would return 0 for out-of-range reads. `s_barrier` = `OpControlBarrier` Workgroup/Workgroup, AcquireRelease + WorkgroupMemory. |
| `ds_cmpst_b32` | The non-returning compare-and-store: `M = (M == data0) ? data1 : M`, the same `OpAtomicCompareExchange` as `ds_cmpst_rtn_b32` with the old value dropped (operands vaddr, data0, data1). Source: RDNA2 ISA DS_CMPST_B32. CPU-checked by `tests/semantic/test_lds_atomics_values.py`; GPU-checked by `runtime/test/shaders/cs_lds_b64_cmpst.asm` (hit and miss on an RTX 3070, driver 621.01, Windows 11), and measured on native gfx1100 through `tools/hw_oracle` (hit, miss and hit-to-zero), where GFX11 spells it `ds_cmpstore_b32` with the store value before the compare value. **Not GPU-verified.** GPU-checked by `runtime/test/shaders/cs_lds_b64_cmpst.asm` (hit and miss on an RTX 3070, driver 621.01, Windows 11). |
| `ds_cmpst_f32`/`_rtn_f32`, `global_atomic_fcmpswap`, `buffer_atomic_fcmpswap` | `tmp = M; M = (tmp == CMP as binary32) ? DATA : tmp`, and the returning forms give `tmp` (RDNA2 ISA). The compare is a float compare (`OpFOrdEqual`): −0 matches +0, and a NaN never matches, not even the same bits. `OpAtomicCompareExchange` compares bits, so this is a loop (`Gen.float_cmpswap_loop`): read M, pick DATA or M by the float compare, and swap that in if M still holds what was read. Exact under contention. Operands: `ds_cmpst_f32` takes CMP then DATA, as `ds_cmpst_b32`; the global and buffer forms take `vdata` as {DATA, CMP}, as `cmpswap`. Inactive lanes, bounds and `glc` are as for their integer siblings. **Not measured:** subnormal inputs; the interpreter compares them exactly. `_x2` forms stay `Unsupported`; the image form is #2653's. Until 2026-11-22 all four raised `Unsupported`. CPU-checked by `tests/semantic/test_float_cmpswap.py` (±0, NaN, ∞, a subnormal, no `glc`, buffer bounds, 32 lanes on one dword). **Not GPU-verified.** |
| LDS ADDTID (`ds_read_addtid_b32`, `ds_write_addtid_b32`) | The LDS forms address one dword at `M0[15:0] + offset + 4 * lane`, where `offset` is an unsigned 16-bit byte offset and `lane` is the invocation index within the RDNA wave. The Workgroup array supplies LDS_BASE. The compute/mesh path uses the ordinary LDS addressing and EXEC guard. The GDS form raises `Unsupported`. Source: RDNA2 ISA §10.4 and §12.13 (opcodes 176/177), LLVM GFX1030 assembly syntax. `tests/semantic/test_lds_addtid.py` compares the two forms with ordinary LDS reads/writes over two waves, including partial EXEC and emulated wave64. |
| `ds_add_f32`, `ds_add_rtn_f32` | `M = M + DATA` as binary32 on the LDS dword (RDNA2 ISA, `DS_ADD_F32`); the `_rtn_` form returns the old M. No core SPIR-V atomic adds floats on Workgroup memory, so it is an `OpAtomicCompareExchange` loop with an `OpFAdd` (round to nearest even, `NoContraction`). That is exact under contention: every update is one successful exchange of the value it read. **Not measured:** how the LDS adder treats denormals and NaN payloads; the result is `OpFAdd`'s IEEE sum. The f32 min/max forms are #2495's. Until 2026-11-22 both raised `Unsupported`. CPU-checked by `tests/semantic/test_lds_add_f32.py` (a value grid, the non-returning form, `offset:`, ties to even, -0 + +0, overflow to ±inf, seeded values, against a once-rounded double sum). **Not GPU-verified.** |
| `ds_mskor_b32`, `ds_mskor_rtn_b32` | `tmp = M[A]; M[A] = (tmp & ~DATA) | DATA2`; the `_rtn_` form returns `tmp` (RDNA2 ISA, DS). Emitted as an atomic AND with `~DATA`, whose result is `tmp`, then an atomic OR with `DATA2`, so the returned value is exact. DATA2 bits outside DATA are ORed in too, as the formula says; it isn't a masked insert. **Approximation:** the memory ends as the single op leaves it unless another lane's op on the same dword lands between the two atomics. Until 2026-11-22 both raised `Unsupported`. CPU-checked by `tests/semantic/test_lds_mskor.py` (a value grid, the non-returning form, DATA2 outside DATA, `offset:`, seeded values). Measured on native gfx1100, including DATA2 bits outside DATA being ORed in, so it is not a masked insert. **Not GPU-verified.** |
Expand Down
4 changes: 3 additions & 1 deletion runtime/test/shaders/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def not_found_message(build, missing):
"cs_w32_lds_subdword", "cs_w32_lds_wide",
"cs_w32_partial_scmp", "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_w32_andn2_exec",
"cs_mask_vgpr_exec")
"cs_mask_vgpr_exec", "cs_w32_fcmpswap")
# 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
Expand Down Expand Up @@ -115,6 +115,8 @@ def not_found_message(build, missing):
# 64-bit scalar data ops and v_mad_u64_u32 (derivations in cs_w32_salu64.asm)
# more ops with CPU-only checks until now (derivations in cs_w32_misc_ext.asm)
# ops merged on 2026-11-22 with CPU-only checks (derivations in cs_w32_new_ops.asm)
# 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]),
("cs_w32_misc_ext", [0x0FFF0FFF, 0xE2C4A688, 0x0007FFFF, 0x7FFF8000, 0xFFFE0002, 0xFFFF0005, 0x509, 0xCAFEF00D]),
("cs_w32_salu64", [0x1E6A2C48, 0x1234, 0xFFFFFFFF, 0x100, 47, 48, 0xFFFF8000, 0xFFFFFFFE]),
Expand Down
84 changes: 84 additions & 0 deletions runtime/test/shaders/cs_w32_fcmpswap.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
; ds_cmpst_f32 / ds_cmpst_rtn_f32 and buffer_atomic_fcmpswap (#3153): a float compare, so -0 matches +0 and a NaN
; never matches, not even its own bits. Lane 0 of a wave32 group stores eight dwords:
; out[0] = ds_cmpst_rtn_f32 old value (LDS +0, CMP -0, DATA 1.0) = 0x00000000
; out[1] = the LDS word after it: -0 == +0, so DATA is stored = 0x3F800000
; out[2] = the LDS word after ds_cmpst_rtn_f32 (LDS NaN, CMP the same NaN, DATA 1.0) = 0x7FC00000
; out[3] = the LDS word after ds_cmpst_f32 (LDS 1.0, CMP 2.0, DATA 3.0): no match = 0x3F800000
; out[4] = buffer_atomic_fcmpswap glc old value (M -0 at byte 0x40, DATA 3.0, CMP +0) = 0x80000000
; out[5] = the word at byte 0x40 after it: -0 == +0 = 0x40400000
; out[6] = the word at byte 0x44 after fcmpswap (M 1.0, DATA 2.0, CMP 0x3F800001) = 0x3F800000
; out[7] = buffer_atomic_fcmpswap glc old value (M NaN at byte 0x48, DATA 1.0, CMP NaN) = 0x7FC00000
; The atomic words are seeded with buffer_store_dword first. EXEC is cut to lane 0 before any memory op (one address
; per op, #1850).
; group: 32,1,1
; Run: vk_compute_test cs_w32_fcmpswap.spv 1 dump -> out[0..7] = 0 1065353216 2143289344 1065353216 2147483648 1077936128 1065353216 2143289344
; mattr: +wavefrontsize32,-wavefrontsize64
v_cmpx_eq_u32_e32 0, v0
v_mov_b32_e32 v10, 0x40
v_mov_b32_e32 v11, 0
ds_write_b32 v10, v11
s_waitcnt lgkmcnt(0)
v_mov_b32_e32 v12, 0x80000000
v_mov_b32_e32 v13, 1.0
ds_cmpst_rtn_f32 v14, v10, v12, v13
s_waitcnt lgkmcnt(0)
ds_read_b32 v15, v10
v_mov_b32_e32 v16, 0x80
v_mov_b32_e32 v17, 0x7fc00000
ds_write_b32 v16, v17
s_waitcnt lgkmcnt(0)
ds_cmpst_rtn_f32 v18, v16, v17, v13
s_waitcnt lgkmcnt(0)
ds_read_b32 v18, v16
v_mov_b32_e32 v19, 0xc0
ds_write_b32 v19, v13
s_waitcnt lgkmcnt(0)
v_mov_b32_e32 v12, 2.0
v_mov_b32_e32 v11, 0x40400000
ds_cmpst_f32 v19, v12, v11
s_waitcnt lgkmcnt(0)
ds_read_b32 v21, v19
s_waitcnt lgkmcnt(0)
v_mov_b32_e32 v20, 0x40
v_mov_b32_e32 v22, 0x80000000
buffer_store_dword v22, v20, s[0:3], 0 offen
v_mov_b32_e32 v20, 0x44
buffer_store_dword v13, v20, s[0:3], 0 offen
v_mov_b32_e32 v20, 0x48
buffer_store_dword v17, v20, s[0:3], 0 offen
s_waitcnt_vscnt null, 0
v_mov_b32_e32 v20, 0x40
v_mov_b32_e32 v2, 0x40400000
v_mov_b32_e32 v3, 0
buffer_atomic_fcmpswap v[2:3], v20, s[0:3], 0 offen glc
v_mov_b32_e32 v20, 0x44
v_mov_b32_e32 v4, 2.0
v_mov_b32_e32 v5, 0x3f800001
buffer_atomic_fcmpswap v[4:5], v20, s[0:3], 0 offen
v_mov_b32_e32 v20, 0x48
v_mov_b32_e32 v6, 1.0
v_mov_b32_e32 v7, 0x7fc00000
buffer_atomic_fcmpswap v[6:7], v20, s[0:3], 0 offen glc
s_waitcnt vmcnt(0)
v_mov_b32_e32 v20, 0x40
buffer_load_dword v8, v20, s[0:3], 0 offen glc
v_mov_b32_e32 v20, 0x44
buffer_load_dword v9, v20, s[0:3], 0 offen glc
s_waitcnt vmcnt(0)
v_mov_b32_e32 v20, 0
buffer_store_dword v14, v20, s[0:3], 0 offen
v_mov_b32_e32 v20, 4
buffer_store_dword v15, v20, s[0:3], 0 offen
v_mov_b32_e32 v20, 8
buffer_store_dword v18, v20, s[0:3], 0 offen
v_mov_b32_e32 v20, 12
buffer_store_dword v21, v20, s[0:3], 0 offen
v_mov_b32_e32 v20, 16
buffer_store_dword v2, v20, s[0:3], 0 offen
v_mov_b32_e32 v20, 20
buffer_store_dword v8, v20, s[0:3], 0 offen
v_mov_b32_e32 v20, 24
buffer_store_dword v9, v20, s[0:3], 0 offen
v_mov_b32_e32 v20, 28
buffer_store_dword v6, v20, s[0:3], 0 offen
s_endpgm
6 changes: 4 additions & 2 deletions scripts/run_gpu_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,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_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_fcmpswap", "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_w64",
"cs_w64_mask_detect",
Expand All @@ -971,6 +971,8 @@ def run_suite(a, work: str) -> int:
# 64-bit scalar data ops and v_mad_u64_u32 (cs_w32_salu64.asm)
# more ops with CPU-only checks until now (cs_w32_misc_ext.asm)
# ops merged on 2026-11-22 with CPU-only checks (cs_w32_new_ops.asm)
# 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],
"cs_w32_misc_ext": [0x0FFF0FFF, 0xE2C4A688, 0x0007FFFF, 0x7FFF8000, 0xFFFE0002, 0xFFFF0005, 0x509, 0xCAFEF00D],
"cs_w32_salu64": [0x1E6A2C48, 0x1234, 0xFFFFFFFF, 0x100, 47, 48, 0xFFFF8000, 0xFFFFFFFE],
Expand Down Expand Up @@ -1058,7 +1060,7 @@ def run_suite(a, work: str) -> int:
"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_subdword", "cs_w32_lds_wide",
"cs_bpermute32", "cs_w32_partial_scmp", "cs_w32_sincos",
"cs_bpermute32", "cs_w32_partial_scmp", "cs_w32_sincos", "cs_w32_fcmpswap",
"cs_lds_b64_cmpst", "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_w32_andn2_exec") and not emulated and not partial
Expand Down
Loading