How to use Vulkan on Bumblebee - a guide to nvidia-xrun

bumblebee
vulkan
nvidia
nvidia-xrun

#1

Attention: This guide is meant for Bumblebee users on Arch-based systems and is based on my experiments and those source articles:

https://wiki.archlinux.org/index.php/Nvidia-xrun

https://www.reddit.com/r/linux_gaming/comments/5t8qb3/guide_how_i_fixed_every_problem_i_had_with_nvidia/

Bumblebee is needed on all hybrid GPU machines (which are usually laptops) because it makes a system use Intel graphics by default, which saves battery power and allows for switching on discrete Nvidia card for chosen applications with a command: primusrun appname . So for example if we want Steam and its games to use Nvidia card, we start it with a command:

$ primusrun steam

The modified command can be incorporated into desktop files or by editing start menus so the app could start seamlessly with Nvidia. However, such awaken Nvidia card doesn’t allow us to use Vulkan! This prevents Bumblebee users, from benefiting of the new Steam Play’s Proton, which uses Dxvk module to translate DX10 and DX11 titles into Vulkan API. Also, some native Linux Vulcan games like Rise of the Tomb Raider simply won’t start that way!

The solution to this is nvidia-xrun . The major premise is simple: install nvidia-xrun, use TTY to launch it with a chosen WM, then launch Steam and play games. This, however, requires some additional steps and is not so seamless as bumblebee itself. This guide is attempting to clear doubts and help with the details of that process.

I tested it all myself with Talos Principle that for me run 40-61 FPS on Bumblebee and 40-110 FPS on Nvidia-xrun, which shows that Vulkan was used. An older Linux game like for example Outcast showed the same average 40-60 FPS count on bumblebee and nvidia-xrun (so in both cases OpenGL was used). There might be some very slight performance increase in OpenGL games with nvidia-xrun from what I saw, but I didn’t test it so thoroughly.

Here is a detailed step by step guide on how to use Vulkan on Bumblebee - a guide to nvidia-xrun.

1. Check if bumblebee is working:

$ primusrun glxgears

It should open the window with spinning cogs and give frame output in terminal like this:

Screenshot_20180824_224908

307 frames in 5.0 seconds = 61.344 FPS
301 frames in 5.0 seconds = 60.024 FPS
301 frames in 5.0 seconds = 60.016 FPS
301 frames in 5.0 seconds = 60.021 FPS
301 frames in 5.0 seconds = 60.022 FPS
301 framesa  in 5.0 seconds = 60.019 FP

Close the visualisation window or use ctrl+c in a terminal to stop the process.

If it doesn’t work, this is beyond scope of this article. You should get acquainted with Bumblebee and troubleshoot what is wrong in your situation:

https://wiki.archlinux.org/index.php/Bumblebee

2. Install nvidia-xrun or nvidia-xrun-git from AUR

Use a or octopi UI, or a preferred AUR helper in a terminal to install nvidia-xrun or nvidia-xrun-git. You should already know how to do that. If not, check Manjaro wiki.

3. Install some simple WM and needed packages to configure it

Here is a thing you should understand. Nvidia-xrun is designed to run programs with Nvidia card from TTY session. However, running Steam directly on it doesn’t work well. So to work around that, we start nvidia-xrun with WM (Window Manager). There is probably no way to open complex DEs like Plasma. In fact, nvidia-xrun is likely meant to use with WM because launching any DE session will make it use it’s default WM and no other DE modules and elements will work then.

Some think that nvidia-xrun saves system resources by using basic WM but the whole usual DE session is still loaded in the background. However, Nvidia and Steam using Openbox WM may be less problematic than for example using Kwin and that may add some extra performance bonuses.

The simplest choice is to use Openbox WM (or a similar one) as it provides a menu on right-click to launch programs. However, if you run Openbox with nvidia-xrun, you get only very basic, vanilla session, without all the utilities around it, so no panel, no wallpaper or any conveniences. Because of that, aside Openbox we need some tools to manage Openbox menus to have at least some basic functionality:

