Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avoiding DirectXMath XMStore/load

I have previously done OpenGL and am now learning some DirectX11. One of the things in the new math library is the presence of Load/Store methods for vectors and matrices (for example http://msdn.microsoft.com/en-us/library/ee415635(v=vs.85).aspx).

For me this quirks me a lot having to store/load each vector and matrix when I want to use them - a lot of bulky code - and I was wondering if there are any nice, clean alternatives to the load/store procedures?

like image 644
KaiserJohaan Avatar asked Jun 26 '14 16:06

KaiserJohaan


1 Answers

You could look at simplemath if that helps. It's now part of the DirectXTK.

From the linked site:

Why wrap DirectXMath?
DirectXMath provides highly optimized vector and matrix math functions, which take advantage of SSE SIMD intrinsics when compiled for x86/x64, or the ARM NEON instruction set when compiled for an ARM platform such as Windows RT or Windows Phone. The downside of being designed for efficient SIMD usage is that DirectXMath can be somewhat complicated to work with. Developers must be aware of correct type usage (understanding the difference between SIMD register types such as XMVECTOR vs. memory storage types such as XMFLOAT4), must take care to maintain correct alignment for SIMD heap allocations, and must carefully structure their code to avoid accessing individual components from a SIMD register. This complexity is necessary for optimal SIMD performance, but sometimes you just want to get stuff working without so much hassle!

You should use SimpleMath if you are:

  • Looking for a C++ math library with similar API to the C# XNA types
  • Porting existing XNA code from C# to C++
  • Wanting to optimize for programmer efficiency (simplicity, readability, development speed) at the expense of runtime efficiency

You should go straight to the underlying DirectXMath API if you:

  • Want to create the fastest possible code
  • Enjoy the lateral thinking needed to express algorithms in raw SIMD
like image 91
Roger Rowland Avatar answered Sep 29 '22 05:09

Roger Rowland