Skip to content

New morton class with arithmetic and comparison operators #860

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 32 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
cdcc9ad
Initial commit
Fletterio Mar 21, 2025
8e84558
Merge branch 'concepts_fix' into mortons
Fletterio Mar 21, 2025
d33fab5
Merge branch 'concepts_fix' into mortons
Fletterio Mar 21, 2025
5fe6c08
CHeckpoint before master merge
Fletterio Mar 23, 2025
f18b2fa
Checkpoint before merging new type_traits change
Fletterio Mar 24, 2025
7d86cba
Merge branch 'master' into mortons
Fletterio Mar 24, 2025
4ebc555
Works, but throws DXC warning
Fletterio Mar 24, 2025
55a2ef6
Added concept for valid morton dimensions
Fletterio Mar 24, 2025
f516256
Creation from vector working as intended
Fletterio Mar 25, 2025
534d81b
Added some extra macro specifiers, vector truncation with no warnings…
Fletterio Mar 26, 2025
6256390
Add safe copile-time vector truncation and some function specifiers f…
Fletterio Mar 26, 2025
246cefc
Morton class done!
Fletterio Mar 27, 2025
1c7f791
Remove some leftover commented code
Fletterio Mar 27, 2025
5088799
Remove leaking macro
Fletterio Mar 27, 2025
e25a35c
Bugfixes with arithmetic
Fletterio Mar 28, 2025
0d9dd4a
Checkpoint, have to check why vector compat isn't working
Fletterio Apr 1, 2025
89d2bf2
Refactor morton class, get new conversion running
Fletterio Apr 2, 2025
de4d0fb
Add new classes for encoding/decoding of mortn codes
Fletterio Apr 3, 2025
799420e
Fix conversion operators
Fletterio Apr 4, 2025
52323bc
Finish the rest of comparison ops and we're done!
Fletterio Apr 5, 2025
b6b7003
Final Mortons
Fletterio Apr 7, 2025
60ff99a
Clean up the emulated int code, fix some constant creation in the mor…
Fletterio Apr 8, 2025
5560162
Addressing latest PR review. Generic overloads for of different func…
Fletterio Apr 8, 2025
e50c56b
Bunch of emulated int64 fixes regarding creation, comparison operator…
Fletterio Apr 9, 2025
b1de9c3
Fix automatic specialize macro in cpp compat intrinsics, add intrins…
Fletterio Apr 9, 2025
ea8cd43
Checkpoint: adding a bunch of operators to emulated vector types
Fletterio Apr 11, 2025
53a5f6a
Vectorized encode/decode for better pipelining
Fletterio Apr 11, 2025
cf52d9c
Adress the last of PR review changes: vectorize more operators, add a…
Fletterio Apr 14, 2025
f954522
Removed `NBL_CONSTEXPR_INLINE_FUNC` macro, replaced all usages with
Fletterio Apr 24, 2025
2d0ffba
Fix the last of the operators
Fletterio Apr 28, 2025
68edc32
Change examples test submodule for master merge
Fletterio Apr 28, 2025
5013c89
Merged master
Fletterio Apr 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/nbl/builtin/hlsl/cpp_compat.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@
#include <nbl/builtin/hlsl/cpp_compat/intrinsics.hlsl>
#include <nbl/builtin/hlsl/cpp_compat/promote.hlsl>

// Had to push some stuff here to avoid circular dependencies
#include <nbl/builtin/hlsl/cpp_compat/impl/vector_impl.hlsl>

#endif
66 changes: 36 additions & 30 deletions include/nbl/builtin/hlsl/cpp_compat/basic.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,7 @@
#define _NBL_BUILTIN_HLSL_CPP_COMPAT_BASIC_INCLUDED_

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

