<?xml version="1.0" encoding="UTF-8"?>
<!-- $Header: /var/cvsroot/gentoo/xml/htdocs/doc/en/dri-howto.xml,v 1.26 2005/10/11 03:46:14 swift Exp $ -->
<!DOCTYPE guide SYSTEM "/dtd/guide.dtd">

<guide link="/doc/en/dri-howto.xml">
<title>Hardware 3D Acceleration Guide</title>
<author title="Author">
<mail link="spyderous@gentoo.org">Donnie Berkholz</mail>
</author>
<author title="Editor">
<mail link="peesh@gentoo.org">Jorge Paulo</mail>
</author>

<abstract>
This document is a guide to getting 3D acceleration working using X11-DRM 
with Xorg in Gentoo Linux.
</abstract>

<license/>

<version>1.0.14</version>
<date>2005-10-11</date>

<chapter>
<title>Introduction</title>
<section>
<title>What is hardware 3D acceleration and why do I want it?</title>
<body>

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

</body>
</section>
<section>
<title>How do I get hardware 3D acceleration?</title>
<body>

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

</body>
</section>
<section>
<title>What is DRI?</title>
<body>

<p>
The <uri link="http://dri.freedesktop.org/wiki/">Direct Rendering
Infrastructure</uri>, 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.
</p>

</body>
</section>
<section>
<title>What is X11-DRM and how does it relate to regular Xorg?</title>
<body>

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

</body>
</section>
<section>
<title>Purpose</title>
<body>

<p>
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 <uri link="http://dri.freedesktop.org/">DRI
homepage</uri> for more info and documentation.
</p>

</body>
</section>
<section>
<title>Feedback</title>
<body>

<p>
With suggestions, questions, etc., e-mail <mail 
link="spyderous@gentoo.org">Donnie Berkholz</mail>.
</p>

</body>
</section>
</chapter>

<chapter>
<title>Install Xorg and configure your kernel</title>
<section>
<title>Install Xorg</title>
<body>

<p>
Please read our <uri link="/doc/en/xorg-config.xml">Xorg Configuration
Guide</uri> to get Xorg up and running.
</p>

</body>
</section>
<section>
<title>Configure your kernel</title>
<body>

<p>
Probe for your chipset and enable just that one.
</p>

<pre caption="Checking your AGP chipset">
# <i>emerge pciutils; lspci | grep AGP</i>
# <i>00:01.0 PCI bridge: Intel Corp. 440BX/ZX/DX - 82443BX/ZX/DX AGP bridge (rev 03)</i>
<comment>(Your output may not match the above due to different hardware.)</comment>
</pre>

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

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

<pre caption="Configuring the kernel">
# <i>ls -l /usr/src/linux </i>
lrwxrwxrwx    1 root     root           22 May 29 18:20 /usr/src/linux -> linux-2.4.20-gentoo-r5
<comment>(Make sure /usr/src/linux links to your current kernel.)</comment>
# <i>cd /usr/src/linux</i>
# <i>make menuconfig</i>
</pre>

<pre caption="make menuconfig options">
Processor type and features ---&gt;
&lt;*&gt; MTRR (Memory Type Range Register) support
Character devices ---&gt;
&lt;M&gt; /dev/agpgart (AGP Support)
[*] Intel 440LX/BX/GX and I815/I820/I830M/I830MP/I840/I845/I850/I860 support
<comment>(Enable your chipset instead of the above.)</comment>
&lt; &gt; Direct Rendering Manager (XFree86 4.1.0 and higher DRI support)
</pre>

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

</body>
</section>
<section>
<title>Compile and install your kernel</title>
<body>

<pre caption="Compiling and installing kernel">
<comment>(This example is for a 2.4 kernel)</comment>
# <i>make dep &amp;&amp; make clean bzImage modules modules_install</i>
# <i>mount /boot</i>
# <i>cp arch/i386/boot/bzImage /boot</i>
</pre>

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

</body>
</section>
</chapter>

<chapter>
<title>Install X11-DRM and configure direct rendering</title>
<section>
<title>Install X11-DRM</title>
<body>

<pre caption="Installing X11-DRM">
# <i>emerge x11-drm</i>
</pre>

</body>
</section>
<section id="configure_xorg">
<title>Configure Xorg.conf</title>
<body>

<p>
Some chipsets require you to rebuild <c>xorg-x11</c> with 
<c>USE="insecure-drivers"</c>. 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.
</p>

<pre caption="Rebuilding xorg-x11">
# <i>vim /etc/portage/package.use</i>
<comment>(Add the following line if you use one of the abovementioned chipsets)</comment>
x11-base/xorg-x11 insecure-drivers

# <i>emerge xorg-x11</i>
</pre>

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

<pre caption="xorg.conf">
...
Section "Module"
  Load "dri"
  Load "glx"
  ...
EndSection
...
Section "Device"
  Driver "radeon"
  ...
EndSection
...
Section "dri"
  Mode 0666
EndSection
</pre>

<p>
If you are using a different driver, replace "radeon" with yours.
</p>

</body>
</section>
</chapter>

<chapter>
<title>Test 3D acceleration</title>
<section>
<title>Reboot to the new kernel</title>
<body>

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

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

</body>
</section>
</chapter>

<chapter>
<title>Using the CVS sources</title>
<section>
<body>

