Skip to contentSkip to conversation

Add virglrenderer support

PATCH Superseded Joseph Kogut 1 participant 7 messages Mar 17 – Mar 18

v4 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v4 cover Add virglrenderer support

Hello,

This patch series adds support for building the virglrenderer library in buildroot.

Virglrenderer is a userspace library used to support rendering and compute in virtual machines over virtio-gpu. Virglrenderer supports serialized API level access to OpenGL and Vulkan through virgl and venus respectively, as well as mediated DRM level access using host native context [0]. Notably libkrun [1] and rutabaga_gfx [2] are also capable of utilizing virglrenderer.

The first patch removes libepoxy's dependency on EGL/GL(X), as it may have depended on them in the past, but now builds without any EGL/GLX support. This allows virglrenderer to build with its libepoxy dependency, without actually depending on EGL/GLX.

This enables, for example, headless compute through Vulkan using Venus or host native context inside virtual machines.

I'm interested in feedback on this change in particular, as it may have second order effects on other packages.

The second patch adds the new virglrenderer package. Optional configs enable VirGL (API-level OpenGL passthrough), Venus (API-level Vulkan passthrough), hardware accelerated video encode/decode through VA-API, and DRM driver specific backends for host native context support.

The third patch adds a patch from upstream virglrenderer that fixes a build issue with glibc 2.43.

The fourth patch adds an OpenGL config for qemu.

The fifth patch adds a qemu virglrenderer config that selects OpenGL support, as virgl/venus support in qemu currently requires a GL accelerated display frontend (a patch series on the mailing list [3] is proposing decoupling display GL support from Venus). Other VMMs such as libkrun don't suffer from the same coupling currently.

For v4 of the series, I realized enabling DRM backends with the optional dependency on specific Mesa drivers didn't make sense. Host native context depends on specific *host kernel* interfaces, and the host may or may not have Mesa at all.

If the host does have Mesa, and a specific DRM consumer (i.e. a vendor's gallium/vulkan driver) is enabled, it's reasonable to assume that the host supports that DRM interface, and we should enable the corresponding DRM backend. For cases where the guest alone runs mesa (headless compute), I introduced explicit configs to enable DRM backends.

Tested with llama-bench running with the vulkan backend in a nested VM. As seen below, the nested guest is sending commands to the host through virtio-gpu twice.

        # llama-bench -m llama-2-7b.Q4_0.gguf -ngl 100 
        ggml_vulkan: Found 1 Vulkan devices:
        ggml_vulkan: 0 = Virtio-GPU Venus (Virtio-GPU Venus (AMD Radeon RX 6900 XT (RADV NAVI21))) (venus) | uma: 0 | fp16: 1 | warp size: 64 | shared memory: 65536 | int dot: 1 | matrix cores: none
        | model                          |       size |     params | backend    | ngl |            test |                  t/s |
        | ------------------------------ | ---------: | ---------: | ---------- | --: | --------------: | -------------------: |
        | llama 7B Q4_0                  |   3.56 GiB |     6.74 B | Vulkan     | 100 |           pp512 |      1220.99 ± 10.12 |
        | llama 7B Q4_0                  |   3.56 GiB |     6.74 B | Vulkan     | 100 |           tg128 |         82.24 ± 1.00 |

build: unknown (0)

More information about the benchmark and results from other hardware on the llama.cpp GitHub discussion here [4].

Build tested with several configs, to ensure correct dependencies and configuration. Not all toolchains build every configuration successfully, but every configuration has multiple passing builds. Failures generally are from warnings treated as errors by default.

-- qemu-virgl-egl --
BR2_PACKAGE_MESA3D=y
BR2_PACKAGE_MESA3D_GALLIUM_DRIVER_SOFTPIPE=y
BR2_PACKAGE_MESA3D_OPENGL_EGL=y
BR2_PACKAGE_QEMU=y
BR2_PACKAGE_QEMU_SYSTEM=y
BR2_PACKAGE_QEMU_SYSTEM_TCG=y
BR2_PACKAGE_QEMU_VIRGLRENDERER=y

-- qemu-virgl-glx --
BR2_PACKAGE_MESA3D=y
BR2_PACKAGE_MESA3D_GALLIUM_DRIVER_SOFTPIPE=y
BR2_PACKAGE_MESA3D_OPENGL_GLX=y
BR2_PACKAGE_QEMU=y
BR2_PACKAGE_QEMU_SYSTEM=y
BR2_PACKAGE_QEMU_SYSTEM_TCG=y
BR2_PACKAGE_QEMU_VIRGLRENDERER=y
BR2_PACKAGE_XORG7=y

-- virglrenderer-venus --
BR2_PACKAGE_VIRGLRENDERER=y
BR2_PACKAGE_VIRGLRENDERER_VENUS=y

-- virglrenderer-drm-amdgpu --
BR2_PACKAGE_MESA3D=y
BR2_PACKAGE_MESA3D_VULKAN_DRIVER_AMD=y
BR2_PACKAGE_VIRGLRENDERER=y

Feedback welcome.

[0] https://www.collabora.com/news-and-blog/blog/2025/01/15/the-state-of-gfx-virtualization-using-virglrenderer/
[1] https://github.com/containers/libkrun
[2] https://github.com/magma-gpu/rutabaga_gfx
[3] https://lore.kernel.org/qemu-devel/[email protected]/
[4] https://github.com/ggml-org/llama.cpp/discussions/10879

---
Changes in v4:
- Removed libepoxy dependency on GL/EGL
- Introduce explicit configs for virglrenderer DRM backends, virgl
(see above note)
- Moved virglrenderer Kconfig from Libraries -> Graphics to 'Graphics
libraries and applications' (next to mesa3d && X.org)
- Add a patch from upstream virglrenderer to fix glibc 2.43 builds
- select libdrm in virglrenderer only when required (drm backends,
video)
- BR2_PACKAGE_VIRGLRENDERER_DRM_BACKEND_MSM depends on !BR2_arm
- Explicitly configure GLX and/or EGL when
BR2_PACKAGE_VIRGLRENDERER_VIRGL=y
- Separate comments for qemu GL/virglrenderer [Romain]
- Split up qemu feature configs into separate commits [Romain]
- Link to v3: https://lore.kernel.org/buildroot/[email protected]/

Changes in v3:
- Bump version to v1.3.0
- Add optional deps for panfrost and i915 native context (new)
- Add config for vaapi support
- Remove GLX in favor of EGL
- Update qemu docs links, as previous ones 404 [Romain]
- Fix invalid config reference in BR2_PACKAGE_QEMU_VIRGLRENDERER
[Romain]
- Select libepoxy when enabling OpenGL support in qemu [Romain]
- Add depends on gcc >= 4.1 to virglrenderer (from meson.build)
- Add depends on libgbm to virglrenderer [Romain]
- Add comments for missing dependencies to virglrenderer Kconfig
- Select vulkan-headers when venus is enabled [Romain]
- Disable venus explicitly when the symbol isn't selected
- Link to v2: https://lore.kernel.org/buildroot/[email protected]

Changes in v2:
- Rebase onto next (python-glslang patch merged)
- Bump version to v1.2.0
- Remove hidden configs for virglrenderer vDRM backends [Romain]
- Fixed typo in qemu/Config.in [Romain]
- Split up configs for qemu OpenGL and virglrenderer support [Romain]
- More detailed qemu config help messages
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Joseph Kogut (5):
package/libepoxy: remove gl/egl dependency package/virglrenderer: new package package/virglrenderer: Fix build with glibc 2.43 package/qemu: add OpenGL config package/qemu: add virglrenderer support

 DEVELOPERS                                         |   1 +
 package/Config.in                                  |   1 +
 package/libepoxy/Config.in                         |   4 -
 package/qemu/Config.in                             |  31 +++++++
 package/qemu/qemu.mk                               |  15 ++-
 .../0001-fix-build-with-glibc-2.43.patch           |  39 ++++++++
 package/virglrenderer/Config.in                    | 101 +++++++++++++++++++++
 package/virglrenderer/virglrenderer.hash           |   5 +
 package/virglrenderer/virglrenderer.mk             |  60 ++++++++++++
 9 files changed, 252 insertions(+), 5 deletions(-)

---
base-commit: e555590b94532097c1319b9450ac84fab06b758b
change-id: 20260219-virglrenderer-c4dad969ad89

Best regards,

Signature · 6 lines
Joseph Kogut <[email protected]>

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#1 lore raw

PATCH v4 1/5 package/libepoxy: remove gl/egl dependency

From: Joseph Kogut <[email protected]>

Libepoxy is a library for handling OpenGL function pointer management.

It has backends for egl/glx, which may at one point have been mandatory to enable, but the library now builds with none of the above enabled features, as seen below.

libepoxy 1.5.10

User defined options
Cross files : /home/joseph/br-test-pkg/arm-aarch64/build/libepoxy-1.5.10//buildroot-build/cross-compilation.conf
b_pie : false
b_staticpic : true
buildtype : release
build.cmake_prefix_path: /home/joseph/br-test-pkg/arm-aarch64/host/lib/cmake
default_library : shared
docs : false
egl : no
glx : no
libdir : lib
build.pkg_config_path : /home/joseph/br-test-pkg/arm-aarch64/host/lib/pkgconfig
prefix : /usr
strip : false
tests : false
x11 : false

Removing these dependencies allows for some applications that require it as a build dependency, but otherwise can run headless or without GL, to build and function.

---
 package/libepoxy/Config.in | 4 ----
 1 file changed, 4 deletions(-)
package/libepoxy/Config.in +0 -4
index 9da190b895..27d2b968d2 100644
@@ -1,12 +1,8 @@
 config BR2_PACKAGE_LIBEPOXY
 	bool "libepoxy"
-	depends on BR2_PACKAGE_HAS_LIBEGL || BR2_PACKAGE_HAS_LIBGL
 	select BR2_PACKAGE_XUTIL_UTIL_MACROS
 	help
 	  Epoxy is a library for handling OpenGL function pointer
 	  management for you.
 
 	  https://github.com/anholt/libepoxy
-
-comment "libepoxy needs an OpenGL and/or OpenGL EGL backend"
-	depends on !BR2_PACKAGE_HAS_LIBEGL && !BR2_PACKAGE_HAS_LIBGL
Signature · 6 lines
2.53.0

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#2 lore raw

PATCH v4 2/5 package/virglrenderer: new package

In reply to Joseph Kogut

Add virglrenderer, an optional dependency of QEMU, which facilitates acceleration of rendering and optionally video decode through virtio-gpu.

---
 DEVELOPERS                               |   1 +
 package/Config.in                        |   1 +
 package/virglrenderer/Config.in          | 101 +++++++++++++++++++++++++++++++
 package/virglrenderer/virglrenderer.hash |   5 ++
 package/virglrenderer/virglrenderer.mk   |  60 ++++++++++++++++++
 5 files changed, 168 insertions(+)
DEVELOPERS +1 -0
index 88a684d9ac..a34cf57923 100644
@@ -1766,6 +1766,7 @@ F:	package/python-xlib/
 F:	package/sentry-cli/
 F:	package/sentry-native/
 F:	package/unclutter-xfixes/
+F:	package/virglrenderer/
 
 N:	Joshua Henderson <[email protected]>
 F:	package/qt5/qt5wayland/
package/Config.in +1 -0
index 371a1c33e1..da54fc2704 100644
@@ -366,6 +366,7 @@ comment "Graphic libraries"
 	source "package/sdl2_ttf/Config.in"
 	source "package/spirv-headers/Config.in"
 	source "package/tk/Config.in"
+	source "package/virglrenderer/Config.in"
 	source "package/vulkan-headers/Config.in"
 	source "package/vulkan-loader/Config.in"
 	source "package/vulkan-sdk/Config.in"
package/virglrenderer/Config.in new file +101 -0

101 lines not on this page · raw message

package/virglrenderer/virglrenderer.hash new file +5 -0
new file mode 100644
index 0000000000..03da595091
@@ -0,0 +1,5 @@
+# Locally calculated
+sha256  065bc56e89e6f631f96101cd62eba0748e48eb888b434edc86e89d05395e76f3  virglrenderer-1.3.0.tar.gz
+
+# License
+sha256  3b32caf16e2402c2aff2b716858713f3e1feded85c25e71bf829816ee5009402  COPYING
package/virglrenderer/virglrenderer.mk new file +60 -0

60 lines not on this page · raw message

Signature · 6 lines
2.53.0

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#3 lore raw

PATCH v4 3/5 package/virglrenderer: Fix build with glibc 2.43

In reply to Joseph Kogut

From: Joseph Kogut <[email protected]>

Add an upstream patch to fix the build with glibc 2.43, not present in a stable release yet.

---
 .../0001-fix-build-with-glibc-2.43.patch           | 39 ++++++++++++++++++++++
 1 file changed, 39 insertions(+)
package/virglrenderer/0001-fix-build-with-glibc-2.43.patch new file +39 -0
new file mode 100644
index 0000000000..fda1d9b218
@@ -0,0 +1,39 @@
+From 986b5fc57b07c06b5e0b3a3694d06898ebc80163 Mon Sep 17 00:00:00 2001
+From: Maximilian Hofmann <[email protected]>
+Date: Thu, 26 Feb 2026 23:28:58 +0100
+Subject: [PATCH] fix: build with glibc 2.43
+
+Several glibc functions now return a const pointer if the input is a
+const pointer and a non-const pointer if the input is non-const, causing
+a build failure.
+
+Fix this by declaring the output pointers as const if they are never
+modified, and for the lone failure where the output is modified, instead
+make the input non-const.
+
+Signed-off-by: Maximilian Hofmann <[email protected]>
+Part-of: <https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1599>
+
+Upstream: https://gitlab.freedesktop.org/virgl/virglrenderer/-/commit/986b5fc57b07c06b5e0b3a3694d06898ebc80163
+
+Signed-off-by: Joseph Kogut <[email protected]>
+---
+ src/gallium/auxiliary/tgsi/tgsi_text.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/src/gallium/auxiliary/tgsi/tgsi_text.c b/src/gallium/auxiliary/tgsi/tgsi_text.c
+index db7d7b95..7e37bf79 100644
+--- a/src/gallium/auxiliary/tgsi/tgsi_text.c
++++ b/src/gallium/auxiliary/tgsi/tgsi_text.c
+@@ -84,7 +84,7 @@ streq_nocase_uprcase(const char *str1,
+ static inline bool skip_n_chars(const char **pcur,
+                                    int n)
+ {
+-   char* str = memchr(*pcur, '\0', n);
++   const char* str = memchr(*pcur, '\0', n);
+    if (unlikely(str)) {
+       *pcur = str;
+       return false;
+-- 
+2.53.0
+
Signature · 6 lines
2.53.0

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#4 lore raw

Re: [Buildroot] [PATCH v4 3/5] package/virglrenderer: Fix build with glibc 2.43

Hi all,

Quoted 5 lines · Joseph Kogut

From: Joseph Kogut <[email protected]>

Add an upstream patch to fix the build with glibc 2.43, not present in a stable release yet.

It looks like I'm missing a Signed-off-by line here. Also, my git-send-email configuration was inconsistent for this series, some commits are authored with one email and signed off with another. I'll fix that and resubmit, sorry for the noise.

Best,
Joseph
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

#5 lore raw

PATCH v4 4/5 package/qemu: add OpenGL config

In reply to Joseph Kogut

From: Joseph Kogut <[email protected]>

---
 package/qemu/Config.in | 14 ++++++++++++++
 package/qemu/qemu.mk   |  8 +++++++-
 2 files changed, 21 insertions(+), 1 deletion(-)
package/qemu/Config.in +14 -0
index e16eafe446..e4e8eb3b63 100644
@@ -116,6 +116,20 @@ config BR2_PACKAGE_QEMU_SDL
 	  Say 'y' to enable the SDL frontend, that is, a graphical
 	  window presenting the VM's display.
 
+config BR2_PACKAGE_QEMU_OPENGL
+	bool "Enable OpenGL"
+	depends on BR2_PACKAGE_HAS_LIBEGL || BR2_PACKAGE_HAS_LIBGL # libepoxy
+	select BR2_PACKAGE_LIBEPOXY
+	help
+	  Say 'y' to enable OpenGL accelerated display frontend support.
+	  This is necessary to efficiently display frames rendered in a
+	  guest on the host.
+
+	  Run qemu with `-display sdl,gl=on`
+
+comment "OpenGL support needs an OpenGL and/or OpenGL EGL backend"
+	depends on !(BR2_PACKAGE_HAS_LIBEGL || BR2_PACKAGE_HAS_LIBGL)
+
 config BR2_PACKAGE_QEMU_FDT
 	bool "Enable FDT"
 	select BR2_PACKAGE_DTC
package/qemu/qemu.mk +7 -1
index 97f8e22091..9b780797fa 100644
@@ -274,6 +274,13 @@ else
 QEMU_OPTS += --disable-usb-redir
 endif
 
+ifeq ($(BR2_PACKAGE_QEMU_OPENGL),y)
+QEMU_OPTS += --enable-opengl
+QEMU_DEPENDENCIES += libepoxy
+else
+QEMU_OPTS += --disable-opengl
+endif
+
 ifeq ($(BR2_STATIC_LIBS),y)
 QEMU_OPTS += --static
 endif
@@ -330,7 +337,6 @@ define QEMU_CONFIGURE_CMDS
 			--disable-membarrier \
 			--disable-mpath \
 			--disable-netmap \
-			--disable-opengl \
 			--disable-oss \
 			--disable-pa \
 			--disable-plugins \
Signature · 6 lines
2.53.0

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#6 lore raw

PATCH v4 5/5 package/qemu: add virglrenderer support

In reply to Joseph Kogut

Add optional virglrenderer support, along with enabling OpenGL when necessary.

https://qemu.readthedocs.io/en/v10.0.3/system/devices/virtio-gpu.html#virtio-gpu-virglrenderer

---
 package/qemu/Config.in | 17 +++++++++++++++++
 package/qemu/qemu.mk   |  7 +++++++
 2 files changed, 24 insertions(+)
package/qemu/Config.in +17 -0
index e4e8eb3b63..599bcb11bb 100644
@@ -130,6 +130,23 @@ config BR2_PACKAGE_QEMU_OPENGL
 comment "OpenGL support needs an OpenGL and/or OpenGL EGL backend"
 	depends on !(BR2_PACKAGE_HAS_LIBEGL || BR2_PACKAGE_HAS_LIBGL)
 
+config BR2_PACKAGE_QEMU_VIRGLRENDERER
+	bool "Enable virglrenderer"
+	depends on BR2_PACKAGE_HAS_LIBEGL || BR2_PACKAGE_HAS_LIBGL
+	select BR2_PACKAGE_QEMU_OPENGL
+	select BR2_PACKAGE_VIRGLRENDERER
+	help
+	  Say 'y' to enable virglrenderer, enabling GL and Vulkan
+	  passthrough from the host to the guest through virtio-gpu.
+	  This enables the guest to have accelerated GL and/or Vulkan.
+
+	  Run qemu with `-device virtio-gpu-gl`
+
+	  https://qemu.readthedocs.io/en/v10.0.3/system/devices/virtio-gpu.html#virtio-gpu-virglrenderer
+
+comment "virglrenderer needs OpenGL accelerated display frontend support"
+	depends on !(BR2_PACKAGE_HAS_LIBEGL || BR2_PACKAGE_HAS_LIBGL)
+
 config BR2_PACKAGE_QEMU_FDT
 	bool "Enable FDT"
 	select BR2_PACKAGE_DTC
package/qemu/qemu.mk +7 -0
index 9b780797fa..e250128dfa 100644
@@ -281,6 +281,13 @@ else
 QEMU_OPTS += --disable-opengl
 endif
 
+ifeq ($(BR2_PACKAGE_QEMU_VIRGLRENDERER),y)
+QEMU_OPTS += --enable-virglrenderer
+QEMU_DEPENDENCIES += virglrenderer
+else
+QEMU_OPTS += --disable-virglrenderer
+endif
+
 ifeq ($(BR2_STATIC_LIBS),y)
 QEMU_OPTS += --static
 endif
Signature · 6 lines
2.53.0

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot