~kissiel/checkbox/migrate-from-make

« back to all changes in this revision

Viewing changes to providers/plainbox-provider-checkbox/bin/graphics_env

"automatic merge of lp:~pierre-equoy/checkbox/AMD-hybrid-graphics-xenial/ by tarmac [r=sylvain-pineau][bug=][author=pierre-equoy]"

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/bash
 
2
# This script checks if the submitted VIDEO resource is from AMD and if it is
 
3
# a discrete GPU (graphics_card_resource orders GPUs by index: 1 is the
 
4
# integrated one, 2 is the discrete one).
 
5
#
 
6
# This script has to be sourced in order to set an environment variable that
 
7
# is used by the open source AMD driver to trigger the use of discrete GPU.
 
8
 
 
9
VENDOR_SLUG=$1
 
10
INDEX=$2
 
11
UBUNTU_CODENAME=`lsb_release -c | awk {'print $2'}`
 
12
 
 
13
# We only want to set the DRI_PRIME env variable on Xenial (16.04) systems
 
14
# running more than 1 GPU.
 
15
if [[ $UBUNTU_CODENAME == "xenial" ]]; then
 
16
    NB_GPU=`cat /var/log/gpu-manager.log | grep "How many cards?" | awk {'print $NF'}`
 
17
    if [ $NB_GPU -gt 1 ]; then
 
18
        if [[ $VENDOR_SLUG == *AMD* ]]; then
 
19
            if [ $INDEX -gt 1 ]; then
 
20
                # See https://wiki.archlinux.org/index.php/PRIME
 
21
                echo "Setting up PRIME GPU offloading for AMD discrete GPU"
 
22
                PROVIDER_ID=`xrandr --listproviders | grep "Sink Output" | awk {'print $4'} | tail -1`
 
23
                SINK_ID=`xrandr --listproviders | grep "Source Output" | awk {'print $4'} | tail -1`
 
24
                xrandr --setprovideroffloadsink ${PROVIDER_ID} ${SINK_ID}
 
25
                export DRI_PRIME=1
 
26
            else
 
27
                export DRI_PRIME=
 
28
            fi
 
29
        fi
 
30
    fi
 
31
fi