xref: /aosp_15_r20/external/mesa3d/docs/drivers/venus.rst (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1*61046927SAndroid Build Coastguard WorkerVirtio-GPU Venus
2*61046927SAndroid Build Coastguard Worker================
3*61046927SAndroid Build Coastguard Worker
4*61046927SAndroid Build Coastguard WorkerVenus is a Virtio-GPU protocol for Vulkan command serialization.  The protocol
5*61046927SAndroid Build Coastguard Workerdefinition and codegen are hosted at `venus-protocol
6*61046927SAndroid Build Coastguard Worker<https://gitlab.freedesktop.org/virgl/venus-protocol>`__.  The renderer is
7*61046927SAndroid Build Coastguard Workerhosted at `virglrenderer
8*61046927SAndroid Build Coastguard Worker<https://gitlab.freedesktop.org/virgl/virglrenderer>`__.
9*61046927SAndroid Build Coastguard Worker
10*61046927SAndroid Build Coastguard WorkerRequirements
11*61046927SAndroid Build Coastguard Worker------------
12*61046927SAndroid Build Coastguard Worker
13*61046927SAndroid Build Coastguard WorkerThe Venus renderer requires
14*61046927SAndroid Build Coastguard Worker
15*61046927SAndroid Build Coastguard Worker- Vulkan 1.1
16*61046927SAndroid Build Coastguard Worker- :ext:`VK_EXT_external_memory_dma_buf`
17*61046927SAndroid Build Coastguard Worker- :ext:`VK_EXT_image_drm_format_modifier`
18*61046927SAndroid Build Coastguard Worker- :ext:`VK_EXT_queue_family_foreign`
19*61046927SAndroid Build Coastguard Worker
20*61046927SAndroid Build Coastguard Workerfrom the host driver.  However, it violates the spec in some places currently
21*61046927SAndroid Build Coastguard Workerand also relies on implementation-defined behaviors in others.  It is not
22*61046927SAndroid Build Coastguard Workerexpected to work on all drivers meeting the requirements.  It has only been
23*61046927SAndroid Build Coastguard Workertested with
24*61046927SAndroid Build Coastguard Worker
25*61046927SAndroid Build Coastguard Worker- ANV 21.1 or later
26*61046927SAndroid Build Coastguard Worker- RADV 21.1 or later (the host kernel must have
27*61046927SAndroid Build Coastguard Worker  ``CONFIG_TRANSPARENT_HUGEPAGE`` disabled because of this `KVM issue
28*61046927SAndroid Build Coastguard Worker  <https://github.com/google/security-research/security/advisories/GHSA-7wq5-phmq-m584>`__)
29*61046927SAndroid Build Coastguard Worker- TURNIP 22.0 or later
30*61046927SAndroid Build Coastguard Worker- Mali r32p0 or later
31*61046927SAndroid Build Coastguard Worker
32*61046927SAndroid Build Coastguard WorkerThe Venus driver requires supports for
33*61046927SAndroid Build Coastguard Worker
34*61046927SAndroid Build Coastguard Worker- ``VIRTGPU_PARAM_3D_FEATURES``
35*61046927SAndroid Build Coastguard Worker- ``VIRTGPU_PARAM_CAPSET_QUERY_FIX``
36*61046927SAndroid Build Coastguard Worker- ``VIRTGPU_PARAM_RESOURCE_BLOB``
37*61046927SAndroid Build Coastguard Worker- ``VIRTGPU_PARAM_HOST_VISIBLE``
38*61046927SAndroid Build Coastguard Worker- ``VIRTGPU_PARAM_CROSS_DEVICE``
39*61046927SAndroid Build Coastguard Worker- ``VIRTGPU_PARAM_CONTEXT_INIT``
40*61046927SAndroid Build Coastguard Worker
41*61046927SAndroid Build Coastguard Workerfrom the virtio-gpu kernel driver, unless vtest is used.  That usually means
42*61046927SAndroid Build Coastguard Workerthe guest kernel should be at least 5.16 or have the parameters back ported,
43*61046927SAndroid Build Coastguard Workerpaired with hypervisors such as `crosvm
44*61046927SAndroid Build Coastguard Worker<https://chromium.googlesource.com/chromiumos/platform/crosvm>`__, or `patched
45*61046927SAndroid Build Coastguard Workerqemu
46*61046927SAndroid Build Coastguard Worker<https://www.collabora.com/news-and-blog/blog/2021/11/26/venus-on-qemu-enabling-new-virtual-vulkan-driver/>`__.
47*61046927SAndroid Build Coastguard Worker
48*61046927SAndroid Build Coastguard Workervtest
49*61046927SAndroid Build Coastguard Worker-----
50*61046927SAndroid Build Coastguard Worker
51*61046927SAndroid Build Coastguard WorkerThe simplest way to test Venus is to use virglrenderer's vtest server.  To
52*61046927SAndroid Build Coastguard Workerbuild virglrenderer with Venus support and to start the vtest server,
53*61046927SAndroid Build Coastguard Worker
54*61046927SAndroid Build Coastguard Worker.. code-block:: sh
55*61046927SAndroid Build Coastguard Worker
56*61046927SAndroid Build Coastguard Worker    $ git clone https://gitlab.freedesktop.org/virgl/virglrenderer.git
57*61046927SAndroid Build Coastguard Worker    $ cd virglrenderer
58*61046927SAndroid Build Coastguard Worker    $ meson out -Dvenus=true
59*61046927SAndroid Build Coastguard Worker    $ meson compile -C out
60*61046927SAndroid Build Coastguard Worker    $ meson devenv -C out
61*61046927SAndroid Build Coastguard Worker    $ ./vtest/virgl_test_server --venus
62*61046927SAndroid Build Coastguard Worker    $ exit
63*61046927SAndroid Build Coastguard Worker
64*61046927SAndroid Build Coastguard WorkerIn another shell,
65*61046927SAndroid Build Coastguard Worker
66*61046927SAndroid Build Coastguard Worker.. code-block:: sh
67*61046927SAndroid Build Coastguard Worker
68*61046927SAndroid Build Coastguard Worker    $ export VK_DRIVER_FILES=<path-to-virtio_icd.x86_64.json>
69*61046927SAndroid Build Coastguard Worker    $ export VN_DEBUG=vtest
70*61046927SAndroid Build Coastguard Worker    $ vulkaninfo
71*61046927SAndroid Build Coastguard Worker    $ vkcube
72*61046927SAndroid Build Coastguard Worker
73*61046927SAndroid Build Coastguard WorkerIf the host driver of the system is not new enough, it is a good idea to build
74*61046927SAndroid Build Coastguard Workerthe host driver as well when building the Venus driver.  Just remember to set
75*61046927SAndroid Build Coastguard Worker:envvar:`VK_DRIVER_FILES` when starting the vtest server so that the vtest
76*61046927SAndroid Build Coastguard Workerserver finds the locally built host driver.
77*61046927SAndroid Build Coastguard Worker
78*61046927SAndroid Build Coastguard WorkerVirtio-GPU
79*61046927SAndroid Build Coastguard Worker----------
80*61046927SAndroid Build Coastguard Worker
81*61046927SAndroid Build Coastguard WorkerThe driver requires ``VIRTGPU_PARAM_CONTEXT_INIT`` from the virtio-gpu kernel
82*61046927SAndroid Build Coastguard Workerdriver, which was upstreamed in kernel 5.16.
83*61046927SAndroid Build Coastguard Worker
84*61046927SAndroid Build Coastguard Workercrosvm is written in Rust.  To build crosvm, make sure Rust has been installed
85*61046927SAndroid Build Coastguard Workerand
86*61046927SAndroid Build Coastguard Worker
87*61046927SAndroid Build Coastguard Worker.. code-block:: sh
88*61046927SAndroid Build Coastguard Worker
89*61046927SAndroid Build Coastguard Worker $ git clone --recurse-submodules \
90*61046927SAndroid Build Coastguard Worker       https://chromium.googlesource.com/chromiumos/platform/crosvm
91*61046927SAndroid Build Coastguard Worker $ cd crosvm
92*61046927SAndroid Build Coastguard Worker $ RUSTFLAGS="-L<path-to-virglrenderer>/out/src" cargo build \
93*61046927SAndroid Build Coastguard Worker       --features "x wl-dmabuf virgl_renderer virgl_renderer_next default-no-sandbox"
94*61046927SAndroid Build Coastguard Worker
95*61046927SAndroid Build Coastguard WorkerNote that crosvm must be built with ``default-no-sandbox`` or started with
96*61046927SAndroid Build Coastguard Worker``--disable-sandbox`` in this setup.
97*61046927SAndroid Build Coastguard Worker
98*61046927SAndroid Build Coastguard WorkerThis is how one might want to start crosvm
99*61046927SAndroid Build Coastguard Worker
100*61046927SAndroid Build Coastguard Worker.. code-block:: sh
101*61046927SAndroid Build Coastguard Worker
102*61046927SAndroid Build Coastguard Worker $ sudo LD_LIBRARY_PATH=<...> VK_DRIVER_FILES=<...> ./target/debug/crosvm run \
103*61046927SAndroid Build Coastguard Worker       --gpu vulkan=true \
104*61046927SAndroid Build Coastguard Worker       --gpu-render-server path=<path-to-virglrenderer>/out/server/virgl_render_server \
105*61046927SAndroid Build Coastguard Worker       --display-window-keyboard \
106*61046927SAndroid Build Coastguard Worker       --display-window-mouse \
107*61046927SAndroid Build Coastguard Worker       --net "host-ip 192.168.0.1,netmask=255.255.255.0,mac=12:34:56:78:9a:bc" \
108*61046927SAndroid Build Coastguard Worker       --rwdisk disk.img \
109*61046927SAndroid Build Coastguard Worker       -p root=/dev/vda1 \
110*61046927SAndroid Build Coastguard Worker       <path-to-bzImage>
111*61046927SAndroid Build Coastguard Worker
112*61046927SAndroid Build Coastguard Workerassuming a working system is installed to partition 1 of ``disk.img``.
113*61046927SAndroid Build Coastguard Worker``sudo`` or ``CAP_NET_ADMIN`` is needed to set up the TAP network device.
114*61046927SAndroid Build Coastguard Worker
115*61046927SAndroid Build Coastguard WorkerVirtio-GPU and Virtio-WL
116*61046927SAndroid Build Coastguard Worker------------------------
117*61046927SAndroid Build Coastguard Worker
118*61046927SAndroid Build Coastguard WorkerIn this setup, the guest userspace uses Xwayland and a special Wayland
119*61046927SAndroid Build Coastguard Workercompositor to connect guest X11/Wayland clients to the host Wayland
120*61046927SAndroid Build Coastguard Workercompositor, using Virtio-WL as the transport.  This setup is more tedious, but
121*61046927SAndroid Build Coastguard Workerthat should hopefully change over time.
122*61046927SAndroid Build Coastguard Worker
123*61046927SAndroid Build Coastguard WorkerFor now, the guest kernel must be built from the ``chromeos-5.10`` branch of
124*61046927SAndroid Build Coastguard Workerthe `Chrome OS kernel
125*61046927SAndroid Build Coastguard Worker<https://chromium.googlesource.com/chromiumos/third_party/kernel>`__.
126*61046927SAndroid Build Coastguard Worker
127*61046927SAndroid Build Coastguard WorkerTo build minigbm and to enable minigbm support in virglrenderer,
128*61046927SAndroid Build Coastguard Worker
129*61046927SAndroid Build Coastguard Worker.. code-block:: sh
130*61046927SAndroid Build Coastguard Worker
131*61046927SAndroid Build Coastguard Worker $ git clone https://chromium.googlesource.com/chromiumos/platform/minigbm
132*61046927SAndroid Build Coastguard Worker $ cd minigbm
133*61046927SAndroid Build Coastguard Worker $ CFLAGS=-DDRV_<I915-or-your-driver> OUT=out DESTDIR=out/install make install
134*61046927SAndroid Build Coastguard Worker $ cd ../virglrenderer
135*61046927SAndroid Build Coastguard Worker $ meson configure out -Dminigbm_allocation=true
136*61046927SAndroid Build Coastguard Worker $ meson compile -C out
137*61046927SAndroid Build Coastguard Worker
138*61046927SAndroid Build Coastguard WorkerMake sure a host Wayland compositor is running.  Replace
139*61046927SAndroid Build Coastguard Worker``--display-window-keyboard --display-window-mouse`` by
140*61046927SAndroid Build Coastguard Worker``--wayland-sock=<path-to-wayland-socket>`` when starting crosvm.
141*61046927SAndroid Build Coastguard Worker
142*61046927SAndroid Build Coastguard WorkerIn the guest, build and start Sommelier, the special Wayland compositor,
143*61046927SAndroid Build Coastguard Worker
144*61046927SAndroid Build Coastguard Worker.. code-block:: sh
145*61046927SAndroid Build Coastguard Worker
146*61046927SAndroid Build Coastguard Worker $ git clone https://chromium.googlesource.com/chromiumos/platform2
147*61046927SAndroid Build Coastguard Worker $ cd platform2/vm_tools/sommelier
148*61046927SAndroid Build Coastguard Worker $ meson out -Dxwayland_path=/usr/bin/Xwayland -Dxwayland_gl_driver_path=/usr/lib/dri
149*61046927SAndroid Build Coastguard Worker $ meson compile -C out
150*61046927SAndroid Build Coastguard Worker $ sudo chmod 777 /dev/wl0
151*61046927SAndroid Build Coastguard Worker $ ./out/sommelier -X --glamor
152*61046927SAndroid Build Coastguard Worker       --xwayland-gl-driver-path=<path-to-locally-built-gl-driver> \
153*61046927SAndroid Build Coastguard Worker       sleep infinity
154*61046927SAndroid Build Coastguard Worker
155*61046927SAndroid Build Coastguard WorkerOptional Requirements
156*61046927SAndroid Build Coastguard Worker---------------------
157*61046927SAndroid Build Coastguard Worker
158*61046927SAndroid Build Coastguard WorkerWhen virglrenderer is built with ``-Dminigbm_allocation=true``, the Venus
159*61046927SAndroid Build Coastguard Workerrenderer might need to import GBM BOs.  The imports will fail unless the host
160*61046927SAndroid Build Coastguard Workerdriver supports the formats, especially multi-planar ones, and the DRM format
161*61046927SAndroid Build Coastguard Workermodifiers of the GBM BOs.
162*61046927SAndroid Build Coastguard Worker
163*61046927SAndroid Build Coastguard WorkerIn the future, if virglrenderer's ``virgl_renderer_export_fence`` is
164*61046927SAndroid Build Coastguard Workersupported, the Venus renderer will require :ext:`VK_KHR_external_fence_fd`
165*61046927SAndroid Build Coastguard Workerwith ``VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT`` from the host driver.
166*61046927SAndroid Build Coastguard Worker
167*61046927SAndroid Build Coastguard WorkerVK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
168*61046927SAndroid Build Coastguard Worker-----------------------------------
169*61046927SAndroid Build Coastguard Worker
170*61046927SAndroid Build Coastguard WorkerThe Venus renderer makes assumptions about ``VkDeviceMemory`` that has
171*61046927SAndroid Build Coastguard Worker``VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT``.  The assumptions are illegal and rely
172*61046927SAndroid Build Coastguard Workeron the current behaviors of the host drivers.  It should be possible to remove
173*61046927SAndroid Build Coastguard Workersome of the assumptions and incrementally improve compatibilities with more
174*61046927SAndroid Build Coastguard Workerhost drivers by imposing platform-specific requirements.  But the long-term
175*61046927SAndroid Build Coastguard Workerplan is to create a new Vulkan extension for the host drivers to address this
176*61046927SAndroid Build Coastguard Workerspecific use case.
177*61046927SAndroid Build Coastguard Worker
178*61046927SAndroid Build Coastguard WorkerThe Venus renderer assumes a device memory that has
179*61046927SAndroid Build Coastguard Worker``VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT`` can be exported as a mmapable dma-buf
180*61046927SAndroid Build Coastguard Worker(in the future, the plan is to export the device memory as an opaque fd).  It
181*61046927SAndroid Build Coastguard Workerchains ``VkExportMemoryAllocateInfo`` to ``VkMemoryAllocateInfo`` without
182*61046927SAndroid Build Coastguard Workerchecking if the host driver can export the device memory.
183*61046927SAndroid Build Coastguard Worker
184*61046927SAndroid Build Coastguard WorkerThe dma-buf is mapped (in the future, the plan is to import the opaque fd and
185*61046927SAndroid Build Coastguard Workercall ``vkMapMemory``) but the mapping is not accessed.  Instead, the mapping
186*61046927SAndroid Build Coastguard Workeris passed to ``KVM_SET_USER_MEMORY_REGION``.  The hypervisor, host KVM, and
187*61046927SAndroid Build Coastguard Workerthe guest kernel work together to set up a write-back or write-combined guest
188*61046927SAndroid Build Coastguard Workermapping (see ``virtio_gpu_vram_mmap`` of the virtio-gpu kernel driver).  CPU
189*61046927SAndroid Build Coastguard Workeraccesses to the device memory are via the guest mapping, and are assumed to be
190*61046927SAndroid Build Coastguard Workercoherent when the device memory also has
191*61046927SAndroid Build Coastguard Worker``VK_MEMORY_PROPERTY_HOST_COHERENT_BIT``.
192*61046927SAndroid Build Coastguard Worker
193*61046927SAndroid Build Coastguard WorkerWhile the Venus renderer can force a ``VkDeviceMemory`` external, it does not
194*61046927SAndroid Build Coastguard Workerforce a ``VkImage`` or a ``VkBuffer`` external.  As a result, it can bind an
195*61046927SAndroid Build Coastguard Workerexternal device memory to a non-external resource.
196