$ sudo pacman -S openbox obmenu obmenu-generator

4. Create and edit ~/.nvidia-xinitrc to make nvidia-xrun start with Openbox by default:

So simply create a file:

$ nano ~/.nvidia-xinitrc

put and save there:

openbox-session

4. Log into TTY2 and use nvidia-xrun

Use ctrl+alt+f2. Give your username and password. Then type:

nvidia-xrun

input your password again.

To exit from nvidia-xrun and TTY, and go back to normal DE see point 6 of this guide.

5. Configure and use Openbox WM to start Steam.

A vanilla openbox session should start. All you will see will be almost black background and a cursor:

Right-click and choose to open xterm terminal. Inside type:

$ obmenu-generator

This will generate more proper Openbox menu based on the programs you have on your system.

Right click on black desktop to invoke Openbox menu and choose: Openbox->Reconfigure

Right-click again - you should have all your programs in the menu, although all in English:

You can also alternatively start programs from a terminal. Alt+tab works for switching windows. In fact, we use terminal now to open obmenu, which is a GUI program to edit

Unfortunately, Openbox’es menus, as the one generated lacks of Steam and some other elements - not sure why. So type in terminal:

$ obmenu

Add a new menu position and name it Steam; command: steam; put it on top, just like in the picture below:

After saving it, right-click the black desktop and see menu with Steam on the top of the list. If you don’t see it, click on Reconfigure and try again. This is how you will launch Steam from now on.

6. Log off from WM and go back to default DE.

To end Openbox session, just choose Exit from the Openbox menu or Logoff.

This should make you back to TTY2 view again. Switch to your normal DE session by pressing ctrl+alt+f1.

7. Possible issues and solutions:

Games have screen tearing (a common problem of such setup):

You need to edit /usr/bin/nvidia-xrun by changing “sudo modprobe nvidia_drm” to “sudo modprobe nvidia_drm modeset=1”. Reboot.

No way to modify sound volume on Openbox nvidia-xrun session:

Use alsamixer in a terminal to adjust the volume.

Launching Qt programs (like Konsole) may occasionally hang in Openbox session:

If you really need to use many Qt programs and it gives you issues, instead Openbox session start lxqt-session. Of course, you need to install first: lxqt-session and lxqt-admin. Then modify ~/.nvidia-xinitrc and put there lxqt-session instead. However at the end of the session, it is not enough to exit openbox, lxqt session will be active and will prevent the Nvidia card from turning off. Use:

$ lxqt-leave

Then choose log-off. This should jump you to TTY2 view.

Switching back to normal DE session with ctrl+alt+f1 crashes X

This happens on openbox-session. Change to lxqt-session as described above.

Plasma pad scrolling is reverted after switching back

Log off Plasma session and log in or go to pad settings and apply them.

There may be also some nicer way to refresh some processes, I’m open to suggestions ;).


Cannot play most steam games
Anyone Lucky with Manjaro + Overwatch? (SOLVED)
[TOC] Nvidia GPU related Tutorials
Artifact card game on dedicated graphics
New version of Steam Play (with Windows games support)
#2

For steam, still - you shouldnt run steam itself, but only the game on the stronger card. This will save room for more performance and on the other side saves battery/energy if the game has a feature like “pause on minimize”.

You can make the game run with the dedicated card by using

primusrun %command%

as start option.


on top of that, i have a question. For Nvidia, does it work to just set
VK_ICD_FILENAMES to /usr/share/vulkan/icd.d/nvidia_icd.json (or whereever the file is in manjaro), to load up nvidias vulkan?


#3

I have no idea what this file does and what is to be expected. This is the first time I see this.
Bumblebee officially won’t work with Vulkan but there are some hacks and workarounds for that like:

Make sure xpra is installed before you begin. Then, start the X11 server for the GPU through bumblebee: optirun bash . Keep the terminal open (closing it will terminate X11 for the GPU).
Then, in another terminal, run your wanted application like so: xpra start --start-child vkcube --use-display=yes --pulseaudio=no --attach=yes --exit-with-client=yes --exit-with-children=yes :8 (replace vkcube with your desired application). It should print some text and after a few seconds pop up your vulkan application, accelerated by the correct GPU, complete with the ability to resize the window etcetera.

Nvidia-xrun is one big hack too or bumblebee itself is a hack as well to make hybrid cards work on both GPUs. Optimus technology is simply not supported on Linux, hence the constant pain and awkwardness of various “solutions”.

As to battery savings, I disagree. If you run a game, you can’t think about that, you always need AC to be plugged in. Running primusrun steam is just a simple solution that works well and has no downsize IMO. Somehow running all desktop on nvidia (on PCs) is fine and people can have great performance results but running Steam interface will somehow decrease nvidia performance in games? I doubt it strongly. Maybe with some very old, very weak cards but modern ones will handle that without a problem. Although… I might do some tests to see what comes out. Maybe I am wrong?

About game parameters from Steam, I am always confused about how to use them. What %command% mean? Do I have to put a specific command there or maybe write literally %command% ? What about actually, ready commands that are shown on Steam pages? How to combine them with other ones? This gets too confusing and messy IMO. I like to keep things simple so primusrun steam and forget about the rest.


#4

Its more because of graphicsbuffer, than the actual “running” performance. I don’t know if Nvidia provides something where you can see the VRAM usage. But It takes from 9 to 500MiB (depending on Browserwindow, BPM, Resolution and available VRAM). I also know of performance downs when the steam client runs in the background and there is some kind of transition action in the client window that (thanks to GPU acceleration) spikes GPU usage for a short moment (wich was already fixed if videos running on the background, but not for transitions / game/deal advertisings).

We have to consider them. Sadly :roll_eyes:

The whole thing would be so easy if steam would just support dual graphics inside of steam. It only has to be an option to "run this game on card " and done. Even if they would only support ubuntu, with DRI prime and nvdia prime, we could figure something out to make it work.

Ahh that’s how you deal with different vulkan implementations on your system. For example AMD has 2 supported vulkan implementations on linux, and you can just switch between them. So I thought when starting the game with bumblebee = loading the nvidia driver for the game, it would just work to load also the vulkan implementation for nvidia right after the driver.


[SOLVED] Bumblebee - Vulkan Issue
[SOLVED] Bumblebee - Vulkan Issue
#5

If the card is waked by a bumblebee, vulkan cannot start. It gives some specific error, I don’t remember the exact wording of it at the moment. So I doubt this would work. This is where nvidia-xrun comes in place.

I wouldn’t be surprised to see that Bumblebee will become capable of running vulkan, because it is changing so fast. On Linux side it was enough to invent dxvk and that allowed for new, awesome technologies to arise.


#6

Yes you literally write primusrun %command%. Combine with others? just add them in there. The reason for this is because you want to run the game with primusrun… not all of steam. This is the correct and recommended method.


#7

Basically that is for optional parametres. For instance, something like vblank_mode=0 primusrun %command% -gl there would mean “My fellow computer please run this game via bumblebee primusrun using OpenGL without vsync”. %command% is a placeholder for the default game binary launch command.

What is still unclear to me (I’ve read here and there, but haven’t dug deep enough) - and that is obviously shouldn’t be covered by this howto - is what is the reason why Bumblebee does not support vulkan? I mean what are the obstacles and if any steps are taken to resolve this? Can anybody clarify please?


#8

For details about Vulkan on Bumblebee read this old, long thread:

Vulkan wasn’t included in drivers back then so that provided obstacles. Everything has changed now and it looks like on the end they are cooking some solution but it’s not there yet.

As to the Steam commands, here is the thing: I am not native English user and not overly technical person - at least from Linux point of view ;). The explanation above is still not clear enough, sorry.

  • do I have to use this %command% all the time?
  • are there any exception, if so why and where?
  • is %command% a static part of every modifying steam command or just on some? if yes or not, than why and where?
  • what does it actually do? what this %command% is for? I don’t see much sense in it, there has to be some point but it’s eluding me
  • with what elements %command% should be linked if there are more of them?
  • what is the correct order and logic of those commands?

Primusrun is a Linux command so it won’t work in Steam, it had to be DRI=1 for using discrete GPU or something like that as far I know. Where to put it? At the beginning, in the end, how to combine it with other parameters? Some say it doesn’t work for them and from lack of output this is problematic.

So basically this doesn’t make much sense to me and I prefer to avoid it, since I just don’t get it. This is why using primusrun steam feels so much simpler and less problematic. The so called “better” solution is just a horror from usability point of view. It is unclear thus it’s easy to get it wrong and you won’t get any error info, in fact you can’t tell if it’s working. If I need more elements to it, it just get confusing fast. Each infos about it are full of gaps that don’t explain it fully.


#9

normal string logic. %command% simply means whatever games launch options you are editing.
Edit the launch options for TF2 and put
primusrun %command%
just means ‘primusrun teamfortress2’. Thats it. Nothing weird.


#10

Yeah as I said just a placehodler. E.g. I have Outlast in my library. Whenever I hit run (or launch I don’t know exactly what’s written on the button in English) it executes a main game binary - outlast(.exe in Windows). This is the default command, and it is what is called %command% when making custom launch commands. Because it actually differs from one game to another for obvious reasons (outlast will run Outlast and dota2 will run Dota 2, etc) there’s a placeholder that substitutes default launch command, and it is %command%. Also a default command could be not that simple, with some options like outlast -vconsole (just for example), and it is just convenient to use such placeholders when needed, because you even don’t have to know the exact default command.
As for your question if you have to use it all the time, well, yes if you want to run a game with some extra options.
There are lots of these kind of things , for instance, some people use funny %username% when they want to address ANY user that would read their message on forum, etc. (“Be aware, %username%”).

I just confirm that it works OK. For quite a long time. steam-manjaro from official Manjaro repository.


#11

Thanks for the info. I get competing informations now and when I tested it in the past it didn’t work.

Anyway, we are getting off-topic. Primusrun is triggering bumblebee and currently it won’t work with Vulkan.

On game market Vulkan itself is still not so meaningful, because it’s too complex and too hard for game developers to learn it. There is too much time pressure so they choose DX11 which is easier. DX12 and Vulkan are very, very similar to developers from technical point of view but DX12 works only on Win10 so using it makes game not playable on Windows 7, so that’s like shooting in own foot. That is why number of DX12 games is dropping instead increasing. If some would be ready to optimize game to that extent, Vulkan has more sense because it will work on all systems, also Windows 7. Still, the time pressure and complexity of the new, deeper frameworks is strong barrier, so Vulkan is not so widely used yet.

However, Vulkan is used for DX10 and DX11 games on Steam Play so the ability to use Vulkan became very important.

I already wrote it somewhere but I wonder, how many users just forgot that bumblebee is not supporting Vulkan so they tried game on Steam Play and then reported it doesn’t work.

There is still a chance that bumblebee somehow implements it.


#12

Thank you for this tutorial. Since recent updates to battle.net I was struggling to make it work. Thanks to your post, it took just two minutes. I am using crossover by codeweavers. They boasted they made sc2 and WoW work again but they forgot to mention that bumblebee users are not included… I didn’t have time to look around how to fix that so I couldn’t have played if it weren’t for you. :slight_smile:

There are some other improvements possible. I would like to have locales in my openbox session for in-game chats. I don’t know if this should be done in systemwide xorg config files or openbox specific files? I wouldn’t want to break KDE settings…