SDL_Flip() behaviour .. (was: Re: [SDL] SDL_UpdateRect() question...)

David Olofson david.olofson at reologica.se
Wed Oct 10 15:00:02 PDT 2001


On Wednesday 10 October 2001 23:17, Trick wrote:
> > > If you update large portions of the screen it's probably better
> > > to use SDL_Flip(screen). Just be sure to pass SDL_DOUBLEBUF as a
> > > flag to SDL_SetVideoMode first. If double buffering is supported
> > > at the current diplay target, SDL_Flip flips the screen buffers,
> > > if it isn't, SDL_Flip is equivalent to SDL_UpdateRect on the
> > > whole screen. So, it works either way =) .
> >
> > Actually, if you care about performance *don't* do that. Check
> > whether or not you get a hardware back surface when asking for
> > SDL_DOUBLEBUF|SDL_HWSURFACE, and if not, use SDL_UpdateRects()
> > instead of SDL_Flip().
>
> Why ? Isn't pageflipping supposed to just flip the pointers to the
> pages beeing flipped ?

Yes, but if that isn't supported, you end up with a *full screen* 
sysRAM->VRAM blit on every flip... If you use SDL_UpdateRects(), at least 
you get speed similar to what you'd get on a target that supports 
hardware pageflipping.


> I understand that performance may suffer if
> SDL_Flip flips one hardware and one software surface, if it needs to
> READ from the video ram to get the current front buffer, but i don't
> see why SDL should be stupid enough to do that..

It isn't, but it's bad enough that it'll end up copying the *whole* 
buffer, although you may only have changed a few percent of the pixels. 
SDL can't help it as it doesn't have the necessary information - but you 
can provide that by using SDL_UpdateRects() instead.


> In those cases it's
> way better to just do a SW-SW flip, and then transfer the front
> buffer to VRAM. This way no performace is lost.

On the contrary, performance *is* lost, compared to updating only parts 
of the back buffer and the performing a hardware flip.


> So, i guess your point is that SDL doesn't do it this way. Since i
> answered that first "why" for you, here's another: Why ? =)
>
> Why doesn't SDL do it this way ? IMHO the extra memory needed for
> this is far less inconvenient than a broken flipping function.

Sure, but I'm talking about performance here - and unless you need to 
update the *whole* screen every frame, using SDL_Flip() may result in a 
significant performance loss if there's no h/w pageflipping.

It may not look like a big deal if you manage to avoid blitting 30% of 
the screen area, but keep in mind that sysRAM->VRAM blitting without 
busmaster DMA is *THE* major performance killer in 2D rendering - and 
it's the only options for some (possible the majority) of SDL targets.

A game that runs at several hundred fps when rendering into a sysRAM 
buffer can drop to 20-30 fps as soon as you try to display it's output. 
Yes, it really is that bad.


//David Olofson --- Programmer, Reologica Instruments AB

.- M A I A -------------------------------------------------.
|      Multimedia Application Integration Architecture      |
| A Free/Open Source Plugin API for Professional Multimedia |
`----------------------------> http://www.linuxdj.com/maia -'
.- David Olofson -------------------------------------------.
| Audio Hacker - Open Source Advocate - Singer - Songwriter |
`-------------------------------------> http://olofson.net -'




More information about the SDL mailing list