Skip to content

Commit a4dabdf

Browse files
author
kevyuu
committed
Simplify mix helper by using select_helper in some specialization
1 parent 727d201 commit a4dabdf

File tree

1 file changed

+3
-47
lines changed

1 file changed

+3
-47
lines changed

include/nbl/builtin/hlsl/cpp_compat/impl/intrinsics_impl.hlsl

Lines changed: 3 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -268,20 +268,6 @@ struct mix_helper<T, T NBL_PARTIAL_REQ_BOT(spirv::FMixIsCallable<T>) >
268268
}
269269
};
270270

271-
template<typename T, typename U>
272-
NBL_PARTIAL_REQ_TOP(spirv::SelectIsCallable<T,U>)
273-
struct mix_helper<T, U NBL_PARTIAL_REQ_BOT(spirv::SelectIsCallable<T,U>) >
274-
{
275-
using return_t = conditional_t<is_vector_v<T>, vector<typename vector_traits<T>::scalar_type, vector_traits<T>::Dimension>, T>;
276-
// for a component of a that is false, the corresponding component of x is returned
277-
// for a component of a that is true, the corresponding component of y is returned
278-
// so we make sure this is correct when calling the operation
279-
static inline return_t __call(const T x, const T y, const U a)
280-
{
281-
return spirv::select<T, U>(a, y, x);
282-
}
283-
};
284-
285271
template<typename SquareMatrix> NBL_PARTIAL_REQ_TOP(matrix_traits<SquareMatrix>::Square)
286272
struct determinant_helper<SquareMatrix NBL_PARTIAL_REQ_BOT(matrix_traits<SquareMatrix>::Square) >
287273
{
@@ -980,43 +966,13 @@ struct mix_helper<T, T NBL_PARTIAL_REQ_BOT(VECTOR_SPECIALIZATION_CONCEPT && !imp
980966
}
981967
};
982968

983-
template<typename T, typename U>
984-
NBL_PARTIAL_REQ_TOP(VECTOR_SPECIALIZATION_CONCEPT && !impl::MixCallingBuiltins<T,U> && concepts::BooleanScalar<U>)
985-
struct mix_helper<T, U NBL_PARTIAL_REQ_BOT(VECTOR_SPECIALIZATION_CONCEPT && !impl::MixCallingBuiltins<T,U> && concepts::BooleanScalar<U>) >
969+
template<typename T, typename U> NBL_PARTIAL_REQ_TOP(concepts::Vectorial<T> && concepts::BooleanScalar<U>)
970+
struct mix_helper<T, U NBL_PARTIAL_REQ_BOT(concepts::Vectorial<T> && concepts::BooleanScalar<U>) >
986971
{
987972
using return_t = T;
988973
static return_t __call(NBL_CONST_REF_ARG(T) x, NBL_CONST_REF_ARG(T) y, NBL_CONST_REF_ARG(U) a)
989974
{
990-
using traitsT = hlsl::vector_traits<T>;
991-
array_get<T, typename traitsT::scalar_type> getterT;
992-
array_set<return_t, typename traitsT::scalar_type> setter;
993-
994-
return_t output;
995-
for (uint32_t i = 0; i < traitsT::Dimension; ++i)
996-
setter(output, i, mix_helper<typename traitsT::scalar_type, U>::__call(getterT(x, i), getterT(y, i), a));
997-
998-
return output;
999-
}
1000-
};
1001-
1002-
template<typename T, typename U>
1003-
NBL_PARTIAL_REQ_TOP(VECTOR_SPECIALIZATION_CONCEPT && !impl::MixCallingBuiltins<T,U> && concepts::Boolean<U> && concepts::Vectorial<U> && vector_traits<T>::Dimension == vector_traits<U>::Dimension)
1004-
struct mix_helper<T, U NBL_PARTIAL_REQ_BOT(VECTOR_SPECIALIZATION_CONCEPT && !impl::MixCallingBuiltins<T,U> && concepts::Boolean<U> && concepts::Vectorial<U> && vector_traits<T>::Dimension == vector_traits<U>::Dimension) >
1005-
{
1006-
using return_t = T;
1007-
static return_t __call(NBL_CONST_REF_ARG(T) x, NBL_CONST_REF_ARG(T) y, NBL_CONST_REF_ARG(U) a)
1008-
{
1009-
using traitsT = hlsl::vector_traits<T>;
1010-
using traitsU = hlsl::vector_traits<U>;
1011-
array_get<T, typename traitsT::scalar_type> getterT;
1012-
array_get<U, typename traitsU::scalar_type> getterU;
1013-
array_set<return_t, typename traitsT::scalar_type> setter;
1014-
1015-
return_t output;
1016-
for (uint32_t i = 0; i < traitsT::Dimension; ++i)
1017-
setter(output, i, mix_helper<typename traitsT::scalar_type, typename traitsU::scalar_type>::__call(getterT(x, i), getterT(y, i), getterU(a, i)));
1018-
1019-
return output;
975+
return select_helper<U, T>(a, y, x);
1020976
}
1021977
};
1022978

0 commit comments

Comments
 (0)