Enable and use open source radeon drivers in a muxless hybrid graphics (Intel/AMD) setup

Introduction

It should be no news to people who have been closely following the open source driver development that it was a hit and miss trying to enable radeon drivers. This tutorial might be useful to those users who have been unaware of how to enable dynamic gpu switching at runtime. Thanks to reddit user JackDostoevsky, who wrote the necessary steps to set it up, this tutorial was possible. This tutorial is just the re-iteration of that post. Read this post, if you want to follow the discussion. I have taken a more conservative approach of installation in this tutorial. If you want to checkout git versions, follow above discussion. In case of ubuntu, I am using 13.04 (linux 3.8) with xorg-edgers ppa. Performance wise in a game under wine, this setup was garbage. While in arch, I got better FPS compared to using just the Intel graphics card. Though the performance of native games were largely improved. Therefore in this case, newer versions of the driver and kernel packages are always better.

Step 1: Installation

Ubuntu

If you are using Ubuntu 13.04, and using catalyst driver uninstall it (Reset Everything). Also, if you have disabled AMD graphics card using vgaswitcheroo in (/etc/rc.loal), remove that line. Enable xorg-edgers ppa and update using following commands.

sudo add-apt-repository ppa:xorg-edgers/ppa 
sudo apt-get update
sudo apt-get dist-upgrade

Note: If you have been using intel graphics installer make sure to remove it, because it might interfere with vgaswitcheroo. Also, if you are on ubuntu 13.10 and above (see comments section), you don’t need to  enable this ppa to get the basic functionality that was added in linux 3.11 to enable switching. However, as I said above since development regarding radeon drivers and kernel (with amd driver features) is happening at a rapid rate, therefore if you want to experience the improvements as they happen, it is probably a good idea to enable this ppa for the graphics drivers.

Arch

If you have been using catalyst driver, remove it. Also make sure systemd-vgaswitcheroo-units service is disabled (systemctl disable vgaswitcheroo.service), if you had installed it to disable dgpu at boot. Update your installation (sudo pacman -Syu) and make sure ati-dri, xf86-video-ati, lib32-mesa, lib32-mesa-libgl, mesa-libgl, mesa-demos, libtxc_dxtn, lib32-libtxc_dxtn and lib32-ati-dri packages are installed in addition to the standard graphics packages.

On linux 3.11 and above, you can enable radeon.dpm=1 kernel parameter to enable dynamic power management.  Also JackDostoevsky notes that “DPM/power management process works significantly better in 3.12 than 3.11 — in 3.12 I get power management on par with Windows”. Therefore, definitely try out 3.12 to get better performance.

Edit: For newer kernels (kernel released in 2015), you no longer need to enable radeon.dpm using kernel parameter (at least in my test in Arch Linux). Since laptops have become quieter without the manual setup of vgaswitcheroo you can perform all the following steps without modifying your system. Just make sure ati drivers are installed, and you have composting enabled (as explained in the next section).

Step 2: Compositing

Make sure the window manager and desktop environment that you use have composting enabled. Standard gnome/cinnamon/unity has it enabled. If you are in xfce you can enable it from settings menu. If you are in LXDE, you can install a package called xcompmgr and enable it in ~/.config/lxsession/LXDE/autostart by adding following line.

@xcompmgr

Default location for LXDE autostart happens to be (/etc/xdg/lxsession/LXDE/autostart), but it did not work for me. Restart your computer (or display manager by properly logging out) for this to take effect.

Step 3: List both GPU providers

Make sure, both graphics cards are enabled. Login as root (sudo su) and read the contents of /sys/kernel/debug/vgaswitcheroo/switch file.

# cat /sys/kernel/debug/vgaswitcheroo/switch 
0:IGD:+: Pwr:0000:00:02.0
1:DIS: : Pwr:0000:01:00.0

Run following command and note the id’s of both providers. You could also just note the names of both providers (radeon and Intel in this case).

$ xrandr --listproviders
Providers: number : 2
Provider 0: id: 0x79 cap: 0xb, Source Output, Sink Output, Sink Offload crtcs: 2 outputs: 4 associated providers: 0 name:Intel
Provider 1: id: 0x53 cap: 0xf, Source Output, Sink Output, Source Offload, Sink Offload crtcs: 4 outputs: 0 associated providers: 0 name:radeon

