mirror of
https://github.com/ProjectLeonida/mandy.git
synced 2026-12-06 23:38:37 +00:00
tbuffer_store_format_* and its d16 forms were Unsupported, though every tbuffer_load_format_* form translates. They now go through buffer_store with the instruction's format, as the loads go through buffer_load_format: - only that format is encoded, with no branch on the V#'s FORMAT; - the bounds check uses its element size; - a V# whose FORMAT is 0 (INVALID) still disables the store, as measured. (@Vonsek covers the MTBUF loads and @opit80 the raw MUBUF accesses through such a V#.) The format parsing the loads did inline becomes mtbuf_format(), shared by both: no modifier is GFX10's default BUF_FMT_8_UNORM, and a format FORMATS has no encoder for stays Unsupported. read_before_write_vgprs now counts a tbuffer store's data VGPRs as reads, as for buffer_store. cs_tbuffer_store.asm stores into 13 sentinel-filled regions through V#s whose format differs from the instruction's or is 0, and reads them back. Every expected word was measured by running the same body natively on a Radeon 680M (gfx1035, RDNA2); wave32 and wave64 gave the same 52 words: - the instruction's format decides the encoding, the element and the bounds; - components the format has but the store doesn't give are 0, and extra ones are dropped; - the default format is one byte, and its neighbours are kept; - a FORMAT-0 V# leaves the region untouched. check.py and run_gpu_tests.py compare the dump. The semantic fixture runs through the interpreter in tests/semantic/test_tbuffer_store.py, which fails on the old translator (Unsupported). It also fails on versions that take the bounds from the V#'s element (5 words differ), take the format from the V#, fill missing components with anything but 0 (1 word), or drop the FORMAT-0 guard (2 words). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
86 lines
4.0 KiB
Python
86 lines
4.0 KiB
Python
"""tbuffer_store_format_* (MTBUF stores with the instruction's own format) through the translator and the interpreter.
|
|
|
|
cs_tbuffer_store.asm stores into 13 sentinel-filled regions through V#s whose FORMAT differs from the instruction's,
|
|
then reads every region back into out[0..51]. check.py's TBUFFER_STORE_WORDS holds the words a Radeon 680M (gfx1035)
|
|
gives natively; the rules are in the .asm header. Here the translated fixture runs on the CPU and must give the same
|
|
words, so the GPU test, the hardware and the translation are kept in step.
|
|
"""
|
|
import os
|
|
import struct
|
|
import sys
|
|
import unittest
|
|
|
|
HERE = os.path.dirname(os.path.abspath(__file__))
|
|
ROOT = os.path.dirname(os.path.dirname(HERE))
|
|
sys.path.insert(0, HERE)
|
|
sys.path.insert(0, os.path.join(ROOT, "runtime", "test", "shaders"))
|
|
sys.path.insert(0, os.environ.get("LEONIDA_TOOLS_DIR") or os.path.join(ROOT, "tools"))
|
|
|
|
import check # noqa: E402 (runtime/test/shaders/check.py; importing it runs nothing)
|
|
import rdna2spirv # noqa: E402
|
|
import support # noqa: E402
|
|
|
|
|
|
def fssm(rsrc2, group):
|
|
"""The compute-shader header words the translator reads: COMPUTE_PGM_RSRC2 and the thread-group size."""
|
|
header = bytearray(0x148)
|
|
struct.pack_into("<4I", header, 0x138, rsrc2, *group)
|
|
return bytes(header)
|
|
|
|
|
|
# 4 user SGPRs (the output V#), workgroup id in s4, 64x1x1 threads: the header build.py gives the GPU tests.
|
|
CS_FSSM = fssm(0x8088, (64, 1, 1))
|
|
# The output V# vk_compute_test passes in s[0:3]: base 0, num_records 0xffffffff, 32_FLOAT, OOB_SELECT 3.
|
|
OUT_VSHARP = [0, 0, 0xFFFFFFFF, 0x31016FAC]
|
|
|
|
|
|
def run(spv):
|
|
memory = {}
|
|
outputs = support.run_fragment(spv, inputs={"%wg_id": (0, 0, 0), "%local_id": (0, 0, 0)},
|
|
push_constants=OUT_VSHARP + [0] * 28, memory=memory)
|
|
return outputs, memory
|
|
|
|
|
|
class TbufferStoreFixture(unittest.TestCase):
|
|
def test_words_match_the_native_measurement(self):
|
|
outputs, memory = run(support.translate_fixture("cs_tbuffer_store", fssm=CS_FSSM))
|
|
self.assertEqual(outputs, {})
|
|
want = check.TBUFFER_STORE_WORDS
|
|
got = [memory.get(4 * i, 0) for i in range(len(want))]
|
|
for i, (g, w) in enumerate(zip(got, want)):
|
|
with self.subTest(out=i, region=hex(0x200 + 16 * (i // 4))):
|
|
self.assertEqual(f"{g:#010x}", f"{w:#010x}")
|
|
# The regions themselves hold the same words, and nothing lands between out[] and the regions.
|
|
self.assertEqual([memory.get(0x200 + 4 * i, 0) for i in range(len(want))], want)
|
|
self.assertEqual(sorted(a for a in memory if len(want) * 4 <= a < 0x200), [])
|
|
|
|
|
|
class TbufferStoreTranslation(unittest.TestCase):
|
|
def store(self, fmt_mod):
|
|
return support.translate_lines("cs_tbuf_one", [
|
|
"v_mov_b32_e32 v20, 1.0", "v_mov_b32_e32 v5, 0x200",
|
|
f"tbuffer_store_format_x v20, v5, s[0:3], 0{fmt_mod} offen", "s_endpgm"], fssm=CS_FSSM)
|
|
|
|
def test_format_outside_formats_is_unsupported(self):
|
|
# BUF_FMT_8_UINT is a GFX10 format the FORMATS table has no encoder for: reported, never guessed.
|
|
with self.assertRaises(rdna2spirv.Unsupported):
|
|
self.store(" format:[BUF_FMT_8_UINT]")
|
|
|
|
def test_default_format_is_one_unorm_byte(self):
|
|
# No modifier is GFX10's default, BUF_FMT_8_UNORM: 1.0 is 0xff in the low byte, the other three kept.
|
|
spv = self.store("")
|
|
memory = {0x200: 0x11223344}
|
|
support.run_fragment(spv, inputs={"%wg_id": (0, 0, 0), "%local_id": (0, 0, 0)},
|
|
push_constants=OUT_VSHARP + [0] * 28, memory=memory)
|
|
self.assertEqual(f"{memory[0x200]:#010x}", "0x112233ff")
|
|
|
|
def test_data_vgprs_are_read(self):
|
|
# read_before_write_vgprs: a store's vdata is a source, as for buffer_store.
|
|
import shader_ir
|
|
ins = shader_ir.parse_line("\ttbuffer_store_format_xy v[7:8], v5, s[4:7], 0 format:[BUF_FMT_32_32_FLOAT] offen")
|
|
self.assertEqual(sorted(rdna2spirv.read_before_write_vgprs([ins])), [5, 7, 8])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|