VirtualBox

source: vbox/trunk/src/VBox/Additions/3D/win/VBoxNine/VBoxNine.c

Last change on this file was 103999, checked in by vboxsync, 2 months ago

Addition/3D,Additions/WINNT/Graphics: Updates for mesa-24.0.2 (not enabled yet). bugref:10606

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.2 KB
Line 
1/* $Id: VBoxNine.c 103999 2024-03-22 12:38:39Z vboxsync $ */
2/** @file
3 * VirtualBox Windows Guest Mesa3D - Direct3D9 state tracker.
4 */
5
6/*
7 * Copyright (C) 2016-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28#include <iprt/win/windows.h>
29#include <iprt/win/d3d9.h>
30//#include <d3dumddi.h>
31
32#if VBOX_MESA_V_MAJOR >= 24
33#include <VBoxGaDriver.h>
34#endif
35#include <VBoxWddmUmHlp.h>
36
37//#include <windef.h>
38//#include <winbase.h>
39//#include <winsvc.h>
40//#include <winnetwk.h>
41//#include <npapi.h>
42//#include <devioctl.h>
43//#include <stdio.h>
44
45//#include <iprt/alloc.h>
46#include <iprt/initterm.h>
47//#include <iprt/string.h>
48//#include <iprt/log.h>
49//#include <VBox/version.h>
50//#include <VBox/VMMDev.h>
51//#include <VBox/Log.h>
52
53#include "adapter9.h"
54#include "surface9.h"
55#include "pipe/p_screen.h"
56
57#include <iprt/types.h>
58// #include <iprt/asm.h>
59
60// #include "VBoxNine.h"
61
62#if VBOX_MESA_V_MAJOR >= 24
63struct pipe_screen * WINAPI GaDrvScreenCreate(const WDDMGalliumDriverEnv *pEnv);
64void WINAPI GaDrvScreenDestroy(struct pipe_screen *s);
65uint32_t WINAPI GaDrvGetSurfaceId(struct pipe_screen *pScreen, struct pipe_resource *pResource);
66const WDDMGalliumDriverEnv *WINAPI GaDrvGetWDDMEnv(struct pipe_screen *pScreen);
67uint32_t WINAPI GaDrvGetContextId(struct pipe_context *pPipeContext);
68void WINAPI GaDrvContextFlush(struct pipe_context *pPipeContext);
69#endif
70
71struct d3dadapter9_context_wddm
72{
73 struct d3dadapter9_context base;
74 void *reserved;
75};
76
77static void
78wddm_destroy(struct d3dadapter9_context *ctx)
79{
80 /* struct d3dadapter9_context_wddm *ctx_wddm = (struct d3dadapter9_context_wddm *)ctx; */
81
82/// @todo screen (hal) is deleted by the upper level. Do not delete here.
83// if (ctx->ref)
84// ctx->ref->destroy(ctx->ref);
85// /* because ref is a wrapper around hal, freeing ref frees hal too. */
86// else if (ctx->hal)
87// ctx->hal->destroy(ctx->hal);
88
89 FREE(ctx);
90}
91
92static HRESULT
93d3dadapter9_context_wddm_create(struct d3dadapter9_context_wddm **ppCtx, struct pipe_screen *s)
94{
95 struct d3dadapter9_context_wddm *ctx = CALLOC_STRUCT(d3dadapter9_context_wddm);
96
97 if (!ctx) { return E_OUTOFMEMORY; }
98
99 ctx->base.hal = s;
100 /** @todo Need software device here. Currently assigned to hw device to prevent NineDevice9_ctor crash. */
101 ctx->base.ref = ctx->base.hal;
102 // D3DADAPTER_IDENTIFIER9 identifier;
103 ctx->base.linear_framebuffer = TRUE;
104 ctx->base.throttling = FALSE;
105 ctx->base.throttling_value = 0;
106 ctx->base.vblank_mode = 1;
107 ctx->base.thread_submit = FALSE;
108 ctx->base.discard_delayed_release = FALSE;
109 ctx->base.tearfree_discard = FALSE;
110 ctx->base.csmt_force = FALSE;
111 ctx->base.dynamic_texture_workaround = FALSE;
112 ctx->base.shader_inline_constants = FALSE;
113 ctx->base.memfd_virtualsizelimit = -1;
114 ctx->base.override_vram_size = -1;
115 ctx->base.destroy = wddm_destroy;
116
117
118 /* read out PCI info */
119 /// @todo read_descriptor(&ctx->base, fd);
120
121 *ppCtx = ctx;
122 return D3D_OK;
123}
124
125#if VBOX_MESA_V_MAJOR < 24
126HRESULT WINAPI
127GaNineD3DAdapter9Create(struct pipe_screen *s, ID3DAdapter9 **ppOut)
128{
129 HRESULT hr;
130 struct d3dadapter9_context_wddm *pCtx = NULL;
131 hr = d3dadapter9_context_wddm_create(&pCtx, s);
132 if (SUCCEEDED(hr))
133 {
134 hr = NineAdapter9_new(&pCtx->base, (struct NineAdapter9 **)ppOut);
135 if (FAILED(hr))
136 {
137 /// @todo NineAdapter9_new calls this as ctx->base.destroy,
138 // and will not call if memory allocation fails.
139 // wddm_destroy(&pCtx->base);
140 }
141 }
142 return hr;
143}
144
145struct pipe_resource * WINAPI
146GaNinePipeResourceFromSurface(IUnknown *pSurface)
147{
148 /// @todo QueryInterface?
149 struct NineResource9 *pResource = (struct NineResource9 *)pSurface;
150 return pResource->resource;
151}
152
153extern struct pipe_context *
154NineDevice9_GetPipe( struct NineDevice9 *This );
155
156struct pipe_context * WINAPI
157GaNinePipeContextFromDevice(IDirect3DDevice9 *pDevice)
158{
159 /// @todo Verify that this is a NineDevice?
160 struct pipe_context *pPipeContext = NineDevice9_GetPipe((struct NineDevice9 *)pDevice);
161 return pPipeContext;
162}
163
164#else /* VBOX_MESA_V_MAJOR >= 24 */
165
166HRESULT WINAPI
167GaNineD3DAdapter9Create(const WDDMGalliumDriverEnv *pEnv, ID3DAdapter9 **ppOut)
168{
169 HRESULT hr;
170 struct pipe_screen *s = GaDrvScreenCreate(pEnv);
171 if (s)
172 {
173 struct d3dadapter9_context_wddm *ctx = NULL;
174 hr = d3dadapter9_context_wddm_create(&ctx, s);
175 if (SUCCEEDED(hr))
176 {
177 hr = NineAdapter9_new(&ctx->base, (struct NineAdapter9 **)ppOut);
178 if (FAILED(hr))
179 {
180 /// @todo NineAdapter9_new calls this as ctx->base.destroy,
181 // and will not call if memory allocation fails.
182 // wddm_destroy(&pCtx->base);
183 }
184 }
185 Assert(SUCCEEDED(hr));
186 }
187 else
188 {
189 hr = E_FAIL;
190 AssertFailed();
191 }
192 return hr;
193}
194
195uint32_t WINAPI
196GaNineGetSurfaceId(IUnknown *pSurface)
197{
198 uint32_t sid = SVGA_ID_INVALID;
199
200 /// @todo QueryInterface?
201 struct NineResource9 *pNineResource = (struct NineResource9 *)pSurface;
202 struct pipe_resource *r = pNineResource->resource;
203 if (r)
204 {
205 struct pipe_screen *s = r->screen;
206 sid = GaDrvGetSurfaceId(s, r);
207 }
208
209 return sid;
210}
211
212extern struct pipe_context *
213NineDevice9_GetPipe( struct NineDevice9 *This );
214
215uint32_t WINAPI
216GaNineGetContextId(IDirect3DDevice9 *pDevice)
217{
218 uint32_t cid = SVGA_ID_INVALID;
219
220 /// @todo Verify that this is a NineDevice?
221 struct pipe_context *pipe = NineDevice9_GetPipe((struct NineDevice9 *)pDevice);
222 if (pipe)
223 cid = GaDrvGetContextId(pipe);
224
225 return cid;
226}
227
228void WINAPI
229GaNineFlush(IDirect3DDevice9 *pDevice)
230{
231 struct pipe_context *pipe = NineDevice9_GetPipe((struct NineDevice9 *)pDevice);
232 if (pipe)
233 GaDrvContextFlush(pipe);
234}
235#endif /* VBOX_MESA_V_MAJOR >= 24 */
236
237BOOL WINAPI DllMain(HINSTANCE hDLLInst,
238 DWORD fdwReason,
239 LPVOID lpvReserved)
240{
241 BOOL fReturn = TRUE;
242
243 RT_NOREF2(hDLLInst, lpvReserved);
244
245 switch (fdwReason)
246 {
247 case DLL_PROCESS_ATTACH:
248 RTR3InitDll(RTR3INIT_FLAGS_UNOBTRUSIVE);
249 D3DKMTLoad();
250 break;
251
252 case DLL_PROCESS_DETACH:
253 /// @todo RTR3Term();
254 break;
255
256 case DLL_THREAD_ATTACH:
257 break;
258
259 case DLL_THREAD_DETACH:
260 break;
261
262 default:
263 break;
264 }
265
266 return fReturn;
267}
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use