Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Solved: How to Fix OpenGL Fails to Load Due to Nvidia Driver on Linux

  • The article explains how to fix the problem of OpenGL failing to load due to the Nvidia driver on Linux systems with hybrid graphics.
  • The article provides two solutions: using prime-select to switch to the Nvidia card as the primary GPU, or using render offload to run specific applications on the Nvidia card while keeping the Intel card as the primary GPU.

If you are a Linux user who wants to run Opengl applications on your system, you may encounter a problem where OpenGL fails to load due to the Nvidia driver. This can happen when you have a hybrid graphics setup with an Intel integrated GPU and an Nvidia discrete GPU, and you are using the proprietary Nvidia driver. In this article, we will explain why this problem occurs and how to solve it.

What is OpenGL and why do I need it?

OpenGL is a cross-platform API for rendering 2D and 3D graphics. It is widely used by many applications, such as games, CAD software, simulation tools, and more. OpenGL allows developers to write portable code that can run on different operating systems and hardware platforms.

To use OpenGL, you need a graphics card that supports it and a driver that implements the OpenGL specification. The driver is responsible for translating the OpenGL commands into instructions that the graphics card can understand and execute.

What is the problem with the Nvidia driver?

The problem is that the Nvidia driver does not support the direct rendering infrastructure (DRI) version 3, which is required by some modern OpenGL applications. DRI is a mechanism that allows applications to access the graphics hardware directly, bypassing the X server. This improves performance and reduces latency.

However, the Nvidia driver only supports DRI version 2, which is incompatible with DRI version 3. This means that applications that use DRI version 3 will fail to load the Nvidia driver and fall back to the Intel driver, which may not support all the OpenGL features that the application requires. This results in errors like:

Xlib: extension "NV-GLX" missing on display "localhost:10.0".
Xlib: extension "NV-GLX" missing on display "localhost:10.0".
X Error of failed request: GLXUnsupportedPrivateRequest
 Major opcode of failed request: 149 (GLX)
 Minor opcode of failed request: 16 (X_GLXVendorPrivate)
 Serial number of failed request: 24
 Current serial number in output stream: 25

How to solve it?

There are two possible solutions to this problem:

  • Use prime-select to switch to the Nvidia card as the primary GPU.
  • Use render offload to run specific applications on the Nvidia card while keeping the Intel card as the primary GPU.

Solution 1: Use prime-select

Prime-select is a tool that allows you to choose which GPU to use as the primary one. By default, it is set to use the Intel card for power saving reasons. However, you can switch it to use the Nvidia card for better performance and compatibility with OpenGL applications.

To use prime-select, you need to install the nvidia-prime package:

sudo apt install nvidia-prime

Then, you can run the following command to switch to the Nvidia card:

sudo prime-select nvidia

You will need to reboot your system for the changes to take effect.

After rebooting, you can verify that you are using the Nvidia card by running:

glxinfo | grep OpenGL

You should see something like:

OpenGL vendor string: NVIDIA Corporation
OpenGL renderer string: GeForce RTX 2060/PCIe/SSE2
OpenGL core profile version string: 4.6.0 NVIDIA 450.102.04
OpenGL core profile shading language version string: 4.60 NVIDIA
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile
OpenGL core profile extensions:
OpenGL version string: 4.6.0 NVIDIA 450.102.04
OpenGL shading language version string: 4.60 NVIDIA
OpenGL context flags: (none)
OpenGL profile mask: (none)
OpenGL extensions:
OpenGL ES profile version string: OpenGL ES 3.2 NVIDIA 450.102.04

This means that you are using the Nvidia driver and OpenGL version 4.6.

Note that using this solution will increase your power consumption and reduce your battery life, as the Nvidia card will be always active.

Solution 2: Use render offload

Render offload is a feature that allows you to run specific applications on the Nvidia card while keeping the Intel card as the primary GPU. This way, you can save power when you are not using OpenGL applications, and still enjoy the benefits of the Nvidia card when you need them.

To use render offload, you need to install the nvidia-driver-435 or later package:

sudo apt install nvidia-driver-435

Then, you need to create or edit the file /etc/X11/xorg.conf.d/10-nvidia.conf with the following content:

Section "OutputClass"
    Identifier "Nvidia Prime"
    MatchDriver "nvidia-drm"
    Driver "nvidia"
    Option "AllowEmptyInitialConfiguration"
    Option "PrimaryGPU" "no"
    Option "SLI" "Auto"
    Option "BaseMosaic" "on"
