Skip to main content
GameDev.net gamedev.net
🔒 Locked

is SDL too slow?

Started by lesmes Aug 4, 2002 at 6:34 AM 14 replies 2.3k views
Original Post
lesmes
lesmes
I am writing some routines to draw 2d graphics with SDL library. The results are that I only get about 50 fps bliting a screen-size SDL_Surface. I investigated that and I found that the bottleneck is in the SDL_Flip function. A dummy while calling SDL_Flip only gets 76 fps, while, for example, Quake 3 gets 180 fps in my computer. I use all the hardware accelerate flags in video mode initialization: bool motor2d::nuevoModoVideo(int resX,int resY,int ppp,bool fullScreen) { int flags; flags = SDL_HWPALETTE | SDL_DOUBLEBUF; if (fullScreen) flags |= SDL_FULLSCREEN; if (videoInfo->hw_available) flags |= SDL_HWSURFACE; else flags |= SDL_SWSURFACE; if (videoInfo->blit_hw) flags |= SDL_HWACCEL; if ((m_pPantalla = SDL_SetVideoMode(resX, resY, ppp, flags )) != NULL) return true; return false; } Someone has the same problem? Thanks.
niyaw
niyaw
might be due to vsync.
baumep
baumep
What resolution and color depth are you using?
If you''re screen resolution is 640x480 and above it is hard to achieve a high framerate as e.g. Q3. The reason why Q3&Co are so fast is because they use 3d HW acceleration which is usually faster than blitting bitmaps.
Here are some suggestions to speed up SDL. If that''s still not enough you might try looking into 2d rendering using OpenGL which is easily possible with SDL. There''s even an additional library (glSDL) available for SDL which can handle that task.
baumep
lesmes
lesmes
This results are de best I get testing with 800x600 and 1024x768 and 8,16,24 & 32 bpp.
It sounds very strange that It only get 76 fps without drawing anything (I only call SDL_Flip in a loop). I run the test in windows xp and redhat linux 7.3 with very similar results.
My computer is an AMD K7-1.4 GHz with a Nvidia Geforce 2MX card.
I test in a P4-1.6 GHz with a SavagePro-Mx and the results are worse, about 40 fps without drawing anything using 800x600.
I have vsync disabled in my windows driver.
stefu
stefu
Have you tried without SDL?
Take for example NeHe basecode and try how fast it is.
Kylotan
Kylotan
If the bottleneck is SDL_Flip, then it''s Vsync that''s holding you back. Which I personally think is a good thing because the visible ''tearing'' can be quite bad on some systems otherwise.

Make sure you are converting all your surfaces to the DisplayFormat for the best performance too.

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost | Asking Questions | Organising code files ]
lesmes
lesmes
I get exactly the same results using doublebuffer/SDL_Flip and using SDL_UpdateRect(screen,0,0,0,0).

The results are executing it in Linux (dummy while that only call SDL_Flip):

320x200:

8 bpp FPS: 502
16 bpp FPS: 438
24 bpp FPS: 207
32 bpp FPS: 826

640x400

8 bpp FPS: 109
16 bpp FPS: 95
24 bpp FPS: 50
32 bpp FPS: 199

800x600

8 bpp FPS: 58
16 bpp FPS: 50
24 bpp FPS: 26
32 bpp FPS: 104

1024x768

8 bpp FPS: 35
16 bpp FPS: 30
24 bpp FPS: 16
32 bpp FPS: 63

Perhaps there is no way to get better performance without openGl.
I''m still investigating...
Thanks a lot to all.
lesmes
lesmes
I found some thing that slows down the test: the SDL_HWPALETTE flag.
Using it I get 76 fps at 800x600x32. Without it, 104 fps.
Nairb
Nairb
Hey,
Something else that might be slowing you down is a lack of SDL_DisplayFormat. You want to convert all your surfaces to the same format as the display format via this function before you use them. I got quite an FPS jump after using this function.

--Nairb
lesmes
lesmes
sorry, SDL_HWPALETTE lack of performance was a test error. I get the same performance with/without his flag.
I use SDL_DisplayFormat to convert surfaces to display format.
Thanks.
Witchcraven
Witchcraven
SDL should be very fast, on windows it is based over directdraw, and ms has that well optimized for windoze.
--------------------------I present for tribute this haiku:Inane Ravings OfThe Haunting JubilationA Mad Engineer©Copyright 2005 ExtrariusAll Rights Reserved
lesmes
lesmes
This is one of my test programs:

#include "SDL.h"
#include "SDL_main.h"
#include <stdlib.h>

#define LOOPS 100

int main(int argc,char *argv[])
{
int i,j;
Uint32 before,after;
SDL_Surface *screen;
SDL_Init(SDL_INIT_VIDEO);
atexit(SDL_Quit);

if (argc!=3)
{
perror("USE: main resx resy\n");
exit(0);
}

for (j=1;j<5;++j)
{
screen = SDL_SetVideoMode(atoi(argv[1]),atoi(argv[2]),8*j,SDL_HWSURFACE|SDL_DOUBLEBUF);
before=SDL_GetTicks();
for (i=0;i SDL_Flip(screen);
after = SDL_GetTicks();
printf("%d bpp\n",j*8);
printf("Time: %d\n",after-before);
printf("FPS: %d\n\n",1000*LOOPS/(after-before));
}
return 0;
}
megajocke
megajocke
quote:
Original post by lesmes
This is one of my test programs:



    
#include "SDL.h"
#include "SDL_main.h"
#include <stdlib.h>

#define LOOPS 100

int main(int argc,char *argv[])
{
int i,j;
Uint32 before,after;
SDL_Surface *screen;
SDL_Init(SDL_INIT_VIDEO);
atexit(SDL_Quit);

if (argc!=3)
{
perror("USE: main resx resy\n");
exit(0);
}

for (j=1;j<5;++j)
{
screen = SDL_SetVideoMode(atoi(argv[1]),atoi(argv[2]),8*j,SDL_HWSURFACE|SDL_DOUBLEBUF);
before=SDL_GetTicks();
for (i=0;i<LOOPS;++i)
SDL_Flip(screen);
after = SDL_GetTicks();
printf("%d bpp\n",j*8);
printf("Time: %d\n",after-before);
printf("FPS: %d\n\n",1000*LOOPS/(after-before));
}
return 0;
}




---------------------

The FPS will be limited by VSync, and you really don't want to go faster than that because of the tearing (why update the screen faster than it's shown?)

Joakim Asplund
http://megajocke.cjb.net

[edited by - megajocke on August 4, 2002 4:13:18 PM]

[edited by - megajocke on August 4, 2002 4:15:41 PM]
lesmes
lesmes
thanks

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.