Giter Site home page Giter Site logo

microsoft / directxmath Goto Github PK

View Code? Open in Web Editor NEW
1.5K 96.0 226.0 2.23 MB

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

Home Page: https://walbourn.github.io/introducing-directxmath/

License: MIT License

C++ 99.73% CMake 0.27%
microsoft directx simd neon cpp-library sse avx avx2 clang msvc

directxmath's Introduction

DirectX Logo

DirectXMath

https://github.com/Microsoft/DirectXMath

Copyright (c) Microsoft Corporation.

February 2024

This package contains the DirectXMath library, an all inline SIMD C++ linear algebra library for use in games and graphics apps.

This code is designed to build with Visual Studio 2019 (16.11), Visual Studio 2022, or clang/LLVM for Windows. It is recommended that you make use of the latest updates.

These components are designed to work without requiring any content from the legacy DirectX SDK. For details, see Where is the DirectX SDK?.

Directory Layout

  • Inc\

    • DirectXMath Files (in the DirectX C++ namespace)

      • DirectXMath.h - Core library
      • DirectXPackedVector.h - Load/Store functions and types for working with various compressed GPU formats
      • DirectXColors.h - .NET-style Color defines in sRGB and linear color space
      • DirectXCollision.h - Bounding volume collision library
  • Extentions\

    • Advanced instruction set variants for guarded codepaths

      • DirectXMathSSE3.h - SSE3
      • DirectXMathBE.h - Supplemental SSE3 (SSSE3)
      • DirectXMathSSE4.h - SSE4.1
      • DirectXMathAVX.h - Advanced Vector Extensions (AVX)
      • DirectXMathAVX2.h - Advanced Vector Extensions 2 (AVX2)
      • DirectXMathF16C.h - Half-precision conversions (F16C)
      • DirectXMathFMA3.h - Fused multiply-accumulate (FMA3)
      • DirectXMathFMA4.h - Fused multiply-accumulate (FMA4)
  • SHMath\

    • Spherical Harmonics math functions

      • DirectXSH.h - Header for SHMath functions
      • DirectXSH.cpp, DirectXSHD3D11.cpp, DirectXSHD3D12.cpp - Implementation
  • XDSP\

    • XDSP.h - Digital Signal Processing helper functions
  • build\

    • Contains YAML files for the build pipelines along with some miscellaneous build files and scripts.

Documentation

Documentation is available on the Microsoft Docs. Additional information can be found on the project wiki.

Compiler support

Officially the library is supported with Microsoft Visual C++ 2019 or later, clang/LLVM v12 or later, and GCC 9 or later. It should also compile with the Intel C++ and MinGW compilers.

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.

To build for non-Windows platforms, you need to provide a sal.h header in your include path. You can obtain an open source version from GitHub.

With GCC, the SAL annotation preprocessor symbols can conflict with the GNU implementation of the Standard C++ Library. The workaround is to include the system headers before including DirectXMath:

#include <algorithm>
#include <utility>

#include <DirectXMath.h>

Notices

All content and source code for this package are subject to the terms of the MIT License.

For the latest version of DirectXMath, bug reports, etc. please visit the project site on GitHub.

Release Notes

  • The clang/LLVM toolset currently does not respect the float_control pragma for SSE instrinsics. Therefore, the use of /fp:fast is not recommended on clang/LLVM until this issue is fixed. See 55713.

Support

For questions, consider using Stack Overflow with the directxmath tag, or the DirectX Discord Server in the dx12-developers or dx9-dx11-developers channel.

For bug reports and feature requests, please use GitHub issues for this project.

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

Code of Conduct

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

Trademarks

This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow Microsoft's Trademark & Brand Guidelines. Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party's policies.

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.

directxmath's People

Contributors

danielkrupinski avatar ianier avatar jpetermugaas avatar msftgits avatar nfrechette avatar nirbheek avatar sbd1138 avatar shinjich avatar walbourn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

directxmath's Issues

constexpr usage fails to build with VS 2015 RTM

Due to a compiler bug, trying to build DirectXMath 3.09 with VS 2015 RTM results in compiler bugs. This is fixed in Update 1 or later. A simple workaround is to treat VS 2015 RTM like VS 2013 and avoid use of constexpr.

Improve FFTUnswizzle performance

Edit: I'm completely rewriting my entry

Using the FFT in XDSP.h I'm implementing a transform routine for pure real sequences equivalent to the function ippsFFTFwd_RToCCS_32f in the Intel IPP. The idea is to use an N/2 complex FFT as described in the literature.

In order to improve the performance of my routine I would like to unswizzle the frequency domain values in place. For even powers of two a swap reordering will do (i.e. the usual radix-4 digit reversal). For odd powers of two, though, FFTUnswizzle keeps the three most significant bits of the index together, like this: 011 10 11 01 -> 01 11 10 011 , which makes implementing in place reordering a bit more challenging.

Has anyone looked into this already?

Remove 17.1 compiler support

When the Xbox One XDK platform drops support for the 17.1 compiler, I can remove one remaining adapter:

  • Remove XM_CTOR_DEFAULT adapter and replace it with =default
  • The XMMatrixMultiply and XMMatrixMultiplyTranspose implementation also have a workaround for compilers prior to VS 2013

Revisit XMLoad/StoreFloat3PK

The XMLoadFloat3PK and XMStoreFloat3PK functions are both all scalar. They could benefit from SIMD optimization.

This format matches DXGI_FORMAT_R11G11B10_FLOAT

AVX2 optimization

For the most part, the AVX2 optimizations are already covered by AVX, F16C, and FMA3. There is one case we can use a new AVX2 instruction:

inline XMVECTOR XM_CALLCONV XMVectorSplatX( FXMVECTOR V )
{
    return _mm_broadcastss_ps( V );
}

See this blog post for more information on AVX2.

Provide linear color space color constants

The current DirectX::Colors colors are all .net constant values which are in the sRGB color space. For gamma-correct rendering, you have to convert them at runtime to linear colors perhaps via XMColorSRGBToRGB.

Ideally the library would provide a DirectX::ColorsLinear namespace with the colors defined in linear color space which are also essential for HDR rendering.

Support __vectorcall when supported

The x86 and x64 compiler in VS 2013 (and 17.1) supports a new calling convention __vectorcall which improves SIMD parameter passing when inlining is not possible.

Support Clang - Compiler

Hello DirectXMath-Team,

I tried to use DirectXMath in a project of mine. Sadly the clang compiler has a different interpretation of the __m128 type. Is there a way, or could you please make a way, that the clang compiler will be happy with DirectXMath? The appearing error is of the following type:

C:\Program Files (x86)\Windows Kits\8.1\Include\um\DirectXMath.h(355,29): error : overloaded 'operator+' must have at least one parameter of class or enumeration type
1> XMVECTOR XM_CALLCONV operator+ (FXMVECTOR V);

Thank you and kind regards
LepelTsmok

Stream functions should be optimized for SSE/ARM-NEON

The existing Stream implementations in DirectXMath for SSE/SSE2 are basic loops that use the non-stream version.

XMVector2TransformStream
XMVector2TransformCoordStream
XMVector2TransformNormalStream
XMVector3TransformStream
XMVector3TransformCoordStream
XMVector3TransformNormalStream
XMVector3ProjectStream
XMVector3UnprojectStream
XMVector4TransformStream
XMPlaneTransformStream

Use SSE3, SSE4, AVX with /arch:AVX switch, F16C with /arch:AVX2

For the x86 and x64 platforms, DirectXMath only uses SSE/SSE2 by default.

If building with /arch:AVX, the library can also make use of

  • SSE3: _mm_moveldup_ps, _mm_movehdup_ps
  • SSE4: _mm_round_ps, _mm_floor_ps, _mm_ceil_ps, _mm_blend_ps, _mm_dp_ps, _mm_extract_ps, _mm_insert_ps
  • AVX: _mm_permute_ps, _mm_permutevar_ps, _mm_broadcast_ss

If building with /arch:AVX2, the library can also make use of:

  • F16C: _mm_cvtph_ps, _mm_cvtph_ps

Clang __m128 won't work with DirectXMath

In a few places in the DirectXMath library, individual vector element access is done by V.m128_f32[i] / V.n128_u32[i] and V.m128_u32[i] / V.n128_u32[i] which lets the compiler do the 'spill' to memory automatically. Clang doesn't support this MSVC/Intel compiler-specific behavior in how __m128 is defined so won't build.

This impacts the following functions:

  • XMVectorGetByIndex

  • XMVectorGetByIndexPtr

  • XMVectorGetIntByIndex

  • XMVectorGetIntByIndexPtr

  • XMVectorSetByIndex

  • XMVectorSetByIndexPtr

  • XMVectorSetIntByIndex

Add conversion types for 16-bit color formats

