"""Semantic tests for FSPX / FidelityFX translator rules (#1754 follow-ups, docs/fspx.md): 1. LLVM VCCTuple scalar register lists ending in vcc_lo,vcc_hi (`[s100,...,s105,vcc_lo,vcc_hi]` and `[s92,...,s105,vcc_lo,vcc_hi]`) parsed in tools/shader_ir.py, clearing `vcc` in tools/lane_masks.py, and handled in s_buffer_load_dwordx*/s_load_dword*, buffer/global addressing, and T#/S# lookups. 2. `src_scc` special source operand (RDNA2 encoding 253 = SCC, 0 or 1) in scalar and vector ALU ops. 3. `image_atomic_*` / `image_atomic_cmpswap` with `a16` packed 16-bit unsigned coordinates (2D and 3D). Standard library only; no GPU, no LLVM, no game files. """ from __future__ import annotations 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) import lane_masks # noqa: E402 import rdna2spirv # noqa: E402 import shader_ir # noqa: E402 import shader_meta # noqa: E402 import spirv_mini_interp as si # noqa: E402 STUB_DXBC = b"DXBC" + bytes(24) + struct.pack(" SCC = 0 "v_add_nc_u32_e32 v3, src_scc, v1", # 20 "v_mov_b32_e32 v4, s6", "v_mov_b32_e32 v5, s7", f"v_mov_b32_e32 v8, {OUT:#x}", "global_store_dwordx4 v8, v[2:5], s[0:1]", ] res = run_cs(body, {}) self.assertEqual([res.get(OUT + 4 * i) for i in range(4)], [21, 20, 1, 11]) class ImageAtomicA16Tests(unittest.TestCase): def test_image_atomic_add_2d_and_3d_a16_translate(self): # 2D a16: one VGPR packs (x: u16 low, y: u16 high); 3D a16: two VGPRs pack (x, y) and (z, _). spv_2d = translate([ "v_mov_b32_e32 v1, 0x00050003", # x=3, y=5 "v_mov_b32_e32 v2, 1", "image_atomic_add v2, v1, s[4:11] dmask:0x1 dim:SQ_RSRC_IMG_2D unorm a16 glc", "s_waitcnt vmcnt(0)", f"v_mov_b32_e32 v6, {OUT:#x}", "global_store_dword v6, v2, s[0:1]", ]) self.assertIn("OpImageTexelPointer", spv_2d) self.assertIn("OpAtomicIAdd", spv_2d) self.assertIn("OpShiftRightLogical %uint", spv_2d) spv_3d = translate([ "v_mov_b32_e32 v1, 0x00050003", # x=3, y=5 "v_mov_b32_e32 v2, 0x00000007", # z=7 "v_mov_b32_e32 v3, 1", "image_atomic_add v3, v[1:2], s[4:11] dmask:0x1 dim:SQ_RSRC_IMG_3D unorm a16", "s_waitcnt vmcnt(0)", ]) self.assertIn("OpCompositeConstruct %v3int", spv_3d) self.assertIn("OpAtomicIAdd", spv_3d) def test_image_atomic_2d_too_few_coords_rejected(self): with self.assertRaises(rdna2spirv.Unsupported): translate([ "v_mov_b32_e32 v1, 0", "v_mov_b32_e32 v2, 1", "image_atomic_add v2, v1, s[4:11] dmask:0x1 dim:SQ_RSRC_IMG_2D unorm", ]) if __name__ == "__main__": unittest.main()