Skip to content

Commit 3c1a4a3

Browse files
Merge pull request #860 from Devsh-Graphics-Programming/mortons
New morton class with arithmetic and comparison operators
2 parents e44a8fb + b803f83 commit 3c1a4a3

31 files changed

+2321
-444
lines changed

include/nbl/builtin/hlsl/algorithm.hlsl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,71 +19,71 @@ namespace impl
1919
// TODO: use structs
2020

2121
template<typename T>
22-
NBL_CONSTEXPR_INLINE_FUNC void swap(NBL_REF_ARG(T) lhs, NBL_REF_ARG(T) rhs)
22+
NBL_CONSTEXPR_FUNC void swap(NBL_REF_ARG(T) lhs, NBL_REF_ARG(T) rhs)
2323
{
2424
T tmp = lhs;
2525
lhs = rhs;
2626
rhs = tmp;
2727
}
2828

2929
template<>
30-
NBL_CONSTEXPR_INLINE_FUNC void swap(NBL_REF_ARG(uint16_t) lhs, NBL_REF_ARG(uint16_t) rhs)
30+
NBL_CONSTEXPR_FUNC void swap(NBL_REF_ARG(uint16_t) lhs, NBL_REF_ARG(uint16_t) rhs)
3131
{
3232
lhs ^= rhs;
3333
rhs ^= lhs;
3434
lhs ^= rhs;
3535
}
3636

3737
template<>
38-
NBL_CONSTEXPR_INLINE_FUNC void swap(NBL_REF_ARG(uint32_t) lhs, NBL_REF_ARG(uint32_t) rhs)
38+
NBL_CONSTEXPR_FUNC void swap(NBL_REF_ARG(uint32_t) lhs, NBL_REF_ARG(uint32_t) rhs)
3939
{
4040
lhs ^= rhs;
4141
rhs ^= lhs;
4242
lhs ^= rhs;
4343
}
4444

4545
template<>
46-
NBL_CONSTEXPR_INLINE_FUNC void swap(NBL_REF_ARG(uint64_t) lhs, NBL_REF_ARG(uint64_t) rhs)
46+
NBL_CONSTEXPR_FUNC void swap(NBL_REF_ARG(uint64_t) lhs, NBL_REF_ARG(uint64_t) rhs)
4747
{
4848
lhs ^= rhs;
4949
rhs ^= lhs;
5050
lhs ^= rhs;
5151
}
5252

5353
template<>
54-
NBL_CONSTEXPR_INLINE_FUNC void swap(NBL_REF_ARG(int16_t) lhs, NBL_REF_ARG(int16_t) rhs)
54+
NBL_CONSTEXPR_FUNC void swap(NBL_REF_ARG(int16_t) lhs, NBL_REF_ARG(int16_t) rhs)
5555
{
5656
lhs ^= rhs;
5757
rhs ^= lhs;
5858
lhs ^= rhs;
5959
}
6060

6161
template<>
62-
NBL_CONSTEXPR_INLINE_FUNC void swap(NBL_REF_ARG(int32_t) lhs, NBL_REF_ARG(int32_t) rhs)
62+
NBL_CONSTEXPR_FUNC void swap(NBL_REF_ARG(int32_t) lhs, NBL_REF_ARG(int32_t) rhs)
6363
{
6464
lhs ^= rhs;
6565
rhs ^= lhs;
6666
lhs ^= rhs;
6767
}
6868

6969
template<>
70-
NBL_CONSTEXPR_INLINE_FUNC void swap(NBL_REF_ARG(int64_t) lhs, NBL_REF_ARG(int64_t) rhs)
70+
NBL_CONSTEXPR_FUNC void swap(NBL_REF_ARG(int64_t) lhs, NBL_REF_ARG(int64_t) rhs)
7171
{
7272
lhs ^= rhs;
7373
rhs ^= lhs;
7474
lhs ^= rhs;
7575
}
7676
#else
7777
template<typename T>
78-
NBL_CONSTEXPR_INLINE_FUNC void swap(NBL_REF_ARG(T) lhs, NBL_REF_ARG(T) rhs)
78+
NBL_CONSTEXPR_FUNC void swap(NBL_REF_ARG(T) lhs, NBL_REF_ARG(T) rhs)
7979
{
8080
std::swap(lhs, rhs);
8181
}
8282
#endif
8383
}
8484

8585
template<typename T>
86-
NBL_CONSTEXPR_INLINE_FUNC void swap(NBL_REF_ARG(T) lhs, NBL_REF_ARG(T) rhs)
86+
NBL_CONSTEXPR_FUNC void swap(NBL_REF_ARG(T) lhs, NBL_REF_ARG(T) rhs)
8787
{
8888
impl::swap<T>(lhs, rhs);
8989
}

include/nbl/builtin/hlsl/blit/default_blit.comp.hlsl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ using namespace nbl::hlsl::blit;
5959
// TODO: push constants
6060

6161
[numthreads(ConstevalParameters::WorkGroupSize,1,1)]
62+
[shader("compute")]
6263
void main()
6364
{
6465
InImgAccessor inImgA;

include/nbl/builtin/hlsl/bxdf/ndf/ggx.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ template<class T>
406406
struct is_ggx : impl::is_ggx<T, typename T::scalar_type> {};
407407

408408
template<typename T>
409-
NBL_CONSTEXPR bool is_ggx_v = is_ggx<T>::value;
409+
NBL_CONSTEXPR_INLINE_NSPC_SCOPE_VAR bool is_ggx_v = is_ggx<T>::value;
410410

411411
}
412412
}

include/nbl/builtin/hlsl/complex.hlsl

Lines changed: 18 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -238,28 +238,28 @@ struct divides< complex_t<Scalar> >
238238
// Out of line generic initialization of static member data not yet supported so we X-Macro identities for Scalar types we want to support
239239
// (left X-Macro here since it's pretty readable)
240240

241-
#define COMPLEX_ARITHMETIC_IDENTITIES(SCALAR) \
241+
#define COMPLEX_ARITHMETIC_IDENTITIES(SCALAR, COMPONENT) \
242242
template<> \
243-
const static complex_t< SCALAR > plus< complex_t< SCALAR > >::identity = { promote< SCALAR , uint32_t>(0), promote< SCALAR , uint32_t>(0)}; \
243+
const static complex_t< SCALAR > plus< complex_t< SCALAR > >::identity = { promote< SCALAR, COMPONENT>(0), promote< SCALAR, COMPONENT>(0)}; \
244244
template<> \
245-
const static complex_t< SCALAR > minus< complex_t< SCALAR > >::identity = { promote< SCALAR , uint32_t>(0), promote< SCALAR , uint32_t>(0)}; \
245+
const static complex_t< SCALAR > minus< complex_t< SCALAR > >::identity = { promote< SCALAR, COMPONENT>(0), promote< SCALAR, COMPONENT>(0)}; \
246246
template<> \
247-
const static complex_t< SCALAR > multiplies< complex_t< SCALAR > >::identity = { promote< SCALAR , uint32_t>(1), promote< SCALAR , uint32_t>(0)}; \
247+
const static complex_t< SCALAR > multiplies< complex_t< SCALAR > >::identity = { promote< SCALAR, COMPONENT>(1), promote< SCALAR, COMPONENT>(0)}; \
248248
template<> \
249-
const static complex_t< SCALAR > divides< complex_t< SCALAR > >::identity = { promote< SCALAR , uint32_t>(1), promote< SCALAR , uint32_t>(0)};
250-
251-
COMPLEX_ARITHMETIC_IDENTITIES(float16_t)
252-
COMPLEX_ARITHMETIC_IDENTITIES(float16_t2)
253-
COMPLEX_ARITHMETIC_IDENTITIES(float16_t3)
254-
COMPLEX_ARITHMETIC_IDENTITIES(float16_t4)
255-
COMPLEX_ARITHMETIC_IDENTITIES(float32_t)
256-
COMPLEX_ARITHMETIC_IDENTITIES(float32_t2)
257-
COMPLEX_ARITHMETIC_IDENTITIES(float32_t3)
258-
COMPLEX_ARITHMETIC_IDENTITIES(float32_t4)
259-
COMPLEX_ARITHMETIC_IDENTITIES(float64_t)
260-
COMPLEX_ARITHMETIC_IDENTITIES(float64_t2)
261-
COMPLEX_ARITHMETIC_IDENTITIES(float64_t3)
262-
COMPLEX_ARITHMETIC_IDENTITIES(float64_t4)
249+
const static complex_t< SCALAR > divides< complex_t< SCALAR > >::identity = { promote< SCALAR, COMPONENT>(1), promote< SCALAR, COMPONENT>(0)};
250+
251+
COMPLEX_ARITHMETIC_IDENTITIES(float16_t, float16_t)
252+
COMPLEX_ARITHMETIC_IDENTITIES(float16_t2, float16_t)
253+
COMPLEX_ARITHMETIC_IDENTITIES(float16_t3, float16_t)
254+
COMPLEX_ARITHMETIC_IDENTITIES(float16_t4, float16_t)
255+
COMPLEX_ARITHMETIC_IDENTITIES(float32_t, float32_t)
256+
COMPLEX_ARITHMETIC_IDENTITIES(float32_t2, float32_t)
257+
COMPLEX_ARITHMETIC_IDENTITIES(float32_t3, float32_t)
258+
COMPLEX_ARITHMETIC_IDENTITIES(float32_t4, float32_t)
259+
COMPLEX_ARITHMETIC_IDENTITIES(float64_t, float64_t)
260+
COMPLEX_ARITHMETIC_IDENTITIES(float64_t2, float64_t)
261+
COMPLEX_ARITHMETIC_IDENTITIES(float64_t3, float64_t)
262+
COMPLEX_ARITHMETIC_IDENTITIES(float64_t4, float64_t)
263263

264264
#undef COMPLEX_ARITHMETIC_IDENTITIES
265265

@@ -436,22 +436,6 @@ complex_t<Scalar> rotateRight(NBL_CONST_REF_ARG(complex_t<Scalar>) value)
436436
return retVal;
437437
}
438438

439-
template<typename Scalar>
440-
struct ternary_operator< complex_t<Scalar> >
441-
{
442-
using type_t = complex_t<Scalar>;
443-
444-
complex_t<Scalar> operator()(bool condition, NBL_CONST_REF_ARG(complex_t<Scalar>) lhs, NBL_CONST_REF_ARG(complex_t<Scalar>) rhs)
445-
{
446-
const vector<Scalar, 2> lhsVector = vector<Scalar, 2>(lhs.real(), lhs.imag());
447-
const vector<Scalar, 2> rhsVector = vector<Scalar, 2>(rhs.real(), rhs.imag());
448-
const vector<Scalar, 2> resultVector = condition ? lhsVector : rhsVector;
449-
const complex_t<Scalar> result = { resultVector.x, resultVector.y };
450-
return result;
451-
}
452-
};
453-
454-
455439
}
456440
}
457441

include/nbl/builtin/hlsl/concepts/core.hlsl

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,23 @@ namespace impl
7272
template<typename T>
7373
struct is_emulating_floating_point_scalar
7474
{
75-
NBL_CONSTEXPR_STATIC_INLINE bool value = FloatingPointScalar<T>;
75+
NBL_CONSTEXPR_STATIC_INLINE bool value = false;
76+
};
77+
78+
template<typename T>
79+
struct is_emulating_integral_scalar
80+
{
81+
NBL_CONSTEXPR_STATIC_INLINE bool value = false;
7682
};
7783
}
7884

7985
//! Floating point types are native floating point types or types that imitate native floating point types (for example emulated_float64_t)
8086
template<typename T>
81-
NBL_BOOL_CONCEPT FloatingPointLikeScalar = impl::is_emulating_floating_point_scalar<T>::value;
87+
NBL_BOOL_CONCEPT FloatingPointLikeScalar = FloatingPointScalar<T> || impl::is_emulating_floating_point_scalar<T>::value;
88+
89+
//! Integral-like types are native integral types or types that imitate native integral types (for example emulated_uint64_t)
90+
template<typename T>
91+
NBL_BOOL_CONCEPT IntegralLikeScalar = IntegralScalar<T> || impl::is_emulating_integral_scalar<T>::value;
8292

8393
}
8494
}

include/nbl/builtin/hlsl/concepts/vector.hlsl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,12 @@ NBL_BOOL_CONCEPT FloatingPointLikeVectorial = concepts::Vectorial<T> && concepts
4040
template<typename T>
4141
NBL_BOOL_CONCEPT IntVectorial = concepts::Vectorial<T> && (is_integral_v<typename vector_traits<T>::scalar_type>);
4242
template<typename T>
43+
NBL_BOOL_CONCEPT IntegralLikeVectorial = concepts::Vectorial<T> && concepts::IntegralLikeScalar<typename vector_traits<T>::scalar_type>;
44+
template<typename T>
4345
NBL_BOOL_CONCEPT SignedIntVectorial = concepts::Vectorial<T> && concepts::SignedIntegralScalar<typename vector_traits<T>::scalar_type>;
4446

4547
}
4648

47-
template<typename Vectorial>
48-
NBL_PARTIAL_REQ_TOP(concepts::Vectorial<Vectorial>)
49-
struct extent<Vectorial, 0 NBL_PARTIAL_REQ_BOT(concepts::Vectorial<Vectorial>) > : integral_constant<uint64_t, vector_traits<Vectorial>::Dimension> {};
50-
5149
}
5250
}
5351
#endif

include/nbl/builtin/hlsl/cpp_compat.hlsl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,9 @@
55
// it includes vector and matrix
66
#include <nbl/builtin/hlsl/cpp_compat/intrinsics.hlsl>
77
#include <nbl/builtin/hlsl/cpp_compat/promote.hlsl>
8+
#include <nbl/builtin/hlsl/cpp_compat/truncate.hlsl>
9+
10+
// Had to push some stuff here to avoid circular dependencies
11+
#include <nbl/builtin/hlsl/cpp_compat/vector.hlsl>
812

913
#endif

include/nbl/builtin/hlsl/cpp_compat/basic.h

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,46 +3,23 @@
33

44
#include <nbl/builtin/hlsl/macros.h>
55

6-
namespace nbl
7-
{
8-
namespace hlsl
9-
{
10-
namespace impl
11-
{
12-
template<typename To, typename From, typename Enabled = void>
13-
struct static_cast_helper
14-
{
15-
static inline To cast(From u)
16-
{
17-
#ifndef __HLSL_VERSION
18-
return static_cast<To>(u);
19-
#else
20-
return To(u);
21-
#endif
22-
}
23-
};
24-
}
25-
26-
template<typename To, typename From>
27-
inline To _static_cast(From v)
28-
{
29-
return impl::static_cast_helper<To, From>::cast(v);
30-
}
31-
32-
}
33-
}
346

357
#ifndef __HLSL_VERSION
368
#include <type_traits>
379

3810
#define ARROW ->
11+
#define NBL_DEREF_THIS (*this)
3912
#define NBL_CONSTEXPR constexpr // TODO: rename to NBL_CONSTEXPR_VAR
4013
#define NBL_CONSTEXPR_FUNC constexpr
4114
#define NBL_CONSTEXPR_STATIC constexpr static
4215
#define NBL_CONSTEXPR_STATIC_INLINE constexpr static inline
4316
#define NBL_CONSTEXPR_INLINE_FUNC constexpr inline
4417
#define NBL_CONSTEXPR_FORCED_INLINE_FUNC NBL_FORCE_INLINE constexpr
4518
#define NBL_CONST_MEMBER_FUNC const
19+
#define NBL_CONSTEXPR_INLINE_NSPC_SCOPE_VAR constexpr inline
20+
#define NBL_CONSTEXPR_FUNC_SCOPE_VAR constexpr
21+
#define NBL_CONSTEXPR_OOL_MEMBER constexpr
22+
#define NBL_CONSTEXPR_INLINE_OOL_MEMBER constexpr inline
4623
#define NBL_IF_CONSTEXPR(...) if constexpr (__VA_ARGS__)
4724

4825
namespace nbl::hlsl
@@ -67,13 +44,18 @@ namespace nbl::hlsl
6744
#else
6845

6946
#define ARROW .arrow().
47+
#define NBL_DEREF_THIS this
7048
#define NBL_CONSTEXPR const static // TODO: rename to NBL_CONSTEXPR_VAR
7149
#define NBL_CONSTEXPR_FUNC
7250
#define NBL_CONSTEXPR_STATIC const static
7351
#define NBL_CONSTEXPR_STATIC_INLINE const static
7452
#define NBL_CONSTEXPR_INLINE_FUNC inline
7553
#define NBL_CONSTEXPR_FORCED_INLINE_FUNC inline
7654
#define NBL_CONST_MEMBER_FUNC
55+
#define NBL_CONSTEXPR_INLINE_NSPC_SCOPE_VAR const static
56+
#define NBL_CONSTEXPR_FUNC_SCOPE_VAR const
57+
#define NBL_CONSTEXPR_OOL_MEMBER const
58+
#define NBL_CONSTEXPR_INLINE_OOL_MEMBER const
7759
#define NBL_IF_CONSTEXPR(...) if (__VA_ARGS__)
7860

7961
namespace nbl
@@ -102,4 +84,33 @@ struct add_pointer
10284

10385
#endif
10486

87+
namespace nbl
88+
{
89+
namespace hlsl
90+
{
91+
namespace impl
92+
{
93+
template<typename To, typename From, typename Enabled = void>
94+
struct static_cast_helper
95+
{
96+
NBL_CONSTEXPR_STATIC_INLINE To cast(From u)
97+
{
98+
#ifndef __HLSL_VERSION
99+
return static_cast<To>(u);
100+
#else
101+
return To(u);
102+
#endif
103+
}
104+
};
105+
}
106+
107+
template<typename To, typename From>
108+
NBL_CONSTEXPR_INLINE_FUNC To _static_cast(From v)
109+
{
110+
return impl::static_cast_helper<To, From>::cast(v);
111+
}
112+
113+
}
114+
}
115+
105116
#endif

0 commit comments

Comments
 (0)