The original xboxmath library did not support 16-byte color formats (5:6:5, 5:5:5:1, or 4:4:4:4). These should be supported for Direct3D 9 formats D3DFMT_R5G6B5, D3DFMT_X1R5G5B5, D3DFMT_A1R5G5B5, D3DFMT_A4R4G4B4.

Revisit XMVectorPow

Both the ARM-NEON and SSE implementation of XMVectorPow just invoke the standard scalar powf method. It should be optimized at some point.

FFT vmulComplex optimization using multiply-add/subtract

The vmulComplex functions in XDSP.h could be further optimized like this:

// (r1, i1) * (r2, i2) = (r1r2 - i1i2, r1i2 + r2i1)
XMVECTOR vr1r2 = XMVectorMultiply(r1, r2);
XMVECTOR vr1i2 = XMVectorMultiply(r1, i2);
rResult = XMVectorNegativeMultiplySubtract(i1, i2, vr1r2); // real: (r1r2 - i1i2)
iResult = XMVectorMultiplyAdd(r2, i1, vr1i2); // imaginary: (r1i2 + r2i1)

On SSE2 it makes no difference, but when compiling for ARM it does.

Add XMVectorRound half away from zero alternative

The current XMVectorRound uses round-to-nearest (even) a.k.a. banker's rounding. This matches the implementation of the _mm_round_ps (SSE4) and vrndnq_f32 (ARMv8 NEON) intrinsics rounding behavior, so it can be implemented in a single instruction.

Many users, however, expect it to match roundf which C99 defines as handling half-way values by rounding away from zero a.k.a. commercial rounding. It might therefore be useful to provide an alternative version of XMVectorRound that supports half away-from-zero rounding instead of round-to-nearest (even).

See Wikipedia

XMMatrixPerspectiveFovLH AspectHByW

I think the AspectHByW parameter of XMMatrixPerspectiveFovLH should be AspectWByH.

If you look at the math to compute m[0][0] and m[1][1] inside XMMatrixPerspectiveFovLH, you'll see that it's identical to the math used in gluPerspective. However, gluPerspective's aspect parameter is width/height.

How could gluPerspective and XMMatrixPerspectiveFovLH use the same math, but have a different meaning? Futhermore, the results in my app look wrong when I pass height/width, but look correct when I pass width/height.

Rec. 2020 Color Conversions

The DirectXMath library includes a number of colorspace conversion functions for sRGB, Linear RGB, HSL, HSV, XYZ, YUV, and YUV_HD color spaces.

For HDR tooling, it should also have Rec. 2020 color conversions defined for UHDTV,

  • XMColorRGBToYUV_UHD
  • XMColorYUVToRGB_UHD

Revisit XMLoad/StoreFloat3SE

The XMLoadFloat3SE and XMStoreFloat3SE functions are both all scalar. They could benefit from SIMD optimization.

Note this matches DXGI_FORMAT_R9G9B9E5_SHAREDEXP

Make use of additional ARMv8 intrinsics

The Windows ARM 32-bit platform requires ARMv7, while the Windows ARM 64-bit platform requires ARMv8. Therefore, DirectXMath can make use of additional ARMv8 ARM-NEON intrinsics for dividing, rounding, and half-precision conversion on the ARM64 platform:

vrndnq_f32
vrndq_f32
vrndmq_f32
vrndpq_f32
vcvt_f32_f16
vcvt_f16_f32
vdivq_f32 

Remove old VS 2010/2012 support adapters

Future versions of DirectXMath are likely to only support VS 2013 and VS 2015. Therefore, I can remove a number of things that are present for older compilers:

Remove the #ifdef guard from #pragma once

Simplify this expression

#if ((_MSC_FULL_VER >= 170065501) && (_MSC_VER < 1800)) || (_MSC_FULL_VER >= 180020418)
#define _XM_VECTORCALL_ 1
#endif

Remove XM_CTOR_DEFAULT adapter and replace it with =default

Remove XM_VMULQ_N_F32, XM_VMLAQ_N_F32, XM_VMULQ_LANE_F32, XM_VMLAQ_LANE_F32 adapters and replace it with vmulq_n_f32, vmlaq_n_f32, vmulq_lane_f32, vmlaq_lane_f32

Warnings when using /Za

DirectXMath.h header does not compile with /Za (disable language extensions).

1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.10586.0\um\DirectXMath.h(630): error C2467: illegal declaration of anonymous 'struct'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.10586.0\um\DirectXMath.h(658): error C2467: illegal declaration of anonymous 'struct'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.10586.0\um\DirectXMath.h(705): error C2467: illegal declaration of anonymous 'struct'

