Skip to content

Commit f5071f4

Browse files
committed
cherry-picked mix_helper fixes
1 parent bcec283 commit f5071f4

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -240,13 +240,17 @@ struct mix_helper<T, T NBL_PARTIAL_REQ_BOT(always_true<decltype(spirv::fMix<T>(e
240240
}
241241
};
242242

243-
template<typename T> NBL_PARTIAL_REQ_TOP(concepts::FloatingPointScalar<T>)
244-
struct mix_helper<T, bool NBL_PARTIAL_REQ_BOT(concepts::FloatingPointScalar<T>) >
243+
template<typename T, typename U>
244+
NBL_PARTIAL_REQ_TOP((concepts::Scalar<T> || concepts::Vectorial<T>) && !concepts::Boolean<T> && concepts::Boolean<U>)
245+
struct mix_helper<T, U NBL_PARTIAL_REQ_BOT((concepts::Scalar<T> || concepts::Vectorial<T>) && !concepts::Boolean<T> && concepts::Boolean<U>) >
245246
{
246247
using return_t = conditional_t<is_vector_v<T>, vector<typename vector_traits<T>::scalar_type, vector_traits<T>::Dimension>, T>;
247-
static inline return_t __call(const T x, const T y, const bool a)
248+
// for a component of a that is false, the corresponding component of x is returned
249+
// for a component of a that is true, the corresponding component of y is returned
250+
// so we make sure this is correct when calling the operation
251+
static inline return_t __call(const T x, const T y, const U a)
248252
{
249-
return a ? x : y;
253+
return spirv::select<T, U>(a, y, x);
250254
}
251255
};
252256

@@ -862,8 +866,8 @@ struct mix_helper<T, T NBL_PARTIAL_REQ_BOT(VECTOR_SPECIALIZATION_CONCEPT) >
862866
};
863867

864868
template<typename T, typename U>
865-
NBL_PARTIAL_REQ_TOP(concepts::Vectorial<T> && concepts::Boolean<U> && vector_traits<T>::Dimension == vector_traits<U>::Dimension)
866-
struct mix_helper<T, U NBL_PARTIAL_REQ_BOT(concepts::Vectorial<T> && concepts::Boolean<U> && vector_traits<T>::Dimension == vector_traits<U>::Dimension) >
869+
NBL_PARTIAL_REQ_TOP(VECTOR_SPECIALIZATION_CONCEPT && concepts::Boolean<U> && vector_traits<T>::Dimension == vector_traits<U>::Dimension)
870+
struct mix_helper<T, U NBL_PARTIAL_REQ_BOT(VECTOR_SPECIALIZATION_CONCEPT && concepts::Boolean<U> && vector_traits<T>::Dimension == vector_traits<U>::Dimension) >
867871
{
868872
using return_t = T;
869873
static return_t __call(NBL_CONST_REF_ARG(T) x, NBL_CONST_REF_ARG(T) y, NBL_CONST_REF_ARG(U) a)

include/nbl/builtin/hlsl/spirv_intrinsics/core.hlsl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,20 @@ template<typename T NBL_FUNC_REQUIRES(concepts::UnsignedIntegral<T>)
346346
[[vk::ext_instruction(spv::OpISubBorrow)]]
347347
SubBorrowOutput<T> subBorrow(T operand1, T operand2);
348348

349+
350+
template<typename T NBL_FUNC_REQUIRES(is_integral_v<T> && !is_matrix_v<T>)
351+
[[vk::ext_instruction(spv::OpIEqual)]]
352+
conditional_t<is_vector_v<T>, vector<bool, vector_traits<T>::Dimension>, bool> IEqual(T lhs, T rhs);
353+
354+
template<typename T NBL_FUNC_REQUIRES(is_floating_point_v<T> && !is_matrix_v<T>)
355+
[[vk::ext_instruction(spv::OpFOrdEqual)]]
356+
conditional_t<is_vector_v<T>, vector<bool, vector_traits<T>::Dimension>, bool> FOrdEqual(T lhs, T rhs);
357+
358+
359+
template<typename T, typename U NBL_FUNC_REQUIRES(!is_matrix_v<T> && !is_matrix_v<U> && is_same_v<typename vector_traits<U>::scalar_type, bool>)
360+
[[vk::ext_instruction(spv::OpSelect)]]
361+
T select(U a, T x, T y);
362+
349363
}
350364

351365
#endif

0 commit comments

Comments
 (0)