microsoft / DirectXMath

DirectXMath is an all inline SIMD C++ linear algebra library for use in games and graphics apps
https://walbourn.github.io/introducing-directxmath/
MIT License
1.54k stars 238 forks source link

Feature request: ios, osx and Android support #67

Closed alek314 closed 6 years ago

alek314 commented 6 years ago

Hello DirectXMath team! We have use DirectXMath in our in house engine for about a year or two now. With some minor fix (most of them are clang related issues) DirectXMath works on osx ,ios and Android. It would be great if DirectXMath can support these platforms officially.

walbourn commented 6 years ago

The DirectXMath library is really only dependent on the intrinsics syntax as it doesn't make use of any Windows APIs--at one point I used IsProcessorFeaturePresent to implement XMVerifyCPUSupport but I removed it some time back.

The x86/x64 targets use Intel syntax intrinsics, so any compiler that supports those should work. I've heard there are some issues with the Intel compiler's 'faking' of Microsoft Visual C++ support due to __vectorcall but you can work around that pretty easily by manually defining _XM_VECTORCALL_ as 0. I made some fixes for clang which doesn't support the XMVECTOR overloads which you can manually enable for other compilers if needed by defining _XM_NO_XMVECTOR_OVERLOADS_.

For ARM (32-bit) the bigger issue is that I assume ARMv7 with the extensions ARM-NEON and VFPv3. This is the minimum processor instruction support for Windows on ARM (a.k.a. Windows RT and Windows Mobile).

Lots of iOS devices are older versions of ARM, although newer ones (iPhone 5 and later) do support ARMv7 with NEON--see this article for iOS. The real issue is that officially iPhone development is done with Objective-C instead of C++, and DirectXMath is a C++ library. There are known workarounds for this issue like Objective-C++.

For Android, even those devices that use ARMv7 don't always include ARM-NEON--the biggest problem with the Android ecosystem is really that it's a sea of possible hardware--but if it meets those requirements it should work.

For ARM (64-bit) the story is a lot cleaner. I assume ARMv8 which requires ARM-NEON and VFPv4. For iOS this should be iPhone 5S or later. For Android, the latest Google, OnePlus, and Samsung devices support it--see this article

There are likely small syntax issues in the ARM-NEON implementation that will need fixed for various compiler toolsets. I've only tested Visual C++ and clang 5/c2, but if you propose small fixes for these other platforms that still work on Visual C++ then it shouldn't be difficult to accept those pull requests.

The no-intrinsics code path is also a good place to start to make sure there are not other syntax/include header issues. If you define _XM_NO_INTRINSICS_ the library falls back to pure C/C++ code paths.

alek314 commented 6 years ago

Lots of information here. If this info were in the Readme.txt, it would helps other people.

walbourn commented 6 years ago

A fair bit of it is on the wiki. I'll take a look at that.

walbourn commented 6 years ago

Note that more recent Intel C++ compiler versions work fine as well.