FMA3 optimization

While extensive use of FMA3 isn't likely warranted (and the MSVC compiler should already be emitting it where it is useful automatically when building with /arch:AVX2), we can add explicit use of FMA3 instructions in two places:

inline XMVECTOR XMVectorMultiplyAdd(FXMVECTOR V1, FXMVECTOR V2, FXMVECTOR V3)
{
    return _mm_fmadd_ps( V1, V2, V3 );
}

inline XMVECTOR XM_CALLCONV XMVectorNegativeMultiplySubtract(
    FXMVECTOR V1, FXMVECTOR V2, FXMVECTOR V3)
{
    return _mm_fnmadd_ps( V1, V2, V3 );
}

See this blog post for more information on FMA3.

Add XMQuaternionRotationToEuler / XMMatrixRotationToEuler

DirectXMath provides a function for converting from a quaternion to a axis/angle, but does not have a method for going from a quaternion back to Euler angles: XMQuaternionToRollPitchYaw

Also could use a rotation matrix to Euler angles that's simplier than the full XMMatrixDecompose: XMMatrixToRollPitchYaw

Add XMMatrixInverseTranspose

The DirectXMath library includes both a XMMatrixTranspose and a XMMatrixInverse, but doing both at once could be made more efficient by omitting the initial transpose.

BoundingFrustum needs support for RH coordinates

Hi,

My application uses Right-Handed coordinates system.
All was fine until I came across the BoundindFrustum interface in Directx Math Collision : BoundingFrustum interface

Frustum culling does not work as intended if I use my View, Projection, Right-Handed matrices.

All is working fine if I compute extra Left-Handed matrices for frustum culling (see code below) :

ProjectionMatrixLH = XMMatrixPerspectiveFovLH(fovAngleY, AspectRatio, NearClip, FarClip);
ViewMatrixLH = XMMatrixLookAtLH(Position, Target, Up);
XMVECTOR Determinant;
XMMATRIX InvViewMatrixLH = XMMatrixInverse(&Determinant, ViewMatrixLH);
BoundingFrustum boundingFrustum = BoundingFrustum();
boundingFrustum.CreateFromMatrix(boundingFrustum, ProjectionMatrixLH);
boundingFrustum.Transform(boundingFrustum, InvViewMatrixLH);

Anyway, is there a "trick" to use the BoundingFrustum interface with Right-Handed matrices ?

Is there more documentation about the Orientation property (public: XMFLOAT4 Orientation) ?

Thanks for advices

Add XMVector[3/4]TransformTranspose(Stream)

DirectXMath has a number of different forms of transformation, but currently lacks an optimized function for doing transforms by transposed matrices:

  • XMVector3TransformTranspose
  • XMVector4TransformTranspose
  • XMVector3TransformTransposeStream
  • XMVector4TransformTransposeStream

This would compute:

v * M = [dot(vx, Mx), dot(vy, My), dot(vz, Mz), dot(vw, Mw)]
v * M^T = mul(v, Mx) + mul(v, My) + mul(v, Mz) + mul(v, Mw)

BoundingOrientedBox::CreateFromPoints solver suffers from numeric problems

Report from Dave Eberly about problems with the oriented box SolveCubic helper function.

The SolveCubic is called to compute the eigenvalues of a real-valued symmetric 3x3 matrix. Such matrices ALWAYS have 3 real eigenvalues, so SolveCubic is returning a theoretically incorrect result. The problem has to do with the precision of 'float' numbers. The cubic-solver approach can be made more robust by preconditioning the matrix.

Root finding using the closed-form algebraic equations for low-degree polynomials is known to be numerically ill conditioned. It is better to use iterative methods. For 3x3 symmetric matrices, a specialized iterative method can be very fast, extremely accurate, and robust.

Deprecated functions and types

The following are hold-overs from XNAMath's Xbox 360 support. Not sure they serve any purpose now or have any uses. Perhaps they should be removed, or at least marked as __declspec(deprecated)

  • XMLoadDecN4 / XMStoreDecN4 / XMDECN4
  • XMLoadDec4 / XMStoreDec4 / XMDEC4
  • XMLoadXDec4 / XMStoreXDec4 / XMXDEC4

Also __vector4i which dates back to Xbox 360. In modern use, it's been replaced by XMVECTORI32.

constexpr usage results in IntelliSense warnings

If you build an application using DirectXMath 3.09 with VS 2015, you get the following IntelliSense errors:

Error (active) constexpr function return is non-constant Direct3D Win32 Game2 c:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\um\DirectXMath.h 268 IntelliSense

Error (active) constexpr function return is non-constant Direct3D Win32 Game2 c:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\um\DirectXMath.h 269 IntelliSense

Error (active) constexpr constructor fails to initialize an anonymous union (defined at line 39) Direct3D Win32 Game2 c:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\um\DirectXPackedVector.h 50 IntelliSense

Error (active) constexpr constructor fails to initialize an anonymous union (defined at line 71) Direct3D Win32 Game2 c:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\um\DirectXPackedVector.h 80 IntelliSense

Error (active) constexpr constructor fails to initialize an anonymous union (defined at line 96) Direct3D Win32 Game2 c:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\um\DirectXPackedVector.h 105 IntelliSense

Error (active) constexpr constructor fails to initialize an anonymous union (defined at line 120) Direct3D Win32 Game2 c:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\um\DirectXPackedVector.h 129 IntelliSense

Error (active) constexpr constructor fails to initialize an anonymous union (defined at line 144) Direct3D Win32 Game2 c:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\um\DirectXPackedVector.h 153 IntelliSense

Error (active) constexpr constructor fails to initialize an anonymous union (defined at line 168) Direct3D Win32 Game2 c:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\um\DirectXPackedVector.h 177 IntelliSense

Error (active) constexpr constructor fails to initialize an anonymous union (defined at line 193) Direct3D Win32 Game2 c:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\um\DirectXPackedVector.h 202 IntelliSense

Error (active) constexpr constructor fails to initialize an anonymous union (defined at line 217) Direct3D Win32 Game2 c:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\um\DirectXPackedVector.h 226 IntelliSense

Error (active) constexpr constructor fails to initialize an anonymous union (defined at line 241) Direct3D Win32 Game2 c:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\um\DirectXPackedVector.h 250 IntelliSense

Error (active) constexpr constructor fails to initialize an anonymous union (defined at line 265) Direct3D Win32 Game2 c:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\um\DirectXPackedVector.h 274 IntelliSense

Error (active) constexpr constructor fails to initialize an anonymous union (defined at line 290) Direct3D Win32 Game2 c:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\um\DirectXPackedVector.h 300 IntelliSense

Error (active) constexpr constructor fails to initialize an anonymous union (defined at line 325) Direct3D Win32 Game2 c:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\um\DirectXPackedVector.h 338 IntelliSense

Error (active) constexpr constructor fails to initialize an anonymous union (defined at line 360) Direct3D Win32 Game2 c:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\um\DirectXPackedVector.h 371 IntelliSense

Error (active) constexpr constructor fails to initialize an anonymous union (defined at line 387) Direct3D Win32 Game2 c:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\um\DirectXPackedVector.h 398 IntelliSense

Error (active) constexpr constructor fails to initialize an anonymous union (defined at line 414) Direct3D Win32 Game2 c:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\um\DirectXPackedVector.h 425 IntelliSense

Error (active) constexpr constructor fails to initialize an anonymous union (defined at line 440) Direct3D Win32 Game2 c:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\um\DirectXPackedVector.h 451 IntelliSense

Error (active) constexpr constructor fails to initialize an anonymous union (defined at line 466) Direct3D Win32 Game2 c:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\um\DirectXPackedVector.h 477 IntelliSense

Error (active) constexpr constructor fails to initialize an anonymous union (defined at line 492) Direct3D Win32 Game2 c:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\um\DirectXPackedVector.h 503 IntelliSense

Error (active) constexpr constructor fails to initialize an anonymous union (defined at line 524) Direct3D Win32 Game2 c:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\um\DirectXPackedVector.h 535 IntelliSense

Error (active) constexpr constructor fails to initialize an anonymous union (defined at line 555) Direct3D Win32 Game2 c:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\um\DirectXPackedVector.h 566 IntelliSense

Error (active) constexpr constructor fails to initialize an anonymous union (defined at line 586) Direct3D Win32 Game2 c:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\um\DirectXPackedVector.h 597 IntelliSense

Error (active) constexpr constructor fails to initialize an anonymous union (defined at line 617) Direct3D Win32 Game2 c:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\um\DirectXPackedVector.h 628 IntelliSense

Error (active) constexpr constructor fails to initialize an anonymous union (defined at line 648) Direct3D Win32 Game2 c:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\um\DirectXPackedVector.h 659 IntelliSense

