Translator: gather a lane mask's bits where a merge takes it as data (SHADER-WAVE-LOOP-EXEC-VOTE) #2501
Closed
leonida/mandy
Tyrannys wants to merge 0 commits from
claude/wave-loop-exec-vote into main
pull from: claude/wave-loop-exec-vote
merge into: leonida:main
leonida:main
leonida:github-pr/3295
leonida:beta
leonida:docs/changelog-3483-3500
leonida:github-pr/3294
leonida:github-pr/2975
leonida:github-pr/2815
leonida:feat/gate-driver-start
leonida:feat/skip-pipelines-release
leonida:perf/lazy-compare
leonida:perf/mwaitx-wait
leonida:test/prio-ceiling-main
leonida:fix/ab-cpu-stdout
leonida:fix/gate-old-crashes
leonida:diag/ab-cpu
leonida:test/main-0312
leonida:github-pr/3291
leonida:diag/indirect-clamp-census
leonida:feat/barrier-enhanced
leonida:perf/texture-frame-ceiling
leonida:perf/dstorage-threads
leonida:fix/console-queue-dma-tables
leonida:fix/port-descriptors-record-parts
leonida:fix/frame-waits-fence
leonida:fix/console-sampler-words
leonida:fix/graphics-userdata-spill
leonida:fix/xg-reserved-layout-rotation
leonida:fix/barrier-console-flags
leonida:fix/switches-wait-test-child
leonida:test/list-value-waits
leonida:test/lot-gxdk-0412
leonida:fix/bvh-compacted-size
leonida:docs/i18n-quickstarts
leonida:feat/native-pipeline-slots
leonida:fix/clippy-leonida-gpu
leonida:fix/list-value-producers
leonida:fix/descriptor-page-straddle
leonida:fix/xmem-low-window
leonida:fix/ffx-jitter-never-zero
leonida:fix/run-stdout-closed
leonida:github-pr/2892
leonida:github-pr/2896
leonida:feat/warm-save-every
leonida:github-pr/2980
leonida:github-pr/2994
leonida:github-pr/3005
leonida:github-pr/3010
leonida:github-pr/3136
leonida:github-pr/3303
leonida:github-pr/3220
leonida:github-pr/3143
leonida:github-pr/3330
leonida:github-pr/3226
leonida:github-pr/3187
leonida:carry/3395
leonida:github-pr/2946
leonida:github-pr/2947
leonida:github-pr/2945
leonida:github-pr/2983
leonida:github-pr/3001
leonida:github-pr/3372
leonida:github-pr/3128
leonida:github-pr/3296
leonida:github-pr/2588
leonida:github-pr/3119
leonida:github-pr/3378
leonida:fix/crash-diagnostics
leonida:feat/dlss-mip-bias
leonida:fix/retired-out-of-order
leonida:fix/dxr-postbuild-barrier
leonida:fix/amd-relay-default
leonida:fix/removed-report-wait
leonida:feat/heap-twin
leonida:feat/vram-margin
leonida:github-pr/2472
leonida:github-pr/3123
leonida:github-pr/3088
leonida:assets/annonce-v1
leonida:github-pr/2794
leonida:github-pr/3300
leonida:github-pr/3304
leonida:github-pr/3308
leonida:github-pr/3367
leonida:github-pr/3369
leonida:fix/launcher-dlss-diagnostics
leonida:github-pr/3269
leonida:github-pr/2957
leonida:github-pr/3205
leonida:fix/crash-zero-guard
leonida:github-pr/3185
leonida:github-pr/3099
leonida:github-pr/3104
leonida:github-pr/3348
leonida:github-pr/3379
leonida:github-pr/3377
leonida:perf/darner-title-priority-ceiling
leonida:github-pr/3376
leonida:gh-readonly-queue/main/pr-3311-b5c45b663dbc5a9c3532bb3f307e5f81b32faefa
leonida:gh-readonly-queue/main/pr-3088-af22e7847ff5808f72d1a1881c24be2fafd20b54
leonida:gh-readonly-queue/main/pr-3123-7f3fa026a94c6646e89244f28e1ce22290361867
leonida:github-pr/3373
leonida:github-pr/3368
leonida:github-pr/3198
leonida:gh-readonly-queue/main/pr-3354-637baa0b77ba47222e7280b17c1a59c6a1781d57
leonida:gh-readonly-queue/main/pr-3365-d7a0e0196a43834813014b4bd3aa5502a8263b14
leonida:gh-readonly-queue/main/pr-3361-5dfe8bbd05ed12fb2f2e1718d9af77a7c5f46fd8
leonida:gh-readonly-queue/main/pr-3366-8da9148204e9d12c585efa9ac2b7cc1ab08c7682
leonida:github-pr/3346
leonida:github-pr/3375
leonida:github-pr/2958
leonida:github-pr/3151
leonida:github-pr/3307
leonida:github-pr/3278
leonida:github-pr/3374
leonida:fix/runtime-test-conservative-fixtures
leonida:github-pr/3366
leonida:ci/shard-semantic-linux
leonida:github-pr/3354
leonida:docs/fg-limit-fps-switch
leonida:github-pr/3365
leonida:fix/read-file-hard-link
leonida:github-pr/3364
leonida:fix/book-slot-heap-never-read
leonida:github-pr/3361
leonida:github-pr/3263
leonida:github-pr/3360
leonida:github-pr/3353
leonida:github-pr/3331
leonida:fix/alias-later-queued-submissions
leonida:github-pr/3352
leonida:github-pr/3228
leonida:github-pr/3349
leonida:claude/gallant-sagan-aamatr
leonida:github-pr/3200
leonida:github-pr/3132
leonida:github-pr/3323
leonida:github-pr/3332
leonida:github-pr/3340
leonida:github-pr/3311
leonida:github-pr/3334
leonida:github-pr/3297
leonida:github-pr/3256
leonida:github-pr/2567
leonida:github-pr/2851
leonida:d3d12/agility-sdk-621
leonida:github-pr/3164
leonida:github-pr/3114
leonida:github-pr/3050
leonida:github-pr/3113
leonida:github-pr/3326
leonida:github-pr/3144
leonida:github-pr/2642
leonida:github-pr/3072
leonida:github-pr/2789
leonida:github-pr/2643
leonida:github-pr/3009
leonida:github-pr/3035
leonida:github-pr/3031
leonida:github-pr/2686
leonida:github-pr/2834
leonida:github-pr/3321
leonida:github-pr/3325
leonida:github-pr/3290
leonida:github-pr/3324
leonida:github-pr/3130
leonida:claude/fervent-curie-m19lnr
leonida:github-pr/3309
leonida:github-pr/3305
leonida:github-pr/3306
leonida:github-pr/3302
leonida:github-pr/3301
leonida:github-pr/3345
leonida:github-pr/3211
leonida:github-pr/3027
leonida:github-pr/3286
leonida:github-pr/3235
leonida:github-pr/3265
leonida:github-pr/3275
leonida:codex/skip-no-hit-ray-passes
leonida:github-pr/2823
leonida:github-pr/2911
leonida:github-pr/3262
leonida:github-pr/3125
leonida:github-pr/3206
leonida:github-pr/3250
leonida:github-pr/3238
leonida:github-pr/3188
leonida:github-pr/2952
leonida:github-pr/3217
leonida:github-pr/3168
leonida:t3/preserve-fsr-sdk-restart-path
leonida:t3/propagate-host-failure-hresult
leonida:github-pr/3209
leonida:t3/launcher-custom-parameters
leonida:github-pr/3207
leonida:github-pr/3183
leonida:github-pr/3160
leonida:github-pr/3201
leonida:ci/less-to-run
leonida:github-pr/2930
leonida:github-pr/2797
leonida:github-pr/2999
leonida:perf/native-compute-shader-forms
leonida:github-pr/3191
leonida:github-pr/3011
leonida:github-pr/3019
leonida:github-pr/2996
leonida:gh-readonly-queue/main/pr-2789-45dc41f95c1cd0dcc29c2c50582e0e9af8a77259
leonida:claude/blissful-franklin-ukp7ag
leonida:github-pr/3141
leonida:github-pr/3156
leonida:github-pr/3150
leonida:github-pr/3153
leonida:github-pr/3163
leonida:github-pr/3142
leonida:github-pr/3139
leonida:github-pr/2841
leonida:github-pr/3069
leonida:github-pr/3098
leonida:github-pr/3107
leonida:github-pr/3071
leonida:github-pr/2774
leonida:github-pr/2889
leonida:github-pr/3075
leonida:github-pr/2661
leonida:github-pr/3064
leonida:github-pr/3054
leonida:github-pr/3049
leonida:github-pr/2855
leonida:github-pr/2943
leonida:github-pr/3016
leonida:github-pr/2887
leonida:github-pr/3006
leonida:github-pr/3003
leonida:github-pr/2993
leonida:notes/card-time-and-plant-flicker
leonida:github-pr/2989
leonida:feat/vulkan-rs
leonida:github-pr/2985
leonida:github-pr/2951
leonida:github-pr/2982
leonida:github-pr/752
leonida:github-pr/792
leonida:github-pr/2877
leonida:github-pr/2654
leonida:github-pr/2893
leonida:github-pr/2948
leonida:github-pr/2944
leonida:github-pr/2919
leonida:github-pr/2915
leonida:archive/ci/less-to-run/20261202T1121Z
leonida:github-pr/2800
leonida:github-pr/2822
leonida:github-pr/2833
leonida:github-pr/2840
leonida:github-pr/2831
leonida:github-pr/2832
leonida:github-pr/2801
leonida:github-pr/2890
leonida:github-pr/2891
leonida:github-pr/2664
leonida:github-pr/2807
leonida:rt-call-trace
leonida:github-pr/2755
leonida:perf/ahead-split
leonida:github-pr/2587
leonida:github-pr/2698
leonida:github-pr/2609
leonida:github-pr/3219
leonida:docs/readme-runtime-proposal
leonida:github-pr/2017
leonida:github-pr/1741
leonida:github-pr/1667
leonida:codex/coord-claim-check-20261124-7e48
No reviewers
Assignees
Clear assignees
No assignees
Labels
Clear labels
bug
Something isn't working
dependencies
Pull requests that update a dependency file
documentation
Improvements or additions to documentation
enhancement
New feature or request
missing claim
Needs a claim in #14
needs rebase
Conflicts with the base branch: rebase it on main
needs-triage
Needs maintainer evaluation before the next triage state
question
Further information is requested
ready-for-agent
Fully specified and ready for an AFK agent
submodules
Pull requests that update submodules code
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
Projects
Clear projects
No items
No project
Milestone
Clear milestone
No items
No milestone
Dependencies
No dependencies set
Notifications
1 participant
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".
No due date set.
Reference
leonida/mandy!2501
Loading…
Reference in a new issue
No description provided.
Delete branch "claude/wave-loop-exec-vote"
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?
Pull request closed
This pull request cannot be reopened because the branch was deleted.
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
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 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 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.
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.
@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_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).
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.
@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).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.
@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).Full translator semantic suite on 4adc6815a: 503 files, 6389 tests, 0 failed. AI-assisted (Claude Code).
#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)
main02f71ccfe7;scripts/check_no_game_data.pypassed (0).4adc6815afc3.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:
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).
@DadaCap thank you for the review. Both points:
docs/design.mdcontract row: in 19f6f8e1b on 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).
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).
@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).
In-game check of this branch on NVIDIA, for the record:
--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.
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.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.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).
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.