Skip to content

Commit ee94e3d

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 8c56a1d commit ee94e3d

15 files changed

+2341
-1098
lines changed

Makefile

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

105-
# virtio-gpu
105+
# virtio-gpu and virgl
106106
ENABLE_VIRTIOGPU ?= 1
107-
ifneq ($(UNAME_S),Linux)
108-
ENABLE_VIRTIOGPU := 0
109-
endif
107+
ENABLE_VIRGL ?= 1
110108

111109
# SDL2
112110
ENABLE_SDL ?= 1
113111
ifeq (, $(shell which sdl2-config))
114112
$(warning No sdl2-config in $$PATH. Check SDL2 installation in advance)
115113
override ENABLE_SDL := 0
116114
endif
117-
118115
ifeq ($(ENABLE_SDL),1)
119116
CFLAGS += $(shell sdl2-config --cflags)
120117
LDFLAGS += $(shell sdl2-config --libs)
121118
else
119+
# Disable virtio-gpu and virgl if SDL is not set
122120
override ENABLE_VIRTIOGPU := 0
121+
override ENABLE_VIRGL := 0
123122
endif
124123

124+
# virtio-gpu
125+
ifneq ($(UNAME_S),Linux)
126+
ENABLE_VIRTIOGPU := 0
127+
endif
125128
ifeq ($(ENABLE_VIRTIOGPU),1)
126-
OBJS_EXTRA += window.o
129+
OBJS_EXTRA += window-events.o
127130
OBJS_EXTRA += virtio-gpu.o
131+
else
132+
override ENABLE_VIRGL := 0
133+
endif
134+
135+
# VirGL
136+
ifeq ($(ENABLE_VIRGL),1)
137+
CFLAGS += $(shell pkg-config virglrenderer gl egl epoxy --cflags)
138+
LDFLAGS += $(shell pkg-config virglrenderer gl egl epoxy --libs)
139+
OBJS_EXTRA += virgl.o
140+
OBJS_EXTRA += window-gl.o
141+
else
142+
ifeq ($(ENABLE_VIRTIOGPU),1)
143+
OBJS_EXTRA += virtio-gpu-sw.o
144+
OBJS_EXTRA += window-sw.o
145+
endif
128146
endif
129147

130148
$(call set-feature, VIRTIOGPU)
149+
$(call set-feature, VIRGL)
131150

132151
BIN = semu
133152
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)