Page MenuHomeFreeBSD

new ports: Nvidia headless/hybrid graphics ("Optimus" support)
Needs ReviewPublic

Authored by theron.tarigo_gmail.com on Nov 23 2019, 5:59 PM.

Details

Reviewers
danfe
Group Reviewers
Contributor Reviewers (ports)
Summary

This enables usage of Nvidia GPU on a system which has both Nvidia and non-Nvidia graphics. A new port is needed since nvidia-driver by itself expects to be the sole provider of GLX, conflicting with other drivers. Creating an nvidia-headless-driver slave port is less invasive than rewriting parts of nvidia-driver to handle all system configurations correctly.

VirtualGL is used by nvidia-hybrid-graphics nvrun-vgl command to move rendered frames from Nvidia GPU to the user's X11 display.

For users of earliest Optimus GPUs (unsupported by 440.x drivers) there is FLAVOR=legacy variant of x11/nvidia-hybrid-graphics.

The most critical aspect of this review is that we must ensure that the changes to nvidia-driver port are correct, that is they must not change the behavior of that port when used alone.

Diff Detail

Lint
Lint Skipped
Unit
Unit Tests Skipped

Event Timeline

linimon retitled this revision from Nvidia headless/hybrid graphics ("Optimus" support) to new ports: Nvidia headless/hybrid graphics ("Optimus" support).Nov 23 2019, 10:34 PM

For the pkg-plist of x11/nvidia-driver, there should be this:

%%EXTENSIONSDIR%%/libglx.so
%%EXTENSIONSDIR%%/libglx.so.1

instead of this

%%MODULESDIR%%/extensions/libglx.so
%%MODULESDIR%%/extensions/libglx.so.1

So that nvidia-driver-headless could build (package phase) with legacy driver : 390, 340, 304 .

Use %%EXTENSIONSDIR%%/libglx.so in nvidia-driver/pkg-plist

For the pkg-plist of x11/nvidia-driver, there should be this:

So that nvidia-driver-headless could build (package phase) with legacy driver : 390, 340, 304 .

You're absolutely right. I let it get lost in switch from 390.x to 440.x patches.

I thought that getting the updated nvidia-headless-driver port to work with the 3xx versions would be more involved because of changed structure, but I just tried it and it works. Thanks!

Fix nvidia-driver pkg-plist. Create nvidia-headless-driver-390 (supports oldest generation of Nvidia GPUs used in hybrid graphics configuration).

Tested and confirmed that the nvidia-driver patches do not alter the nvidia-driver or nvidia-driver-390 builds.

I let it get lost in switch from 390.x to 440.x patches.
I thought that getting the updated nvidia-headless-driver port to work with the 3xx versions would be more involved because of changed structure, but I just tried it and it works. Thanks!

I see now why I left it out. However having both 390.x and 440.x work is a simple fix. Confirmed that this revision does not alter the builds of nvidia-driver and nvidia-driver-390, so that the only functional change of this revision is the creation of new ports.

x11/nvidia-hybrid-graphics/Makefile
9

here (and in headless-utils) having a run depend on nvidia-headless-driver will force the install of the latest nvidia driver which will prevent legacy driver user to install nvidia-hybrid-graphics.
To this I see two solutions: not depending on the nvidia driver so that user can choose the version, or having a slave port with the version like for nvidia-headless-driver

x11/nvidia-hybrid-graphics/Makefile
9

Thanks. Is using FLAVORS for such small variations (that need to be packaged) no longer controversial? If I understand https://www.freebsd.org/doc/en_US.ISO8859-1/books/porters-handbook/flavors-using.html correctly, this is an intended use (the flavor would be "390" or "legacy")

This seems preferable to either creating more slave port directories or removing the dependency, which would allow installation of a useless hybrid-graphics package and foreseeably cause user frustration (despite a warning in pkg-message).

