55#include <nbl/builtin/hlsl/type_traits.hlsl>
66#include <nbl/builtin/hlsl/vector_utils/vector_traits.hlsl>
77#include <nbl/builtin/hlsl/array_accessors.hlsl>
8- #include <nbl/builtin/hlsl/spirv_intrinsics/core.hlsl>
9- #include <nbl/builtin/hlsl/spirv_intrinsics/glsl.std.450 .hlsl>
108#include <nbl/builtin/hlsl/cpp_compat/impl/intrinsics_impl.hlsl>
9+ #include <nbl/builtin/hlsl/matrix_utils/matrix_traits.hlsl>
10+ #include <nbl/builtin/hlsl/ieee754.hlsl>
1111
1212#ifndef __HLSL_VERSION
1313#include <algorithm>
@@ -121,14 +121,17 @@ inline T lerp(NBL_CONST_REF_ARG(T) x, NBL_CONST_REF_ARG(T) y, NBL_CONST_REF_ARG(
121121}
122122
123123// transpose not defined cause its implemented via hidden friend
124- template<typename T, uint16_t N, uint16_t M >
125- inline matrix <T, M, N> transpose (NBL_CONST_REF_ARG (matrix <T, N, M> ) m)
124+ template<typename Matrix >
125+ inline typename matrix_traits<Matrix>::transposed_type transpose (NBL_CONST_REF_ARG (Matrix ) m)
126126{
127- #ifdef __HLSL_VERSION
128- return spirv::transpose (m);
129- #else
130- return reinterpret_cast<matrix <T, M, N>&>(glm::transpose (reinterpret_cast<typename matrix <T, N, M>::Base const &>(m)));
131- #endif
127+ return cpp_compat_intrinsics_impl::transpose_helper<Matrix>::transpose (m);
128+ }
129+
130+ // TODO: concepts, to ensure that MatT is a matrix and VecT is a vector type
131+ template<typename MatT, typename VecT>
132+ VecT mul (MatT mat, VecT vec)
133+ {
134+ return cpp_compat_intrinsics_impl::mul_helper<MatT, VecT>::multiply (mat, vec);
132135}
133136
134137template<typename T>
@@ -151,8 +154,8 @@ inline T max(NBL_CONST_REF_ARG(T) a, NBL_CONST_REF_ARG(T) b)
151154#endif
152155}
153156
154- template<typename FloatingPoint>
155- inline FloatingPoint isnan (NBL_CONST_REF_ARG (FloatingPoint) val)
157+ template<typename FloatingPoint NBL_FUNC_REQUIRES (hlsl::is_floating_point_v<FloatingPoint>)
158+ inline bool isnan (NBL_CONST_REF_ARG (FloatingPoint) val)
156159{
157160#ifdef __HLSL_VERSION
158161 return spirv::isNan (val);
@@ -161,7 +164,17 @@ inline FloatingPoint isnan(NBL_CONST_REF_ARG(FloatingPoint) val)
161164#endif
162165}
163166
164- template<typename FloatingPoint>
167+ template <typename Integer NBL_FUNC_REQUIRES (hlsl::is_integral_v<Integer>)
168+ inline bool isnan (Integer val)
169+ {
170+ using AsUint = typename unsigned_integer_of_size<sizeof (Integer)>::type;
171+ using AsFloat = typename float_of_size<sizeof (Integer)>::type;
172+
173+ AsUint asUint = bit_cast<AsUint, Integer>(val);
174+ return bool ((ieee754::extractBiasedExponent<Integer>(val) == ieee754::traits<AsFloat>::specialValueExp) && (asUint & ieee754::traits<AsFloat>::mantissaMask));
175+ }
176+
177+ template<typename FloatingPoint NBL_FUNC_REQUIRES (hlsl::is_floating_point_v<FloatingPoint>)
165178inline FloatingPoint isinf (NBL_CONST_REF_ARG (FloatingPoint) val)
166179{
167180#ifdef __HLSL_VERSION
@@ -171,6 +184,16 @@ inline FloatingPoint isinf(NBL_CONST_REF_ARG(FloatingPoint) val)
171184#endif
172185}
173186
187+ template<typename Integer NBL_FUNC_REQUIRES (hlsl::is_integral_v<Integer>)
188+ inline bool isinf (Integer val)
189+ {
190+ using AsUint = typename unsigned_integer_of_size<sizeof (Integer)>::type;
191+ using AsFloat = typename float_of_size<sizeof (Integer)>::type;
192+
193+ AsUint tmp = bit_cast<AsUint>(val);
194+ return (tmp & (~ieee754::traits<AsFloat>::signMask)) == ieee754::traits<AsFloat>::inf;
195+ }
196+
174197template<typename T>
175198inline T exp2 (NBL_CONST_REF_ARG (T) val)
176199{
0 commit comments