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 WaveIsFirstLane HLSL Function #99158

Closed
12 tasks
Tracked by #99235
farzonl opened this issue Jul 16, 2024 · 1 comment · Fixed by #103299
Closed
12 tasks
Tracked by #99235

Implement the WaveIsFirstLane HLSL Function #99158

farzonl opened this issue Jul 16, 2024 · 1 comment · Fixed by #103299
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 WaveIsFirstLane clang builtin,
  • Link WaveIsFirstLane clang builtin with hlsl_intrinsics.h
  • Add sema checks for WaveIsFirstLane to CheckHLSLBuiltinFunctionCall in SemaChecking.cpp
  • Add codegen for WaveIsFirstLane to EmitHLSLBuiltinExpr in CGBuiltin.cpp
  • Add codegen tests to clang/test/CodeGenHLSL/builtins/WaveIsFirstLane.hlsl
  • Add sema tests to clang/test/SemaHLSL/BuiltIns/WaveIsFirstLane-errors.hlsl
  • Create the int_dx_WaveIsFirstLane intrinsic in IntrinsicsDirectX.td
  • Create the DXILOpMapping of int_dx_WaveIsFirstLane to 110 in DXIL.td
  • Create the WaveIsFirstLane.ll and WaveIsFirstLane_errors.ll tests in llvm/test/CodeGen/DirectX/
  • Create the int_spv_WaveIsFirstLane intrinsic in IntrinsicsSPIRV.td
  • In SPIRVInstructionSelector.cpp create the WaveIsFirstLane lowering and map it to int_spv_WaveIsFirstLane in SPIRVInstructionSelector::selectIntrinsic.
  • Create SPIR-V backend test case in llvm/test/CodeGen/SPIRV/hlsl-intrinsics/WaveIsFirstLane.ll

DirectX

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

SPIR-V

OpGroupNonUniformElect:

Description:

Result is true only in the active invocation with the
lowest id in the group, otherwise 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.

Capability:
GroupNonUniform

Missing before version 1.3.

Word Count Opcode Results Operands

4

333

<id>
Result Type

Result <id>

Scope <id>
Execution

Test Case(s)

Example 1

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

export bool fn() {
    return WaveIsFirstLane();
}

HLSL:

Returns true only for the active lane in the current wave with the smallest index.

Syntax

bool WaveIsFirstLane(void);

Parameters

This function has no parameters.

Return value

True only for the active lane in the current wave with the smallest index.

Remarks

This function can be used to identify operations that are to be executed only once per wave.

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

 

Examples

 if ( WaveIsFirstLane() )
{
    . . . // once per-wave code
}

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
@farzonl farzonl linked a pull request Aug 19, 2024 that will close this issue
@EugeneZelenko EugeneZelenko added the clang:codegen IR generation bugs: mangling, exceptions, etc. label Sep 4, 2024
@llvmbot
Copy link
Member

llvmbot commented Sep 4, 2024

@llvm/issue-subscribers-clang-codegen

Author: Farzon Lotfi (farzonl)

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

DirectX

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

SPIR-V

OpGroupNonUniformElect:

Description:

Result is true only in the active invocation with the
lowest id in the group, otherwise 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.

Capability:
GroupNonUniform

Missing before version 1.3.

<table>
<colgroup>
<col style="width: 20%" />
<col style="width: 20%" />
<col style="width: 20%" />
<col style="width: 20%" />
<col style="width: 20%" />
</colgroup>
<thead>
<tr>
<th>Word Count</th>
<th>Opcode</th>
<th>Results</th>
<th>Operands</th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p>4</p></td>
<td class="tableblock halign-left valign-top"><p>333</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>
</tr>
</tbody>
</table>

Test Case(s)

Example 1

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

export bool fn() {
    return WaveIsFirstLane();
}

HLSL:

Returns true only for the active lane in the current wave with the smallest index.

Syntax

bool WaveIsFirstLane(void);

Parameters

This function has no parameters.

Return value

True only for the active lane in the current wave with the smallest index.

Remarks

This function can be used to identify operations that are to be executed only once per wave.

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

 

Examples

 if ( WaveIsFirstLane() )
{
    . . . // once per-wave code
}

See also

<dl> <dt>

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

Shader Model 6
</dt> </dl>

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
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants