diff --git a/runtime/test/shaders/w64_graphics.py b/runtime/test/shaders/w64_graphics.py index 5b8114445..0ebda3c22 100644 --- a/runtime/test/shaders/w64_graphics.py +++ b/runtime/test/shaders/w64_graphics.py @@ -15,8 +15,9 @@ 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). +pass, including on devices with 64 as their only size (AMD GCN). W64G_REF= checks the other device's tier A/B draws +against those files. Tier C compares a verified 32-wide draw with the saved 64-wide run. A fixed-32 device can +use its default draw. A device whose subgroups can be narrower than 32 (Intel: 8..32) and that could not be held to 32 or 64 skips the tier A and B pixel fixtures: its fragment stage may run fewer live lanes than 32 (Intel UHD 770 reports 32 but runs 16 live @@ -275,11 +276,18 @@ def _draw_heap(tools, spirv, name, size, tmp): return None, "unsupported: " + out.strip().splitlines()[-1] if r.returncode or not heap.is_file(): return None, f"exit {r.returncode}: {' | '.join(out.strip().splitlines()[-3:])}" + _record_device_range(out) words = list(struct.unpack("<%dI" % (65536 // 4), heap.read_bytes())) return [tuple(words[VS_RECORDS + 4 * v:VS_RECORDS + 4 * v + 4]) for v in range(records)], words -_device_min = [None] # the smallest subgroup size vk_harness reported for the device +_device_range = None # subgroup size limits reported by the harness for this draw + + +def _record_device_range(output): + global _device_range + match = re.search(r"subgroup (\d+)\.\.(\d+)", output) + _device_range = (int(match[1]), int(match[2])) if match else None # Pixel fixtures that read lanes beyond the first 16 (a half-wave exchange, lane L ^ 16), and how many live lanes per @@ -334,9 +342,7 @@ def draw(tools, spirv, name, size, tmp): data = raw.read_bytes() if len(data) != W * H * 16: return None, f"{len(data)} bytes of pixels, expected {W * H * 16}", None - m = re.search(r"subgroup (\d+)\.\.(\d+)", out) - if m: - _device_min[0] = int(m.group(1)) + _record_device_range(out) applied = None if size: applied = f"fragment subgroup size: {size}\n" in out.replace("\r", "") @@ -409,8 +415,8 @@ def check(tools, spirv, name): # 8..32) and that could not be held to 32 or 64 may run fewer live lanes than it reports (UHD 770: 16 live # behind a reported 32): reads across them return garbage. if tier in ("A", "B") and name.startswith("ps_") and 64 not in runs and 32 not in runs \ - and _device_min[0] is not None and _device_min[0] < 32: - return Skip(f"SKIP (the fragment stage may run fewer live lanes than 32 here ({_device_min[0]}..) " + and _device_range is not None and _device_range[0] < 32: + return Skip(f"SKIP (the fragment stage may run fewer live lanes than 32 here ({_device_range[0]}..) " "and 32 or 64 could not be required: tiers A and B assume 32 or 64 live lanes)") # A fixture that reads a lane beyond the quad or the first 16 (NEEDS_LIVE_LANES) is judged only where the # measured live width is enough: the stage can report a subgroup size it does not fill (Intel: 32 reported, @@ -443,11 +449,12 @@ def check(tools, spirv, name): for size, (words, heap) in runs.items(): if size == 64: continue - if tier == "C" and comparable(name, ref_words, None) != comparable(name, words, None): - return "a partition-invariant word differs from the 64-lane reference" if tier == "C": if comparable(name, ref_words, None) != comparable(name, words, None): - return "a word that must not depend on the partition differs from the 64-lane reference" + return "a partition-invariant word differs from the 64-lane reference" + # A default draw can be 64-wide itself. Use it only if it is our sole, known 32-wide run. + if size is None and (32 in runs or _device_range != (32, 32)): + continue if not partition_dependent(name, ref_words, words): return "tier C but the run equals the 64-lane reference: the detector is wrong" compared = True @@ -458,7 +465,7 @@ def check(tools, spirv, name): Path(save).mkdir(parents=True, exist_ok=True) (Path(save) / (name + ".ref64.raw")).write_bytes(b"".join(struct.pack("<4I", *w) for w in runs[64][0])) if tier == "C" and not compared: - return Skip("SKIP (tier C needs a device that can require both 64 and 32, or W64G_REF)") + return Skip("SKIP (tier C needs verified 32- and 64-wide draws; W64G_REF can supply the 64-wide draw)") return "" diff --git a/tests/test_w64_graphics_reference.py b/tests/test_w64_graphics_reference.py index e0c1ecd79..561969765 100644 --- a/tests/test_w64_graphics_reference.py +++ b/tests/test_w64_graphics_reference.py @@ -13,6 +13,36 @@ class TierCReferenceTests(unittest.TestCase): + def test_default_width_does_not_stand_in_for_a_wave32_draw(self) -> None: + name = "ps_w64_c_lane_id" + count = w64_graphics.W * w64_graphics.H + frames = {width: [(i % width, i % 32, i % 64, 0) for i in range(count)] for width in (32, 64)} + with tempfile.TemporaryDirectory() as work, patch.dict(os.environ, W64G_REF=work, W64G_SAVE_REF=""), \ + patch.object(w64_graphics, "_device_range", None): + (Path(work) / f"{name}.spv").touch() + (Path(work) / f"{name}.ref64.raw").write_bytes( + b"".join(struct.pack("<4I", *pixel) for pixel in frames[64]) + ) + for required, default, limits, should_compare in ( + ((32, 64), 64, "32..64", True), + ((32, 64), 32, "32..64", True), + ((32,), 32, "32..32", True), + ((64,), 64, "64..64", False), + ((), 32, "32..32", True), # VS/GS with a fixed width and no applied stage request + ((), 64, "32..64", False), # the harness has no proof of the default draw's width + ): + def draw(_tools, _spirv, _name, size, _tmp): + w64_graphics._record_device_range(f"device: test (subgroup {limits})") + return frames[size if size in required else default], None, size in required + + with self.subTest(required=required, default=default), \ + patch.object(w64_graphics, "draw", side_effect=draw): + result = w64_graphics.check(work, work, name) + if should_compare: + self.assertEqual(result, "") + else: + self.assertIsInstance(result, w64_graphics.Skip) + def test_partition_invariant_word_must_match_reference(self) -> None: name = "ps_w64_c_lane_id" # The fixture writes lane ID, lane ID within a half, pixel X and zero. @@ -30,6 +60,7 @@ def test_partition_invariant_word_must_match_reference(self) -> None: with patch.dict(os.environ, W64G_REF=work, W64G_SAVE_REF=""): for case, reference, frame, expected in ( ("valid", wave64, wave32, ""), + ("same lanes", wave64, wave64, "equals the 64-lane reference"), ("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"), @@ -47,6 +78,21 @@ def test_partition_invariant_word_must_match_reference(self) -> None: else: self.assertEqual(result, "") + def test_unverified_width_still_checks_reference_invariants(self) -> None: + name = "ps_w64_c_lane_id" + count = w64_graphics.W * w64_graphics.H + frame = [(i % 64, i % 32, i % 64, 0) for i in range(count)] + reference = frame.copy() + reference[0] = (0, 0, 1, 0) + with tempfile.TemporaryDirectory() as work, patch.dict(os.environ, W64G_REF=work, W64G_SAVE_REF=""), \ + patch.object(w64_graphics, "_device_range", (32, 64)), \ + patch.object(w64_graphics, "draw", return_value=(frame, None, False)): + (Path(work) / f"{name}.spv").touch() + (Path(work) / f"{name}.ref64.raw").write_bytes( + b"".join(struct.pack("<4I", *pixel) for pixel in reference) + ) + self.assertIn("partition-invariant word", w64_graphics.check(work, work, name)) + 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=""):