SDL2.0 wish-list

my votes:
improve SDL blit performance

  • Auto-manage software back buffer surface for better
    performance on fullscreen hardware blits

That is, integrated “SemiTriple” buffering? Yeah, it would be handy
not having to create a shadow surface manually to get a s/w rendering
surface in combination with a page flipped h/w double buffer display.

However, though that would be trivial to implement, and would help in
some cases, it’s hard to figure out automatically when to use it.
On a backend, such as DirectDraw, where some blits (opaque and
colorkey, AFAIK) are h/w accelerated whereas others (alpha) are not,
it’s not as simple as one solution being faster than the other. It
depends entirely on what the application is doing.

Dropping all h/w acceleration just to deal with a small alpha
blended player sprite would result in a major performance drop on
DirectDraw, for example. Although alpha blitting to a h/w surface is
extremely expensive in itself, the full h/w acceleration you get for
other blits may be more than enough to make up for it in some
applications.

And if the application isn’t doing any alpha blending at all, there is
clearly no point in using a s/w shadow surface - especially not
without an extremely efficient dirty rect system, or constant full
screen scrolling.

  • Mechanism to handle dirty rectangles within SDL

That would be handy too, but I don’t think there is such a thing as a
fully generic dirty rect management algorithm that works well in all
situations. It’s of course possible to come up with something that’s
very efficient in terms of avoiding to update unchanged areas, but
any alorithm like that is bound to have (at least) three issues:

1) It's going to burn quite a few cycles, merging rects,
   calculating intersections, adjusting microtiles or whatever.

2) It's either going to generate lots of rectangles, or it'll
   update lots of unchanged pixels in some situations. (The
   number of rectangles may matter a lot to some backends.)

3) It's a total waste for full screen scrollers and other
   applications that don't need automatic dirty rects. In
   fact, it may even slow things down by getting in the way.

Right now its not “simple” to do well performing 2D in
SDL. Would be nice to free us of these complex chores.

Good point, but then again, it’s rarely simple to do anything fast.
The most effective optimizations are about exploiting the fact that
most applications need to deal only with a few specal cases.
Optimizing for the general case is about the hardest thing you can
do, if at all possible.

Well, there is one way to get “good performance” even in the general
case, though it’s not really about optimization at all: Full h/w
acceleration and just repainting the whole screen every frame. On any
reasonably current hardware, that’s fast, simple and handles pretty
much anything without side effects.

Without other side effects than that “Requires hardware accelerated
OpenGL, Direct3D or DirectFB” part, that is…

I think the stuff you mention is best done in add-on libs, or perhaps
in optional plugins of some form. It would be handy to be able to
plug such functionality in in between the SDL API and the backends,
but it’s not platform specific stuff, so it doesn’t really belong
in SDL at all, I guess. You need some info about the current video
subsystem set up, but that’s about it. You need a lot more info from
the application than from SDL to do a good job.

//David Olofson - Programmer, Composer, Open Source Advocate

