Skip to content

Instantly share code, notes, and snippets.

@plembo
Last active April 25, 2024 16:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save plembo/c545f802652d3386cc6798a771684cbf to your computer and use it in GitHub Desktop.
Save plembo/c545f802652d3386cc6798a771684cbf to your computer and use it in GitHub Desktop.
3d acceleration for Linux guests in KVM on Ubuntu Desktop

VirGL for Linux KVM guests on Ubuntu Desktop

NOTE: Please don't ask for help here, it was a miracle that I got it to work at all. Seek answers in the usual places (yes, even Stackoverflow knows more than I do).

The question: How can I get 3d accelerated graphics for Linux guests in KVM without using PCI passthrough?

The short answer is: Use VirGL. The long answer is more complicated, because the VirGL project has had slow but steady progress towards actually working reliably, but the degree to which any given Linux distribution (or related driver project) is in sync has varied greatly over time. Even if it works right now, today, on your machine, it might not tomorrow. Note that even when it works, graphics performance is mediocre to downright painful.

Tested on Ubuntu Desktop 22.04.04 LTS with qemu-kvm, in an "Ubuntu on Xorg" session (not Wayland). Linux quests must have spice-vdagent installed (Ubuntu installs this by default). The hardware is a AMD 5600G desktop with a NVIDIA GTX3050, and a Intel i5-10300H laptop with a mobile NVIDIA GTX1650 TI.

For practical purposes, there's no difference in the configuration for the desktop and laptop. Both need the egl-headless device.

Procedure

  1. In VirtManager > Video > VirtIo enable 3D acceleration.
  2. Display > Spice set listen type to None, and leave OpenGL unchecked
  3. Overview > XML
  4. Add the following additional node under the existing <graphics> block:
<graphics type="egl-headless">
   <gl rendernode="/dev/dri/renderD128"/>
</graphics>
  1. Save and start VM.

3D acceleration for Windows guests?

Not yet, although it is being worked on. I've been using the viogpu drivers on my Windows guests in conjunction with virtio graphics for a while, but that only provides 2D acceleration. While virtio is included in modern Linux kernels and spice-vdagent by most Linux distributions, Windows requires the latest spice-guest-tools and virtio-win drivers from the virtio-win ISO (including viogpudo), but performance is currently about the same as Video QXL. Of course, both Oracle VirtualBox and VMware Workstation Player have 3D acceleration that is better than nothing: but not by much.

On Windows you can get display details by calling up the dxdiag tool and looking at the Display tab. GLView will show any OpenGL version loaded (it crashes on my Windows guests).

Testing

To quickly check performance on Linux, install and use mesa-utils and glmark2.

Keep in mind that this is a virtual 3D card, not PCI pass-through of your host's integrated or discrete graphics card. Running even moderately demanding benchmarks like "Valley" is not recommended.

What difference does it make? My quick comparion of GLMark scores between a QXL and virtio VirGL Linux guest resulted in pretty decent scores for VirGL, about equivalent to a bare-metal iGPU (like Intel's UHD 620 or 630). Enough to prevent lagging in many services (including YouTube videos), although still not ideal for most games even at the lowest resolution. 2D QXL's performance on Linux falls far short of VirGL 3D.

References

"VirGL". Mesa3D documentation, https://docs.mesa3d.org/drivers/virgl/.

Max R. "Draft: virgl/win: Virtio GPU 3D acceleration for Windows". Mesa Merge Requests, 24 July 2023, https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24223 (last update by requestor, 11 April 2024).

ninjachicken1. "How do I get a multi-display virgl 3D accelerated QEMU VM on an NVIDIA card in virt manager". Superuser, 14 August 2023, https://superuser.com/questions/1804067/how-do-i-get-a-multi-display-virgl-3d-accelerated-qemu-vm-on-a-nvidia-card-in-vi.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment