shader: lower subgroup ballot find-lowest-bit in the SPIR-V bridge #1358
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1365"
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 R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T09:24:01Z.
Change
Lowers
OpGroupNonUniformBallotFindLSB %uint %scope %ballotin the named SPIR-V bridge profile (tools/spirv_ballot_extract.py), next to the existing ballot bit extraction. SPIRV-Cross cannot convert this operation to HLSL ("Cannot trivially implement BallotFindLSB in HLSL"), so a module that uses it did not reach DXC at all.Each of the four ballot words goes through GLSL
FindILsb, offset by 0, 32, 64 and 96. An empty word stays all ones and the smallest candidate wins, so an empty ballot gives0xffffffff. The lowering has no branches, loads or stores. It needs a Subgroup scope constant and a%uintresult (anything else is rejected or left alone), reuses an existingGLSL.std.450import or adds one, and keeps the reserved%x2w_ballot_ID check.AI-assisted. Related: the ballot bit extraction lowering (#656). No overlapping open PR touches these files.
Verification
python3 -B tests/spirv_window/ballot.py spirv-as spirv-val spirv-crosspasses on this branch and fails onorigin/mainwith the same tools (the find-lowest-bit operation is left unlowered).tests/spirv_window/{sampler,compare_sampler,check}.py,tests/docs_links_check.pyandtests/bidi_controls_check.pypass.spirv-val --target-env vulkan1.2and converts with SPIRV-Cross at shader models 60 and 66 (package 2021.01.15). The module also holds a bit extraction, so the two lowerings' constants are checked together.spirv_ballot_extract_warpin theprpreset. I ran the lowered SPIR-V in a small CPU interpreter instead: all 256 words match the bit-scan reference.Evidence and follow-up
The fixture is generated in the test from the existing ballot fixture's header, no external data. Thread i ballots bit i (128 positions, every word and bit 31/32 boundary) and, in a second output range, two bits at 5i+3 and 7i+11, with an empty ballot on every eighth thread (expected
0xffffffff). The reference scans the 128 bits one by one, independently of the lowering. The last 64 output words are sentinels and must stay untouched. The ballot operand is built from the thread index, so the result does not depend on the adapter's wave width.Negative controls, each compiled and run on the adapter, must be caught at their first differing word and with the predicted mismatch count: wrong offset (word 64, 58 words), swapped words (word 32, 115), highest instead of lowest bit (word 128, 24), no empty-word fill (word 64, 107). Counts come from a model of each faulty lowering and were reproduced by the CPU interpreter.
Rejection cases: Workgroup scope, a non-scope constant, a non-constant and an unknown scope ID raise; a non-
%uintresult is left unchanged; a used%x2w_ballot_ID raises.Checklist
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T09:29:19Z.
Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit
e99dfccdc13ef43edaeea5b21c66b4e976d6c458:--preset dev):ctest --preset dev -R '^spirv_ballot_extract_warp$' --no-tests=error --output-on-failure: 1/1 passed (0.90s)/O2(--preset release):ctest --preset release -R '^spirv_ballot_extract_warp$' --no-tests=error --output-on-failure: 1/1 passed (0.84s)Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T09:29:28Z.
Codex Review Summary: ✅ Completed
This comment shows the latest Codex review activity on this pull request.
e99dfccℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.