shader: lower masked bit counts in small startup compute groups #2282

Merged
RavenCurseBurg merged 2 commits from upstream-pr/2290 into main 2026-11-25 11:02:53 +00:00
RavenCurseBurg commented 2026-11-25 10:16:27 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by RavenCurseBurg on 2026-11-25T10:16:27Z.


Refs #2274, item A, uniform-mask v_mbcnt in 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_b32 counts set mask bits strictly below the flat local lane and adds the base modulo 2³². v_mbcnt_hi_u32_b32 copies 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 first v_mbcnt_lo_u32_b32. The fixture uses two 4×2×4 groups, sparse mask 0x85241249, 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.
  • The normal 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.py passed 7/7. git diff --check origin/main...HEAD passed.

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_check then run ctest --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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6602181665 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2290). Originally posted by [RavenCurseBurg](https://github.com/RavenCurseBurg) on 2026-11-25T10:16:27Z. --- Refs #2274, item A, uniform-mask `v_mbcnt` in 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_b32` counts set mask bits strictly below the flat local lane and adds the base modulo 2³². `v_mbcnt_hi_u32_b32` copies 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 first `v_mbcnt_lo_u32_b32`. The fixture uses two 4×2×4 groups, sparse mask `0x85241249`, 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. - The normal `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.py` passed 7/7. `git diff --check origin/main...HEAD` passed. The [clean Windows build and WARP run at this head](https://github.com/RavenCurseBurg/Xbox2Windows/actions/runs/45593441166) 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_check` then run `ctest --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.
tedin7 commented 2026-11-25 11:02:22 +00:00 (Migrated from github.com)

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)

  • Lane is tid.x + X*(tid.y + Y*tid.z). With XYZ <= 32 the shift is at most 31, so (1u << lane) - 1u is defined and covers lane 31.
  • _lo counts mask bits strictly below the lane and adds the base modulo 2^32. _hi copies the base, which is correct when every thread is in the low half of a wave32 or wave64.
  • Stage is restricted to 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.
  • The title is neutral and the change is clean-room. The PR is mergeable. CI: the Linux Python job and the gfx1013 assemble/translate job pass. "Build and test on Windows" was still pending when I looked.

Commands executed locally in a worktree at that head

  • python3 -B tests/startup_gfx2hlsl_compute_check.py passed: "compute entry, numthreads, masked bit counts, manifest, offen store forms and the store, descriptor, execz and sample refusals pass".
  • python3 tests/docs_links_check.py passed (18 files, 437 links).
  • python3 tests/bidi_controls_check.py passed (1579 files).
  • git diff --check origin/main...HEAD was clean.

Mutation (local, reverted with git checkout -- .)

  • Changed ((1u << lane) - 1u) to ((2u << lane) - 1u), which counts the lane itself. The Linux check still passed.
  • Changed the & between the mask and the lane bound to |. The Linux check still passed.
  • This is expected, because the Linux path only checks refusals and does not compare values. The PR says the WARP/hardware control mbcnt and dispatch runs kill the mutations. I did not rerun Windows. Please make sure the Windows CI job or the Win2025 run confirms that startup_gfx2hlsl_compute_mbcnt_* and the dispatch tests actually ran and were not skipped (they use SKIP_RETURN_CODE 77).

Findings

  • P1: none.
  • P2: none.
  • nit: _hi requires a known mask (const_u32(ops[1])) even though the mask is unused. Hardware accepts any mask for _hi in 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 the mask = self.const_u32(ops[1]) line.
  • note: the README.md row's ctest -R pattern uses \| inside a Markdown table cell. Check that it renders as | and that it matches the new startup_gfx2hlsl_compute_mbcnt_* names.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6055726257 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2290#pullrequestreview-6055726257). Originally posted by [tedin7](https://github.com/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`)** - Lane is `tid.x + X*(tid.y + Y*tid.z)`. With X*Y*Z <= 32 the shift is at most 31, so `(1u << lane) - 1u` is defined and covers lane 31. - `_lo` counts mask bits strictly below the lane and adds the base modulo 2^32. `_hi` copies the base, which is correct when every thread is in the low half of a wave32 or wave64. - Stage is restricted to `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. - The title is neutral and the change is clean-room. The PR is mergeable. CI: the Linux Python job and the gfx1013 assemble/translate job pass. "Build and test on Windows" was still pending when I looked. **Commands executed locally in a worktree at that head** - `python3 -B tests/startup_gfx2hlsl_compute_check.py` passed: "compute entry, numthreads, masked bit counts, manifest, offen store forms and the store, descriptor, execz and sample refusals pass". - `python3 tests/docs_links_check.py` passed (18 files, 437 links). - `python3 tests/bidi_controls_check.py` passed (1579 files). - `git diff --check origin/main...HEAD` was clean. **Mutation (local, reverted with `git checkout -- .`)** - Changed `((1u << lane) - 1u)` to `((2u << lane) - 1u)`, which counts the lane itself. The Linux check still passed. - Changed the `&` between the mask and the lane bound to `|`. The Linux check still passed. - This is expected, because the Linux path only checks refusals and does not compare values. The PR says the WARP/hardware `control mbcnt` and `dispatch` runs kill the mutations. I did not rerun Windows. Please make sure the Windows CI job or the Win2025 run confirms that `startup_gfx2hlsl_compute_mbcnt_*` and the dispatch tests actually ran and were not skipped (they use `SKIP_RETURN_CODE 77`). **Findings** - P1: none. - P2: none. - nit: `_hi` requires a known mask (`const_u32(ops[1])`) even though the mask is unused. Hardware accepts any mask for `_hi` in 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 the `mask = self.const_u32(ops[1])` line. - note: the `README.md` row's `ctest -R` pattern uses `\|` inside a Markdown table cell. Check that it renders as `|` and that it matches the new `startup_gfx2hlsl_compute_mbcnt_*` names. AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-25 11:02:22 +00:00 (Migrated from github.com)

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 on be690e82.

Summary: No P1 or P2. The only change since the last review is one comment line in tools/startup/gfx2hlsl.py (above mask = self.const_u32(ops[1]) in op_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, _hi copies the base).

State

  • git diff --stat be690e8 HEAD: 1 file, 1 insertion (the comment).
  • Mergeable. Title is neutral. CI at this head: Linux Python checks pass, gfx1013 assemble/translate pass, Windows build and test pass.

Commands executed locally in a worktree at this head

  • python3 tests/startup_gfx2hlsl_compute_check.py passed (masked bit counts, refusals).
  • python3 tests/docs_links_check.py passed (18 files, 437 links).
  • python3 tests/bidi_controls_check.py passed (1579 files).
  • git diff --check origin/main...HEAD clean.
  • Mutation (reverted with 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

  • nit (unchanged): I could not find an mbcnt or 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 from be690e82). I did not rerun Win2025, since the delta is comment-only.

Findings: P1: none. P2: none.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6055877214 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2290#pullrequestreview-6055877214). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T10:30:06Z. **Review:** COMMENTED --- Re-review of head `8a689dcdbabcb1aabf55619807db88906c408639` (comment only). Previous review was on `be690e82`. **Summary:** No P1 or P2. The only change since the last review is one comment line in `tools/startup/gfx2hlsl.py` (above `mask = self.const_u32(ops[1])` in `op_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, `_hi` copies the base). **State** - `git diff --stat be690e8 HEAD`: 1 file, 1 insertion (the comment). - Mergeable. Title is neutral. CI at this head: Linux Python checks pass, gfx1013 assemble/translate pass, Windows build and test pass. **Commands executed locally in a worktree at this head** - `python3 tests/startup_gfx2hlsl_compute_check.py` passed (masked bit counts, refusals). - `python3 tests/docs_links_check.py` passed (18 files, 437 links). - `python3 tests/bidi_controls_check.py` passed (1579 files). - `git diff --check origin/main...HEAD` clean. - Mutation (reverted with `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** - nit (unchanged): I could not find an `mbcnt` or 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 from `be690e82`). I did not rerun Win2025, since the delta is comment-only. **Findings:** P1: none. P2: none. AI-assisted; commands listed were executed locally.
RavenCurseBurg commented 2026-11-25 11:02:29 +00:00 (Migrated from github.com)

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, actual 00000008. Replacing AND with OR failed first at the same word, actual 00000011.

8a689dcd adds 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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7159649875 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2290#issuecomment-7159649875). Originally posted by [RavenCurseBurg](https://github.com/RavenCurseBurg) on 2026-11-25T10:24:24Z. --- The [Windows 2025 run at the reviewed head](https://github.com/RavenCurseBurg/Xbox2Windows/actions/runs/45593441166) 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`, actual `00000008`. Replacing AND with OR failed first at the same word, actual `00000011`. `8a689dcd` adds 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.
RavenCurseBurg commented 2026-11-25 11:02:30 +00:00 (Migrated from github.com)

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 ran startup_gfx2hlsl_compute_controls (0.77 s), startup_gfx2hlsl_compute_warp (1.15 s) and startup_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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7160009789 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2290#issuecomment-7160009789). Originally posted by [RavenCurseBurg](https://github.com/RavenCurseBurg) on 2026-11-25T10:40:05Z. --- Confirmed on the re-reviewed head `8a689dcdbabcb1aabf55619807db88906c408639`. The separate [Windows 2025 job](https://github.com/RavenCurseBurg/Xbox2Windows/actions/runs/45594748131) built that commit and ran `startup_gfx2hlsl_compute_controls` (0.77 s), `startup_gfx2hlsl_compute_warp` (1.15 s) and `startup_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.
upstream-sync closed this pull request 2026-11-25 12:01:38 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
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
R0Y00/Xbox2Windows!2282
No description provided.