2
2
#define _NBL_BUILTIN_HLSL_SPIRV_INTRINSICS_GLSL_STD_450_INCLUDED_
3
3
4
4
#ifdef __HLSL_VERSION
5
+ #include <nbl/builtin/hlsl/vector_utils/vector_traits.hlsl>
6
+ #include <nbl/builtin/hlsl/matrix_utils/matrix_traits.hlsl>
5
7
#include <nbl/builtin/hlsl/cpp_compat/basic.h>
6
8
#include <nbl/builtin/hlsl/concepts.hlsl>
7
9
#include "spirv/unified1/GLSL.std.450.h"
@@ -12,70 +14,81 @@ namespace hlsl
12
14
{
13
15
namespace spirv
14
16
{
15
- // Find MSB and LSB restricted to 32-bit width component types https://registry.khronos.org/SPIR-V/specs/unified1/GLSL.std.450.html
16
- template<typename Integral32 NBL_FUNC_REQUIRES (is_same_v<Integral32, int32_t> || is_same_v<Integral32, uint32_t>)
17
- [[vk::ext_instruction (GLSLstd450::GLSLstd450FindILsb, "GLSL.std.450" )]]
18
- Integral32 findILsb (Integral32 value);
19
17
20
- template<int N>
21
- [[vk::ext_instruction (GLSLstd450::GLSLstd450FindILsb, "GLSL.std.450" )]]
22
- vector <int32_t, N> findILsb (vector <int32_t, N> value);
18
+ namespace concepts
19
+ {
20
+ // scalar or vector whose component type is floating-point.
21
+ template<typename T>
22
+ NBL_BOOL_CONCEPT FloatingPointVectorOrScalar = is_floating_point_v<T> && (!is_matrix_v<T>);
23
+ // scalar or vector whose component type is 16-bit or 32-bit floating-point.
24
+ template<typename T>
25
+ NBL_BOOL_CONCEPT FloatingPointVectorOrScalar32or16BitSize = FloatingPointVectorOrScalar<T> && (sizeof (typename vector_traits<T>::scalar_type) == 4 || sizeof (typename vector_traits<T>::scalar_type) == 2 );
26
+ //is interpreted as signed
27
+ //integer scalar or integer vector types
28
+ template<typename T>
29
+ NBL_BOOL_CONCEPT IntegralVectorOrScalar = is_integral_v<T> && is_signed_v<T> && !is_matrix_v<T>;
30
+ //interpreted as unsigned
31
+ //integer scalar or integer vector types
32
+ template<typename T>
33
+ NBL_BOOL_CONCEPT UnsignedIntegralVectorOrScalar = is_integral_v<T> && is_unsigned_v<T> && !is_matrix_v<T>;
34
+ //be signed integer scalar or signed integer vector types
35
+ //This instruction is currently limited to 32 - bit width components.
36
+ template<typename T>
37
+ NBL_BOOL_CONCEPT IntegralVectorOrScalar32BitSize = IntegralVectorOrScalar<T> && (sizeof (typename vector_traits<T>::scalar_type) == 4 );
38
+ //be unsigned integer scalar or unsigned integer vector types
39
+ //This instruction is currently limited to 32 - bit width components.
40
+ template<typename T>
41
+ NBL_BOOL_CONCEPT UnsignedIntegralVectorOrScalar32BitSize = UnsignedIntegralVectorOrScalar<T> && (sizeof (typename vector_traits<T>::scalar_type) == 4 );
42
+ }
23
43
24
- template<int N>
44
+ // Find MSB and LSB restricted to 32-bit width component types https://registry.khronos.org/SPIR-V/specs/unified1/GLSL.std.450.html
45
+ template<typename T NBL_FUNC_REQUIRES (concepts::IntegralVectorOrScalar32BitSize<T> || concepts::UnsignedIntegralVectorOrScalar32BitSize<T>)
25
46
[[vk::ext_instruction (GLSLstd450::GLSLstd450FindILsb, "GLSL.std.450" )]]
26
- vector <uint32_t, N> findILsb (vector <uint32_t, N> value);
27
-
28
- template<typename Int32_t NBL_FUNC_REQUIRES (is_same_v<Int32_t, int32_t>)
29
- [[vk::ext_instruction (GLSLstd450::GLSLstd450FindSMsb, "GLSL.std.450" )]]
30
- int32_t findSMsb (Int32_t value);
47
+ T findILsb (T value);
31
48
32
- template<int N>
49
+ template<typename T NBL_FUNC_REQUIRES (concepts::IntegralVectorOrScalar32BitSize<T>)
33
50
[[vk::ext_instruction (GLSLstd450::GLSLstd450FindSMsb, "GLSL.std.450" )]]
34
- vector <int32_t, N> findSMsb (vector <int32_t, N> value);
35
-
36
- template<typename Uint32_t NBL_FUNC_REQUIRES (is_same_v<Uint32_t, uint32_t>)
37
- [[vk::ext_instruction (GLSLstd450::GLSLstd450FindUMsb, "GLSL.std.450" )]]
38
- int32_t findUMsb (Uint32_t value);
51
+ T findSMsb (T value);
39
52
40
- template<int N>
53
+ template<typename T NBL_FUNC_REQUIRES (concepts::UnsignedIntegralVectorOrScalar32BitSize<T>)
41
54
[[vk::ext_instruction (GLSLstd450::GLSLstd450FindUMsb, "GLSL.std.450" )]]
42
- vector <uint32_t, N> findUMsb (vector <uint32_t, N> value);
55
+ T findUMsb (T value);
43
56
44
- template<typename FloatingPoint>
57
+ template<typename T NBL_FUNC_REQUIRES (concepts::FloatingPointVectorOrScalar32or16BitSize<T>)
45
58
[[vk::ext_instruction (GLSLstd450::GLSLstd450Pow, "GLSL.std.450" )]]
46
- enable_if_t<is_floating_point<FloatingPoint>::value && !is_matrix_v<FloatingPoint>, FloatingPoint> pow (FloatingPoint lhs, FloatingPoint rhs);
59
+ T pow (T lhs, T rhs);
47
60
48
- template<typename FloatingPoint>
61
+ template<typename T NBL_FUNC_REQUIRES (concepts::FloatingPointVectorOrScalar32or16BitSize<T>)
49
62
[[vk::ext_instruction (GLSLstd450::GLSLstd450Exp, "GLSL.std.450" )]]
50
- enable_if_t<is_floating_point<FloatingPoint>::value && !is_matrix_v<FloatingPoint>, FloatingPoint> exp (FloatingPoint val);
63
+ T exp (T val);
51
64
52
- template<typename FloatingPoint>
65
+ template<typename T NBL_FUNC_REQUIRES (concepts::FloatingPointVectorOrScalar32or16BitSize<T>)
53
66
[[vk::ext_instruction (GLSLstd450::GLSLstd450Exp2, "GLSL.std.450" )]]
54
- enable_if_t<is_floating_point<FloatingPoint>::value && !is_matrix_v<FloatingPoint>, FloatingPoint> exp2 (FloatingPoint val);
67
+ T exp2 (T val);
55
68
56
- template<typename FloatingPoint>
69
+ template<typename T NBL_FUNC_REQUIRES (concepts::FloatingPointVectorOrScalar32or16BitSize<T>)
57
70
[[vk::ext_instruction (GLSLstd450::GLSLstd450Log, "GLSL.std.450" )]]
58
- enable_if_t<is_floating_point<FloatingPoint>::value && !is_matrix_v<FloatingPoint>, FloatingPoint> log (FloatingPoint val);
71
+ T log (T val);
59
72
60
- template<typename FloatingPoint>
73
+ template<typename T NBL_FUNC_REQUIRES (concepts::FloatingPointVectorOrScalar<T>)
61
74
[[vk::ext_instruction (GLSLstd450::GLSLstd450Sqrt, "GLSL.std.450" )]]
62
- enable_if_t<is_floating_point_v<FloatingPoint> && !is_matrix_v<FloatingPoint>, FloatingPoint> sqrt (FloatingPoint val);
75
+ T sqrt (T val);
63
76
64
- template<typename FloatingPoint>
77
+ template<typename T NBL_FUNC_REQUIRES (concepts::FloatingPointVectorOrScalar<T>)
65
78
[[vk::ext_instruction (GLSLstd450::GLSLstd450InverseSqrt, "GLSL.std.450" )]]
66
- enable_if_t<is_floating_point_v<FloatingPoint> && !is_matrix_v<FloatingPoint>, FloatingPoint> inverseSqrt (FloatingPoint val);
79
+ T inverseSqrt (T val);
67
80
68
- template<typename FloatingPoint>
81
+ template<typename T NBL_FUNC_REQUIRES (concepts::FloatingPointVectorOrScalar<T>)
69
82
[[vk::ext_instruction (GLSLstd450::GLSLstd450Floor, "GLSL.std.450" )]]
70
- enable_if_t<is_floating_point_v<FloatingPoint> && !is_matrix_v<FloatingPoint>, FloatingPoint> floor (FloatingPoint val);
83
+ T floor (T val);
71
84
72
- template<typename FloatingPoint>
85
+ template<typename T NBL_FUNC_REQUIRES (concepts::FloatingPointVectorOrScalar<T> && is_scalar_v<T>)
73
86
[[vk::ext_instruction (GLSLstd450::GLSLstd450Cross, "GLSL.std.450" )]]
74
- enable_if_t<is_floating_point_v<FloatingPoint>, vector <FloatingPoint , 3 > > cross (NBL_CONST_REF_ARG (vector <FloatingPoint , 3 >) lhs, NBL_CONST_REF_ARG (vector <FloatingPoint , 3 >) rhs);
87
+ vector <T , 3 > cross (NBL_CONST_REF_ARG (vector <T , 3 >) lhs, NBL_CONST_REF_ARG (vector <T , 3 >) rhs);
75
88
76
- template<typename FloatingPoint>
89
+ template<typename T NBL_FUNC_REQUIRES (concepts::FloatingPointVectorOrScalar<T>)
77
90
[[vk::ext_instruction (GLSLstd450::GLSLstd450FMix, "GLSL.std.450" )]]
78
- enable_if_t<is_floating_point_v<FloatingPoint> && !is_matrix_v<FloatingPoint>, FloatingPoint> fMix (FloatingPoint x, FloatingPoint y, FloatingPoint a);
91
+ T fMix (T x, T y, T a);
79
92
80
93
template<typename T, int N>
81
94
[[vk::ext_instruction (GLSLstd450::GLSLstd450Determinant, "GLSL.std.450" )]]
@@ -94,63 +107,62 @@ float32_t4 unpackSnorm4x8(uint32_t p);
94
107
[[vk::ext_instruction (GLSLstd450UnpackUnorm4x8, "GLSL.std.450" )]]
95
108
float32_t4 unpackUnorm4x8 (uint32_t p);
96
109
97
- template<typename FloatingPointVector>
110
+ template<typename T NBL_FUNC_REQUIRES (concepts::FloatingPointVectorOrScalar<T>)
98
111
[[vk::ext_instruction (GLSLstd450Length, "GLSL.std.450" )]]
99
- enable_if_t<is_floating_point_v<FloatingPointVector>&& is_vector_v<FloatingPointVector>, FloatingPointVector> length (FloatingPointVector vec);
112
+ typename vector_traits<T>::scalar_type length (T vec);
100
113
101
- template<typename FloatingPointVector>
114
+ template<typename T NBL_FUNC_REQUIRES (concepts::FloatingPointVectorOrScalar<T>)
102
115
[[vk::ext_instruction (GLSLstd450Normalize, "GLSL.std.450" )]]
103
- enable_if_t<is_floating_point_v<FloatingPointVector> && is_vector_v<FloatingPointVector>, FloatingPointVector> normalize (FloatingPointVector vec);
116
+ T normalize (T vec);
104
117
105
- // TODO: will not work for vectors, fix
106
- template<typename FloatingPoint>
118
+ template<typename T NBL_FUNC_REQUIRES (concepts::FloatingPointVectorOrScalar<T>)
107
119
[[vk::ext_instruction (GLSLstd450FClamp, "GLSL.std.450" )]]
108
- enable_if_t<is_floating_point_v<FloatingPoint>, FloatingPoint> fClamp (FloatingPoint val, FloatingPoint min , FloatingPoint max );
109
- template<typename UnsignedInteger>
120
+ T fClamp (T val, T min , T max );
121
+ template<typename T NBL_FUNC_REQUIRES (concepts::UnsignedIntegralVectorOrScalar<T>)
110
122
[[vk::ext_instruction (GLSLstd450UClamp, "GLSL.std.450" )]]
111
- enable_if_t<is_integral_v<UnsignedInteger> && !is_signed_v<UnsignedInteger>, UnsignedInteger> uClamp (UnsignedInteger val, UnsignedInteger min , UnsignedInteger max );
112
- template<typename Integer>
123
+ T uClamp (T val, T min , T max );
124
+ template<typename T NBL_FUNC_REQUIRES (concepts::IntegralVectorOrScalar<T>)
113
125
[[vk::ext_instruction (GLSLstd450SClamp, "GLSL.std.450" )]]
114
- enable_if_t<is_integral_v<Integer> && is_signed_v<Integer>, Integer> sClamp (Integer val, Integer min , Integer max );
126
+ T sClamp (T val, T min , T max );
115
127
116
- template<typename FloatingPoint>
128
+ template<typename T NBL_FUNC_REQUIRES (concepts::FloatingPointVectorOrScalar<T>)
117
129
[[vk::ext_instruction (GLSLstd450FMin, "GLSL.std.450" )]]
118
- enable_if_t<is_floating_point_v<FloatingPoint>, FloatingPoint> fMin (FloatingPoint val);
119
- template<typename UnsignedInteger>
130
+ T fMin (T val);
131
+ template<typename T NBL_FUNC_REQUIRES (concepts::UnsignedIntegralVectorOrScalar<T>)
120
132
[[vk::ext_instruction (GLSLstd450UMin, "GLSL.std.450" )]]
121
- enable_if_t<is_integral_v<UnsignedInteger> && !is_signed_v<UnsignedInteger>, UnsignedInteger> uMin (UnsignedInteger val);
122
- template<typename Integer>
133
+ T uMin (T val);
134
+ template<typename T NBL_FUNC_REQUIRES (concepts::IntegralVectorOrScalar<T>)
123
135
[[vk::ext_instruction (GLSLstd450SMin, "GLSL.std.450" )]]
124
- enable_if_t<is_integral_v<Integer>&& is_signed_v<Integer>, Integer> sMin (Integer val);
136
+ T sMin (T val);
125
137
126
- template<typename FloatingPoint>
138
+ template<typename T NBL_FUNC_REQUIRES (concepts::FloatingPointVectorOrScalar<T>)
127
139
[[vk::ext_instruction (GLSLstd450FMax, "GLSL.std.450" )]]
128
- enable_if_t<is_floating_point_v<FloatingPoint>, FloatingPoint> fMax (FloatingPoint val);
129
- template<typename UnsignedInteger>
140
+ T fMax (T val);
141
+ template<typename T NBL_FUNC_REQUIRES (concepts::UnsignedIntegralVectorOrScalar<T>)
130
142
[[vk::ext_instruction (GLSLstd450UMax, "GLSL.std.450" )]]
131
- enable_if_t<is_integral_v<UnsignedInteger> && !is_signed_v<UnsignedInteger>, UnsignedInteger> uMax (UnsignedInteger val);
132
- template<typename Integer>
143
+ T uMax (T val);
144
+ template<typename T NBL_FUNC_REQUIRES (concepts::IntegralVectorOrScalar<T>)
133
145
[[vk::ext_instruction (GLSLstd450SMax, "GLSL.std.450" )]]
134
- enable_if_t<is_integral_v<Integer>&& is_signed_v<Integer>, Integer> sMax (Integer val);
146
+ T sMax (T val);
135
147
136
- template<typename FloatingPoint>
148
+ template<typename T NBL_FUNC_REQUIRES (concepts::FloatingPointVectorOrScalar<T>)
137
149
[[vk::ext_instruction (GLSLstd450FAbs, "GLSL.std.450" )]]
138
- enable_if_t<is_floating_point_v<FloatingPoint>, FloatingPoint> fAbs (FloatingPoint val);
139
- template<typename Integer>
150
+ T fAbs (T val);
151
+ template<typename T NBL_FUNC_REQUIRES (concepts::IntegralVectorOrScalar<T>)
140
152
[[vk::ext_instruction (GLSLstd450SAbs, "GLSL.std.450" )]]
141
- enable_if_t<is_integral_v<Integer> && is_signed_v<Integer>, Integer> sAbs (Integer val);
153
+ T sAbs (T val);
142
154
143
- template<typename FloatingPoint>
155
+ template<typename T NBL_FUNC_REQUIRES (concepts::FloatingPointVectorOrScalar32or16BitSize<T>)
144
156
[[vk::ext_instruction (GLSLstd450Sin, "GLSL.std.450" )]]
145
- enable_if_t<is_floating_point_v<FloatingPoint>, FloatingPoint> sin (FloatingPoint val);
157
+ T sin (T val);
146
158
147
- template<typename FloatingPoint>
159
+ template<typename T NBL_FUNC_REQUIRES (concepts::FloatingPointVectorOrScalar32or16BitSize<T>)
148
160
[[vk::ext_instruction (GLSLstd450Cos, "GLSL.std.450" )]]
149
- enable_if_t<is_floating_point_v<FloatingPoint>, FloatingPoint> cos (FloatingPoint val);
161
+ T cos (T val);
150
162
151
- template<typename FloatingPoint>
163
+ template<typename T NBL_FUNC_REQUIRES (concepts::FloatingPointVectorOrScalar32or16BitSize<T>)
152
164
[[vk::ext_instruction (GLSLstd450Acos, "GLSL.std.450" )]]
153
- enable_if_t<is_floating_point_v<FloatingPoint>, FloatingPoint> acos (FloatingPoint val);
165
+ T acos (T val);
154
166
155
167
}
156
168
}
0 commit comments