How to do a fast update?

first : can i use HWSURFACE and DOUBLEBUF in windowed mode ?
if yes : it doesn’t work with me :frowning:

when i make a video info, he says that i have 0Mo of video ram … and
that
hwsurface, blithw->sw, … are not available
and when i create the main surface with setvideomode, even if i ask
HWSURFACE
or DOUBLEBUF, i have none of them
why ?
(this result happen on many different computeurs, not only mine…)

My real problem :
In my program, SDL_updateRect of all screen is very very very slow
(maybe because
i haven’t hwsurface and doublebuf). How can i do if i want to make a
fast scrolling for my
game ?

first : can i use HWSURFACE and DOUBLEBUF in windowed mode ?
if yes : it doesn’t work with me :frowning:

when i make a video info, he says that i have 0Mo of video ram … and
that
hwsurface, blithw->sw, … are not available
and when i create the main surface with setvideomode, even if i ask
HWSURFACE
or DOUBLEBUF, i have none of them
why ?
(this result happen on many different computeurs, not only mine…)

My real problem :
In my program, SDL_updateRect of all screen is very very very slow
(maybe because
i haven’t hwsurface and doublebuf). How can i do if i want to make a
fast scrolling for my
game ?

The fastest blits are from hardware to hardware. If you set
SDL_HWSURFACE|SDL_DOUBLEBUF with SetVideoMode() you can check that it is
hardware by the video flags. If the back buffer is a hardware surface, and
the surface you are blitting is hardware too (sprite/tile/etc) you will
get very fast blitting (but only if you have support for
hardware-to-hardware blits).

You probably know this but just to clarify the following: software
surfaces are in the system’s main memory and hardware surfaces are in AGP
memory or VRAM. Knowing these facts can explain the performance
characteristics of the various blits.

Based on my understanding, here is the order of blits from fastest to
slowest. (assuming the implementation is in place to make them work)

  1. hardware -> hardware
  2. software -> software
  3. software -> hardware
  4. hardware -> software

To make a fast scrolling game you have to minimize the # of software to
hardware blits (when you have to do bus transactions to video memory ==
slow). One way to do this by caching frequently used tiles/sprites/etc in
hardware surfaces. For example, a certain tile may repeat many times on
the same frame. You can then transfer it to VRAM 1 time instead of however
many times it repeats on that frame, giving you big savings in the number
of bus transactions needed. To blit hardware->hardware you only have to
send a small amount of information telling the video card what to do. I
wrote a small app that does simple verticle scrolling. I found that if the
tiles & backbuffer where in software at 32 bit color, I got 20 fps. But
if all the surfaces are in hardware I get 300 fps!

There are some situations where you should not use hardware surfaces. If
your game needs to access pixels from the surface (for collision detection
etc), you are better off using a software surface (again, since the bus
transaction can cost millions of cycles to complete from VRAM).

AGP memory is kinda half-way between VRAM and main memory - you get not as
fast agp->vram blits but it’s not as slow reading pixels from agp.

Well, thats my 2 bits on the hardware/software blitting story…hope this
helps.

DarrellOn Wed, 8 Nov 2000, blavyl wrote:

i thank you very much for this informations, but i still have a problem :
when i ask SDL_HWSURFACE | SDL_DOUBLEBUF with setvideomode,
i can’t get them (not only on my computer…)
maybe i make something wrong… can you help me ?*************
here is what i use to test :

#include <stdio.h>
#include <SDL/SDL.h>

