What's the right way to utilize ARM SIMD on iPhone for Game vector/matrix operation? - iphone

I'm making an vector/matrix library for Game which utilizes SIMD unit on iPhone (3GS or later).
How can I do this?
I searched about this, now I know several options:
Accelerate framework (BLAS+LAPACK+...) from Apple (iPhone OS 4)
OpenMAX implementation library from ARM
GCC auto-vectorization feature
What's the most suitable way for vector/matrix library for game?

You should assume GCC won't auto-vectorize your code, because it sounds like that is very unlikely to happen!
Like Paul said, to get the most performance from your iPhone you should write your own ARM Assembly code using NEON SIMD instructions for as much of it as you can. But that assumes you understand ARM assembly language as well as NEON, timing delays, etc. So if you don't want to learn ARM Assembly language, then Apple's Accelerate framework and ARM's OpenMAX libraries both have numerous functions that are already written in ARM assembly language with NEON SIMD instructions.
So either Accelerate or OpenMAX should be very good if you can use them. I haven't compared the 2 to see which one is actually faster, but I assume ARM's OpenMAX is slightly faster than Apple's implementation since ARM designed the NEON specs! But they should both run extremely fast.

With time come new answers:
The bullet physics engine is now optimized for NEON SIMD by Apple. http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=8490

To do it well you will probably need to write your own SIMD routines. Use the Neon C intrinsics in gcc rather than assembler to ease the pain of doing this.

I created a couple of NEON optimized Mat*Mat and Mat*Vec routine using inline ASM. They are part of the Oolong Engine, but they are under the MIT license, so you can use them as you like:
http://code.google.com/p/oolongengine/source/browse/trunk/Oolong%20Engine2/Math/neonmath/neon_matrix_impl.cpp

Apple now has <simd/simd.h> which is a library of optimized math routines for small vectors, matrices, and quaternions as part of the Accelerate framework you mention.
Seems like that's probably the easiest way today.
https://developer.apple.com/documentation/accelerate/simd?language=objc

Related

Cross-platform development with GLKit?

I've just installed the current Xcode 4 release and realized the new "GLKit" API thats also used in the OpenGL Template for iOS. So, I want to develop an cross-plattform game for iOS, Mac & Windows. GLKit seems like a step backwards in terms of portability, but the GLKit Features (specially like asynchronous texture loading) are great benefits...
How can I develop a cross-plattform game with GLKit? I would need to write any grapics code twice, right? Or is there something like an GLKit implementation for windows?
Any idea, workaround, code-design advice (how to divide the GLKit Code from other components?) is welcome - thanks!
I can't think of anything that GLKit does which cannot be replaced by non-GLKit code. It can make some OpenGL ES 2.0 tasks simpler by abstracting them away from you, but it doesn't do anything unique. The closest it comes to having something you can't replicate elsewhere (from what I've tinkered with) is the accelerated matrix and vector math functions it provides, but even those could be replaced with a little Accelerate or NEON code.
While I'd like to use GLKit within my applications, I'm still supporting iOS 4.2 with them, which doesn't have GLKit available. There's nothing that I'm currently prevented from doing because I can't use GLKit, I just have to write a little more code to handle things like view updates, texture uploads, matrix math, etc. There's plenty of documentation and examples out there for these operations, so you don't need to worry about being on your own when it comes to implementing them.
You're going to have much larger problems than GLKit when trying to make your code be cross-platform with the Mac, and expecially so with Windows. Desktop OpenGL and OpenGL ES have some differences in their implementations, and you'll need to be aware of the places to substitute one function or built-in variable for another. CAOpenGLLayer and NSOpenGLView on the Mac are also different from the CAEAGLLayer on iOS, and AppKit overall is a different animal than UIKit.
Windows will be even more of a challenge to support, because you won't be able to use any of the Cocoa frameworks, and most likely no Objective-C as well. This will take a lot more of your time than any OpenGL / OpenGL ES differences.

Sound Effect Library/Extension for OpenAL (running on iOS)?

I want to do some DSP effect processing, create effect like flanger, echo, etc.
Could it be done via OpenAL? Or should I use enterely different framework/library?
Since iOS 5.0 some of the DSP effects are natively supported by OpenAL.
For example, reverb is supported with emulation for more than 10 different spaces (Small/Medium/Large Room, Medium/Large Hall, Plate, Medium/Large Chamber, Cathedral and several variations).
You can find a good reference implementation in the ObjectAL wrapper. The repository is available at https://github.com/kstenerud/ObjectAL-for-iPhone
Grab the source from this repository, load "ObjectAL.xcodeproj" and run the ObjectALDemo target on any iOS 5.0 device (should also work on the simulator). This will give you a good starting point and feeling of what the reverb effect is capable of. I personally recommend taking advantage of the ObjectAL library instead of working with OpenAL directly.
Good luck with your project!
Just write your own audio library. iOS devices don't have hardware acceleration for OpenAL. It isnt particularly difficult to do, and then you can also use apples audio units (some of which are hardware accelerated).

Audio Library C++ for a multicross platform use (iphone, android...)

i'm trying to make a C++ engine that will read a mp3 file, and make some image zoom/translation depending on the time of the reading sound file. I think I could use OpenGL ES to render what I want, and calling some OpenGL ES instructions in my C++ files, and init my drawing context in Obj-C/Java. I want to do the same for the sound, but i don't really know what to use, and if I can really do it or not in C++.
I searched for library so I found Bass and Fmod (which is not free for commercial use). They said it's multicross platform (Windows, Unix, MacOS) but I dont understand if it manners for mobile, and if I can really use it. Does anyone have been through this? Do you recommand me another free library?
Thanks again, and I apologize for my poor english,
Arnaud
Have a look at libpd (Pure Data for embedded applications)
http://download.puredata.info/libpd (the library has been released very recently, but the code is very mature indeed)
http://createdigitalmusic.com/2010/10/libpd-put-pure-data-in-your-app-on-an-iphone-or-android-and-everywhere-free/
Audio is often problematic and it is pretty much always a good idea to write your own high-level API that does exactly what you want to do (and nothing else) and to assume you will then be writing a thin layer between it and whatever audio library you are using underneath. If you're lucky and there's a library available that does things the way you would do them then it's trivial. If not, at least it's still possible. In either case, your app code is not tied to an external sound API.
I have used FMOD on multiple different commercial projects over the years for PC, Mac and iPhone, and have always liked it - but it's not free. OpenAL has always seemed sorta, I dunno: clunky? But you only have to deal with it when writing your API layer, and your app code never has to see it.
It's easy for me to say "write your own API" since I've been writing commercial games for 20 years and so know what I think an audio API should look like. If you don't have your own idea how you think it should be, then I suggest you look at a 3rd party library that makes sense to you and take the functions from it that you will be using and write your own API to do be a set of functions that do nothing but call those.
Since you have both OpenAL and FMOD available to you free for development you can then make your API work with both, and chances are it's then going to work with anything else you might come across.
OpenAL may be your best bet. Look at this answer: Android OpenAL?
It seems possible to compile OpenAL on Android.
If you are looking for just PCM audio input/output ( and not MP3 decoding ) try PortAudio or RTAudio
RtAudio or PortAudio, which one to use?

CoreGraphics Alternative?

I'm looking for a 2D rendering library as an alternative to CoreGraphics on iPhone. Everything in my app is pretty dynamic, which makes splitting things up into layers and animations rather hard.
I'm quite familiar with OpenGL, and that is how rendering is implemented right now. Everything would be so much easier to expand and development would go so much faster if I didn't have to worry about the low-level stuff in OpenGL, though (And my code would look so much neater :D).
I prefer C++ over Objective-C, so if you know any C++ libraries for rendering, that would be great. I can work with C too. Path-based rendering, like in CoreGraphics or the JavaScript Canvas API, would be beneficial. Would Cairo work on iPhone?
I've actually been working on my own 2D renderer, which I'll probably release even if I don't end up using in my app, because I enjoy working on it. Does the iPhone support the stencil buffer? I can do polygon triangulation, or use GLU's tesselation library, but the stencil buffer would safe a load of work in the long run.
Edit: Also, I've implemented rendering in this app with CoreGraphics before, and it didn't get as good of a frame rate as I'd like. I did some research, and people have suggested not using CoreGraphics for things that are constantly redrawing the screen. Some said CoreGraphics doesn't use the GPU, others said it was some caching mechanism. I've avoided it ever since.
MonkVG is an OpenVG 1.1 like vector graphics API implementation currently using an OpenGL ES backend that should be compatible with any HW that supports OpenGL ES 2.0 which includes most iOS and Android devices.
This is an open source BSD licensed project that is in active development. At the time of this writing it is in a very early pre-release state (very minimal features implemented). Contributors and sponsors welcome.
It can be found at GitHub http://github.com/micahpearlman/MonkVG
Also, there is a SVG and SWF (flash) renderers built on top of MonkVG:
MonkSVG
MonkSWF

Engine for use with PC and Iphone?

Are there any engines that allow me to develop for pc and iphone at the same time? My preferred language would be c#, but that probably won't happen, so I probably will learn c++ or java.
I want a 2d engine, by the way.
No experience with it but...
http://www.torquepowered.com/products/torque-2D/
C# and Java aren't allowed on the iPhone, so a C or C++ engine would be your best bet. I'm guessing you're doing a game--if so, you'll probably want to use OpenGL. I don't know any specifically, but here's a full list.
Working with pure Core Animation layers can yield cross-platform 2-D drawing and animation between iPhone, iPad, and Mac. As an example of this, the Core Plot framework runs on Mac and iPhone from the same codebase. Core Animation lets you do some pretty complex animations and layout in 2-D.
It is against the rules in OS 4 to write an iPhone app in something other than Apple's dev tools. However, IANAL but I'd expect that it is in theory ok to take the app you made there and then try to run it on an emulation layer etc.. on the /other/ platform(s). Not sure about direct solutions, but check out the GNU Objective-C runtime / GNUStep, they might be a helpful starting point.