Implement VirtIO GPU and input devices
Summary
This pull request introduces initial support for virtio-gpu and virtio-input devices in semu, conforming to the VirtIO specification 1.3.
VirtIO-GPU
- Based on
VirtIO MMIO transport layer(i.e., Linux platform device) - Implements basic 2D rendering support.
- Provides two rendering backends:
- Software-based backend (supports 2D rendering only, ready to be integrated into rv32emu).
- virglrenderer backend (to enable hardware-accelerated 3D rendering in a future patch).
- Compatible with:
- Successfully tested with:
VirtIO-Input
- Implements basic keyboard emulation.
- Implements basic mouse emulation.
Prerequisites
Note: this list is not yet exhaustive
$ sudo apt install libsdl2-dev libsdl2-2.0-0 libsdl2-image-dev libsdl2-image-2.0-0
Build kernel image and test rootfs image
$ make rootfs.cpio # Download prebuilt minimal rootfs for initrd
$ ./scripts/build-image.sh --all --x11 --external-root --extra-packages
Use --x11 for full setup; omit it for a minimal setup.
Run X11
- Launch
semu:
$ make check
- Run
startx
$ startx
- After
X11shows up, launch the benchmark programs:
$ glmark2
$ glxgears
Run DirectFB2
- Launch
semu:
$ make check
- Kill
X11(Skip if--x11is not used)
$ ps | grep 'Xorg'
<PID> root /usr/bin/Xorg :0.0 vt01 -s 0 -noreset -allowMouseOpenFail
$ kill <PID>
- Set up environment variables via
run.sh:
$ source ./run.sh
- Run
DirectFB2test programs:
df_andi df_fire df_neo df_window
df_texture df_video df_knuckles
df_input df_neo df_window
df_matrix df_dok df_fire
df_palette df_cpuload df_spacedream
df_layers df_pss df_input
Run kmscube
- Launch
semu:
$ make check
- Kill
X11(Skip if--x11is not used)
$ ps | grep 'Xorg'
<PID> root /usr/bin/Xorg :0.0 vt01 -s 0 -noreset -allowMouseOpenFail
$ kill <PID>
- Run
kmscube
$ kmscube
Run modetest
The simplest method to test VirtIO-GPU.
-
Enable
BR2_PACKAGE_LIBDRM_INSTALL_TESTSin the Buildroot then rebuild the image. -
Launch
semu:
$ make check
- Run
modetestprogram
$ modetest -M virtio_gpu -s 34:1024x768
A test image should then show up in the display window.
How about using virglrenderer? See https://mail.gnu.org/archive/html/qemu-devel/2021-02/msg04235.html
Yes, I do plan to support VirGL for acceleration.
As far as I know, the offloading of rendering operations to the host GPU is called 3D mode by VirtIO's spec, whereas this pull request only implemented 2D mode due to the overall complexity.
Before implementing 3D rendering mode with VirGL, I think we need to configure the Buildroot to have a minimal desktop environment or set the Mesa benchmark tools without a desktop manager (I'm not sure if this is feasible).
In conclusion, I'll recommend first merging this pull request as a checkpoint for virtio-gpu and then adding support for VirGL in a later pull request.
Rather than relying on Xvfb as a heavy-duty solution for validating Linux DRM/framebuffer, it might be more efficient to use lighter tools like drm-framebuffer. This tool, designed for testing drm devices, takes data from stdin and displays it, offering a simpler and more straightforward approach.
Rather than relying on Xvfb as a heavy-duty solution for validating Linux DRM/framebuffer, it might be more efficient to use lighter tools like drm-framebuffer. This tool, designed for testing drm devices, takes data from stdin and displays it, offering a simpler and more straightforward approach.
Actually, the intention of using Xvfb here is to make sure the SDL window can be launched in the CI environment by GitHub Action.
Merely executing Xvfb :1 -screen 0 1600x1200x24 is inadequate because, although it confirms the initialization of SDL with libX11, it does not guarantee the accuracy of the window content rendered in Xvfb.
Merely executing
Xvfb :1 -screen 0 1600x1200x24is inadequate because, although it confirms the initialization of SDL with libX11, it does not guarantee the accuracy of the window content rendered in Xvfb.
The latest modification allows the virtio-gpu to be run without SDL, so the current CI test can pass by executing make ENABLE_SDL=0. (16794a2)