Hardware 3D Acceleration Guide Donnie Berkholz Jorge Paulo This document is a guide to getting 3D acceleration working using X11-DRM with Xorg in Gentoo Linux. 1.2 2006-02-01 Introduction
What is hardware 3D acceleration and why do I want it?

With hardware 3D acceleration, three-dimensional rendering uses the graphics processor on your video card instead of taking up valuable CPU resources drawing 3D images. It's also referred to as "hardware acceleration" instead of "software acceleration" because without this 3D acceleration your CPU is forced to draw everything itself using the Mesa software rendering libraries, which takes up quite a bit of processing power. While Xorg typically supports 2D hardware acceleration, it often lacks hardware 3D acceleration. Three-dimensional hardware acceleration is valuable in situations requiring rendering of 3D objects such as games, 3D CAD and modeling.

How do I get hardware 3D acceleration?

In many cases, both binary and open-source drivers exist. Open-source drivers are preferable since we're using Linux and open source is one of its underlying principles. Sometimes, binary drivers are the only option, like with nVidia's cards. Binary drivers include media-video/nvidia-kernel and media-video/nvidia-glx for nVidia cards, media-video/mgavideo for Matrox cards and media-video/ati-drivers for ATI cards. Other open-source drivers include media-video/kyro-kernel for KyroII cards and media-video/ati-gatos for ATI cards, which aim to support ATI's video capabilities more fully.

What is DRI?

The Direct Rendering Infrastructure, also known as the DRI, is a framework for allowing direct access to graphics hardware in a safe and efficient manner. It includes changes to the X server, to several client libraries and to the kernel. The first major use for the DRI is to create fast OpenGL implementations.

What is X11-DRM and how does it relate to regular Xorg?

X11-DRM is an enhancement to Xorg that adds 3D acceleration for cards by adding the kernel module necessary for direct rendering.

Purpose

This guide is for people who can't get direct rendering working with just Xorg. X11-DRM works for 3dfx, gamma, i8x0, matrox, rage128, radeon, mach64 and sis300 series drivers. See the DRI homepage for more info and documentation.

Feedback

With suggestions, questions, etc., e-mail Donnie Berkholz.

Install Xorg and configure your kernel
Install Xorg

Please read our Xorg Configuration Guide to get Xorg up and running.

Configure your kernel

Probe for your chipset and enable just that one.

# emerge pciutils; lspci | grep AGP
# 00:01.0 PCI bridge: Intel Corp. 440BX/ZX/DX - 82443BX/ZX/DX AGP bridge (rev 03)
(Your output may not match the above due to different hardware.)

If your chipset is not supported by the kernel you might have some succes by passing agp=try_unsupported as a kernel parameter. This will use Intel's generic routines for AGP support. To add this parameter, edit your bootloader configuration file!

Most, if not all, kernels should have these options. This was configured using gentoo-sources-2.4.20-r5.

# ls -l /usr/src/linux 
lrwxrwxrwx    1 root     root           22 May 29 18:20 /usr/src/linux -> linux-2.4.20-gentoo-r5
(Make sure /usr/src/linux links to your current kernel.)
# cd /usr/src/linux
# make menuconfig
Processor type and features --->
<*> MTRR (Memory Type Range Register) support
Character devices --->
<M> /dev/agpgart (AGP Support)
[M] Intel 440LX/BX/GX and I815/I820/I830M/I830MP/I840/I845/I850/I860 support
(Enable your chipset instead of the above.)
< > Direct Rendering Manager (XFree86 4.1.0 and higher DRI support)

Make sure the Direct Rendering Manager (DRM) is off. The X11-DRM package will provide its own.

Compile and install your kernel
(This example is for a 2.4 kernel)
# make dep && make clean bzImage modules modules_install
# mount /boot
# cp arch/i386/boot/bzImage /boot

If you want your kernel to be named something other than bzImage, be sure to copy to /boot/yourname instead. Don't forget to set up grub.conf or lilo.conf and run /sbin/lilo if you use LILO.

Install X11-DRM and configure direct rendering
Install X11-DRM
# emerge x11-drm
Configure Xorg.conf

Some chipsets require you to rebuild xorg-x11 with USE="insecure-drivers". This applies to mach64, unichrome and savage chipsets on xorg-x11-6.8.2, and to mach64 and unichrome on xorg-x11-6.8.99.x. Savage users should not try xorg-x11-6.8.99.x as support for the savage there is broken.

(Add the insecure-drivers USE flag if you use one of the aforementioned chipsets)
# echo "x11-base/xorg-x11 insecure-drivers" >> /etc/portage/package.use

# emerge xorg-x11

Open /etc/X11/xorg.conf with your favorite text editor and edit it to enable DRI and GLX.

...
Section "Module"
  Load "dri"
  Load "glx"
  ...
EndSection
...
Section "Device"
  Driver "radeon"
  ...
EndSection
...
Section "dri"
  Mode 0666