.- Audiality -----------------------------------------------.
| Free/Open Source audio engine for games and multimedia. |
| MIDI, modular synthesis, real time effects, scripting,… |
`-----------------------------------> http://audiality.org -’
http://olofson.nethttp://www.reologica.se —On Saturday 26 February 2005 16.16, Jason Robertson wrote:

Being 100% thread-safe would be good! Passing some
sort of SDL instance pointer into every function would
go a long way toward having thread-safety.

Making every function re-entrant with mutexes and stuff would probably
just make it slower and harder to debug, and it wouldn’t fix the issue
that many of the underlying event systems and GUIs expect operations
to
happen in particular thread(s). I’m not really sure that would be a
win at all.

If some GUI is defective enough to require that operations happen
in a particular thread, simply document this limitation. Then the
app developers can judge for themselves whether or not that GUI is
worth supporting.

Mac OS X requires that all operations related to the GUI be serialized
to the main thread, with few exceptions.

Fine. Throw that in the documentation. Then only Apple is to blame.

The error handling code can at least be thread-safe, along with
anything else that doesn’t need to call into the OS.

Even the linear alpha blending in SDL is crude, it does it the "cheap"
way by dividing by 256, not 255. The Altivec patches I’m working on
do
correct linear alpha blending, but only if you have a PowerPC with
Altivec.

Correct, or simply not as horrible?

Correct means a lookup table. (or some very slow math!)

The algorithm I’m using is ((src * alpha) + (dst * (255 - alpha))) /
255. This is, by definition, correct linear alpha blending (at 8 bits
precision). Technically it’s implemented more like this:

tmp = (1 + (src * alpha) + (dst * (255 - alpha)))
res = (tmp + (tmp >> 8)) >> 8

But that is equivalent to dividing by 255 for every possible value you
could generate here [0, 255*255].

Slow math? My Altivec per-pixel alpha blit is not only correct, but is
several times faster than the incorrect scalar implementation. A
lookup table slows you down when your bottleneck isn’t the CPU.

Sorry, your math is wrong because the pixel data is not linear.
Composite white over black at 50% alpha. The result should be
around 190 to 195, not 127 to 128. Compare the dark grey you get
against the apparent grey (stand back a few feet) of an image
composed of thin horizontal black and white lines.

The correct operation, using a 0.0 … 1.0 scale for linear data:

unsigned char dst, src, res, alpha;
float linear_dst, linear_src, linear_res;

linear_dst = sRGB_to_linear(dst);
linear_src = sRGB_to_linear(src);
linear_res = ( linear_srcalpha + dst(255-alpha) ) * (1/255.0);
res = linear_to_sRGB(linear_res);

Optimize as desired, perhaps using 16-bit fractions instead
of floats, but you MUST have lookup tables if you want to work
on normal image data without using the pow() function.

The simple algorithm works only if the image data is linear.
This can be made to work; I certainly prefer it. Blits to the
screen would need to convert, as would operations that load
images from files. To maintain accuracy, you’d need at least
10 or 12 bits per channel when using linear data.On Sat, 2005-02-26 at 13:34 -0500, Bob Ippolito wrote:

On Feb 26, 2005, at 7:47 AM, Albert Cahalan wrote:

On Sat, 2005-02-26 at 00:40 -0500, Bob Ippolito wrote:

On Feb 25, 2005, at 11:48 PM, Albert Cahalan wrote:

Even the linear alpha blending in SDL is crude, it does it the
"cheap"
way by dividing by 256, not 255. The Altivec patches I’m working on
do
correct linear alpha blending, but only if you have a PowerPC with
Altivec.

Correct, or simply not as horrible?

Correct means a lookup table. (or some very slow math!)

The algorithm I’m using is ((src * alpha) + (dst * (255 - alpha))) /
255. This is, by definition, correct linear alpha blending (at 8 bits
precision). Technically it’s implemented more like this:

tmp = (1 + (src * alpha) + (dst * (255 - alpha)))
res = (tmp + (tmp >> 8)) >> 8

But that is equivalent to dividing by 255 for every possible value you
could generate here [0, 255*255].

Slow math? My Altivec per-pixel alpha blit is not only correct, but
is
several times faster than the incorrect scalar implementation. A
lookup table slows you down when your bottleneck isn’t the CPU.

Sorry, your math is wrong because the pixel data is not linear.
Composite white over black at 50% alpha. The result should be
around 190 to 195, not 127 to 128. Compare the dark grey you get
against the apparent grey (stand back a few feet) of an image
composed of thin horizontal black and white lines.

The correct operation, using a 0.0 … 1.0 scale for linear data:

unsigned char dst, src, res, alpha;
float linear_dst, linear_src, linear_res;

linear_dst = sRGB_to_linear(dst);
linear_src = sRGB_to_linear(src);
linear_res = ( linear_srcalpha + dst(255-alpha) ) * (1/255.0);
res = linear_to_sRGB(linear_res);

Optimize as desired, perhaps using 16-bit fractions instead
of floats, but you MUST have lookup tables if you want to work
on normal image data without using the pow() function.

The simple algorithm works only if the image data is linear.
This can be made to work; I certainly prefer it. Blits to the
screen would need to convert, as would operations that load
images from files. To maintain accuracy, you’d need at least
10 or 12 bits per channel when using linear data.

The math I used is correct by definition, and is the same algorithm you
are using in the above example minus the color space conversions. SDL
1.2.x does not have any concept of color spaces, especially non-linear
ones. You’re confusing two different problems. I was referring to the
fact that SDL’s scalar alpha blending algorithms aren’t correct by any
definition because they divide by 256 rather than 255, with a special
case for opaque pixels.

-bobOn Feb 26, 2005, at 2:03 PM, Albert Cahalan wrote:

On Sat, 2005-02-26 at 13:34 -0500, Bob Ippolito wrote:

On Feb 26, 2005, at 7:47 AM, Albert Cahalan wrote:

On Sat, 2005-02-26 at 00:40 -0500, Bob Ippolito wrote:

On Feb 25, 2005, at 11:48 PM, Albert Cahalan wrote:

The correct operation, using a 0.0 … 1.0 scale for linear data:

unsigned char dst, src, res, alpha;
float linear_dst, linear_src, linear_res;

linear_dst = sRGB_to_linear(dst);
linear_src = sRGB_to_linear(src);
linear_res = ( linear_srcalpha + dst(255-alpha) ) * (1/255.0);
res = linear_to_sRGB(linear_res);

Optimize as desired, perhaps using 16-bit fractions instead
of floats, but you MUST have lookup tables if you want to work
on normal image data without using the pow() function.

The simple algorithm works only if the image data is linear.
This can be made to work; I certainly prefer it. Blits to the
screen would need to convert, as would operations that load
images from files. To maintain accuracy, you’d need at least
10 or 12 bits per channel when using linear data.

The math I used is correct by definition, and is the same algorithm you
are using in the above example minus the color space conversions.

I’ll agree with “correct by definition” only if you’ll agree that
the code must never be used on normal image data. :slight_smile:

Calling the sRGB to/from linear conversions "color space conversions"
is a bit misleading. The black point, white point, and primaries all
remain the same. It’s really a gamma conversion, using the special
gamma curve defined by the sRGB standard. It’s not very different from
changing 5:6:5 data into 8:8:8 data; no out-of-gamut colors will ever
be produced.

Observe the lack of matrix operations and 3-D meshes in this
simple (unoptimized) conversion code:

// sRGB to linear
R = r / 255.0;
G = g / 255.0;
B = b / 255.0;
R = (R<=0.03928) ? R/12.92 : pow((R+0.055)/1.055,2.4);
G = (G<=0.03928) ? G/12.92 : pow((G+0.055)/1.055,2.4);
B = (B<=0.03928) ? B/12.92 : pow((B+0.055)/1.055,2.4);

That’s nothing like, for example, sRGB to YCbCr or CIE L,a*,b*.
What is normally thought of as a color space conversion will
involve horribly complicated stuff like dealing with out-of-gamut
values.

sRGB_to_linear is a simple table with 256 entries.

linear_to_sRGB is similar, but with more entries.
I’ve found 4096 entries to work very well.

SDL
1.2.x does not have any concept of color spaces, especially non-linear
ones. You’re confusing two different problems. I was referring to the
fact that SDL’s scalar alpha blending algorithms aren’t correct by any
definition because they divide by 256 rather than 255, with a special
case for opaque pixels.

Dividing by 256 is insignificant compared to the incorrect usage of
linear blending on non-linear data.On Sat, 2005-02-26 at 14:50 -0500, Bob Ippolito wrote:

On Feb 26, 2005, at 2:03 PM, Albert Cahalan wrote:

Hello Albert,

Selon Albert Cahalan :

That’s nothing like, for example, sRGB to YCbCr or CIE L,a*,b*.
What is normally thought of as a color space conversion will
involve horribly complicated stuff like dealing with out-of-gamut
values.

Your explanations are very interesting.

I knew something was wrong with alpha blending done the current way, but didn’t
knew the rational behind this. I saw this recently in a small painting program
I’m writing for my daughter (and in some old painting programs in the past).

I think we must keep in mind the basic purpose of SDL. It is a multimedia
library. Most applications written using it doesn’t care about wrong alpha
blending. Current implementation is enough to draw a nice antialised space ship
over a battlefield. Most applications don’t want sRGB conversion, since this
would mean a big drop in speed.

Of course, painting programs badly need accurate alpha blending and don’t care
that much about speed.

I see one way to handle this dilemna : implement a new
SDL_BlitSurfaceAccurateBlending() function that would use sRGB conversion. This
one would of course not be hardware accelerated, and so not recommended on
hardware surfaces.

Maybe this function would better fit an add-on lib than SDL itself…

Would it be enough for you ?

I think you can’t expect SDL to ever work internaly in sRGB for the reasons I
gave above.

Best regards,

Xavier

[…]

Current implementation is enough to draw a nice antialised space
ship over a battlefield. Most applications don’t want sRGB
conversion, since this would mean a big drop in speed.

Then again, there’s usually no h/w acceleration for alpha anyway, and
with RLE acceleration, AA sprites only depend on blending for the
edges.

Fixed Rate Pig uses AA for all sprites, and translucency for a good
deal of them at that, and still achieves frame rates in the thousands
with s/w rendering on my old P-III. I don’t think it would be an
issue if the alpha blending was a few times more expensive - though
it would probably rule out old Pentium and 486 machines.

Of course, painting programs badly need accurate alpha blending and
don’t care that much about speed.

They also tend to need a whole lot of other stuff, so I don’t really
see the point in having SDL deal with their specific problems. It’s
easy enough to do this in an add-on library.

However…

[…]

I see one way to handle this dilemna : implement a new
SDL_BlitSurfaceAccurateBlending() function that would use sRGB
conversion. This one would of course not be hardware accelerated,
and so not recommended on hardware surfaces.

…you can h/w accelerate this, and much more, with pixel shaders.
That way, you can do it properly while running in circles around the
current s/w blitters.

Of course, that won’t work on anything older than a GeForce 3 or
something, and it will only work on platforms with serious OpenGL or
Direct3D drivers…

Either way, it actually seems like some video cards implement, or at
least approximate this when doing normal alpha blending using some 3D
API. At least, blending with glSDL looks different on some cards and
drivers.

Maybe this function would better fit an add-on lib than SDL
itself…

Yes, but that really rules out h/w acceleration, unless SDL provides
some kind of low level backend API for such add-on libs to talk to.
And if such a thing is added, we risk get various add-on libs that
only support certain backends… Tricky stuff to get right.

//David Olofson - Programmer, Composer, Open Source Advocate

.- Audiality -----------------------------------------------.
| Free/Open Source audio engine for games and multimedia. |
| MIDI, modular synthesis, real time effects, scripting,… |
`-----------------------------------> http://audiality.org -’
http://olofson.nethttp://www.reologica.se —On Saturday 26 February 2005 23.04, Xavier Joubert wrote:

