diff --git a/docs/experiments.md b/docs/experiments.md index f5c8cb13a9..b3d293324f 100644 --- a/docs/experiments.md +++ b/docs/experiments.md @@ -3808,6 +3808,12 @@ exporting vertices 0–63. Wave 1 passes one more barrier and writes vertices it the position of vertex 2 collapses the triangle and changes 528 pixels. The CPU check also runs the waves in both host evaluation orders. +The static and runtime mesh lowerers read a concrete `src_scc` as the word +0 or 1. The fixture compares the triangle allocation word, then compares that +SCC with 1 for equality or 0 for inequality before taking the branch. Both +forms preserve the triangle and quad outputs. Reading an undefined SCC or +one that still depends on a constant-buffer value produces a refusal. + [`tools/mesh_dynamic_aot.py`](../tools/mesh_dynamic_aot.py) emits one desktop mesh shader for a two-wave64 triangle entry. It splits runtime input cases at scalar equality tests and reruns the existing wave model for each case. diff --git a/tests/mesh_dynamic_aot_check.py b/tests/mesh_dynamic_aot_check.py index 3e7090071c..e3c1f8ee5e 100644 --- a/tests/mesh_dynamic_aot_check.py +++ b/tests/mesh_dynamic_aot_check.py @@ -29,6 +29,43 @@ def expect_refusal(decoded, geometry_word_count, text, limits=MESH_LIMITS): raise AssertionError(f"Expected refusal: {text}") +def check_scc_operand(): + # Preserve the geometry comparison's truth value before its conditional branch. + # LLVM gfx1013 wave64: s_cmp_eq_u32 src_scc, 1 / s_cmp_lg_u32 0, src_scc. + body = decode(CODE) + offset = next(pc for pc, op in body if op.startswith("s_cbranch_scc0 ")) + expected = enumerate_variants(body, 2, MESH_LIMITS) + for instruction in ("fd8106bf", "80fd07bf"): + program = decode(CODE[:offset] + bytes.fromhex(instruction) + CODE[offset:]) + assert enumerate_variants(program, 2, MESH_LIMITS) == expected + for geometry in ([0x1003, SECOND], [0x2004, SECOND]): + assert lower_static(program, geometry, MESH_LIMITS) == lower_static(body, geometry, MESH_LIMITS) + + # The first instruction cannot read an undefined SCC. + undefined = decode(bytes.fromhex("fd8106bf") + CODE) + for lowerer, inputs in ((lower_static, [0x1003, SECOND]), (lower, 2)): + try: + lowerer(undefined, inputs, MESH_LIMITS) + except ValueError as error: + assert "Undefined scalar predicate in src_scc" in str(error), error + else: + raise AssertionError("Accepted src_scc before a predicate was defined") + wave = Wave(0, []) + for addend, carry in (("0", 0), ("1", 1)): + wave.scalar_op("s_add_u32", ["s6", "0xffffffff", addend]) + wave.scalar_op("s_mov_b32", ["s7", "src_scc"]) + assert wave.scalar("s7") == carry + # A constant-buffer comparison has no concrete result at translation time. + wave.s[7] = "pointData[0].x" + wave.scalar_op("s_cmp_eq_u32", ["s7", "0"]) + try: + wave.scalar_op("s_cmp_eq_u32", ["src_scc", "1"]) + except ValueError as error: + assert "Dynamic scalar predicate in src_scc" in str(error), error + else: + raise AssertionError("Treated a dynamic SCC as a concrete word") + + def check_retired_wave(): body = decode(CODE) decoded = decode(RETIRED_PREFIX + CODE) @@ -137,6 +174,7 @@ def check_exec_restore(decoded): def check(): + check_scc_operand() check_retired_wave() decoded = decode(CODE) variants = enumerate_variants(decoded, 2, MESH_LIMITS) diff --git a/tools/mesh_entry_aot.py b/tools/mesh_entry_aot.py index d53d0365fa..7a9c0afd0e 100644 --- a/tools/mesh_entry_aot.py +++ b/tools/mesh_entry_aot.py @@ -198,6 +198,12 @@ def scalar(self, t, allow_undef=False): if self.vcc is None: raise ValueError("Undefined wave predicate") return self.vcc + if t == "src_scc": + if self.scc is None: + raise ValueError("Undefined scalar predicate in src_scc") + if isinstance(self.scc, Dyn): + raise ValueError("Dynamic scalar predicate in src_scc") + return int(self.scc) if re.fullmatch(r"-?\d+\.\d+", t): return struct.unpack("