Performance issues

Hi Folks,

I’m pretty new to video programming, but have many years of experience on embedded systems (mechanical control systems mostly).

Anyway, I’m writing a slot machine simulator, and am having problems getting performance out of the system. Basically, I’m using SDL_ BlitSurface to blit a portion of an image to a rectangle, and it’s pretty slow (800x600,16bpp,double-buffered).

Now, am I missing something? I have a background image, which I then place the aforementioned rectangle on. I don’t re-draw the background at all - just update the rectangle. Is this making any sense?

If someone can help, I’d appreciate it…

Thanks
Ed---------------------------------
Try the all-new Yahoo! Mail . “The New Version is radically easier to use” ? The Wall Street Journal

Hi,

have you done the usual stuff?

By that I mean, are you converting your surfaces
before displaying them?

http://www.libsdl.org/cgi/docwiki.cgi/SDL_5fDisplayFormat

Are you enabling hardware surfaces?

Cheers,
Paulo

Edward Byard wrote:> Hi Folks,

I’m pretty new to video programming, but have many years of experience
on embedded systems (mechanical control systems mostly).

Anyway, I’m writing a slot machine simulator, and am having problems
getting performance out of the system. Basically, I’m using SDL_
BlitSurface to blit a portion of an image to a rectangle, and it’s
pretty slow (800x600,16bpp,double-buffered).

Now, am I missing something? I have a background image, which I then
place the aforementioned rectangle on. I don’t re-draw the background at
all - just update the rectangle. Is this making any sense?

If someone can help, I’d appreciate it…

Thanks
Ed


Try the all-new Yahoo! Mail
http://us.rd.yahoo.com/mail/uk/taglines/default/nowyoucan/wall_st_2/*http://us.rd.yahoo.com/evt=40565/*http://uk.docs.yahoo.com/nowyoucan.html
. “The New Version is radically easier to use” ? The Wall Street Journal



SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

Edward Byard wrote:

Hi Folks,

I’m pretty new to video programming, but have many years of experience on embedded systems (mechanical control systems mostly).

Anyway, I’m writing a slot machine simulator, and am having problems getting performance out of the system. Basically, I’m using SDL_ BlitSurface to blit a portion of an image to a rectangle, and it’s pretty slow (800x600,16bpp,double-buffered).

Few relevant questions. Is this on an embedded system? How does you
hardware work (everything fits into video memory/screen control
blackbox/something else)? Are you sure this is really double-buffered
(in hardware, having flipping instead of copying)?

Now even more proper question is that is your installation SDL is
relying on? One big bad thing can be improper backend for SDL when you
have really things supported in hardware (for example for win32 you
would use win32 graphics backend instead of dx).

Now, am I missing something? I have a background image, which I then place the aforementioned rectangle on. I don’t re-draw the background at all - just update the rectangle. Is this making any sense?

Yes, this makes a sense. But in this case you should prefer always
SDL_UpdateRects() instead of SDL_Flip() (i assume you are using those
instead, right?) and single-buffer surface as you would still (most
probably, someone correct me if i am wrong?) need to call these
functions. Again, this depends on your installation.

And quotating another mail:

Paulo Pinto wrote:

By that I mean, are you converting your surfaces
before displaying them?

http://www.libsdl.org/cgi/docwiki.cgi/SDL_5fDisplayFormat

This conversion is relevant as it won’t need to do
conversion-on-blitting. Also I would recommend to use bitdepth 0 when
creating the primary surface (SDL_SetVideoMode()) which will stick to
system default, on some systems it has to emulate that certain bitdepth
and that won’t do any good for performance when calling SDL_Flip() or
SDL_UpdateRects().

Hope I could help you at least a bit…

  • – Kuisma
    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.4.4 (GNU/Linux)
    Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org

iD8DBQFE2EXuHIcMorDK+qsRAkekAJwM3b/jbc/PZ3nWqRfwksGg/kTb8QCfXkPd
6s6KagoPCA8vhHBMEKrGFQ4=
=xjAb
-----END PGP SIGNATURE-----

Yes I am using converted surfaces. I’m using hardware surfaces too. Forgot to mention I’m using SDL_image libs…

Here’s some code…

Screen = SDL_SetVideoMode(SCREEN_WIDTH,SCREEN_HEIGHT,16,SDL_HWSURFACE|SDL_DOUBLEBUF);

if (Screen==NULL)
{
    printf("Can't set video mode: ", SDL_GetError(), "\n");
    return 0;
}
// load up some graphics...LoadGraphic converts surfaces using SDL_DisplayFormat...

Background = LoadGraphic("graphics/bgnd.tga");
  Temp = LoadGraphic("graphics/strip.tga");
DrawImage(Background,0,0,SCREEN_WIDTH,SCREEN_HEIGHT,Screen,0,0,255);

                SDL_Rect DstRect;
                SDL_Rect SrcRect;
                DstRect.x = 165;
                DstRect.y = 245;
                DstRect.h = 100;
                DstRect.w = Graphic ->w;

                SrcRect.x = 0;
                SrcRect.y = Graphic ->h;
                SrcRect.h = 100;
                SrcRect.w = Graphic ->w;
                while (SrcRect.y!=-4)
                {
                    DrawImage(Graphic ,SrcRect.x,SrcRect.y,SrcRect.w,SrcRect.h,Screen,DstRect.x,DstRect.y,255);
                    SDL_UpdateRect(Screen,0,0,0,0);
                    SrcRect.y -= 4;
                }

…and this runs dead slow - I’m updating the Screen (which is also a Rect)

It’s not going to be anything stupid like frame rates is it? It’s going very slowly so I guessed not…I want it to just zoom by…not crawl…

Thanks
Ed

Paulo Pinto wrote: Hi,

have you done the usual stuff?

By that I mean, are you converting your surfaces
before displaying them?

http://www.libsdl.org/cgi/docwiki.cgi/SDL_5fDisplayFormat

Are you enabling hardware surfaces?

Cheers,
Paulo

Edward Byard wrote:> Hi Folks,

I’m pretty new to video programming, but have many years of experience
on embedded systems (mechanical control systems mostly).

Anyway, I’m writing a slot machine simulator, and am having problems
getting performance out of the system. Basically, I’m using SDL_
BlitSurface to blit a portion of an image to a rectangle, and it’s
pretty slow (800x600,16bpp,double-buffered).

Now, am I missing something? I have a background image, which I then
place the aforementioned rectangle on. I don’t re-draw the background at
all - just update the rectangle. Is this making any sense?

If someone can help, I’d appreciate it…

Thanks
Ed


Try the all-new Yahoo! Mail

. “The New Version is radically easier to use” ? The Wall Street Journal



SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


All new Yahoo! Mail “The new Interface is stunning in its simplicity and ease of use.” - PC Magazine

Kuisma, this isn’t an embedded system, it’s just a standard 1.5Ghz PC running Win2k.

Now even more proper question is that is your installation SDL is
relying on? One big bad thing can be improper backend for SDL when you
have really things supported in hardware (for example for win32 you
would use win32 graphics backend instead of dx).

Hmm - well I’m just using whatever is native to my SDL installation & system -
I’d prefer to keep DirectX or OpenGL out of the equation and just use whatever is
on the system…if you understand me. I’d like this game to just port to any PC running
Windows…

Thanks
Ed

Kuisma Salonen <kuisma.salonen at nokia.com> wrote: -----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

Edward Byard wrote:

Hi Folks,

I’m pretty new to video programming, but have many years of experience on embedded systems (mechanical control systems mostly).

Anyway, I’m writing a slot machine simulator, and am having problems getting performance out of the system. Basically, I’m using SDL_ BlitSurface to blit a portion of an image to a rectangle, and it’s pretty slow (800x600,16bpp,double-buffered).

Few relevant questions. Is this on an embedded system? How does you
hardware work (everything fits into video memory/screen control
blackbox/something else)? Are you sure this is really double-buffered
(in hardware, having flipping instead of copying)?

Now even more proper question is that is your installation SDL is
relying on? One big bad thing can be improper backend for SDL when you
have really things supported in hardware (for example for win32 you
would use win32 graphics backend instead of dx).

Now, am I missing something? I have a background image, which I then place the aforementioned rectangle on. I don’t re-draw the background at all - just update the rectangle. Is this making any sense?

Yes, this makes a sense. But in this case you should prefer always
SDL_UpdateRects() instead of SDL_Flip() (i assume you are using those
instead, right?) and single-buffer surface as you would still (most
probably, someone correct me if i am wrong?) need to call these
functions. Again, this depends on your installation.

And quotating another mail:

Paulo Pinto wrote:

By that I mean, are you converting your surfaces
before displaying them?

http://www.libsdl.org/cgi/docwiki.cgi/SDL_5fDisplayFormat

This conversion is relevant as it won’t need to do
conversion-on-blitting. Also I would recommend to use bitdepth 0 when
creating the primary surface (SDL_SetVideoMode()) which will stick to
system default, on some systems it has to emulate that certain bitdepth
and that won’t do any good for performance when calling SDL_Flip() or
SDL_UpdateRects().

Hope I could help you at least a bit…

  • – Kuisma
    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.4.4 (GNU/Linux)
    Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org

iD8DBQFE2EXuHIcMorDK+qsRAkekAJwM3b/jbc/PZ3nWqRfwksGg/kTb8QCfXkPd
6s6KagoPCA8vhHBMEKrGFQ4=
=xjAb
-----END PGP SIGNATURE-----_______________________________________________
SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


Copy addresses and emails from any email account to Yahoo! Mail - quick, easy and free. Do it now…

Can you share your code?

Thanks

— Edward Byard <e_byard at yahoo.co.uk> wrote:> Hi Folks,

I’m pretty new to video programming, but have many years of
experience on embedded systems (mechanical control systems mostly).

Anyway, I’m writing a slot machine simulator, and am having problems
getting performance out of the system. Basically, I’m using SDL_
BlitSurface to blit a portion of an image to a rectangle, and it’s
pretty slow (800x600,16bpp,double-buffered).

Now, am I missing something? I have a background image, which I then
place the aforementioned rectangle on. I don’t re-draw the background
at all - just update the rectangle. Is this making any sense?

If someone can help, I’d appreciate it…

Thanks
Ed


Try the all-new Yahoo! Mail . “The New Version is radically easier
to use” ? The Wall Street Journal>


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

Yes I am using converted surfaces. I’m using hardware surfaces too. Forgot to mention I’m using SDL_image libs…

Here’s some non-intuitive advice…
Try disabling hardware surfaces and double-buffering. :slight_smile:

-Sam Lantinga, Senior Software Engineer, Blizzard Entertainment

Hello !

When you are using Windows with DirectX you should, if possible
use only HW Surfaces. When you are not using Alpha Blending
this are the fastest blits you can get.

I don’t think SDL_DisplayFormat
really uses HW surfaces themself. So maybe you are not using
HW surfaces in reality. To really get HW Surfaces use SDL_CreateRGBSurfaces
with the HW Surface Flag and after that test them. Maybe after that
SDL_DisplayFormat is also needed.

Another thing to use DirectX in Windows
to make sure you are using DirectX set the env. SDL_VIDEODRIVER to directx

When you are using AlphaBlending it maybe faster to have
not only the two buffers in Video Memory, but also a blitting surface
where you blit to in normal memory. When doing Alpha Blending it
needs to read pixel values from source and dest. and Video Busses
are not designed for fast reading.

When you are using Doublebuffering use SDL_Flip, not SDL_UpdateRect.

CU

               while (SrcRect.y!=-4)
               {
                   DrawImage(Graphic ,SrcRect.x,SrcRect.y,SrcRect.w,SrcRect.h,Screen,DstRect.x,DstRect.y,255);
                   SDL_UpdateRect(Screen,0,0,0,0);
                   SrcRect.y -= 4;
               }

You are updating the entire screen during each pass in this loop!

Instead of SDL_UpdateRect(Screen,0,0,0,0), use the destination rectangle
returned by SDL_BlitSurface as it contains the part that need updating.

But simply changing the above to
SDL_UpdateRect(Screen, DstRect.x, DstRect.y, SrcRect.w, srcRect.h); should
give a nice speedup.On Tue, 8 Aug 2006, Edward Byard wrote: