Skip to content

Commit 01dcf66

Browse files
author
devsh
committed
Merge branch 'master' into ngfx-sdk-integration
2 parents 64ad91a + 099693e commit 01dcf66

File tree

28 files changed

+2256
-99
lines changed

28 files changed

+2256
-99
lines changed

examples_tests

Submodule examples_tests updated 39 files

include/nbl/asset/utils/CCompilerSet.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ namespace nbl::asset
3333

3434
#ifdef _NBL_PLATFORM_WINDOWS_
3535
return m_HLSLCompiler;
36+
#else
37+
return nullptr;
3638
#endif
3739
}
3840
else if (contentType == IShader::E_CONTENT_TYPE::ECT_GLSL)

include/nbl/builtin/hlsl/algorithm.hlsl

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,84 @@ namespace nbl
1111
namespace hlsl
1212
{
1313

14+
namespace impl
15+
{
16+
#ifdef __HLSL_VERSION
17+
18+
// TODO: use structs
19+
20+
template<typename T>
21+
NBL_CONSTEXPR_INLINE_FUNC void swap(NBL_REF_ARG(T) lhs, NBL_REF_ARG(T) rhs)
22+
{
23+
T tmp = lhs;
24+
lhs = rhs;
25+
rhs = tmp;
26+
}
27+
28+
template<>
29+
NBL_CONSTEXPR_INLINE_FUNC void swap(NBL_REF_ARG(uint16_t) lhs, NBL_REF_ARG(uint16_t) rhs)
30+
{
31+
lhs ^= rhs;
32+
rhs ^= lhs;
33+
lhs ^= rhs;
34+
}
35+
36+
template<>
37+
NBL_CONSTEXPR_INLINE_FUNC void swap(NBL_REF_ARG(uint32_t) lhs, NBL_REF_ARG(uint32_t) rhs)
38+
{
39+
lhs ^= rhs;
40+
rhs ^= lhs;
41+
lhs ^= rhs;
42+
}
43+
44+
template<>
45+
NBL_CONSTEXPR_INLINE_FUNC void swap(NBL_REF_ARG(uint64_t) lhs, NBL_REF_ARG(uint64_t) rhs)
46+
{
47+
lhs ^= rhs;
48+
rhs ^= lhs;
49+
lhs ^= rhs;
50+
}
51+
52+
template<>
53+
NBL_CONSTEXPR_INLINE_FUNC void swap(NBL_REF_ARG(int16_t) lhs, NBL_REF_ARG(int16_t) rhs)
54+
{
55+
lhs ^= rhs;
56+
rhs ^= lhs;
57+
lhs ^= rhs;
58+
}
59+
60+
template<>
61+
NBL_CONSTEXPR_INLINE_FUNC void swap(NBL_REF_ARG(int32_t) lhs, NBL_REF_ARG(int32_t) rhs)
62+
{
63+
lhs ^= rhs;
64+
rhs ^= lhs;
65+
lhs ^= rhs;
66+
}
67+
68+
template<>
69+
NBL_CONSTEXPR_INLINE_FUNC void swap(NBL_REF_ARG(int64_t) lhs, NBL_REF_ARG(int64_t) rhs)
70+
{
71+
lhs ^= rhs;
72+
rhs ^= lhs;
73+
lhs ^= rhs;
74+
}
75+
#else
76+
template<typename T>
77+
NBL_CONSTEXPR_INLINE_FUNC void swap(NBL_REF_ARG(T) lhs, NBL_REF_ARG(T) rhs)
78+
{
79+
std::swap(lhs, rhs);
80+
}
81+
#endif
82+
}
83+
84+
template<typename T>
85+
NBL_CONSTEXPR_INLINE_FUNC void swap(NBL_REF_ARG(T) lhs, NBL_REF_ARG(T) rhs)
86+
{
87+
impl::swap<T>(lhs, rhs);
88+
}
89+
90+
91+
#ifdef __HLSL_VERSION
1492

1593
namespace impl
1694
{
@@ -146,6 +224,7 @@ uint upper_bound(inout Accessor accessor, const uint begin, const uint end, cons
146224
return impl::upper_bound<Accessor,typename Accessor::value_type>(accessor,begin,end,value);
147225
}
148226

227+
#endif
149228
}
150229
}
151230

include/nbl/builtin/hlsl/cpp_compat/impl/intrinsics_impl.hlsl

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
#define _NBL_BUILTIN_HLSL_CPP_COMPAT_IMPL_INTRINSICS_IMPL_INCLUDED_
33

