diff options
Diffstat (limited to 'src/VBox/Additions/3D/win/VBoxNine')
-rw-r--r-- | src/VBox/Additions/3D/win/VBoxNine/Makefile.kmk | 74 | ||||
-rw-r--r-- | src/VBox/Additions/3D/win/VBoxNine/VBoxNine.c | 181 | ||||
-rw-r--r-- | src/VBox/Additions/3D/win/VBoxNine/VBoxNine.def | 34 | ||||
-rw-r--r-- | src/VBox/Additions/3D/win/VBoxNine/VBoxNine.rc | 66 | ||||
-rw-r--r-- | src/VBox/Additions/3D/win/VBoxNine/nine/nine_memory_helper.c | 176 |
5 files changed, 531 insertions, 0 deletions
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..43f4906b --- /dev/null +++ b/src/VBox/Additions/3D/win/VBoxNine/Makefile.kmk @@ -0,0 +1,74 @@ +# $Id: Makefile.kmk $ +## @file +# Sub-Makefile for VBoxNine D3D9 state tracker. +# + +# +# Copyright (C) 2016-2023 Oracle and/or its affiliates. +# +# This file is part of VirtualBox base platform packages, as +# available from https://www.virtualbox.org. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation, in version 3 of the +# License. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, see <https://www.gnu.org/licenses>. +# +# SPDX-License-Identifier: GPL-3.0-only +# + +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/frontends/nine +VBoxNine_SOURCES = \ + nine/nine_memory_helper.c \ + 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)/VBoxMesaLib$(VBOX_SUFF_LIB) \ + $(VBOX_PATH_ADDITIONS_LIB)/VBoxMesaUtilLib$(VBOX_SUFF_LIB) \ + $(VBOX_PATH_ADDITIONS_LIB)/VBoxMesaNineLib$(VBOX_SUFF_LIB) + +if defined(VBOX_SIGNING_MODE) && defined(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)/VBoxMesaLib-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..59b73db6 --- /dev/null +++ b/src/VBox/Additions/3D/win/VBoxNine/VBoxNine.c @@ -0,0 +1,181 @@ +/* $Id: VBoxNine.c $ */ +/** @file + * VirtualBox Windows Guest Mesa3D - Direct3D9 state tracker. + */ + +/* + * Copyright (C) 2016-2023 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * SPDX-License-Identifier: GPL-3.0-only + */ + +#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.hal = s; + /** @todo Need software device here. Currently assigned to hw device to prevent NineDevice9_ctor crash. */ + ctx->base.ref = ctx->base.hal; + // D3DADAPTER_IDENTIFIER9 identifier; + ctx->base.linear_framebuffer = TRUE; + ctx->base.throttling = FALSE; + ctx->base.throttling_value = 0; + ctx->base.vblank_mode = 1; + ctx->base.thread_submit = FALSE; + ctx->base.discard_delayed_release = FALSE; + ctx->base.tearfree_discard = FALSE; + ctx->base.csmt_force = FALSE; + ctx->base.dynamic_texture_workaround = FALSE; + ctx->base.shader_inline_constants = FALSE; + ctx->base.memfd_virtualsizelimit = -1; + ctx->base.override_vram_size = -1; + ctx->base.destroy = wddm_destroy; + + + /* 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..5197ba7b --- /dev/null +++ b/src/VBox/Additions/3D/win/VBoxNine/VBoxNine.def @@ -0,0 +1,34 @@ +; $Id: VBoxNine.def $; +;; @file +; Export definition file for the VBoxNine D3D9 state tracker. +; + +; +; Copyright (C) 2016-2023 Oracle and/or its affiliates. +; +; This file is part of VirtualBox base platform packages, as +; available from https://www.virtualbox.org. +; +; This program is free software; you can redistribute it and/or +; modify it under the terms of the GNU General Public License +; as published by the Free Software Foundation, in version 3 of the +; License. +; +; This program is distributed in the hope that it will be useful, but +; WITHOUT ANY WARRANTY; without even the implied warranty of +; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +; General Public License for more details. +; +; You should have received a copy of the GNU General Public License +; along with this program; if not, see <https://www.gnu.org/licenses>. +; +; SPDX-License-Identifier: GPL-3.0-only +; + +LIBRARY VBOXNINE + +EXPORTS + GaNineD3DAdapter9Create @1 + 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..4ad22662 --- /dev/null +++ b/src/VBox/Additions/3D/win/VBoxNine/VBoxNine.rc @@ -0,0 +1,66 @@ +/* $Id: VBoxNine.rc $ */ +/** @file + * VBoxNine - Resource file containing version info and icon. + */ + +/* + * Copyright (C) 2016-2023 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * SPDX-License-Identifier: GPL-3.0-only + */ + +#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/VBoxNine/nine/nine_memory_helper.c b/src/VBox/Additions/3D/win/VBoxNine/nine/nine_memory_helper.c new file mode 100644 index 00000000..9fe5c652 --- /dev/null +++ b/src/VBox/Additions/3D/win/VBoxNine/nine/nine_memory_helper.c @@ -0,0 +1,176 @@ +/* + * Copyright (C) 2016-2023 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * SPDX-License-Identifier: GPL-3.0-only + */ + +/* + * Copyright 2020 Axel Davy <davyaxel0@gmail.com> + * + * 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 + * on the rights to use, copy, modify, merge, publish, distribute, sub + * license, 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 (including the next + * paragraph) 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 NON-INFRINGEMENT. IN NO EVENT SHALL + * THE AUTHOR(S) AND/OR THEIR SUPPLIERS 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 "util/list.h" +#include "util/u_memory.h" +#include "util/slab.h" + +#include "nine_debug.h" +#include "nine_memory_helper.h" +#include "nine_state.h" + +#include <iprt/win/windows.h> + +#define DIVUP(a,b) (((a)+(b)-1)/(b)) + +/* Required alignment for allocations */ +#define NINE_ALLOCATION_ALIGNMENT 32 + +#define DBG_CHANNEL (DBG_BASETEXTURE|DBG_SURFACE|DBG_VOLUME|DBG_TEXTURE|DBG_CUBETEXTURE) + +struct nine_allocation { + unsigned is_external; + void *external; +}; + +struct nine_allocator { + struct slab_mempool external_allocation_pool; + CRITICAL_SECTION mutex_slab; +}; + +struct nine_allocation * +nine_allocate(struct nine_allocator *allocator, unsigned size) +{ + struct nine_allocation *allocation; + (void)allocator; + assert(sizeof(struct nine_allocation) <= NINE_ALLOCATION_ALIGNMENT); + allocation = align_calloc(size + NINE_ALLOCATION_ALIGNMENT, NINE_ALLOCATION_ALIGNMENT); + allocation->is_external = false; + return allocation; +} + + +void nine_free(struct nine_allocator *allocator, struct nine_allocation *allocation) +{ + if (allocation->is_external) { + EnterCriticalSection(&allocator->mutex_slab); + slab_free_st(&allocator->external_allocation_pool, allocation); + LeaveCriticalSection(&allocator->mutex_slab); + } else + align_free(allocation); +} + +void nine_free_worker(struct nine_allocator *allocator, struct nine_allocation *allocation) +{ + nine_free(allocator, allocation); +} + +void *nine_get_pointer(struct nine_allocator *allocator, struct nine_allocation *allocation) +{ + (void)allocator; + if (allocation->is_external) + return allocation->external; + return (uint8_t *)allocation + NINE_ALLOCATION_ALIGNMENT; +} + +void nine_pointer_weakrelease(struct nine_allocator *allocator, struct nine_allocation *allocation) +{ + (void)allocator; + (void)allocation; +} + +void nine_pointer_strongrelease(struct nine_allocator *allocator, struct nine_allocation *allocation) +{ + (void)allocator; + (void)allocation; +} + +void nine_pointer_delayedstrongrelease(struct nine_allocator *allocator, + struct nine_allocation *allocation, + unsigned *counter) +{ + (void)allocator; + (void)allocation; + (void)counter; +} + +struct nine_allocation * +nine_suballocate(struct nine_allocator* allocator, struct nine_allocation *allocation, int offset) +{ + struct nine_allocation *new_allocation; + EnterCriticalSection(&allocator->mutex_slab); + new_allocation = slab_alloc_st(&allocator->external_allocation_pool); + LeaveCriticalSection(&allocator->mutex_slab); + new_allocation->is_external = true; + if (allocation->is_external) + new_allocation->external = (uint8_t *)allocation->external + offset; + else + new_allocation->external = (uint8_t *)allocation + NINE_ALLOCATION_ALIGNMENT + offset; + return new_allocation; +} + +struct nine_allocation * +nine_wrap_external_pointer(struct nine_allocator* allocator, void* data) +{ + struct nine_allocation *new_allocation; + EnterCriticalSection(&allocator->mutex_slab); + new_allocation = slab_alloc_st(&allocator->external_allocation_pool); + LeaveCriticalSection(&allocator->mutex_slab); + new_allocation->is_external = true; + new_allocation->external = data; + return new_allocation; +} + +struct nine_allocator * +nine_allocator_create(struct NineDevice9 *device, int memfd_virtualsizelimit) +{ + struct nine_allocator* allocator = MALLOC(sizeof(struct nine_allocator)); + (void)device; + (void)memfd_virtualsizelimit; + + if (!allocator) + return NULL; + + slab_create(&allocator->external_allocation_pool, sizeof(struct nine_allocation), 4096); + InitializeCriticalSection(&allocator->mutex_slab); + + return allocator; +} + +void +nine_allocator_destroy(struct nine_allocator *allocator) +{ + slab_destroy(&allocator->external_allocation_pool); + DeleteCriticalSection(&allocator->mutex_slab); +} |