SDL Performance once again

Hello everybody,

I have read a couple of discussions on this topic but still haven’t formed a
consistent picture in my mind.

The question is simple: suppose I initialize SDL, and perform a simple loop:
Erase the whole screen
Blit a background image
Blit several sprites
Pefrorm flip

How many FPS should I get on a typical modern hardware (say, 1,5 GHz
processor and a decent videocard; 102476832b) under reasonable
assumptions?

I know it depends on hardware/software surfaces, fullscreen/windowed mode,
etc., but still? In my case it is usually 70-80 FPS, no more (while I
expected at least 150).

One reply in the newsgroup was something like: “if you want to get speed in
SDL, you should use OpenGL, otherwise you execute a generic cross-platform
(slow) code”. Is it really so? I mean if I want speed, I should forget about
all SDL functions for blitting and about third-party routines for primitives
(like SDL_prim), and begin to study OpenGL?

Thanks!

I have read a couple of discussions on this topic but still haven’t formed a
consistent picture in my mind.

The question is simple: suppose I initialize SDL, and perform a simple loop:
Erase the whole screen
Blit a background image
Blit several sprites
Pefrorm flip

In this case, erasing the screen is not needed and depending on how much
is covered by sprites SDL_UpdateRects may be faster than SDL_Flip.

How many FPS should I get on a typical modern hardware (say, 1,5 GHz
processor and a decent videocard; 102476832b) under reasonable
assumptions?

I know it depends on hardware/software surfaces, fullscreen/windowed mode,
etc., but still? In my case it is usually 70-80 FPS, no more (while I
expected at least 150).

Playing around with testblitspeed should answer most of those questions.
On X11 a quick back-of-the-envelope calculation gives around 100 FPS as
a teoretical max. In practice, you will never get there more than a few ms
at a time.

One reply in the newsgroup was something like: “if you want to get speed
in SDL, you should use OpenGL, otherwise you execute a generic
cross-platform (slow) code”. Is it really so? I mean if I want speed, I
should forget about all SDL functions for blitting and about third-party
routines for primitives (like SDL_prim), and begin to study OpenGL?

Or wait for SDL 1.3.

The problem with SDL 1.2 is that almost no blits is HW accelerated, while
in OpenGL most of them are.On Thu, 7 Sep 2006, Maxim Mozgovoy wrote:

Hello !

I have read a couple of discussions on this topic but still haven’t
formed a consistent picture in my mind.

The question is simple: suppose I initialize SDL, and perform a simple
loop:
Erase the whole screen
Blit a background image
Blit several sprites
Pefrorm flip

How many FPS should I get on a typical modern hardware (say, 1,5 GHz
processor and a decent videocard; 102476832b) under reasonable
assumptions?

I know it depends on hardware/software surfaces, fullscreen/windowed
mode, etc., but still? In my case it is usually 70-80 FPS, no more (while
I
expected at least 150).

One reply in the newsgroup was something like: “if you want to get speed
in SDL, you should use OpenGL, otherwise you execute a generic
cross-platform (slow) code”. Is it really so? I mean if I want speed, I
should forget about all SDL functions for blitting and about third-party
routines for primitives (like SDL_prim), and begin to study OpenGL?

You can get good speeds if you use HW Surfaces and
DGA on Linux/X11 or DirectX on Windows. When these
things are supported on your system. Another thing
if you want to have Alpha Blending use SW Surfaces
when not using OpenGL as Alpha Blending needs read&write
of pixels which is the fastest in system memory.

CU

Or wait for SDL 1.3.

The problem with SDL 1.2 is that almost no blits is HW accelerated, while
in OpenGL most of them are.

well, but is it sensible to use SDL only to get access to DirectX/OpenGL?
(not talking about sound and event handling). It is crossplatform, but
that’s all…

but ok, thank you very much; if in 1.3. version these issues will be solved,
I can wait :slight_smile:

Hello Maxim,

Thursday, September 7, 2006, 5:13:29 PM, you wrote:

Hello everybody,

I have read a couple of discussions on this topic but still haven’t formed a
consistent picture in my mind.

I know it depends on hardware/software surfaces, fullscreen/windowed mode,
etc., but still? In my case it is usually 70-80 FPS, no more (while I
expected at least 150).

What platform and what backend?

One reply in the newsgroup was something like: “if you want to get speed in
SDL, you should use OpenGL, otherwise you execute a generic cross-platform
(slow) code”. Is it really so? I mean if I want speed, I should forget about
all SDL functions for blitting and about third-party routines for primitives
(like SDL_prim), and begin to study OpenGL?

It all depends on the backend. Under Windows, if a blit can be done in
hardware (ie, if the DirectX backend is used, if the source and dest
formats are the same, and if the surfaces are in video memory) then a
hardware blit is done. If the blit involves format conversion,
software routines are used. On some backends, software is always used.

Saying “Use OpenGL” is a knee jerk thing. It depends what you want to
do. If you want to do lots of scaled blits, GL is better. If you want alpha
transparency, GL is better. If what you’re blitting is dynamically
changing often, GL is a pain. GL is also only any good if you assume
that the user will have a hardware accelerated GL implementation. If
they don#t, the software GL will be much slower than any software
based 2d blitters.–
Best regards,
Peter mailto:@Peter_Mulholland

What platform and what backend?

say, Windows, “typical” modern hardware.

Sorry for stupid question, but when you say “DirectX/OpenGL” – does it mean
that I have to use these libraries’ native routines?

I mean, can I invoke, say, SDL_BlitSurface() and somehow enable it to use
OpenGL (or DirectX) mode? It doesn’t work for OpenGL surfaces, if I remember
correctly…

Hello Maxim,

Friday, September 8, 2006, 3:18:18 PM, you wrote:

Sorry for stupid question, but when you say “DirectX/OpenGL” – does it mean
that I have to use these libraries’ native routines?

For OpenGL, yes. The most SDL will do is take care of the platform
specific parts of initialising GL. It doesn’t do anything else, and
the 2D blit stuff does not work when you are using GL.

I mean, can I invoke, say, SDL_BlitSurface() and somehow enable it to use
OpenGL (or DirectX) mode? It doesn’t work for OpenGL surfaces, if I remember
correctly…

Kind of. SDL has various video backends, sometimes more than one on
different platforms. For Windows, there are two - DirectX and GDI.

As of recent SDL versions, the default backend is GDI for reasons of
wider compatibility. However, the DirectX backend will give better
performance. To enable the DirectX backend in your program, add the
following before you call SDL_Init()

SDL_putenv(“SDL_VIDEODRIVER=directx”);

This should increase performance somewhat. The catch is your program
will require DirectX 7 or better (ie, no Windows 95 or NT). It is
unconfirmed as to whether the older DirectX API’s will be in Vista,
but I would imagine Microsoft aren’t dumb enough to remove them.–
Best regards,
Peter mailto:@Peter_Mulholland