Skip to content

Implement the WaveReadLaneAt HLSL Function #70104

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

Closed
12 tasks
Tracked by #99235 ...
llvm-beanz opened this issue Oct 24, 2023 · 2 comments · Fixed by #112570
Closed
12 tasks
Tracked by #99235 ...

Implement the WaveReadLaneAt HLSL Function #70104

llvm-beanz opened this issue Oct 24, 2023 · 2 comments · Fixed by #112570
Assignees
Labels
backend:DirectX HLSL HLSL Language Support

Comments

@llvm-beanz
Copy link
Collaborator

llvm-beanz commented Oct 24, 2023

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

DirectX

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

SPIR-V

OpGroupNonUniformShuffle:

Description:

Result is the Value of the invocation identified by the
id Id.

Result Type must be a scalar or vector of floating-point
type
, integer type, or Boolean
type
.

Execution is a Scope that identifies the group of
invocations affected by this command.

The type of Value must be the same as Result Type.

Id must be a scalar of integer type, whose Signedness
operand is 0.

The resulting value is undefined if Id is an inactive invocation, or
is greater than or equal to the size of the group.

Capability:
GroupNonUniformShuffle

Missing before version 1.3.

Word Count Opcode Results Operands

6

345

<id>
Result Type

Result <id>

Scope <id>
Execution

<id>
Value

<id>
Id

Test Case(s)

Example 1

//dxc WaveReadLaneAt_test.hlsl -T lib_6_8 -E fn -enable-16bit-types -spirv -fspv-target-env=universal1.5 -fcgl -O0

export float4 fn(float4 p1, uint p2) {
    return WaveReadLaneAt(p1, p2);
}

HLSL:

Returns the value of the expression for the given lane index within the specified wave.

Syntax

<type> WaveReadLaneAt(
   <type> expr,
   uint laneIndex
);

Parameters

expr

The expression to evaluate.

laneIndex

The index of the lane for which the expr result will be returned.

Return value

The resulting value is the result of expr. It will be uniform if laneIndex is uniform.

Remarks

If laneIndex is uniform, then this is effectively a broadcast operation; otherwise, it's a shuffle operation.

The result is undefined on a helper lane, or if the lane referred to by laneIndex is inactive or a helper lane.

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

See also

@llvm-beanz llvm-beanz converted this from a draft issue Oct 24, 2023
@llvm-beanz llvm-beanz added the HLSL HLSL Language Support label Oct 24, 2023
@farzonl farzonl changed the title [HLSL] Implement WaveReadLaneAt intrinsic Implement the WaveReadLaneAt HLSL Function Jul 16, 2024
@inbelic
Copy link
Contributor

inbelic commented Sep 25, 2024

Taking a look into this.

@damyanp
Copy link
Contributor

damyanp commented Oct 4, 2024

Marking re-estimate this. Since this was originally refined, we have a different approach to implementing intrinsics and the way we've been estimating intrinsics has changed quite a bit.

@damyanp damyanp moved this to Active in HLSL Support Oct 9, 2024
@damyanp damyanp moved this from Active to Reviewing in HLSL Support Oct 10, 2024
inbelic added a commit that referenced this issue Oct 16, 2024
- create a clang built-in in Builtins.td
    - add semantic checking in SemaHLSL.cpp
    - link the WaveReadLaneAt api in hlsl_intrinsics.h
    - add lowering to spirv backend op GroupNonUniformShuffle
      with Scope = 2 (Group) in SPIRVInstructionSelector.cpp
    - add WaveReadLaneAt intrinsic to IntrinsicsDirectX.td and mapping
      to DXIL.td

    - add tests for HLSL intrinsic lowering to spirv intrinsic in
      WaveReadLaneAt.hlsl
    - add tests for sema checks in WaveReadLaneAt-errors.hlsl
    - add spir-v backend tests in WaveReadLaneAt.ll
    - add test to show scalar dxil lowering functionality

    - note that this doesn't include support for the scalarizer to
      handle WaveReadLaneAt will be added in a future pr

This is the first part #70104
DanielCChen pushed a commit to DanielCChen/llvm-project that referenced this issue Oct 16, 2024
- create a clang built-in in Builtins.td
    - add semantic checking in SemaHLSL.cpp
    - link the WaveReadLaneAt api in hlsl_intrinsics.h
    - add lowering to spirv backend op GroupNonUniformShuffle
      with Scope = 2 (Group) in SPIRVInstructionSelector.cpp
    - add WaveReadLaneAt intrinsic to IntrinsicsDirectX.td and mapping
      to DXIL.td

    - add tests for HLSL intrinsic lowering to spirv intrinsic in
      WaveReadLaneAt.hlsl
    - add tests for sema checks in WaveReadLaneAt-errors.hlsl
    - add spir-v backend tests in WaveReadLaneAt.ll
    - add test to show scalar dxil lowering functionality

    - note that this doesn't include support for the scalarizer to
      handle WaveReadLaneAt will be added in a future pr

This is the first part llvm#70104
inbelic added a commit that referenced this issue Oct 16, 2024
- Implement trivial scalarization for the `WaveReadLaneAt` DXIL
intrinsic
- Add test case to demonstrate the lowering path

Resolves #70104
@damyanp damyanp removed the status in HLSL Support Oct 22, 2024
@damyanp damyanp moved this to Closed in HLSL Support Apr 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:DirectX HLSL HLSL Language Support
Projects
Status: Closed
Development

Successfully merging a pull request may close this issue.

5 participants