<warn>
Don't do this if the package worked.
</warn>

</body>
</section>
<section>
<title>Do you need the CVS?</title>
<body>

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

</body>
</section>
<section>
<title>Do the CVS sources support your card?</title>
<body>

<p>
Check the DRI <uri link="http://dri.freedesktop.org/wiki/Status">supported
cards list</uri> to see if the CVS supports your card. Even if it doesn't, but
it supports a similar card, try it.
</p>

<!-- I see a couple of 8x AGP stuff on the Internet about vanilla 2.4 kernels;
     is this now available or not? I've commented it out for the time being,
     hoping that this doesn't affect us :)

<warn>
"Linux 2.4 doesn't support agp 8x, so I had to go find a backport. The backport 
works .... it doesn't patch quite properly, and it requires 2.4.21 (I've only 
gotten it to work with vanilla, straight from the tarball (not ebuild)). First 
go get the 2.4.20-2.4.21 patch from kernel.org .... (then get the patch,) It 
was on a mailing list somewhere. It doesn't patch cleanly - - one file fails, 
the pci_ids.h file, but if you actually read the file and the reject list, it's
very easy to fix. But it does load, and it gives me 1600x1200 with video 
(although a bit slow b/c of lack of dga) with xfree-drm." (SanityInAnarchy on 
#gentoo)
</warn>

<impo>
The patch is a little tricky to work with but <uri 
link="http://www.ussg.iu.edu/hypermail/linux/kernel/0302.2/att-1618/01-agp3.diff.bz2">here's 
the link</uri>. If you can disable 8X AGP in your BIOS, change it to 4X and you 
may not need the patch.
</impo>
-->

</body>
</section>
<section>
<title>Follow the CVS Instructions</title>
<body>

<p>
The DRI project has a document about CVS compiling themselves. Please read <uri
link="http://dri.freedesktop.org/wiki/Building">the document</uri> and follow
the instructions up to the <e>Installing for X.org</e> part.
</p>

</body>
</section>
<section>
<title>Install the CVS</title>
<body>

<p>
Verify that the DRI kernel module(s) for your system were built:
</p>

<pre caption="Verification">
# <i>cd ~/DRI-CVS/build/xc/programs/Xserver/hw/xfree86/os-support/linux/drm/kernel; ls</i>
</pre>

<p>
For the 3dfx Voodoo, you should see <path>tdfx.o</path>. For the Matrox 
G200/G400, you should see <path>mga.o</path>. For the ATI Rage 128, you should 
see <path>r128.o</path>. For the ATI Radeon, you should see 
<path>radeon.o</path>. For the Intel i810, you should see <path>i810.o</path>. 
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.
</p>

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

<pre caption="Backing up Xorg">
# <i>quickpkg xorg-x11</i>
<comment>(This backs up your Xorg-X11 package.)</comment>
# <i>make install</i>
</pre>

<p>
Follow the "Configure Xorg" section above.
</p>

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

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

</body>
</section>
</chapter>

<chapter>
<title>Tweak your performance</title>
<section>
<title>Get the most out of direct rendering</title>
<body>

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

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

<p>
If you want to set even more features, check out the <uri
link="http://dri.freedesktop.org/wiki/FeatureMatrix">feature matrix</uri> on
the DRI web site or the <uri
link="http://dri.sourceforge.net/doc/dri_driver_features.phtml">features
listing</uri> on Sourceforge.
</p>

</body>
</section>
</chapter>

<chapter>
<title>Troubleshooting</title>
<section>
<title>It doesn't work. I just recompiled my kernel or switched to a new one.</title>
<body>

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

</body>
</section>

<section>
<title>It doesn't work. I don't have rendering, and I can't tell why.</title>
<body>

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

</body>
</section>
<section>
<title>When I startx, I get this error: "[drm] failed to load kernel module agpgart"</title>
<body>

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

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

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

</body>
</section>
<section>
<title>I have a Radeon, and I want TV-Out.</title>
<body>

<p>
Check out ati-gatos drivers. <c>emerge -s gatos</c>.
</p>

</body>
</section>
<section>
<title>It doesn't work. My card is so incredibly new and cool that it isn't supported at all.</title>
<body>

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

</body>
</section>
<section>
<title>I have a PCI card and it doesn't work.  Help!</title>
<body>

<p>
In section "Device" enable ForcePCIMode. 
</p>

<pre caption="Enabling ForcePCIMode">
Option "ForcePCIMode" "True"
</pre>

</body>
</section>
</chapter>

<chapter>
<title>Acknowledgments</title>
<section>
<body>

<ol>
  <li>
    Christopher Webber for suggesting a troubleshooting question about changing 
    or recompiling kernels
  </li>
  <li>
    Steve, for suggesting consistency between the cases of dri and DRI in 
    XF86Config
  </li>
</ol>

</body>
</section>
</chapter>

<chapter>
<title>References</title>
<section>
<body>

<ol>
  <li><uri>http://forums.gentoo.org/viewtopic.php?t=46681</uri></li>
  <li><uri>http://forums.gentoo.org/viewtopic.php?t=29264</uri></li>
  <li><uri>http://dri.freedesktop.org/</uri></li>
  <li><uri>http://www.retinalburn.net/linux/dri_status.html</uri></li>
</ol>

</body>
</section>
</chapter>
</guide>
