mirror of
https://github.com/ProjectLeonida/mandy.git
synced 2026-12-06 23:38: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>
61 lines
2.1 KiB
NASM
61 lines
2.1 KiB
NASM
; Wave64 LDS read-after-write across the halves of ONE wave, no s_barrier: LDS operations of a wave execute in
|
|
; order, so a ds_read issued after a ds_write sees every lane's write, including the other half's. A wave64 run as
|
|
; two 32-wide subgroups needs the halves ordered (or a barrier) for this to hold.
|
|
; v2 = 100 + lane, ds_write_b32 LDS[lane * 4] = v2, then ds_read_b32 v5 = LDS[(lane ^ 32) * 4] = 100 + (lane ^ 32).
|
|
; out[0] lane 0 -> 132 out[1] lane 5 -> 137 out[2] lane 32 -> 100 out[3] lane 40 -> 108
|
|
; out[4] lane 63 -> 131 out[5] lane 33 -> 101 out[6] lane 17 -> 149 out[7] lane 50 -> 118
|
|
; (A buffer_store/buffer_load variant is not included: the 64-word output buffer holds only the observed words.)
|
|
; Run: vk_compute_test cs_w64x_lds_raw.spv 1 dump --require-wave64
|
|
; -> out[0..7] = 132 137 100 108 131 101 149 118
|
|
; mattr: +wavefrontsize64,-wavefrontsize32
|
|
v_mbcnt_lo_u32_b32 v1, -1, 0
|
|
v_mbcnt_hi_u32_b32 v1, -1, v1
|
|
v_add_nc_u32_e32 v2, 100, v1
|
|
v_lshlrev_b32_e32 v3, 2, v1
|
|
ds_write_b32 v3, v2
|
|
v_xor_b32_e32 v4, 32, v1
|
|
v_lshlrev_b32_e32 v4, 2, v4
|
|
ds_read_b32 v5, v4
|
|
s_waitcnt lgkmcnt(0)
|
|
s_mov_b64 exec, -1
|
|
v_cmpx_eq_u32_e32 0, v1
|
|
v_mov_b32_e32 v20, v5
|
|
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 5, v1
|
|
v_mov_b32_e32 v20, v5
|
|
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 32, v1
|
|
v_mov_b32_e32 v20, v5
|
|
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 40, v1
|
|
v_mov_b32_e32 v20, v5
|
|
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 63, v1
|
|
v_mov_b32_e32 v20, v5
|
|
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 33, v1
|
|
v_mov_b32_e32 v20, v5
|
|
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 17, v1
|
|
v_mov_b32_e32 v20, v5
|
|
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 50, v1
|
|
v_mov_b32_e32 v20, v5
|
|
v_mov_b32_e32 v21, 28
|
|
buffer_store_dword v20, v21, s[0:3], 0 offen
|
|
s_endpgm
|