-
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?
Conversation
… on HLSL side by specializing , a bunch of morton operators
…or both cpp and hlsl
| #ifndef __HLSL_VERSION | ||
| template<typename F1, typename F2 > requires(is_same_v<std::invoke_result_t<F1>, std::invoke_result_t<F2>()> ) | ||
| struct ternary_operator | ||
| { | ||
| using type_t = T; | ||
|
|
||
| NBL_CONSTEXPR_FUNC T operator()(NBL_CONST_REF_ARG(bool) condition, NBL_CONST_REF_ARG(T) lhs, NBL_CONST_REF_ARG(T) rhs) | ||
| { | ||
| return select<bool, T>(condition, lhs, rhs); | ||
| } | ||
| using type_t = std::invoke_result_t<F1>; | ||
|
|
||
| constexpr inline type_t operator()(const bool condition, const F1& lhs, const F2& rhs) | ||
| { | ||
| if (condition) | ||
| return std::invoke(lhs); | ||
| else | ||
| return std::invoke(rhs); | ||
| } | ||
| }; | ||
| #else | ||
| template<typename F1, typename F2 NBL_PRIMARY_REQUIRES(is_same_v<decltype(experimental::declval<F1>()()),decltype(experimental::declval<F2>()())> ) | ||
| struct ternary_operator | ||
| { | ||
| using type_t = decltype(experimental::declval<F1>().operator()); | ||
|
|
||
| NBL_CONSTEXPR_FUNC type_t operator()(const bool condition, NBL_CONST_REF_ARG(F1) lhs, NBL_CONST_REF_ARG(F2) rhs) | ||
| { | ||
| if (condition) | ||
| return lhs(); | ||
| else | ||
| return rhs(); | ||
| } | ||
| }; | ||
| #endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see no reason to have two separate implementations, the HLSL one should work everywhere.
Also provide 4 overloads which takes lhs and rhs as NBL_REF_ARG instead of CONST_REF_ARG (so the calls can be stateful but mutable0
| { | ||
| 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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ifdef __HLSL_VERSION then use spirv::select instead of ternary ? op (so DXC codegens OpSelect and not a branch
| 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; | ||
| } | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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 T vector)
The vector<bool,N> and vector<T,N> specialization should use spirv::select but only exists for HLSL, see how it was done for mix_helper
Description
Adds a new class for 2,3 and 4-dimensional morton codes, with arithmetic and comparison operators
Testing
TODO
TODO list:
Need to make sure all operators work properly before merging