We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 11

Summary: Optimized C 32bit RGB<->RGBA alpha masking blitters
Product: SDL Reporter: Ryan C. Gordon <icculus>
Component: videoAssignee: Ryan C. Gordon <icculus>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: codepro
Version: HG 1.2   
Hardware: All   
OS: All   
Attachments: optimized blitters patch

Description Ryan C. Gordon 2006-01-03 11:50:14 UTC
From: "Alex Volkov" <avcp-sdlmail@usa.net>
To: <sdl@libsdl.org>
Date: Thu, 8 Sep 2005 04:22:57 -0400
Subject: [SDL] [patch] Optimized C 32bit RGB<->RGBA alpha masking blitters

Hello, all. A couple patches here. I am new to the list so please forgive me
if there is a more suitable bugtracker somewhere that I could not find.

The first patch is not exactly relevant to the message subject -- it's just
to correct an error hidden by #ifdefs.
The second patch adds optimized C blitters for the 32 bit surfaces
(RGB<->RGBA) for the case where the R,G,B fields are the same on source and
destination. The selection conditions could be added to the normal_blit_4[]
table instead to replace the 'else if', but the variants of R,G,B fields are
many. Some MMX/SSE code would improve the speed, of course, but this is
already much better than doing BlitNtoN() for these cases.

Cheers!
Alex.
Comment 1 Ryan C. Gordon 2006-01-03 11:50:43 UTC
Created attachment 9 [details]
optimized blitters patch
Comment 2 Ryan C. Gordon 2006-01-04 15:48:29 UTC
I can't see how this patch's blitter ever gets called. If there's no alpha and the RGB masks match, SDL_CalculateBlit() will choose SDL_BlitCopy() at a higher level without calling SDL_CalculateBlitN(), where this patch's blitter would be chosen. If there is alpha, we'll end up in SDL_CalculateAlphaBlit().

Am I missing something here?

--ryan.


Comment 3 Alex Volkov 2006-01-04 17:49:14 UTC
The SDL_CalculateBlit() will never choose SDL_BlitCopy() because map->identity will never be set for such blits -- one surface has Amask and the other does not.

In the case of a RGBA->RGB blit, the blitter would be called when the source (RGBA) surface does not have SDL_SRCALPHA flag set. In this case, the blit_index would be 0 (assuming SDL_SRCOLORKEY is not there either), and SDL_CalculateAlphaBlit() would not get called.
Comment 4 Ryan C. Gordon 2006-01-05 11:41:09 UTC
Oh, I see. I had SRCALPHA set on the source surface, which prevented me from hitting this blitter.

I've updated SDL12/test/testblitspeed.c so I can exercise this codepath...this blitter is a little more than 3x faster than what it would otherwise use, which is pretty darned nice.  :)

I tweaked the patch so that it'll try to find a blitter in the normal_blit table first, though...this will let it fall into the Altivec blitters on PowerPC, which will probably beat this code, and future-proofs against an SSE (whatever) version being added later. It'll use this if we ended up with BlitNtoN as the blitter in the normal_blit table.

It's in CVS now, thanks!

--ryan.

Comment 5 Ryan C. Gordon 2006-01-27 11:23:02 UTC
Setting Sam as "QA Contact" on all bugs (even resolved ones) so he'll definitely be in the loop to any further discussion here about SDL.

--ryan.