EndSection

If you are using a different driver, replace "radeon" with yours.

Changes to modules.autoload.d

You will need to add the module name that your card uses to /etc/modules.autoload.d/kernel-2.6 to ensure that the module is loaded automatically when the system starts up.

(Change module name as required.)
intel-agp
Test 3D acceleration
Reboot to the new kernel

Reboot your computer to your new kernel. It's time to see if you have direct rendering and how good it is.

# startx
(No need to load modules for your driver or agpgart, if you compiled agpgart as a module.)
(They will be loaded automatically.)
# glxinfo | grep rendering
direct rendering: Yes
(If it says "No," you don't have 3D acceleration.)
# glxgears
(Test your frames per second (FPS) at the default size. The number should be )
(significantly higher than before installing x11-drm. Do this while the CPU is as idle as possible.)
Using the CVS sources
Don't do this if the package worked.
Do you need the CVS?

First you have to check whether the x11-drm package works. If it doesn't and you have checked your logs to verify it's not a configuration error, you might want to consider the CVS sources. There are also daily driver snapshots available if you do not wish to build the full CVS.

Do the CVS sources support your card?

Check the DRI supported cards list to see if the CVS supports your card. Even if it doesn't, but it supports a similar card, try it.

Follow the CVS Instructions

The DRI project has a document about CVS compiling themselves. Please read the document and follow the instructions up to the Installing for X.org part.

Install the CVS

Verify that the DRI kernel module(s) for your system were built:

# cd ~/DRI-CVS/build/xc/programs/Xserver/hw/xfree86/os-support/linux/drm/kernel; ls

For the 3dfx Voodoo, you should see tdfx.o. For the Matrox G200/G400, you should see mga.o. For the ATI Rage 128, you should see r128.o. For the ATI Radeon, you should see radeon.o. For the Intel i810, you should see i810.o. If the DRI kernel module(s) failed to build, you should verify that you're using the right version of the Linux kernel. The most recent kernels are not always supported.

Install over your X.org installation. You may wish to back up xorg-x11.

# quickpkg xorg-x11
(This backs up your Xorg-X11 package.)
# make install

Follow the "Configure Xorg" section above.

To load the appropriate DRM module in your running kernel, copy the kernel module to /lib/modules/`uname -r`/kernel/drivers/char/drm/ then run modules-update and restart your X server. If you're not running the kernel you'll be using it in, instead of `uname -r`, use that kernel's name.

Make sure you first unload any older DRI kernel modules that might be already loaded. Note that some DRM modules require that the agpgart module be loaded first.
Tweak your performance
Get the most out of direct rendering

A few options may increase performance by up to 30 percent (or more) over the default. Set them in /etc/X11/xorg.conf.

Section "Device"
  Option     "AGPMode" "4"
  (This increased FPS from 609 to 618.)
  Option     "AGPFastWrite" "True"
  (This had no measurable effect, but it may increase instability of your computer.)
  (You may also need to set it in your BIOS.)
  Option     "EnablePageFlip" "True"
  (This improved FPS from 618 to 702. It also is "risky" but few people have reported problems.)
  ...
EndSection

If you want to set even more features, check out the feature matrix on the DRI web site or the features listing on Sourceforge.

Troubleshooting
It doesn't work. I just recompiled my kernel or switched to a new one.

Whenever you rebuild your kernel or switch to another kernel, you'll have to rebuild the kernel module. Note that you don't need to remerge xorg-x11, but you will need to remerge x11-drm.

It doesn't work. I don't have rendering, and I can't tell why.

Try insmod radeon before you start the X server. Also, try building agpgart into the kernel instead of as a module.

When I startx, I get this error: "[drm] failed to load kernel module agpgart"

That's because you compiled agpgart into the kernel instead of as a module. Ignore it unless you're having problems.

Direct rendering doesn't work, and in /var/log/Xorg.0.log I have an error about driver version too low.

You aren't using the x11-drm driver. Check if you compiled DRM and the driver into the kernel; you shouldn't have.

I have a Radeon, and I want TV-Out.

Check out ati-gatos drivers. emerge -s gatos.

It doesn't work. My card is so incredibly new and cool that it isn't supported at all.

Try out the binary drivers. For ati-drivers, a listing is at http://www.schneider-digital.de/html/download_ati.php. If those don't support it, use fbdev. It's slow, but it works.

I have a PCI card and it doesn't work. Help!

In section "Device" enable ForcePCIMode.

Option "ForcePCIMode" "True"
Acknowledgments
  1. Christopher Webber for suggesting a troubleshooting question about changing or recompiling kernels
  2. Steve, for suggesting consistency between the cases of dri and DRI in XF86Config
References
  1. http://forums.gentoo.org/viewtopic.php?t=46681
  2. http://forums.gentoo.org/viewtopic.php?t=29264
  3. http://dri.freedesktop.org/
  4. http://www.retinalburn.net/linux/dri_status.html