Skip to content

Instantly share code, notes, and snippets.

@Francesco149
Last active October 16, 2017 18:26
Show Gist options
  • Save Francesco149/c97dd9a6a2b47a162955170aa7785157 to your computer and use it in GitHub Desktop.
Save Francesco149/c97dd9a6a2b47a162955170aa7785157 to your computer and use it in GitHub Desktop.

Setting up ati/radeon acceleration on Sabotage Linux

With the recent addition of mesalib-radeon with gallium radeon drivers, many modern radeon gpu's are now fully supported with 3D acceleration.

Note that, while I have a working system with these radeon drivers, these guidelines are purely written from what I remember doing and are not tested on a clean install. Please report any mistakes or missing steps.

Installing the required packages

First of all, install xorg (and the default mesalib that comes with it) as usual:

butch install xorg

Now override mesalib with mesalib-radeon and install the radeon X11 driver:

butch install mesalib-radeon xf86-video-ati

Note: you can later switch back to default mesa with butch relink mesalib if you need to.

Since lxde straight up hardlocks and forces you to reboot if anything goes wrong with acceleration, I recommend testing with dwm until you're sure everything is working:

butch install dwm
nano /etc/xinitrc
# comment out or remove "exec startlxde" and add "exec dwm"

Also, make sure to install the latest firmware blobs as they will be needed in the next step:

butch install linux-firmware-git

We will also want the glx demos to confirm that acceleration is working:

butch install glxdemos

Firmware blobs

You need to provide the drivers with the correct firmware blobs for your specific card.

The easiest way is building them into the kernel.

Edit /src/KEEP/linux.config and find this setting:

CONFIG_EXTRA_FIRMWARE=""

Edit it to the list of firmware blobs you want to build into the kernel.

Then add this line right below it:

CONFIG_EXTRA_FIRMWARE_DIR="/lib/firmware"

You can find a table of the correct blobs for each GPU family and model at the gentoo wiki -> https://wiki.gentoo.org/wiki/Radeon#Firmware .

Example settings for my r9 270x (PITCAIRN):

CONFIG_EXTRA_FIRMWARE="radeon/pitcairn_ce.bin radeon/pitcairn_mc.bin radeon/pitcairn_me.bin radeon/pitcairn_pfp.bin radeon/pitcairn_rlc.bin radeon/pitcairn_smc.bin radeon/pitcairn_k_smc.bin radeon/TAHITI_uvd.bin radeon/TAHITI_vce.bin"
CONFIG_EXTRA_FIRMWARE_DIR="/lib/firmware"

Once that's done, rebuild the kernel (make sure your /boot partition is mounted before doing it!):

butch rebuild kernel

and reboot.

Starting Xorg

I don't recommend running stuff as root if you don't need to, so log out of root and into your user.

Also, make sure your user is in the video and tty groups (edit /etc/group if not).

Run startx. If dwm starts correctly, open a terminal with ALT+SHIFT+Enter and check that acceleration is indeed working:

LIBGL_DEBUG=verbose \
  glxinfo | egrep -i "direct|mesa|glamor|dri2|dri3"

You want to make sure:

  • direct rendering is yes
  • at least dri2 is supported
  • various mesa extensions are showing
  • opengl version is reasonable (3.3-3.0 for me)
  • it doesn't mention anything about software rendering
  • driver name is correct (radeonsi for me, other drivers include r600, r300, radeon, ...)

Don't worry about missing dri3 support and missing config file warnings, those aren't critical.

Other signs of broken acceleration can be low desktop resolution or non-native resolution and slow screen refreshing when opening terminals.

Run vblank_mode=0 glxgears to make sure 3D stuff is running smoothly, most cards should get thousands of FPS (terminal output).

You can also check /var/log/Xorg.0.log for errors or stuff related to software rendering.

If you're sure everything is working correctly, press Shift+CTRL+Q or just type killall Xorg to kill xorg, then edit /etc/xinitrc and change it back to exec startlxde or change it to whatever DE/WM you wish to use.