Hi David,

Selon David Olofson :

Fixed Rate Pig uses AA for all sprites, and translucency for a good
deal of them at that, and still achieves frame rates in the thousands
with s/w rendering on my old P-III. I don’t think it would be an
issue if the alpha blending was a few times more expensive - though
it would probably rule out old Pentium and 486 machines.

Don’t forget PC is not the only hardware SDL runs on… Mobiles phones are much
more limited.

Furthermore as I already wrote, no game coder ever complained about current
blending in SDL. So, why try to fix something that is not broken ?

I see one way to handle this dilemna : implement a new
SDL_BlitSurfaceAccurateBlending() function that would use sRGB
conversion. This one would of course not be hardware accelerated,
and so not recommended on hardware surfaces.
…you can h/w accelerate this, and much more, with pixel shaders.
That way, you can do it properly while running in circles around the
current s/w blitters.

I guess so, but since games don’t need it, and since painting programs don’t
need speed, why waste time ?

Xavier

Being 100% thread-safe would be good! Passing some
sort of SDL instance pointer into every function would
go a long way toward having thread-safety.

God, no.

Whether we break compatibility or not, let’s not guarantee that every
existing SDL app will need fixing.

–ryan.

I’ll second that. Good God NO!

	Bob PendletonOn Sat, 2005-02-26 at 01:12 -0500, Ryan C. Gordon wrote:

SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

The correct operation, using a 0.0 … 1.0 scale for linear data:

unsigned char dst, src, res, alpha;
float linear_dst, linear_src, linear_res;

linear_dst = sRGB_to_linear(dst);
linear_src = sRGB_to_linear(src);
linear_res = ( linear_srcalpha + dst(255-alpha) ) * (1/255.0);
res = linear_to_sRGB(linear_res);

Optimize as desired, perhaps using 16-bit fractions instead
of floats, but you MUST have lookup tables if you want to work
on normal image data without using the pow() function.

The simple algorithm works only if the image data is linear.
This can be made to work; I certainly prefer it. Blits to the
screen would need to convert, as would operations that load
images from files. To maintain accuracy, you’d need at least
10 or 12 bits per channel when using linear data.

The math I used is correct by definition, and is the same algorithm you
are using in the above example minus the color space conversions.

I’ll agree with “correct by definition” only if you’ll agree that
the code must never be used on normal image data. :slight_smile:

Calling the sRGB to/from linear conversions "color space conversions"
is a bit misleading. The black point, white point, and primaries all
remain the same. It’s really a gamma conversion, using the special
gamma curve defined by the sRGB standard.

Yes, it is gamma correction, and therefore is a separate operation from
alpha blending. Not even vaguely related. Since the rest of what you are
talking about is all based on your confusing alpha blending and gamma
correction, it is time to drop this subject.

	Bob PendletonOn Sat, 2005-02-26 at 14:50 -0500, Albert Cahalan wrote:

On Sat, 2005-02-26 at 14:50 -0500, Bob Ippolito wrote:

On Feb 26, 2005, at 2:03 PM, Albert Cahalan wrote:

It’s not very different from
changing 5:6:5 data into 8:8:8 data; no out-of-gamut colors will ever
be produced.

Observe the lack of matrix operations and 3-D meshes in this
simple (unoptimized) conversion code:

// sRGB to linear
R = r / 255.0;
G = g / 255.0;
B = b / 255.0;
R = (R<=0.03928) ? R/12.92 : pow((R+0.055)/1.055,2.4);
G = (G<=0.03928) ? G/12.92 : pow((G+0.055)/1.055,2.4);
B = (B<=0.03928) ? B/12.92 : pow((B+0.055)/1.055,2.4);

That’s nothing like, for example, sRGB to YCbCr or CIE L,a*,b*.
What is normally thought of as a color space conversion will
involve horribly complicated stuff like dealing with out-of-gamut
values.

sRGB_to_linear is a simple table with 256 entries.

linear_to_sRGB is similar, but with more entries.
I’ve found 4096 entries to work very well.

SDL
1.2.x does not have any concept of color spaces, especially non-linear
ones. You’re confusing two different problems. I was referring to the
fact that SDL’s scalar alpha blending algorithms aren’t correct by any
definition because they divide by 256 rather than 255, with a special
case for opaque pixels.

Dividing by 256 is insignificant compared to the incorrect usage of
linear blending on non-linear data.


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Xavier Joubert wrote:

Of course, painting programs badly need accurate alpha blending and don’t care
that much about speed.

Wrong. Accurate alpha blending is very important, yes, but speed is
also very important. There’s few things more frustrating than getting
line segments every time you try drawing a curve because the CPU can’t
keep up.

  • Gerry

Hi David,

Selon David Olofson <@David_Olofson>:

Fixed Rate Pig uses AA for all sprites, and translucency for a
good
deal of them at that, and still achieves frame rates in the
thousands
with s/w rendering on my old P-III. I don’t think it would be an
issue if the alpha blending was a few times more expensive -
though
it would probably rule out old Pentium and 486 machines.

Don’t forget PC is not the only hardware SDL runs on… Mobiles
phones are much more limited.

Good point.

Furthermore as I already wrote, no game coder ever complained about
current
blending in SDL. So, why try to fix something that is not broken ?

Right; correct blending should be an extra feature, not a replacement
for the current method. In fact, just replacing the current algorithm
would break lots of existing code/artwork that relies on the "broken"
blending.

I see one way to handle this dilemna : implement a new
SDL_BlitSurfaceAccurateBlending() function that would use sRGB
conversion. This one would of course not be hardware
accelerated,

and so not recommended on hardware surfaces.
…you can h/w accelerate this, and much more, with pixel
shaders.

That way, you can do it properly while running in circles around
the current s/w blitters.

I guess so, but since games don’t need it, and since painting
programs don’t need speed, why waste time ?

Right. And if you really want that kind of stuff (additive blending,
bump mapping and whatnot) + extreme performance, you should really
be talking directly to your 3D API of choice.

Same line of reasoning that makes me want to keep any non-SDL-2D
compliant features out of glSDL, basically; if you need more than a
quick way to speed up your SDL 2D code where OpenGL is available, you
should use OpenGL directly.

That said, this depends on where SDL is going. If the primary target
is to remain mainstream PC, console and similar hardware, I think
support for more advanced blending and transformations will be
required eventually. These features are accelerated by pretty much
anything already (even some handheld devices, it seems), and either
way, the CPU power of your average PC is on a level where even rather
generic s/w fallbacks can deliver playable performance in sensible
resolutions.

Either way, it might still be better to keep this advanced stuff -
that will only work on a few of the many supported platforms, at
least until your average cellphone will happily run Q3A at playable
framerates - in a “separate” lib, or at least as an optional module.
(It has to interact closely with the backend code, so it’ll probably
have to be maintained pretty much in parallel with SDL regardless.)

ARL - Advanced Rendering Layer…? :slight_smile:

I see two main uses for such a thing:
1) Advanced accelerated rendering on a few supported
targets, such as OpenGL and Direct3D.
2) Powerful toolkit for off-line and less performance
critical rendering, regardless of backend.

Of course, these two could be separated as well, creating one s/w
rendering module that deals only with the “public” SDL API, and one
Advanced Accelerated Rendering module, that pullls in the former for
s/w fallbacks, to avoid code duplication.

//David Olofson - Programmer, Composer, Open Source Advocate

.- Audiality -----------------------------------------------.
| Free/Open Source audio engine for games and multimedia. |
| MIDI, modular synthesis, real time effects, scripting,… |
`-----------------------------------> http://audiality.org -’
http://olofson.nethttp://www.reologica.se —On Sunday 27 February 2005 00.42, Xavier Joubert wrote:

Furthermore as I already wrote, no game coder ever complained about current
blending in SDL. So, why try to fix something that is not broken ?

Did they know to complain? As you yourself said in another post:

I knew something was wrong with alpha blending done the
current way, but didn’t knew the rational behind this.
I saw this recently in a small painting program I’m writing
for my daughter (and in some old painting programs in the past).

Understandably, the problem was a mystery to you. I don’t
recall that you reported the problem. Probably most people
write off the problem as “just some weird error”.

Games are definitely affected. Suppose I have an RT strategy
game, sort of like Warcraft or SimCity I guess. (you can tell
I’m not a gamer, huh?) Perhaps the player gets to drag stuff
(buildings, weaponry, etc.) from a toolbar to the world grid.
As he does so, his cursor may be a 50% opaque version of the
object. That won’t look right with current SDL blending.

Consider also icons in partially-transparent control overlays.
For example, an item (life juice, key, etc.) selection dialog
might drop down over the main display. It is nice to have the
dialog blending properly, as if it really were translucent.

Spaceship anti-aliasing is a poor example because of the black
background. Try airplanes against a normal daytime sky. With
bad alpha blending, you’ll get dark outlines around them.On Sun, 2005-02-27 at 00:42 +0100, Xavier Joubert wrote:

Xavier Joubert wrote:

Of course, painting programs badly need accurate alpha blending
and don’t care
that much about speed.

Wrong. Accurate alpha blending is very important, yes, but speed is
also very important.

Well, speed is always important, to some extent. At some point, an
application stops being interactive - and that will render some
applications completely unusable…

There’s few things more frustrating than
getting line segments every time you try drawing a curve because the
CPU can’t keep up.

Right, but that phenomenon is to be blamed on incorrect input event
handling. Events should be buffered internally, and/or the
applications should (preferably) try to optimize the rendering by
means of fast paths for chains of events, rather than doing the full
apply + refresh cycle for every event.

Another solution is to do the interactive rendering in "draft mode"
for instant feedback, and then implement the operation with full
quality on the actual image when the user releases the mouse button,
or hits “Render” or something. A small step towards structured
graphics, basically.

That said, it’s much nicer if you can actually see what you’re doing
while you’re doing it. :slight_smile:

//David Olofson - Programmer, Composer, Open Source Advocate

.- Audiality -----------------------------------------------.
| Free/Open Source audio engine for games and multimedia. |
| MIDI, modular synthesis, real time effects, scripting,… |
`-----------------------------------> http://audiality.org -’
http://olofson.nethttp://www.reologica.se —On Sunday 27 February 2005 03.25, Gerry wrote:

Calling the sRGB to/from linear conversions "color space conversions"
is a bit misleading. The black point, white point, and primaries all
remain the same. It’s really a gamma conversion, using the special
gamma curve defined by the sRGB standard.

Yes, it is gamma correction, and therefore is a separate operation from
alpha blending. Not even vaguely related. Since the rest of what you are
talking about is all based on your confusing alpha blending and gamma
correction, it is time to drop this subject.

I’m not confused. Perhaps you are? I hope you don’t wish to
simply pretend this problem doesn’t exist. I know it’s ugly
to fix, but it looks ugly on the screen too.

The situation:

a. All alpha blending must be done with linear (gamma==1.0) data.
Any other use of alpha blending is a serious bug.

b. All modern computer displays require non-linear (gamma!=1.0)
data by default; many are not configurable.

c. The vast majority of image files contain non-linear data.

Suppose I wish to do an alpha-blending blit to the screen.
In general, SDL is unable to correctly blit the image!

Various ways to deal with this:

a. Only use alpha==100% and alpha==0%. :slight_smile:

b. sRGB->linear on file load, and linear->sRGB to the screen
(so all in-memory buffers are linear)

c. alpha blend operation gets built-in gamma conversionOn Sat, 2005-02-26 at 18:48 -0600, Bob Pendleton wrote:

On Sat, 2005-02-26 at 14:50 -0500, Albert Cahalan wrote:

Then there is no need for an SDL 2.0 at all.
If the interface doesn’t change, the major
version number shouldn’t change either.

I suggest that you stick with SDL 1.x if you
like the existing interface. Why not? If it
has the interface you like, there is no need
for you to switch.On Sat, 2005-02-26 at 18:38 -0600, Bob Pendleton wrote:

On Sat, 2005-02-26 at 01:12 -0500, Ryan C. Gordon wrote:

Being 100% thread-safe would be good! Passing some
sort of SDL instance pointer into every function would
go a long way toward having thread-safety.

God, no.

Whether we break compatibility or not, let’s not guarantee that every
existing SDL app will need fixing.

–ryan.

I’ll second that. Good God NO!

[…]

Spaceship anti-aliasing is a poor example because of the black
background. Try airplanes against a normal daytime sky. With
bad alpha blending, you’ll get dark outlines around them.

Fixed Rate Pig uses SDL’s alpha blending for all sprites, and though
the effect is visible if you know what to look for, it’s not very
obvious, even against the lightest areas of the daytime sky
background. Looks a lot better than no AA, at least! Maybe I was just
lucky with the colors of the AA edge pixels?

