Index: x11/nvidia-driver/Makefile =================================================================== --- x11/nvidia-driver/Makefile +++ x11/nvidia-driver/Makefile @@ -9,7 +9,7 @@ # you need to use legacy driver version and install one of corresponding # slave ports instead (`x11/nvidia-driver-340' or `x11/nvidia-driver-304'). -PORTNAME= nvidia-driver +PORTNAME?= nvidia-driver DISTVERSION?= 440.31 # Always try to set PORTREVISION as it can be overridden by the slave ports PORTREVISION?= 0 @@ -18,8 +18,8 @@ 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" @@ -58,6 +58,7 @@ 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 @@ -93,8 +94,25 @@ FREEBSD_AGP_DESC= Use FreeBSD AGP GART driver .endif -PLIST_SUB+= MODULESDIR=${MODULESDIR} +PLIST_SUB+= MODULESDIR=${MODULESDIR} \ + EXTENSIONSDIR=${EXTENSIONSDIR} +.ifdef LIBGLDIR +PLIST_SUB+= LIBGLDIR=${LIBGLDIR} +.else +PLIST_SUB+= LIBGLDIR="@comment " +.endif + +.ifdef NO_LIBMAP +PLIST_SUB+= LIBGLMAP="@comment " +.else +PLIST_SUB+= LIBGLMAP="" +.endif + +.if ${PORTNAME} != nvidia-headless-driver +CONFLICTS_INSTALL+= nvidia-headless-* +.endif + .include pre-patch: @@ -269,8 +287,30 @@ ${STAGEDIR}${PREFIX}/lib/libGLESv2-NVIDIA.so.2 ${RM} ${STAGEDIR}${PREFIX}/lib/libGLESv2.so .endif +# nvidia-headless-driver does not want libmap +.ifndef NO_LIBMAP @${MKDIR} ${STAGEDIR}${PREFIX}/etc/libmap.d/ ${INSTALL_DATA} ${WRKDIR}/nvidia.conf \ ${STAGEDIR}${PREFIX}/etc/libmap.d/ +.endif +# nvidia-headless-utils needs a library path containing unrenamed lib*GL*.so +.ifdef LIBGLDIR + ${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 +.if ${NVVERSION} < 410.057 +# nvidia-headless-driver needs a separate modules dir +.if ${EXTENSIONSDIR} != ${MODULESDIR}/extensions/.nvidia + ${MKDIR} ${STAGEDIR}${PREFIX}/${EXTENSIONSDIR} + ${MV} ${STAGEDIR}${PREFIX}/${MODULESDIR}/extensions/.nvidia/* \ + ${STAGEDIR}${PREFIX}/${EXTENSIONSDIR}/ +.endif +.endif + .include Index: x11/nvidia-driver/pkg-plist =================================================================== --- x11/nvidia-driver/pkg-plist +++ x11/nvidia-driver/pkg-plist @@ -1,7 +1,10 @@ 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 @@ -49,8 +52,8 @@ share/egl/egl_external_platform.d/10_nvidia_wayland.json share/glvnd/egl_vendor.d/10_nvidia.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 Index: x11/nvidia-headless-driver/Makefile =================================================================== --- x11/nvidia-headless-driver/Makefile +++ x11/nvidia-headless-driver/Makefile @@ -0,0 +1,19 @@ +PORTNAME= nvidia-headless-driver +# Explicitly set PORTREVISION as it can be overridden by the master port +PORTREVISION= 0 + +MASTERDIR= ${.CURDIR}/../nvidia-driver + +MAINTAINER= theron@FreeBSD.org +COMMENT= NVidia graphics card binary drivers for hardware OpenGL rendering on secondary device + +CONFLICTS_INSTALL= nvidia-driver + +EXTENSIONSDIR= lib/xorg/modules-NVIDIA/extensions +NO_LIBMAP=1 + +LIBGLDIR= lib/libGL-NVIDIA + +SUB_FILES= pkg-message + +.include "${MASTERDIR}/Makefile" Index: x11/nvidia-headless-driver/pkg-message =================================================================== --- x11/nvidia-headless-driver/pkg-message +++ x11/nvidia-headless-driver/pkg-message @@ -0,0 +1,7 @@ +Utilization of this driver for GLX acceleration requires special configuration +of an Xorg server instance. Install one of the following ports to automate +this configuration: + + x11/nvidia-headless-utils for non-graphical application + + x11/nvidia-hybrid-graphics for forwarding to another Xorg server Index: x11/nvidia-headless-utils/Makefile =================================================================== --- x11/nvidia-headless-utils/Makefile +++ x11/nvidia-headless-utils/Makefile @@ -0,0 +1,23 @@ +# $FreeBSD$ + +PORTNAME?= nvidia-headless-utils +DISTVERSION= 0.5 +CATEGORIES= x11 +MASTER_SITES= https://raw.githubusercontent.com/therontarigo/freebsd-gpu-headless/master/dist/ +DISTNAME= nvidia-headless-utils-${DISTVERSION} +EXTRACT_SUFX= .tar.xz + +MAINTAINER= theron@FreeBSD.org +COMMENT?= Utilities for running OpenGL applications on nvidia-headless-driver + +RUN_DEPENDS?= nvidia-xconfig:x11/nvidia-xconfig \ + nvidia-headless-driver>=390.87:x11/nvidia-headless-driver \ + ${LOCALBASE}/bin/Xorg:x11-servers/xorg-server + +ONLY_FOR_ARCHS= i386 amd64 + +SUB_FILES?= pkg-message + +USE_RC_SUBR?= nvidia_xorg + +.include Index: x11/nvidia-headless-utils/distinfo =================================================================== --- x11/nvidia-headless-utils/distinfo +++ x11/nvidia-headless-utils/distinfo @@ -0,0 +1,3 @@ +TIMESTAMP = 1573416029 +SHA256 (nvidia-headless-utils-0.5.tar.xz) = fe5a35cda9587cda1dfea74e8221a94f2ebb46d3f3fecb761eeb3b150ffcc662 +SIZE (nvidia-headless-utils-0.5.tar.xz) = 2112 Index: x11/nvidia-headless-utils/files/nvidia_xorg.in =================================================================== --- x11/nvidia-headless-utils/files/nvidia_xorg.in +++ x11/nvidia-headless-utils/files/nvidia_xorg.in @@ -0,0 +1,54 @@ +#!/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:=YES} +: ${nvidia_manage_kld:=YES} + +command="%%LOCALBASE%%/bin/Xorg" +pidfile=/var/run/${name}.pid +start_cmd="${name}_start" +stop_postcmd="${name}_poststop" + +nvidia_xorg_start() +{ + if checkyesno nvidia_manage_kld; then + if checkyesno nvidia_modeset; then + kldload -n nvidia-modeset + else + kldload -n nvidia + fi + fi + + %%PREFIX%%/bin/Xorg-nvidia-headless > /var/log/nvidia-headless-xorg.log 2>&1 & + pid=$! + printf %s $pid > "$pidfile" +} + +nvidia_xorg_poststop() +{ + rm -f "$pidfile" + + if checkyesno nvidia_manage_kld; then + if checkyesno nvidia_modeset; then + kldstat -q -n nvidia-modeset && kldunload -f nvidia-modeset + else + kldstat -q -n nvidia && kldunload -f nvidia + fi + fi +} + +run_rc_command "$1" Index: x11/nvidia-headless-utils/files/pkg-message.in =================================================================== --- x11/nvidia-headless-utils/files/pkg-message.in +++ x11/nvidia-headless-utils/files/pkg-message.in @@ -0,0 +1,17 @@ +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 + +Install x11/nvidia-hybrid-graphics if graphical output of the Nvidia +accelerated application on the current X11 display is required. + +Modify %%PREFIX%%/etc/X11/xorg-nvidia-headless-template.conf to change general +Xorg options, or run %%PREFIX%%/bin/nvidia-headless-xconfig, then edit +%%PREFIX%%/etc/X11/xorg-nvidia-headless.conf if post-xconfig modifications are +required. + +Running %%PREFIX%%/bin/nvidia-headless-xconfig will allow Xorg-nvidia-headless +to run as non-superuser if Xorg has been installed setuid. Index: x11/nvidia-headless-utils/pkg-descr =================================================================== --- x11/nvidia-headless-utils/pkg-descr +++ x11/nvidia-headless-utils/pkg-descr @@ -0,0 +1,7 @@ +This port provides scripts and template configuration files for setting up and +using x11/nvidia-headless-driver for offscreen hardware OpenGL rendering. + +A separate port, x11/nvidia-hybrid-graphics enables presentation of a graphical +application on the current X11 display while utilizing Nvidia acceleration. + +WWW: https://github.com/therontarigo/freebsd-gpu-headless Index: x11/nvidia-headless-utils/pkg-plist =================================================================== --- x11/nvidia-headless-utils/pkg-plist +++ x11/nvidia-headless-utils/pkg-plist @@ -0,0 +1,6 @@ +bin/Xorg-nvidia-headless +bin/nvidia-headless-xconfig +bin/nvrun +etc/X11/xorg-nvidia-headless-template.conf +etc/nvidia-headless.conf +libexec/nvidia-headless-utils/readconf Index: x11/nvidia-hybrid-graphics/Makefile =================================================================== --- x11/nvidia-hybrid-graphics/Makefile +++ x11/nvidia-hybrid-graphics/Makefile @@ -0,0 +1,28 @@ +# $FreeBSD$ + +PORTNAME= nvidia-hybrid-graphics +MASTERDIR= ${.CURDIR}/../nvidia-headless-utils + +COMMENT= NVIDIA headless (discrete GPU) graphics acceleration - AKA Optimus + +RUN_DEPENDS= nvidia-headless-utils>=0.3:x11/nvidia-headless-utils \ + nvidia-headless-driver>=390.87:x11/nvidia-headless-driver \ + ${LOCALBASE}/VirtualGL/bin/vglrun:x11/virtualgl \ + nvidia-settings:x11/nvidia-settings + +DESCR= ${.CURDIR}/pkg-descr +PLIST= ${.CURDIR}/pkg-plist + +SUB_FILES= +USE_RC_SUBR= + +OPTIONS_DEFINE= OPTIRUN +OPTIONS_DEFAULT= OPTIRUN +OPTIONS_SUB= OPTIRUN +OPTIRUN_DESC= Install "optirun" alias for nvrun-vgl + +post-install-OPTIRUN-on: + @${RLN} ${STAGEDIR}${PREFIX}/bin/nvrun-vgl \ + ${STAGEDIR}${PREFIX}/bin/optirun + +.include "${MASTERDIR}/Makefile" Index: x11/nvidia-hybrid-graphics/pkg-descr =================================================================== --- x11/nvidia-hybrid-graphics/pkg-descr +++ x11/nvidia-hybrid-graphics/pkg-descr @@ -0,0 +1,8 @@ +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 Index: x11/nvidia-hybrid-graphics/pkg-plist =================================================================== --- x11/nvidia-hybrid-graphics/pkg-plist +++ x11/nvidia-hybrid-graphics/pkg-plist @@ -0,0 +1,4 @@ +bin/nvrun-vgl +%%OPTIRUN%%bin/optirun +etc/nvidia-hybrid.conf +libexec/nvidia-settings-hybrid Index: x11/nvidia-settings/Makefile =================================================================== --- x11/nvidia-settings/Makefile +++ x11/nvidia-settings/Makefile @@ -28,11 +28,14 @@ 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 \ @@ -57,5 +60,9 @@ ${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 Index: x11/nvidia-settings/files/nvidia-settings.in =================================================================== --- x11/nvidia-settings/files/nvidia-settings.in +++ x11/nvidia-settings/files/nvidia-settings.in @@ -0,0 +1,3 @@ +#!/bin/sh +[ -e "%%LOCALBASE%%/libexec/nvidia-settings-hybrid" ] && exec %%LOCALBASE%%/libexec/nvidia-settings-hybrid "$@" +exec %%PREFIX%%/libexec/nvidia-settings "$@"