You can also add your desired start-up commands here, such as disabling mouse acceleration, setting up multiple monitors with xrandr, and so on. I personally like to put them in a separate script in /local and source it in xinitrc just in case xinitrc gets overwritten by installing packages or updating them.

You can also use ~/.xinitrc, but it will only apply to your current user.

You might also want to enable various options such as disabling forced vsync on some cards and enabling dri3 (boosts performance by ~25%) by creating a /share/X11/xorg.conf.d/10-device.conf with the following contents:

Section "Device"
    Identifier "ATI"
    Option "SwapbuffersWait" "0"
    Option "AccelMethod" "glamor"
    Option "DRI3" "1"
EndSection

Troubleshooting

If anything goes wrong, the first thing you should do is ensuring that the correct mesalib is linked:

butch relink mesalib-radeon

and try again. The links can easily get overwritten by updating the default mesalib or packages that depend on it. I personally completely uninstalled mesalib:

butch unlink mesalib
rm -rf /opt/mesalib
nano /share/lib/butch
# remove line with mesalib

If it still doesn't work and you're sure the correct mesa version is installed, try inspecting /var/log/Xorg.0.log for errors (search for EE and error).

It's very easy for modules to load out of order, so check /share/X11/xorg.conf.d/30-glamor.conf and /share/X11/xorg.conf.d/20-modules.conf to make sure glamoregl is always being loaded last, or only before radeon.

Example of working 20-modules.conf and 30-glamor.conf:

# 20-modules.conf

Section "Module"
    Load "exa"
    Load "wfb"

    Load "dri"
    Load "dri2"
    Load "glx"
    
    Load "int10"
    Load "vbe"
    Load "fb"
    Load "shadowfb"
    Load "shadow"
    Load "vgahw"
    Load "evdev"
    Load "fbdevhw"
EndSection
# 30-glamor.conf

Section "Module"
    Load "exa"
    Load "fb"
    Load "shadow"
    Load "vgahw"
    Load "glamoregl"
EndSection

Another place you can check is the output of dmesg | grep -i radeon or any word you think your gpu might show up as in logs. You can also grep for stuff like "drm".

Or simply read through all the output to see if you can spot any errors related to the GPU. If firmware blobs aren't loaded correctly, it will complain that DRI won't fully work and stuff like that.

This table on the gentoo wiki provides driver names for each GPU so you can grep for it: https://wiki.gentoo.org/wiki/Radeon#Installation

Unlocking clock rates on cards with quirks

The kernel throttles some specific radeon cards due to potential instability, including mine. This lowers clock speed by even 50%.

Some time ago I wrote a guide to get rid of these quirks: https://gist.github.com/Francesco149/0302fbb5e056f3339ae17d3c13257929

It's for ubuntu, but you can just copy /src/build/kernel to somewhere, cd into it and follow along with the edits.

Once you know which files you will be editing, you can init a git repo with the clean files so you can easily generate a patch file later:

git init
git add ./path/to/some/file.c
git commit -m "clean"
# ...
# do edits
# ...
git diff > kernel-disable-radeon-quirks.patch

You can then add this patch to the kernel package or make a copy of the kernel package with the patch. Just make sure it's applied after all the other patches.

Here's an example of applying the patch on sabotage for my r9 270x: https://github.com/Francesco149/sabotage/commit/73147e8f65b9311f366fd99bfa4b5ee82dd0d6cc

Note that you won't have the debug fs to check gpu clocks and force power levels unless you enable it in your kernel configuration, but you will likely be able to notice higher fps and louder fans in tests such as vblank_mode=0 glxgears .

Make sure to keep a backup boot entry with a clean kernel if you want to be safe, but you can always repair your system by chrooting from any live cd if the kernel stops booting.

I use this tweak and it yields up to 50% performance increase in most games and benchmarks.

Stability is actually unaffected, so the bug was probably solved a long time ago or it only affects specific hardware combinations.

In this bug report you can find users reporting various cards that benefit from this: https://bugs.freedesktop.org/show_bug.cgi?id=76490

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment