Index: trunk/src/VBox/Additions/3D/Config.kmk
===================================================================
--- trunk/src/VBox/Additions/3D/Config.kmk	(revision 103998)
+++ trunk/src/VBox/Additions/3D/Config.kmk	(revision 103999)
@@ -33,5 +33,14 @@
 endif
 
-VBOX_MESA            := mesa-21.3.8
+#NEW_MESA := 1
+
+ifdef NEW_MESA
+ VBOX_MESA_VERSION    := 24.0.2
+ VBOX_MESA_V_MAJOR    := 24
+else
+ VBOX_MESA_VERSION    := 21.3.8
+ VBOX_MESA_V_MAJOR    := 21
+endif
+VBOX_MESA            := mesa-$(VBOX_MESA_VERSION)
 VBOX_PATH_3D         := $(PATH_ROOT)/src/VBox/Additions/3D
 VBOX_PATH_MESA       := $(PATH_ROOT)/src/VBox/Additions/3D/mesa/$(VBOX_MESA)
@@ -48,10 +57,11 @@
 TEMPLATE_VBoxMesa3DGuestR3Dll_SDKS.win = $(TEMPLATE_NewerVccVBoxGuestR3Dll_SDKS) $(VBOX_WINDDK_GST_W8)
 TEMPLATE_VBoxMesa3DGuestR3Dll_DEFS     = $(TEMPLATE_NewerVccVBoxGuestR3Dll_DEFS) \
-	VBOX_WITH_MESA3D
+	VBOX_WITH_MESA3D \
+	VBOX_MESA_V_MAJOR=$(VBOX_MESA_V_MAJOR)
 ifdef VBOX_WITH_VMSVGA
  TEMPLATE_VBoxMesa3DGuestR3Dll_DEFS   += VBOX_WITH_VMSVGA
 endif
 # VirtualBox specific modifications of the Mesa3D code.
-# All modified places can be found by searching for VBOX
+# All modified places can be found by searching for VBOX or IPRT_NO_CRT
 #
 # Each define represents a group of related modifications.
@@ -93,7 +103,17 @@
 	WINAPI=__stdcall \
 	_WIN32
+if $(VBOX_MESA_V_MAJOR) >= 24
+ TEMPLATE_VBoxMesa3DGuestR3Dll_DEFS.win += \
+ 	WINDOWS_NO_FUTEX \
+ 	HAVE_STRUCT_TIMESPEC
+endif
+TEMPLATE_VBoxMesa3DGuestR3Dll_CFLAGS.win = $(TEMPLATE_NewerVccVBoxGuestR3Dll_CFLAGS.win)
+if $(VBOX_MESA_V_MAJOR) >= 24
+ # Mesa 24+ needs -std:c11 for 'alignas', etc
+ TEMPLATE_VBoxMesa3DGuestR3Dll_CFLAGS.win += -std:c11
+endif
 ifdef VBOX_WITH_VMSVGA
  # treat as error: warning C4013: 'close' undefined; assuming extern returning int
- TEMPLATE_VBoxMesa3DGuestR3Dll_CFLAGS  = $(TEMPLATE_NewerVccVBoxGuestR3Dll_CFLAGS) -we4013
+ TEMPLATE_VBoxMesa3DGuestR3Dll_CFLAGS.win += -we4013
 endif
 TEMPLATE_VBoxMesa3DGuestR3Dll_INCS     = $(TEMPLATE_NewerVccVBoxGuestR3Dll_INCS) \
Index: trunk/src/VBox/Additions/3D/win/VBoxGL/Makefile.kmk
===================================================================
--- trunk/src/VBox/Additions/3D/win/VBoxGL/Makefile.kmk	(revision 103998)
+++ trunk/src/VBox/Additions/3D/win/VBoxGL/Makefile.kmk	(revision 103999)
@@ -34,11 +34,17 @@
 VBoxGL_TEMPLATE = VBoxMesa3DGuestR3DllMinVista
 VBoxGL_DEFS     = VBOXGL
+if $(VBOX_MESA_V_MAJOR) >= 24
+ VBoxGL_DEFS    += \
+ 	VBOX_MESA_STATIC_DRIVER
+endif
 # -wd4005: '__useHeader' : redefinition
 VBOXGL_DISABLED_WARNINGS := -wd4005
+# -wd4100: 'api': unreferenced formal parameter
 # -wd4204: nonstandard extension used: non-constant aggregate initializer
+# -wd4245: 'return': conversion from 'int' to 'unsigned int', signed/unsigned mismatch
 # -wd4267: 'initializing': conversion from 'size_t' to 'unsigned int', possible loss of data
 # -wd4459: stw_device.h(102): warning C4459: declaration of 'stw_dev' hides global declaration
 # -wd4668: c99_compat.h(99): warning C4668: '__STDC_VERSION__' is not defined as a preprocessor macro, replacing with '0' for '#if/#elif'
-VBOXGL_DISABLED_WARNINGS += -wd4204 -wd4267 -wd4459 -wd4668
+VBOXGL_DISABLED_WARNINGS += -wd4100 -wd4204 -wd4245 -wd4267 -wd4459 -wd4668
 VBoxGL_CFLAGS   = $(VBOXGL_DISABLED_WARNINGS)
 VBoxGL_CXXFLAGS = $(VBOXGL_DISABLED_WARNINGS)
