Skip to content

Commit 9498523

Browse files
inbelicadam-yang
authored andcommitted
[HLSL][SPIRV][DXIL] Implement WaveActiveSum intrinsic
- add clang builtin to Builtins.td - link builtin in hlsl_intrinsics - add codegen for spirv intrinsic and two directx intrinsics to retain signedness information of the operands in CGBuiltin.cpp - add semantic analysis in SemaHLSL.cpp - add lowering of spirv intrinsic to spirv backend in SPIRVInstructionSelector.cpp - add lowering of directx intrinsics to WaveActiveOp dxil op in DXIL.td - add test cases to illustrate passes
1 parent 576b538 commit 9498523

File tree

14 files changed

+491
-0
lines changed

14 files changed

+491
-0
lines changed

clang/include/clang/Basic/Builtins.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4795,6 +4795,12 @@ def HLSLWaveActiveCountBits : LangBuiltin<"HLSL_LANG"> {
47954795
let Prototype = "unsigned int(bool)";
47964796
}
47974797

4798+
def HLSLWaveActiveSum : LangBuiltin<"HLSL_LANG"> {
4799+
let Spellings = ["__builtin_hlsl_wave_active_sum"];
4800+
let Attributes = [NoThrow, Const];
4801+
let Prototype = "void (...)";
4802+
}
4803+
47984804
def HLSLWaveGetLaneIndex : LangBuiltin<"HLSL_LANG"> {
47994805
let Spellings = ["__builtin_hlsl_wave_get_lane_index"];
48004806
let Attributes = [NoThrow, Const];

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9299,6 +9299,9 @@ def err_typecheck_expect_scalar_or_vector : Error<
92999299
"a vector of such type is required">;
93009300
def err_typecheck_expect_any_scalar_or_vector : Error<
93019301
"invalid operand of type %0 where a scalar or vector is required">;
9302+
def err_typecheck_expect_scalar_or_vector_not_type : Error<
9303+
"invalid operand of type %0 where %1 or "
9304+
"a vector of such type is not allowed">;
93029305
def err_typecheck_expect_flt_or_vector : Error<
93039306
"invalid operand of type %0 where floating, complex or "
93049307
"a vector of such types is required">;

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19186,6 +19186,23 @@ static Intrinsic::ID getFirstBitHighIntrinsic(CGHLSLRuntime &RT, QualType QT) {
1918619186
return RT.getFirstBitUHighIntrinsic();
1918719187
}
1918819188

19189+
// Return wave active sum that corresponds to the QT scalar type
19190+
static Intrinsic::ID getWaveActiveSumIntrinsic(llvm::Triple::ArchType Arch,
19191+
CGHLSLRuntime &RT, QualType QT) {
19192+
switch (Arch) {
19193+
case llvm::Triple::spirv:
19194+
return llvm::Intrinsic::spv_wave_active_sum;
19195+
case llvm::Triple::dxil: {
19196+
if (QT->isUnsignedIntegerType())
19197+
return llvm::Intrinsic::dx_wave_active_usum;
19198+
return llvm::Intrinsic::dx_wave_active_sum;
19199+
}
19200+
default:
19201+
llvm_unreachable("Intrinsic WaveActiveSum"
19202+
" not supported by target architecture");
19203+
}
19204+
}
19205+
1918919206
Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned BuiltinID,
1919019207
const CallExpr *E,
1919119208
ReturnValueSlot ReturnValue) {
@@ -19491,6 +19508,23 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: {
1949119508
Intrinsic::getOrInsertDeclaration(&CGM.getModule(), ID),
1949219509
ArrayRef{OpExpr});
1949319510
}
19511+
case Builtin::BI__builtin_hlsl_wave_active_sum: {
19512+
// Due to the use of variadic arguments, explicitly retreive argument
19513+
Value *OpExpr = EmitScalarExpr(E->getArg(0));
19514+
llvm::FunctionType *FT = llvm::FunctionType::get(
19515+
OpExpr->getType(), ArrayRef{OpExpr->getType()}, false);
19516+
Intrinsic::ID IID = getWaveActiveSumIntrinsic(
19517+
getTarget().getTriple().getArch(), CGM.getHLSLRuntime(),
19518+
E->getArg(0)->getType());
19519+
19520+
// Get overloaded name
19521+
std::string Name =
19522+
Intrinsic::getName(IID, ArrayRef{OpExpr->getType()}, &CGM.getModule());
19523+
return EmitRuntimeCall(CGM.CreateRuntimeFunction(FT, Name, {},
19524+
/*Local=*/false,
19525+
/*AssumeConvergent=*/true),
19526+
ArrayRef{OpExpr}, "hlsl.wave.active.sum");
19527+
}
1949419528
case Builtin::BI__builtin_hlsl_wave_get_lane_index: {
1949519529
// We don't define a SPIR-V intrinsic, instead it is a SPIR-V built-in
1949619530
// defined in SPIRVBuiltins.td. So instead we manually get the matching name

clang/lib/Headers/hlsl/hlsl_intrinsics.h

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2396,6 +2396,105 @@ __attribute__((convergent)) double3 WaveReadLaneAt(double3, int32_t);
23962396
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_read_lane_at)
23972397
__attribute__((convergent)) double4 WaveReadLaneAt(double4, int32_t);
23982398

