Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
63 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
c53668c
Merge branch 'master' into mortons
Nov 19, 2025
977c7dd
Add constexpr to _static_cast
Nov 20, 2025
3294d04
Change NBL_CONSTEXPR_STATIC_FUNC to NBL_CONSTEXPR_STATIC
Nov 20, 2025
e2401c6
Add template<> to signify specialization
Nov 20, 2025
07f7a4a
Remove duplicate partial specialization.
Nov 20, 2025
42baa6c
Change NBL_CONSTEXPR_STATIC_FUNC to NBL_CONSTEXPR_STATIC
Nov 20, 2025
22e78eb
Fix concatenation of 'operator' and OP with '##' since operatorOP is …
Nov 20, 2025
8daf855
'equals' to 'equal'
Nov 20, 2025
831244f
Pass vec by value not ref
Nov 20, 2025
a560180
Use truncate to truncate
Nov 20, 2025
e320ed8
Make morton compile
Nov 22, 2025
83d27c9
NBL_CONSTEXPR_INLINE_VAR for template constexpr variable
Nov 27, 2025
c496916
Promote and Truncate take vector and scalar by value and the rest by …
Nov 28, 2025
d7bd053
Remove promote and truncate comment about specialization
Nov 28, 2025
3f3a23e
Add comment to rename log2
Nov 28, 2025
8dcdfdd
Change dimension type from uint16_t to int32_t
Nov 28, 2025
92cd9e7
Redefine some macro
Nov 28, 2025
7f6d8b8
use const instead of static const for local variable in hlsl
Nov 28, 2025
1d9ce20
Rename NBL_CONSTEXPR_INLINE to NBL_CONSTEXPR_INLINE_NSPC_SCOPE_VAR
Nov 28, 2025
1eded12
Refactor emulated_integral_64
Dec 1, 2025
aa9e24d
Add unary_minus_operator class
Dec 1, 2025
6683cd5
Remove commented code on emulated/vector_t.hlsl
Dec 1, 2025
cdb6ad7
Unify all Truncate specializaton for vector type
Dec 1, 2025
c365240
Fix promote.hlsl and reduce the amount of specialization for Promote
Dec 1, 2025
ec1d674
Make promote constrainable
Dec 1, 2025
51e35cf
equal to _equal
Dec 1, 2025
062ce7b
Remove some constraint in morton::code::create
Dec 1, 2025
6c82428
Remove NBL_CONSTEXPR_STATIC_INLINE_VAR macro
Dec 2, 2025
ca2ac6f
Remove Bit count constraint on some of Transcoder method due to redun…
Dec 2, 2025
4c9635d
Use cpp syntax instead of portable macro wherever possible
Dec 2, 2025
23292bd
Fix morton code constraint
Dec 3, 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
2 changes: 2 additions & 0 deletions include/nbl/builtin/hlsl/cpp_compat/basic.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <type_traits>

#define ARROW ->
#define NBL_DEREF_THIS (*this)
#define NBL_CONSTEXPR constexpr // TODO: rename to NBL_CONSTEXPR_VAR
#define NBL_CONSTEXPR_FUNC constexpr
#define NBL_CONSTEXPR_STATIC constexpr static
Expand Down Expand Up @@ -44,6 +45,7 @@ namespace nbl::hlsl
#else

#define ARROW .arrow().
#define NBL_DEREF_THIS this
#define NBL_CONSTEXPR const static // TODO: rename to NBL_CONSTEXPR_VAR
#define NBL_CONSTEXPR_FUNC
#define NBL_CONSTEXPR_STATIC const static
Expand Down
50 changes: 16 additions & 34 deletions include/nbl/builtin/hlsl/cpp_compat/truncate.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ namespace nbl
namespace hlsl
{

namespace concepts
{
template<typename To, typename From>
NBL_BOOL_CONCEPT can_truncate_vector = concepts::Vectorial<To> && concepts::Vectorial<From> && concepts::same_as<typename vector_traits<To>::scalar_type, typename vector_traits<From>::scalar_type > && vector_traits<To>::Dimension <= vector_traits<From>::Dimension;
}

namespace impl
{

Expand All @@ -21,44 +27,20 @@ struct Truncate
}
};

template<typename Scalar, int32_t N> NBL_PARTIAL_REQ_TOP(concepts::Scalar<Scalar>)
struct Truncate<vector<Scalar, 1>, vector<Scalar, N> NBL_PARTIAL_REQ_BOT(concepts::Scalar<Scalar>) >
template<typename To, typename From> NBL_PARTIAL_REQ_TOP(concepts::can_truncate_vector<To, From>)
struct Truncate<To, From NBL_PARTIAL_REQ_BOT(concepts::can_truncate_vector<To, From>) >
{
NBL_CONSTEXPR_FUNC vector<Scalar, 1> operator()(const vector<Scalar, N> v)
NBL_CONSTEXPR_FUNC To operator()(const From v)
{
vector<Scalar, 1> truncated = { v[0] };
return truncated;
array_get<From, typename vector_traits<From>::scalar_type> getter;
array_set<To, typename vector_traits<To>::scalar_type> setter;
To output;
[[unroll]]
for (int i = 0; i < vector_traits<To>::Dimension; ++i)
setter(output, i, getter(v, i));
return output;
}
};

template<typename Scalar, int32_t N> NBL_PARTIAL_REQ_TOP(concepts::Scalar<Scalar> && N >= 2)
struct Truncate<vector<Scalar, 2>, vector<Scalar, N> NBL_PARTIAL_REQ_BOT(concepts::Scalar<Scalar> && N >= 2) >
{
NBL_CONSTEXPR_FUNC vector<Scalar, 2> operator()(const vector<Scalar, N> v)
{
vector<Scalar, 2> truncated = { v[0], v[1]};
return truncated;
}
};

template<typename Scalar, int32_t N> NBL_PARTIAL_REQ_TOP(concepts::Scalar<Scalar>&& N >= 3)
struct Truncate<vector<Scalar, 3>, vector<Scalar, N> NBL_PARTIAL_REQ_BOT(concepts::Scalar<Scalar>&& N >= 3) >
{
NBL_CONSTEXPR_FUNC vector<Scalar, 3> operator()(const vector<Scalar, N> v)
{
vector<Scalar, 3> truncated = { v[0], v[1], v[2] };
return truncated;
}
};

template<typename Scalar, int32_t N> NBL_PARTIAL_REQ_TOP(concepts::Scalar<Scalar>&& N >= 4)
struct Truncate<vector<Scalar, 4>, vector<Scalar, N> NBL_PARTIAL_REQ_BOT(concepts::Scalar<Scalar>&& N >= 4) >
{
NBL_CONSTEXPR_FUNC vector<Scalar, 4> operator()(const vector<Scalar, N> v)
{
vector<Scalar, 4> truncated = { v[0], v[1], v[2], v[3] };
return truncated;
}
};

} //namespace impl
Expand Down
155 changes: 155 additions & 0 deletions include/nbl/builtin/hlsl/emulated/int64_common_member_inc.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@

storage_t data;

/**
* @brief Creates an `emulated_int64` from a vector of two `uint32_t`s representing its bitpattern
*
* @param [in] _data Vector of `uint32_t` encoding the `uint64_t/int64_t` being emulated. Stored as little endian (first component are the lower 32 bits)
*/
NBL_CONSTEXPR_STATIC this_t create(NBL_CONST_REF_ARG(storage_t) _data)
{
this_t retVal;
retVal.data = _data;
return retVal;
}

/**
* @brief Creates an `emulated_int64` from two `uint32_t`s representing its bitpattern
*
* @param [in] lo Lowest 32 bits of the `uint64_t/int64_t` being emulated
* @param [in] hi Highest 32 bits of the `uint64_t/int64_t` being emulated
*/
NBL_CONSTEXPR_STATIC this_t create(NBL_CONST_REF_ARG(uint32_t) lo, NBL_CONST_REF_ARG(uint32_t) hi)
{
return create(storage_t(lo, hi));
}

// ------------------------------------------------------- CONVERSION OPERATORS---------------------------------------------------------------
// GLM requires these for vector casts

#ifndef __HLSL_VERSION

template<concepts::IntegralScalar I>
constexpr explicit operator I() const noexcept;

#endif

// ------------------------------------------------------- INTERNAL GETTERS -------------------------------------------------

NBL_CONSTEXPR_FUNC uint32_t __getLSB() NBL_CONST_MEMBER_FUNC
{
return data.x;
}

NBL_CONSTEXPR_FUNC uint32_t __getMSB() NBL_CONST_MEMBER_FUNC
{
return data.y;
}

// ------------------------------------------------------- BITWISE OPERATORS -------------------------------------------------

NBL_CONSTEXPR_FUNC this_t operator&(NBL_CONST_REF_ARG(this_t) rhs) NBL_CONST_MEMBER_FUNC
{
this_t retVal = create(data & rhs.data);
return retVal;
}

