Skip to content

Commit be5ef6b

Browse files
committed
use spirv intrinsic for dot
1 parent 0ecda6a commit be5ef6b

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

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

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ template<typename T> AUTO_SPECIALIZE_TRIVIAL_CASE_HELPER(find_lsb_helper, findIL
134134
#undef FIND_MSB_LSB_RETURN_TYPE
135135

136136
template<typename T> AUTO_SPECIALIZE_TRIVIAL_CASE_HELPER(bitReverse_helper, bitReverse, (T), (T), T)
137+
template<typename T> AUTO_SPECIALIZE_TRIVIAL_CASE_HELPER(dot_helper, dot, (T), (T)(T), typename vector_traits<T>::scalar_type)
137138
template<typename T> AUTO_SPECIALIZE_TRIVIAL_CASE_HELPER(transpose_helper, transpose, (T), (T), T)
138139
template<typename T> AUTO_SPECIALIZE_TRIVIAL_CASE_HELPER(length_helper, length, (T), (T), typename vector_traits<T>::scalar_type)
139140
template<typename T> AUTO_SPECIALIZE_TRIVIAL_CASE_HELPER(normalize_helper, normalize, (T), (T), T)
@@ -599,20 +600,6 @@ struct nClamp_helper<T>
599600
}
600601
};
601602

602-
#endif // C++ only specializations
603-
604-
// C++ and HLSL specializations
605-
606-
template<typename T>
607-
NBL_PARTIAL_REQ_TOP(concepts::UnsignedIntegralScalar<T>)
608-
struct bitReverseAs_helper<T NBL_PARTIAL_REQ_BOT(concepts::UnsignedIntegralScalar<T>) >
609-
{
610-
static T __call(NBL_CONST_REF_ARG(T) val, uint16_t bits)
611-
{
612-
return bitReverse_helper<T>::__call(val) >> promote<T, scalar_type_t<T> >(scalar_type_t <T>(sizeof(T) * 8 - bits));
613-
}
614-
};
615-
616603
template<typename Vectorial>
617604
NBL_PARTIAL_REQ_TOP(concepts::Vectorial<Vectorial>)
618605
struct dot_helper<Vectorial NBL_PARTIAL_REQ_BOT(concepts::Vectorial<Vectorial>) >
@@ -632,6 +619,20 @@ struct dot_helper<Vectorial NBL_PARTIAL_REQ_BOT(concepts::Vectorial<Vectorial>)
632619
}
633620
};
634621

622+
#endif // C++ only specializations
623+
624+
// C++ and HLSL specializations
625+
626+
template<typename T>
627+
NBL_PARTIAL_REQ_TOP(concepts::UnsignedIntegralScalar<T>)
628+
struct bitReverseAs_helper<T NBL_PARTIAL_REQ_BOT(concepts::UnsignedIntegralScalar<T>) >
629+
{
630+
static T __call(NBL_CONST_REF_ARG(T) val, uint16_t bits)
631+
{
632+
return bitReverse_helper<T>::__call(val) >> promote<T, scalar_type_t<T> >(scalar_type_t <T>(sizeof(T) * 8 - bits));
633+
}
634+
};
635+
635636
#ifdef __HLSL_VERSION
636637
// SPIR-V already defines specializations for builtin vector types
637638
#define VECTOR_SPECIALIZATION_CONCEPT concepts::Vectorial<T> && !is_vector_v<T>

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,10 @@ template<typename T NBL_FUNC_REQUIRES(is_floating_point_v<T> && is_vector_v<T>)
318318
[[vk::ext_instruction(spv::OpIsInf)]]
319319
vector<bool, vector_traits<T>::Dimension> isInf(T val);
320320

321+
template<typename Vector NBL_FUNC_REQUIRES(is_vector_v<T>)
322+
[[vk::ext_instruction( spv::OpDot )]]
323+
typename vector_traits<Vector>::scalar_type dot(Vector lhs, Vector rhs);
324+
321325
template<typename Matrix>
322326
[[vk::ext_instruction( spv::OpTranspose )]]
323327
Matrix transpose(Matrix mat);

0 commit comments

Comments
 (0)