-
Notifications
You must be signed in to change notification settings - Fork 67
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
base: master
Are you sure you want to change the base?
Changes from 51 commits
cdcc9ad
8e84558
d33fab5
5fe6c08
f18b2fa
7d86cba
4ebc555
55a2ef6
f516256
534d81b
6256390
246cefc
1c7f791
5088799
e25a35c
0d9dd4a
89d2bf2
de4d0fb
799420e
52323bc
b6b7003
60ff99a
5560162
e50c56b
b1de9c3
ea8cd43
53a5f6a
cf52d9c
f954522
2d0ffba
68edc32
5013c89
c53668c
977c7dd
3294d04
e2401c6
07f7a4a
42baa6c
22e78eb
8daf855
831244f
a560180
e320ed8
83d27c9
c496916
d7bd053
3f3a23e
8dcdfdd
92cd9e7
7f6d8b8
1d9ce20
1eded12
aa9e24d
6683cd5
cdb6ad7
c365240
ec1d674
51e35cf
062ce7b
6c82428
ca2ac6f
4c9635d
23292bd
5da522e
812ae7b
341d6cd
2fd2cba
1255d1c
527129f
ed696ef
4da1fb8
402b823
99b25ff
70a88fa
ded5d8f
17d0717
791b2b9
ac2070e
727d201
a4dabdf
1a32ed2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,7 +27,7 @@ template<typename UnsignedInteger NBL_FUNC_REQUIRES(hlsl::is_integral_v<Unsigned | |
| inline bool isnan_uint_impl(UnsignedInteger val) | ||
| { | ||
| using AsFloat = typename float_of_size<sizeof(UnsignedInteger)>::type; | ||
| NBL_CONSTEXPR UnsignedInteger Mask = (UnsignedInteger(0) - 1) >> 1; | ||
| NBL_CONSTEXPR_FUNC_SCOPE_VAR UnsignedInteger Mask = (UnsignedInteger(0) - 1) >> 1; | ||
| UnsignedInteger absVal = val & Mask; | ||
| return absVal > (ieee754::traits<AsFloat>::specialValueExp << ieee754::traits<AsFloat>::mantissaBitCnt); | ||
| } | ||
|
|
@@ -90,6 +90,8 @@ template<typename T NBL_STRUCT_CONSTRAINABLE> | |
| struct all_helper; | ||
| template<typename T NBL_STRUCT_CONSTRAINABLE> | ||
| struct any_helper; | ||
| template<typename B, typename T NBL_STRUCT_CONSTRAINABLE> | ||
| struct select_helper; | ||
| template<typename T NBL_STRUCT_CONSTRAINABLE> | ||
| struct bitReverseAs_helper; | ||
| template<typename T NBL_STRUCT_CONSTRAINABLE> | ||
|
|
@@ -119,6 +121,12 @@ struct nMax_helper; | |
| template<typename T NBL_STRUCT_CONSTRAINABLE> | ||
| struct nClamp_helper; | ||
| template<typename T NBL_STRUCT_CONSTRAINABLE> | ||
| struct addCarry_helper; | ||
| template<typename T NBL_STRUCT_CONSTRAINABLE> | ||
| struct subBorrow_helper; | ||
| template<typename T NBL_STRUCT_CONSTRAINABLE> | ||
| struct undef_helper; | ||
| template<typename T NBL_STRUCT_CONSTRAINABLE> | ||
| struct fma_helper; | ||
|
|
||
| #ifdef __HLSL_VERSION // HLSL only specializations | ||
|
|
@@ -133,8 +141,8 @@ struct fma_helper; | |
| // the template<> needs to be written ourselves | ||
| // return type is __VA_ARGS__ to protect against `,` in templated return types | ||
| #define AUTO_SPECIALIZE_TRIVIAL_CASE_HELPER(HELPER_NAME, SPIRV_FUNCTION_NAME, ARG_TYPE_LIST, ARG_TYPE_SET, ...)\ | ||
| NBL_PARTIAL_REQ_TOP(is_same_v<decltype(spirv::SPIRV_FUNCTION_NAME<T>(BOOST_PP_SEQ_FOR_EACH_I(DECLVAL, _, ARG_TYPE_SET))), __VA_ARGS__ >) \ | ||
| struct HELPER_NAME<BOOST_PP_SEQ_FOR_EACH_I(WRAP, _, ARG_TYPE_LIST) NBL_PARTIAL_REQ_BOT(is_same_v<decltype(spirv::SPIRV_FUNCTION_NAME<T>(BOOST_PP_SEQ_FOR_EACH_I(DECLVAL, _, ARG_TYPE_SET))), __VA_ARGS__ >) >\ | ||
| NBL_PARTIAL_REQ_TOP(is_same_v<decltype(spirv::SPIRV_FUNCTION_NAME< BOOST_PP_SEQ_FOR_EACH_I(WRAP, _, ARG_TYPE_LIST) >(BOOST_PP_SEQ_FOR_EACH_I(DECLVAL, _, ARG_TYPE_SET))), __VA_ARGS__ >) \ | ||
| struct HELPER_NAME<BOOST_PP_SEQ_FOR_EACH_I(WRAP, _, ARG_TYPE_LIST) NBL_PARTIAL_REQ_BOT(is_same_v<decltype(spirv::SPIRV_FUNCTION_NAME< BOOST_PP_SEQ_FOR_EACH_I(WRAP, _, ARG_TYPE_LIST) >(BOOST_PP_SEQ_FOR_EACH_I(DECLVAL, _, ARG_TYPE_SET))), __VA_ARGS__ >) >\ | ||
| {\ | ||
| using return_t = __VA_ARGS__;\ | ||
| static inline return_t __call( BOOST_PP_SEQ_FOR_EACH_I(DECL_ARG, _, ARG_TYPE_SET) )\ | ||
|
|
@@ -156,8 +164,9 @@ template<typename T> AUTO_SPECIALIZE_TRIVIAL_CASE_HELPER(length_helper, length, | |
| template<typename T> AUTO_SPECIALIZE_TRIVIAL_CASE_HELPER(normalize_helper, normalize, (T), (T), T) | ||
| template<typename T> AUTO_SPECIALIZE_TRIVIAL_CASE_HELPER(rsqrt_helper, inverseSqrt, (T), (T), T) | ||
| template<typename T> AUTO_SPECIALIZE_TRIVIAL_CASE_HELPER(fract_helper, fract, (T), (T), T) | ||
| template<typename T> AUTO_SPECIALIZE_TRIVIAL_CASE_HELPER(all_helper, any, (T), (T), bool) | ||
| template<typename T> AUTO_SPECIALIZE_TRIVIAL_CASE_HELPER(all_helper, all, (T), (T), bool) | ||
| template<typename T> AUTO_SPECIALIZE_TRIVIAL_CASE_HELPER(any_helper, any, (T), (T), bool) | ||
| template<typename B, typename T> AUTO_SPECIALIZE_TRIVIAL_CASE_HELPER(select_helper, select, (B)(T), (B)(T)(T), T) | ||
| template<typename T> AUTO_SPECIALIZE_TRIVIAL_CASE_HELPER(sign_helper, fSign, (T), (T), T) | ||
| template<typename T> AUTO_SPECIALIZE_TRIVIAL_CASE_HELPER(sign_helper, sSign, (T), (T), T) | ||
| template<typename T> AUTO_SPECIALIZE_TRIVIAL_CASE_HELPER(radians_helper, radians, (T), (T), T) | ||
|
|
@@ -179,6 +188,10 @@ template<typename T, typename U> AUTO_SPECIALIZE_TRIVIAL_CASE_HELPER(refract_hel | |
| template<typename T> AUTO_SPECIALIZE_TRIVIAL_CASE_HELPER(nMax_helper, nMax, (T), (T)(T), T) | ||
| template<typename T> AUTO_SPECIALIZE_TRIVIAL_CASE_HELPER(nMin_helper, nMin, (T), (T)(T), T) | ||
| template<typename T> AUTO_SPECIALIZE_TRIVIAL_CASE_HELPER(nClamp_helper, nClamp, (T), (T)(T), T) | ||
| // Can use trivial case and not worry about restricting `T` with a concept since `spirv::AddCarryOutput / SubBorrowOutput` already take care of that | ||
| template<typename T> AUTO_SPECIALIZE_TRIVIAL_CASE_HELPER(addCarry_helper, addCarry, (T), (T)(T), spirv::AddCarryOutput<T>) | ||
| template<typename T> AUTO_SPECIALIZE_TRIVIAL_CASE_HELPER(subBorrow_helper, subBorrow, (T), (T)(T), spirv::SubBorrowOutput<T>) | ||
| template<typename T> AUTO_SPECIALIZE_TRIVIAL_CASE_HELPER(undef_helper, undef, (T), , T) | ||
| template<typename T> AUTO_SPECIALIZE_TRIVIAL_CASE_HELPER(fma_helper, fma, (T), (T)(T)(T), T) | ||
|
|
||
| #define BITCOUNT_HELPER_RETRUN_TYPE conditional_t<is_vector_v<T>, vector<int32_t, vector_traits<T>::Dimension>, int32_t> | ||
|
|
@@ -629,6 +642,72 @@ struct nClamp_helper<T> | |
| } | ||
| }; | ||
|
|
||
| // Once again no need to restrict the two below with concepts for same reason as HLSL version | ||
| template<typename T> | ||
| struct addCarry_helper | ||
| { | ||
| using return_t = spirv::AddCarryOutput<T>; | ||
| constexpr static inline return_t __call(const T operand1, const T operand2) | ||
| { | ||
| return_t retVal; | ||
| retVal.result = operand1 + operand2; | ||
| retVal.carry = T(retVal.result < operand1); | ||
| return retVal; | ||
| } | ||
| }; | ||
|
|
||
| template<typename T> | ||
| struct subBorrow_helper | ||
| { | ||
| using return_t = spirv::SubBorrowOutput<T>; | ||
| constexpr static inline return_t __call(const T operand1, const T operand2) | ||
| { | ||
| return_t retVal; | ||
| retVal.result = static_cast<T>(operand1 - operand2); | ||
| retVal.borrow = T(operand1 < operand2); | ||
| return retVal; | ||
| } | ||
| }; | ||
|
|
||
| template<typename B, typename T> | ||
| NBL_PARTIAL_REQ_TOP(concepts::BooleanScalar<B>) | ||
| struct select_helper<B, T NBL_PARTIAL_REQ_BOT(concepts::BooleanScalar<B>) > | ||
| { | ||
| NBL_CONSTEXPR_STATIC T __call(NBL_CONST_REF_ARG(B) condition, NBL_CONST_REF_ARG(T) object1, NBL_CONST_REF_ARG(T) object2) | ||
| { | ||
| return condition ? object1 : object2; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
| }; | ||
|
|
||
| template<typename B, typename T> | ||
| NBL_PARTIAL_REQ_TOP(concepts::Boolean<B>&& concepts::Vector<B>&& concepts::Vector<T> && (extent_v<B> == extent_v<T>)) | ||
| struct select_helper<B, T NBL_PARTIAL_REQ_BOT(concepts::Boolean<B>&& concepts::Vector<B>&& concepts::Vector<T> && (extent_v<B> == extent_v<T>)) > | ||
| { | ||
| NBL_CONSTEXPR_STATIC T __call(NBL_CONST_REF_ARG(B) condition, NBL_CONST_REF_ARG(T) object1, NBL_CONST_REF_ARG(T) object2) | ||
| { | ||
| using traits = hlsl::vector_traits<T>; | ||
| array_get<B, bool> conditionGetter; | ||
| array_get<T, typename traits::scalar_type> objectGetter; | ||
| array_set<T, typename traits::scalar_type> setter; | ||
|
|
||
| T selected; | ||
| for (uint32_t i = 0; i < traits::Dimension; ++i) | ||
| setter(selected, i, conditionGetter(condition, i) ? objectGetter(object1, i) : objectGetter(object2, i)); | ||
|
|
||
| return selected; | ||
| } | ||
| }; | ||
|
Comment on lines
+668
to
+685
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the code in this specialization should be reserved for non-native vectors (either the boolean vector is non-native or the The |
||
|
|
||
| template<typename T> | ||
| struct undef_helper | ||
| { | ||
| NBL_CONSTEXPR_STATIC T __call() | ||
| { | ||
| T t; | ||
| return t; | ||
| } | ||
| }; | ||
|
|
||
| template<typename FloatingPoint> | ||
| requires concepts::FloatingPointScalar<FloatingPoint> | ||
| struct fma_helper<FloatingPoint> | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.