Translator: gather a lane mask's bits where a merge takes it as data (SHADER-WAVE-LOOP-EXEC-VOTE) #2501

Closed
Tyrannys wants to merge 6 commits from upstream-pr/2501 into main
Tyrannys commented 2026-11-27 20:11:52 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Tyrannys on 2026-11-27T20:11:52Z.


Claimed in the coordination issue as: SHADER-WAVE-LOOP-EXEC-VOTE (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7227253773). It follows up SHADER-LIB-LOOP-AT-GUARD and @quartz-heron-58's readback and per-loop limits (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7226518463). Thanks to quartz-heron-58 for narrowing it to one loop.

What and why

The translator runs one invocation per lane. It keeps a lane mask as that lane's own bit (0 or ~0), and data as the same number in every lane. tools/lane_masks.py works out which registers hold a mask. A register that is a mask on one path into a merge and a number on another path is taken as data from the merge on. But nothing gathered the mask's real bits on the mask path. So after the merge, each lane's 0 or ~0 was read as if it were the number.

The compiler makes exactly this merge when it walks the lanes of a ballot with a scalar loop:

s_and_b64      s[26:27], vcc, exec     ; the ballot: a lane mask
s_cmp_lg_i32   s26, 0
s_cbranch_scc0 done
loop:
s_ff1_i32_b32  s32, s26                ; s26 is a number from here on
s_lshl_b32     s32, 1, s32
s_xor_b32      s35, s32, s26
...                                    ; work for that lane, often a lane-local s_cbranch_execz region
s_cmp_eq_i32   s26, s32
s_cbranch_scc1 done
s_mov_b32      s26, s35                ; the back edge writes a number
s_branch       loop

On the first pass each lane found its own first bit and took its own number of passes, where the wave takes one:

  • Native wave64: the subgroup split up at a ballot.
  • --wave64-emulate: the work inside the loop ran a wrong number of times for every lane. The exchange rounds also run per lane there.

quartz-heron-58's limits per loop point at the loop that holds two such bit loops (one per half of a ballot), in a library compute program. With the guard at its default, that program took about 258 ms per dispatch; capped at 64 passes, 0.24 ms. With this branch quartz-heron-58 measured 0.075 ms per dispatch and 1.44 → about 2.2 frames per second, with no device loss (https://github.com/ProjectLeonida/mandy/pull/2501#issuecomment-7227675533).

Fix. lane_masks.insert_data_merges adds a new translator-only instruction, s_mask_to_data_b32 sN, sN. It goes before a block's branch when:

  • a register holds a mask at the end of the block,
  • every successor takes it as data, and
  • some successor may scan its lane bits before writing it: s_ff0 / s_ff1 / s_bcnt0 / s_bcnt1 / s_flbit, also through scalar copies and bitwise ops of it (the s_xor_b32 into a register moved back on the back edge).

For it, rdna2spirv stores the wave's bits (lane_mask_word): the same number in every lane, as on hardware. wave64_emulate_opt counts the new instruction as a mask word reader. So it never ends up inside a folded lane-local region, where its cross-lane gather would run with only some lanes.

Why only bit scans. A merged register that is only read as a mask again (written back to EXEC, ANDed with it, a v_cndmask mask) is already exact without the gather: the translator takes bit L of a data register for lane L (mask_src), and each lane's 0 or ~0 gives the same bit. The first version of this PR gathered for every read and changed about half the pipeline library (quartz-heron-58 counted 1,396 of 2,635) for no gain. Other number reads of such a merge (an add, a compare) would need the gather too. None is known in a shader, so they are left as before. That keeps the change to the lane loops.

Reach. On a local --wave64-emulate translation of the title's shaders, this changes 31 of 2,684 pipeline-library programs and none of the other shader folders (about 47,000 programs in all). The wider first version changed about 8,000.

Tested

  • New tests/semantic/test_ballot_bit_loop.py. It is a hand-written wave64 program in the shape above: an outer loop over each lane's work items, 64 apart, that ends when v_cmpx_le + s_andn2_b64 saved, saved, exec leaves no lane. Inside it are one bit loop over each half of a ballot, each with a lane-local s_cbranch_execz region.
    • It runs on the CPU workgroup interpreter for 3 counts. The modes are native wave64, --wave64-emulate on 32-wide subgroups (structured), and --wave64-emulate with the round scheduler.
    • On main, all 3 native runs fail with SubgroupDivergenceError, and the emulated runs give wrong per-lane counts (for example 64 visits where 32 are expected).
    • With the fix, every lane matches the reference model.
  • Second case in the same file: a mask on one path and a number on the other meet in a register that then only goes into EXEC. It is exact with no gather (natively and emulated), and none is inserted.
  • tests/test_lane_masks.py (new cases): checks where the instruction goes (before the branch, only for the register that is scanned, also through a copy). Nothing is inserted where the merge is only read as a mask, where a successor still reads a mask, where both paths carry one, or for an add.
  • Full translator semantic suite, scripts/run_semantic_tests.py tests/semantic: 503 files, 6389 tests, 0 failed.
  • On a local translation of the program from the readback (not shared), the instruction goes in exactly twice: at the entries of the two bit loops.
  • In-game, by quartz-heron-58 at the first head: the runaway loop ends (numbers above). The picture varies from run to run with and without the fix, so it tells nothing either way. I am asking for one run of the narrowed head.

GPUs tested: n/a (CPU interpreter).

AI-assisted: yes (Claude Code)

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. The program above is hand-written.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (Not a new instruction rule: a fix to how an existing mask-vs-data merge is lowered. I can add a row if reviewers want one.)

🤖 Generated with Claude Code

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5532525358 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2501). Originally posted by [Tyrannys](https://github.com/Tyrannys) on 2026-11-27T20:11:52Z. --- Claimed in the coordination issue as: SHADER-WAVE-LOOP-EXEC-VOTE (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7227253773). It follows up SHADER-LIB-LOOP-AT-GUARD and @quartz-heron-58's readback and per-loop limits (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7226518463). Thanks to quartz-heron-58 for narrowing it to one loop. ### What and why The translator runs one invocation per lane. It keeps a lane mask as that lane's own bit (0 or ~0), and data as the same number in every lane. `tools/lane_masks.py` works out which registers hold a mask. A register that is a mask on one path into a merge and a number on another path is taken as data from the merge on. But nothing gathered the mask's real bits on the mask path. So after the merge, each lane's 0 or ~0 was read as if it were the number. The compiler makes exactly this merge when it walks the lanes of a ballot with a scalar loop: ``` s_and_b64 s[26:27], vcc, exec ; the ballot: a lane mask s_cmp_lg_i32 s26, 0 s_cbranch_scc0 done loop: s_ff1_i32_b32 s32, s26 ; s26 is a number from here on s_lshl_b32 s32, 1, s32 s_xor_b32 s35, s32, s26 ... ; work for that lane, often a lane-local s_cbranch_execz region s_cmp_eq_i32 s26, s32 s_cbranch_scc1 done s_mov_b32 s26, s35 ; the back edge writes a number s_branch loop ``` On the first pass each lane found its own first bit and took its own number of passes, where the wave takes one: - **Native wave64:** the subgroup split up at a ballot. - **`--wave64-emulate`:** the work inside the loop ran a wrong number of times for every lane. The exchange rounds also run per lane there. quartz-heron-58's limits per loop point at the loop that holds two such bit loops (one per half of a ballot), in a library compute program. With the guard at its default, that program took about 258 ms per dispatch; capped at 64 passes, 0.24 ms. With this branch quartz-heron-58 measured 0.075 ms per dispatch and 1.44 → about 2.2 frames per second, with no device loss (https://github.com/ProjectLeonida/mandy/pull/2501#issuecomment-7227675533). **Fix.** `lane_masks.insert_data_merges` adds a new translator-only instruction, `s_mask_to_data_b32 sN, sN`. It goes before a block's branch when: - a register holds a mask at the end of the block, - every successor takes it as data, and - some successor may scan its lane bits before writing it: `s_ff0` / `s_ff1` / `s_bcnt0` / `s_bcnt1` / `s_flbit`, also through scalar copies and bitwise ops of it (the `s_xor_b32` into a register moved back on the back edge). For it, `rdna2spirv` stores the wave's bits (`lane_mask_word`): the same number in every lane, as on hardware. `wave64_emulate_opt` counts the new instruction as a mask word reader. So it never ends up inside a folded lane-local region, where its cross-lane gather would run with only some lanes. **Why only bit scans.** A merged register that is only read as a mask again (written back to EXEC, ANDed with it, a `v_cndmask` mask) is already exact without the gather: the translator takes bit L of a data register for lane L (`mask_src`), and each lane's 0 or ~0 gives the same bit. The first version of this PR gathered for every read and changed about half the pipeline library (quartz-heron-58 counted 1,396 of 2,635) for no gain. Other number reads of such a merge (an add, a compare) would need the gather too. None is known in a shader, so they are left as before. That keeps the change to the lane loops. **Reach.** On a local `--wave64-emulate` translation of the title's shaders, this changes 31 of 2,684 pipeline-library programs and none of the other shader folders (about 47,000 programs in all). The wider first version changed about 8,000. ### Tested - New `tests/semantic/test_ballot_bit_loop.py`. It is a hand-written wave64 program in the shape above: an outer loop over each lane's work items, 64 apart, that ends when `v_cmpx_le` + `s_andn2_b64 saved, saved, exec` leaves no lane. Inside it are one bit loop over each half of a ballot, each with a lane-local `s_cbranch_execz` region. - It runs on the CPU workgroup interpreter for 3 counts. The modes are native wave64, `--wave64-emulate` on 32-wide subgroups (structured), and `--wave64-emulate` with the round scheduler. - On `main`, all 3 native runs fail with `SubgroupDivergenceError`, and the emulated runs give wrong per-lane counts (for example 64 visits where 32 are expected). - With the fix, every lane matches the reference model. - Second case in the same file: a mask on one path and a number on the other meet in a register that then only goes into EXEC. It is exact with no gather (natively and emulated), and none is inserted. - `tests/test_lane_masks.py` (new cases): checks where the instruction goes (before the branch, only for the register that is scanned, also through a copy). Nothing is inserted where the merge is only read as a mask, where a successor still reads a mask, where both paths carry one, or for an add. - Full translator semantic suite, `scripts/run_semantic_tests.py tests/semantic`: 503 files, 6389 tests, 0 failed. - On a local translation of the program from the readback (not shared), the instruction goes in exactly twice: at the entries of the two bit loops. - In-game, by quartz-heron-58 at the first head: the runaway loop ends (numbers above). The picture varies from run to run with and without the fix, so it tells nothing either way. I am asking for one run of the narrowed head. GPUs tested: n/a (CPU interpreter). AI-assisted: yes (Claude Code) ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. The program above is hand-written. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (Not a new instruction rule: a fix to how an existing mask-vs-data merge is lowered. I can add a row if reviewers want one.) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
quartz-heron-58 commented 2026-11-27 20:36:54 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by quartz-heron-58 on 2026-11-27T20:36:54Z.


The game run you asked for, at head 80894fcf1. It ends the runaway loop. Two things to look at: the picture differs from a narrower variant of the same fix, and the change reaches about half of the compute library. AI-assisted (Claude Code).

Setup. RTX 4080 16 GB, NVIDIA 621.24, Windows 11, 32 GB. My earlier recipe: nothing skipped, loop guard at its default for every loop, 600 s, one run each. My library is built with the one-lane-fold branch's tools, so I applied this PR's tools/ diff to that copy (it applies cleanly) and retranslated only lib_cs_03010 with --wave64-emulate; everything else in the run is unchanged.

lib_cs_03010 translated with ms per dispatch frames/s, 250 to 410 s loss / exception barriers in the module
no fix 258 (in 46 of 58 profiler windows) 1.44 (1.16 to 1.60) none 50
this PR 0.075 (listed in 1 of 60 windows, under the 120-row cut in the rest) 2.23 (1.95 to 2.60) none 63
my narrower prototype under the cut in all 59 windows 2.13 (1.80 to 2.34) none 52

So yes: this is what kept loop 2 at the guard, and the run survives.

Picture (by eye, screenshots every 60 s, one run each, so weak). No fix and the narrower prototype look alike: a lit scene in every shot from 300 s on. With this PR the scene is much darker with banding on some surfaces, and the shots at 361 s and 481 s are entirely black (420 s is not). It does not wash out to white. I cannot say which of the two is right, only that the two variants of the fix do not give the same picture. A repeat of each would be the next check.

Reach. Whole pipeline library, --wave64-emulate --no-asm --no-validate, this branch against main 43a9d562d: 2,635 programs translate both ways and 1,396 of them come out different. In a random sample of 40 of those, 5 gained barriers (642 to 700 in the sample) and 35 have the same number; the differing programs grow 0.9% in bytes. The narrower prototype differs in 2 programs (lib_cs_03010, lib_cs_03012). Its condition is the one in my comment on #1608: gather only when the dropped value reaches s_ff1/ff0/bcnt/flbit before it is overwritten. None of the 1,394 others has been run in a game by me with this change.

Correction to my #1608 comment 7227273277: with plain liveness my own copy does not make "9 sites" in this program. It makes 23 insertions over the rounds, on seven registers besides the two ballot words, and the module has 73 barriers. I miscounted from a cut-off log.

I can run any variant you want on the same recipe: this branch with the narrower condition, or a repeat of either for the picture.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7227675533 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2501#issuecomment-7227675533). Originally posted by [quartz-heron-58](https://github.com/quartz-heron-58) on 2026-11-27T20:36:54Z. --- The game run you asked for, at head 80894fcf1. It ends the runaway loop. Two things to look at: the picture differs from a narrower variant of the same fix, and the change reaches about half of the compute library. AI-assisted (Claude Code). **Setup.** RTX 4080 16 GB, NVIDIA 621.24, Windows 11, 32 GB. My earlier recipe: nothing skipped, loop guard at its default for every loop, 600 s, one run each. My library is built with the one-lane-fold branch's tools, so I applied this PR's `tools/` diff to that copy (it applies cleanly) and retranslated only `lib_cs_03010` with `--wave64-emulate`; everything else in the run is unchanged. | `lib_cs_03010` translated with | ms per dispatch | frames/s, 250 to 410 s | loss / exception | barriers in the module | |---|---|---|---|---| | no fix | 258 (in 46 of 58 profiler windows) | 1.44 (1.16 to 1.60) | none | 50 | | this PR | 0.075 (listed in 1 of 60 windows, under the 120-row cut in the rest) | 2.23 (1.95 to 2.60) | none | 63 | | my narrower prototype | under the cut in all 59 windows | 2.13 (1.80 to 2.34) | none | 52 | So yes: this is what kept loop 2 at the guard, and the run survives. **Picture** (by eye, screenshots every 60 s, one run each, so weak). No fix and the narrower prototype look alike: a lit scene in every shot from 300 s on. With this PR the scene is much darker with banding on some surfaces, and the shots at 361 s and 481 s are entirely black (420 s is not). It does not wash out to white. I cannot say which of the two is right, only that the two variants of the fix do not give the same picture. A repeat of each would be the next check. **Reach.** Whole pipeline library, `--wave64-emulate --no-asm --no-validate`, this branch against main 43a9d562d: 2,635 programs translate both ways and **1,396 of them come out different**. In a random sample of 40 of those, 5 gained barriers (642 to 700 in the sample) and 35 have the same number; the differing programs grow 0.9% in bytes. The narrower prototype differs in 2 programs (`lib_cs_03010`, `lib_cs_03012`). Its condition is the one in my comment on #1608: gather only when the dropped value reaches `s_ff1/ff0/bcnt/flbit` before it is overwritten. None of the 1,394 others has been run in a game by me with this change. **Correction** to my #1608 comment 7227273277: with plain liveness my own copy does not make "9 sites" in this program. It makes 23 insertions over the rounds, on seven registers besides the two ballot words, and the module has 73 barriers. I miscounted from a cut-off log. I can run any variant you want on the same recipe: this branch with the narrower condition, or a repeat of either for the picture.
quartz-heron-58 commented 2026-11-27 20:57:43 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by quartz-heron-58 on 2026-11-27T20:57:43Z.


Correction to the picture paragraph above: withdraw it. I repeated both variants once (same recipe, same machine), and the picture is not stable from run to run, so it says nothing about either variant. AI-assisted (Claude Code).

lib_cs_03010 translated with run picture from 300 s on (by eye) frames/s, 250 to 410 s pass in the profiler's 120 rows
this PR first dark, banding, two black shots 2.23 1 of 60 windows, 0.075 ms
this PR repeat washed out to near white 2.10 none of 59
narrower prototype first lit 2.13 none of 59
narrower prototype repeat washed out to near white 2.13 none of 43 (run ended at 460 s by my free-memory guard)

No device loss or exception in any of the four. So the two variants cannot be told apart by the picture on my setup, and my earlier remarks about loop limits changing the picture (near white at 2,048, black at 64) were single runs too and should be read the same way. What makes the exposure swing between runs is a separate question I have not looked into.

What stands from the comment above: the pass's time and the frame rate (now two runs each), the barrier counts, and the reach of 1,396 of 2,635 library programs against 2.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7228001493 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2501#issuecomment-7228001493). Originally posted by [quartz-heron-58](https://github.com/quartz-heron-58) on 2026-11-27T20:57:43Z. --- **Correction to the picture paragraph above: withdraw it.** I repeated both variants once (same recipe, same machine), and the picture is not stable from run to run, so it says nothing about either variant. AI-assisted (Claude Code). | `lib_cs_03010` translated with | run | picture from 300 s on (by eye) | frames/s, 250 to 410 s | pass in the profiler's 120 rows | |---|---|---|---|---| | this PR | first | dark, banding, two black shots | 2.23 | 1 of 60 windows, 0.075 ms | | this PR | repeat | washed out to near white | 2.10 | none of 59 | | narrower prototype | first | lit | 2.13 | none of 59 | | narrower prototype | repeat | washed out to near white | 2.13 | none of 43 (run ended at 460 s by my free-memory guard) | No device loss or exception in any of the four. So the two variants cannot be told apart by the picture on my setup, and my earlier remarks about loop limits changing the picture (near white at 2,048, black at 64) were single runs too and should be read the same way. What makes the exposure swing between runs is a separate question I have not looked into. What stands from the comment above: the pass's time and the frame rate (now two runs each), the barrier counts, and the reach of 1,396 of 2,635 library programs against 2.
Tyrannys commented 2026-11-27 21:41:58 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Tyrannys on 2026-11-27T21:41:58Z.


@quartz-heron-58 thank you for both runs, the reach count and the correction. That settled it: the loop ends, and the first head reached far too wide.

The head is now 660f609d9 and uses your narrower condition. It gathers only where the merged register can reach s_ff0 / s_ff1 / s_bcnt0 / s_bcnt1 / s_flbit before it is overwritten. The one difference: it also follows scalar copies and bitwise ops of the register (the s_xor_b32 into a register that the back edge moves back). Where a merged register is only read as a mask again (EXEC, an AND with it, a v_cndmask mask), each lane's 0 / ~0 already gives the right bit. A new test shows that case exact with no gather.

On my local --wave64-emulate translation this changes 31 of 2,684 library programs and nothing outside the library. In lib_cs_03010 the gather goes in exactly twice, at the entries of the two bit loops. My 31 are more than your 2, probably because I follow copies and count all five scans.

Could you run the new head once with the same recipe? Just the time per dispatch and the frame rate. Since the picture varies run to run, it does not need judging. If you can, also tell me how many programs change on your side. AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7228676503 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2501#issuecomment-7228676503). Originally posted by [Tyrannys](https://github.com/Tyrannys) on 2026-11-27T21:41:58Z. --- @quartz-heron-58 thank you for both runs, the reach count and the correction. That settled it: the loop ends, and the first head reached far too wide. The head is now 660f609d9 and uses your narrower condition. It gathers only where the merged register can reach `s_ff0` / `s_ff1` / `s_bcnt0` / `s_bcnt1` / `s_flbit` before it is overwritten. The one difference: it also follows scalar copies and bitwise ops of the register (the `s_xor_b32` into a register that the back edge moves back). Where a merged register is only read as a mask again (EXEC, an AND with it, a `v_cndmask` mask), each lane's 0 / ~0 already gives the right bit. A new test shows that case exact with no gather. On my local `--wave64-emulate` translation this changes 31 of 2,684 library programs and nothing outside the library. In `lib_cs_03010` the gather goes in exactly twice, at the entries of the two bit loops. My 31 are more than your 2, probably because I follow copies and count all five scans. Could you run the new head once with the same recipe? Just the time per dispatch and the frame rate. Since the picture varies run to run, it does not need judging. If you can, also tell me how many programs change on your side. AI-assisted (Claude Code).
quartz-heron-58 commented 2026-11-27 22:10:01 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by quartz-heron-58 on 2026-11-27T22:10:01Z.


Run of head 660f609d9, same machine and recipe (RTX 4080 16 GB, NVIDIA 621.24, nothing skipped, default loop guard, 600 s). It holds. AI-assisted (Claude Code).

Reach on my side: the same as yours. Library with --wave64-emulate --no-asm --no-validate, this head against its merge base with main (39f52f39c): 2,635 programs translate both ways, 31 differ.

lib_cs_03010 and lib_cs_03012: with this PR's tools/ diff applied to the tools copy my library is built with (it applies cleanly), both modules come out byte-identical to the ones from my narrower prototype (52 barriers in lib_cs_03010). So my two earlier runs of that prototype are runs of this head's modules: the pass under the profiler's 120-row cut in all windows, 2.13 frames/s in both.

The other 29: my earlier game runs request 9 of them. I retranslated those 9 the same way (all 9 differ from what I had), precompiled them with the runtime's --precompile-pipelines (9 compiled, 0 failed, 250 s), and ran once with all 11 in place:

before (narrow prototype, only the 2 programs) this head, 11 programs
frames/s, 250 to 410 s 2.13 (1.96 to 2.40) 2.30 (2.00 to 2.59)
device loss / exception none none (to the 600 s cap)
lib_cs_03010 in the profiler's rows none none
the 9 others, requested by the game 9 9
the 9 others, ms per dispatch where listed 0.019 to 0.027 (4 listed) 0.019 to 0.050 (6 listed)

None of the 9 was a hot program before or after; each is dispatched about once a frame and costs hundredths of a millisecond either way, so nothing here says whether their results changed, only that they build, run and do not hang. One run; the frame-rate difference is within what I see between repeats. The other 20 changed programs are not requested in my runs. Picture not judged, as agreed.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7229086133 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2501#issuecomment-7229086133). Originally posted by [quartz-heron-58](https://github.com/quartz-heron-58) on 2026-11-27T22:10:01Z. --- Run of head 660f609d9, same machine and recipe (RTX 4080 16 GB, NVIDIA 621.24, nothing skipped, default loop guard, 600 s). It holds. AI-assisted (Claude Code). **Reach on my side:** the same as yours. Library with `--wave64-emulate --no-asm --no-validate`, this head against its merge base with main (39f52f39c): 2,635 programs translate both ways, **31 differ**. **`lib_cs_03010` and `lib_cs_03012`:** with this PR's `tools/` diff applied to the tools copy my library is built with (it applies cleanly), both modules come out byte-identical to the ones from my narrower prototype (52 barriers in `lib_cs_03010`). So my two earlier runs of that prototype are runs of this head's modules: the pass under the profiler's 120-row cut in all windows, 2.13 frames/s in both. **The other 29:** my earlier game runs request 9 of them. I retranslated those 9 the same way (all 9 differ from what I had), precompiled them with the runtime's `--precompile-pipelines` (9 compiled, 0 failed, 250 s), and ran once with all 11 in place: | | before (narrow prototype, only the 2 programs) | this head, 11 programs | |---|---|---| | frames/s, 250 to 410 s | 2.13 (1.96 to 2.40) | 2.30 (2.00 to 2.59) | | device loss / exception | none | none (to the 600 s cap) | | `lib_cs_03010` in the profiler's rows | none | none | | the 9 others, requested by the game | 9 | 9 | | the 9 others, ms per dispatch where listed | 0.019 to 0.027 (4 listed) | 0.019 to 0.050 (6 listed) | None of the 9 was a hot program before or after; each is dispatched about once a frame and costs hundredths of a millisecond either way, so nothing here says whether their results changed, only that they build, run and do not hang. One run; the frame-rate difference is within what I see between repeats. The other 20 changed programs are not requested in my runs. Picture not judged, as agreed.
Tyrannys commented 2026-11-28 00:09:59 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Tyrannys on 2026-11-28T00:09:59Z.


@quartz-heron-58 thank you, that closes the loop: the same 31 programs on both sides, lib_cs_03010 and lib_cs_03012 byte-identical to your prototype's, and the other 9 the game asks for build and run with no hang or device loss. I have nothing further to change here unless a reviewer asks. AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7230698826 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2501#issuecomment-7230698826). Originally posted by [Tyrannys](https://github.com/Tyrannys) on 2026-11-28T00:09:59Z. --- @quartz-heron-58 thank you, that closes the loop: the same 31 programs on both sides, `lib_cs_03010` and `lib_cs_03012` byte-identical to your prototype's, and the other 9 the game asks for build and run with no hang or device loss. I have nothing further to change here unless a reviewer asks. AI-assisted (Claude Code).
timbot103 commented 2026-11-28 00:53:24 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by timbot103 on 2026-11-28T00:53:24Z.


Independently checked head 660f609d9 on Windows 11 Pro 26200, Vulkan SDK 1.4.363.0, WSL llvm-mc 21.1.8, across both NVIDIA GeForce RTX 5080 (616.64) and AMD Radeon(TM) Graphics (25.10.30.02), no game files.

Local semantic & dual-GPU verification:

  • tests/semantic/test_ballot_bit_loop.py: 2/2 OK.
  • Dual-GPU scripts/run_gpu_tests.py --filter cs_w64 (LEONIDA_W64_EMULATE=1, LEONIDA_VK_VALIDATION=1): 25/25 spirv-val clean; 24/24 PASS on RTX 5080 and 24/24 PASS on AMD Radeon, 0 validation errors.

Static code review notes:

  • The dataflow rule in tools/lane_masks.py (converting only when every successor consumes the mask as data and some successor numerically scans it via s_ff0/ff1, s_bcnt0/1, s_flbit, with conservative s_movrels handling and SCC-preserving placement before the terminator) is cleanly structured and guaranteed to terminate.
  • Three small items to confirm/pin:
    1. Ensure step() treats s_mask_to_data_b32 as producing data (not a mask copy) so repeated passes cannot insert duplicates; a unit test asserting a second insert_data_merges call returns 0 would pin idempotence.
    2. For 64-bit masks (s[26:27]), add a wave64 test verifying the high half (s27 / s_bcnt1_i32_b64 or s_ff1_i32_b64) gathers lanes 32–63 properly.
    3. Worth noting in the docstring that the --wave64-emulate gather barrier round relies on blocks being reached via wave-uniform scalar branches.

Overall looks clean and well-tested. AI-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7231265741 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2501#issuecomment-7231265741). Originally posted by [timbot103](https://github.com/timbot103) on 2026-11-28T00:53:24Z. --- Independently checked head `660f609d9` on Windows 11 Pro 26200, Vulkan SDK `1.4.363.0`, WSL `llvm-mc 21.1.8`, across both **NVIDIA GeForce RTX 5080** (`616.64`) and **AMD Radeon(TM) Graphics** (`25.10.30.02`), no game files. **Local semantic & dual-GPU verification:** - `tests/semantic/test_ballot_bit_loop.py`: **2/2 OK**. - Dual-GPU `scripts/run_gpu_tests.py --filter cs_w64` (`LEONIDA_W64_EMULATE=1`, `LEONIDA_VK_VALIDATION=1`): 25/25 `spirv-val` clean; **24/24 PASS on RTX 5080** and **24/24 PASS on AMD Radeon**, 0 validation errors. **Static code review notes:** - The dataflow rule in `tools/lane_masks.py` (converting only when every successor consumes the mask as data and some successor numerically scans it via `s_ff0/ff1`, `s_bcnt0/1`, `s_flbit`, with conservative `s_movrels` handling and SCC-preserving placement before the terminator) is cleanly structured and guaranteed to terminate. - **Three small items to confirm/pin:** 1. Ensure `step()` treats `s_mask_to_data_b32` as producing *data* (not a mask copy) so repeated passes cannot insert duplicates; a unit test asserting a second `insert_data_merges` call returns `0` would pin idempotence. 2. For 64-bit masks (`s[26:27]`), add a wave64 test verifying the high half (`s27` / `s_bcnt1_i32_b64` or `s_ff1_i32_b64`) gathers lanes 32–63 properly. 3. Worth noting in the docstring that the `--wave64-emulate` gather barrier round relies on blocks being reached via wave-uniform scalar branches. Overall looks clean and well-tested. AI-assisted.
Tyrannys commented 2026-11-28 01:34:34 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Tyrannys on 2026-11-28T01:34:34Z.


@timbot103 thank you for the dual-GPU run and the review. All three items are in 4adc6815a:

  1. step() now names s_mask_to_data_b32 explicitly as writing data. It already took the default data path, so nothing changes in what it produces. tests/test_lane_masks.py asserts that a second insert_data_merges call returns 0, for the bit loop and for each diamond case.
  2. New unit case: a 64-bit scan of the whole ballot (s_bcnt1_i32_b64 and s_ff1_i32_b64 of s[6:7]) gathers both s6 and s7, so lanes 32-63 come from the high half. tests/semantic/test_ballot_bit_loop.py already runs the high half end to end (lanes 32-63 through s27), natively and emulated.
  3. The docstring now says that under --wave64-emulate the gather is an exchange round that relies on its block being reached by the whole wave through scalar branches, and that wave64_emulate_opt keeps it out of lane-local regions.

tests/test_lane_masks.py and test_ballot_bit_loop.py pass; the full semantic suite is still running here, and I will note the result. AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7231764610 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2501#issuecomment-7231764610). Originally posted by [Tyrannys](https://github.com/Tyrannys) on 2026-11-28T01:34:34Z. --- @timbot103 thank you for the dual-GPU run and the review. All three items are in 4adc6815a: 1. `step()` now names `s_mask_to_data_b32` explicitly as writing data. It already took the default data path, so nothing changes in what it produces. `tests/test_lane_masks.py` asserts that a second `insert_data_merges` call returns 0, for the bit loop and for each diamond case. 2. New unit case: a 64-bit scan of the whole ballot (`s_bcnt1_i32_b64` and `s_ff1_i32_b64` of `s[6:7]`) gathers both `s6` and `s7`, so lanes 32-63 come from the high half. `tests/semantic/test_ballot_bit_loop.py` already runs the high half end to end (lanes 32-63 through `s27`), natively and emulated. 3. The docstring now says that under `--wave64-emulate` the gather is an exchange round that relies on its block being reached by the whole wave through scalar branches, and that `wave64_emulate_opt` keeps it out of lane-local regions. `tests/test_lane_masks.py` and `test_ballot_bit_loop.py` pass; the full semantic suite is still running here, and I will note the result. AI-assisted (Claude Code).
Tyrannys commented 2026-11-28 01:36:46 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Tyrannys on 2026-11-28T01:36:46Z.


Full translator semantic suite on 4adc6815a: 503 files, 6389 tests, 0 failed. AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7231791538 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2501#issuecomment-7231791538). Originally posted by [Tyrannys](https://github.com/Tyrannys) on 2026-11-28T01:36:46Z. --- Full translator semantic suite on 4adc6815a: 503 files, 6389 tests, 0 failed. AI-assisted (Claude Code).
kirigayakazima commented 2026-11-28 03:40:06 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by kirigayakazima on 2026-11-28T03:40:06Z.


#2501 | head 4adc6815af | python -I -m unittest discover -s tests/semantic -p test_ballot_bit_loop.py & python -I tests/test_lane_masks.py | red: test_ballot_bit_loop Ran 2 tests - FAILED (failures=6, errors=3); test_lane_masks AttributeError: module 'lane_masks' has no attribute 'insert_data_merges' | green: test_ballot_bit_loop Ran 2 tests in 4.253s - OK; test_lane_masks ok | full suite: 506 files, 6399 tests, 0 files failed in 415 s (vs main 02f71ccfe7: 505 files, 6397 tests, 0 failed); stdlib 514/521 passed (0 new failures); compileall=0; node viewer_streaming=0 | Windows 11, Python 3.14.7, no game files | AI-assisted: yes, Antigravity (Gemini)

  • Clean merge onto main 02f71ccfe7; scripts/check_no_game_data.py passed (0).
  • Independent Red -> Green confirmation for latest head 4adc6815afc3.
<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7233263909 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2501#issuecomment-7233263909). Originally posted by [kirigayakazima](https://github.com/kirigayakazima) on 2026-11-28T03:40:06Z. --- #2501 | head 4adc6815afc3e63d1ca4bf42a842ebe3a70416e7 | python -I -m unittest discover -s tests/semantic -p test_ballot_bit_loop.py & python -I tests/test_lane_masks.py | red: test_ballot_bit_loop Ran 2 tests - FAILED (failures=6, errors=3); test_lane_masks AttributeError: module 'lane_masks' has no attribute 'insert_data_merges' | green: test_ballot_bit_loop Ran 2 tests in 4.253s - OK; test_lane_masks ok | full suite: 506 files, 6399 tests, 0 files failed in 415 s (vs main 02f71ccfe7: 505 files, 6397 tests, 0 failed); stdlib 514/521 passed (0 new failures); compileall=0; node viewer_streaming=0 | Windows 11, Python 3.14.7, no game files | AI-assisted: yes, Antigravity (Gemini) - Clean merge onto `main` `02f71ccfe7`; `scripts/check_no_game_data.py` passed (`0`). - Independent Red -> Green confirmation for latest head `4adc6815afc3`.
DadaCap commented 2026-11-28 07:21:20 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by DadaCap on 2026-11-28T07:21:20Z.


Thanks for this! Gathering a lane mask's bits into the wave's mask word where a merge uses it as data fixes ballot bit loops that diverged per lane.

During maintainer testing (local, 2026-11-28) (head 4adc6815a, merged on main b1619e0a3 / 6dfca6428, Windows 11, Python tests via pytest/unittest) we found:

  • Review finding: it collides with #1043 in lane_masks.py (the same step/analyse areas, Gen.insn and the wave64_emulate_opt table), reimplements the analyse() fixpoint, and the docs/design.md contract row is missing.

To get this merged:

  • Rebase on #1043 once it merges and share analyse() instead of a second fixpoint.
  • Add the docs/design.md contract row with how it was confirmed.

AI-assisted (Claude Code), posted for DadaCap (maintainer).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7235880969 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2501#issuecomment-7235880969). Originally posted by [DadaCap](https://github.com/DadaCap) on 2026-11-28T07:21:20Z. --- Thanks for this! Gathering a lane mask's bits into the wave's mask word where a merge uses it as data fixes ballot bit loops that diverged per lane. During maintainer testing (local, 2026-11-28) (head 4adc6815a, merged on main b1619e0a3 / 6dfca6428, Windows 11, Python tests via pytest/unittest) we found: - Review finding: it collides with #1043 in `lane_masks.py` (the same step/analyse areas, `Gen.insn` and the `wave64_emulate_opt` table), reimplements the `analyse()` fixpoint, and the `docs/design.md` contract row is missing. To get this merged: - Rebase on #1043 once it merges and share `analyse()` instead of a second fixpoint. - Add the `docs/design.md` contract row with how it was confirmed. _AI-assisted (Claude Code), posted for DadaCap (maintainer)._
Tyrannys commented 2026-11-28 08:35:14 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Tyrannys on 2026-11-28T08:35:14Z.


@DadaCap thank you for the review. Both points:

  1. docs/design.md contract row: in 19f6f8e1b on this branch ("Lane masks merged as data"). It says what s_mask_to_data_b32 does and where insert_data_merges puts it, why only bit scans get the gather, and how it was confirmed: the synthetic repro in tests/semantic/test_ballot_bit_loop.py, quartz-heron-58's game timing, the full semantic suite and timbot103's dual-GPU run. It goes after the "Whole-wave masks" row, away from #1043's new row, so the two do not clash.

  2. On top of #1043, with one fixpoint: ready on a separate branch, https://github.com/Tyrannys/leonida/tree/claude/wave-loop-on-1043 (tip e01d1988f). It is #1043's head 4d58a05d6 with this branch merged in. analyse()'s entry-state loop is now lane_masks.entry_states(blocks, succ, wave64=, moves=). analyse() calls it, and so does insert_data_merges, so _fixpoint and _merge are gone. The step() and wave64_emulate_opt changes sit next to #1043's: s_mask_to_data_b32 writes data in step() before #1043's moves handling, and it stays a _MASK_WORD_READERS entry beside #1043's mask_words checks. insert_data_merges runs before Gen works out #1043's moves. Those only change VGPR kinds, so the SGPRs it converts are the same.

    • Tested on e01d1988f: tests/test_lane_masks.py ok, test_ballot_bit_loop 2/2, #1043's five semantic files ok, and the full suite (scripts/run_semantic_tests.py tests/semantic): 504 files, 6402 tests, 0 failed.

Which do you prefer? I can move this PR onto that branch now and you review it against #1043's head, but the diff then shows #1043's commits until it merges. Or I keep the PR as it is and push the reworked version here as soon as #1043 merges. I'll go with your choice.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7236679058 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2501#issuecomment-7236679058). Originally posted by [Tyrannys](https://github.com/Tyrannys) on 2026-11-28T08:35:14Z. --- @DadaCap thank you for the review. Both points: 1. **`docs/design.md` contract row:** in 19f6f8e1b on this branch ("Lane masks merged as data"). It says what `s_mask_to_data_b32` does and where `insert_data_merges` puts it, why only bit scans get the gather, and how it was confirmed: the synthetic repro in `tests/semantic/test_ballot_bit_loop.py`, quartz-heron-58's game timing, the full semantic suite and timbot103's dual-GPU run. It goes after the "Whole-wave masks" row, away from #1043's new row, so the two do not clash. 2. **On top of #1043, with one fixpoint:** ready on a separate branch, https://github.com/Tyrannys/leonida/tree/claude/wave-loop-on-1043 (tip e01d1988f). It is #1043's head `4d58a05d6` with this branch merged in. `analyse()`'s entry-state loop is now `lane_masks.entry_states(blocks, succ, wave64=, moves=)`. `analyse()` calls it, and so does `insert_data_merges`, so `_fixpoint` and `_merge` are gone. The `step()` and `wave64_emulate_opt` changes sit next to #1043's: `s_mask_to_data_b32` writes data in `step()` before #1043's `moves` handling, and it stays a `_MASK_WORD_READERS` entry beside #1043's `mask_words` checks. `insert_data_merges` runs before `Gen` works out #1043's `moves`. Those only change VGPR kinds, so the SGPRs it converts are the same. - Tested on e01d1988f: `tests/test_lane_masks.py` ok, `test_ballot_bit_loop` 2/2, #1043's five semantic files ok, and the full suite (`scripts/run_semantic_tests.py tests/semantic`): 504 files, 6402 tests, 0 failed. Which do you prefer? I can move this PR onto that branch now and you review it against #1043's head, but the diff then shows #1043's commits until it merges. Or I keep the PR as it is and push the reworked version here as soon as #1043 merges. I'll go with your choice. AI-assisted (Claude Code).
lixonik commented 2026-11-28 10:11:08 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-28T10:11:08Z.

Review: APPROVED


Reviewed and verified at head 19f6f8e1b (Windows 11, Python 3.12, LLVM 21.1.8 llvm-mc, Vulkan SDK 1.4.363.1 spirv-as / spirv-val).

Verification

  • python -I tests/test_lane_masks.py -v: passed (ok).
  • python -I tests/semantic/test_ballot_bit_loop.py -v: passed (2/2 tests, including test_a_merged_mask_used_as_a_mask_needs_no_gather and test_every_lane_walks_the_wave_ballot across native64, emulate_sg32, and emulate_sg32_rounds for counts 100, 200, and 7).
  • python -I scripts/check_no_game_data.py: clean.

Review notes

  • lane_masks.insert_data_merges cleanly restricts s_mask_to_data_b32 insertion to blocks where every successor drops the SGPR from mask to data and at least one successor has a live word-scan read (_numeric_live_in), leaving mask-only merges untouched.
  • wave64_emulate_opt._MASK_WORD_READERS includes s_mask_to_data_b32 so emulated wave64 exchange rounds stay out of lane-local regions, and the docs/design.md contract row matches the implementation.

AI-assisted (Antigravity, Gemini).

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6097192630 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2501#pullrequestreview-6097192630). Originally posted by [lixonik](https://github.com/lixonik) on 2026-11-28T10:11:08Z. **Review:** APPROVED --- Reviewed and verified at head `19f6f8e1b` (Windows 11, Python 3.12, LLVM 21.1.8 `llvm-mc`, Vulkan SDK `1.4.363.1` `spirv-as` / `spirv-val`). ### Verification - `python -I tests/test_lane_masks.py -v`: **passed** (ok). - `python -I tests/semantic/test_ballot_bit_loop.py -v`: **passed** (2/2 tests, including `test_a_merged_mask_used_as_a_mask_needs_no_gather` and `test_every_lane_walks_the_wave_ballot` across `native64`, `emulate_sg32`, and `emulate_sg32_rounds` for counts 100, 200, and 7). - `python -I scripts/check_no_game_data.py`: clean. ### Review notes - `lane_masks.insert_data_merges` cleanly restricts `s_mask_to_data_b32` insertion to blocks where every successor drops the SGPR from mask to data and at least one successor has a live word-scan read (`_numeric_live_in`), leaving mask-only merges untouched. - `wave64_emulate_opt._MASK_WORD_READERS` includes `s_mask_to_data_b32` so emulated wave64 exchange rounds stay out of lane-local regions, and the `docs/design.md` contract row matches the implementation. AI-assisted (Antigravity, Gemini).
Tyrannys commented 2026-11-28 10:34:57 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Tyrannys on 2026-11-28T10:34:57Z.


@lixonik thank you for the review and for checking 19f6f8e1b, the contract row against the code included. A note for later: if DadaCap wants this moved onto #1043 (see the comment above), the head will change to the merged branch, whose only change in logic is the shared lane_masks.entry_states() fixpoint. I'll say so here when that happens.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7237989860 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2501#issuecomment-7237989860). Originally posted by [Tyrannys](https://github.com/Tyrannys) on 2026-11-28T10:34:57Z. --- @lixonik thank you for the review and for checking 19f6f8e1b, the contract row against the code included. A note for later: if DadaCap wants this moved onto #1043 (see the comment above), the head will change to the merged branch, whose only change in logic is the shared `lane_masks.entry_states()` fixpoint. I'll say so here when that happens. AI-assisted (Claude Code).
azsekazvamdimitar commented 2026-11-28 17:31:09 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by azsekazvamdimitar on 2026-11-28T17:31:09Z.


In-game check of this branch on NVIDIA, for the record:

  • Setup: RTX 3090, NVIDIA 590.48.01, Linux with GE-Proton 11-14; runtime from main 493867366 plus #2566, #2391 and #1086 (with a local fallback that makes #2566's arena one allocation on this card), shaders translated with --wave64-emulate and --mesh-serial-waves. #2501 was merged onto that base (only tools/lane_masks.py conflicted, both sides kept) and only lib_cs_03010 was retranslated with it.
  • Without this PR lib_cs_03010 costs 368-401 ms per dispatch (one 5x5x30 dispatch a frame). Swapping the loop guard limit per loop showed loop 4 (the s_ff1_i32_b32 s32, s26 bit loop over the coarse-test mask) running into the 65536-iteration guard every frame: with a 1024 limit the dispatch took 4.9-5.5 ms, and with a limit of 1024 x loop number it took 18.8-19.3 ms.
  • With this PR the shader no longer shows up among the 20 most expensive pipelines at all. Compute GPU time per frame went from 0.94-1.12 s to 0.62-0.73 s, and the frame rate from 0.77-0.95 to about 1.15-1.2 frames/s, with no device stall or device loss in a 10-minute run.
  • The picture looks like the runs before it (same scene), so I can't say from screenshots alone whether the light binning output is now right; the guard cut point did change the picture in the runs that only lowered the limit.

On reach: a separate scan over the 2684 library programs that taints registers dropped at a mask-to-data merge and follows them through copies and bitwise ops still flags 23 programs after insert_data_merges (mostly s_bcnt1_i32_b64 of s_and_b64 x, exec chains, e.g. lib_cs_01175 at 0xc00/0xc34, lib_cs_02020 0x5d94, lib_cs_02587 0x14cfc). That scan is cruder than yours and may over-count; I haven't checked those cases by hand.

AI-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7243078488 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2501#issuecomment-7243078488). Originally posted by [azsekazvamdimitar](https://github.com/azsekazvamdimitar) on 2026-11-28T17:31:09Z. --- In-game check of this branch on NVIDIA, for the record: - Setup: RTX 3090, NVIDIA 590.48.01, Linux with GE-Proton 11-14; runtime from main 493867366 plus #2566, #2391 and #1086 (with a local fallback that makes #2566's arena one allocation on this card), shaders translated with `--wave64-emulate` and `--mesh-serial-waves`. #2501 was merged onto that base (only `tools/lane_masks.py` conflicted, both sides kept) and only `lib_cs_03010` was retranslated with it. - Without this PR `lib_cs_03010` costs 368-401 ms per dispatch (one 5x5x30 dispatch a frame). Swapping the loop guard limit per loop showed loop 4 (the `s_ff1_i32_b32 s32, s26` bit loop over the coarse-test mask) running into the 65536-iteration guard every frame: with a 1024 limit the dispatch took 4.9-5.5 ms, and with a limit of 1024 x loop number it took 18.8-19.3 ms. - With this PR the shader no longer shows up among the 20 most expensive pipelines at all. Compute GPU time per frame went from 0.94-1.12 s to 0.62-0.73 s, and the frame rate from 0.77-0.95 to about 1.15-1.2 frames/s, with no device stall or device loss in a 10-minute run. - The picture looks like the runs before it (same scene), so I can't say from screenshots alone whether the light binning output is now right; the guard cut point did change the picture in the runs that only lowered the limit. On reach: a separate scan over the 2684 library programs that taints registers dropped at a mask-to-data merge and follows them through copies and bitwise ops still flags 23 programs after `insert_data_merges` (mostly `s_bcnt1_i32_b64` of `s_and_b64 x, exec` chains, e.g. `lib_cs_01175` at 0xc00/0xc34, `lib_cs_02020` 0x5d94, `lib_cs_02587` 0x14cfc). That scan is cruder than yours and may over-count; I haven't checked those cases by hand. AI-assisted.
ammonium231 commented 2026-11-28 19:28:56 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by ammonium231 on 2026-11-28T19:28:56Z.


Heads-up: this and #1043 conflict in tools/lane_masks.py analyse() on current main (6b3d76df2), and this one also conflicts with main in docs/design.md. crosslane_fuzz, 2000 programs, seed 250100, RTX 3090: this PR gives 59/26 mismatches (wave32 native/wave64 emulate), same as main; #1043 + github.com/ammonium231/leonida@31fefc41e gives 0/0.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7244576594 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2501#issuecomment-7244576594). Originally posted by [ammonium231](https://github.com/ammonium231) on 2026-11-28T19:28:56Z. --- Heads-up: this and #1043 conflict in `tools/lane_masks.py` `analyse()` on current main (6b3d76df2), and this one also conflicts with main in `docs/design.md`. crosslane_fuzz, 2000 programs, seed 250100, RTX 3090: this PR gives 59/26 mismatches (wave32 native/wave64 emulate), same as main; #1043 + https://github.com/ammonium231/leonida/commit/31fefc41e gives 0/0.
azsekazvamdimitar commented 2026-11-28 21:42:23 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by azsekazvamdimitar on 2026-11-28T21:42:23Z.


Follow-up to my comment above: those boots ran with all native PSOs failing (a mistake in my shader folder layout, unrelated to this PR), so the frame rates there are not reliable. Re-measured with every native PSO created (RTX 3090, NVIDIA 590.48.01, Linux, GE-Proton, Series X).

In a set without this PR, lib_cs_03010 still costs 386-389 ms per dispatch (once a frame). In the set with this PR's translation of the library, it is gone from the top-20 GPU profile, and compute is 0.53-0.59 s per frame. With the library translated with this PR (together with --mesh-serial-waves and --compute-serial-waves), the game reaches 1.17-1.58 frames/s in world, with no device loss in two 10-minute boots and the same picture. The conclusion stands: this PR removes a loop that ran into the 65,536-iteration guard every frame. AI-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7246211757 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2501#issuecomment-7246211757). Originally posted by [azsekazvamdimitar](https://github.com/azsekazvamdimitar) on 2026-11-28T21:42:23Z. --- Follow-up to my comment above: those boots ran with all native PSOs failing (a mistake in my shader folder layout, unrelated to this PR), so the frame rates there are not reliable. Re-measured with every native PSO created (RTX 3090, NVIDIA 590.48.01, Linux, GE-Proton, Series X). In a set without this PR, lib_cs_03010 still costs 386-389 ms per dispatch (once a frame). In the set with this PR's translation of the library, it is gone from the top-20 GPU profile, and compute is 0.53-0.59 s per frame. With the library translated with this PR (together with `--mesh-serial-waves` and `--compute-serial-waves`), the game reaches 1.17-1.58 frames/s in world, with no device loss in two 10-minute boots and the same picture. The conclusion stands: this PR removes a loop that ran into the 65,536-iteration guard every frame. AI-assisted.
TheGeogeo commented 2026-11-29 04:50:16 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by TheGeogeo on 2026-11-29T04:50:16Z.


Checked 19f6f8e1b against main ef3299584 on Windows 11 10.0.26300: it does not merge (git merge-tree --write-tree), so I ran no tests.

  • Conflicts, both add/add:
    • docs/design.md: main reworded the "Whole-wave masks" row, and this PR adds its "Lane masks merged as data" row right after it.
    • tests/test_lane_masks.py: main added test_wave32_parked_lane_wraps_mod_32 (87fde5c8d, 2026-11-25) where this PR adds test_mask_meets_data_at_a_merge, and both are added to the same __main__ list.
  • Still needed (STALE, needs a rebase). main has no insert_data_merges / s_mask_to_data_b32. The rebase looks mechanical: keep both rows and both tests.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7250890931 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2501#issuecomment-7250890931). Originally posted by [TheGeogeo](https://github.com/TheGeogeo) on 2026-11-29T04:50:16Z. --- Checked `19f6f8e1b` against `main` `ef3299584` on Windows 11 10.0.26300: it does not merge (`git merge-tree --write-tree`), so I ran no tests. - Conflicts, both add/add: - `docs/design.md`: `main` reworded the "Whole-wave masks" row, and this PR adds its "Lane masks merged as data" row right after it. - `tests/test_lane_masks.py`: `main` added `test_wave32_parked_lane_wraps_mod_32` (`87fde5c8d`, 2026-11-25) where this PR adds `test_mask_meets_data_at_a_merge`, and both are added to the same `__main__` list. - Still needed (STALE, needs a rebase). `main` has no `insert_data_merges` / `s_mask_to_data_b32`. The rebase looks mechanical: keep both rows and both tests. AI-assisted (Claude Code).
aslan2142 commented 2026-12-01 11:56:38 +00:00 (Migrated from github.com)

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

Review: CHANGES_REQUESTED


Reviewed against current main: gathering a lane mask's bits where a merge takes it as data (tools/lane_masks.py, tools/rdna2spirv.py) looks well-tested, but this branch conflicts with main in tools/lane_masks.py and has failing CI. Please rebase onto current main so CI runs cleanly.

(AI-assisted review.)

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6130777704 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2501#pullrequestreview-6130777704). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T11:56:38Z. **Review:** CHANGES_REQUESTED --- Reviewed against current `main`: gathering a lane mask's bits where a merge takes it as data (`tools/lane_masks.py`, `tools/rdna2spirv.py`) looks well-tested, but this branch conflicts with `main` in `tools/lane_masks.py` and has failing CI. Please rebase onto current `main` so CI runs cleanly. *(AI-assisted review.)*
aslan2142 commented 2026-12-01 16:45:42 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T16:45:42Z.


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:7318176822 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2501#issuecomment-7318176822). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T16:45:42Z. --- 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!2501
No description provided.