Skip to content

Commit 2b861ea

Browse files
committed
Fix
1 parent cf3e18d commit 2b861ea

File tree

2 files changed

+41
-34
lines changed

2 files changed

+41
-34
lines changed

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

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,22 @@ struct cross_helper<T NBL_PARTIAL_REQ_BOT(concepts::FloatingPointVector<T> && (v
252252

253253
#else // C++ only specializations
254254

255+
template<typename UnsignedInteger NBL_FUNC_REQUIRES(hlsl::is_integral_v<UnsignedInteger>&& hlsl::is_unsigned_v<UnsignedInteger>)
256+
inline bool isnan_uint_impl(UnsignedInteger val)
257+
{
258+
using AsFloat = typename float_of_size<sizeof(UnsignedInteger)>::type;
259+
constexpr UnsignedInteger Mask = (static_cast<UnsignedInteger>(0) - 1) >> 1;
260+
UnsignedInteger absVal = val & Mask;
261+
return absVal > (ieee754::traits<AsFloat>::specialValueExp << ieee754::traits<AsFloat>::mantissaBitCnt);
262+
}
263+
264+
template<typename UnsignedInteger NBL_FUNC_REQUIRES(hlsl::is_integral_v<UnsignedInteger>&& hlsl::is_unsigned_v<UnsignedInteger>)
265+
inline bool isinf_uint_impl(UnsignedInteger val)
266+
{
267+
using AsFloat = typename float_of_size<sizeof(UnsignedInteger)>::type;
268+
return (val & (~ieee754::traits<AsFloat>::signMask)) == ieee754::traits<AsFloat>::inf;
269+
}
270+
255271
#define DECL_ARG(r,data,i,_T) BOOST_PP_COMMA_IF(BOOST_PP_NOT_EQUAL(i,0)) const _T arg##i
256272
#define WRAP(r,data,i,_T) BOOST_PP_COMMA_IF(BOOST_PP_NOT_EQUAL(i,0)) _T
257273
#define ARG(r,data,i,_T) BOOST_PP_COMMA_IF(BOOST_PP_NOT_EQUAL(i,0)) arg##i
@@ -542,15 +558,6 @@ struct refract_helper<T, U>
542558
}
543559
};
544560

545-
template<typename UnsignedInteger NBL_FUNC_REQUIRES(hlsl::is_integral_v<UnsignedInteger>&& hlsl::is_unsigned_v<UnsignedInteger>)
546-
inline bool isnan_uint_impl(UnsignedInteger val)
547-
{
548-
using AsFloat = typename float_of_size<sizeof(UnsignedInteger)>::type;
549-
constexpr UnsignedInteger Mask = ~static_cast<UnsignedInteger>(0);
550-
UnsignedInteger absVal = val & Mask;
551-
return absVal > (ieee754::traits<AsFloat>::specialValueExp << ieee754::traits<AsFloat>::mantissaBitCnt);
552-
}
553-
554561
template<typename T>
555562
requires concepts::FloatingPoint<T>
556563
struct nMin_helper<T>
@@ -841,9 +848,28 @@ struct smoothStep_helper<T NBL_PARTIAL_REQ_BOT(VECTOR_SPECIALIZATION_CONCEPT) >
841848
}
842849
};
843850

851+
template<typename T>
852+
NBL_PARTIAL_REQ_TOP(VECTOR_SPECIALIZATION_CONCEPT)
853+
struct mix_helper<T, T NBL_PARTIAL_REQ_BOT(VECTOR_SPECIALIZATION_CONCEPT) >
854+
{
855+
using return_t = T;
856+
static return_t __call(NBL_CONST_REF_ARG(T) x, NBL_CONST_REF_ARG(T) y, NBL_CONST_REF_ARG(T) a)
857+
{
858+
using traits = hlsl::vector_traits<T>;
859+
array_get<T, typename traits::scalar_type> getter;
860+
array_set<return_t, typename traits::scalar_type> setter;
861+
862+
return_t output;
863+
for (uint32_t i = 0; i < traits::Dimension; ++i)
864+
setter(output, i, mix_helper<typename traits::scalar_type, typename traits::scalar_type>::__call(getter(x, i), getter(y, i), getter(a, i)));
865+
866+
return output;
867+
}
868+
};
869+
844870
template<typename T, typename U>
845-
NBL_PARTIAL_REQ_TOP(VECTOR_SPECIALIZATION_CONCEPT && vector_traits<T>::Dimension == vector_traits<U>::Dimension)
846-
struct mix_helper<T, U NBL_PARTIAL_REQ_BOT(VECTOR_SPECIALIZATION_CONCEPT && vector_traits<T>::Dimension == vector_traits<U>::Dimension) >
871+
NBL_PARTIAL_REQ_TOP(concepts::Vectorial<T> && concepts::Boolean<U> && vector_traits<T>::Dimension == vector_traits<U>::Dimension)
872+
struct mix_helper<T, U NBL_PARTIAL_REQ_BOT(concepts::Vectorial<T> && concepts::Boolean<U> && vector_traits<T>::Dimension == vector_traits<U>::Dimension) >
847873
{
848874
using return_t = T;
849875
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/tgmath/impl.hlsl

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,6 @@ namespace hlsl
2222
namespace tgmath_impl
2323
{
2424

25-
template<typename UnsignedInteger NBL_FUNC_REQUIRES(hlsl::is_integral_v<UnsignedInteger>&& hlsl::is_unsigned_v<UnsignedInteger>)
26-
inline bool isnan_uint_impl(UnsignedInteger val)
27-
{
28-
using AsFloat = typename float_of_size<sizeof(UnsignedInteger)>::type;
29-
UnsignedInteger absVal = val & (hlsl::numeric_limits<UnsignedInteger>::max >> 1);
30-
return absVal > (ieee754::traits<AsFloat>::specialValueExp << ieee754::traits<AsFloat>::mantissaBitCnt);
31-
}
32-
33-
template<typename UnsignedInteger NBL_FUNC_REQUIRES(hlsl::is_integral_v<UnsignedInteger>&& hlsl::is_unsigned_v<UnsignedInteger>)
34-
inline bool isinf_uint_impl(UnsignedInteger val)
35-
{
36-
using AsFloat = typename float_of_size<sizeof(UnsignedInteger)>::type;
37-
return (val & (~ieee754::traits<AsFloat>::signMask)) == ieee754::traits<AsFloat>::inf;
38-
}
39-
4025
template<typename T NBL_STRUCT_CONSTRAINABLE>
4126
struct erf_helper;
4227
template<typename T NBL_STRUCT_CONSTRAINABLE>
@@ -175,12 +160,8 @@ struct modf_helper<T NBL_PARTIAL_REQ_BOT(concepts::FloatingPointScalar<T>) >
175160
using return_t = T;
176161
static inline return_t __call(const T x)
177162
{
178-
T tmp = abs_helper<T>::__call(x);
179-
tmp = spirv::fract<T>(tmp);
180-
if (x < 0)
181-
tmp *= -1;
182-
183-
return tmp;
163+
ModfOutput<T> output = modfStruct_helper<T>::__call(x);
164+
return output.fractionalPart;
184165
}
185166
};
186167

@@ -307,7 +288,7 @@ struct isinf_helper<T>
307288
// GCC and Clang will always return false with call to std::isinf when fast math is enabled,
308289
// this implementation will always return appropriate output regardless is fast math is enabled or not
309290
using AsUint = typename unsigned_integer_of_size<sizeof(T)>::type;
310-
return tgmath_impl::isinf_uint_impl(reinterpret_cast<const AsUint&>(arg));
291+
return cpp_compat_intrinsics_impl::isinf_uint_impl(reinterpret_cast<const AsUint&>(arg));
311292
}
312293
};
313294

@@ -321,7 +302,7 @@ struct isnan_helper<T>
321302
// GCC and Clang will always return false with call to std::isnan when fast math is enabled,
322303
// this implementation will always return appropriate output regardless is fast math is enabled or not
323304
using AsUint = typename unsigned_integer_of_size<sizeof(T)>::type;
324-
return tgmath_impl::isnan_uint_impl(reinterpret_cast<const AsUint&>(arg));
305+
return cpp_compat_intrinsics_impl::isnan_uint_impl(reinterpret_cast<const AsUint&>(arg));
325306
}
326307
};
327308

0 commit comments

Comments
 (0)