Skip to content
Merged
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
6 changes: 6 additions & 0 deletions docs/experiments.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
38 changes: 38 additions & 0 deletions tests/mesh_dynamic_aot_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions tools/mesh_entry_aot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("<I", struct.pack("<f", float(t)))[0]
return int(t, 0)
Expand Down
Loading