mirror of
https://github.com/ProjectLeonida/mandy.git
synced 2026-12-06 12:48:35 +00:00
- Exclude v_readfirstlane from --mesh-native-wave32 until per-use uniformity analysis proves the source wave-uniform (with ms_native_readfirstlane.asm and test_mesh_native_wave32.py regression test + docs/design.md update). - Lower SPIRV_OPT_LARGE_BYTES from 750 KiB to 512 KiB so library/lib_cs_03245 and siblings use the safe SSA pass set instead of --scalar-replacement=0 (avoiding NVIDIA 590.48.01 compiler SIGSEGV during warmup). AI-assisted.
95 lines
3.8 KiB
Python
95 lines
3.8 KiB
Python
"""Unit tests for --mesh-native-wave32 and --compute-serial-waves.
|
|
|
|
Verifies:
|
|
1. A mesh shader that reads the first active lane retains workgroup wave64 emulation.
|
|
2. A 128-thread barrier-free compute shader with no LDS or atomics uses --compute-serial-waves
|
|
(LocalSize 64 1 1, compute_serial_waves == 2) when --wave64-emulate --compute-serial-waves are set.
|
|
3. A 128-thread compute shader with s_barrier stays on the side-by-side form (compute_serial_waves not set).
|
|
4. --spirv-opt threshold constants select the SSA pass set for large shaders.
|
|
"""
|
|
import os
|
|
import struct
|
|
import sys
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
from unittest.mock import patch
|
|
|
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
import support # noqa: F401
|
|
import rdna2spirv
|
|
from test_mesh_cull_store import _dxbc, _mesh_psv0
|
|
|
|
|
|
def _cs_fssm(sx=128, sy=1, sz=1):
|
|
fssm = bytearray(0x148)
|
|
struct.pack_into("<4I", fssm, 0x138, 0x8088, sx, sy, sz)
|
|
return bytes(fssm)
|
|
|
|
|
|
def _translate_cs(asm_lines, sx=128, sy=1, sz=1, csw=True):
|
|
with tempfile.TemporaryDirectory() as td:
|
|
os.makedirs(os.path.join(td, "disasm"))
|
|
os.makedirs(os.path.join(td, "fssm"))
|
|
sp = os.path.join(td, "disasm", "CS_test.s")
|
|
fp = os.path.join(td, "fssm", "CS_test.fssm")
|
|
with open(sp, "w", encoding="utf-8", newline="\n") as f:
|
|
f.write("; CS_test code 0x0..0x100 (header), gfx1013, 0 invalid words\n")
|
|
for line in asm_lines:
|
|
f.write("\t" + line + "\n")
|
|
with open(fp, "wb") as f:
|
|
f.write(_cs_fssm(sx, sy, sz))
|
|
old_w64 = rdna2spirv.WAVE64_EMULATE
|
|
old_csw = rdna2spirv.COMPUTE_SERIAL_WAVES
|
|
try:
|
|
rdna2spirv.WAVE64_EMULATE = True
|
|
rdna2spirv.COMPUTE_SERIAL_WAVES = csw
|
|
asm = rdna2spirv.translate(sp)
|
|
gen = rdna2spirv.translate.last_gen
|
|
meta = rdna2spirv.shader_meta(gen, asm, src_path=sp, fssm_path=fp)
|
|
return asm, gen, meta
|
|
finally:
|
|
rdna2spirv.WAVE64_EMULATE = old_w64
|
|
rdna2spirv.COMPUTE_SERIAL_WAVES = old_csw
|
|
|
|
|
|
class ComputeSerialWavesAndOptTest(unittest.TestCase):
|
|
def test_mesh_first_active_lane_uses_the_whole_wave(self):
|
|
source = Path(__file__).with_name("ms_native_readfirstlane.asm")
|
|
lines = [line for line in source.read_text(encoding="utf-8").splitlines() if not line.startswith(";")]
|
|
dxbc = _dxbc([(b"PSV0", _mesh_psv0(128, 64, 64))])
|
|
with patch.object(rdna2spirv, "WAVE64_EMULATE", True), patch.object(rdna2spirv, "MESH_NATIVE_WAVE32", True):
|
|
support.translate_lines("ms_first_active", lines, dxbc=dxbc)
|
|
self.assertTrue(rdna2spirv.translate.last_gen.emulate)
|
|
self.assertFalse(rdna2spirv.translate.last_gen.ms_native_wave32)
|
|
|
|
def test_csw_activates_on_barrier_free_128_thread_cs(self):
|
|
asm, gen, meta = _translate_cs([
|
|
"s_mov_b64 exec, -1",
|
|
"v_add_nc_u32_e32 v0, 1, v0",
|
|
"s_endpgm",
|
|
], sx=128, csw=True)
|
|
self.assertEqual(gen.cs_serial, 2)
|
|
self.assertEqual(meta.get("compute_serial_waves"), 2)
|
|
self.assertIn("OpExecutionMode %main LocalSize 64 1 1", asm)
|
|
|
|
def test_csw_skips_when_barrier_present(self):
|
|
asm, gen, meta = _translate_cs([
|
|
"s_mov_b64 exec, -1",
|
|
"s_barrier",
|
|
"v_add_nc_u32_e32 v0, 1, v0",
|
|
"s_endpgm",
|
|
], sx=128, csw=True)
|
|
self.assertFalse(gen.cs_serial)
|
|
self.assertNotIn("compute_serial_waves", meta)
|
|
|
|
def test_spirv_opt_constants(self):
|
|
self.assertGreater(rdna2spirv.SPIRV_OPT_LARGE_BYTES, 0)
|
|
self.assertIn("--ssa-rewrite", rdna2spirv.SPIRV_OPT_SSA_PASSES)
|
|
self.assertNotIn("--scalar-replacement=0", rdna2spirv.SPIRV_OPT_SSA_PASSES)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|