@@ -53,10 +59,26 @@
 	$(VBOX_PATH_VMSVGA_INC) \
 	$(VBOX_GRAPHICS_INCS)
+if $(VBOX_MESA_V_MAJOR) >= 24
+ VBoxGL_INCS    += \
+ 	$(VBOX_PATH_3D)/win/VBoxSVGA \
+ 	$(VBOX_PATH_MESA)/src/mapi \
+ 	$(VBOX_PATH_MESA)/src/gallium/drivers/svga \
+ 	$(VBOX_PATH_MESA)/src/gallium/winsys/svga/drm
+endif
 VBoxGL_SOURCES  = \
-	$(VBOX_PATH_MESA)/src/gallium/targets/libgl-gdi/opengl32.def \
+	GaDrvEnvKMT.cpp \
+	VBoxGL.c \
 	VBoxGL.rc
-VBoxGL_SOURCES += \
-	GaDrvEnvKMT.cpp \
-	VBoxGL.c
+if $(VBOX_MESA_V_MAJOR) >= 24
+ VBoxGL_SOURCES += \
+ 	../VBoxSVGA/VBoxSVGA.c \
+ 	../VBoxSVGA/winsys/vmw_screen.c \
+ 	../VBoxSVGA/winsys/vmw_screen_wddm.c \
+ 	../VBoxSVGA/winsys/vmw_screen_ioctl.c \
+ 	$(VBoxGL_0_OUTDIR)/opengl32.def
+else
+ VBoxGL_SOURCES  += \
+ 	$(VBOX_PATH_MESA)/src/gallium/targets/libgl-gdi/opengl32.def
+endif
 VBoxGL_LIBS     = \
 	$(VBOX_PATH_ADDITIONS_LIB)/VBoxWddmUmHlp$(VBOX_SUFF_LIB) \
@@ -65,4 +87,15 @@
 	$(VBOX_PATH_ADDITIONS_LIB)/VBoxMesaUtilLib$(VBOX_SUFF_LIB) \
 	$(VBOX_PATH_ADDITIONS_LIB)/VBoxMesaLib$(VBOX_SUFF_LIB)
+if $(VBOX_MESA_V_MAJOR) >= 24
+ VBoxGL_LIBS     += \
+ 	$(VBOX_PATH_ADDITIONS_LIB)/VBoxMesaSVGAWinsysLib$(VBOX_SUFF_LIB) \
+ 	$(VBOX_PATH_ADDITIONS_LIB)/VBoxMesaSVGALib$(VBOX_SUFF_LIB)
+endif
+
+$$(VBoxGL_0_OUTDIR)/opengl32.def: \
+		$(PATH_SUB_CURRENT)/opengl32_defs.py \
+		$(VBOX_PATH_MESA)/src/gallium/targets/libgl-gdi/opengl32.def.in | $$(dir $$@)
+	$(call MSG_GENERATE,python,$@,$$@)
+	$(QUIET)$(VBOX_BLD_PYTHON) $< $(VBOX_PATH_MESA)/src/gallium/targets/libgl-gdi/opengl32.def.in $@
 
 if defined(VBOX_SIGNING_MODE) && defined(VBOX_SIGN_ADDITIONS)
@@ -82,4 +115,9 @@
 	$(VBOX_PATH_ADDITIONS_LIB)/VBoxMesaUtilLib-x86$(VBOX_SUFF_LIB) \
 	$(VBOX_PATH_ADDITIONS_LIB)/VBoxMesaLib-x86$(VBOX_SUFF_LIB)
+if $(VBOX_MESA_V_MAJOR) >= 24
+ VBoxGL-x86_LIBS     += \
+ 	$(VBOX_PATH_ADDITIONS_LIB)/VBoxMesaSVGAWinsysLib-x86$(VBOX_SUFF_LIB) \
+ 	$(VBOX_PATH_ADDITIONS_LIB)/VBoxMesaSVGALib-x86$(VBOX_SUFF_LIB)
+endif
 VBoxGL-x86_DEFS         = $(VBoxGL_DEFS) VBOX_WOW64
 
Index: trunk/src/VBox/Additions/3D/win/VBoxGL/VBoxGL.c
===================================================================
--- trunk/src/VBox/Additions/3D/win/VBoxGL/VBoxGL.c	(revision 103998)
+++ trunk/src/VBox/Additions/3D/win/VBoxGL/VBoxGL.c	(revision 103999)
@@ -33,7 +33,11 @@
 
 #include "pipe/p_state.h"
+#if VBOX_MESA_V_MAJOR >= 24
+#include "state_tracker/st_context.h"
+#endif
 #include "svga3d_reg.h"
 
 #include <iprt/asm.h>
+#include <iprt/initterm.h>
 
 #include <common/wddm/VBoxMPIf.h>
@@ -41,4 +45,5 @@
 #include <Psapi.h>
 
+#if VBOX_MESA_V_MAJOR < 24
 static const char *g_pszSvgaDll =
 #ifdef VBOX_WOW64
@@ -48,4 +53,5 @@
 #endif
 ;
+#endif
 
 static struct GaDrvFunctions
@@ -60,4 +66,5 @@
 
 
+#if VBOX_MESA_V_MAJOR < 24
 static HMODULE gaDrvLoadSVGA(struct GaDrvFunctions *pDrvFuncs)
 {
@@ -80,4 +87,22 @@
     return hmod;
 }
+#else
+struct pipe_screen * WINAPI GaDrvScreenCreate(const WDDMGalliumDriverEnv *pEnv);
+void WINAPI GaDrvScreenDestroy(struct pipe_screen *s);
+uint32_t WINAPI GaDrvGetSurfaceId(struct pipe_screen *pScreen, struct pipe_resource *pResource);
+const WDDMGalliumDriverEnv *WINAPI GaDrvGetWDDMEnv(struct pipe_screen *pScreen);
+uint32_t WINAPI GaDrvGetContextId(struct pipe_context *pPipeContext);
+void WINAPI GaDrvContextFlush(struct pipe_context *pPipeContext);
+
+static void initDrvFuncs(void)
+{
+    g_drvfuncs.pfnGaDrvScreenCreate = GaDrvScreenCreate;
+    g_drvfuncs.pfnGaDrvScreenDestroy = GaDrvScreenDestroy;
+    g_drvfuncs.pfnGaDrvGetWDDMEnv = GaDrvGetWDDMEnv;
+    g_drvfuncs.pfnGaDrvGetContextId = GaDrvGetContextId;
+    g_drvfuncs.pfnGaDrvGetSurfaceId = GaDrvGetSurfaceId;
+    g_drvfuncs.pfnGaDrvContextFlush = GaDrvContextFlush;
+}
+#endif
 
 struct stw_shared_surface
@@ -252,5 +277,9 @@
     struct pipe_screen *screen = NULL;
 
+#if VBOX_MESA_V_MAJOR < 24
     if (gaDrvLoadSVGA(&g_drvfuncs))
+#else
+    initDrvFuncs();
+#endif
     {
         WDDMGalliumDriverEnv const *pEnv = GaDrvEnvKmtCreate();
@@ -291,5 +320,9 @@
 }
 
+#if VBOX_MESA_V_MAJOR < 24
 static boolean
