Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions runtime/test/shaders/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,16 @@ def fmt_d16_xyz_test(tools, spirv, env=None):
return dump_test(tools, spirv, "cs_fmt_d16_xyz", FMT_D16_XYZ_WORDS, len(FMT_D16_XYZ_WORDS), env)


def pk_mul_lo_const_test(tools, spirv, env=None):
"""The fixture writes four words per lane for 32 lanes, beyond the harness's default 64-word heap.
Allocate all 128 words and check every lane, not just the first two printed by the harness."""
env = dict(os.environ if env is None else env)
if sg := subgroup_size(spirv, "cs_pk_mul_lo_const"):
env.setdefault("VKC_SUBGROUP_SIZE", str(sg))
want = PK_MUL_LO_WORDS[:4] * 32
return dump_test(tools, spirv, "cs_pk_mul_lo_const", want, len(want), env)


class Skip(str):
"""A result that is neither a pass nor a failure: the device can't run the test."""

Expand Down Expand Up @@ -1846,8 +1856,7 @@ def main():
results.append(("cs_fma_fused", fma_fused_test(tools, spirv)))
results.append(("cs_cvt_pk_u8", compute_test(tools, spirv, "cs_cvt_pk_u8", "1", "dump",
expected_words=CVT_PK_U8_WORDS)))
results.append(("cs_pk_mul_lo_const", compute_test(tools, spirv, "cs_pk_mul_lo_const", "1", "dump",
expected_words=PK_MUL_LO_WORDS)))
results.append(("cs_pk_mul_lo_const", pk_mul_lo_const_test(tools, spirv)))
for name, want in W64X_DUMPS: # without --require-wave64 when LEONIDA_W64_EMULATE=1
results.append((name, compute_test(tools, spirv, name, "1", "dump", require_wave64=not W64_EMULATED,
expected_words=want)))
Expand Down
11 changes: 7 additions & 4 deletions scripts/run_gpu_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
sys.path.insert(0, SHADER_DIR)
from build import CLIP_CASES, clip_container, shader_source
from check import (Skip, clip_test, fmt_1010102_test, fmt_d16_xyz_test, fmt_int_narrow_test, fmt_sint32_test,
fmt_xy_xyz_test, tbuffer_store_test)
fmt_xy_xyz_test, tbuffer_store_test, pk_mul_lo_const_test)
from check import compute_unsupported # vk_compute_test's exit 77 over a feature the module needs
from compute_fixture import compute_header
from check import SAMPLER_CASES, sampler_test # ps_ssharp: the S#/T# mip fields (vk_sampler_test)
from check import (CMPX_CLASS_WORDS, CVT_F32_SAT_CASES, CVT_PK_U8_WORDS, PK_MUL_LO_WORDS, GRADIENT_TESTS, TEST_PROGRAMS, TEXTURE_MIP_DEPENDENCIES,
from check import (CMPX_CLASS_WORDS, CVT_F32_SAT_CASES, CVT_PK_U8_WORDS, GRADIENT_TESTS, TEST_PROGRAMS, TEXTURE_MIP_DEPENDENCIES,
TEXTURE_MIP_TEST, GATHER_LOD_TEST, MIP_TEST_PASSES, TEXTURE_CONSTANTS, USER_SGPRS_ENV, USER_SGPRS_WORDS, Skip, mesh_v5_test, not_found_message,
pick_build_dir, start_failure, table_fetch_test, texture_gradient_a16_test, texture_mip_test)
from check import SIGNED_MIP_TEST, UINT_MIP_TEST
Expand Down Expand Up @@ -1006,7 +1006,7 @@ def run_suite(a, work: str) -> int:
results.append((name, ok, problem or f"4096 pixels in each of {len(GET_LOD_TESTS[name])} draw(s): the "
"clamped and the calculated LOD within 1/16"))
elif name in ("cs_bounds", "cs_smem_bounds", "cs_smem_stride_align", "cs_smem_sload_neg", "cs_smem_sconst_off", "cs_buf_tail", "cs_oob_select", "cs_oob_tail",
"cs_buf_swizzle", "cs_cmpx_class_f32", "cs_cvt_pk_u8", "cs_pk_mul_lo_const", "cs_buf_load_sub", "cs_buf_fmt8"):
"cs_buf_swizzle", "cs_cmpx_class_f32", "cs_cvt_pk_u8", "cs_buf_load_sub", "cs_buf_fmt8"):
# num_records bounds check (cs_bounds.asm): the out-of-bounds store is dropped and the out-of-bounds
# load reads 0, so thread 0's four output words are fixed. One thread, no wave64 requirement.
# cs_cmpx_class_f32 and cs_cvt_pk_u8 are per-lane and need no particular subgroup width either.
Expand All @@ -1030,7 +1030,6 @@ def run_suite(a, work: str) -> int:
0xBEEF0001],
"cs_cmpx_class_f32": CMPX_CLASS_WORDS,
"cs_cvt_pk_u8": CVT_PK_U8_WORDS,
"cs_pk_mul_lo_const": PK_MUL_LO_WORDS,
# TEST-510: sub-dword MUBUF loads (RAW end check by element size) and GFX10_FORMAT_8_UINT
"cs_buf_load_sub": [0x80, 0xFFFFFF80, 0x1FF, 0xFFFF807F, 0xAB01, 0xCD, 0, 0],
"cs_buf_fmt8": [0x7F, 0x80, 0xFF, 0x01, 0, 0, 0xFF, 1],
Expand All @@ -1039,6 +1038,10 @@ def run_suite(a, work: str) -> int:
vals = words[:len(want)] if words else []
results.append((name,) + compute_result(rc, msg, rc == 0 and vals == want,
" ".join(hex(x) for x in vals) if vals else msg))
elif name == "cs_pk_mul_lo_const":
problem = pk_mul_lo_const_test(a.build, spirv_dir, cs_env)
ok = None if isinstance(problem, Skip) else not problem
results.append((name, ok, problem or "128/128 dumped words exact (32 lanes)"))
elif name == "cs_fmt_1010102":
problem = fmt_1010102_test(a.build, spirv_dir, cs_env)
results.append((name, not problem, problem or "64/64 dumped words exact"))
Expand Down
110 changes: 110 additions & 0 deletions tests/test_pk_mul_lo_gpu_fixture.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
"""The packed-multiply GPU fixture needs a 512-byte heap and checks all 32 lanes, through both runners.

python -I tests/test_pk_mul_lo_gpu_fixture.py

Harness and translation stand-ins only; no GPU, LLVM or game files.
"""
from contextlib import redirect_stdout
import io
import json
import os
from pathlib import Path
import struct
import sys
import tempfile
from types import SimpleNamespace
import unittest
from unittest.mock import patch

sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "scripts"))
import run_gpu_tests as rgt # noqa: E402
import check # noqa: E402; run_gpu_tests adds the shader-tools directory

NAME = "cs_pk_mul_lo_const"
# The four RDNA2-measured words in cs_pk_mul_lo_const.asm, for all 32 lanes.
WORDS = [0x00009E88, 0x03675433, 0x00230000, 0x00077F6C] * 32
GOOD = struct.pack("<128I", *WORDS)
VALIDATION = {"LEONIDA_VK_VALIDATION": "1", "VK_KHRONOS_VALIDATION_GPUAV_ENABLE": "1",
"LEONIDA_W64_EMULATE": "1"}


class PackedMultiplyFixture(unittest.TestCase):
def exercise(self, runner, data=GOOD, code=0, diagnostic="", subgroup=None):
with tempfile.TemporaryDirectory() as tmp:
work = Path(tmp)
spirv = work / "spirv"
spirv.mkdir()
(spirv / f"{NAME}.spv").touch()
(spirv / "index.json").write_text(
json.dumps({NAME: {"wave64_emulated": True, "subgroup_size": 32}}), encoding="utf-8", newline="\n")
calls = []

def harness(tool, shader, *args, env=None):
calls.append((tool, shader, args, dict(env)))
self.assertEqual(Path(tool).stem, "vk_compute_test")
self.assertEqual(Path(shader).stem, NAME)
self.assertEqual(args, ("1", "dump"))
self.assertEqual(env["VKC_OUT_WORDS"], "128")
for key, value in VALIDATION.items():
self.assertEqual(env[key], value)
self.assertEqual(env["VKC_SUBGROUP_SIZE"], str(subgroup or 32))
target = Path(env["VKC_DUMP"])
self.assertFalse(target.exists())
if data is not None:
target.write_bytes(data)
# Correct console words cannot hide a corrupt tail or a validation failure.
return code, diagnostic + "\nout[0..7] = " + " ".join(map(str, WORDS[:8])) + "\n"

