Skip to content
1 change: 1 addition & 0 deletions docs/design.md

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions docs/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,14 @@ only for `check.py`, the shaders read the tail from push constants the programs
(`LEONIDA_MESH_COMPUTE=1`) isn't combined with it yet: its vertex shader still reads the output address from push
constants, so those tests skip.

## Mesh shaders with their waves in series

`LEONIDA_MESH_SERIAL_WAVES=1` for `run_gpu_tests.py`, together with `LEONIDA_W64_EMULATE=1`, translates the mesh
shaders with `--mesh-serial-waves` (`docs/design.md`, "Mesh shaders with their waves in series"): the ones that
qualify run one pass per wave in 64 invocations. The `ms_*` tests must pass with and without it;
`ms_w64x_wave_votes` is the one whose two waves take different branches and both give the triangle a vertex. `ms_w64x_wave_loops` is the one whose two waves run a loop of different length (5 and 9 iterations), each iteration reading a wave-wide count, so under emulation the waves reach different numbers of barriers.
With `LEONIDA_MESH_COMPUTE=1` as well (below), the same tests run the passes in the `--mesh-compute` form.

## GPUs without mesh shaders (NVIDIA Pascal and older)

Without `VK_EXT_mesh_shader`, the `ms_*` tests are skipped; that's expected, not a failure. To test the path that
Expand Down
63 changes: 63 additions & 0 deletions runtime/test/shaders/ms_w64x_wave_loops.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
; Mesh shader (NGG, wave64, 128 threads = 2 waves): each wave runs a loop whose every iteration reads a wave-wide
; count, and the two waves leave it after a different number of iterations.
; limit of a lane = (lane & 3) + 1 in wave 0, (lane & 7) + 1 in wave 1.
; each iteration counts the lanes whose limit is above the iteration number (s_bcnt1 of a 64-lane compare), adds
; the count to a sum and goes round again while the count is not 0.
; wave 0: counts 64, 48, 32, 16, 0: 5 iterations, sum 160. wave 1: 64, 56, ..., 8, 0: 9 iterations, sum 288.
; A wave whose sum is right sets the blue channel of param0 to 0.5 in the vertices it exports, else 0.
; The triangle is ms_tri's, with its vertices from threads 0 and 1 (wave 0) and thread 64 (wave 1), as in
; ms_w64x_wave_votes: the picture is ms_tri's only when both waves ran their own number of iterations with their
; own lanes. Under --wave64-emulate every count is an exchange with a workgroup barrier inside the loop, so the
; waves reach different numbers of barriers; with --mesh-serial-waves the two loops run one after the other.
; Only wave 0 sends the mesh allocation (1 primitive, 65 vertices: indices 0, 1 and 64 are used).
; Needs a DXBC with PSV0 (128 threads, 128/64 outputs, triangles; see scripts/run_gpu_tests.py):
; VKH_MESH=1 vk_harness ms_w64x_wave_loops.spv fs_passthru.spv out.raw
; -> every pixel = ((x+0.5)/64, (y+0.5)/64, 0.5, 1), identical to ms_tri.
; mattr: +wavefrontsize64,-wavefrontsize32
v_mbcnt_lo_u32_b32 v0, -1, 0
v_mbcnt_hi_u32_b32 v0, -1, v0
v_mov_b32_e32 v11, v0
s_bfe_u32 s4, s3, 0x40018
v_lshl_add_u32 v0, s4, 6, v0
s_mov_b32 s14, 288
s_cmp_eq_u32 s4, 0
s_cselect_b32 s5, 3, 7
s_cselect_b32 s14, 160, s14
v_and_b32_e32 v13, s5, v11
v_add_nc_u32_e32 v13, 1, v13
s_mov_b32 s20, 0
s_mov_b32 s22, 0
v_mov_b32_e32 v20, s20
v_cmp_lt_u32_e64 s[6:7], v20, v13
s_bcnt1_i32_b64 s10, s[6:7]
s_add_u32 s22, s22, s10
s_add_u32 s20, s20, 1
s_cmp_lg_u32 s10, 0
s_cbranch_scc1 65528
s_cmp_eq_u32 s22, s14
s_cselect_b32 s13, 1, 0
v_cvt_f32_u32_e32 v15, s13
v_mul_f32_e32 v15, 0.5, v15
v_cmp_eq_u32_e32 vcc, 1, v0
v_cndmask_b32_e64 v1, -1.0, 0x40400000, vcc
v_cndmask_b32_e64 v3, 0, 2.0, vcc
v_cmp_eq_u32_e32 vcc, 64, v0
v_cndmask_b32_e64 v2, -1.0, 0x40400000, vcc
v_cndmask_b32_e64 v4, 0, 2.0, vcc
v_mov_b32_e32 v6, 0
v_mov_b32_e32 v7, 1.0
v_mov_b32_e32 v8, v15
s_mov_b32 m0, 0x1041
s_cmp_lg_u32 s4, 0
s_cbranch_scc1 1
s_sendmsg sendmsg(MSG_GS_ALLOC_REQ)
v_cmp_gt_u32_e64 s[16:17], 2, v0
v_cmp_eq_u32_e64 s[18:19], 64, v0
s_or_b64 exec, s[16:17], s[18:19]
exp pos0 v1, v2, v6, v7 done
exp param0 v3, v4, v8, v7
s_mov_b64 exec, -1
v_cmpx_eq_u32_e32 0, v0
v_mov_b32_e32 v9, 0x4000400
exp prim v9, off, off, off done
s_endpgm
57 changes: 57 additions & 0 deletions runtime/test/shaders/ms_w64x_wave_votes.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
; Mesh shader (NGG, wave64, 128 threads = 2 waves): the two waves take different branches, each with its own
; wave-wide reads, and each wave contributes vertices to the one triangle.
; wave 0: ballot of (lane & 7) == 5, s_bcnt1 must be 8.
; wave 1: ballot of lane < 3, s_bcnt1 must be 3, plus v_readfirstlane of the lane number, which must be 0.
; A wave whose count is right sets the blue channel of param0 to 0.5 in the vertices it exports, else 0.
; The triangle is ms_tri's, but its vertices come from threads 0 and 1 (wave 0) and thread 64 (wave 1), so the
; picture is ms_tri's only when both waves ran their own branch with their own votes: a wave that saw the other
; wave's ballot, or ran the other branch, gets a different count. Only wave 0 sends the mesh allocation
; (1 primitive, 65 vertices: indices 0, 1 and 64 are used).
; Needs a DXBC with PSV0 (128 threads, 128/64 outputs, triangles; see scripts/run_gpu_tests.py):
; VKH_MESH=1 vk_harness ms_w64x_wave_votes.spv fs_passthru.spv out.raw
; -> every pixel = ((x+0.5)/64, (y+0.5)/64, 0.5, 1), identical to ms_tri.
; mattr: +wavefrontsize64,-wavefrontsize32
v_mbcnt_lo_u32_b32 v0, -1, 0
v_mbcnt_hi_u32_b32 v0, -1, v0
v_mov_b32_e32 v11, v0
s_bfe_u32 s4, s3, 0x40018
v_lshl_add_u32 v0, s4, 6, v0
s_cmp_eq_u32 s4, 0
s_cbranch_scc0 6
v_and_b32_e32 v12, 7, v11
v_cmp_eq_u32_e64 s[6:7], 5, v12
s_bcnt1_i32_b64 s10, s[6:7]
s_mov_b32 s14, 8
s_branch 6
v_cmp_gt_u32_e64 s[6:7], 3, v11
s_bcnt1_i32_b64 s10, s[6:7]
v_readfirstlane_b32 s15, v11
s_add_u32 s10, s10, s15
s_mov_b32 s14, 3
s_cmp_eq_u32 s10, s14
s_cselect_b32 s13, 1, 0
v_cvt_f32_u32_e32 v15, s13
v_mul_f32_e32 v15, 0.5, v15
v_cmp_eq_u32_e32 vcc, 1, v0
v_cndmask_b32_e64 v1, -1.0, 0x40400000, vcc
v_cndmask_b32_e64 v3, 0, 2.0, vcc
v_cmp_eq_u32_e32 vcc, 64, v0
v_cndmask_b32_e64 v2, -1.0, 0x40400000, vcc
v_cndmask_b32_e64 v4, 0, 2.0, vcc
v_mov_b32_e32 v6, 0
v_mov_b32_e32 v7, 1.0
v_mov_b32_e32 v8, v15
s_mov_b32 m0, 0x1041
s_cmp_lg_u32 s4, 0
s_cbranch_scc1 1
s_sendmsg sendmsg(MSG_GS_ALLOC_REQ)
v_cmp_gt_u32_e64 s[16:17], 2, v0
v_cmp_eq_u32_e64 s[18:19], 64, v0
s_or_b64 exec, s[16:17], s[18:19]
exp pos0 v1, v2, v6, v7 done
exp param0 v3, v4, v8, v7
s_mov_b64 exec, -1
v_cmpx_eq_u32_e32 0, v0
v_mov_b32_e32 v9, 0x4000400
exp prim v9, off, off, off done
s_endpgm
8 changes: 6 additions & 2 deletions scripts/run_gpu_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,8 @@ def run_suite(a, work: str) -> int:
])
elif name in ("ms_tri", "ms_w64x_ballot", "ms_wave_info_s3", "ms_f16_pack"):
dxbc = make_dxbc([(b"PSV0", make_ms_psv0(128, 64, 64, 2))])
elif name in ("ms_w64x_wave_votes", "ms_w64x_wave_loops"): # vertex 64 comes from the second wave: 128 output vertices
dxbc = make_dxbc([(b"PSV0", make_ms_psv0(128, 128, 64, 2))])
elif name == "ms_v5_workgroup":
dxbc = make_dxbc([(b"PSV0", make_ms_psv0(32, 3, 1, group_shared=128))])
elif name == "ms_clip":
Expand Down Expand Up @@ -945,6 +947,8 @@ def run_suite(a, work: str) -> int:
cmd.append("--texel-offset-fallback")
if MESH_COMPUTE: # mesh shaders as compute writing to a buffer, drawn by tools/mesh_compute_vs.py
cmd.append("--mesh-compute")
if os.environ.get("LEONIDA_MESH_SERIAL_WAVES") == "1": # with --wave64-emulate: one pass per wave
cmd.append("--mesh-serial-waves")
if pc_tail_ubo(): # 128 push-constant bytes; heap base and code base from a uniform block at set 1
cmd.append("--pc-tail-ubo")
if os.environ.get("LEONIDA_FMA") in ("glsl", "khr", "exact"): # GLSL Fma, OpFmaKHR or emulated (docs/design.md)
Expand Down Expand Up @@ -1632,13 +1636,13 @@ def run_suite(a, work: str) -> int:
problem = mesh_v5_test(a.build, spirv_dir, Path(raw_dir) / f"{name}.raw")
results.append((name, None if isinstance(problem, Skip) else not problem,
problem or "24/24 workgroup coordinates exact (2 x 3 x 4)"))
elif name in ("ms_tri", "ms_w64x_ballot", "ms_wave_info_s3"):
elif name in ("ms_tri", "ms_w64x_ballot", "ms_wave_info_s3", "ms_w64x_wave_votes", "ms_w64x_wave_loops"):
raw = os.path.join(raw_dir, f"{name}.raw")
env = mesh_env(spirv_dir, name, gfx_env)
rc, msg = run_readback(raw, run_cmd, [vk_harness, spv, fs_passthru, raw], env=env)
# ms_w64x_ballot needs exact wave64 (a 64-wide subgroup, or --wave64-emulate): skip it elsewhere, as
# the wave64 compute dumps are.
no64 = (name == "ms_w64x_ballot" and not w64_emulated() and
no64 = (name in ("ms_w64x_ballot", "ms_w64x_wave_votes", "ms_w64x_wave_loops") and not w64_emulated() and
not any(int(x) >= 64 for x in re.findall(r"subgroup \d+\.\.(\d+)", msg)))
if rc == UNSUPPORTED:
results.append((name, None, unsupported_skip(msg)))
Expand Down
3 changes: 3 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ def mesh_psv0_chunk(threads=(128, 1, 1), max_vertices=64, max_primitives=64, top
SAMPLE_DXBC = {"gs_tri": GS_TRI_DXBC, "ms_tri": MS_TRI_DXBC, "ms_clip": MS_CLIP_DXBC, "ms_wave_info_s3": MS_TRI_DXBC,
"ms_w64x_ballot": MS_TRI_DXBC, "ms_f16_pack": MS_TRI_DXBC, # scripts/run_gpu_tests.py, ms_tri's PSV0
"gs_w64_a_ring": GS_TRI_DXBC, "gs_w64_c_lane_id": GS_TRI_DXBC, # build.py gives every gs_* gs_tri's
# vertex 64 comes from the second wave: 128 output vertices (scripts/run_gpu_tests.py)
"ms_w64x_wave_votes": make_dxbc([mesh_psv0_chunk(max_vertices=128)]),
"ms_w64x_wave_loops": make_dxbc([mesh_psv0_chunk(max_vertices=128)]),
"ms_v5_workgroup": make_dxbc([mesh_psv0_chunk(threads=(32, 1, 1), max_vertices=3,
max_primitives=1, group_shared=128)])}

Expand Down
Loading
Loading