22#define _NBL_BUILTIN_HLSL_SPIRV_INTRINSICS_GLSL_STD_450_INCLUDED_
33
44#ifdef __HLSL_VERSION
5+ #include <nbl/builtin/hlsl/vector_utils/vector_traits.hlsl>
6+ #include <nbl/builtin/hlsl/matrix_utils/matrix_traits.hlsl>
57#include <nbl/builtin/hlsl/cpp_compat/basic.h>
68#include <nbl/builtin/hlsl/concepts.hlsl>
79#include "spirv/unified1/GLSL.std.450.h"
@@ -12,70 +14,81 @@ namespace hlsl
1214{
1315namespace spirv
1416{
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);
1917
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+ }
2343
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>)
2546[[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);
3148
32- template<int N>
49+ template<typename T NBL_FUNC_REQUIRES (concepts::IntegralVectorOrScalar32BitSize<T>)
3350[[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);
3952
40- template<int N>
53+ template<typename T NBL_FUNC_REQUIRES (concepts::UnsignedIntegralVectorOrScalar32BitSize<T>)
4154[[vk::ext_instruction (GLSLstd450::GLSLstd450FindUMsb, "GLSL.std.450" )]]
42- vector <uint32_t, N> findUMsb (vector <uint32_t, N> value);
55+ T findUMsb (T value);
4356
44- template<typename FloatingPoint>
57+ template<typename T NBL_FUNC_REQUIRES (concepts::FloatingPointVectorOrScalar32or16BitSize<T>)
4558[[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);
4760
48- template<typename FloatingPoint>
61+ template<typename T NBL_FUNC_REQUIRES (concepts::FloatingPointVectorOrScalar32or16BitSize<T>)
4962[[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);
5164
52- template<typename FloatingPoint>
65+ template<typename T NBL_FUNC_REQUIRES (concepts::FloatingPointVectorOrScalar32or16BitSize<T>)
5366[[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);
5568
56- template<typename FloatingPoint>
69+ template<typename T NBL_FUNC_REQUIRES (concepts::FloatingPointVectorOrScalar32or16BitSize<T>)
5770[[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);
5972
60- template<typename FloatingPoint>
73+ template<typename T NBL_FUNC_REQUIRES (concepts::FloatingPointVectorOrScalar<T>)
6174[[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);
6376
64- template<typename FloatingPoint>
77+ template<typename T NBL_FUNC_REQUIRES (concepts::FloatingPointVectorOrScalar<T>)
6578[[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);
6780
68- template<typename FloatingPoint>
81+ template<typename T NBL_FUNC_REQUIRES (concepts::FloatingPointVectorOrScalar<T>)
6982[[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);
7184
72- template<typename FloatingPoint>
85+ template<typename T NBL_FUNC_REQUIRES (concepts::FloatingPointVectorOrScalar<T> && is_scalar_v<T>)
7386[[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);
7588
76- template<typename FloatingPoint>
89+ template<typename T NBL_FUNC_REQUIRES (concepts::FloatingPointVectorOrScalar<T>)
7790[[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);
7992
8093template<typename T, int N>
8194[[vk::ext_instruction (GLSLstd450::GLSLstd450Determinant, "GLSL.std.450" )]]
@@ -94,63 +107,62 @@ float32_t4 unpackSnorm4x8(uint32_t p);
94107[[vk::ext_instruction (GLSLstd450UnpackUnorm4x8, "GLSL.std.450" )]]
95108float32_t4 unpackUnorm4x8 (uint32_t p);
96109
97- template<typename FloatingPointVector>
110+ template<typename T NBL_FUNC_REQUIRES (concepts::FloatingPointVectorOrScalar<T>)
98111[[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);
100113
101- template<typename FloatingPointVector>
114+ template<typename T NBL_FUNC_REQUIRES (concepts::FloatingPointVectorOrScalar<T>)
102115[[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);
104117
105- // TODO: will not work for vectors, fix
106- template<typename FloatingPoint>
118+ template<typename T NBL_FUNC_REQUIRES (concepts::FloatingPointVectorOrScalar<T>)
107119[[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>)
110122[[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>)
113125[[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 );
115127
116- template<typename FloatingPoint>
128+ template<typename T NBL_FUNC_REQUIRES (concepts::FloatingPointVectorOrScalar<T>)
117129[[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>)
120132[[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>)
123135[[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);
125137
126- template<typename FloatingPoint>
138+ template<typename T NBL_FUNC_REQUIRES (concepts::FloatingPointVectorOrScalar<T>)
127139[[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>)
130142[[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>)
133145[[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);
135147
136- template<typename FloatingPoint>
148+ template<typename T NBL_FUNC_REQUIRES (concepts::FloatingPointVectorOrScalar<T>)
137149[[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>)
140152[[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);
142154
143- template<typename FloatingPoint>
155+ template<typename T NBL_FUNC_REQUIRES (concepts::FloatingPointVectorOrScalar32or16BitSize<T>)
144156[[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);
146158
147- template<typename FloatingPoint>
159+ template<typename T NBL_FUNC_REQUIRES (concepts::FloatingPointVectorOrScalar32or16BitSize<T>)
148160[[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);
150162
151- template<typename FloatingPoint>
163+ template<typename T NBL_FUNC_REQUIRES (concepts::FloatingPointVectorOrScalar32or16BitSize<T>)
152164[[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);
154166
155167}
156168}
0 commit comments