-
Notifications
You must be signed in to change notification settings - Fork 4
SIMD Vs Non ‐SIMD Demos
I would recommend reading What is SIMD / NEON, as the DEMO here will greatly help you understand how all this SIMD/NEON stuff works, before reading the below, of course if you have already read it then just ignore this message.
There are two demos you can download and compare the speed and power of SIMD. These are Shadow Casting application.
The first demo is ShadowCast2D, you can download the demo here. This Shadow Caster was created by OneLoneCoder, a long time ago, and it is an amazing shadow caster application, beautifully written to be honest. You can watch the video here
The second demo is ShadowCast2D_SIMD, you can download the demo here. This is the exact same project as ShadowCast2D except the draw routines have been replaced with SIMD methods.
The below images compare the differences in frame rate. As stated int What is SIMD / NEON section “Frame Rate should not be used as an indication of how fast your game is running…”
But for our comparison we are going to use it anyway 🤦♂️
ShadowCast2D Debug (14 Fps):
ShadowCast2D_SIMD Debug (38 Fps):
ShadowCast2D Release (123 Fps)
ShadowCast2D_SIMD Release (193 Fps)
In the above comparisons we see a mark increase in performance when the SIMD methods are been executed. So, what did we change?
Only a few methods were updated in the ShadowCast2D_SIMD for this to work, and yes it was a simple change.
In the ShadowCast2D_SIMD.cpp file we changed:
DrawSprite(fSourceX - 255, fSourceY - 255, sprLightCast);
// To:
DrawSprite_SIMD(fSourceX - 255, fSourceY - 255, sprLightCast);
FillTriangle (…);
// To:
FillTriangle_SIMD(…);
FillRect(…);
// To:
FillRect_SIMD(…);
FillCircle(…);
// To:
FillCircle_SIMD(…);
And that’s it, job done.
There are advance options for SIMD that can be enabled at the sprite level to improve performance. These are explained below in the “A Little More Technical” section.
One such option is to enable Store Sub Sprite
, do not use this option with Shadow Casting, unless you have a few GBs of RAM to spare.
You would think you would be happy with that, ok yes, let make if faster!!!
Ok let’s use the DrawMergeSprite_SIMD:
Replace this code in the ShadowCast2D_SIMD project:
With
And run it in release mode.
ShadowCast2D_SIMD Release with DrawMergeSprite_SIMD (259 Fps)
Have fun playing around with it, there are other ways this can be optimised more.
Change the Int Main:
to
ShadowCast2D_SIMD Release with DrawMergeSprite_SIMD 640*480 (294 Fps)
Now change int main on both projects to:
ShadowCast2D Release 1280*960 (8 Fps)
ShadowCast2D_SIMD Release 1280*960 (92 Fps)
As stated earlier, SIMD does not always increase the speed of your application, it is more likely to stabilize your frame rate. In the example above we see the frame rate drop from 123 Fps to 8 Fps for the ShadowCast2D, while SIMD dropped from a whopping 259Fps to 92Fps. You have still 60Fps to play with before user experience is impacted.
Also remember this is Shadow Casting!
Shadow Casting places your application under tremendous pressure, remember the days when you could disable “Shadows” on your game to improve speed? Well, these days this option is still there, it just it is automatic now 😊
- For Visual Studio All In One Android and iOS (Windows) Project Template: OLC Pixel Game Engine Mobile 2.2.8 Visual Studio for Android and iOS
- For Visual Studio Android Only (Windows) Use this project: OLC Pixel Game Engine Mobile 2.2.8 for Android Visual Studio
- For Android Studio (Windows/Linux/MAC) Use this project: OLC Pixel Game Engine Mobile 2.2.8 for Android Studio
- For Xcode (MAC) Use this project: OLC Pixel Game Engine Mobile 2.2.8 for Xcode