Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement the WaveActiveAnyTrue HLSL Function #99160

Closed
12 tasks
Tracked by #99235
farzonl opened this issue Jul 16, 2024 · 2 comments · Fixed by #115902
Closed
12 tasks
Tracked by #99235

Implement the WaveActiveAnyTrue HLSL Function #99160

farzonl opened this issue Jul 16, 2024 · 2 comments · Fixed by #115902
Assignees
Labels
backend:DirectX backend:SPIR-V bot:HLSL clang:codegen IR generation bugs: mangling, exceptions, etc. HLSL HLSL Language Support metabug Issue to collect references to a group of similar or related issues.

Comments

@farzonl
Copy link
Member

farzonl commented Jul 16, 2024

  • Implement WaveActiveAnyTrue clang builtin,
  • Link WaveActiveAnyTrue clang builtin with hlsl_intrinsics.h
  • Add sema checks for WaveActiveAnyTrue to CheckHLSLBuiltinFunctionCall in SemaChecking.cpp
  • Add codegen for WaveActiveAnyTrue to EmitHLSLBuiltinExpr in CGBuiltin.cpp
  • Add codegen tests to clang/test/CodeGenHLSL/builtins/WaveActiveAnyTrue.hlsl
  • Add sema tests to clang/test/SemaHLSL/BuiltIns/WaveActiveAnyTrue-errors.hlsl
  • Create the int_dx_WaveActiveAnyTrue intrinsic in IntrinsicsDirectX.td
  • Create the DXILOpMapping of int_dx_WaveActiveAnyTrue to 113 in DXIL.td
  • Create the WaveActiveAnyTrue.ll and WaveActiveAnyTrue_errors.ll tests in llvm/test/CodeGen/DirectX/
  • Create the int_spv_WaveActiveAnyTrue intrinsic in IntrinsicsSPIRV.td
  • In SPIRVInstructionSelector.cpp create the WaveActiveAnyTrue lowering and map it to int_spv_WaveActiveAnyTrue in SPIRVInstructionSelector::selectIntrinsic.
  • Create SPIR-V backend test case in llvm/test/CodeGen/SPIRV/hlsl-intrinsics/WaveActiveAnyTrue.ll

DirectX

DXIL Opcode DXIL OpName Shader Model Shader Stages
113 WaveAnyTrue 6.0 ('library', 'compute', 'amplification', 'mesh', 'pixel', 'vertex', 'hull', 'domain', 'geometry', 'raygeneration', 'intersection', 'anyhit', 'closesthit', 'miss', 'callable', 'node')

SPIR-V

OpGroupNonUniformAny:

Description:

Evaluates a predicate for all active invocations in the group,
resulting in true if predicate evaluates to true for any active
invocation in the group, otherwise the result is
false.

Result Type must be a Boolean type.

Execution is a Scope that identifies the group of
invocations affected by this command. It must be Subgroup.

Predicate must be a Boolean type.

Capability:
GroupNonUniformVote

Missing before version 1.3.

Word Count Opcode Results Operands

5

335

<id>
Result Type

Result <id>

Scope <id>
Execution

<id>
Predicate

Test Case(s)

Example 1

//dxc WaveActiveAnyTrue_test.hlsl -T lib_6_8 -enable-16bit-types -O0

export bool fn(bool p1) {
    return WaveActiveAnyTrue(p1);
}

HLSL:

Returns true if the expression is true in any of the active lanes in the current wave.

Syntax

bool WaveActiveAnyTrue(
   bool expr
);

Parameters

expr

The boolean expression to evaluate.

Return value

True if the expression is true in any lane.

Remarks

This function is supported from shader model 6.0 in all shader stages.

 

See also

Overview of Shader Model 6

Shader Model 6

@farzonl farzonl added backend:DirectX backend:SPIR-V bot:HLSL HLSL HLSL Language Support metabug Issue to collect references to a group of similar or related issues. labels Jul 16, 2024
@spall spall moved this to Planning in HLSL Support Oct 29, 2024
@V-FEXrt
Copy link
Contributor

V-FEXrt commented Oct 29, 2024

Looking at this!

@davidcook-msft davidcook-msft moved this from Planning to Ready in HLSL Support Oct 29, 2024
@damyanp damyanp moved this from Ready to Active in HLSL Support Nov 11, 2024
@damyanp damyanp moved this from Active to Needs Review in HLSL Support Nov 12, 2024
@spall spall closed this as completed in 6735c5e Nov 21, 2024
@github-project-automation github-project-automation bot moved this from Needs Review to Closed in HLSL Support Nov 21, 2024
@EugeneZelenko EugeneZelenko added the clang:codegen IR generation bugs: mangling, exceptions, etc. label Nov 21, 2024
@llvmbot
Copy link
Member

llvmbot commented Nov 21, 2024

@llvm/issue-subscribers-clang-codegen

Author: Farzon Lotfi (farzonl)

