Page MenuHomeFreeBSD

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

Authored by theron.tarigo_gmail.com on Nov 23 2019, 5:59 PM.
Tags
None
Referenced Files
Unknown Object (File)
Tue, Nov 26, 8:55 AM
Unknown Object (File)
Tue, Nov 26, 6:29 AM
Unknown Object (File)
Mon, Nov 25, 3:23 PM
Unknown Object (File)
Wed, Nov 20, 9:45 PM
Unknown Object (File)
Wed, Nov 20, 7:55 PM
Unknown Object (File)
Wed, Nov 20, 7:55 PM
Unknown Object (File)
Wed, Nov 20, 7:55 PM
Unknown Object (File)
Wed, Nov 20, 7:55 PM

Details

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=390 variant of x11/nvidia-hybrid-graphics.

Diff Detail

Repository
rP FreeBSD ports repository
Lint
Lint Skipped
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
10

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
10

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 ↗(On Diff #69297)

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
13

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
13

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
13

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
14

Ditto.

x11/nvidia-headless-utils/distinfo
4

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
39

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}
theron.tarigo_gmail.com edited the summary of this revision. (Show Details)

Simplified the ports.
External source for small scripts is no longer used.
pkg-messages improved.

These are addressed by the latest diff.

theron.tarigo_gmail.com added inline comments.
x11/nvidia-driver/Makefile
62

This is the existing implementation, both x11/nvidia-driver and x11-servers/xorg-server's install script know about this directory. I merely refactored it to its own variable so nvidia-secondary-driver may override it.
It is moot for the 4xx drivers since 410.057, but still needed for -390 legacy drivers.

Fixed the file paths by uploading a correctly formatted diff this time.

x11/nvidia-settings/files/nvidia-settings.in
4

Here it seems that exec %%PREFIX%%/libexec/nvidia-settings "$@" is always called, even when there is %%LOCALBASE%%/libexec/nvidia-settings-hybrid

Shouldn't this be
[ -e "%%LOCALBASE%%/libexec/nvidia-settings-hybrid" ] && exec %%LOCALBASE%%/libexec/nvidia-settings-hybrid "$@" || exec %%PREFIX%%/libexec/nvidia-settings "$@"
Instead ?

theron.tarigo_gmail.com added inline comments.
x11/nvidia-settings/files/nvidia-settings.in
4

exec replaces shell process with the new process, therefore the script does not continue and there is no superfluous shell process once libexec/nvidia-settings(-hybrid) is running.

x11/nvidia-hybrid-graphics/Makefile
41–43

You should be using x_IMPLIES instead: 5.13.3.7. OPT_IMPLIES

80

As VIRTUALGL is required by OPTIRUN, this is not needed.

theron.tarigo_gmail.com marked an inline comment as done.

Use OPT_IMPLIES for OPTIRUN->VIRTUALGL dependency

x11/nvidia-driver/Makefile
13

DISTVERSION upstream has been bumped to 460.80 so the patch needs to be updated or resync'd to ensure the portname change gets picked up.

This revision was not accepted when it landed; it landed in state Needs Review.Jun 15 2021, 7:31 PM
This revision was automatically updated to reflect the committed changes.