99#ifndef _HLSL_HLSL_DETAILS_H_
1010#define _HLSL_HLSL_DETAILS_H_
1111
12- #if __is_target_arch(dxil)
13- #define IS_ARCH_DXIL 1
14- #else
15- #define IS_ARCH_DXIL 0
16- #endif
17-
18- #if __is_target_arch(spirv)
19- #define IS_ARCH_SPIRV 1
20- #else
21- #define IS_ARCH_SPIRV 0
22- #endif
23-
24- #define ARCH_CONDITION (arch ) \
25- if (IS_ARCH_##arch) \
26- return true ;
27-
28- // Note: arch is used to bypass
29- // the generic implementation
30- #define EXPAND_ARCH_CONDITIONS (arch ) \
31- ARCH_CONDITION (arch) \
32- /* Add more architectures as needed */
33-
34- #define DEFINE_TARGET_LOWERING (function_name, ...) \
35- constexpr bool Has##function_name##Lowering() { \
36- EXPAND_ARCH_CONDITIONS (__VA_ARGS__) \
37- return false ; /* Default case if no match */ \
38- }
39-
4012namespace hlsl {
4113
4214namespace __detail {
@@ -69,7 +41,6 @@ constexpr enable_if_t<sizeof(U) == sizeof(T), U> bit_cast(T F) {
6941 return __builtin_bit_cast (U, F);
7042}
7143
72- DEFINE_TARGET_LOWERING (Length, SPIRV)
7344template <typename T>
7445constexpr enable_if_t <is_same<float , T>::value || is_same<half, T>::value, T>
7546length_impl (T X) {
@@ -79,14 +50,14 @@ length_impl(T X) {
7950template <typename T, int N>
8051constexpr enable_if_t <is_same<float , T>::value || is_same<half, T>::value, T>
8152length_vec_impl (vector<T, N> X) {
82- if (HasLengthLowering ())
83- return __builtin_hlsl_length (X);
53+ #if (__has_builtin(__builtin_hlsl_length))
54+ return __builtin_hlsl_length (X);
55+ #endif
8456 vector<T, N> XSquared = X * X;
8557 T XSquaredSum = __builtin_hlsl_reduce_add (XSquared);
8658 return __builtin_elementwise_sqrt (XSquaredSum);
8759}
8860
89- DEFINE_TARGET_LOWERING (Distance, SPIRV)
9061template <typename T>
9162constexpr enable_if_t <is_same<float , T>::value || is_same<half, T>::value, T>
9263distance_impl (T X, T Y) {
@@ -96,8 +67,9 @@ distance_impl(T X, T Y) {
9667template <typename T, int N>
9768constexpr enable_if_t <is_same<float , T>::value || is_same<half, T>::value, T>
9869distance_vec_impl (vector<T, N> X, vector<T, N> Y) {
99- if (HasDistanceLowering ())
100- return __builtin_hlsl_distance (X, Y);
70+ #if (__has_builtin(__builtin_hlsl_distance))
71+ return __builtin_hlsl_distance (X, Y);
72+ #endif
10173 return length_vec_impl (X - Y);
10274}
10375
0 commit comments