DirectXTex: Updated to use DirectXMath 3.06 when available

This commit is contained in:
walbourn_cp 2013-09-09 12:45:36 -07:00
parent c9f5fdb7a8
commit 7523b2bb9b

View File

@ -23,6 +23,7 @@
using namespace DirectX::PackedVector; using namespace DirectX::PackedVector;
#endif #endif
#if DIRECTX_MATH_VERSION < 306
namespace namespace
{ {
inline float round_to_nearest( float x ) inline float round_to_nearest( float x )
@ -45,6 +46,7 @@ namespace
return i + 1.f; return i + 1.f;
} }
}; };
#endif
namespace DirectX namespace DirectX
{ {
@ -664,6 +666,9 @@ bool _LoadScanline( XMVECTOR* pDestination, size_t count,
LOAD_SCANLINE( XMUDECN4, XMLoadUDecN4 ); LOAD_SCANLINE( XMUDECN4, XMLoadUDecN4 );
case DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM: case DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM:
#if DIRECTX_MATH_VERSION >= 306
LOAD_SCANLINE( XMUDECN4, XMLoadUDecN4_XR );
#else
if ( size >= sizeof(XMUDECN4) ) if ( size >= sizeof(XMUDECN4) )
{ {
const XMUDECN4 * __restrict sPtr = reinterpret_cast<const XMUDECN4*>(pSource); const XMUDECN4 * __restrict sPtr = reinterpret_cast<const XMUDECN4*>(pSource);
@ -689,6 +694,7 @@ bool _LoadScanline( XMVECTOR* pDestination, size_t count,
return true; return true;
} }
return false; return false;
#endif
case DXGI_FORMAT_R10G10B10A2_UINT: case DXGI_FORMAT_R10G10B10A2_UINT:
LOAD_SCANLINE( XMUDEC4, XMLoadUDec4 ); LOAD_SCANLINE( XMUDEC4, XMLoadUDec4 );
@ -977,6 +983,9 @@ bool _LoadScanline( XMVECTOR* pDestination, size_t count,
return false; return false;
case DXGI_FORMAT_R9G9B9E5_SHAREDEXP: case DXGI_FORMAT_R9G9B9E5_SHAREDEXP:
#if DIRECTX_MATH_VERSION >= 306
LOAD_SCANLINE3( XMFLOAT3SE, XMLoadFloat3SE, g_XMIdentityR3 )
#else
if ( size >= sizeof(XMFLOAT3SE) ) if ( size >= sizeof(XMFLOAT3SE) )
{ {
const XMFLOAT3SE * __restrict sPtr = reinterpret_cast<const XMFLOAT3SE*>(pSource); const XMFLOAT3SE * __restrict sPtr = reinterpret_cast<const XMFLOAT3SE*>(pSource);
@ -998,6 +1007,7 @@ bool _LoadScanline( XMVECTOR* pDestination, size_t count,
return true; return true;
} }
return false; return false;
#endif
case DXGI_FORMAT_R8G8_B8G8_UNORM: case DXGI_FORMAT_R8G8_B8G8_UNORM:
if ( size >= sizeof(XMUBYTEN4) ) if ( size >= sizeof(XMUBYTEN4) )
@ -1228,6 +1238,9 @@ bool _StoreScanline( LPVOID pDestination, size_t size, DXGI_FORMAT format,
STORE_SCANLINE( XMUDECN4, XMStoreUDecN4 ); STORE_SCANLINE( XMUDECN4, XMStoreUDecN4 );
case DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM: case DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM:
#if DIRECTX_MATH_VERSION >= 306
STORE_SCANLINE( XMUDECN4, XMStoreUDecN4_XR );
#else
if ( size >= sizeof(XMUDECN4) ) if ( size >= sizeof(XMUDECN4) )
{ {
static const XMVECTORF32 Scale = { 510.0f, 510.0f, 510.0f, 3.0f }; static const XMVECTORF32 Scale = { 510.0f, 510.0f, 510.0f, 3.0f };
@ -1254,6 +1267,7 @@ bool _StoreScanline( LPVOID pDestination, size_t size, DXGI_FORMAT format,
return true; return true;
} }
return false; return false;
#endif
case DXGI_FORMAT_R10G10B10A2_UINT: case DXGI_FORMAT_R10G10B10A2_UINT:
STORE_SCANLINE( XMUDEC4, XMStoreUDec4 ); STORE_SCANLINE( XMUDEC4, XMStoreUDec4 );
@ -1536,6 +1550,9 @@ bool _StoreScanline( LPVOID pDestination, size_t size, DXGI_FORMAT format,
return false; return false;
case DXGI_FORMAT_R9G9B9E5_SHAREDEXP: case DXGI_FORMAT_R9G9B9E5_SHAREDEXP:
#if DIRECTX_MATH_VERSION >= 306
STORE_SCANLINE( XMFLOAT3SE, XMStoreFloat3SE )
#else
if ( size >= sizeof(XMFLOAT3SE) ) if ( size >= sizeof(XMFLOAT3SE) )
{ {
static const float maxf9 = float(0x1FF << 7); static const float maxf9 = float(0x1FF << 7);
@ -1575,6 +1592,7 @@ bool _StoreScanline( LPVOID pDestination, size_t size, DXGI_FORMAT format,
return true; return true;
} }
return false; return false;
#endif
case DXGI_FORMAT_R8G8_B8G8_UNORM: case DXGI_FORMAT_R8G8_B8G8_UNORM:
if ( size >= sizeof(XMUBYTEN4) ) if ( size >= sizeof(XMUBYTEN4) )
@ -1873,7 +1891,8 @@ HRESULT _ConvertFromR32G32B32A32( const Image* srcImages, size_t nimages, const
// if C_linear > 0.0031308 -> C_srgb = ( 1 + a ) * pow( C_Linear, 1 / 2.4 ) - a // if C_linear > 0.0031308 -> C_srgb = ( 1 + a ) * pow( C_Linear, 1 / 2.4 ) - a
// where a = 0.055 // where a = 0.055
//------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------
static inline XMVECTOR RGBToSRGB( FXMVECTOR rgb ) #if DIRECTX_MATH_VERSION < 306
static inline XMVECTOR XMColorRGBToSRGB( FXMVECTOR rgb )
{ {
static const XMVECTORF32 Cutoff = { 0.0031308f, 0.0031308f, 0.0031308f, 1.f }; static const XMVECTORF32 Cutoff = { 0.0031308f, 0.0031308f, 0.0031308f, 1.f };
static const XMVECTORF32 Linear = { 12.92f, 12.92f, 12.92f, 1.f }; static const XMVECTORF32 Linear = { 12.92f, 12.92f, 12.92f, 1.f };
@ -1888,6 +1907,7 @@ static inline XMVECTOR RGBToSRGB( FXMVECTOR rgb )
V = XMVectorSelect( V1, V0, select ); V = XMVectorSelect( V1, V0, select );
return XMVectorSelect( rgb, V, g_XMSelect1110 ); return XMVectorSelect( rgb, V, g_XMSelect1110 );
} }
#endif
_Use_decl_annotations_ _Use_decl_annotations_
bool _StoreScanlineLinear( LPVOID pDestination, size_t size, DXGI_FORMAT format, bool _StoreScanlineLinear( LPVOID pDestination, size_t size, DXGI_FORMAT format,
@ -1934,7 +1954,7 @@ bool _StoreScanlineLinear( LPVOID pDestination, size_t size, DXGI_FORMAT format,
default: default:
// can't treat A8, XR, Depth, SNORM, UINT, or SINT as sRGB // can't treat A8, XR, Depth, SNORM, UINT, or SINT as sRGB
flags &= ~TEX_FILTER_SRGB; flags &= ~TEX_FILTER_SRGB;
break; break;
} }
@ -1946,7 +1966,7 @@ bool _StoreScanlineLinear( LPVOID pDestination, size_t size, DXGI_FORMAT format,
XMVECTOR* ptr = pSource; XMVECTOR* ptr = pSource;
for( size_t i=0; i < count; ++i, ++ptr ) for( size_t i=0; i < count; ++i, ++ptr )
{ {
*ptr = RGBToSRGB( *ptr ); *ptr = XMColorRGBToSRGB( *ptr );
} }
} }
@ -1961,7 +1981,8 @@ bool _StoreScanlineLinear( LPVOID pDestination, size_t size, DXGI_FORMAT format,
// if C_srgb > 0.04045 -> C_linear = pow( ( C_srgb + a ) / ( 1 + a ), 2.4 ) // if C_srgb > 0.04045 -> C_linear = pow( ( C_srgb + a ) / ( 1 + a ), 2.4 )
// where a = 0.055 // where a = 0.055
//------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------
static inline XMVECTOR SRGBToRGB( FXMVECTOR srgb ) #if DIRECTX_MATH_VERSION < 306
static inline XMVECTOR XMColorSRGBToRGB( FXMVECTOR srgb )
{ {
static const XMVECTORF32 Cutoff = { 0.04045f, 0.04045f, 0.04045f, 1.f }; static const XMVECTORF32 Cutoff = { 0.04045f, 0.04045f, 0.04045f, 1.f };
static const XMVECTORF32 ILinear = { 1.f/12.92f, 1.f/12.92f, 1.f/12.92f, 1.f }; static const XMVECTORF32 ILinear = { 1.f/12.92f, 1.f/12.92f, 1.f/12.92f, 1.f };
@ -1976,6 +1997,7 @@ static inline XMVECTOR SRGBToRGB( FXMVECTOR srgb )
V = XMVectorSelect( V0, V1, select ); V = XMVectorSelect( V0, V1, select );
return XMVectorSelect( srgb, V, g_XMSelect1110 ); return XMVectorSelect( srgb, V, g_XMSelect1110 );
} }
#endif
_Use_decl_annotations_ _Use_decl_annotations_
bool _LoadScanlineLinear( XMVECTOR* pDestination, size_t count, bool _LoadScanlineLinear( XMVECTOR* pDestination, size_t count,
@ -2034,7 +2056,7 @@ bool _LoadScanlineLinear( XMVECTOR* pDestination, size_t count,
XMVECTOR* ptr = pDestination; XMVECTOR* ptr = pDestination;
for( size_t i=0; i < count; ++i, ++ptr ) for( size_t i=0; i < count; ++i, ++ptr )
{ {
*ptr = SRGBToRGB( *ptr ); *ptr = XMColorSRGBToRGB( *ptr );
} }
} }
@ -2251,7 +2273,7 @@ void _ConvertScanline( XMVECTOR* pBuffer, size_t count, DXGI_FORMAT outFormat, D
XMVECTOR* ptr = pBuffer; XMVECTOR* ptr = pBuffer;
for( size_t i=0; i < count; ++i, ++ptr ) for( size_t i=0; i < count; ++i, ++ptr )
{ {
*ptr = SRGBToRGB( *ptr ); *ptr = XMColorSRGBToRGB( *ptr );
} }
} }
} }
@ -2451,7 +2473,7 @@ void _ConvertScanline( XMVECTOR* pBuffer, size_t count, DXGI_FORMAT outFormat, D
XMVECTOR* ptr = pBuffer; XMVECTOR* ptr = pBuffer;
for( size_t i=0; i < count; ++i, ++ptr ) for( size_t i=0; i < count; ++i, ++ptr )
{ {
*ptr = RGBToSRGB( *ptr ); *ptr = XMColorRGBToSRGB( *ptr );
} }
} }
} }