feat: lower group-uniform any-lane SCC branch in mesh programs #2134

Merged
tedin7 merged 3 commits from upstream-pr/2142 into main 2026-11-25 08:45:23 +00:00
tedin7 commented 2026-11-25 01:30:56 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T01:30:56Z.


Part of #1998

What this unblocks: mesh programs that branch on "any lane active" across both waves (Item A, about 1,190 programs) can now be lowered instead of refused.

What changed

  • The two-wave64 mesh interpreter runs waves in lockstep between barriers and models LDS publish (ds_write_b32), s_barrier, ds_read_b32, v_readfirstlane_b32 and SCC branches (s_cbranch_scc0, s_cbranch_scc1).
  • 64-bit scalar compares (s_cmp_lg_u64, s_cmp_eq_u64) and s_cmp_lg_u32 are accepted. Unsupported widths are refused by name.
  • Refused: reads nobody published, stores not waited before the barrier, reads before their wait, own-store reads before a barrier, conflicting stores, dynamic or unaligned LDS addresses.
  • New source-built program tests/mesh_scc_any_lane.s with embedded bytes.
  • New tests registered in CMake: mesh_scc_any_lane_cpu, mesh_scc_any_lane_draw_{hardware,warp}.
  • Docs: docs/experiments.md.

Verification

Executed locally (Linux, CPU only):

python3 -B tests/mesh_scc_any_lane_check.py
python3 -B tests/mesh_dynamic_geometry_check.py
python3 -B tests/mesh_dynamic_aot_check.py
python3 -B tests/mesh_amplification_refusal_check.py
python3 -B tests/mesh_multi_check.py
python3 -B tests/pso_readiness_check.py

All passed. A dry run of the lowering gave (4,2) for T in {0,64,100,127} and (3,1) for T in {128,200}. The three mutants (own flag only, flipped branch, 32-bit mask compare) give (3,1) at T=100.

NOT run yet (needs Win2025, Stage 2):

ctest --preset release --no-tests=error -R "mesh_scc_any_lane" -V
python3 -B tests/mesh_scc_any_lane_check.py binary llvm-mc llvm-objcopy libLLVM-15.so.1

