Skip to content

Commit 6a2bcff

Browse files
committed
Added FloatingPointLike concept
1 parent e3bf45a commit 6a2bcff

File tree

4 files changed

+39
-11
lines changed

4 files changed

+39
-11
lines changed

include/nbl/builtin/hlsl/concepts/core.hlsl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,19 @@ NBL_BOOL_CONCEPT floating_point = nbl::hlsl::is_floating_point_v<T> && nbl::hlsl
9191

9292
#endif
9393

94+
namespace impl
95+
{
96+
template<typename T>
97+
struct IsEmulatingFloatingPointType
98+
{
99+
static const bool value = false;
100+
};
101+
}
102+
103+
//! Floating point types are native floating point types or types that imitate native floating point types (for example emulated_float64_t)
104+
template<typename T>
105+
NBL_BOOL_CONCEPT FloatingPointLike = (nbl::hlsl::is_floating_point_v<T> && nbl::hlsl::is_scalar_v<T>) || impl::IsEmulatingFloatingPointType<T>::value;
106+
94107
}
95108
}
96109
}

include/nbl/builtin/hlsl/concepts/vector.hlsl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ NBL_BOOL_CONCEPT Vectorial = vector_traits<T>::IsVector;
5050
template<typename T>
5151
NBL_BOOL_CONCEPT FloatingPointVectorial = concepts::Vectorial<T> && concepts::floating_point<typename vector_traits<T>::scalar_type>;
5252
template<typename T>
53+
NBL_BOOL_CONCEPT FloatingPointLikeVectorial = concepts::Vectorial<T> && concepts::FloatingPointLike<typename vector_traits<T>::scalar_type>;
54+
template<typename T>
5355
NBL_BOOL_CONCEPT IntVectorial = concepts::Vectorial<T> && (is_integral_v<typename vector_traits<T>::scalar_type>);
5456
template<typename T>
5557
NBL_BOOL_CONCEPT SignedIntVectorial = concepts::Vectorial<T> && concepts::signed_integral<typename vector_traits<T>::scalar_type>;

include/nbl/builtin/hlsl/emulated/float64_t.hlsl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define _NBL_BUILTIN_HLSL_EMULATED_FLOAT64_T_HLSL_INCLUDED_
33

44
#include <nbl/builtin/hlsl/emulated/float64_t_impl.hlsl>
5+
#include <nbl/builtin/hlsl/concepts/core.hlsl>
56

67
namespace nbl
78
{
@@ -580,6 +581,18 @@ IMPLEMENT_IEEE754_FUNC_SPEC_FOR_EMULATED_F64_TYPE(emulated_float64_t<true, false
580581
IMPLEMENT_IEEE754_FUNC_SPEC_FOR_EMULATED_F64_TYPE(emulated_float64_t<false, true>);
581582
}
582583

584+
namespace concepts
585+
{
586+
namespace impl
587+
{
588+
template<bool FastMath, bool FlushDenormToZero>
589+
struct IsEmulatingFloatingPointType<emulated_float64_t<FastMath, FlushDenormToZero> >
590+
{
591+
static const bool value = true;
592+
};
593+
}
594+
}
595+
583596
}
584597
}
585598

