Why is Fract much slower under linux?


During the development of fract I noticed a performance difference between win32 and linux by a factor of two or more. After doing some research on this I found that X11 cannot create a "hardware" surface. Using a hardware surface to draw on is critical for the performance, because if the surface is "software", the memory-to-VRAM copy is VERY slow. This means, the benchmark would spend nearly 50% of the time in framebuffer flipping, which is totally unconnected with the rendering itself. I thought that something has to be done.

After a little googling I figured out two methods of resolving the problem:

1. Using DGA.

The DGA (Direct Graphics Access) X11 extension makes possible for the superuser to create hardware surfaces in fullscreen mode. DGA support is driver-specific and, with some drivers, may introduce lower framerates with DGA on. Note, that DGA may be unsupported and may even cause problems, e.g. resulting in system hang.

How to enable xfree86-dga:

  1. Open up your XFree (or X.org) configuration file. Find the line that contains "omit xfree86-dga". Comment it out (so that xfree86-dga is NOT omitted, and, thus, enabled).
  2. Restart the X.
  3. Open up a terminal window. If not running with superuser privileges, do a su before proceeding.
  4. Run fract with the following command line:

# env SDL_VIDEODRIVER=dga ./fract

2. Using YUV overlay

This will be used by default if fract is unable to obtain a hardware surface. In this case, it would check if your videocard supports hardware accelerated YUV surfaces (most videocards do). If not it falls back to "software" surface. Else it performs a few benchmarks to determine which is the fastest RGB-to-YUV conversion available. The conversion is usually fast, but it does cost time. Also, the YUV flip may be accelerated, but, with badly written drivers, it could be slower than real "surface flipping" under Windows.

Here's an example. I've got an ATI Radeon 9800 video adapter. The Windows version performs at 45 fps, while the Linux one (using the "radeon" driver) does only ~20 fps with software flipping and ~24 fps when using YUV overlay. The DGA is not helping.

Recently installed the ATI's closed source driver ("fglrx"). The "software" flipping version is faster, but still lags behind. Using DGA, I acheived 39 fps. Using overlay flipping I got 44 fps. Not bad?

Conclusion

So, if linux lags significantly, consider using the latest drivers available for your videocard.

Try using DGA, as YUV overlays usually result in coarser image quality. If you are a quality maniac you may explicitly tell fract not to use overlays, with --no-overlay option

If your driver incorrectly reports lack of hardware support for YUV overlays, use --force-overlay option.