|
1 | | -//===----- detail.h - HLSL definitions for intrinsics ----------===// |
| 1 | +//===----- hlsl_detail.h - HLSL definitions for intrinsics ----------------===// |
2 | 2 | // |
3 | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | 4 | // See https://llvm.org/LICENSE.txt for license information. |
|
9 | 9 | #ifndef _HLSL_HLSL_DETAILS_H_ |
10 | 10 | #define _HLSL_HLSL_DETAILS_H_ |
11 | 11 |
|
12 | | -#include "hlsl_alias_intrinsics.h" |
13 | | - |
14 | 12 | namespace hlsl { |
15 | 13 |
|
16 | 14 | namespace __detail { |
@@ -43,59 +41,9 @@ constexpr enable_if_t<sizeof(U) == sizeof(T), U> bit_cast(T F) { |
43 | 41 | return __builtin_bit_cast(U, F); |
44 | 42 | } |
45 | 43 |
|
46 | | -constexpr vector<uint, 4> d3d_color_to_ubyte4_impl(vector<float, 4> V) { |
47 | | - // Use the same scaling factor used by FXC, and DXC for DXIL |
48 | | - // (i.e., 255.001953) |
49 | | - // https://github.com/microsoft/DirectXShaderCompiler/blob/070d0d5a2beacef9eeb51037a9b04665716fd6f3/lib/HLSL/HLOperationLower.cpp#L666C1-L697C2 |
50 | | - // The DXC implementation refers to a comment on the following stackoverflow |
51 | | - // discussion to justify the scaling factor: "Built-in rounding, necessary |
52 | | - // because of truncation. 0.001953 * 256 = 0.5" |
53 | | - // https://stackoverflow.com/questions/52103720/why-does-d3dcolortoubyte4-multiplies-components-by-255-001953f |
54 | | - return V.zyxw * 255.001953f; |
55 | | -} |
56 | | - |
57 | | -template <typename T> |
58 | | -constexpr enable_if_t<is_same<float, T>::value || is_same<half, T>::value, T> |
59 | | -length_impl(T X) { |
60 | | - return abs(X); |
61 | | -} |
62 | | - |
63 | | -template <typename T, int N> |
64 | | -constexpr enable_if_t<is_same<float, T>::value || is_same<half, T>::value, T> |
65 | | -length_vec_impl(vector<T, N> X) { |
66 | | -#if (__has_builtin(__builtin_spirv_length)) |
67 | | - return __builtin_spirv_length(X); |
68 | | -#else |
69 | | - return sqrt(dot(X, X)); |
70 | | -#endif |
71 | | -} |
72 | | - |
73 | | -template <typename T> |
74 | | -constexpr enable_if_t<is_same<float, T>::value || is_same<half, T>::value, T> |
75 | | -distance_impl(T X, T Y) { |
76 | | - return length_impl(X - Y); |
77 | | -} |
78 | | - |
79 | | -template <typename T, int N> |
80 | | -constexpr enable_if_t<is_same<float, T>::value || is_same<half, T>::value, T> |
81 | | -distance_vec_impl(vector<T, N> X, vector<T, N> Y) { |
82 | | - return length_vec_impl(X - Y); |
83 | | -} |
84 | | - |
85 | | -template <typename T> |
86 | | -constexpr enable_if_t<is_same<float, T>::value || is_same<half, T>::value, T> |
87 | | -reflect_impl(T I, T N) { |
88 | | - return I - 2 * N * I * N; |
89 | | -} |
90 | | - |
91 | | -template <typename T, int L> |
92 | | -constexpr vector<T, L> reflect_vec_impl(vector<T, L> I, vector<T, L> N) { |
93 | | -#if (__has_builtin(__builtin_spirv_reflect)) |
94 | | - return __builtin_spirv_reflect(I, N); |
95 | | -#else |
96 | | - return I - 2 * N * dot(I, N); |
97 | | -#endif |
98 | | -} |
| 44 | +template <typename T> struct is_arithmetic { |
| 45 | + static const bool Value = __is_arithmetic(T); |
| 46 | +}; |
99 | 47 |
|
100 | 48 | } // namespace __detail |
101 | 49 | } // namespace hlsl |
|
0 commit comments