+#else
+static bool
+#endif
 wddm_get_adapter_luid(struct pipe_screen *screen,
                       HDC hDC,
@@ -534,4 +567,5 @@
             vboxVDbgVEHandlerRegister();
 #endif
+            RTR3InitDll(RTR3INIT_FLAGS_UNOBTRUSIVE);
             D3DKMTLoad();
             stw_init(&stw_winsys);
Index: trunk/src/VBox/Additions/3D/win/VBoxGL/opengl32_defs.py
===================================================================
--- trunk/src/VBox/Additions/3D/win/VBoxGL/opengl32_defs.py	(revision 103999)
+++ trunk/src/VBox/Additions/3D/win/VBoxGL/opengl32_defs.py	(revision 103999)
@@ -0,0 +1,72 @@
+"""
+Copyright (C) 2024 Oracle and/or its affiliates.
+
+This file is part of VirtualBox base platform packages, as
+available from https://www.virtualbox.org.
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation, in version 3 of the
+License.
+
+This program is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, see <https://www.gnu.org/licenses>.
+
+SPDX-License-Identifier: GPL-3.0-only
+"""
+
+import sys
+
+#
+# Strip @d from function names:
+# glAccum@8                            @7
+# DrvCopyContext@12
+#
+def GenerateDef():
+
+    # Read lines from input file
+    in_file = open(sys.argv[1], "r")
+    if not in_file:
+        print("Error: couldn't open %s file!" % sys.argv[1])
+        sys.exit()
+
+    lines = in_file.readlines()
+
+    in_file.close()
+
+    # Write def file
+    out_file = open(sys.argv[2], "w")
+    if not out_file:
+        print("Error: couldn't open %s file!" % sys.argv[2])
+        sys.exit()
+
+    out_file.write('EXPORTS\n')
+
+    for line in lines:
+        line = line.strip()
+        if len(line) == 0:
+            continue
+
+        line_parts = line.split()
+        if len(line_parts) == 0:
+            continue
+
+        name_parts = line_parts[0].split('@')
+        if len(name_parts) != 2:
+            continue
+
+        out_line = name_parts[0]
+        if len(line_parts) > 1:
+            numSpaces = 30 - len(name_parts[0])
+            out_line = out_line + ' '*numSpaces + line_parts[1]
+
+        out_file.write('\t' + out_line + '\n')
+
+    out_file.close()
+
+GenerateDef()
Index: trunk/src/VBox/Additions/3D/win/VBoxNine/Makefile.kmk
===================================================================
--- trunk/src/VBox/Additions/3D/win/VBoxNine/Makefile.kmk	(revision 103998)
+++ trunk/src/VBox/Additions/3D/win/VBoxNine/Makefile.kmk	(revision 103999)
@@ -33,4 +33,8 @@
 
 VBoxNine_TEMPLATE = VBoxMesa3DGuestR3DllMinVista
+if $(VBOX_MESA_V_MAJOR) >= 24
+ VBoxNine_DEFS     = \
+ 	VBOX_MESA_STATIC_DRIVER
+endif
 #  -wd4100: unreferenced formal parameter
 #  -wd4200: nonstandard extension used : zero-sized array in struct/union
@@ -41,9 +45,27 @@
 VBoxNine_INCS     = \
 	$(VBOX_PATH_MESA)/src/gallium/frontends/nine
+if $(VBOX_MESA_V_MAJOR) >= 24
+ VBoxNine_INCS    += \
+ 	$(VBOX_PATH_3D)/win/include \
+ 	$(VBOX_PATH_3D)/win/VBoxSVGA \
+ 	$(VBOX_PATH_MESA)/src/gallium/drivers/svga \
+ 	$(VBOX_PATH_MESA)/src/gallium/drivers/svga/include \
+ 	$(VBOX_PATH_MESA)/src/gallium/winsys/svga/drm
+endif
 VBoxNine_SOURCES  = \
 	nine/nine_memory_helper.c \
 	VBoxNine.c \
-	VBoxNine.rc \
-	VBoxNine.def
+	VBoxNine.rc
+if $(VBOX_MESA_V_MAJOR) < 24
+ VBoxNine_SOURCES += \
+ 	VBoxNine.def
+else
+ VBoxNine_SOURCES += \
+ 	VBoxNine_static_drv.def \
+ 	../VBoxSVGA/VBoxSVGA.c \
+ 	../VBoxSVGA/winsys/vmw_screen.c \
+ 	../VBoxSVGA/winsys/vmw_screen_wddm.c \
+ 	../VBoxSVGA/winsys/vmw_screen_ioctl.c
+endif
 VBoxNine_LIBS     = \
 	$(VBOX_PATH_ADDITIONS_LIB)/VBoxWddmUmHlp$(VBOX_SUFF_LIB) \
@@ -52,4 +74,9 @@
 	$(VBOX_PATH_ADDITIONS_LIB)/VBoxMesaUtilLib$(VBOX_SUFF_LIB) \
 	$(VBOX_PATH_ADDITIONS_LIB)/VBoxMesaNineLib$(VBOX_SUFF_LIB)
+if $(VBOX_MESA_V_MAJOR) >= 24
+ VBoxNine_LIBS    += \
+ 	$(VBOX_PATH_ADDITIONS_LIB)/VBoxMesaSVGAWinsysLib$(VBOX_SUFF_LIB) \
+ 	$(VBOX_PATH_ADDITIONS_LIB)/VBoxMesaSVGALib$(VBOX_SUFF_LIB)
+endif
 
 if defined(VBOX_SIGNING_MODE) && defined(VBOX_SIGN_ADDITIONS)
@@ -69,4 +96,9 @@
 	$(VBOX_PATH_ADDITIONS_LIB)/VBoxMesaUtilLib-x86$(VBOX_SUFF_LIB) \
 	$(VBOX_PATH_ADDITIONS_LIB)/VBoxMesaNineLib-x86$(VBOX_SUFF_LIB)
+if $(VBOX_MESA_V_MAJOR) >= 24
+ VBoxNine-x86_LIBS    += \
+ 	$(VBOX_PATH_ADDITIONS_LIB)/VBoxMesaSVGAWinsysLib-x86$(VBOX_SUFF_LIB) \
+ 	$(VBOX_PATH_ADDITIONS_LIB)/VBoxMesaSVGALib-x86$(VBOX_SUFF_LIB)
+endif
 VBoxNine-x86_DEFS         = $(VBoxNine_DEFS) VBOX_WOW64
 
Index: trunk/src/VBox/Additions/3D/win/VBoxNine/VBoxNine.c
===================================================================
--- trunk/src/VBox/Additions/3D/win/VBoxNine/VBoxNine.c	(revision 103998)
+++ trunk/src/VBox/Additions/3D/win/VBoxNine/VBoxNine.c	(revision 103999)
@@ -30,4 +30,7 @@
 //#include <d3dumddi.h>
 
+#if VBOX_MESA_V_MAJOR >= 24
+#include <VBoxGaDriver.h>
+#endif
 #include <VBoxWddmUmHlp.h>
 
@@ -41,5 +44,5 @@
 
 //#include <iprt/alloc.h>
-//#include <iprt/initterm.h>
+#include <iprt/initterm.h>
 //#include <iprt/string.h>
 //#include <iprt/log.h>
@@ -56,4 +59,13 @@
 
 // #include "VBoxNine.h"
+
+#if VBOX_MESA_V_MAJOR >= 24
+struct pipe_screen * WINAPI GaDrvScreenCreate(const WDDMGalliumDriverEnv *pEnv);
+void WINAPI GaDrvScreenDestroy(struct pipe_screen *s);
+uint32_t WINAPI GaDrvGetSurfaceId(struct pipe_screen *pScreen, struct pipe_resource *pResource);
+const WDDMGalliumDriverEnv *WINAPI GaDrvGetWDDMEnv(struct pipe_screen *pScreen);
+uint32_t WINAPI GaDrvGetContextId(struct pipe_context *pPipeContext);
+void WINAPI GaDrvContextFlush(struct pipe_context *pPipeContext);
+#endif
 
 struct d3dadapter9_context_wddm
@@ -111,4 +123,5 @@
 }
 
+#if VBOX_MESA_V_MAJOR < 24
 HRESULT WINAPI
 GaNineD3DAdapter9Create(struct pipe_screen *s, ID3DAdapter9 **ppOut)
@@ -149,4 +162,77 @@
 }
 