2399+
//===----------------------------------------------------------------------===//
2400+
// WaveActiveSum builtins
2401+
//===----------------------------------------------------------------------===//
2402+
2403+
_HLSL_16BIT_AVAILABILITY(shadermodel, 6.0)
2404+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2405+
__attribute((convergent)) half WaveActiveSum(half);
2406+
_HLSL_16BIT_AVAILABILITY(shadermodel, 6.0)
2407+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2408+
__attribute((convergent)) half2 WaveActiveSum(half2);
2409+
_HLSL_16BIT_AVAILABILITY(shadermodel, 6.0)
2410+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2411+
__attribute((convergent)) half3 WaveActiveSum(half3);
2412+
_HLSL_16BIT_AVAILABILITY(shadermodel, 6.0)
2413+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2414+
__attribute((convergent)) half4 WaveActiveSum(half4);
2415+
2416+
#ifdef __HLSL_ENABLE_16_BIT
2417+
_HLSL_AVAILABILITY(shadermodel, 6.0)
2418+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2419+
__attribute((convergent)) int16_t WaveActiveSum(int16_t);
2420+
_HLSL_AVAILABILITY(shadermodel, 6.0)
2421+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2422+
__attribute((convergent)) int16_t2 WaveActiveSum(int16_t2);
2423+
_HLSL_AVAILABILITY(shadermodel, 6.0)
2424+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2425+
__attribute((convergent)) int16_t3 WaveActiveSum(int16_t3);
2426+
_HLSL_AVAILABILITY(shadermodel, 6.0)
2427+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2428+
__attribute((convergent)) int16_t4 WaveActiveSum(int16_t4);
2429+
2430+
_HLSL_AVAILABILITY(shadermodel, 6.0)
2431+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2432+
__attribute((convergent)) uint16_t WaveActiveSum(uint16_t);
2433+
_HLSL_AVAILABILITY(shadermodel, 6.0)
2434+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2435+
__attribute((convergent)) uint16_t2 WaveActiveSum(uint16_t2);
2436+
_HLSL_AVAILABILITY(shadermodel, 6.0)
2437+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2438+
__attribute((convergent)) uint16_t3 WaveActiveSum(uint16_t3);
2439+
_HLSL_AVAILABILITY(shadermodel, 6.0)
2440+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2441+
__attribute((convergent)) uint16_t4 WaveActiveSum(uint16_t4);
2442+
#endif
2443+
2444+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2445+
__attribute((convergent)) int WaveActiveSum(int);
2446+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2447+
__attribute((convergent)) int2 WaveActiveSum(int2);
2448+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2449+
__attribute((convergent)) int3 WaveActiveSum(int3);
2450+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2451+
__attribute((convergent)) int4 WaveActiveSum(int4);
2452+
2453+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2454+
__attribute((convergent)) uint WaveActiveSum(uint);
2455+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2456+
__attribute((convergent)) uint2 WaveActiveSum(uint2);
2457+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2458+
__attribute((convergent)) uint3 WaveActiveSum(uint3);
2459+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2460+
__attribute((convergent)) uint4 WaveActiveSum(uint4);
2461+
2462+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2463+
__attribute((convergent)) int64_t WaveActiveSum(int64_t);
2464+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2465+
__attribute((convergent)) int64_t2 WaveActiveSum(int64_t2);
2466+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2467+
__attribute((convergent)) int64_t3 WaveActiveSum(int64_t3);
2468+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2469+
__attribute((convergent)) int64_t4 WaveActiveSum(int64_t4);
2470+
2471+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2472+
__attribute((convergent)) uint64_t WaveActiveSum(uint64_t);
2473+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2474+
__attribute((convergent)) uint64_t2 WaveActiveSum(uint64_t2);
2475+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2476+
__attribute((convergent)) uint64_t3 WaveActiveSum(uint64_t3);
2477+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2478+
__attribute((convergent)) uint64_t4 WaveActiveSum(uint64_t4);
2479+
2480+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2481+
__attribute((convergent)) float WaveActiveSum(float);
2482+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2483+
__attribute((convergent)) float2 WaveActiveSum(float2);
2484+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2485+
__attribute((convergent)) float3 WaveActiveSum(float3);
2486+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2487+
__attribute((convergent)) float4 WaveActiveSum(float4);
2488+
2489+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2490+
__attribute((convergent)) double WaveActiveSum(double);
2491+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2492+
__attribute((convergent)) double2 WaveActiveSum(double2);
2493+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2494+
__attribute((convergent)) double3 WaveActiveSum(double3);
2495+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2496+
__attribute((convergent)) double4 WaveActiveSum(double4);
2497+
23992498
//===----------------------------------------------------------------------===//
24002499
// sign builtins
24012500
//===----------------------------------------------------------------------===//

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1865,6 +1865,23 @@ static bool CheckAnyScalarOrVector(Sema *S, CallExpr *TheCall,
18651865
return false;
18661866
}
18671867

1868+
static bool CheckNotScalarType(Sema *S, CallExpr *TheCall, QualType Scalar,
1869+
unsigned ArgIndex) {
1870+
assert(TheCall->getNumArgs() >= ArgIndex);
1871+
QualType ArgType = TheCall->getArg(ArgIndex)->getType();
1872+
auto *VTy = ArgType->getAs<VectorType>();
1873+
// is the scalar or vector<scalar>
1874+
if (S->Context.hasSameUnqualifiedType(ArgType, Scalar) ||
1875+
(VTy &&
1876+
S->Context.hasSameUnqualifiedType(VTy->getElementType(), Scalar))) {
1877+
S->Diag(TheCall->getArg(0)->getBeginLoc(),
1878+
diag::err_typecheck_expect_scalar_or_vector_not_type)
1879+
<< ArgType << Scalar;
1880+
return true;
1881+
}
1882+
return false;
1883+
}
1884+
18681885
static bool CheckBoolSelect(Sema *S, CallExpr *TheCall) {
18691886
assert(TheCall->getNumArgs() == 3);
18701887
Expr *Arg1 = TheCall->getArg(1);
@@ -2155,6 +2172,20 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
21552172
TheCall->setType(ArgTyA);
21562173
break;
21572174
}
2175+
case Builtin::BI__builtin_hlsl_wave_active_sum: {
2176+
if (SemaRef.checkArgCount(TheCall, 1))
2177+
return true;
2178+
2179+
// Ensure input expr type is a scalar/vector and the same as the return type
2180+
if (CheckAnyScalarOrVector(&SemaRef, TheCall, 0))
2181+
return true;
2182+
if (CheckNotScalarType(&SemaRef, TheCall, getASTContext().BoolTy, 0))
2183+
return true;
2184+
ExprResult Expr = TheCall->getArg(0);
2185+
QualType ArgTyExpr = Expr.get()->getType();
2186+
TheCall->setType(ArgTyExpr);
2187+
break;
2188+
}
21582189
// Note these are llvm builtins that we want to catch invalid intrinsic
21592190
// generation. Normal handling of these builitns will occur elsewhere.
21602191
case Builtin::BI__builtin_elementwise_bitreverse: {
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -triple \
2+
// RUN: dxil-pc-shadermodel6.3-compute %s -emit-llvm -disable-llvm-passes -o - | \
3+
// RUN: FileCheck %s --check-prefixes=CHECK,CHECK-DXIL
4+
// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -triple \
5+
// RUN: spirv-pc-vulkan-compute %s -emit-llvm -disable-llvm-passes -o - | \
6+
// RUN: FileCheck %s --check-prefixes=CHECK,CHECK-SPIRV
7+
8+
// Test basic lowering to runtime function call.
9+
10+
// CHECK-LABEL: test_int
11+
int test_int(int expr) {
12+
// CHECK-SPIRV: %[[RET:.*]] = call spir_func [[TY:.*]] @llvm.spv.wave.active.sum.i32([[TY]] %[[#]])
13+
// CHECK-DXIL: %[[RET:.*]] = call [[TY:.*]] @llvm.dx.wave.active.sum.i32([[TY]] %[[#]])
14+
// CHECK: ret [[TY]] %[[RET]]
15+
return WaveActiveSum(expr);
16+
}
17+
18+
// CHECK-DXIL: declare [[TY]] @llvm.dx.wave.active.sum.i32([[TY]]) #[[#attr:]]
19+
// CHECK-SPIRV: declare spir_func [[TY]] @llvm.spv.wave.active.sum.i32([[TY]]) #[[#attr:]]
20+
21+
// CHECK-LABEL: test_uint64_t
22+
uint64_t test_uint64_t(uint64_t expr) {
23+
// CHECK-SPIRV: %[[RET:.*]] = call spir_func [[TY:.*]] @llvm.spv.wave.active.sum.i64([[TY]] %[[#]])
24+
// CHECK-DXIL: %[[RET:.*]] = call [[TY:.*]] @llvm.dx.wave.active.usum.i64([[TY]] %[[#]])
25+
// CHECK: ret [[TY]] %[[RET]]
26+
return WaveActiveSum(expr);
27+
}
28+
29+
// CHECK-DXIL: declare [[TY]] @llvm.dx.wave.active.usum.i64([[TY]]) #[[#attr:]]
30+
// CHECK-SPIRV: declare spir_func [[TY]] @llvm.spv.wave.active.sum.i64([[TY]]) #[[#attr:]]
31+
32+
// Test basic lowering to runtime function call with array and float value.
33+
34+
// CHECK-LABEL: test_floatv4
35+
float4 test_floatv4(float4 expr) {
36+
// CHECK-SPIRV: %[[RET1:.*]] = call spir_func [[TY1:.*]] @llvm.spv.wave.active.sum.v4f32([[TY1]] %[[#]]
37+
// CHECK-DXIL: %[[RET1:.*]] = call [[TY1:.*]] @llvm.dx.wave.active.sum.v4f32([[TY1]] %[[#]])
38+
// CHECK: ret [[TY1]] %[[RET1]]
39+
return WaveActiveSum(expr);
40+
}
41+
42+
// CHECK-DXIL: declare [[TY1]] @llvm.dx.wave.active.sum.v4f32([[TY1]]) #[[#attr]]
43+
// CHECK-SPIRV: declare spir_func [[TY1]] @llvm.spv.wave.active.sum.v4f32([[TY1]]) #[[#attr]]
44+
45+
// CHECK: attributes #[[#attr]] = {{{.*}} convergent {{.*}}}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -emit-llvm-only -disable-llvm-passes -verify
2+
3+
int test_too_few_arg() {
4+
return __builtin_hlsl_wave_active_sum();
5+
// expected-error@-1 {{too few arguments to function call, expected 1, have 0}}
6+
}
7+
8+
float2 test_too_many_arg(float2 p0) {
9+
return __builtin_hlsl_wave_active_sum(p0, p0);
10+
// expected-error@-1 {{too many arguments to function call, expected 1, have 2}}
11+
}
12+
13+
bool test_expr_bool_type_check(bool p0) {
14+
return __builtin_hlsl_wave_active_sum(p0);
15+
// expected-error@-1 {{invalid operand of type 'bool' where 'bool' or a vector of such type is not allowed}}
16+
}
17+
18+
bool2 test_expr_bool_vec_type_check(bool2 p0) {
19+
return __builtin_hlsl_wave_active_sum(p0);
20+
// expected-error@-1 {{invalid operand of type 'bool2' (aka 'vector<bool, 2>') where 'bool' or a vector of such type is not allowed}}
21+
}
22+
23+
struct S { float f; };
24+
25+
S test_expr_struct_type_check(S p0) {
26+
return __builtin_hlsl_wave_active_sum(p0);
27+
// expected-error@-1 {{invalid operand of type 'S' where a scalar or vector is required}}
28+
}

llvm/include/llvm/IR/IntrinsicsDirectX.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ def int_dx_wave_active_countbits : DefaultAttrsIntrinsic<[llvm_i32_ty], [llvm_i1
105105
def int_dx_wave_all : DefaultAttrsIntrinsic<[llvm_i1_ty], [llvm_i1_ty], [IntrConvergent, IntrNoMem]>;
106106
def int_dx_wave_any : DefaultAttrsIntrinsic<[llvm_i1_ty], [llvm_i1_ty], [IntrConvergent, IntrNoMem]>;
107107
def int_dx_wave_getlaneindex : DefaultAttrsIntrinsic<[llvm_i32_ty], [], [IntrConvergent, IntrNoMem]>;
108+
def int_dx_wave_active_sum : DefaultAttrsIntrinsic<[llvm_any_ty], [LLVMMatchType<0>], [IntrConvergent, IntrNoMem]>;
109+
def int_dx_wave_active_usum : DefaultAttrsIntrinsic<[llvm_anyint_ty], [LLVMMatchType<0>], [IntrConvergent, IntrNoMem]>;
108110
def int_dx_wave_is_first_lane : DefaultAttrsIntrinsic<[llvm_i1_ty], [], [IntrConvergent]>;
109111
def int_dx_wave_readlane : DefaultAttrsIntrinsic<[llvm_any_ty], [LLVMMatchType<0>, llvm_i32_ty], [IntrConvergent, IntrNoMem]>;
110112
def int_dx_sign : DefaultAttrsIntrinsic<[LLVMScalarOrSameVectorWidth<0, llvm_i32_ty>], [llvm_any_ty], [IntrNoMem]>;

llvm/include/llvm/IR/IntrinsicsSPIRV.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ let TargetPrefix = "spv" in {
9191
def int_spv_wave_active_countbits : DefaultAttrsIntrinsic<[llvm_i32_ty], [llvm_i1_ty], [IntrConvergent, IntrNoMem]>;
9292
def int_spv_wave_all : DefaultAttrsIntrinsic<[llvm_i1_ty], [llvm_i1_ty], [IntrConvergent, IntrNoMem]>;
9393
def int_spv_wave_any : DefaultAttrsIntrinsic<[llvm_i1_ty], [llvm_i1_ty], [IntrConvergent, IntrNoMem]>;
94+
def int_spv_wave_active_sum : DefaultAttrsIntrinsic<[llvm_any_ty], [LLVMMatchType<0>], [IntrConvergent, IntrNoMem]>;
9495
def int_spv_wave_is_first_lane : DefaultAttrsIntrinsic<[llvm_i1_ty], [], [IntrConvergent]>;
9596
def int_spv_wave_readlane : DefaultAttrsIntrinsic<[llvm_any_ty], [LLVMMatchType<0>, llvm_i32_ty], [IntrConvergent, IntrNoMem]>;
9697
def int_spv_sign : DefaultAttrsIntrinsic<[LLVMScalarOrSameVectorWidth<0, llvm_i32_ty>], [llvm_any_ty], [IntrNoMem]>;

llvm/lib/Target/DirectX/DXIL.td

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,14 @@ defvar BarrierMode_GroupMemoryBarrierWithGroupSync = 9;
303303
defvar BarrierMode_AllMemoryBarrier = 10;
304304
defvar BarrierMode_AllMemoryBarrierWithGroupSync = 11;
305305

306+
defvar WaveOpKind_Sum = 0;
307+
defvar WaveOpKind_Product = 1;
308+
defvar WaveOpKind_Min = 2;
309+
defvar WaveOpKind_Max = 3;
310+
311+
defvar SignedOpKind_Signed = 0;
312+
defvar SignedOpKind_Unsigned = 1;
313+
306314
// Intrinsic arg selection
307315
class IntrinArgSelectType;
308316
def IntrinArgSelect_Index : IntrinArgSelectType;
@@ -979,6 +987,24 @@ def WaveActiveAnyTrue : DXILOp<113, waveAnyTrue> {
979987
let stages = [Stages<DXIL1_0, [all_stages]>];
980988
}
981989

990+
def WaveActiveOp : DXILOp<119, waveActiveOp> {
991+
let Doc = "returns the result of the operation across waves";
992+
let intrinsics = [
993+
IntrinSelect<
994+
int_dx_wave_active_sum,
995+
[ IntrinArgIndex<0>, IntrinArgI8<WaveOpKind_Sum>, IntrinArgI8<SignedOpKind_Signed> ]>,
996+
IntrinSelect<
997+
int_dx_wave_active_usum,
998+
[ IntrinArgIndex<0>, IntrinArgI8<WaveOpKind_Sum>, IntrinArgI8<SignedOpKind_Unsigned> ]>,
999+
];
1000+
1001+
let arguments = [OverloadTy, Int8Ty, Int8Ty];
1002+
let result = OverloadTy;
1003+
let overloads = [Overloads<DXIL1_0, [HalfTy, FloatTy, DoubleTy, Int16Ty, Int32Ty, Int64Ty]>];
1004+
let stages = [Stages<DXIL1_0, [all_stages]>];
1005+
let attributes = [Attributes<DXIL1_0, [ReadNone]>];
1006+
}
1007+
9821008
def WaveIsFirstLane : DXILOp<110, waveIsFirstLane> {
9831009
let Doc = "returns 1 for the first lane in the wave";
9841010
let intrinsics = [ IntrinSelect<int_dx_wave_is_first_lane> ];

0 commit comments

Comments
 (0)