1 | /* $Id: VBoxGallium.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VirtualBox Windows Guest Mesa3D - Gallium driver interface. Constructs Gallium stack.
|
---|
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 "VBoxGallium.h"
|
---|
29 | #include <VBoxGaNine.h>
|
---|
30 |
|
---|
31 | #include "VBoxD3DAdapter9.h"
|
---|
32 | #include "VBoxPresent.h"
|
---|
33 | #include "VBoxGaD3DDevice9Ex.h"
|
---|
34 | #include "GaDrvEnvWddm.h"
|
---|
35 |
|
---|
36 | #include <VBox/log.h>
|
---|
37 |
|
---|
38 | #include <iprt/asm.h>
|
---|
39 | #include <iprt/string.h>
|
---|
40 |
|
---|
41 | /*
|
---|
42 | * Loading Gallium state tracker and driver:
|
---|
43 | * 1) load the hardware driver VBoxVMSVGA or VBoxVirGL:
|
---|
44 | * a) get an entry point to create the pipe_screen;
|
---|
45 | * b) create the pipe_screen passing handles required to call the WDDM miniport driver.
|
---|
46 | * 2) load VBoxNine:
|
---|
47 | * a) get an entry point to create the ID3DAdapter interface (GaNineD3DAdapter9Create);
|
---|
48 | * b) create ID3DAdapter passing the pipe_screen pointer.
|
---|
49 | * 3) create GaDirect3D9Ex to have IDirect3DEx or GaDirect3DDevice9Ex to have IDirect3DDevice9Ex,
|
---|
50 | * which is returned to WDDM user mode driver to substitute wine's IDirect3DDevice9Ex.
|
---|
51 | */
|
---|
52 |
|
---|
53 | static const char *gpszNineDll =
|
---|
54 | #ifdef VBOX_WDDM_WOW64
|
---|
55 | "VBoxNine-x86.dll"
|
---|
56 | #else
|
---|
57 | "VBoxNine.dll"
|
---|
58 | #endif
|
---|
59 | ;
|
---|
60 |
|
---|
61 | static const char *gpszSvgaDll =
|
---|
62 | #ifdef VBOX_WDDM_WOW64
|
---|
63 | "VBoxSVGA-x86.dll"
|
---|
64 | #else
|
---|
65 | "VBoxSVGA.dll"
|
---|
66 | #endif
|
---|
67 | ;
|
---|
68 |
|
---|
69 | /**
|
---|
70 | * Loads a system DLL.
|
---|
71 | *
|
---|
72 | * @returns Module handle or NULL
|
---|
73 | * @param pszName The DLL name.
|
---|
74 | */
|
---|
75 | static HMODULE loadSystemDll(const char *pszName)
|
---|
76 | {
|
---|
77 | char szPath[MAX_PATH];
|
---|
78 | UINT cchPath = GetSystemDirectoryA(szPath, sizeof(szPath));
|
---|
79 | size_t cbName = strlen(pszName) + 1;
|
---|
80 | if (cchPath + 1 + cbName > sizeof(szPath))
|
---|
81 | {
|
---|
82 | SetLastError(ERROR_FILENAME_EXCED_RANGE);
|
---|
83 | return NULL;
|
---|
84 | }
|
---|
85 | szPath[cchPath] = '\\';
|
---|
86 | memcpy(&szPath[cchPath + 1], pszName, cbName);
|
---|
87 | return LoadLibraryA(szPath);
|
---|
88 | }
|
---|
89 |
|
---|
90 | struct VBOXGAPROC
|
---|
91 | {
|
---|
92 | const char *pszName;
|
---|
93 | FARPROC *ppfn;
|
---|
94 | };
|
---|
95 |
|
---|
96 | static HRESULT getProcAddresses(HMODULE hmod, struct VBOXGAPROC *paProcs)
|
---|
97 | {
|
---|
98 | struct VBOXGAPROC *pIter = paProcs;
|
---|
99 | while (pIter->pszName)
|
---|
100 | {
|
---|
101 | FARPROC pfn = GetProcAddress(hmod, pIter->pszName);
|
---|
102 | if (pfn == NULL)
|
---|
103 | {
|
---|
104 | Log(("Failed to get the entry point: %s\n", pIter->pszName));
|
---|
105 | return E_FAIL;
|
---|
106 | }
|
---|
107 |
|
---|
108 | *pIter->ppfn = pfn;
|
---|
109 | ++pIter;
|
---|
110 | }
|
---|
111 |
|
---|
112 | return S_OK;
|
---|
113 | }
|
---|
114 |
|
---|
115 | static HRESULT loadDll(const char *pszName, HMODULE *phmod, struct VBOXGAPROC *paProcs)
|
---|
116 | {
|
---|
117 | *phmod = loadSystemDll(pszName);
|
---|
118 | if (!*phmod)
|
---|
119 | {
|
---|
120 | Log(("Failed to load the DLL: %s\n", pszName));
|
---|
121 | return E_FAIL;
|
---|
122 | }
|
---|
123 |
|
---|
124 | return getProcAddresses(*phmod, paProcs);
|
---|
125 | }
|
---|
126 |
|
---|
127 | /*
|
---|
128 | * GalliumStack
|
---|
129 | *
|
---|
130 | * Load Gallium dlls and provide helpers to create D3D9 interfaces and call Gallium driver API.
|
---|
131 | */
|
---|
132 | class VBoxGalliumStack: public IGalliumStack
|
---|
133 | {
|
---|
134 | public:
|
---|
135 | VBoxGalliumStack();
|
---|
136 | virtual ~VBoxGalliumStack();
|
---|
137 |
|
---|
138 | HRESULT Load();
|
---|
139 |
|
---|
140 | /* IUnknown methods */
|
---|
141 | STDMETHOD(QueryInterface)(THIS_ REFIID riid, void** ppvObj);
|
---|
142 | STDMETHOD_(ULONG,AddRef)(THIS);
|
---|
143 | STDMETHOD_(ULONG,Release)(THIS);
|
---|
144 |
|
---|
145 | /* IGalliumStack */
|
---|
146 | STDMETHOD(CreateDirect3DEx)(HANDLE hAdapter,
|
---|
147 | HANDLE hDevice,
|
---|
148 | const D3DDDI_DEVICECALLBACKS *pDeviceCallbacks,
|
---|
149 | const VBOXGAHWINFO *pHWInfo,
|
---|
150 | IDirect3D9Ex **ppOut);
|
---|
151 | STDMETHOD(GaCreateDeviceEx)(THIS_
|
---|
152 | D3DDEVTYPE DeviceType,HWND hFocusWindow,DWORD BehaviorFlags,
|
---|
153 | D3DPRESENT_PARAMETERS* pPresentationParameters,
|
---|
154 | D3DDISPLAYMODEEX* pFullscreenDisplayMode,
|
---|
155 | HANDLE hAdapter,
|
---|
156 | HANDLE hDevice,
|
---|
157 | const D3DDDI_DEVICECALLBACKS *pDeviceCallbacks,
|
---|
158 | const VBOXGAHWINFO *pHWInfo,
|
---|
159 | IDirect3DDevice9Ex** ppReturnedDeviceInterface);
|
---|
160 |
|
---|
161 | STDMETHOD(GaNineD3DAdapter9Create)(struct pipe_screen *s, ID3DAdapter9 **ppOut);
|
---|
162 | STDMETHOD_(struct pipe_resource *, GaNinePipeResourceFromSurface)(IUnknown *pSurface);
|
---|
163 | STDMETHOD_(struct pipe_context *, GaNinePipeContextFromDevice)(IDirect3DDevice9 *pDevice);
|
---|
164 |
|
---|
165 | STDMETHOD_(struct pipe_screen *, GaDrvScreenCreate)(const WDDMGalliumDriverEnv *pEnv);
|
---|
166 | STDMETHOD_(void, GaDrvScreenDestroy)(struct pipe_screen *s);
|
---|
167 | STDMETHOD_(WDDMGalliumDriverEnv const *, GaDrvGetWDDMEnv)(struct pipe_screen *pScreen);
|
---|
168 | STDMETHOD_(uint32_t, GaDrvGetContextId)(struct pipe_context *pPipeContext);
|
---|
169 | STDMETHOD_(uint32_t, GaDrvGetSurfaceId)(struct pipe_screen *pScreen, struct pipe_resource *pResource);
|
---|
170 | STDMETHOD_(void, GaDrvContextFlush)(struct pipe_context *pPipeContext);
|
---|
171 |
|
---|
172 | private:
|
---|
173 | void unload();
|
---|
174 |
|
---|
175 | volatile ULONG mcRefs;
|
---|
176 |
|
---|
177 | HMODULE mhmodStateTracker;
|
---|
178 | HMODULE mhmodDriver;
|
---|
179 |
|
---|
180 | struct GaNineFunctions
|
---|
181 | {
|
---|
182 | PFNGaNineD3DAdapter9Create pfnGaNineD3DAdapter9Create;
|
---|
183 | PFNGaNinePipeResourceFromSurface pfnGaNinePipeResourceFromSurface;
|
---|
184 | PFNGaNinePipeContextFromDevice pfnGaNinePipeContextFromDevice;
|
---|
185 | } mNine;
|
---|
186 |
|
---|
187 | struct GaDrvFunctions
|
---|
188 | {
|
---|
189 | PFNGaDrvScreenCreate pfnGaDrvScreenCreate;
|
---|
190 | PFNGaDrvScreenDestroy pfnGaDrvScreenDestroy;
|
---|
191 | PFNGaDrvGetWDDMEnv pfnGaDrvGetWDDMEnv;
|
---|
192 | PFNGaDrvGetContextId pfnGaDrvGetContextId;
|
---|
193 | PFNGaDrvGetSurfaceId pfnGaDrvGetSurfaceId;
|
---|
194 | PFNGaDrvContextFlush pfnGaDrvContextFlush;
|
---|
195 | } mDrv;
|
---|
196 | };
|
---|
197 |
|
---|
198 |
|
---|
199 | /*
|
---|
200 | * IDirect3D9Ex implementation corresponds to one WDDM device.
|
---|
201 | */
|
---|
202 | class GaDirect3D9Ex: public IGaDirect3D9Ex
|
---|
203 | {
|
---|
204 | public:
|
---|
205 | GaDirect3D9Ex(VBoxGalliumStack *pStack);
|
---|
206 | virtual ~GaDirect3D9Ex();
|
---|
207 |
|
---|
208 | HRESULT Init(HANDLE hAdapter,
|
---|
209 | HANDLE hDevice,
|
---|
210 | const D3DDDI_DEVICECALLBACKS *pDeviceCallbacks,
|
---|
211 | const VBOXGAHWINFO *pHWInfo);
|
---|
212 |
|
---|
213 | /*** IUnknown methods ***/
|
---|
214 | STDMETHOD(QueryInterface)(THIS_ REFIID riid, void** ppvObj);
|
---|
215 | STDMETHOD_(ULONG,AddRef)(THIS);
|
---|
216 | STDMETHOD_(ULONG,Release)(THIS);
|
---|
217 |
|
---|
218 | /*** IDirect3D9 methods ***/
|
---|
219 | STDMETHOD(RegisterSoftwareDevice)(THIS_ void* pInitializeFunction);
|
---|
220 | STDMETHOD_(UINT, GetAdapterCount)(THIS);
|
---|
221 | STDMETHOD(GetAdapterIdentifier)(THIS_ UINT Adapter,DWORD Flags,D3DADAPTER_IDENTIFIER9* pIdentifier);
|
---|
222 | STDMETHOD_(UINT, GetAdapterModeCount)(THIS_ UINT Adapter,D3DFORMAT Format);
|
---|
223 | STDMETHOD(EnumAdapterModes)(THIS_ UINT Adapter,D3DFORMAT Format,UINT Mode,D3DDISPLAYMODE* pMode);
|
---|
224 | STDMETHOD(GetAdapterDisplayMode)(THIS_ UINT Adapter,D3DDISPLAYMODE* pMode);
|
---|
225 | STDMETHOD(CheckDeviceType)(THIS_ UINT Adapter,D3DDEVTYPE DevType,D3DFORMAT AdapterFormat,
|
---|
226 | D3DFORMAT BackBufferFormat,BOOL bWindowed);
|
---|
227 | STDMETHOD(CheckDeviceFormat)(THIS_ UINT Adapter,D3DDEVTYPE DeviceType,D3DFORMAT AdapterFormat,
|
---|
228 | DWORD Usage,D3DRESOURCETYPE RType,D3DFORMAT CheckFormat);
|
---|
229 | STDMETHOD(CheckDeviceMultiSampleType)(THIS_ UINT Adapter,D3DDEVTYPE DeviceType,D3DFORMAT SurfaceFormat,
|
---|
230 | BOOL Windowed,D3DMULTISAMPLE_TYPE MultiSampleType,DWORD* pQualityLevels);
|
---|
231 | STDMETHOD(CheckDepthStencilMatch)(THIS_ UINT Adapter,D3DDEVTYPE DeviceType,D3DFORMAT AdapterFormat,
|
---|
232 | D3DFORMAT RenderTargetFormat,D3DFORMAT DepthStencilFormat);
|
---|
233 | STDMETHOD(CheckDeviceFormatConversion)(THIS_ UINT Adapter,D3DDEVTYPE DeviceType,D3DFORMAT SourceFormat,
|
---|
234 | D3DFORMAT TargetFormat);
|
---|
235 | STDMETHOD(GetDeviceCaps)(THIS_ UINT Adapter,D3DDEVTYPE DeviceType,D3DCAPS9* pCaps);
|
---|
236 | STDMETHOD_(HMONITOR, GetAdapterMonitor)(THIS_ UINT Adapter);
|
---|
237 | STDMETHOD(CreateDevice)(THIS_ UINT Adapter,D3DDEVTYPE DeviceType,HWND hFocusWindow,
|
---|
238 | DWORD BehaviorFlags,D3DPRESENT_PARAMETERS* pPresentationParameters,
|
---|
239 | IDirect3DDevice9** ppReturnedDeviceInterface);
|
---|
240 |
|
---|
241 | /*** IDirect3D9Ex methods ***/
|
---|
242 | STDMETHOD_(UINT, GetAdapterModeCountEx)(THIS_ UINT Adapter,CONST D3DDISPLAYMODEFILTER* pFilter);
|
---|
243 | STDMETHOD(EnumAdapterModesEx)(THIS_ UINT Adapter,CONST D3DDISPLAYMODEFILTER* pFilter,
|
---|
244 | UINT Mode,D3DDISPLAYMODEEX* pMode);
|
---|
245 | STDMETHOD(GetAdapterDisplayModeEx)(THIS_ UINT Adapter,D3DDISPLAYMODEEX* pMode,D3DDISPLAYROTATION* pRotation);
|
---|
246 | STDMETHOD(CreateDeviceEx)(THIS_ UINT Adapter,D3DDEVTYPE DeviceType,HWND hFocusWindow,DWORD BehaviorFlags,
|
---|
247 | D3DPRESENT_PARAMETERS* pPresentationParameters,
|
---|
248 | D3DDISPLAYMODEEX* pFullscreenDisplayMode,
|
---|
249 | IDirect3DDevice9Ex** ppReturnedDeviceInterface);
|
---|
250 | STDMETHOD(GetAdapterLUID)(THIS_ UINT Adapter,LUID * pLUID);
|
---|
251 |
|
---|
252 | /* IGaDirect3D9Ex methods */
|
---|
253 | STDMETHOD_(IGalliumStack *, GetGalliumStack)(THIS);
|
---|
254 | STDMETHOD_(ID3DAdapter9 *, GetAdapter9)(THIS);
|
---|
255 | STDMETHOD_(struct pipe_screen *, GetScreen)(THIS);
|
---|
256 |
|
---|
257 | private:
|
---|
258 | void cleanup();
|
---|
259 |
|
---|
260 | volatile ULONG mcRefs;
|
---|
261 |
|
---|
262 | VBoxGalliumStack *mpStack;
|
---|
263 | struct pipe_screen *mpPipeScreen;
|
---|
264 | ID3DAdapter9 *mpD3DAdapter9;
|
---|
265 |
|
---|
266 | /* The Gallium driver environment helper object. */
|
---|
267 | GaDrvEnvWddm mEnv;
|
---|
268 | };
|
---|
269 |
|
---|
270 |
|
---|
271 | /*
|
---|
272 | * VBoxGalliumStack implementation.
|
---|
273 | */
|
---|
274 |
|
---|
275 | VBoxGalliumStack::VBoxGalliumStack()
|
---|
276 | :
|
---|
277 | mcRefs(0),
|
---|
278 | mhmodStateTracker(0),
|
---|
279 | mhmodDriver(0)
|
---|
280 | {
|
---|
281 | RT_ZERO(mNine);
|
---|
282 | RT_ZERO(mDrv);
|
---|
283 | }
|
---|
284 |
|
---|
285 | VBoxGalliumStack::~VBoxGalliumStack()
|
---|
286 | {
|
---|
287 | unload();
|
---|
288 | }
|
---|
289 |
|
---|
290 | STDMETHODIMP_(ULONG) VBoxGalliumStack::AddRef()
|
---|
291 | {
|
---|
292 | ULONG refs = InterlockedIncrement(&mcRefs);
|
---|
293 | return refs;
|
---|
294 | }
|
---|
295 |
|
---|
296 | STDMETHODIMP_(ULONG) VBoxGalliumStack::Release()
|
---|
297 | {
|
---|
298 | ULONG refs = InterlockedDecrement(&mcRefs);
|
---|
299 | if (refs == 0)
|
---|
300 | {
|
---|
301 | delete this;
|
---|
302 | }
|
---|
303 | return refs;
|
---|
304 | }
|
---|
305 |
|
---|
306 | STDMETHODIMP VBoxGalliumStack::QueryInterface(REFIID riid,
|
---|
307 | void **ppvObject)
|
---|
308 | {
|
---|
309 | if (!ppvObject)
|
---|
310 | {
|
---|
311 | return E_POINTER;
|
---|
312 | }
|
---|
313 |
|
---|
314 | if (IsEqualGUID(IID_IUnknown, riid))
|
---|
315 | {
|
---|
316 | AddRef();
|
---|
317 | *ppvObject = this;
|
---|
318 | return S_OK;
|
---|
319 | }
|
---|
320 |
|
---|
321 | *ppvObject = NULL;
|
---|
322 | return E_NOINTERFACE;
|
---|
323 | }
|
---|
324 |
|
---|
325 | HRESULT VBoxGalliumStack::Load()
|
---|
326 | {
|
---|
327 | struct VBOXGAPROC aNineProcs[] =
|
---|
328 | {
|
---|
329 | { "GaNineD3DAdapter9Create", (FARPROC *)&mNine.pfnGaNineD3DAdapter9Create },
|
---|
330 | { "GaNinePipeResourceFromSurface", (FARPROC *)&mNine.pfnGaNinePipeResourceFromSurface },
|
---|
331 | { "GaNinePipeContextFromDevice", (FARPROC *)&mNine.pfnGaNinePipeContextFromDevice },
|
---|
332 | { NULL, NULL }
|
---|
333 | };
|
---|
334 |
|
---|
335 | struct VBOXGAPROC aDrvProcs[] =
|
---|
336 | {
|
---|
337 | { "GaDrvScreenCreate", (FARPROC *)&mDrv.pfnGaDrvScreenCreate },
|
---|
338 | { "GaDrvScreenDestroy", (FARPROC *)&mDrv.pfnGaDrvScreenDestroy },
|
---|
339 | { "GaDrvGetWDDMEnv", (FARPROC *)&mDrv.pfnGaDrvGetWDDMEnv },
|
---|
340 | { "GaDrvGetContextId", (FARPROC *)&mDrv.pfnGaDrvGetContextId },
|
---|
341 | { "GaDrvGetSurfaceId", (FARPROC *)&mDrv.pfnGaDrvGetSurfaceId },
|
---|
342 | { "GaDrvContextFlush", (FARPROC *)&mDrv.pfnGaDrvContextFlush },
|
---|
343 | { NULL, NULL }
|
---|
344 | };
|
---|
345 |
|
---|
346 | /** @todo Select the driver dll according to the hardware. */
|
---|
347 | const char *pszDriverDll = gpszSvgaDll;
|
---|
348 |
|
---|
349 | HRESULT hr = loadDll(pszDriverDll, &mhmodDriver, aDrvProcs);
|
---|
350 | if (SUCCEEDED(hr))
|
---|
351 | {
|
---|
352 | hr = loadDll(gpszNineDll, &mhmodStateTracker, aNineProcs);
|
---|
353 | }
|
---|
354 |
|
---|
355 | return hr;
|
---|
356 | }
|
---|
357 |
|
---|
358 | void VBoxGalliumStack::unload()
|
---|
359 | {
|
---|
360 | RT_ZERO(mNine);
|
---|
361 | RT_ZERO(mDrv);
|
---|
362 |
|
---|
363 | if (mhmodStateTracker)
|
---|
364 | {
|
---|
365 | FreeLibrary(mhmodStateTracker);
|
---|
366 | mhmodStateTracker = 0;
|
---|
367 | }
|
---|
368 |
|
---|
369 | if (mhmodDriver)
|
---|
370 | {
|
---|
371 | FreeLibrary(mhmodDriver);
|
---|
372 | mhmodDriver = 0;
|
---|
373 | }
|
---|
374 | }
|
---|
375 |
|
---|
376 | STDMETHODIMP VBoxGalliumStack::GaNineD3DAdapter9Create(struct pipe_screen *s,
|
---|
377 | ID3DAdapter9 **ppOut)
|
---|
378 | {
|
---|
379 | return mNine.pfnGaNineD3DAdapter9Create(s, ppOut);
|
---|
380 | }
|
---|
381 |
|
---|
382 | STDMETHODIMP_(struct pipe_resource *) VBoxGalliumStack::GaNinePipeResourceFromSurface(IUnknown *pSurface)
|
---|
383 | {
|
---|
384 | return mNine.pfnGaNinePipeResourceFromSurface(pSurface);
|
---|
385 | }
|
---|
386 |
|
---|
387 | STDMETHODIMP_(struct pipe_context *) VBoxGalliumStack::GaNinePipeContextFromDevice(IDirect3DDevice9 *pDevice)
|
---|
388 | {
|
---|
389 | return mNine.pfnGaNinePipeContextFromDevice(pDevice);
|
---|
390 | }
|
---|
391 |
|
---|
392 | STDMETHODIMP_(struct pipe_screen *) VBoxGalliumStack::GaDrvScreenCreate(const WDDMGalliumDriverEnv *pEnv)
|
---|
393 | {
|
---|
394 | return mDrv.pfnGaDrvScreenCreate(pEnv);
|
---|
395 | }
|
---|
396 |
|
---|
397 | STDMETHODIMP_(void) VBoxGalliumStack::GaDrvScreenDestroy(struct pipe_screen *s)
|
---|
398 | {
|
---|
399 | mDrv.pfnGaDrvScreenDestroy(s);
|
---|
400 | }
|
---|
401 |
|
---|
402 | STDMETHODIMP_(WDDMGalliumDriverEnv const *) VBoxGalliumStack::GaDrvGetWDDMEnv(struct pipe_screen *pScreen)
|
---|
403 | {
|
---|
404 | return mDrv.pfnGaDrvGetWDDMEnv(pScreen);
|
---|
405 | }
|
---|
406 |
|
---|
407 | STDMETHODIMP_(uint32_t) VBoxGalliumStack::GaDrvGetContextId(struct pipe_context *pPipeContext)
|
---|
408 | {
|
---|
409 | return mDrv.pfnGaDrvGetContextId(pPipeContext);
|
---|
410 | }
|
---|
411 |
|
---|
412 | STDMETHODIMP_(uint32_t) VBoxGalliumStack::GaDrvGetSurfaceId(struct pipe_screen *pScreen,
|
---|
413 | struct pipe_resource *pResource)
|
---|
414 | {
|
---|
415 | return mDrv.pfnGaDrvGetSurfaceId(pScreen, pResource);
|
---|
416 | }
|
---|
417 |
|
---|
418 | STDMETHODIMP_(void) VBoxGalliumStack::GaDrvContextFlush(struct pipe_context *pPipeContext)
|
---|
419 | {
|
---|
420 | mDrv.pfnGaDrvContextFlush(pPipeContext);
|
---|
421 | }
|
---|
422 |
|
---|
423 | STDMETHODIMP VBoxGalliumStack::CreateDirect3DEx(HANDLE hAdapter,
|
---|
424 | HANDLE hDevice,
|
---|
425 | const D3DDDI_DEVICECALLBACKS *pDeviceCallbacks,
|
---|
426 | const VBOXGAHWINFO *pHWInfo,
|
---|
427 | IDirect3D9Ex **ppOut)
|
---|
428 | {
|
---|
429 | GaDirect3D9Ex *p = new GaDirect3D9Ex(this);
|
---|
430 | if (!p)
|
---|
431 | return E_OUTOFMEMORY;
|
---|
432 |
|
---|
433 | HRESULT hr = p->Init(hAdapter, hDevice, pDeviceCallbacks, pHWInfo);
|
---|
434 | if (SUCCEEDED(hr))
|
---|
435 | {
|
---|
436 | p->AddRef();
|
---|
437 | *ppOut = p;
|
---|
438 | }
|
---|
439 | else
|
---|
440 | {
|
---|
441 | delete p;
|
---|
442 | }
|
---|
443 |
|
---|
444 | return hr;
|
---|
445 | }
|
---|
446 |
|
---|
447 | STDMETHODIMP VBoxGalliumStack::GaCreateDeviceEx(D3DDEVTYPE DeviceType,
|
---|
448 | HWND hFocusWindow,
|
---|
449 | DWORD BehaviorFlags,
|
---|
450 | D3DPRESENT_PARAMETERS* pPresentationParameters,
|
---|
451 | D3DDISPLAYMODEEX* pFullscreenDisplayMode,
|
---|
452 | HANDLE hAdapter,
|
---|
453 | HANDLE hDevice,
|
---|
454 | const D3DDDI_DEVICECALLBACKS *pDeviceCallbacks,
|
---|
455 | const VBOXGAHWINFO *pHWInfo,
|
---|
456 | IDirect3DDevice9Ex **ppReturnedDeviceInterface)
|
---|
457 | {
|
---|
458 | /* Create the per-WDDM-device gallium adapter. */
|
---|
459 | IGaDirect3D9Ex *pD3D9 = NULL;
|
---|
460 | HRESULT hr = CreateDirect3DEx(hAdapter,
|
---|
461 | hDevice,
|
---|
462 | pDeviceCallbacks,
|
---|
463 | pHWInfo,
|
---|
464 | (IDirect3D9Ex **)&pD3D9);
|
---|
465 | if (SUCCEEDED(hr))
|
---|
466 | {
|
---|
467 | /* Create wrapper object for IDirect3DDevice9Ex */
|
---|
468 | GaDirect3DDevice9Ex *p = new GaDirect3DDevice9Ex(pD3D9, hAdapter, hDevice, pDeviceCallbacks);
|
---|
469 | if (p)
|
---|
470 | {
|
---|
471 | hr = p->Init(DeviceType, hFocusWindow, BehaviorFlags, pPresentationParameters, pFullscreenDisplayMode);
|
---|
472 | if (SUCCEEDED(hr))
|
---|
473 | {
|
---|
474 | p->AddRef();
|
---|
475 | *ppReturnedDeviceInterface = p;
|
---|
476 | }
|
---|
477 | else
|
---|
478 | {
|
---|
479 | delete p;
|
---|
480 | }
|
---|
481 | }
|
---|
482 | else
|
---|
483 | {
|
---|
484 | hr = E_OUTOFMEMORY;
|
---|
485 | }
|
---|
486 |
|
---|
487 | pD3D9->Release();
|
---|
488 | }
|
---|
489 |
|
---|
490 | return hr;
|
---|
491 | }
|
---|
492 |
|
---|
493 | HRESULT GalliumStackCreate(IGalliumStack **ppOut)
|
---|
494 | {
|
---|
495 | VBoxGalliumStack *p = new VBoxGalliumStack();
|
---|
496 | if (!p)
|
---|
497 | return E_OUTOFMEMORY;
|
---|
498 |
|
---|
499 | HRESULT hr = p->Load();
|
---|
500 | if (SUCCEEDED(hr))
|
---|
501 | {
|
---|
502 | p->AddRef();
|
---|
503 | *ppOut = p;
|
---|
504 | }
|
---|
505 | else
|
---|
506 | {
|
---|
507 | delete p;
|
---|
508 | }
|
---|
509 |
|
---|
510 | return hr;
|
---|
511 | }
|
---|
512 |
|
---|
513 |
|
---|
514 | /*
|
---|
515 | * GaDirect3D9Ex
|
---|
516 | *
|
---|
517 | * IDirect3D9Ex implementation based on Gallium D3D9 state tracker "nine".
|
---|
518 | */
|
---|
519 |
|
---|
520 | GaDirect3D9Ex::GaDirect3D9Ex(VBoxGalliumStack *pStack)
|
---|
521 | :
|
---|
522 | mcRefs(0),
|
---|
523 | mpStack(pStack),
|
---|
524 | mpPipeScreen(0),
|
---|
525 | mpD3DAdapter9(0)
|
---|
526 | {
|
---|
527 | mpStack->AddRef();
|
---|
528 | }
|
---|
529 |
|
---|
530 | GaDirect3D9Ex::~GaDirect3D9Ex()
|
---|
531 | {
|
---|
532 | cleanup();
|
---|
533 | }
|
---|
534 |
|
---|
535 | STDMETHODIMP_(ULONG) GaDirect3D9Ex::AddRef()
|
---|
536 | {
|
---|
537 | ULONG refs = InterlockedIncrement(&mcRefs);
|
---|
538 | return refs;
|
---|
539 | }
|
---|
540 |
|
---|
541 | STDMETHODIMP_(ULONG) GaDirect3D9Ex::Release()
|
---|
542 | {
|
---|
543 | ULONG refs = InterlockedDecrement(&mcRefs);
|
---|
544 | if (refs == 0)
|
---|
545 | {
|
---|
546 | delete this;
|
---|
547 | }
|
---|
548 | return refs;
|
---|
549 | }
|
---|
550 |
|
---|
551 | STDMETHODIMP GaDirect3D9Ex::QueryInterface(REFIID riid,
|
---|
552 | void **ppvObject)
|
---|
553 | {
|
---|
554 | if (!ppvObject)
|
---|
555 | {
|
---|
556 | return E_POINTER;
|
---|
557 | }
|
---|
558 |
|
---|
559 | if ( IsEqualGUID(IID_IGaDirect3D9Ex, riid)
|
---|
560 | || IsEqualGUID(IID_IDirect3D9Ex, riid)
|
---|
561 | || IsEqualGUID(IID_IDirect3D9, riid)
|
---|
562 | || IsEqualGUID(IID_IUnknown, riid))
|
---|
563 | {
|
---|
564 | AddRef();
|
---|
565 | *ppvObject = this;
|
---|
566 | return S_OK;
|
---|
567 | }
|
---|
568 |
|
---|
569 | *ppvObject = NULL;
|
---|
570 | return E_NOINTERFACE;
|
---|
571 | }
|
---|
572 |
|
---|
573 | HRESULT GaDirect3D9Ex::Init(HANDLE hAdapter,
|
---|
574 | HANDLE hDevice,
|
---|
575 | const D3DDDI_DEVICECALLBACKS *pDeviceCallbacks,
|
---|
576 | const VBOXGAHWINFO *pHWInfo)
|
---|
577 | {
|
---|
578 | LogFunc(("%p %p %p\n", hAdapter, hDevice, pDeviceCallbacks));
|
---|
579 |
|
---|
580 | HRESULT hr;
|
---|
581 |
|
---|
582 | mEnv.Init(hAdapter, hDevice, pDeviceCallbacks, pHWInfo);
|
---|
583 | const WDDMGalliumDriverEnv *pEnv = mEnv.Env();
|
---|
584 |
|
---|
585 | mpPipeScreen = mpStack->GaDrvScreenCreate(pEnv);
|
---|
586 | if (mpPipeScreen)
|
---|
587 | {
|
---|
588 | hr = mpStack->GaNineD3DAdapter9Create(mpPipeScreen, &mpD3DAdapter9);
|
---|
589 | Assert(SUCCEEDED(hr));
|
---|
590 | }
|
---|
591 | else
|
---|
592 | {
|
---|
593 | hr = E_FAIL;
|
---|
594 | AssertFailed();
|
---|
595 | }
|
---|
596 |
|
---|
597 | return hr;
|
---|
598 | }
|
---|
599 |
|
---|
600 | void GaDirect3D9Ex::cleanup()
|
---|
601 | {
|
---|
602 | if (mpD3DAdapter9)
|
---|
603 | {
|
---|
604 | D3DAdapter9_Release(mpD3DAdapter9);
|
---|
605 | mpD3DAdapter9 = NULL;
|
---|
606 | }
|
---|
607 |
|
---|
608 | if (mpPipeScreen)
|
---|
609 | {
|
---|
610 | mpStack->GaDrvScreenDestroy(mpPipeScreen);
|
---|
611 | mpPipeScreen = NULL;
|
---|
612 | }
|
---|
613 |
|
---|
614 | if (mpStack)
|
---|
615 | {
|
---|
616 | mpStack->Release();
|
---|
617 | mpStack = 0;
|
---|
618 | }
|
---|
619 | }
|
---|
620 |
|
---|
621 | #define TRAPNOTIMPL do { \
|
---|
622 | ASMBreakpoint(); \
|
---|
623 | } while (0)
|
---|
624 |
|
---|
625 |
|
---|
626 | STDMETHODIMP GaDirect3D9Ex::RegisterSoftwareDevice(void *pInitializeFunction)
|
---|
627 | {
|
---|
628 | RT_NOREF(pInitializeFunction);
|
---|
629 | TRAPNOTIMPL;
|
---|
630 | return D3DERR_INVALIDCALL;
|
---|
631 | }
|
---|
632 |
|
---|
633 | STDMETHODIMP_(UINT) GaDirect3D9Ex::GetAdapterCount()
|
---|
634 | {
|
---|
635 | TRAPNOTIMPL;
|
---|
636 | return 1;
|
---|
637 | }
|
---|
638 |
|
---|
639 | STDMETHODIMP GaDirect3D9Ex::GetAdapterIdentifier(UINT Adapter,
|
---|
640 | DWORD Flags,
|
---|
641 | D3DADAPTER_IDENTIFIER9 *pIdentifier)
|
---|
642 | {
|
---|
643 | RT_NOREF3(Adapter, Flags, pIdentifier);
|
---|
644 | TRAPNOTIMPL;
|
---|
645 | return D3DERR_INVALIDCALL;
|
---|
646 | }
|
---|
647 |
|
---|
648 | STDMETHODIMP_(UINT) GaDirect3D9Ex::GetAdapterModeCount(UINT Adapter,
|
---|
649 | D3DFORMAT Format)
|
---|
650 | {
|
---|
651 | RT_NOREF2(Adapter, Format);
|
---|
652 | TRAPNOTIMPL;
|
---|
653 | return 1;
|
---|
654 | }
|
---|
655 |
|
---|
656 | STDMETHODIMP GaDirect3D9Ex::EnumAdapterModes(UINT Adapter,
|
---|
657 | D3DFORMAT Format,
|
---|
658 | UINT Mode,
|
---|
659 | D3DDISPLAYMODE *pMode)
|
---|
660 | {
|
---|
661 | RT_NOREF4(Adapter, Format, Mode, pMode);
|
---|
662 | TRAPNOTIMPL;
|
---|
663 | return D3DERR_INVALIDCALL;
|
---|
664 | }
|
---|
665 |
|
---|
666 | STDMETHODIMP GaDirect3D9Ex::GetAdapterDisplayMode(UINT Adapter,
|
---|
667 | D3DDISPLAYMODE *pMode)
|
---|
668 | {
|
---|
669 | RT_NOREF2(Adapter, pMode);
|
---|
670 | TRAPNOTIMPL;
|
---|
671 | return D3DERR_INVALIDCALL;
|
---|
672 | }
|
---|
673 |
|
---|
674 | STDMETHODIMP GaDirect3D9Ex::CheckDeviceType(UINT iAdapter,
|
---|
675 | D3DDEVTYPE DevType,
|
---|
676 | D3DFORMAT DisplayFormat,
|
---|
677 | D3DFORMAT BackBufferFormat,
|
---|
678 | BOOL bWindowed)
|
---|
679 | {
|
---|
680 | RT_NOREF5(iAdapter, DevType, DisplayFormat, BackBufferFormat, bWindowed);
|
---|
681 | TRAPNOTIMPL;
|
---|
682 | return D3DERR_INVALIDCALL;
|
---|
683 | }
|
---|
684 |
|
---|
685 | STDMETHODIMP GaDirect3D9Ex::CheckDeviceFormat(UINT Adapter,
|
---|
686 | D3DDEVTYPE DeviceType,
|
---|
687 | D3DFORMAT AdapterFormat,
|
---|
688 | DWORD Usage,
|
---|
689 | D3DRESOURCETYPE RType,
|
---|
690 | D3DFORMAT CheckFormat)
|
---|
691 | {
|
---|
692 | RT_NOREF6(Adapter, DeviceType, AdapterFormat, Usage, RType, CheckFormat);
|
---|
693 | TRAPNOTIMPL;
|
---|
694 | return D3DERR_INVALIDCALL;
|
---|
695 | }
|
---|
696 |
|
---|
697 | STDMETHODIMP GaDirect3D9Ex::CheckDeviceMultiSampleType(UINT Adapter,
|
---|
698 | D3DDEVTYPE DeviceType,
|
---|
699 | D3DFORMAT SurfaceFormat,
|
---|
700 | BOOL Windowed,
|
---|
701 | D3DMULTISAMPLE_TYPE MultiSampleType,
|
---|
702 | DWORD *pQualityLevels)
|
---|
703 | {
|
---|
704 | RT_NOREF6(Adapter, DeviceType, SurfaceFormat, Windowed, MultiSampleType, pQualityLevels);
|
---|
705 | TRAPNOTIMPL;
|
---|
706 | return D3DERR_INVALIDCALL;
|
---|
707 | }
|
---|
708 |
|
---|
709 | STDMETHODIMP GaDirect3D9Ex::CheckDepthStencilMatch(UINT Adapter,
|
---|
710 | D3DDEVTYPE DeviceType,
|
---|
711 | D3DFORMAT AdapterFormat,
|
---|
712 | D3DFORMAT RenderTargetFormat,
|
---|
713 | D3DFORMAT DepthStencilFormat)
|
---|
714 | {
|
---|
715 | RT_NOREF5(Adapter, DeviceType, AdapterFormat, RenderTargetFormat, DepthStencilFormat);
|
---|
716 | TRAPNOTIMPL;
|
---|
717 | return D3DERR_INVALIDCALL;
|
---|
718 | }
|
---|
719 |
|
---|
720 | STDMETHODIMP GaDirect3D9Ex::CheckDeviceFormatConversion(UINT Adapter,
|
---|
721 | D3DDEVTYPE DeviceType,
|
---|
722 | D3DFORMAT SourceFormat,
|
---|
723 | D3DFORMAT TargetFormat)
|
---|
724 | {
|
---|
725 | RT_NOREF4(Adapter, DeviceType, SourceFormat, TargetFormat);
|
---|
726 | TRAPNOTIMPL;
|
---|
727 | return D3DERR_INVALIDCALL;
|
---|
728 | }
|
---|
729 |
|
---|
730 | STDMETHODIMP GaDirect3D9Ex::GetDeviceCaps(UINT Adapter,
|
---|
731 | D3DDEVTYPE DeviceType,
|
---|
732 | D3DCAPS9 *pCaps)
|
---|
733 | {
|
---|
734 | RT_NOREF(Adapter);
|
---|
735 | HRESULT hr = D3DAdapter9_GetDeviceCaps(mpD3DAdapter9, DeviceType, pCaps);
|
---|
736 | return hr;
|
---|
737 | }
|
---|
738 |
|
---|
739 | STDMETHODIMP_(HMONITOR) GaDirect3D9Ex::GetAdapterMonitor(UINT Adapter)
|
---|
740 | {
|
---|
741 | RT_NOREF(Adapter);
|
---|
742 | TRAPNOTIMPL;
|
---|
743 | return NULL;
|
---|
744 | }
|
---|
745 |
|
---|
746 | STDMETHODIMP GaDirect3D9Ex::CreateDevice(UINT Adapter,
|
---|
747 | D3DDEVTYPE DeviceType,
|
---|
748 | HWND hFocusWindow,
|
---|
749 | DWORD BehaviorFlags,
|
---|
750 | D3DPRESENT_PARAMETERS *pPresentationParameters,
|
---|
751 | IDirect3DDevice9 **ppReturnedDeviceInterface)
|
---|
752 | {
|
---|
753 | return CreateDeviceEx(Adapter, DeviceType, hFocusWindow, BehaviorFlags, pPresentationParameters,
|
---|
754 | NULL, (IDirect3DDevice9Ex **)ppReturnedDeviceInterface);
|
---|
755 | }
|
---|
756 |
|
---|
757 | STDMETHODIMP_(UINT) GaDirect3D9Ex::GetAdapterModeCountEx(UINT Adapter,
|
---|
758 | CONST D3DDISPLAYMODEFILTER *pFilter)
|
---|
759 | {
|
---|
760 | RT_NOREF2(Adapter, pFilter);
|
---|
761 | TRAPNOTIMPL;
|
---|
762 | return 1;
|
---|
763 | }
|
---|
764 |
|
---|
765 | STDMETHODIMP GaDirect3D9Ex::EnumAdapterModesEx(UINT Adapter,
|
---|
766 | CONST D3DDISPLAYMODEFILTER *pFilter,
|
---|
767 | UINT Mode,
|
---|
768 | D3DDISPLAYMODEEX *pMode)
|
---|
769 | {
|
---|
770 | RT_NOREF4(Adapter, pFilter, Mode, pMode);
|
---|
771 | TRAPNOTIMPL;
|
---|
772 | return D3DERR_INVALIDCALL;
|
---|
773 | }
|
---|
774 |
|
---|
775 | STDMETHODIMP GaDirect3D9Ex::GetAdapterDisplayModeEx(UINT Adapter,
|
---|
776 | D3DDISPLAYMODEEX *pMode,
|
---|
777 | D3DDISPLAYROTATION *pRotation)
|
---|
778 | {
|
---|
779 | RT_NOREF3(Adapter, pMode, pRotation);
|
---|
780 | TRAPNOTIMPL;
|
---|
781 | return D3DERR_INVALIDCALL;
|
---|
782 | }
|
---|
783 |
|
---|
784 | STDMETHODIMP GaDirect3D9Ex::CreateDeviceEx(UINT Adapter,
|
---|
785 | D3DDEVTYPE DeviceType,
|
---|
786 | HWND hFocusWindow,
|
---|
787 | DWORD BehaviorFlags,
|
---|
788 | D3DPRESENT_PARAMETERS *pPresentationParameters,
|
---|
789 | D3DDISPLAYMODEEX *pFullscreenDisplayMode,
|
---|
790 | IDirect3DDevice9Ex **ppReturnedDeviceInterface)
|
---|
791 | {
|
---|
792 | RT_NOREF7(Adapter, DeviceType, hFocusWindow, BehaviorFlags, pPresentationParameters,
|
---|
793 | pFullscreenDisplayMode, ppReturnedDeviceInterface);
|
---|
794 | /* This method should never be called. GaCreateDeviceEx is the right one. */
|
---|
795 | TRAPNOTIMPL;
|
---|
796 | return D3DERR_INVALIDCALL;
|
---|
797 | }
|
---|
798 |
|
---|
799 | STDMETHODIMP GaDirect3D9Ex::GetAdapterLUID(UINT Adapter,
|
---|
800 | LUID *pLUID)
|
---|
801 | {
|
---|
802 | RT_NOREF2(Adapter, pLUID);
|
---|
803 | TRAPNOTIMPL;
|
---|
804 | return D3DERR_INVALIDCALL;
|
---|
805 | }
|
---|
806 |
|
---|
807 | STDMETHODIMP_(IGalliumStack *) GaDirect3D9Ex::GetGalliumStack(void)
|
---|
808 | {
|
---|
809 | return mpStack;
|
---|
810 | }
|
---|
811 |
|
---|
812 | STDMETHODIMP_(ID3DAdapter9 *) GaDirect3D9Ex::GetAdapter9(void)
|
---|
813 | {
|
---|
814 | return mpD3DAdapter9;
|
---|
815 | }
|
---|
816 |
|
---|
817 | STDMETHODIMP_(struct pipe_screen *) GaDirect3D9Ex::GetScreen(void)
|
---|
818 | {
|
---|
819 | return mpPipeScreen;
|
---|
820 | }
|
---|