reprend #2183: loop guard: one total of loop visits per invocation, on top of each loop's limit (SHADER-LOOP-TOTAL) #2736

Closed
OreoFR wants to merge 4 commits from upstream-pr/2736 into main
OreoFR commented 2026-11-30 13:39:28 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-30T13:39:28Z.


Carries #2183 by @QemmHD, because it conflicts with main after #2566 and the reminder to merge main (https://github.com/ProjectLeonida/mandy/pull/2183#issuecomment-7250891782) got no answer within the delay of the carry rule. If the author comes back, this carry is dropped.

Item: SHADER-LOOP-TOTAL-CARRY (claimed in https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7280119323; original item SHADER-LOOP-TOTAL).

What this branch is

  • The author's branch at 88abd1609, unchanged (no rebase, author commits kept).
  • A merge of main (from the carry preparation of 29/11) that resolves the conflict, then a merge of current main f9f3ec4c6 (no new conflict). Both merge commits carry Co-authored-by the author.
  • Nothing else: the change itself is the original PR's; see #2183 for what and why, and the verifications posted there.

What conflicted and how it was resolved

  • tools/spirv_loop_guard.py (2 hunks): the PR's TypePointer|EntryPoint added to main's CRLF-safe regex; main's bool/int check on limit applied to total too.

Open question for a human: tests/semantic/test_wave64_single_wave_barrier.py (a main test, a02a5ef7a) fails on this branch: it requires that a barrier inside a loop depends only on %pc, and the PR adds %loop_guard_total to the loop's exit condition. Is that safe for a barrier under emulated wave64, and should such loops be left out of the total or the test widened? Not decided here. The concern djrolfes raised and qhukz13 reproduced on #2183 (scheduler barrier) is the same area.

Tests

  • On this branch (main f9f3ec4c6 merged), Windows 11, Python 3.12, no GPU used: tests/semantic/test_loop_iteration_guard.py: 6 OK; tests/test_spirv_loop_guard.py: 9 OK; tests/semantic/test_wave64_single_wave_barrier.py: 1 failure (see above).
  • Earlier merge: red: test_loop_iteration_guard 2 errors; full semantic suite 529 files / 6527 tests, 3 failures = main's 2 + test_wave64_single_wave_barrier.
  • python -I scripts/check_no_game_data.py on every file this PR changes: clean.
  • CI on this PR covers the rest (C++ build and ctest, the full translator suite).

Depends on: none.

Needs a careful human read of the resolution and an independent verifier before merge (red/green on another machine).

AI-assisted (Claude Code, oreofr-agent).

🤖 Generated with Claude Code

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5566391309 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2736). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-30T13:39:28Z. --- Carries #2183 by @QemmHD, because it conflicts with `main` after #2566 and the reminder to merge `main` (https://github.com/ProjectLeonida/mandy/pull/2183#issuecomment-7250891782) got no answer within the delay of the carry rule. If the author comes back, this carry is dropped. Item: `SHADER-LOOP-TOTAL-CARRY` (claimed in https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7280119323; original item `SHADER-LOOP-TOTAL`). ### What this branch is - The author's branch at `88abd1609`, unchanged (no rebase, author commits kept). - A merge of `main` (from the carry preparation of 29/11) that resolves the conflict, then a merge of current `main` `f9f3ec4c6` (no new conflict). Both merge commits carry `Co-authored-by` the author. - Nothing else: the change itself is the original PR's; see #2183 for what and why, and the verifications posted there. ### What conflicted and how it was resolved - `tools/spirv_loop_guard.py` (2 hunks): the PR's `TypePointer|EntryPoint` added to `main`'s CRLF-safe regex; `main`'s bool/int check on `limit` applied to `total` too. **Open question for a human:** `tests/semantic/test_wave64_single_wave_barrier.py` (a `main` test, a02a5ef7a) fails on this branch: it requires that a barrier inside a loop depends only on `%pc`, and the PR adds `%loop_guard_total` to the loop's exit condition. Is that safe for a barrier under emulated wave64, and should such loops be left out of the total or the test widened? Not decided here. The concern djrolfes raised and qhukz13 reproduced on #2183 (scheduler barrier) is the same area. ### Tests - On this branch (`main` `f9f3ec4c6` merged), Windows 11, Python 3.12, no GPU used: `tests/semantic/test_loop_iteration_guard.py`: 6 OK; `tests/test_spirv_loop_guard.py`: 9 OK; `tests/semantic/test_wave64_single_wave_barrier.py`: **1 failure** (see above). - Earlier merge: red: `test_loop_iteration_guard` 2 errors; full semantic suite 529 files / 6527 tests, 3 failures = `main`'s 2 + `test_wave64_single_wave_barrier`. - `python -I scripts/check_no_game_data.py` on every file this PR changes: clean. - CI on this PR covers the rest (C++ build and `ctest`, the full translator suite). Depends on: none. **Needs a careful human read of the resolution and an independent verifier before merge** (red/green on another machine). AI-assisted (Claude Code, oreofr-agent). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
OreoFR commented 2026-11-30 13:46:14 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-30T13:46:14Z.


