A rough overview of using Nvidia Optimus on FreeBSD.
New approach (as of 2018.03.11)
Run x11/virtualgl from ports and the rest should work.
Old approach
as of 20180715, gcc47 has been removed. The following will no longer work.
Initial port/PR: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=192617
- Make sure Nvidia Optimus is enabled in BIOS.
Install graphics/libjpeg-turbo and lang/gcc47. Make sure to tick the PIC option on make config for libjpeg-turbo.
- Now download VirtualGL and build it.
Comment: Fairly simple, CMake based. You might need to tweak a single file or two to account for a certain function being defined elsewhere on FreeBSD, I forgot. Also, set CC=gcc47 and CXX=g++47 beforehand.
Now, install x11/nvidia-driver. Be warned that when you next update graphics/libGL, it will try to create a symlink from the Nvidia libGL.so in %LOCALBASE%/lib/.nvidia to %LOCALBASE%/lib/libGL.so! Don't let it do that.
Now you must configure a /etc/X11/xorg.conf.nv. Mine looks a little like this:
Section "ServerLayout" Identifier "Layout0" Option "AutoAddDevices" "false" InputDevice "fake" "CorePointer" EndSection Section "Device" Identifier "Device1" Driver "nvidia" VendorName "NVIDIA Corporation" BusID "PCI:01:00:0" Option "NoLogo" "true" Option "UseEDID" "false" Option "ConnectedMonitor" "DFP" EndSection Section "InputDevice" Identifier "fake" Driver "" EndSection
Modify xmj's turn_off_nvidia.sh replacing all _OFF/DOFF/SDOF and so on to read ON instead. Execute it. Now kldload nvidia
We can test this now. Run X -conf xorg.conf.nv -sharevts -noreset :8 in bg.
Now run /opt/VirtualGL/bin/vglrun -ld /usr/local/lib/.nvidia/ -d ":8" glxgears
- Did it work? Congratulations!
And to turn off Nvidia, simply end the running X server on the Nvidia card, kldunload nvidia, and execute turn_off_nvidia.sh.