If it shows only one provider something is wrong. In ubuntu, I found if I boot with AMD graphics card disabled and try to enable it afterwards, above command sometimes did not list both providers. Therefore, make sure you don’t disable amd graphics card using some scripts, or settings. Sometimes just not installing proper packages is the problem. If above command lists both provides then it is all good.

Step 4: Enable prime/optimus dynamic switching.

Run following command (with id’s or names noted above) to enable the switching. Above command listed 0x79 and 0x53 as id’s.

$ xrandr --setprovideroffloadsink 0x53 0x79

or

$ xrandr --setprovideroffloadsink radeon Intel

I think the second option is better, because re-installation of the OS resets the ids. After this step, if you prepend DRI_PRIME=1 environment variable command while running your application you force the graphical processing to AMD graphics card and the final composting to happen in intel graphics card. If you don’t use this variable, your application runs on default intel graphics card as it used to.

$ DRI_PRIME=1 yourapplicationname

E.g

$ DRI_PRIME=1 glxinfo | grep"OpenGL renderer"
$ DRI_PRIME=1 glxgears -info 
$ DRI_PRIME=1 wine somegame.exe
$ env DRI_PRIME=1 steam steam://rungameid/570

To make the process seamless, you can put the setprovideroffloadsink (above) command in the startup file like .bashrc (or create a .desktop file in ~/.config/autostart/ directory). You can learn about creating a .desktop file in my other post. To run an application create a script that prepends DRI_PRIME=1. E.g. (rungame.sh)

#!/bin/bash
DRI_PRIME=1 glxinfo | grep"OpenGL renderer"
DRI_PRIME=1 $1

After making above script executable (chmod +x rungame.sh) and adding it to PATH environment variable you can run your game by using the script.

$ rungame.sh "game-name"

As I said above, FPS in one of the games under wine was crap in ubuntu. For xonotic in ultra settings, I got 15 FPS in intel hd 3000, and it maintained 30+ FPS in AMD graphics card. One problem I had on Arch was that the computer turned off without any warnings (most probably overheating). Therefore watch closely the overheating issue. As the development progresses, some of the heating issues should be solved.

Also, one reason for overheating (because of the compact build of laptops) might be because of lack of space between the laptop and the vent (in addition to dust build up). If there is no space between the fan and the other blocking surface (e.g., bottom surface) (from where air flows in), as you progress in the game the gpu heats up, and there is no sufficient cool air to flow in. This in fact, heats up the whole environment to the side of the laptop from which air flows out. Result is, temperature gets above the max (85 degrees) pretty quickly reaches the critical point (100 degrees). At this point, the game is no more playable and computer is almost unusable (even turns off).

laptop with input fan at bottom

You can fix this issue by putting your laptop above a book or something that does not cover up the input vent. In my 2-3 hours gaming test temperature never went above 80 degrees and maintained a fairly playable FPS. When I exited the game, it came to 50 degrees just within 1 minute. You can also use external laptop fan while using heavy applications.

source:wikihow

source:wikihow

One strange but good thing I have with arch is I don’t have to enable AMD graphics card at boot (radeon.dpm=1). In newer versions, I don’t even install vgaswitcheroo service. The /sys/kernel/debug/vgaswitcheroo/switch shows the discrete (amd) card as DynOff and when it is used it shows ad DynOn as opposed to Pwr and Off as before. After boot I can just run the setprovideroffloadsink and run an application using DRI_PRIME=1.

If this is true (please test this).

This tutorial listed steps necessary for ubuntu and arch. In ubuntu installing ia32-libs installs all the 32-bit libraries necessary for radeon driver to work on 32-bit applications (In newer versions of ubuntu ia32-libs meta package does not exist, therefore you have to install the 32-bit libraries separately as explained in my catalyst driver installation posts for ubuntu). With this information, it should not be hard to set it up on other distributions too. Also, there is lot of development happening in newer kernels regarding dynamic power management and runtime GPU management. Look forward to those releases.

Tell me your experience, and Good Luck:) !!

22 Comments

Filed under Uncategorized

