The fastest way to do a SDL_BlitSurface()

Which is the fastest way?

  1. Blit a SDL_Surface with HW_SURFACE to a SDL_Surface with HW_SURFACE set.
  2. Blit a SDL_Surface with SW_SURFACE to a SDL_Surface with HW_SURFACE set.

if 1: Is it always best to have all my sprites (SDL_Surface’s) in
HW_SUFACE’s?
else: Why?

Which is the fastest way?

  1. Blit a SDL_Surface with HW_SURFACE to a SDL_Surface with HW_SURFACE set.
  2. Blit a SDL_Surface with SW_SURFACE to a SDL_Surface with HW_SURFACE set.

The first should always be faster for copy blits - if not, the driver
should not have let you create hardware surfaces in the first place.
For alpha blits it depends whether the driver accelerates them.
If not, it’s generally the case that

SWSURFACE onto SWSURFACE is faster than
SWSURFACE_onto HWSURFACE is faster than
HWSURFACE onto HWSURFACE

since access to video memory is usually slower than RAM, and alpha blits
imply read-modify-write operations (the source is read, and the destination
is both read and written, making you pay the latency several times for
each pixel).

Of course, if you blit to a SWSURFACE you have to transport the result
to the video memory sooner or later anyway, but if you do a lot of
alpha blending it might be worth the effort. The competent programmer
will always try and benchmark the alternatives when it matters. :slight_smile:

It would be nice to have a way of knowing what operations will be
accelerated by hardware, so a game could decide whether to use an
intermediary software surface for alpha blending or target vidmem
directly. Though in general I want to keep this sort of enquiries to
a minimum - ideally SDL should automatically give the programmer
the best surface for the task, so a binary should work unchanged
on a platform with different acceleration.

In a program I wrote, I have the program bench at the start the speeds
for certain types of blits and other memory access stuff, then have the
program change the function it uses at initialization to blit or load
bitmaps. What might bench the fastest on your system, might not be the
fastest on another system. Especially with SDL which can run on so many
different systems in many different configurations.

http://www.mongeese.orgOn Tue, 3 Oct 2000, Mattias Engdegard wrote:

Which is the fastest way?

  1. Blit a SDL_Surface with HW_SURFACE to a SDL_Surface with HW_SURFACE set.
  2. Blit a SDL_Surface with SW_SURFACE to a SDL_Surface with HW_SURFACE set.

The first should always be faster for copy blits - if not, the driver
should not have let you create hardware surfaces in the first place.
For alpha blits it depends whether the driver accelerates them.
If not, it’s generally the case that

SWSURFACE onto SWSURFACE is faster than
SWSURFACE_onto HWSURFACE is faster than
HWSURFACE onto HWSURFACE

since access to video memory is usually slower than RAM, and alpha blits
imply read-modify-write operations (the source is read, and the destination
is both read and written, making you pay the latency several times for
each pixel).

Of course, if you blit to a SWSURFACE you have to transport the result
to the video memory sooner or later anyway, but if you do a lot of
alpha blending it might be worth the effort. The competent programmer
will always try and benchmark the alternatives when it matters. :slight_smile:

It would be nice to have a way of knowing what operations will be
accelerated by hardware, so a game could decide whether to use an
intermediary software surface for alpha blending or target vidmem
directly. Though in general I want to keep this sort of enquiries to
a minimum - ideally SDL should automatically give the programmer
the best surface for the task, so a binary should work unchanged
on a platform with different acceleration.