From 27883c976cef043acda7cbff794cf51d5dcc3283 Mon Sep 17 00:00:00 2001 From: Christian Helmuth Date: Mon, 4 Oct 2021 08:26:25 +0200 Subject: [PATCH] vbox6: 3D support skeleton files required for VBox6's VMSVGA/VBoxSVGA with 3D accelaration (accelerate3D="true"). issue #4380 --- .../lib/mk/spec/x86_64/virtualbox6-devices.mk | 38 ++++++++- repos/ports/lib/mk/virtualbox6-common.inc | 2 +- repos/ports/src/virtualbox6/glx_x11.cc | 81 +++++++++++++++++++ repos/ports/src/virtualbox6/include/GL/glx.h | 47 +++++++++++ repos/ports/src/virtualbox6/include/X11/X.h | 32 ++++++++ .../ports/src/virtualbox6/include/X11/Xatom.h | 6 ++ .../ports/src/virtualbox6/include/X11/Xlib.h | 59 ++++++++++++++ .../ports/src/virtualbox6/include/X11/Xutil.h | 27 +++++++ .../src/virtualbox6/patches/devahci.patch | 2 +- .../src/virtualbox6/patches/devsvga.patch | 12 +++ repos/ports/src/virtualbox6/patches/series | 1 + repos/ports/src/virtualbox6/target.mk | 3 +- 12 files changed, 306 insertions(+), 4 deletions(-) create mode 100644 repos/ports/src/virtualbox6/glx_x11.cc create mode 100644 repos/ports/src/virtualbox6/include/GL/glx.h create mode 100644 repos/ports/src/virtualbox6/include/X11/X.h create mode 100644 repos/ports/src/virtualbox6/include/X11/Xatom.h create mode 100644 repos/ports/src/virtualbox6/include/X11/Xlib.h create mode 100644 repos/ports/src/virtualbox6/include/X11/Xutil.h create mode 100644 repos/ports/src/virtualbox6/patches/devsvga.patch diff --git a/repos/ports/lib/mk/spec/x86_64/virtualbox6-devices.mk b/repos/ports/lib/mk/spec/x86_64/virtualbox6-devices.mk index d93db0c58f..a636f7ba3f 100644 --- a/repos/ports/lib/mk/spec/x86_64/virtualbox6-devices.mk +++ b/repos/ports/lib/mk/spec/x86_64/virtualbox6-devices.mk @@ -1,5 +1,7 @@ include $(REP_DIR)/lib/mk/virtualbox6-common.inc +LIBS += stdcxx mesa + SRC_CC += Devices/Audio/AudioHlp.cpp SRC_CC += Devices/Audio/AudioMixBuffer.cpp SRC_CC += Devices/Audio/AudioMixer.cpp @@ -19,12 +21,28 @@ SRC_CC += Devices/EFI/DevSmc.cpp SRC_CC += Devices/EFI/FlashCore.cpp SRC_CC += Devices/GIMDev/DrvUDP.cpp SRC_CC += Devices/GIMDev/GIMDev.cpp -SRC_CC += Devices/Graphics/DevVGA.cpp SRC_CC += Devices/Graphics/DevVGA-SVGA.cpp +SRC_CC += Devices/Graphics/DevVGA-SVGA3d-glHlp.cpp +SRC_CC += Devices/Graphics/DevVGA-SVGA3d-hlp.cpp +SRC_CC += Devices/Graphics/DevVGA-SVGA3d-info.cpp +SRC_CC += Devices/Graphics/DevVGA-SVGA3d-ogl.cpp +SRC_CC += Devices/Graphics/DevVGA-SVGA3d-savedstate.cpp +SRC_CC += Devices/Graphics/DevVGA-SVGA3d-shared.cpp +SRC_CC += Devices/Graphics/DevVGA-SVGA3d.cpp +SRC_CC += Devices/Graphics/DevVGA.cpp SRC_CC += Devices/Graphics/DevVGA_VBVA.cpp SRC_CC += Devices/Graphics/DevVGA_VDMA.cpp SRC_CC += Devices/Graphics/HGSMI/HGSMIHost.cpp SRC_CC += Devices/Graphics/HGSMI/SHGSMIHost.cpp +SRC_C += Devices/Graphics/shaderlib/directx.c +SRC_C += Devices/Graphics/shaderlib/glsl_shader.c +SRC_C += Devices/Graphics/shaderlib/libWineStub/debug.c +SRC_C += Devices/Graphics/shaderlib/shader.c +SRC_C += Devices/Graphics/shaderlib/shader_sm1.c +SRC_C += Devices/Graphics/shaderlib/shader_sm4.c +SRC_C += Devices/Graphics/shaderlib/shaderapi.c +SRC_C += Devices/Graphics/shaderlib/stateblock.c +SRC_C += Devices/Graphics/shaderlib/utils.c SRC_CC += Devices/Input/DevPS2.cpp SRC_CC += Devices/Input/DevPS2K.cpp SRC_CC += Devices/Input/DevPS2M.cpp @@ -105,11 +123,29 @@ SRC_CC += GuestHost/DragAndDrop/DnDPath.cpp INC_DIR += $(VBOX_DIR)/Devices/build INC_DIR += $(VBOX_DIR)/Devices/Bus +INC_DIR += $(VBOX_DIR)/Devices/Graphics/shaderlib/wine/include INC_DIR += $(VIRTUALBOX_DIR)/include/VBox/Graphics # found in src/VBox/Devices/Makefile.kmk CC_OPT += -DVBOX_HGCM_HOST_CODE +# SVGA3D/wine specific config +WINE_CC_OPT := -D__WINESRC__ -DWINE_NOWINSOCK -D_USE_MATH_DEFINES \ + -DVBOX_USING_WINDDK_W7_OR_LATER \ + -DVBOX_WINE_WITH_SINGLE_SWAPCHAIN_CONTEXT \ + -DVBOX_WINE_WITH_IPRT \ + -UVBOX_WITH_WDDM + +CC_OPT_Devices/Graphics/shaderlib/directx = $(WINE_CC_OPT) +CC_OPT_Devices/Graphics/shaderlib/glsl_shader = $(WINE_CC_OPT) +CC_OPT_Devices/Graphics/shaderlib/libWineStub/debug = $(WINE_CC_OPT) +CC_OPT_Devices/Graphics/shaderlib/shader = $(WINE_CC_OPT) +CC_OPT_Devices/Graphics/shaderlib/shader_sm1 = $(WINE_CC_OPT) +CC_OPT_Devices/Graphics/shaderlib/shader_sm4 = $(WINE_CC_OPT) +CC_OPT_Devices/Graphics/shaderlib/shaderapi = $(WINE_CC_OPT) +CC_OPT_Devices/Graphics/shaderlib/stateblock = $(WINE_CC_OPT) +CC_OPT_Devices/Graphics/shaderlib/utils = $(WINE_CC_OPT) + Devices/Graphics/DevVGA.o: vbetables.h vbetables.h: vbetables-gen diff --git a/repos/ports/lib/mk/virtualbox6-common.inc b/repos/ports/lib/mk/virtualbox6-common.inc index bfaadc2b1d..a9573f6780 100644 --- a/repos/ports/lib/mk/virtualbox6-common.inc +++ b/repos/ports/lib/mk/virtualbox6-common.inc @@ -80,7 +80,7 @@ VBOX_CC_OPT += -DVBOX_VERSION_MAJOR=$(VBOX_VERSION_MAJOR) \ VBOX_CC_OPT += -DVBOX_WITH_WDDM -DVBOXWDDM_WITH_VBVA VBOX_CC_OPT += -DVBOX_WITH_VDMA -VBOX_CC_OPT += -DVBOX_WITH_VMSVGA +VBOX_CC_OPT += -DVBOX_WITH_VMSVGA -DVBOX_WITH_VMSVGA3D -DVMSVGA3D_OPENGL VBOX_CC_OPT += -DVBOX_HDD_NO_DYNAMIC_BACKENDS VBOX_CC_OPT += -DVBOX_WITH_SCSI VBOX_CC_OPT += -DVBOX_WITH_HOSTNETIF_API diff --git a/repos/ports/src/virtualbox6/glx_x11.cc b/repos/ports/src/virtualbox6/glx_x11.cc new file mode 100644 index 0000000000..a2f1bc9b04 --- /dev/null +++ b/repos/ports/src/virtualbox6/glx_x11.cc @@ -0,0 +1,81 @@ +/* + * \brief GLX/X11 emulation for SVGA3D + * \author Christian Helmuth + * \date 2021-10-01 + */ + +/* + * Copyright (C) 2021 Genode Labs GmbH + * + * This file is distributed under the terms of the GNU General Public License + * version 2. + */ + +/* Genode includes */ +#include + +/* GLX/X11 includes */ +#include +#include +#include +#include + +/* VirtualBox includes */ +#include +#include + +/* local includes */ +#include + +static bool const debug = true; + +using namespace Genode; + + +/* from VBoxSVGA3DLazyLoad.asm */ +extern "C" int ExplicitlyLoadVBoxSVGA3D(bool fResolveAllImports, PRTERRINFO pErrInfo) TRACE(VINF_SUCCESS); + + +/* + * GLX + */ + +//static void impl_glXGetProcAddress(GLubyte const *procname) +//{ +//} + +void (*glXGetProcAddress(const GLubyte *procname))(void) +{ + log(__func__, ": procname='", (char const *)procname, "'"); + + return (void(*)())nullptr; +} + +extern "C" GLXFBConfig * glXChooseFBConfig(Display *dpy, int screen, const int *attribList, int *nitems) STOP +extern "C" XVisualInfo * glXChooseVisual(Display *dpy, int screen, int *attribList) STOP +extern "C" GLXContext glXCreateContext(Display *dpy, XVisualInfo *vis, GLXContext shareList, Bool direct) STOP +extern "C" void glXDestroyContext(Display *dpy, GLXContext ctx) STOP +extern "C" int glXGetFBConfigAttrib(Display *dpy, GLXFBConfig config, int attribute, int *value) STOP +extern "C" XVisualInfo * glXGetVisualFromFBConfig(Display *dpy, GLXFBConfig config) STOP +extern "C" Bool glXMakeCurrent(Display *dpy, GLXDrawable drawable, GLXContext ctx) STOP +extern "C" Bool glXQueryVersion(Display *dpy, int *maj, int *min) STOP + + +/* + * Xlib + */ + +extern "C" int XCloseDisplay(Display *) STOP +extern "C" Colormap XCreateColormap(Display *, Window, Visual *, int) STOP +extern "C" Window XCreateWindow( Display *, Window, int, int, unsigned int, unsigned int, unsigned int, int, unsigned int, Visual *, unsigned long, XSetWindowAttributes *) STOP +extern "C" Window XDefaultRootWindow(Display *) STOP +extern "C" int XDestroyWindow(Display *, Window) STOP +extern "C" XErrorHandler XSetErrorHandler(XErrorHandler) STOP +extern "C" int XFree(void *) STOP +extern "C" Status XGetWindowAttributes(Display *, Window, XWindowAttributes *) STOP +extern "C" int XMapWindow(Display *, Window) STOP +extern "C" int XNextEvent(Display *, XEvent *) STOP +extern "C" Display * XOpenDisplay(char *name) STOP +extern "C" int XPending(Display *) STOP +extern "C" int XScreenNumberOfScreen(Screen *) STOP +extern "C" int XSync(Display *, Bool) STOP diff --git a/repos/ports/src/virtualbox6/include/GL/glx.h b/repos/ports/src/virtualbox6/include/GL/glx.h new file mode 100644 index 0000000000..0a1e79cf86 --- /dev/null +++ b/repos/ports/src/virtualbox6/include/GL/glx.h @@ -0,0 +1,47 @@ +#ifndef _GL__GLX_H_ +#define _GL__GLX_H_ + +#include +#include +#include + + +#ifdef __cplusplus +extern "C" { +#endif + + +#define GLX_RGBA 4 +#define GLX_DOUBLEBUFFER 5 +#define GLX_RED_SIZE 8 +#define GLX_GREEN_SIZE 9 +#define GLX_BLUE_SIZE 10 +#define GLX_ALPHA_SIZE 11 +#define GLX_DEPTH_SIZE 12 +#define GLX_STENCIL_SIZE 13 + +#define GLX_WINDOW_BIT 0x00000001 +#define GLX_DRAWABLE_TYPE 0x8010 + +typedef struct _GLXContext { void *dummy; } * GLXContext; +typedef struct _GLXFBConfig { void *dummy; } * GLXFBConfig; + +typedef XID GLXDrawable; + +extern void (*glXGetProcAddress(const GLubyte *procname))(void); + +extern GLXFBConfig * glXChooseFBConfig(Display *dpy, int screen, const int *attribList, int *nitems); +extern XVisualInfo * glXChooseVisual(Display *dpy, int screen, int *attribList); +extern GLXContext glXCreateContext(Display *dpy, XVisualInfo *vis, GLXContext shareList, Bool direct); +extern void glXDestroyContext(Display *dpy, GLXContext ctx); +extern int glXGetFBConfigAttrib(Display *dpy, GLXFBConfig config, int attribute, int *value); +extern XVisualInfo * glXGetVisualFromFBConfig(Display *dpy, GLXFBConfig config); +extern Bool glXMakeCurrent(Display *dpy, GLXDrawable drawable, GLXContext ctx); +extern Bool glXQueryVersion(Display *dpy, int *maj, int *min); + + +#ifdef __cplusplus +} +#endif + +#endif /* _GL__GLX_H_ */ diff --git a/repos/ports/src/virtualbox6/include/X11/X.h b/repos/ports/src/virtualbox6/include/X11/X.h new file mode 100644 index 0000000000..9466545b29 --- /dev/null +++ b/repos/ports/src/virtualbox6/include/X11/X.h @@ -0,0 +1,32 @@ +#ifndef _X11__X_H_ +#define _X11__X_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/* originally in X11/Xmd.h */ +typedef unsigned int CARD32; + +typedef CARD32 XID; +typedef CARD32 VisualID; +typedef XID Window; +typedef XID Colormap; + +#define None 0L +#define InputOutput 1 +#define AllocNone 0 + +#define StructureNotifyMask (1L<<17) + +#define CWBackPixel (1L<<1) +#define CWBorderPixel (1L<<3) +#define CWOverrideRedirect (1L<<9) +#define CWEventMask (1L<<11) +#define CWColormap (1L<<13) + +#ifdef __cplusplus +} +#endif + +#endif /* _X11__X_H_ */ diff --git a/repos/ports/src/virtualbox6/include/X11/Xatom.h b/repos/ports/src/virtualbox6/include/X11/Xatom.h new file mode 100644 index 0000000000..021f23d787 --- /dev/null +++ b/repos/ports/src/virtualbox6/include/X11/Xatom.h @@ -0,0 +1,6 @@ +#ifndef _X11__XATOM_H_ +#define _X11__XATOM_H_ + +/* included but content not used */ + +#endif /* _X11__XATOM_H_ */ diff --git a/repos/ports/src/virtualbox6/include/X11/Xlib.h b/repos/ports/src/virtualbox6/include/X11/Xlib.h new file mode 100644 index 0000000000..620c68a5d0 --- /dev/null +++ b/repos/ports/src/virtualbox6/include/X11/Xlib.h @@ -0,0 +1,59 @@ +#ifndef _X11__XLIB_H_ +#define _X11__XLIB_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define Bool int +#define Status int +#define True 1 +#define False 0 + +typedef struct { void *dummy; } Display; +typedef struct { void *dummy; } Screen; +typedef struct { void *dummy; } Visual; + +typedef struct { unsigned char error_code; } XErrorEvent; + +typedef union _XEvent { + int type; + XErrorEvent xerror; +} XEvent; + +typedef struct { Screen *screen; } XWindowAttributes; + +typedef struct { + unsigned long background_pixel; + unsigned long border_pixel; + long event_mask; + Bool override_redirect; + Colormap colormap; +} XSetWindowAttributes; + +typedef int (*XErrorHandler) (Display *, XErrorEvent *); + +extern int XCloseDisplay(Display *); +extern Colormap XCreateColormap(Display *, Window, Visual *, int); +extern Window XCreateWindow( Display *, Window, int, int, unsigned int, unsigned int, unsigned int, int, unsigned int, Visual *, unsigned long, XSetWindowAttributes *); +extern Window XDefaultRootWindow(Display *); +extern int XDestroyWindow(Display *, Window); +extern XErrorHandler XSetErrorHandler(XErrorHandler); +extern int XFree(void *); +extern Status XGetWindowAttributes(Display *, Window, XWindowAttributes *); +extern int XMapWindow(Display *, Window); +extern int XNextEvent(Display *, XEvent *); +extern Display * XOpenDisplay(char *name); +extern int XPending(Display *); +extern int XScreenNumberOfScreen(Screen *); +extern int XSync(Display *, Bool); + +#define DefaultScreen(display) (0) + +#ifdef __cplusplus +} +#endif + +#endif /* _X11__XLIB_H_ */ diff --git a/repos/ports/src/virtualbox6/include/X11/Xutil.h b/repos/ports/src/virtualbox6/include/X11/Xutil.h new file mode 100644 index 0000000000..ba6216541c --- /dev/null +++ b/repos/ports/src/virtualbox6/include/X11/Xutil.h @@ -0,0 +1,27 @@ +#ifndef _X11__XUTIL_H_ +#define _X11__XUTIL_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + Visual *visual; + VisualID visualid; + int screen; + int depth; + unsigned long red_mask; + unsigned long green_mask; + unsigned long blue_mask; + int colormap_size; + int bits_per_rgb; +} XVisualInfo; + +#ifdef __cplusplus +} +#endif + +#endif /* _X11__XUTIL_H_ */ + diff --git a/repos/ports/src/virtualbox6/patches/devahci.patch b/repos/ports/src/virtualbox6/patches/devahci.patch index 536d6d476b..2f80d4cd1e 100644 --- a/repos/ports/src/virtualbox6/patches/devahci.patch +++ b/repos/ports/src/virtualbox6/patches/devahci.patch @@ -1,4 +1,4 @@ -Patch for DevAHCI model to really kick the consumer of requests (WiP) +Patch for DevAHCI model to really kick the consumer of requests +++ a/src/virtualbox6/src/VBox/Devices/Storage/DevAHCI.cpp +++ b/src/virtualbox6/src/VBox/Devices/Storage/DevAHCI.cpp diff --git a/repos/ports/src/virtualbox6/patches/devsvga.patch b/repos/ports/src/virtualbox6/patches/devsvga.patch new file mode 100644 index 0000000000..d8875af821 --- /dev/null +++ b/repos/ports/src/virtualbox6/patches/devsvga.patch @@ -0,0 +1,12 @@ +Patch to RT_OS_LINUX in SVGA OpenGL layer + +--- a/src/virtualbox6/src/VBox/Devices/Graphics/DevVGA-SVGA3d-ogl.cpp ++++ b/src/virtualbox6/src/VBox/Devices/Graphics/DevVGA-SVGA3d-ogl.cpp +@@ -47,6 +47,7 @@ + + #include "DevVGA-SVGA.h" + #include "DevVGA-SVGA3d.h" ++#define RT_OS_LINUX /* we have to force RT_OS_LINUX */ + #include "DevVGA-SVGA3d-internal.h" + + #ifdef DUMP_SHADER_DISASSEMBLY diff --git a/repos/ports/src/virtualbox6/patches/series b/repos/ports/src/virtualbox6/patches/series index a4c29a49c2..4b939e26a6 100644 --- a/repos/ports/src/virtualbox6/patches/series +++ b/repos/ports/src/virtualbox6/patches/series @@ -8,3 +8,4 @@ smp_sipi.patch tm_poke.patch exec_state.patch rttimer.patch +devsvga.patch diff --git a/repos/ports/src/virtualbox6/target.mk b/repos/ports/src/virtualbox6/target.mk index 27726ebb77..31deef08fd 100644 --- a/repos/ports/src/virtualbox6/target.mk +++ b/repos/ports/src/virtualbox6/target.mk @@ -8,7 +8,7 @@ include $(REP_DIR)/lib/mk/virtualbox6-common.inc CC_WARN += -Wall -SRC_CC := main.cc drivers.cc +SRC_CC := main.cc drivers.cc glx_x11.cc SRC_CC += libc.cc unimpl.cc dummies.cc pdm.cc devices.cc nem.cc SRC_CC += pthread.cc network.cc devxhci.cc SRC_CC += sup.cc sup_sem.cc sup_gmm.cc sup_drv.cc sup_vm.cc sup_vcpu.cc sup_gim.cc @@ -18,6 +18,7 @@ LIBS += base LIBS += stdcxx LIBS += libiconv LIBS += qemu-usb +LIBS += mesa CC_OPT_main = -Wno-multistatement-macros CC_OPT += -DProgress=ClientProgress