Hardware 3D Acceleration Guide (Англ.)

Ссылка на оригинал: http://www.gentoo.org/doc/en/dri-howto.xml

С версии: 1.0


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 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 x11-drivers/nvidia-drivers and x11-drivers/nvidia-legacy-drivers for nVidia 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. VIA card owners should not use x11-drm, but should instead use the DRI provided in recent kernels (>2.6.13). See the DRI homepage for more info and documentation.


Feedback


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


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


Code Listing 2.1: 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.2: 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.3: make menuconfig options

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


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


3. Install X11-DRM and configure direct rendering


Install X11-DRM


Code Listing 3.1: Installing 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.


Code Listing 3.2: Rebuilding xorg-x11

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


Code Listing 3.3: xorg.conf

...

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.


Code Listing 3.4: Editing /etc/modules.autoload.d/kernel-2.6

(Change module name as required.)

intel-agp


Note: If you compiled agpgart as a module, you will also need to add it to /etc/modules.autoload.d/kernel-2.6.



4. Test 3D acceleration


Reboot to the new kernel


Reboot your computer to your new kernel and login as a normal user. 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, even if you compiled them 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.)



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


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


Code Listing 5.2: Backing up Xorg

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

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/xorg.conf. However, you will first need to check that your motherboard and video card support these options.


First, let's see if your video card can support fast writes. We'll do this by closely inspecting the output from lspci. Specifically, we are looking at the "VGA compatible controller" information.


Code Listing 6.1: Video card check

# lspci -vv

01:00.0 VGA compatible controller: ATI Technologies Inc Radeon Mobility M6 LY (prog-if 00 [VGA])

. . .

Capabilities: [58] AGP version 2.0

Status: RQ=48 Iso- ArqSz=0 Cal=0 SBA+ ITACoh- GART64- HTrans- 64bit- FW+ AGP3- Rate=x1,x2,x4



While quite a lot of information is produced, we are looking for FW in the "Status" subsection of the AGP "Capabilities" section. If FW+ is present in the "Status" line, it means the card supports fast writes. We can now check if the motherboard supports fast writes.

Important: If you do not see FW+, but instead see FW-, you cannot enable fast writes in xorg.conf. Your card does not support fast writes.



Now let's make sure the motherboard supports fast writes as well. This time, look at the "Host bridge" section of your lspci output.


Code Listing 6.2: Motherboard check

# lspci -vv

00:00.0 Host bridge: Intel Corporation 82830 830 Chipset Host Bridge (rev 02)

. . .

Capabilities: [a0] AGP version 2.0

Status: RQ=32 Iso- ArqSz=0 Cal=0 SBA+ ITACoh- GART64- HTrans- 64bit- FW+ AGP3- Rate=x1,x2,x4



Again, examine the "Status" subsection of your AGP "Capabilities" section. Look for FW. If you see FW+, your motherboard supports fast writes.

Important: Remember, both your video card information and your motherboard information must show the same FW capability. If either device shows FW- in "Status", you cannot enable fast writes in xorg.conf.



Assuming that all has gone well and both your motherboard and video card support fast writes, let's enable this option in /etc/X11/xorg.conf and get the best performance out of your hardware.


Code Listing 6.3: 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


Warning: Enabling AGPFastWrite on a VIA chipset will very likely cause your machine to lock up. VIA chipsets do not play nicely with fast writes, so use this setting at your own risk.


Note: Remember, if you want fast writes to work properly, you will have to first enable the appropriate option in your BIOS.



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


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


Code Listing 7.1: Enabling ForcePCIMode

Option "ForcePCIMode" "True"



8. Acknowledgments

Christopher Webber for suggesting a troubleshooting question about changing or recompiling kernels

Steve, for suggesting consistency between the cases of dri and DRI in XF86Config


9. References