diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 14:19:18 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 14:19:18 +0000 |
commit | 4035b1bfb1e5843a539a8b624d21952b756974d1 (patch) | |
tree | f1e9cd5bf548cbc57ff2fddfb2b4aa9ae95587e2 /src/VBox/Additions/3D | |
parent | Initial commit. (diff) | |
download | virtualbox-upstream.tar.xz virtualbox-upstream.zip |
Adding upstream version 6.1.22-dfsg.upstream/6.1.22-dfsgupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/VBox/Additions/3D')
41 files changed, 6109 insertions, 0 deletions
diff --git a/src/VBox/Additions/3D/Config.kmk b/src/VBox/Additions/3D/Config.kmk new file mode 100644 index 00000000..2256278c --- /dev/null +++ b/src/VBox/Additions/3D/Config.kmk @@ -0,0 +1,96 @@ +# $Id: Config.kmk $ +## @file +# kBuild Configuration file for the Mesa3D. +# + +# +# Copyright (C) 2016-2020 Oracle Corporation +# +# This file is part of VirtualBox Open Source Edition (OSE), as +# available from http://www.virtualbox.org. This file is free software; +# you can redistribute it and/or modify it under the terms of the GNU +# General Public License (GPL) as published by the Free Software +# Foundation, in version 2 as it comes in the "COPYING" file of the +# VirtualBox OSE distribution. VirtualBox OSE is distributed in the +# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. +# + +VBOX_MESA3D_CONFIG_KMK_INCLUDED := 1 + +# Include the top-level configure file. +ifndef VBOX_ROOT_CONFIG_KMK_INCLUDED +include $(PATH_ROOT)/Config.kmk +endif + +VBOX_MESA := mesa-17.3.9 +VBOX_PATH_3D := $(PATH_ROOT)/src/VBox/Additions/3D +VBOX_PATH_MESA := $(PATH_ROOT)/src/VBox/Additions/3D/mesa/$(VBOX_MESA) +VBOX_PATH_WDDM := $(PATH_ROOT)/src/VBox/Additions/WINNT/Graphics/Video +VBOX_PATH_VMSVGA_INC := $(VBOX_PATH_MESA)/src/gallium/drivers/svga/include + +# +# Base template for Mesa3D code and code which uses Mesa3D libraries. +# +TEMPLATE_VBoxMesa3DGuestR3Dll = VBox Mesa 3D Guest User Mode DLL +TEMPLATE_VBoxMesa3DGuestR3Dll_EXTENDS = NewerVccVBoxGuestR3Dll +TEMPLATE_VBoxMesa3DGuestR3Dll_INST = $(INST_ADDITIONS) +TEMPLATE_VBoxMesa3DGuestR3Dll_DEFS = $(TEMPLATE_NewerVccVBoxGuestR3Dll_DEFS) \ + VBOX_WITH_MESA3D +TEMPLATE_VBoxMesa3DGuestR3Dll_SDKS.win = $(TEMPLATE_NewerVccVBoxGuestR3Dll_SDKS) \ + $(VBOX_WINDDK_GST_W8) +# VirtualBox specific modifications of the Mesa3D code. +# All modified places can be found by searching for VBOX +# +# Each define represents a group of related modifications. +# The purpose of the separation is to document why each modification was necessary. +# +# Modifications which would be nice to have in upstream Mesa code are marked with '*' here. +# +# VBOX Modifications in headers shared with VBox WDDM driver code (see comments). +# VBOX_WITH_MESA3D_COMPILE Tweaks to compile Mesa as part of VBox WDDM. +# VBOX_WITH_MESA3D_D3D_FROM_SYSTEMMEM Create D3DPOOL_SYSTEMMEM textures from provided system memory pointer. +# VBOX_WITH_MESA3D_D3D_THREADPOOL (No) threadpool for VBox build. +# VBOX_WITH_MESA3D_DBG Tweaks for easier debugging and better logging. +# VBOX_WITH_MESA3D_HACKS Hacks to make it work (need a proper solutions). +# *VBOX_WITH_MESA3D_MSC Tweaks for Microsoft VCC. +# VBOX_WITH_MESA3D_NINE_SVGA Make the D3D state tracker to work together with VMSVGA. +# VBOX_WITH_MESA3D_SVGA_GPU_FINISHED PIPE_QUERY_GPU_FINISHED in VMSVGA driver. +# VBOX_WITH_MESA3D_SVGA_HALFZ D3D Z coord [0.0;1.0] in the Gallium SVGA driver (VGPU9 only). +# VBOX_WITH_MESA3D_SVGA_INSTANCING Instancing for DrawPrimitives in the Gallium SVGA driver +# (VGPU9 only, VGPU10 has it). +TEMPLATE_VBoxMesa3DGuestR3Dll_DEFS += \ + VBOX_WITH_MESA3D_COMPILE \ + VBOX_WITH_MESA3D_D3D_FROM_SYSTEMMEM \ + VBOX_WITH_MESA3D_D3D_THREADPOOL \ + VBOX_WITH_MESA3D_DBG \ + VBOX_WITH_MESA3D_HACKS \ + VBOX_WITH_MESA3D_MSC \ + VBOX_WITH_MESA3D_NINE_SVGA \ + VBOX_WITH_MESA3D_SVGA_GPU_FINISHED \ + VBOX_WITH_MESA3D_SVGA_HALFZ \ + VBOX_WITH_MESA3D_SVGA_INSTANCING +TEMPLATE_VBoxMesa3DGuestR3Dll_DEFS.win = $(TEMPLATE_NewerVccVBoxGuestR3Dll_DEFS.win) \ + _USE_MATH_DEFINES \ + WINAPI=__stdcall \ + _WIN32 +TEMPLATE_VBoxMesa3DGuestR3Dll_INCS = $(TEMPLATE_NewerVccVBoxGuestR3Dll_INCS) \ + $(VBOX_PATH_MESA)/include \ + $(VBOX_PATH_MESA)/include/c99 \ + $(VBOX_PATH_MESA)/src \ + $(VBOX_PATH_MESA)/src/mesa \ + $(VBOX_PATH_MESA)/src/gallium/auxiliary \ + $(VBOX_PATH_MESA)/src/gallium/include \ + $(VBOX_PATH_3D)/win/VBoxWddmUmHlp + +# +# Variant of VBoxMesa3DGuestR3Dll that requires Windows Vista or later. +# +TEMPLATE_VBoxMesa3DGuestR3DllMinVista = VBox Mesa 3D Guest User Mode DLL (Windows Vista or newer) +TEMPLATE_VBoxMesa3DGuestR3DllMinVista_EXTENDS = VBoxMesa3DGuestR3Dll +ifeq ($(KBUILD_TARGET),win) +TEMPLATE_VBoxMesa3DGuestR3DllMinVista_LDFLAGS.win.x86 = $(filter-out -Section:.bss$(COMMA)RW!K,$(TEMPLATE_VBoxMesa3DGuestR3Dll_LDFLAGS.win.x86)) +TEMPLATE_VBoxMesa3DGuestR3DllMinVista_POST_CMDS.win.x86 = $(subst $(VBOX_PE_SET_VERSION), $(VBOX_PE_SET_VERSION) --vista,$(TEMPLATE_VBoxMesa3DGuestR3Dll_POST_CMDS.win.x86)) +TEMPLATE_VBoxMesa3DGuestR3DllMinVista_POST_CMDS.win.amd64 = $(if $(eq $(tool_do),LINK_LIBRARY),,$(VBOX_PE_SET_VERSION) --vista $(out)$$(NLTAB)$(TEMPLATE_VBoxMesa3DGuestR3Dll_POST_CMDS.win.amd64)) +TEMPLATE_VBoxMesa3DGuestR3DllMinVista_LNK_DEPS.win.amd64 = $(if $(eq $(tool_do),LINK_LIBRARY),,$(VBOX_PE_SET_VERSION)) $(TEMPLATE_VBoxMesa3DGuestR3Dll_LNK_DEPS.win.amd64) +endif + diff --git a/src/VBox/Additions/3D/Makefile.kmk b/src/VBox/Additions/3D/Makefile.kmk new file mode 100644 index 00000000..cef57fba --- /dev/null +++ b/src/VBox/Additions/3D/Makefile.kmk @@ -0,0 +1,36 @@ +# $Id: Makefile.kmk $ +## @file +# Sub-Makefile for the Mesa3D code. +# + +# +# Copyright (C) 2016-2020 Oracle Corporation +# +# This file is part of VirtualBox Open Source Edition (OSE), as +# available from http://www.virtualbox.org. This file is free software; +# you can redistribute it and/or modify it under the terms of the GNU +# General Public License (GPL) as published by the Free Software +# Foundation, in version 2 as it comes in the "COPYING" file of the +# VirtualBox OSE distribution. VirtualBox OSE is distributed in the +# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. +# + +SUB_DEPTH = ../../../.. +include $(KBUILD_PATH)/subheader.kmk + +# +# Make sure our Config.kmk is included. +# +ifndef VBOX_MESA3D_CONFIG_KMK_INCLUDED +include $(PATH_SUB_CURRENT)/Config.kmk +endif + +# +# Include sub-makefile. +# +include $(PATH_SUB_CURRENT)/mesa/Makefile.kmk +if1of ($(KBUILD_TARGET), win) +include $(PATH_SUB_CURRENT)/win/Makefile.kmk +endif + +include $(FILE_KBUILD_SUB_FOOTER) diff --git a/src/VBox/Additions/3D/mesa/.scm-settings b/src/VBox/Additions/3D/mesa/.scm-settings new file mode 100644 index 00000000..9d803ff1 --- /dev/null +++ b/src/VBox/Additions/3D/mesa/.scm-settings @@ -0,0 +1,20 @@ +# $Id: .scm-settings $ +## @file +# Source code massager settings for 3D additions stuff. +# + +# +# Copyright (C) 2010-2020 Oracle Corporation +# +# This file is part of VirtualBox Open Source Edition (OSE), as +# available from http://www.virtualbox.org. This file is free software; +# you can redistribute it and/or modify it under the terms of the GNU +# General Public License (GPL) as published by the Free Software +# Foundation, in version 2 as it comes in the "COPYING" file of the +# VirtualBox OSE distribution. VirtualBox OSE is distributed in the +# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. +# + + +--filter-out-dirs "/mesa-*/." + diff --git a/src/VBox/Additions/3D/mesa/Makefile.kmk b/src/VBox/Additions/3D/mesa/Makefile.kmk new file mode 100644 index 00000000..1c844f6f --- /dev/null +++ b/src/VBox/Additions/3D/mesa/Makefile.kmk @@ -0,0 +1,982 @@ +# $Id: Makefile.kmk $ +## @file +# Sub-Makefile for the VirtualBox Guest Mesa 3D components +# + +# +# Copyright (C) 2016-2020 Oracle Corporation +# +# This file is part of VirtualBox Open Source Edition (OSE), as +# available from http://www.virtualbox.org. This file is free software; +# you can redistribute it and/or modify it under the terms of the GNU +# General Public License (GPL) as published by the Free Software +# Foundation, in version 2 as it comes in the "COPYING" file of the +# VirtualBox OSE distribution. VirtualBox OSE is distributed in the +# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. +# + +SUB_DEPTH = ../../../../.. +include $(KBUILD_PATH)/subheader.kmk + +# +# Target lists. +# +LIBRARIES.win += \ + VBoxMesaUtilLib \ + VBoxMesaLib \ + VBoxMesaWglLib \ + VBoxMesaGalliumAuxLib \ + VBoxMesaNineLib \ + VBoxMesaSVGALib \ + VBoxMesaSVGAWinsysLib +LIBRARIES.win.amd64 += \ + VBoxMesaUtilLib-x86 \ + VBoxMesaLib-x86 \ + VBoxMesaWglLib-x86 \ + VBoxMesaGalliumAuxLib-x86 \ + VBoxMesaNineLib-x86 \ + VBoxMesaSVGALib-x86 \ + VBoxMesaSVGAWinsysLib-x86 + + +TEMPLATE_VBoxMesa3DGuestR3Lib = VBox Mesa 3D Guest User Mode Library +TEMPLATE_VBoxMesa3DGuestR3Lib_EXTENDS = VBoxMesa3DGuestR3Dll +TEMPLATE_VBoxMesa3DGuestR3Lib_INST = $(INST_ADDITIONS_LIB) +ifeq ($(KBUILD_TARGET),win) +# Do not treat warnings as errors, because Mesa code produces too many warnings with MSC. +TEMPLATE_VBoxMesa3DGuestR3Lib_CFLAGS = $(filter-out -WX,$(TEMPLATE_VBoxMesa3DGuestR3Dll_CFLAGS)) +TEMPLATE_VBoxMesa3DGuestR3Lib_CXXFLAGS = $(filter-out -WX,$(TEMPLATE_VBoxMesa3DGuestR3Dll_CXXFLAGS)) +# -wd4005: vcc120: '__useHeader' : macro redefinition +# -wd4013: undefined; assuming extern returning int +# -wd4018: signed/unsigned mismatch +# -wd4054: 'type cast' : from function pointer to data pointer 'void *' +# -wd4057: 'function' : 'int *' differs in indirection to slightly different base types from 'uint32_t *' +# -wd4090: 'function' : different 'const' qualifiers +# -wd4098: 'void' function returning a value +# -wd4099: 'st_src_reg' : type name first seen using 'class' now seen using 'struct' +# -wd4100: unreferenced formal parameter +# -wd4101: unreferenced local variable +# -wd4130: '==' : logical operation on address of string constant +# -wd4132: 'color' : const object should be initialized +# -wd4146: unary minus operator applied to unsigned type, result still unsigned +# -wd4152: nonstandard extension, function/data pointer conversion in expression +# -wd4189: 'signo' : local variable is initialized but not referenced +# -wd4200: nonstandard extension used : zero-sized array in struct/union +# -wd4204: nonstandard extension used : non-constant aggregate initializer +# -wd4206: nonstandard extension used : translation unit is empty +# -wd4211: nonstandard extension used : redefined extern to static +# -wd4221: nonstandard extension used : 'tokens' : cannot be initialized using address of automatic variable 'tokens' +# -wd4245: '=' : conversion from 'int' to 'unsigned int', signed/unsigned mismatch +# -wd4255: no function prototype given +# -wd4258: 'i' : definition from the for loop is ignored; the definition from the enclosing scope is used +# -wd4265: 'ir_variable_refcount_visitor' : class has virtual functions, but destructor is not virtual +# -wd4267: '=' : conversion from 'size_t' to 'unsigned int', possible loss of data +# -wd4266: 'void ir_visitor::visit(ir_rvalue *)' : no override available for virtual member function from base 'ir_visitor'; function is hidden +# -wd4287: unsigned/negative constant mismatch +# -wd4291: 'void *exec_node::operator new(size_t,void *)' : no matching operator delete found; memory will not be freed if initialization throws an exception +# -wd4305: truncation from 'double' to 'const float' +# -wd4306: 'type cast' : conversion from 'int' to 'void *' of greater size +# -wd4310: cast truncates constant value +# -wd4311: 'type cast' : pointer truncation from 'void *' to 'unsigned long' +# -wd4351: new behavior: elements of array '_mesa_glsl_parse_state::cs_input_local_size' will be default initialized +# -wd4355: 'this' : used in base member initializer list +# -wd4388: '==' : signed/unsigned mismatch +# -wd4389: '==' : signed/unsigned mismatch +# -wd4640: 'ts' : construction of local static object is not thread-safe +# -wd4668: '__STDC_VERSION__' is not defined as a preprocessor macro, replacing with '0' for '#if/#elif' +# -wd4700: uninitialized local variable 'tmp' used +# -wd4701: potentially uninitialized local variable 'query' used +# -wd4702: unreachable code +# -wd4703: vcc120: potentially uninitialized local pointer variable 'gen_func' used +# -wd4756: overflow in constant arithmetic +# -wd4800: 'int' : forcing value to bool 'true' or 'false' (performance warning) +# -wd4805: '|=' : unsafe mix of type 'GLboolean' and type 'bool' in operation +# -wd4918: 'y' : invalid character in pragma optimization list +VBOX_MESA3D_VCC_DISABLED_WARNINGS = \ + -wd4005 -wd4013 -wd4018 -wd4054 -wd4057 -wd4090 -wd4098 -wd4099 -wd4100 -wd4101 -wd4130 -wd4132 -wd4146 \ + -wd4152 -wd4189 -wd4200 -wd4204 -wd4206 -wd4211 -wd4221 -wd4245 -wd4255 -wd4258 -wd4265 -wd4267 -wd4266 \ + -wd4287 -wd4291 -wd4305 -wd4306 -wd4310 -wd4311 -wd4351 -wd4355 -wd4388 -wd4389 -wd4640 -wd4668 -wd4700 \ + -wd4701 -wd4702 -wd4703 -wd4756 -wd4800 -wd4805 -wd4918 +TEMPLATE_VBoxMesa3DGuestR3Lib_CFLAGS.win += $(VBOX_MESA3D_VCC_DISABLED_WARNINGS) +TEMPLATE_VBoxMesa3DGuestR3Lib_CXXFLAGS.win += $(VBOX_MESA3D_VCC_DISABLED_WARNINGS) +endif +TEMPLATE_VBoxMesa3DGuestR3Lib_INCS = \ + include \ + $(VBOX_MESA)/include/GL \ + $(VBOX_MESA)/src/mapi \ + $(VBOX_MESA)/src/util \ + $(VBOX_MESA)/src/mesa/main \ + $(VBOX_MESA)/src/compiler \ + $(VBOX_MESA)/src/compiler/nir \ + $(VBOX_MESA)/src/gallium/state_trackers/wgl \ + $(TEMPLATE_VBoxMesa3DGuestR3Dll_INCS) +TEMPLATE_VBoxMesa3DGuestR3Lib_DEFS = \ + $(TEMPLATE_VBoxMesa3DGuestR3Dll_DEFS) \ + PACKAGE_VERSION=\"$(VBOX_MESA)\" \ + PACKAGE_BUGREPORT=\"$(VBOX_MESA)\" +# For wgl, glapi and mesa +TEMPLATE_VBoxMesa3DGuestR3Lib_DEFS += \ + MAPI_MODE_UTIL _GDI32_ BUILD_GL32 KHRONOS_DLL_EXPORTS GL_API=GLAPI GL_APIENTRY=GLAPIENTRY _GLAPI_NO_EXPORTS +TEMPLATE_VBoxMesa3DGuestR3Lib_DEFS.release = \ + $(TEMPLATE_VBoxMesa3DGuestR3Dll_DEFS.release) \ + NDEBUG + + +# +# VBoxMesaUtilLib +# +VBoxMesaUtilLib_TEMPLATE = VBoxMesa3DGuestR3Lib +VBoxMesaUtilLib_SOURCES = \ + $(VBOX_MESA)/src/util/bitscan.c \ + $(VBOX_MESA)/src/util/build_id.c \ + $(VBOX_MESA)/src/util/crc32.c \ + $(VBOX_MESA)/src/util/debug.c \ + $(VBOX_MESA)/src/util/disk_cache.c \ + $(VBOX_MESA)/src/util/half_float.c \ + $(VBOX_MESA)/src/util/hash_table.c \ + $(VBOX_MESA)/src/util/ralloc.c \ + $(VBOX_MESA)/src/util/rand_xor.c \ + $(VBOX_MESA)/src/util/register_allocate.c \ + $(VBOX_MESA)/src/util/rgtc.c \ + $(VBOX_MESA)/src/util/set.c \ + $(VBOX_MESA)/src/util/mesa-sha1.c \ + $(VBOX_MESA)/src/util/sha1/sha1.c \ + $(VBOX_MESA)/src/util/slab.c \ + $(VBOX_MESA)/src/util/string_buffer.c \ + $(VBOX_MESA)/src/util/strtod.c \ + $(VBOX_MESA)/src/util/u_atomic.c \ + $(VBOX_MESA)/src/util/u_queue.c \ + $(VBOX_MESA)/src/util/u_vector.c +# Auto-generated +VBoxMesaUtilLib_SOURCES += \ + $(VBOX_MESA)/src/util/format_srgb.c + +# 32 bit lib for 64 bit build +VBoxMesaUtilLib-x86_EXTENDS = VBoxMesaUtilLib +VBoxMesaUtilLib-x86_BLD_TRG_ARCH = x86 + + +# +# VBoxMesaLib +# +VBoxMesaLib_TEMPLATE = VBoxMesa3DGuestR3Lib +VBoxMesaLib_SOURCES = \ + $(VBOX_MESA)/src/mesa/state_tracker/st_atifs_to_tgsi.c \ + $(VBOX_MESA)/src/mesa/state_tracker/st_atom_array.c \ + $(VBOX_MESA)/src/mesa/state_tracker/st_atom_atomicbuf.c \ + $(VBOX_MESA)/src/mesa/state_tracker/st_atom_blend.c \ + $(VBOX_MESA)/src/mesa/state_tracker/st_atom.c \ + $(VBOX_MESA)/src/mesa/state_tracker/st_atom_clip.c \ + $(VBOX_MESA)/src/mesa/state_tracker/st_atom_constbuf.c \ + $(VBOX_MESA)/src/mesa/state_tracker/st_atom_depth.c \ + $(VBOX_MESA)/src/mesa/state_tracker/st_atom_framebuffer.c \ + $(VBOX_MESA)/src/mesa/state_tracker/st_atom_image.c \ + $(VBOX_MESA)/src/mesa/state_tracker/st_atom_msaa.c \ + $(VBOX_MESA)/src/mesa/state_tracker/st_atom_pixeltransfer.c \ + $(VBOX_MESA)/src/mesa/state_tracker/st_atom_rasterizer.c \ + $(VBOX_MESA)/src/mesa/state_tracker/st_atom_sampler.c \ + $(VBOX_MESA)/src/mesa/state_tracker/st_atom_scissor.c \ + $(VBOX_MESA)/src/mesa/state_tracker/st_atom_shader.c \ + $(VBOX_MESA)/src/mesa/state_tracker/st_atom_stipple.c \ + $(VBOX_MESA)/src/mesa/state_tracker/st_atom_storagebuf.c \ + $(VBOX_MESA)/src/mesa/state_tracker/st_atom_tess.c \ + $(VBOX_MESA)/src/mesa/state_tracker/st_atom_texture.c \ + $(VBOX_MESA)/src/mesa/state_tracker/st_atom_viewport.c \ + $(VBOX_MESA)/src/mesa/state_tracker/st_cb_bitmap.c \ + $(VBOX_MESA)/src/mesa/state_tracker/st_cb_bitmap_shader.c \ + $(VBOX_MESA)/src/mesa/state_tracker/st_cb_blit.c \ + $(VBOX_MESA)/src/mesa/state_tracker/st_cb_bufferobjects.c \ + $(VBOX_MESA)/src/mesa/state_tracker/st_cb_clear.c \ + $(VBOX_MESA)/src/mesa/state_tracker/st_cb_compute.c \ + $(VBOX_MESA)/src/mesa/state_tracker/st_cb_condrender.c \ + $(VBOX_MESA)/src/mesa/state_tracker/st_cb_copyimage.c \ + $(VBOX_MESA)/src/mesa/state_tracker/st_cb_drawpixels.c \ + $(VBOX_MESA)/src/mesa/state_tracker/st_cb_drawpixels_shader.c \ + $(VBOX_MESA)/src/mesa/state_tracker/st_cb_drawtex.c \ + $(VBOX_MESA)/src/mesa/state_tracker/st_cb_eglimage.c \ + $(VBOX_MESA)/src/mesa/state_tracker/st_cb_fbo.c \ + $(VBOX_MESA)/src/mesa/state_tracker/st_cb_feedback.c \ + $(VBOX_MESA)/src/mesa/state_tracker/st_cb_flush.c \ + $(VBOX_MESA)/src/mesa/state_tracker/st_cb_memoryobjects.c \ + $(VBOX_MESA)/src/mesa/state_tracker/st_cb_msaa.c \ + $(VBOX_MESA)/src/mesa/state_tracker/st_cb_perfmon.c \ + $(VBOX_MESA)/src/mesa/state_tracker/st_cb_program.c \ + $(VBOX_MESA)/src/mesa/state_tracker/st_cb_queryobj.c \ + $(VBOX_MESA)/src/mesa/state_tracker/st_cb_rasterpos.c \ + $(VBOX_MESA)/src/mesa/state_tracker/st_cb_readpixels.c \ + $(VBOX_MESA)/src/mesa/state_tracker/st_cb_strings.c \ + $(VBOX_MESA)/src/mesa/state_tracker/st_cb_syncobj.c \ + $(VBOX_MESA)/src/mesa/state_tracker/st_cb_texturebarrier.c \ + $(VBOX_MESA)/src/mesa/state_tracker/st_cb_texture.c \ + $(VBOX_MESA)/src/mesa/state_tracker/st_cb_viewport.c \ + $(VBOX_MESA)/src/mesa/state_tracker/st_cb_xformfb.c \ + $(VBOX_MESA)/src/mesa/state_tracker/st_context.c \ + $(VBOX_MESA)/src/mesa/state_tracker/st_copytex.c \ + $(VBOX_MESA)/src/mesa/state_tracker/st_debug.c \ + $(VBOX_MESA)/src/mesa/state_tracker/st_draw.c \ + $(VBOX_MESA)/src/mesa/state_tracker/st_draw_feedback.c \ + $(VBOX_MESA)/src/mesa/state_tracker/st_extensions.c \ + $(VBOX_MESA)/src/mesa/state_tracker/st_format.c \ + $(VBOX_MESA)/src/mesa/state_tracker/st_gen_mipmap.c \ + $(VBOX_MESA)/src/mesa/state_tracker/st_glsl_to_nir.cpp \ + $(VBOX_MESA)/src/mesa/state_tracker/st_glsl_to_tgsi.cpp \ + $(VBOX_MESA)/src/mesa/state_tracker/st_glsl_to_tgsi_private.cpp \ + $(VBOX_MESA)/src/mesa/state_tracker/st_glsl_to_tgsi_temprename.cpp \ + $(VBOX_MESA)/src/mesa/state_tracker/st_glsl_types.cpp \ + $(VBOX_MESA)/src/mesa/state_tracker/st_manager.c \ + $(VBOX_MESA)/src/mesa/state_tracker/st_mesa_to_tgsi.c \ + $(VBOX_MESA)/src/mesa/state_tracker/st_nir_lower_builtin.c \ + $(VBOX_MESA)/src/mesa/state_tracker/st_nir_lower_tex_src_plane.c \ + $(VBOX_MESA)/src/mesa/state_tracker/st_pbo.c \ + $(VBOX_MESA)/src/mesa/state_tracker/st_program.c \ + $(VBOX_MESA)/src/mesa/state_tracker/st_sampler_view.c \ + $(VBOX_MESA)/src/mesa/state_tracker/st_scissor.c \ + $(VBOX_MESA)/src/mesa/state_tracker/st_shader_cache.c \ + $(VBOX_MESA)/src/mesa/state_tracker/st_texture.c \ + $(VBOX_MESA)/src/mesa/state_tracker/st_tgsi_lower_yuv.c \ + $(VBOX_MESA)/src/mesa/state_tracker/st_vdpau.c +VBoxMesaLib_SOURCES += \ + $(VBOX_MESA)/src/mesa/program/arbprogparse.c \ + $(VBOX_MESA)/src/mesa/program/ir_to_mesa.cpp \ + $(VBOX_MESA)/src/mesa/program/lex.yy.c \ + $(VBOX_MESA)/src/mesa/program/prog_cache.c \ + $(VBOX_MESA)/src/mesa/program/prog_execute.c \ + $(VBOX_MESA)/src/mesa/program/prog_instruction.c \ + $(VBOX_MESA)/src/mesa/program/prog_noise.c \ + $(VBOX_MESA)/src/mesa/program/prog_opt_constant_fold.c \ + $(VBOX_MESA)/src/mesa/program/prog_optimize.c \ + $(VBOX_MESA)/src/mesa/program/prog_parameter.c \ + $(VBOX_MESA)/src/mesa/program/prog_parameter_layout.c \ + $(VBOX_MESA)/src/mesa/program/prog_print.c \ + $(VBOX_MESA)/src/mesa/program/program.c \ + $(VBOX_MESA)/src/mesa/program/programopt.c \ + $(VBOX_MESA)/src/mesa/program/program_parse_extra.c \ + $(VBOX_MESA)/src/mesa/program/program_parse.tab.c \ + $(VBOX_MESA)/src/mesa/program/prog_statevars.c \ + $(VBOX_MESA)/src/mesa/program/symbol_table.c +VBoxMesaLib_SOURCES += \ + $(VBOX_MESA)/src/mesa/main/accum.c \ + $(VBOX_MESA)/src/mesa/main/api_arrayelt.c \ + $(VBOX_MESA)/src/mesa/main/api_exec.c \ + $(VBOX_MESA)/src/mesa/main/api_loopback.c \ + $(VBOX_MESA)/src/mesa/main/api_validate.c \ + $(VBOX_MESA)/src/mesa/main/arbprogram.c \ + $(VBOX_MESA)/src/mesa/main/arrayobj.c \ + $(VBOX_MESA)/src/mesa/main/atifragshader.c \ + $(VBOX_MESA)/src/mesa/main/attrib.c \ + $(VBOX_MESA)/src/mesa/main/barrier.c \ + $(VBOX_MESA)/src/mesa/main/bbox.c \ + $(VBOX_MESA)/src/mesa/main/blend.c \ + $(VBOX_MESA)/src/mesa/main/blit.c \ + $(VBOX_MESA)/src/mesa/main/bufferobj.c \ + $(VBOX_MESA)/src/mesa/main/buffers.c \ + $(VBOX_MESA)/src/mesa/main/clear.c \ + $(VBOX_MESA)/src/mesa/main/clip.c \ + $(VBOX_MESA)/src/mesa/main/colortab.c \ + $(VBOX_MESA)/src/mesa/main/compute.c \ + $(VBOX_MESA)/src/mesa/main/condrender.c \ + $(VBOX_MESA)/src/mesa/main/context.c \ + $(VBOX_MESA)/src/mesa/main/convolve.c \ + $(VBOX_MESA)/src/mesa/main/copyimage.c \ + $(VBOX_MESA)/src/mesa/main/cpuinfo.c \ + $(VBOX_MESA)/src/mesa/main/debug.c \ + $(VBOX_MESA)/src/mesa/main/debug_output.c \ + $(VBOX_MESA)/src/mesa/main/depth.c \ + $(VBOX_MESA)/src/mesa/main/dlist.c \ + $(VBOX_MESA)/src/mesa/main/drawpix.c \ + $(VBOX_MESA)/src/mesa/main/drawtex.c \ + $(VBOX_MESA)/src/mesa/main/enable.c \ + $(VBOX_MESA)/src/mesa/main/enums.c \ + $(VBOX_MESA)/src/mesa/main/errors.c \ + $(VBOX_MESA)/src/mesa/main/eval.c \ + $(VBOX_MESA)/src/mesa/main/execmem.c \ + $(VBOX_MESA)/src/mesa/main/extensions.c \ + $(VBOX_MESA)/src/mesa/main/extensions_table.c \ + $(VBOX_MESA)/src/mesa/main/externalobjects.c \ + $(VBOX_MESA)/src/mesa/main/fbobject.c \ + $(VBOX_MESA)/src/mesa/main/feedback.c \ + $(VBOX_MESA)/src/mesa/main/ff_fragment_shader.cpp \ + $(VBOX_MESA)/src/mesa/main/ffvertex_prog.c \ + $(VBOX_MESA)/src/mesa/main/fog.c \ + $(VBOX_MESA)/src/mesa/main/format_fallback.c \ + $(VBOX_MESA)/src/mesa/main/format_pack.c \ + $(VBOX_MESA)/src/mesa/main/format_unpack.c \ + $(VBOX_MESA)/src/mesa/main/formatquery.c \ + $(VBOX_MESA)/src/mesa/main/formats.c \ + $(VBOX_MESA)/src/mesa/main/format_utils.c \ + $(VBOX_MESA)/src/mesa/main/framebuffer.c \ + $(VBOX_MESA)/src/mesa/main/get.c \ + $(VBOX_MESA)/src/mesa/main/genmipmap.c \ + $(VBOX_MESA)/src/mesa/main/getstring.c \ + $(VBOX_MESA)/src/mesa/main/glformats.c \ + $(VBOX_MESA)/src/mesa/main/glthread.c \ + $(VBOX_MESA)/src/mesa/main/hash.c \ + $(VBOX_MESA)/src/mesa/main/hint.c \ + $(VBOX_MESA)/src/mesa/main/histogram.c \ + $(VBOX_MESA)/src/mesa/main/image.c \ + $(VBOX_MESA)/src/mesa/main/imports.c \ + $(VBOX_MESA)/src/mesa/main/light.c \ + $(VBOX_MESA)/src/mesa/main/lines.c \ + $(VBOX_MESA)/src/mesa/main/marshal.c \ + $(VBOX_MESA)/src/mesa/main/marshal_generated.c \ + $(VBOX_MESA)/src/mesa/main/matrix.c \ + $(VBOX_MESA)/src/mesa/main/mipmap.c \ + $(VBOX_MESA)/src/mesa/main/mm.c \ + $(VBOX_MESA)/src/mesa/main/multisample.c \ + $(VBOX_MESA)/src/mesa/main/objectlabel.c \ + $(VBOX_MESA)/src/mesa/main/objectpurge.c \ + $(VBOX_MESA)/src/mesa/main/pack.c \ + $(VBOX_MESA)/src/mesa/main/pbo.c \ + $(VBOX_MESA)/src/mesa/main/performance_monitor.c \ + $(VBOX_MESA)/src/mesa/main/performance_query.c \ + $(VBOX_MESA)/src/mesa/main/pipelineobj.c \ + $(VBOX_MESA)/src/mesa/main/pixel.c \ + $(VBOX_MESA)/src/mesa/main/pixelstore.c \ + $(VBOX_MESA)/src/mesa/main/pixeltransfer.c \ + $(VBOX_MESA)/src/mesa/main/points.c \ + $(VBOX_MESA)/src/mesa/main/polygon.c \ + $(VBOX_MESA)/src/mesa/main/program_resource.c \ + $(VBOX_MESA)/src/mesa/main/querymatrix.c \ + $(VBOX_MESA)/src/mesa/main/queryobj.c \ + $(VBOX_MESA)/src/mesa/main/rastpos.c \ + $(VBOX_MESA)/src/mesa/main/readpix.c \ + $(VBOX_MESA)/src/mesa/main/remap.c \ + $(VBOX_MESA)/src/mesa/main/renderbuffer.c \ + $(VBOX_MESA)/src/mesa/main/robustness.c \ + $(VBOX_MESA)/src/mesa/main/samplerobj.c \ + $(VBOX_MESA)/src/mesa/main/scissor.c \ + $(VBOX_MESA)/src/mesa/main/shaderapi.c \ + $(VBOX_MESA)/src/mesa/main/shaderimage.c \ + $(VBOX_MESA)/src/mesa/main/shaderobj.c \ + $(VBOX_MESA)/src/mesa/main/shader_query.cpp \ + $(VBOX_MESA)/src/mesa/main/shared.c \ + $(VBOX_MESA)/src/mesa/main/state.c \ + $(VBOX_MESA)/src/mesa/main/stencil.c \ + $(VBOX_MESA)/src/mesa/main/syncobj.c \ + $(VBOX_MESA)/src/mesa/main/texcompress.c \ + $(VBOX_MESA)/src/mesa/main/texcompress_bptc.c \ + $(VBOX_MESA)/src/mesa/main/texcompress_cpal.c \ + $(VBOX_MESA)/src/mesa/main/texcompress_etc.c \ + $(VBOX_MESA)/src/mesa/main/texcompress_fxt1.c \ + $(VBOX_MESA)/src/mesa/main/texcompress_rgtc.c \ + $(VBOX_MESA)/src/mesa/main/texcompress_s3tc.c \ + $(VBOX_MESA)/src/mesa/main/texenv.c \ + $(VBOX_MESA)/src/mesa/main/texformat.c \ + $(VBOX_MESA)/src/mesa/main/texgen.c \ + $(VBOX_MESA)/src/mesa/main/texgetimage.c \ + $(VBOX_MESA)/src/mesa/main/teximage.c \ + $(VBOX_MESA)/src/mesa/main/texobj.c \ + $(VBOX_MESA)/src/mesa/main/texparam.c \ + $(VBOX_MESA)/src/mesa/main/texstate.c \ + $(VBOX_MESA)/src/mesa/main/texstorage.c \ + $(VBOX_MESA)/src/mesa/main/texstore.c \ + $(VBOX_MESA)/src/mesa/main/texturebindless.c \ + $(VBOX_MESA)/src/mesa/main/textureview.c \ + $(VBOX_MESA)/src/mesa/main/transformfeedback.c \ + $(VBOX_MESA)/src/mesa/main/uniform_query.cpp \ + $(VBOX_MESA)/src/mesa/main/uniforms.c \ + $(VBOX_MESA)/src/mesa/main/varray.c \ + $(VBOX_MESA)/src/mesa/main/vdpau.c \ + $(VBOX_MESA)/src/mesa/main/version.c \ + $(VBOX_MESA)/src/mesa/main/viewport.c \ + $(VBOX_MESA)/src/mesa/main/vtxfmt.c \ + $(VBOX_MESA)/src/mesa/main/es1_conversion.c +VBoxMesaLib_SOURCES += \ + $(VBOX_MESA)/src/mesa/math/m_debug_clip.c \ + $(VBOX_MESA)/src/mesa/math/m_debug_norm.c \ + $(VBOX_MESA)/src/mesa/math/m_debug_xform.c \ + $(VBOX_MESA)/src/mesa/math/m_eval.c \ + $(VBOX_MESA)/src/mesa/math/m_matrix.c \ + $(VBOX_MESA)/src/mesa/math/m_translate.c \ + $(VBOX_MESA)/src/mesa/math/m_vector.c +VBoxMesaLib_SOURCES += \ + $(VBOX_MESA)/src/mesa/vbo/vbo_context.c \ + $(VBOX_MESA)/src/mesa/vbo/vbo_exec_api.c \ + $(VBOX_MESA)/src/mesa/vbo/vbo_exec_array.c \ + $(VBOX_MESA)/src/mesa/vbo/vbo_exec.c \ + $(VBOX_MESA)/src/mesa/vbo/vbo_exec_draw.c \ + $(VBOX_MESA)/src/mesa/vbo/vbo_exec_eval.c \ + $(VBOX_MESA)/src/mesa/vbo/vbo_minmax_index.c \ + $(VBOX_MESA)/src/mesa/vbo/vbo_noop.c \ + $(VBOX_MESA)/src/mesa/vbo/vbo_primitive_restart.c \ + $(VBOX_MESA)/src/mesa/vbo/vbo_rebase.c \ + $(VBOX_MESA)/src/mesa/vbo/vbo_save_api.c \ + $(VBOX_MESA)/src/mesa/vbo/vbo_save.c \ + $(VBOX_MESA)/src/mesa/vbo/vbo_save_draw.c \ + $(VBOX_MESA)/src/mesa/vbo/vbo_save_loopback.c \ + $(VBOX_MESA)/src/mesa/vbo/vbo_split.c \ + $(VBOX_MESA)/src/mesa/vbo/vbo_split_copy.c \ + $(VBOX_MESA)/src/mesa/vbo/vbo_split_inplace.c +VBoxMesaLib_SOURCES += \ + $(VBOX_MESA)/src/compiler/blob.c \ + $(VBOX_MESA)/src/compiler/glsl_types.cpp \ + $(VBOX_MESA)/src/compiler/nir_types.cpp \ + $(VBOX_MESA)/src/compiler/shader_enums.c \ + $(VBOX_MESA)/src/compiler/glsl/ast_array_index.cpp \ + $(VBOX_MESA)/src/compiler/glsl/ast_expr.cpp \ + $(VBOX_MESA)/src/compiler/glsl/ast_function.cpp \ + $(VBOX_MESA)/src/compiler/glsl/ast_to_hir.cpp \ + $(VBOX_MESA)/src/compiler/glsl/ast_type.cpp \ + $(VBOX_MESA)/src/compiler/glsl/builtin_functions.cpp \ + $(VBOX_MESA)/src/compiler/glsl/builtin_types.cpp \ + $(VBOX_MESA)/src/compiler/glsl/builtin_variables.cpp \ + $(VBOX_MESA)/src/compiler/glsl/generate_ir.cpp \ + $(VBOX_MESA)/src/compiler/glsl/glsl_parser_extras.cpp \ + $(VBOX_MESA)/src/compiler/glsl/glsl_symbol_table.cpp \ + $(VBOX_MESA)/src/compiler/glsl/glsl_to_nir.cpp \ + $(VBOX_MESA)/src/compiler/glsl/hir_field_selection.cpp \ + $(VBOX_MESA)/src/compiler/glsl/ir_array_refcount.cpp \ + $(VBOX_MESA)/src/compiler/glsl/ir_basic_block.cpp \ + $(VBOX_MESA)/src/compiler/glsl/ir_builder.cpp \ + $(VBOX_MESA)/src/compiler/glsl/ir_clone.cpp \ + $(VBOX_MESA)/src/compiler/glsl/ir_constant_expression.cpp \ + $(VBOX_MESA)/src/compiler/glsl/ir.cpp \ + $(VBOX_MESA)/src/compiler/glsl/ir_equals.cpp \ + $(VBOX_MESA)/src/compiler/glsl/ir_expression_flattening.cpp \ + $(VBOX_MESA)/src/compiler/glsl/ir_function_can_inline.cpp \ + $(VBOX_MESA)/src/compiler/glsl/ir_function_detect_recursion.cpp \ + $(VBOX_MESA)/src/compiler/glsl/ir_function.cpp \ + $(VBOX_MESA)/src/compiler/glsl/ir_hierarchical_visitor.cpp \ + $(VBOX_MESA)/src/compiler/glsl/ir_hv_accept.cpp \ + $(VBOX_MESA)/src/compiler/glsl/ir_print_visitor.cpp \ + $(VBOX_MESA)/src/compiler/glsl/ir_reader.cpp \ + $(VBOX_MESA)/src/compiler/glsl/ir_rvalue_visitor.cpp \ + $(VBOX_MESA)/src/compiler/glsl/ir_set_program_inouts.cpp \ + $(VBOX_MESA)/src/compiler/glsl/ir_validate.cpp \ + $(VBOX_MESA)/src/compiler/glsl/ir_variable_refcount.cpp \ + $(VBOX_MESA)/src/compiler/glsl/linker.cpp \ + $(VBOX_MESA)/src/compiler/glsl/link_atomics.cpp \ + $(VBOX_MESA)/src/compiler/glsl/link_functions.cpp \ + $(VBOX_MESA)/src/compiler/glsl/link_interface_blocks.cpp \ + $(VBOX_MESA)/src/compiler/glsl/link_uniforms.cpp \ + $(VBOX_MESA)/src/compiler/glsl/link_uniform_initializers.cpp \ + $(VBOX_MESA)/src/compiler/glsl/link_uniform_block_active_visitor.cpp \ + $(VBOX_MESA)/src/compiler/glsl/link_uniform_blocks.cpp \ + $(VBOX_MESA)/src/compiler/glsl/link_varyings.cpp \ + $(VBOX_MESA)/src/compiler/glsl/loop_analysis.cpp \ + $(VBOX_MESA)/src/compiler/glsl/loop_unroll.cpp \ + $(VBOX_MESA)/src/compiler/glsl/lower_blend_equation_advanced.cpp \ + $(VBOX_MESA)/src/compiler/glsl/lower_buffer_access.cpp \ + $(VBOX_MESA)/src/compiler/glsl/lower_const_arrays_to_uniforms.cpp \ + $(VBOX_MESA)/src/compiler/glsl/lower_cs_derived.cpp \ + $(VBOX_MESA)/src/compiler/glsl/lower_discard.cpp \ + $(VBOX_MESA)/src/compiler/glsl/lower_discard_flow.cpp \ + $(VBOX_MESA)/src/compiler/glsl/lower_distance.cpp \ + $(VBOX_MESA)/src/compiler/glsl/lower_if_to_cond_assign.cpp \ + $(VBOX_MESA)/src/compiler/glsl/lower_instructions.cpp \ + $(VBOX_MESA)/src/compiler/glsl/lower_int64.cpp \ + $(VBOX_MESA)/src/compiler/glsl/lower_jumps.cpp \ + $(VBOX_MESA)/src/compiler/glsl/lower_mat_op_to_vec.cpp \ + $(VBOX_MESA)/src/compiler/glsl/lower_noise.cpp \ + $(VBOX_MESA)/src/compiler/glsl/lower_offset_array.cpp \ + $(VBOX_MESA)/src/compiler/glsl/lower_packed_varyings.cpp \ + $(VBOX_MESA)/src/compiler/glsl/lower_named_interface_blocks.cpp \ + $(VBOX_MESA)/src/compiler/glsl/lower_packing_builtins.cpp \ + $(VBOX_MESA)/src/compiler/glsl/lower_subroutine.cpp \ + $(VBOX_MESA)/src/compiler/glsl/lower_tess_level.cpp \ + $(VBOX_MESA)/src/compiler/glsl/lower_texture_projection.cpp \ + $(VBOX_MESA)/src/compiler/glsl/lower_variable_index_to_cond_assign.cpp \ + $(VBOX_MESA)/src/compiler/glsl/lower_vec_index_to_cond_assign.cpp \ + $(VBOX_MESA)/src/compiler/glsl/lower_vec_index_to_swizzle.cpp \ + $(VBOX_MESA)/src/compiler/glsl/lower_vector.cpp \ + $(VBOX_MESA)/src/compiler/glsl/lower_vector_derefs.cpp \ + $(VBOX_MESA)/src/compiler/glsl/lower_vector_insert.cpp \ + $(VBOX_MESA)/src/compiler/glsl/lower_vertex_id.cpp \ + $(VBOX_MESA)/src/compiler/glsl/lower_output_reads.cpp \ + $(VBOX_MESA)/src/compiler/glsl/lower_shared_reference.cpp \ + $(VBOX_MESA)/src/compiler/glsl/lower_ubo_reference.cpp \ + $(VBOX_MESA)/src/compiler/glsl/opt_algebraic.cpp \ + $(VBOX_MESA)/src/compiler/glsl/opt_array_splitting.cpp \ + $(VBOX_MESA)/src/compiler/glsl/opt_conditional_discard.cpp \ + $(VBOX_MESA)/src/compiler/glsl/opt_constant_folding.cpp \ + $(VBOX_MESA)/src/compiler/glsl/opt_constant_propagation.cpp \ + $(VBOX_MESA)/src/compiler/glsl/opt_constant_variable.cpp \ + $(VBOX_MESA)/src/compiler/glsl/opt_copy_propagation.cpp \ + $(VBOX_MESA)/src/compiler/glsl/opt_copy_propagation_elements.cpp \ + $(VBOX_MESA)/src/compiler/glsl/opt_dead_builtin_variables.cpp \ + $(VBOX_MESA)/src/compiler/glsl/opt_dead_builtin_varyings.cpp \ + $(VBOX_MESA)/src/compiler/glsl/opt_dead_code.cpp \ + $(VBOX_MESA)/src/compiler/glsl/opt_dead_code_local.cpp \ + $(VBOX_MESA)/src/compiler/glsl/opt_dead_functions.cpp \ + $(VBOX_MESA)/src/compiler/glsl/opt_flatten_nested_if_blocks.cpp \ + $(VBOX_MESA)/src/compiler/glsl/opt_flip_matrices.cpp \ + $(VBOX_MESA)/src/compiler/glsl/opt_function_inlining.cpp \ + $(VBOX_MESA)/src/compiler/glsl/opt_if_simplification.cpp \ + $(VBOX_MESA)/src/compiler/glsl/opt_minmax.cpp \ + $(VBOX_MESA)/src/compiler/glsl/opt_noop_swizzle.cpp \ + $(VBOX_MESA)/src/compiler/glsl/opt_rebalance_tree.cpp \ + $(VBOX_MESA)/src/compiler/glsl/opt_redundant_jumps.cpp \ + $(VBOX_MESA)/src/compiler/glsl/opt_structure_splitting.cpp \ + $(VBOX_MESA)/src/compiler/glsl/opt_swizzle_swizzle.cpp \ + $(VBOX_MESA)/src/compiler/glsl/opt_tree_grafting.cpp \ + $(VBOX_MESA)/src/compiler/glsl/opt_vectorize.cpp \ + $(VBOX_MESA)/src/compiler/glsl/propagate_invariance.cpp \ + $(VBOX_MESA)/src/compiler/glsl/s_expression.cpp \ + $(VBOX_MESA)/src/compiler/glsl/string_to_uint_map.cpp \ + $(VBOX_MESA)/src/compiler/glsl/shader_cache.cpp \ + $(VBOX_MESA)/src/compiler/glsl/ir_builder_print_visitor.cpp \ + $(VBOX_MESA)/src/compiler/glsl/glsl_lexer.cpp \ + $(VBOX_MESA)/src/compiler/glsl/glsl_parser.cpp \ + $(VBOX_MESA)/src/compiler/glsl/glcpp/pp.c \ + $(VBOX_MESA)/src/compiler/glsl/glcpp/glcpp-lex.c \ + $(VBOX_MESA)/src/compiler/glsl/glcpp/glcpp-parse.c \ + $(VBOX_MESA)/src/compiler/nir/nir_constant_expressions.c \ + $(VBOX_MESA)/src/compiler/nir/nir_opcodes.c \ + $(VBOX_MESA)/src/compiler/nir/nir_opt_algebraic.c \ + $(VBOX_MESA)/src/compiler/nir/nir.c \ + $(VBOX_MESA)/src/compiler/nir/nir_clone.c \ + $(VBOX_MESA)/src/compiler/nir/nir_control_flow.c \ + $(VBOX_MESA)/src/compiler/nir/nir_dominance.c \ + $(VBOX_MESA)/src/compiler/nir/nir_from_ssa.c \ + $(VBOX_MESA)/src/compiler/nir/nir_gather_info.c \ + $(VBOX_MESA)/src/compiler/nir/nir_gs_count_vertices.c \ + $(VBOX_MESA)/src/compiler/nir/nir_inline_functions.c \ + $(VBOX_MESA)/src/compiler/nir/nir_instr_set.c \ + $(VBOX_MESA)/src/compiler/nir/nir_intrinsics.c \ + $(VBOX_MESA)/src/compiler/nir/nir_linking_helpers.c \ + $(VBOX_MESA)/src/compiler/nir/nir_liveness.c \ + $(VBOX_MESA)/src/compiler/nir/nir_loop_analyze.c \ + $(VBOX_MESA)/src/compiler/nir/nir_lower_64bit_packing.c \ + $(VBOX_MESA)/src/compiler/nir/nir_lower_alpha_test.c \ + $(VBOX_MESA)/src/compiler/nir/nir_lower_alu_to_scalar.c \ + $(VBOX_MESA)/src/compiler/nir/nir_lower_atomics.c \ + $(VBOX_MESA)/src/compiler/nir/nir_lower_atomics_to_ssbo.c \ + $(VBOX_MESA)/src/compiler/nir/nir_lower_bitmap.c \ + $(VBOX_MESA)/src/compiler/nir/nir_lower_clamp_color_outputs.c \ + $(VBOX_MESA)/src/compiler/nir/nir_lower_clip.c \ + $(VBOX_MESA)/src/compiler/nir/nir_lower_clip_cull_distance_arrays.c \ + $(VBOX_MESA)/src/compiler/nir/nir_lower_constant_initializers.c \ + $(VBOX_MESA)/src/compiler/nir/nir_lower_double_ops.c \ + $(VBOX_MESA)/src/compiler/nir/nir_lower_drawpixels.c \ + $(VBOX_MESA)/src/compiler/nir/nir_lower_global_vars_to_local.c \ + $(VBOX_MESA)/src/compiler/nir/nir_lower_gs_intrinsics.c \ + $(VBOX_MESA)/src/compiler/nir/nir_lower_load_const_to_scalar.c \ + $(VBOX_MESA)/src/compiler/nir/nir_lower_locals_to_regs.c \ + $(VBOX_MESA)/src/compiler/nir/nir_lower_idiv.c \ + $(VBOX_MESA)/src/compiler/nir/nir_lower_indirect_derefs.c \ + $(VBOX_MESA)/src/compiler/nir/nir_lower_int64.c \ + $(VBOX_MESA)/src/compiler/nir/nir_lower_io.c \ + $(VBOX_MESA)/src/compiler/nir/nir_lower_io_to_temporaries.c \ + $(VBOX_MESA)/src/compiler/nir/nir_lower_io_to_scalar.c \ + $(VBOX_MESA)/src/compiler/nir/nir_lower_io_types.c \ + $(VBOX_MESA)/src/compiler/nir/nir_lower_passthrough_edgeflags.c \ + $(VBOX_MESA)/src/compiler/nir/nir_lower_patch_vertices.c \ + $(VBOX_MESA)/src/compiler/nir/nir_lower_phis_to_scalar.c \ + $(VBOX_MESA)/src/compiler/nir/nir_lower_read_invocation_to_scalar.c \ + $(VBOX_MESA)/src/compiler/nir/nir_lower_regs_to_ssa.c \ + $(VBOX_MESA)/src/compiler/nir/nir_lower_returns.c \ + $(VBOX_MESA)/src/compiler/nir/nir_lower_samplers.c \ + $(VBOX_MESA)/src/compiler/nir/nir_lower_samplers_as_deref.c \ + $(VBOX_MESA)/src/compiler/nir/nir_lower_system_values.c \ + $(VBOX_MESA)/src/compiler/nir/nir_lower_tex.c \ + $(VBOX_MESA)/src/compiler/nir/nir_lower_to_source_mods.c \ + $(VBOX_MESA)/src/compiler/nir/nir_lower_two_sided_color.c \ + $(VBOX_MESA)/src/compiler/nir/nir_lower_uniforms_to_ubo.c \ + $(VBOX_MESA)/src/compiler/nir/nir_lower_vars_to_ssa.c \ + $(VBOX_MESA)/src/compiler/nir/nir_lower_var_copies.c \ + $(VBOX_MESA)/src/compiler/nir/nir_lower_vec_to_movs.c \ + $(VBOX_MESA)/src/compiler/nir/nir_lower_wpos_center.c \ + $(VBOX_MESA)/src/compiler/nir/nir_lower_wpos_ytransform.c \ + $(VBOX_MESA)/src/compiler/nir/nir_metadata.c \ + $(VBOX_MESA)/src/compiler/nir/nir_move_vec_src_uses_to_dest.c \ + $(VBOX_MESA)/src/compiler/nir/nir_normalize_cubemap_coords.c \ + $(VBOX_MESA)/src/compiler/nir/nir_opt_conditional_discard.c \ + $(VBOX_MESA)/src/compiler/nir/nir_opt_constant_folding.c \ + $(VBOX_MESA)/src/compiler/nir/nir_opt_copy_prop_vars.c \ + $(VBOX_MESA)/src/compiler/nir/nir_opt_copy_propagate.c \ + $(VBOX_MESA)/src/compiler/nir/nir_opt_cse.c \ + $(VBOX_MESA)/src/compiler/nir/nir_opt_dce.c \ + $(VBOX_MESA)/src/compiler/nir/nir_opt_dead_cf.c \ + $(VBOX_MESA)/src/compiler/nir/nir_opt_gcm.c \ + $(VBOX_MESA)/src/compiler/nir/nir_opt_global_to_local.c \ + $(VBOX_MESA)/src/compiler/nir/nir_opt_if.c \ + $(VBOX_MESA)/src/compiler/nir/nir_opt_intrinsics.c \ + $(VBOX_MESA)/src/compiler/nir/nir_opt_loop_unroll.c \ + $(VBOX_MESA)/src/compiler/nir/nir_opt_move_comparisons.c \ + $(VBOX_MESA)/src/compiler/nir/nir_opt_peephole_select.c \ + $(VBOX_MESA)/src/compiler/nir/nir_opt_remove_phis.c \ + $(VBOX_MESA)/src/compiler/nir/nir_opt_trivial_continues.c \ + $(VBOX_MESA)/src/compiler/nir/nir_opt_undef.c \ + $(VBOX_MESA)/src/compiler/nir/nir_phi_builder.c \ + $(VBOX_MESA)/src/compiler/nir/nir_print.c \ + $(VBOX_MESA)/src/compiler/nir/nir_propagate_invariant.c \ + $(VBOX_MESA)/src/compiler/nir/nir_remove_dead_variables.c \ + $(VBOX_MESA)/src/compiler/nir/nir_repair_ssa.c \ + $(VBOX_MESA)/src/compiler/nir/nir_search.c \ + $(VBOX_MESA)/src/compiler/nir/nir_split_var_copies.c \ + $(VBOX_MESA)/src/compiler/nir/nir_sweep.c \ + $(VBOX_MESA)/src/compiler/nir/nir_to_lcssa.c \ + $(VBOX_MESA)/src/compiler/nir/nir_validate.c \ + $(VBOX_MESA)/src/compiler/nir/nir_worklist.c +VBoxMesaLib_SOURCES += \ + $(VBOX_MESA)/src/mapi/glapi/glapi_dispatch.c \ + $(VBOX_MESA)/src/mapi/glapi/glapi_entrypoint.c \ + $(VBOX_MESA)/src/mapi/glapi/glapi_getproc.c \ + $(VBOX_MESA)/src/mapi/glapi/glapi_nop.c \ + $(VBOX_MESA)/src/mapi/glapi/glapi.c \ + $(VBOX_MESA)/src/mapi/u_current.c \ + $(VBOX_MESA)/src/mapi/u_execmem.c +# Not used +# $(VBOX_MESA)/src/compiler/glsl/standalone_scaffolding.cpp +# $(VBOX_MESA)/src/compiler/glsl/standalone.cpp + +# Disable optimization for some files, because it takes over 2 minutes to compile them with MSC otherwise. +$(VBOX_MESA)/src/mesa/main/format_unpack.c_CFLAGS.release += -Od +$(VBOX_MESA)/src/mesa/main/format_utils.c_CFLAGS.release += -Od +$(VBOX_MESA)/src/mesa/main/mipmap.c_CFLAGS.release += -Od + +# 32 bit lib for 64 bit build +VBoxMesaLib-x86_EXTENDS = VBoxMesaLib +VBoxMesaLib-x86_BLD_TRG_ARCH = x86 + + +# +# VBoxMesaWglLib +# +VBoxMesaWglLib_TEMPLATE = VBoxMesa3DGuestR3Lib +VBoxMesaWglLib_SOURCES = \ + $(VBOX_MESA)/src/gallium/state_trackers/wgl/stw_context.c \ + $(VBOX_MESA)/src/gallium/state_trackers/wgl/stw_device.c \ + $(VBOX_MESA)/src/gallium/state_trackers/wgl/stw_ext_context.c \ + $(VBOX_MESA)/src/gallium/state_trackers/wgl/stw_ext_extensionsstring.c \ + $(VBOX_MESA)/src/gallium/state_trackers/wgl/stw_ext_pbuffer.c \ + $(VBOX_MESA)/src/gallium/state_trackers/wgl/stw_ext_pixelformat.c \ + $(VBOX_MESA)/src/gallium/state_trackers/wgl/stw_ext_rendertexture.c \ + $(VBOX_MESA)/src/gallium/state_trackers/wgl/stw_ext_swapinterval.c \ + $(VBOX_MESA)/src/gallium/state_trackers/wgl/stw_framebuffer.c \ + $(VBOX_MESA)/src/gallium/state_trackers/wgl/stw_getprocaddress.c \ + $(VBOX_MESA)/src/gallium/state_trackers/wgl/stw_nopfuncs.c \ + $(VBOX_MESA)/src/gallium/state_trackers/wgl/stw_pixelformat.c \ + $(VBOX_MESA)/src/gallium/state_trackers/wgl/stw_st.c \ + $(VBOX_MESA)/src/gallium/state_trackers/wgl/stw_tls.c \ + $(VBOX_MESA)/src/gallium/state_trackers/wgl/stw_wgl.c + +# 32 bit lib for 64 bit build +VBoxMesaWglLib-x86_EXTENDS = VBoxMesaWglLib +VBoxMesaWglLib-x86_BLD_TRG_ARCH = x86 + + +# +# VBoxMesaGalliumAuxLib +# +VBoxMesaGalliumAuxLib_TEMPLATE = VBoxMesa3DGuestR3Lib +VBoxMesaGalliumAuxLib_SOURCES = \ + $(VBOX_MESA)/src/gallium/auxiliary/cso_cache/cso_cache.c \ + $(VBOX_MESA)/src/gallium/auxiliary/cso_cache/cso_context.c \ + $(VBOX_MESA)/src/gallium/auxiliary/cso_cache/cso_hash.c \ + $(VBOX_MESA)/src/gallium/auxiliary/draw/draw_context.c \ + $(VBOX_MESA)/src/gallium/auxiliary/draw/draw_fs.c \ + $(VBOX_MESA)/src/gallium/auxiliary/draw/draw_gs.c \ + $(VBOX_MESA)/src/gallium/auxiliary/draw/draw_pipe_aaline.c \ + $(VBOX_MESA)/src/gallium/auxiliary/draw/draw_pipe_aapoint.c \ + $(VBOX_MESA)/src/gallium/auxiliary/draw/draw_pipe.c \ + $(VBOX_MESA)/src/gallium/auxiliary/draw/draw_pipe_clip.c \ + $(VBOX_MESA)/src/gallium/auxiliary/draw/draw_pipe_cull.c \ + $(VBOX_MESA)/src/gallium/auxiliary/draw/draw_pipe_flatshade.c \ + $(VBOX_MESA)/src/gallium/auxiliary/draw/draw_pipe_offset.c \ + $(VBOX_MESA)/src/gallium/auxiliary/draw/draw_pipe_pstipple.c \ + $(VBOX_MESA)/src/gallium/auxiliary/draw/draw_pipe_stipple.c \ + $(VBOX_MESA)/src/gallium/auxiliary/draw/draw_pipe_twoside.c \ + $(VBOX_MESA)/src/gallium/auxiliary/draw/draw_pipe_unfilled.c \ + $(VBOX_MESA)/src/gallium/auxiliary/draw/draw_pipe_util.c \ + $(VBOX_MESA)/src/gallium/auxiliary/draw/draw_pipe_validate.c \ + $(VBOX_MESA)/src/gallium/auxiliary/draw/draw_pipe_vbuf.c \ + $(VBOX_MESA)/src/gallium/auxiliary/draw/draw_pipe_wide_line.c \ + $(VBOX_MESA)/src/gallium/auxiliary/draw/draw_pipe_wide_point.c \ + $(VBOX_MESA)/src/gallium/auxiliary/draw/draw_prim_assembler.c \ + $(VBOX_MESA)/src/gallium/auxiliary/draw/draw_pt.c \ + $(VBOX_MESA)/src/gallium/auxiliary/draw/draw_pt_emit.c \ + $(VBOX_MESA)/src/gallium/auxiliary/draw/draw_pt_fetch.c \ + $(VBOX_MESA)/src/gallium/auxiliary/draw/draw_pt_fetch_emit.c \ + $(VBOX_MESA)/src/gallium/auxiliary/draw/draw_pt_fetch_shade_emit.c \ + $(VBOX_MESA)/src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline.c \ + $(VBOX_MESA)/src/gallium/auxiliary/draw/draw_pt_post_vs.c \ + $(VBOX_MESA)/src/gallium/auxiliary/draw/draw_pt_so_emit.c \ + $(VBOX_MESA)/src/gallium/auxiliary/draw/draw_pt_util.c \ + $(VBOX_MESA)/src/gallium/auxiliary/draw/draw_pt_vsplit.c \ + $(VBOX_MESA)/src/gallium/auxiliary/draw/draw_vertex.c \ + $(VBOX_MESA)/src/gallium/auxiliary/draw/draw_vs.c \ + $(VBOX_MESA)/src/gallium/auxiliary/draw/draw_vs_exec.c \ + $(VBOX_MESA)/src/gallium/auxiliary/draw/draw_vs_variant.c \ + $(VBOX_MESA)/src/gallium/auxiliary/hud/font.c \ + $(VBOX_MESA)/src/gallium/auxiliary/hud/hud_context.c \ + $(VBOX_MESA)/src/gallium/auxiliary/hud/hud_cpu.c \ + $(VBOX_MESA)/src/gallium/auxiliary/hud/hud_nic.c \ + $(VBOX_MESA)/src/gallium/auxiliary/hud/hud_cpufreq.c \ + $(VBOX_MESA)/src/gallium/auxiliary/hud/hud_diskstat.c \ + $(VBOX_MESA)/src/gallium/auxiliary/hud/hud_sensors_temp.c \ + $(VBOX_MESA)/src/gallium/auxiliary/hud/hud_driver_query.c \ + $(VBOX_MESA)/src/gallium/auxiliary/hud/hud_fps.c \ + $(VBOX_MESA)/src/gallium/auxiliary/indices/u_primconvert.c \ + $(VBOX_MESA)/src/gallium/auxiliary/os/os_misc.c \ + $(VBOX_MESA)/src/gallium/auxiliary/os/os_process.c \ + $(VBOX_MESA)/src/gallium/auxiliary/os/os_time.c \ + $(VBOX_MESA)/src/gallium/auxiliary/pipebuffer/pb_buffer_fenced.c \ + $(VBOX_MESA)/src/gallium/auxiliary/pipebuffer/pb_buffer_malloc.c \ + $(VBOX_MESA)/src/gallium/auxiliary/pipebuffer/pb_bufmgr_alt.c \ + $(VBOX_MESA)/src/gallium/auxiliary/pipebuffer/pb_bufmgr_cache.c \ + $(VBOX_MESA)/src/gallium/auxiliary/pipebuffer/pb_bufmgr_debug.c \ + $(VBOX_MESA)/src/gallium/auxiliary/pipebuffer/pb_bufmgr_mm.c \ + $(VBOX_MESA)/src/gallium/auxiliary/pipebuffer/pb_bufmgr_ondemand.c \ + $(VBOX_MESA)/src/gallium/auxiliary/pipebuffer/pb_bufmgr_pool.c \ + $(VBOX_MESA)/src/gallium/auxiliary/pipebuffer/pb_bufmgr_slab.c \ + $(VBOX_MESA)/src/gallium/auxiliary/pipebuffer/pb_cache.c \ + $(VBOX_MESA)/src/gallium/auxiliary/pipebuffer/pb_slab.c \ + $(VBOX_MESA)/src/gallium/auxiliary/pipebuffer/pb_validate.c \ + $(VBOX_MESA)/src/gallium/auxiliary/postprocess/pp_celshade.c \ + $(VBOX_MESA)/src/gallium/auxiliary/postprocess/pp_colors.c \ + $(VBOX_MESA)/src/gallium/auxiliary/postprocess/pp_init.c \ + $(VBOX_MESA)/src/gallium/auxiliary/postprocess/pp_mlaa.c \ + $(VBOX_MESA)/src/gallium/auxiliary/postprocess/pp_program.c \ + $(VBOX_MESA)/src/gallium/auxiliary/postprocess/pp_run.c \ + $(VBOX_MESA)/src/gallium/auxiliary/rbug/rbug_connection.c \ + $(VBOX_MESA)/src/gallium/auxiliary/rbug/rbug_context.c \ + $(VBOX_MESA)/src/gallium/auxiliary/rbug/rbug_core.c \ + $(VBOX_MESA)/src/gallium/auxiliary/rbug/rbug_demarshal.c \ + $(VBOX_MESA)/src/gallium/auxiliary/rbug/rbug_shader.c \ + $(VBOX_MESA)/src/gallium/auxiliary/rbug/rbug_texture.c \ + $(VBOX_MESA)/src/gallium/auxiliary/rtasm/rtasm_cpu.c \ + $(VBOX_MESA)/src/gallium/auxiliary/rtasm/rtasm_execmem.c \ + $(VBOX_MESA)/src/gallium/auxiliary/rtasm/rtasm_x86sse.c \ + $(VBOX_MESA)/src/gallium/auxiliary/tgsi/tgsi_aa_point.c \ + $(VBOX_MESA)/src/gallium/auxiliary/tgsi/tgsi_build.c \ + $(VBOX_MESA)/src/gallium/auxiliary/tgsi/tgsi_dump.c \ + $(VBOX_MESA)/src/gallium/auxiliary/tgsi/tgsi_exec.c \ + $(VBOX_MESA)/src/gallium/auxiliary/tgsi/tgsi_emulate.c \ + $(VBOX_MESA)/src/gallium/auxiliary/tgsi/tgsi_from_mesa.c \ + $(VBOX_MESA)/src/gallium/auxiliary/tgsi/tgsi_info.c \ + $(VBOX_MESA)/src/gallium/auxiliary/tgsi/tgsi_iterate.c \ + $(VBOX_MESA)/src/gallium/auxiliary/tgsi/tgsi_lowering.c \ + $(VBOX_MESA)/src/gallium/auxiliary/tgsi/tgsi_parse.c \ + $(VBOX_MESA)/src/gallium/auxiliary/tgsi/tgsi_point_sprite.c \ + $(VBOX_MESA)/src/gallium/auxiliary/tgsi/tgsi_sanity.c \ + $(VBOX_MESA)/src/gallium/auxiliary/tgsi/tgsi_scan.c \ + $(VBOX_MESA)/src/gallium/auxiliary/tgsi/tgsi_strings.c \ + $(VBOX_MESA)/src/gallium/auxiliary/tgsi/tgsi_text.c \ + $(VBOX_MESA)/src/gallium/auxiliary/tgsi/tgsi_transform.c \ + $(VBOX_MESA)/src/gallium/auxiliary/tgsi/tgsi_two_side.c \ + $(VBOX_MESA)/src/gallium/auxiliary/tgsi/tgsi_ureg.c \ + $(VBOX_MESA)/src/gallium/auxiliary/tgsi/tgsi_util.c \ + $(VBOX_MESA)/src/gallium/auxiliary/translate/translate.c \ + $(VBOX_MESA)/src/gallium/auxiliary/translate/translate_cache.c \ + $(VBOX_MESA)/src/gallium/auxiliary/translate/translate_generic.c \ + $(VBOX_MESA)/src/gallium/auxiliary/translate/translate_sse.c \ + $(VBOX_MESA)/src/gallium/auxiliary/util/u_bitmask.c \ + $(VBOX_MESA)/src/gallium/auxiliary/util/u_blit.c \ + $(VBOX_MESA)/src/gallium/auxiliary/util/u_blitter.c \ + $(VBOX_MESA)/src/gallium/auxiliary/util/u_cache.c \ + $(VBOX_MESA)/src/gallium/auxiliary/util/u_cpu_detect.c \ + $(VBOX_MESA)/src/gallium/auxiliary/util/u_debug.c \ + $(VBOX_MESA)/src/gallium/auxiliary/util/u_debug_describe.c \ + $(VBOX_MESA)/src/gallium/auxiliary/util/u_debug_flush.c \ + $(VBOX_MESA)/src/gallium/auxiliary/util/u_debug_image.c \ + $(VBOX_MESA)/src/gallium/auxiliary/util/u_debug_memory.c \ + $(VBOX_MESA)/src/gallium/auxiliary/util/u_debug_refcnt.c \ + $(VBOX_MESA)/src/gallium/auxiliary/util/u_debug_stack.c \ + $(VBOX_MESA)/src/gallium/auxiliary/util/u_debug_symbol.c \ + $(VBOX_MESA)/src/gallium/auxiliary/util/u_dl.c \ + $(VBOX_MESA)/src/gallium/auxiliary/util/u_draw.c \ + $(VBOX_MESA)/src/gallium/auxiliary/util/u_draw_quad.c \ + $(VBOX_MESA)/src/gallium/auxiliary/util/u_dump_defines.c \ + $(VBOX_MESA)/src/gallium/auxiliary/util/u_dump_state.c \ + $(VBOX_MESA)/src/gallium/auxiliary/util/u_format.c \ + $(VBOX_MESA)/src/gallium/auxiliary/util/u_format_etc.c \ + $(VBOX_MESA)/src/gallium/auxiliary/util/u_format_latc.c \ + $(VBOX_MESA)/src/gallium/auxiliary/util/u_format_other.c \ + $(VBOX_MESA)/src/gallium/auxiliary/util/u_format_rgtc.c \ + $(VBOX_MESA)/src/gallium/auxiliary/util/u_format_s3tc.c \ + $(VBOX_MESA)/src/gallium/auxiliary/util/u_format_tests.c \ + $(VBOX_MESA)/src/gallium/auxiliary/util/u_format_yuv.c \ + $(VBOX_MESA)/src/gallium/auxiliary/util/u_format_zs.c \ + $(VBOX_MESA)/src/gallium/auxiliary/util/u_framebuffer.c \ + $(VBOX_MESA)/src/gallium/auxiliary/util/u_gen_mipmap.c \ + $(VBOX_MESA)/src/gallium/auxiliary/util/u_handle_table.c \ + $(VBOX_MESA)/src/gallium/auxiliary/util/u_hash_table.c \ + $(VBOX_MESA)/src/gallium/auxiliary/util/u_helpers.c \ + $(VBOX_MESA)/src/gallium/auxiliary/util/u_index_modify.c \ + $(VBOX_MESA)/src/gallium/auxiliary/util/u_linear.c \ + $(VBOX_MESA)/src/gallium/auxiliary/util/u_math.c \ + $(VBOX_MESA)/src/gallium/auxiliary/util/u_mm.c \ + $(VBOX_MESA)/src/gallium/auxiliary/util/u_network.c \ + $(VBOX_MESA)/src/gallium/auxiliary/util/u_prim_restart.c \ + $(VBOX_MESA)/src/gallium/auxiliary/util/u_pstipple.c \ + $(VBOX_MESA)/src/gallium/auxiliary/util/u_resource.c \ + $(VBOX_MESA)/src/gallium/auxiliary/util/u_ringbuffer.c \ + $(VBOX_MESA)/src/gallium/auxiliary/util/u_sampler.c \ + $(VBOX_MESA)/src/gallium/auxiliary/util/u_simple_shaders.c \ + $(VBOX_MESA)/src/gallium/auxiliary/util/u_suballoc.c \ + $(VBOX_MESA)/src/gallium/auxiliary/util/u_surface.c \ + $(VBOX_MESA)/src/gallium/auxiliary/util/u_surfaces.c \ + $(VBOX_MESA)/src/gallium/auxiliary/util/u_tests.c \ + $(VBOX_MESA)/src/gallium/auxiliary/util/u_texture.c \ + $(VBOX_MESA)/src/gallium/auxiliary/util/u_tile.c \ + $(VBOX_MESA)/src/gallium/auxiliary/util/u_transfer.c \ + $(VBOX_MESA)/src/gallium/auxiliary/util/u_upload_mgr.c \ + $(VBOX_MESA)/src/gallium/auxiliary/util/u_vbuf.c +# Auto-generated +VBoxMesaGalliumAuxLib_SOURCES += \ + $(VBOX_MESA)/src/gallium/auxiliary/indices/u_indices_gen.c \ + $(VBOX_MESA)/src/gallium/auxiliary/indices/u_unfilled_gen.c \ + $(VBOX_MESA)/src/gallium/auxiliary/util/u_format_table.c + +# 32 bit lib for 64 bit build +VBoxMesaGalliumAuxLib-x86_EXTENDS = VBoxMesaGalliumAuxLib +VBoxMesaGalliumAuxLib-x86_BLD_TRG_ARCH = x86 + + +# +# VBoxMesaNineLib +# +VBoxMesaNineLib_TEMPLATE = VBoxMesa3DGuestR3Lib +VBoxMesaNineLib_INCS = \ + $(VBOX_MESA)/include/D3D9 +VBoxMesaNineLib_DEFS.win = COBJMACROS INC_OLE2 +# -wd4028: formal parameter 4 different from declaration +# 'nine_context_set_vertex_shader_constant_f' parameter is declared 'const unsigned pConstantData_size' +# but autogenerated code produces 'unsigned pConstantData_size'. +VBoxMesaNineLib_CFLAGS.win = -wd4028 +VBoxMesaNineLib_SOURCES = \ + $(VBOX_MESA)/src/gallium/state_trackers/nine/adapter9.c \ + $(VBOX_MESA)/src/gallium/state_trackers/nine/authenticatedchannel9.c \ + $(VBOX_MESA)/src/gallium/state_trackers/nine/basetexture9.c \ + $(VBOX_MESA)/src/gallium/state_trackers/nine/buffer9.c \ + $(VBOX_MESA)/src/gallium/state_trackers/nine/cryptosession9.c \ + $(VBOX_MESA)/src/gallium/state_trackers/nine/cubetexture9.c \ + $(VBOX_MESA)/src/gallium/state_trackers/nine/device9.c \ + $(VBOX_MESA)/src/gallium/state_trackers/nine/device9ex.c \ + $(VBOX_MESA)/src/gallium/state_trackers/nine/device9video.c \ + $(VBOX_MESA)/src/gallium/state_trackers/nine/guid.c \ + $(VBOX_MESA)/src/gallium/state_trackers/nine/indexbuffer9.c \ + $(VBOX_MESA)/src/gallium/state_trackers/nine/iunknown.c \ + $(VBOX_MESA)/src/gallium/state_trackers/nine/nine_buffer_upload.c \ + $(VBOX_MESA)/src/gallium/state_trackers/nine/nine_debug.c \ + $(VBOX_MESA)/src/gallium/state_trackers/nine/nine_dump.c \ + $(VBOX_MESA)/src/gallium/state_trackers/nine/nineexoverlayextension.c \ + $(VBOX_MESA)/src/gallium/state_trackers/nine/nine_ff.c \ + $(VBOX_MESA)/src/gallium/state_trackers/nine/nine_helpers.c \ + $(VBOX_MESA)/src/gallium/state_trackers/nine/nine_lock.c \ + $(VBOX_MESA)/src/gallium/state_trackers/nine/nine_pipe.c \ + $(VBOX_MESA)/src/gallium/state_trackers/nine/nine_quirk.c \ + $(VBOX_MESA)/src/gallium/state_trackers/nine/nine_queue.c \ + $(VBOX_MESA)/src/gallium/state_trackers/nine/nine_shader.c \ + $(VBOX_MESA)/src/gallium/state_trackers/nine/nine_state.c \ + $(VBOX_MESA)/src/gallium/state_trackers/nine/pixelshader9.c \ + $(VBOX_MESA)/src/gallium/state_trackers/nine/query9.c \ + $(VBOX_MESA)/src/gallium/state_trackers/nine/resource9.c \ + $(VBOX_MESA)/src/gallium/state_trackers/nine/stateblock9.c \ + $(VBOX_MESA)/src/gallium/state_trackers/nine/surface9.c \ + $(VBOX_MESA)/src/gallium/state_trackers/nine/swapchain9.c \ + $(VBOX_MESA)/src/gallium/state_trackers/nine/swapchain9ex.c \ + $(VBOX_MESA)/src/gallium/state_trackers/nine/texture9.c \ + $(VBOX_MESA)/src/gallium/state_trackers/nine/threadpool.c \ + $(VBOX_MESA)/src/gallium/state_trackers/nine/vertexbuffer9.c \ + $(VBOX_MESA)/src/gallium/state_trackers/nine/vertexdeclaration9.c \ + $(VBOX_MESA)/src/gallium/state_trackers/nine/vertexshader9.c \ + $(VBOX_MESA)/src/gallium/state_trackers/nine/volume9.c \ + $(VBOX_MESA)/src/gallium/state_trackers/nine/volumetexture9.c + +# 32 bit lib for 64 bit build +VBoxMesaNineLib-x86_EXTENDS = VBoxMesaNineLib +VBoxMesaNineLib-x86_BLD_TRG_ARCH = x86 + + +# +# VBoxMesaSVGALib +# +VBoxMesaSVGALib_TEMPLATE = VBoxMesa3DGuestR3Lib +VBoxMesaSVGALib_INCS = \ + $(VBOX_MESA)/src/gallium/drivers/svga/include +VBoxMesaSVGALib_SOURCES = \ + $(VBOX_MESA)/src/gallium/drivers/svga/svga_cmd.c \ + $(VBOX_MESA)/src/gallium/drivers/svga/svga_cmd_vgpu10.c \ + $(VBOX_MESA)/src/gallium/drivers/svga/svga_context.c \ + $(VBOX_MESA)/src/gallium/drivers/svga/svga_draw_arrays.c \ + $(VBOX_MESA)/src/gallium/drivers/svga/svga_draw.c \ + $(VBOX_MESA)/src/gallium/drivers/svga/svga_draw_elements.c \ + $(VBOX_MESA)/src/gallium/drivers/svga/svga_format.c \ + $(VBOX_MESA)/src/gallium/drivers/svga/svga_link.c \ + $(VBOX_MESA)/src/gallium/drivers/svga/svga_msg.c \ + $(VBOX_MESA)/src/gallium/drivers/svga/svga_pipe_blend.c \ + $(VBOX_MESA)/src/gallium/drivers/svga/svga_pipe_blit.c \ + $(VBOX_MESA)/src/gallium/drivers/svga/svga_pipe_clear.c \ + $(VBOX_MESA)/src/gallium/drivers/svga/svga_pipe_constants.c \ + $(VBOX_MESA)/src/gallium/drivers/svga/svga_pipe_depthstencil.c \ + $(VBOX_MESA)/src/gallium/drivers/svga/svga_pipe_draw.c \ + $(VBOX_MESA)/src/gallium/drivers/svga/svga_pipe_flush.c \ + $(VBOX_MESA)/src/gallium/drivers/svga/svga_pipe_fs.c \ + $(VBOX_MESA)/src/gallium/drivers/svga/svga_pipe_gs.c \ + $(VBOX_MESA)/src/gallium/drivers/svga/svga_pipe_misc.c \ + $(VBOX_MESA)/src/gallium/drivers/svga/svga_pipe_query.c \ + $(VBOX_MESA)/src/gallium/drivers/svga/svga_pipe_rasterizer.c \ + $(VBOX_MESA)/src/gallium/drivers/svga/svga_pipe_sampler.c \ + $(VBOX_MESA)/src/gallium/drivers/svga/svga_pipe_streamout.c \ + $(VBOX_MESA)/src/gallium/drivers/svga/svga_pipe_vertex.c \ + $(VBOX_MESA)/src/gallium/drivers/svga/svga_pipe_vs.c \ + $(VBOX_MESA)/src/gallium/drivers/svga/svga_resource_buffer.c \ + $(VBOX_MESA)/src/gallium/drivers/svga/svga_resource_buffer_upload.c \ + $(VBOX_MESA)/src/gallium/drivers/svga/svga_resource.c \ + $(VBOX_MESA)/src/gallium/drivers/svga/svga_resource_texture.c \ + $(VBOX_MESA)/src/gallium/drivers/svga/svga_sampler_view.c \ + $(VBOX_MESA)/src/gallium/drivers/svga/svga_screen.c \ + $(VBOX_MESA)/src/gallium/drivers/svga/svga_screen_cache.c \ + $(VBOX_MESA)/src/gallium/drivers/svga/svga_shader.c \ + $(VBOX_MESA)/src/gallium/drivers/svga/svga_state.c \ + $(VBOX_MESA)/src/gallium/drivers/svga/svga_state_constants.c \ + $(VBOX_MESA)/src/gallium/drivers/svga/svga_state_framebuffer.c \ + $(VBOX_MESA)/src/gallium/drivers/svga/svga_state_fs.c \ + $(VBOX_MESA)/src/gallium/drivers/svga/svga_state_gs.c \ + $(VBOX_MESA)/src/gallium/drivers/svga/svga_state_need_swtnl.c \ + $(VBOX_MESA)/src/gallium/drivers/svga/svga_state_rss.c \ + $(VBOX_MESA)/src/gallium/drivers/svga/svga_state_sampler.c \ + $(VBOX_MESA)/src/gallium/drivers/svga/svga_state_tgsi_transform.c \ + $(VBOX_MESA)/src/gallium/drivers/svga/svga_state_tss.c \ + $(VBOX_MESA)/src/gallium/drivers/svga/svga_state_vdecl.c \ + $(VBOX_MESA)/src/gallium/drivers/svga/svga_state_vs.c \ + $(VBOX_MESA)/src/gallium/drivers/svga/svga_surface.c \ + $(VBOX_MESA)/src/gallium/drivers/svga/svga_swtnl_backend.c \ + $(VBOX_MESA)/src/gallium/drivers/svga/svga_swtnl_draw.c \ + $(VBOX_MESA)/src/gallium/drivers/svga/svga_swtnl_state.c \ + $(VBOX_MESA)/src/gallium/drivers/svga/svga_tgsi.c \ + $(VBOX_MESA)/src/gallium/drivers/svga/svga_tgsi_decl_sm30.c \ + $(VBOX_MESA)/src/gallium/drivers/svga/svga_tgsi_insn.c \ + $(VBOX_MESA)/src/gallium/drivers/svga/svga_tgsi_vgpu10.c \ + $(VBOX_MESA)/src/gallium/drivers/svga/svgadump/svga_dump.c \ + $(VBOX_MESA)/src/gallium/drivers/svga/svgadump/svga_shader_dump.c \ + $(VBOX_MESA)/src/gallium/drivers/svga/svgadump/svga_shader_op.c + +# 32 bit lib for 64 bit build +VBoxMesaSVGALib-x86_EXTENDS = VBoxMesaSVGALib +VBoxMesaSVGALib-x86_BLD_TRG_ARCH = x86 + + +# +# VBoxMesaSVGAWinsysLib +# +VBoxMesaSVGAWinsysLib_TEMPLATE = VBoxMesa3DGuestR3Lib +VBoxMesaSVGAWinsysLib_INCS += \ + $(VBOX_MESA)/src/gallium/drivers/svga/include \ + $(VBOX_MESA)/src/gallium/drivers/svga +VBoxMesaSVGAWinsysLib_SOURCES = \ + $(VBOX_MESA)/src/gallium/winsys/svga/drm/pb_buffer_simple_fenced.c \ + $(VBOX_MESA)/src/gallium/winsys/svga/drm/vmw_buffer.c \ + $(VBOX_MESA)/src/gallium/winsys/svga/drm/vmw_context.c \ + $(VBOX_MESA)/src/gallium/winsys/svga/drm/vmw_fence.c \ + $(VBOX_MESA)/src/gallium/winsys/svga/drm/vmw_screen_pools.c \ + $(VBOX_MESA)/src/gallium/winsys/svga/drm/vmw_screen_svga.c \ + $(VBOX_MESA)/src/gallium/winsys/svga/drm/vmw_surface.c \ + $(VBOX_MESA)/src/gallium/winsys/svga/drm/vmw_shader.c \ + $(VBOX_MESA)/src/gallium/winsys/svga/drm/vmw_query.c + +# These will be reimplemented for WDDM +#VBoxMesaSVGAWinsysLib_SOURCES += \ +# $(VBOX_MESA)/src/gallium/winsys/svga/drm/vmw_screen.c \ +# $(VBOX_MESA)/src/gallium/winsys/svga/drm/vmw_screen_dri.c \ +# $(VBOX_MESA)/src/gallium/winsys/svga/drm/vmw_screen_ioctl.c + +# 32 bit lib for 64 bit build +VBoxMesaSVGAWinsysLib-x86_EXTENDS = VBoxMesaSVGAWinsysLib +VBoxMesaSVGAWinsysLib-x86_BLD_TRG_ARCH = x86 + + +include $(FILE_KBUILD_SUB_FOOTER) + diff --git a/src/VBox/Additions/3D/mesa/include/assert.h b/src/VBox/Additions/3D/mesa/include/assert.h new file mode 100644 index 00000000..b5b4941e --- /dev/null +++ b/src/VBox/Additions/3D/mesa/include/assert.h @@ -0,0 +1,33 @@ +/* $Id: assert.h $ */ +/** @file + * Replaces C runtime assert with a simplified version which just hits breakpoint. + * + * Mesa code uses assert.h a lot, which is inconvenient because the C runtime + * implementation wants to open a message box and it does not work in the + * graphics driver. + */ + +/* + * Copyright (C) 2017-2020 Oracle Corporation + * + * This file is part of VirtualBox Open Source Edition (OSE), as + * available from http://www.virtualbox.org. This file is free software; + * you can redistribute it and/or modify it under the terms of the GNU + * General Public License (GPL) as published by the Free Software + * Foundation, in version 2 as it comes in the "COPYING" file of the + * VirtualBox OSE distribution. VirtualBox OSE is distributed in the + * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. + */ + +#ifndef GA_INCLUDED_3D_MESA_assert_h +#define GA_INCLUDED_3D_MESA_assert_h +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + +#include <iprt/asm.h> + +#undef assert +#define assert(_e) (void)( (!!(_e)) || (ASMBreakpoint(), 0) ) + +#endif /* !GA_INCLUDED_3D_MESA_assert_h */ diff --git a/src/VBox/Additions/3D/mesa/include/git_sha1.h b/src/VBox/Additions/3D/mesa/include/git_sha1.h new file mode 100644 index 00000000..0a4090a9 --- /dev/null +++ b/src/VBox/Additions/3D/mesa/include/git_sha1.h @@ -0,0 +1,28 @@ +/* $Id: git_sha1.h $ */ +/** @file + * Provides this include file for Mesa. + * + * Mesa code does not check MESA_GIT_SHA1 define before including the file. + */ + +/* + * Copyright (C) 2018-2020 Oracle Corporation + * + * This file is part of VirtualBox Open Source Edition (OSE), as + * available from http://www.virtualbox.org. This file is free software; + * you can redistribute it and/or modify it under the terms of the GNU + * General Public License (GPL) as published by the Free Software + * Foundation, in version 2 as it comes in the "COPYING" file of the + * VirtualBox OSE distribution. VirtualBox OSE is distributed in the + * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. + */ + +#ifndef GA_INCLUDED_3D_MESA_git_sha1_h +#define GA_INCLUDED_3D_MESA_git_sha1_h +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + +/* Nothing. */ + +#endif /* !GA_INCLUDED_3D_MESA_git_sha1_h */ diff --git a/src/VBox/Additions/3D/win/Makefile.kmk b/src/VBox/Additions/3D/win/Makefile.kmk new file mode 100644 index 00000000..f45e8283 --- /dev/null +++ b/src/VBox/Additions/3D/win/Makefile.kmk @@ -0,0 +1,29 @@ +# $Id: Makefile.kmk $ +## @file +# Sub-Makefile for the Windows guest components using Mesa3D. +# + +# +# Copyright (C) 2016-2020 Oracle Corporation +# +# This file is part of VirtualBox Open Source Edition (OSE), as +# available from http://www.virtualbox.org. This file is free software; +# you can redistribute it and/or modify it under the terms of the GNU +# General Public License (GPL) as published by the Free Software +# Foundation, in version 2 as it comes in the "COPYING" file of the +# VirtualBox OSE distribution. VirtualBox OSE is distributed in the +# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. +# + +SUB_DEPTH = ../../../../.. +include $(KBUILD_PATH)/subheader.kmk + +# Include sub-makefile. +include $(PATH_SUB_CURRENT)/VBoxWddmUmHlp/Makefile.kmk +include $(PATH_SUB_CURRENT)/VBoxICD/Makefile.kmk +include $(PATH_SUB_CURRENT)/VBoxGL/Makefile.kmk +include $(PATH_SUB_CURRENT)/VBoxNine/Makefile.kmk +include $(PATH_SUB_CURRENT)/VBoxSVGA/Makefile.kmk + +include $(FILE_KBUILD_SUB_FOOTER) + diff --git a/src/VBox/Additions/3D/win/VBoxGL/GaDrvEnvKMT.cpp b/src/VBox/Additions/3D/win/VBoxGL/GaDrvEnvKMT.cpp new file mode 100644 index 00000000..30fe0b94 --- /dev/null +++ b/src/VBox/Additions/3D/win/VBoxGL/GaDrvEnvKMT.cpp @@ -0,0 +1,1202 @@ +/* $Id: GaDrvEnvKMT.cpp $ */ +/** @file + * VirtualBox Windows Guest Mesa3D - Gallium driver interface to the WDDM miniport driver using Kernel Mode Thunks. + */ + +/* + * Copyright (C) 2016-2020 Oracle Corporation + * + * This file is part of VirtualBox Open Source Edition (OSE), as + * available from http://www.virtualbox.org. This file is free software; + * you can redistribute it and/or modify it under the terms of the GNU + * General Public License (GPL) as published by the Free Software + * Foundation, in version 2 as it comes in the "COPYING" file of the + * VirtualBox OSE distribution. VirtualBox OSE is distributed in the + * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. + */ + +#include "GaDrvEnvKMT.h" + +#include <UmHlpInternal.h> + +#include "svga3d_reg.h" + +#include <common/wddm/VBoxMPIf.h> + +#include <iprt/assertcompile.h> +#include <iprt/param.h> /* For PAGE_SIZE */ + +AssertCompile(sizeof(HANDLE) >= sizeof(D3DKMT_HANDLE)); + + +/* + * AVL configuration. + */ +#define KAVL_FN(a) RTAvlU32##a +#define KAVL_MAX_STACK 27 /* Up to 2^24 nodes. */ +#define KAVL_CHECK_FOR_EQUAL_INSERT 1 /* No duplicate keys! */ +#define KAVLNODECORE AVLU32NODECORE +#define PKAVLNODECORE PAVLU32NODECORE +#define PPKAVLNODECORE PPAVLU32NODECORE +#define KAVLKEY AVLU32KEY +#define PKAVLKEY PAVLU32KEY +#define KAVLENUMDATA AVLU32ENUMDATA +#define PKAVLENUMDATA PAVLU32ENUMDATA +#define PKAVLCALLBACK PAVLU32CALLBACK + + +/* + * AVL Compare macros + */ +#define KAVL_G(key1, key2) ( (key1) > (key2) ) +#define KAVL_E(key1, key2) ( (key1) == (key2) ) +#define KAVL_NE(key1, key2) ( (key1) != (key2) ) + + +#include <iprt/avl.h> + +/* + * Include the code. + */ +#define SSToDS(ptr) ptr +#define KMAX RT_MAX +#define kASSERT(_e) do { } while (0) +#include "avl_Base.cpp.h" +#include "avl_Get.cpp.h" +//#include "avl_GetBestFit.cpp.h" +//#include "avl_RemoveBestFit.cpp.h" +//#include "avl_DoWithAll.cpp.h" +#include "avl_Destroy.cpp.h" + + +typedef struct GaKmtCallbacks +{ + D3DKMT_HANDLE hAdapter; + D3DKMT_HANDLE hDevice; + D3DKMTFUNCTIONS const *d3dkmt; + LUID AdapterLuid; +} GaKmtCallbacks; + +class GaDrvEnvKmt +{ + public: + GaDrvEnvKmt(); + ~GaDrvEnvKmt(); + + HRESULT Init(void); + + const WDDMGalliumDriverEnv *Env(); + + /* + * KMT specific helpers. + */ + bool drvEnvKmtRenderCompose(uint32_t u32Cid, + void *pvCommands, + uint32_t cbCommands, + ULONGLONG PresentHistoryToken); + D3DKMT_HANDLE drvEnvKmtContextHandle(uint32_t u32Cid); + D3DKMT_HANDLE drvEnvKmtSurfaceHandle(uint32_t u32Sid); + + GaKmtCallbacks mKmtCallbacks; + + private: + + VBOXGAHWINFO mHWInfo; + + /* Map to convert context id (cid) to WDDM context information (GAWDDMCONTEXTINFO). + * Key is the 32 bit context id. + */ + AVLU32TREE mContextTree; + + /* Map to convert surface id (sid) to WDDM surface information (GAWDDMSURFACEINFO). + * Key is the 32 bit surface id. + */ + AVLU32TREE mSurfaceTree; + + WDDMGalliumDriverEnv mEnv; + + static DECLCALLBACK(uint32_t) gaEnvContextCreate(void *pvEnv, + boolean extended, + boolean vgpu10); + static DECLCALLBACK(void) gaEnvContextDestroy(void *pvEnv, + uint32_t u32Cid); + static DECLCALLBACK(int) gaEnvSurfaceDefine(void *pvEnv, + GASURFCREATE *pCreateParms, + GASURFSIZE *paSizes, + uint32_t cSizes, + uint32_t *pu32Sid); + static DECLCALLBACK(void) gaEnvSurfaceDestroy(void *pvEnv, + uint32_t u32Sid); + static DECLCALLBACK(int) gaEnvRender(void *pvEnv, + uint32_t u32Cid, + void *pvCommands, + uint32_t cbCommands, + GAFENCEQUERY *pFenceQuery); + static DECLCALLBACK(void) gaEnvFenceUnref(void *pvEnv, + uint32_t u32FenceHandle); + static DECLCALLBACK(int) gaEnvFenceQuery(void *pvEnv, + uint32_t u32FenceHandle, + GAFENCEQUERY *pFenceQuery); + static DECLCALLBACK(int) gaEnvFenceWait(void *pvEnv, + uint32_t u32FenceHandle, + uint32_t u32TimeoutUS); + static DECLCALLBACK(int) gaEnvRegionCreate(void *pvEnv, + uint32_t u32RegionSize, + uint32_t *pu32GmrId, + void **ppvMap); + static DECLCALLBACK(void) gaEnvRegionDestroy(void *pvEnv, + uint32_t u32GmrId, + void *pvMap); + + /* + * Internal. + */ + bool doRender(uint32_t u32Cid, void *pvCommands, uint32_t cbCommands, + GAFENCEQUERY *pFenceQuery, ULONGLONG PresentHistoryToken, bool fPresentRedirected); +}; + +typedef struct GAWDDMCONTEXTINFO +{ + AVLU32NODECORE Core; + D3DKMT_HANDLE hContext; + VOID *pCommandBuffer; + UINT CommandBufferSize; + D3DDDI_ALLOCATIONLIST *pAllocationList; + UINT AllocationListSize; + D3DDDI_PATCHLOCATIONLIST *pPatchLocationList; + UINT PatchLocationListSize; +} GAWDDMCONTEXTINFO; + +typedef struct GAWDDMSURFACEINFO +{ + AVLU32NODECORE Core; + D3DKMT_HANDLE hAllocation; +} GAWDDMSURFACEINFO; + + +/// @todo vboxDdi helpers must return a boof success indicator +static bool +vboxDdiQueryAdapterInfo(GaKmtCallbacks *pKmtCallbacks, + D3DKMT_HANDLE hAdapter, + VBOXWDDM_QAI *pAdapterInfo, + uint32_t cbAdapterInfo) +{ + D3DKMT_QUERYADAPTERINFO QAI; + memset(&QAI, 0, sizeof(QAI)); + QAI.hAdapter = hAdapter; + QAI.Type = KMTQAITYPE_UMDRIVERPRIVATE; + QAI.pPrivateDriverData = pAdapterInfo; + QAI.PrivateDriverDataSize = cbAdapterInfo; + + NTSTATUS Status = pKmtCallbacks->d3dkmt->pfnD3DKMTQueryAdapterInfo(&QAI); + return Status == STATUS_SUCCESS; +} + +static void +vboxDdiDeviceDestroy(GaKmtCallbacks *pKmtCallbacks, + D3DKMT_HANDLE hDevice) +{ + if (hDevice) + { + D3DKMT_DESTROYDEVICE DestroyDeviceData; + memset(&DestroyDeviceData, 0, sizeof(DestroyDeviceData)); + DestroyDeviceData.hDevice = hDevice; + pKmtCallbacks->d3dkmt->pfnD3DKMTDestroyDevice(&DestroyDeviceData); + } +} + +static bool +vboxDdiDeviceCreate(GaKmtCallbacks *pKmtCallbacks, + D3DKMT_HANDLE *phDevice) +{ + D3DKMT_CREATEDEVICE CreateDeviceData; + memset(&CreateDeviceData, 0, sizeof(CreateDeviceData)); + CreateDeviceData.hAdapter = pKmtCallbacks->hAdapter; + // CreateDeviceData.Flags = 0; + + NTSTATUS Status = pKmtCallbacks->d3dkmt->pfnD3DKMTCreateDevice(&CreateDeviceData); + if (Status == STATUS_SUCCESS) + { + *phDevice = CreateDeviceData.hDevice; + return true; + } + return false; +} + +static bool +vboxDdiContextGetId(GaKmtCallbacks *pKmtCallbacks, + D3DKMT_HANDLE hContext, + uint32_t *pu32Cid) +{ + VBOXDISPIFESCAPE_GAGETCID data; + memset(&data, 0, sizeof(data)); + data.EscapeHdr.escapeCode = VBOXESC_GAGETCID; + // data.EscapeHdr.cmdSpecific = 0; + // data.u32Cid = 0; + + /* If the user-mode display driver sets hContext to a non-NULL value, the driver must + * have also set hDevice to a non-NULL value... + */ + D3DKMT_ESCAPE EscapeData; + memset(&EscapeData, 0, sizeof(EscapeData)); + EscapeData.hAdapter = pKmtCallbacks->hAdapter; + EscapeData.hDevice = pKmtCallbacks->hDevice; + EscapeData.Type = D3DKMT_ESCAPE_DRIVERPRIVATE; + // EscapeData.Flags.HardwareAccess = 0; + EscapeData.pPrivateDriverData = &data; + EscapeData.PrivateDriverDataSize = sizeof(data); + EscapeData.hContext = hContext; + + NTSTATUS Status = pKmtCallbacks->d3dkmt->pfnD3DKMTEscape(&EscapeData); + if (Status == STATUS_SUCCESS) + { + *pu32Cid = data.u32Cid; + return true; + } + return false; +} + +static void +vboxDdiContextDestroy(GaKmtCallbacks *pKmtCallbacks, + GAWDDMCONTEXTINFO *pContextInfo) +{ + if (pContextInfo->hContext) + { + D3DKMT_DESTROYCONTEXT DestroyContextData; + memset(&DestroyContextData, 0, sizeof(DestroyContextData)); + DestroyContextData.hContext = pContextInfo->hContext; + pKmtCallbacks->d3dkmt->pfnD3DKMTDestroyContext(&DestroyContextData); + } +} + +static bool +vboxDdiContextCreate(GaKmtCallbacks *pKmtCallbacks, + void *pvPrivateData, uint32_t cbPrivateData, + GAWDDMCONTEXTINFO *pContextInfo) +{ + D3DKMT_CREATECONTEXT CreateContextData; + memset(&CreateContextData, 0, sizeof(CreateContextData)); + CreateContextData.hDevice = pKmtCallbacks->hDevice; + // CreateContextData.NodeOrdinal = 0; + // CreateContextData.EngineAffinity = 0; + // CreateContextData.Flags.Value = 0; + CreateContextData.pPrivateDriverData = pvPrivateData; + CreateContextData.PrivateDriverDataSize = cbPrivateData; + CreateContextData.ClientHint = D3DKMT_CLIENTHINT_OPENGL; + + NTSTATUS Status = pKmtCallbacks->d3dkmt->pfnD3DKMTCreateContext(&CreateContextData); + if (Status == STATUS_SUCCESS) + { + /* Query cid. */ + uint32_t u32Cid = 0; + bool fSuccess = vboxDdiContextGetId(pKmtCallbacks, CreateContextData.hContext, &u32Cid); + if (fSuccess) + { + pContextInfo->Core.Key = u32Cid; + pContextInfo->hContext = CreateContextData.hContext; + pContextInfo->pCommandBuffer = CreateContextData.pCommandBuffer; + pContextInfo->CommandBufferSize = CreateContextData.CommandBufferSize; + pContextInfo->pAllocationList = CreateContextData.pAllocationList; + pContextInfo->AllocationListSize = CreateContextData.AllocationListSize; + pContextInfo->pPatchLocationList = CreateContextData.pPatchLocationList; + pContextInfo->PatchLocationListSize = CreateContextData.PatchLocationListSize; + + return true; + } + + vboxDdiContextDestroy(pKmtCallbacks, pContextInfo); + } + + return false; +} + +/* static */ DECLCALLBACK(void) +GaDrvEnvKmt::gaEnvContextDestroy(void *pvEnv, + uint32_t u32Cid) +{ + GaDrvEnvKmt *pThis = (GaDrvEnvKmt *)pvEnv; + + GAWDDMCONTEXTINFO *pContextInfo = (GAWDDMCONTEXTINFO *)RTAvlU32Remove(&pThis->mContextTree, u32Cid); + if (pContextInfo) + { + vboxDdiContextDestroy(&pThis->mKmtCallbacks, pContextInfo); + memset(pContextInfo, 0, sizeof(*pContextInfo)); + free(pContextInfo); + } +} + +D3DKMT_HANDLE GaDrvEnvKmt::drvEnvKmtContextHandle(uint32_t u32Cid) +{ + GAWDDMCONTEXTINFO *pContextInfo = (GAWDDMCONTEXTINFO *)RTAvlU32Get(&mContextTree, u32Cid); + Assert(pContextInfo); + return pContextInfo ? pContextInfo->hContext : 0; +} + +/* static */ DECLCALLBACK(uint32_t) +GaDrvEnvKmt::gaEnvContextCreate(void *pvEnv, + boolean extended, + boolean vgpu10) +{ + GaDrvEnvKmt *pThis = (GaDrvEnvKmt *)pvEnv; + + GAWDDMCONTEXTINFO *pContextInfo; + pContextInfo = (GAWDDMCONTEXTINFO *)malloc(sizeof(GAWDDMCONTEXTINFO)); + if (!pContextInfo) + return (uint32_t)-1; + + VBOXWDDM_CREATECONTEXT_INFO privateData; + memset(&privateData, 0, sizeof(privateData)); + privateData.u32IfVersion = 9; + privateData.enmType = VBOXWDDM_CONTEXT_TYPE_GA_3D; + privateData.u.vmsvga.u32Flags = extended? VBOXWDDM_F_GA_CONTEXT_EXTENDED: 0; + privateData.u.vmsvga.u32Flags |= vgpu10? VBOXWDDM_F_GA_CONTEXT_VGPU10: 0; + + bool fSuccess = vboxDdiContextCreate(&pThis->mKmtCallbacks, + &privateData, sizeof(privateData), pContextInfo); + if (fSuccess) + { + if (RTAvlU32Insert(&pThis->mContextTree, &pContextInfo->Core)) + { + return pContextInfo->Core.Key; + } + + vboxDdiContextDestroy(&pThis->mKmtCallbacks, + pContextInfo); + } + + Assert(0); + free(pContextInfo); + return (uint32_t)-1; +} + +static D3DDDIFORMAT svgaToD3DDDIFormat(SVGA3dSurfaceFormat format) +{ + switch (format) + { + case SVGA3D_X8R8G8B8: return D3DDDIFMT_X8R8G8B8; + case SVGA3D_A8R8G8B8: return D3DDDIFMT_A8R8G8B8; + case SVGA3D_ALPHA8: return D3DDDIFMT_A8; + case SVGA3D_R8G8B8A8_UNORM: return D3DDDIFMT_A8B8G8R8; + case SVGA3D_A4R4G4B4: return D3DDDIFMT_A4R4G4B4; + case SVGA3D_LUMINANCE8: return D3DDDIFMT_L8; + case SVGA3D_A1R5G5B5: return D3DDDIFMT_A1R5G5B5; + case SVGA3D_LUMINANCE8_ALPHA8: return D3DDDIFMT_A8L8; + case SVGA3D_R5G6B5: return D3DDDIFMT_R5G6B5; + case SVGA3D_ARGB_S10E5: return D3DDDIFMT_A16B16G16R16F; + case SVGA3D_ARGB_S23E8: return D3DDDIFMT_A32B32G32R32F; + default: break; + } + + VBoxDispMpLoggerLogF("WDDM: EnvKMT: unsupported surface format %d\n", format); + Assert(0); + return D3DDDIFMT_UNKNOWN; +} + +/* static */ DECLCALLBACK(int) +GaDrvEnvKmt::gaEnvSurfaceDefine(void *pvEnv, + GASURFCREATE *pCreateParms, + GASURFSIZE *paSizes, + uint32_t cSizes, + uint32_t *pu32Sid) +{ + GaDrvEnvKmt *pThis = (GaDrvEnvKmt *)pvEnv; + + D3DKMT_ESCAPE EscapeData; + VBOXDISPIFESCAPE_GASURFACEDEFINE *pData; + uint32_t cbAlloc; + uint8_t *pu8Req; + uint32_t cbReq; + + /* Size of the SVGA request data */ + cbReq = sizeof(GASURFCREATE) + cSizes * sizeof(GASURFSIZE); + /* How much to allocate for WDDM escape data. */ + cbAlloc = sizeof(VBOXDISPIFESCAPE_GASURFACEDEFINE) + + cbReq; + + pData = (VBOXDISPIFESCAPE_GASURFACEDEFINE *)malloc(cbAlloc); + if (!pData) + return -1; + + pData->EscapeHdr.escapeCode = VBOXESC_GASURFACEDEFINE; + // pData->EscapeHdr.cmdSpecific = 0; + // pData->u32Sid = 0; + pData->cbReq = cbReq; + pData->cSizes = cSizes; + + pu8Req = (uint8_t *)&pData[1]; + memcpy(pu8Req, pCreateParms, sizeof(GASURFCREATE)); + memcpy(&pu8Req[sizeof(GASURFCREATE)], paSizes, cSizes * sizeof(GASURFSIZE)); + + memset(&EscapeData, 0, sizeof(EscapeData)); + EscapeData.hAdapter = pThis->mKmtCallbacks.hAdapter; + EscapeData.hDevice = pThis->mKmtCallbacks.hDevice; + EscapeData.Type = D3DKMT_ESCAPE_DRIVERPRIVATE; + EscapeData.Flags.HardwareAccess = 1; + EscapeData.pPrivateDriverData = pData; + EscapeData.PrivateDriverDataSize = cbAlloc; + // EscapeData.hContext = 0; + + NTSTATUS Status = pThis->mKmtCallbacks.d3dkmt->pfnD3DKMTEscape(&EscapeData); + if (Status == STATUS_SUCCESS) + { + /* Create a kernel mode allocation for render targets, + * because we will need kernel mode handles for Present. + */ + if (pCreateParms->flags & SVGA3D_SURFACE_HINT_RENDERTARGET) + { + /* First check if the format is supported. */ + D3DDDIFORMAT const ddiFormat = svgaToD3DDDIFormat((SVGA3dSurfaceFormat)pCreateParms->format); + if (ddiFormat != D3DDDIFMT_UNKNOWN) + { + GAWDDMSURFACEINFO *pSurfaceInfo = (GAWDDMSURFACEINFO *)malloc(sizeof(GAWDDMSURFACEINFO)); + if (pSurfaceInfo) + { + memset(pSurfaceInfo, 0, sizeof(GAWDDMSURFACEINFO)); + + VBOXWDDM_ALLOCINFO wddmAllocInfo; + memset(&wddmAllocInfo, 0, sizeof(wddmAllocInfo)); + + wddmAllocInfo.enmType = VBOXWDDM_ALLOC_TYPE_UMD_RC_GENERIC; + wddmAllocInfo.fFlags.RenderTarget = 1; + wddmAllocInfo.hSharedHandle = 0; + wddmAllocInfo.hostID = pData->u32Sid; + wddmAllocInfo.SurfDesc.slicePitch = 0; + wddmAllocInfo.SurfDesc.depth = paSizes[0].cDepth; + wddmAllocInfo.SurfDesc.width = paSizes[0].cWidth; + wddmAllocInfo.SurfDesc.height = paSizes[0].cHeight; + wddmAllocInfo.SurfDesc.format = ddiFormat; + wddmAllocInfo.SurfDesc.VidPnSourceId = 0; + wddmAllocInfo.SurfDesc.bpp = vboxWddmCalcBitsPerPixel(wddmAllocInfo.SurfDesc.format); + wddmAllocInfo.SurfDesc.pitch = vboxWddmCalcPitch(wddmAllocInfo.SurfDesc.width, + wddmAllocInfo.SurfDesc.format); + wddmAllocInfo.SurfDesc.cbSize = vboxWddmCalcSize(wddmAllocInfo.SurfDesc.pitch, + wddmAllocInfo.SurfDesc.height, + wddmAllocInfo.SurfDesc.format); + wddmAllocInfo.SurfDesc.d3dWidth = vboxWddmCalcWidthForPitch(wddmAllocInfo.SurfDesc.pitch, + wddmAllocInfo.SurfDesc.format); + + D3DDDI_ALLOCATIONINFO AllocationInfo; + memset(&AllocationInfo, 0, sizeof(AllocationInfo)); + // AllocationInfo.hAllocation = NULL; + // AllocationInfo.pSystemMem = NULL; + AllocationInfo.pPrivateDriverData = &wddmAllocInfo; + AllocationInfo.PrivateDriverDataSize = sizeof(wddmAllocInfo); + + D3DKMT_CREATEALLOCATION CreateAllocation; + memset(&CreateAllocation, 0, sizeof(CreateAllocation)); + CreateAllocation.hDevice = pThis->mKmtCallbacks.hDevice; + CreateAllocation.NumAllocations = 1; + CreateAllocation.pAllocationInfo = &AllocationInfo; + + Status = pThis->mKmtCallbacks.d3dkmt->pfnD3DKMTCreateAllocation(&CreateAllocation); + if (Status == STATUS_SUCCESS) + { + pSurfaceInfo->Core.Key = pData->u32Sid; + pSurfaceInfo->hAllocation = AllocationInfo.hAllocation; + if (!RTAvlU32Insert(&pThis->mSurfaceTree, &pSurfaceInfo->Core)) + { + Status = STATUS_NOT_SUPPORTED; + } + } + + if (Status != STATUS_SUCCESS) + { + free(pSurfaceInfo); + } + } + else + { + Status = STATUS_NOT_SUPPORTED; + } + } + else + { + /* Unsupported render target format. */ + Status = STATUS_NOT_SUPPORTED; + } + } + + if (Status != STATUS_SUCCESS) + { + gaEnvSurfaceDestroy(pvEnv, pData->u32Sid); + } + } + + if (Status == STATUS_SUCCESS) + { + *pu32Sid = pData->u32Sid; + free(pData); + return 0; + } + + Assert(0); + free(pData); + return -1; +} + +/* static */ DECLCALLBACK(void) +GaDrvEnvKmt::gaEnvSurfaceDestroy(void *pvEnv, + uint32_t u32Sid) +{ + GaDrvEnvKmt *pThis = (GaDrvEnvKmt *)pvEnv; + + VBOXDISPIFESCAPE_GASURFACEDESTROY data; + memset(&data, 0, sizeof(data)); + data.EscapeHdr.escapeCode = VBOXESC_GASURFACEDESTROY; + // data.EscapeHdr.cmdSpecific = 0; + data.u32Sid = u32Sid; + + D3DKMT_ESCAPE EscapeData; + memset(&EscapeData, 0, sizeof(EscapeData)); + EscapeData.hAdapter = pThis->mKmtCallbacks.hAdapter; + EscapeData.hDevice = pThis->mKmtCallbacks.hDevice; + EscapeData.Type = D3DKMT_ESCAPE_DRIVERPRIVATE; + EscapeData.Flags.HardwareAccess = 1; + EscapeData.pPrivateDriverData = &data; + EscapeData.PrivateDriverDataSize = sizeof(data); + // EscapeData.hContext = 0; + + NTSTATUS Status = pThis->mKmtCallbacks.d3dkmt->pfnD3DKMTEscape(&EscapeData); + Assert(Status == STATUS_SUCCESS); + + /* Try to remove from sid -> hAllocation map. */ + GAWDDMSURFACEINFO *pSurfaceInfo = (GAWDDMSURFACEINFO *)RTAvlU32Remove(&pThis->mSurfaceTree, u32Sid); + if (pSurfaceInfo) + { + D3DKMT_DESTROYALLOCATION DestroyAllocation; + memset(&DestroyAllocation, 0, sizeof(DestroyAllocation)); + DestroyAllocation.hDevice = pThis->mKmtCallbacks.hDevice; + // DestroyAllocation.hResource = 0; + DestroyAllocation.phAllocationList = &pSurfaceInfo->hAllocation; + DestroyAllocation.AllocationCount = 1; + + Status = pThis->mKmtCallbacks.d3dkmt->pfnD3DKMTDestroyAllocation(&DestroyAllocation); + Assert(Status == STATUS_SUCCESS); + + free(pSurfaceInfo); + } +} + +D3DKMT_HANDLE GaDrvEnvKmt::drvEnvKmtSurfaceHandle(uint32_t u32Sid) +{ + GAWDDMSURFACEINFO *pSurfaceInfo = (GAWDDMSURFACEINFO *)RTAvlU32Get(&mSurfaceTree, u32Sid); + return pSurfaceInfo ? pSurfaceInfo->hAllocation : 0; +} + +static bool +vboxDdiFenceCreate(GaKmtCallbacks *pKmtCallbacks, + GAWDDMCONTEXTINFO *pContextInfo, + uint32_t *pu32FenceHandle) +{ + VBOXDISPIFESCAPE_GAFENCECREATE fenceCreate; + memset(&fenceCreate, 0, sizeof(fenceCreate)); + fenceCreate.EscapeHdr.escapeCode = VBOXESC_GAFENCECREATE; + // fenceCreate.EscapeHdr.cmdSpecific = 0; + + /* If the user-mode display driver sets hContext to a non-NULL value, the driver must + * have also set hDevice to a non-NULL value... + */ + D3DKMT_ESCAPE EscapeData; + memset(&EscapeData, 0, sizeof(EscapeData)); + EscapeData.hAdapter = pKmtCallbacks->hAdapter; + EscapeData.hDevice = pKmtCallbacks->hDevice; + EscapeData.Type = D3DKMT_ESCAPE_DRIVERPRIVATE; + // EscapeData.Flags.HardwareAccess = 0; + EscapeData.pPrivateDriverData = &fenceCreate; + EscapeData.PrivateDriverDataSize = sizeof(fenceCreate); + EscapeData.hContext = pContextInfo->hContext; + + NTSTATUS Status = pKmtCallbacks->d3dkmt->pfnD3DKMTEscape(&EscapeData); + if (Status == STATUS_SUCCESS) + { + *pu32FenceHandle = fenceCreate.u32FenceHandle; + return true; + } + + Assert(0); + return false; +} + +static bool +vboxDdiFenceQuery(GaKmtCallbacks *pKmtCallbacks, + uint32_t u32FenceHandle, + GAFENCEQUERY *pFenceQuery) +{ + VBOXDISPIFESCAPE_GAFENCEQUERY fenceQuery; + memset(&fenceQuery, 0, sizeof(fenceQuery)); + fenceQuery.EscapeHdr.escapeCode = VBOXESC_GAFENCEQUERY; + // fenceQuery.EscapeHdr.cmdSpecific = 0; + fenceQuery.u32FenceHandle = u32FenceHandle; + + D3DKMT_ESCAPE EscapeData; + memset(&EscapeData, 0, sizeof(EscapeData)); + EscapeData.hAdapter = pKmtCallbacks->hAdapter; + EscapeData.hDevice = pKmtCallbacks->hDevice; + EscapeData.Type = D3DKMT_ESCAPE_DRIVERPRIVATE; + // EscapeData.Flags.HardwareAccess = 0; + EscapeData.pPrivateDriverData = &fenceQuery; + EscapeData.PrivateDriverDataSize = sizeof(fenceQuery); + EscapeData.hContext = 0; + + NTSTATUS Status = pKmtCallbacks->d3dkmt->pfnD3DKMTEscape(&EscapeData); + if (Status == STATUS_SUCCESS) + { + pFenceQuery->u32FenceHandle = fenceQuery.u32FenceHandle; + pFenceQuery->u32SubmittedSeqNo = fenceQuery.u32SubmittedSeqNo; + pFenceQuery->u32ProcessedSeqNo = fenceQuery.u32ProcessedSeqNo; + pFenceQuery->u32FenceStatus = fenceQuery.u32FenceStatus; + return true; + } + + Assert(0); + return false; +} + +/* static */ DECLCALLBACK(int) +GaDrvEnvKmt::gaEnvFenceQuery(void *pvEnv, + uint32_t u32FenceHandle, + GAFENCEQUERY *pFenceQuery) +{ + GaDrvEnvKmt *pThis = (GaDrvEnvKmt *)pvEnv; + + if (!pThis->mKmtCallbacks.hDevice) + { + pFenceQuery->u32FenceStatus = GA_FENCE_STATUS_NULL; + return 0; + } + + bool fSuccess = vboxDdiFenceQuery(&pThis->mKmtCallbacks, u32FenceHandle, pFenceQuery); + return fSuccess ? 0: -1; +} + +static bool +vboxDdiFenceWait(GaKmtCallbacks *pKmtCallbacks, + uint32_t u32FenceHandle, + uint32_t u32TimeoutUS) +{ + VBOXDISPIFESCAPE_GAFENCEWAIT fenceWait; + memset(&fenceWait, 0, sizeof(fenceWait)); + fenceWait.EscapeHdr.escapeCode = VBOXESC_GAFENCEWAIT; + // pFenceWait->EscapeHdr.cmdSpecific = 0; + fenceWait.u32FenceHandle = u32FenceHandle; + fenceWait.u32TimeoutUS = u32TimeoutUS; + + D3DKMT_ESCAPE EscapeData; + memset(&EscapeData, 0, sizeof(EscapeData)); + EscapeData.hAdapter = pKmtCallbacks->hAdapter; + EscapeData.hDevice = pKmtCallbacks->hDevice; + EscapeData.Type = D3DKMT_ESCAPE_DRIVERPRIVATE; + // EscapeData.Flags.HardwareAccess = 0; + EscapeData.pPrivateDriverData = &fenceWait; + EscapeData.PrivateDriverDataSize = sizeof(fenceWait); + EscapeData.hContext = 0; + + NTSTATUS Status = pKmtCallbacks->d3dkmt->pfnD3DKMTEscape(&EscapeData); + Assert(Status == STATUS_SUCCESS); + return Status == STATUS_SUCCESS; +} + +/* static */ DECLCALLBACK(int) +GaDrvEnvKmt::gaEnvFenceWait(void *pvEnv, + uint32_t u32FenceHandle, + uint32_t u32TimeoutUS) +{ + GaDrvEnvKmt *pThis = (GaDrvEnvKmt *)pvEnv; + + if (!pThis->mKmtCallbacks.hDevice) + return 0; + + bool fSuccess = vboxDdiFenceWait(&pThis->mKmtCallbacks, u32FenceHandle, u32TimeoutUS); + return fSuccess ? 0 : -1; +} + +static bool +vboxDdiFenceUnref(GaKmtCallbacks *pKmtCallbacks, + uint32_t u32FenceHandle) +{ + VBOXDISPIFESCAPE_GAFENCEUNREF fenceUnref; + memset(&fenceUnref, 0, sizeof(fenceUnref)); + fenceUnref.EscapeHdr.escapeCode = VBOXESC_GAFENCEUNREF; + // pFenceUnref->EscapeHdr.cmdSpecific = 0; + fenceUnref.u32FenceHandle = u32FenceHandle; + + D3DKMT_ESCAPE EscapeData; + memset(&EscapeData, 0, sizeof(EscapeData)); + EscapeData.hAdapter = pKmtCallbacks->hAdapter; + EscapeData.hDevice = pKmtCallbacks->hDevice; + EscapeData.Type = D3DKMT_ESCAPE_DRIVERPRIVATE; + // EscapeData.Flags.HardwareAccess = 0; + EscapeData.pPrivateDriverData = &fenceUnref; + EscapeData.PrivateDriverDataSize = sizeof(fenceUnref); + EscapeData.hContext = 0; + + NTSTATUS Status = pKmtCallbacks->d3dkmt->pfnD3DKMTEscape(&EscapeData); + Assert(Status == STATUS_SUCCESS); + return Status == STATUS_SUCCESS; +} + +/* static */ DECLCALLBACK(void) +GaDrvEnvKmt::gaEnvFenceUnref(void *pvEnv, + uint32_t u32FenceHandle) +{ + GaDrvEnvKmt *pThis = (GaDrvEnvKmt *)pvEnv; + + if (!pThis->mKmtCallbacks.hDevice) + return; + + vboxDdiFenceUnref(&pThis->mKmtCallbacks, u32FenceHandle); +} + +/** Calculate how many commands will fit in the buffer. + * + * @param pu8Commands Command buffer. + * @param cbCommands Size of command buffer. + * @param cbAvail Available buffer size.. + * @param pu32Length Size of commands which will fit in cbAvail bytes. + */ +static bool +vboxCalcCommandLength(const uint8_t *pu8Commands, uint32_t cbCommands, uint32_t cbAvail, uint32_t *pu32Length) +{ + uint32_t u32Length = 0; + const uint8_t *pu8Src = pu8Commands; + const uint8_t *pu8SrcEnd = pu8Commands + cbCommands; + + while (pu8SrcEnd > pu8Src) + { + const uint32_t cbSrcLeft = pu8SrcEnd - pu8Src; + if (cbSrcLeft < sizeof(uint32_t)) + { + return false; + } + + /* Get the command id and command length. */ + const uint32_t u32CmdId = *(uint32_t *)pu8Src; + uint32_t cbCmd = 0; + + if (SVGA_3D_CMD_BASE <= u32CmdId && u32CmdId < SVGA_3D_CMD_MAX) + { + if (cbSrcLeft < sizeof(SVGA3dCmdHeader)) + { + return false; + } + + const SVGA3dCmdHeader *pHeader = (SVGA3dCmdHeader *)pu8Src; + cbCmd = sizeof(SVGA3dCmdHeader) + pHeader->size; + if (cbCmd % sizeof(uint32_t) != 0) + { + return false; + } + if (cbSrcLeft < cbCmd) + { + return false; + } + } + else + { + /* It is not expected that any of common SVGA commands will be in the command buffer + * because the SVGA gallium driver does not use them. + */ + return false; + } + + if (u32Length + cbCmd > cbAvail) + { + if (u32Length == 0) + { + /* No commands fit into the buffer. */ + return false; + } + break; + } + + pu8Src += cbCmd; + u32Length += cbCmd; + } + + *pu32Length = u32Length; + return true; +} + +static bool +vboxDdiRender(GaKmtCallbacks *pKmtCallbacks, + GAWDDMCONTEXTINFO *pContextInfo, uint32_t u32FenceHandle, void *pvCommands, uint32_t cbCommands, + ULONGLONG PresentHistoryToken, bool fPresentRedirected) +{ + uint32_t cbLeft; + const uint8_t *pu8Src; + + cbLeft = cbCommands; + pu8Src = (uint8_t *)pvCommands; + /* Even when cbCommands is 0, submit the fence. The following code deals with this. */ + do + { + /* Actually available space. */ + const uint32_t cbAvail = pContextInfo->CommandBufferSize; + if (cbAvail <= sizeof(u32FenceHandle)) + { + return false; + } + + /* How many bytes of command data still to copy. */ + uint32_t cbCommandChunk = cbLeft; + + /* How many bytes still to copy. */ + uint32_t cbToCopy = sizeof(u32FenceHandle) + cbCommandChunk; + + /* Copy the buffer identifier. */ + if (cbToCopy <= cbAvail) + { + /* Command buffer is big enough. */ + *(uint32_t *)pContextInfo->pCommandBuffer = u32FenceHandle; + } + else + { + /* Split. Write zero as buffer identifier. */ + *(uint32_t *)pContextInfo->pCommandBuffer = 0; + + /* Get how much commands data will fit in the buffer. */ + if (!vboxCalcCommandLength(pu8Src, cbCommandChunk, cbAvail - sizeof(u32FenceHandle), &cbCommandChunk)) + { + return false; + } + + cbToCopy = sizeof(u32FenceHandle) + cbCommandChunk; + } + + if (cbCommandChunk) + { + /* Copy the command data. */ + memcpy((uint8_t *)pContextInfo->pCommandBuffer + sizeof(u32FenceHandle), pu8Src, cbCommandChunk); + } + + /* Advance the command position. */ + pu8Src += cbCommandChunk; + cbLeft -= cbCommandChunk; + + D3DKMT_RENDER RenderData; + memset(&RenderData, 0, sizeof(RenderData)); + RenderData.hContext = pContextInfo->hContext; + // RenderData.CommandOffset = 0; + RenderData.CommandLength = cbToCopy; + // RenderData.AllocationCount = 0; + // RenderData.PatchLocationCount = 0; + RenderData.PresentHistoryToken = PresentHistoryToken; + RenderData.Flags.PresentRedirected = fPresentRedirected; + + NTSTATUS Status = pKmtCallbacks->d3dkmt->pfnD3DKMTRender(&RenderData); + Assert(Status == STATUS_SUCCESS); + if (Status != STATUS_SUCCESS) + { + return false; + } + + pContextInfo->pCommandBuffer = RenderData.pNewCommandBuffer; + pContextInfo->CommandBufferSize = RenderData.NewCommandBufferSize; + pContextInfo->pAllocationList = RenderData.pNewAllocationList; + pContextInfo->AllocationListSize = RenderData.NewAllocationListSize; + pContextInfo->pPatchLocationList = RenderData.pNewPatchLocationList; + pContextInfo->PatchLocationListSize = RenderData.NewPatchLocationListSize; + } while (cbLeft); + + return true; +} + +bool GaDrvEnvKmt::doRender(uint32_t u32Cid, void *pvCommands, uint32_t cbCommands, + GAFENCEQUERY *pFenceQuery, ULONGLONG PresentHistoryToken, bool fPresentRedirected) +{ + uint32_t u32FenceHandle; + GAWDDMCONTEXTINFO *pContextInfo = (GAWDDMCONTEXTINFO *)RTAvlU32Get(&mContextTree, u32Cid); + if (!pContextInfo) + return false; + + bool fSuccess = true; + u32FenceHandle = 0; + if (pFenceQuery) + { + fSuccess = vboxDdiFenceCreate(&mKmtCallbacks, pContextInfo, &u32FenceHandle); + } + + if (fSuccess) + { + fSuccess = vboxDdiRender(&mKmtCallbacks, pContextInfo, u32FenceHandle, + pvCommands, cbCommands, PresentHistoryToken, fPresentRedirected); + if (fSuccess) + { + if (pFenceQuery) + { + if (!vboxDdiFenceQuery(&mKmtCallbacks, u32FenceHandle, pFenceQuery)) + { + pFenceQuery->u32FenceStatus = GA_FENCE_STATUS_NULL; + } + } + } + } + return fSuccess; +} + +/* static */ DECLCALLBACK(int) +GaDrvEnvKmt::gaEnvRender(void *pvEnv, + uint32_t u32Cid, + void *pvCommands, + uint32_t cbCommands, + GAFENCEQUERY *pFenceQuery) +{ + GaDrvEnvKmt *pThis = (GaDrvEnvKmt *)pvEnv; + return pThis->doRender(u32Cid, pvCommands, cbCommands, pFenceQuery, 0, false) ? 1 : 0; +} + +bool GaDrvEnvKmt::drvEnvKmtRenderCompose(uint32_t u32Cid, + void *pvCommands, + uint32_t cbCommands, + ULONGLONG PresentHistoryToken) +{ + return doRender(u32Cid, pvCommands, cbCommands, NULL, PresentHistoryToken, true); +} + + +static bool +vboxDdiRegionCreate(GaKmtCallbacks *pKmtCallbacks, + uint32_t u32RegionSize, + uint32_t *pu32GmrId, + void **ppvMap) +{ + VBOXDISPIFESCAPE_GAREGION data; + memset(&data, 0, sizeof(data)); + data.EscapeHdr.escapeCode = VBOXESC_GAREGION; + // data.EscapeHdr.cmdSpecific = 0; + data.u32Command = GA_REGION_CMD_CREATE; + data.u32NumPages = (u32RegionSize + PAGE_SIZE - 1) / PAGE_SIZE; + // data.u32GmrId = 0; + // data.u64UserAddress = 0; + + D3DKMT_ESCAPE EscapeData; + memset(&EscapeData, 0, sizeof(EscapeData)); + EscapeData.hAdapter = pKmtCallbacks->hAdapter; + EscapeData.hDevice = pKmtCallbacks->hDevice; + EscapeData.Type = D3DKMT_ESCAPE_DRIVERPRIVATE; + // EscapeData.Flags.HardwareAccess = 0; + EscapeData.pPrivateDriverData = &data; + EscapeData.PrivateDriverDataSize = sizeof(data); + // EscapeData.hContext = 0; + + NTSTATUS Status = pKmtCallbacks->d3dkmt->pfnD3DKMTEscape(&EscapeData); + if (Status == STATUS_SUCCESS) + { + *pu32GmrId = data.u32GmrId; + *ppvMap = (void *)(uintptr_t)data.u64UserAddress; + return true; + } + + Assert(0); + return false; +} + +/* static */ DECLCALLBACK(int) +GaDrvEnvKmt::gaEnvRegionCreate(void *pvEnv, + uint32_t u32RegionSize, + uint32_t *pu32GmrId, + void **ppvMap) +{ + GaDrvEnvKmt *pThis = (GaDrvEnvKmt *)pvEnv; + + if (pThis->mKmtCallbacks.hDevice) + { + /* That is a real device */ + bool fSuccess = vboxDdiRegionCreate(&pThis->mKmtCallbacks, u32RegionSize, pu32GmrId, ppvMap); + return fSuccess ? 0: -1; + } + + /* That is a fake device, created when WDDM adapter is initialized. */ + *ppvMap = malloc(u32RegionSize); + if (*ppvMap) + { + *pu32GmrId = 0; + return 0; + } + + return -1; +} + +static bool +vboxDdiRegionDestroy(GaKmtCallbacks *pKmtCallbacks, + uint32_t u32GmrId) +{ + VBOXDISPIFESCAPE_GAREGION data; + memset(&data, 0, sizeof(data)); + data.EscapeHdr.escapeCode = VBOXESC_GAREGION; + // data.EscapeHdr.cmdSpecific = 0; + data.u32Command = GA_REGION_CMD_DESTROY; + // data.u32NumPages = 0; + data.u32GmrId = u32GmrId; + // data.u64UserAddress = 0; + + D3DKMT_ESCAPE EscapeData; + memset(&EscapeData, 0, sizeof(EscapeData)); + EscapeData.hAdapter = pKmtCallbacks->hAdapter; + EscapeData.hDevice = pKmtCallbacks->hDevice; + EscapeData.Type = D3DKMT_ESCAPE_DRIVERPRIVATE; + // EscapeData.Flags.HardwareAccess = 0; + EscapeData.pPrivateDriverData = &data; + EscapeData.PrivateDriverDataSize = sizeof(data); + // EscapeData.hContext = 0; + + NTSTATUS Status = pKmtCallbacks->d3dkmt->pfnD3DKMTEscape(&EscapeData); + Assert(Status == STATUS_SUCCESS); + return Status == STATUS_SUCCESS; +} + +/* static */ DECLCALLBACK(void) +GaDrvEnvKmt::gaEnvRegionDestroy(void *pvEnv, + uint32_t u32GmrId, + void *pvMap) +{ + GaDrvEnvKmt *pThis = (GaDrvEnvKmt *)pvEnv; + + if (pThis->mKmtCallbacks.hDevice) + { + vboxDdiRegionDestroy(&pThis->mKmtCallbacks, u32GmrId); + } + else + { + free(pvMap); + } +} + +GaDrvEnvKmt::GaDrvEnvKmt() + : + mContextTree(0), + mSurfaceTree(0) +{ + RT_ZERO(mKmtCallbacks); + RT_ZERO(mHWInfo); + RT_ZERO(mEnv); +} + +GaDrvEnvKmt::~GaDrvEnvKmt() +{ +} + +HRESULT GaDrvEnvKmt::Init(void) +{ + mKmtCallbacks.d3dkmt = D3DKMTFunctions(); + + /* Figure out which adapter to use. */ + NTSTATUS Status = vboxDispKmtOpenAdapter2(&mKmtCallbacks.hAdapter, &mKmtCallbacks.AdapterLuid); + Assert(Status == STATUS_SUCCESS); + if (Status == STATUS_SUCCESS) + { + VBOXWDDM_QAI adapterInfo; + bool fSuccess = vboxDdiQueryAdapterInfo(&mKmtCallbacks, mKmtCallbacks.hAdapter, &adapterInfo, sizeof(adapterInfo)); + Assert(fSuccess); + if (fSuccess) + { + fSuccess = vboxDdiDeviceCreate(&mKmtCallbacks, &mKmtCallbacks.hDevice); + Assert(fSuccess); + if (fSuccess) + { + mHWInfo = adapterInfo.u.vmsvga.HWInfo; + + /* + * Success. + */ + return S_OK; + } + + vboxDdiDeviceDestroy(&mKmtCallbacks, mKmtCallbacks.hDevice); + } + + vboxDispKmtCloseAdapter(mKmtCallbacks.hAdapter); + } + + return E_FAIL; +} + +const WDDMGalliumDriverEnv *GaDrvEnvKmt::Env() +{ + if (mEnv.cb == 0) + { + mEnv.cb = sizeof(WDDMGalliumDriverEnv); + mEnv.pHWInfo = &mHWInfo; + mEnv.pvEnv = this; + mEnv.pfnContextCreate = gaEnvContextCreate; + mEnv.pfnContextDestroy = gaEnvContextDestroy; + mEnv.pfnSurfaceDefine = gaEnvSurfaceDefine; + mEnv.pfnSurfaceDestroy = gaEnvSurfaceDestroy; + mEnv.pfnRender = gaEnvRender; + mEnv.pfnFenceUnref = gaEnvFenceUnref; + mEnv.pfnFenceQuery = gaEnvFenceQuery; + mEnv.pfnFenceWait = gaEnvFenceWait; + mEnv.pfnRegionCreate = gaEnvRegionCreate; + mEnv.pfnRegionDestroy = gaEnvRegionDestroy; + } + + return &mEnv; +} + +RT_C_DECLS_BEGIN + +const WDDMGalliumDriverEnv *GaDrvEnvKmtCreate(void) +{ + GaDrvEnvKmt *p = new GaDrvEnvKmt(); + if (p) + { + HRESULT hr = p->Init(); + if (hr != S_OK) + { + delete p; + p = NULL; + } + } + return p ? p->Env() : NULL; +} + +void GaDrvEnvKmtDelete(const WDDMGalliumDriverEnv *pEnv) +{ + if (pEnv) + { + GaDrvEnvKmt *p = (GaDrvEnvKmt *)pEnv->pvEnv; + delete p; + } +} + +D3DKMT_HANDLE GaDrvEnvKmtContextHandle(const WDDMGalliumDriverEnv *pEnv, uint32_t u32Cid) +{ + GaDrvEnvKmt *p = (GaDrvEnvKmt *)pEnv->pvEnv; + return p->drvEnvKmtContextHandle(u32Cid); +} + +D3DKMT_HANDLE GaDrvEnvKmtSurfaceHandle(const WDDMGalliumDriverEnv *pEnv, uint32_t u32Sid) +{ + GaDrvEnvKmt *p = (GaDrvEnvKmt *)pEnv->pvEnv; + return p->drvEnvKmtSurfaceHandle(u32Sid); +} + +void GaDrvEnvKmtAdapterLUID(const WDDMGalliumDriverEnv *pEnv, LUID *pAdapterLuid) +{ + GaDrvEnvKmt *p = (GaDrvEnvKmt *)pEnv->pvEnv; + *pAdapterLuid = p->mKmtCallbacks.AdapterLuid; +} + +D3DKMT_HANDLE GaDrvEnvKmtAdapterHandle(const WDDMGalliumDriverEnv *pEnv) +{ + GaDrvEnvKmt *p = (GaDrvEnvKmt *)pEnv->pvEnv; + return p->mKmtCallbacks.hAdapter; +} + +D3DKMT_HANDLE GaDrvEnvKmtDeviceHandle(const WDDMGalliumDriverEnv *pEnv) +{ + GaDrvEnvKmt *p = (GaDrvEnvKmt *)pEnv->pvEnv; + return p->mKmtCallbacks.hDevice; +} + +void GaDrvEnvKmtRenderCompose(const WDDMGalliumDriverEnv *pEnv, + uint32_t u32Cid, + void *pvCommands, + uint32_t cbCommands, + ULONGLONG PresentHistoryToken) +{ + GaDrvEnvKmt *p = (GaDrvEnvKmt *)pEnv->pvEnv; + p->drvEnvKmtRenderCompose(u32Cid, pvCommands, cbCommands, PresentHistoryToken); +} + +RT_C_DECLS_END diff --git a/src/VBox/Additions/3D/win/VBoxGL/GaDrvEnvKMT.h b/src/VBox/Additions/3D/win/VBoxGL/GaDrvEnvKMT.h new file mode 100644 index 00000000..34960c01 --- /dev/null +++ b/src/VBox/Additions/3D/win/VBoxGL/GaDrvEnvKMT.h @@ -0,0 +1,48 @@ +/* $Id: GaDrvEnvKMT.h $ */ +/** @file + * VirtualBox Windows Guest Mesa3D - Gallium driver interface to the WDDM miniport driver. + */ + +/* + * Copyright (C) 2016-2020 Oracle Corporation + * + * This file is part of VirtualBox Open Source Edition (OSE), as + * available from http://www.virtualbox.org. This file is free software; + * you can redistribute it and/or modify it under the terms of the GNU + * General Public License (GPL) as published by the Free Software + * Foundation, in version 2 as it comes in the "COPYING" file of the + * VirtualBox OSE distribution. VirtualBox OSE is distributed in the + * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. + */ + +#ifndef GA_INCLUDED_SRC_3D_win_VBoxGL_GaDrvEnvKMT_h +#define GA_INCLUDED_SRC_3D_win_VBoxGL_GaDrvEnvKMT_h +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + +#include <VBoxGaDriver.h> +#include <VBoxWddmUmHlp.h> + +RT_C_DECLS_BEGIN + +const WDDMGalliumDriverEnv *GaDrvEnvKmtCreate(void); +void GaDrvEnvKmtDelete(const WDDMGalliumDriverEnv *pEnv); + +D3DKMT_HANDLE GaDrvEnvKmtContextHandle(const WDDMGalliumDriverEnv *pEnv, + uint32_t u32Cid); +D3DKMT_HANDLE GaDrvEnvKmtSurfaceHandle(const WDDMGalliumDriverEnv *pEnv, + uint32_t u32Sid); +void GaDrvEnvKmtAdapterLUID(const WDDMGalliumDriverEnv *pEnv, + LUID *pAdapterLuid); +D3DKMT_HANDLE GaDrvEnvKmtAdapterHandle(const WDDMGalliumDriverEnv *pEnv); +D3DKMT_HANDLE GaDrvEnvKmtDeviceHandle(const WDDMGalliumDriverEnv *pEnv); +void GaDrvEnvKmtRenderCompose(const WDDMGalliumDriverEnv *pEnv, + uint32_t u32Cid, + void *pvCommands, + uint32_t cbCommands, + ULONGLONG PresentHistoryToken); + +RT_C_DECLS_END + +#endif /* !GA_INCLUDED_SRC_3D_win_VBoxGL_GaDrvEnvKMT_h */ diff --git a/src/VBox/Additions/3D/win/VBoxGL/Makefile.kmk b/src/VBox/Additions/3D/win/VBoxGL/Makefile.kmk new file mode 100644 index 00000000..9ea0ea0c --- /dev/null +++ b/src/VBox/Additions/3D/win/VBoxGL/Makefile.kmk @@ -0,0 +1,113 @@ +# $Id: Makefile.kmk $ +## @file +# Sub-Makefile for VBoxGL OpenGL state tracker. +# + +# +# Copyright (C) 2018-2020 Oracle Corporation +# +# This file is part of VirtualBox Open Source Edition (OSE), as +# available from http://www.virtualbox.org. This file is free software; +# you can redistribute it and/or modify it under the terms of the GNU +# General Public License (GPL) as published by the Free Software +# Foundation, in version 2 as it comes in the "COPYING" file of the +# VirtualBox OSE distribution. VirtualBox OSE is distributed in the +# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. +# + +SUB_DEPTH = ../../../../../.. +include $(KBUILD_PATH)/subheader.kmk + +# Define this to build software OpenGL driver +#VBOX_WITH_MESA3D_GL_SOFTWARE = 1 + +DLLS += VBoxGL +DLLS.amd64 += VBoxGL-x86 + +VBoxGL_TEMPLATE = VBoxMesa3DGuestR3DllMinVista +# -wd4005: '__useHeader' : redefinition +VBoxGL_CFLAGS = -wd4005 +VBoxGL_INCS = \ + $(VBOX_PATH_3D)/win/include \ + $(VBOX_PATH_MESA)/include/GL \ + $(VBOX_PATH_MESA)/src/gallium/state_trackers/wgl \ + $(VBOX_PATH_MESA)/src/gallium/winsys/sw \ + $(VBOX_PATH_MESA)/src/gallium/drivers \ + $(PATH_ROOT)/src/VBox/Additions/WINNT/Graphics/Video \ + $(PATH_ROOT)/src/VBox/Runtime/common/table \ + $(VBOX_PATH_VMSVGA_INC) \ + $(VBOX_GRAPHICS_INCS) +VBoxGL_SOURCES = \ + $(VBOX_PATH_MESA)/src/gallium/state_trackers/wgl/opengl32.def \ + VBoxGL.rc +ifndef VBOX_WITH_MESA3D_GL_SOFTWARE +VBoxGL_SOURCES += \ + GaDrvEnvKMT.cpp \ + VBoxGL.c +else +VBoxGL_SOURCES += \ + $(VBOX_PATH_MESA)/src/gallium/targets/libgl-gdi/libgl_gdi.c +VBoxGL_SOURCES += \ + $(VBOX_PATH_MESA)/src/gallium/winsys/sw/gdi/gdi_sw_winsys.c +VBoxGL_SOURCES += \ + $(VBOX_PATH_MESA)/src/gallium/drivers/softpipe/sp_buffer.c \ + $(VBOX_PATH_MESA)/src/gallium/drivers/softpipe/sp_clear.c \ + $(VBOX_PATH_MESA)/src/gallium/drivers/softpipe/sp_context.c \ + $(VBOX_PATH_MESA)/src/gallium/drivers/softpipe/sp_compute.c \ + $(VBOX_PATH_MESA)/src/gallium/drivers/softpipe/sp_draw_arrays.c \ + $(VBOX_PATH_MESA)/src/gallium/drivers/softpipe/sp_fence.c \ + $(VBOX_PATH_MESA)/src/gallium/drivers/softpipe/sp_flush.c \ + $(VBOX_PATH_MESA)/src/gallium/drivers/softpipe/sp_fs_exec.c \ + $(VBOX_PATH_MESA)/src/gallium/drivers/softpipe/sp_image.c \ + $(VBOX_PATH_MESA)/src/gallium/drivers/softpipe/sp_prim_vbuf.c \ + $(VBOX_PATH_MESA)/src/gallium/drivers/softpipe/sp_quad_blend.c \ + $(VBOX_PATH_MESA)/src/gallium/drivers/softpipe/sp_quad_depth_test.c \ + $(VBOX_PATH_MESA)/src/gallium/drivers/softpipe/sp_quad_fs.c \ + $(VBOX_PATH_MESA)/src/gallium/drivers/softpipe/sp_quad_pipe.c \ + $(VBOX_PATH_MESA)/src/gallium/drivers/softpipe/sp_quad_stipple.c \ + $(VBOX_PATH_MESA)/src/gallium/drivers/softpipe/sp_query.c \ + $(VBOX_PATH_MESA)/src/gallium/drivers/softpipe/sp_screen.c \ + $(VBOX_PATH_MESA)/src/gallium/drivers/softpipe/sp_setup.c \ + $(VBOX_PATH_MESA)/src/gallium/drivers/softpipe/sp_state_blend.c \ + $(VBOX_PATH_MESA)/src/gallium/drivers/softpipe/sp_state_clip.c \ + $(VBOX_PATH_MESA)/src/gallium/drivers/softpipe/sp_state_derived.c \ + $(VBOX_PATH_MESA)/src/gallium/drivers/softpipe/sp_state_image.c \ + $(VBOX_PATH_MESA)/src/gallium/drivers/softpipe/sp_state_rasterizer.c \ + $(VBOX_PATH_MESA)/src/gallium/drivers/softpipe/sp_state_sampler.c \ + $(VBOX_PATH_MESA)/src/gallium/drivers/softpipe/sp_state_shader.c \ + $(VBOX_PATH_MESA)/src/gallium/drivers/softpipe/sp_state_so.c \ + $(VBOX_PATH_MESA)/src/gallium/drivers/softpipe/sp_state_surface.c \ + $(VBOX_PATH_MESA)/src/gallium/drivers/softpipe/sp_state_vertex.c \ + $(VBOX_PATH_MESA)/src/gallium/drivers/softpipe/sp_surface.c \ + $(VBOX_PATH_MESA)/src/gallium/drivers/softpipe/sp_tex_sample.c \ + $(VBOX_PATH_MESA)/src/gallium/drivers/softpipe/sp_tex_tile_cache.c \ + $(VBOX_PATH_MESA)/src/gallium/drivers/softpipe/sp_texture.c \ + $(VBOX_PATH_MESA)/src/gallium/drivers/softpipe/sp_tile_cache.c +endif +VBoxGL_LIBS = \ + $(VBOX_PATH_ADDITIONS_LIB)/VBoxWddmUmHlp$(VBOX_SUFF_LIB) \ + $(VBOX_PATH_ADDITIONS_LIB)/VBoxMesaGalliumAuxLib$(VBOX_SUFF_LIB) \ + $(VBOX_PATH_ADDITIONS_LIB)/VBoxMesaWglLib$(VBOX_SUFF_LIB) \ + $(VBOX_PATH_ADDITIONS_LIB)/VBoxMesaUtilLib$(VBOX_SUFF_LIB) \ + $(VBOX_PATH_ADDITIONS_LIB)/VBoxMesaLib$(VBOX_SUFF_LIB) + +ifdef VBOX_SIGN_ADDITIONS + VBoxGL_INSTTYPE = none + VBoxGL_DEBUG_INSTTYPE = both +endif + +# +# VBoxGL-x86 - x86 version of VBoxGL built for amd64 build +# +VBoxGL-x86_EXTENDS = VBoxGL +VBoxGL-x86_BLD_TRG_ARCH = x86 +VBoxGL-x86_LIBS = \ + $(VBOX_PATH_ADDITIONS_LIB)/VBoxWddmUmHlp-x86$(VBOX_SUFF_LIB) \ + $(VBOX_PATH_ADDITIONS_LIB)/VBoxMesaGalliumAuxLib-x86$(VBOX_SUFF_LIB) \ + $(VBOX_PATH_ADDITIONS_LIB)/VBoxMesaWglLib-x86$(VBOX_SUFF_LIB) \ + $(VBOX_PATH_ADDITIONS_LIB)/VBoxMesaUtilLib-x86$(VBOX_SUFF_LIB) \ + $(VBOX_PATH_ADDITIONS_LIB)/VBoxMesaLib-x86$(VBOX_SUFF_LIB) +VBoxGL-x86_DEFS = $(VBoxGL_DEFS) VBOX_WOW64 + +include $(FILE_KBUILD_SUB_FOOTER) + diff --git a/src/VBox/Additions/3D/win/VBoxGL/VBoxGL.c b/src/VBox/Additions/3D/win/VBoxGL/VBoxGL.c new file mode 100644 index 00000000..4621d383 --- /dev/null +++ b/src/VBox/Additions/3D/win/VBoxGL/VBoxGL.c @@ -0,0 +1,408 @@ +/* $Id: VBoxGL.c $ */ +/** @file + * VirtualBox Windows Guest Mesa3D - OpenGL driver. + */ + +/* + * Copyright (C) 2018-2020 Oracle Corporation + * + * This file is part of VirtualBox Open Source Edition (OSE), as + * available from http://www.virtualbox.org. This file is free software; + * you can redistribute it and/or modify it under the terms of the GNU + * General Public License (GPL) as published by the Free Software + * Foundation, in version 2 as it comes in the "COPYING" file of the + * VirtualBox OSE distribution. VirtualBox OSE is distributed in the + * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. + */ + +#include "GaDrvEnvKMT.h" + +#include "stw_winsys.h" +#include "stw_device.h" +#include "stw_context.h" + +#include "pipe/p_state.h" +#include "svga3d_reg.h" + +#include <iprt/asm.h> + +#include <common/wddm/VBoxMPIf.h> + +static const char *g_pszSvgaDll = +#ifdef VBOX_WOW64 + "VBoxSVGA-x86.dll" +#else + "VBoxSVGA.dll" +#endif +; + +static struct GaDrvFunctions +{ + PFNGaDrvScreenCreate pfnGaDrvScreenCreate; + PFNGaDrvScreenDestroy pfnGaDrvScreenDestroy; + PFNGaDrvGetWDDMEnv pfnGaDrvGetWDDMEnv; + PFNGaDrvGetContextId pfnGaDrvGetContextId; + PFNGaDrvGetSurfaceId pfnGaDrvGetSurfaceId; + PFNGaDrvContextFlush pfnGaDrvContextFlush; +} g_drvfuncs; + + +static HMODULE gaDrvLoadSVGA(struct GaDrvFunctions *pDrvFuncs) +{ + struct VBOXWDDMDLLPROC aDrvProcs[] = + { + { "GaDrvScreenCreate", (FARPROC *)&pDrvFuncs->pfnGaDrvScreenCreate }, + { "GaDrvScreenDestroy", (FARPROC *)&pDrvFuncs->pfnGaDrvScreenDestroy }, + { "GaDrvGetWDDMEnv", (FARPROC *)&pDrvFuncs->pfnGaDrvGetWDDMEnv }, + { "GaDrvGetContextId", (FARPROC *)&pDrvFuncs->pfnGaDrvGetContextId }, + { "GaDrvGetSurfaceId", (FARPROC *)&pDrvFuncs->pfnGaDrvGetSurfaceId }, + { "GaDrvContextFlush", (FARPROC *)&pDrvFuncs->pfnGaDrvContextFlush }, + { NULL, NULL } + }; + + HMODULE hmod = VBoxWddmLoadSystemDll(g_pszSvgaDll); + if (hmod) + { + VBoxWddmLoadAdresses(hmod, aDrvProcs); + } + return hmod; +} + +struct stw_shared_surface +{ + D3DKMT_HANDLE hResource; + D3DKMT_HANDLE hSurface; + uint32_t u32Sid; +}; + +static NTSTATUS vboxKmtPresent(D3DKMT_HANDLE hContext, HWND hwnd, D3DKMT_HANDLE hSource, LONG lWidth, LONG lHeight) +{ + RECT r; + r.left = 0; + r.top = 0; + r.right = lWidth; + r.bottom = lHeight; + + D3DKMT_PRESENT PresentData; + memset(&PresentData, 0, sizeof(PresentData)); + PresentData.hContext = hContext; + PresentData.hWindow = hwnd; + PresentData.hSource = hSource; + PresentData.hDestination = 0; + PresentData.Flags.Blt = 1; + PresentData.Flags.SrcRectValid = 1; + PresentData.Flags.DstRectValid = 1; + PresentData.SrcRect = r; + PresentData.SubRectCnt = 1; + PresentData.pSrcSubRects = &r; + PresentData.DstRect = r; + + D3DKMTFUNCTIONS const *d3dkmt = D3DKMTFunctions(); + NTSTATUS Status = d3dkmt->pfnD3DKMTPresent(&PresentData); + return Status; +} + +NTSTATUS vboxKmtOpenSharedSurface(D3DKMT_HANDLE hDevice, D3DKMT_HANDLE hSharedSurface, struct stw_shared_surface *pSurf) +{ + D3DKMTFUNCTIONS const *d3dkmt = D3DKMTFunctions(); + + D3DKMT_QUERYRESOURCEINFO QueryResourceInfoData; + memset(&QueryResourceInfoData, 0, sizeof(QueryResourceInfoData)); + QueryResourceInfoData.hDevice = hDevice; + QueryResourceInfoData.hGlobalShare = hSharedSurface; + + NTSTATUS Status = d3dkmt->pfnD3DKMTQueryResourceInfo(&QueryResourceInfoData); + if (Status == STATUS_SUCCESS) + { + D3DDDI_OPENALLOCATIONINFO OpenAllocationInfoData; + memset(&OpenAllocationInfoData, 0, sizeof(OpenAllocationInfoData)); + + D3DKMT_OPENRESOURCE OpenResourceData; + memset(&OpenResourceData, 0, sizeof(OpenResourceData)); + OpenResourceData.hDevice = hDevice; + OpenResourceData.hGlobalShare = hSharedSurface; + OpenResourceData.NumAllocations = 1; + OpenResourceData.pOpenAllocationInfo = &OpenAllocationInfoData; + if (QueryResourceInfoData.PrivateRuntimeDataSize) + { + OpenResourceData.pPrivateRuntimeData = malloc(QueryResourceInfoData.PrivateRuntimeDataSize); + if (OpenResourceData.pPrivateRuntimeData == NULL) + { + Status = STATUS_NOT_SUPPORTED; + } + OpenResourceData.PrivateRuntimeDataSize = QueryResourceInfoData.PrivateRuntimeDataSize; + } + if (QueryResourceInfoData.ResourcePrivateDriverDataSize) + { + OpenResourceData.pResourcePrivateDriverData = malloc(QueryResourceInfoData.ResourcePrivateDriverDataSize); + if (OpenResourceData.pResourcePrivateDriverData == NULL) + { + Status = STATUS_NOT_SUPPORTED; + } + OpenResourceData.ResourcePrivateDriverDataSize = QueryResourceInfoData.ResourcePrivateDriverDataSize; + } + if (QueryResourceInfoData.TotalPrivateDriverDataSize) + { + OpenResourceData.pTotalPrivateDriverDataBuffer = malloc(QueryResourceInfoData.TotalPrivateDriverDataSize); + if (OpenResourceData.pTotalPrivateDriverDataBuffer == NULL) + { + Status = STATUS_NOT_SUPPORTED; + } + OpenResourceData.TotalPrivateDriverDataBufferSize = QueryResourceInfoData.TotalPrivateDriverDataSize; + } + + if (Status == STATUS_SUCCESS) + { + Status = d3dkmt->pfnD3DKMTOpenResource(&OpenResourceData); + if (Status == STATUS_SUCCESS) + { + Assert(OpenAllocationInfoData.PrivateDriverDataSize == sizeof(VBOXWDDM_ALLOCINFO)); + VBOXWDDM_ALLOCINFO *pVBoxAllocInfo = (VBOXWDDM_ALLOCINFO *)OpenAllocationInfoData.pPrivateDriverData; + pSurf->hResource = OpenResourceData.hResource; + pSurf->hSurface = OpenAllocationInfoData.hAllocation; + pSurf->u32Sid = pVBoxAllocInfo->hostID; + } + } + + if (OpenResourceData.pPrivateRuntimeData != NULL) + { + free(OpenResourceData.pPrivateRuntimeData); + } + if (OpenResourceData.pResourcePrivateDriverData != NULL) + { + free(OpenResourceData.pResourcePrivateDriverData); + } + if (OpenResourceData.pTotalPrivateDriverDataBuffer != NULL) + { + free(OpenResourceData.pTotalPrivateDriverDataBuffer); + } + } + + return Status; +} + +NTSTATUS vboxKmtCloseSharedSurface(D3DKMT_HANDLE hDevice, struct stw_shared_surface *pSurf) +{ + D3DKMTFUNCTIONS const *d3dkmt = D3DKMTFunctions(); + + D3DKMT_DESTROYALLOCATION DestroyAllocationData; + memset(&DestroyAllocationData, 0, sizeof(DestroyAllocationData)); + DestroyAllocationData.hDevice = hDevice; + DestroyAllocationData.hResource = pSurf->hResource; + /* "If the OpenGL ICD sets the handle in the hResource member to a non-NULL value, + * the ICD must set phAllocationList to NULL." and + * "the AllocationCount member is ignored by the OpenGL runtime." + */ + // DestroyAllocationData.phAllocationList = NULL; + // DestroyAllocationData.AllocationCount = 0; + + NTSTATUS Status = d3dkmt->pfnD3DKMTDestroyAllocation(&DestroyAllocationData); + Assert(Status == STATUS_SUCCESS); + return Status; +} + + +static struct pipe_screen * +wddm_screen_create(void) +{ + struct pipe_screen *screen = NULL; + + if (gaDrvLoadSVGA(&g_drvfuncs)) + { + WDDMGalliumDriverEnv const *pEnv = GaDrvEnvKmtCreate(); + if (pEnv) + { + /// @todo pEnv to include destructor callback, to be called from winsys screen destructor? + screen = g_drvfuncs.pfnGaDrvScreenCreate(pEnv); + } + } + + return screen; +} + +static void +wddm_present(struct pipe_screen *screen, + struct pipe_resource *res, + HDC hDC) +{ + struct stw_context *ctx = stw_current_context(); + struct pipe_context *pipe = ctx->st->pipe; + + const WDDMGalliumDriverEnv *pEnv = g_drvfuncs.pfnGaDrvGetWDDMEnv(screen); + if (pEnv) + { + /* Get context and kernel-mode handle of the resource. */ + uint32_t u32Cid = g_drvfuncs.pfnGaDrvGetContextId(pipe); + D3DKMT_HANDLE hContext = GaDrvEnvKmtContextHandle(pEnv, u32Cid); + + uint32_t u32SourceSid = g_drvfuncs.pfnGaDrvGetSurfaceId(screen, res); + D3DKMT_HANDLE hSource = GaDrvEnvKmtSurfaceHandle(pEnv, u32SourceSid); + + HWND hwnd = WindowFromDC(hDC); + + vboxKmtPresent(hContext, hwnd, hSource, res->width0, res->height0); + } +} + +static boolean +wddm_get_adapter_luid(struct pipe_screen *screen, + LUID *pAdapterLuid) +{ + const WDDMGalliumDriverEnv *pEnv = g_drvfuncs.pfnGaDrvGetWDDMEnv(screen); + if (pEnv) + { + GaDrvEnvKmtAdapterLUID(pEnv, pAdapterLuid); + return true; + } + + return false; +} + +static struct stw_shared_surface * +wddm_shared_surface_open(struct pipe_screen *screen, + HANDLE hSharedSurface) +{ + struct stw_shared_surface *surface = NULL; + + const WDDMGalliumDriverEnv *pEnv = g_drvfuncs.pfnGaDrvGetWDDMEnv(screen); + if (pEnv) + { + surface = (struct stw_shared_surface *)malloc(sizeof(struct stw_shared_surface)); + if (surface) + { + D3DKMT_HANDLE hDevice = GaDrvEnvKmtDeviceHandle(pEnv); + NTSTATUS Status = vboxKmtOpenSharedSurface(hDevice, (D3DKMT_HANDLE)hSharedSurface, surface); + if (Status != STATUS_SUCCESS) + { + free(surface); + surface = NULL; + } + } + } + return surface; +} + +static void +wddm_shared_surface_close(struct pipe_screen *screen, + struct stw_shared_surface *surface) +{ + const WDDMGalliumDriverEnv *pEnv = g_drvfuncs.pfnGaDrvGetWDDMEnv(screen); + if (pEnv) + { + D3DKMT_HANDLE hDevice = GaDrvEnvKmtDeviceHandle(pEnv); + vboxKmtCloseSharedSurface(hDevice, surface); + } + free(surface); +} + +static void +wddm_compose(struct pipe_screen *screen, + struct pipe_resource *res, + struct stw_shared_surface *dest, + LPCRECT pRect, + ULONGLONG PresentHistoryToken) +{ + struct stw_context *ctx = stw_current_context(); + struct pipe_context *pipe = ctx->st->pipe; + + /* The ICD asked to present something, make sure that any outstanding commends are submitted. */ + g_drvfuncs.pfnGaDrvContextFlush(pipe); + + uint32_t u32SourceSid = g_drvfuncs.pfnGaDrvGetSurfaceId(screen, res); + + /* Generate SVGA_3D_CMD_SURFACE_COPY command for these resources. */ + struct + { + SVGA3dCmdHeader header; + SVGA3dCmdSurfaceCopy surfaceCopy; + SVGA3dCopyBox box; + } command; + + command.header.id = SVGA_3D_CMD_SURFACE_COPY; + command.header.size = sizeof(command) - sizeof(SVGA3dCmdHeader); + + command.surfaceCopy.src.sid = u32SourceSid; + command.surfaceCopy.src.face = 0; + command.surfaceCopy.src.mipmap = 0; + command.surfaceCopy.dest.sid = dest->u32Sid; + command.surfaceCopy.dest.face = 0; + command.surfaceCopy.dest.mipmap = 0; + + command.box.x = pRect->left; + command.box.y = pRect->top; + command.box.z = 0; + command.box.w = pRect->right - pRect->left; + command.box.h = pRect->bottom - pRect->top; + command.box.d = 1; + command.box.srcx = 0; + command.box.srcy = 0; + command.box.srcz = 0; + + const WDDMGalliumDriverEnv *pEnv = g_drvfuncs.pfnGaDrvGetWDDMEnv(screen); + if (pEnv) + { + uint32_t u32Cid = g_drvfuncs.pfnGaDrvGetContextId(pipe); + GaDrvEnvKmtRenderCompose(pEnv, u32Cid, &command, sizeof(command), PresentHistoryToken); + } +} + +static const struct stw_winsys stw_winsys = { + wddm_screen_create, + wddm_present, + wddm_get_adapter_luid, + wddm_shared_surface_open, + wddm_shared_surface_close, + wddm_compose +}; + +BOOL WINAPI DllMain(HINSTANCE hDLLInst, + DWORD fdwReason, + LPVOID lpvReserved) +{ + RT_NOREF2(hDLLInst, lpvReserved); + + switch (fdwReason) + { + case DLL_PROCESS_ATTACH: + D3DKMTLoad(); + stw_init(&stw_winsys); + stw_init_thread(); + break; + + case DLL_PROCESS_DETACH: + break; + + case DLL_THREAD_ATTACH: + stw_init_thread(); + break; + + case DLL_THREAD_DETACH: + stw_cleanup_thread(); + break; + + default: + if (lpvReserved == NULL) + { + // We're being unloaded from the process. + stw_cleanup_thread(); + stw_cleanup(); + } + else + { + // Process itself is terminating, and all threads and modules are + // being detached. + // + // The order threads (including llvmpipe rasterizer threads) are + // destroyed can not be relied up, so it's not safe to cleanup. + // + // However global destructors (e.g., LLVM's) will still be called, and + // if Microsoft OPENGL32.DLL's DllMain is called after us, it will + // still try to invoke DrvDeleteContext to destroys all outstanding, + // so set stw_dev to NULL to return immediately if that happens. + stw_dev = NULL; + } + break; + } + + return TRUE; +} diff --git a/src/VBox/Additions/3D/win/VBoxGL/VBoxGL.rc b/src/VBox/Additions/3D/win/VBoxGL/VBoxGL.rc new file mode 100644 index 00000000..1ed2caf3 --- /dev/null +++ b/src/VBox/Additions/3D/win/VBoxGL/VBoxGL.rc @@ -0,0 +1,56 @@ +/* $Id: VBoxGL.rc $ */ +/** @file + * VBoxGL - Resource file containing version info and icon. + */ + +/* + * Copyright (C) 2018-2020 Oracle Corporation + * + * This file is part of VirtualBox Open Source Edition (OSE), as + * available from http://www.virtualbox.org. This file is free software; + * you can redistribute it and/or modify it under the terms of the GNU + * General Public License (GPL) as published by the Free Software + * Foundation, in version 2 as it comes in the "COPYING" file of the + * VirtualBox OSE distribution. VirtualBox OSE is distributed in the + * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. + */ + +#include <windows.h> +#include <VBox/version.h> + +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US + +VS_VERSION_INFO VERSIONINFO + FILEVERSION VBOX_RC_FILE_VERSION + PRODUCTVERSION VBOX_RC_FILE_VERSION + FILEFLAGSMASK VS_FFI_FILEFLAGSMASK + FILEFLAGSMASK VS_FFI_FILEFLAGSMASK + FILEFLAGS VBOX_RC_FILE_FLAGS + FILEOS VBOX_RC_FILE_OS + FILETYPE VBOX_RC_TYPE_DLL + FILESUBTYPE VFT2_UNKNOWN +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904b0" + BEGIN + VALUE "FileDescription", "VirtualBox OpenGL Mesa State Tracker\0" + VALUE "InternalName", "VBoxGL\0" +#ifdef VBOX_WOW64 + VALUE "OriginalFilename", "VBoxGL-x86.DLL\0" +#else + VALUE "OriginalFilename", "VBoxGL.DLL\0" +#endif + VALUE "CompanyName", VBOX_RC_COMPANY_NAME + VALUE "FileVersion", VBOX_RC_FILE_VERSION_STR + VALUE "LegalCopyright", VBOX_RC_LEGAL_COPYRIGHT + VALUE "ProductName", VBOX_RC_PRODUCT_NAME_GA_STR + VALUE "ProductVersion", VBOX_RC_PRODUCT_VERSION_STR + VBOX_RC_MORE_STRINGS + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1200 + END +END diff --git a/src/VBox/Additions/3D/win/VBoxICD/Makefile.kmk b/src/VBox/Additions/3D/win/VBoxICD/Makefile.kmk new file mode 100644 index 00000000..80733a3c --- /dev/null +++ b/src/VBox/Additions/3D/win/VBoxICD/Makefile.kmk @@ -0,0 +1,69 @@ +# $Id: Makefile.kmk $ +## @file +# Sub-Makefile for OpenGL ICD loader. +# + +# +# Copyright (C) 2018-2020 Oracle Corporation +# +# This file is part of VirtualBox Open Source Edition (OSE), as +# available from http://www.virtualbox.org. This file is free software; +# you can redistribute it and/or modify it under the terms of the GNU +# General Public License (GPL) as published by the Free Software +# Foundation, in version 2 as it comes in the "COPYING" file of the +# VirtualBox OSE distribution. VirtualBox OSE is distributed in the +# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. +# + +SUB_DEPTH = ../../../../../.. +include $(KBUILD_PATH)/subheader.kmk + +VBOX_GL_ICD_DEF_FILE = $(VBOX_PATH_MESA)/src/gallium/state_trackers/wgl/opengl32.mingw.def + +DLLS += VBoxICD +DLLS.amd64 += VBoxICD-x86 + +VBoxICD_TEMPLATE = VBoxMesa3DGuestR3DllMinVista +# -wd4005: '__useHeader' : redefinition +VBoxICD_CFLAGS = -wd4005 +VBoxICD_INCS = \ + $(VBOX_PATH_3D)/win/include \ + $(PATH_ROOT)/src/VBox/Additions/WINNT/Graphics/Video \ + $(VBOX_GRAPHICS_INCS) +VBoxICD_SOURCES = \ + $(VBOX_PATH_MESA)/src/gallium/state_trackers/wgl/opengl32.def \ + $(VBoxICD_0_OUTDIR)/forwarders.asm \ + $(VBoxICD_0_OUTDIR)/pfns.c \ + VBoxICD.c \ + VBoxICD.rc +VBoxICD_CLEAN = \ + $(VBoxICD_0_OUTDIR)/forwarders.asm \ + $(VBoxICD_0_OUTDIR)/pfns.c +VBoxICD_LIBS = \ + $(VBOX_PATH_ADDITIONS_LIB)/VBoxWddmUmHlp$(VBOX_SUFF_LIB) + +$$(VBoxICD_0_OUTDIR)/forwarders.asm: \ + $(PATH_SUB_CURRENT)/icd_forwarders.py $(VBOX_GL_ICD_DEF_FILE) | $$(dir $$@) + $(call MSG_GENERATE,python,$@,$(VBOX_GL_ICD_DEF_FILE)) + $(QUIET)$(VBOX_BLD_PYTHON) $< $(VBOX_GL_ICD_DEF_FILE) $@ +$$(VBoxICD_0_OUTDIR)/pfns.c: \ + $(PATH_SUB_CURRENT)/icd_pfns.py $(VBOX_GL_ICD_DEF_FILE) | $$(dir $$@) + $(call MSG_GENERATE,python,$@,$(VBOX_GL_ICD_DEF_FILE)) + $(QUIET)$(VBOX_BLD_PYTHON) $< $(VBOX_GL_ICD_DEF_FILE) $@ + +ifdef VBOX_SIGN_ADDITIONS +VBoxICD_INSTTYPE = none +VBoxICD_DEBUG_INSTTYPE = both +endif + +# +# x86 version built for amd64 build +# +VBoxICD-x86_EXTENDS = VBoxICD +VBoxICD-x86_BLD_TRG_ARCH = x86 +VBoxICD-x86_LIBS = \ + $(VBOX_PATH_ADDITIONS_LIB)/VBoxWddmUmHlp-x86$(VBOX_SUFF_LIB) +VBoxICD-x86_DEFS = $(VBoxICD_DEFS) VBOX_WOW64 + +include $(FILE_KBUILD_SUB_FOOTER) + diff --git a/src/VBox/Additions/3D/win/VBoxICD/VBoxICD.c b/src/VBox/Additions/3D/win/VBoxICD/VBoxICD.c new file mode 100644 index 00000000..5c37f699 --- /dev/null +++ b/src/VBox/Additions/3D/win/VBoxICD/VBoxICD.c @@ -0,0 +1,155 @@ +/* $Id: VBoxICD.c $ */ +/** @file + * VirtualBox Windows Guest Mesa3D - OpenGL driver loader. + */ + +/* + * Copyright (C) 2018-2020 Oracle Corporation + * + * This file is part of VirtualBox Open Source Edition (OSE), as + * available from http://www.virtualbox.org. This file is free software; + * you can redistribute it and/or modify it under the terms of the GNU + * General Public License (GPL) as published by the Free Software + * Foundation, in version 2 as it comes in the "COPYING" file of the + * VirtualBox OSE distribution. VirtualBox OSE is distributed in the + * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. + */ + +#include <VBoxWddmUmHlp.h> + +#include <common/wddm/VBoxMPIf.h> + +static const char *g_pszGalliumDll = +#ifdef VBOX_WOW64 + "VBoxGL-x86.dll" +#else + "VBoxGL.dll" +#endif +; + +static const char *g_pszChromiumDll = +#ifdef VBOX_WOW64 + "VBoxOGL-x86.dll" +#else + "VBoxOGL.dll" +#endif +; + +extern struct VBOXWDDMDLLPROC aIcdProcs[]; + +HMODULE volatile g_hmodICD = NULL; + +static NTSTATUS +vboxDdiQueryAdapterInfo(D3DKMT_HANDLE hAdapter, + VBOXWDDM_QAI *pAdapterInfo, + uint32_t cbAdapterInfo) +{ + NTSTATUS Status; + D3DKMTFUNCTIONS const *d3dkmt = D3DKMTFunctions(); + + if (d3dkmt->pfnD3DKMTQueryAdapterInfo) + { + D3DKMT_QUERYADAPTERINFO QAI; + memset(&QAI, 0, sizeof(QAI)); + QAI.hAdapter = hAdapter; + QAI.Type = KMTQAITYPE_UMDRIVERPRIVATE; + QAI.pPrivateDriverData = pAdapterInfo; + QAI.PrivateDriverDataSize = cbAdapterInfo; + + Status = d3dkmt->pfnD3DKMTQueryAdapterInfo(&QAI); + } + else + { + Status = STATUS_NOT_SUPPORTED; + } + + return Status; +} + +void VBoxLoadICD(void) +{ + NTSTATUS Status; + D3DKMT_HANDLE hAdapter = 0; + + D3DKMTLoad(); + + Status = vboxDispKmtOpenAdapter(&hAdapter); + if (Status == STATUS_SUCCESS) + { + VBOXWDDM_QAI adapterInfo; + Status = vboxDdiQueryAdapterInfo(hAdapter, &adapterInfo, sizeof(adapterInfo)); + if (Status == STATUS_SUCCESS) + { + const char *pszDll = NULL; + switch (adapterInfo.enmHwType) + { + case VBOXVIDEO_HWTYPE_VBOX: pszDll = g_pszChromiumDll; break; + default: + case VBOXVIDEO_HWTYPE_VMSVGA: pszDll = g_pszGalliumDll; break; + } + + if (pszDll) + { + g_hmodICD = VBoxWddmLoadSystemDll(pszDll); + if (g_hmodICD) + { + VBoxWddmLoadAdresses(g_hmodICD, aIcdProcs); + } + } + } + + vboxDispKmtCloseAdapter(hAdapter); + } +} + +/* + * MSDN says: + * "You should never perform the following tasks from within DllMain: + * Call LoadLibrary or LoadLibraryEx (either directly or indirectly)." + * + * However it turned out that loading the real ICD from DLL_PROCESS_ATTACH works, + * and loading it in a lazy way fails for unknown reason on 64 bit Windows. + * + * So just call VBoxLoadICD from DLL_PROCESS_ATTACH. + */ +BOOL WINAPI DllMain(HINSTANCE hDLLInst, + DWORD fdwReason, + LPVOID lpvReserved) +{ + RT_NOREF(hDLLInst); + + switch (fdwReason) + { + case DLL_PROCESS_ATTACH: + VBoxLoadICD(); + break; + + case DLL_PROCESS_DETACH: + if (lpvReserved == NULL) + { + /* "The DLL is being unloaded because of a call to FreeLibrary." */ + if (g_hmodICD) + { + FreeLibrary(g_hmodICD); + g_hmodICD = NULL; + } + } + else + { + /* "The DLL is being unloaded due to process termination." */ + /* Do not bother. */ + } + break; + + case DLL_THREAD_ATTACH: + break; + + case DLL_THREAD_DETACH: + break; + + default: + break; + } + + return TRUE; +} diff --git a/src/VBox/Additions/3D/win/VBoxICD/VBoxICD.rc b/src/VBox/Additions/3D/win/VBoxICD/VBoxICD.rc new file mode 100644 index 00000000..2aeadb30 --- /dev/null +++ b/src/VBox/Additions/3D/win/VBoxICD/VBoxICD.rc @@ -0,0 +1,56 @@ +/* $Id: VBoxICD.rc $ */ +/** @file + * VBoxGL - Resource file containing version info and icon. + */ + +/* + * Copyright (C) 2018-2020 Oracle Corporation + * + * This file is part of VirtualBox Open Source Edition (OSE), as + * available from http://www.virtualbox.org. This file is free software; + * you can redistribute it and/or modify it under the terms of the GNU + * General Public License (GPL) as published by the Free Software + * Foundation, in version 2 as it comes in the "COPYING" file of the + * VirtualBox OSE distribution. VirtualBox OSE is distributed in the + * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. + */ + +#include <windows.h> +#include <VBox/version.h> + +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US + +VS_VERSION_INFO VERSIONINFO + FILEVERSION VBOX_RC_FILE_VERSION + PRODUCTVERSION VBOX_RC_FILE_VERSION + FILEFLAGSMASK VS_FFI_FILEFLAGSMASK + FILEFLAGSMASK VS_FFI_FILEFLAGSMASK + FILEFLAGS VBOX_RC_FILE_FLAGS + FILEOS VBOX_RC_FILE_OS + FILETYPE VBOX_RC_TYPE_DLL + FILESUBTYPE VFT2_UNKNOWN +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904b0" + BEGIN + VALUE "FileDescription", "VirtualBox OpenGL ICD Loader\0" + VALUE "InternalName", "VBoxICD\0" +#ifdef VBOX_WOW64 + VALUE "OriginalFilename", "VBoxICD-x86.dll\0" +#else + VALUE "OriginalFilename", "VBoxICD.dll\0" +#endif + VALUE "CompanyName", VBOX_RC_COMPANY_NAME + VALUE "FileVersion", VBOX_RC_FILE_VERSION_STR + VALUE "LegalCopyright", VBOX_RC_LEGAL_COPYRIGHT + VALUE "ProductName", VBOX_RC_PRODUCT_NAME_GA_STR + VALUE "ProductVersion", VBOX_RC_PRODUCT_VERSION_STR + VBOX_RC_MORE_STRINGS + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1200 + END +END diff --git a/src/VBox/Additions/3D/win/VBoxICD/icd_forwarders.py b/src/VBox/Additions/3D/win/VBoxICD/icd_forwarders.py new file mode 100755 index 00000000..b67671e7 --- /dev/null +++ b/src/VBox/Additions/3D/win/VBoxICD/icd_forwarders.py @@ -0,0 +1,95 @@ +""" +Copyright (C) 2018-2020 Oracle Corporation + +This file is part of VirtualBox Open Source Edition (OSE), as +available from http://www.virtualbox.org. This file is free software; +you can redistribute it and/or modify it under the terms of the GNU +General Public License (GPL) as published by the Free Software +Foundation, in version 2 as it comes in the "COPYING" file of the +VirtualBox OSE distribution. VirtualBox OSE is distributed in the +hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. +""" + +import sys + +def GenerateForwarders(): + + # Get list of functions. + exports_file = open(sys.argv[1], "r") + if not exports_file: + print("Error: couldn't open %s file!" % filename) + sys.exit() + + names = [] + cbArgs = [] + for line in exports_file.readlines(): + line = line.strip() + if len(line) > 0 and line[0] != ';' and line != 'EXPORTS': + # Parse 'glAccum = glAccum@8' + words = line.split('=', 1) + + # Function name + names.append(words[0].strip()) + + # Size of arguments in bytes + words = words[1].split('@') + cbArgs.append(words[1].strip()) + + exports_file.close() + + + # + # Assembler forwarders + # + asm_file = open(sys.argv[2], "w") + if not asm_file: + print("Error: couldn't open %s file!" % filename) + sys.exit() + + asm_file.write('%include "iprt/asmdefs.mac"\n') + asm_file.write('\n') + asm_file.write(';;;; Enable ICD_LAZY_LOAD to lazy load the ICD DLL (does not work on Win64)\n') + asm_file.write('; %define ICD_LAZY_LOAD 1\n') + asm_file.write('\n') + asm_file.write('%ifdef RT_ARCH_AMD64\n') + asm_file.write('%define PTR_SIZE_PREFIX qword\n') + asm_file.write('%else ; X86\n') + asm_file.write('%define PTR_SIZE_PREFIX dword\n') + asm_file.write('%endif\n') + asm_file.write('\n') + asm_file.write('%ifdef ICD_LAZY_LOAD\n') + asm_file.write('extern NAME(VBoxLoadICD)\n') + asm_file.write('%endif\n') + asm_file.write('extern NAME(g_hmodICD)\n') + + for index in range(len(names)): + fn = names[index] + cbRet = cbArgs[index] + asm_file.write('\n') + asm_file.write('BEGINPROC_EXPORTED %s\n' % fn) + asm_file.write(' extern NAME(pfn_%s)\n' % fn) + asm_file.write('; int3\n') + asm_file.write('%ifdef ICD_LAZY_LOAD\n') + asm_file.write(' mov xAX, PTR_SIZE_PREFIX NAME(g_hmodICD)\n') + asm_file.write(' mov xAX, [xAX]\n') + asm_file.write(' or xAX, xAX\n') + asm_file.write(' jnz l_icd_loaded_%s\n' % fn) + asm_file.write(' call NAME(VBoxLoadICD)\n') + asm_file.write('l_icd_loaded_%s:\n' % fn) + asm_file.write('%endif\n') + asm_file.write(' mov xAX, PTR_SIZE_PREFIX NAME(pfn_%s)\n' % fn) + asm_file.write(' mov xAX, [xAX]\n') + asm_file.write(' or xAX, xAX\n') + asm_file.write(' jnz l_jmp_to_%s\n' % fn) + asm_file.write('%ifdef RT_ARCH_AMD64\n') + asm_file.write(' ret\n') + asm_file.write('%else ; X86\n') + asm_file.write(' ret %s\n' % cbRet) + asm_file.write('%endif\n') + asm_file.write('l_jmp_to_%s:\n' % fn) + asm_file.write(' jmp xAX\n') + asm_file.write('ENDPROC %s\n' % fn) + + asm_file.close() + +GenerateForwarders() diff --git a/src/VBox/Additions/3D/win/VBoxICD/icd_pfns.py b/src/VBox/Additions/3D/win/VBoxICD/icd_pfns.py new file mode 100755 index 00000000..7c93a7c2 --- /dev/null +++ b/src/VBox/Additions/3D/win/VBoxICD/icd_pfns.py @@ -0,0 +1,63 @@ +""" +Copyright (C) 2018-2020 Oracle Corporation + +This file is part of VirtualBox Open Source Edition (OSE), as +available from http://www.virtualbox.org. This file is free software; +you can redistribute it and/or modify it under the terms of the GNU +General Public License (GPL) as published by the Free Software +Foundation, in version 2 as it comes in the "COPYING" file of the +VirtualBox OSE distribution. VirtualBox OSE is distributed in the +hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. +""" + +import sys + +def GeneratePfns(): + + # Get list of functions. + exports_file = open(sys.argv[1], "r") + if not exports_file: + print("Error: couldn't open %s file!" % filename) + sys.exit() + + names = [] + for line in exports_file.readlines(): + line = line.strip() + if len(line) > 0 and line[0] != ';' and line != 'EXPORTS': + # Parse 'glAccum = glAccum@8' + words = line.split('=') + + # Function name + names.append(words[0].strip()) + + exports_file.close() + + + # + # C loader data + # + c_file = open(sys.argv[2], "w") + if not c_file: + print("Error: couldn't open %s file!" % filename) + sys.exit() + + c_file.write('#include <iprt/win/windows.h>\n') + c_file.write('#include <VBoxWddmUmHlp.h>\n') + c_file.write('\n') + + for index in range(len(names)): + fn = names[index] + c_file.write('FARPROC pfn_%s;\n' % fn) + c_file.write('\n') + + c_file.write("struct VBOXWDDMDLLPROC aIcdProcs[] =\n") + c_file.write('{\n') + for index in range(len(names)): + fn = names[index] + c_file.write(' { "%s", &pfn_%s },\n' % (fn, fn) ) + c_file.write(' { NULL, NULL }\n') + c_file.write('};\n') + + c_file.close() + +GeneratePfns() diff --git a/src/VBox/Additions/3D/win/VBoxNine/Makefile.kmk b/src/VBox/Additions/3D/win/VBoxNine/Makefile.kmk new file mode 100644 index 00000000..f3a24cac --- /dev/null +++ b/src/VBox/Additions/3D/win/VBoxNine/Makefile.kmk @@ -0,0 +1,61 @@ +# $Id: Makefile.kmk $ +## @file +# Sub-Makefile for VBoxNine D3D9 state tracker. +# + +# +# Copyright (C) 2016-2020 Oracle Corporation +# +# This file is part of VirtualBox Open Source Edition (OSE), as +# available from http://www.virtualbox.org. This file is free software; +# you can redistribute it and/or modify it under the terms of the GNU +# General Public License (GPL) as published by the Free Software +# Foundation, in version 2 as it comes in the "COPYING" file of the +# VirtualBox OSE distribution. VirtualBox OSE is distributed in the +# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. +# + +SUB_DEPTH = ../../../../../.. +include $(KBUILD_PATH)/subheader.kmk + +DLLS += VBoxNine +DLLS.amd64 += VBoxNine-x86 + +VBoxNine_TEMPLATE = VBoxMesa3DGuestR3DllMinVista +# -wd4100: unreferenced formal parameter +# -wd4200: nonstandard extension used : zero-sized array in struct/union +# -wd4245: 'return' : conversion from 'int' to 'unsigned int', signed/unsigned mismatch +# -wd4255: no function prototype given +# -wd4668: 'something' is not defined as a preprocessor macro, replacing with '0' for '#if/#elif' +VBoxNine_CFLAGS = -wd4100 -wd4200 -wd4245 -wd4255 -wd4668 +VBoxNine_INCS = \ + $(VBOX_PATH_MESA)/src/gallium/state_trackers/nine +VBoxNine_SOURCES = \ + VBoxNine.c \ + VBoxNine.rc \ + VBoxNine.def +VBoxNine_LIBS = \ + $(VBOX_PATH_ADDITIONS_LIB)/VBoxWddmUmHlp$(VBOX_SUFF_LIB) \ + $(VBOX_PATH_ADDITIONS_LIB)/VBoxMesaGalliumAuxLib$(VBOX_SUFF_LIB) \ + $(VBOX_PATH_ADDITIONS_LIB)/VBoxMesaUtilLib$(VBOX_SUFF_LIB) \ + $(VBOX_PATH_ADDITIONS_LIB)/VBoxMesaNineLib$(VBOX_SUFF_LIB) + +ifdef VBOX_SIGN_ADDITIONS + VBoxNine_INSTTYPE = none + VBoxNine_DEBUG_INSTTYPE = both +endif + +# +# VBoxNine-x86 - x86 version of VBoxNine built for amd64 build +# +VBoxNine-x86_EXTENDS = VBoxNine +VBoxNine-x86_BLD_TRG_ARCH = x86 +VBoxNine-x86_LIBS = \ + $(VBOX_PATH_ADDITIONS_LIB)/VBoxWddmUmHlp-x86$(VBOX_SUFF_LIB) \ + $(VBOX_PATH_ADDITIONS_LIB)/VBoxMesaGalliumAuxLib-x86$(VBOX_SUFF_LIB) \ + $(VBOX_PATH_ADDITIONS_LIB)/VBoxMesaUtilLib-x86$(VBOX_SUFF_LIB) \ + $(VBOX_PATH_ADDITIONS_LIB)/VBoxMesaNineLib-x86$(VBOX_SUFF_LIB) +VBoxNine-x86_DEFS = $(VBoxNine_DEFS) VBOX_WOW64 + +include $(FILE_KBUILD_SUB_FOOTER) + diff --git a/src/VBox/Additions/3D/win/VBoxNine/VBoxNine.c b/src/VBox/Additions/3D/win/VBoxNine/VBoxNine.c new file mode 100644 index 00000000..a26c3924 --- /dev/null +++ b/src/VBox/Additions/3D/win/VBoxNine/VBoxNine.c @@ -0,0 +1,168 @@ +/* $Id: VBoxNine.c $ */ +/** @file + * VirtualBox Windows Guest Mesa3D - Direct3D9 state tracker. + */ + +/* + * Copyright (C) 2016-2020 Oracle Corporation + * + * This file is part of VirtualBox Open Source Edition (OSE), as + * available from http://www.virtualbox.org. This file is free software; + * you can redistribute it and/or modify it under the terms of the GNU + * General Public License (GPL) as published by the Free Software + * Foundation, in version 2 as it comes in the "COPYING" file of the + * VirtualBox OSE distribution. VirtualBox OSE is distributed in the + * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. + */ + +#include <iprt/win/windows.h> +#include <iprt/win/d3d9.h> +//#include <d3dumddi.h> + +#include <VBoxWddmUmHlp.h> + +//#include <windef.h> +//#include <winbase.h> +//#include <winsvc.h> +//#include <winnetwk.h> +//#include <npapi.h> +//#include <devioctl.h> +//#include <stdio.h> + +//#include <iprt/alloc.h> +//#include <iprt/initterm.h> +//#include <iprt/string.h> +//#include <iprt/log.h> +//#include <VBox/version.h> +//#include <VBox/VMMDev.h> +//#include <VBox/Log.h> + +#include "adapter9.h" +#include "surface9.h" +#include "pipe/p_screen.h" + +#include <iprt/types.h> +// #include <iprt/asm.h> + +// #include "VBoxNine.h" + +struct d3dadapter9_context_wddm +{ + struct d3dadapter9_context base; + void *reserved; +}; + +static void +wddm_destroy(struct d3dadapter9_context *ctx) +{ + /* struct d3dadapter9_context_wddm *ctx_wddm = (struct d3dadapter9_context_wddm *)ctx; */ + +/// @todo screen (hal) is deleted by the upper level. Do not delete here. +// if (ctx->ref) +// ctx->ref->destroy(ctx->ref); +// /* because ref is a wrapper around hal, freeing ref frees hal too. */ +// else if (ctx->hal) +// ctx->hal->destroy(ctx->hal); + + FREE(ctx); +} + +static HRESULT +d3dadapter9_context_wddm_create(struct d3dadapter9_context_wddm **ppCtx, struct pipe_screen *s) +{ + struct d3dadapter9_context_wddm *ctx = CALLOC_STRUCT(d3dadapter9_context_wddm); + + if (!ctx) { return E_OUTOFMEMORY; } + + ctx->base.destroy = wddm_destroy; + + ctx->base.linear_framebuffer = 1; + + ctx->base.hal = s; + + ctx->base.throttling = FALSE; + ctx->base.throttling_value = 0; + + ctx->base.vblank_mode = 1; + + ctx->base.thread_submit = 0; + + /** @todo Need software device here. Currently assigned to hw device to prevent NineDevice9_ctor crash. */ + ctx->base.ref = ctx->base.hal; + + /* read out PCI info */ + /// @todo read_descriptor(&ctx->base, fd); + + *ppCtx = ctx; + return D3D_OK; +} + +HRESULT WINAPI +GaNineD3DAdapter9Create(struct pipe_screen *s, ID3DAdapter9 **ppOut) +{ + HRESULT hr; + struct d3dadapter9_context_wddm *pCtx = NULL; + hr = d3dadapter9_context_wddm_create(&pCtx, s); + if (SUCCEEDED(hr)) + { + hr = NineAdapter9_new(&pCtx->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); + } + } + return hr; +} + +struct pipe_resource * WINAPI +GaNinePipeResourceFromSurface(IUnknown *pSurface) +{ + /// @todo QueryInterface? + struct NineResource9 *pResource = (struct NineResource9 *)pSurface; + return pResource->resource; +} + +extern struct pipe_context * +NineDevice9_GetPipe( struct NineDevice9 *This ); + +struct pipe_context * WINAPI +GaNinePipeContextFromDevice(IDirect3DDevice9 *pDevice) +{ + /// @todo Verify that this is a NineDevice? + struct pipe_context *pPipeContext = NineDevice9_GetPipe((struct NineDevice9 *)pDevice); + return pPipeContext; +} + +BOOL WINAPI DllMain(HINSTANCE hDLLInst, + DWORD fdwReason, + LPVOID lpvReserved) +{ + BOOL fReturn = TRUE; + + RT_NOREF2(hDLLInst, lpvReserved); + + switch (fdwReason) + { + case DLL_PROCESS_ATTACH: + //RTR3InitDll(RTR3INIT_FLAGS_UNOBTRUSIVE); + D3DKMTLoad(); + break; + + case DLL_PROCESS_DETACH: + /// @todo RTR3Term(); + break; + + case DLL_THREAD_ATTACH: + break; + + case DLL_THREAD_DETACH: + break; + + default: + break; + } + + return fReturn; +} diff --git a/src/VBox/Additions/3D/win/VBoxNine/VBoxNine.def b/src/VBox/Additions/3D/win/VBoxNine/VBoxNine.def new file mode 100644 index 00000000..0f899346 --- /dev/null +++ b/src/VBox/Additions/3D/win/VBoxNine/VBoxNine.def @@ -0,0 +1,24 @@ +; $Id: VBoxNine.def $; +;; @file +; Export definition file for the VBoxNine D3D9 state tracker. +; + +; +; Copyright (C) 2016-2020 Oracle Corporation +; +; This file is part of VirtualBox Open Source Edition (OSE), as +; available from http://www.virtualbox.org. This file is free software; +; you can redistribute it and/or modify it under the terms of the GNU +; General Public License (GPL) as published by the Free Software +; Foundation, in version 2 as it comes in the "COPYING" file of the +; VirtualBox OSE distribution. VirtualBox OSE is distributed in the +; hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. +; + +LIBRARY VBOXNINE + +EXPORTS + GaNineD3DAdapter9Create @1 + GaNinePipeResourceFromSurface @2 + GaNinePipeContextFromDevice @3 + diff --git a/src/VBox/Additions/3D/win/VBoxNine/VBoxNine.rc b/src/VBox/Additions/3D/win/VBoxNine/VBoxNine.rc new file mode 100644 index 00000000..c610b38b --- /dev/null +++ b/src/VBox/Additions/3D/win/VBoxNine/VBoxNine.rc @@ -0,0 +1,56 @@ +/* $Id: VBoxNine.rc $ */ +/** @file + * VBoxNine - Resource file containing version info and icon. + */ + +/* + * Copyright (C) 2016-2020 Oracle Corporation + * + * This file is part of VirtualBox Open Source Edition (OSE), as + * available from http://www.virtualbox.org. This file is free software; + * you can redistribute it and/or modify it under the terms of the GNU + * General Public License (GPL) as published by the Free Software + * Foundation, in version 2 as it comes in the "COPYING" file of the + * VirtualBox OSE distribution. VirtualBox OSE is distributed in the + * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. + */ + +#include <windows.h> +#include <VBox/version.h> + +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US + +VS_VERSION_INFO VERSIONINFO + FILEVERSION VBOX_RC_FILE_VERSION + PRODUCTVERSION VBOX_RC_FILE_VERSION + FILEFLAGSMASK VS_FFI_FILEFLAGSMASK + FILEFLAGSMASK VS_FFI_FILEFLAGSMASK + FILEFLAGS VBOX_RC_FILE_FLAGS + FILEOS VBOX_RC_FILE_OS + FILETYPE VBOX_RC_TYPE_DLL + FILESUBTYPE VFT2_UNKNOWN +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904b0" + BEGIN + VALUE "FileDescription", "VirtualBox D3D9 Mesa State Tracker\0" + VALUE "InternalName", "VBoxNine\0" +#ifdef VBOX_WOW64 + VALUE "OriginalFilename", "VBoxNine-x86.DLL\0" +#else + VALUE "OriginalFilename", "VBoxNine.DLL\0" +#endif + VALUE "CompanyName", VBOX_RC_COMPANY_NAME + VALUE "FileVersion", VBOX_RC_FILE_VERSION_STR + VALUE "LegalCopyright", VBOX_RC_LEGAL_COPYRIGHT + VALUE "ProductName", VBOX_RC_PRODUCT_NAME_GA_STR + VALUE "ProductVersion", VBOX_RC_PRODUCT_VERSION_STR + VBOX_RC_MORE_STRINGS + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1200 + END +END diff --git a/src/VBox/Additions/3D/win/VBoxSVGA/.scm-settings b/src/VBox/Additions/3D/win/VBoxSVGA/.scm-settings new file mode 100644 index 00000000..471a2a71 --- /dev/null +++ b/src/VBox/Additions/3D/win/VBoxSVGA/.scm-settings @@ -0,0 +1,19 @@ +# $Id: .scm-settings $ +## @file +# Source code massager settings for VBoxDTrace. +# + +# +# Copyright (C) 2010-2020 Oracle Corporation +# +# This file is part of VirtualBox Open Source Edition (OSE), as +# available from http://www.virtualbox.org. This file is free software; +# you can redistribute it and/or modify it under the terms of the GNU +# General Public License (GPL) as published by the Free Software +# Foundation, in version 2 as it comes in the "COPYING" file of the +# VirtualBox OSE distribution. VirtualBox OSE is distributed in the +# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. +# + + +--filter-out-dirs "*/winsys/." diff --git a/src/VBox/Additions/3D/win/VBoxSVGA/Makefile.kmk b/src/VBox/Additions/3D/win/VBoxSVGA/Makefile.kmk new file mode 100644 index 00000000..7b9ab30c --- /dev/null +++ b/src/VBox/Additions/3D/win/VBoxSVGA/Makefile.kmk @@ -0,0 +1,71 @@ +# $Id: Makefile.kmk $ +## @file +# Sub-Makefile for VBoxSVGA hardware driver. +# + +# +# Copyright (C) 2016-2020 Oracle Corporation +# +# This file is part of VirtualBox Open Source Edition (OSE), as +# available from http://www.virtualbox.org. This file is free software; +# you can redistribute it and/or modify it under the terms of the GNU +# General Public License (GPL) as published by the Free Software +# Foundation, in version 2 as it comes in the "COPYING" file of the +# VirtualBox OSE distribution. VirtualBox OSE is distributed in the +# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. +# + +SUB_DEPTH = ../../../../../.. +include $(KBUILD_PATH)/subheader.kmk + +DLLS += VBoxSVGA +DLLS.amd64 += VBoxSVGA-x86 + +VBoxSVGA_TEMPLATE = VBoxMesa3DGuestR3DllMinVista +# -wd4005: vcc120: '__useHeader' : macro redefinition +# -wd4100: unreferenced formal parameter +# -wd4200: nonstandard extension used : zero-sized array in struct/union +# -wd4211: nonstandard extension used : redefined extern to static +# -wd4245: 'return' : conversion from 'int' to 'unsigned int', signed/unsigned mismatch +# -wd4255: no function prototype given +# -wd4668: 'something' is not defined as a preprocessor macro, replacing with '0' for '#if/#elif' +VBoxSVGA_CFLAGS = -wd4005 -wd4100 -wd4200 -wd4211 -wd4245 -wd4255 -wd4668 +VBoxSVGA_INCS = \ + $(VBOX_PATH_3D)/win/include \ + $(VBOX_PATH_MESA)/src/gallium/drivers/svga \ + $(VBOX_PATH_MESA)/src/gallium/drivers/svga/include \ + $(VBOX_PATH_MESA)/src/gallium/winsys/svga/drm +VBoxSVGA_SOURCES = \ + winsys/vmw_screen_ioctl.c \ + winsys/vmw_screen_wddm.c \ + winsys/vmw_screen.c \ + VBoxSVGA.c \ + VBoxSVGA.rc \ + VBoxSVGA.def +VBoxSVGA_LIBS = \ + $(VBOX_PATH_ADDITIONS_LIB)/VBoxWddmUmHlp$(VBOX_SUFF_LIB) \ + $(VBOX_PATH_ADDITIONS_LIB)/VBoxMesaGalliumAuxLib$(VBOX_SUFF_LIB) \ + $(VBOX_PATH_ADDITIONS_LIB)/VBoxMesaUtilLib$(VBOX_SUFF_LIB) \ + $(VBOX_PATH_ADDITIONS_LIB)/VBoxMesaSVGAWinsysLib$(VBOX_SUFF_LIB) \ + $(VBOX_PATH_ADDITIONS_LIB)/VBoxMesaSVGALib$(VBOX_SUFF_LIB) + +ifdef VBOX_SIGN_ADDITIONS + VBoxSVGA_INSTTYPE = none + VBoxSVGA_DEBUG_INSTTYPE = both +endif + +# +# VBoxSVGA-x86 - x86 version of VBoxSVGA built for amd64 build +# +VBoxSVGA-x86_EXTENDS = VBoxSVGA +VBoxSVGA-x86_BLD_TRG_ARCH = x86 +VBoxSVGA-x86_LIBS = \ + $(VBOX_PATH_ADDITIONS_LIB)/VBoxWddmUmHlp-x86$(VBOX_SUFF_LIB) \ + $(VBOX_PATH_ADDITIONS_LIB)/VBoxMesaGalliumAuxLib-x86$(VBOX_SUFF_LIB) \ + $(VBOX_PATH_ADDITIONS_LIB)/VBoxMesaUtilLib-x86$(VBOX_SUFF_LIB) \ + $(VBOX_PATH_ADDITIONS_LIB)/VBoxMesaSVGAWinsysLib-x86$(VBOX_SUFF_LIB) \ + $(VBOX_PATH_ADDITIONS_LIB)/VBoxMesaSVGALib-x86$(VBOX_SUFF_LIB) +VBoxSVGA-x86_DEFS = $(VBoxSVGA_DEFS) VBOX_WOW64 + +include $(FILE_KBUILD_SUB_FOOTER) + diff --git a/src/VBox/Additions/3D/win/VBoxSVGA/VBoxSVGA.c b/src/VBox/Additions/3D/win/VBoxSVGA/VBoxSVGA.c new file mode 100644 index 00000000..dea3b558 --- /dev/null +++ b/src/VBox/Additions/3D/win/VBoxSVGA/VBoxSVGA.c @@ -0,0 +1,136 @@ +/* $Id: VBoxSVGA.c $ */ +/** @file + * VirtualBox Windows Guest Mesa3D - VMSVGA hardware driver. + */ + +/* + * Copyright (C) 2016-2020 Oracle Corporation + * + * This file is part of VirtualBox Open Source Edition (OSE), as + * available from http://www.virtualbox.org. This file is free software; + * you can redistribute it and/or modify it under the terms of the GNU + * General Public License (GPL) as published by the Free Software + * Foundation, in version 2 as it comes in the "COPYING" file of the + * VirtualBox OSE distribution. VirtualBox OSE is distributed in the + * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. + */ + +#include <VBoxWddmUmHlp.h> + +#include "svga_public.h" +#include "svga_screen.h" +#include "pipe/p_screen.h" +#include "pipe/p_context.h" +#include "state_tracker/drm_driver.h" + +#include "wddm_screen.h" + +struct svga_winsys_screen * +svga_wddm_winsys_screen_create(const WDDMGalliumDriverEnv *pEnv); + +struct pipe_screen * WINAPI +GaDrvScreenCreate(const WDDMGalliumDriverEnv *pEnv) +{ + struct svga_winsys_screen *sws = svga_wddm_winsys_screen_create(pEnv); + if (sws) + return svga_screen_create(sws); + return NULL; +} + +void WINAPI +GaDrvScreenDestroy(struct pipe_screen *s) +{ + if (s) + s->destroy(s); +} + +uint32_t WINAPI +GaDrvGetSurfaceId(struct pipe_screen *pScreen, struct pipe_resource *pResource) +{ + uint32_t u32Sid = 0; + + if ( pScreen + && pResource) + { + /* Get the sid (surface id). */ + struct winsys_handle whandle; + memset(&whandle, 0, sizeof(whandle)); + whandle.type = DRM_API_HANDLE_TYPE_SHARED; + + if (pScreen->resource_get_handle(pScreen, NULL, pResource, &whandle, PIPE_HANDLE_USAGE_READ)) + { + u32Sid = (uint32_t)whandle.handle; + } + } + + return u32Sid; +} + +const WDDMGalliumDriverEnv *WINAPI +GaDrvGetWDDMEnv(struct pipe_screen *pScreen) +{ + HANDLE hAdapter = NULL; + + if (pScreen) + { + struct svga_screen *pSvgaScreen = svga_screen(pScreen); + struct vmw_winsys_screen_wddm *vws_wddm = (struct vmw_winsys_screen_wddm *)pSvgaScreen->sws; + + return vws_wddm->pEnv; + } + + return hAdapter; +} + +uint32_t WINAPI +GaDrvGetContextId(struct pipe_context *pPipeContext) +{ + uint32 u32Cid = ~0; + + if (pPipeContext) + { + struct svga_winsys_context *pSWC = svga_winsys_context(pPipeContext); + u32Cid = pSWC->cid; + } + + return u32Cid; +} + +void WINAPI +GaDrvContextFlush(struct pipe_context *pPipeContext) +{ + if (pPipeContext) + pPipeContext->flush(pPipeContext, NULL, PIPE_FLUSH_END_OF_FRAME); +} + +BOOL WINAPI DllMain(HINSTANCE hDLLInst, + DWORD fdwReason, + LPVOID lpvReserved) +{ + BOOL fReturn = TRUE; + + RT_NOREF2(hDLLInst, lpvReserved); + + switch (fdwReason) + { + case DLL_PROCESS_ATTACH: + //RTR3InitDll(RTR3INIT_FLAGS_UNOBTRUSIVE); + D3DKMTLoad(); + break; + + case DLL_PROCESS_DETACH: + /// @todo RTR3Term(); + break; + + case DLL_THREAD_ATTACH: + break; + + case DLL_THREAD_DETACH: + break; + + default: + break; + } + + return fReturn; +} diff --git a/src/VBox/Additions/3D/win/VBoxSVGA/VBoxSVGA.def b/src/VBox/Additions/3D/win/VBoxSVGA/VBoxSVGA.def new file mode 100644 index 00000000..2214787a --- /dev/null +++ b/src/VBox/Additions/3D/win/VBoxSVGA/VBoxSVGA.def @@ -0,0 +1,26 @@ +; $Id: VBoxSVGA.def $ +;; @file +; Linker defintion file for the VBoxSVGA hardware driver. +; + +; +; Copyright (C) 2016-2020 Oracle Corporation +; +; This file is part of VirtualBox Open Source Edition (OSE), as +; available from http://www.virtualbox.org. This file is free software; +; you can redistribute it and/or modify it under the terms of the GNU +; General Public License (GPL) as published by the Free Software +; Foundation, in version 2 as it comes in the "COPYING" file of the +; VirtualBox OSE distribution. VirtualBox OSE is distributed in the +; hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. +; + +LIBRARY VBOXSVGA + +EXPORTS + GaDrvScreenCreate @1 + GaDrvScreenDestroy @2 + GaDrvGetWDDMEnv @3 + GaDrvGetContextId @4 + GaDrvGetSurfaceId @5 + GaDrvContextFlush @6 diff --git a/src/VBox/Additions/3D/win/VBoxSVGA/VBoxSVGA.rc b/src/VBox/Additions/3D/win/VBoxSVGA/VBoxSVGA.rc new file mode 100644 index 00000000..006ce30c --- /dev/null +++ b/src/VBox/Additions/3D/win/VBoxSVGA/VBoxSVGA.rc @@ -0,0 +1,56 @@ +/* $Id: VBoxSVGA.rc $ */ +/** @file + * VBoxSVGA - Resource file containing version info and icon. + */ + +/* + * Copyright (C) 2016-2020 Oracle Corporation + * + * This file is part of VirtualBox Open Source Edition (OSE), as + * available from http://www.virtualbox.org. This file is free software; + * you can redistribute it and/or modify it under the terms of the GNU + * General Public License (GPL) as published by the Free Software + * Foundation, in version 2 as it comes in the "COPYING" file of the + * VirtualBox OSE distribution. VirtualBox OSE is distributed in the + * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. + */ + +#include <windows.h> +#include <VBox/version.h> + +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US + +VS_VERSION_INFO VERSIONINFO + FILEVERSION VBOX_RC_FILE_VERSION + PRODUCTVERSION VBOX_RC_FILE_VERSION + FILEFLAGSMASK VS_FFI_FILEFLAGSMASK + FILEFLAGSMASK VS_FFI_FILEFLAGSMASK + FILEFLAGS VBOX_RC_FILE_FLAGS + FILEOS VBOX_RC_FILE_OS + FILETYPE VBOX_RC_TYPE_DLL + FILESUBTYPE VFT2_UNKNOWN +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904b0" + BEGIN + VALUE "FileDescription", "VirtualBox D3D9 Mesa VMSVGA Hardware Driver\0" + VALUE "InternalName", "VBoxSVGA\0" +#ifdef VBOX_WOW64 + VALUE "OriginalFilename", "VBoxSVGA-x86.DLL\0" +#else + VALUE "OriginalFilename", "VBoxSVGA.DLL\0" +#endif + VALUE "CompanyName", VBOX_RC_COMPANY_NAME + VALUE "FileVersion", VBOX_RC_FILE_VERSION_STR + VALUE "LegalCopyright", VBOX_RC_LEGAL_COPYRIGHT + VALUE "ProductName", VBOX_RC_PRODUCT_NAME_GA_STR + VALUE "ProductVersion", VBOX_RC_PRODUCT_VERSION_STR + VBOX_RC_MORE_STRINGS + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1200 + END +END diff --git a/src/VBox/Additions/3D/win/VBoxSVGA/wddm_screen.h b/src/VBox/Additions/3D/win/VBoxSVGA/wddm_screen.h new file mode 100644 index 00000000..d17f6b48 --- /dev/null +++ b/src/VBox/Additions/3D/win/VBoxSVGA/wddm_screen.h @@ -0,0 +1,37 @@ +/* $Id: wddm_screen.h $ */ +/** @file + * VirtualBox Windows Guest Mesa3D - VMSVGA hardware driver. + */ + +/* + * Copyright (C) 2016-2020 Oracle Corporation + * + * This file is part of VirtualBox Open Source Edition (OSE), as + * available from http://www.virtualbox.org. This file is free software; + * you can redistribute it and/or modify it under the terms of the GNU + * General Public License (GPL) as published by the Free Software + * Foundation, in version 2 as it comes in the "COPYING" file of the + * VirtualBox OSE distribution. VirtualBox OSE is distributed in the + * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. + */ + +#ifndef GA_INCLUDED_SRC_3D_win_VBoxSVGA_wddm_screen_h +#define GA_INCLUDED_SRC_3D_win_VBoxSVGA_wddm_screen_h +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + +#include <VBoxGaDriver.h> + +#include "vmw_screen.h" + +struct vmw_winsys_screen_wddm +{ + struct vmw_winsys_screen base; + + const WDDMGalliumDriverEnv *pEnv; + VBOXGAHWINFOSVGA HwInfo; +}; + +#endif /* !GA_INCLUDED_SRC_3D_win_VBoxSVGA_wddm_screen_h */ + diff --git a/src/VBox/Additions/3D/win/VBoxSVGA/winsys/Makefile.kup b/src/VBox/Additions/3D/win/VBoxSVGA/winsys/Makefile.kup new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/src/VBox/Additions/3D/win/VBoxSVGA/winsys/Makefile.kup diff --git a/src/VBox/Additions/3D/win/VBoxSVGA/winsys/vmw_screen.c b/src/VBox/Additions/3D/win/VBoxSVGA/winsys/vmw_screen.c new file mode 100644 index 00000000..008805f4 --- /dev/null +++ b/src/VBox/Additions/3D/win/VBoxSVGA/winsys/vmw_screen.c @@ -0,0 +1,120 @@ +/* + * Copyright (C) 2016-2020 Oracle Corporation + * + * This file is part of VirtualBox Open Source Edition (OSE), as + * available from http://www.virtualbox.org. This file is free software; + * you can redistribute it and/or modify it under the terms of the GNU + * General Public License (GPL) as published by the Free Software + * Foundation, in version 2 as it comes in the "COPYING" file of the + * VirtualBox OSE distribution. VirtualBox OSE is distributed in the + * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. + */ + +/********************************************************** + * Copyright 2009-2015 VMware, Inc. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + **********************************************************/ + + +#include "vmw_screen.h" +#include "vmw_fence.h" +#include "vmw_context.h" + +#include "util/u_memory.h" +#include "pipe/p_compiler.h" + +#include "../wddm_screen.h" + +/* Called from vmw_drm_create_screen(), creates and initializes the + * vmw_winsys_screen structure, which is the main entity in this + * module. + * First, check whether a vmw_winsys_screen object already exists for + * this device, and in that case return that one, making sure that we + * have our own file descriptor open to DRM. + */ + +struct vmw_winsys_screen_wddm * +vmw_winsys_create_wddm(const WDDMGalliumDriverEnv *pEnv) +{ + struct vmw_winsys_screen_wddm *vws; + + if ( pEnv->pHWInfo == NULL + || pEnv->pHWInfo->u32HwType != VBOX_GA_HW_TYPE_VMSVGA) + return NULL; + + vws = CALLOC_STRUCT(vmw_winsys_screen_wddm); + if (!vws) + goto out_no_vws; + + vws->pEnv = pEnv; + vws->HwInfo = pEnv->pHWInfo->u.svga; + + vws->base.device = 0; /* not used */ + vws->base.open_count = 1; + vws->base.ioctl.drm_fd = -1; /* not used */ + vws->base.base.have_gb_dma = TRUE; + vws->base.base.need_to_rebind_resources = FALSE; + + if (!vmw_ioctl_init(&vws->base)) + goto out_no_ioctl; + + vws->base.fence_ops = vmw_fence_ops_create(&vws->base); + if (!vws->base.fence_ops) + goto out_no_fence_ops; + + if(!vmw_pools_init(&vws->base)) + goto out_no_pools; + + if (!vmw_winsys_screen_init_svga(&vws->base)) + goto out_no_svga; + + cnd_init(&vws->base.cs_cond); + mtx_init(&vws->base.cs_mutex, mtx_plain); + + return vws; +out_no_svga: + vmw_pools_cleanup(&vws->base); +out_no_pools: + vws->base.fence_ops->destroy(vws->base.fence_ops); +out_no_fence_ops: + vmw_ioctl_cleanup(&vws->base); +out_no_ioctl: + FREE(vws); +out_no_vws: + return NULL; +} + +void +vmw_winsys_destroy(struct vmw_winsys_screen *vws) +{ + struct vmw_winsys_screen_wddm *vws_wddm = (struct vmw_winsys_screen_wddm *)vws; + RT_NOREF(vws_wddm); + if (--vws->open_count == 0) { + vmw_pools_cleanup(vws); + vws->fence_ops->destroy(vws->fence_ops); + vmw_ioctl_cleanup(vws); + mtx_destroy(&vws->cs_mutex); + cnd_destroy(&vws->cs_cond); + FREE(vws); + } +} diff --git a/src/VBox/Additions/3D/win/VBoxSVGA/winsys/vmw_screen_ioctl.c b/src/VBox/Additions/3D/win/VBoxSVGA/winsys/vmw_screen_ioctl.c new file mode 100644 index 00000000..04397d42 --- /dev/null +++ b/src/VBox/Additions/3D/win/VBoxSVGA/winsys/vmw_screen_ioctl.c @@ -0,0 +1,799 @@ +/* + * Copyright (C) 2016-2020 Oracle Corporation + * + * This file is part of VirtualBox Open Source Edition (OSE), as + * available from http://www.virtualbox.org. This file is free software; + * you can redistribute it and/or modify it under the terms of the GNU + * General Public License (GPL) as published by the Free Software + * Foundation, in version 2 as it comes in the "COPYING" file of the + * VirtualBox OSE distribution. VirtualBox OSE is distributed in the + * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. + */ + +/********************************************************** + * Copyright 2009-2015 VMware, Inc. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + **********************************************************/ + +#include "svga_cmd.h" +#include "util/u_memory.h" +#include "util/u_math.h" +#include "svgadump/svga_dump.h" +#include "state_tracker/drm_driver.h" +#include "vmw_screen.h" +#include "vmw_context.h" +#include "vmw_fence.h" +#include "vmwgfx_drm.h" +#include "svga3d_caps.h" +#include "svga3d_reg.h" + +#include "../wddm_screen.h" + +#include <iprt/asm.h> + +#define VMW_MAX_DEFAULT_TEXTURE_SIZE (128 * 1024 * 1024) +#define VMW_FENCE_TIMEOUT_SECONDS 60 + +struct vmw_region +{ + uint32_t handle; + uint64_t map_handle; + void *data; + uint32_t map_count; + uint32_t size; + struct vmw_winsys_screen_wddm *vws_wddm; +}; + +uint32_t +vmw_region_size(struct vmw_region *region) +{ + return region->size; +} + +uint32 +vmw_ioctl_context_create(struct vmw_winsys_screen *vws) +{ + struct vmw_winsys_screen_wddm *vws_wddm = (struct vmw_winsys_screen_wddm *)vws; + return vws_wddm->pEnv->pfnContextCreate(vws_wddm->pEnv->pvEnv, false, false); +} + +uint32 +vmw_ioctl_extended_context_create(struct vmw_winsys_screen *vws, + boolean vgpu10) +{ + struct vmw_winsys_screen_wddm *vws_wddm = (struct vmw_winsys_screen_wddm *)vws; + return vws_wddm->pEnv->pfnContextCreate(vws_wddm->pEnv->pvEnv, true, vgpu10); +} + +void +vmw_ioctl_context_destroy(struct vmw_winsys_screen *vws, uint32 cid) +{ + struct vmw_winsys_screen_wddm *vws_wddm = (struct vmw_winsys_screen_wddm *)vws; + vws_wddm->pEnv->pfnContextDestroy(vws_wddm->pEnv->pvEnv, cid); + return; +} + +/* + * Allocates a device unique surface id, and queues a create surface command + * for the host. Does not wait for host completion. The surface ID can be + * used directly in the command stream and shows up as the same surface + * ID on the host. + */ +uint32 +vmw_ioctl_surface_create(struct vmw_winsys_screen *vws, + SVGA3dSurfaceFlags flags, + SVGA3dSurfaceFormat format, + unsigned usage, + SVGA3dSize size, + uint32_t numFaces, uint32_t numMipLevels, + unsigned sampleCount) +{ + struct vmw_winsys_screen_wddm *vws_wddm = (struct vmw_winsys_screen_wddm *)vws; + + GASURFCREATE createParms; + GASURFSIZE sizes[DRM_VMW_MAX_SURFACE_FACES* + DRM_VMW_MAX_MIP_LEVELS]; + GASURFSIZE *cur_size; + uint32_t iFace; + uint32_t iMipLevel; + uint32_t u32Sid; + int ret; + + RT_NOREF(sampleCount); + + memset(&createParms, 0, sizeof(createParms)); + createParms.flags = (uint32_t) flags; + createParms.format = (uint32_t) format; + createParms.usage = (uint32_t) usage; + + if (numFaces * numMipLevels >= GA_MAX_SURFACE_FACES*GA_MAX_MIP_LEVELS) { + return (uint32_t)-1; + } + cur_size = sizes; + for (iFace = 0; iFace < numFaces; ++iFace) { + SVGA3dSize mipSize = size; + + createParms.mip_levels[iFace] = numMipLevels; + for (iMipLevel = 0; iMipLevel < numMipLevels; ++iMipLevel) { + cur_size->cWidth = mipSize.width; + cur_size->cHeight = mipSize.height; + cur_size->cDepth = mipSize.depth; + cur_size->u32Reserved = 0; + mipSize.width = MAX2(mipSize.width >> 1, 1); + mipSize.height = MAX2(mipSize.height >> 1, 1); + mipSize.depth = MAX2(mipSize.depth >> 1, 1); + cur_size++; + } + } + for (iFace = numFaces; iFace < SVGA3D_MAX_SURFACE_FACES; ++iFace) { + createParms.mip_levels[iFace] = 0; + } + + ret = vws_wddm->pEnv->pfnSurfaceDefine(vws_wddm->pEnv->pvEnv, &createParms, &sizes[0], numFaces * numMipLevels, &u32Sid); + if (ret) { + return (uint32_t)-1; + } + + return u32Sid; +} + +uint32 +vmw_ioctl_gb_surface_create(struct vmw_winsys_screen *vws, + SVGA3dSurfaceFlags flags, + SVGA3dSurfaceFormat format, + unsigned usage, + SVGA3dSize size, + uint32_t numFaces, + uint32_t numMipLevels, + unsigned sampleCount, + uint32_t buffer_handle, + struct vmw_region **p_region) +{ + RT_NOREF10(vws, flags, format, usage, size, numFaces, numMipLevels, sampleCount, buffer_handle, p_region); + // guest-backed surface + // DeviceCallbacks.pfnAllocateCb(pDevice->hDevice, pDdiAllocate); + return (uint32_t)-1; +} + +/** + * vmw_ioctl_surface_req - Fill in a struct surface_req + * + * @vws: Winsys screen + * @whandle: Surface handle + * @req: The struct surface req to fill in + * @needs_unref: This call takes a kernel surface reference that needs to + * be unreferenced. + * + * Returns 0 on success, negative error type otherwise. + * Fills in the surface_req structure according to handle type and kernel + * capabilities. + */ +static int +vmw_ioctl_surface_req(const struct vmw_winsys_screen *vws, + const struct winsys_handle *whandle, + struct drm_vmw_surface_arg *req, + boolean *needs_unref) +{ + RT_NOREF4(vws, whandle, req, needs_unref); + // ??? + return -1; +} + +/** + * vmw_ioctl_gb_surface_ref - Put a reference on a guest-backed surface and + * get surface information + * + * @vws: Screen to register the reference on + * @handle: Kernel handle of the guest-backed surface + * @flags: flags used when the surface was created + * @format: Format used when the surface was created + * @numMipLevels: Number of mipmap levels of the surface + * @p_region: On successful return points to a newly allocated + * struct vmw_region holding a reference to the surface backup buffer. + * + * Returns 0 on success, a system error on failure. + */ +int +vmw_ioctl_gb_surface_ref(struct vmw_winsys_screen *vws, + const struct winsys_handle *whandle, + SVGA3dSurfaceFlags *flags, + SVGA3dSurfaceFormat *format, + uint32_t *numMipLevels, + uint32_t *handle, + struct vmw_region **p_region) +{ + RT_NOREF7(vws, whandle, flags, format, numMipLevels, handle, p_region); + // ??? DeviceCallbacks.pfnLockCb(pDevice->hDevice, ); + return -1; +} + +void +vmw_ioctl_surface_destroy(struct vmw_winsys_screen *vws, uint32 sid) +{ + struct vmw_winsys_screen_wddm *vws_wddm = (struct vmw_winsys_screen_wddm *)vws; + /// @todo ? take into account surface references, referencing should be probably implemented here in user mode. + vws_wddm->pEnv->pfnSurfaceDestroy(vws_wddm->pEnv->pvEnv, sid); + return; +} + +void +vmw_ioctl_command(struct vmw_winsys_screen *vws, int32_t cid, + uint32_t throttle_us, void *commands, uint32_t size, + struct pipe_fence_handle **pfence, int32_t imported_fence_fd, + uint32_t flags) +{ + struct vmw_winsys_screen_wddm *vws_wddm = (struct vmw_winsys_screen_wddm *)vws; + GAFENCEQUERY FenceQuery; + RT_NOREF3(throttle_us, imported_fence_fd, flags); +#ifdef DEBUG + // svga_dump_commands(commands, size); +#endif + memset(&FenceQuery, 0, sizeof(FenceQuery)); + FenceQuery.u32FenceStatus = GA_FENCE_STATUS_NULL; + + vws_wddm->pEnv->pfnRender(vws_wddm->pEnv->pvEnv, cid, commands, size, pfence? &FenceQuery: NULL); + if (FenceQuery.u32FenceStatus == GA_FENCE_STATUS_NULL) + { + /* + * Kernel has already synced, or caller requested no fence. + */ + if (pfence) + *pfence = NULL; + } + else + { + if (pfence) + { + vmw_fences_signal(vws->fence_ops, FenceQuery.u32ProcessedSeqNo, FenceQuery.u32SubmittedSeqNo, TRUE); + + *pfence = vmw_fence_create(vws->fence_ops, FenceQuery.u32FenceHandle, + FenceQuery.u32SubmittedSeqNo, /* mask */ 0, -1); + if (*pfence == NULL) + { + /* + * Fence creation failed. Need to sync. + */ + (void) vmw_ioctl_fence_finish(vws, FenceQuery.u32FenceHandle, /* mask */ 0); + vmw_ioctl_fence_unref(vws, FenceQuery.u32FenceHandle); + } + } + } + return; +} + +struct vmw_region * +vmw_ioctl_region_create(struct vmw_winsys_screen *vws, uint32_t size) +{ + /* 'region' is a buffer visible both for host and guest */ + struct vmw_region *region; + struct vmw_winsys_screen_wddm *vws_wddm = (struct vmw_winsys_screen_wddm *)vws; + uint32_t u32GmrId = 0; + void *pvMap = NULL; + int ret; + + region = CALLOC_STRUCT(vmw_region); + if (!region) + goto out_err1; + + ret = vws_wddm->pEnv->pfnRegionCreate(vws_wddm->pEnv->pvEnv, size, &u32GmrId, &pvMap); + + if (ret) { + vmw_error("IOCTL failed %d: %s\n", ret, strerror(-ret)); + goto out_err1; + } + + region->handle = u32GmrId; + region->map_handle = 0; + region->data = pvMap; + region->map_count = 0; + region->size = size; + region->vws_wddm = vws_wddm; + + return region; + +out_err1: + FREE(region); + return NULL; +} + +void +vmw_ioctl_region_destroy(struct vmw_region *region) +{ + struct vmw_winsys_screen_wddm *vws_wddm = region->vws_wddm; + + vws_wddm->pEnv->pfnRegionDestroy(vws_wddm->pEnv->pvEnv, region->handle, region->data); + + FREE(region); +} + +SVGAGuestPtr +vmw_ioctl_region_ptr(struct vmw_region *region) +{ + SVGAGuestPtr ptr; + ptr.gmrId = region->handle; + ptr.offset = 0; + return ptr; +} + +void * +vmw_ioctl_region_map(struct vmw_region *region) +{ + debug_printf("%s: gmrId = %u\n", __FUNCTION__, + region->handle); + + if (region->data == NULL) + { + /* Should not get here. */ + return NULL; + } + + ++region->map_count; + + return region->data; +} + +void +vmw_ioctl_region_unmap(struct vmw_region *region) +{ + /// @todo + --region->map_count; +} + +/** + * vmw_ioctl_syncforcpu - Synchronize a buffer object for CPU usage + * + * @region: Pointer to a struct vmw_region representing the buffer object. + * @dont_block: Dont wait for GPU idle, but rather return -EBUSY if the + * GPU is busy with the buffer object. + * @readonly: Hint that the CPU access is read-only. + * @allow_cs: Allow concurrent command submission while the buffer is + * synchronized for CPU. If FALSE command submissions referencing the + * buffer will block until a corresponding call to vmw_ioctl_releasefromcpu. + * + * This function idles any GPU activities touching the buffer and blocks + * command submission of commands referencing the buffer, even from + * other processes. + */ +int +vmw_ioctl_syncforcpu(struct vmw_region *region, + boolean dont_block, + boolean readonly, + boolean allow_cs) +{ + RT_NOREF4(region, dont_block, readonly, allow_cs); + // ??? + return -1; +} + +/** + * vmw_ioctl_releasefromcpu - Undo a previous syncforcpu. + * + * @region: Pointer to a struct vmw_region representing the buffer object. + * @readonly: Should hold the same value as the matching syncforcpu call. + * @allow_cs: Should hold the same value as the matching syncforcpu call. + */ +void +vmw_ioctl_releasefromcpu(struct vmw_region *region, + boolean readonly, + boolean allow_cs) +{ + RT_NOREF3(region, readonly, allow_cs); + // ??? + return; +} + +void +vmw_ioctl_fence_unref(struct vmw_winsys_screen *vws, + uint32_t handle) +{ + struct vmw_winsys_screen_wddm *vws_wddm = (struct vmw_winsys_screen_wddm *)vws; + vws_wddm->pEnv->pfnFenceUnref(vws_wddm->pEnv->pvEnv, handle); +} + +static inline uint32_t +vmw_drm_fence_flags(uint32_t flags) +{ + uint32_t dflags = 0; + + if (flags & SVGA_FENCE_FLAG_EXEC) + dflags |= DRM_VMW_FENCE_FLAG_EXEC; + if (flags & SVGA_FENCE_FLAG_QUERY) + dflags |= DRM_VMW_FENCE_FLAG_QUERY; + + return dflags; +} + + +int +vmw_ioctl_fence_signalled(struct vmw_winsys_screen *vws, + uint32_t handle, + uint32_t flags) +{ + RT_NOREF(flags); + struct vmw_winsys_screen_wddm *vws_wddm = (struct vmw_winsys_screen_wddm *)vws; + GAFENCEQUERY FenceQuery; + int ret; + + memset(&FenceQuery, 0, sizeof(FenceQuery)); + FenceQuery.u32FenceStatus = GA_FENCE_STATUS_NULL; + + ret = vws_wddm->pEnv->pfnFenceQuery(vws_wddm->pEnv->pvEnv, handle, &FenceQuery); + + if (ret != 0) + return ret; + + if (FenceQuery.u32FenceStatus == GA_FENCE_STATUS_NULL) + return 0; /* Treat as signalled. */ + + vmw_fences_signal(vws->fence_ops, FenceQuery.u32ProcessedSeqNo, FenceQuery.u32SubmittedSeqNo, TRUE); + + return FenceQuery.u32FenceStatus == GA_FENCE_STATUS_SIGNALED ? 0 : -1; +} + + + +int +vmw_ioctl_fence_finish(struct vmw_winsys_screen *vws, + uint32_t handle, + uint32_t flags) +{ + RT_NOREF(flags); + struct vmw_winsys_screen_wddm *vws_wddm = (struct vmw_winsys_screen_wddm *)vws; + + vws_wddm->pEnv->pfnFenceWait(vws_wddm->pEnv->pvEnv, handle, VMW_FENCE_TIMEOUT_SECONDS*1000000); + + return 0; /* Regardless. */ +} + +uint32 +vmw_ioctl_shader_create(struct vmw_winsys_screen *vws, + SVGA3dShaderType type, + uint32 code_len) +{ + RT_NOREF3(vws, type, code_len); + // DeviceCallbacks.pfnAllocateCb(pDevice->hDevice, pDdiAllocate); + return 0; +} + +void +vmw_ioctl_shader_destroy(struct vmw_winsys_screen *vws, uint32 shid) +{ + RT_NOREF2(vws, shid); + // ??? DeviceCallbacks.pfnDeallocateCb(pDevice->hDevice, pDdiAllocate); + return; +} + +static int +vmw_ioctl_parse_caps(struct vmw_winsys_screen *vws, + const uint32_t *cap_buffer) +{ + unsigned i; + + 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].result.u = cap_buffer[i]; + } + return 0; + } else { + const uint32 *capsBlock; + const SVGA3dCapsRecord *capsRecord = NULL; + uint32 offset; + const SVGA3dCapPair *capArray; + unsigned numCaps, index; + + /* + * Search linearly through the caps block records for the specified type. + */ + capsBlock = cap_buffer; + for (offset = 0; capsBlock[offset] != 0; offset += capsBlock[offset]) { + const SVGA3dCapsRecord *record; + if (offset >= SVGA_FIFO_3D_CAPS_SIZE) + break; + record = (const SVGA3dCapsRecord *) (capsBlock + offset); + if ((record->header.type >= SVGA3DCAPS_RECORD_DEVCAPS_MIN) && + (record->header.type <= SVGA3DCAPS_RECORD_DEVCAPS_MAX) && + (!capsRecord || (record->header.type > capsRecord->header.type))) { + capsRecord = record; + } + } + + if(!capsRecord) + return -1; + + /* + * Calculate the number of caps from the size of the record. + */ + capArray = (const SVGA3dCapPair *) capsRecord->data; + numCaps = (int) ((capsRecord->header.length * sizeof(uint32) - + sizeof capsRecord->header) / (2 * sizeof(uint32))); + + for (i = 0; i < numCaps; i++) { + index = capArray[i][0]; + if (index < vws->ioctl.num_cap_3d) { + vws->ioctl.cap_3d[index].has_cap = TRUE; + vws->ioctl.cap_3d[index].result.u = capArray[i][1]; + } else { + debug_printf("Unknown devcaps seen: %d\n", index); + } + } + } + return 0; +} + +static int +vboxGetParam(struct vmw_winsys_screen_wddm *vws_wddm, struct drm_vmw_getparam_arg *gp_arg) +{ + /* DRM_VMW_GET_PARAM */ + switch (gp_arg->param) + { + case DRM_VMW_PARAM_NUM_STREAMS: + gp_arg->value = 1; /* const */ + break; + case DRM_VMW_PARAM_NUM_FREE_STREAMS: + gp_arg->value = 1; /* const */ + break; + case DRM_VMW_PARAM_3D: + gp_arg->value = 1; /** @todo */ + break; + case DRM_VMW_PARAM_HW_CAPS: + gp_arg->value = vws_wddm->HwInfo.au32Regs[SVGA_REG_CAPABILITIES]; + break; + case DRM_VMW_PARAM_FIFO_CAPS: + gp_arg->value = vws_wddm->HwInfo.au32Fifo[SVGA_FIFO_CAPABILITIES]; + break; + case DRM_VMW_PARAM_MAX_FB_SIZE: + gp_arg->value = vws_wddm->HwInfo.au32Regs[SVGA_REG_MAX_PRIMARY_BOUNDING_BOX_MEM]; + break; + case DRM_VMW_PARAM_FIFO_HW_VERSION: + if (vws_wddm->HwInfo.au32Fifo[SVGA_FIFO_CAPABILITIES] & SVGA_FIFO_CAP_3D_HWVERSION_REVISED) + { + gp_arg->value = + vws_wddm->HwInfo.au32Fifo[SVGA_FIFO_3D_HWVERSION_REVISED]; + } + else + { + gp_arg->value = + vws_wddm->HwInfo.au32Fifo[SVGA_FIFO_3D_HWVERSION]; + } + break; + case DRM_VMW_PARAM_MAX_SURF_MEMORY: + gp_arg->value = vws_wddm->HwInfo.au32Regs[SVGA_REG_MEMORY_SIZE]; + break; + case DRM_VMW_PARAM_3D_CAPS_SIZE: + gp_arg->value = (SVGA_FIFO_3D_CAPS_LAST - + SVGA_FIFO_3D_CAPS + 1) * + sizeof(uint32_t); + break; + case DRM_VMW_PARAM_MAX_MOB_MEMORY: + gp_arg->value = 0; + break; + case DRM_VMW_PARAM_MAX_MOB_SIZE: + gp_arg->value = 0; + break; + case DRM_VMW_PARAM_SCREEN_TARGET: + gp_arg->value = 1; + break; + case DRM_VMW_PARAM_VGPU10: + gp_arg->value = 0; + break; + default: return -1; + } + return 0; +} + +static int +vboxGet3DCap(struct vmw_winsys_screen_wddm *vws_wddm, void *pvCap, size_t cbCap) +{ + /* DRM_VMW_GET_3D_CAP */ + memcpy(pvCap, &vws_wddm->HwInfo.au32Fifo[SVGA_FIFO_3D_CAPS], cbCap); + return 0; +} + + +boolean +vmw_ioctl_init(struct vmw_winsys_screen *vws) +{ + struct drm_vmw_getparam_arg gp_arg; + // struct drm_vmw_get_3d_cap_arg cap_arg; + unsigned int size; + int ret; + uint32_t *cap_buffer; + boolean drm_gb_capable; + boolean have_drm_2_5 = 1; /* unused */ + + struct vmw_winsys_screen_wddm *vws_wddm = (struct vmw_winsys_screen_wddm *)vws; + + VMW_FUNC; + + vws->ioctl.have_drm_2_6 = 1; /* unused */ + vws->ioctl.have_drm_2_9 = 1; + + vws->ioctl.drm_execbuf_version = vws->ioctl.have_drm_2_9 ? 2 : 1; + + drm_gb_capable = 1; + + memset(&gp_arg, 0, sizeof(gp_arg)); + gp_arg.param = DRM_VMW_PARAM_3D; + ret = vboxGetParam(vws_wddm, &gp_arg); + if (ret || gp_arg.value == 0) { + vmw_error("No 3D enabled (%i, %s).\n", ret, strerror(-ret)); + goto out_no_3d; + } + + memset(&gp_arg, 0, sizeof(gp_arg)); + gp_arg.param = DRM_VMW_PARAM_FIFO_HW_VERSION; + ret = vboxGetParam(vws_wddm, &gp_arg); + if (ret) { + vmw_error("Failed to get fifo hw version (%i, %s).\n", + ret, strerror(-ret)); + goto out_no_3d; + } + vws->ioctl.hwversion = gp_arg.value; + + //memset(&gp_arg, 0, sizeof(gp_arg)); + //gp_arg.param = DRM_VMW_PARAM_HW_CAPS; + //ret = vboxGetParam(vws_wddm, &gp_arg); + //if (ret) + // vws->base.have_gb_objects = FALSE; + //else + // vws->base.have_gb_objects = + // !!(gp_arg.value & (uint64_t) SVGA_CAP_GBOBJECTS); + /* The driver does not support this feature. */ + vws->base.have_gb_objects = FALSE; + + if (vws->base.have_gb_objects && !drm_gb_capable) + goto out_no_3d; + + vws->base.have_vgpu10 = FALSE; + if (vws->base.have_gb_objects) { + memset(&gp_arg, 0, sizeof(gp_arg)); + gp_arg.param = DRM_VMW_PARAM_3D_CAPS_SIZE; + ret = vboxGetParam(vws_wddm, &gp_arg); + if (ret) + size = SVGA_FIFO_3D_CAPS_SIZE * sizeof(uint32_t); + else + size = gp_arg.value; + + if (vws->base.have_gb_objects) + vws->ioctl.num_cap_3d = size / sizeof(uint32_t); + else + vws->ioctl.num_cap_3d = SVGA3D_DEVCAP_MAX; + + + memset(&gp_arg, 0, sizeof(gp_arg)); + gp_arg.param = DRM_VMW_PARAM_MAX_MOB_MEMORY; + ret = vboxGetParam(vws_wddm, &gp_arg); + if (ret) { + /* Just guess a large enough value. */ + vws->ioctl.max_mob_memory = 256*1024*1024; + } else { + vws->ioctl.max_mob_memory = gp_arg.value; + } + + memset(&gp_arg, 0, sizeof(gp_arg)); + gp_arg.param = DRM_VMW_PARAM_MAX_MOB_SIZE; + ret = vboxGetParam(vws_wddm, &gp_arg); + + if (ret || gp_arg.value == 0) { + vws->ioctl.max_texture_size = VMW_MAX_DEFAULT_TEXTURE_SIZE; + } else { + vws->ioctl.max_texture_size = gp_arg.value; + } + + /* Never early flush surfaces, mobs do accounting. */ + vws->ioctl.max_surface_memory = ~0ULL; + + if (vws->ioctl.have_drm_2_9) { + + memset(&gp_arg, 0, sizeof(gp_arg)); + gp_arg.param = DRM_VMW_PARAM_VGPU10; + ret = vboxGetParam(vws_wddm, &gp_arg); + if (ret == 0 && gp_arg.value != 0) { + const char *vgpu10_val; + + debug_printf("Have VGPU10 interface and hardware.\n"); + 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; + } else { + debug_printf("Enabling VGPU10 interface.\n"); + } + } + } + } else { + vws->ioctl.num_cap_3d = SVGA3D_DEVCAP_MAX; + + memset(&gp_arg, 0, sizeof(gp_arg)); + gp_arg.param = DRM_VMW_PARAM_MAX_SURF_MEMORY; + if (have_drm_2_5) + ret = vboxGetParam(vws_wddm, &gp_arg); + if (!have_drm_2_5 || ret) { + /* Just guess a large enough value, around 800mb. */ + vws->ioctl.max_surface_memory = 0x30000000; + } else { + vws->ioctl.max_surface_memory = gp_arg.value; + } + + vws->ioctl.max_texture_size = VMW_MAX_DEFAULT_TEXTURE_SIZE; + + size = SVGA_FIFO_3D_CAPS_SIZE * sizeof(uint32_t); + } + + debug_printf("VGPU10 interface is %s.\n", + vws->base.have_vgpu10 ? "on" : "off"); + + cap_buffer = calloc(1, size); + if (!cap_buffer) { + debug_printf("Failed alloc fifo 3D caps buffer.\n"); + goto out_no_3d; + } + + vws->ioctl.cap_3d = calloc(vws->ioctl.num_cap_3d, + sizeof(*vws->ioctl.cap_3d)); + if (!vws->ioctl.cap_3d) { + debug_printf("Failed alloc fifo 3D caps buffer.\n"); + goto out_no_caparray; + } + +// memset(&cap_arg, 0, sizeof(cap_arg)); +// cap_arg.buffer = (uint64_t) (unsigned long) (cap_buffer); +// cap_arg.max_size = size; + + ret = vboxGet3DCap(vws_wddm, cap_buffer, size); + + if (ret) { + debug_printf("Failed to get 3D capabilities" + " (%i, %s).\n", ret, strerror(-ret)); + goto out_no_caps; + } + + ret = vmw_ioctl_parse_caps(vws, cap_buffer); + if (ret) { + debug_printf("Failed to parse 3D capabilities" + " (%i, %s).\n", ret, strerror(-ret)); + goto out_no_caps; + } + free(cap_buffer); + vmw_printf("%s OK\n", __FUNCTION__); + return TRUE; + out_no_caps: + free(vws->ioctl.cap_3d); + out_no_caparray: + free(cap_buffer); + out_no_3d: + vws->ioctl.num_cap_3d = 0; + debug_printf("%s Failed\n", __FUNCTION__); + return FALSE; +} + + + +void +vmw_ioctl_cleanup(struct vmw_winsys_screen *vws) +{ + VMW_FUNC; + RT_NOREF(vws); +} diff --git a/src/VBox/Additions/3D/win/VBoxSVGA/winsys/vmw_screen_wddm.c b/src/VBox/Additions/3D/win/VBoxSVGA/winsys/vmw_screen_wddm.c new file mode 100644 index 00000000..dbd7795e --- /dev/null +++ b/src/VBox/Additions/3D/win/VBoxSVGA/winsys/vmw_screen_wddm.c @@ -0,0 +1,161 @@ +/* + * Copyright (C) 2016-2020 Oracle Corporation + * + * This file is part of VirtualBox Open Source Edition (OSE), as + * available from http://www.virtualbox.org. This file is free software; + * you can redistribute it and/or modify it under the terms of the GNU + * General Public License (GPL) as published by the Free Software + * Foundation, in version 2 as it comes in the "COPYING" file of the + * VirtualBox OSE distribution. VirtualBox OSE is distributed in the + * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. + */ + +/********************************************************** + * Copyright 2009-2015 VMware, Inc. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + **********************************************************/ + + +#include "pipe/p_compiler.h" +#include "util/u_inlines.h" +#include "util/u_memory.h" +#include "util/u_format.h" + +#include "vmw_context.h" +#include "vmw_screen.h" +#include "vmw_surface.h" +#include "vmw_buffer.h" +#include "svga_drm_public.h" +#include "svga3d_surfacedefs.h" + +#include "state_tracker/drm_driver.h" + +#include "vmwgfx_drm.h" + +#include "../wddm_screen.h" + +#include <iprt/asm.h> + +static struct svga_winsys_surface * +vmw_drm_surface_from_handle(struct svga_winsys_screen *sws, + struct winsys_handle *whandle, + SVGA3dSurfaceFormat *format); + +static struct svga_winsys_surface * +vmw_drm_gb_surface_from_handle(struct svga_winsys_screen *sws, + struct winsys_handle *whandle, + SVGA3dSurfaceFormat *format); +static boolean +vmw_drm_surface_get_handle(struct svga_winsys_screen *sws, + struct svga_winsys_surface *surface, + unsigned stride, + struct winsys_handle *whandle); + +struct vmw_winsys_screen_wddm * +vmw_winsys_create_wddm(const WDDMGalliumDriverEnv *pEnv); + +/* This is actually the entrypoint to the entire driver, + * called by the target bootstrap code. + */ +struct svga_winsys_screen * +svga_wddm_winsys_screen_create(const WDDMGalliumDriverEnv *pEnv) +{ + struct vmw_winsys_screen_wddm *vws; + + if (pEnv->cb < sizeof(WDDMGalliumDriverEnv)) + goto out_no_vws; + + vws = vmw_winsys_create_wddm(pEnv); + if (!vws) + goto out_no_vws; + + /* XXX do this properly */ + vws->base.base.surface_from_handle = vws->base.base.have_gb_objects ? + vmw_drm_gb_surface_from_handle : vmw_drm_surface_from_handle; + vws->base.base.surface_get_handle = vmw_drm_surface_get_handle; + + return &vws->base.base; + +out_no_vws: + return NULL; +} + +static struct svga_winsys_surface * +vmw_drm_gb_surface_from_handle(struct svga_winsys_screen *sws, + struct winsys_handle *whandle, + SVGA3dSurfaceFormat *format) +{ + RT_NOREF3(sws, whandle, format); + return 0; +} + +static struct svga_winsys_surface * +vmw_drm_surface_from_handle(struct svga_winsys_screen *sws, + struct winsys_handle *whandle, + SVGA3dSurfaceFormat *format) +{ + RT_NOREF3(sws, whandle, format); + return 0; +} + +/* + * The user mode driver asks the kernel driver to create a resource + * (vmw_ioctl_surface_create) and gets a sid (surface id). + * This function is supposed to convert the sid to a handle (file descriptor) + * which can be used to access the surface. + */ +static boolean +vmw_drm_surface_get_handle(struct svga_winsys_screen *sws, + struct svga_winsys_surface *surface, + unsigned stride, + struct winsys_handle *whandle) +{ + struct vmw_winsys_screen *vws = vmw_winsys_screen(sws); + struct vmw_svga_winsys_surface *vsrf; + + RT_NOREF(vws); + + if (!surface) + return FALSE; + + vsrf = vmw_svga_winsys_surface(surface); + whandle->handle = vsrf->sid; + whandle->stride = stride; + whandle->offset = 0; + + switch (whandle->type) { + case DRM_API_HANDLE_TYPE_SHARED: + case DRM_API_HANDLE_TYPE_KMS: + whandle->handle = vsrf->sid; + break; + case DRM_API_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 TRUE; +} diff --git a/src/VBox/Additions/3D/win/VBoxWddmUmHlp/D3DKMT.cpp b/src/VBox/Additions/3D/win/VBoxWddmUmHlp/D3DKMT.cpp new file mode 100644 index 00000000..a1b460d1 --- /dev/null +++ b/src/VBox/Additions/3D/win/VBoxWddmUmHlp/D3DKMT.cpp @@ -0,0 +1,250 @@ +/* $Id: D3DKMT.cpp $ */ +/** @file + * WDDM Kernel Mode Thunks helpers. + */ + +/* + * Copyright (C) 2018-2020 Oracle Corporation + * + * This file is part of VirtualBox Open Source Edition (OSE), as + * available from http://www.virtualbox.org. This file is free software; + * you can redistribute it and/or modify it under the terms of the GNU + * General Public License (GPL) as published by the Free Software + * Foundation, in version 2 as it comes in the "COPYING" file of the + * VirtualBox OSE distribution. VirtualBox OSE is distributed in the + * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. + */ + +/* We're unable to use standard r3 vbgl-based backdoor logging API because win8 Metro apps + * can not do CreateFile/Read/Write by default. + * This is why we use miniport escape functionality to issue backdoor log string to the miniport + * and submit it to host via standard r0 backdoor logging api accordingly + */ + +#include "UmHlpInternal.h" + + +/** Loads a system DLL. + * + * @returns Module handle or NULL + * @param pszName The DLL name. + */ +DECLCALLBACK(HMODULE) VBoxWddmLoadSystemDll(const char *pszName) +{ + char szPath[MAX_PATH]; + UINT cchPath = GetSystemDirectoryA(szPath, sizeof(szPath)); + size_t cbName = strlen(pszName) + 1; + if (cchPath + 1 + cbName > sizeof(szPath)) + { + SetLastError(ERROR_FILENAME_EXCED_RANGE); + return NULL; + } + szPath[cchPath] = '\\'; + memcpy(&szPath[cchPath + 1], pszName, cbName); + return LoadLibraryA(szPath); +} + +DECLCALLBACK(void) VBoxWddmLoadAdresses(HMODULE hmod, VBOXWDDMDLLPROC *paProcs) +{ + struct VBOXWDDMDLLPROC *pIter = paProcs; + while (pIter->pszName) + { + FARPROC pfn = GetProcAddress(hmod, pIter->pszName); + *pIter->ppfn = pfn; + ++pIter; + } +} + +/* + * Kernel Mode Thunks (KMT) initialization. + */ + +#define D3DKMT_LOAD_ENTRY(a) { #a, (FARPROC *)&g_D3DKMT.pfn##a } + +static D3DKMTFUNCTIONS g_D3DKMT = { 0 }; +static VBOXWDDMDLLPROC g_D3DKMTLoadTable[] = +{ + D3DKMT_LOAD_ENTRY(D3DKMTOpenAdapterFromHdc), + D3DKMT_LOAD_ENTRY(D3DKMTOpenAdapterFromDeviceName), + D3DKMT_LOAD_ENTRY(D3DKMTCloseAdapter), + D3DKMT_LOAD_ENTRY(D3DKMTQueryAdapterInfo), + D3DKMT_LOAD_ENTRY(D3DKMTEscape), + D3DKMT_LOAD_ENTRY(D3DKMTCreateDevice), + D3DKMT_LOAD_ENTRY(D3DKMTDestroyDevice), + D3DKMT_LOAD_ENTRY(D3DKMTCreateContext), + D3DKMT_LOAD_ENTRY(D3DKMTDestroyContext), + D3DKMT_LOAD_ENTRY(D3DKMTCreateAllocation), + D3DKMT_LOAD_ENTRY(D3DKMTDestroyAllocation), + D3DKMT_LOAD_ENTRY(D3DKMTRender), + D3DKMT_LOAD_ENTRY(D3DKMTPresent), + D3DKMT_LOAD_ENTRY(D3DKMTGetSharedPrimaryHandle), + D3DKMT_LOAD_ENTRY(D3DKMTQueryResourceInfo), + D3DKMT_LOAD_ENTRY(D3DKMTOpenResource), + D3DKMT_LOAD_ENTRY(D3DKMTEnumAdapters), + D3DKMT_LOAD_ENTRY(D3DKMTOpenAdapterFromLuid), + {NULL, NULL}, +}; + +#undef D3DKMT_LOAD_ENTRY + +/** Initialize Kernel Mode Thunks (KMT) pointers in the g_D3DKMT structure. + * + * @returns True if successful. + */ +DECLCALLBACK(int) D3DKMTLoad(void) +{ + /* Modules which use D3DKMT must link with gdi32. */ + HMODULE hmod = GetModuleHandleA("gdi32.dll"); + Assert(hmod); + if (hmod) + { + VBoxWddmLoadAdresses(hmod, g_D3DKMTLoadTable); + } + return hmod != NULL; +} + +DECLCALLBACK(D3DKMTFUNCTIONS const *) D3DKMTFunctions(void) +{ + return &g_D3DKMT; +} + + +/* + * Getting VirtualBox Graphics Adapter handle. + */ + +static NTSTATUS vboxDispKmtOpenAdapterFromHdc(D3DKMT_HANDLE *phAdapter, LUID *pLuid) +{ + *phAdapter = 0; + + D3DKMTFUNCTIONS const *d3dkmt = D3DKMTFunctions(); + if (d3dkmt->pfnD3DKMTOpenAdapterFromHdc == NULL) + return STATUS_NOT_SUPPORTED; + + D3DKMT_OPENADAPTERFROMHDC OpenAdapterData; + memset(&OpenAdapterData, 0, sizeof(OpenAdapterData)); + + for (int i = 0; ; ++i) + { + DISPLAY_DEVICEA dd; + memset(&dd, 0, sizeof(dd)); + dd.cb = sizeof(dd); + + if (!EnumDisplayDevicesA(NULL, i, &dd, 0)) + break; + + if (dd.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE) + { + OpenAdapterData.hDc = CreateDCA(NULL, dd.DeviceName, NULL, NULL); + break; + } + } + + Assert(OpenAdapterData.hDc); + + NTSTATUS Status; + if (OpenAdapterData.hDc) + { + Status = d3dkmt->pfnD3DKMTOpenAdapterFromHdc(&OpenAdapterData); + Assert(Status == STATUS_SUCCESS); + if (Status == STATUS_SUCCESS) + { + *phAdapter = OpenAdapterData.hAdapter; + if (pLuid) + { + *pLuid = OpenAdapterData.AdapterLuid; + } + } + + DeleteDC(OpenAdapterData.hDc); + } + else + { + Status = STATUS_NOT_SUPPORTED; + } + + return Status; +} + +static NTSTATUS vboxDispKmtOpenAdapterFromLuid(D3DKMT_HANDLE *phAdapter, LUID *pLuid) +{ + *phAdapter = 0; + + D3DKMTFUNCTIONS const *d3dkmt = D3DKMTFunctions(); + if ( d3dkmt->pfnD3DKMTOpenAdapterFromLuid == NULL + || d3dkmt->pfnD3DKMTEnumAdapters == NULL) + return STATUS_NOT_SUPPORTED; + + D3DKMT_ENUMADAPTERS EnumAdaptersData; + memset(&EnumAdaptersData, 0, sizeof(EnumAdaptersData)); + EnumAdaptersData.NumAdapters = RT_ELEMENTS(EnumAdaptersData.Adapters); + + NTSTATUS Status = d3dkmt->pfnD3DKMTEnumAdapters(&EnumAdaptersData); + Assert(Status == STATUS_SUCCESS); + if (Status == STATUS_SUCCESS) + { + Assert(EnumAdaptersData.NumAdapters); + + /* Try the same twice: if we fail to open the adapter containing present sources, + * then try to open any adapter. + */ + for (int iPass = 0; iPass < 2 && *phAdapter == 0; ++iPass) + { + for (ULONG i = 0; i < EnumAdaptersData.NumAdapters; ++i) + { + if (iPass > 0 || EnumAdaptersData.Adapters[i].NumOfSources) + { + D3DKMT_OPENADAPTERFROMLUID OpenAdapterData; + memset(&OpenAdapterData, 0, sizeof(OpenAdapterData)); + OpenAdapterData.AdapterLuid = EnumAdaptersData.Adapters[i].AdapterLuid; + + Status = d3dkmt->pfnD3DKMTOpenAdapterFromLuid(&OpenAdapterData); + Assert(Status == STATUS_SUCCESS); + if (Status == STATUS_SUCCESS) + { + *phAdapter = OpenAdapterData.hAdapter; + if (pLuid) + { + *pLuid = EnumAdaptersData.Adapters[i].AdapterLuid; + } + break; + } + } + } + } + } + + return Status; +} + +NTSTATUS vboxDispKmtOpenAdapter2(D3DKMT_HANDLE *phAdapter, LUID *pLuid) +{ + NTSTATUS Status = vboxDispKmtOpenAdapterFromLuid(phAdapter, pLuid); + if (Status != STATUS_SUCCESS) + { + /* Fallback for pre-Windows8 */ + Status = vboxDispKmtOpenAdapterFromHdc(phAdapter, pLuid); + } + + return Status; +} + +NTSTATUS vboxDispKmtOpenAdapter(D3DKMT_HANDLE *phAdapter) +{ + return vboxDispKmtOpenAdapter2(phAdapter, NULL); +} + +NTSTATUS vboxDispKmtCloseAdapter(D3DKMT_HANDLE hAdapter) +{ + D3DKMTFUNCTIONS const *d3dkmt = D3DKMTFunctions(); + if (d3dkmt->pfnD3DKMTCloseAdapter == NULL) + return STATUS_NOT_SUPPORTED; + + D3DKMT_CLOSEADAPTER CloseAdapterData; + CloseAdapterData.hAdapter = hAdapter; + + NTSTATUS Status = d3dkmt->pfnD3DKMTCloseAdapter(&CloseAdapterData); + Assert(Status == STATUS_SUCCESS); + + return Status; +} diff --git a/src/VBox/Additions/3D/win/VBoxWddmUmHlp/Makefile.kmk b/src/VBox/Additions/3D/win/VBoxWddmUmHlp/Makefile.kmk new file mode 100644 index 00000000..b8d7e1ef --- /dev/null +++ b/src/VBox/Additions/3D/win/VBoxWddmUmHlp/Makefile.kmk @@ -0,0 +1,45 @@ +# $Id: Makefile.kmk $ +## @file +# Sub-Makefile for the VirtualBox WDDM user mode driver +# + +# +# Copyright (C) 2018-2020 Oracle Corporation +# +# This file is part of VirtualBox Open Source Edition (OSE), as +# available from http://www.virtualbox.org. This file is free software; +# you can redistribute it and/or modify it under the terms of the GNU +# General Public License (GPL) as published by the Free Software +# Foundation, in version 2 as it comes in the "COPYING" file of the +# VirtualBox OSE distribution. VirtualBox OSE is distributed in the +# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. +# + +SUB_DEPTH = ../../../../../.. +include $(KBUILD_PATH)/subheader.kmk + +LIBRARIES += VBoxWddmUmHlp +LIBRARIES.amd64 += VBoxWddmUmHlp-x86 + +# +# VBoxWddmUmHlp - logger and other helpers for user mode driver +# +VBoxWddmUmHlp_TEMPLATE = VBoxMesa3DGuestR3DllMinVista +VBoxWddmUmHlp_INST = $(INST_ADDITIONS_LIB) +VBoxWddmUmHlp_DEFS = VBOX_WITH_WDDM +VBoxWddmUmHlp_INCS = \ + $(PATH_ROOT)/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/shared \ + $(VBOX_PATH_3D)/win/include \ + $(VBOX_GRAPHICS_INCS) +VBoxWddmUmHlp_SOURCES = \ + D3DKMT.cpp \ + VBoxMpLogger.cpp + +# +# 64-bit version for 32-bit build. +# +VBoxWddmUmHlp-x86_EXTENDS = VBoxWddmUmHlp +VBoxWddmUmHlp-x86_BLD_TRG_ARCH = x86 + +include $(FILE_KBUILD_SUB_FOOTER) + diff --git a/src/VBox/Additions/3D/win/VBoxWddmUmHlp/UmHlpInternal.h b/src/VBox/Additions/3D/win/VBoxWddmUmHlp/UmHlpInternal.h new file mode 100644 index 00000000..ab170d03 --- /dev/null +++ b/src/VBox/Additions/3D/win/VBoxWddmUmHlp/UmHlpInternal.h @@ -0,0 +1,26 @@ +/* $Id: UmHlpInternal.h $ */ +/** @file + * VBox WDDM User Mode Driver Helpers + */ + +/* + * Copyright (C) 2018-2020 Oracle Corporation + * + * This file is part of VirtualBox Open Source Edition (OSE), as + * available from http://www.virtualbox.org. This file is free software; + * you can redistribute it and/or modify it under the terms of the GNU + * General Public License (GPL) as published by the Free Software + * Foundation, in version 2 as it comes in the "COPYING" file of the + * VirtualBox OSE distribution. VirtualBox OSE is distributed in the + * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. + */ + +#ifndef GA_INCLUDED_SRC_3D_win_VBoxWddmUmHlp_UmHlpInternal_h +#define GA_INCLUDED_SRC_3D_win_VBoxWddmUmHlp_UmHlpInternal_h +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + +#include "VBoxWddmUmHlp.h" + +#endif /* !GA_INCLUDED_SRC_3D_win_VBoxWddmUmHlp_UmHlpInternal_h */ diff --git a/src/VBox/Additions/3D/win/VBoxWddmUmHlp/VBoxMpLogger.cpp b/src/VBox/Additions/3D/win/VBoxWddmUmHlp/VBoxMpLogger.cpp new file mode 100644 index 00000000..a58387c9 --- /dev/null +++ b/src/VBox/Additions/3D/win/VBoxWddmUmHlp/VBoxMpLogger.cpp @@ -0,0 +1,131 @@ +/* $Id: VBoxMpLogger.cpp $ */ +/** @file + * VBox WDDM Display logger implementation + */ + +/* + * Copyright (C) 2018-2020 Oracle Corporation + * + * This file is part of VirtualBox Open Source Edition (OSE), as + * available from http://www.virtualbox.org. This file is free software; + * you can redistribute it and/or modify it under the terms of the GNU + * General Public License (GPL) as published by the Free Software + * Foundation, in version 2 as it comes in the "COPYING" file of the + * VirtualBox OSE distribution. VirtualBox OSE is distributed in the + * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. + */ + +/* We're unable to use standard r3 vbgl-based backdoor logging API because win8 Metro apps + * can not do CreateFile/Read/Write by default. + * This is why we use miniport escape functionality to issue backdoor log string to the miniport + * and submit it to host via standard r0 backdoor logging api accordingly + */ + +#include "UmHlpInternal.h" + +#include <../../../common/wddm/VBoxMPIf.h> + +#include <stdio.h> + +DECLCALLBACK(void) VBoxDispMpLoggerLog(const char *pszString) +{ + D3DKMTFUNCTIONS const *d3dkmt = D3DKMTFunctions(); + if (d3dkmt->pfnD3DKMTEscape == NULL) + return; + + D3DKMT_HANDLE hAdapter; + NTSTATUS Status = vboxDispKmtOpenAdapter(&hAdapter); + Assert(Status == STATUS_SUCCESS); + if (Status == 0) + { + uint32_t cbString = (uint32_t)strlen(pszString) + 1; + uint32_t cbCmd = RT_UOFFSETOF_DYN(VBOXDISPIFESCAPE_DBGPRINT, aStringBuf[cbString]); + PVBOXDISPIFESCAPE_DBGPRINT pCmd = (PVBOXDISPIFESCAPE_DBGPRINT)malloc(cbCmd); + Assert(pCmd); + if (pCmd) + { + pCmd->EscapeHdr.escapeCode = VBOXESC_DBGPRINT; + pCmd->EscapeHdr.u32CmdSpecific = 0; + memcpy(pCmd->aStringBuf, pszString, cbString); + + D3DKMT_ESCAPE EscapeData; + memset(&EscapeData, 0, sizeof(EscapeData)); + EscapeData.hAdapter = hAdapter; + // EscapeData.hDevice = NULL; + EscapeData.Type = D3DKMT_ESCAPE_DRIVERPRIVATE; + // EscapeData.Flags.HardwareAccess = 0; + EscapeData.pPrivateDriverData = pCmd; + EscapeData.PrivateDriverDataSize = cbCmd; + // EscapeData.hContext = NULL; + + Status = d3dkmt->pfnD3DKMTEscape(&EscapeData); + Assert(Status == STATUS_SUCCESS); + + free(pCmd); + } + + Status = vboxDispKmtCloseAdapter(hAdapter); + Assert(Status == STATUS_SUCCESS); + } +} + +DECLCALLBACK(void) VBoxDispMpLoggerLogF(const char *pszString, ...) +{ + char szBuffer[4096] = {0}; + va_list pArgList; + va_start(pArgList, pszString); + _vsnprintf(szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0]), pszString, pArgList); + va_end(pArgList); + + VBoxDispMpLoggerLog(szBuffer); +} + +/* + * Prefix the output string with module name and pid/tid. + */ +static const char *vboxUmLogGetModuleName(void) +{ + static int s_fModuleNameInited = 0; + static char s_szModuleName[MAX_PATH]; + + if (!s_fModuleNameInited) + { + const DWORD cchName = GetModuleFileNameA(NULL, s_szModuleName, RT_ELEMENTS(s_szModuleName)); + if (cchName == 0) + { + return "<no module>"; + } + s_fModuleNameInited = 1; + } + return &s_szModuleName[0]; +} + +DECLCALLBACK(void) VBoxWddmUmLog(const char *pszString) +{ + char szBuffer[4096]; + const int cbBuffer = sizeof(szBuffer); + char *pszBuffer = &szBuffer[0]; + + int cbWritten = _snprintf(pszBuffer, cbBuffer, "['%s' 0x%x.0x%x]: ", + vboxUmLogGetModuleName(), GetCurrentProcessId(), GetCurrentThreadId()); + if (cbWritten < 0 || cbWritten >= cbBuffer) + { + Assert(0); + pszBuffer[0] = 0; + cbWritten = 0; + } + + const size_t cbLeft = cbBuffer - cbWritten; + const size_t cbString = strlen(pszString) + 1; + if (cbString <= cbLeft) + { + memcpy(pszBuffer + cbWritten, pszString, cbString); + } + else + { + memcpy(pszBuffer + cbWritten, pszString, cbLeft - 1); + pszBuffer[cbWritten + cbLeft - 1] = 0; + } + + VBoxDispMpLoggerLog(szBuffer); +} diff --git a/src/VBox/Additions/3D/win/VBoxWddmUmHlp/VBoxWddmUmHlp.h b/src/VBox/Additions/3D/win/VBoxWddmUmHlp/VBoxWddmUmHlp.h new file mode 100644 index 00000000..b26dbb7f --- /dev/null +++ b/src/VBox/Additions/3D/win/VBoxWddmUmHlp/VBoxWddmUmHlp.h @@ -0,0 +1,100 @@ +/* $Id: VBoxWddmUmHlp.h $ */ +/** @file + * VBox WDDM User Mode Driver Helpers + */ + +/* + * Copyright (C) 2018-2020 Oracle Corporation + * + * This file is part of VirtualBox Open Source Edition (OSE), as + * available from http://www.virtualbox.org. This file is free software; + * you can redistribute it and/or modify it under the terms of the GNU + * General Public License (GPL) as published by the Free Software + * Foundation, in version 2 as it comes in the "COPYING" file of the + * VirtualBox OSE distribution. VirtualBox OSE is distributed in the + * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. + */ + +#ifndef GA_INCLUDED_SRC_3D_win_VBoxWddmUmHlp_VBoxWddmUmHlp_h +#define GA_INCLUDED_SRC_3D_win_VBoxWddmUmHlp_VBoxWddmUmHlp_h +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + +#include <iprt/win/d3d9.h> +#include <d3dumddi.h> +#include <d3dkmthk.h> + +#include <iprt/asm.h> +#include <iprt/cdefs.h> + +/* Do not require IPRT library. */ +#if defined(Assert) +#undef Assert +#endif +#ifdef RT_STRICT +#define Assert(_e) (void)( (!!(_e)) || (ASMBreakpoint(), 0) ) +#else +#define Assert(_e) (void)( 0 ) +#endif + +/* Do not require ntstatus.h. + * D3DKMT functions return NTSTATUS, but the driver code uses it only as a success/failure indicator. + * Therefore define the success and a failure status here. + */ +#ifndef STATUS_SUCCESS +#define STATUS_SUCCESS 0 +#endif +#ifndef STATUS_NOT_SUPPORTED +#define STATUS_NOT_SUPPORTED ((NTSTATUS)0xC00000BBL) +#endif + +RT_C_DECLS_BEGIN + +typedef struct VBOXWDDMDLLPROC +{ + char const *pszName; + FARPROC *ppfn; +} VBOXWDDMDLLPROC; + +typedef struct D3DKMTFUNCTIONS +{ + PFND3DKMT_OPENADAPTERFROMHDC pfnD3DKMTOpenAdapterFromHdc; + PFND3DKMT_OPENADAPTERFROMDEVICENAME pfnD3DKMTOpenAdapterFromDeviceName; + PFND3DKMT_CLOSEADAPTER pfnD3DKMTCloseAdapter; + PFND3DKMT_QUERYADAPTERINFO pfnD3DKMTQueryAdapterInfo; + PFND3DKMT_ESCAPE pfnD3DKMTEscape; + PFND3DKMT_CREATEDEVICE pfnD3DKMTCreateDevice; + PFND3DKMT_DESTROYDEVICE pfnD3DKMTDestroyDevice; + PFND3DKMT_CREATECONTEXT pfnD3DKMTCreateContext; + PFND3DKMT_DESTROYCONTEXT pfnD3DKMTDestroyContext; + PFND3DKMT_CREATEALLOCATION pfnD3DKMTCreateAllocation; + PFND3DKMT_DESTROYALLOCATION pfnD3DKMTDestroyAllocation; + PFND3DKMT_RENDER pfnD3DKMTRender; + PFND3DKMT_PRESENT pfnD3DKMTPresent; + PFND3DKMT_GETSHAREDPRIMARYHANDLE pfnD3DKMTGetSharedPrimaryHandle; + PFND3DKMT_QUERYRESOURCEINFO pfnD3DKMTQueryResourceInfo; + PFND3DKMT_OPENRESOURCE pfnD3DKMTOpenResource; + + /* Win 8+ */ + PFND3DKMT_ENUMADAPTERS pfnD3DKMTEnumAdapters; + PFND3DKMT_OPENADAPTERFROMLUID pfnD3DKMTOpenAdapterFromLuid; +} D3DKMTFUNCTIONS; + +DECLCALLBACK(HMODULE) VBoxWddmLoadSystemDll(const char *pszName); +DECLCALLBACK(void) VBoxWddmLoadAdresses(HMODULE hmod, VBOXWDDMDLLPROC *paProcs); + +DECLCALLBACK(int) D3DKMTLoad(void); +DECLCALLBACK(D3DKMTFUNCTIONS const *) D3DKMTFunctions(void); + +DECLCALLBACK(void) VBoxDispMpLoggerLogF(const char *pszString, ...); +DECLCALLBACK(void) VBoxWddmUmLog(const char *pszString); + +/** @todo Rename to VBoxWddm* */ +NTSTATUS vboxDispKmtOpenAdapter2(D3DKMT_HANDLE *phAdapter, LUID *pLuid); +NTSTATUS vboxDispKmtOpenAdapter(D3DKMT_HANDLE *phAdapter); +NTSTATUS vboxDispKmtCloseAdapter(D3DKMT_HANDLE hAdapter); + +RT_C_DECLS_END + +#endif /* !GA_INCLUDED_SRC_3D_win_VBoxWddmUmHlp_VBoxWddmUmHlp_h */ diff --git a/src/VBox/Additions/3D/win/include/VBoxGaDriver.h b/src/VBox/Additions/3D/win/include/VBoxGaDriver.h new file mode 100644 index 00000000..95a3322c --- /dev/null +++ b/src/VBox/Additions/3D/win/include/VBoxGaDriver.h @@ -0,0 +1,98 @@ +/* $Id: VBoxGaDriver.h $ */ +/** @file + * VirtualBox Windows Guest Mesa3D - Gallium driver interface. + */ + +/* + * Copyright (C) 2016-2020 Oracle Corporation + * + * This file is part of VirtualBox Open Source Edition (OSE), as + * available from http://www.virtualbox.org. This file is free software; + * you can redistribute it and/or modify it under the terms of the GNU + * General Public License (GPL) as published by the Free Software + * Foundation, in version 2 as it comes in the "COPYING" file of the + * VirtualBox OSE distribution. VirtualBox OSE is distributed in the + * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. + */ + +#ifndef GA_INCLUDED_3D_WIN_VBoxGaDriver_h +#define GA_INCLUDED_3D_WIN_VBoxGaDriver_h +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + +#include <VBoxGaHWInfo.h> +#include <VBoxGaTypes.h> + +#include <iprt/win/windows.h> + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct WDDMGalliumDriverEnv +{ + /* Size of the structure. */ + DWORD cb; + const VBOXGAHWINFO *pHWInfo; + /* The environment context pointer to use in the following callbacks. */ + void *pvEnv; + /* The callbacks to use by the driver. */ + DECLCALLBACKMEMBER(uint32_t, pfnContextCreate)(void *pvEnv, + boolean extended, + boolean vgpu10); + DECLCALLBACKMEMBER(void, pfnContextDestroy)(void *pvEnv, + uint32_t u32Cid); + DECLCALLBACKMEMBER(int, pfnSurfaceDefine)(void *pvEnv, + GASURFCREATE *pCreateParms, + GASURFSIZE *paSizes, + uint32_t cSizes, + uint32_t *pu32Sid); + DECLCALLBACKMEMBER(void, pfnSurfaceDestroy)(void *pvEnv, + uint32_t u32Sid); + DECLCALLBACKMEMBER(int, pfnRender)(void *pvEnv, + uint32_t u32Cid, + void *pvCommands, + uint32_t cbCommands, + GAFENCEQUERY *pFenceQuery); + DECLCALLBACKMEMBER(void, pfnFenceUnref)(void *pvEnv, + uint32_t u32FenceHandle); + DECLCALLBACKMEMBER(int, pfnFenceQuery)(void *pvEnv, + uint32_t u32FenceHandle, + GAFENCEQUERY *pFenceQuery); + DECLCALLBACKMEMBER(int, pfnFenceWait)(void *pvEnv, + uint32_t u32FenceHandle, + uint32_t u32TimeoutUS); + DECLCALLBACKMEMBER(int, pfnRegionCreate)(void *pvEnv, + uint32_t u32RegionSize, + uint32_t *pu32GmrId, + void **ppvMap); + DECLCALLBACKMEMBER(void, pfnRegionDestroy)(void *pvEnv, + uint32_t u32GmrId, + void *pvMap); +} WDDMGalliumDriverEnv; + +typedef struct pipe_screen * WINAPI FNGaDrvScreenCreate(const WDDMGalliumDriverEnv *pEnv); +typedef FNGaDrvScreenCreate *PFNGaDrvScreenCreate; + +typedef void WINAPI FNGaDrvScreenDestroy(struct pipe_screen *s); +typedef FNGaDrvScreenDestroy *PFNGaDrvScreenDestroy; + +typedef const WDDMGalliumDriverEnv * WINAPI FNGaDrvGetWDDMEnv(struct pipe_screen *pScreen); +typedef FNGaDrvGetWDDMEnv *PFNGaDrvGetWDDMEnv; + +typedef uint32_t WINAPI FNGaDrvGetContextId(struct pipe_context *pPipeContext); +typedef FNGaDrvGetContextId *PFNGaDrvGetContextId; + +typedef uint32_t WINAPI FNGaDrvGetSurfaceId(struct pipe_screen *pScreen, struct pipe_resource *pResource); +typedef FNGaDrvGetSurfaceId *PFNGaDrvGetSurfaceId; + +typedef void WINAPI FNGaDrvContextFlush(struct pipe_context *pPipeContext); +typedef FNGaDrvContextFlush *PFNGaDrvContextFlush; + +#ifdef __cplusplus +} +#endif + +#endif /* !GA_INCLUDED_3D_WIN_VBoxGaDriver_h */ + diff --git a/src/VBox/Additions/3D/win/include/VBoxGaHWInfo.h b/src/VBox/Additions/3D/win/include/VBoxGaHWInfo.h new file mode 100644 index 00000000..22d3af2e --- /dev/null +++ b/src/VBox/Additions/3D/win/include/VBoxGaHWInfo.h @@ -0,0 +1,54 @@ +/* $Id: VBoxGaHWInfo.h $ */ +/** @file + * VirtualBox Windows Guest Mesa3D - Gallium driver interface. + */ + +/* + * Copyright (C) 2016-2020 Oracle Corporation + * + * This file is part of VirtualBox Open Source Edition (OSE), as + * available from http://www.virtualbox.org. This file is free software; + * you can redistribute it and/or modify it under the terms of the GNU + * General Public License (GPL) as published by the Free Software + * Foundation, in version 2 as it comes in the "COPYING" file of the + * VirtualBox OSE distribution. VirtualBox OSE is distributed in the + * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. + */ + +#ifndef GA_INCLUDED_3D_WIN_VBoxGaHWInfo_h +#define GA_INCLUDED_3D_WIN_VBoxGaHWInfo_h +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + +#include <iprt/assert.h> + +#include <VBoxGaHwSVGA.h> + +/* Gallium virtual hardware supported by the miniport. */ +#define VBOX_GA_HW_TYPE_UNKNOWN 0 +#define VBOX_GA_HW_TYPE_VMSVGA 1 + +/* + * VBOXGAHWINFO contains information about the virtual hardware, which is passed + * to the user mode Gallium driver. The driver can not query the info at the initialization time, + * therefore we send the complete info to the driver. + * + * VBOXGAHWINFO struct goes both to 32 and 64 bit user mode binaries, take care of alignment. + */ +#pragma pack(1) +typedef struct VBOXGAHWINFO +{ + uint32_t u32HwType; /* VBOX_GA_HW_TYPE_* */ + uint32_t u32Reserved; + union + { + VBOXGAHWINFOSVGA svga; + uint8_t au8Raw[65536]; + } u; +} VBOXGAHWINFO; +#pragma pack() + +AssertCompile(RT_SIZEOFMEMB(VBOXGAHWINFO, u) <= RT_SIZEOFMEMB(VBOXGAHWINFO, u.au8Raw)); + +#endif /* !GA_INCLUDED_3D_WIN_VBoxGaHWInfo_h */ diff --git a/src/VBox/Additions/3D/win/include/VBoxGaHwSVGA.h b/src/VBox/Additions/3D/win/include/VBoxGaHwSVGA.h new file mode 100644 index 00000000..68b7edc1 --- /dev/null +++ b/src/VBox/Additions/3D/win/include/VBoxGaHwSVGA.h @@ -0,0 +1,56 @@ +/* $Id: VBoxGaHwSVGA.h $ */ +/** @file + * VirtualBox Windows Guest Mesa3D - Gallium driver interface. + */ + +/* + * Copyright (C) 2016-2020 Oracle Corporation + * + * This file is part of VirtualBox Open Source Edition (OSE), as + * available from http://www.virtualbox.org. This file is free software; + * you can redistribute it and/or modify it under the terms of the GNU + * General Public License (GPL) as published by the Free Software + * Foundation, in version 2 as it comes in the "COPYING" file of the + * VirtualBox OSE distribution. VirtualBox OSE is distributed in the + * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. + */ + +#ifndef GA_INCLUDED_3D_WIN_VBoxGaHwSVGA_h +#define GA_INCLUDED_3D_WIN_VBoxGaHwSVGA_h +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + +#include <iprt/types.h> + +/* + * VBOXGAHWINFOSVGA contains information about the virtual hardware, which is neede dy the user mode + * Gallium driver. The driver can not query the info at the initialization time, therefore + * we send the complete info to the driver. + * + * Since both FIFO and SVGA_REG_ are expanded over time, we reserve some space. + * The Gallium user mode driver can figure out which part of au32Regs and au32Fifo + * is valid from the raw data. + * + * VBOXGAHWINFOSVGA struct goes both to 32 and 64 bit user mode binaries, take care of alignment. + */ +#pragma pack(1) +typedef struct VBOXGAHWINFOSVGA +{ + uint32_t cbInfoSVGA; + + /* Copy of SVGA_REG_*, up to 256, currently 58 are used. */ + uint32_t au32Regs[256]; + + /* Copy of FIFO registers, up to 1024, currently 290 are used. */ + uint32_t au32Fifo[1024]; + + /* Currently SVGA has 244 caps, 512 should be ok for near future. + * This is a copy of SVGA_REG_DEV_CAP enumeration. + * Only valid if SVGA_CAP_GBOBJECTS is set in SVGA_REG_CAPABILITIES. + */ + uint32_t au32Caps[512]; +} VBOXGAHWINFOSVGA; +#pragma pack() + +#endif /* !GA_INCLUDED_3D_WIN_VBoxGaHwSVGA_h */ diff --git a/src/VBox/Additions/3D/win/include/VBoxGaNine.h b/src/VBox/Additions/3D/win/include/VBoxGaNine.h new file mode 100644 index 00000000..2195f289 --- /dev/null +++ b/src/VBox/Additions/3D/win/include/VBoxGaNine.h @@ -0,0 +1,48 @@ +/* $Id: VBoxGaNine.h $ */ +/** @file + * VirtualBox Windows Guest Mesa3D - Gallium driver interface for WDDM user mode driver. + */ + +/* + * Copyright (C) 2016-2020 Oracle Corporation + * + * This file is part of VirtualBox Open Source Edition (OSE), as + * available from http://www.virtualbox.org. This file is free software; + * you can redistribute it and/or modify it under the terms of the GNU + * General Public License (GPL) as published by the Free Software + * Foundation, in version 2 as it comes in the "COPYING" file of the + * VirtualBox OSE distribution. VirtualBox OSE is distributed in the + * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. + */ + +#ifndef GA_INCLUDED_3D_WIN_VBoxGaNine_h +#define GA_INCLUDED_3D_WIN_VBoxGaNine_h +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + +#include <iprt/win/d3d9.h> + +#ifdef __cplusplus +extern "C" { +#endif + +struct pipe_screen; +struct pipe_resource; +struct pipe_context; +typedef struct ID3DAdapter9 ID3DAdapter9; + +typedef HRESULT WINAPI FNGaNineD3DAdapter9Create(struct pipe_screen *s, ID3DAdapter9 **ppOut); +typedef FNGaNineD3DAdapter9Create *PFNGaNineD3DAdapter9Create; + +typedef struct pipe_resource * WINAPI FNGaNinePipeResourceFromSurface(IUnknown *pSurface); +typedef FNGaNinePipeResourceFromSurface *PFNGaNinePipeResourceFromSurface; + +typedef struct pipe_context * WINAPI FNGaNinePipeContextFromDevice(IDirect3DDevice9 *pDevice); +typedef FNGaNinePipeContextFromDevice *PFNGaNinePipeContextFromDevice; + +#ifdef __cplusplus +} +#endif + +#endif /* !GA_INCLUDED_3D_WIN_VBoxGaNine_h */ diff --git a/src/VBox/Additions/3D/win/include/VBoxGaTypes.h b/src/VBox/Additions/3D/win/include/VBoxGaTypes.h new file mode 100644 index 00000000..3e40be83 --- /dev/null +++ b/src/VBox/Additions/3D/win/include/VBoxGaTypes.h @@ -0,0 +1,78 @@ +/* $Id: VBoxGaTypes.h $ */ +/** @file + * VirtualBox Windows Guest Mesa3D - Gallium driver interface. + */ + +/* + * Copyright (C) 2016-2020 Oracle Corporation + * + * This file is part of VirtualBox Open Source Edition (OSE), as + * available from http://www.virtualbox.org. This file is free software; + * you can redistribute it and/or modify it under the terms of the GNU + * General Public License (GPL) as published by the Free Software + * Foundation, in version 2 as it comes in the "COPYING" file of the + * VirtualBox OSE distribution. VirtualBox OSE is distributed in the + * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. + */ + +#ifndef GA_INCLUDED_3D_WIN_VBoxGaTypes_h +#define GA_INCLUDED_3D_WIN_VBoxGaTypes_h +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + +#include <iprt/types.h> + +#ifdef __cplusplus +extern "C" { +#endif + +#define GA_MAX_SURFACE_FACES 6 +#define GA_MAX_MIP_LEVELS 24 + +typedef struct GASURFCREATE +{ + uint32_t flags; /* SVGA3dSurfaceFlags */ + uint32_t format; /* SVGA3dSurfaceFormat */ + uint32_t usage; /* SVGA_SURFACE_USAGE_* */ + uint32_t mip_levels[GA_MAX_SURFACE_FACES]; +} GASURFCREATE; + +typedef struct GASURFSIZE +{ + uint32_t cWidth; + uint32_t cHeight; + uint32_t cDepth; + uint32_t u32Reserved; +} GASURFSIZE; + +#define GA_FENCE_STATUS_NULL 0 /* Fence not found */ +#define GA_FENCE_STATUS_IDLE 1 +#define GA_FENCE_STATUS_SUBMITTED 2 +#define GA_FENCE_STATUS_SIGNALED 3 + +typedef struct GAFENCEQUERY +{ + /* IN: The miniport's handle of the fence. + * Assigned by the miniport. Not DXGK fence id! + */ + uint32_t u32FenceHandle; + + /* OUT: The miniport's sequence number associated with the command buffer. + */ + uint32_t u32SubmittedSeqNo; + + /* OUT: The miniport's sequence number associated with the last command buffer completed on host. + */ + uint32_t u32ProcessedSeqNo; + + /* OUT: GA_FENCE_STATUS_*. */ + uint32_t u32FenceStatus; +} GAFENCEQUERY; + +#ifdef __cplusplus +} +#endif + +#endif /* !GA_INCLUDED_3D_WIN_VBoxGaTypes_h */ + |