Skip to content

Commit

Permalink
Improvements to running Xorg with NVIDIA
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh5 committed Jul 7, 2023
1 parent 6824406 commit df9423c
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 40 deletions.
16 changes: 13 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ RUN \
pciutils \
pkg-config \
procps \
psmisc \
psutils \
rsync \
screen \
sudo \
Expand Down Expand Up @@ -169,10 +171,19 @@ RUN \
dbus-x11 \
libxcomposite-dev \
libxcursor1 \
wmctrl \
x11-utils \
x11-xfs-utils \
x11-xkb-utils \
x11-xserver-utils \
x11vnc \
xauth \
xbindkeys \
xclip \
xdotool \
xfishtank \
xfonts-base \
xinit \
xorg \
xserver-xorg-core \
xserver-xorg-input-evdev \
Expand Down Expand Up @@ -360,7 +371,6 @@ RUN \
&& apt-get update \
&& echo steam steam/question select "I AGREE" | debconf-set-selections \
&& echo steam steam/license note '' | debconf-set-selections \
&& apt-get install -y \
&& apt-get install -y \
steam \
steam-devices \
Expand Down Expand Up @@ -470,6 +480,7 @@ RUN \
i965-va-driver-shaders \
libva2 \
vainfo \
vdpauinfo \
&& \
echo "**** Section cleanup ****" \
&& apt-get clean autoclean -y \
Expand Down Expand Up @@ -552,8 +563,7 @@ COPY overlay /
# Set display environment variables
ENV \
DISPLAY_CDEPTH="24" \
DISPLAY_DPI="96" \
DISPLAY_REFRESH="60" \
DISPLAY_REFRESH="120" \
DISPLAY_SIZEH="900" \
DISPLAY_SIZEW="1600" \
DISPLAY_VIDEO_PORT="DFP" \
Expand Down
1 change: 0 additions & 1 deletion Dockerfile.arch
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,6 @@ COPY overlay /
# Set display environment variables
ENV \
DISPLAY_CDEPTH="24" \
DISPLAY_DPI="96" \
DISPLAY_REFRESH="60" \
DISPLAY_SIZEH="900" \
DISPLAY_SIZEW="1600" \
Expand Down
1 change: 0 additions & 1 deletion devops/run_server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ cmd="docker run -d --name='${container_name}' \
-e TZ='Pacific/Auckland' \
-e USER_LOCALES='en_US.UTF-8 UTF-8' \
-e DISPLAY_CDEPTH='24' \
-e DISPLAY_DPI='96' \
-e DISPLAY_REFRESH='60' \
-e DISPLAY_SIZEH='720' \
-e DISPLAY_SIZEW='1280' \
Expand Down
19 changes: 10 additions & 9 deletions overlay/etc/cont-init.d/60-configure_gpu_driver.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,15 @@ function install_nvidia_driver {
${USER_HOME}/Downloads/NVIDIA_${nvidia_host_driver_version}.run \
--silent \
--accept-license \
--no-kernel-module \
--skip-depmod \
--skip-module-unload \
--no-kernel-modules \
--no-kernel-module-source \
--install-compat32-libs \
--no-nouveau-check \
--no-nvidia-modprobe \
--no-systemd \
--no-distro-scripts \
--no-rpms \
--no-backup \
--no-check-for-alternate-installs \
Expand Down Expand Up @@ -123,17 +128,13 @@ if [[ ! -z ${nvidia_pci_address} ]]; then
else
echo "**** No NVIDIA device found ****";
fi
# Intel GPU
if [[ ! -z ${intel_cpu_model} ]]; then
echo "**** Found Intel device '${intel_cpu_model}' ****";
install_intel_gpu_driver
else
echo "**** No Intel device found ****";
fi
# Intel Arc
# Intel Arc GPU or Intel CPU with possible iGPU
if [[ ! -z ${intel_gpu_model} ]]; then
echo "**** Found Intel device '${intel_gpu_model}' ****";
install_intel_gpu_driver
elif [[ ! -z ${intel_cpu_model} ]]; then
echo "**** Found Intel device '${intel_cpu_model}' ****";
install_intel_gpu_driver
else
echo "**** No Intel device found ****";
fi
Expand Down
26 changes: 20 additions & 6 deletions overlay/etc/cont-init.d/70-configure_xorg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,18 @@ fi

export nvidia_gpu_hex_id=$(nvidia-smi --format=csv --query-gpu=pci.bus_id --id="${gpu_select}" 2> /dev/null | sed -n 2p)

export monitor_connected=$(cat /sys/class/drm/card*/status | awk '/^connected/ { print $1; }' | head -n1)

# Fech current configuration (if modified in UI)
if [ -f "${USER_HOME}/.config/xfce4/xfconf/xfce-perchannel-xml/displays.xml" ]; then
new_display_sizew=$(cat ${USER_HOME}/.config/xfce4/xfconf/xfce-perchannel-xml/displays.xml | grep Resolution | head -n1 | grep -oP '(?<=value=").*?(?=")' | cut -d'x' -f1)
new_display_sizeh=$(cat ${USER_HOME}/.config/xfce4/xfconf/xfce-perchannel-xml/displays.xml | grep Resolution | head -n1 | grep -oP '(?<=value=").*?(?=")' | cut -d'x' -f2)
if [ "${new_display_sizew}x" != "x" ] && [ "${new_display_sizeh}x" != "x" ]; then
new_display_refresh=$(cat ${USER_HOME}/.config/xfce4/xfconf/xfce-perchannel-xml/displays.xml | grep RefreshRate | head -n1 | grep -oP '(?<=value=").*?(?=")' | cut -d'x' -f2)
if [ "${new_display_sizew}x" != "x" ] && [ "${new_display_sizeh}x" != "x" ] && [ "${new_display_refresh}x" != "x" ]; then
export DISPLAY_SIZEW="${new_display_sizew}"
export DISPLAY_SIZEH="${new_display_sizeh}"
# Round refresh rate to closest multiple of 60
export DISPLAY_REFRESH="$(echo ${new_display_refresh} | awk '{rounded = int(($1 + 30) / 60) * 60; if (rounded < 30) rounded += 60; print rounded}')"
fi
fi

Expand All @@ -33,9 +38,17 @@ function configure_nvidia_x_server {
echo "Configuring X11 with PCI bus ID: '${bus_id}'"
export MODELINE=$(cvt -r "${DISPLAY_SIZEW}" "${DISPLAY_SIZEH}" "${DISPLAY_REFRESH}" | sed -n 2p)
echo "Writing X11 config with ${MODELINE}"
nvidia-xconfig --virtual="${DISPLAY_SIZEW}x${DISPLAY_SIZEH}" --depth="${DISPLAY_CDEPTH}" --mode=$(echo "${MODELINE}" | awk '{print $2}' | tr -d '"') --allow-empty-initial-configuration --no-probe-all-gpus --busid="${bus_id}" --only-one-x-screen --connected-monitor="${DISPLAY_VIDEO_PORT}"
sed -i '/Driver\s\+"nvidia"/a\ Option "ModeValidation" "NoMaxPClkCheck, NoEdidMaxPClkCheck, NoMaxSizeCheck, NoHorizSyncCheck, NoVertRefreshCheck, NoVirtualSizeCheck, NoExtendedGpuCapabilitiesCheck, NoTotalSizeCheck, NoDualLinkDVICheck, NoDisplayPortBandwidthCheck, AllowNon3DVisionModes, AllowNonHDMI3DModes, AllowNonEdidModes, NoEdidHDMI2Check, AllowDpInterlaced"' /etc/X11/xorg.conf
connected_monitor="--use-display-device=None"
if [[ "X${DISPLAY_VIDEO_PORT:-}" != "X" ]]; then
connected_monitor="--connected-monitor=${DISPLAY_VIDEO_PORT:?}"
fi
nvidia-xconfig --virtual="${DISPLAY_SIZEW:?}x${DISPLAY_SIZEH:?}" --depth="${DISPLAY_CDEPTH:?}" --mode=$(echo "${MODELINE:?}" | awk '{print $2}' | tr -d '"') --allow-empty-initial-configuration --no-probe-all-gpus --busid="${bus_id:?}" --no-multigpu --no-sli --no-base-mosaic --only-one-x-screen ${connected_monitor:?}
sed -i '/Driver\s\+"nvidia"/a\ Option "ModeValidation" "NoMaxPClkCheck, NoEdidMaxPClkCheck, NoMaxSizeCheck, NoHorizSyncCheck, NoVertRefreshCheck, NoVirtualSizeCheck, NoTotalSizeCheck, NoDualLinkDVICheck, NoDisplayPortBandwidthCheck, AllowNon3DVisionModes, AllowNonHDMI3DModes, AllowNonEdidModes, NoEdidHDMI2Check, AllowDpInterlaced"\n Option "HardDPMS" "False"' /etc/X11/xorg.conf
sed -i '/Section\s\+"Monitor"/a\ '"${MODELINE}" /etc/X11/xorg.conf
# Prevent interference between GPUs
echo -e "Section \"ServerFlags\"\n Option \"AutoAddGPU\" \"false\"\nEndSection" | sudo tee -a /etc/X11/xorg.conf > /dev/null
# Configure primary GPU
sed -i '/Driver\s\+"nvidia"/a\ Option "AllowEmptyInitialConfiguration"\n Option "PrimaryGPU" "yes"' /usr/share/X11/xorg.conf.d/nvidia-drm-outputclass.conf
}

# Allow anybody for running x server
Expand All @@ -44,13 +57,14 @@ function configure_x_server {
if grep -Fxq "allowed_users=console" /etc/X11/Xwrapper.config; then
echo "Configure Xwrapper.config"
sed -i "s/allowed_users=console/allowed_users=anybody/" /etc/X11/Xwrapper.config
echo 'needs_root_rights=yes' >> /etc/X11/Xwrapper.config
fi

# Remove previous Xorg config
rm -f /etc/X11/xorg.conf

# Ensure the X socket path exists
mkdir -p ${XORG_SOCKET_DIR}
mkdir -p ${XORG_SOCKET_DIR:?}

# Clear out old lock files
display_file=${XORG_SOCKET_DIR}/X${DISPLAY#:}
Expand Down Expand Up @@ -85,8 +99,8 @@ function configure_x_server {
else
echo "Leaving evdev inputs disabled"
fi

monitor_connected=$(cat /sys/class/drm/card*/status | awk '/^connected/ { print $1; }' | head -n1)
# Configure dummy config if no monitor is connected (not applicable to NVIDIA)
if [[ "X${monitor_connected}" == "X" ]]; then
echo "No monitors connected. Installing dummy xorg.conf"
# Use a dummy display input
Expand Down
1 change: 0 additions & 1 deletion overlay/etc/supervisor.d/dind.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ autostart=false
autorestart=true
user=root
command=/usr/bin/start-dind.sh
environment=DISPLAY="%(ENV_DISPLAY)s",DISPLAY_DPI="%(ENV_DISPLAY_DPI)s",XDG_RUNTIME_DIR="/tmp/runtime-root"
stopsignal=INT
stdout_logfile=/home/%(ENV_USER)s/.cache/log/dind.log
stdout_logfile_maxbytes=10MB
Expand Down
2 changes: 1 addition & 1 deletion overlay/etc/supervisor.d/xorg.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ autostart=false
autorestart=true
user=root
command=/usr/bin/start-xorg.sh
environment=DISPLAY="%(ENV_DISPLAY)s",DISPLAY_DPI="%(ENV_DISPLAY_DPI)s",XDG_RUNTIME_DIR="/tmp/runtime-root"
environment=DISPLAY="%(ENV_DISPLAY)s",XDG_RUNTIME_DIR="/tmp/runtime-root"
stopsignal=INT
stdout_logfile=/home/%(ENV_USER)s/.cache/log/xorg.log
stdout_logfile_maxbytes=10MB
Expand Down
34 changes: 23 additions & 11 deletions overlay/usr/bin/start-xorg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# Modified By: Josh.5 (jsunnex@gmail.com)
###
set -e
source /usr/bin/common-functions.sh

# CATCH TERM SIGNAL:
_term() {
Expand All @@ -19,18 +20,29 @@ trap _term SIGTERM SIGINT

# EXECUTE PROCESS:
# Wait for udev
MAX=10
CT=0
while [ ! -f /tmp/.udev-started ]; do
sleep 1
CT=$(( CT + 1 ))
if [ "$CT" -ge "$MAX" ]; then
LOG "FATAL: $0: Gave up waiting for udev server to start"
exit 11
fi
done
wait_for_udev
# Run X server
/usr/bin/Xorg -ac -noreset -novtswitch -sharevts -dpi "${DISPLAY_DPI}" +extension "GLX" +extension "RANDR" +extension "RENDER" vt7 "${DISPLAY}" &
/usr/bin/Xorg \
-ac \
-noreset \
-novtswitch \
-sharevts \
+extension RANDR \
+extension RENDER \
+extension GLX \
+extension XVideo \
+extension DOUBLE-BUFFER \
+extension SECURITY \
+extension DAMAGE \
+extension X-Resource \
-extension XINERAMA -xinerama \
+extension Composite +extension COMPOSITE \
-dpms \
-s off \
-nolisten tcp \
-iglx \
-verbose \
vt7 "${DISPLAY:?}" &
xorg_pid=$!


Expand Down
7 changes: 0 additions & 7 deletions overlay/usr/share/vulkan/icd.d/nvidia_icd.json

This file was deleted.

0 comments on commit df9423c

Please sign in to comment.