- [ ] Implement `WaveActiveAnyTrue` clang builtin, - [ ] Link `WaveActiveAnyTrue` clang builtin with `hlsl_intrinsics.h` - [ ] Add sema checks for `WaveActiveAnyTrue` to `CheckHLSLBuiltinFunctionCall` in `SemaChecking.cpp` - [ ] Add codegen for `WaveActiveAnyTrue` to `EmitHLSLBuiltinExpr` in `CGBuiltin.cpp` - [ ] Add codegen tests to `clang/test/CodeGenHLSL/builtins/WaveActiveAnyTrue.hlsl` - [ ] Add sema tests to `clang/test/SemaHLSL/BuiltIns/WaveActiveAnyTrue-errors.hlsl` - [ ] Create the `int_dx_WaveActiveAnyTrue` intrinsic in `IntrinsicsDirectX.td` - [ ] Create the `DXILOpMapping` of `int_dx_WaveActiveAnyTrue` to `113` in `DXIL.td` - [ ] Create the `WaveActiveAnyTrue.ll` and `WaveActiveAnyTrue_errors.ll` tests in `llvm/test/CodeGen/DirectX/` - [ ] Create the `int_spv_WaveActiveAnyTrue` intrinsic in `IntrinsicsSPIRV.td` - [ ] In SPIRVInstructionSelector.cpp create the `WaveActiveAnyTrue` lowering and map it to `int_spv_WaveActiveAnyTrue` in `SPIRVInstructionSelector::selectIntrinsic`. - [ ] Create SPIR-V backend test case in `llvm/test/CodeGen/SPIRV/hlsl-intrinsics/WaveActiveAnyTrue.ll`

DirectX

DXIL Opcode DXIL OpName Shader Model Shader Stages
113 WaveAnyTrue 6.0 ('library', 'compute', 'amplification', 'mesh', 'pixel', 'vertex', 'hull', 'domain', 'geometry', 'raygeneration', 'intersection', 'anyhit', 'closesthit', 'miss', 'callable', 'node')

SPIR-V

OpGroupNonUniformAny:

Description:

Evaluates a predicate for all active invocations in the group,
resulting in true if predicate evaluates to true for any active
invocation in the group, otherwise the result is
false.

Result Type must be a Boolean type.

Execution is a Scope that identifies the group of
invocations affected by this command. It must be Subgroup.

Predicate must be a Boolean type.

Capability:
GroupNonUniformVote

Missing before version 1.3.

<table style="width:100%;">
<colgroup>
<col style="width: 16%" />
<col style="width: 16%" />
<col style="width: 16%" />
<col style="width: 16%" />
<col style="width: 16%" />
<col style="width: 16%" />
</colgroup>
<thead>
<tr>
<th>Word Count</th>
<th>Opcode</th>
<th>Results</th>
<th>Operands</th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p>5</p></td>
<td class="tableblock halign-left valign-top"><p>335</p></td>
<td
class="tableblock halign-left valign-top"><p><em>&lt;id&gt;</em><br />
<em>Result Type</em></p></td>
<td class="tableblock halign-left valign-top"><p><a
href="#ResultId"><em>Result &lt;id&gt;</em></a></p></td>
<td class="tableblock halign-left valign-top"><p><a
href="#Scope_-id-"><em>Scope &lt;id&gt;</em></a><br />
<em>Execution</em></p></td>
<td
class="tableblock halign-left valign-top"><p><em>&lt;id&gt;</em><br />
<em>Predicate</em></p></td>
</tr>
</tbody>
</table>

Test Case(s)

Example 1

//dxc WaveActiveAnyTrue_test.hlsl -T lib_6_8 -enable-16bit-types -O0

export bool fn(bool p1) {
    return WaveActiveAnyTrue(p1);
}

HLSL:

Returns true if the expression is true in any of the active lanes in the current wave.

Syntax

bool WaveActiveAnyTrue(
   bool expr
);

Parameters

<dl> <dt>

expr
</dt> <dd>

The boolean expression to evaluate.

</dd> </dl>

Return value

True if the expression is true in any lane.

Remarks

This function is supported from shader model 6.0 in all shader stages.

 

See also

<dl> <dt>

Overview of Shader Model 6
</dt> <dt>

Shader Model 6
</dt> </dl>

KornevNikita pushed a commit to intel/llvm that referenced this issue Feb 19, 2025
Resolves llvm/llvm-project#99160

- [x]  Implement `WaveActiveAnyTrue` clang builtin,
- [x]  Link `WaveActiveAnyTrue` clang builtin with `hlsl_intrinsics.h`
- [x] Add sema checks for `WaveActiveAnyTrue` to
`CheckHLSLBuiltinFunctionCall` in `SemaChecking.cpp`
- [x] Add codegen for `WaveActiveAnyTrue` to `EmitHLSLBuiltinExpr` in
`CGBuiltin.cpp`
- [x] Add codegen tests to
`clang/test/CodeGenHLSL/builtins/WaveActiveAnyTrue.hlsl`
- [x] Add sema tests to
`clang/test/SemaHLSL/BuiltIns/WaveActiveAnyTrue-errors.hlsl`
- [x] Create the `int_dx_WaveActiveAnyTrue` intrinsic in
`IntrinsicsDirectX.td`
- [x] Create the `DXILOpMapping` of `int_dx_WaveActiveAnyTrue` to `113`
in `DXIL.td`
- [x] Create the `WaveActiveAnyTrue.ll` and
`WaveActiveAnyTrue_errors.ll` tests in `llvm/test/CodeGen/DirectX/`
- [x] Create the `int_spv_WaveActiveAnyTrue` intrinsic in
`IntrinsicsSPIRV.td`
- [x] In SPIRVInstructionSelector.cpp create the `WaveActiveAnyTrue`
lowering and map it to `int_spv_WaveActiveAnyTrue` in
`SPIRVInstructionSelector::selectIntrinsic`.
- [x] Create SPIR-V backend test case in
`llvm/test/CodeGen/SPIRV/hlsl-intrinsics/WaveActiveAnyTrue.ll`

---------

Co-authored-by: Finn Plummer <[email protected]>
Co-authored-by: Greg Roth <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:DirectX backend:SPIR-V bot:HLSL clang:codegen IR generation bugs: mangling, exceptions, etc. HLSL HLSL Language Support metabug Issue to collect references to a group of similar or related issues.
Projects
Status: Closed
Development

Successfully merging a pull request may close this issue.

4 participants