-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[HLSL] Implement WaveReadLaneAt
intrinsics
#110739
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
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \ | ||
// RUN: dxil-pc-shadermodel6.3-compute %s -emit-llvm -disable-llvm-passes -o - | \ | ||
// RUN: FileCheck %s --check-prefixes=CHECK,CHECK-DXIL | ||
// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \ | ||
// RUN: spirv-pc-vulkan-compute %s -emit-llvm -disable-llvm-passes -o - | \ | ||
// RUN: FileCheck %s --check-prefixes=CHECK,CHECK-SPIRV | ||
|
||
// Test basic lowering to runtime function call. | ||
|
||
// CHECK-LABEL: test_int | ||
int test_int(int expr, uint idx) { | ||
// CHECK-SPIRV: %[[#entry_tok:]] = call token @llvm.experimental.convergence.entry() | ||
|
||
// CHECK-SPIRV: %[[RET:.*]] = call [[TY:.*]] @llvm.spv.wave.read.lane.at.i32([[TY]] %[[#]], i32 %[[#]]) | ||
// CHECK-DXIL: %[[RET:.*]] = call [[TY:.*]] @llvm.dx.wave.read.lane.at.i32([[TY]] %[[#]], i32 %[[#]]) | ||
|
||
// CHECK: ret [[TY]] %[[RET]] | ||
return WaveReadLaneAt(expr, idx); | ||
} | ||
|
||
// CHECK-DXIL: declare [[TY]] @llvm.dx.wave.read.lane.at.i32([[TY]], i32) #[[#attr:]] | ||
// CHECK-SPIRV: declare [[TY]] @llvm.spv.wave.read.lane.at.i32([[TY]], i32) #[[#attr:]] | ||
|
||
// Test basic lowering to runtime function call with array and float value. | ||
|
||
// CHECK-LABEL: test_floatv4 | ||
float4 test_floatv4(float4 expr, uint idx) { | ||
// CHECK-SPIRV: %[[#entry_tok1:]] = call token @llvm.experimental.convergence.entry() | ||
|
||
// CHECK-SPIRV: %[[RET1:.*]] = call [[TY1:.*]] @llvm.spv.wave.read.lane.at.v4f32([[TY1]] %[[#]], i32 %[[#]]) | ||
// CHECK-DXIL: %[[RET1:.*]] = call [[TY1:.*]] @llvm.dx.wave.read.lane.at.v4f32([[TY1]] %[[#]], i32 %[[#]]) | ||
|
||
// CHECK: ret [[TY1]] %[[RET1]] | ||
return WaveReadLaneAt(expr, idx); | ||
} | ||
|
||
// CHECK-DXIL: declare [[TY1]] @llvm.dx.wave.read.lane.at.v4f32([[TY1]], i32) #[[#attr]] | ||
// CHECK-SPIRV: declare [[TY1]] @llvm.spv.wave.read.lane.at.v4f32([[TY1]], i32) #[[#attr]] | ||
|
||
// CHECK: attributes #[[#attr]] = {{{.*}} convergent {{.*}}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm-only -disable-llvm-passes -verify -verify-ignore-unexpected | ||
|
||
bool test_too_few_arg() { | ||
return __builtin_hlsl_wave_read_lane_at(); | ||
// expected-error@-1 {{too few arguments to function call, expected 2, have 0}} | ||
} | ||
|
||
float2 test_too_few_arg_1(float2 p0) { | ||
return __builtin_hlsl_wave_read_lane_at(p0); | ||
// expected-error@-1 {{too few arguments to function call, expected 2, have 1}} | ||
} | ||
|
||
float2 test_too_many_arg(float2 p0) { | ||
return __builtin_hlsl_wave_read_lane_at(p0, p0, p0); | ||
// expected-error@-1 {{too many arguments to function call, expected 2, have 3}} | ||
} | ||
|
||
float3 test_index_type_check(float3 p0, double idx) { | ||
return __builtin_hlsl_wave_read_lane_at(p0, idx); | ||
// expected-error@-1 {{passing 'double' to parameter of incompatible type 'unsigned int'}} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2653,6 +2653,21 @@ bool SPIRVInstructionSelector::selectIntrinsic(Register ResVReg, | |
.addUse(GR.getSPIRVTypeID(ResType)) | ||
.addUse(GR.getOrCreateConstInt(3, I, IntTy, TII)); | ||
} | ||
case Intrinsic::spv_wave_read_lane_at: { | ||
assert(I.getNumOperands() == 4); | ||
assert(I.getOperand(2).isReg()); | ||
assert(I.getOperand(3).isReg()); | ||
|
||
// Defines the execution scope currently 2 for group, see scope table | ||
SPIRVType *IntTy = GR.getOrCreateSPIRVIntegerType(32, I, TII); | ||
return BuildMI(BB, I, I.getDebugLoc(), | ||
TII.get(SPIRV::OpGroupNonUniformShuffle)) | ||
.addDef(ResVReg) | ||
.addUse(GR.getSPIRVTypeID(ResType)) | ||
.addUse(I.getOperand(2).getReg()) | ||
.addUse(I.getOperand(3).getReg()) | ||
.addUse(GR.getOrCreateConstInt(2, I, IntTy, TII)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IIUC, an HLSL |
||
} | ||
case Intrinsic::spv_step: | ||
return selectStep(ResVReg, ResType, I); | ||
// Discard intrinsics which we do not expect to actually represent code after | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
; RUN: opt -S -dxil-op-lower -mtriple=dxil-pc-shadermodel6.3-compute %s | FileCheck %s | ||
|
||
define noundef <4 x half> @wave_rla_halfv4(<4 x half> noundef %expr, i32 noundef %idx) #0 { | ||
entry: | ||
; CHECK: call <4 x half> @dx.op.waveReadLaneAt.v4f16(i32 117, <4 x half> %expr, i32 %idx) | ||
%ret = call <4 x half> @llvm.dx.wave.read.lane.at.v4f16(<4 x half> %expr, i32 %idx) | ||
ret <4 x half> %ret | ||
} | ||
|
||
define noundef <4 x float> @wave_rla_floatv4(<4 x float> noundef %expr, i32 noundef %idx) #0 { | ||
entry: | ||
; CHECK: call <4 x float> @dx.op.waveReadLaneAt.v4f32(i32 117, <4 x float> %expr, i32 %idx) | ||
%ret = call <4 x float> @llvm.dx.wave.read.lane.at.v4f32(<4 x float> %expr, i32 %idx) | ||
ret <4 x float> %ret | ||
} | ||
|
||
define noundef <4 x double> @wave_rla_doublev4(<4 x double> noundef %expr, i32 noundef %idx) #0 { | ||
entry: | ||
; CHECK: call <4 x double> @dx.op.waveReadLaneAt.v4f64(i32 117, <4 x double> %expr, i32 %idx) | ||
%ret = call <4 x double> @llvm.dx.wave.read.lane.at.v4f64(<4 x double> %expr, i32 %idx) | ||
ret <4 x double> %ret | ||
} | ||
|
||
define noundef <4 x i1> @wave_rla_v4i1(<4 x i1> noundef %expr, i32 noundef %idx) #0 { | ||
entry: | ||
; CHECK: call <4 x i1> @dx.op.waveReadLaneAt.v4i1(i32 117, <4 x i1> %expr, i32 %idx) | ||
%ret = call <4 x i1> @llvm.dx.wave.read.lane.at.v4i1(<4 x i1> %expr, i32 %idx) | ||
ret <4 x i1> %ret | ||
} | ||
|
||
define noundef <4 x i16> @wave_rla_v4i16(<4 x i16> noundef %expr, i32 noundef %idx) #0 { | ||
entry: | ||
; CHECK: call <4 x i16> @dx.op.waveReadLaneAt.v4i16(i32 117, <4 x i16> %expr, i32 %idx) | ||
%ret = call <4 x i16> @llvm.dx.wave.read.lane.at.v4i16(<4 x i16> %expr, i32 %idx) | ||
ret <4 x i16> %ret | ||
} | ||
|
||
define noundef <4 x i32> @wave_rla_v4i32(<4 x i32> noundef %expr, i32 noundef %idx) #0 { | ||
entry: | ||
; CHECK: call <4 x i32> @dx.op.waveReadLaneAt.v4i32(i32 117, <4 x i32> %expr, i32 %idx) | ||
%ret = call <4 x i32> @llvm.dx.wave.read.lane.at.v4i32(<4 x i32> %expr, i32 %idx) | ||
ret <4 x i32> %ret | ||
} | ||
|
||
declare <4 x half> @llvm.dx.wave.read.lane.at.v4f16(<4 x half>, i32) #1 | ||
declare <4 x float> @llvm.dx.wave.read.lane.at.v4f32(<4 x float>, i32) #1 | ||
declare <4 x double> @llvm.dx.wave.read.lane.at.v4f64(<4 x double>, i32) #1 | ||
|
||
declare <4 x i1> @llvm.dx.wave.read.lane.at.v4i1(<4 x i1>, i32) #1 | ||
declare <4 x i16> @llvm.dx.wave.read.lane.at.v4i16(<4 x i16>, i32) #1 | ||
declare <4 x i32> @llvm.dx.wave.read.lane.at.v4i32(<4 x i32>, i32) #1 | ||
|
||
attributes #0 = { convergent norecurse "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" "no-trapping-math"="true" "stack-protector-buffer-size"="8" } | ||
attributes #1 = { convergent nocallback nofree nosync nounwind willreturn } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
; RUN: opt -S -dxil-op-lower -mtriple=dxil-pc-shadermodel6.3-compute %s | FileCheck %s | ||
|
||
define noundef half @wave_rla_half(half noundef %expr, i32 noundef %idx) #0 { | ||
entry: | ||
; CHECK: call half @dx.op.waveReadLaneAt.f16(i32 117, half %expr, i32 %idx) | ||
%ret = call half @llvm.dx.wave.read.lane.at.f16(half %expr, i32 %idx) | ||
ret half %ret | ||
} | ||
|
||
define noundef float @wave_rla_float(float noundef %expr, i32 noundef %idx) #0 { | ||
entry: | ||
; CHECK: call float @dx.op.waveReadLaneAt.f32(i32 117, float %expr, i32 %idx) | ||
%ret = call float @llvm.dx.wave.read.lane.at(float %expr, i32 %idx) | ||
ret float %ret | ||
} | ||
|
||
define noundef double @wave_rla_double(double noundef %expr, i32 noundef %idx) #0 { | ||
entry: | ||
; CHECK: call double @dx.op.waveReadLaneAt.f64(i32 117, double %expr, i32 %idx) | ||
%ret = call double @llvm.dx.wave.read.lane.at(double %expr, i32 %idx) | ||
ret double %ret | ||
} | ||
|
||
define noundef i1 @wave_rla_i1(i1 noundef %expr, i32 noundef %idx) #0 { | ||
entry: | ||
; CHECK: call i1 @dx.op.waveReadLaneAt.i1(i32 117, i1 %expr, i32 %idx) | ||
%ret = call i1 @llvm.dx.wave.read.lane.at.i1(i1 %expr, i32 %idx) | ||
ret i1 %ret | ||
} | ||
|
||
define noundef i16 @wave_rla_i16(i16 noundef %expr, i32 noundef %idx) #0 { | ||
entry: | ||
; CHECK: call i16 @dx.op.waveReadLaneAt.i16(i32 117, i16 %expr, i32 %idx) | ||
%ret = call i16 @llvm.dx.wave.read.lane.at.i16(i16 %expr, i32 %idx) | ||
ret i16 %ret | ||
} | ||
|
||
define noundef i32 @wave_rla_i32(i32 noundef %expr, i32 noundef %idx) #0 { | ||
entry: | ||
; CHECK: call i32 @dx.op.waveReadLaneAt.i32(i32 117, i32 %expr, i32 %idx) | ||
%ret = call i32 @llvm.dx.wave.read.lane.at.i32(i32 %expr, i32 %idx) | ||
ret i32 %ret | ||
} | ||
|
||
declare half @llvm.dx.wave.read.lane.at.f16(half, i32) #1 | ||
declare float @llvm.dx.wave.read.lane.at.f32(float, i32) #1 | ||
declare double @llvm.dx.wave.read.lane.at.f64(double, i32) #1 | ||
|
||
declare i1 @llvm.dx.wave.read.lane.at.i1(i1, i32) #1 | ||
declare i16 @llvm.dx.wave.read.lane.at.i16(i16, i32) #1 | ||
declare i32 @llvm.dx.wave.read.lane.at.i32(i32, i32) #1 | ||
|
||
attributes #0 = { norecurse "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" "no-trapping-math"="true" "stack-protector-buffer-size"="8" } | ||
attributes #1 = { nocallback nofree nosync nounwind willreturn } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops, will remove when I address other comments