Skip to content

Commit 3781ae5

Browse files
committed
[WIP] Support VirGL
Follow the installation guide from: https://gitlab.freedesktop.org/virgl/virglrenderer Prerequisite: `sudo apt install libepoxy-dev`
1 parent 85c56a2 commit 3781ae5

File tree

11 files changed

+1672
-510
lines changed

11 files changed

+1672
-510
lines changed

Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@ ifneq ($(UNAME_S),Linux)
6969
ENABLE_VIRTIOGPU := 0
7070
endif
7171

72+
# VirGL
73+
ENABLE_VIRGL ?= 1
74+
ifeq ($(ENABLE_VIRGL),1)
75+
CFLAGS += $(shell pkg-config virglrenderer gl egl epoxy --cflags)
76+
LDFLAGS += $(shell pkg-config virglrenderer gl egl epoxy --libs)
77+
OBJS_EXTRA += virgl.o
78+
endif
79+
80+
$(call set-feature, VIRGL)
81+
7282
# SDL2
7383
ENABLE_SDL ?= 1
7484
ifeq (, $(shell which sdl2-config))

common.h

Lines changed: 10 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
@@ -30,6 +34,12 @@ static inline void bitmap_set_bit(unsigned long *map, unsigned long bit)
3034
set_bit(bit % BITS_PER_LONG, &map[bit / BITS_PER_LONG]);
3135
}
3236

37+
size_t copy_iov_to_buf(const struct iovec *iov,
38+
const unsigned int iov_cnt,
39+
size_t offset,
40+
void *buf,
41+
size_t bytes);
42+
3343
/* Range check
3444
* For any variable range checking:
3545
* if (x >= minx && x <= maxx) ...

device.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,6 @@ void virtio_gpu_write(hart_t *vm,
266266
uint8_t width,
267267
uint32_t value);
268268

269-
void semu_virgl_init(virtio_gpu_state_t *vgpu);
270-
271269
void virtio_gpu_init(virtio_gpu_state_t *vgpu);
272270
void virtio_gpu_add_scanout(virtio_gpu_state_t *vgpu,
273271
uint32_t width,

feature.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
#define SEMU_FEATURE_VIRTIOGPU 1
1818
#endif
1919

20+
/* VirGL */
21+
#ifndef SEMU_FEATURE_VIRGL
22+
#define SEMU_FEATURE_VIRGL 1
23+
#endif
24+
2025
/* virtio-input */
2126
#ifndef SEMU_FEATURE_VIRTIOINPUT
2227
#define SEMU_FEATURE_VIRTIOINPUT 1

main.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "device.h"
1212
#include "riscv.h"
1313
#include "riscv_private.h"
14+
#include "virgl.h"
1415
#include "window.h"
1516

1617
#define PRIV(x) ((emu_state_t *) x->priv)
@@ -722,19 +723,23 @@ static int semu_start(int argc, char **argv)
722723
emu.mtimer.mtimecmp = calloc(vm.n_hart, sizeof(uint64_t));
723724
emu.mswi.msip = calloc(vm.n_hart, sizeof(uint32_t));
724725
emu.sswi.ssip = calloc(vm.n_hart, sizeof(uint32_t));
725-
#if SEMU_HAS(VIRTIOGPU)
726-
emu.vgpu.ram = emu.ram;
727-
virtio_gpu_init(&(emu.vgpu));
728-
virtio_gpu_add_scanout(&(emu.vgpu), 1024, 768);
729-
window_init();
730-
#endif
731726
#if SEMU_HAS(VIRTIOINPUT)
732727
emu.vkeyboard.ram = emu.ram;
733728
virtio_input_init(&(emu.vkeyboard));
734729

735730
emu.vmouse.ram = emu.ram;
736731
virtio_input_init(&(emu.vmouse));
737732
#endif
733+
#if SEMU_HAS(VIRTIOGPU)
734+
emu.vgpu.ram = emu.ram;
735+
virtio_gpu_init(&(emu.vgpu));
736+
virtio_gpu_add_scanout(&(emu.vgpu), 1024, 768);
737+
738+
window_init();
739+
#endif
740+
#if SEMU_HAS(VIRGL)
741+
semu_virgl_init(&(emu.vgpu));
742+
#endif
738743

739744
/* Emulate */
740745
uint32_t peripheral_update_ctr = 0;
@@ -773,6 +778,10 @@ static int semu_start(int argc, char **argv)
773778
if (emu.vmouse.InterruptStatus)
774779
emu_update_vinput_mouse_interrupts(&vm);
775780
#endif
781+
782+
#if SEMU_HAS(VIRGL)
783+
semu_virgl_fence_poll();
784+
#endif
776785
}
777786

778787
emu_update_timer_interrupt(vm.hart[i]);

0 commit comments

Comments
 (0)