The D3D12 WARP readback test and the LLVM reassembly check of the hand-encoded bytes are pending. Draft until they pass.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6595043397 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2142). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T01:30:56Z. --- Part of #1998 What this unblocks: mesh programs that branch on "any lane active" across both waves (Item A, about 1,190 programs) can now be lowered instead of refused. ## What changed - The two-wave64 mesh interpreter runs waves in lockstep between barriers and models LDS publish (`ds_write_b32`), `s_barrier`, `ds_read_b32`, `v_readfirstlane_b32` and SCC branches (`s_cbranch_scc0`, `s_cbranch_scc1`). - 64-bit scalar compares (`s_cmp_lg_u64`, `s_cmp_eq_u64`) and `s_cmp_lg_u32` are accepted. Unsupported widths are refused by name. - Refused: reads nobody published, stores not waited before the barrier, reads before their wait, own-store reads before a barrier, conflicting stores, dynamic or unaligned LDS addresses. - New source-built program `tests/mesh_scc_any_lane.s` with embedded bytes. - New tests registered in CMake: `mesh_scc_any_lane_cpu`, `mesh_scc_any_lane_draw_{hardware,warp}`. - Docs: `docs/experiments.md`. ## Verification Executed locally (Linux, CPU only): ```text python3 -B tests/mesh_scc_any_lane_check.py python3 -B tests/mesh_dynamic_geometry_check.py python3 -B tests/mesh_dynamic_aot_check.py python3 -B tests/mesh_amplification_refusal_check.py python3 -B tests/mesh_multi_check.py python3 -B tests/pso_readiness_check.py ``` All passed. A dry run of the lowering gave (4,2) for T in {0,64,100,127} and (3,1) for T in {128,200}. The three mutants (own flag only, flipped branch, 32-bit mask compare) give (3,1) at T=100. NOT run yet (needs Win2025, Stage 2): ```text ctest --preset release --no-tests=error -R "mesh_scc_any_lane" -V python3 -B tests/mesh_scc_any_lane_check.py binary llvm-mc llvm-objcopy libLLVM-15.so.1 ``` The D3D12 WARP readback test and the LLVM reassembly check of the hand-encoded bytes are pending. Draft until they pass. AI-assisted; commands listed were executed locally.
chatgpt-codex-connector[bot commented 2026-11-25 02:01:56 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-25T01:45:12Z.

Review: COMMENTED


💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6fa78fc62e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6050340675 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2142#pullrequestreview-6050340675). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-25T01:45:12Z. **Review:** COMMENTED --- <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `6fa78fc62e` <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". </details>
chatgpt-codex-connector[bot commented 2026-11-25 02:02:08 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-25T01:36:37Z.


Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-25T01:45:15.051571Z 6fa78fc Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7149746972 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2142#issuecomment-7149746972). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-25T01:36:37Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"6fa78fc62ed27727d7934da139651a894d432c51","has_any_findings":true,"has_unresolved_findings":true,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} --> <details> <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ✅ **Completed** <relative-time datetime="2026-11-25T01:45:15.051571Z">2026-11-25T01:45:15.051571Z</relative-time> | `6fa78fc` | Draft marked ready | <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@codex review" or "@codex security review". Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. </details> </details>
chatgpt-codex-connector[bot commented 2026-11-25 02:02:15 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-25T01:45:12Z.

Code review location: tools/mesh_entry_aot.py; line 623

@@ -515,6 +590,40 @@ def run(self, decoded, expressions):
         raise ValueError("No program exit")
 
 
+def run_group(waves, decoded, expressions):
+    """Run the waves of one group in lockstep between barriers.
+
+    Each wave runs to its next barrier before any wave goes on. Stores become
+    visible to every wave only when all of them have reached the barrier.
+    """
+    lds = {}
+    for wave in waves:
+        wave.lds = lds
+    running = [wave.steps(decoded, expressions) for wave in waves]
+    while True:
+        reached = 0
+        for steps in running:
+            try:
+                next(steps)
+                reached += 1
+            except StopIteration:
+                pass
+        if not reached:
+            return
+        if reached != len(waves):
+            raise ValueError("Waves of one group reach different numbers of barriers")
+        published = {}
+        for wave in waves:
+            for address, data in wave.staged.items():
+                if published.setdefault(address, data) != data:
+                    raise ValueError("Waves store different values to one LDS dword")
+        for wave in waves:
+            if wave.reads.intersection(address for other in waves if other is not wave for address in other.staged):
+                raise ValueError("LDS dword read and stored by different waves without a barrier")
+            wave.staged, wave.reads = {}, set()

P2 Badge Validate all waves before clearing staged LDS stores

If wave 0 overwrites a previously published dword while wave 1 reads it in the same barrier interval, wave 0's staged map is cleared before wave 1's reads are checked. The latter therefore misses the conflicting store, and lower() accepts a shader specialized to the old value; reversing the wave roles correctly rejects the same hazard. Check every wave against all staged stores before clearing any of them.

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4689095356 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2142#discussion_r4689095356). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-25T01:45:12Z. **Code review location:** `tools/mesh_entry_aot.py`; line 623 ~~~~diff @@ -515,6 +590,40 @@ def run(self, decoded, expressions): raise ValueError("No program exit") +def run_group(waves, decoded, expressions): + """Run the waves of one group in lockstep between barriers. + + Each wave runs to its next barrier before any wave goes on. Stores become + visible to every wave only when all of them have reached the barrier. + """ + lds = {} + for wave in waves: + wave.lds = lds + running = [wave.steps(decoded, expressions) for wave in waves] + while True: + reached = 0 + for steps in running: + try: + next(steps) + reached += 1 + except StopIteration: + pass + if not reached: + return + if reached != len(waves): + raise ValueError("Waves of one group reach different numbers of barriers") + published = {} + for wave in waves: + for address, data in wave.staged.items(): + if published.setdefault(address, data) != data: + raise ValueError("Waves store different values to one LDS dword") + for wave in waves: + if wave.reads.intersection(address for other in waves if other is not wave for address in other.staged): + raise ValueError("LDS dword read and stored by different waves without a barrier") + wave.staged, wave.reads = {}, set() ~~~~ --- **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Validate all waves before clearing staged LDS stores** If wave 0 overwrites a previously published dword while wave 1 reads it in the same barrier interval, wave 0's `staged` map is cleared before wave 1's `reads` are checked. The latter therefore misses the conflicting store, and `lower()` accepts a shader specialized to the old value; reversing the wave roles correctly rejects the same hazard. Check every wave against all staged stores before clearing any of them. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
chatgpt-codex-connector[bot commented 2026-11-25 02:02:15 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-25T01:45:12Z.

Code review location: tools/mesh_entry_aot.py; line 612

@@ -515,6 +590,40 @@ def run(self, decoded, expressions):
         raise ValueError("No program exit")
 
 
+def run_group(waves, decoded, expressions):
+    """Run the waves of one group in lockstep between barriers.
+
+    Each wave runs to its next barrier before any wave goes on. Stores become
+    visible to every wave only when all of them have reached the barrier.
+    """
+    lds = {}
+    for wave in waves:
+        wave.lds = lds
+    running = [wave.steps(decoded, expressions) for wave in waves]
+    while True:
+        reached = 0
+        for steps in running:
+            try:
+                next(steps)
+                reached += 1
+            except StopIteration:
+                pass
+        if not reached:
+            return

P2 Badge Validate the final LDS interval before returning

When wave 1 overwrites a previously published LDS dword and wave 0 reads it after the last barrier, both generators can terminate here before the cross-wave hazard checks run. The program is then accepted and its read is folded to the old value; adding a trailing barrier correctly rejects the otherwise identical program. The final interval needs the same LDS conflict validation as a barrier-terminated interval before run_group() returns.

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4689095366 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2142#discussion_r4689095366). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-25T01:45:12Z. **Code review location:** `tools/mesh_entry_aot.py`; line 612 ~~~~diff @@ -515,6 +590,40 @@ def run(self, decoded, expressions): raise ValueError("No program exit") +def run_group(waves, decoded, expressions): + """Run the waves of one group in lockstep between barriers. + + Each wave runs to its next barrier before any wave goes on. Stores become + visible to every wave only when all of them have reached the barrier. + """ + lds = {} + for wave in waves: + wave.lds = lds + running = [wave.steps(decoded, expressions) for wave in waves] + while True: + reached = 0 + for steps in running: + try: + next(steps) + reached += 1 + except StopIteration: + pass + if not reached: + return ~~~~ --- **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Validate the final LDS interval before returning** When wave 1 overwrites a previously published LDS dword and wave 0 reads it after the last barrier, both generators can terminate here before the cross-wave hazard checks run. The program is then accepted and its read is folded to the old value; adding a trailing barrier correctly rejects the otherwise identical program. The final interval needs the same LDS conflict validation as a barrier-terminated interval before `run_group()` returns. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
chatgpt-codex-connector[bot commented 2026-11-25 02:02:16 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-25T01:45:12Z.

Code review location: tools/mesh_entry_aot.py; line 442

@@ -383,7 +399,58 @@ def fp(x):
                 raise ValueError("Pending vector destination")
             self.v[lane][int(d[1:])] = v & U32 if isinstance(v, int) else v
 
+    def lds_op(self, op, tail):
+        """One dword per live lane at a concrete, aligned, in-range LDS address.
+
+        A load sees only dwords published at an earlier barrier. A wave's own
+        unpublished store is refused rather than guessed at.
+        """
+        write = op == "ds_write_b32"
+        match = re.fullmatch(r"(v\d+), (v\d+)(?: offset:(\d+))?", tail)
+        if not match:
+            raise ValueError(f"Unsupported {op} operands")
+        first, second = match[1], match[2]
+        offset = int(match[3] or 0)
+        address_reg, data_reg, dest = (first, second, None) if write else (second, None, first)
+        if offset >= LDS_BYTES:
+            raise ValueError("LDS offset outside the group allocation")
+        writes = {}
+        for lane in range(64):
+            if not self.exec & (1 << lane):
+                continue
+            address = self.lane_value(address_reg, lane)
+            if type(address) is not int:
+                raise ValueError("Dynamic LDS address")
+            address += offset
+            if address % 4 or not 0 <= address < LDS_BYTES:
+                raise ValueError("LDS address outside the group allocation or unaligned")
+            if write:
+                data = self.lane_value(data_reg, lane)
+                if type(data) is not int:
+                    raise ValueError("LDS store of a non-integer value")
+                if writes.setdefault(address, data & U32) != data & U32:
+                    raise ValueError("Lanes store different values to one LDS dword")
+            else:
+                if address in self.staged:
+                    raise ValueError("LDS load of this wave's store before a barrier")
+                if address not in self.lds:
+                    raise ValueError("LDS load of a dword no wave published")
+                if (lane, dest) in self.pending_v or (lane, dest) in self.pending_ds:
+                    raise ValueError("LDS load overwrites a pending result")
+                self.reads.add(address)
+                self.v[lane][int(dest[1:])] = self.lds[address]
+                self.pending_ds.add((lane, dest))

P2 Badge Apply pending LDS hazards to all VGPR destination checks

pending_ds is consulted when issuing another DS load, but the destination checks in vector_op, both buffer-load handlers, and RuntimeWave.vector_op still consult only pending_v. Consequently, a ds_read_b32 followed by a buffer_load_dword to the same VGPR before either wait is accepted. After the waits, the model assumes the buffer value even though the asynchronous writes have no established completion order. Extend the destination checks to include pending LDS results so the lowerer rejects this overlap instead of specializing exports or branches using an unproven value.

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4689095372 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2142#discussion_r4689095372). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-25T01:45:12Z. **Code review location:** `tools/mesh_entry_aot.py`; line 442 ~~~~diff @@ -383,7 +399,58 @@ def fp(x): raise ValueError("Pending vector destination") self.v[lane][int(d[1:])] = v & U32 if isinstance(v, int) else v + def lds_op(self, op, tail): + """One dword per live lane at a concrete, aligned, in-range LDS address. + + A load sees only dwords published at an earlier barrier. A wave's own + unpublished store is refused rather than guessed at. + """ + write = op == "ds_write_b32" + match = re.fullmatch(r"(v\d+), (v\d+)(?: offset:(\d+))?", tail) + if not match: + raise ValueError(f"Unsupported {op} operands") + first, second = match[1], match[2] + offset = int(match[3] or 0) + address_reg, data_reg, dest = (first, second, None) if write else (second, None, first) + if offset >= LDS_BYTES: + raise ValueError("LDS offset outside the group allocation") + writes = {} + for lane in range(64): + if not self.exec & (1 << lane): + continue + address = self.lane_value(address_reg, lane) + if type(address) is not int: + raise ValueError("Dynamic LDS address") + address += offset + if address % 4 or not 0 <= address < LDS_BYTES: + raise ValueError("LDS address outside the group allocation or unaligned") + if write: + data = self.lane_value(data_reg, lane) + if type(data) is not int: + raise ValueError("LDS store of a non-integer value") + if writes.setdefault(address, data & U32) != data & U32: + raise ValueError("Lanes store different values to one LDS dword") + else: + if address in self.staged: + raise ValueError("LDS load of this wave's store before a barrier") + if address not in self.lds: + raise ValueError("LDS load of a dword no wave published") + if (lane, dest) in self.pending_v or (lane, dest) in self.pending_ds: + raise ValueError("LDS load overwrites a pending result") + self.reads.add(address) + self.v[lane][int(dest[1:])] = self.lds[address] + self.pending_ds.add((lane, dest)) ~~~~ --- **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Apply pending LDS hazards to all VGPR destination checks** `pending_ds` is consulted when issuing another DS load, but the destination checks in `vector_op`, both buffer-load handlers, and `RuntimeWave.vector_op` still consult only `pending_v`. Consequently, a `ds_read_b32` followed by a `buffer_load_dword` to the same VGPR before either wait is accepted. After the waits, the model assumes the buffer value even though the asynchronous writes have no established completion order. Extend the destination checks to include pending LDS results so the lowerer rejects this overlap instead of specializing exports or branches using an unproven value. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
tedin7 commented 2026-11-25 03:01:03 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T02:19:40Z.

Review: COMMENTED


No description provided.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6050728239 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2142#pullrequestreview-6050728239). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T02:19:40Z. **Review:** COMMENTED --- _No description provided._
tedin7 commented 2026-11-25 03:01:03 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T02:19:41Z.

Review: COMMENTED


No description provided.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6050728635 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2142#pullrequestreview-6050728635). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T02:19:41Z. **Review:** COMMENTED --- _No description provided._
tedin7 commented 2026-11-25 03:01:03 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T02:19:43Z.

Review: COMMENTED


No description provided.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6050729122 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2142#pullrequestreview-6050729122). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T02:19:43Z. **Review:** COMMENTED --- _No description provided._
tedin7 commented 2026-11-25 03:01:26 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T02:19:39Z.

Code review location: tools/mesh_entry_aot.py; line 623

@@ -515,6 +590,40 @@ def run(self, decoded, expressions):
         raise ValueError("No program exit")
 
 
+def run_group(waves, decoded, expressions):
+    """Run the waves of one group in lockstep between barriers.
+
+    Each wave runs to its next barrier before any wave goes on. Stores become
+    visible to every wave only when all of them have reached the barrier.
+    """
+    lds = {}
+    for wave in waves:
+        wave.lds = lds
+    running = [wave.steps(decoded, expressions) for wave in waves]
+    while True:
+        reached = 0
+        for steps in running:
+            try:
+                next(steps)
+                reached += 1
+            except StopIteration:
+                pass
+        if not reached:
+            return
+        if reached != len(waves):
+            raise ValueError("Waves of one group reach different numbers of barriers")
+        published = {}
+        for wave in waves:
+            for address, data in wave.staged.items():
+                if published.setdefault(address, data) != data:
+                    raise ValueError("Waves store different values to one LDS dword")
+        for wave in waves:
+            if wave.reads.intersection(address for other in waves if other is not wave for address in other.staged):
+                raise ValueError("LDS dword read and stored by different waves without a barrier")
+            wave.staged, wave.reads = {}, set()

Fixed in b11224a7: run_group now checks every wave against all staged stores before clearing any (check_interval). Verification: tests/mesh_scc_any_lane_check.py new regression checks fail before and pass after; Linux checks run_checks_parallel 7/7; Win2025 dev and release 15/15 mesh WARP+CPU tests. AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4689431051 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2142#discussion_r4689431051). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T02:19:39Z. **Code review location:** `tools/mesh_entry_aot.py`; line 623 ~~~~diff @@ -515,6 +590,40 @@ def run(self, decoded, expressions): raise ValueError("No program exit") +def run_group(waves, decoded, expressions): + """Run the waves of one group in lockstep between barriers. + + Each wave runs to its next barrier before any wave goes on. Stores become + visible to every wave only when all of them have reached the barrier. + """ + lds = {} + for wave in waves: + wave.lds = lds + running = [wave.steps(decoded, expressions) for wave in waves] + while True: + reached = 0 + for steps in running: + try: + next(steps) + reached += 1 + except StopIteration: + pass + if not reached: + return + if reached != len(waves): + raise ValueError("Waves of one group reach different numbers of barriers") + published = {} + for wave in waves: + for address, data in wave.staged.items(): + if published.setdefault(address, data) != data: + raise ValueError("Waves store different values to one LDS dword") + for wave in waves: + if wave.reads.intersection(address for other in waves if other is not wave for address in other.staged): + raise ValueError("LDS dword read and stored by different waves without a barrier") + wave.staged, wave.reads = {}, set() ~~~~ --- Fixed in b11224a7: run_group now checks every wave against all staged stores before clearing any (check_interval). Verification: tests/mesh_scc_any_lane_check.py new regression checks fail before and pass after; Linux checks run_checks_parallel 7/7; Win2025 dev and release 15/15 mesh WARP+CPU tests. AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-25 03:01:26 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T02:19:41Z.

Code review location: tools/mesh_entry_aot.py; line 612

@@ -515,6 +590,40 @@ def run(self, decoded, expressions):
         raise ValueError("No program exit")
 
 
+def run_group(waves, decoded, expressions):
+    """Run the waves of one group in lockstep between barriers.
+
+    Each wave runs to its next barrier before any wave goes on. Stores become
+    visible to every wave only when all of them have reached the barrier.
+    """
+    lds = {}
+    for wave in waves:
+        wave.lds = lds
+    running = [wave.steps(decoded, expressions) for wave in waves]
+    while True:
+        reached = 0
+        for steps in running:
+            try:
+                next(steps)
+                reached += 1
+            except StopIteration:
+                pass
+        if not reached:
+            return

Fixed in b11224a7: the final interval goes through the same check_interval before run_group returns. Verification: tests/mesh_scc_any_lane_check.py new regression checks fail before and pass after; Linux checks run_checks_parallel 7/7; Win2025 dev and release 15/15 mesh WARP+CPU tests. AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4689431350 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2142#discussion_r4689431350). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T02:19:41Z. **Code review location:** `tools/mesh_entry_aot.py`; line 612 ~~~~diff @@ -515,6 +590,40 @@ def run(self, decoded, expressions): raise ValueError("No program exit") +def run_group(waves, decoded, expressions): + """Run the waves of one group in lockstep between barriers. + + Each wave runs to its next barrier before any wave goes on. Stores become + visible to every wave only when all of them have reached the barrier. + """ + lds = {} + for wave in waves: + wave.lds = lds + running = [wave.steps(decoded, expressions) for wave in waves] + while True: + reached = 0 + for steps in running: + try: + next(steps) + reached += 1 + except StopIteration: + pass + if not reached: + return ~~~~ --- Fixed in b11224a7: the final interval goes through the same check_interval before run_group returns. Verification: tests/mesh_scc_any_lane_check.py new regression checks fail before and pass after; Linux checks run_checks_parallel 7/7; Win2025 dev and release 15/15 mesh WARP+CPU tests. AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-25 03:01:26 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T02:19:43Z.

Code review location: tools/mesh_entry_aot.py; line 442

@@ -383,7 +399,58 @@ def fp(x):
                 raise ValueError("Pending vector destination")
             self.v[lane][int(d[1:])] = v & U32 if isinstance(v, int) else v
 
+    def lds_op(self, op, tail):
+        """One dword per live lane at a concrete, aligned, in-range LDS address.
+
+        A load sees only dwords published at an earlier barrier. A wave's own
+        unpublished store is refused rather than guessed at.
+        """
+        write = op == "ds_write_b32"
+        match = re.fullmatch(r"(v\d+), (v\d+)(?: offset:(\d+))?", tail)
+        if not match:
+            raise ValueError(f"Unsupported {op} operands")
+        first, second = match[1], match[2]
+        offset = int(match[3] or 0)
+        address_reg, data_reg, dest = (first, second, None) if write else (second, None, first)
+        if offset >= LDS_BYTES:
+            raise ValueError("LDS offset outside the group allocation")
+        writes = {}
+        for lane in range(64):
+            if not self.exec & (1 << lane):
+                continue
+            address = self.lane_value(address_reg, lane)
+            if type(address) is not int:
+                raise ValueError("Dynamic LDS address")
+            address += offset
+            if address % 4 or not 0 <= address < LDS_BYTES:
+                raise ValueError("LDS address outside the group allocation or unaligned")
+            if write:
+                data = self.lane_value(data_reg, lane)
+                if type(data) is not int:
+                    raise ValueError("LDS store of a non-integer value")
+                if writes.setdefault(address, data & U32) != data & U32:
+                    raise ValueError("Lanes store different values to one LDS dword")
+            else:
+                if address in self.staged:
+                    raise ValueError("LDS load of this wave's store before a barrier")
+                if address not in self.lds:
+                    raise ValueError("LDS load of a dword no wave published")
+                if (lane, dest) in self.pending_v or (lane, dest) in self.pending_ds:
+                    raise ValueError("LDS load overwrites a pending result")
+                self.reads.add(address)
+                self.v[lane][int(dest[1:])] = self.lds[address]
+                self.pending_ds.add((lane, dest))

Fixed in b11224a7: vector_pending (pending_v or pending_ds) now guards ALU and buffer-load destinations in mesh_entry_aot and RuntimeWave. Verification: tests/mesh_scc_any_lane_check.py new regression checks fail before and pass after; Linux checks run_checks_parallel 7/7; Win2025 dev and release 15/15 mesh WARP+CPU tests. AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4689431681 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2142#discussion_r4689431681). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T02:19:43Z. **Code review location:** `tools/mesh_entry_aot.py`; line 442 ~~~~diff @@ -383,7 +399,58 @@ def fp(x): raise ValueError("Pending vector destination") self.v[lane][int(d[1:])] = v & U32 if isinstance(v, int) else v + def lds_op(self, op, tail): + """One dword per live lane at a concrete, aligned, in-range LDS address. + + A load sees only dwords published at an earlier barrier. A wave's own + unpublished store is refused rather than guessed at. + """ + write = op == "ds_write_b32" + match = re.fullmatch(r"(v\d+), (v\d+)(?: offset:(\d+))?", tail) + if not match: + raise ValueError(f"Unsupported {op} operands") + first, second = match[1], match[2] + offset = int(match[3] or 0) + address_reg, data_reg, dest = (first, second, None) if write else (second, None, first) + if offset >= LDS_BYTES: + raise ValueError("LDS offset outside the group allocation") + writes = {} + for lane in range(64): + if not self.exec & (1 << lane): + continue + address = self.lane_value(address_reg, lane) + if type(address) is not int: + raise ValueError("Dynamic LDS address") + address += offset + if address % 4 or not 0 <= address < LDS_BYTES: + raise ValueError("LDS address outside the group allocation or unaligned") + if write: + data = self.lane_value(data_reg, lane) + if type(data) is not int: + raise ValueError("LDS store of a non-integer value") + if writes.setdefault(address, data & U32) != data & U32: + raise ValueError("Lanes store different values to one LDS dword") + else: + if address in self.staged: + raise ValueError("LDS load of this wave's store before a barrier") + if address not in self.lds: + raise ValueError("LDS load of a dword no wave published") + if (lane, dest) in self.pending_v or (lane, dest) in self.pending_ds: + raise ValueError("LDS load overwrites a pending result") + self.reads.add(address) + self.v[lane][int(dest[1:])] = self.lds[address] + self.pending_ds.add((lane, dest)) ~~~~ --- Fixed in b11224a7: vector_pending (pending_v or pending_ds) now guards ALU and buffer-load destinations in mesh_entry_aot and RuntimeWave. Verification: tests/mesh_scc_any_lane_check.py new regression checks fail before and pass after; Linux checks run_checks_parallel 7/7; Win2025 dev and release 15/15 mesh WARP+CPU tests. AI-assisted; commands listed were executed locally.
thepatrickworld commented 2026-11-25 04:04:19 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by thepatrickworld on 2026-11-25T03:42:07Z.


Draw run on hardware — RX 9070 XT, driver 32.0.32029.2010:

mesh_pipeline_ms=0.167
pixels=1024 mismatches=0     (six times, one per threshold)
mutant: own flag only / flipped branch / 32-bit mask compare

The six thresholds each draw the full quad when a wave has a live lane, and all 1024 pixels match; the three mutants are rejected, so the check separates the any-lane flag from a per-lane one.

Limits: AMD only, no NVIDIA; mesh pipelines are the one path WARP does not implement, so there is no second adapter to compare against here.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7152162458 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2142#issuecomment-7152162458). Originally posted by [thepatrickworld](https://github.com/thepatrickworld) on 2026-11-25T03:42:07Z. --- Draw run on hardware — RX 9070 XT, driver 32.0.32029.2010: ``` mesh_pipeline_ms=0.167 pixels=1024 mismatches=0 (six times, one per threshold) mutant: own flag only / flipped branch / 32-bit mask compare ``` The six thresholds each draw the full quad when a wave has a live lane, and all 1024 pixels match; the three mutants are rejected, so the check separates the any-lane flag from a per-lane one. Limits: AMD only, no NVIDIA; mesh pipelines are the one path WARP does not implement, so there is no second adapter to compare against here. _AI-assisted._
R0Y00 commented 2026-11-25 08:05:05 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-25T07:50:51Z.


I replayed the same 32 local mesh-stage samples through lower() on main e94e14ff and this head 8b77c25f. The comparison used the bounded two-wave evaluator with identical synthetic geometry inputs. Branch displacements were decoded as signed instruction immediates and checked against their byte targets. Main stopped at s_cbranch_scc1 in all 32. This head reached the LDS store on the wave-zero path and stopped at s_waitcnt_depctr in all 32. No complete shader or pixel result is claimed.

The shared pattern is a single-lane LDS store in one wave and a read in another, with distinct static barrier instructions on the two branches. This makes the existing cross-wave LDS scheduling valuable to the slot 57 follow-up. A source-built control for the observed dependency-counter wait and barrier pair would test the next step without adding a broad wait-as-no-op fallback. Runtime tracking

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7156318447 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2142#issuecomment-7156318447). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-25T07:50:51Z. --- I replayed the same 32 local mesh-stage samples through `lower()` on main `e94e14ff` and this head `8b77c25f`. The comparison used the bounded two-wave evaluator with identical synthetic geometry inputs. Branch displacements were decoded as signed instruction immediates and checked against their byte targets. Main stopped at `s_cbranch_scc1` in all 32. This head reached the LDS store on the wave-zero path and stopped at `s_waitcnt_depctr` in all 32. No complete shader or pixel result is claimed. The shared pattern is a single-lane LDS store in one wave and a read in another, with distinct static barrier instructions on the two branches. This makes the existing cross-wave LDS scheduling valuable to the slot 57 follow-up. A source-built control for the observed dependency-counter wait and barrier pair would test the next step without adding a broad wait-as-no-op fallback. [Runtime tracking](https://github.com/R0Y00/Xbox2Windows/issues/870#issuecomment-7156155480)
upstream-sync closed this pull request 2026-11-25 09:03:55 +00:00
R0Y00 commented 2026-11-25 09:04:12 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-25T08:18:04Z.


Follow-up to the two-wave LDS review above. I published the wait and barrier follow-up on an integration branch with #2253 and both commits from this PR, preserving their authorship. The follow-up depends on both PRs and main's retired-wave handling from #2241.

For gfx1013, s_waitcnt_depctr 0xffe3 retires the tracked VM_VSRC source-register dependency. The model continues to track LDS completion with lgkmcnt(0) and publishes only when live waves reach the same barrier. The source-built two-wave control reads the original stored word after the producer overwrites the source register. The controls for an absent dependency wait, a different immediate, missing store and load completion waits, and different static barrier instructions each refuse. RDNA 2 ISA §§4.3, 4.4, 12.5

python -B tests/mesh_scc_any_lane_check.py, python -B tests/mesh_dynamic_geometry_check.py, python -B tests/mesh_dynamic_aot_check.py, and python -B tests/startup_gfx2hlsl_watch_check.py passed. The 19-instruction source-built control decoded identically in the checked-in decoder and the LLVM 15 disassembler. The translated draw control (python -B tests/mesh_scc_any_lane_draw_check.py <dxc> <offscreen_check> <warp|hardware>) matched 1,024/1,024 pixels on WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656 under Windows 11 build 26200.9974, with no D3D12 debug errors or warnings.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7156856136 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2142#issuecomment-7156856136). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-25T08:18:04Z. --- Follow-up to the two-wave LDS review above. I published [the wait and barrier follow-up](https://github.com/R0Y00/Xbox2Windows/commit/f8da4cf7fa6521db4ad85e991497f1d602bef4a0) on an [integration branch](https://github.com/R0Y00/Xbox2Windows/tree/codex/startup-mesh-lds-integration) with #2253 and both commits from this PR, preserving their authorship. The follow-up depends on both PRs and main's retired-wave handling from #2241. For gfx1013, `s_waitcnt_depctr 0xffe3` retires the tracked VM_VSRC source-register dependency. The model continues to track LDS completion with `lgkmcnt(0)` and publishes only when live waves reach the same barrier. The source-built two-wave control reads the original stored word after the producer overwrites the source register. The controls for an absent dependency wait, a different immediate, missing store and load completion waits, and different static barrier instructions each refuse. [RDNA 2 ISA §§4.3, 4.4, 12.5](https://www.amd.com/content/dam/amd/en/documents/radeon-tech-docs/instruction-set-architectures/rdna2-shader-instruction-set-architecture.pdf) `python -B tests/mesh_scc_any_lane_check.py`, `python -B tests/mesh_dynamic_geometry_check.py`, `python -B tests/mesh_dynamic_aot_check.py`, and `python -B tests/startup_gfx2hlsl_watch_check.py` passed. The 19-instruction source-built control decoded identically in the checked-in decoder and the LLVM 15 disassembler. The translated draw control (`python -B tests/mesh_scc_any_lane_draw_check.py <dxc> <offscreen_check> <warp|hardware>`) matched 1,024/1,024 pixels on WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656 under Windows 11 build 26200.9974, with no D3D12 debug errors or warnings.
R0Y00 commented 2026-11-25 09:04:12 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-25T08:27:58Z.


I merged main into the PR branch at 59a1189c. The CMake conflict now retains both the SCC any-lane tests and #2244's two-exit tests. Six host-side suites passed. With the D3D12 debug layer enabled, WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656 each matched all 1,024 pixels at all six thresholds and detected the three mutations. This verifies the existing SCC fixture. The dependent wait/barrier follow-up linked above still has its own acceptance checks.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7157058361 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2142#issuecomment-7157058361). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-25T08:27:58Z. --- I merged main into the PR branch at `59a1189c`. The CMake conflict now retains both the SCC any-lane tests and #2244's two-exit tests. Six host-side suites passed. With the D3D12 debug layer enabled, WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656 each matched all 1,024 pixels at all six thresholds and detected the three mutations. This verifies the existing SCC fixture. The dependent wait/barrier follow-up linked above still has its own acceptance checks.
thepatrickworld commented 2026-11-25 11:02:36 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by thepatrickworld on 2026-11-25T11:02:27Z.


Correction on the timing line: mesh_pipeline_ms=0.167 was the last of six values, not a representative one.

The six lines in drawc2142.log are 30.636, 0.197, 0.195, 0.169, 12.400, 0.167. Quoting only the smallest makes the dispatch look uniform across the six thresholds when it is not — the two large values are presumably cold starts, but the log does not label the thresholds, so I cannot say which is which.

Everything else in the comment (1024 pixels, mismatches=0 six times) is as written.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7160506843 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2142#issuecomment-7160506843). Originally posted by [thepatrickworld](https://github.com/thepatrickworld) on 2026-11-25T11:02:27Z. --- Correction on the timing line: `mesh_pipeline_ms=0.167` was the **last** of six values, not a representative one. The six lines in `drawc2142.log` are `30.636`, `0.197`, `0.195`, `0.169`, `12.400`, `0.167`. Quoting only the smallest makes the dispatch look uniform across the six thresholds when it is not — the two large values are presumably cold starts, but the log does not label the thresholds, so I cannot say which is which. Everything else in the comment (1024 pixels, `mismatches=0` six times) is as written. _AI-assisted._
thepatrickworld commented 2026-11-25 12:01:53 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by thepatrickworld on 2026-11-25T11:16:22Z.


Two corrections to the verdict lines of my comment above.

  1. "The three mutants are rejected" is not in the log. It prints the three names — own flag only, flipped branch, 32-bit mask compare — and nothing about their outcome. That they are rejected is what the fixture is supposed to establish, not what the run reported, and I should not have written it as an observation.

  2. "Mesh pipelines are the one path WARP does not implement" — I have no WARP run for this PR, so I cannot say that. It may be true of the platform, but it is not something this run showed.

What stands: six thresholds, pixels=1024 mismatches=0 each time, and the timing range I corrected in the previous comment.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7160825755 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2142#issuecomment-7160825755). Originally posted by [thepatrickworld](https://github.com/thepatrickworld) on 2026-11-25T11:16:22Z. --- Two corrections to the verdict lines of my comment above. 1. "The three mutants are rejected" is not in the log. It prints the three names — `own flag only`, `flipped branch`, `32-bit mask compare` — and nothing about their outcome. That they are rejected is what the fixture is supposed to establish, not what the run reported, and I should not have written it as an observation. 2. "Mesh pipelines are the one path WARP does not implement" — I have no WARP run for this PR, so I cannot say that. It may be true of the platform, but it is not something this run showed. What stands: six thresholds, `pixels=1024 mismatches=0` each time, and the timing range I corrected in the previous comment. _AI-assisted._
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!2134
No description provided.