Skip to content

Commit f99ad10

Browse files
committed
Added all and any
1 parent 2e56fc9 commit f99ad10

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

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

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,52 @@ struct rsqrt_helper<FloatingPointVector NBL_PARTIAL_REQ_BOT(is_vector_v<Floating
781781
}
782782
};
783783

784+
// ALL
785+
786+
template<typename T NBL_STRUCT_CONSTRAINABLE>
787+
struct all_helper;
788+
789+
template<typename BooleanVector>
790+
NBL_PARTIAL_REQ_TOP(is_vector_v<BooleanVector> && is_same_v<typename vector_traits<BooleanVector>::scalar_type, bool>)
791+
struct all_helper<BooleanVector NBL_PARTIAL_REQ_BOT(is_vector_v<BooleanVector> && is_same_v<typename vector_traits<BooleanVector>::scalar_type, bool>) >
792+
{
793+
static bool __call(NBL_CONST_REF_ARG(BooleanVector) x)
794+
{
795+
using traits = hlsl::vector_traits<BooleanVector>;
796+
array_get<BooleanVector, typename traits::scalar_type> getter;
797+
array_set<BooleanVector, typename traits::scalar_type> setter;
798+
799+
bool output = true;
800+
for (uint32_t i = 0; i < traits::Dimension; ++i)
801+
output = output && getter(x, i);
802+
803+
return output;
804+
}
805+
};
806+
807+
// ANY
808+
809+
template<typename T NBL_STRUCT_CONSTRAINABLE>
810+
struct any_helper;
811+
812+
template<typename BooleanVector>
813+
NBL_PARTIAL_REQ_TOP(is_vector_v<BooleanVector>&& is_same_v<typename vector_traits<BooleanVector>::scalar_type, bool>)
814+
struct any_helper<BooleanVector NBL_PARTIAL_REQ_BOT(is_vector_v<BooleanVector>&& is_same_v<typename vector_traits<BooleanVector>::scalar_type, bool>) >
815+
{
816+
static bool __call(NBL_CONST_REF_ARG(BooleanVector) x)
817+
{
818+
using traits = hlsl::vector_traits<BooleanVector>;
819+
array_get<BooleanVector, typename traits::scalar_type> getter;
820+
array_set<BooleanVector, typename traits::scalar_type> setter;
821+
822+
bool output = false;
823+
for (uint32_t i = 0; i < traits::Dimension; ++i)
824+
output = output || getter(x, i);
825+
826+
return output;
827+
}
828+
};
829+
784830
}
785831
}
786832
}

include/nbl/builtin/hlsl/cpp_compat/intrinsics.hlsl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,18 @@ inline Integer bitReverse(Integer val)
128128
return cpp_compat_intrinsics_impl::bitReverse_helper<Integer>::__call(val);
129129
}
130130

131+
template<typename Vector>
132+
inline bool all(Vector vec)
133+
{
134+
return cpp_compat_intrinsics_impl::all_helper<Vector>::__call(vec);
135+
}
136+
137+
template<typename Vector>
138+
inline bool any(Vector vec)
139+
{
140+
return cpp_compat_intrinsics_impl::any_helper<Vector>::__call(vec);
141+
}
142+
131143
}
132144
}
133145

0 commit comments

Comments
 (0)