I’m contemplating adding hardware acceleration support to SDL X11 video.
Keith Packard and I are talking about a direct pixmap access extension
to XFree86 so that touching video memory will not involve copying it over
the network, but even if that is the case, it may be possible to get fairly
good speed with purely sprite-based action games.
This would allow locking the video card accelerator and memory mapping
the video memory, but would still probably require root permissions for
systems without the framebuffer console set up.
The basic trade-off is still the same - if the screen surface gets in
video memory, then it is very fast to blit to, and copy to the screen,
but it is very slow to modify directly. The reason I hadn’t added
support for this before is that there’s no way to tell whether a pixmap
actually made it into video memory, and if it didn’t then you get the
very slow updates using XGetImage() and XPutImage(), without any of the
benefits of hardware acceleration. So many SDL applications rely on
being able to directly modify the screen surface (for alpha blending,
particle effects, etc.), that it hasn’t been worth it until now.
Anyway, the side-effect of this would be changing the semantics of
SDL_HWSURFACE to mean simply that the surface is in video memory, not
necessarily being the visible video memory. A new flag, SDL_HWVISIBLE
would imply that you are writing directly to the visible video memory.
I could use these semantics to allow blit hardware acceleration under
windowed DirectX as well.
How useful would this be to people?
I needed to write out all the semantics to keep things straight:===
There are a number of different video memory configurations available:
-
Display surface has SDL_HWSURFACE and SDL_DOUBLEBUF
In this configuration, you are writing to the non-visible page of the
video hardware. When you call SDL_Flip(), the hardware will wait for
the next vertical retrace, and then swap pages so that the previously
non-visible screen becomes visible.
This configuration is normally only available in fullscreen mode.
[Only available using the DGA 2.0 video driver in X11] -
Display surface has SDL_HWSURFACE and SDL_HWVISIBLE
In this configuration, you are writing to the visible video memory.
All drawing and blits become immediately visible.
This configuration is normally only available in fullscreen mode.
[Only available using the DGA 2.0 video driver in X11] -
Display surface has SDL_HWSURFACE
In this configuration, you are writing to an offscreen area of video
memory. Areas that you wish to become visible must be copied to the
visible video memory by using SDL_UpdateRects().
[Possibly available under X11 with the proposed extension] -
Display surface does not have SDL_HWSURFACE set
In this configuration, you are writing to an offscreen area of system
memory. Areas that you wish to become visible must be copied to the
visible video memory by using SDL_UpdateRects().
[Currently the only thing available under X11]
If you requested that the display surface reside in video memory, but the
resulting surface did not end up in video memory, it may be possible that
there was not enough spare video memory, the video driver does not support
direct video access, or some sort of format conversion is occurring.
If the display surface ended up in video memory, it is also possible to
have secondary surfaces in video memory. In general, you should create
your secondary surfaces as a single collection of multiple sprites, and
blit portions of that surface to the display surface. You should place
the largest and most frequently used artwork in video memory first, so
it is most likely to take advantage of accelerated blits.
Accessing video memory tends to be fairly slow. If you plan to change
pixels directly, or use a lot of unaccelerated blits, you should probably
create your display surface in system memory and perform rectangle updates
to video memory (via SDL_UpdateRects().)
====
Again, this is a tentative expansion of the current semantics.
Comments are welcome!
See ya,
-Sam Lantinga, Lead Programmer, Loki Entertainment Software