EndSection

This will configure the X server to use the Intel card as the primary GPU and the Nvidia card as the secondary GPU.

You will need to reboot your system for the changes to take effect.

After rebooting, you can verify that you are using the Intel card by running:

glxinfo | grep OpenGL

You should see something like:

OpenGL vendor string: Intel
OpenGL renderer string: Mesa Intel(R) UHD Graphics (CML GT2)
OpenGL core profile version string: 4.6 (Core Profile) Mesa 20.2.6
OpenGL core profile shading language version string: 4.60
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile
OpenGL core profile extensions:
OpenGL version string: 4.6 (Compatibility Profile) Mesa 20.2.6
OpenGL shading language version string: 4.60
OpenGL context flags: (none)
OpenGL profile mask: compatibility profile
OpenGL extensions:
OpenGL ES profile version string: OpenGL ES 3.2 Mesa 20.2.6
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.20
OpenGL ES profile extensions:

This means that you are using the Intel driver and OpenGL version 4.6.

To run a specific application on the Nvidia card, you need to use the __NV_PRIME_RENDER_OFFLOAD=1 environment variable, for example:

__NV_PRIME_RENDER_OFFLOAD=1 glxinfo | grep OpenGL

You should see something like:

OpenGL vendor string: NVIDIA Corporation
OpenGL renderer string: GeForce RTX 2060/PCIe/SSE2
OpenGL core profile version string: 4.6.0 NVIDIA 450.102.04
OpenGL core profile shading language version string: 4.60 NVIDIA
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile
OpenGL core profile extensions:
OpenGL version string: 4.6.0 NVIDIA 450.102.04
OpenGL shading language version string: 4.60 NVIDIA
OpenGL context flags: (none)
OpenGL profile mask: (none)
OpenGL extensions:
OpenGL ES profile version string: OpenGL ES 3.2 NVIDIA 450.102.04

This means that you are using the Nvidia driver and OpenGL version 4.6 for this application only.

You can also use the __GLX_VENDOR_LIBRARY_NAME=nvidia environment variable to achieve the same result, for example:

__GLX_VENDOR_LIBRARY_NAME=nvidia glxinfo | grep OpenGL

You should see the same output as above.

Note that using this solution may require some extra steps to enable synchronization between the two GPUs, such as using the __GL_SYNC_TO_VBLANK=1 or __GL_SYNC_DISPLAY_DEVICE environment variables, or using a compositor that supports PRIME synchronization, such as KDE Plasma or Mutter.

Conclusion

In this article, we have explained why OpenGL fails to load due to the Nvidia driver on Linux systems with hybrid graphics, and how to fix it by using either prime-select or render offload. We hope that this article has helped you to solve your problem and enjoy your OpenGL applications on Linux.

Frequently Asked Questions (FAQs)

Question: How can I check which GPU is being used by an OpenGL application?

Answer: You can use the nvidia-smi command to monitor the GPU usage and memory consumption of each process running on the Nvidia card.

Question: How can I switch back to the Intel card as the primary GPU?

Answer: You can use the prime-select command with the intel argument, for example:

sudo prime-select intel

You will need to reboot your system for the changes to take effect.

Question: How can I run an OpenGL application on the Nvidia card without using the environment variables?

Answer: You can use the prime-run command, which is a wrapper script that sets the environment variables for you, for example:

prime-run glxinfo | grep OpenGL

Question: How can I update the Nvidia driver to the latest version?

Answer: You can use the nvidia-driver-460 package, which provides the latest stable driver from Nvidia, for example:

sudo apt install nvidia-driver-460

You will need to reboot your system for the changes to take effect.

Disclaimer: This article is based on personal experience and research, and is not endorsed by or affiliated with Nvidia or any other company or organization. The information provided here is for educational purposes only, and may not work for every system or situation. Use it at your own risk and discretion.

The post Solved: How to Fix OpenGL Fails to Load Due to Nvidia Driver on Linux appeared first on PUPUWEB - Information Resource for Emerging Technology Trends and Cybersecurity.



This post first appeared on PUPUWEB - Information Resource For Emerging Technology Trends And Cybersecurity, please read the originial post: here

Share the post

Solved: How to Fix OpenGL Fails to Load Due to Nvidia Driver on Linux

×

Subscribe to Pupuweb - Information Resource For Emerging Technology Trends And Cybersecurity

Get updates delivered right to your inbox!

Thank you for your subscription

×