QEMU Support For Rendering Vulkan Software On The Hosts GPU In Virtual Machines Using Virgil 3D Is Underway

From LinuxReviews
Jump to navigationJump to search
Vulkan-logo.png

It is currently possible to run OpenGL applications in virtual Linux machines in QEMU and have the rendering done on the host machine's GPU. It works, and it is faster than software rendering within the virtual machine, but it is not blazing fast. It will eventually be possible to render Vulkan software the exact same way.

written by 윤채경 (Yoon Chae-kyung)  2021-03-27 - last edited 2021-03-29. © CC BY

Virgil-3d-on-gentoo-linux-in-a-qemu-virtual-machine.jpg
Virgil enabled on Gentoo Linux in a QEMU virtual machine benchmarking glmark2 performance.

Virgil 3d is a collection of software for range of components such as the Linux kernel, the Mesa graphics library and the QEMU virtual machine. It can be used to run software using OpenGL rendering at a not-grinding-halt pace in a virtual Linux machine on a Linux host. It can also be used to run Linux-native OpenGL applications on Google's Chrome OS.

What You Need[edit]

The QEMU emulator has had support for Virgil for years. You do not need anything in particular to use Virgil 3d, it has built-in support. It can be enabled by running it with the virtio display driver and GL rendering.

qemu-kvm -vga virtio -display gtk,gl=on {more options}

Kernel support within the virtual machine is required to make it work. The Linux kernel has had support for a very long time. It has to be enabled with the CONFIG_DRM_VIRTIO_GPU configuration option.

There will be some incriminating evidence in the kernel ring buffer (dmesg) on Linux installations running within a virtual machine if virtio-vga is working:

File: dmesg
[drm] pci: virtio-vga detected at 0000:00:02.0
virtio-pci 0000:00:02.0: vgaarb: deactivate vga console
[drm] features: +virgl +edid
[drm] Initialized virtio_gpu 0.1.0 0 for virtio0 on minor 0
virtio_gpu virtio0: fb0: virtio_gpudrmfb frame buffer device

Virgil is also supported by the Mesa graphics library. The Mesa library within the virtual machine needs to have the virgl driver compiled in. It is included in a package named something like mesa-dri-drivers on most distributions. Gentoo Linux needs VIDEO_CARDS=virgl when compiling media-libs/mesa.

What You Get[edit]

Virgil-3d-performance-on-gentoo-linux-in-a-qemu-virtual-machine.jpg
Virgil 3D performance on Gentoo Linux in a QEMU virtual machine benchmarked by glmark2.

glmark2 is not the world's best or most versatile benchmarking tool, but it can produce some simple numbers for a quick comparison. glmark -l will list all the built-in scenes it has so you can run glmark2 --benchmark scenename if you do not want to run all of them.

glmark2 --benchmark terrain -s 1920x1050

produces widely different scores on a decent 6-core machine with a AMD RX 570 depending on what it is running on. The bare metal score is a tad higher than the score produced within a QEMU virtual machine with Virgil 3D enabled.

glmark2, terrain, 1920x1050

The jellyfish scene produces similarly dismal results.

glmark2, jellyfish, 1920x1050

So What's The Point?[edit]

The Virgil 3D GPU project, with a very sparse website at virgil3d.github.io, is clearly not something you can use to run demanding OpenGL games on a Linux distribution running in a QEMU virtual machine. It is not an alternative to running virtual machines with GPU pass-through where the virtual machine has sole access to a GPU. However, it does have a purpose which becomes clear if you look at the following graph:

glmark2, terrain, 1920x1050

The difference between 516 fps native and 60 using virgl in QEMU is huge. The difference between virgl and software rendering using llvmpipe is equally huge. Virgil 3D may not be good enough for most games, but it is good enough to run very simple OpenGL applications with some sparse GPU acceleration.

Vulkan Support Is Coming[edit]

Virgil 3D can currently only be used to run OpenGL applications. That's about to change. Google-employed software engineer Chia-I Wu is working on a virtio-gpu Vulkan driver. It is already at a state where it can be tested using the "VirGL virtual OpenGL renderer" virglrenderer - which, dispite the name, can be used to render Vulkan too if you apply the right virglrenderer patches and compile it yourself. You will also have to compile a custom Mesa build with Chia-I Wus Mesa virtio-gpu Vulkan driver patches.

Google isn't funding Wu to work on this because they want GNU/Linux desktop users to be able to run Vulkan in virtual Linux machines in QEMU, they are doing it because their Chrome OS needs it to run Linux software using Vulkan. Wus work will eventually make it possible to run Windows games from Steam (thanks to Wine/Proton) on Chromebooks.

The good news for GNU/Linux users is that it won't be very hard to add Vulkan rendering support to QEMU once the required puzzle-pieces are in place in the Mesa graphics library.

GNU/Linux users will probably be able to use QEMU to run Vulkan applications on Linux distributions in virtual machines in a year or so. The foundation is laid, but there is still much work to be done, so don't expect that virgil Vulkan support will arrive next week or next month.

5.00
(2 votes)


avatar

Intgr

9 months ago
Score 0++

Looking at these graphs, it awfully seems like the virgl frame rate is capped to 60 fps, which seems like monitor refresh rate. If true, these results are awfully misleading and the conclusions are false.

The same happens when I run glxgears on my machine (no virgl).

% glxgears Running synchronized to the vertical refresh. The framerate should be approximately the same as the monitor refresh rate. 303 frames in 5.0 seconds = 60.484 FPS

300 frames in 5.0 seconds = 59.995 FPS
avatar

Chaekyung

9 months ago
Score 1++
It is just a coincidence that "glmark2 --benchmark terrain -s 1920x1050" happens to produce a score near 60. -s 256x256 scores 68, which is above 60.
avatar

Intgr

9 months ago
Score 0++
Ah OK, thanks for confirming.
avatar

Anonymous (143964cfd7)

4 months ago
Score 0

Anyone know if concurrent guests can be supported? I tried and seems to work but sometimes there are glitches or outright blank screens. Could this somehow be supported? Would using a more powerful GPU with more memory help?

Any info appreciated.
Add your comment
LinuxReviews welcomes all comments. If you do not want to be anonymous, register or log in. It is free.