Verified by OreoFR on macOS 27.2.1, Apple M5, Python 3.12.16 (pytest, no GPU), main f9f3ec4c6.

  • MEASURED, red (main + only this PR's tests): test_loop_iteration_guard.py: 1 failed, 4 passed. test_control_flow_branches.py (33), test_loop_ballot_barrier.py (15) and test_wave64_emulate_opt.py (34) pass on both sides.
  • MEASURED, green (main + merge --no-ff of 528e65eb4): test_loop_iteration_guard.py 6 passed; the other three unchanged and passing.
  • MEASURED, still red with this PR: tests/semantic/test_wave64_single_wave_barrier.py: 1 failed, 2 passed. The failure is AssertionError: {'%loop_guard_total', '%pc'} not less than or equal to {'%pc'} (line 103).
  • MEASURED: the same file on plain main f9f3ec4c6 passes (3 passed), so this PR is what turns it red. That matches the open question in the PR description.
  • Verdict: not green. 1 file regresses, and it waits on the human decision the description asks for (leave such loops out of the total, or widen the test).
  • Not covered: the C++ build, ctest and the rest of the suite (CI).

Not independent: this PR and this check share the same owner (OreoFR). Treat it as a second-machine run, not an independent review.

AI-assisted: Claude Code

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7280330149 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2736#issuecomment-7280330149). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-30T13:46:14Z. --- Verified by OreoFR on macOS 27.2.1, Apple M5, Python 3.12.16 (pytest, no GPU), `main` `f9f3ec4c6`. - MEASURED, red (`main` + only this PR's tests): `test_loop_iteration_guard.py`: 1 failed, 4 passed. `test_control_flow_branches.py` (33), `test_loop_ballot_barrier.py` (15) and `test_wave64_emulate_opt.py` (34) pass on both sides. - MEASURED, green (`main` + `merge --no-ff` of `528e65eb4`): `test_loop_iteration_guard.py` 6 passed; the other three unchanged and passing. - MEASURED, **still red with this PR:** `tests/semantic/test_wave64_single_wave_barrier.py`: 1 failed, 2 passed. The failure is `AssertionError: {'%loop_guard_total', '%pc'} not less than or equal to {'%pc'}` (line 103). - MEASURED: the same file on plain `main` `f9f3ec4c6` passes (3 passed), so this PR is what turns it red. That matches the open question in the PR description. - Verdict: **not green.** 1 file regresses, and it waits on the human decision the description asks for (leave such loops out of the total, or widen the test). - Not covered: the C++ build, `ctest` and the rest of the suite (CI). **Not independent:** this PR and this check share the same owner (OreoFR). Treat it as a second-machine run, not an independent review. AI-assisted: Claude Code
merzleckeier commented 2026-11-30 14:07:39 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by merzleckeier on 2026-11-30T14:07:39Z.


Independent dynamic barrier counterexample on the carry. 528e65eb merged onto main f44904d2 (tree 90f7d91c). CachyOS x86-64, Python 3.14.10, SPIRV-Tools 2026.4. CPU interpretation of synthetic programs only.

MEASURED. I translated the checked-in BarrierInLoopsTests._wave_divergent_barrier_loop_cs(True) fixture as a 128-invocation compute workgroup on 32-lane subgroups (emulate=True, structured=False, per-loop limit 64). The translated form is emulated wave64 rounds.

Loop guard CPU workgroup result
main per-loop only Completed, readback 2 on lanes 0–63 and 4 on lanes 64–127
PR, aggregate limit 0 Completed with the same readback
PR, aggregate limit 16 64/128 invocations arrived (64 already returned) at OpControlBarrier
PR, aggregate limit 16 except at the outer %loop_head Completed with the same readback, aggregate guard still present on the inner chain loop

A separate 64-invocation SPIR-V fixture has a finite first loop taking 1 or 3 iterations and then a shared loop with three workgroup barriers. At aggregate limit 4, only 32 invocations reach the third barrier. Main and a test-only control that leaves the aggregate check off that specific barrier loop complete with all 64 reaching all three barriers. All 10 generated modules pass spirv-val --target-env vulkan1.2. The execution requirement is stated in the SPIR-V specification for OpControlBarrier.

Five stock test modules gave 65/65 on main and 66/67 on the PR. The sole stock failure is the separate single-wave %pc guard assertion. The dynamic failure above uses the real round scheduler and deliberately small test budgets. A second agent recomputed the results from the modules. AI-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7280876417 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2736#issuecomment-7280876417). Originally posted by [merzleckeier](https://github.com/merzleckeier) on 2026-11-30T14:07:39Z. --- **Independent dynamic barrier counterexample on the carry.** `528e65eb` merged onto `main` `f44904d2` (tree `90f7d91c`). CachyOS x86-64, Python 3.14.10, SPIRV-Tools 2026.4. CPU interpretation of synthetic programs only. **MEASURED.** I translated the checked-in `BarrierInLoopsTests._wave_divergent_barrier_loop_cs(True)` fixture as a 128-invocation compute workgroup on 32-lane subgroups (`emulate=True`, `structured=False`, per-loop limit 64). The translated form is `emulated wave64 rounds`. | Loop guard | CPU workgroup result | | --- | --- | | `main` per-loop only | Completed, readback 2 on lanes 0–63 and 4 on lanes 64–127 | | PR, aggregate limit 0 | Completed with the same readback | | PR, aggregate limit 16 | `64/128 invocations arrived (64 already returned)` at `OpControlBarrier` | | PR, aggregate limit 16 except at the outer `%loop_head` | Completed with the same readback, aggregate guard still present on the inner chain loop | A separate 64-invocation SPIR-V fixture has a finite first loop taking 1 or 3 iterations and then a shared loop with three workgroup barriers. At aggregate limit 4, only 32 invocations reach the third barrier. Main and a test-only control that leaves the aggregate check off that specific barrier loop complete with all 64 reaching all three barriers. All 10 generated modules pass `spirv-val --target-env vulkan1.2`. The execution requirement is stated in the [SPIR-V specification for `OpControlBarrier`](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#OpControlBarrier). Five stock test modules gave 65/65 on main and 66/67 on the PR. The sole stock failure is the separate single-wave `%pc` guard assertion. The dynamic failure above uses the real round scheduler and deliberately small test budgets. A second agent recomputed the results from the modules. AI-assisted.
merzleckeier commented 2026-11-30 15:29:01 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by merzleckeier on 2026-11-30T15:29:01Z.


Wave64 barrier follow-up on 083c011a9

I reran the two-wave fixture with 083c011a9 merged onto main be769080 (tree b8158809). The new revision updates the single-wave assertion to allow the aggregate guard. The preceding PR revision and this one have the same tools/ tree when merged onto that base.

MEASURED. All five targeted suites pass (66 tests on main, 68 on the merge tree, including three single-wave tests on each). For the two-wave case, I used the repository's synthetic BarrierInLoopsTests._wave_divergent_barrier_loop_cs(True) fixture with 128 invocations, 32-lane subgroups, emulate=True, structured=False, and a per-loop limit of 64. Execution used the CPU interpreter.

Aggregate budget Result on the merge tree
0 (disabled) 64 outputs of 2 followed by 64 outputs of 4, matching main
12 The first 64 outputs are 2. The other 64 are unwritten.
16 Non-uniform OpControlBarrier: 64/128 invocations arrived (64 already returned)
24 All 128 outputs match main.

The budget-16 assembly is byte-identical to the earlier report. In a test-only control, I exempted just the %loop_head scheduler back edge from the aggregate budget. The per-loop limit and the inner loop's aggregate check still apply. That restores all 128 outputs at budgets 12 and 16 for this fixture. All seven modules pass spirv-val --target-env vulkan1.2. An independent CPU replay of the assemblies confirmed the outcomes with both subgroup scheduling orders.

The results show the scheduler's aggregate exit can diverge at a caller-selected budget even with the updated single-wave check. Earlier report

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7283071536 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2736#issuecomment-7283071536). Originally posted by [merzleckeier](https://github.com/merzleckeier) on 2026-11-30T15:29:01Z. --- # Wave64 barrier follow-up on 083c011a9 I reran the two-wave fixture with `083c011a9` merged onto `main` `be769080` (tree `b8158809`). The new revision updates the single-wave assertion to allow the aggregate guard. The preceding PR revision and this one have the same `tools/` tree when merged onto that base. **MEASURED.** All five targeted suites pass (66 tests on `main`, 68 on the merge tree, including three single-wave tests on each). For the two-wave case, I used the repository's synthetic `BarrierInLoopsTests._wave_divergent_barrier_loop_cs(True)` fixture with 128 invocations, 32-lane subgroups, `emulate=True`, `structured=False`, and a per-loop limit of 64. Execution used the CPU interpreter. | Aggregate budget | Result on the merge tree | | --- | --- | | 0 (disabled) | 64 outputs of 2 followed by 64 outputs of 4, matching `main` | | 12 | The first 64 outputs are 2. The other 64 are unwritten. | | 16 | `Non-uniform OpControlBarrier: 64/128 invocations arrived (64 already returned)` | | 24 | All 128 outputs match `main`. | The budget-16 assembly is byte-identical to the earlier report. In a test-only control, I exempted just the `%loop_head` scheduler back edge from the aggregate budget. The per-loop limit and the inner loop's aggregate check still apply. That restores all 128 outputs at budgets 12 and 16 for this fixture. All seven modules pass `spirv-val --target-env vulkan1.2`. An independent CPU replay of the assemblies confirmed the outcomes with both subgroup scheduling orders. The results show the scheduler's aggregate exit can diverge at a caller-selected budget even with the updated single-wave check. [Earlier report](https://github.com/ProjectLeonida/mandy/pull/2736#issuecomment-7280876417)
KelboLive commented 2026-11-30 15:35:36 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by KelboLive on 2026-11-30T15:35:36Z.


Full-suite failure on Windows at 528e65eb4: the branch is red against main in an existing test.

python -I -m unittest discover -s tests/semantic -p test_wave64_single_wave_barrier.py
...
FAIL: test_single_wave_stays_structured_with_pc_only_guards
  File "tests/semantic/test_wave64_single_wave_barrier.py", line 103, in test_single_wave_stays_structured_with_pc_only_guards
    self.assertLessEqual(loaded, {"%pc"})
AssertionError: {'%pc', '%loop_guard_total'} not less than or equal to {'%pc'}
Ran 3 tests: FAILED (failures=1)
  • Same command on main b17b22d33: 3 tests OK.
  • The branch is green on its own targeted files (test_loop_iteration_guard, test_loop_ballot_barrier, test_control_flow_branches, test_wave64_emulate_opt), so this is an expectation the new %loop_guard_total state invalidates in a file the PR does not touch.
  • The full 549-file suite stops on it as FAILED: test_wave64_single_wave_barrier (exit code 1).

Either the test needs %loop_guard_total allowed in that load set (if loading it in a single-wave shader is intended), or the translator should not emit that load for the PC-only-guard case. As-is, CI's semantic job should be red for this head.

AI-assisted: yes (opencode).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7283248915 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2736#issuecomment-7283248915). Originally posted by [KelboLive](https://github.com/KelboLive) on 2026-11-30T15:35:36Z. --- **Full-suite failure on Windows** at `528e65eb4`: the branch is red against `main` in an existing test. ``` python -I -m unittest discover -s tests/semantic -p test_wave64_single_wave_barrier.py ... FAIL: test_single_wave_stays_structured_with_pc_only_guards File "tests/semantic/test_wave64_single_wave_barrier.py", line 103, in test_single_wave_stays_structured_with_pc_only_guards self.assertLessEqual(loaded, {"%pc"}) AssertionError: {'%pc', '%loop_guard_total'} not less than or equal to {'%pc'} Ran 3 tests: FAILED (failures=1) ``` - Same command on `main` `b17b22d33`: **3 tests OK**. - The branch is green on its own targeted files (`test_loop_iteration_guard`, `test_loop_ballot_barrier`, `test_control_flow_branches`, `test_wave64_emulate_opt`), so this is an expectation the new `%loop_guard_total` state invalidates in a file the PR does not touch. - The full 549-file suite stops on it as `FAILED: test_wave64_single_wave_barrier (exit code 1)`. Either the test needs `%loop_guard_total` allowed in that load set (if loading it in a single-wave shader is intended), or the translator should not emit that load for the PC-only-guard case. As-is, CI's semantic job should be red for this head. AI-assisted: yes (opencode).
KelboLive commented 2026-11-30 15:39:25 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by KelboLive on 2026-11-30T15:39:25Z.


Full-run summary for the failure above: *549 files, 6,677 tests, 1 file failed — \ est_wave64_single_wave_barrier* (448 s, -j 16). Every other file passes.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7283356527 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2736#issuecomment-7283356527). Originally posted by [KelboLive](https://github.com/KelboLive) on 2026-11-30T15:39:25Z. --- Full-run summary for the failure above: **549 files, 6,677 tests, 1 file failed — \ est_wave64_single_wave_barrier\** (448 s, \-j 16\). Every other file passes.
KelboLive commented 2026-11-30 15:44:16 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by KelboLive on 2026-11-30T15:44:16Z.


Suggested resolution: the new %loop_guard_total is a Private per-invocation value (uniform across the wave), so the barrier guards are still uniform — the test's set is what needs widening, not the translator. One-line change in tests/semantic/test_wave64_single_wave_barrier.py:

# The invocation-wide loop total is uniform (a Private variable), so it may appear in a barrier guard.
self.assertLessEqual(loaded, {"%pc", "%loop_guard_total"})

That keeps the property the test is about (no lane-varying value in a barrier guard) while accepting the new guard. The full suite then needs a rerun to confirm nothing else asserts the old set.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7283495825 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2736#issuecomment-7283495825). Originally posted by [KelboLive](https://github.com/KelboLive) on 2026-11-30T15:44:16Z. --- Suggested resolution: the new `%loop_guard_total` is a Private per-invocation value (uniform across the wave), so the barrier guards are still uniform — the test's set is what needs widening, not the translator. One-line change in `tests/semantic/test_wave64_single_wave_barrier.py`: ```python # The invocation-wide loop total is uniform (a Private variable), so it may appear in a barrier guard. self.assertLessEqual(loaded, {"%pc", "%loop_guard_total"}) ``` That keeps the property the test is about (no lane-varying value in a barrier guard) while accepting the new guard. The full suite then needs a rerun to confirm nothing else asserts the old set.
KelboLive commented 2026-11-30 15:50:49 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by KelboLive on 2026-11-30T15:50:49Z.


Applied the one-line change locally on top of 528e65eb4 (not pushed) and re-ran:

  • test_wave64_single_wave_barrier.py: 3 tests OK.
  • Full suite: 549 files, 6,677 tests, 0 files failed in 350 s with -j 24.

So the widened set is the only blocker on this machine; no other test depends on the old assertion. The exact change I applied:

            # The invocation-wide loop total is uniform (a Private variable), so it may appear in a barrier guard.
            self.assertLessEqual(loaded, {"%pc", "%loop_guard_total"})

AI-assisted: yes (opencode).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7283691950 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2736#issuecomment-7283691950). Originally posted by [KelboLive](https://github.com/KelboLive) on 2026-11-30T15:50:49Z. --- Applied the one-line change locally on top of `528e65eb4` (not pushed) and re-ran: - `test_wave64_single_wave_barrier.py`: **3 tests OK**. - Full suite: **549 files, 6,677 tests, 0 files failed** in 350 s with `-j 24`. So the widened set is the only blocker on this machine; no other test depends on the old assertion. The exact change I applied: ```python # The invocation-wide loop total is uniform (a Private variable), so it may appear in a barrier guard. self.assertLessEqual(loaded, {"%pc", "%loop_guard_total"}) ``` AI-assisted: yes (opencode).
KelboLive commented 2026-11-30 17:43:43 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by KelboLive on 2026-11-30T17:43:43Z.


Confirmed on the updated head 083c011a9:

  • test_wave64_single_wave_barrier.py: 3/3 OK (the new test comment covers the uniform loop-total guard).
  • Full suite: 549 files, 6,677 tests, 0 files failed in 393 s with -j 32.

The regression from the earlier head is resolved on Windows. Environment: Ryzen 9 7950X3D, Windows 11 Pro 10.0.26200.9711, Python 3.12.10, llvm-mc 21.1.8.

AI-assisted: yes (opencode).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7286755297 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2736#issuecomment-7286755297). Originally posted by [KelboLive](https://github.com/KelboLive) on 2026-11-30T17:43:43Z. --- Confirmed on the updated head `083c011a9`: - `test_wave64_single_wave_barrier.py`: **3/3 OK** (the new test comment covers the uniform loop-total guard). - Full suite: **549 files, 6,677 tests, 0 files failed** in 393 s with `-j 32`. The regression from the earlier head is resolved on Windows. Environment: Ryzen 9 7950X3D, Windows 11 Pro 10.0.26200.9711, Python 3.12.10, llvm-mc 21.1.8. AI-assisted: yes (opencode).
aslan2142 commented 2026-12-01 11:49:21 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T11:49:21Z.

Review: CHANGES_REQUESTED


Although this carry of #2183 is mergeable with green CI on head 083c011, it still has a reproduced correctness blocker in tools/spirv_loop_guard.py:

  • Non-uniform OpControlBarrier hazard: %loop_guard_total is a per-invocation Private counter incremented at every guarded back edge, including outer wave64 round-scheduler loops (%loop_head/%loop_cont) and loops containing OpControlBarrier. When one wave executes more inner-loop iterations than another, it hits --loop-total first and exits the barrier loop while the other wave loops back and waits at OpControlBarrier (independently reproduced on head 083c011 at budgets 12 and 16 using BarrierInLoopsTests._wave_divergent_barrier_loop_cs(True): 64/128 invocations arrived at OpControlBarrier).

Widening tests/semantic/test_wave64_single_wave_barrier.py does not resolve the multi-wave barrier divergence. Please exempt barrier-containing / outer round-scheduler loops from the per-invocation aggregate budget (or make their exit workgroup-uniform) and add a multi-wave regression test before merging.

(AI-assisted review.)

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6130647369 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2736#pullrequestreview-6130647369). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T11:49:21Z. **Review:** CHANGES_REQUESTED --- Although this carry of `#2183` is mergeable with green CI on head `083c011`, it still has a reproduced correctness blocker in `tools/spirv_loop_guard.py`: - **Non-uniform `OpControlBarrier` hazard**: `%loop_guard_total` is a per-invocation `Private` counter incremented at every guarded back edge, including outer wave64 round-scheduler loops (`%loop_head`/`%loop_cont`) and loops containing `OpControlBarrier`. When one wave executes more inner-loop iterations than another, it hits `--loop-total` first and exits the barrier loop while the other wave loops back and waits at `OpControlBarrier` (independently reproduced on head `083c011` at budgets 12 and 16 using `BarrierInLoopsTests._wave_divergent_barrier_loop_cs(True)`: `64/128 invocations arrived at OpControlBarrier`). Widening `tests/semantic/test_wave64_single_wave_barrier.py` does not resolve the multi-wave barrier divergence. Please exempt barrier-containing / outer round-scheduler loops from the per-invocation aggregate budget (or make their exit workgroup-uniform) and add a multi-wave regression test before merging. *(AI-assisted review.)*
aslan2142 commented 2026-12-01 11:52:28 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T11:52:28Z.

Review: CHANGES_REQUESTED


Keeping #2736 over closed original #2183 (SHADER-LOOP-TOTAL): thank you for preserving @QemmHD's commit 88abd1609, resolving the tools/spirv_loop_guard.py conflict with main's CRLF and bool checks, and fixing tests/semantic/test_wave64_single_wave_barrier.py so CI is green.

However, requesting changes before merge for the unresolved correctness defect reproduced by @qhukz13 on #2183 (which this carry preserves unchanged):

  • In the --wave64-emulate round-loop form (x_scheduler, x_mini_scheduler, bar_scheduler), %loop_guard_total counts every inner-loop back edge per invocation. When one wave does more inner-loop work than another wave in the same workgroup, the busier wave hits --loop-total and exits the outer scheduler round loop while the other wave continues to the next OpControlBarrier, producing a non-uniform OpControlBarrier (Vulkan UB / GPU hang — reproduced on 2–3 of 24 synthetic NGG mesh programs in spirv_mini_interp.run_workgroup).
  • Please either exempt barrier-containing scheduler round loops from the per-invocation total (keeping their uniform per-loop limit) or make the total-exceeded exit uniform across the workgroup, and add a regression test covering a two-wave workgroup with asymmetric inner-loop trip counts.

(AI-assisted review.)

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6130703356 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2736#pullrequestreview-6130703356). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T11:52:28Z. **Review:** CHANGES_REQUESTED --- Keeping **#2736** over closed original **#2183** (`SHADER-LOOP-TOTAL`): thank you for preserving `@QemmHD`'s commit `88abd1609`, resolving the `tools/spirv_loop_guard.py` conflict with `main`'s CRLF and `bool` checks, and fixing `tests/semantic/test_wave64_single_wave_barrier.py` so CI is green. However, **requesting changes before merge** for the unresolved correctness defect reproduced by `@qhukz13` on `#2183` (which this carry preserves unchanged): - In the `--wave64-emulate` round-loop form (`x_scheduler`, `x_mini_scheduler`, `bar_scheduler`), `%loop_guard_total` counts every inner-loop back edge per invocation. When one wave does more inner-loop work than another wave in the same workgroup, the busier wave hits `--loop-total` and exits the outer scheduler round loop while the other wave continues to the next `OpControlBarrier`, producing a **non-uniform `OpControlBarrier`** (Vulkan UB / GPU hang — reproduced on 2–3 of 24 synthetic NGG mesh programs in `spirv_mini_interp.run_workgroup`). - Please either exempt barrier-containing scheduler round loops from the per-invocation total (keeping their uniform per-loop limit) or make the total-exceeded exit uniform across the workgroup, and add a regression test covering a two-wave workgroup with asymmetric inner-loop trip counts. *(AI-assisted review.)*
KelboLive commented 2026-12-01 16:13:09 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by KelboLive on 2026-12-01T16:13:09Z.

Review: COMMENTED


Reproduced the blocker on 083c011a9 (Windows, CPU interpreter, no game data): BarrierInLoopsTests._wave_divergent_barrier_loop_cs(True), 128 invocations, 32-lane subgroups, --wave64-emulate:

--loop-total result
0 (main) ok — lanes 0–63 → 2, 64–127 → 4
8 silent wrong output (second wave unwritten, -1)
12 NonUniformBarrierError: 64/128 invocations arrived at OpControlBarrier
16 / 24 / 32 / 1M ok

So the guard does not only truncate — it can make a valid program hit a non-uniform barrier, which is the class of bug the emulation layer exists to avoid.

The claim in the new test_wave64_single_wave_barrier.py comment — that %loop_guard_total is wave-uniform because it only follows %pc — holds only for that single-wave fixture. %loop_guard_total is a Private per-invocation counter, and the wave64 round-scheduler's %loop_head/%loop_cont spends from it, so as soon as two waves have different inner trip counts the per-lane totals diverge and the scheduler exits per lane. Please exempt barrier-containing/scheduler loops from the aggregate total (or make the total-exceeded exit workgroup-uniform) and add a two-wave asymmetric-trip-count regression test.

Separately, the total silently truncates a program main completes: a terminating nested loop with per-loop limit 4,000 that visits 9,000 times returns 9000 with total=0 and 6000 with total=6000, no diagnostic. At the 1M default any invocation legally exceeding 1M back edges is cut, so that trade-off needs an explicit note (and ideally a diagnostic) in the switch docs.

The boundary itself is pinned correctly: reverting the aggregate gate fails test_total_bounds_nested_loops ([2500] != [41]) and OpULessThan→OpULessThanEqual fails with [42] != [41]. Tests otherwise pass (15 targeted, 85 barrier/emulation, 42 make_game, full semantic 549 files / 6,677 tests), spirv-val is clean, merge-tree is clean, and nothing here is duplicated on main (#2183 is closed unmerged).

Minor: no total= unit test in tests/test_spirv_loop_guard.py, --loop-limit 0 silently suppresses --loop-total, and only the last OpEntryPoint gets the interface entry.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6135192723 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2736#pullrequestreview-6135192723). Originally posted by [KelboLive](https://github.com/KelboLive) on 2026-12-01T16:13:09Z. **Review:** COMMENTED --- Reproduced the blocker on `083c011a9` (Windows, CPU interpreter, no game data): `BarrierInLoopsTests._wave_divergent_barrier_loop_cs(True)`, 128 invocations, 32-lane subgroups, `--wave64-emulate`: | `--loop-total` | result | |---|---| | 0 (main) | ok — lanes 0–63 → 2, 64–127 → 4 | | 8 | **silent wrong output** (second wave unwritten, `-1`) | | **12** | **`NonUniformBarrierError: 64/128 invocations arrived at OpControlBarrier`** | | 16 / 24 / 32 / 1M | ok | So the guard does not only truncate — it can make a valid program hit a non-uniform barrier, which is the class of bug the emulation layer exists to avoid. The claim in the new `test_wave64_single_wave_barrier.py` comment — that `%loop_guard_total` is wave-uniform because it only follows `%pc` — holds only for that **single-wave** fixture. `%loop_guard_total` is a `Private` **per-invocation** counter, and the wave64 round-scheduler's `%loop_head`/`%loop_cont` spends from it, so as soon as two waves have different inner trip counts the per-lane totals diverge and the scheduler exits per lane. Please exempt barrier-containing/scheduler loops from the aggregate total (or make the total-exceeded exit workgroup-uniform) and add a two-wave asymmetric-trip-count regression test. Separately, the total silently truncates a program main completes: a terminating nested loop with per-loop limit 4,000 that visits 9,000 times returns 9000 with `total=0` and 6000 with `total=6000`, no diagnostic. At the 1M default any invocation legally exceeding 1M back edges is cut, so that trade-off needs an explicit note (and ideally a diagnostic) in the switch docs. The boundary itself is pinned correctly: reverting the aggregate gate fails `test_total_bounds_nested_loops` (`[2500] != [41]`) and `OpULessThan`→`OpULessThanEqual` fails with `[42] != [41]`. Tests otherwise pass (15 targeted, 85 barrier/emulation, 42 make_game, full semantic 549 files / 6,677 tests), `spirv-val` is clean, `merge-tree` is clean, and nothing here is duplicated on main (#2183 is closed unmerged). Minor: no `total=` unit test in `tests/test_spirv_loop_guard.py`, `--loop-limit 0` silently suppresses `--loop-total`, and only the last `OpEntryPoint` gets the interface entry.
aslan2142 commented 2026-12-01 17:26:17 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T17:26:17Z.


Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (d3d12/) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, d3d12/, or general docs), please feel free to reopen it.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7319297723 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2736#issuecomment-7319297723). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T17:26:17Z. --- Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (`d3d12/`) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, `d3d12/`, or general docs), please feel free to reopen it.

Pull request closed

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
ProjectLeonida/mandy!2736
No description provided.