From Gentoo Wiki
< Xorg
Jump to:navigation Jump to:search
This page is a translated version of the page Xorg/Hardware 3D acceleration guide and the translation is 42% complete.
Outdated translations are marked like this.
Other languages:

This document is a guide to getting 3D acceleration working using the DRM with Xorg in Gentoo.


什么是硬件 3D 加速,我为什么需要它?

With hardware 3D acceleration, three-dimensional rendering uses the graphics processor on the 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 the 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.

获得 3D 加速

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, especially if the graphics card is so new that open source drivers have not yet been written to support its features. Binary drivers include x11-drivers/nvidia-drivers for NVIDIA cards and x11-drivers/xf86-video-ati (used to be x11-drivers/ati-drivers) for older AMD/ATI cards, dev-libs/amdgpu-pro-opencl for newer AMD cards.

什么是 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 Xorg server, to several client libraries and to the kernel. The first major use for the DRI is to create fast OpenGL implementations.

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

The DRM (Direct Rendering Manager) is an enhancement to Xorg that adds 3D acceleration for cards by adding the kernel module necessary for direct rendering.


本指南适用于无法仅使用 Xorg 进行直接渲染的人员。 DRM 适用于以下驱动程序:

有关更多信息和文档,请参阅 主页

安装 Xorg 并配置内核

安装 Xorg

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


Probe for the specifics of the relevant hardware.

root #emerge --ask sys-apps/pciutils
root #lspci | grep -Ei "VGA|AGP|3D"
# 00:01.0 PCI bridge: Intel Corp. 440BX/ZX/DX - 82443BX/ZX/DX AGP bridge (rev 03)

The output may not match the above due to different hardware, whatever is returned will help inform the user as to what kernel options to consider.

Certain kernel options will be required, others may cause problems. Hardware specific resources concerning which kernel option for which hardware exist within this wiki and elsewhere.

It is possible however unlikely that the given command returns nothing at all. In this case, the whole output of lspci -nnk would be a good bit of information to review and/or to pass along when seeking help.

In the given example, where the chipset is an AGP chipset, but a different one unsupported by the kernel, some success may be obtained by passing agp=try_unsupported as a kernel parameter. This will use Intel's generic routines for AGP support. To add this parameter, edit the bootloader's configuration file. Again, required kernel config options and available bootloader parameters will vary based on hardware specifics.

Before proceeding to change any kernel options, if necessary, make sure /usr/src/linux links to the intended kernel:

root #ls -dl /usr/src/linux*
lrwxrwxrwx  1 root root   19 Feb 16 16:30 /usr/src/linux -> linux-5.4.18-gentoo
drwxr-xr-x 27 root root 4096 Feb 16 21:27 /usr/src/linux-4.19.103-gentoo

确保 /usr/src/linux 链接到当前内核:

root #eselect kernel list
root #eselect kernel set
user $eselect kernel list


root #cd /usr/src/linux
root #make menuconfig
root #cd /usr/src/linux
root #make menuconfig

Most, if not all, kernels should have these options set. In any case, options labeled <M> are compiled as modules and loaded-as-necessary, thus being very unlikely to break anything if not required.

This was configured using a standard sys-kernel/gentoo-sources kernel.

内核 硬件 3D 加速选项
Processor type and features --->
<*> MTRR (Memory Type Range Register) support
Device drivers --->
   Graphics support --->
   <M> /dev/agpgart (AGP Support) --->
      (The agpgart option is not present on 64-bit kernels;
      just choose the appropriate chipset support.)
      <M> Intel 440LX/BX/GX, I8xx and E7x05 support
      (Enable the appropriate chipset instead of the above.)
   <M> Direct Rendering Manager (XFree86 4.1.0 and higher DRI support) --->
      <M> (Select the appropriate  graphics card from the list)


root #make && make install && make modules_install

不要忘记设置 grub.conflilo.conf

使用 LILO 时,执行:

root #lilo

使用 GRUB 2 时,运行:

root #grub-mkconfig -o /boot/grub/grub.cfg



root #gpasswd -a $USER video


配置 Xorg

Hopefully just adding the appropriate user to the video group is sufficient to enable direct rendering. However, Xorg may need some additional configuration via the /etc/X11/xorg.conf.d/ directory. New configuration files created in this directory may be named any alpha-numeric file name, as long as the file suffix ends in .conf. Open up a favorite text editor and create a file with this inside it:

文件 /etc/X11/xorg.conf.d/10-dri.conf
Section "Device"
  Driver "radeon"
Section "dri"
  Mode 0666

radeon 替换为相应驱动程序的名称。


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

文件 /etc/modules-load.d/video.conf
intel-agp # 用你的驱动替代
如果你将 agpgart 编译为模块,你还需要将其添加到 /etc/modules-load.d/video.conf

测试 3D 加速


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. glxinfo and glxgears are part of the x11-apps/mesa-progs package, so make sure it is installed before you attempt to run these commands.

user $startx

No need to load modules for your driver or agpgart, even if you compiled them as a module. They will be loaded automatically.

user $glxinfo | grep rendering
direct rendering: Yes

If it outputs "No", you don't have 3D acceleration.

user $glxgears

Test your frames per second (FPS) at the default size. The number should be significantly higher than before configuring DRM. Do this while the CPU is as idle as possible.

FPS may be limited by your screen's refresh rate, so keep this in mind if glxgears reports only about 70-100 FPS. games-fps/xonotic or other 3D games are better benchmarking tools, as they give you real-world performance results.

Get the most out of direct rendering

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



Try modprobe radeon before you start the X server (replace radeon with the name of your driver). Also, try building agpgart into the kernel instead of as a module.

Failed to load kernel module agpgart when running startx

error: "[drm] failed to load kernel module agpgart" after invoking startx is caused by presents of compiled agpgart in the kernel instead of as a module. Ignore it unless you're having problems.

TV-Out on Radeon GPU

The drivers originally developed by the GATOS project have been merged into Xorg's codebase. You don't need anything special for TV-Out; x11-drivers/xf86-video-ati will work just fine.

Compatibility for freshly released GPUs

Try out the binary drivers. For AMD cards, use ati-drivers. If those don't support it, use fbdev. It's slow, but it works.

PCI 卡不能正常工作

Create a config file in /etc/X11/xorg.conf.d/; name it anything you want as long as it ends in .conf. Add the following to it:

文件 /etc/X11/xorg.conf.x/10-pcimode.confAdding ForcePCI Mode
Section "Device"
  Option "ForcePCIMode" "True"


This page is based on a document formerly found on our main website gentoo.org.
The following people contributed to the original document: Donnie Berkholz (dberkholz) , peesh, nightmorph
They are listed here because wiki history does not allow for any external attribution. If you edit the wiki article, please do not add yourself here; your contributions are recorded on each article's associated history page.