Nvidia Optimus with Bumblebee and Primus Tips

Background

As many of you know Bumblebee is the current workaround for using Nvidia optimus with linux. At the heart of bumblebee has been VirtualGL which is now being superseded by Primus.

If you have Bumblebee you’ll know that to use your discrete card you need to invoke “optirun <application>” from the command line and then after a short wait your application runs using the VirtualGL backend. Unfortunately the VirtualGL backend does not play nice with some applications, particularly Wine and Crossover. Primus is the replacement of optirun and it all it means to the end user is that instead of using optirun you now invoke an app with “primusrun <application>”.

I highly recommend (as do the developers of Bumbleebee) primus over VirtualGL because there are a host of benefits. My favorite benefit is that it works perfectly with wine and Crossover meaning I can play my Windows games on my discrete card instead of having to use my integrated one and has substantially better performance too. Here is a post by the Bumblebee Project on G+: https://plus.google.com/102207276811032054708/posts/ic3AJRKf2VF

Installation

A fine, upstanding member of out community has already made a repo for us with OBS. software.opensuse.org:

*Install the 32bit version if running a 64bit OS along with the 64bit one as you need it for Wine/Crossover as they are 32bit. I recommend a reboot after install Primus but I don’t think it is essential.

Now if you try run something with primusrun you’ll get an error something like primus:

fatal: failed to load any of the libraries: /usr/$LIB/nvidia-bumblebee/libGL.so.1 ...

Don’t worry, the fix is super easy! All you need to do is copy a few folders and you are done.

From a terminal run:

 sudo mkdir /usr/lib/nvidia-bumblebee
