Skip to content
Snippets Groups Projects
Commit 2ee6acf8 authored by Theron Tarigo's avatar Theron Tarigo Committed by Kevin Bowling
Browse files

x11/nvidia-hybrid-graphics: Optimus Technology

PR:		192617
Reported by:	David Mackay <davidjx8p@gmail.com>
Reviewed by:	many
Tested by:	many
Approved by:	portmgr (maintainer timeout: 15 days)
Differential Revision:	https://reviews.freebsd.org/D22521
parent e5291897
No related branches found
No related tags found
No related merge requests found
Showing
with 349 additions and 7 deletions
......@@ -13,7 +13,7 @@
# the port aims to support building against arbitrary DISTVERSION, i.e.
# ``make DISTVERSION=xxx.yy.zz -DNO_CHECKSUM'' should typically work.
PORTNAME= nvidia-driver
PORTNAME?= nvidia-driver
DISTVERSION?= 460.80
# Always try to set PORTREVISION as it can be overridden by the slave ports
PORTREVISION?= 0
......@@ -22,8 +22,8 @@ MASTER_SITES= NVIDIA/XFree86/FreeBSD-${ARCH_SUFX}/${DISTVERSION}
DISTNAME= NVIDIA-FreeBSD-${ARCH_SUFX}-${DISTVERSION}
DISTFILES= ${DISTNAME}${EXTRACT_SUFX}
MAINTAINER= danfe@FreeBSD.org
COMMENT= NVidia graphics card binary drivers for hardware OpenGL rendering
MAINTAINER?= danfe@FreeBSD.org
COMMENT?= NVidia graphics card binary drivers for hardware OpenGL rendering
LICENSE_FILE= ${WRKSRC}/doc/license.txt
.include "${.CURDIR}/../nvidia-driver/Makefile.common"
......@@ -43,7 +43,10 @@ WAYLAND_JSON_PATH= ${PREFIX}/share/egl/egl_external_platform.d
MAKE_ENV= DEBUG_FLAGS=${DEBUG_FLAGS} \
EGL_GLVND_JSON_PATH=${STAGEDIR}${GLVND_JSON_PATH} \
EGL_WAYLAND_JSON_PATH=${STAGEDIR}${WAYLAND_JSON_PATH}
SUB_FILES= pkg-message nvidia.conf
SUB_FILES= pkg-message
.if !defined(LIBGLDIR)
SUB_FILES+= nvidia.conf
.endif
.if ${NVVERSION} < 410.057
SUB_FILES+= pkg-deinstall pkg-install
.endif
......@@ -54,6 +57,7 @@ SUB_PATCHES= extra-patch-src-Makefile \
extra-patch-src-nvidia_pci.c
DOCSDIR= ${PREFIX}/share/doc/NVIDIA_GLX-1.0
MODULESDIR= lib/xorg/modules
EXTENSIONSDIR?= ${MODULESDIR}/extensions/.nvidia
PORTDOCS= *
.if ${NVVERSION} >= 331.013
......@@ -96,6 +100,20 @@ FREEBSD_AGP_DESC= Use FreeBSD AGP GART driver
.endif
PLIST_SUB+= MODULESDIR=${MODULESDIR}
.if ${NVVERSION} < 410.057
PLIST_SUB+= EXTENSIONSDIR=${EXTENSIONSDIR}
.else
PLIST_SUB+= EXTENSIONSDIR="@comment "
.endif
.if defined(LIBGLDIR)
PLIST_SUB+= LIBGLDIR=${LIBGLDIR} LIBGLMAP="@comment "
.else
PLIST_SUB+= LIBGLDIR="@comment " LIBGLMAP=""
.endif
.if ${PORTNAME} != nvidia-secondary-driver
CONFLICTS_INSTALL+= nvidia-secondary-driver
.endif
.include <bsd.port.pre.mk>
......@@ -284,8 +302,32 @@ post-install: .SILENT
${STAGEDIR}${PREFIX}/lib/libGLESv2-NVIDIA.so.2
${RM} ${STAGEDIR}${PREFIX}/lib/libGLESv2.so
.endif
# Configuration of Nvidia as secondary GPU requires preserving Mesa libraries
# as default implementation; a libmap must not override in this case.
.if !defined(LIBGLDIR)
@${MKDIR} ${STAGEDIR}${PREFIX}/etc/libmap.d/
${INSTALL_DATA} ${WRKDIR}/nvidia.conf \
${STAGEDIR}${PREFIX}/etc/libmap.d/
.else
# libgl proxies require a library path containing unrenamed lib*GL*.so
${MKDIR} ${STAGEDIR}${PREFIX}/${LIBGLDIR}
${RLN} ${STAGEDIR}${PREFIX}/lib/libGL-NVIDIA.so.1 \
${STAGEDIR}${PREFIX}/${LIBGLDIR}/libGL.so.1
${RLN} ${STAGEDIR}${PREFIX}/lib/libEGL-NVIDIA.so.1 \
${STAGEDIR}${PREFIX}/${LIBGLDIR}/libEGL.so.1
${RLN} ${STAGEDIR}${PREFIX}/lib/libGLESv2-NVIDIA.so.2 \
${STAGEDIR}${PREFIX}/${LIBGLDIR}/libGLESv2.so.2
.endif
# Configuration of Nvidia as secondary GPU requires preserving xorg-server's
# libglx.so and moving Nvidia's glx to where it can be found by a secondary
# Xorg instance.
# Not needed since 410.057: Nvidia driver finds libglxserver_nvidia.so instead.
.if ${NVVERSION} < 410.057
.if ${EXTENSIONSDIR} != ${MODULESDIR}/extensions/.nvidia
${MKDIR} ${STAGEDIR}${PREFIX}/${EXTENSIONSDIR}
${MV} ${STAGEDIR}${PREFIX}/${MODULESDIR}/extensions/.nvidia/* \
${STAGEDIR}${PREFIX}/${EXTENSIONSDIR}/
.endif
.endif
.include <bsd.port.post.mk>
bin/nvidia-bug-report.sh
bin/nvidia-debugdump
bin/nvidia-smi
etc/libmap.d/nvidia.conf
%%LIBGLMAP%%etc/libmap.d/nvidia.conf
%%LIBGLDIR%%/libGL.so.1
%%LIBGLDIR%%/libEGL.so.1
%%LIBGLDIR%%/libGLESv2.so.2
lib/libEGL-NVIDIA.so
lib/libEGL-NVIDIA.so.1
lib/libEGL_nvidia.so
......@@ -86,8 +89,8 @@ share/glvnd/egl_vendor.d/10_nvidia.json
share/vulkan/icd.d/nvidia_icd.json
share/vulkan/implicit_layer.d/nvidia_layers.json
%%MODULESDIR%%/drivers/nvidia_drv.so
%%MODULESDIR%%/extensions/.nvidia/libglx.so
%%MODULESDIR%%/extensions/.nvidia/libglx.so.1
%%EXTENSIONSDIR%%/libglx.so
%%EXTENSIONSDIR%%/libglx.so.1
%%MODULESDIR%%/extensions/libglxserver_nvidia.so
%%MODULESDIR%%/extensions/libglxserver_nvidia.so.1
/%%KMODDIR%%/nvidia.ko
......
# Created by: Theron Tarigo <theron.tarigo@gmail.com>
PORTNAME= nvidia-hybrid-graphics
PORTVERSION= 0.5
CATEGORIES= x11
MASTER_SITES= # none
DISTFILES= # none
MAINTAINER= theron.tarigo@gmail.com
COMMENT= NVIDIA secondary GPU configuration - Optimus Technology support
LICENSE= BSD2CLAUSE
RUN_DEPENDS= nvidia-xconfig:x11/nvidia-xconfig \
${LOCALBASE}/bin/Xorg:x11-servers/xorg-server
FLAVORS= default 390
NO_ARCH= yes
NO_BUILD= yes
WRKSRC= ${WRKDIR}/src
default_RUN_DEPENDS= \
nvidia-secondary-driver>=440.64:x11/nvidia-secondary-driver
390_RUN_DEPENDS= \
nvidia-secondary-driver-390>=390.87:x11/nvidia-secondary-driver-390
VIRTUALGL_RUN_DEPENDS= ${LOCALBASE}/VirtualGL/bin/vglrun:x11/virtualgl
390_PKGNAMESUFFIX= -390
OPTIONS_DEFINE= VIRTUALGL OPTIRUN
OPTIONS_DEFAULT= VIRTUALGL OPTIRUN
OPTIONS_SUB= OPTIRUN
VIRTUALGL_DESC= Use VirtualGL for OpenGL redirection support
OPTIRUN_DESC= Install "optirun" alias for nvrun-vgl
OPTIRUN_IMPLIES= VIRTUALGL
scripts= \
bin/Xorg-nvidia-headless \
bin/nvidia-headless-xconfig \
bin/nvrun \
bin/nvrun-vgl \
libexec/nvidia-headless-utils/readconf \
libexec/nvidia-settings-hybrid
configs= \
etc/X11/xorg-nvidia-headless-template.conf \
etc/nvidia-headless.conf \
etc/nvidia-hybrid.conf \
SUB_FILES= pkg-message ${scripts:%=src/%} ${configs:%=src/%}
SUB_LIST+= VGLRUN=${LOCALBASE}/VirtualGL/bin/vglrun
USE_RC_SUBR= nvidia_xorg
do-extract:
.for f in ${SUB_FILES}
${MKDIR} ${WRKDIR}/${f:H}
.endfor
do-install:
.for f in ${scripts}
@${MKDIR} ${STAGEDIR}${PREFIX}/${f:H}
${INSTALL_SCRIPT} ${WRKSRC}/${f} ${STAGEDIR}${PREFIX}/${f}
.endfor
.for f in ${configs}
@${MKDIR} ${STAGEDIR}${PREFIX}/${f:H}
${INSTALL_DATA} ${WRKSRC}/${f} ${STAGEDIR}${PREFIX}/${f}.sample
.endfor
post-install:
@${MKDIR} ${STAGEDIR}${PREFIX}/etc/X11/xorg-nvidia-headless.conf.d
post-install-OPTIRUN-on:
@${RLN} ${STAGEDIR}${PREFIX}/bin/nvrun-vgl \
${STAGEDIR}${PREFIX}/bin/optirun
.include <bsd.port.mk>
#!/bin/sh
#
# $FreeBSD$
#
# PROVIDE: nvidia_xorg
# REQUIRE: LOGIN
# KEYWORD: shutdown
. /etc/rc.subr
name=nvidia_xorg
rcvar=nvidia_xorg_enable
desc="Nvidia GPU Dedicated Xorg"
load_rc_config $name
: ${nvidia_xorg_enable:=NO}
: ${nvidia_modeset:=NO}
: ${nvidia_manage_kld:=YES}
command=/usr/sbin/daemon
pidfile=/var/run/${name}.pid
procname="%%LOCALBASE%%/bin/Xorg"
command_args="-p ${pidfile} -f %%PREFIX%%/bin/Xorg-nvidia-headless"
start_precmd="${name}_prestart"
stop_postcmd="${name}_poststop"
if checkyesno nvidia_modeset; then
kmod=nvidia-modeset
else
kmod=nvidia
fi
nvidia_xorg_prestart()
{
if checkyesno nvidia_manage_kld; then
kldload -n ${kmod} || return 1
fi
}
nvidia_xorg_poststop()
{
if checkyesno nvidia_manage_kld; then
kldunload -f ${kmod} || return 1
fi
}
run_rc_command "$1"
Running Xorg-nvidia-headless at startup is recommended especially on mobile
systems since leaving Nvidia GPU powered on with no Xorg may consume
significantly more power.
# sysrc nvidia_xorg_enable=YES
# service nvidia_xorg start
The Xorg instance uses separate configuration files from the defaults for Xorg:
%%PREFIX%%/etc/X11/xorg-nvidia-headless.conf.d/
%%PREFIX%%/etc/X11/xorg-nvidia-headless-template.conf
Only used if xorg-nvidia-headless.conf does not exist.
This file is passed through nvidia-xconfig, which does not preserve
all options.
%%PREFIX%%/etc/X11/xorg-nvidia-headless.conf
Created by manually invoking %%PREFIX%%/bin/nvidia-headless-xconfig.
Once created, this configuration is not passed through nvidia-xconfig.
Configuration is not normally needed for typical OpenGL acceleration usage.
A properly configured xorg-nvidia-headless.conf will allow Xorg-nvidia-headless
to be started by non-superuser if Xorg has been installed setuid.
#!/bin/sh
conf=%%PREFIX%%/etc/nvidia-headless.conf
. %%PREFIX%%/libexec/nvidia-headless-utils/readconf
if [ -z "$NVDISPLAY" ]; then printf %s\\n "NVDISPLAY required in environment or in $conf" >&2 ; exit 1; fi
xconfig=%%LOCALBASE%%/etc/X11/xorg-nvidia-headless.conf
xconfarg=xorg-nvidia-headless.conf
if [ ! -e "$xconfig" ]; then
if [ "$(id -u)" != 0 ]; then
printf %s\\n "nvidia-headless must be configured by superuser" >&2
exit 1
fi
xconfig=/var/cache/nvidia-headless/xorg.conf
mkdir -p /var/cache/nvidia-headless
xconfarg="$xconfig"
%%PREFIX%%/bin/nvidia-headless-xconfig -o "$xconfig"
fi
exec %%LOCALBASE%%/bin/Xorg -sharevts -novtswitch -noreset -config "$xconfarg" -configdir "xorg-nvidia-headless.conf.d" "$NVDISPLAY" "$@"
#!/bin/sh
exec %%LOCALBASE%%/bin/nvidia-xconfig \
--enable-all-gpus \
--preserve-busid \
--allow-empty-initial-configuration \
--connected-monitor=DFP \
--no-use-edid \
-c %%PREFIX%%/etc/X11/xorg-nvidia-headless-template.conf \
-o %%LOCALBASE%%/etc/X11/xorg-nvidia-headless.conf "$@"
#!/bin/sh
conf=%%PREFIX%%/etc/nvidia-headless.conf
. %%PREFIX%%/libexec/nvidia-headless-utils/readconf
conf=%%PREFIX%%/etc/nvidia-hybrid.conf
. %%PREFIX%%/libexec/nvidia-headless-utils/readconf
if [ -z "$NVDISPLAY" ]; then printf %s\\n "NVDISPLAY required in environment or in $conf" >&2 ; exit 1; fi
if [ -z "$VGLRUN" ]; then printf %s\\n "VGLRUN required in environment or in $conf" >&2 ; exit 1; fi
exec "$VGLRUN" -ld "%%LOCALBASE%%/lib/libGL-NVIDIA" -d "$NVDISPLAY" "$@"
#!/bin/sh
conf=%%PREFIX%%/etc/nvidia-headless.conf
. %%PREFIX%%/libexec/nvidia-headless-utils/readconf
if [ -z "$NVDISPLAY" ]; then printf %s\\n "NVDISPLAY required in environment or in $conf" >&2 ; exit 1; fi
export DISPLAY="$NVDISPLAY"
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:%%LOCALBASE%%/lib/libGL-NVIDIA"
exec "$@"
Section "ServerLayout"
Identifier "nvidia"
Screen 0 "Screen0"
InputDevice "fake" "CorePointer" "CoreKeyboard"
Option "AutoAddDevices" "false"
EndSection
Section "Files"
ModulePath "%%LOCALBASE%%/lib/xorg/modules-NVIDIA"
ModulePath "%%LOCALBASE%%/lib/xorg/modules"
EndSection
Section "Module"
Load "dri3"
Load "glx"
Disable "efifb"
EndSection
Section "InputDevice"
Identifier "fake"
Driver ""
EndSection
Section "Monitor"
Identifier "Monitor0"
EndSection
Section "Device"
Identifier "Device0"
Driver "nvidia"
EndSection
Section "Screen"
Identifier "Screen0"
Device "Device0"
Monitor "Monitor0"
EndSection
NVDISPLAY=:8
VGLRUN=%%VGLRUN%%
while IFS== read -r _var _val ; do
expr "$_var" : '[a-zA-Z][a-zA-Z0-9_]*$' >&- && \
eval [ -z \${$_var+UNSET} ] '&&' $_var="\$_val" '||' true || \
printf %s\\n "$conf: $_var: bad variable name" >&2
done < "$conf" ; unset _var _val
#!/bin/sh
conf=%%PREFIX%%/etc/nvidia-headless.conf
. %%PREFIX%%/libexec/nvidia-headless-utils/readconf
exec nvrun-vgl %%LOCALBASE%%/libexec/nvidia-settings -c "$NVDISPLAY" "$@"
This port integrates the Nvidia graphics driver and supporting utilities with
VirtualGL, enabling use of Nvidia acceleration on a system with hybrid graphics
hardware configuration, aka "Optimus".
Applications to be run with Nvidia acceleration should be started using
`nvrun-vgl`.
WWW: https://github.com/therontarigo/freebsd-gpu-headless
bin/Xorg-nvidia-headless
bin/nvidia-headless-xconfig
bin/nvrun
libexec/nvidia-headless-utils/readconf
%%VIRTUALGL%%bin/nvrun-vgl
%%OPTIRUN%%bin/optirun
libexec/nvidia-settings-hybrid
@sample etc/X11/xorg-nvidia-headless-template.conf.sample
@sample etc/nvidia-headless.conf.sample
@sample etc/nvidia-hybrid.conf.sample
@dir etc/X11/xorg-nvidia-headless.conf.d
# Created by: Theron Tarigo <theron.tarigo@gmail.com>
MASTERDIR= ${.CURDIR}/../nvidia-driver-390
NVSDR_MASTERDIR= ${.CURDIR}/../nvidia-secondary-driver
.include "${NVSDR_MASTERDIR}/Makefile"
# Created by: Theron Tarigo <theron.tarigo@gmail.com>
PORTNAME= nvidia-secondary-driver
# Explicitly set PORTREVISION as it can be overridden by the master port
PORTREVISION= 0
MASTERDIR?= ${.CURDIR}/../nvidia-driver
MAINTAINER= theron.tarigo@gmail.com
COMMENT= NVidia graphics card binary drivers for hardware OpenGL rendering on secondary device
CONFLICTS_INSTALL= nvidia-driver
EXTENSIONSDIR= lib/xorg/modules-NVIDIA/extensions
LIBGLDIR= lib/libGL-NVIDIA
SUB_FILES= pkg-message
.include "${MASTERDIR}/Makefile"
Utilization of this driver for GLX acceleration requires special configuration
of an Xorg server instance.
x11/nvidia-hybrid-graphics is provided to handle this configuration.
......@@ -27,11 +27,14 @@ USE_GITHUB= yes
GH_ACCOUNT= NVIDIA
PLIST_FILES= bin/nvidia-settings \
libexec/nvidia-settings \
man/man1/nvidia-settings.1.gz \
lib/libnvidia-gtk2.so.${PORTVERSION} \
share/applications/nvidia-settings.desktop \
share/pixmaps/nvidia-settings.png
SUB_FILES= nvidia-settings
LDFLAGS+= -pthread
LLD_UNSAFE= yes
MAKE_ENV= NV_USE_BUNDLED_LIBJANSSON=0 \
......@@ -56,5 +59,9 @@ post-install: .SILENT
${STAGEDIR}/${DESKTOPDIR}
${INSTALL_DATA} ${WRKSRC}/doc/nvidia-settings.png \
${STAGEDIR}/${PREFIX}/share/pixmaps
${MV} ${STAGEDIR}${PREFIX}/bin/nvidia-settings \
${STAGEDIR}${PREFIX}/libexec/nvidia-settings
${INSTALL} ${WRKDIR}/nvidia-settings \
${STAGEDIR}${PREFIX}/bin/nvidia-settings
.include <bsd.port.mk>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment