Tuesday, November 20, 2012

Primus: Better Performance And Less Power Consumption For Bumblebee [Optimus Hybrid Graphics Chipsets]

Nvidia Optimus is a technology used to increases battery life by switching between two graphics adapters (a low-performance integrated Intel graphics adapter and a high-performance one by Nvidia) within a computer system. Optimus GPU switching is officially only supported on Windows, but it's also unofficially available on Linux thanks to the Bumblebee project.

Primus brings better performance and less power consumption when using Bumblebee, by replacing VirtualGL. According to the Bumblebee G+ page, this has the following advantages over the optirun (VirtualGL) solution used by default in Bumblebee:
  • Less overhead (better framerates) and cleaner solution (no networking or compression involved at all)
  • Fixes the "bug" that causes Bumblebee to shut down the GPU too early sometimes (no more need for the "optirun bash" workaround)
  • Less buggy/glitchy, easier to debug
  • Only uses/starts secondary GPU for OpenGL parts of applications - everything else remains on your main GPU (power savings)

The Bumblebee developers explain what Primus does and the difference between Primus / optirun in simple terms in a comment on their G+ page:

Bumblebee uses VirtualGL to copy the image generated by the second (faster) GPU to your display. VirtualGL was intended for use over a network though, so it takes a great many steps to enable this (compression, sending the image over a network link, decompression, etc).

Primus doesn't perform all these "extra" steps, instead taking a more direct route (copying the rendered image in memory to the other GPU, then displaying there). In theory this should get you better performance as well as better compatibility. Running applications will "see" the OpenGL implementation of your real hardware, nothing virtual is presented to them.

For comparison, here are the framerates I get on my laptop when using the integrated Intel graphics, when using the Nvidia graphics card using optirun and using primusrun (this is just for FPS and not an indicator for the whole performance!):

glxspheres intel gpu
Integrated (Intel) graphics

glxspheres optirun bumblebee
optirun (default in Bumblebee) using the Nvidia GPU

glxspheres primusrun bumblebee
Primus using the Nvidia GPU

As you can see, the FPS using  Primus is a lot better than using the integrated graphics or using optirun with the Nvidia GPU.

Note: I've used "vblank_mode=0 primusrun" instead of simply running "primusrun" because that was recommended by the Primus GitHub page for benchmarking. Without it, I get just 60 FPS because of vblank synchronisation.


Primus might be integrated into Bumblebee in the future, but until then you can install it separately using the instructions below.



How to install Primus for Bumblebee in Ubuntu


Firstly, you'll need to install Bumblebee, so check out the installation instructions available on the Ubuntu wiki if you haven't installed it already.

Ubuntu 12.04, 12.10 and 13.04 users can install Primus using a PPA. To add it and install Primus in Ubuntu, use the commands below:
sudo add-apt-repository ppa:zhurikhin/primus
sudo apt-get update
sudo apt-get install primus
64bit systems: to get 32bit applications to work with Primus on 64bit, also install the "primus-lib:i386" package:
sudo apt-get install primus-lib:i386


Update: Primus is now also available in the Bumblebee Stable PPA. To add the Bumblebee PPA and install Primus, use the following commands:
sudo add-apt-repository ppa:bumblebee/stable
sudo apt-get update
sudo apt-get install primus
64bit: you also need to install the "primus-libs-ia32:i386" package (note that if you're using the Primus PPA, the package name is different - "primus-lib:i386" - see above, and you should purge the previous primus* files before using the ones in the Bumblebee PPA. Hopefully this will be fixed soon):
sudo apt-get install primus-libs-ia32:i386

Arch Linux: Primus is available in AUR: primus-git, lib32-primus-git

For other Linux distributions, get the Primus source code from GitHub.

Once installed, use "primusrun APP", to launch an application or game - this works just like the "optirun" command available in Bumblebee ("APP" is the application or game executable which you want to run using the Nvidia GPU).