You are not logged in.

#1 2019-02-06 10:58:34

GloW_on_dub
Member
Registered: 2013-03-13
Posts: 388

[SOLVED] How to use mesa while nvidia module is loaded ?

[Note] This post is unrelated to optimus, bumblebee or bbswitch

I have a desktop computed with a nvidia GPU on it.
I'm trying to be able to switch between nvidia and mesa with an environment variable

Here is what I'm able to achieve so far :

Without nvidia package installed and with nouveau :

$  glxinfo | grep OpenGL | grep string
OpenGL vendor string: nouveau
OpenGL renderer string: NVE6
OpenGL core profile version string: 4.3 (Core Profile) Mesa 18.3.2
OpenGL core profile shading language version string: 4.30
OpenGL version string: 4.3 (Compatibility Profile) Mesa 18.3.2
OpenGL shading language version string: 4.30
OpenGL ES profile version string: OpenGL ES 3.2 Mesa 18.3.2
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.20
$ LIBGL_ALWAYS_SOFTWARE=1 glxinfo | grep OpenGL | grep string
OpenGL vendor string: VMware, Inc.
OpenGL renderer string: llvmpipe (LLVM 7.0, 256 bits)
OpenGL core profile version string: 3.3 (Core Profile) Mesa 18.3.2
OpenGL core profile shading language version string: 3.30
OpenGL version string: 3.1 Mesa 18.3.2
OpenGL shading language version string: 1.40
OpenGL ES profile version string: OpenGL ES 3.0 Mesa 18.3.2
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.00

With nvidia package installed (and nouveau automatically blacklisted):

$ glxinfo | grep OpenGL | grep string
OpenGL vendor string: NVIDIA Corporation
OpenGL renderer string: GeForce GTX 645/PCIe/SSE2
OpenGL core profile version string: 4.6.0 NVIDIA 415.27
OpenGL core profile shading language version string: 4.60 NVIDIA
OpenGL version string: 4.6.0 NVIDIA 415.27
OpenGL shading language version string: 4.60 NVIDIA
OpenGL ES profile version string: OpenGL ES 3.2 NVIDIA 415.27
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.20
$ LIBGL_ALWAYS_SOFTWARE=1 glxinfo | grep OpenGL | grep string
OpenGL vendor string: NVIDIA Corporation
OpenGL renderer string: GeForce GTX 645/PCIe/SSE2
OpenGL core profile version string: 4.6.0 NVIDIA 415.27
OpenGL core profile shading language version string: 4.60 NVIDIA
OpenGL version string: 4.6.0 NVIDIA 415.27
OpenGL shading language version string: 4.60 NVIDIA
OpenGL ES profile version string: OpenGL ES 3.2 NVIDIA 415.27
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.20
$ __GLX_VENDOR_LIBRARY_NAME=mesa glxinfo | grep OpenGL | grep string
libGL error: No matching fbConfigs or visuals found
libGL error: failed to load driver: swrast
X Error of failed request:  GLXBadContext
  Major opcode of failed request:  151 (GLX)
  Minor opcode of failed request:  6 (X_GLXIsDirect)
  Serial number of failed request:  53
  Current serial number in output stream:  52

So, in conclusion, LIBGL_ALWAYS_SOFTWARE is ignored by the nvidia module, __GLX_VENDOR_LIBRARY_NAME=mesa fails completely, and the only way to use mesa so far is to remove (or blacklist) nvidia.
What would be the right way to use mesa while having nvidia module loaded ?

Last edited by GloW_on_dub (2019-02-07 16:19:58)

Offline

#2 2019-02-06 13:12:53

seth
Member
Registered: 2012-09-03
Posts: 50,008

Re: [SOLVED] How to use mesa while nvidia module is loaded ?

It's ignored by the nvidia GL implementation and what you try is not possible.
You'll have to unload the nvidia module and load nouveau.

What's the point of this exercise?
If you just want to run SW rendered OpenGL on the nvidia blob, use a nested X11 server (Xephyr)

Offline

#3 2019-02-07 11:11:41

Lone_Wolf
Member
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 11,868

Re: [SOLVED] How to use mesa while nvidia module is loaded ?

seth wrote:

It's ignored by the nvidia GL implementation and what you try is not possible.
You'll have to unload the nvidia module and load nouveau.

Maybe it's possible .

libglvnd readme.md wrote:

libglvnd is a vendor-neutral dispatch layer for arbitrating OpenGL API calls between multiple vendors. It allows multiple drivers from different vendors to coexist on the same filesystem, and determines which vendor to dispatch each API call to at runtime.

emphasis is mine.

Check https://github.com/NVIDIA/libglvnd/blob … /README.md , it should give an idea how the mechanism works.

A quick read of it suggests it matters whether you need OpenGL, GLX or EGL to be rerouted.
You'll also need to create a suitable context and set the glvendor it uses.

As seth asked, please elaborate on your purpose.

Last edited by Lone_Wolf (2019-02-07 11:12:07)


Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.


(A works at time B)  && (time C > time B ) ≠  (A works at time C)

Offline

#4 2019-02-07 12:52:10

seth
Member
Registered: 2012-09-03
Posts: 50,008

Re: [SOLVED] How to use mesa while nvidia module is loaded ?

libGLX_mesa.so will not talk to the nvidia stack.
libglvnd turns libGL* into wrappers that invoke the proper backend - the purpose is the optimus scenario as you'll have to use different GL implementations for intel and the nvidia driver.
But if you've an X11 server using the nvidia driver and thus the nvidia kernel module, libGLX_mesa.so will either throw you the error in his last output or segfault.

Offline

#5 2019-02-07 15:43:15

GloW_on_dub
Member
Registered: 2013-03-13
Posts: 388

Re: [SOLVED] How to use mesa while nvidia module is loaded ?

I'm working on an OpenGL application. I have a mesa specific bug that has been found by a user and finding a way to switch from mesa to Nvidia without unloading/loading modules would be a workflow improvement on my side.


If you just want to run SW rendered OpenGL on the nvidia blob, use a nested X11 server (Xephyr)

That seems uselessly complicated to use Xephyr in order to run a single application with mesa instead of nvidia.


Check https://github.com/NVIDIA/libglvnd/blob … /README.md , it should give an idea how the mechanism works.

__GLX_VENDOR_LIBRARY_NAME=mesa  is indeed talking to libglvnd https://github.com/NVIDIA/libglvnd/blob … lx.c#L2109, and I would have expected this to work, but it does not.

Last edited by GloW_on_dub (2019-02-07 15:46:33)

Offline

#6 2019-02-07 15:51:56

seth
Member
Registered: 2012-09-03
Posts: 50,008

Re: [SOLVED] How to use mesa while nvidia module is loaded ?

=> Use Xephyr to get a mesa stack (assuming it's not a performance bug)

Offline

#7 2019-02-07 16:19:34

GloW_on_dub
Member
Registered: 2013-03-13
Posts: 388

Re: [SOLVED] How to use mesa while nvidia module is loaded ?

It is indeed working great, thanks.
My usecase is solved, but libglvnd is suposed to have this capability.

for reference :

$ glxinfo | grep OpenGL | grep string
OpenGL vendor string: NVIDIA Corporation
OpenGL renderer string: GeForce GTX 645/PCIe/SSE2
OpenGL core profile version string: 4.6.0 NVIDIA 415.27
OpenGL core profile shading language version string: 4.60 NVIDIA
OpenGL version string: 4.6.0 NVIDIA 415.27
OpenGL shading language version string: 4.60 NVIDIA
OpenGL ES profile version string: OpenGL ES 3.2 NVIDIA 415.27
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.20

$ Xephyr -br -ac -noreset -screen 1920x1080 :1&
[1] 14200

$ DISPLAY=:1 glxinfo | grep OpenGL | grep string
OpenGL vendor string: VMware, Inc.
OpenGL renderer string: llvmpipe (LLVM 7.0, 256 bits)
OpenGL core profile version string: 3.3 (Core Profile) Mesa 18.3.3
OpenGL core profile shading language version string: 3.30
OpenGL version string: 3.1 Mesa 18.3.3
OpenGL shading language version string: 1.40
OpenGL ES profile version string: OpenGL ES 3.0 Mesa 18.3.3
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.00

Offline

#8 2019-02-07 16:26:08

seth
Member
Registered: 2012-09-03
Posts: 50,008

Re: [SOLVED] How to use mesa while nvidia module is loaded ?

No, it is not. This is for the optimus scenario, where you got different and incompatible stacks.
The mesa GLX implementation is utterly incompatible w/ the nvidia drivers and the nvidia GL implementation likewise w/ everything else.
The purpose of libglvnd is to have both installed at the same time so you can select which SW/HW stack to use, but it's going down either the nvidia route or the mesa one (typically to an intel chip) - complete w/ different X11 drivers and kernel modules and chips.
Xephyr basically gets you that w/o a second GPU, in a more "emulated" way.

Offline

#9 2019-02-08 13:03:27

GloW_on_dub
Member
Registered: 2013-03-13
Posts: 388

Re: [SOLVED] How to use mesa while nvidia module is loaded ?

Thanks for the explanation.

for completion, I want to mention that I was able to switch between mesa and nvidia by building mesa myself and then pointing to the mesa libs in LD_LIBRARY_PATH.

$ glxinfo | grep OpenGL | grep string
OpenGL vendor string: NVIDIA Corporation
OpenGL renderer string: GeForce GTX 645/PCIe/SSE2
OpenGL core profile version string: 4.6.0 NVIDIA 415.27
OpenGL core profile shading language version string: 4.60 NVIDIA
OpenGL version string: 4.6.0 NVIDIA 415.27
OpenGL shading language version string: 4.60 NVIDIA
OpenGL ES profile version string: OpenGL ES 3.2 NVIDIA 415.27
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.20

$ LD_LIBRARY_PATH=/path/to/llvm/install/lib/:/path/to/mesa/install/lib/ glxinfo | grep OpenGL | grep string
OpenGL vendor string: VMware, Inc.
OpenGL renderer string: Gallium 0.4 on llvmpipe (LLVM 3.9, 256 bits)
OpenGL core profile version string: 3.3 (Core Profile) Mesa 13.0.6
OpenGL core profile shading language version string: 3.30
OpenGL version string: 3.0 Mesa 13.0.6
OpenGL shading language version string: 1.30
OpenGL ES profile version string: OpenGL ES 3.0 Mesa 13.0.6
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.00

Offline

#10 2019-02-08 13:35:14

seth
Member
Registered: 2012-09-03
Posts: 50,008

Re: [SOLVED] How to use mesa while nvidia module is loaded ?

Be aware that you might run into random segfaults when things get more real than glxinfo (a common theme when libGL* was exclusive and users had linked the wrong lib)

Offline

#11 2019-02-08 14:46:10

Lone_Wolf
Member
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 11,868

Re: [SOLVED] How to use mesa while nvidia module is loaded ?

Pity glvnd is so limited.

For a short time i was dreaming of a system with 4+ videocards from multiple brands and models all doing what they're best suited for, managed by libglvnd


Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.


(A works at time B)  && (time C > time B ) ≠  (A works at time C)

Offline

#12 2019-02-09 11:05:57

Gusar
Member
Registered: 2009-08-25
Posts: 3,605

Re: [SOLVED] How to use mesa while nvidia module is loaded ?

Lone_Wolf wrote:

Pity glvnd is so limited.

glvnd only handles the client-side, but there's still the server-side GLX module to take care of. Nvidia just sent a RFC to the mesa list on how to handle GLX, so things are moving forward: https://lists.freedesktop.org/archives/ … 14832.html

Offline

#13 2019-02-09 11:18:08

Lone_Wolf
Member
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 11,868

Re: [SOLVED] How to use mesa while nvidia module is loaded ?

I just noticed it on xorg devel, does seem i'm not the only one that want such functionality.


Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.


(A works at time B)  && (time C > time B ) ≠  (A works at time C)

Offline

Board footer

Powered by FluxBB