44
#include <nbl/builtin/hlsl/cpp_compat/basic.h>
5+
#include <nbl/builtin/hlsl/matrix_utils/matrix_traits.hlsl>
56
#include <nbl/builtin/hlsl/concepts.hlsl>
7+
#include <nbl/builtin/hlsl/spirv_intrinsics/core.hlsl>
8+
#include <nbl/builtin/hlsl/spirv_intrinsics/glsl.std.450.hlsl>
69

710
namespace nbl
811
{
@@ -20,7 +23,7 @@ struct dot_helper
2023
static array_get<T, scalar_type> getter;
2124
scalar_type retval = getter(lhs, 0) * getter(rhs, 0);
2225

23-
static const uint32_t ArrayDim = sizeof(T) / sizeof(scalar_type);
26+
static const uint32_t ArrayDim = vector_traits<T>::Dimension;
2427
for (uint32_t i = 1; i < ArrayDim; ++i)
2528
retval = retval + getter(lhs, i) * getter(rhs, i);
2629

@@ -293,6 +296,42 @@ struct find_msb_return_type<vector<Integer, N> >
293296
template<typename Integer>
294297
using find_lsb_return_type = find_msb_return_type<Integer>;
295298

299+
template<typename T NBL_STRUCT_CONSTRAINABLE>
300+
struct bitReverse_helper;
301+
302+
template<typename Integer>
303+
NBL_PARTIAL_REQ_TOP(hlsl::is_integral_v<Integer> && hlsl::is_scalar_v<Integer>)
304+
struct bitReverse_helper<Integer NBL_PARTIAL_REQ_BOT(hlsl::is_integral_v<Integer>&& hlsl::is_scalar_v<Integer>) >
305+
{
306+
static inline Integer __call(NBL_CONST_REF_ARG(Integer) val)
307+
{
308+
#ifdef __HLSL_VERSION
309+
return spirv::bitReverse(val);
310+
#else
311+
return glm::bitfieldReverse(val);
312+
#endif
313+
}
314+
};
315+
316+
template<typename Vector>
317+
NBL_PARTIAL_REQ_TOP(hlsl::is_vector_v<Vector>)
318+
struct bitReverse_helper<Vector NBL_PARTIAL_REQ_BOT(hlsl::is_integral_v<Vector> && hlsl::is_vector_v<Vector>) >
319+
{
320+
static Vector __call(NBL_CONST_REF_ARG(Vector) vec)
321+
{
322+
#ifdef __HLSL_VERSION
323+
return spirv::bitReverse(vec);
324+
#else
325+
Vector output;
326+
using traits = hlsl::vector_traits<Vector>;
327+
for (uint32_t i = 0; i < traits::Dimension; ++i)
328+
output[i] = bitReverse_helper<scalar_type_t<Vector> >::__call(vec[i]);
329+
return output;
330+
#endif
331+
}
332+
};
333+
334+
296335
template<typename T, typename U NBL_STRUCT_CONSTRAINABLE>
297336
struct lerp_helper;
298337

@@ -362,6 +401,33 @@ struct lerp_helper<vector<T, N>, vector<bool, N> >
362401
}
363402
};
364403

404+
template<typename Matrix>
405+
struct transpose_helper;
406+
407+
template<typename T, int N, int M>
408+
struct transpose_helper<matrix<T, N, M> >
409+
{
410+
using transposed_t = typename matrix_traits<matrix<T, N, M> >::transposed_type;
411+
412+
static transposed_t transpose(NBL_CONST_REF_ARG(matrix<T, N, M>) m)
413+
{
414+
#ifdef __HLSL_VERSION
415+
return spirv::transpose(m);
416+
#else
417+
return reinterpret_cast<transposed_t&>(glm::transpose(reinterpret_cast<typename matrix<T, N, M>::Base const&>(m)));
418+
#endif
419+
}
420+
};
421+
422+
template<typename LhsT, typename RhsT>
423+
struct mul_helper
424+
{
425+
static inline RhsT multiply(LhsT lhs, RhsT rhs)
426+
{
427+
return mul(lhs, rhs);
428+
}
429+
};
430+
365431
}
366432
}
367433
}

include/nbl/builtin/hlsl/cpp_compat/intrinsics.hlsl

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
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

134137
template<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>)
165178
inline 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+
174197
template<typename T>
175198
inline T exp2(NBL_CONST_REF_ARG(T) val)
176199
{
@@ -206,6 +229,13 @@ inline FloatingPoint rsqrt(FloatingPoint x)
206229
#endif
207230
}
208231

232+
template<typename Integer>
233+
inline Integer bitReverse(Integer val)
234+
{
235+
return cpp_compat_intrinsics_impl::bitReverse_helper<Integer>::__call(val);
236+
}
237+
238+
209239
}
210240
}
211241

0 commit comments

Comments
 (0)