My 3D graphics software, written in C# using SlimDX, does a lot of vector operations on the CPU. (In this specific situation, it is not possible to offload the work to the GPU).
How can I make my vector math faster? So far, I have found these approaches:
Are there any other options to accomplish faster vector math in .NET?
Write a DLL using Microsoft Visual C++'s compiler. Use standard C++ with SSE intrinsics and/or OpenMP for the heavy numeric code, with #pragma unmanaged
. Use #pragma managed
to define a clean C++/CLI API which C# can use.
C++ interop is quite a bit faster than p/invoke. And C++/CLI is the only elegant way to deal with both garbage collected memory and the assumptions of native functions (that memory blocks won't move).
You might find that moving some of the OpenGL calls to C++, and using the C++-allocated memory buffers directly for loading VBOs, etc. also gives a big performance win.
Microsoft just announced support for generating vectorized instructions in their .NET Native compiler thanks to back-end C++ compiler optimizations, and more importantly native support for SIMD vector types in the most recent version of their JIT ("RyuJIT"). See some samples here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With