shader: lower compute v_mbcnt_lo/hi_u32_b32 with a uniform mask #1775
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1782"
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 henriazz10 on 2026-11-24T18:34:43Z.
Change
Refs #1543. This is the
v_mbcnt_lo_u32_b32/v_mbcnt_hi_u32_b32slice claimed in https://github.com/R0Y00/Xbox2Windows/issues/1543#issuecomment-7135171733. It is separate from thev_or_b32_dppslice and touches onlytools/compute_store_aot.py, its test and the docs.v_mbcnt_lo_u32_b32 vD, mask, baselowers tocountbits(mask & ((1u << (gindex & 31u)) - 1u)) + base.gindexisSV_GroupIndex, the flat local thread index. gfx10 numbers the lanes of a wave by that index modulo the wave size, so the result does not depend on the desktop wave width and uses no wave intrinsic.execis not read, matching the instruction.v_mbcnt_hi_u32_b32 vD, mask, baselowers tobase: a wave32 lane has no bit in the high half of the mask.wave_size=32(--wave-size 32, a new optionallower()argument and CLI option). Without it the program could be wave64, and it is refused withUnverified lane count operand or wave size.wave_size=64is refused.mbcnt_controls().tools/mesh_entry_aot.pyfor lanes 0–31.s_bcnt1_i32_b32 ... exec_lo,v_readlane,v_writelaneandds_bpermuteare not part of this PR. The other parts of #1543 remain open.Verification
Commit
65660899, rebased onto67319a17. Windows 11 build 26300, VS 2019 Build Tools 16.11 (MSVC 14.29), DXC 1.8.2502.11, Python 3.12, debug layer enabled.offscreen_checkwas built from an earliermain(0aa6522c); this PR does not change it. The rebase resolved conflicts with thersrc2,image_float_domainandv_cvt_pk_u8_f32work inlower()'s signature, its CLI anddocs/experiments.md. The controls, both draws and the LLVM 15 run below were repeated on65660899.compared_words=320 mismatches=0,debug_errors=0compared_words=320 mismatches=0,debug_errors=0No capability skips.
The LLVM 15 round trip ran separately from the GPU runs, in Ubuntu 22.04 (
llvm-1515.0.7 from apt, as in the Linux CI job):mbcnt_binary()assembles the fixture, disassembles it and requires the samev_mbcntlines and the same translation.Before the rebase, on
4c83e0ccover81df4051, there were no regressions on WARP with the same toolchain:draw,draw-guard-read,draw-f32,draw-lds-privateanddraw-mubuf-format-storeall exit 0. The new CTest entries arecompute_store_aot_mbcnt_warpandcompute_store_aot_mbcnt_hardware. I ran the script directly with the commands above, not through CTest.Evidence and follow-up
The fixture is source-built and hand-written in LLVM 15 spelling. It runs one group of 64 threads, two wave32 waves, and each thread stores three words:
mbcnt_lo(-1, 0),mbcnt_lo(0x5a5a5a5a, 7)andmbcnt_hi(-1, lane). A Python model gives the expected words by counting bits belowflat % 32. All 320 words are compared.mbcnt_hiadding 32.1u << (gindex & 63u)equals the modulo-32 form on both adapters.docs/experiments.mdrecords this next to the new section.Assumption: the wave32 statement belongs to the caller, as for the existing
ds_*_addtidpath. Nothing in the container proves the wave size. Wave64 programs (lane = flat % 64, withmbcnt_hicounting the high half) are left for a follow-up.Checklist
docs/experiments.md).AI-assisted (Claude Code, Claude Opus 5.5). The measurements above come from runs on the machine described in Verification.
🤖 Generated with Claude Code
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T18:48:08Z.
Review: COMMENTED
Verified commit
65660899028ae93b524102cb353278afce1ed94e— no defects found.Checks run locally (Linux)
git diff --check origin/main...HEAD— passedpython -B tests/docs_links_check.py— passed (17 Markdown files, 366 links)python -B tests/bidi_controls_check.py— passed (1303 tracked files)python -B tests/compute_store_check.py binary llvm-mc-19 llvm-objcopy-19 /usr/lib/llvm-19/lib/libLLVM-19.so— passed (includesmbcnt_controls()andmbcnt_binary()assemble/disassemble round-trip)python -B tests/rdna2_tools_check.py— passed (148 tests, 18 skipped)python -B tests/form_coverage_check.py— passedMutation controls (reverted cleanly after each)
wave_size != 32check intools/compute_store_aot.py->mbcnt_controls()failed (AssertionError: Expected rejection: Unverified lane count operand or wave size).+ {hlsl_word(base)}inv_mbcnt_lo_u32_b32lowering ->mbcnt_controls()failed on exact HLSL output check.v_mbcnt_hi_u32_b32lowering to add32uinstead of passing throughbase->mbcnt_controls()failed on exact HLSL output check.Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP)
--preset dev):ctest --preset dev -R '^(compute_store_aot_mbcnt_warp|compute_store_aot_warp|compute_store_aot_guard_read_warp|compute_store_aot_f32_warp)$' --parallel 6 --no-tests=error --output-on-failure— 4/4 passed (compute_store_aot_mbcnt_warp4.43s)/O2(--preset release):ctest --preset release -R '^(compute_store_aot_mbcnt_warp|compute_store_aot_warp|compute_store_aot_guard_read_warp|compute_store_aot_f32_warp)$' --parallel 6 --no-tests=error --output-on-failure— 4/4 passed (compute_store_aot_mbcnt_warp4.49s)AI-assisted; commands listed were executed locally.