mirror of
https://github.com/ProjectLeonida/mandy.git
synced 2026-12-06 21:48:37 +00:00
Add --wave64-emulate to tools/rdna2spirv.py. A wave64 compute or mesh shader then uses no subgroup operation: everything a lane needs from the rest of its wave (votes for s_cbranch_*/SCC, whole-mask words for s_bcnt1/s_ff1/v_mbcnt, v_readlane, v_readfirstlane, ds_bpermute, ds_swizzle, v_permlane16/x16) goes through a Workgroup buffer. The program runs in rounds that end at one OpControlBarrier in uniform control flow; a cross-lane op cuts its basic block, and the rest runs one round later, when all 64 lanes have written. s_barrier becomes a scheduler state, and conflicting memory accesses in one segment are ordered by a round. This answers #94 and #101 for compute and mesh shaders: on 32-wide subgroups (NVIDIA) they are now exact, not approximate. Two fixes that apply without the flag: - v_writelane_b32 in cs/ms selects the lane by the wave lane. On a 32-wide subgroup writes to lanes 32-63 were lost. - ds_bpermute_b32 in wave64 runs as two wave32s (RDNA ISA 10.4.4): on a 64-wide subgroup lanes 32-63 read the low half, and an inactive source lane now reads 0. New hand-written GPU tests cs_w64x_* and ms_w64x_ballot pin down the cross-half semantics. LEONIDA_W64_EMULATE=1 makes build.py, run_gpu_tests.py and check.py use the flag. Other translator output is byte-identical. Tested on NVIDIA GeForce RTX 5070 Laptop (driver 617.42, subgroup 32) and AMD Radeon 880M (driver 26.11.2 LLPC, subgroup 64): run_gpu_tests.py 37/37 on both with the flag (RTX 5070 without it: 21/37; 880M without it: 37/37, was 36/37 before the bpermute fix). AI-assisted (Claude Code). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
75 lines
2.6 KiB
NASM
75 lines
2.6 KiB
NASM
; Wave64 wave-wide branches decided by one half only. VCC / EXEC are wave registers, so s_cbranch_* is taken by the
|
|
; whole wave: both halves must run (or skip) the same scalar instructions. A 32-wide subgroup decides per half.
|
|
; (A) VCC = lane 40 only (upper half), s_cbranch_vccnz taken -> `s_mov_b32 s6, 1` is skipped in ALL lanes: s6 = 0.
|
|
; (per-half: the low half sees VCC = 0, falls through, s6 = 1 there)
|
|
; (B) VCC = lane 3 only (low half), s_cbranch_vccnz taken -> s7 = 0 everywhere (upper half would fall through).
|
|
; (C) EXEC = lanes 32-39 (exec_lo = 0, exec_hi = 0xff), s_cbranch_execz NOT taken (EXEC != 0) -> `s_mov_b32 s9, 5` runs
|
|
; in all lanes: s9 = 5 (per-half: the low half has EXEC = 0, takes the branch, s9 = 0 there)
|
|
; (D) VCC = lane 40 only, s_cbranch_vccz NOT taken -> s10 = 9 everywhere (low half would take it, s10 = 0)
|
|
; Stores: out[0] lane 0 s6, out[1] lane 40 s6, out[2] lane 40 s7, out[3] lane 63 s7, out[4] lane 0 s9, out[5] lane 40 s9,
|
|
; out[6] lane 0 s10, out[7] lane 63 s10.
|
|
; Run: vk_compute_test cs_w64x_branch.spv 1 dump --require-wave64
|
|
; -> out[0..7] = 0 0 0 0 5 5 9 9
|
|
; mattr: +wavefrontsize64,-wavefrontsize32
|
|
v_mbcnt_lo_u32_b32 v1, -1, 0
|
|
v_mbcnt_hi_u32_b32 v1, -1, v1
|
|
s_mov_b32 s6, 0
|
|
v_cmp_eq_u32_e32 vcc, 40, v1
|
|
s_cbranch_vccnz 1
|
|
s_mov_b32 s6, 1
|
|
s_mov_b32 s7, 0
|
|
v_cmp_eq_u32_e32 vcc, 3, v1
|
|
s_cbranch_vccnz 1
|
|
s_mov_b32 s7, 1
|
|
s_mov_b32 s9, 0
|
|
s_mov_b32 exec_lo, 0
|
|
s_mov_b32 exec_hi, 0xff
|
|
s_cbranch_execz 1
|
|
s_mov_b32 s9, 5
|
|
s_mov_b64 exec, -1
|
|
s_mov_b32 s10, 0
|
|
v_cmp_eq_u32_e32 vcc, 40, v1
|
|
s_cbranch_vccz 1
|
|
s_mov_b32 s10, 9
|
|
s_mov_b64 exec, -1
|
|
v_cmpx_eq_u32_e32 0, v1
|
|
v_mov_b32_e32 v20, s6
|
|
v_mov_b32_e32 v21, 0
|
|
buffer_store_dword v20, v21, s[0:3], 0 offen
|
|
s_mov_b64 exec, -1
|
|
v_cmpx_eq_u32_e32 40, v1
|
|
v_mov_b32_e32 v20, s6
|
|
v_mov_b32_e32 v21, 4
|
|
buffer_store_dword v20, v21, s[0:3], 0 offen
|
|
s_mov_b64 exec, -1
|
|
v_cmpx_eq_u32_e32 40, v1
|
|
v_mov_b32_e32 v20, s7
|
|
v_mov_b32_e32 v21, 8
|
|
buffer_store_dword v20, v21, s[0:3], 0 offen
|
|
s_mov_b64 exec, -1
|
|
v_cmpx_eq_u32_e32 63, v1
|
|
v_mov_b32_e32 v20, s7
|
|
v_mov_b32_e32 v21, 12
|
|
buffer_store_dword v20, v21, s[0:3], 0 offen
|
|
s_mov_b64 exec, -1
|
|
v_cmpx_eq_u32_e32 0, v1
|
|
v_mov_b32_e32 v20, s9
|
|
v_mov_b32_e32 v21, 16
|
|
buffer_store_dword v20, v21, s[0:3], 0 offen
|
|
s_mov_b64 exec, -1
|
|
v_cmpx_eq_u32_e32 40, v1
|
|
v_mov_b32_e32 v20, s9
|
|
v_mov_b32_e32 v21, 20
|
|
buffer_store_dword v20, v21, s[0:3], 0 offen
|
|
s_mov_b64 exec, -1
|
|
v_cmpx_eq_u32_e32 0, v1
|
|
v_mov_b32_e32 v20, s10
|
|
v_mov_b32_e32 v21, 24
|
|
buffer_store_dword v20, v21, s[0:3], 0 offen
|
|
s_mov_b64 exec, -1
|
|
v_cmpx_eq_u32_e32 63, v1
|
|
v_mov_b32_e32 v20, s10
|
|
v_mov_b32_e32 v21, 28
|
|
buffer_store_dword v20, v21, s[0:3], 0 offen
|
|
s_endpgm
|