Skip to content

Commit a640976

Browse files
committed
Moved flipSign function to ieee754.hlsl
1 parent 147c080 commit a640976

File tree

4 files changed

+10
-45
lines changed

4 files changed

+10
-45
lines changed

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

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -360,41 +360,6 @@ struct mul_helper
360360
}
361361
};
362362

363-
template<typename T NBL_STRUCT_CONSTRAINABLE>
364-
struct negate_helper;
365-
366-
template<typename FloatingPoint>
367-
NBL_PARTIAL_REQ_TOP(hlsl::is_floating_point_v<FloatingPoint> && hlsl::is_scalar_v<FloatingPoint>)
368-
struct negate_helper<FloatingPoint NBL_PARTIAL_REQ_BOT(hlsl::is_floating_point_v<FloatingPoint> && hlsl::is_scalar_v<FloatingPoint>) >
369-
{
370-
static inline FloatingPoint __call(NBL_CONST_REF_ARG(FloatingPoint) val)
371-
{
372-
#ifdef __HLSL_VERSION
373-
return spirv::fNegate(val);
374-
#else
375-
return -val;
376-
#endif
377-
}
378-
};
379-
380-
template<typename Vector>
381-
NBL_PARTIAL_REQ_TOP(hlsl::is_vector_v<Vector>)
382-
struct negate_helper<Vector NBL_PARTIAL_REQ_BOT(hlsl::is_floating_point_v<Vector> && hlsl::is_vector_v<Vector>) >
383-
{
384-
static Vector __call(NBL_CONST_REF_ARG(Vector) vec)
385-
{
386-
#ifdef __HLSL_VERSION
387-
return spirv::fNegate(vec);
388-
#else
389-
Vector output;
390-
using traits = hlsl::vector_traits<Vector>;
391-
for (uint32_t i = 0; i < traits::Dimension; ++i)
392-
output[i] = negate_helper<traits::scalar_type >::__call(vec[i]);
393-
return output;
394-
#endif
395-
}
396-
};
397-
398363
}
399364
}
400365
}

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,6 @@ inline Integer bitReverse(Integer val)
152152
return cpp_compat_intrinsics_impl::bitReverse_helper<Integer>::__call(val);
153153
}
154154

155-
template<typename FloatingPoint>
156-
inline FloatingPoint negate(FloatingPoint val)
157-
{
158-
return cpp_compat_intrinsics_impl::negate_helper<FloatingPoint>::__call(val);
159-
}
160-
161155
}
162156
}
163157

include/nbl/builtin/hlsl/ieee754.hlsl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,16 @@ NBL_CONSTEXPR_INLINE_FUNC FloatingPoint copySign(FloatingPoint to, FloatingPoint
141141
return bit_cast<FloatingPoint>(toAsUint | extractSignPreserveBitPattern(from));
142142
}
143143

144+
template <typename FloatingPoint NBL_FUNC_REQUIRES(hlsl::is_floating_point_v<FloatingPoint>&& hlsl::is_scalar_v<FloatingPoint>)
145+
NBL_CONSTEXPR_INLINE_FUNC FloatingPoint flipSign(FloatingPoint val)
146+
{
147+
using AsFloat = typename float_of_size<sizeof(FloatingPoint)>::type;
148+
using AsUint = typename unsigned_integer_of_size<sizeof(FloatingPoint)>::type;
149+
const AsUint asUint = ieee754::impl::bitCastToUintType(val);
150+
151+
return bit_cast<FloatingPoint>(asUint ^ ieee754::traits<AsFloat>::signMask);
152+
}
153+
144154
}
145155
}
146156
}

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,6 @@ template<typename Matrix>
246246
[[vk::ext_instruction( spv::OpTranspose )]]
247247
Matrix transpose(Matrix mat);
248248

249-
template<typename FloatingPoint>
250-
[[vk::ext_instruction(spv::OpFNegate)]]
251-
enable_if_t<is_floating_point_v<FloatingPoint>, FloatingPoint> fNegate(FloatingPoint mat);
252-
253249
}
254250

255251
#endif

0 commit comments

Comments
 (0)