"""The wave size of an FSPX program (the FidelityFX DLL's, docs/fspx.md) comes from its dispatch state: kind 0 word 4 bit 20 set = wave32, which tools/fspx_unpack.py writes to fspx/.json as `wave32`. Before, a program without an FSSM sidecar got the code heuristic, which also counts any _b64 op on vcc or exec as wave64; the DLL's wave32 programs move vcc as an ordinary SGPR pair, so they were translated as wave64, and a wave64 program without any marker as wave32. Every case is a hand-written listing in the FSPX layout (disasm/, fspx/.json and .code, no fssm/), translated by tools/rdna2spirv.py. The last class runs the result, where the two wave sizes give different answers. Standard library only; no GPU, no LLVM, no game files. """ import json import os import struct import sys import tempfile import unittest import warnings HERE = os.path.dirname(os.path.abspath(__file__)) ROOT = os.path.dirname(os.path.dirname(HERE)) sys.dont_write_bytecode = True sys.path.insert(0, os.environ.get("LEONIDA_TOOLS_DIR") or os.path.join(ROOT, "tools")) sys.path.insert(0, HERE) sys.path.insert(0, os.path.join(ROOT, "tests")) import rdna2spirv # noqa: E402 import spirv_mini_interp as si # noqa: E402 from test_fssm_unpack import make_dxbc, make_xbch, make_xdat_list # noqa: E402 STUB_DXBC = b"DXBC" + bytes(24) + struct.pack(".json beside it says.""" with self.assertRaises(rdna2spirv.Unsupported) as cm: translate(VCC_AS_DATA, wave32=True, fssm=fssm_header(wave32=True)) self.assertIn("FSSM wave32 header contradicts wave64 code", str(cm.exception)) self.assertTrue(translate(["v_mov_b32_e32 v1, v0"], wave32=True, fssm=fssm_header(wave32=False))[1]) # v0 = local id x. Lane 0 stores readlane(3 * lane + 1, 40): the lane select is S1[4:0] in wave32 (lane 8, 25) and # S1[5:0] in wave64 (lane 40, 121). No instruction here is a wave marker, so only the dispatch state decides. READLANE_40 = [ "v_mad_u32_u24 v2, v0, 3, 1", "v_readlane_b32 s6, v2, 40", "v_cmpx_eq_u32_e32 0, v0", "v_mov_b32_e32 v20, s6", "v_mov_b32_e32 v21, 0", "buffer_store_dword v20, v21, s[0:3], 0 offen", ] def run(asm, subgroup_size): memory = si.run_workgroup( asm, 64, subgroup_size, inputs_for=lambda i: {"%wg_id": (0, 0, 0), "%local_id": (i, 0, 0), "%sg_lane": i % subgroup_size}, push_constants=VSHARP + [0] * 32, memory={}) return memory.get(0) class TheChoiceMatters(unittest.TestCase): def test_readlane_40_reads_lane_8_in_wave32_and_lane_40_in_wave64(self): asm32, wave64 = translate(READLANE_40, wave32=True) self.assertFalse(wave64) self.assertEqual(run(asm32, 32), 3 * 8 + 1) asm64, wave64 = translate(READLANE_40, wave32=False) self.assertTrue(wave64) self.assertEqual(run(asm64, 64), 3 * 40 + 1) class LibraryGraphicsWaveSize(unittest.TestCase): def test_source_wave32_corroborates_a_32_bit_exec_instruction(self): body = [ "s_bfm_b64 s[8:9], 3, 1", "s_and_saveexec_b32 s10, -1", "v_mov_b32_e32 v20, 0", "exp pos0 v20, v20, v20, v20 done", ] for flags, expected_wave64 in (([True], False), ([False], True), ([True, False], True), ([], True)): with self.subTest(flags=flags): payloads = [(0x0D, make_xbch(fssm_header(flag))) for flag in flags] source = make_dxbc([(b"DXIL", make_xdat_list(payloads))]) _, wave64 = translate(body, name="vs_wave", container=source) self.assertEqual(wave64, expected_wave64) if __name__ == "__main__": unittest.main()