Skip to content

Commit 3ec077f

Browse files
committed
Safer handling of NaNs in vector case (don't assume XMVectorClamp will return NaN if given a NaN)
1 parent ab4e114 commit 3ec077f

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

DirectXTex/DirectXTexConvert.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,12 +195,15 @@ namespace
195195

196196
inline void SanitizeFloat16(XMVECTOR& v, DWORD flags)
197197
{
198-
// Convert NaNs to 0.0f
199-
if (!(flags & TEX_FILTER_FLOAT_KEEP_NANS))
200-
v = XMVectorSelect(XMVectorZero(), v, XMVectorIsNaN(v));
198+
XMVECTOR isNaN = XMVectorIsNaN(v);
201199

202200
if (!(flags & TEX_FILTER_FLOAT_SATURATE_TO_INF))
203201
v = XMVectorClamp(v, g_HalfMin, g_HalfMax);
202+
203+
if (flags & TEX_FILTER_FLOAT_KEEP_NANS)
204+
v = XMVectorSelect(XMVectorSplatQNaN(), v, isNaN);
205+
else
206+
v = XMVectorSelect(XMVectorZero(), v, isNaN);
204207
}
205208

206209
inline void SanitizeFloat16(float& v, DWORD flags)

0 commit comments

Comments
 (0)