def translate(cmd, **kwargs):
self.assertEqual(cmd[:3], [sys.executable, "-I", rgt.TRANSLATOR])
(spirv / f"{NAME}.spv").touch()
return 0, ""

env = {**VALIDATION, "VKC_OUT_WORDS": "64"}
if subgroup is not None:
env["VKC_SUBGROUP_SIZE"] = str(subgroup)
with (patch.dict(os.environ, env), patch.object(check, "run", side_effect=harness),
patch.object(rgt, "assemble_to_s", side_effect=lambda _mc, _src, dst, _name: Path(dst).touch()),
patch.object(rgt, "spirv_as"), patch.object(rgt, "run_cmd", side_effect=translate),
patch.object(rgt, "bary_fallback", return_value=False),
patch.object(rgt, "f16_interp_fallback", return_value=False)):
if subgroup is None:
os.environ.pop("VKC_SUBGROUP_SIZE", None)
if runner == "check":
result = check.pk_mul_lo_const_test(tmp, str(spirv))
status, output = (0 if not result else 1), str(result)
else:
args = SimpleNamespace(filter=NAME, build=tmp, llvm_mc="unused")
output = io.StringIO()
with redirect_stdout(output):
status = rgt.run_suite(args, tmp)
output = output.getvalue()
self.assertEqual(len(calls), 1)
return status, output

def test_both_runners_allocate_and_check_all_lanes_with_validation_enabled(self):
for runner in ("check", "run_gpu_tests"):
with self.subTest(runner=runner):
status, output = self.exercise(runner)
self.assertEqual(status, 0, output)

def test_an_explicit_subgroup_size_is_forwarded(self):
status, output = self.exercise("check", subgroup=64)
self.assertEqual(status, 0, output)

def test_bad_readback_or_harness_failure_never_passes(self):
wrong = struct.pack("<128I", *WORDS[:-1], WORDS[-1] ^ 1)
cases = (("last lane", wrong, 0, "", "word 127"),
("old allocation", GOOD[:256], 0, "", "expected 512 dump bytes, got 256"),
("missing dump", None, 0, "", "no VKC_DUMP file written"),
("validation error", GOOD, 1, "validation: out-of-bounds store", "exit 1"))
for runner in ("check", "run_gpu_tests"):
for label, data, code, diagnostic, expected in cases:
with self.subTest(runner=runner, case=label):
status, output = self.exercise(runner, data, code, diagnostic)
self.assertEqual(status, 1, output)
self.assertIn(expected, output)


if __name__ == "__main__":
unittest.main()
2 changes: 2 additions & 0 deletions tests/test_shader_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ def harness(_tool, shader, *args, env=None):
if name == "cs_cvt_pk_u8":
return 0, "out[0..7] = " + " ".join(map(str, check.CVT_PK_U8_WORDS)) + "\n"
if name == "cs_pk_mul_lo_const":
self.assertEqual((args, env["VKC_OUT_WORDS"]), (("1", "dump"), "128"))
Path(env["VKC_DUMP"]).write_bytes(struct.pack("<128I", *(check.PK_MUL_LO_WORDS[:4] * 32)))
return 0, "out[0..7] = " + " ".join(map(str, check.PK_MUL_LO_WORDS)) + "\n"
if name == "cs_store":
return 0, "out[0..7] = " + " ".join(map(str, (check.CS_STORE + [0] * 8)[:8])) + "\n"
Expand Down