Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Intel dGPU prime offload support #537

Merged
merged 1 commit into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 19 additions & 15 deletions providers/base/bin/graphics_env.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
#!/bin/bash
# This script checks if the submitted VIDEO resource is from AMD or nvidia
# and if it is a discrete GPU (graphics_card_resource orders GPUs by index:
# 1 is theintegrated one, 2 is the discrete one).
# 1 is the integrated one, 2 is the discrete one).
#
# This script has to be sourced in order to set an environment variable that
# is used by the open source AMD driver and properties nvidia driver to
# is used by the open source AMD driver and nvidia proprietary driver to
# trigger the use of discrete GPU.

DRIVER=$1
INDEX=$2
PCIBUS="$(echo "$3" | rev | cut -d '/' -f 1 | rev)"
PCIBUS_OFFLOAD_FORMAT=pci-"${PCIBUS//[:.]/_}"

# Some environment variables(like XDG_SESSION_TYPE) are set by some services
# (like graphical-session.target), but during system suspend/resume, they will
# be unset.
ensure_xdg_session_type() {
local max_attempts=5
local attempt=0
while [ -z "$XDG_SESSION_TYPE" ]; do
while [ -z "${XDG_SESSION_TYPE}" ]; do
sleep 1

echo "Waiting for XDG_SESSION_TYPE to be set"
Expand All @@ -25,8 +27,8 @@ ensure_xdg_session_type() {
XDG_SESSION_TYPE=$(loginctl show-session "${SESSION}" | grep 'Type' | cut -d '=' -f 2)

attempt=$((attempt+1))
if [ $attempt -eq $max_attempts ]; then
>&2 echo "XDG_SESSION_TYPE was not set after $max_attempts attempts"
if [ ${attempt} -eq ${max_attempts} ]; then
>&2 echo "XDG_SESSION_TYPE was not set after ${max_attempts} attempts"
exit 1
fi
done
Expand All @@ -35,11 +37,11 @@ ensure_xdg_session_type() {
}

# We only want to set the variable on systems with more than
# 1 GPU running the amdgpu/radeon/nvidia drivers.
if [[ $DRIVER == "amdgpu" || $DRIVER == "radeon" ]]; then
NB_GPU=$(udev_resource.py -l VIDEO | grep -oP -m1 '\d+')
if [[ $NB_GPU -gt 1 ]]; then
if [[ $INDEX -gt 1 ]]; then
# 1 GPU running the amdgpu/radeon/nvidia/i915 drivers.
NB_GPU=$(udev_resource.py -l VIDEO | grep -oP -m1 '\d+')
if [[ ${NB_GPU} -gt 1 ]]; then
if [[ ${DRIVER} == "amdgpu" || ${DRIVER} == "radeon" ]]; then
if [[ ${INDEX} -gt 1 ]]; then
# See https://wiki.archlinux.org/index.php/PRIME
echo "Setting up PRIME GPU offloading for AMD discrete GPU"
if ! cat /var/log/Xorg.0.log ~/.local/share/xorg/Xorg.0.log 2>&1 | grep -q DRI3; then
Expand All @@ -51,21 +53,23 @@ if [[ $DRIVER == "amdgpu" || $DRIVER == "radeon" ]]; then
else
export DRI_PRIME=
fi
fi
elif [[ $DRIVER == "nvidia" || $DRIVER == "pcieport" ]]; then
NB_GPU=$(udev_resource.py -l VIDEO | grep -oP -m1 '\d+')
if [[ $NB_GPU -gt 1 ]]; then
elif [[ ${DRIVER} == "nvidia" || ${DRIVER} == "pcieport" ]]; then
nvidia_nvlink_check.sh
NVLINK=$?
if [[ $INDEX -gt 1 && ${NVLINK} -ne 0 && "$(prime-select query)" = 'on-demand' ]]; then
if [[ ${INDEX} -gt 1 && ${NVLINK} -ne 0 && "$(prime-select query)" = 'on-demand' ]]; then
echo "Setting up PRIME GPU offloading for nvidia discrete GPU"
export __NV_PRIME_RENDER_OFFLOAD=1
export __GLX_VENDOR_LIBRARY_NAME=nvidia
else
unset __NV_PRIME_RENDER_OFFLOAD
unset __GLX_VENDOR_LIBRARY_NAME
fi
elif [[ ${DRIVER} == "i915" && -n "${PCIBUS}" ]]; then
echo "Setting up PRIME GPU offloading for pci@${PCIBUS} Intel GPU"
export DRI_PRIME=${PCIBUS_OFFLOAD_FORMAT}
fi
else
unset DRI_PRIME
fi

ensure_xdg_session_type
8 changes: 4 additions & 4 deletions providers/base/units/graphics/jobs.pxu
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ requires:
package.name == 'gir1.2-gst-plugins-base-0.10' or package.name == 'gir1.2-gst-plugins-base-1.0'
command:
# shellcheck disable=SC1091
source graphics_env.sh {driver} {index}
source graphics_env.sh {driver} {index} {path}
gst_pipeline_test.py -t 2 'videotestsrc ! videoconvert ! autovideosink' || gst_pipeline_test.py -t 2 'videotestsrc ! ffmpegcolorspace ! autovideosink'
_summary: Test that video can be displayed with {vendor} {product}
_description:
Expand Down Expand Up @@ -280,7 +280,7 @@ id: graphics/{index}_valid_opengl_renderer_{product_slug}
requires: executable.name == 'glxinfo'
command:
# shellcheck disable=SC1091
source graphics_env.sh {driver} {index}
source graphics_env.sh {driver} {index} {path}
renderer=$(glxinfo | grep "OpenGL re")
echo "$renderer"
if grep -qi 'Intel' <<<"$renderer"; then
Expand All @@ -298,7 +298,7 @@ flags: also-after-suspend
requires: executable.name == 'glxgears'
command:
# shellcheck disable=SC1091
source graphics_env.sh {driver} {index}
source graphics_env.sh {driver} {index} {path}
glxgears
true
_summary: Test that glxgears works for {vendor} {product}
Expand All @@ -321,7 +321,7 @@ flags: also-after-suspend
requires: executable.name == 'glxgears'
command:
# shellcheck disable=SC1091
source graphics_env.sh {driver} {index}
source graphics_env.sh {driver} {index} {path}
glxgears -fullscreen
true
_summary: Test that glxgears works on fullscreen for {vendor} {product}
Expand Down
4 changes: 2 additions & 2 deletions providers/base/units/suspend/suspend-graphics.pxu
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ depends:
requires: executable.name == 'glxgears'
command:
# shellcheck disable=SC1091
source graphics_env.sh {{ driver }} {{ index }}
source graphics_env.sh {{ driver }} {{ index }} {{ path }}
glxgears
true
_summary: Test that glxgears works for {{ vendor }} {{ product }} after suspend
Expand Down Expand Up @@ -306,4 +306,4 @@ _description:
1. Click "Test" to test display rotation. The display will be rotated every 4 seconds.
2. Check if all rotations (normal right inverted left) took place without permanent screen corruption
VERIFICATION:
Did the display rotation take place without permanent screen corruption after suspend?
Did the display rotation take place without permanent screen corruption after suspend?
4 changes: 4 additions & 0 deletions providers/resource/bin/graphics_card_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ def main():
elif (record['driver'] in ('nvidia', 'pcieport')
and compare_ubuntu_release_version('22.04')):
record['prime_gpu_offload'] = 'On'
elif record['driver'] == 'i915':
record['prime_gpu_offload'] = 'On'
else:
record['prime_gpu_offload'] = 'Off'
else:
record['prime_gpu_offload'] = 'Off'
record['switch_to_cmd'] = switch_cmds[record['driver']][0]
Expand Down