1773f61e9SGurchetan Singh.. 2773f61e9SGurchetan Singh SPDX-License-Identifier: GPL-2.0-or-later 3773f61e9SGurchetan Singh 4773f61e9SGurchetan Singhvirtio-gpu 5773f61e9SGurchetan Singh========== 6773f61e9SGurchetan Singh 7773f61e9SGurchetan SinghThis document explains the setup and usage of the virtio-gpu device. 8773f61e9SGurchetan SinghThe virtio-gpu device paravirtualizes the GPU and display controller. 9773f61e9SGurchetan Singh 10773f61e9SGurchetan SinghLinux kernel support 11773f61e9SGurchetan Singh-------------------- 12773f61e9SGurchetan Singh 13773f61e9SGurchetan Singhvirtio-gpu requires a guest Linux kernel built with the 14773f61e9SGurchetan Singh``CONFIG_DRM_VIRTIO_GPU`` option. 15773f61e9SGurchetan Singh 16773f61e9SGurchetan SinghQEMU virtio-gpu variants 17773f61e9SGurchetan Singh------------------------ 18773f61e9SGurchetan Singh 19773f61e9SGurchetan SinghQEMU virtio-gpu device variants come in the following form: 20773f61e9SGurchetan Singh 21773f61e9SGurchetan Singh * ``virtio-vga[-BACKEND]`` 22773f61e9SGurchetan Singh * ``virtio-gpu[-BACKEND][-INTERFACE]`` 23773f61e9SGurchetan Singh * ``vhost-user-vga`` 24773f61e9SGurchetan Singh * ``vhost-user-pci`` 25773f61e9SGurchetan Singh 26773f61e9SGurchetan Singh**Backends:** QEMU provides a 2D virtio-gpu backend, and two accelerated 27773f61e9SGurchetan Singhbackends: virglrenderer ('gl' device label) and rutabaga_gfx ('rutabaga' 28773f61e9SGurchetan Singhdevice label). There is a vhost-user backend that runs the graphics stack 29773f61e9SGurchetan Singhin a separate process for improved isolation. 30773f61e9SGurchetan Singh 31773f61e9SGurchetan Singh**Interfaces:** QEMU further categorizes virtio-gpu device variants based 32773f61e9SGurchetan Singhon the interface exposed to the guest. The interfaces can be classified 33773f61e9SGurchetan Singhinto VGA and non-VGA variants. The VGA ones are prefixed with virtio-vga 34773f61e9SGurchetan Singhor vhost-user-vga while the non-VGA ones are prefixed with virtio-gpu or 35773f61e9SGurchetan Singhvhost-user-gpu. 36773f61e9SGurchetan Singh 37773f61e9SGurchetan SinghThe VGA ones always use the PCI interface, but for the non-VGA ones, the 38773f61e9SGurchetan Singhuser can further pick between MMIO or PCI. For MMIO, the user can suffix 39773f61e9SGurchetan Singhthe device name with -device, though vhost-user-gpu does not support MMIO. 40773f61e9SGurchetan SinghFor PCI, the user can suffix it with -pci. Without these suffixes, the 41773f61e9SGurchetan Singhplatform default will be chosen. 42773f61e9SGurchetan Singh 43773f61e9SGurchetan Singhvirtio-gpu 2d 44773f61e9SGurchetan Singh------------- 45773f61e9SGurchetan Singh 46773f61e9SGurchetan SinghThe default 2D backend only performs 2D operations. The guest needs to 47773f61e9SGurchetan Singhemploy a software renderer for 3D graphics. 48773f61e9SGurchetan Singh 49773f61e9SGurchetan SinghTypically, the software renderer is provided by `Mesa`_ or `SwiftShader`_. 50773f61e9SGurchetan SinghMesa's implementations (LLVMpipe, Lavapipe and virgl below) work out of box 51773f61e9SGurchetan Singhon typical modern Linux distributions. 52773f61e9SGurchetan Singh 53773f61e9SGurchetan Singh.. parsed-literal:: 54773f61e9SGurchetan Singh -device virtio-gpu 55773f61e9SGurchetan Singh 56773f61e9SGurchetan Singh.. _Mesa: https://www.mesa3d.org/ 57773f61e9SGurchetan Singh.. _SwiftShader: https://github.com/google/swiftshader 58773f61e9SGurchetan Singh 59773f61e9SGurchetan Singhvirtio-gpu virglrenderer 60773f61e9SGurchetan Singh------------------------ 61773f61e9SGurchetan Singh 62773f61e9SGurchetan SinghWhen using virgl accelerated graphics mode in the guest, OpenGL API calls 63773f61e9SGurchetan Singhare translated into an intermediate representation (see `Gallium3D`_). The 64773f61e9SGurchetan Singhintermediate representation is communicated to the host and the 65773f61e9SGurchetan Singh`virglrenderer`_ library on the host translates the intermediate 66773f61e9SGurchetan Singhrepresentation back to OpenGL API calls. 67773f61e9SGurchetan Singh 68773f61e9SGurchetan Singh.. parsed-literal:: 69773f61e9SGurchetan Singh -device virtio-gpu-gl 70773f61e9SGurchetan Singh 71773f61e9SGurchetan Singh.. _Gallium3D: https://www.freedesktop.org/wiki/Software/gallium/ 72773f61e9SGurchetan Singh.. _virglrenderer: https://gitlab.freedesktop.org/virgl/virglrenderer/ 73773f61e9SGurchetan Singh 74*94d0ea1cSAntonio CaggianoTranslation of Vulkan API calls is supported since release of `virglrenderer`_ 75*94d0ea1cSAntonio Caggianov1.0.0 using `venus`_ protocol. ``Venus`` virtio-gpu capability set ("capset") 76*94d0ea1cSAntonio Caggianorequires host blob support (``hostmem`` and ``blob`` fields) and should 77*94d0ea1cSAntonio Caggianobe enabled using ``venus`` field. The ``hostmem`` field specifies the size 78*94d0ea1cSAntonio Caggianoof virtio-gpu host memory window. This is typically between 256M and 8G. 79*94d0ea1cSAntonio Caggiano 80*94d0ea1cSAntonio Caggiano.. parsed-literal:: 81*94d0ea1cSAntonio Caggiano -device virtio-gpu-gl,hostmem=8G,blob=true,venus=true 82*94d0ea1cSAntonio Caggiano 83*94d0ea1cSAntonio Caggiano.. _venus: https://gitlab.freedesktop.org/virgl/venus-protocol/ 84*94d0ea1cSAntonio Caggiano 85773f61e9SGurchetan Singhvirtio-gpu rutabaga 86773f61e9SGurchetan Singh------------------- 87773f61e9SGurchetan Singh 88773f61e9SGurchetan Singhvirtio-gpu can also leverage rutabaga_gfx to provide `gfxstream`_ 89773f61e9SGurchetan Singhrendering and `Wayland display passthrough`_. With the gfxstream rendering 90773f61e9SGurchetan Singhmode, GLES and Vulkan calls are forwarded to the host with minimal 91773f61e9SGurchetan Singhmodification. 92773f61e9SGurchetan Singh 93773f61e9SGurchetan SinghThe crosvm book provides directions on how to build a `gfxstream-enabled 94773f61e9SGurchetan Singhrutabaga`_ and launch a `guest Wayland proxy`_. 95773f61e9SGurchetan Singh 96773f61e9SGurchetan SinghThis device does require host blob support (``hostmem`` field below). The 97773f61e9SGurchetan Singh``hostmem`` field specifies the size of virtio-gpu host memory window. 98773f61e9SGurchetan SinghThis is typically between 256M and 8G. 99773f61e9SGurchetan Singh 100773f61e9SGurchetan SinghAt least one virtio-gpu capability set ("capset") must be specified when 101773f61e9SGurchetan Singhstarting the device. The currently capsets supported are ``gfxstream-vulkan`` 102773f61e9SGurchetan Singhand ``cross-domain`` for Linux guests. For Android guests, the experimental 103773f61e9SGurchetan Singh``x-gfxstream-gles`` and ``x-gfxstream-composer`` capsets are also supported. 104773f61e9SGurchetan Singh 105773f61e9SGurchetan SinghThe device will try to auto-detect the wayland socket path if the 106773f61e9SGurchetan Singh``cross-domain`` capset name is set. The user may optionally specify 107773f61e9SGurchetan Singh``wayland-socket-path`` for non-standard paths. 108773f61e9SGurchetan Singh 109773f61e9SGurchetan SinghThe ``wsi`` option can be set to ``surfaceless`` or ``headless``. 110773f61e9SGurchetan SinghSurfaceless doesn't create a native window surface, but does copy from the 111773f61e9SGurchetan Singhrender target to the Pixman buffer if a virtio-gpu 2D hypercall is issued. 112773f61e9SGurchetan SinghHeadless is like surfaceless, but doesn't copy to the Pixman buffer. 113773f61e9SGurchetan SinghSurfaceless is the default if ``wsi`` is not specified. 114773f61e9SGurchetan Singh 115773f61e9SGurchetan Singh.. parsed-literal:: 116773f61e9SGurchetan Singh -device virtio-gpu-rutabaga,gfxstream-vulkan=on,cross-domain=on, 117773f61e9SGurchetan Singh hostmem=8G,wayland-socket-path=/tmp/nonstandard/mock_wayland.sock, 118773f61e9SGurchetan Singh wsi=headless 119773f61e9SGurchetan Singh 120773f61e9SGurchetan Singh.. _gfxstream: https://android.googlesource.com/platform/hardware/google/gfxstream/ 121773f61e9SGurchetan Singh.. _Wayland display passthrough: https://www.youtube.com/watch?v=OZJiHMtIQ2M 122773f61e9SGurchetan Singh.. _gfxstream-enabled rutabaga: https://crosvm.dev/book/appendix/rutabaga_gfx.html 123773f61e9SGurchetan Singh.. _guest Wayland proxy: https://crosvm.dev/book/devices/wayland.html 124