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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/design.md
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ How the generated SPIR-V expects the runtime to work:
| Full-corpus pipeline build | `vk_pipeline_check <spirv dir> pipeline_cache.bin --jobs 4` on an RTX 4060 Ti (NVIDIA 595 driver): **all 26,503 shaders become real pipelines, 0 failures** (cs 2,689, ps 12,101, ms 9,282, vs 2,236, gs 195; graphics stages with generated stub partners). Compile time 40,784 s of CPU (2.84 h wall on 4 threads): cs 23,633 s (mean 8.8 s; the ray-tracing ScreenProbes/RTShadowTrace shaders take 2-19 min each), ps 11,481 s, ms 5,395 s, vs 275 s. The resulting `VkPipelineCache` is 3.81 GB; seeding a run with it makes those pipelines instant, which is what a fast first boot needs. The cache is per driver and GPU, and a shader whose SPIR-V changes compiles again (the checker resumes from the file). Neither register storage (one variable per register) nor smaller SPIR-V cut NVIDIA compile time: the big ray-tracing shaders are expensive as such, so the runtime should compile them in the background rather than block on them. |
| Wave-uniform branches | VCC and EXEC are wave-wide registers, but one invocation holds only its own lane's bit. `s_cbranch_vccz/vccnz/execz/execnz` therefore reduce the condition across the subgroup (`OpGroupNonUniformAny`), so the whole wave takes the branch together, as on hardware. Before this, each lane decided alone. A lane could skip scalar instructions that the hardware wave executes (its SGPRs went stale for later code), and cross-lane ops or barriers inside the block saw a split wave. `v_cmp`/`v_cmp_class`/64-bit compares now write 0 for inactive lanes (hardware VOPC behaviour), so the reduction sees the true mask. GPU-checked with `runtime/test/shaders/ps_uniform_branch.asm`: lanes whose own VCC bit is 0 run the block's scalar add when their wave has any set bit. `s_cbranch_scc0/1` stay per lane; SCC is uniform as long as the SGPRs feeding it are. |
| Compute shaders | FSSM header word **0x138 = `COMPUTE_PGM_RSRC2`**: USER_SGPR [5:1], TGID_X/Y/Z_EN [9:7], TG_SIZE_EN [10], TIDIG_COMP_CNT [12:11], LDS_SIZE [23:15] in 512-byte units. Words **0x13C/0x140/0x144 = thread-group size**. This was checked against what all 2,689 CS read before writing: 2,281 match exactly, and the rest overshoot only through loop-carried registers in the straight-line check. 0x110, which looked similar, doesn't match. Layout: s0..user−1 = user data (push constants), then the enabled workgroup IDs (`WorkgroupId`), and v0/v1/v2 = thread ID x/y/z (`LocalInvocationId`, separate VGPRs on GFX10). Example: the 1,013 shaders with RSRC2 `0x998` have 12 user SGPRs, group ID x/y in s12/s13, and compute x = s12·32 + v0. Shaders with TG_SIZE_EN are rejected for now. GPU-checked with `runtime/test/shaders/cs_lds.asm` through `runtime/test/vk_compute_test.cpp`: 4 groups × 64 threads, LDS exchange between the two waves of a group behind `s_barrier`, store through a V# into the device-address heap, 0 mismatches. |
| 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. **On the native path it is not proven:** the barrier stays where `s_barrier` is, and in the 1.0.2.1 corpus it sits inside a selection or loop construct in 43 of the 55 wave32 cs shaders with `s_barrier` (always native) and in every ms and most wave64 cs shaders when they run natively (AMD). Branches are scalar, so whole waves take the same path. No hang has been seen: `cs_barrier_divergent.asm` (two barrier sites in different branches), an early end of the other waves and a per-wave loop count all pass on NVIDIA RTX 4070 Ti (drivers 610.88 and 621.24) and RTX 5090 (Linux 595.99). SHADER-91 tracks this; a barrier-only round scheduler (the emulated loop without its cross-lane part) is the fix if a hang shows up. |
| 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`. 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`. **Not GPU-verified.** |
| 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`. In wave64 the permute runs as two wave32s (RDNA ISA §10.4.4): each half reads lanes of its own half, and a source lane that is off in EXEC reads 0. 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). 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. |
Expand Down
9 changes: 7 additions & 2 deletions runtime/test/shaders/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ def not_found_message(build, missing):
CS_STORE = [0x400080ff, 0xe00003ff, 0x3c004000, 0xeeeeeeee, 0x40003c00, 0xbc003800]
CS_SMEM = [0x5eed0024, 0x5eed0028, 0x5eed002c, 0x5eed0030, 0x5eed0010, 0x5eed0014, 0x5eed0018, 0x5eed001c]
WAVE32_DUMPS = ("cs_store", "cs_smem_soffset_imm", "cs_wqm_w32", "cs_w32_lane_wrap", "cs_movrelsd_2", "cs_w32_permute",
"cs_barrier_divergent", "cs_w32_lds_u8_d16", "cs_bpermute32", "cs_w32_partial_scmp", "cs_exec_const")
"cs_barrier_divergent", "cs_barrier_early_end", "cs_barrier_loop", "cs_w32_lds_u8_d16", "cs_bpermute32",
"cs_w32_partial_scmp", "cs_exec_const")
# 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.
WAVE32_LANE_DUMPS = ("cs_wqm_w32", "cs_w32_lane_wrap", "cs_w32_permute", "cs_bpermute32", "cs_w32_partial_scmp", "cs_exec_const")
Expand All @@ -101,7 +102,11 @@ def not_found_message(build, missing):
("cs_w32_partial_scmp", [0, 1, 1, 0, 1, 1, 1, 1]), # a 20-thread wave32: s_cmp mask, -1
("cs_wqm_w64_half", [11, 14, 0, 1, 6, 8, 12, 2]),
# SHADER-91: two s_barrier sites in wave-uniform branches meet like one barrier; wave 0 reads wave 3
("cs_barrier_divergent", [127, 126, 125, 124, 123, 122, 121, 120])]
("cs_barrier_divergent", [127, 126, 125, 124, 123, 122, 121, 120]),
# SHADER-91: waves that end without an s_barrier don't hold the barrier of the ones still running
("cs_barrier_early_end", [127, 126, 125, 124, 123, 122, 121, 120]),
# SHADER-91: a barrier in a loop with a per-wave trip count; the k-th one waits for the waves still running
("cs_barrier_loop", [128, 96, 64, 32, 128, 96, 64, 0xEEEEEEEE])]
# num_records bounds check (cs_bounds.asm): one thread, so no 64-wide subgroup requirement.
# The SMEM and raw MUBUF rules measured on an RX 6800 (derivations in each .asm header): one thread too.
# Never run cs_smem_sload_neg with a translator that zero-extends the s_load immediate: it reads 4 GiB past the heap.
Expand Down
22 changes: 22 additions & 0 deletions runtime/test/shaders/cs_barrier_early_end.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
; group: 128,1,1
; SHADER-91: a wave that has ended no longer counts at s_barrier. Wave32, 128 threads = 4 waves. Every thread
; writes its id to LDS[id]; waves 1-3 then end without an s_barrier, and wave 0 waits at one. On RDNA the barrier
; releases once the other waves have ended, and wave 0 reads what wave 3 wrote: out[i] = LDS[127 - i] = 127 - i.
; Translated, the s_barrier sits in a branch that only wave 0 takes: Intel's driver loses the device on that
; (an OpControlBarrier outside uniform control flow); barrier rounds keep the barrier at the top level.
; Run: vk_compute_test cs_barrier_early_end.spv 1 dump
; Expect: out[0..7] = 127 126 125 124 123 122 121 120
v_lshlrev_b32_e32 v2, 2, v0
ds_write_b32 v2, v0
s_waitcnt lgkmcnt(0)
v_readfirstlane_b32 s5, v0
s_lshr_b32 s5, s5, 5
s_cmp_lg_u32 s5, 0
s_cbranch_scc1 9
s_barrier
v_sub_nc_u32_e32 v3, 0x1fc, v2
ds_read_b32 v4, v3
s_waitcnt lgkmcnt(0)
v_cmpx_gt_u32_e32 8, v0
buffer_store_dword v4, v2, s[0:3], 0 offen
s_endpgm
37 changes: 37 additions & 0 deletions runtime/test/shaders/cs_barrier_loop.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
; group: 128,1,1
; SHADER-91: s_barrier in a loop whose trip count differs per wave. Wave32, 128 threads = 4 waves; wave w runs
; w + 1 iterations. Iteration k adds 1 to LDS[k] from each of the wave's 32 lanes, waits at s_barrier, then
; reads LDS[k] and stores it to out[4 * (3 - w) + k]. On RDNA every s_barrier counts against the same barrier
; and a wave that has ended no longer counts, so the k-th barrier releases once every wave still running has
; added to LDS[k]: LDS[k] = 32 * (4 - k) when read. Wave 3 stores out[0..3] and wave 2 out[4..6]; out[7] would
; be wave 2's fourth iteration, which it doesn't run, so it keeps the sentinel 0xeeeeeeee.
; Run: vk_compute_test cs_barrier_loop.spv 1 dump
; Expect: out[0..7] = 128 96 64 32 128 96 64 4008636142
v_lshlrev_b32_e32 v2, 2, v0
v_mov_b32_e32 v3, 0
v_cmpx_gt_u32_e32 4, v0
ds_write_b32 v2, v3
s_mov_b32 exec_lo, -1
s_waitcnt lgkmcnt(0)
s_barrier
v_readfirstlane_b32 s5, v0
s_lshr_b32 s5, s5, 5
s_add_u32 s6, s5, 1
s_sub_u32 s9, 3, s5
s_lshl_b32 s9, s9, 4
s_mov_b32 s7, 0
v_mov_b32_e32 v5, 1
v_mov_b32_e32 v1, s7
ds_add_u32 v1, v5
s_waitcnt lgkmcnt(0)
s_barrier
ds_read_b32 v4, v1
s_waitcnt lgkmcnt(0)
s_add_u32 s10, s9, s7
v_mov_b32_e32 v6, s10
buffer_store_dword v4, v6, s[0:3], 0 offen
s_add_u32 s7, s7, 4
s_sub_u32 s6, s6, 1
s_cmp_lg_u32 s6, 0
s_cbranch_scc1 -16
s_endpgm
12 changes: 9 additions & 3 deletions scripts/run_gpu_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,8 @@ def run_suite(a, work: str) -> int:
"cs_w64x_branch", "cs_w64x_ballot", "cs_w64x_wg128_branches", "cs_w64x_lds_raw",
"cs_w64x_lds_war", "cs_w64x_partial", "cs_w64x_sbarrier", "cs_w64x_load_ballot_load",
"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_bpermute32", "cs_w64x_partial_scmp", "cs_w32_partial_scmp", "cs_barrier_early_end",
"cs_barrier_loop"):
cs_dump_wants = {
"cs_store": [0x400080FF, 0xE00003FF, 0x3C004000, 0xEEEEEEEE, 0x40003C00, 0xBC003800],
# base + soffset + imm (cs_smem_soffset_imm.asm); out[4..7] are seeds the shader leaves alone
Expand Down Expand Up @@ -755,6 +756,10 @@ def run_suite(a, work: str) -> int:
"cs_bpermute32": [0, 50, 162, 99, 36, 218, 183, 15], # wave32: needs 32 lanes
# SHADER-91: s_barrier sites in different wave-uniform branches meet (cs_barrier_divergent.asm)
"cs_barrier_divergent": [127, 126, 125, 124, 123, 122, 121, 120],
# SHADER-91: other waves end without s_barrier (cs_barrier_early_end.asm); a loop whose trip count
# differs per wave (cs_barrier_loop.asm)
"cs_barrier_early_end": [127, 126, 125, 124, 123, 122, 121, 120],
"cs_barrier_loop": [128, 96, 64, 32, 128, 96, 64, 0xEEEEEEEE],
}
want = cs_dump_wants[name]
# Every dump but cs_store / cs_smem_soffset_imm / cs_w32_lane_wrap / cs_movrelsd_2 / cs_w32_permute /
Expand All @@ -767,8 +772,9 @@ def run_suite(a, work: str) -> int:
emulated = w64_emulated()
partial = name in ("cs_w64x_partial", "cs_w64x_partial_scmp")
wave64 = name not in ("cs_store", "cs_smem_soffset_imm", "cs_wqm_w32", "cs_w32_lane_wrap", "cs_movrelsd_2",
"cs_w32_permute", "cs_barrier_divergent", "cs_w32_lds_u8_d16", "cs_bpermute32",
"cs_w32_partial_scmp", "cs_exec_const") and not emulated and not partial
"cs_w32_permute", "cs_barrier_divergent", "cs_barrier_early_end", "cs_barrier_loop",
"cs_w32_lds_u8_d16", "cs_bpermute32", "cs_w32_partial_scmp",
"cs_exec_const") and not emulated and not partial

if partial and not emulated:
cs_env = dict(os.environ, VKC_SUBGROUP_SIZE="64")
Expand Down
Loading