3030#include < optional>
3131#include < vector>
3232
33+ #define GENERATE_HLSL_INTRINSIC_FUNCTION_DEFAULT (FunctionName, \
34+ IntrinsicPostfix) \
35+ GENERATE_HLSL_INTRINSIC_FUNCTION (FunctionName, IntrinsicPostfix, 1 , 1 )
36+
3337// A function generator macro for picking the right intrinsic
3438// for the target backend
35- #define GENERATE_HLSL_INTRINSIC_FUNCTION (FunctionName, IntrinsicPostfix ) \
39+ #define GENERATE_HLSL_INTRINSIC_FUNCTION (FunctionName, IntrinsicPostfix, \
40+ IncludeDXIL, IncludeSPIRV) \
3641 llvm::Intrinsic::ID get##FunctionName##Intrinsic() { \
3742 llvm::Triple::ArchType Arch = getArch (); \
3843 switch (Arch) { \
39- case llvm::Triple::dxil: \
40- return llvm::Intrinsic::dx_##IntrinsicPostfix; \
41- case llvm::Triple::spirv: \
42- return llvm::Intrinsic::spv_##IntrinsicPostfix; \
44+ /* Include DXIL case only if IncludeDXIL is true */ \
45+ IF_INCLUDE (IncludeDXIL, case llvm::Triple::dxil \
46+ : return llvm::Intrinsic::dx_##IntrinsicPostfix;) \
47+ /* Include SPIRV case only if IncludeSPIRV is true */ \
48+ IF_INCLUDE (IncludeSPIRV, case llvm::Triple::spirv \
49+ : return llvm::Intrinsic::spv_##IntrinsicPostfix;) \
50+ \
4351 default : \
4452 llvm_unreachable (" Intrinsic " #IntrinsicPostfix \
4553 " not supported by target architecture" ); \
4654 } \
4755 }
4856
57+ #define IF_INCLUDE (Condition, Code ) IF_INCLUDE_IMPL(Condition, Code)
58+ #define IF_INCLUDE_IMPL (Condition, Code ) IF_INCLUDE_##Condition(Code)
59+
60+ #define IF_INCLUDE_1 (Code ) Code
61+ #define IF_INCLUDE_0 (Code )
62+
4963namespace llvm {
5064class GlobalVariable ;
5165class Function ;
@@ -72,36 +86,43 @@ class CGHLSLRuntime {
7286 // Start of reserved area for HLSL intrinsic getters.
7387 // ===----------------------------------------------------------------------===//
7488
75- GENERATE_HLSL_INTRINSIC_FUNCTION (All, all)
76- GENERATE_HLSL_INTRINSIC_FUNCTION (Any, any)
77- GENERATE_HLSL_INTRINSIC_FUNCTION (Cross, cross)
78- GENERATE_HLSL_INTRINSIC_FUNCTION (Degrees, degrees)
79- GENERATE_HLSL_INTRINSIC_FUNCTION (Frac, frac)
80- GENERATE_HLSL_INTRINSIC_FUNCTION (Lerp, lerp)
81- GENERATE_HLSL_INTRINSIC_FUNCTION (Normalize, normalize)
82- GENERATE_HLSL_INTRINSIC_FUNCTION (Rsqrt, rsqrt)
83- GENERATE_HLSL_INTRINSIC_FUNCTION (Saturate, saturate)
84- GENERATE_HLSL_INTRINSIC_FUNCTION (Sign, sign)
85- GENERATE_HLSL_INTRINSIC_FUNCTION (Step, step)
86- GENERATE_HLSL_INTRINSIC_FUNCTION (Radians, radians)
87- GENERATE_HLSL_INTRINSIC_FUNCTION (ThreadId, thread_id)
88- GENERATE_HLSL_INTRINSIC_FUNCTION (FDot, fdot)
89- GENERATE_HLSL_INTRINSIC_FUNCTION (SDot, sdot)
90- GENERATE_HLSL_INTRINSIC_FUNCTION (UDot, udot)
91- GENERATE_HLSL_INTRINSIC_FUNCTION (Dot4AddI8Packed, dot4add_i8packed)
92- GENERATE_HLSL_INTRINSIC_FUNCTION (Dot4AddU8Packed, dot4add_u8packed)
93- GENERATE_HLSL_INTRINSIC_FUNCTION (WaveActiveAnyTrue, wave_any)
94- GENERATE_HLSL_INTRINSIC_FUNCTION (WaveActiveCountBits, wave_active_countbits)
95- GENERATE_HLSL_INTRINSIC_FUNCTION (WaveIsFirstLane, wave_is_first_lane)
96- GENERATE_HLSL_INTRINSIC_FUNCTION (WaveReadLaneAt, wave_readlane)
97- GENERATE_HLSL_INTRINSIC_FUNCTION (FirstBitUHigh, firstbituhigh)
98- GENERATE_HLSL_INTRINSIC_FUNCTION (FirstBitSHigh, firstbitshigh)
99- GENERATE_HLSL_INTRINSIC_FUNCTION (NClamp, nclamp)
100- GENERATE_HLSL_INTRINSIC_FUNCTION (SClamp, sclamp)
101- GENERATE_HLSL_INTRINSIC_FUNCTION (UClamp, uclamp)
102-
103- GENERATE_HLSL_INTRINSIC_FUNCTION (CreateHandleFromBinding, handle_fromBinding)
104- GENERATE_HLSL_INTRINSIC_FUNCTION (BufferUpdateCounter, bufferUpdateCounter)
89+ GENERATE_HLSL_INTRINSIC_FUNCTION_DEFAULT (All, all)
90+ GENERATE_HLSL_INTRINSIC_FUNCTION_DEFAULT (Any, any)
91+ GENERATE_HLSL_INTRINSIC_FUNCTION_DEFAULT (Cross, cross)
92+ GENERATE_HLSL_INTRINSIC_FUNCTION_DEFAULT (Degrees, degrees)
93+ GENERATE_HLSL_INTRINSIC_FUNCTION (Distance, distance, /* IncludeDXIL*/ 0 ,
94+ /* IncludeSPIRV*/ 1 )
95+ GENERATE_HLSL_INTRINSIC_FUNCTION_DEFAULT (Frac, frac)
96+ GENERATE_HLSL_INTRINSIC_FUNCTION (Length, length, /* IncludeDXIL*/ 0 ,
97+ /* IncludeSPIRV*/ 1 )
98+ GENERATE_HLSL_INTRINSIC_FUNCTION_DEFAULT (Lerp, lerp)
99+ GENERATE_HLSL_INTRINSIC_FUNCTION_DEFAULT (Normalize, normalize)
100+ GENERATE_HLSL_INTRINSIC_FUNCTION_DEFAULT (Rsqrt, rsqrt)
101+ GENERATE_HLSL_INTRINSIC_FUNCTION_DEFAULT (Saturate, saturate)
102+ GENERATE_HLSL_INTRINSIC_FUNCTION_DEFAULT (Sign, sign)
103+ GENERATE_HLSL_INTRINSIC_FUNCTION_DEFAULT (Step, step)
104+ GENERATE_HLSL_INTRINSIC_FUNCTION_DEFAULT (Radians, radians)
105+ GENERATE_HLSL_INTRINSIC_FUNCTION_DEFAULT (ThreadId, thread_id)
106+ GENERATE_HLSL_INTRINSIC_FUNCTION_DEFAULT (FDot, fdot)
107+ GENERATE_HLSL_INTRINSIC_FUNCTION_DEFAULT (SDot, sdot)
108+ GENERATE_HLSL_INTRINSIC_FUNCTION_DEFAULT (UDot, udot)
109+ GENERATE_HLSL_INTRINSIC_FUNCTION_DEFAULT (Dot4AddI8Packed, dot4add_i8packed)
110+ GENERATE_HLSL_INTRINSIC_FUNCTION_DEFAULT (Dot4AddU8Packed, dot4add_u8packed)
111+ GENERATE_HLSL_INTRINSIC_FUNCTION_DEFAULT (WaveActiveAnyTrue, wave_any)
112+ GENERATE_HLSL_INTRINSIC_FUNCTION_DEFAULT (WaveActiveCountBits,
113+ wave_active_countbits)
114+ GENERATE_HLSL_INTRINSIC_FUNCTION_DEFAULT (WaveIsFirstLane, wave_is_first_lane)
115+ GENERATE_HLSL_INTRINSIC_FUNCTION_DEFAULT (WaveReadLaneAt, wave_readlane)
116+ GENERATE_HLSL_INTRINSIC_FUNCTION_DEFAULT (FirstBitUHigh, firstbituhigh)
117+ GENERATE_HLSL_INTRINSIC_FUNCTION_DEFAULT (FirstBitSHigh, firstbitshigh)
118+ GENERATE_HLSL_INTRINSIC_FUNCTION_DEFAULT (NClamp, nclamp)
119+ GENERATE_HLSL_INTRINSIC_FUNCTION_DEFAULT (SClamp, sclamp)
120+ GENERATE_HLSL_INTRINSIC_FUNCTION_DEFAULT (UClamp, uclamp)
121+
122+ GENERATE_HLSL_INTRINSIC_FUNCTION_DEFAULT (CreateHandleFromBinding,
123+ handle_fromBinding)
124+ GENERATE_HLSL_INTRINSIC_FUNCTION_DEFAULT (BufferUpdateCounter,
125+ bufferUpdateCounter)
105126
106127 // ===----------------------------------------------------------------------===//
107128 // End of reserved area for HLSL intrinsic getters.
0 commit comments