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
pull from: upstream-pr/2501
merge into: ProjectLeonida:main
ProjectLeonida:main
ProjectLeonida:claude/loop-total
ProjectLeonida:claude/pops-collision-seed
ProjectLeonida:claude/dstorage-hold-page-reads
ProjectLeonida:claude/host-image-copy-switch
ProjectLeonida:feat/gdk-lifecycle-window-hook
ProjectLeonida:claude/d16s8-uav-nvidia-fallback
ProjectLeonida:feat/mfplat-offline-shim
ProjectLeonida:claude/gameinput-slow-reader
ProjectLeonida:fix/rt-null-barrier-clear
ProjectLeonida:claude/depth-resolve-sample-positions
ProjectLeonida:integration/palmetto-parity
ProjectLeonida:claude/valu-literal-sext
ProjectLeonida:claude/slot74-pool-handle
ProjectLeonida:claude/rgb9e5-uint-alias-view
ProjectLeonida:claude/fssm-root-layout-tables
ProjectLeonida:feat/gdk-speech-display-lifecycle
ProjectLeonida:asset-audio-skip-current
ProjectLeonida:qemmhd/old-9940-rectangle-quad-lists
ProjectLeonida:feat/ws2-offline-shim
ProjectLeonida:qemmhd/rt-d16-unorm-uav
ProjectLeonida:feat/xs-device-stops-7-9
ProjectLeonida:qemmhd/rt-depth-same-base-shapes
ProjectLeonida:qemmhd/rt-lazy-attachment-variant
ProjectLeonida:feat/acphal-xma2-decoder
ProjectLeonida:asset-audio-skip
ProjectLeonida:codex/coord-claim-check-20261124-7e48
ProjectLeonida:feat/xs-frame-pacing-presentx
ProjectLeonida:feat/xs-device-vm-options
ProjectLeonida:old-pr/9844
ProjectLeonida:old-pr/9978
ProjectLeonida:old-pr/9815
ProjectLeonida:old-pr/10057
ProjectLeonida:old-pr/9874
ProjectLeonida:old-pr/9965
ProjectLeonida:old-pr/9863
ProjectLeonida:old-pr/10068
ProjectLeonida:old-pr/10066
ProjectLeonida:old-pr/10067
ProjectLeonida:old-pr/10007
ProjectLeonida:old-pr/10061
ProjectLeonida:old-pr/10065
ProjectLeonida:old-pr/10059
ProjectLeonida:old-pr/10063
ProjectLeonida:old-pr/10055
ProjectLeonida:old-pr/10062
ProjectLeonida:old-pr/10042
ProjectLeonida:old-pr/10041
ProjectLeonida:old-pr/10049
ProjectLeonida:old-pr/10047
ProjectLeonida:old-pr/10046
ProjectLeonida:old-pr/10045
ProjectLeonida:old-pr/10056
ProjectLeonida:old-pr/10043
ProjectLeonida:old-pr/10036
ProjectLeonida:old-pr/10034
ProjectLeonida:old-pr/9984
ProjectLeonida:old-pr/10052
ProjectLeonida:old-pr/10038
ProjectLeonida:old-pr/10033
ProjectLeonida:old-pr/10028
ProjectLeonida:old-pr/10050
ProjectLeonida:old-pr/9891
ProjectLeonida:old-pr/9889
ProjectLeonida:old-pr/10051
ProjectLeonida:old-pr/10019
ProjectLeonida:old-pr/10027
ProjectLeonida:old-pr/10029
ProjectLeonida:old-pr/10031
ProjectLeonida:old-pr/10026
ProjectLeonida:old-pr/9941
ProjectLeonida:old-pr/10030
ProjectLeonida:old-pr/10040
ProjectLeonida:old-pr/9990
ProjectLeonida:old-pr/10021
ProjectLeonida:old-pr/9962
ProjectLeonida:old-pr/10022
ProjectLeonida:old-pr/10020
ProjectLeonida:old-pr/10015
ProjectLeonida:old-pr/10025
ProjectLeonida:old-pr/9886
ProjectLeonida:old-pr/10048
ProjectLeonida:old-pr/10014
ProjectLeonida:old-pr/10011
ProjectLeonida:old-pr/9861
ProjectLeonida:old-pr/10010
ProjectLeonida:old-pr/10008
ProjectLeonida:old-pr/9860
ProjectLeonida:old-pr/10006
ProjectLeonida:old-pr/9920
ProjectLeonida:old-pr/9995
ProjectLeonida:old-pr/10000
ProjectLeonida:old-pr/10016
ProjectLeonida:old-pr/10004
ProjectLeonida:old-pr/10023
ProjectLeonida:old-pr/9982
ProjectLeonida:old-pr/9981
ProjectLeonida:old-pr/9983
ProjectLeonida:old-pr/9970
ProjectLeonida:old-pr/9969
ProjectLeonida:old-pr/9968
ProjectLeonida:old-pr/9971
ProjectLeonida:old-pr/9972
ProjectLeonida:old-pr/9942
ProjectLeonida:old-pr/9963
ProjectLeonida:old-pr/9960
ProjectLeonida:old-pr/9964
ProjectLeonida:old-pr/9985
ProjectLeonida:old-pr/9973
ProjectLeonida:old-pr/9862
ProjectLeonida:old-pr/9953
ProjectLeonida:old-pr/10017
ProjectLeonida:old-pr/9952
ProjectLeonida:old-pr/9955
ProjectLeonida:old-pr/9946
ProjectLeonida:old-pr/9954
ProjectLeonida:old-pr/9938
ProjectLeonida:old-pr/9956
ProjectLeonida:old-pr/9856
ProjectLeonida:old-pr/9947
ProjectLeonida:old-pr/9924
ProjectLeonida:old-pr/9961
ProjectLeonida:old-pr/9927
ProjectLeonida:old-pr/9979
ProjectLeonida:old-pr/10032
ProjectLeonida:old-pr/9926
ProjectLeonida:old-pr/5237
ProjectLeonida:old-pr/9951
ProjectLeonida:old-pr/9931
ProjectLeonida:old-pr/9902
ProjectLeonida:old-pr/9921
ProjectLeonida:old-pr/9994
ProjectLeonida:old-pr/9775
ProjectLeonida:old-pr/9768
ProjectLeonida:old-pr/9905
ProjectLeonida:old-pr/9936
ProjectLeonida:old-pr/9901
ProjectLeonida:old-pr/9904
ProjectLeonida:old-pr/9906
ProjectLeonida:old-pr/9988
ProjectLeonida:old-pr/9908
ProjectLeonida:old-pr/9909
ProjectLeonida:old-pr/9911
ProjectLeonida:old-pr/9912
ProjectLeonida:old-pr/9913
ProjectLeonida:old-pr/9887
ProjectLeonida:old-pr/9916
ProjectLeonida:old-pr/9919
ProjectLeonida:old-pr/9925
ProjectLeonida:old-pr/9933
ProjectLeonida:old-pr/9935
ProjectLeonida:old-pr/9918
ProjectLeonida:old-pr/9879
ProjectLeonida:old-pr/9880
ProjectLeonida:old-pr/9881
ProjectLeonida:old-pr/9996
ProjectLeonida:old-pr/9876
ProjectLeonida:old-pr/9892
ProjectLeonida:old-pr/9899
ProjectLeonida:old-pr/9915
ProjectLeonida:old-pr/9914
ProjectLeonida:old-pr/9872
ProjectLeonida:old-pr/9869
ProjectLeonida:old-pr/9866
ProjectLeonida:old-pr/9819
ProjectLeonida:old-pr/10012
ProjectLeonida:old-pr/9857
ProjectLeonida:old-pr/9893
ProjectLeonida:old-pr/9897
ProjectLeonida:old-pr/9928
ProjectLeonida:old-pr/9868
ProjectLeonida:old-pr/9917
ProjectLeonida:old-pr/9940
ProjectLeonida:old-pr/9873
ProjectLeonida:old-pr/9816
ProjectLeonida:old-pr/10009
ProjectLeonida:old-pr/9900
ProjectLeonida:old-pr/9966
ProjectLeonida:old-pr/9859
ProjectLeonida:old-pr/9843
ProjectLeonida:old-pr/9991
ProjectLeonida:old-pr/10058
ProjectLeonida:old-pr/9883
ProjectLeonida:old-pr/9838
ProjectLeonida:old-pr/9835
ProjectLeonida:old-pr/9959
ProjectLeonida:old-pr/9895
ProjectLeonida:old-pr/9837
ProjectLeonida:old-pr/9858
ProjectLeonida:old-pr/9865
ProjectLeonida:old-pr/9864
ProjectLeonida:old-pr/9840
ProjectLeonida:old-pr/9820
ProjectLeonida:old-pr/4669
ProjectLeonida:old-pr/9848
ProjectLeonida:old-pr/9850
ProjectLeonida:old-pr/9810
ProjectLeonida:old-pr/9799
ProjectLeonida:old-pr/9853
ProjectLeonida:old-pr/9875
ProjectLeonida:old-pr/9831
ProjectLeonida:old-pr/9796
ProjectLeonida:old-pr/9801
ProjectLeonida:old-pr/9813
ProjectLeonida:old-pr/9794
ProjectLeonida:old-pr/7417
ProjectLeonida:old-pr/9781
ProjectLeonida:old-pr/9806
ProjectLeonida:old-pr/9958
ProjectLeonida:old-pr/9809
ProjectLeonida:old-pr/9791
ProjectLeonida:old-pr/9792
ProjectLeonida:old-pr/10053
ProjectLeonida:old-pr/9784
ProjectLeonida:old-pr/9789
ProjectLeonida:old-pr/9849
ProjectLeonida:old-pr/9846
ProjectLeonida:old-pr/9773
ProjectLeonida:old-pr/9785
ProjectLeonida:old-pr/9803
ProjectLeonida:old-pr/9826
ProjectLeonida:old-pr/9839
ProjectLeonida:old-pr/9922
ProjectLeonida:old-pr/9948
ProjectLeonida:old-pr/7189
ProjectLeonida:old-pr/9957
ProjectLeonida:old-pr/9823
ProjectLeonida:old-pr/9807
ProjectLeonida:old-pr/9851
ProjectLeonida:old-pr/9774
ProjectLeonida:old-pr/9830
ProjectLeonida:old-pr/9836
ProjectLeonida:old-pr/9822
ProjectLeonida:old-pr/9783
ProjectLeonida:old-pr/9833
ProjectLeonida:old-pr/9890
ProjectLeonida:old-pr/9770
ProjectLeonida:old-pr/9769
ProjectLeonida:old-pr/9772
ProjectLeonida:old-pr/9787
ProjectLeonida:old-pr/9852
ProjectLeonida:old-pr/9834
ProjectLeonida:old-pr/9845
ProjectLeonida:old-pr/9871
ProjectLeonida:old-pr/9771
ProjectLeonida:old-pr/9776
ProjectLeonida:old-pr/10005
ProjectLeonida:old-pr/9949
ProjectLeonida:old-pr/9923
ProjectLeonida:old-pr/9805
ProjectLeonida:old-pr/9829
ProjectLeonida:old-pr/9790
ProjectLeonida:old-pr/9827
ProjectLeonida:old-pr/9929
ProjectLeonida:old-pr/9855
ProjectLeonida:old-pr/9934
ProjectLeonida:old-pr/9907
ProjectLeonida:old-pr/9910
ProjectLeonida:old-pr/9779
ProjectLeonida:old-pr/9780
ProjectLeonida:old-pr/9885
ProjectLeonida:old-pr/9882
ProjectLeonida:old-pr/9877
ProjectLeonida:old-pr/9998
ProjectLeonida:old-pr/4251
ProjectLeonida:old-pr/9987
ProjectLeonida:old-pr/9989
ProjectLeonida:old-pr/9950
ProjectLeonida:old-pr/9777
ProjectLeonida:old-pr/10044
ProjectLeonida:old-pr/9884
ProjectLeonida:old-pr/2906
ProjectLeonida:old-pr/5076
ProjectLeonida:old-pr/9937
ProjectLeonida:old-pr/9986
ProjectLeonida:old-pr/3014
ProjectLeonida:old-pr/9943
ProjectLeonida:old-pr/9939
ProjectLeonida:old-pr/4682
ProjectLeonida:old-pr/4765
No reviewers
Labels
Clear labels
No items
No labels
Milestone
Clear milestone
No items
No milestone
Assignees
Clear assignees
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
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2501"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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.pyworks 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:
On the first pass each lane found its own first bit and took its own number of passes, where the wave takes one:
--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_mergesadds a new translator-only instruction,s_mask_to_data_b32 sN, sN. It goes before a block's branch when:s_ff0/s_ff1/s_bcnt0/s_bcnt1/s_flbit, also through scalar copies and bitwise ops of it (thes_xor_b32into a register moved back on the back edge).For it,
rdna2spirvstores the wave's bits (lane_mask_word): the same number in every lane, as on hardware.wave64_emulate_optcounts 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_cndmaskmask) 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-emulatetranslation 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
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 whenv_cmpx_le+s_andn2_b64 saved, saved, execleaves no lane. Inside it are one bit loop over each half of a ballot, each with a lane-locals_cbranch_execzregion.--wave64-emulateon 32-wide subgroups (structured), and--wave64-emulatewith the round scheduler.main, all 3 native runs fail withSubgroupDivergenceError, and the emulated runs give wrong per-lane counts (for example 64 visits where 32 are expected).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.scripts/run_semantic_tests.py tests/semantic: 503 files, 6389 tests, 0 failed.GPUs tested: n/a (CPU interpreter).
AI-assisted: yes (Claude Code)
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).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
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 onlylib_cs_03010with--wave64-emulate; everything else in the run is unchanged.lib_cs_03010translated withSo 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 main43a9d562d: 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 reachess_ff1/ff0/bcnt/flbitbefore 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.
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_03010translated withNo 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.
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
660f609d9and uses your narrower condition. It gathers only where the merged register can reachs_ff0/s_ff1/s_bcnt0/s_bcnt1/s_flbitbefore it is overwritten. The one difference: it also follows scalar copies and bitwise ops of the register (thes_xor_b32into a register that the back edge moves back). Where a merged register is only read as a mask again (EXEC, an AND with it, av_cndmaskmask), each lane's 0 / ~0 already gives the right bit. A new test shows that case exact with no gather.On my local
--wave64-emulatetranslation this changes 31 of 2,684 library programs and nothing outside the library. Inlib_cs_03010the 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).
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_03010andlib_cs_03012: with this PR'stools/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 inlib_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:lib_cs_03010in the profiler's rowsNone 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.
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_03010andlib_cs_03012byte-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).Imported from ubiquitarianism/leonida. Originally posted by timbot103 on 2026-11-28T00:53:24Z.
Independently checked head
660f609d9on Windows 11 Pro 26200, Vulkan SDK1.4.363.0, WSLllvm-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.scripts/run_gpu_tests.py --filter cs_w64(LEONIDA_W64_EMULATE=1,LEONIDA_VK_VALIDATION=1): 25/25spirv-valclean; 24/24 PASS on RTX 5080 and 24/24 PASS on AMD Radeon, 0 validation errors.Static code review notes:
tools/lane_masks.py(converting only when every successor consumes the mask as data and some successor numerically scans it vias_ff0/ff1,s_bcnt0/1,s_flbit, with conservatives_movrelshandling and SCC-preserving placement before the terminator) is cleanly structured and guaranteed to terminate.step()treatss_mask_to_data_b32as producing data (not a mask copy) so repeated passes cannot insert duplicates; a unit test asserting a secondinsert_data_mergescall returns0would pin idempotence.s[26:27]), add a wave64 test verifying the high half (s27/s_bcnt1_i32_b64ors_ff1_i32_b64) gathers lanes 32–63 properly.--wave64-emulategather barrier round relies on blocks being reached via wave-uniform scalar branches.Overall looks clean and well-tested. AI-assisted.
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:step()now namess_mask_to_data_b32explicitly as writing data. It already took the default data path, so nothing changes in what it produces.tests/test_lane_masks.pyasserts that a secondinsert_data_mergescall returns 0, for the bit loop and for each diamond case.s_bcnt1_i32_b64ands_ff1_i32_b64ofs[6:7]) gathers boths6ands7, so lanes 32-63 come from the high half.tests/semantic/test_ballot_bit_loop.pyalready runs the high half end to end (lanes 32-63 throughs27), natively and emulated.--wave64-emulatethe gather is an exchange round that relies on its block being reached by the whole wave through scalar branches, and thatwave64_emulate_optkeeps it out of lane-local regions.tests/test_lane_masks.pyandtest_ballot_bit_loop.pypass; the full semantic suite is still running here, and I will note the result. AI-assisted (Claude Code).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).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 main02f71ccfe7: 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)main02f71ccfe7;scripts/check_no_game_data.pypassed (0).4adc6815afc3.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 mainb1619e0a3/6dfca6428, Windows 11, Python tests via pytest/unittest) we found:lane_masks.py(the same step/analyse areas,Gen.insnand thewave64_emulate_opttable), reimplements theanalyse()fixpoint, and thedocs/design.mdcontract row is missing.To get this merged:
analyse()instead of a second fixpoint.docs/design.mdcontract row with how it was confirmed.AI-assisted (Claude Code), posted for DadaCap (maintainer).
Imported from ubiquitarianism/leonida. Originally posted by Tyrannys on 2026-11-28T08:35:14Z.
@DadaCap thank you for the review. Both points:
docs/design.mdcontract row: in19f6f8e1bon this branch ("Lane masks merged as data"). It says whats_mask_to_data_b32does and whereinsert_data_mergesputs it, why only bit scans get the gather, and how it was confirmed: the synthetic repro intests/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.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
4d58a05d6with this branch merged in.analyse()'s entry-state loop is nowlane_masks.entry_states(blocks, succ, wave64=, moves=).analyse()calls it, and so doesinsert_data_merges, so_fixpointand_mergeare gone. Thestep()andwave64_emulate_optchanges sit next to #1043's:s_mask_to_data_b32writes data instep()before #1043'smoveshandling, and it stays a_MASK_WORD_READERSentry beside #1043'smask_wordschecks.insert_data_mergesruns beforeGenworks out #1043'smoves. Those only change VGPR kinds, so the SGPRs it converts are the same.tests/test_lane_masks.pyok,test_ballot_bit_loop2/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).
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.8llvm-mc, Vulkan SDK1.4.363.1spirv-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, includingtest_a_merged_mask_used_as_a_mask_needs_no_gatherandtest_every_lane_walks_the_wave_ballotacrossnative64,emulate_sg32, andemulate_sg32_roundsfor counts 100, 200, and 7).python -I scripts/check_no_game_data.py: clean.Review notes
lane_masks.insert_data_mergescleanly restrictss_mask_to_data_b32insertion 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_READERSincludess_mask_to_data_b32so emulated wave64 exchange rounds stay out of lane-local regions, and thedocs/design.mdcontract row matches the implementation.AI-assisted (Antigravity, Gemini).
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 sharedlane_masks.entry_states()fixpoint. I'll say so here when that happens.AI-assisted (Claude Code).
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:
493867366plus #2566, #2391 and #1086 (with a local fallback that makes #2566's arena one allocation on this card), shaders translated with--wave64-emulateand--mesh-serial-waves. #2501 was merged onto that base (onlytools/lane_masks.pyconflicted, both sides kept) and onlylib_cs_03010was retranslated with it.lib_cs_03010costs 368-401 ms per dispatch (one 5x5x30 dispatch a frame). Swapping the loop guard limit per loop showed loop 4 (thes_ff1_i32_b32 s32, s26bit 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.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(mostlys_bcnt1_i32_b64ofs_and_b64 x, execchains, e.g.lib_cs_01175at 0xc00/0xc34,lib_cs_020200x5d94,lib_cs_025870x14cfc). That scan is cruder than yours and may over-count; I haven't checked those cases by hand.AI-assisted.
Imported from ubiquitarianism/leonida. Originally posted by ammonium231 on 2026-11-28T19:28:56Z.
Heads-up: this and #1043 conflict in
tools/lane_masks.pyanalyse()on current main (6b3d76df2), and this one also conflicts with main indocs/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@31fefc41egives 0/0.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-wavesand--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.Imported from ubiquitarianism/leonida. Originally posted by TheGeogeo on 2026-11-29T04:50:16Z.
Checked
19f6f8e1bagainstmainef3299584on Windows 11 10.0.26300: it does not merge (git merge-tree --write-tree), so I ran no tests.docs/design.md:mainreworded the "Whole-wave masks" row, and this PR adds its "Lane masks merged as data" row right after it.tests/test_lane_masks.py:mainaddedtest_wave32_parked_lane_wraps_mod_32(87fde5c8d, 2026-11-25) where this PR addstest_mask_meets_data_at_a_merge, and both are added to the same__main__list.mainhas noinsert_data_merges/s_mask_to_data_b32. The rebase looks mechanical: keep both rows and both tests.AI-assisted (Claude Code).
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 withmainintools/lane_masks.pyand has failing CI. Please rebase onto currentmainso CI runs cleanly.(AI-assisted review.)
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.Pull request closed