Passthrough graphics acceleration without extra command

I have a laptop with Optimus graphics (dual graphics cards Intel+Nvidia). I pass the Nvidia one through to an HVM to use it for graphics acceleration there. I use VirtualGL to make it use the Nvidia card for acceleration and still output the result to the Qubes graphics driver.

The annoying thing is that using VirtualGL requires running every command with vglrun. So instead of the entire HVM utilizing graphics acceleration, it’s only the select programs I run with vglrun. Is there any way to redirect everything to VirtualGL?

Otherwise I read about two other possibilities, but I don’t understand them well enough:

  1. It seems you can use Bumblebee. However, that appears to require running commands with ‘optirun’, which is the same problem I have already. But how does switchable graphics work on a regular Linux bare metal installation then? Surely people using bare metal linux with switchable graphics have some kind of automated way that enables and disables the dedicated accelerator for everything, rather than having to run everything with optirun by hand.

  2. This GitHub comment proposes using Glamor: Support specifying a ROM file for PCI devices to support passthrough of laptop nVidia GPUs · Issue #7559 · QubesOS/qubes-issues · GitHub
    I set it up the way the comment describes (uncommenting the Render line in xorg.conf), but it doesn’t enable graphics acceleration in any way. I read the related commits and read about Glamor, but I don’t really understand what this is supposed to accomplish. Does anyone have insight what this is supposed to be doing?

Also this:

I suspect that you could write some kind of wrapper that will prepend all your commands with vglrun, but that would be quite annoying to handle. What if you need to run command without it?

I think the simplest way would be to just edit your desktop files. For instance, replace command in qubes-run-terminal for xfce4-terminal -x '/bin/vglrun bash'. This way you get vglrun shell when you start your terminal, and all applications that you run in it will have the same properties.

Similarly, you can edit desktop files for all applications that you want to be accelerated.

Yes, I think PRIME would be better, the problem is that requires the proprietary Nvidia driver. The proprietary driver tries to load the firmware through some kind of system call, because the firmware is not on the card itself. The comment linked in my first post explains how to emulate the system call, but it’s not working for me, all drivers still can’t load the firmware even with those changes. I don’t know what kind of system call exactly and I don’t know enough about Qubes internals to fix this. Nouveau has an override to load the firmware from a file instead. That’s how I got it to work.

Editing the shortcuts is how I’m dealing with it right now. It just doesn’t seem like a nice solution. Ideally the system should automatically use the dedicated card when necessary, just like on a bare metal Optimus installation.

As far as I know the proprietary driver should work without any additional tinkering. How do you install it? Do you run nouveau currently?

For regular Nvidia cards the proprietary driver works without tinkering nowadays, but for certain Optimus cards it does not, because the firmware is in a shared EEPROM on the mainboard, rather than on the graphics card. The proprietary driver knows how to load it from there, but that doesn’t work inside a VM, unless you patch it somehow to make it available via the same method, as the comment linked in my first post attempts to do.

1 Like

It seems like you can configure your environment to have VirtualGL functionality:

Tip: vglrun is actually just a shell script that (temporarily) sets some environment variables before running the requested application - most importantly it adds the libraries that provide all the VirtualGL functionality to LD_PRELOAD. If it better suits your workflow, you could just set those variables yourself instead. The following command lists all environment variables that vglrun would set for your particular set-up:

comm -1 -3 <(env | sort) <(vglrun env | grep -v '^\[' | sort)

https://wiki.archlinux.org/title/VirtualGL#Running_applications

I didn’t know vglrun is just a script like this. I ran the command listed there and put all environment variables in /etc/environment, now everything is accelerated. Thank you.

1 Like