NBL_CONSTEXPR_FUNC this_t operator|(NBL_CONST_REF_ARG(this_t) rhs) NBL_CONST_MEMBER_FUNC
{
this_t retVal = create(data | rhs.data);
return retVal;
}

NBL_CONSTEXPR_FUNC this_t operator^(NBL_CONST_REF_ARG(this_t) rhs) NBL_CONST_MEMBER_FUNC
{
this_t retVal = create(data ^ rhs.data);
return retVal;
}

NBL_CONSTEXPR_FUNC this_t operator~() NBL_CONST_MEMBER_FUNC
{
this_t retVal = create(~data);
return retVal;
}

// Only valid in CPP
#ifndef __HLSL_VERSION
constexpr inline this_t operator>>(uint32_t bits) const;

constexpr inline this_t operator<<(uint32_t bits) const;

constexpr inline this_t& operator&=(const this_t& val)
{
data &= val.data;
return *this;
}

constexpr inline this_t& operator|=(const this_t& val)
{
data |= val.data;
return *this;
}

constexpr inline this_t& operator^=(const this_t& val)
{
data ^= val.data;
return *this;
}

#endif

// ------------------------------------------------------- ARITHMETIC OPERATORS -------------------------------------------------

NBL_CONSTEXPR_FUNC this_t operator+(NBL_CONST_REF_ARG(this_t) rhs) NBL_CONST_MEMBER_FUNC
{
const spirv::AddCarryOutput<uint32_t> lowerAddResult = addCarry(__getLSB(), rhs.__getLSB());
return create(lowerAddResult.result, __getMSB() + rhs.__getMSB() + lowerAddResult.carry);
}

NBL_CONSTEXPR_FUNC this_t operator-(NBL_CONST_REF_ARG(this_t) rhs) NBL_CONST_MEMBER_FUNC
{
const spirv::SubBorrowOutput<uint32_t> lowerSubResult = subBorrow(__getLSB(), rhs.__getLSB());
return create(lowerSubResult.result, __getMSB() - rhs.__getMSB() - lowerSubResult.borrow);
}

// ------------------------------------------------------- COMPARISON OPERATORS -------------------------------------------------
NBL_CONSTEXPR_FUNC bool operator==(NBL_CONST_REF_ARG(this_t) rhs) NBL_CONST_MEMBER_FUNC
{
equal_to<storage_t> equals;
return all(equals(data, rhs.data));
}

NBL_CONSTEXPR_FUNC bool operator!=(NBL_CONST_REF_ARG(this_t) rhs) NBL_CONST_MEMBER_FUNC
{
not_equal_to<storage_t> notEquals;
return any(notEquals(data, rhs.data));
}

NBL_CONSTEXPR_FUNC bool operator<(NBL_CONST_REF_ARG(this_t) rhs) NBL_CONST_MEMBER_FUNC
{
// Either the topmost bits, when interpreted with correct sign, are less than those of `rhs`, or they're equal and the lower bits are less
// (lower bits are always positive in both unsigned and 2's complement so comparison can happen as-is)
const bool MSBEqual = __getMSB() == rhs.__getMSB();
const bool MSB = Signed ? (bit_cast<int32_t>(__getMSB()) < bit_cast<int32_t>(rhs.__getMSB())) : (__getMSB() < rhs.__getMSB());
const bool LSB = __getLSB() < rhs.__getLSB();
return MSBEqual ? LSB : MSB;
}

NBL_CONSTEXPR_FUNC bool operator>(NBL_CONST_REF_ARG(this_t) rhs) NBL_CONST_MEMBER_FUNC
{
// Same reasoning as above
const bool MSBEqual = __getMSB() == rhs.__getMSB();
const bool MSB = Signed ? (bit_cast<int32_t>(__getMSB()) > bit_cast<int32_t>(rhs.__getMSB())) : (__getMSB() > rhs.__getMSB());
const bool LSB = __getLSB() > rhs.__getLSB();
return MSBEqual ? LSB : MSB;
}

NBL_CONSTEXPR_FUNC bool operator<=(NBL_CONST_REF_ARG(this_t) rhs) NBL_CONST_MEMBER_FUNC
{
return !operator>(rhs);
}

NBL_CONSTEXPR_FUNC bool operator>=(NBL_CONST_REF_ARG(this_t) rhs) NBL_CONST_MEMBER_FUNC
{
return !operator<(rhs);
}
Loading
Loading