shader: lower masked bit counts in small startup compute groups #2282
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2290"
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 RavenCurseBurg on 2026-11-25T10:16:27Z.
Refs #2274, item A, uniform-mask
v_mbcntin the startup compute translator. This uses the small-group constraint established for the offline tool in #1782.In a compute group of at most 32 threads,
v_mbcnt_lo_u32_b32counts set mask bits strictly below the flat local lane and adds the base modulo 2³².v_mbcnt_hi_u32_b32copies the base. The mask must be literal or a proven constant SGPR. The base can also be a VGPR. EXEC predicates the destination write. The tests include refusals for larger groups, vector and run-time masks, EXEC/VCC interpretations, an unknown scalar base, modifiers and other stages.Verification
Head
be690e82. LLVM 15.0.7 assembled both 128-byte gfx1013 kernels and all seven encoded negative inputs from the included source. The original startup translator refused the firstv_mbcnt_lo_u32_b32. The fixture uses two 4×2×4 groups, sparse mask0x85241249, bases 7 and UINT_MAX, and an all-ones mask read with only lanes 16–31 active. The CPU model accumulates one mask bit at a time and also checks the 64 untouched words.python -B tests/startup_gfx2hlsl_compute_check.py dispatch <dxc> <offscreen_check> <backend>matched all 320 words in A, B, C, D and D-wrap on both WARP and a GeForce RTX 4060. Windows build 26100.9711, WARP driver 10.0.26100.9711, NVIDIA driver 32.0.15.9579. The local debug layer was unavailable.python -B tests/startup_gfx2hlsl_compute_check.py control mbcnt <dxc> <offscreen_check> <backend>detected all six mutations on each device. Ignoring the sparse mask, counting the entire mask, using only X, dropping the base, adding low bits in the high instruction, and writing an inactive destination failed first at words 8, 0, 16, 0, 5 and 2 respectively. The check pins each expected and actual word.python -B tools/startup/gfx2hlsl.py --pending <cache>path produced the same HLSL and manifest for the two synthetic requests. Each actual CSO matched all 320 output words on both devices.python -B tools/run_checks_parallel.py tests/startup_gfx2hlsl_compute_check.py tests/startup_compute_translate_check.py tests/startup_gfx2hlsl_loop_constants_check.py tests/startup_gfx2hlsl_readfirstlane_uniform_check.py tests/startup_compute_gather_lz_check.py tests/docs_links_check.py tests/bidi_controls_check.pypassed 7/7.git diff --check origin/main...HEADpassed.The clean Windows build and WARP run at this head passed all three selected CTests. With the D3D12 debug layer enabled, each of the five positive cases and six negative controls reported zero errors and zero warnings.
To repeat the registered checks, build
offscreen_checkthen runctest --preset release --no-tests=error -R '^startup_gfx2hlsl_compute_(controls|(mbcnt_)?(warp|hardware))$' -V.The assembly and CPU references are synthetic repository fixtures under the MIT license. AI-assisted with Codex.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T10:20:14Z.
Review: COMMENTED
Review of head
be690e82a2a137d6003f92e920293ba6c3b4b963(comment only).Summary: The lowering looks correct for the stated constraint, and I found no P1 or P2 issues. One nit and two notes are below.
Checked by reading
tools/startup/gfx2hlsl.py(op_v_mbcnt_lo_u32_b32)tid.x + X*(tid.y + Y*tid.z). With XYZ <= 32 the shift is at most 31, so(1u << lane) - 1uis defined and covers lane 31._locounts mask bits strictly below the lane and adds the base modulo 2^32._hicopies the base, which is correct when every thread is in the low half of a wave32 or wave64.cs. Modifiers, wrong operand count, non-VGPR or multi-register destinations, and unknown masks are refused. The base must be a VGPR or a constant.Commands executed locally in a worktree at that head
python3 -B tests/startup_gfx2hlsl_compute_check.pypassed: "compute entry, numthreads, masked bit counts, manifest, offen store forms and the store, descriptor, execz and sample refusals pass".python3 tests/docs_links_check.pypassed (18 files, 437 links).python3 tests/bidi_controls_check.pypassed (1579 files).git diff --check origin/main...HEADwas clean.Mutation (local, reverted with
git checkout -- .)((1u << lane) - 1u)to((2u << lane) - 1u), which counts the lane itself. The Linux check still passed.&between the mask and the lane bound to|. The Linux check still passed.control mbcntanddispatchruns kill the mutations. I did not rerun Windows. Please make sure the Windows CI job or the Win2025 run confirms thatstartup_gfx2hlsl_compute_mbcnt_*and the dispatch tests actually ran and were not skipped (they useSKIP_RETURN_CODE 77).Findings
_hirequires a known mask (const_u32(ops[1])) even though the mask is unused. Hardware accepts any mask for_hiin this group size. The extra refusal is safe, but it is stricter than needed. Either relax it or add a short comment saying it is intentional.tools/startup/gfx2hlsl.py, around themask = self.const_u32(ops[1])line.README.mdrow'sctest -Rpattern uses\|inside a Markdown table cell. Check that it renders as|and that it matches the newstartup_gfx2hlsl_compute_mbcnt_*names.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T10:30:06Z.
Review: COMMENTED
Re-review of head
8a689dcdbabcb1aabf55619807db88906c408639(comment only). Previous review was onbe690e82.Summary: No P1 or P2. The only change since the last review is one comment line in
tools/startup/gfx2hlsl.py(abovemask = self.const_u32(ops[1])inop_v_mbcnt_lo_u32_b32). It addresses my earlier nit by stating that the constant-mask requirement is intentional for both halves. No logic changed, so my earlier read of the lowering still holds (lane =tid.x + X*(tid.y + Y*tid.z), at most 32 threads so the shift is at most 31,_hicopies the base).State
git diff --stat be690e8 HEAD: 1 file, 1 insertion (the comment).Commands executed locally in a worktree at this head
python3 tests/startup_gfx2hlsl_compute_check.pypassed (masked bit counts, refusals).python3 tests/docs_links_check.pypassed (18 files, 437 links).python3 tests/bidi_controls_check.pypassed (1579 files).git diff --check origin/main...HEADclean.git checkout -- .):((1u << lane) - 1u)changed to((2u << lane) - 1u). The Linux check still passed, as before. The Linux check only covers refusals and the emitted shape, not values.Notes
mbcntor compute dispatch test in the Windows CI log for this head. The value check therefore depends on the WARP run the PR describes. Please confirm that run covered this logic (only a comment differs frombe690e82). I did not rerun Win2025, since the delta is comment-only.Findings: P1: none. P2: none.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by RavenCurseBurg on 2026-11-25T10:24:24Z.
The Windows 2025 run at the reviewed head ran all three registered selections: host controls, WARP dispatch and WARP MBCNT controls. All passed, with no skips. Every WARP dispatch reported an enabled D3D12 debug layer and zero errors/warnings. Both dispatch and MBCNT controls also ran on the desktop RTX 4060.
I applied each of your two mutations directly to the translator and compiled case D with DXC. On WARP and the RTX 4060, counting the current lane failed first at word 0, expected
00000007, actual00000008. Replacing AND with OR failed first at the same word, actual00000011.8a689dcdadds a comment explaining the deliberate shared constant-mask profile for LO and HI. GitHub's rendered README cell contains the literal CTest expression^startup_gfx2hlsl_compute_(controls|(mbcnt_)?(warp|hardware))$. It selects the regular dispatch and MBCNT tests for either adapter as well as the host controls.Imported from R0Y00/Xbox2Windows. Originally posted by RavenCurseBurg on 2026-11-25T10:40:05Z.
Confirmed on the re-reviewed head
8a689dcdbabcb1aabf55619807db88906c408639. The separate Windows 2025 job built that commit and ranstartup_gfx2hlsl_compute_controls(0.77 s),startup_gfx2hlsl_compute_warp(1.15 s) andstartup_gfx2hlsl_compute_mbcnt_warp(1.04 s). All three passed, none skipped. The job checks for the five positive comparisons, six individual control mismatches, and an enabled WARP debug layer with zero errors and warnings.