Gentoo Logo
Gentoo Logo Side

Hardware 3D Acceleration Guide

Content:

1. 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 XFree86 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 (dri.sourceforge.net), 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 XFree-DRM and how does it relate to regular XFree86? 

XFree-DRM is an enhancement to XFree86 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 XFree. XFree-DRM works for 3dfx, gamma, i8x0, matrox, rage128, radeon, mach64 (as of xfree-drm-4.3.0-r7) and sis300 series drivers. Since the 2.4 kernels' Direct Rendering Manager (DRM) doesn't support XFree 4.3, the xfree-drm package is needed. If you're using a 2.6 kernel, its DRM supports XFree 4.3; Gentoo's XFree-DRM package is not yet working on 2.6 kernels. See the DRI homepage for more info and documentation.

Feedback 

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

2. Install XFree86 and configure your kernel

Install XFree86 

Code Listing 2.1: Installing XFree86

# emerge x11-base/xfree

Configure your kernel 

Probe for your chipset and enable just that one.

Code Listing 2.2: Checking your AGP chipset

# 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.

Code Listing 2.3: Configuring the kernel

# 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

Code Listing 2.4: make menuconfig options

Processor type and features --->
<*> MTRR (Memory Type Range Register) support
Character devices --->
<M> /dev/agpgart (AGP Support)
[*] 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 DRI support)

Make sure the Direct Rendering Manager (DRM) is off. The XFree-DRM package will provide its own. The 2.4 kernel's version is for XFree 4.2.

Compile and install your kernel 

Code Listing 2.5: Compiling and installing 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.

3. Install XFree-DRM and configure direct rendering

Install XFree-DRM 

Code Listing 3.1: Installing XFree-DRM

# ACCEPT_KEYWORDS="~x86" emerge xfree-drm

Configure XF86Config 

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

Code Listing 3.2: XF86Config

...
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.

4. 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.

Code Listing 4.1: Testing rendering

# 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 xfree-drm. Do this while the CPU is as idle as possible.

5. Using the CVS sources

Warning: Don't do this if the package worked.

Do you need the CVS? 

First you have to check whether the xfree-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 XFree86 or Installing for X.org part.

Install the CVS 

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

Code Listing 5.1: Verification

# 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 XFree86 or X.org installation. You may wish to back up xfree or xorg-x11.

Code Listing 5.2: Backing up XFree

# quickpkg xfree
// This backs up your XFree86 package.
# make install

Follow the "Configure XF86Config" 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.

Warning: 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.

6. 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/XF86Config.

Code Listing 6.1: XF86Config

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 features listing on the DRI Web site.

7. 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 xfree, but you will need to remerge xfree-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/XFree86.0.log I have an error about driver version too low. 

You aren't using the xfree-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.html. 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.

Code Listing 7.1: Enabling ForcePCIMode

Option "ForcePCIMode" "True"

8. 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

9. References

  1. http://forums.gentoo.org/viewtopic.php?t=46681
  2. http://forums.gentoo.org/viewtopic.php?t=29264
  3. http://dri.sourceforge.net/
  4. http://www.retinalburn.net/linux/dri_status.html

The contents of this document are licensed under the Creative Commons - Attribution / Share Alike license.
Print
line
Updated August 07, 2004
line
Donnie Berkholz
Author

Jorge Paulo
Editor

line
Summary:  This document is a guide to getting 3D acceleration working using XFree-DRM with XFree86 in Gentoo Linux.
line
The Gentoo Linux Store
line
Copyright 2001-2004 Gentoo Foundation, Inc. Questions, Comments, Corrections? Email [email protected].