How to enable 3d acceleration in KVM?

All merged.

1 Like

As for the disappointing performance…

Maybe we’re still having the wrong QEMU command line? (Because our libvirt XML files configuration files might be non-ideal.)

Quote QEMU - ArchWiki

virtio-vga / virtio-gpu is a paravirtual 3D graphics driver based on virgl. It’s mature, currently supporting only Linux guests with mesa compiled with the option gallium-drivers=virgl.

To enable 3D acceleration on the guest system, select this vga with -device virtio-vga-gl and enable the OpenGL context in the display device with -display sdl,gl=on or -display gtk,gl=on for the SDL and GTK display output respectively. Successful configuration can be confirmed looking at the kernel log in the guest:

To check

sudo dmesg | grep drm

[drm] pci: virtio-vga detected
[drm] virgl 3d acceleration enabled

Note: DRM is referring to Direct Rendering Manager. Unrelated to Digital Restrictions Management.

So instead of SPICE we might need to use in QEMU terms:

  • -display sdl,gl=on or
  • -display gtk,gl=on

We also might need to use:

  • -device virtio-vga-gl,
  • or similar.

This yet has to be translated to our XML configuration files.


SDL might be faster but comes with some disadvantages such as a lack of copy/paste feature, window not scrollable, presumably no automatic window resize, presumably no seamless entering/leaving with key/mouse of the VM window.

Source: Features/GtkDisplayState - QEMU

(I don’t know if this information is outdated. Perhaps SDL has been improved since and that wiki page being outdated.)


GTK might have better features.

source: GTK GUI for QEmu

Performance same, slower than SDL? Negligible difference? Needs testing.


So in our configuration we might need to remove:

    <graphics type='spice' autoport='yes'>

The following might work.

    <!-- Graphics settings -->
    <graphics type='sdl'>
      <listen type='none'/>
      <clipboard copypaste='no'/>
      <filetransfer enable='no'/>
      <gl enable='yes'/>
    </graphics>

    <!-- Video settings -->
    <video>
      <model type='virtio' heads='1' primary='yes'>
        <acceleration accel3d='yes'/>
      </model>
    </video>

Untested.

Please test.


I couldn’t find gtk in libvirt configuration manual. Maybe it’s undocumented. Maybe a simple

    <graphics type='gtk'>

would work.

Otherwise, we could also use manual QEMU command line:

  <qemu:commandline>
    <qemu:arg value='-display'/>
    <qemu:arg value='sdl,gl=on'/>
  </qemu:commandline>