fix(tests): cover the implicit MTBUF format in memory comparisons

LLVM omits the format modifier for 8_UNORM. Decode that spelling in the reference model and generate it so typed-buffer fuzz runs cover the same input.
This commit is contained in:
Vonsek
2026-11-22 18:55:58 +01:00
parent 49475796c2
commit 376417b1ac
2 changed files with 23 additions and 4 deletions

View File

@ -123,6 +123,20 @@ class FormatDecode(unittest.TestCase):
"tbuffer_load_format_xyzw v[8:11], off, s[0:3], 0 format:[BUF_FMT_32_UINT]"])
self.assertEqual([ref.v[i] for i in range(8, 12)], [42, 0, 0, 0])
def test_mtbuf_default_format_matches_explicit_8_unorm(self) -> None:
descriptor = md.OOB_RAW | md.XYZW | (20 << 12)
setup = ["s_mov_b32 s0, 0x7000", "s_mov_b32 s1, 0", "s_mov_b32 s2, 0x1000",
f"s_mov_b32 s3, {descriptor:#x}"]
for modifier in (" format:[BUF_FMT_8_UNORM]", ""):
with self.subTest(modifier=modifier):
load = "tbuffer_load_format_xyzw v[8:11], off, s[0:3], 0" + modifier
probe = program(setup + [load, "s_waitcnt vmcnt(0)"], {0x7000: 0xFF})
ref = md.RefMachine(dict(probe.memory))
ref.run(probe.lines)
self.assertEqual([ref.v[reg] for reg in md.EXPORT], [0x3F800000, 0, 0, 0])
status, detail = md.run_one("ps_mem_default_mtbuf", probe)
self.assertEqual(status, "match", detail)
def test_shader86_closed_open_questions(self):
"""Missing W repeats X; UNORM raw 3 matches correctly rounded 0x3c40c0c1 (no 1-ULP split)."""
base = ["s_mov_b32 s0, 0x7000", "s_mov_b32 s1, 0", "s_mov_b32 s2, 0x100"]

View File

@ -254,7 +254,9 @@ class RefMachine:
for c in range(ncomp):
self.v[vdata + c] = 0
return
name = "GFX10_FORMAT_" + fm.split("BUF_FMT_")[-1].rstrip("]")
# LLVM omits the default MTBUF instruction format from its listing.
fmt = DEFAULT_TBUFFER_FORMAT if fm is None else fm.split("BUF_FMT_")[-1].rstrip("]")
name = "GFX10_FORMAT_" + fmt
else:
name = FORMAT_NAMES[descriptor_format]
widths, kind = parse_format(name)
@ -541,8 +543,10 @@ def gen_global(rng, prog):
return [("v", VDATA + i) for i in range(n)]
# The five formats tbuffer loads use in the 1.0.2.1 corpus (counted over all 26,503 shaders).
TBUFFER_FORMATS = ("16_16_SNORM", "8_8_8_8_UNORM", "8_8_8_8_UINT", "2_10_10_10_UNORM", "16_16_16_16_UINT")
DEFAULT_TBUFFER_FORMAT = "8_UNORM"
# Exercise the implicit LLVM spelling alongside the five MTBUF formats found in the 1.0.2.1 corpus.
TBUFFER_FORMATS = ("16_16_SNORM", "8_8_8_8_UNORM", "8_8_8_8_UINT", "2_10_10_10_UNORM", "16_16_16_16_UINT",
DEFAULT_TBUFFER_FORMAT)
XYZW = 4 | 5 << 3 | 6 << 6 | 7 << 9
OOB_STRUCTURED, OOB_RAW = 1 << 28, 3 << 28 # V# word3 OOB_SELECT
@ -589,7 +593,8 @@ def gen_buffer_format(rng, prog):
addr_mods = "offen"
vdata = reg_range("v", VDATA, ncomp)
if tbuffer:
prog.lines.append(f"tbuffer_load_format_{suffix} {vdata}, {operands} format:[BUF_FMT_{fname}] {addr_mods}")
format_mod = "" if fname == DEFAULT_TBUFFER_FORMAT else f" format:[BUF_FMT_{fname}]"
prog.lines.append(f"tbuffer_load_format_{suffix} {vdata}, {operands}{format_mod} {addr_mods}")
else:
prog.lines.append(f"buffer_load_format_{suffix} {vdata}, {operands} {addr_mods}")
prog.lines.append("s_waitcnt vmcnt(0)")