From f215e02bf85f68d3a6106c2a1f4f7f063f819064 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Thu, 11 Apr 2024 10:17:27 +0200 Subject: Adding upstream version 7.0.14-dfsg. Signed-off-by: Daniel Baumann --- src/VBox/Additions/3D/win/VBoxNine/VBoxNine.c | 181 ++++++++++++++++++++++++++ 1 file changed, 181 insertions(+) create mode 100644 src/VBox/Additions/3D/win/VBoxNine/VBoxNine.c (limited to 'src/VBox/Additions/3D/win/VBoxNine/VBoxNine.c') 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 . + * + * SPDX-License-Identifier: GPL-3.0-only + */ + +#include +#include +//#include + +#include + +//#include +//#include +//#include +//#include +//#include +//#include +//#include + +//#include +//#include +//#include +//#include +//#include +//#include +//#include + +#include "adapter9.h" +#include "surface9.h" +#include "pipe/p_screen.h" + +#include +// #include + +// #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; +} -- cgit v1.2.3