"""buffer_load_format_d16_hi_x and buffer_store_format_d16_hi_x against their d16_x forms, on the CPU. RDNA2 ISA (MUBUF): buffer_load_format_d16_hi_x decodes one component as buffer_load_format_d16_x does (to f16 for a float format, to a saturated 16-bit integer for an integer one) but writes it to the high half of vdata, keeping the low half; buffer_store_format_d16_hi_x stores the component from the high half of vdata where d16_x stores the low half. For every format the translator decodes (Gen.FORMATS) each _hi form must give exactly what the d16_x form gives, moved to / taken from the other half. Run through spirv_mini_interp; standard library only; no game files. """ 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 rdna2spirv # noqa: E402 import spirv_mini_interp as si # noqa: E402 STUB_DXBC = b"DXBC" + bytes(24) + struct.pack("> 16, KEEP >> 16) # d16_x keeps the high half self.assertEqual(hi, (lo & 0xFFFF) << 16 | (KEEP & 0xFFFF)) def test_store_takes_the_high_half(self): for code in sorted(rdna2spirv.Gen.FORMATS): for v in (0x3C00, 0xB800, 0x7BFF, 0x0001, 0x8000): with self.subTest(fmt=code, v=hex(v)): want = store("buffer_store_format_d16_x", code, 0xABCD0000 | v) self.assertEqual(store("buffer_store_format_d16_hi_x", code, v << 16 | 0xABCD), want) def test_first_read_analysis_counts_the_kept_half(self): from shader_ir import parse_line self.assertEqual(rdna2spirv.read_before_write_vgprs( [parse_line("\tbuffer_load_format_d16_hi_x v5, v1, s[8:11], 0 offen")]), {1, 5}) if __name__ == "__main__": unittest.main()