sudo cp /usr/lib/nvidia/* /usr/lib/nvidia-bumblebee
sudo mkdir /usr/lib64/nvidia-bumblebee/
sudo cp /usr/lib64/nvidia/* /usr/lib64/nvidia-bumblebee

Again you might need to reboot. You could always do this with dolphin in super-user mode and just copy paste the files in the same folder and just specify “nvidia-bumblebee” as the folder name. I would highly recommend this to most users as its harder to make a mess up.

Testing

vblank_mode=0 primusrun glxspheres

It should give something like this:

:~> vblank_mode=0 primusrun  glxspheres                                                                             
Polygons in scene: 62464                                                                                                             
ATTENTION: default value of option vblank_mode overridden by environment.                                                            
ATTENTION: default value of option vblank_mode overridden by environment.                                                            
Visual ID of window: 0x96                                                                                                            
ATTENTION: default value of option vblank_mode overridden by environment.                                                            
ATTENTION: default value of option vblank_mode overridden by environment.                                                            
ATTENTION: option value of option vblank_mode ignored.                                                                               
Context is Direct                                                                                                                    
OpenGL Renderer: GeForce GT 550M/PCIe/SSE2                                                                                           
primus: sorry, not implemented: glXUseXFont                                                                                          
236.366525 frames/sec - 263.785042 Mpixels/sec                                                                                       
241.331845 frames/sec - 269.326339 Mpixels/sec                                                                                       
240.886716 frames/sec - 268.829575 Mpixels/sec                                                                                       
241.437659 frames/sec - 269.444427 Mpixels/sec                                                                                       
239.505292 frames/sec - 267.287906 Mpixels/sec   

In comparison, optirun gives:

:~> vblank_mode=0 optirun glxspheres                                                                              
Polygons in scene: 62464                                                                                                             
Visual ID of window: 0x21                                                                                                            
Context is Direct                                                                                                                    
OpenGL Renderer: GeForce GT 550M/PCIe/SSE2
110.628062 frames/sec - 123.460917 Mpixels/sec
122.449406 frames/sec - 136.653538 Mpixels/sec
133.291433 frames/sec - 148.753240 Mpixels/sec
133.511781 frames/sec - 148.999148 Mpixels/sec
134.822179 frames/sec - 150.461552 Mpixels/sec

Summary

This will not bork your system and is really worth your time if you’re a Nvidia Optimus/Bumblebee user. The improvement in performance alone is worth checking out while the greater flexibility with Wine/Crossover is a real bonus for gamers.

Hope this helps!

Tip

To launch a crossover app like steam with primusrun try:

primusrun /opt/cxoffice/bin/wine --bottle "<name of bottle>" --cx-app <name of application>

E.g.

primusrun /opt/cxoffice/bin/wine --bottle "Steam" --cx-app steam.exe

Disclaimer

If this breaks your system, deletes data or irrecoverably ruins your digital life then I am not to be held responsible as you took these steps yourself and should always double check everything you do. Try at your own risk!

Why not just link the directories, so if the nvidia libraries are updated, primus won’t be using outdated libraries?


sudo ln -s /usr/lib/nvidia /usr/lib/nvidia-bumblebee
sudo ln -s /usr/lib64/nvidia /usr/lib64/nvidia-bumblebee

Also,
I had to add a lib line to primusrun, because nvidia libraries were not in the lib path:


PRIMUS_libGL=${PRIMUS_libGL}:/usr/\$LIB/nvidia/

which I added just after this line:


# PRIMUS_libGL=${PRIMUS_libGL}:/usr/\$LIB/opengl/nvidia/lib

Thanks for the information!
Eric

OpenSuse 12.2
Nvidia drivers installed from: Index of /repositories/home:/Bumblebee-Project:/nVidia:/latest/openSUSE_12.2
bumblebee and primus installed from: Index of /repositories/home:/Overman79/openSUSE_12.2
Got this from the 3rd post in: https://forums.opensuse.org/english/get-technical-help-here/64-bit/479942-right-nvidia-optimus-driver-configuration.html

Thanks for posting this info on Primus me3064. It’s good to see the development that is going on in support of those with hybrid graphics hardware. I don’t own such hardware so, haven’t really kept up with the state of play.

Idiot me! Why did I “forget” about symlinks. They are such useful little things. This is definitely a better solution.

That’s surprising. I didn’t have to do that at all. I wonder what differences in set-up we have that would cause something like that. The use of symlinks shouldn’t be a factor.

Another thing, people should remember to disable composting desktops when working with primus. You’ll get skipped frames, poor performance and sometimes artifacts/tearing. On KDE you can just hit Alt+Shift+F12 to toggle composting on and off.

And here’s another one that should have thought about something. Uninstalled vdrift (my testcase) before thinking about disabling KDE’s desktop effects :smiley:

Hi guys,

I just got my Sager NP9150 laptop with 3rd gen intel i7 processor and nVidia GTX 670MX graphics card, and installed opensuse 12.2 on it. I installed bumblebee from Index of /repositories/home:/Overman79/openSUSE_12.2 and nvidia drivers from Index of /repositories/home:/Bumblebee-Project:/nVidia:/latest/openSUSE_12.2 . I then created the links like so:


sudo ln -s /usr/lib/nvidia /usr/lib/nvidia-bumblebee sudo ln -s /usr/lib64/nvidia /usr/lib64/nvidia-bumblebee

Now, I can run opensuse without “nomodeset” in boot options. I can also run programs with optirun and primusrun, but I am getting more performance using optirun instead of running with primusrun:

shekhar@nuxpc:~> optirun glxspheres
Polygons in scene: 62464
Visual ID of window: 0x21
Context is Direct
OpenGL Renderer: GeForce GTX 670MX/PCIe/SSE2
128.540991 frames/sec - 143.451746 Mpixels/sec
128.211575 frames/sec - 143.084118 Mpixels/sec
129.766444 frames/sec - 144.819351 Mpixels/sec
129.740692 frames/sec - 144.790612 Mpixels/sec



shekhar@nuxpc:~> primusrun glxspheres
Polygons in scene: 62464
Visual ID of window: 0x9a
Context is Direct
OpenGL Renderer: GeForce GTX 670MX/PCIe/SSE2
primus: sorry, not implemented: glXUseXFont
61.028143 frames/sec - 68.107407 Mpixels/sec
59.687538 frames/sec - 66.611293 Mpixels/sec
59.677998 frames/sec - 66.600646 Mpixels/sec
59.683653 frames/sec - 66.606956 Mpixels/sec
59.706089 frames/sec - 66.631995 Mpixels/sec
59.652635 frames/sec - 66.572340 Mpixels/sec



shekhar@nuxpc:~> glxspheres
Polygons in scene: 62464                                                                       
Visual ID of window: 0x9a                                                                       
Context is Direct                                                                               
OpenGL Renderer: Mesa DRI Intel(R) Ivybridge Mobile                                                 
55.882620 frames/sec - 62.365004 Mpixels/sec                                                           
57.641833 frames/sec - 64.328286 Mpixels/sec                                                           
59.194579 frames/sec - 66.061150 Mpixels/sec                                                             
55.231061 frames/sec - 61.637864 Mpixels/sec                                                                   
58.113533 frames/sec - 64.854703 Mpixels/sec                                                                   
57.230644 frames/sec - 63.869399 Mpixels/sec                                                                   
57.193870 frames/sec - 63.828359 Mpixels/sec                                                                   
57.134889 frames/sec - 63.762536 Mpixels/sec 


While using primusrun, the performance is similiar to that of running without optirun. Also, while using primus, it says “sorry, not implemented: glXUseXFont”.

Any idea on why I am getting poor performance with primusrun?

Found the culprit: vblank_mode=0 was missing, (I am assuming, it drops the frames to match with the display framerate to avoid unnecessary computation)


shekhar@nuxpc:~> vblank_mode=0 primusrun glxspheres
Polygons in scene: 62464                                                                                             
ATTENTION: default value of option vblank_mode overridden by environment.                                              
ATTENTION: default value of option vblank_mode overridden by environment.                                              
Visual ID of window: 0x9a                                                                                                  
ATTENTION: default value of option vblank_mode overridden by environment.                                                  
ATTENTION: default value of option vblank_mode overridden by environment.                                                  
ATTENTION: option value of option vblank_mode ignored.
Context is Direct
OpenGL Renderer: GeForce GTX 670MX/PCIe/SSE2
primus: sorry, not implemented: glXUseXFont
347.210224 frames/sec - 387.486610 Mpixels/sec
373.126234 frames/sec - 416.408877 Mpixels/sec
372.699481 frames/sec - 415.932620 Mpixels/sec
371.692007 frames/sec - 414.808280 Mpixels/sec