int main() {

SDL_Surface *s;
const SDL_VideoInfo *vi;

SDL_Init(SDL_INIT_VIDEO);

vi = SDL_GetVideoInfo();
printf(“hw available : %d\nblit hw-hw : %d\nblit sw-hw : %d\nvidmem :
%d\nbpp : %d \n”,
vi->hw_available,
vi->blit_hw,
vi->blit_sw,
vi->video_mem,
vi->vfmt->BitsPerPixel);

s = SDL_SetVideoMode(640, 480, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);

printf(“hwsurface : %d\ndoublebuf : %d\nflags : %d\n”,
(s->flags & SDL_HWSURFACE) == SDL_HWSURFACE,
(s->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF, s->flags);

return 0;
}


and this is the output :
hw available : 0
blit hw-hw : 0
blit sw-hw : 0
vidmem : 0
bpp : 32
hwsurface : 0
doublebuf : 0
flags : 0

(i test this with a voodoo5 , a matrox mystic 2 and some others… )

On Wed, 8 Nov 2000, blavyl wrote:

first : can i use HWSURFACE and DOUBLEBUF in windowed mode ?
if yes : it doesn’t work with me :frowning:

when i make a video info, he says that i have 0Mo of video ram … and
that
hwsurface, blithw->sw, … are not available
and when i create the main surface with setvideomode, even if i ask
HWSURFACE
or DOUBLEBUF, i have none of them
why ?
(this result happen on many different computeurs, not only mine…)

My real problem :
In my program, SDL_updateRect of all screen is very very very slow
(maybe because
i haven’t hwsurface and doublebuf). How can i do if i want to make a
fast scrolling for my
game ?

The fastest blits are from hardware to hardware. If you set
SDL_HWSURFACE|SDL_DOUBLEBUF with SetVideoMode() you can check that it is
hardware by the video flags. If the back buffer is a hardware surface, and
the surface you are blitting is hardware too (sprite/tile/etc) you will
get very fast blitting (but only if you have support for
hardware-to-hardware blits).

You probably know this but just to clarify the following: software
surfaces are in the system’s main memory and hardware surfaces are in AGP
memory or VRAM. Knowing these facts can explain the performance
characteristics of the various blits.

Based on my understanding, here is the order of blits from fastest to
slowest. (assuming the implementation is in place to make them work)

  1. hardware -> hardware
  2. software -> software
  3. software -> hardware
  4. hardware -> software

To make a fast scrolling game you have to minimize the # of software to
hardware blits (when you have to do bus transactions to video memory ==
slow). One way to do this by caching frequently used tiles/sprites/etc in
hardware surfaces. For example, a certain tile may repeat many times on
the same frame. You can then transfer it to VRAM 1 time instead of however
many times it repeats on that frame, giving you big savings in the number
of bus transactions needed. To blit hardware->hardware you only have to
send a small amount of information telling the video card what to do. I
wrote a small app that does simple verticle scrolling. I found that if the
tiles & backbuffer where in software at 32 bit color, I got 20 fps. But
if all the surfaces are in hardware I get 300 fps!

There are some situations where you should not use hardware surfaces. If
your game needs to access pixels from the surface (for collision detection
etc), you are better off using a software surface (again, since the bus
transaction can cost millions of cycles to complete from VRAM).

AGP memory is kinda half-way between VRAM and main memory - you get not as
fast agp->vram blits but it’s not as slow reading pixels from agp.

Well, thats my 2 bits on the hardware/software blitting story…hope this
helps.

Darrell

i thank you very much for this informations, but i still have a problem :
when i ask SDL_HWSURFACE | SDL_DOUBLEBUF with setvideomode,
i can’t get them (not only on my computer…)
maybe i make something wrong… can you help me ?


here is what i use to test :

#include <stdio.h>
#include <SDL/SDL.h>

int main() {

SDL_Surface *s;
const SDL_VideoInfo *vi;

Why is this const? It needs to be changed when SDL_GetVideoInfo returns a
new value! Not sure if this is your problem, but it looks suspicious. You
might also check that the directx driver is being used. (use
SDL_VideoDriverName() )On Thu, 9 Nov 2000, blavyl wrote:

i thank you very much for this informations, but i still have a problem :
when i ask SDL_HWSURFACE | SDL_DOUBLEBUF with setvideomode,

It’s not possible to set this up on some driver configurations. The most
common of these is X11 on Linux, and any non-fullscreen video mode.

See ya,
-Sam Lantinga, Lead Programmer, Loki Entertainment Software

Can someone clear this up for me?

Okay, I would like to create a double-buffered hardware surface. Does

SetVideoMode(SDL_HWSURFACE|SDL_DOUBLEBUF)

set this all up? Or do I have to explicitly create two surfaces?

A related issue: Say I create the surface its name is screen. I assume I’m
draw on surface A while B is displayed, then call SDL_Flip. Afterwards, is
surface pointing to B, so I can write to it while A is displayed?

And does the backbuffer always get cleared first? Can I prevent this to
improve performance, i.e. when I know the entire screen will be overdrawn
anyways?

On a side note: on my machine (Win2K, TNT2Ultra, DX7) SDL_LockSurface seems
to prevent me from drawing to the screen, even though SDL_MUSTLOCK returns
true, and SDL_LockSurface and SDL_UnlockSurface appear to have been
successful. Any suggestions, other than don’t lock it?

Brent Schartung

Can someone clear this up for me?

Okay, I would like to create a double-buffered hardware surface. Does

SetVideoMode(SDL_HWSURFACE|SDL_DOUBLEBUF)

set this all up? Or do I have to explicitly create two surfaces?

Yes, it sets it all up, however it’s not guaranteed to work in all environments,
so you need to check the flags of the returned surface. It tends to work if
you also set the SDL_FULLSCREEN flag, and you are working with the following
video drivers:
DirectX, framebuffer console, DGA 2.0, DrawSprockets

A related issue: Say I create the surface its name is screen. I assume I’m
draw on surface A while B is displayed, then call SDL_Flip. Afterwards, is
surface pointing to B, so I can write to it while A is displayed?

And does the backbuffer always get cleared first? Can I prevent this to
improve performance, i.e. when I know the entire screen will be overdrawn
anyways?

No, the backbuffer is not cleared, but remember that you won’t always get
a page-flipped video mode, so check for that.

On a side note: on my machine (Win2K, TNT2Ultra, DX7) SDL_LockSurface seems
to prevent me from drawing to the screen, even though SDL_MUSTLOCK returns
true, and SDL_LockSurface and SDL_UnlockSurface appear to have been
successful. Any suggestions, other than don’t lock it?

Very strange. What order are you doing the operations?
The correct order is:

lock
write pixels to surface
unlock
update screen (flip, updaterects, etc.)

See ya!
-Sam Lantinga, Lead Programmer, Loki Entertainment Software

“Sam Lantinga” wrote in message
news:E13xByC-0000L8-00 at roboto.devolution.com

Very strange. What order are you doing the operations?
The correct order is:

lock
write pixels to surface
unlock
update screen (flip, updaterects, etc.)

Also, note that blits to (or from) the surface should occur outside the
lock/unlock block.–
Rainer Deyke (root at rainerdeyke.com)
Shareware computer games - http://rainerdeyke.com
"In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor

Rainer Deyke wrote:

The correct order is:

lock
write pixels to surface
unlock
update screen (flip, updaterects, etc.)

Also, note that blits to (or from) the surface should occur outside the
lock/unlock block.

I’m sorry… can you explain me this point a little bit?
SDL_BlitSurface
locks the surface? Do I need to lock only when I access to the
surface->pixels array? (on a hw surface) or even If I use SDL_* to
access
the surface (if I load a bitmap directly to the visible surface,
for example)–
signed
derethor of centolos

Derethor wrote:

Rainer Deyke wrote:

The correct order is:

lock
write pixels to surface
unlock
update screen (flip, updaterects, etc.)

Also, note that blits to (or from) the surface should occur outside the
lock/unlock block.

I’m sorry… can you explain me this point a little bit?
SDL_BlitSurface
locks the surface? Do I need to lock only when I access to the
surface->pixels array? (on a hw surface) or even If I use SDL_* to
access
the surface (if I load a bitmap directly to the visible surface,
for example)

Locking/Unlocking is only for pixel access. The underlying api (DirectX, X11,
DGA, SVGAlib, GameSprokets, etc) can’t blit while the surface is locked for
pixel access. I don’t believe you have to lock the surface when loading a
bitmap (if anything like that needs to be done, I am sure the SDL would do it
for you). The documentation says you should minimize (or eliminate) all
system calls inbetween lock/unlock, because they may be holding back system
operations (so the system is waiting for an unlock and you are waiting for the
system) causing the program to freeze.

    -- David Snopek

The documentation says you should minimize (or eliminate) all
system calls inbetween lock/unlock, because they may be holding back system
operations (so the system is waiting for an unlock and you are waiting for the
system) causing the program to freeze.

Correct. Just a clarification: “system calls” above should be interpreted
as “SDL API calls”, not ordinary system calls to the operating system

The documentation says you should minimize (or eliminate) all
system calls inbetween lock/unlock, because they may be holding back system
operations (so the system is waiting for an unlock and you are waiting for the
system) causing the program to freeze.

Correct. Just a clarification: “system calls” above should be interpreted
as “SDL API calls”, not ordinary system calls to the operating system

Right, although I don’t recommend doing anything but raw pixel access
(and maybe disk access) between lock/unlock calls.

See ya!
-Sam Lantinga, Lead Programmer, Loki Entertainment Software