xref: /aosp_15_r20/external/crosvm/docs/book/src/appendix/rutabaga_gfx.md (revision bb4ee6a4ae7042d18b07a98463b9c8b875e44b39)
1# Rutabaga Virtual Graphics Interface
2
3The Rutabaga Virtual Graphics Interface (VGI) is a cross-platform abstraction for GPU and display
4virtualization. The virtio-gpu
5[context type](https://www.phoronix.com/news/VirtIO-Linux-5.16-Ctx-Type) feature is used to dispatch
6commands between various Rust, C++, and C implementations. The diagram below does not exhaustively
7depict all available context types.
8
9<!-- Image from https://goto.google.com/crosvm-rutabaga-diagram -->
10
11![rutabaga diagram](images/rutabaga_gfx.png)
12
13## Rust API
14
15Although hosted in the crosvm repository, the Rutabaga VGI is designed to be portable across VMM
16implementations. The Rust API is available on [crates.io](https://crates.io/crates/rutabaga_gfx).
17
18## Rutabaga C API
19
20The following documentation shows how to build Rutabaga's C API with gfxstream enabled, which is the
21common use case.
22
23### Build dependencies
24
25```sh
26sudo apt install libdrm libglm-dev libstb-dev
27```
28
29### Install libaemu
30
31```sh
32git clone https://android.googlesource.com/platform/hardware/google/aemu
33cd aemu/
34git checkout v0.1.2-aemu-release
35cmake -DAEMU_COMMON_GEN_PKGCONFIG=ON \
36       -DAEMU_COMMON_BUILD_CONFIG=gfxstream \
37       -DENABLE_VKCEREAL_TESTS=OFF -B build
38cmake --build build -j
39sudo cmake --install build
40```
41
42### Install gfxstream host
43
44```sh
45git clone https://android.googlesource.com/platform/hardware/google/gfxstream
46cd gfxstream/
47meson setup host-build/
48meson install -C host-build/
49```
50
51### Install FFI bindings to Rutabaga
52
53```sh
54cd $(crosvm_dir)/rutabaga_gfx/ffi/
55meson setup rutabaga-ffi-build/
56meson install -C rutabaga-ffi-build/
57```
58
59### Install virglrenderer host
60
61Rutabaga's C API can also be built with virglrenderer enabled. To use virglrenderer feature first
62install virglrenderer on the host.
63
64```sh
65git clone https://gitlab.freedesktop.org/virgl/virglrenderer.git
66cd virglrenderer/
67git checkout virglrenderer-1.0.1
68meson setup build/
69meson install -C build/
70```
71
72### Latest releases for potential packaging
73
74- [Rutabaga FFI v0.1.2](https://crates.io/crates/rutabaga_gfx_ffi)
75- [gfxstream v0.1.2](https://android.googlesource.com/platform/hardware/google/gfxstream/+/refs/tags/v0.1.2-gfxstream-release)
76- [AEMU v0.1.2](https://android.googlesource.com/platform/hardware/google/aemu/+/refs/tags/v0.1.2-aemu-release)
77- [virglrenderer v1.0.1](https://gitlab.freedesktop.org/virgl/virglrenderer/-/tree/virglrenderer-1.0.1)
78
79# Kumquat Media Server
80
81The Kumquat Media server provides a way to test virtio multi-media protocols without a virtual
82machine. The following example shows how to run GL and Vulkan apps with `virtio-gpu` +
83`gfxstream-vulkan`. Full windowing will only work on platforms that support `dma_buf` and
84`dma_fence`.
85
86Only headless apps are likely to work on Nvidia, and requires
87[this change](https://crrev.com/c/5698371).
88
89## Build GPU-enabled server
90
91First install [libaemu](#install-libaemu) and the [gfxstream-host](#install-gfxstream-host), then:
92
93```sh
94cd $(crosvm_dir)/rutabaga_gfx/kumquat/server/
95cargo build --features=gfxstream
96```
97
98## Build and install client library
99
100```sh
101cd $(crosvm_dir)/rutabaga_gfx/kumquat/gpu_client/
102meson setup client-build
103ninja -C client-build/ install
104```
105
106## Build gfxstream guest
107
108Mesa provides gfxstream vulkan guest libraries.
109
110```sh
111git clone https://gitlab.freedesktop.org/mesa/mesa.git
112cd mesa
113meson setup guest-build/ -Dvulkan-drivers="gfxstream-experimental" -Dgallium-drivers="" -Dopengl=false
114ninja -C guest-build/
115```
116
117## Run apps
118
119In one terminal:
120
121```sh
122cd $(crosvm_dir)/rutabaga_gfx/kumquat/server/
123./target/debug/kumquat
124```
125
126In another terminal, run:
127
128```sh
129export MESA_LOADER_DRIVER_OVERRIDE=zink
130export VIRTGPU_KUMQUAT=1
131export VK_ICD_FILENAMES=$(mesa_dir)/guest-build/src/gfxstream/guest/vulkan/gfxstream_vk_devenv_icd.x86_64.json
132
133vkcube
134```
135
136# Linux guests
137
138To test gfxstream with Debian guests, make sure your display environment is headless.
139
140```
141systemctl set-default multi-user.target
142```
143
144Build gfxstream guest as previously and start the compositor. The `VIRTGPU_KUMQUAT` variable is no
145longer needed:
146
147```sh
148export MESA_LOADER_DRIVER_OVERRIDE=zink
149export VK_ICD_FILENAMES=$(mesa_dir)/guest-build/src/gfxstream/guest/vulkan/gfxstream_vk_devenv_icd.x86_64.json
150weston --backend=drm
151```
152
153# Contributing to gfxstream
154
155To contribute to gfxstream without an Android tree:
156
157```sh
158git clone https://android.googlesource.com/platform/hardware/google/gfxstream
159cd gfxstream/
160git commit -a -m blah
161git push origin HEAD:refs/for/main
162```
163
164The AOSP Gerrit instance will ask for an identity. Follow the instructions, a Google account is
165needed.
166