(BTW, don’t even look at Kobo Deluxe. Most sprites and fonts have dark
outlines on purpose - even though you can rarely tell because of the
dark background. Doesn’t look all that great in some cases, but
that’s a different matter. :slight_smile:

//David Olofson - Programmer, Composer, Open Source Advocate

.- Audiality -----------------------------------------------.
| Free/Open Source audio engine for games and multimedia. |
| MIDI, modular synthesis, real time effects, scripting,… |
`-----------------------------------> http://audiality.org -’
http://olofson.nethttp://www.reologica.se —On Sunday 27 February 2005 03.44, Albert Cahalan wrote:

Mac OS X requires that all operations related to the GUI be serialized
to the main thread, with few exceptions.

We control main() on MacOS…we could always spin a thread that calls
SDL_main() and then reserve the real main thread for event queue
processing. Then SDL_PollEvents(), etc can grab a mutex before pulling
events from the internal queue that SDL maintains anyhow.

Don’t know if this would actually work, just thinking out loud here.

–ryan.

Mac OS X requires that all operations related to the GUI be
serialized to the main thread, with few exceptions.

We control main() on MacOS…we could always spin a thread that calls
SDL_main() and then reserve the real main thread for event queue
processing. Then SDL_PollEvents(), etc can grab a mutex before pulling
events from the internal queue that SDL maintains anyhow.

Don’t know if this would actually work, just thinking out loud here.

Ugh :slight_smile:

BTW: I’ve updated my Altivec patch
http://svn.red-bean.com/bob/SDL-altivec/trunk/ to include some 565
blits (32->565, 565->32, 32->565 pixel alpha)… I’m still looking for
software that needs anything else.

-bobOn Feb 27, 2005, at 6:09 AM, Ryan C. Gordon wrote:

Ugh :slight_smile:

I didn’t say it was pretty. :slight_smile:

But it would probably fix the thread safety issue without any noticable
change to any existing apps.

But, can someone confirm that there really IS a thread-safety issue on
the Mac? Or is it just a matter of not pumping the queue from two
threads at the same time? One is easy to serialize inside SDL, the other
would require a hack like the one I mentioned.

BTW: I’ve updated my Altivec patch
http://svn.red-bean.com/bob/SDL-altivec/trunk/ to include some 565
blits (32->565, 565->32, 32->565 pixel alpha)… I’m still looking for
software that needs anything else.

Nice. We should probably get this into the mainline CVS soon.

–ryan.

Ugh :slight_smile:

I didn’t say it was pretty. :slight_smile:

But it would probably fix the thread safety issue without any
noticable change to any existing apps.

But, can someone confirm that there really IS a thread-safety issue on
the Mac? Or is it just a matter of not pumping the queue from two
threads at the same time? One is easy to serialize inside SDL, the
other would require a hack like the one I mentioned.

AppKit is mostly NOT threadsafe. Drawing you can do in another
thread, holding the appropriate locks, but not much else.

BTW: I’ve updated my Altivec patch
http://svn.red-bean.com/bob/SDL-altivec/trunk/ to include some 565
blits (32->565, 565->32, 32->565 pixel alpha)… I’m still looking for
software that needs anything else.

Nice. We should probably get this into the mainline CVS soon.

Yeah, I would like some better tests for this stuff though. I’m not
entirely sure I’ve been able to test all of them. I’m not sure how to
benchmark any of the 16bit stuff. I’ve been using various applications
(Blob Wars, Frozen Bubble, Super Tux, Angry Drunken Dwarves) to test
the correctness of the blits, not really an exact science by any
means… There may be a blit or two that I have implemented but never
been able to get an application to cover it.

I made a couple improvements to the code that you wrote that you might
be interested in if you end up writing Altivec stuff in the future. The
big one is that I’m using 15 as the constant for the overflow vector
load, so it doesn’t need to overcompensate for overrun since you’re
guaranteed not to stomp on a bad page. This is what Apple recommends.

Should I be asking someone for CVS access, or is somebody else going to
maintain this code?

-bobOn Feb 27, 2005, at 6:27 AM, Ryan C. Gordon wrote: