QEMU Virgil - Virtualization, acceleration, celebration

Updated: October 2, 2020

Virtualization is a clever thing. A computer within a computer, if you will, an endless series of possibilities and usecase scenarios. Except one. Gaming. Ask any nerd who runs virtual machines, for whatever reason, and they will most likely point out one big deficiency in all and every virtualization software - insufficiently developed or powerful enough graphics stack.

Indeed, quite often, when you run guest operating systems inside virtual machines, you are often limited by the graphics acceleration - 2D and 3D functionality that is behind the native capabilities of your host. So if you think virtualization can solve many of your issues - gaming is not one of them. Virgil 3d is a project that aims to bring 3D wonders to virtualization software, with the goal of one day offering parity to host performance. An implementation of this solution is QEMU Virgil, which allows you to have SDL2 and Virgil 3d enabled in QEMU/KVM-based virtual machines. Sounds interesting. So let's have a look.

Teaser

Setup

The one big downside with this kind of effort is that can be quite complicated, and it takes time to get everything configured and running. However, with Virgil 3d, if you want to try the existing snap package, it dispenses with all gory bits of manual compilation and whatnot. Hint: As one must always share, I be affiliated with the snap effort, so if you smell bias, run away!

sudo snap install qemu-virgil
sudo snap connect qemu-virgil:kvm

Running a virtual machine

Let's have a look at a (sample) command for how you can start a 3D-accelerated virtual machine. If you feel a little overwhelmed, I'd suggest you take a look at my Introduction to KVM guide from a few years ago. Most of the stuff detailed there still applies.

qemu-virgil -enable-kvm -m 4096 -device virtio-vga,virgl=on -display sdl,gl=on -netdev user,id=ethernet.0,hostfwd=tcp::10022-:22 -device rtl8139,netdev=ethernet.0 -soundhw ac97 kubuntu.img -boot d -cdrom kubuntu.iso

What do we have here?

Let's take a look at all these colorful options:

There are many other options you could try. Like the number of virtual CPUs, different CPU models, snapshots, disk caching mode, USB functionality, various memory management feature, and more. But we're not here to master KVM, we're here to have some 3D fun.

Create hard disk

So, you can do something like:

qemu-img create -f qcow2 kubuntu.img 20g

Start virtual machine & 3D graphics

Press Enter. Magic ensues. The virtual machine will boot, and you will soon see the desktop of whichever guest operating system you've chosen. For my test, I've selected Kubuntu 20.04, running on top of Fedora 32. But you can use anything you like for your guest, including Windows.

Booting

VM running

You can check the 3D acceleration enablement with:

glxinfo | grep "direct rendering"

3D acceleration

Now, this does not mean that every single 3D rendering function has been implemented, but it sure if a good start. Indeed, my Kubuntu VM had all the nice bits and pieces, and it was fairly sprightly, including solid 3D performance. I even ran the PassMarkburn-in test to see what gives. Cushty.

3D benchmark

Conclusion

Virgil looks like a really nice thing. Because it's a relatively simple and inexpensive solution. Now, I know people who have multi-GPU computers, and they have clever VM configurations, where different GPU cards are used separately by the host and the guest virtual machine, using PCI bus identifiers and whatnot, offering near-native performance in their guest systems. But that's often beyond the skill and budget of an ordinary nerd. Because let's be realistic, really ordinary people won't use Linux, or virtualization, or anything like that.

In between zero and everything 3D, if you have a need for some fancy graphics in your virtual machines, then perhaps Virgil can provide you with the right level of functionality. It's maybe niche, it's still in development, but it works reasonably well, and from my testing, the performance is adequate. We're still not at a stage where virtualization can fully and completely replace physical hardware (if ever), but Virgil is a right step in the right direction. Have a go, nerd away. We're done here.

Cheers.

You may also like: