-
Notifications
You must be signed in to change notification settings - Fork 11.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[HLSL] Implement
WaveReadLaneAt
intrinsic (#111010)
- 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
- Loading branch information
Showing
14 changed files
with
413 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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,74 @@ | ||
// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -fnative-half-type -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 -fnative-half-type -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 for int values. | ||
|
||
// CHECK-LABEL: test_int | ||
int test_int(int expr, uint idx) { | ||
// CHECK-SPIRV: %[[#entry_tok0:]] = call token @llvm.experimental.convergence.entry() | ||
// CHECK-SPIRV: %[[RET:.*]] = call [[TY:.*]] @llvm.spv.wave.readlane.i32([[TY]] %[[#]], i32 %[[#]]) [ "convergencectrl"(token %[[#entry_tok0]]) ] | ||
// CHECK-DXIL: %[[RET:.*]] = call [[TY:.*]] @llvm.dx.wave.readlane.i32([[TY]] %[[#]], i32 %[[#]]) | ||
// CHECK: ret [[TY]] %[[RET]] | ||
return WaveReadLaneAt(expr, idx); | ||
} | ||
|
||
// CHECK-DXIL: declare [[TY]] @llvm.dx.wave.readlane.i32([[TY]], i32) #[[#attr:]] | ||
// CHECK-SPIRV: declare [[TY]] @llvm.spv.wave.readlane.i32([[TY]], i32) #[[#attr:]] | ||
|
||
#ifdef __HLSL_ENABLE_16_BIT | ||
// CHECK-LABEL: test_int16 | ||
int16_t test_int16(int16_t expr, uint idx) { | ||
// CHECK-SPIRV: %[[#entry_tok1:]] = call token @llvm.experimental.convergence.entry() | ||
// CHECK-SPIRV: %[[RET:.*]] = call [[TY:.*]] @llvm.spv.wave.readlane.i16([[TY]] %[[#]], i32 %[[#]]) [ "convergencectrl"(token %[[#entry_tok1]]) ] | ||
// CHECK-DXIL: %[[RET:.*]] = call [[TY:.*]] @llvm.dx.wave.readlane.i16([[TY]] %[[#]], i32 %[[#]]) | ||
// CHECK: ret [[TY]] %[[RET]] | ||
return WaveReadLaneAt(expr, idx); | ||
} | ||
|
||
// CHECK-DXIL: declare [[TY]] @llvm.dx.wave.readlane.i16([[TY]], i32) #[[#attr:]] | ||
// CHECK-SPIRV: declare [[TY]] @llvm.spv.wave.readlane.i16([[TY]], i32) #[[#attr:]] | ||
#endif | ||
|
||
// Test basic lowering to runtime function call with array and float values. | ||
|
||
// CHECK-LABEL: test_half | ||
half test_half(half expr, uint idx) { | ||
// CHECK-SPIRV: %[[#entry_tok2:]] = call token @llvm.experimental.convergence.entry() | ||
// CHECK-SPIRV: %[[RET:.*]] = call [[TY:.*]] @llvm.spv.wave.readlane.f16([[TY]] %[[#]], i32 %[[#]]) [ "convergencectrl"(token %[[#entry_tok2]]) ] | ||
// CHECK-DXIL: %[[RET:.*]] = call [[TY:.*]] @llvm.dx.wave.readlane.f16([[TY]] %[[#]], i32 %[[#]]) | ||
// CHECK: ret [[TY]] %[[RET]] | ||
return WaveReadLaneAt(expr, idx); | ||
} | ||
|
||
// CHECK-DXIL: declare [[TY]] @llvm.dx.wave.readlane.f16([[TY]], i32) #[[#attr:]] | ||
// CHECK-SPIRV: declare [[TY]] @llvm.spv.wave.readlane.f16([[TY]], i32) #[[#attr:]] | ||
|
||
// CHECK-LABEL: test_double | ||
double test_double(double expr, uint idx) { | ||
// CHECK-SPIRV: %[[#entry_tok3:]] = call token @llvm.experimental.convergence.entry() | ||
// CHECK-SPIRV: %[[RET:.*]] = call [[TY:.*]] @llvm.spv.wave.readlane.f64([[TY]] %[[#]], i32 %[[#]]) [ "convergencectrl"(token %[[#entry_tok3]]) ] | ||
// CHECK-DXIL: %[[RET:.*]] = call [[TY:.*]] @llvm.dx.wave.readlane.f64([[TY]] %[[#]], i32 %[[#]]) | ||
// CHECK: ret [[TY]] %[[RET]] | ||
return WaveReadLaneAt(expr, idx); | ||
} | ||
|
||
// CHECK-DXIL: declare [[TY]] @llvm.dx.wave.readlane.f64([[TY]], i32) #[[#attr:]] | ||
// CHECK-SPIRV: declare [[TY]] @llvm.spv.wave.readlane.f64([[TY]], i32) #[[#attr:]] | ||
|
||
// CHECK-LABEL: test_floatv4 | ||
float4 test_floatv4(float4 expr, uint idx) { | ||
// CHECK-SPIRV: %[[#entry_tok4:]] = call token @llvm.experimental.convergence.entry() | ||
// CHECK-SPIRV: %[[RET1:.*]] = call [[TY1:.*]] @llvm.spv.wave.readlane.v4f32([[TY1]] %[[#]], i32 %[[#]]) [ "convergencectrl"(token %[[#entry_tok4]]) ] | ||
// CHECK-DXIL: %[[RET1:.*]] = call [[TY1:.*]] @llvm.dx.wave.readlane.v4f32([[TY1]] %[[#]], i32 %[[#]]) | ||
// CHECK: ret [[TY1]] %[[RET1]] | ||
return WaveReadLaneAt(expr, idx); | ||
} | ||
|
||
// CHECK-DXIL: declare [[TY1]] @llvm.dx.wave.readlane.v4f32([[TY1]], i32) #[[#attr]] | ||
// CHECK-SPIRV: declare [[TY1]] @llvm.spv.wave.readlane.v4f32([[TY1]], i32) #[[#attr]] | ||
|
||
// CHECK: attributes #[[#attr]] = {{{.*}} convergent {{.*}}} |
This file contains 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,38 @@ | ||
// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -emit-llvm-only -disable-llvm-passes -verify | ||
|
||
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_double_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'}} | ||
} | ||
|
||
float3 test_index_int3_type_check(float3 p0, int3 idxs) { | ||
return __builtin_hlsl_wave_read_lane_at(p0, idxs); | ||
// expected-error@-1 {{passing 'int3' (aka 'vector<int, 3>') to parameter of incompatible type 'unsigned int'}} | ||
} | ||
|
||
struct S { float f; }; | ||
|
||
float3 test_index_S_type_check(float3 p0, S idx) { | ||
return __builtin_hlsl_wave_read_lane_at(p0, idx); | ||
// expected-error@-1 {{passing 'S' to parameter of incompatible type 'unsigned int'}} | ||
} | ||
|
||
S test_expr_struct_type_check(S p0, int idx) { | ||
return __builtin_hlsl_wave_read_lane_at(p0, idx); | ||
// expected-error@-1 {{invalid operand of type 'S' where a scalar or vector is required}} | ||
} |
This file contains 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 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 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 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
Oops, something went wrong.