Skip to content

Commit dbf9304

Browse files
committed
Implement virglrenderer-based virtio-gpu device
Follow the installation guide from: https://gitlab.freedesktop.org/virgl/virglrenderer Prerequisite: `sudo apt install libepoxy-dev`
1 parent 86e2492 commit dbf9304

15 files changed

+2341
-1098
lines changed

Makefile

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,32 +126,51 @@ ifeq ($(call has, VIRTIOINPUT), 1)
126126
OBJS_EXTRA += virtio-input.o
127127
endif
128128

129-
# virtio-gpu
129+
# virtio-gpu and virgl
130130
ENABLE_VIRTIOGPU ?= 1
131-
ifneq ($(UNAME_S),Linux)
132-
ENABLE_VIRTIOGPU := 0
133-
endif
131+
ENABLE_VIRGL ?= 1
134132

135133
# SDL2
136134
ENABLE_SDL ?= 1
137135
ifeq (, $(shell which sdl2-config))
138136
$(warning No sdl2-config in $$PATH. Check SDL2 installation in advance)
139137
override ENABLE_SDL := 0
140138
endif
141-
142139
ifeq ($(ENABLE_SDL),1)
143140
CFLAGS += $(shell sdl2-config --cflags)
144141
LDFLAGS += $(shell sdl2-config --libs)
145142
else
143+
# Disable virtio-gpu and virgl if SDL is not set
146144
override ENABLE_VIRTIOGPU := 0
145+
override ENABLE_VIRGL := 0
147146
endif
148147

148+
# virtio-gpu
149+
ifneq ($(UNAME_S),Linux)
150+
ENABLE_VIRTIOGPU := 0
151+
endif
149152
ifeq ($(ENABLE_VIRTIOGPU),1)
150-
OBJS_EXTRA += window.o
153+
OBJS_EXTRA += window-events.o
151154
OBJS_EXTRA += virtio-gpu.o
155+
else
156+
override ENABLE_VIRGL := 0
157+
endif
158+
159+
# VirGL
160+
ifeq ($(ENABLE_VIRGL),1)
161+
CFLAGS += $(shell pkg-config virglrenderer gl egl epoxy --cflags)
162+
LDFLAGS += $(shell pkg-config virglrenderer gl egl epoxy --libs)
163+
OBJS_EXTRA += virgl.o
164+
OBJS_EXTRA += window-gl.o
165+
else
166+
ifeq ($(ENABLE_VIRTIOGPU),1)
167+
OBJS_EXTRA += virtio-gpu-sw.o
168+
OBJS_EXTRA += window-sw.o
169+
endif
152170
endif
153171

154172
$(call set-feature, VIRTIOGPU)
173+
$(call set-feature, VIRGL)
155174

156175
BIN = semu
157176
all: $(BIN) minimal.dtb

common.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
#pragma once
22

3+
#include <stddef.h>
4+
#include <stdint.h>
5+
#include <sys/uio.h>
6+
37
#include "feature.h"
48

59
#define BITS_PER_CHAR 8

device.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,6 @@ void virtio_gpu_write(hart_t *vm,
270270
uint8_t width,
271271
uint32_t value);
272272

273-
void semu_virgl_init(virtio_gpu_state_t *vgpu);
274-
275273
void virtio_gpu_init(virtio_gpu_state_t *vgpu);
276274
void virtio_gpu_add_scanout(virtio_gpu_state_t *vgpu,
277275
uint32_t width,

feature.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
#define SEMU_FEATURE_VIRTIOGPU 1
2323
#endif
2424

25+
/* VirGL */
26+
#ifndef SEMU_FEATURE_VIRGL
27+
#define SEMU_FEATURE_VIRGL 1
28+
#endif
29+
2530
/* virtio-input */
2631
#ifndef SEMU_FEATURE_VIRTIOINPUT
2732
#define SEMU_FEATURE_VIRTIOINPUT 1

main.c

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@
1313
#include "mini-gdbstub/include/gdbstub.h"
1414
#include "riscv.h"
1515
#include "riscv_private.h"
16+
#include "virgl.h"
1617
#include "window.h"
1718

1819
#define PRIV(x) ((emu_state_t *) x->priv)
1920

21+
extern const struct window_backend g_window;
22+
2023
/* Define fetch separately since it is simpler (fixed width, already checked
2124
* alignment, only main RAM is executable).
2225
*/
@@ -760,19 +763,23 @@ static int semu_init(emu_state_t *emu, int argc, char **argv)
760763
fprintf(stderr, "No virtio-snd functioned\n");
761764
emu->vsnd.ram = emu->ram;
762765
#endif
763-
#if SEMU_HAS(VIRTIOGPU)
764-
emu->vgpu.ram = emu->ram;
765-
virtio_gpu_init(&(emu->vgpu));
766-
virtio_gpu_add_scanout(&(emu->vgpu), 1024, 768);
767-
window_init();
768-
#endif
769766
#if SEMU_HAS(VIRTIOINPUT)
770767
emu->vkeyboard.ram = emu->ram;
771768
virtio_input_init(&(emu->vkeyboard));
772769

773770
emu->vmouse.ram = emu->ram;
774771
virtio_input_init(&(emu->vmouse));
775772
#endif
773+
#if SEMU_HAS(VIRTIOGPU)
774+
emu->vgpu.ram = emu->ram;
775+
virtio_gpu_init(&(emu->vgpu));
776+
virtio_gpu_add_scanout(&(emu->vgpu), 1024, 768);
777+
778+
g_window.window_init();
779+
#endif
780+
#if SEMU_HAS(VIRGL)
781+
semu_virgl_init(&(emu->vgpu));
782+
#endif
776783

777784
emu->peripheral_update_ctr = 0;
778785
emu->debug = debug;
@@ -823,6 +830,10 @@ static int semu_step(emu_state_t *emu)
823830
if (emu->vmouse.InterruptStatus)
824831
emu_update_vinput_mouse_interrupts(vm);
825832
#endif
833+
834+
#if SEMU_HAS(VIRGL)
835+
semu_virgl_fence_poll();
836+
#endif
826837
}
827838

828839
emu_update_timer_interrupt(vm->hart[i]);

0 commit comments

Comments
 (0)