Alpha blit

Hi,

I’ve some performance problems with hardware alpha blitting (read: it crawls
when I use it with hardware surfaces) and I’ve seen others have too (I’m using
Windows (XP)). Note that I’m using SDL 1.2.4 because I’m doing the tests with
pygame (which uses 1.2.4), but I think that’s not the problem, keep reading.
Some have replied that may be caused by drivers not implementing it.

But after having given a quick look to SDL_dx5video.c, I have some doubts alpha
blitting is ever hardware accelerated…

Indeed, in DX5_UpdateVideoInfo, we have this:

if ( (DDCaps.dwCaps & DDCAPS_ALPHA) == DDCAPS_ALPHA ) {
	/* This is only for alpha channel, and DirectX 6
	   doesn't support 2D alpha blits yet, so set it 0
	 */
	this->info.blit_hw_A = 0;
}

So the caps is tested, but the flag is set to 0 whatever the card is able to do.
Also, the DX5_SetHWAlpha() function is implemented as “return -1;”, so when
DX5_HWAccelBlit() checks the alpha blit support:

if ( (src->flags & SDL_SRCALPHA) == SDL_SRCALPHA ) {
	if ( DX5_SetHWAlpha(this, src, src->format->alpha) < 0 ) {
		src->flags &= ~SDL_HWACCEL;
	}
}

the surface is flagged as not accelerated.

Finally, DX5_HWAccelBlit() uses the DirectDraw BltFast() function which is not
able to do alpha blitting, so… (maybe I should have started my explanations
with that !)

So, my questions:

Q1: is really the hardware alpha blit not supported or have I missed something ?
(note that I’m new to SDL, I’ve never used it)
Q2: if the answer to the first part of Q1 is yes, then is it only something that
has been missed, or is there some reasons for this ? I think that alpha blit was
supported by DX5 (at least DirectDraw::Blt() was and that’s the function one has
to use to blit with alpha), so it should be possible to have SDL supports it…
Q3: I may try to make a patch if it’s something to add, but keep in mind I know
nothing of SDL, so it could take some times

Thanks for your comments.

Popov wrote:

Hi,

I’ve some performance problems with hardware alpha blitting (read: it crawls
when I use it with hardware surfaces) and I’ve seen others have too (I’m using
Windows (XP)). Note that I’m using SDL 1.2.4 because I’m doing the tests with
pygame (which uses 1.2.4), but I think that’s not the problem, keep reading.
Some have replied that may be caused by drivers not implementing it.

But after having given a quick look to SDL_dx5video.c, I have some doubts alpha
blitting is ever hardware accelerated…

Indeed, in DX5_UpdateVideoInfo, we have this:

if ( (DDCaps.dwCaps & DDCAPS_ALPHA) == DDCAPS_ALPHA ) {
/* This is only for alpha channel, and DirectX 6
doesn’t support 2D alpha blits yet, so set it 0
*/
this->info.blit_hw_A = 0;
}

So the caps is tested, but the flag is set to 0 whatever the card is able to do.
Also, the DX5_SetHWAlpha() function is implemented as “return -1;”, so when
DX5_HWAccelBlit() checks the alpha blit support:

if ( (src->flags & SDL_SRCALPHA) == SDL_SRCALPHA ) {
if ( DX5_SetHWAlpha(this, src, src->format->alpha) < 0 ) {
src->flags &= ~SDL_HWACCEL;
}
}

the surface is flagged as not accelerated.

Finally, DX5_HWAccelBlit() uses the DirectDraw BltFast() function which is not
able to do alpha blitting, so… (maybe I should have started my explanations
with that !)

So, my questions:

Q1: is really the hardware alpha blit not supported or have I missed something ?
(note that I’m new to SDL, I’ve never used it)

No, alpha blitting is not accelerated.

Q2: if the answer to the first part of Q1 is yes, then is it only something that
has been missed, or is there some reasons for this ? I think that alpha blit was
supported by DX5 (at least DirectDraw::Blt() was and that’s the function one has
to use to blit with alpha), so it should be possible to have SDL supports it…

Well, if you know how to add this to the DirectX backend, it could be
supported very quickly. You’ll also need another pending fix I have to
fix problems related to hw accelerated alpha blits :
http://icps.u-strasbg.fr/~marchesin/sdl/sdl_alphafix.patch

Q3: I may try to make a patch if it’s something to add, but keep in mind I know
nothing of SDL, so it could take some times

I think it would be nice.
Now I don’t know why it was disabled in the first place. Maybe there’s
something preventing it from being supported. Or maybe that’s just the
fix I have that’s missing. I don’t know. Maybe the old timers could
answer this one…

Stephane