+#else /* VBOX_MESA_V_MAJOR >= 24 */
+
+HRESULT WINAPI
+GaNineD3DAdapter9Create(const WDDMGalliumDriverEnv *pEnv, ID3DAdapter9 **ppOut)
+{
+    HRESULT hr;
+    struct pipe_screen *s = GaDrvScreenCreate(pEnv);
+    if (s)
+    {
+        struct d3dadapter9_context_wddm *ctx = NULL;
+        hr = d3dadapter9_context_wddm_create(&ctx, s);
+        if (SUCCEEDED(hr))
+        {
+            hr = NineAdapter9_new(&ctx->base, (struct NineAdapter9 **)ppOut);
+            if (FAILED(hr))
+            {
+                /// @todo NineAdapter9_new calls this as ctx->base.destroy,
+                //       and will not call if memory allocation fails.
+                // wddm_destroy(&pCtx->base);
+            }
+        }
+        Assert(SUCCEEDED(hr));
+    }
+    else
+    {
+        hr = E_FAIL;
+        AssertFailed();
+    }
+    return hr;
+}
+
+uint32_t WINAPI
+GaNineGetSurfaceId(IUnknown *pSurface)
+{
+    uint32_t sid = SVGA_ID_INVALID;
+
+    /// @todo QueryInterface?
+    struct NineResource9 *pNineResource = (struct NineResource9 *)pSurface;
+    struct pipe_resource *r = pNineResource->resource;
+    if (r)
+    {
+        struct pipe_screen *s = r->screen;
+        sid = GaDrvGetSurfaceId(s, r);
+    }
+
+    return sid;
+}
+
+extern struct pipe_context *
+NineDevice9_GetPipe( struct NineDevice9 *This );
+
+uint32_t WINAPI
+GaNineGetContextId(IDirect3DDevice9 *pDevice)
+{
+    uint32_t cid = SVGA_ID_INVALID;
+
+    /// @todo Verify that this is a NineDevice?
+    struct pipe_context *pipe = NineDevice9_GetPipe((struct NineDevice9 *)pDevice);
+    if (pipe)
+        cid = GaDrvGetContextId(pipe);
+
+    return cid;
+}
+
+void WINAPI
+GaNineFlush(IDirect3DDevice9 *pDevice)
+{
+    struct pipe_context *pipe = NineDevice9_GetPipe((struct NineDevice9 *)pDevice);
+    if (pipe)
+        GaDrvContextFlush(pipe);
+}
+#endif /* VBOX_MESA_V_MAJOR >= 24 */
+
 BOOL WINAPI DllMain(HINSTANCE hDLLInst,
                     DWORD fdwReason,
@@ -160,5 +246,5 @@
     {
         case DLL_PROCESS_ATTACH:
-            //RTR3InitDll(RTR3INIT_FLAGS_UNOBTRUSIVE);
+            RTR3InitDll(RTR3INIT_FLAGS_UNOBTRUSIVE);
             D3DKMTLoad();
             break;
Index: trunk/src/VBox/Additions/3D/win/VBoxNine/VBoxNine_static_drv.def
===================================================================
--- trunk/src/VBox/Additions/3D/win/VBoxNine/VBoxNine_static_drv.def	(revision 103999)
+++ trunk/src/VBox/Additions/3D/win/VBoxNine/VBoxNine_static_drv.def	(revision 103999)
@@ -0,0 +1,34 @@
+; $Id$;
+;; @file
+; Export definition file for the VBoxNine D3D9 state tracker.
+;
+
+;
+; Copyright (C) 2024 Oracle and/or its affiliates.
+;
+; This file is part of VirtualBox base platform packages, as
+; available from https://www.virtualbox.org.
+;
+; This program is free software; you can redistribute it and/or
+; modify it under the terms of the GNU General Public License
+; as published by the Free Software Foundation, in version 3 of the
+; License.
+;
+; This program is distributed in the hope that it will be useful, but
+; WITHOUT ANY WARRANTY; without even the implied warranty of
+; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+; General Public License for more details.
+;
+; You should have received a copy of the GNU General Public License
+; along with this program; if not, see <https://www.gnu.org/licenses>.
+;
+; SPDX-License-Identifier: GPL-3.0-only
+;
+
+LIBRARY VBOXNINE
+
+EXPORTS
+        GaNineD3DAdapter9Create             @1
+        GaNineGetSurfaceId                  @2
+        GaNineGetContextId                  @3
+        GaNineFlush                         @4
Index: trunk/src/VBox/Additions/3D/win/VBoxSVGA/VBoxSVGA.c
===================================================================
--- trunk/src/VBox/Additions/3D/win/VBoxSVGA/VBoxSVGA.c	(revision 103998)
+++ trunk/src/VBox/Additions/3D/win/VBoxSVGA/VBoxSVGA.c	(revision 103999)
@@ -27,4 +27,6 @@
 
 #include <VBoxWddmUmHlp.h>
+
+#include <iprt/initterm.h>
 
 #include "svga_public.h"
@@ -70,5 +72,5 @@
         if (pScreen->resource_get_handle(pScreen, NULL, pResource, &whandle, 0))
         {
-            u32Sid = (uint32_t)whandle.handle;
+            u32Sid = (uint32_t)(uintptr_t)whandle.handle;
         }
     }
@@ -114,4 +116,5 @@
 }
 
+#ifndef VBOX_MESA_STATIC_DRIVER
 BOOL WINAPI DllMain(HINSTANCE hDLLInst,
                     DWORD fdwReason,
@@ -125,5 +128,5 @@
     {
         case DLL_PROCESS_ATTACH:
-            //RTR3InitDll(RTR3INIT_FLAGS_UNOBTRUSIVE);
+            RTR3InitDll(RTR3INIT_FLAGS_UNOBTRUSIVE);
             D3DKMTLoad();
             break;
@@ -145,2 +148,3 @@
     return fReturn;
 }
+#endif
Index: trunk/src/VBox/Additions/3D/win/VBoxSVGA/winsys/vmw_screen.c
===================================================================
--- trunk/src/VBox/Additions/3D/win/VBoxSVGA/winsys/vmw_screen.c	(revision 103998)
+++ trunk/src/VBox/Additions/3D/win/VBoxSVGA/winsys/vmw_screen.c	(revision 103999)
@@ -54,5 +54,9 @@
 #include "util/os_file.h"
 #include "util/u_memory.h"
+#if VBOX_MESA_V_MAJOR < 24
 #include "pipe/p_compiler.h"
+#else
+#include "util/compiler.h"
+#endif
 #include "util/u_hash_table.h"
 
@@ -86,13 +90,22 @@
    vws->open_count = 1;
    vws->ioctl.drm_fd = -1; /* not used */
-   vws->force_coherent = FALSE;
+   vws->force_coherent = false;
    if (!vmw_ioctl_init(vws))
       goto out_no_ioctl;
 
    vws->base.have_gb_dma = !vws->force_coherent;
-   vws->base.need_to_rebind_resources = FALSE;
+   vws->base.need_to_rebind_resources = false;
    vws->base.have_transfer_from_buffer_cmd = vws->base.have_vgpu10;
-   vws->base.have_constant_buffer_offset_cmd = FALSE;
-   vws->cache_maps = FALSE;
+#if VBOX_MESA_V_MAJOR < 24
+   vws->base.have_constant_buffer_offset_cmd = false;
+#else
+   vws->base.have_constant_buffer_offset_cmd =
+      vws->ioctl.have_drm_2_20 && vws->base.have_sm5;
+   vws->base.have_index_vertex_buffer_offset_cmd = false;
+   vws->base.have_rasterizer_state_v2_cmd =
+      vws->ioctl.have_drm_2_20 && vws->base.have_sm5;
+#endif
+
+   vws->cache_maps = false;
    vws->fence_ops = vmw_fence_ops_create(vws);
    if (!vws->fence_ops)
Index: trunk/src/VBox/Additions/3D/win/VBoxSVGA/winsys/vmw_screen_ioctl.c
===================================================================
--- trunk/src/VBox/Additions/3D/win/VBoxSVGA/winsys/vmw_screen_ioctl.c	(revision 103998)
+++ trunk/src/VBox/Additions/3D/win/VBoxSVGA/winsys/vmw_screen_ioctl.c	(revision 103999)
@@ -110,5 +110,9 @@
 uint32
 vmw_ioctl_extended_context_create(struct vmw_winsys_screen *vws,
+#if VBOX_MESA_V_MAJOR < 24
                                   boolean vgpu10)
+#else
+                                  bool vgpu10)
+#endif
 {
    struct vmw_winsys_screen_wddm *vws_wddm = (struct vmw_winsys_screen_wddm *)vws;
@@ -265,5 +269,9 @@
                       const struct winsys_handle *whandle,
                       struct drm_vmw_surface_arg *req,
+#if VBOX_MESA_V_MAJOR < 24
                       boolean *needs_unref)
+#else
+                      bool *needs_unref)
+#endif
 {
    ASMBreakpoint();
@@ -444,7 +452,13 @@
 int
 vmw_ioctl_syncforcpu(struct vmw_region *region,
+#if VBOX_MESA_V_MAJOR < 24
                      boolean dont_block,
                      boolean readonly,
                      boolean allow_cs)
+#else
+                     bool dont_block,
+                     bool readonly,
+                     bool allow_cs)
+#endif
 {
     ASMBreakpoint();
@@ -462,6 +476,11 @@
 void
 vmw_ioctl_releasefromcpu(struct vmw_region *region,
+#if VBOX_MESA_V_MAJOR < 24
                          boolean readonly,
                          boolean allow_cs)
+#else
+                         bool readonly,
+                         bool allow_cs)
+#endif
 {
    ASMBreakpoint();
@@ -513,5 +532,6 @@
       return 0; /* Treat as signalled. */
 
-   vmw_fences_signal(vws->fence_ops, FenceQuery.u32ProcessedSeqNo, FenceQuery.u32SubmittedSeqNo, TRUE);
+   /** @todo last 3 params in mesa: arg.passed_seqno, 0, false */
+   vmw_fences_signal(vws->fence_ops, FenceQuery.u32ProcessedSeqNo, FenceQuery.u32SubmittedSeqNo, true);
 
    return FenceQuery.u32FenceStatus == GA_FENCE_STATUS_SIGNALED ? 0 : -1;
@@ -559,5 +579,5 @@
    if (vws->base.have_gb_objects) {
       for (i = 0; i < vws->ioctl.num_cap_3d; ++i) {
-	 vws->ioctl.cap_3d[i].has_cap = TRUE;
+	 vws->ioctl.cap_3d[i].has_cap = true;
 	 vws->ioctl.cap_3d[i].result.u = cap_buffer[i];
       }
@@ -599,5 +619,5 @@
 	 index = capArray[i][0];
 	 if (index < vws->ioctl.num_cap_3d) {
-	    vws->ioctl.cap_3d[index].has_cap = TRUE;
+	    vws->ioctl.cap_3d[index].has_cap = true;
 	    vws->ioctl.cap_3d[index].result.u = capArray[i][1];
 	 } else {
@@ -727,4 +747,9 @@
             gp_arg->value = (vboxGetShaderModel(vws_wddm) >= SVGA_SM_5);
             break;
+#if VBOX_MESA_V_MAJOR >= 24
+        case DRM_VMW_PARAM_GL43:
+            gp_arg->value = false; /** @todo */
+            break;
+#endif
         default: return -1;
     }
@@ -743,5 +768,9 @@
 }
 
+#if VBOX_MESA_V_MAJOR < 24
 boolean
+#else
+bool
+#endif
 vmw_ioctl_init(struct vmw_winsys_screen *vws)
 {
@@ -752,6 +781,11 @@
    int ret;
    uint32_t *cap_buffer;
+#if VBOX_MESA_V_MAJOR < 24
    boolean drm_gb_capable;
    boolean have_drm_2_5;
+#else
+   bool drm_gb_capable;
+   bool have_drm_2_5;
+#endif
 
    VMW_FUNC;
@@ -765,4 +799,7 @@
    vws->ioctl.have_drm_2_18 = 1;
    vws->ioctl.have_drm_2_19 = 1;
+#if VBOX_MESA_V_MAJOR >= 24
+   vws->ioctl.have_drm_2_20 = 1;
+#endif
 
    vws->ioctl.drm_execbuf_version = vws->ioctl.have_drm_2_9 ? 2 : 1;
@@ -792,5 +829,5 @@
    ret = vboxGetParam(vws_wddm, &gp_arg);
    if (ret)
-      vws->base.have_gb_objects = FALSE;
+      vws->base.have_gb_objects = false;
    else
       vws->base.have_gb_objects =
@@ -800,7 +837,10 @@
       goto out_no_3d;
 
-   vws->base.have_vgpu10 = FALSE;
-   vws->base.have_sm4_1 = FALSE;
-   vws->base.have_intra_surface_copy = FALSE;
+   vws->base.have_vgpu10 = false;
+   vws->base.have_sm4_1 = false;
+   vws->base.have_intra_surface_copy = false;
+#if VBOX_MESA_V_MAJOR >= 24
+   vws->base.device_id = 0x0405; /* assume SVGA II */
+#endif
 
    if (vws->base.have_gb_objects) {
@@ -836,9 +876,9 @@
 
             debug_printf("Have VGPU10 interface and hardware.\n");
-            vws->base.have_vgpu10 = TRUE;
+            vws->base.have_vgpu10 = true;
             vgpu10_val = getenv("SVGA_VGPU10");
             if (vgpu10_val && strcmp(vgpu10_val, "0") == 0) {
                debug_printf("Disabling VGPU10 interface.\n");
-               vws->base.have_vgpu10 = FALSE;
+               vws->base.have_vgpu10 = false;
             } else {
                debug_printf("Enabling VGPU10 interface.\n");
@@ -852,5 +892,5 @@
          ret = vboxGetParam(vws_wddm, &gp_arg);
          if (ret == 0 && gp_arg.value != 0) {
-            vws->base.have_intra_surface_copy = TRUE;
+            vws->base.have_intra_surface_copy = true;
          }
 
@@ -859,5 +899,5 @@
          ret = vboxGetParam(vws_wddm, &gp_arg);
          if (ret == 0 && gp_arg.value != 0) {
-            vws->base.have_sm4_1 = TRUE;
+            vws->base.have_sm4_1 = true;
          }
       }
@@ -868,7 +908,18 @@
          ret = vboxGetParam(vws_wddm, &gp_arg);
          if (ret == 0 && gp_arg.value != 0) {
-            vws->base.have_sm5 = TRUE;
+            vws->base.have_sm5 = true;
          }
       }
+
+#if VBOX_MESA_V_MAJOR >= 24
+      if (vws->ioctl.have_drm_2_20 && vws->base.have_sm5) {
+         memset(&gp_arg, 0, sizeof(gp_arg));
+         gp_arg.param = DRM_VMW_PARAM_GL43;
+         ret = vboxGetParam(vws_wddm, &gp_arg);
+         if (ret == 0 && gp_arg.value != 0) {
+            vws->base.have_gl43 = true;
+         }
+      }
+#endif
 
       memset(&gp_arg, 0, sizeof(gp_arg));
@@ -886,5 +937,5 @@
 
       if (vws->ioctl.have_drm_2_16) {
-         vws->base.have_coherent = TRUE;
+         vws->base.have_coherent = true;
       }
    } else {
@@ -948,15 +999,15 @@
       * modules before 2.10.
       */
-      vws->base.have_generate_mipmap_cmd = TRUE;
-      vws->base.have_set_predication_cmd = TRUE;
+      vws->base.have_generate_mipmap_cmd = true;
+      vws->base.have_set_predication_cmd = true;
    }
 
    if (vws->ioctl.have_drm_2_15) {
-      vws->base.have_fence_fd = TRUE;
+      vws->base.have_fence_fd = true;
    }
 
    free(cap_buffer);
    vmw_printf("%s OK\n", __FUNCTION__);
-   return TRUE;
+   return true;
   out_no_caps:
    free(vws->ioctl.cap_3d);
@@ -966,5 +1017,5 @@
    vws->ioctl.num_cap_3d = 0;
    debug_printf("%s Failed\n", __FUNCTION__);
-   return FALSE;
+   return false;
 }
 
Index: trunk/src/VBox/Additions/3D/win/VBoxSVGA/winsys/vmw_screen_wddm.c
===================================================================
--- trunk/src/VBox/Additions/3D/win/VBoxSVGA/winsys/vmw_screen_wddm.c	(revision 103998)
+++ trunk/src/VBox/Additions/3D/win/VBoxSVGA/winsys/vmw_screen_wddm.c	(revision 103999)
@@ -47,5 +47,9 @@
 
 
+#if VBOX_MESA_V_MAJOR < 24
 #include "pipe/p_compiler.h"
+#else
+#include "util/compiler.h"
+#endif
 #include "util/u_inlines.h"
 #include "util/u_memory.h"
@@ -75,5 +79,9 @@
                                struct winsys_handle *whandle,
                                SVGA3dSurfaceFormat *format);
+#if VBOX_MESA_V_MAJOR < 24
 static boolean
+#else
+static bool
+#endif
 vmw_drm_surface_get_handle(struct svga_winsys_screen *sws,
 			   struct svga_winsys_surface *surface,
@@ -116,4 +124,5 @@
 {
     RT_NOREF3(sws, whandle, format);
+    AssertFailed();
     return 0;
 }
@@ -125,4 +134,5 @@
 {
     RT_NOREF3(sws, whandle, format);
+    AssertFailed();
     return 0;
 }
@@ -134,5 +144,9 @@
  * which can be used to access the surface.
  */
+#if VBOX_MESA_V_MAJOR < 24
 static boolean
+#else
+static bool
+#endif
 vmw_drm_surface_get_handle(struct svga_winsys_screen *sws,
 			   struct svga_winsys_surface *surface,
@@ -146,8 +160,12 @@
 
     if (!surface)
-	return FALSE;
+	return false;
 
     vsrf = vmw_svga_winsys_surface(surface);
+#if VBOX_MESA_V_MAJOR < 24
     whandle->handle = vsrf->sid;
+#else
+    whandle->handle = (HANDLE)(uintptr_t)vsrf->sid;
+#endif
     whandle->stride = stride;
     whandle->offset = 0;
@@ -156,16 +174,14 @@
     case WINSYS_HANDLE_TYPE_SHARED:
     case WINSYS_HANDLE_TYPE_KMS:
-       whandle->handle = vsrf->sid;
        break;
     case WINSYS_HANDLE_TYPE_FD:
-       whandle->handle = vsrf->sid; /// @todo will this be enough for WDDM?
        break;
     default:
        vmw_error("Attempt to export unsupported handle type %d.\n",
 		 whandle->type);
-       return FALSE;
+       return false;
     }
 
-    return TRUE;
+    return true;
 }
 
Index: trunk/src/VBox/Additions/3D/win/include/VBoxGaNine.h
===================================================================
--- trunk/src/VBox/Additions/3D/win/include/VBoxGaNine.h	(revision 103998)
+++ trunk/src/VBox/Additions/3D/win/include/VBoxGaNine.h	(revision 103999)
@@ -38,9 +38,12 @@
 #endif
 
+#if VBOX_MESA_V_MAJOR < 24
 struct pipe_screen;
 struct pipe_resource;
 struct pipe_context;
+#endif
 typedef struct ID3DAdapter9 ID3DAdapter9;
 
+#if VBOX_MESA_V_MAJOR < 24
 typedef HRESULT WINAPI FNGaNineD3DAdapter9Create(struct pipe_screen *s, ID3DAdapter9 **ppOut);
 typedef FNGaNineD3DAdapter9Create *PFNGaNineD3DAdapter9Create;
@@ -51,4 +54,17 @@
 typedef struct pipe_context * WINAPI FNGaNinePipeContextFromDevice(IDirect3DDevice9 *pDevice);
 typedef FNGaNinePipeContextFromDevice *PFNGaNinePipeContextFromDevice;
+#else
+typedef HRESULT WINAPI FNGaNineD3DAdapter9Create(const WDDMGalliumDriverEnv *pEnv, ID3DAdapter9 **ppOut);
+typedef FNGaNineD3DAdapter9Create *PFNGaNineD3DAdapter9Create;
+
+typedef uint32_t WINAPI FNGaNineGetSurfaceId(IUnknown *pSurface);
+typedef FNGaNineGetSurfaceId *PFNGaNineGetSurfaceId;
+
+typedef uint32_t WINAPI FNGaNineGetContextId(IDirect3DDevice9 *pDevice);
+typedef FNGaNineGetContextId *PFNGaNineGetContextId;
+
+typedef void WINAPI FNGaNineFlush(IDirect3DDevice9 *pDevice);
+typedef FNGaNineFlush *PFNGaNineFlush;
+#endif
 
 #ifdef __cplusplus
