| 1 |
Virtio-GPU Venus |
| 2 |
================ |
| 3 |
|
| 4 |
Venus is a Virtio-GPU protocol for Vulkan command serialization. The protocol |
| 5 |
definition and codegen are hosted at `venus-protocol |
| 6 |
<https://gitlab.freedesktop.org/virgl/venus-protocol>`__. The renderer is |
| 7 |
hosted at `virglrenderer |
| 8 |
<https://gitlab.freedesktop.org/virgl/virglrenderer>`__. |
| 9 |
|
| 10 |
Requirements |
| 11 |
------------ |
| 12 |
|
| 13 |
The Venus renderer requires |
| 14 |
|
| 15 |
- Linux platform |
| 16 |
- Vulkan 1.1 |
| 17 |
- :ext:`VK_KHR_external_memory_fd` |
| 18 |
- Android platform |
| 19 |
- Vulkan 1.1 |
| 20 |
- :ext:`VK_EXT_external_memory_dma_buf` |
| 21 |
- :ext:`VK_EXT_image_drm_format_modifier` |
| 22 |
- :ext:`VK_EXT_queue_family_foreign` |
| 23 |
|
| 24 |
from the host driver. However, it violates the spec and relies on |
| 25 |
implementation-defined behaviors to support ``vkMapMemory`` (see `below |
| 26 |
<#vk-memory-property-host-visible-bit>`__). It is not expected to work on all |
| 27 |
drivers meeting the requirements. It has only been tested with: |
| 28 |
|
| 29 |
- ANV 21.1 or later |
| 30 |
- RADV 21.1 or later |
| 31 |
- Note: you need 6.13+ kernel that already has |
| 32 |
`KVM: Stop grabbing references to PFNMAP'd pages |
| 33 |
<https://lore.kernel.org/all/[email protected]/>`__. |
| 34 |
- Note: for dGPU paired with Intel CPU, you need 6.11+ kernel patched with |
| 35 |
`KVM: VMX: Always honor guest PAT on CPUs that support self-snoop |
| 36 |
<https://lore.kernel.org/all/[email protected]/>`__, |
| 37 |
or 6.16+ kernel with VMM to opt-out ``KVM_X86_QUIRK_IGNORE_GUEST_PAT`` (QEMU |
| 38 |
request is `here <https://gitlab.com/qemu-project/qemu/-/issues/2943>`__). |
| 39 |
- Turnip 22.0 or later |
| 40 |
- PanVK 25.1 or later |
| 41 |
- Lavapipe 22.1 or later |
| 42 |
- Mali (Proprietary) r32p0 or later |
| 43 |
- NVIDIA (Proprietary) 570.86 or later |
| 44 |
- Note: if paired with Intel CPU, you need 6.11+ kernel patched with |
| 45 |
`KVM: VMX: Always honor guest PAT on CPUs that support self-snoop |
| 46 |
<https://lore.kernel.org/all/[email protected]/>`__, |
| 47 |
or 6.16+ kernel with VMM to opt-out ``KVM_X86_QUIRK_IGNORE_GUEST_PAT`` (QEMU |
| 48 |
request is `here <https://gitlab.com/qemu-project/qemu/-/issues/2943>`__). |
| 49 |
|
| 50 |
The Venus driver requires supports for |
| 51 |
|
| 52 |
- ``VIRTGPU_PARAM_3D_FEATURES`` |
| 53 |
- ``VIRTGPU_PARAM_CAPSET_QUERY_FIX`` |
| 54 |
- ``VIRTGPU_PARAM_RESOURCE_BLOB`` |
| 55 |
- ``VIRTGPU_PARAM_HOST_VISIBLE`` |
| 56 |
- ``VIRTGPU_PARAM_CONTEXT_INIT`` |
| 57 |
|
| 58 |
from the virtio-gpu kernel driver, unless vtest is used. That usually means |
| 59 |
the guest kernel should be at least 5.16 or have the parameters back ported, |
| 60 |
paired with hypervisors such as `crosvm <https://crosvm.dev>`__, or `QEMU |
| 61 |
<https://www.qemu.org>`__. |
| 62 |
|
| 63 |
vtest |
| 64 |
----- |
| 65 |
|
| 66 |
The simplest way to test Venus is to use virglrenderer's vtest server. To |
| 67 |
build virglrenderer with Venus support and to start the vtest server, |
| 68 |
|
| 69 |
.. code-block:: sh |
| 70 |
|
| 71 |
$ git clone https://gitlab.freedesktop.org/virgl/virglrenderer.git |
| 72 |
$ cd virglrenderer |
| 73 |
$ meson out -Dvenus=true |
| 74 |
$ meson compile -C out |
| 75 |
$ meson devenv -C out |
| 76 |
$ ./vtest/virgl_test_server --venus |
| 77 |
$ exit |
| 78 |
|
| 79 |
In another shell, |
| 80 |
|
| 81 |
.. code-block:: sh |
| 82 |
|
| 83 |
$ export VK_DRIVER_FILES=<path-to-virtio_icd.x86_64.json> |
| 84 |
$ export VN_DEBUG=vtest |
| 85 |
$ vulkaninfo |
| 86 |
$ vkcube |
| 87 |
|
| 88 |
If the host driver of the system is not new enough, it is a good idea to build |
| 89 |
the host driver as well when building the Venus driver. Just remember to set |
| 90 |
:envvar:`VK_DRIVER_FILES` when starting the vtest server so that the vtest |
| 91 |
server finds the locally built host driver. |
| 92 |
|
| 93 |
Virtio-GPU |
| 94 |
---------- |
| 95 |
|
| 96 |
The driver requires ``VIRTGPU_PARAM_CONTEXT_INIT`` from the virtio-gpu kernel |
| 97 |
driver, which was upstreamed in kernel 5.16. |
| 98 |
|
| 99 |
crosvm is written in Rust. To build crosvm, make sure Rust has been installed |
| 100 |
and |
| 101 |
|
| 102 |
.. code-block:: sh |
| 103 |
|
| 104 |
$ git clone --recurse-submodules \ |
| 105 |
https://chromium.googlesource.com/chromiumos/platform/crosvm |
| 106 |
$ cd crosvm |
| 107 |
$ RUSTFLAGS="-L<path-to-virglrenderer>/out/src" cargo build \ |
| 108 |
--features "x wl-dmabuf virgl_renderer virgl_renderer_next default-no-sandbox" |
| 109 |
|
| 110 |
Note that crosvm must be built with ``default-no-sandbox`` or started with |
| 111 |
``--disable-sandbox`` in this setup. |
| 112 |
|
| 113 |
This is how one might want to start crosvm |
| 114 |
|
| 115 |
.. code-block:: sh |
| 116 |
|
| 117 |
$ sudo LD_LIBRARY_PATH=<...> VK_DRIVER_FILES=<...> ./target/debug/crosvm run \ |
| 118 |
--gpu vulkan=true \ |
| 119 |
--gpu-render-server path=<path-to-virglrenderer>/out/server/virgl_render_server \ |
| 120 |
--display-window-keyboard \ |
| 121 |
--display-window-mouse \ |
| 122 |
--net "host-ip 192.168.0.1,netmask=255.255.255.0,mac=12:34:56:78:9a:bc" \ |
| 123 |
--rwdisk disk.img \ |
| 124 |
-p root=/dev/vda1 \ |
| 125 |
<path-to-bzImage> |
| 126 |
|
| 127 |
assuming a working system is installed to partition 1 of ``disk.img``. |
| 128 |
``sudo`` or ``CAP_NET_ADMIN`` is needed to set up the TAP network device. |
| 129 |
|
| 130 |
Optional Requirements |
| 131 |
--------------------- |
| 132 |
|
| 133 |
When virglrenderer is built with ``-Dminigbm_allocation=true``, the Venus |
| 134 |
renderer might need to import GBM BOs. The imports will fail unless the host |
| 135 |
driver supports the formats, especially multi-planar ones, and the DRM format |
| 136 |
modifiers of the GBM BOs. |
| 137 |
|
| 138 |
In the future, if virglrenderer's ``virgl_renderer_export_fence`` is |
| 139 |
supported, the Venus renderer will require :ext:`VK_KHR_external_fence_fd` |
| 140 |
with ``VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT`` from the host driver. |
| 141 |
|
| 142 |
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
| 143 |
----------------------------------- |
| 144 |
|
| 145 |
The Venus renderer makes assumptions about ``VkDeviceMemory`` that has |
| 146 |
``VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT``. The assumptions are illegal and rely |
| 147 |
on the current behaviors of the host drivers. It should be possible to remove |
| 148 |
some of the assumptions and incrementally improve compatibilities with more |
| 149 |
host drivers by imposing platform-specific requirements. But the long-term |
| 150 |
plan is to create a new Vulkan extension for the host drivers to address this |
| 151 |
specific use case. |
| 152 |
|
| 153 |
The Venus renderer assumes a device memory that has |
| 154 |
``VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT`` can be exported as a mmapable dma-buf |
| 155 |
(in the future, the plan is to export the device memory as an opaque fd). It |
| 156 |
chains ``VkExportMemoryAllocateInfo`` to ``VkMemoryAllocateInfo`` without |
| 157 |
checking if the host driver can export the device memory. |
| 158 |
|
| 159 |
The dma-buf is mapped (in the future, the plan is to import the opaque fd and |
| 160 |
call ``vkMapMemory``) but the mapping is not accessed. Instead, the mapping |
| 161 |
is passed to ``KVM_SET_USER_MEMORY_REGION``. The hypervisor, host KVM, and |
| 162 |
the guest kernel work together to set up a write-back or write-combined guest |
| 163 |
mapping (see ``virtio_gpu_vram_mmap`` of the virtio-gpu kernel driver). CPU |
| 164 |
accesses to the device memory are via the guest mapping, and are assumed to be |
| 165 |
coherent when the device memory also has |
| 166 |
``VK_MEMORY_PROPERTY_HOST_COHERENT_BIT``. |
| 167 |
|
| 168 |
While the Venus renderer can force a ``VkDeviceMemory`` external, it does not |
| 169 |
force a ``VkImage`` or a ``VkBuffer`` external. As a result, it can bind an |
| 170 |
external device memory to a non-external resource. |