Wanted to chime in here that this patchset seems to work well on my thinkpad P43s with i915 and Quadro P520 gpu's installed. running both chrome and firefox works well, they report the nvidia gpu being used and webGL demo's seem to render without issues. I did bump the nvidia-driver DISTVERSION to 440.82 from 440.64. I did no have to pass any special configuration options to Xorg either, so it seems the latest xorg-1.20 code is playing nicely as well.

x11/nvidia-headless-driver-390/Makefile
4

By not specifying the DISTVERSION to 390.132 the build will use DISTVERSION 440.82 (I don't understand why but it is happening), and then the port name will be nvidia-headless-driver instead of nvidia-headless-driver-390 .
At least that the result that I get using synth, but I think that this should happen to poudriere as well.
At the moment using this fix it

DISTVERSION= 390.132
HEADLESS_MASTERDIR=	${.CURDIR}/../nvidia-headless-driver
PKGNAMESUFFIX=	-390
.include "${HEADLESS_MASTERDIR}/Makefile"
x11/nvidia-hybrid-graphics/Makefile
12

I'm a bit obscured by RUN_DEPENDS= nvidia-headless-utils and using nvidia-headless-utils as MASTERDIR at the same time. Why is this port a slave at all?

x11/nvidia-hybrid-graphics/Makefile
12

I had the two separate ports for two different use-cases:

  • Headless graphics. Only the bare minimum for using command-line OpenGL (in future: OpenCL and Vulkan) workflow.
  • Hybrid graphics. Real-time rendering to the Intel display, requiring VirtualGL

I thought for the headless case, dependency on a particular nvidia driver version and VirtualGL are extraneous.
But for hybrid graphics case, pulling in all the parts from a single pkg-install on a new desktop installation seems best, thus the dependencies.

The hybrid case is a strict superset of what is needed for headless. It's still a slave port since there is only one github repository for all this.
Probably I should abandon "headless-utils" and just make it an option of hybrid-graphics port?

x11/nvidia-hybrid-graphics/Makefile
12

Probably I should abandon "headless-utils" and just make it an option of hybrid-graphics port?

I think, yes.

x11/nvidia-driver/Makefile
62

Why hiding the directory?

105

In ports, it should be spelled as .if defined(LIBGLDIR).

111

Separate NO_LIBMAP thingy looks redundant as it's always aligned LIBGLDIR, no?

299

Ditto.

305

Ditto.

323

Superfluous blank line.

x11/nvidia-headless-driver/Makefile
13

Ditto.

x11/nvidia-headless-utils/distinfo
3

Is the size is so small, perhaps it makes more sense to keep it inside the port's directory like e.g. ports-mgmt/portlint port does?

x11/nvidia-headless-utils/files/nvidia_xorg.in
38

This is wrong, in Unix, pidfiles are \n-terminated.

When NVVERSION is >= 410.057, we do

${REINPLACE_CMD} -e '/extensions\/\.nvidia\/libglx/d' ${TMPPLIST}

but when we are using the optimus version of nvidia, libglx will not be in .nvidia folder

${REINPLACE_CMD} -e '/extensions\/libglx/d' ${TMPPLIST}

I used NO_LIBMAP variable to handle this case, here a snippet of the patch:

 pre-patch:
@@ -239,8 +257,12 @@
 		/extensions\/libglxserver_nvidia\.so/d ; \
 		/10_nvidia\.json/d' ${TMPPLIST}
 .else
+.if defined(NO_LIBMAP)
+	${REINPLACE_CMD} -e '/extensions\/libglx/d' ${TMPPLIST}
+.else
 	${REINPLACE_CMD} -e '/extensions\/\.nvidia\/libglx/d' ${TMPPLIST}
 .endif
+.endif
 .if ${NVVERSION} < 415.013
 	${REINPLACE_CMD} -e '/libnvidia-egl-wayland\.so/d ; \
 		/10_nvidia_wayland\.json/d' ${TMPPLIST}