Using System.Numerics.Vector for Graphics Programming

We’ve just released a major update to the SIMD vector types we’ve blogged about earlier (first announcement, second update).

We’ve now made the vector library a lot more more useful for typical graphics operations. We added matrix types, a plane type, and a quaternion type. We’ve also added many methods that are often used on fixed size vectors, such as Lerp, DistanceSquared, Normalize, and Reflect.

We also completed our SIMD support for primitive types by adding support for Vector<uint> and Vector<ulong>.

Getting the new bits

In order to try out the update, you’ll need the following components:

Changes in this release

The first thing you’ll notice is that we renamed the package from Microsoft.Bcl.Simd to System.Numerics.Vectors. We intend to ship more .NET components on NuGet so we felt that we need to use a better naming convention that allows people to find our packages.

We decided to simply match our namespace and assembly naming convention. However, in case your project already references Microsoft.Bcl.Simd, you can simply upgrade. In that case your project will automatically add a reference to System.Numerics.Vectors and show a README file that tells you to remove the now superfluous reference to Microsoft.Bcl.Simd.

Here is the list of API changes we performed:

  • We’ve added support for Vector<uint> and Vector<ulong>. We now support all integral types, including unsigned
  • Added new types
    • Matrix3x2
    • Matrix4x4
    • Plane
    • Quaternion
  • Made fixed size vector types more useful by adding a bunch of methods:
    • Distance, DistanceSquared
    • Length, LengthSquared
    • Lerp
    • Normalize
    • Reflect
    • SquareRoot
    • Transform, TransformNormal
  • Renamed Vector2f, Vector3f, Vector4f by removing the f suffix
  • Merged VectorMath with Vector and Vector1, Vector2, Vector3
  • Moved all static methods from Vector<T> to the non-generic Vector class
  • Renamed Vector<T>.Length to Vector<T>.Count

We’ve also updated the SIMD samples to be compatible with the new version.

Summary

Today, we’ve released RyuJIT CTP 5 and a much improved System.Numerics.Vectors NuGet package which adds support for more graphics related APIs.

Please provide feedback as we’re trying to lock down the API design. You can simply leave a comment here or send us an email via the contact form.