Skip to content

SIMD Vs Non ‐SIMD Demos

John Galvin edited this page Oct 28, 2024 · 2 revisions

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.


DEMOS

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 🤦‍♂️

Comparisons

ShadowCast2D Debug (14 Fps):

image

ShadowCast2D_SIMD Debug (38 Fps):

image

ShadowCast2D Release (123 Fps)

image

ShadowCast2D_SIMD Release (193 Fps)

image

So what was changed?

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.

Important Note:

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.

"But Johnngy we want it faster..."

You would think you would be happy with that, ok yes, let make if faster!!!

image

Ok let’s use the DrawMergeSprite_SIMD:

Replace this code in the ShadowCast2D_SIMD project:

image

With

image

And run it in release mode.

ShadowCast2D_SIMD Release with DrawMergeSprite_SIMD (259 Fps)

image

Have fun playing around with it, there are other ways this can be optimised more.

Change the Int Main:

image

to

image

ShadowCast2D_SIMD Release with DrawMergeSprite_SIMD 640*480 (294 Fps)

image

Now change int main on both projects to:

image

ShadowCast2D Release 1280*960 (8 Fps)

image

ShadowCast2D_SIMD Release 1280*960 (92 Fps)

image

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 😊

Clone this wiki locally