22 responses to “Enable and use open source radeon drivers in a muxless hybrid graphics (Intel/AMD) setup

  1. You sir, are a savior. Just to add to the discussion – this method works out of the box for the 13.10 beta with all upgrades and WITHOUT the xorg/edgers PPA. I can finally use my HD 8730m. Thanks a million.

  2. Hi. Ubuntu 13.10 64bits here. ATI HD6600M / Intel 3000
    I have enabled radeon.dpm=1 kernel parameter in Grub, too.
    Open source radeon driver is working with no fan problems, and a pretty good performance (almost 4.000 FPS glxgears; 30/120/120 fps SupertuxKart)
    Thank you very much!

  3. Know, i would only like that my 3D programs will be opened with the ATI card, by default.

    Any idea?

    • Assuming, you have executed the setprovider command.

      E.g If you want to execute tuxracer game on AMD card, you need to create a script file (lets say at /home/username/bin/tuxracer.sh) with following text (make it executable using chmod + x).

      DRI_PRIME=1 /usr/bin/tuxracer

      Now, all you have to do is either edit tuxracer .desktop file located at /usr/share/applications or copy the file inside /home/username/.local/share/applications directory, and change the Exec line to point to the script file like this.

      Exec=/home/username/bin/tuxracer.sh

      If you copy the desktop file to .local make sure to change Name, so you don’t confuse between the two versions.

      If the game is non-standard, you can use this tutorial to play more with the desktop file options.

      • Thanks! That’s the solution for me

        …but I think it would be a great idea to manage an automatic method somehow. I mean, a way to make the system reconize applications that need 3D acceleration.

      • Currently, I don’t know such solution in Linux. In windows, catalyst driver adds this option (open in high graphics mode etc).

        There was a talk (may be this one), where they were talking about that (for optimus/muxless setup like ours). May be it will come, when Wayland/Mir takes over X11 and frameworks/Window Managers decide which application to run using which gpu :)

  4. Hi, Do you have any solution for xrandr showing only one devide. I am actually using nvidia gpu, but I think it is relative. I have the quistion posted on fedora forums (“http://forums.fedoraforum.org/showthread.php?t=300306”), Please, if you have any solution, help me.
    Thank you.

  5. Hi! What should I do, if i can’t enable the discrete card (it says DynOff)? Here I wroted more about my problem… http://ubuntuforums.org/showthread.php?t=2304265

    • DRI_PRIME is the way to go with open source radeon driver. You can completely ignore vgaswitcheroo. Newer drivers should take care of the problem Linux had (turning on radeon driver from start), without vgaswitcheroo. In my case the radeon driver is off without vgaswitcheroo.

      Since you are getting the desired FPS with radeon driver, you don’t need to configure anything. However, to be on safe side, follow Step 3 of this tutorial (except the vgaswitcheroo part). As I said above, see whether your laptop starts fine without vgaswitcheroo (does not automatically turn on amd card, every time you start the computer).

      As for you getting the black screen, you need to understand how open source dual graphics card work specially intel+amd (see the muxless figure above). You need both graphics card for the amd graphics card to work. Therefore, switching one or the other is not the option. When you use DRI_PRIME=1, after setting the sink (if it does not work by default, see Step 3 above), you are instructing the graphics processing to happen in AMD card and after the image is constructed, it is forwarded to intel graphics card for display (as shown by the blue and red boxes in above figure). Therefore, if you have to run some application, use DRI_PRIME=1, and if it works thats fine.

      I have been able to play games that only works on AMD graphics card using this method. However, you have to understand that there are several OpenGL functions that are still not fully implemented in open source radeon drivers. See this page (http://mesamatrix.net/) for what is implemented, and check what your application needs.

      • Thank’s for reply)
        The problem is – I can’t use yout step 3 cause I’ve only 1 provider (intel). As I wrote above I have “DynOff” at discrete card as vgaswitcheroo says. So with DRI_PRIME the open gl goes faster for example in glxgears or glxheads, but GL_Render are still Intel in both case (dri_prime or just normal ). In My boot I don’t have an option to turn it ON or OFF (I mean card). I’ve only to choose “Fixed” or “Dynamic” wich is not working as well. In rc.local it returns only “exit 0” and grub have only runlevel 3 and “radeon.modeset=1” option. I’ve got 1 idea – what about if Xorg just doesn’t load the module as radeon. But as I know in 14.04 you can’t configure the xorg.conf – in my case it’s even not exist! I found the log file in /var/log/Xorg.0.log and there wasn’t any “radeon” So with help of this log i found the place with conf – /usr/share/X11/xorg.conf.d there is no xorg.conf but here some conf for drivers (I’ve got 20-intel.conf, but nothing with radeon conf…)
        And the last at /etc/modprobe.d there is some blacklist. so the radeonfb in blacklist as framebuffer…
        So I’m really confused and I’ve no idea how enable tis card. I can see it at the devices, but i can’t use it becase of.. i don’t know))

      • Discrete card should be in DynOff state, by default. When you run an application with DRI_PRIME=1 E.g.,

        $ DRI_PRIME=1 glxgears -info

        It should change the state to DynPwr. After quitting the application, quite often it changes back to DynPwr. Some time it takes longer time for the graphics fan to go off. When you run above command you should also get information about the driver currently in use in first few lines of the ouptput. In my computer the output looks like this.
        $ DRI_PRIME=1 glxgears -info
        Running synchronized to the vertical refresh. The framerate should be
        approximately the same as the monitor refresh rate.
        GL_RENDERER = Gallium 0.4 on AMD CAICOS (DRM 2.43.0, LLVM 3.7.0)
        GL_VERSION = 3.0 Mesa 11.0.6
        GL_VENDOR = X.Org

        1. Make sure you are using newer kernel (at least as old as specified in this post).
        2. If you are using new kernel, you don’t need to bother with radeon.modeset=1.
        3. Move (remove) radeonfb blacklist file
        4. When your desktop environment starts make sure you run xrandr --setprovideroffloadsink radeon Intel command in a startup file (You can add a desktop file in .config/autostart directory and call a script that runs this command).
        5. Before running step 4, make sure you are using a modern desktop environment (gnome, kde etc), otherwise you have to install and start a compositor before starting 4.
        6. When you search ‘radeon’ in /var/log/Xorg.0.log you have to get something like.
        [ 14585.599] (II) LoadModule: "radeon"
        [ 14585.599] (II) Loading /usr/lib/xorg/modules/drivers/radeon_drv.so
        [ 14585.613] (II) Module radeon: vendor="X.Org Foundation"

        7. Make sure, you have installed radeon xorg drivers properly (xserver-xorg-video-ati for ubuntu, and xf86-video-ati for arch).
        8. Check dmesg for radeon driver
        9. Make sure, you have proper binary for your radeon graphics card. In early days, I had to get the r600 binary for CAICOS separately.

  6. 1. kernel 3.19
    I added radeon.runpm=0 to /etc/default/grub and now I have the PWR on DIS but it still doesn’t switch witch switcheroo – blackscreen..
    4. xrandr returned just 1 provider (Intel)…
    5. I’m using Unity, so I don’t think that it’s not modern desktop…
    6. There is no ‘radeon’ in in /var/log/Xorg.0.log, just Intel…
    7,9 I’ve auto remove xserver-xorg-video-ati/radeon/intel and install it again. Without intel I have Unity without some graphic stuff like transparation etc. so i’ve added intel and now i have the same..
    8. here is my demsg
    dmesg | egrep ‘drm|radeon’
    [ 0.000000] Command line: BOOT_IMAGE=/vmlinuz-3.19.0-37-generic root=/dev/mapper/ubuntu–vg-root ro quiet splash radeon.runpm=0 vt.handoff=7
    [ 0.000000] Kernel command line: BOOT_IMAGE=/vmlinuz-3.19.0-37-generic root=/dev/mapper/ubuntu–vg-root ro quiet splash radeon.runpm=0 vt.handoff=7
    [ 9.852973] [drm] Initialized drm 1.1.0 20060810
    [ 9.886109] [drm] Memory usable by graphics device = 2048M
    [ 9.886115] fb: switching to inteldrmfb from VESA VGA
    [ 9.886219] [drm] Replacing VGA console driver
    [ 9.915213] [drm] Supports vblank timestamp caching Rev 2 (21.10.2013).
    [ 9.915217] [drm] Driver supports precise vblank timestamp query.
    [ 9.951494] fbcon: inteldrmfb (fb0) is primary device
    [ 9.951566] i915 0000:00:02.0: fb0: inteldrmfb frame buffer device
    [ 10.191019] [drm] Initialized i915 1.6.0 20141121 for 0000:00:02.0 on minor 0
    [ 10.980016] [drm] radeon kernel modesetting enabled.
    [ 11.507405] radeon 0000:01:00.0: enabling device (0000 -> 0003)
    [ 11.507769] [drm] initializing kernel modesetting (CAICOS 0x1002:0x6760 0x103C:0x1656).
    [ 11.507788] [drm] register mmio base: 0xC6500000
    [ 11.507790] [drm] register mmio size: 131072
    [ 11.546835] radeon 0000:01:00.0: VRAM: 1024M 0x0000000000000000 – 0x000000003FFFFFFF (1024M used)
    [ 11.546838] radeon 0000:01:00.0: GTT: 1024M 0x0000000040000000 – 0x000000007FFFFFFF
    [ 11.546840] [drm] Detected VRAM RAM=1024M, BAR=256M
    [ 11.546841] [drm] RAM width 64bits DDR
    [ 11.546923] [drm] radeon: 1024M of VRAM memory ready
    [ 11.546924] [drm] radeon: 1024M of GTT memory ready.
    [ 11.546936] [drm] Loading CAICOS Microcode
    [ 12.124086] [drm] Internal thermal controller with fan control
    [ 12.128949] [drm] radeon: dpm initialized
    [ 12.179943] [drm] GART: num cpu pages 262144, num gpu pages 262144
    [ 12.180853] [drm] PCIE gen 2 link speeds already enabled
    [ 12.183408] [drm] PCIE GART of 1024M enabled (table at 0x0000000000274000).
    [ 12.183526] radeon 0000:01:00.0: WB enabled
    [ 12.183529] radeon 0000:01:00.0: fence driver on ring 0 use gpu addr 0x0000000040000c00 and cpu addr 0xffff880158778c00
    [ 12.183532] radeon 0000:01:00.0: fence driver on ring 3 use gpu addr 0x0000000040000c0c and cpu addr 0xffff880158778c0c
    [ 12.185023] radeon 0000:01:00.0: fence driver on ring 5 use gpu addr 0x0000000000072118 and cpu addr 0xffffc900219b2118
    [ 12.185026] [drm] Supports vblank timestamp caching Rev 2 (21.10.2013).
    [ 12.185027] [drm] Driver supports precise vblank timestamp query.
    [ 12.185029] radeon 0000:01:00.0: radeon: MSI limited to 32-bit
    [ 12.185067] radeon 0000:01:00.0: radeon: using MSI.
    [ 12.185115] [drm] radeon: irq initialized.
    [ 12.201817] [drm] ring test on 0 succeeded in 2 usecs
    [ 12.201831] [drm] ring test on 3 succeeded in 7 usecs
    [ 12.377916] [drm] ring test on 5 succeeded in 2 usecs
    [ 12.377928] [drm] UVD initialized successfully.
    [ 12.378335] [drm] ib test on ring 0 succeeded in 0 usecs
    [ 12.378411] [drm] ib test on ring 3 succeeded in 0 usecs
    [ 13.024975] [drm] ib test on ring 5 succeeded
    [ 13.026989] [drm] Radeon Display Connectors
    [ 13.039687] radeon 0000:01:00.0: No connectors reported connected with modes
    [ 13.039692] [drm] Cannot find any crtc or sizes – going 1024×768
    [ 13.041709] [drm] fb mappable at 0xA0475000
    [ 13.041711] [drm] vram apper at 0xA0000000
    [ 13.041712] [drm] size 3145728
    [ 13.041713] [drm] fb depth is 24
    [ 13.041714] [drm] pitch is 4096
    [ 13.041806] radeon 0000:01:00.0: fb1: radeondrmfb frame buffer device
    [ 13.044611] [drm] Initialized radeon 2.40.0 20080528 for 0000:01:00.0 on minor 1

    Look’s like I don’t have missing radeon driver…

    • Yes the kernel seems to initialize the radeon driver. I don’t know why xrandr list provider does not show both cards. See this link and check if you are missing anything.

      • Finally, I’ve found the problem. When I just installed the Ubuntu – my bightness hotkeys didn’t change the brightnes screen, so I’ve change a bit the 20-intel.conf file. So now I removed from that file lines:
        Driver “intel”
        BusID “PCI:0:2:0”
        And now xradr list me 3 providers (don’t know why not 2) and DRI_PRIME=1 working!!

  7. Hi xpressrazor,
    Thank you for that great tuto. On my computer with Intel HD 5500 and Radeon R7 M265, that works fine, exept for opening videos :
    – When I open a video with vlc, it instantly craches with ‘Segmentation fault error (core dumped)’
    – When I open a video with totem, i have to resize the windows otherwise there is no image. And even if it works when I resize, I can’t open the totem menu, it is like it is “covered” by the video.
    – When I open a video with kaffeine, it works but the quality is not great, there is awful aliasing
    Do you know what is the problem ?
    I am under manjaro 16.06 and gnome 3.20.
    Thanks

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s