Issue 240510
Summary [HLSL][SPIR-V] Add code generation for `WaveMultiPrefixCountBits`
Labels new issue
Assignees
Reporter bob80905
    ## Summary

Add SPIR-V code generation for the HLSL builtin:

```hlsl
uint WaveMultiPrefixCountBits(bool value, uint4 mask);
```

Clang now supports this builtin for DirectX. SPIR-V code generation remains
unimplemented.

Issue #99211 covered the DirectX implementation and is closed. This issue
tracks the missing SPIR-V support.

## Expected behavior

Return the number of earlier active lanes whose input is true and whose
lane belongs to the partition specified by `mask`.

The result must exclude the current lane and inactive lanes. Mask bits
outside the subgroup size must not affect the result.

## Possible implementation

The following sequence could implement the operation:

```text
ballot = OpGroupNonUniformBallot(Subgroup, value)
masked = OpBitwiseAnd(ballot, mask)
result = OpGroupNonUniformBallotBitCount(
    Subgroup, ExclusiveScan, masked)
```

These operations are available in SPIR-V 1.3 with the
`GroupNonUniformBallot` capability. This proposal needs implementation
and validation.

## Tests

- Add Clang and SPIR-V code generation tests.
- Check false, true, and mixed inputs.
- Check full-subgroup masks and multiple partitions.
- Check single-lane partitions and inactive lanes.

## References

- Original issue: https://github.com/llvm/llvm-project/issues/99211
- HLSL specification:
 https://microsoft.github.io/DirectX-Specs/d3d/HLSL_ShaderModel6_5.html#wavemultiprefix-functions
- SPIR-V ballot bit count:
 https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#OpGroupNonUniformBallotBitCount
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to