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
2 changes: 1 addition & 1 deletion docs/design.md
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ How the generated SPIR-V expects the runtime to work:
| Piece | Contract |
|---|---|
| Heap-relative buffer device addresses | `Gen.host_addr` sign-extends the low 48 bits of the effective VA after adding any byte offset, then adds `%heap_base`. The runtime stores `device_address - heap_base` in a V#'s 48-bit base field. NVIDIA's Windows driver can place an imported buffer below the heap, so that offset is negative. Zero extension made the resulting device address too high by `2^48`. Console user-mode VAs below `2^47` and full-width root descriptor addresses already within the signed 48-bit range retain their values. A 64-bit base-plus-offset sum gives the correct address for effective VAs in that range, including when the sum crosses zero. Each new shader's `index.json` entry carries `"vsharp_base_sign_extended": true`. Check the field on all loaded entries before enabling below-arena imports for a library, because older modules can share an index with newly translated ones. `tests/semantic/test_vsharp_sext48.py` checks the emitted shifts, both reads against synthetic memory, and the metadata field. |
| Null sources in 64-bit integer VALU compares | `v_cmp` and `v_cmpx` relations `eq`, `ne`, `lt`, `le`, `gt`, `ge` on `u64` and `i64` read `null` as the 64-bit value 0 in either source, like immediate `0`. Register pairs and immediates retain their existing semantics; `v_cmp` writes the active lane's comparison to VCC/SGPR, while `v_cmpx` narrows EXEC without changing VCC. Source: RDNA2 ISA special operand `null` reads zero; LLVM `llvm-mc -mcpu=gfx1013` accepts the encoding. CPU-checked by `tests/semantic/test_vcmp64_null_src.py` (both sources, signed/unsigned ordering, equality, e32/e64, EXEC and inactive lanes); **not GPU-verified, no corpus count**. |
| Null sources in 64-bit integer VALU compares | `v_cmp` and `v_cmpx` relations `eq`, `ne`, `lt`, `le`, `gt`, `ge` on `u64` and `i64` read `null` as the 64-bit value 0 in either source, like immediate `0`. Register pairs and immediates retain their existing semantics; `v_cmp` writes the active lane's comparison to VCC/SGPR, while `v_cmpx` narrows EXEC without changing VCC. Source: RDNA2 ISA special operand `null` reads zero; LLVM `llvm-mc -mcpu=gfx1013` accepts the encoding. CPU-checked by `tests/semantic/test_vcmp64_null_src.py` (both sources, signed/unsigned ordering, equality, e32/e64, EXEC and inactive lanes) and GPU-verified on an NVIDIA GeForce RTX 3070 (Vulkan 1.4.357, driver 621.24, native and `--wave64-emulate`) and NVIDIA GeForce RTX 5070 (Windows 11, Vulkan validation on) by `runtime/test/shaders/cs_w32_vcmp64_null.asm` (all 8 lane-mask/VCC words exact); **no corpus count**. |
| `s_load_dword*` with `vcc` 64-bit base pointer | SMEM `s_load_dword*` accepts `vcc` (`{vcc_lo, vcc_hi}`, hardware `s[106:107]`) as its 64-bit base pointer in `Gen.scalar_load`, loading `%vcc` as the low dword and `%vcc_hi` as the high dword; `s_buffer_load*` still requires a 4-dword V# and rejects 2-dword `vcc`. Source: RDNA2 ISA SMEM `SBASE` encoding (`sbase = 53` -> `s[106:107] = vcc`). Confirmed by corpus count over the 2,684-shader pipeline library compute corpus (79 shaders use `vcc` as the `s_load` base: 72 `s_load_dwordx4 sgpr, vcc`, 6 `s_load_dwordx8 sgpr, vcc`, 1 `s_load_dwordx4 slist, vcc`; all 79 translate and pass `spirv-val` under `--wave64-emulate`) and CPU-checked by `tests/semantic/test_sload_vcc_base.py` (`spirv-as` + `spirv-val`) and `tests/semantic/test_scalar_mem_smem.py` (both halves and the resulting addresses); **not GPU-verified**: the synthetic `runtime/test/shaders/cs_smem_vcc_base.asm` reads back eight seeded words through the pair in the standard GPU runner. |
| Execution model | One invocation = one lane. Compute and mesh waves derive lanes from the workgroup-local index; other stages use the subgroup lane. A wave = a subgroup, so cross-lane ops (`ds_swizzle`, `v_permlane*`, `v_readlane`/`v_writelane`, `v_mbcnt`) become subgroup shuffles. Wave32 pixel shaders split a 64-lane physical subgroup into two logical waves: lane IDs are `SubgroupLocalInvocationId & 31`, shuffle sources retain the current half (`& 32`), and ballots/votes use that half's 32-bit word. A value the translator knows is uniform (the bindless descriptor index) is read from the half's first running lane, never from a fixed lane, which need not be running (SHADER-1016). Other stage/wave combinations still require subgroup size == wave size or wave64 emulation. **Requires subgroup size == wave size** (wave32 maps directly onto NVIDIA GPUs; wave64 shaders need a 64-wide subgroup or emulation). `v_readlane_b32`/`v_writelane_b32` mask the lane select with 63 in wave64 (`S1[5:0]`) and 31 in wave32 (`S1[4:0]`); until SHADER-52 both used 63, so a wave32 select ≥ 32 pointed past a 32-wide subgroup. GPU-checked with `cs_w32_lane_wrap.asm` (lane 40 → 8). For the fragment-half rule, `ps_bitmask_perm` produced 4096/4096 exact pixels on an AMD Radeon RX 5700 XT; Vulkan reported a default subgroup size of 64 (range 32..64), but does not permit pinning fragment subgroup size on this device. CPU semantic tests compare a 64-lane wave32 pixel subgroup against two 32-lane subgroups for reads/writes, permutations, ballots, and votes. |
| DPP | VOP1/VOP2 `_dpp` applies to src0. DPP16 controls (`quad_perm`, `row_shl/shr/ror/share/xmask/mirror/half_mirror`) and DPP8 (`dpp8` + `fi`) select the source lane, then `row_mask` (one bit per 16-lane row) and `bank_mask` (one bit per 4-lane bank) decide which destination lanes update. A lane whose row/bank is off is not written. A source lane outside the row is invalid: `bound_ctrl` 1 uses 0 as src0, otherwise the lane is not written. A source lane inactive under EXEC is used when `fi` is 1; otherwise `bound_ctrl` decides. DPP8 always writes an enabled lane: `fi` 1 reads the inactive source, `fi` 0 uses 0. DPP16/8 never leaves its 16/8-lane group, so this is exact on every subgroup at least that wide; under `--wave64-emulate` the exchange goes through the workgroup buffer like the other cross-lane ops. GPU-checked with `runtime/test/shaders/cs_dpp*.asm` on an RTX 3070 and hardware-measured on an RX 6800. On an RX 6700 XT (gfx1031), `tools/crosslane_fuzz.py --dpp-sweep --oracle hw` checks every DPP16 control × `bound_ctrl` × `fi`, every `row_mask`/`bank_mask` pair and the DPP8 selects in wave32 and wave64: 14,412 cases, all matching these rules (BUILD-162, `docs/shader_validation.md` FUZZ-7). The ballot of the source lanes' EXEC bits and the shuffle are each stored to a Function variable of their own (`Gen.eager`): SPIRV-Cross (MoltenVK) inlines a single-use result into the expression that uses it, which put the ballot on the right of a short-circuiting `&&` and the shuffle in a ternary's arm, so lanes out of their row skipped the ballot and row_shr:1's lane 1 found lane 0 inactive (`cs_dpp_ops` on MoltenVK; SHADER-529). A store is a statement every lane runs. For native FI=0, the source-lane ballot bit also selects the shuffle index: an absent or EXEC-off source is redirected to the current subgroup lane before `OpGroupNonUniformShuffle`, because masking an undefined shuffle result afterwards is not sufficient; FI=1 is unchanged. CPU-checked by `tests/semantic/test_dpp_eager_subgroup.py::test_fi0_shuffle_index_is_ballot_safe` with a hand-written `quad_perm` case whose active lane 6 reads absent lane 7 in a seven-invocation wave; **not GPU-verified**. Checked in SPIRV-Cross 1.3.239's MSL for the `cs_dpp*` tests (each op is now its own statement) and by `tests/semantic/test_dpp_eager_subgroup.py`; not yet run on a Mac. Semantics from the RDNA2 ISA, AMD LLVM modifier syntax and the GPUOpen DPP notes. |
Expand Down
7 changes: 5 additions & 2 deletions runtime/test/shaders/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,15 @@ 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_vcmp64_null")
# 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
# otherwise pick a narrower size and return different words (#774).
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_vcmp64_null")
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]),
Expand Down Expand Up @@ -151,6 +151,9 @@ def not_found_message(build, missing):
("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]),
# Null sources in 64-bit integer VALU compares (cs_w32_vcmp64_null.asm)
("cs_w32_vcmp64_null", [0x11111111, 0x77777777, 0x66666666, 0x88888888,
0x00EE00EE, 0x5555AAAA, 0x08888888, 0x96A53C69]),
("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
("cs_w32_lds_u8_d16", [0xBEEF00FF, 0x00FF1234, 0xBEEFFF80, 0xFF801234, 0xBEEF007F, 0x007F1234, 0xBEEF0080, 0xFFFF1234]),
Expand Down
113 changes: 113 additions & 0 deletions runtime/test/shaders/cs_w32_vcmp64_null.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
; Null sources in 64-bit integer VALU compares (docs/design.md contract row):
; v_cmp and v_cmpx relations eq, ne, lt, le, gt, ge on u64 and i64 with null (= 0) in src0, src1, or both.
; Wave32 (32 lanes): each lane i gets a 64-bit value V(i) by (i & 3):
; r=0: 0x00000000_00000000 (0)
; r=1: 0x00000000_00000001 (+1)
; r=2: 0x00000001_00000000 (2^32, high dword non-zero, low dword 0)
; r=3: 0x80000000_00000000 (2^63 unsigned / -2^63 signed)
; Each lane ORs (1 << lane) into LDS[k] when its bit in mask k is set, then lane 0 stores eight 32-bit words:
; out[0] = v_cmp_eq_u64_e32 vcc_lo, null, v[2:3] (0 == V; r=0 only) = 0x11111111
; out[1] = v_cmp_ge_i64_e64 s8, v[2:3], null (V >= 0 signed; r=0,1,2) = 0x77777777
; out[2] = v_cmp_lt_i64_e32 vcc_lo, null, v[2:3] (0 < V signed; r=1,2) = 0x66666666
; out[3] = v_cmp_gt_i64_e64 s10, null, v[2:3] (0 > V signed; r=3 only) = 0x88888888
; out[4] = v_cmp_gt_u64_e64 s11, v[2:3], null under EXEC=0x00FF00FF (V > 0 u64, masked) = 0x00EE00EE
; out[5] = (v_cmp_le_u64_e64 null, null | v_cmp_ne_i64_e64 null, null) under EXEC=0x5555AAAA = 0x5555AAAA
; out[6] = EXEC after v_cmpx_lt_i64_e64 v[2:3], null under EXEC=0x0FFFFFFF (V < 0 signed) = 0x08888888
; out[7] = VCC after that v_cmpx (must keep sentinel 0x96A53C69 untouched) = 0x96A53C69
; group: 32,1,1
; Run: VKC_SUBGROUP_SIZE=32 vk_compute_test cs_w32_vcmp64_null.spv 1 dump -> out[0..7] = 286331153 2004318071 1717986918 2290649224 15597806 1431677610 143165576 2527411305
; mattr: +wavefrontsize32,-wavefrontsize64
; regen_fixtures: wave32
v_and_b32_e32 v4, 3, v0
v_cmp_eq_u32_e32 vcc_lo, 1, v4
v_cndmask_b32_e64 v2, 0, 1, vcc_lo
v_cmp_eq_u32_e32 vcc_lo, 2, v4
v_cndmask_b32_e64 v3, 0, 1, vcc_lo
v_cmp_eq_u32_e32 vcc_lo, 3, v4
v_cndmask_b32_e64 v3, v3, 0x80000000, vcc_lo

v_cmp_eq_u64_e32 vcc_lo, null, v[2:3]
s_mov_b32 s6, vcc_lo

v_cmp_ge_i64_e64 s8, v[2:3], null

v_cmp_lt_i64_e32 vcc_lo, null, v[2:3]
s_mov_b32 s9, vcc_lo

v_cmp_gt_i64_e64 s10, null, v[2:3]

s_mov_b32 exec_lo, 0x00ff00ff
v_cmp_gt_u64_e64 s11, v[2:3], null

s_mov_b32 exec_lo, 0x5555aaaa
v_cmp_le_u64_e64 s12, null, null
v_cmp_ne_i64_e64 s13, null, null
s_or_b32 s12, s12, s13

s_mov_b32 vcc_lo, 0x96a53c69
s_mov_b32 exec_lo, 0x0fffffff
v_cmpx_lt_i64_e64 v[2:3], null
s_mov_b32 s14, exec_lo
s_mov_b32 s15, vcc_lo

s_mov_b32 exec_lo, -1
v_mov_b32_e32 v6, 0
v_mov_b32_e32 v7, 0
v_cmpx_eq_u32_e32 0, v0
ds_write_b32 v6, v7
ds_write_b32 v6, v7 offset:4
ds_write_b32 v6, v7 offset:8
ds_write_b32 v6, v7 offset:12
ds_write_b32 v6, v7 offset:16
ds_write_b32 v6, v7 offset:20
ds_write_b32 v6, v7 offset:24
s_waitcnt lgkmcnt(0)
s_mov_b32 exec_lo, -1
s_barrier

v_mov_b32_e32 v5, 1
v_lshlrev_b32_e32 v5, v0, v5
v_cndmask_b32_e64 v7, 0, v5, s6
ds_or_b32 v6, v7
v_cndmask_b32_e64 v7, 0, v5, s8
ds_or_b32 v6, v7 offset:4
v_cndmask_b32_e64 v7, 0, v5, s9
ds_or_b32 v6, v7 offset:8
v_cndmask_b32_e64 v7, 0, v5, s10
ds_or_b32 v6, v7 offset:12
v_cndmask_b32_e64 v7, 0, v5, s11
ds_or_b32 v6, v7 offset:16
v_cndmask_b32_e64 v7, 0, v5, s12
ds_or_b32 v6, v7 offset:20
v_cndmask_b32_e64 v7, 0, v5, s14
ds_or_b32 v6, v7 offset:24
s_waitcnt lgkmcnt(0)
s_barrier

v_cmpx_eq_u32_e32 0, v0
ds_read_b32 v21, v6
ds_read_b32 v22, v6 offset:4
ds_read_b32 v23, v6 offset:8
ds_read_b32 v24, v6 offset:12
ds_read_b32 v25, v6 offset:16
ds_read_b32 v26, v6 offset:20
ds_read_b32 v27, v6 offset:24
s_waitcnt lgkmcnt(0)
v_mov_b32_e32 v20, 0
buffer_store_dword v21, v20, s[0:3], 0 offen
v_mov_b32_e32 v20, 4
buffer_store_dword v22, v20, s[0:3], 0 offen
v_mov_b32_e32 v20, 8
buffer_store_dword v23, v20, s[0:3], 0 offen
v_mov_b32_e32 v20, 12
buffer_store_dword v24, v20, s[0:3], 0 offen
v_mov_b32_e32 v20, 16
buffer_store_dword v25, v20, s[0:3], 0 offen
v_mov_b32_e32 v20, 20
buffer_store_dword v26, v20, s[0:3], 0 offen
v_mov_b32_e32 v20, 24
buffer_store_dword v27, v20, s[0:3], 0 offen
v_mov_b32_e32 v20, 28
v_mov_b32_e32 v28, s15
buffer_store_dword v28, v20, s[0:3], 0 offen
s_endpgm
7 changes: 5 additions & 2 deletions scripts/run_gpu_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1211,7 +1211,7 @@ def run_suite(a, work: str) -> int:
"cs_w64x_mask_reuse", "cs_w64x_mask_reuse2", "cs_w64x_chain_barrier", "cs_barrier_divergent",
"cs_bpermute32", "cs_w64x_partial_scmp", "cs_w32_partial_scmp", "cs_w32_partial_permute", "cs_barrier_early_end",
"cs_barrier_loop", "cs_w64x_andn2_exec", "cs_w64x_saveexec_b64", "cs_w64x_cmp_sdst", "cs_lds_b64_cmpst", "cs_lds_xchg64_ext", "cs_lds_atomics_ext", "cs_w32_andn2_exec",
"cs_mask_vgpr_exec", "cs_w32_exec_computed", "cs_w64_exec_computed"):
"cs_mask_vgpr_exec", "cs_w32_exec_computed", "cs_w64_exec_computed", "cs_w32_vcmp64_null"):
cs_dump_wants = {
"cs_store": [0x400080FF, 0xE00003FF, 0x3C004000, 0xEEEEEEEE, 0x40003C00, 0xBC003800, 0x40FF8000, 0x3FF00000],
# base + soffset + imm (cs_smem_soffset_imm.asm); out[4..7] are seeds the shader leaves alone
Expand All @@ -1237,6 +1237,9 @@ def run_suite(a, work: str) -> int:
"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],
# Null sources in 64-bit integer VALU compares (cs_w32_vcmp64_null.asm)
"cs_w32_vcmp64_null": [0x11111111, 0x77777777, 0x66666666, 0x88888888,
0x00EE00EE, 0x5555AAAA, 0x08888888, 0x96A53C69],
"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)
"cs_w32_lds_u8_d16": [0xBEEF00FF, 0x00FF1234, 0xBEEFFF80, 0xFF801234, 0xBEEF007F, 0x007F1234, 0xBEEF0080, 0xFFFF1234],
Expand Down Expand Up @@ -1342,7 +1345,7 @@ def run_suite(a, work: str) -> int:
"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
"cs_w32_exec_computed", "cs_w32_vcmp64_null") and not emulated and not partial
if partial and not emulated:
cs_env = dict(os.environ, VKC_SUBGROUP_SIZE="64")
if name in WAVE32_LANE_DUMPS: # 32 lanes even without index.json, as check.py requests (#774)
Expand Down
Loading