include/nbl/builtin/hlsl/tgmath.hlsl

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,25 @@ namespace nbl
2424
namespace hlsl
2525
{
2626
// TODO: will not work for emulated_float as an input because `concepts::floating_point<T>` is only for native floats, fix every occurance
27-
template<typename FloatingPoint NBL_FUNC_REQUIRES(concepts::floating_point<FloatingPoint>)
27+
template<typename FloatingPoint NBL_FUNC_REQUIRES(concepts::FloatingPointLike<FloatingPoint>)
2828
inline FloatingPoint erf(FloatingPoint x)
2929
{
3030
return tgmath_impl::erf_helper<FloatingPoint>::__call(x);
3131
}
3232

33-
template<typename FloatingPoint NBL_FUNC_REQUIRES(concepts::floating_point<FloatingPoint>)
33+
template<typename FloatingPoint NBL_FUNC_REQUIRES(concepts::FloatingPointLike<FloatingPoint>)
3434
inline FloatingPoint erfInv(FloatingPoint x)
3535
{
3636
return tgmath_impl::erfInv_helper<FloatingPoint>::__call(x);
3737
}
3838

39-
template<typename T NBL_FUNC_REQUIRES(concepts::floating_point<T> || concepts::Vectorial<T>)
39+
template<typename T NBL_FUNC_REQUIRES(concepts::FloatingPointLike<T> || concepts::Vectorial<T>)
4040
inline T floor(NBL_CONST_REF_ARG(T) val)
4141
{
4242
return tgmath_impl::floor_helper<T>::__call(val);
4343
}
4444

45-
template<typename T, typename U NBL_FUNC_REQUIRES((concepts::floating_point<T> || concepts::FloatingPointVectorial<T>) && (concepts::floating_point<U> || is_same_v<U, bool>))
45+
template<typename T, typename U NBL_FUNC_REQUIRES((concepts::FloatingPointLike<T> || concepts::FloatingPointLikeVectorial<T>) && (concepts::floating_point<U> || is_same_v<U, bool>))
4646
inline T lerp(NBL_CONST_REF_ARG(T) x, NBL_CONST_REF_ARG(T) y, NBL_CONST_REF_ARG(U) a)
4747
{
4848
return tgmath_impl::lerp_helper<T, U>::__call(x, y, a);
@@ -54,7 +54,7 @@ inline bool isnan(NBL_CONST_REF_ARG(FloatingPoint) val)
5454
return tgmath_impl::isnan_helper<FloatingPoint>::__call(val);
5555
}
5656

57-
template<typename V NBL_FUNC_REQUIRES(concepts::FloatingPointVectorial<V>)
57+
template<typename V NBL_FUNC_REQUIRES(concepts::FloatingPointLikeVectorial<V>)
5858
inline vector<bool, vector_traits<V>::Dimension> isnan(NBL_CONST_REF_ARG(V) val)
5959
{
6060
return tgmath_impl::isnan_helper<V>::__call(val);
@@ -66,38 +66,38 @@ inline FloatingPoint isinf(NBL_CONST_REF_ARG(FloatingPoint) val)
6666
return tgmath_impl::isinf_helper<FloatingPoint>::__call(val);
6767
}
6868

69-
template<typename V NBL_FUNC_REQUIRES(concepts::FloatingPointVectorial<V>)
69+
template<typename V NBL_FUNC_REQUIRES(concepts::FloatingPointLikeVectorial<V>)
7070
inline vector<bool, vector_traits<V>::Dimension> isinf(NBL_CONST_REF_ARG(V) val)
7171
{
7272
return tgmath_impl::isinf_helper<V>::__call(val);
7373
}
7474

75-
template<typename T NBL_FUNC_REQUIRES(concepts::floating_point<T> || concepts::FloatingPointVectorial<T>)
75+
template<typename T NBL_FUNC_REQUIRES(concepts::FloatingPointLike<T> || concepts::FloatingPointLikeVectorial<T>)
7676
inline T pow(NBL_CONST_REF_ARG(T) x, NBL_CONST_REF_ARG(T) y)
7777
{
7878
return tgmath_impl::pow_helper<T>::__call(x, y);
7979
}
8080

81-
template<typename T NBL_FUNC_REQUIRES(concepts::floating_point<T> || concepts::FloatingPointVectorial<T>)
81+
template<typename T NBL_FUNC_REQUIRES(concepts::FloatingPointLike<T> || concepts::FloatingPointLikeVectorial<T>)
8282
inline T exp(NBL_CONST_REF_ARG(T) x)
8383
{
8484
return tgmath_impl::exp_helper<T>::__call(x);
8585
}
8686

8787

88-
template<typename T NBL_FUNC_REQUIRES(concepts::floating_point<T> || concepts::Vectorial<T>)
88+
template<typename T NBL_FUNC_REQUIRES(concepts::FloatingPointLike<T> || concepts::Vectorial<T>)
8989
inline T exp2(NBL_CONST_REF_ARG(T) x)
9090
{
9191
return tgmath_impl::exp2_helper<T>::__call(x);
9292
}
9393

94-
template<typename T NBL_FUNC_REQUIRES(concepts::floating_point<T> || concepts::FloatingPointVectorial<T>)
94+
template<typename T NBL_FUNC_REQUIRES(concepts::FloatingPointLike<T> || concepts::FloatingPointLikeVectorial<T>)
9595
inline T log(NBL_CONST_REF_ARG(T) x)
9696
{
9797
return tgmath_impl::log_helper<T>::__call(x);
9898
}
9999

100-
template<typename T NBL_FUNC_REQUIRES(concepts::floating_point<T> || concepts::signed_integral<T> || concepts::FloatingPointVectorial<T> || concepts::SignedIntVectorial<T>)
100+
template<typename T NBL_FUNC_REQUIRES(concepts::FloatingPointLike<T> || concepts::signed_integral<T> || concepts::FloatingPointLikeVectorial<T> || concepts::SignedIntVectorial<T>)
101101
inline T abs(NBL_CONST_REF_ARG(T) val)
102102
{
103103
return tgmath_impl::abs_helper<T>::__call(val);

0 commit comments

Comments
 (0)