namespace nbl
{
namespace hlsl
{
namespace impl
{
template<typename To, typename From, typename Enabled = void>
struct static_cast_helper
{
static inline To cast(From u)
{
#ifndef __HLSL_VERSION
return static_cast<To>(u);
#else
return To(u);
#endif
}
};
}

template<typename To, typename From>
inline To _static_cast(From v)
{
return impl::static_cast_helper<To, From>::cast(v);
}

}
}
#include <nbl/builtin/hlsl/concepts/impl/base.hlsl>

#ifndef __HLSL_VERSION
#include <type_traits>
Expand All @@ -40,7 +12,9 @@ inline To _static_cast(From v)
#define NBL_CONSTEXPR_FUNC constexpr
#define NBL_CONSTEXPR_STATIC constexpr static
#define NBL_CONSTEXPR_STATIC_INLINE constexpr static inline
#define NBL_CONSTEXPR_STATIC_FUNC constexpr static
#define NBL_CONSTEXPR_INLINE_FUNC constexpr inline
#define NBL_CONSTEXPR_STATIC_INLINE_FUNC constexpr static inline
#define NBL_CONSTEXPR_FORCED_INLINE_FUNC NBL_FORCE_INLINE constexpr
#define NBL_CONST_MEMBER_FUNC const

Expand All @@ -65,14 +39,17 @@ namespace nbl::hlsl

#else


#define ARROW .arrow().
#define NBL_CONSTEXPR const static // TODO: rename to NBL_CONSTEXPR_VAR
#define NBL_CONSTEXPR_FUNC
#define NBL_CONSTEXPR_STATIC const static
#define NBL_CONSTEXPR_STATIC_INLINE const static
#define NBL_CONSTEXPR_STATIC_FUNC static
#define NBL_CONSTEXPR_INLINE_FUNC inline
#define NBL_CONSTEXPR_STATIC_INLINE_FUNC static inline
#define NBL_CONSTEXPR_FORCED_INLINE_FUNC inline
#define NBL_CONST_MEMBER_FUNC
#define NBL_CONST_MEMBER_FUNC

namespace nbl
{
Expand Down Expand Up @@ -100,4 +77,33 @@ struct add_pointer

#endif

namespace nbl
{
namespace hlsl
{
namespace impl
{
template<typename To, typename From, typename Enabled = void NBL_STRUCT_CONSTRAINABLE >
struct static_cast_helper
{
NBL_CONSTEXPR_STATIC_INLINE_FUNC To cast(From u)
{
#ifndef __HLSL_VERSION
return static_cast<To>(u);
#else
return To(u);
#endif
}
};
}

template<typename To, typename From>
NBL_CONSTEXPR_INLINE_FUNC To _static_cast(From v)
{
return impl::static_cast_helper<To, From>::cast(v);
}

}
}

#endif
35 changes: 35 additions & 0 deletions include/nbl/builtin/hlsl/cpp_compat/impl/vector_impl.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#ifndef _NBL_BUILTIN_HLSL_CPP_COMPAT_IMPL_VECTOR_IMPL_INCLUDED_
#define _NBL_BUILTIN_HLSL_CPP_COMPAT_IMPL_VECTOR_IMPL_INCLUDED_

#include <nbl/builtin/hlsl/cpp_compat/basic.h>
#include <nbl/builtin/hlsl/cpp_compat/vector.hlsl>
#include <nbl/builtin/hlsl/concepts.hlsl>

// To prevent implicit truncation warnings
namespace nbl
{
namespace hlsl
{
namespace impl
{

template<typename T, uint16_t N, uint16_t M> NBL_PARTIAL_REQ_TOP(N <= M)
struct static_cast_helper<vector<T, N>, vector<T, M> NBL_PARTIAL_REQ_BOT(N <= M) >
{
NBL_CONSTEXPR_STATIC_INLINE_FUNC vector<T, N> cast(NBL_CONST_REF_ARG(vector<T, M>) val)
{
vector<T, N> retVal;
[[unroll]]
for (uint16_t i = 0; i < N; i++)
{
retVal[i] = val[i];
}
return retVal;
}
};

}
}
}

#endif
Loading