diff --git a/runtime/test/shaders/w64_graphics.py b/runtime/test/shaders/w64_graphics.py index 649fc4630b..d10e98ee82 100644 --- a/runtime/test/shaders/w64_graphics.py +++ b/runtime/test/shaders/w64_graphics.py @@ -12,9 +12,9 @@ tier C the words the header names differ between the two sizes, which shows the translator's detector is right to flag the shader (the other words stay equal) -A device that can require only one size (NVIDIA: 32 only) cannot run the comparison. There the default-size image is -checked against the derived words (tiers A, B), the tier C check is skipped, and two environment variables let a -second device stand in for the missing size: W64G_SAVE_REF= stores the 64-lane run after its available checks +A device that can require only one size (NVIDIA: 32 only) still checks the words with a known value in every tier. +Tier C skips the comparison between sizes if the other width is unavailable. Two environment variables let a second +device stand in for the missing size: W64G_SAVE_REF= stores the 64-lane run after its available checks pass, including on devices with 64 as their only size (AMD GCN). W64G_REF= compares every run of the other device with those files (equal for A and B, different for C). @@ -348,6 +348,8 @@ def expected_problem(name, words, heap): wrong.append((i, w, want)) if wrong: i, w, want = wrong[0] + if tier == "C": + return f"a partition-invariant word differs in {len(wrong)} of {len(words)} records, first at {i}: got {w}, want {want}" return f"{len(wrong)} of {len(words)} pixels differ from the derived words, first ({_x(i)},{_y(i)}): got {w}, want {want}" if name.endswith("_b_ballot_atomic"): want = sorted(i + 1 for i in range(len(words)) if _x(i) % 4 == 1) @@ -411,13 +413,13 @@ def check(tools, spirv, name): if live is not None and live < need: return Skip(f"SKIP (the fragment stage has {live} live lanes per subgroup here, measured with " f"ps_live_width; this fixture needs {need})") + for size, (words, heap) in runs.items(): + if tier != "C" and size is None and len(runs) > 1: + continue # the default draw repeats one of the forced sizes for tiers A and B + p = expected_problem(name, words, heap) + if p: + return f"{size or 'default size'}: {p}" if tier in ("A", "B"): - for size, (words, heap) in runs.items(): - if size is None and len(runs) > 1: - continue # the default draw repeats one of the forced sizes - p = expected_problem(name, words, heap) - if p: - return f"{size or 'default size'}: {p}" if 64 in runs and 32 in runs and comparable(name, *runs[64]) != comparable(name, *runs[32]): return "the images at required subgroup size 64 and 32 differ" elif 64 in runs and 32 in runs: diff --git a/tests/test_w64_graphics_reference.py b/tests/test_w64_graphics_reference.py index c258b097d8..e0c1ecd794 100644 --- a/tests/test_w64_graphics_reference.py +++ b/tests/test_w64_graphics_reference.py @@ -21,15 +21,23 @@ def test_partition_invariant_word_must_match_reference(self) -> None: wrong_x = wave32.copy() lane, half, x, zero = wrong_x[73] wrong_x[73] = (lane, half, x + 1, zero) + wrong_reference = wave64.copy() + lane, half, x, zero = wrong_reference[73] + wrong_reference[73] = (lane, half, x + 1, zero) with tempfile.TemporaryDirectory() as work: (Path(work) / f"{name}.spv").touch() - (Path(work) / f"{name}.ref64.raw").write_bytes( - b"".join(struct.pack("<4I", *pixel) for pixel in wave64) - ) with patch.dict(os.environ, W64G_REF=work, W64G_SAVE_REF=""): - for frame, expected in ((wave32, ""), (wrong_x, "partition-invariant word")): - with self.subTest(expected=expected), patch.object( + for case, reference, frame, expected in ( + ("valid", wave64, wave32, ""), + ("bad draw", wave64, wrong_x, "partition-invariant word"), + ("bad reference", wrong_reference, wave32, "partition-invariant word"), + ("same wrong x", wrong_reference, wrong_x, "partition-invariant word"), + ): + (Path(work) / f"{name}.ref64.raw").write_bytes( + b"".join(struct.pack("<4I", *pixel) for pixel in reference) + ) + with self.subTest(case=case), patch.object( w64_graphics, "draw", side_effect=lambda _tools, _spirv, _name, size, _tmp: (frame, None, size == 32), ): @@ -39,6 +47,24 @@ def test_partition_invariant_word_must_match_reference(self) -> None: else: self.assertEqual(result, "") + def test_two_measured_widths_still_check_the_triangle_index(self) -> None: + name = "gs_w64_c_lane_id" + with tempfile.TemporaryDirectory() as work, patch.dict(os.environ, W64G_REF="", W64G_SAVE_REF=""): + (Path(work) / f"{name}.spv").touch() + for bad_widths in ((), (64, 32, None), (None,)): + def draw(_tools, _spirv, _name, size, _tmp): + width = size or 32 + frame = [(i % width, i % 32, 0 if size in bad_widths else i, 0) + for i in range(w64_graphics.VS_VERTICES // 3)] + return frame, None, size is not None + + with self.subTest(bad_widths=bad_widths), patch.object(w64_graphics, "draw", side_effect=draw): + result = w64_graphics.check(work, work, name) + if bad_widths: + self.assertIn("partition-invariant word differs", result) + else: + self.assertEqual(result, "") + class SaveReferenceTests(unittest.TestCase): def setUp(self) -> None: @@ -90,6 +116,19 @@ def test_wave64_only_exports_tier_c_reference_on_skip(self) -> None: reference = self.work / f"{name}.ref64.raw" self.assertEqual(reference.read_bytes(), b"".join(struct.pack("<4I", *p) for p in frame)) + def test_bad_tier_c_draw_fails_before_skip_or_export(self) -> None: + name = "vs_w64_c_lane_id" + # The third word is the vertex index at every subgroup width. + frame = [(i % 64, i % 32, i, 0) for i in range(w64_graphics.VS_VERTICES)] + reference = self.work / f"{name}.ref64.raw" + self.assertIsInstance(self.replay(name, frame, sizes=(64,)), w64_graphics.Skip) + saved = reference.read_bytes() + frame[7] = (7, 7, 0, 0) + for sizes in ((64,), (32,), ()): + with self.subTest(sizes=sizes): + self.assertIn("partition-invariant word", self.replay(name, frame, sizes=sizes)) + self.assertEqual(reference.read_bytes(), saved) + if __name__ == "__main__": unittest.main()