Split wave32 geometry: refuse prefix counts over a mask #44

Manually merged
github merged 1 commit from gh-pr/44/head into gh-pr/44/base 2026-11-26 04:06:01 +00:00
Owner

@⁠grahamster2 on GitHub · 2026-11-22 20:31 UTC · original
grahamster2:fix/wave32-mask-prefix-count → main · +137 −3 · 3 files · 1 commits · merged 2026-11-22 21:33 UTC

Summary

The split wave32 form of a logical wave64 (geometry mode on adapters without 64-lane waves, e.g. NVIDIA, since #14) gives each native half only its own word of EXEC, VCC and v_cmp results. geometry_wave32_hazards refuses the cross-half operations, but it had no rule for v_mbcnt_lo/hi over a mask. For lanes 32..63, v_mbcnt_lo of exec_lo / vcc_lo / a v_cmp SGPR pair then counts 0 instead of the active lanes of 0..31, so a compaction index or prefix count is silently wrong.

  • v_mbcnt_* whose SRC0 is not an inline constant or literal is now a hazard ("prefix count over a whole-wave mask"). The lane-index idiom (v_mbcnt of -1) stays accepted.
  • A VOP3 v_cmp into an SGPR pair is a mask too, in geometry_wave32_hazards and in mesh_wave's taint. So s_bcnt / s_ff1 / s_flbit of one of its 32-bit words, and an s_cmp of such a word that a branch reads, are refused like the 64-bit forms.

Emission is unchanged.

Test

gpu_geometry_wave32_prefix_count_over_a_mask: an ES computes VCC (lanes with lane & 3 != 0) and s[10:11] (lanes below 40), then v_mbcnt over VCC, over s[10:11] and over EXEC after s_and_saveexec, and stores the three counts. It runs the compute pass only (runner::dispatch), so an adapter without mesh shaders can run it too. If the split translation is refused, the test passes. If it translates, the output must equal a CPU wave64 reference. The native translation must always succeed, and on a wave64 adapter it also runs and is checked against the reference.

Before the fix, on both an RTX 3080 (wave 32) and a Radeon RDNA2 iGPU (forced to the split form), lanes 0..31 were right and lanes 32..63 counted only their own half, e.g. got / want for [VCC, s[10:11], EXEC]:

lane got want
33 0, 1, 0 24, 33, 24
43 8, 8, 8 32, 40, 32
63 23, 8, 23 47, 40, 47

After the fix, it passes on both, and the native wave64 run on the iGPU matches the CPU reference. geometry_wave32_rejects_cross_half_operations and a new mesh_wave unit test cover the new rules.

cargo test --workspace --release --no-fail-fast on the RTX 3080 with XCL_SAMPLE_RPF set to a retail shaders.rpf: lib 328 passed, 0 failed. gpu_pso_e2e gives 4 / 6, the same 2 mesh failures as on main (wave64 MS on a 32-lane adapter, #39 / #42). retail_es_gs_voxelize_geometry_mode and retail_gs_pipeline_through_the_hook still pass, and the first of them uses the split path there. All 195 ES+GS pairs of that pack pass geometry_wave32_hazards before and after, so the new rule refuses no retail program.

Open question

The v_mbcnt rule refuses any non-constant SRC0, including an SGPR that only holds a constant. That fails closed like the other rules. A taint-based version is possible if you'd prefer it. #39 will need the same check for the mesh path, so this rule would apply there too.

**@⁠grahamster2** on GitHub · 2026-11-22 20:31 UTC · [original](https://github.com/xcl-dev/xcl/pull/44) `grahamster2:fix/wave32-mask-prefix-count` → `main` · +137 −3 · 3 files · 1 commits · merged 2026-11-22 21:33 UTC ### Summary The split wave32 form of a logical wave64 (geometry mode on adapters without 64-lane waves, e.g. NVIDIA, since #14) gives each native half only its own word of EXEC, VCC and `v_cmp` results. `geometry_wave32_hazards` refuses the cross-half operations, but it had no rule for `v_mbcnt_lo/hi` over a mask. For lanes 32..63, `v_mbcnt_lo` of `exec_lo` / `vcc_lo` / a `v_cmp` SGPR pair then counts 0 instead of the active lanes of 0..31, so a compaction index or prefix count is silently wrong. - `v_mbcnt_*` whose SRC0 is not an inline constant or literal is now a hazard ("prefix count over a whole-wave mask"). The lane-index idiom (`v_mbcnt` of -1) stays accepted. - A VOP3 `v_cmp` into an SGPR pair is a mask too, in `geometry_wave32_hazards` and in `mesh_wave`'s taint. So `s_bcnt` / `s_ff1` / `s_flbit` of one of its 32-bit words, and an `s_cmp` of such a word that a branch reads, are refused like the 64-bit forms. Emission is unchanged. ### Test `gpu_geometry_wave32_prefix_count_over_a_mask`: an ES computes VCC (lanes with `lane & 3 != 0`) and `s[10:11]` (lanes below 40), then `v_mbcnt` over VCC, over `s[10:11]` and over EXEC after `s_and_saveexec`, and stores the three counts. It runs the compute pass only (`runner::dispatch`), so an adapter without mesh shaders can run it too. If the split translation is refused, the test passes. If it translates, the output must equal a CPU wave64 reference. The native translation must always succeed, and on a wave64 adapter it also runs and is checked against the reference. Before the fix, on both an RTX 3080 (wave 32) and a Radeon RDNA2 iGPU (forced to the split form), lanes 0..31 were right and lanes 32..63 counted only their own half, e.g. got / want for [VCC, s[10:11], EXEC]: | lane | got | want | |---|---|---| | 33 | 0, 1, 0 | 24, 33, 24 | | 43 | 8, 8, 8 | 32, 40, 32 | | 63 | 23, 8, 23 | 47, 40, 47 | After the fix, it passes on both, and the native wave64 run on the iGPU matches the CPU reference. `geometry_wave32_rejects_cross_half_operations` and a new `mesh_wave` unit test cover the new rules. `cargo test --workspace --release --no-fail-fast` on the RTX 3080 with `XCL_SAMPLE_RPF` set to a retail `shaders.rpf`: lib 328 passed, 0 failed. `gpu_pso_e2e` gives 4 / 6, the same 2 mesh failures as on `main` (wave64 MS on a 32-lane adapter, #39 / #42). `retail_es_gs_voxelize_geometry_mode` and `retail_gs_pipeline_through_the_hook` still pass, and the first of them uses the split path there. All 195 ES+GS pairs of that pack pass `geometry_wave32_hazards` before and after, so the new rule refuses no retail program. ### Open question The `v_mbcnt` rule refuses any non-constant SRC0, including an SGPR that only holds a constant. That fails closed like the other rules. A taint-based version is possible if you'd prefer it. #39 will need the same check for the mesh path, so this rule would apply there too.
The split form of a logical wave64 (adapters without 64-lane waves) gives
each native half only its own word of EXEC, VCC and v_cmp results. A
v_mbcnt over such a mask then counted 0 for the other half: in lanes
32..63 a compaction index or prefix count missed the active lanes of
0..31 (an ES counting the lanes of a v_cmp got 0..23 instead of 24..47
there on the RTX 3080).

geometry_wave32_hazards now refuses v_mbcnt whose SRC0 is not a constant
(the lane-index idiom, v_mbcnt of -1, stays accepted). A VOP3 v_cmp into
an SGPR pair is a mask too, in the scan and in mesh_wave's taint, so
s_bcnt / s_ff1 / s_flbit of one of its words and an s_cmp of a word that
a branch reads are refused like the 64-bit forms.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:05:59 +00:00
github manually merged commit a31275939a into gh-pr/44/base 2026-11-26 04:06:01 +00:00
Author
Owner

@⁠ivall on GitHub · 2026-11-22 21:33 UTC · original

Thanks, merged! On an RX 9070 (native wave64) all tests pass, gpu_pso_e2e too with a retail shaders.rpf (6 / 6). It changes nothing there, as expected. The v_mbcnt table is a nice catch.

**@⁠ivall** on GitHub · 2026-11-22 21:33 UTC · [original](https://github.com/xcl-dev/xcl/pull/44#issuecomment-7086137824) Thanks, merged! On an RX 9070 (native wave64) all tests pass, `gpu_pso_e2e` too with a retail `shaders.rpf` (6 / 6). It changes nothing there, as expected. The `v_mbcnt` table is a nice catch.
This discussion has been locked. Commenting is limited to contributors.
No description provided.