Skip to content
Chuck Walbourn edited this page Aug 3, 2020 · 66 revisions

http://go.microsoft.com/fwlink/?LinkID=615560

GitHub Release Date Nuget GitHub (Pre-)Release Date

GitHub last commit Azure DevOps test suite build

DirectX LogoDirectXMath is an all inline SIMD C++ linear algebra library for use in games and graphics apps.

See this post.

Documentation

The DirectXMath library is documented here.

Windows SDK

The DirectXMath library is included in the Windows SDK starting with version 8.0. Therefore it is included with Visual C++ 2012, 2013, 2015, 2017, and 2019. For a full list versions, see releases.

NuGet

DirectXMath is also available on NuGet.

Instruction set

For x86/x64, DirectXMath makes use of SSE/SSE2 intrinsics. All x64 native CPUs are required to support SSE and SSE2. Windows 8.0 (32-bit) or later will not install without SSE/SSE2 support.

For ARM, DirectXMath makes use of ARMv7 ARM-NEON intrinsics. All Windows on ARM devices support ARM-NEON and VFPv3.

For ARM64, DirectXMath makes use of ARMv8 ARM-NEON intrinsics. ARM-NEON and VFPv4 support is required for the ARM 64 architecture.

See this post for full details.

Using _XM_NO_INTRINSICS_ results in only C/C++ codepaths which should work on any architecture, but the library is not optimized for this case.

Architecture switch

If you build with /arch:AVX (-mavx or -mf16c on clang/LLVM) such that your binary requires Intel Advanced Vector Extensions, DirectXMath 3.09 or later will make use of SSE3, SSE4.1, and AVX instructions.

The primary benefit of building with /arch:AVX is the use of the VEX prefix in all generated SSE instructions.

If you build with /arch:AVX2 (-mavx2 on clang/LLVM) such that your binary requires Intel Advanced Vector Extensions 2, DirectXMath 3.09 or later will make use of SSE3, SSE4.1, AVX, and F16C instructions.

The compiler should make use of FMA3 as appropriate when building with /arch:AVX2 even without explicit use of the _mm_f*add_ps intrinsic. In DirectXMath 3.10 or later, XMVerifyCPUSupport will check for AVX2 and FMA3 instruction support when building with /arch:AVX2.

Windows XP

The DirectXMath library is all inline and uses only Visual C++ intrinsics. Therefore, it is compatible with all version of Windows supported by Visual C++. There's no standard configuration that will put DirectXMath in the include path when using the v1x0_xp Platform Toolset, but you can add it manually or make use of the NuGet package. Keep in mind there are a number of other differences when doing DirectX development for Windows XP support. See this post.

Migrating code

Details on moving from XNAMath to DirectXMath are covered in Code Migration from the XNA Math Library.

Moving from the legacy D3DX9/D3DX10 D3DXMath is covered in Working with D3DXMath.

Calling convention

Be sure to read the Microsoft Docs details on the calling convention types which are designed to deal with the various architectures and vector calling conventions. The best way to ensure you have them correct is to attempt to build your code with x86, x64, and ARM.

Language extensions

DirectXMath is written using standard Intel-style intrinsics, which should be portable to other compilers. The ARM and ARM64 codepaths use ARM-style intrinsics (earlier versions of the library used Visual C++ specific __n64 and __n128), so these are also portable.

The DirectXMath library make use of two commonly implemented extensions to Standard C++:

  • anonymous structs, which are widely supported and are part of the C11 standard. Note that the library also uses anonymous unions, but these are part of the C++ and C99 standard.
  • #pragma once rather than old-style #define based guards, but are widely supported

Because of these, DirectXMath is not compatible with Visual C++'s /Za switch which enforces ISO C89 / C++11. It does work with /permissive-.

Compiler support

In addition to Microsoft Visual C++, the library has been compiled with the Intel C++ 18.0 compiler and clang/LLVM v9 to verify conformance. It should also work with GCC and MinGW.

When building with clang/LLVM or other GNU C compilers, the _XM_NO_XMVECTOR_OVERLOADS_ control define is set because these compilers do not support creating operator overloads for the XMVECTOR type. You can choose to enable this preprocessor define explicitly to do the same thing with Visual C++ for improved portability.

For non-Windows platforms, you should use the open source version of sal.h in your include search path.

Additional content

Extensions - Advanced instruction set variants for DirectXMath
SHMath - Spherical Harmonics math
XDSP - Digital Signal Processing helper functions
Stereo3D - Stereo 3D matrix helper functions

Resources

Related

See the DirectX Tool Kit's SimpleMath wrapper for DirectXMath.

Credits

The xboxmath library was originated by Matt Bronder with contributions from Sakphong Chanbai and David Hefner for the Xbox 360.

The xnamath library for the DirectX SDK and Xbox XDK was the work of Chuck Walbourn and Becky Heineman based on xboxmath, with contributions from Jeremy Gup, Dan Haffner, Matt Lee, Casey Meekhof, Rich Sauer, Jason Strayer, and Xiaoyue Zheng.

The DirectXMath library for the Windows SDK and Xbox One XDK is the work of Chuck Walbourn based on xnamath, with contributions from Darren Anderson, Matt Lee, Aaron Rodriguez Hernandez, Yuichi Ito, Reza Nourai, Rich Sauer, and Jason Strayer.

Thanks to Dave Eberly for his contributions particularly in improving the transcendental functions.

Thanks to Bruce Dawson for his help with the rounding functions.

Thanks to Andrew Farrier for the fixes to XMVerifyCPUSupport to properly support clang.

Thanks to Scott Matloff for his help in getting the library updated to use Intel SVML for VS 2019.

Special thanks to Andy Glaister and Shawn Hargreaves for their on-going support and sponsorship.

For Use

  • Universal Windows Platform apps
  • Windows desktop apps
  • Windows 10
  • Windows 8.1
  • Windows 7 Service Pack 1
  • Xbox One
  • Xbox Series S/X

For Development

  • Visual Studio 2019
  • Visual Studio 2017

Related Projects

DirectX Tool Kit for DirectX 11

DirectX Tool Kit for DirectX 12

DirectXMesh

DirectXTex

Tools

Test Suite

Clone this wiki locally
You can’t perform that action at this time.