Error (active) constexpr constructor fails to initialize an anonymous union (defined at line 679) Direct3D Win32 Game2 c:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\um\DirectXPackedVector.h 690 IntelliSense

Error (active) constexpr constructor fails to initialize an anonymous union (defined at line 706) Direct3D Win32 Game2 c:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\um\DirectXPackedVector.h 718 IntelliSense

Error (active) constexpr constructor fails to initialize an anonymous union (defined at line 732) Direct3D Win32 Game2 c:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\um\DirectXPackedVector.h 744 IntelliSense

Error (active) constexpr constructor fails to initialize an anonymous union (defined at line 758) Direct3D Win32 Game2 c:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\um\DirectXPackedVector.h 770 IntelliSense

Error (active) constexpr constructor fails to initialize an anonymous union (defined at line 784) Direct3D Win32 Game2 c:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\um\DirectXPackedVector.h 796 IntelliSense

Error (active) constexpr constructor fails to initialize an anonymous union (defined at line 811) Direct3D Win32 Game2 c:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\um\DirectXPackedVector.h 822 IntelliSense

Error (active) constexpr constructor fails to initialize an anonymous union (defined at line 840) Direct3D Win32 Game2 c:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\um\DirectXPackedVector.h 851 IntelliSense

There are no build errors/breaks in the actual build, so it's specific to the IntelliSense compiler. This does not happen with older versions of Visual C++ or DirectXMath.

DirectXMath types don't work with constexpr

We tried changing all static consts in our app to be constexpr instead, in an effort to keep up with new C++ language features. But it didn't work because XMFLOAT3 and XMFLOAT2 can't be made constexpr.

We tried to make this:

constexpr VertexPositionColorTex33 quadVertices[] =
{
    {
 XMFLOAT3(-0.2f,  0.2f, 0.f), XMFLOAT3(1.0f, 1.0f, 1.0f), XMFLOAT2(0.f, 0.f) },
    { 
XMFLOAT3( 0.2f,  0.2f, 0.f), XMFLOAT3(1.0f, 1.0f, 1.0f), XMFLOAT2(1.f, 0.f) },
    { 
XMFLOAT3( 0.2f, -0.2f, 0.f), XMFLOAT3(1.0f, 1.0f, 1.0f), XMFLOAT2(1.f, 1.f) },
    { 
XMFLOAT3(-0.2f, -0.2f, 0.f), XMFLOAT3(1.0f, 1.0f, 1.0f), XMFLOAT2(0.f, 1.f) },
};

The value constructors for XMFLOAT3 and XMFLOAT2 are not constexpr, so that can't be compiled. The same is presumably true for other XM* types.

To fix XMFLOAT3 and XMFLOAT2 for use in a constexpr initializer list, we were able to add the constexpr qualifier to the value constructor:

constexpr XMFLOAT3(float _x, float _y, float _z) : x(_x), y(_y), z(_z) {}
constexpr XMFLOAT2(float _x, float _y) : x(_x), y(_y) {}

Need explicit vector division

The original xboxmath library did not include an XMVectorDivide. It instead expected client code to use multiply-by-reciprocal. As there's an explicit divide function in SSE/SSE2, the new method is needed.

Use SSE3 horizontal ops in x86/x64 version

For the x86 and x64 platforms, DirectXMath only uses SSE/SSE2 by default. If you build with /arch:AVX it can make use of SSE3, SSE4.1, and AVX. With /arch:AVX2 it can use SSE3, SSE4.1, AVX, and F16C.

The question is at what point can DirectXMath assume SSE3 as well for the 'base' case (i.e. without /arch:AVX or /arch:AVX2). SSE/SSE2 is required for x64 CPUs, Windows 8.1 x86 OS, and the Windows 10 x86 OS. SSE3 is not. That said, however, the Valve Hardware survey pegs the support for SSE3 at 99% so it may well be a defacto standard at this point.

I think adding _XM_SSE3_INTRINSICS_ as it's own control define is now worth-while, although it will only be on when explicitly enabled or when using /arch:AVX or /arch:AVX2.

XMMatrixRotationRollPitchYaw arguments order

The function is named XMMatrixRotationRollPitchYaw, but its arguments are in a different order, which is a little tricky:

inline XMMATRIX XM_CALLCONV XMMatrixRotationRollPitchYaw
(
    float Pitch, 
    float Yaw, 
    float Roll
)

Don't know if there's an easy backwards-compatible fix to this problem, but I figure it should be documented as an issue anyways.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.