VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispD3DIf.cpp@ 46593

Last change on this file since 46593 was 46593, checked in by vboxsync, 11 years ago

updates

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 37.7 KB
Line 
1/* $Id: VBoxDispD3DIf.cpp 46593 2013-06-17 14:32:51Z vboxsync $ */
2
3/** @file
4 * VBoxVideo Display D3D User mode dll
5 */
6
7/*
8 * Copyright (C) 2011-2012 Oracle Corporation
9 *
10 * This file is part of VirtualBox Open Source Edition (OSE), as
11 * available from http://www.virtualbox.org. This file is free software;
12 * you can redistribute it and/or modify it under the terms of the GNU
13 * General Public License (GPL) as published by the Free Software
14 * Foundation, in version 2 as it comes in the "COPYING" file of the
15 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
17 */
18
19#include "VBoxDispD3DIf.h"
20#include "VBoxDispD3DCmn.h"
21
22#include <iprt/assert.h>
23
24void VBoxDispD3DClose(VBOXDISPD3D *pD3D)
25{
26 FreeLibrary(pD3D->hD3DLib);
27 pD3D->hD3DLib = NULL;
28}
29
30/**
31 * Loads a system DLL.
32 *
33 * @returns Module handle or NULL
34 * @param pszName The DLL name.
35 */
36static HMODULE loadSystemDll(const char *pszName)
37{
38 char szPath[MAX_PATH];
39 UINT cchPath = GetSystemDirectoryA(szPath, sizeof(szPath));
40 size_t cbName = strlen(pszName) + 1;
41 if (cchPath + 1 + cbName > sizeof(szPath))
42 {
43 SetLastError(ERROR_FILENAME_EXCED_RANGE);
44 return NULL;
45 }
46 szPath[cchPath] = '\\';
47 memcpy(&szPath[cchPath + 1], pszName, cbName);
48 return LoadLibraryA(szPath);
49}
50
51HRESULT VBoxDispD3DOpen(VBOXDISPD3D *pD3D)
52{
53#ifdef VBOX_WDDM_WOW64
54 pD3D->hD3DLib = loadSystemDll("VBoxD3D9wddm-x86.dll");
55#else
56 pD3D->hD3DLib = loadSystemDll("VBoxD3D9wddm.dll");
57#endif
58 if (!pD3D->hD3DLib)
59 {
60 DWORD winErr = GetLastError();
61 WARN((__FUNCTION__": LoadLibrary failed, winErr = (%d)", winErr));
62 return E_FAIL;
63 }
64
65 do
66 {
67 pD3D->pfnDirect3DCreate9Ex = (PFNVBOXDISPD3DCREATE9EX)GetProcAddress(pD3D->hD3DLib, "Direct3DCreate9Ex");
68 if (!pD3D->pfnDirect3DCreate9Ex)
69 {
70 WARN(("no Direct3DCreate9Ex"));
71 break;
72 }
73
74 pD3D->pfnVBoxWineExD3DDev9CreateTexture = (PFNVBOXWINEEXD3DDEV9_CREATETEXTURE)GetProcAddress(pD3D->hD3DLib, "VBoxWineExD3DDev9CreateTexture");
75 if (!pD3D->pfnVBoxWineExD3DDev9CreateTexture)
76 {
77 WARN(("no VBoxWineExD3DDev9CreateTexture"));
78 break;
79 }
80
81 pD3D->pfnVBoxWineExD3DDev9CreateCubeTexture = (PFNVBOXWINEEXD3DDEV9_CREATECUBETEXTURE)GetProcAddress(pD3D->hD3DLib, "VBoxWineExD3DDev9CreateCubeTexture");
82 if (!pD3D->pfnVBoxWineExD3DDev9CreateCubeTexture)
83 {
84 WARN(("no VBoxWineExD3DDev9CreateCubeTexture"));
85 break;
86 }
87
88 pD3D->pfnVBoxWineExD3DDev9CreateVolumeTexture = (PFNVBOXWINEEXD3DDEV9_CREATEVOLUMETEXTURE)GetProcAddress(pD3D->hD3DLib, "VBoxWineExD3DDev9CreateVolumeTexture");
89 if (!pD3D->pfnVBoxWineExD3DDev9CreateVolumeTexture)
90 {
91 WARN(("no VBoxWineExD3DDev9CreateVolumeTexture"));
92 break;
93 }
94
95 pD3D->pfnVBoxWineExD3DDev9Flush = (PFNVBOXWINEEXD3DDEV9_FLUSH)GetProcAddress(pD3D->hD3DLib, "VBoxWineExD3DDev9Flush");
96 if (!pD3D->pfnVBoxWineExD3DDev9Flush)
97 {
98 WARN(("no VBoxWineExD3DDev9Flush"));
99 break;
100 }
101
102 pD3D->pfnVBoxWineExD3DDev9FlushToHost = (PFNVBOXWINEEXD3DDEV9_FLUSHTOHOST)GetProcAddress(pD3D->hD3DLib, "VBoxWineExD3DDev9FlushToHost");
103 if (!pD3D->pfnVBoxWineExD3DDev9FlushToHost)
104 {
105 WARN(("no VBoxWineExD3DDev9FlushToHost"));
106 break;
107 }
108
109 pD3D->pfnVBoxWineExD3DDev9Finish = (PFNVBOXWINEEXD3DDEV9_FINISH)GetProcAddress(pD3D->hD3DLib, "VBoxWineExD3DDev9Finish");
110 if (!pD3D->pfnVBoxWineExD3DDev9Finish)
111 {
112 WARN(("no VBoxWineExD3DDev9Finish"));
113 break;
114 }
115
116 pD3D->pfnVBoxWineExD3DDev9VolBlt = (PFNVBOXWINEEXD3DDEV9_VOLBLT)GetProcAddress(pD3D->hD3DLib, "VBoxWineExD3DDev9VolBlt");
117 if (!pD3D->pfnVBoxWineExD3DDev9VolBlt)
118 {
119 WARN(("no VBoxWineExD3DDev9VolBlt"));
120 break;
121 }
122
123 pD3D->pfnVBoxWineExD3DDev9VolTexBlt = (PFNVBOXWINEEXD3DDEV9_VOLTEXBLT)GetProcAddress(pD3D->hD3DLib, "VBoxWineExD3DDev9VolTexBlt");
124 if (!pD3D->pfnVBoxWineExD3DDev9VolTexBlt)
125 {
126 WARN(("no VBoxWineExD3DDev9VolTexBlt"));
127 break;
128 }
129
130 pD3D->pfnVBoxWineExD3DDev9Term = (PFNVBOXWINEEXD3DDEV9_TERM)GetProcAddress(pD3D->hD3DLib, "VBoxWineExD3DDev9Term");
131 if (!pD3D->pfnVBoxWineExD3DDev9Term)
132 {
133 WARN(("no VBoxWineExD3DDev9Term"));
134 break;
135 }
136
137 pD3D->pfnVBoxWineExD3DSwapchain9Present = (PFNVBOXWINEEXD3DSWAPCHAIN9_PRESENT)GetProcAddress(pD3D->hD3DLib, "VBoxWineExD3DSwapchain9Present");
138 if (!pD3D->pfnVBoxWineExD3DSwapchain9Present)
139 {
140 WARN(("no VBoxWineExD3DSwapchain9Present"));
141 break;
142 }
143
144 return S_OK;
145
146 } while (0);
147
148 VBoxDispD3DClose(pD3D);
149
150 return E_FAIL;
151}
152
153
154
155static FORMATOP gVBoxFormatOps3D[] = {
156 {D3DDDIFMT_A8R8G8B8,
157 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|
158 FORMATOP_SAME_FORMAT_RENDERTARGET|
159 FORMATOP_SAME_FORMAT_UP_TO_ALPHA_RENDERTARGET|
160 FORMATOP_CONVERT_TO_ARGB|FORMATOP_OFFSCREENPLAIN|FORMATOP_SRGBREAD|
161 FORMATOP_MEMBEROFGROUP_ARGB|
162 FORMATOP_SRGBWRITE|FORMATOP_VERTEXTEXTURE, 0, 0, 0},
163
164 {D3DDDIFMT_X8R8G8B8,
165 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|
166 FORMATOP_SAME_FORMAT_RENDERTARGET|
167 FORMATOP_DISPLAYMODE|FORMATOP_3DACCELERATION|
168 FORMATOP_CONVERT_TO_ARGB|FORMATOP_OFFSCREENPLAIN|FORMATOP_SRGBREAD|
169 FORMATOP_MEMBEROFGROUP_ARGB|
170 FORMATOP_SRGBWRITE|FORMATOP_VERTEXTEXTURE, 0, 0, 0},
171
172 {D3DDDIFMT_A2R10G10B10,
173 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|
174 FORMATOP_SAME_FORMAT_RENDERTARGET|
175 0|
176 FORMATOP_CONVERT_TO_ARGB|FORMATOP_OFFSCREENPLAIN|
177 FORMATOP_MEMBEROFGROUP_ARGB|
178 FORMATOP_VERTEXTEXTURE, 0, 0, 0},
179
180 {D3DDDIFMT_X1R5G5B5,
181 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|
182 FORMATOP_SAME_FORMAT_RENDERTARGET|
183 0|
184 FORMATOP_CONVERT_TO_ARGB|FORMATOP_OFFSCREENPLAIN|
185 FORMATOP_MEMBEROFGROUP_ARGB|
186 FORMATOP_VERTEXTEXTURE, 0, 0, 0},
187
188 {D3DDDIFMT_A1R5G5B5,
189 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|
190 FORMATOP_SAME_FORMAT_RENDERTARGET|
191 FORMATOP_SAME_FORMAT_UP_TO_ALPHA_RENDERTARGET|
192 FORMATOP_CONVERT_TO_ARGB|FORMATOP_OFFSCREENPLAIN|
193 FORMATOP_MEMBEROFGROUP_ARGB|
194 FORMATOP_VERTEXTEXTURE, 0, 0, 0},
195
196 {D3DDDIFMT_A4R4G4B4,
197 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|
198 FORMATOP_SAME_FORMAT_RENDERTARGET|
199 FORMATOP_SAME_FORMAT_UP_TO_ALPHA_RENDERTARGET|
200 FORMATOP_OFFSCREENPLAIN|
201 0|
202 FORMATOP_VERTEXTEXTURE, 0, 0, 0},
203
204 {D3DDDIFMT_R5G6B5,
205 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|
206 FORMATOP_SAME_FORMAT_RENDERTARGET|
207 FORMATOP_DISPLAYMODE|FORMATOP_3DACCELERATION|
208 FORMATOP_CONVERT_TO_ARGB|FORMATOP_OFFSCREENPLAIN|
209 FORMATOP_MEMBEROFGROUP_ARGB|
210 FORMATOP_VERTEXTEXTURE, 0, 0, 0},
211
212 {D3DDDIFMT_L16,
213 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|
214 0|
215 0|
216 FORMATOP_OFFSCREENPLAIN|
217 0|
218 FORMATOP_VERTEXTEXTURE, 0, 0, 0},
219
220 {D3DDDIFMT_A8L8,
221 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|
222 0|
223 0|
224 FORMATOP_OFFSCREENPLAIN|
225 0|
226 FORMATOP_VERTEXTEXTURE, 0, 0, 0},
227
228 {D3DDDIFMT_A8,
229 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|
230 0|
231 0|
232 FORMATOP_OFFSCREENPLAIN|
233 0|
234 FORMATOP_VERTEXTEXTURE, 0, 0, 0},
235
236 {D3DDDIFMT_L8,
237 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|
238 0|
239 0|
240 FORMATOP_OFFSCREENPLAIN|
241 0|
242 FORMATOP_VERTEXTEXTURE, 0, 0, 0},
243
244 {D3DDDIFMT_D16, FORMATOP_TEXTURE|FORMATOP_ZSTENCIL|FORMATOP_ZSTENCIL_WITH_ARBITRARY_COLOR_DEPTH, 0, 0, 0},
245 {D3DDDIFMT_D24S8, FORMATOP_TEXTURE|FORMATOP_ZSTENCIL|FORMATOP_ZSTENCIL_WITH_ARBITRARY_COLOR_DEPTH, 0, 0, 0},
246 {D3DDDIFMT_D24X8, FORMATOP_TEXTURE|FORMATOP_ZSTENCIL|FORMATOP_ZSTENCIL_WITH_ARBITRARY_COLOR_DEPTH, 0, 0, 0},
247 {D3DDDIFMT_D16_LOCKABLE, FORMATOP_ZSTENCIL|FORMATOP_ZSTENCIL_WITH_ARBITRARY_COLOR_DEPTH, 0, 0, 0},
248 {D3DDDIFMT_X8D24, FORMATOP_TEXTURE|FORMATOP_ZSTENCIL|FORMATOP_ZSTENCIL_WITH_ARBITRARY_COLOR_DEPTH, 0, 0, 0},
249 {D3DDDIFMT_D32F_LOCKABLE, FORMATOP_TEXTURE|FORMATOP_ZSTENCIL|FORMATOP_ZSTENCIL_WITH_ARBITRARY_COLOR_DEPTH, 0, 0, 0},
250 {D3DDDIFMT_S8D24, FORMATOP_TEXTURE|FORMATOP_ZSTENCIL|FORMATOP_ZSTENCIL_WITH_ARBITRARY_COLOR_DEPTH, 0, 0, 0},
251
252 {D3DDDIFMT_DXT1,
253 FORMATOP_TEXTURE|FORMATOP_CUBETEXTURE|
254 0|
255 0|
256 FORMATOP_OFFSCREENPLAIN|FORMATOP_SRGBREAD|
257 0|
258 FORMATOP_VERTEXTEXTURE, 0, 0, 0},
259
260 {D3DDDIFMT_DXT2,
261 FORMATOP_TEXTURE|FORMATOP_CUBETEXTURE|
262 0|
263 0|
264 FORMATOP_OFFSCREENPLAIN|FORMATOP_SRGBREAD|
265 0|
266 FORMATOP_VERTEXTEXTURE, 0, 0, 0},
267
268 {D3DDDIFMT_DXT3,
269 FORMATOP_TEXTURE|FORMATOP_CUBETEXTURE|
270 0|
271 0|
272 FORMATOP_OFFSCREENPLAIN|FORMATOP_SRGBREAD|
273 0|
274 FORMATOP_VERTEXTEXTURE, 0, 0, 0},
275
276 {D3DDDIFMT_DXT4,
277 FORMATOP_TEXTURE|FORMATOP_CUBETEXTURE|
278 0|
279 0|
280 FORMATOP_OFFSCREENPLAIN|FORMATOP_SRGBREAD|
281 0|
282 FORMATOP_VERTEXTEXTURE, 0, 0, 0},
283
284 {D3DDDIFMT_DXT5,
285 FORMATOP_TEXTURE|FORMATOP_CUBETEXTURE|
286 0|
287 0|
288 FORMATOP_OFFSCREENPLAIN|FORMATOP_SRGBREAD|
289 0|
290 FORMATOP_VERTEXTEXTURE, 0, 0, 0},
291
292 {D3DDDIFMT_X8L8V8U8,
293 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|
294 0|
295 0|
296 0|
297 FORMATOP_BUMPMAP|
298 FORMATOP_VERTEXTEXTURE, 0, 0, 0},
299
300 {D3DDDIFMT_A2W10V10U10,
301 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|
302 0|
303 0|
304 0|
305 FORMATOP_BUMPMAP|
306 FORMATOP_VERTEXTEXTURE, 0, 0, 0},
307
308 {D3DDDIFMT_V8U8,
309 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|
310 0|
311 0|
312 0|
313 FORMATOP_BUMPMAP|
314 FORMATOP_VERTEXTEXTURE, 0, 0, 0},
315
316 {D3DDDIFMT_Q8W8V8U8,
317 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|
318 0|
319 0|
320 FORMATOP_OFFSCREENPLAIN|
321 FORMATOP_BUMPMAP|
322 FORMATOP_VERTEXTEXTURE, 0, 0, 0},
323
324 {D3DDDIFMT_CxV8U8, FORMATOP_NOFILTER|FORMATOP_NOALPHABLEND|FORMATOP_NOTEXCOORDWRAPNORMIP, 0, 0, 0},
325
326 {D3DDDIFMT_R16F,
327 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|
328 FORMATOP_SAME_FORMAT_RENDERTARGET|
329 0|
330 FORMATOP_OFFSCREENPLAIN|
331 0|
332 FORMATOP_VERTEXTEXTURE, 0, 0, 0},
333
334 {D3DDDIFMT_R32F,
335 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|
336 FORMATOP_SAME_FORMAT_RENDERTARGET|
337 0|
338 FORMATOP_OFFSCREENPLAIN|
339 0|
340 FORMATOP_VERTEXTEXTURE, 0, 0, 0},
341
342 {D3DDDIFMT_G16R16F,
343 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|
344 FORMATOP_SAME_FORMAT_RENDERTARGET|
345 0|
346 FORMATOP_OFFSCREENPLAIN|
347 0|
348 FORMATOP_VERTEXTEXTURE, 0, 0, 0},
349
350 {D3DDDIFMT_G32R32F,
351 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|
352 FORMATOP_SAME_FORMAT_RENDERTARGET|
353 0|
354 FORMATOP_OFFSCREENPLAIN|
355 0|
356 FORMATOP_VERTEXTEXTURE, 0, 0, 0},
357
358 {D3DDDIFMT_A16B16G16R16F,
359 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|
360 FORMATOP_SAME_FORMAT_RENDERTARGET|
361 0|
362 FORMATOP_OFFSCREENPLAIN|
363 0|
364 FORMATOP_VERTEXTEXTURE, 0, 0, 0},
365
366 {D3DDDIFMT_A32B32G32R32F,
367 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|
368 FORMATOP_SAME_FORMAT_RENDERTARGET|
369 0|
370 FORMATOP_OFFSCREENPLAIN|
371 0|
372 FORMATOP_VERTEXTEXTURE, 0, 0, 0},
373
374 {D3DDDIFMT_G16R16,
375 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|
376 FORMATOP_SAME_FORMAT_RENDERTARGET|
377 0|
378 FORMATOP_OFFSCREENPLAIN|
379 0|
380 FORMATOP_VERTEXTEXTURE, 0, 0, 0},
381
382 {D3DDDIFMT_A16B16G16R16,
383 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|
384 FORMATOP_SAME_FORMAT_RENDERTARGET|
385 0|
386 FORMATOP_OFFSCREENPLAIN|
387 0|
388 FORMATOP_VERTEXTEXTURE, 0, 0, 0},
389
390 {D3DDDIFMT_V16U16,
391 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|
392 0|
393 0|
394 0|
395 FORMATOP_BUMPMAP|
396 FORMATOP_VERTEXTEXTURE, 0, 0, 0},
397
398 {D3DDDIFMT_P8, FORMATOP_DISPLAYMODE|FORMATOP_3DACCELERATION|FORMATOP_OFFSCREENPLAIN, 0, 0, 0},
399
400 {D3DDDIFMT_UYVY,
401 0|
402 0|
403 0|
404 FORMATOP_CONVERT_TO_ARGB|FORMATOP_OFFSCREENPLAIN|
405 FORMATOP_NOFILTER|
406 FORMATOP_NOALPHABLEND|
407 FORMATOP_NOTEXCOORDWRAPNORMIP, 0, 0, 0},
408
409 {D3DDDIFMT_YUY2,
410 0|
411 0|
412 0|
413 FORMATOP_CONVERT_TO_ARGB|FORMATOP_OFFSCREENPLAIN|
414 FORMATOP_NOFILTER|
415 FORMATOP_NOALPHABLEND|
416 FORMATOP_NOTEXCOORDWRAPNORMIP, 0, 0, 0},
417
418 {D3DDDIFMT_Q16W16V16U16,
419 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|
420 FORMATOP_SAME_FORMAT_RENDERTARGET|
421 0|
422 FORMATOP_OFFSCREENPLAIN|
423 FORMATOP_BUMPMAP|FORMATOP_DMAP|
424 FORMATOP_VERTEXTEXTURE, 0, 0, 0},
425
426 {D3DDDIFMT_X8B8G8R8,
427 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|
428 FORMATOP_SAME_FORMAT_RENDERTARGET|
429 FORMATOP_SAME_FORMAT_UP_TO_ALPHA_RENDERTARGET|
430 FORMATOP_CONVERT_TO_ARGB|FORMATOP_OFFSCREENPLAIN|FORMATOP_SRGBREAD|
431 FORMATOP_DMAP|FORMATOP_MEMBEROFGROUP_ARGB|
432 FORMATOP_SRGBWRITE|FORMATOP_AUTOGENMIPMAP|FORMATOP_VERTEXTEXTURE|
433 FORMATOP_OVERLAY, 0, 0, 0},
434
435 {D3DDDIFMT_BINARYBUFFER, FORMATOP_OFFSCREENPLAIN, 0, 0, 0},
436
437 {D3DDDIFMT_A4L4,
438 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|
439 0|
440 0|
441 FORMATOP_CONVERT_TO_ARGB|FORMATOP_OFFSCREENPLAIN|
442 FORMATOP_DMAP|
443 FORMATOP_VERTEXTEXTURE, 0, 0, 0},
444
445 {D3DDDIFMT_A2B10G10R10,
446 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|
447 FORMATOP_SAME_FORMAT_RENDERTARGET|
448 0|
449 FORMATOP_CONVERT_TO_ARGB|FORMATOP_OFFSCREENPLAIN|
450 FORMATOP_DMAP|FORMATOP_MEMBEROFGROUP_ARGB|
451 FORMATOP_AUTOGENMIPMAP|FORMATOP_VERTEXTEXTURE, 0, 0, 0},
452};
453
454static FORMATOP gVBoxFormatOpsBase[] = {
455 {D3DDDIFMT_X8R8G8B8, FORMATOP_DISPLAYMODE, 0, 0, 0},
456
457 {D3DDDIFMT_R8G8B8, FORMATOP_DISPLAYMODE, 0, 0, 0},
458
459 {D3DDDIFMT_R5G6B5, FORMATOP_DISPLAYMODE, 0, 0, 0},
460
461 {D3DDDIFMT_P8, FORMATOP_DISPLAYMODE, 0, 0, 0},
462};
463
464static DDSURFACEDESC gVBoxSurfDescsBase[] = {
465 {
466 sizeof (DDSURFACEDESC), /* DWORD dwSize; */
467 DDSD_CAPS | DDSD_PIXELFORMAT, /* DWORD dwFlags; */
468 0, /* DWORD dwHeight; */
469 0, /* DWORD dwWidth; */
470 {
471 0, /* Union */
472 /* LONG lPitch; */
473 /* DWORD dwLinearSize; */
474 },
475 0, /* DWORD dwBackBufferCount; */
476 {
477 0, /* Union */
478 /* DWORD dwMipMapCount; */
479 /* DWORD dwZBufferBitDepth; */
480 /* DWORD dwRefreshRate; */
481 },
482 0, /* DWORD dwAlphaBitDepth; */
483 0, /* DWORD dwReserved; */
484 NULL, /* LPVOID lpSurface; */
485 {
486 0, /* DWORD dwColorSpaceLowValue; */
487 0, /* DWORD dwColorSpaceHighValue; */
488 }, /* DDCOLORKEY ddckCKDestOverlay; */
489 {
490 0, /* DWORD dwColorSpaceLowValue; */
491 0, /* DWORD dwColorSpaceHighValue; */
492 }, /* DDCOLORKEY ddckCKDestBlt; */
493 {
494 0, /* DWORD dwColorSpaceLowValue; */
495 0, /* DWORD dwColorSpaceHighValue; */
496 }, /* DDCOLORKEY ddckCKSrcOverlay; */
497 {
498 0, /* DWORD dwColorSpaceLowValue; */
499 0, /* DWORD dwColorSpaceHighValue; */
500 }, /* DDCOLORKEY ddckCKSrcBlt; */
501 {
502 sizeof (DDPIXELFORMAT), /* DWORD dwSize; */
503 DDPF_RGB, /* DWORD dwFlags; */
504 0, /* DWORD dwFourCC; */
505 {
506 32, /* union */
507 /* DWORD dwRGBBitCount; */
508 /* DWORD dwYUVBitCount; */
509 /* DWORD dwZBufferBitDepth; */
510 /* DWORD dwAlphaBitDepth; */
511 /* DWORD dwLuminanceBitCount; */
512 /* DWORD dwBumpBitCount; */
513 },
514 {
515 0xff0000, /* union */
516 /* DWORD dwRBitMask; */
517 /* DWORD dwYBitMask; */
518 /* DWORD dwStencilBitDepth; */
519 /* DWORD dwLuminanceBitMask; */
520 /* DWORD dwBumpDuBitMask; */
521 },
522 {
523 0xff00,
524 /* DWORD dwGBitMask; */
525 /* DWORD dwUBitMask; */
526 /* DWORD dwZBitMask; */
527 /* DWORD dwBumpDvBitMask; */
528 },
529 {
530 0xff,
531 /* DWORD dwBBitMask; */
532 /* DWORD dwVBitMask; */
533 /* DWORD dwStencilBitMask; */
534 /* DWORD dwBumpLuminanceBitMask; */
535 },
536 {
537 0,
538 /* DWORD dwRGBAlphaBitMask; */
539 /* DWORD dwYUVAlphaBitMask; */
540 /* DWORD dwLuminanceAlphaBitMask; */
541 /* DWORD dwRGBZBitMask; */
542 /* DWORD dwYUVZBitMask; */
543 },
544 }, /* DDPIXELFORMAT ddpfPixelFormat; */
545 {
546 DDSCAPS_BACKBUFFER
547 | DDSCAPS_COMPLEX
548 | DDSCAPS_FLIP
549 | DDSCAPS_FRONTBUFFER
550 | DDSCAPS_LOCALVIDMEM
551 | DDSCAPS_PRIMARYSURFACE
552 | DDSCAPS_VIDEOMEMORY
553 | DDSCAPS_VISIBLE /* DWORD dwCaps; */
554 } /* DDSCAPS ddsCaps; */
555 },
556 {
557 sizeof (DDSURFACEDESC), /* DWORD dwSize; */
558 DDSD_CAPS | DDSD_PIXELFORMAT, /* DWORD dwFlags; */
559 0, /* DWORD dwHeight; */
560 0, /* DWORD dwWidth; */
561 {
562 0, /* Union */
563 /* LONG lPitch; */
564 /* DWORD dwLinearSize; */
565 },
566 0, /* DWORD dwBackBufferCount; */
567 {
568 0, /* Union */
569 /* DWORD dwMipMapCount; */
570 /* DWORD dwZBufferBitDepth; */
571 /* DWORD dwRefreshRate; */
572 },
573 0, /* DWORD dwAlphaBitDepth; */
574 0, /* DWORD dwReserved; */
575 NULL, /* LPVOID lpSurface; */
576 {
577 0, /* DWORD dwColorSpaceLowValue; */
578 0, /* DWORD dwColorSpaceHighValue; */
579 }, /* DDCOLORKEY ddckCKDestOverlay; */
580 {
581 0, /* DWORD dwColorSpaceLowValue; */
582 0, /* DWORD dwColorSpaceHighValue; */
583 }, /* DDCOLORKEY ddckCKDestBlt; */
584 {
585 0, /* DWORD dwColorSpaceLowValue; */
586 0, /* DWORD dwColorSpaceHighValue; */
587 }, /* DDCOLORKEY ddckCKSrcOverlay; */
588 {
589 0, /* DWORD dwColorSpaceLowValue; */
590 0, /* DWORD dwColorSpaceHighValue; */
591 }, /* DDCOLORKEY ddckCKSrcBlt; */
592 {
593 sizeof (DDPIXELFORMAT), /* DWORD dwSize; */
594 DDPF_RGB, /* DWORD dwFlags; */
595 0, /* DWORD dwFourCC; */
596 {
597 24, /* union */
598 /* DWORD dwRGBBitCount; */
599 /* DWORD dwYUVBitCount; */
600 /* DWORD dwZBufferBitDepth; */
601 /* DWORD dwAlphaBitDepth; */
602 /* DWORD dwLuminanceBitCount; */
603 /* DWORD dwBumpBitCount; */
604 },
605 {
606 0xff0000, /* union */
607 /* DWORD dwRBitMask; */
608 /* DWORD dwYBitMask; */
609 /* DWORD dwStencilBitDepth; */
610 /* DWORD dwLuminanceBitMask; */
611 /* DWORD dwBumpDuBitMask; */
612 },
613 {
614 0xff00,
615 /* DWORD dwGBitMask; */
616 /* DWORD dwUBitMask; */
617 /* DWORD dwZBitMask; */
618 /* DWORD dwBumpDvBitMask; */
619 },
620 {
621 0xff,
622 /* DWORD dwBBitMask; */
623 /* DWORD dwVBitMask; */
624 /* DWORD dwStencilBitMask; */
625 /* DWORD dwBumpLuminanceBitMask; */
626 },
627 {
628 0,
629 /* DWORD dwRGBAlphaBitMask; */
630 /* DWORD dwYUVAlphaBitMask; */
631 /* DWORD dwLuminanceAlphaBitMask; */
632 /* DWORD dwRGBZBitMask; */
633 /* DWORD dwYUVZBitMask; */
634 },
635 }, /* DDPIXELFORMAT ddpfPixelFormat; */
636 {
637 DDSCAPS_BACKBUFFER
638 | DDSCAPS_COMPLEX
639 | DDSCAPS_FLIP
640 | DDSCAPS_FRONTBUFFER
641 | DDSCAPS_LOCALVIDMEM
642 | DDSCAPS_PRIMARYSURFACE
643 | DDSCAPS_VIDEOMEMORY
644 | DDSCAPS_VISIBLE /* DWORD dwCaps; */
645 } /* DDSCAPS ddsCaps; */
646 },
647 {
648 sizeof (DDSURFACEDESC), /* DWORD dwSize; */
649 DDSD_CAPS | DDSD_PIXELFORMAT, /* DWORD dwFlags; */
650 0, /* DWORD dwHeight; */
651 0, /* DWORD dwWidth; */
652 {
653 0, /* Union */
654 /* LONG lPitch; */
655 /* DWORD dwLinearSize; */
656 },
657 0, /* DWORD dwBackBufferCount; */
658 {
659 0, /* Union */
660 /* DWORD dwMipMapCount; */
661 /* DWORD dwZBufferBitDepth; */
662 /* DWORD dwRefreshRate; */
663 },
664 0, /* DWORD dwAlphaBitDepth; */
665 0, /* DWORD dwReserved; */
666 NULL, /* LPVOID lpSurface; */
667 {
668 0, /* DWORD dwColorSpaceLowValue; */
669 0, /* DWORD dwColorSpaceHighValue; */
670 }, /* DDCOLORKEY ddckCKDestOverlay; */
671 {
672 0, /* DWORD dwColorSpaceLowValue; */
673 0, /* DWORD dwColorSpaceHighValue; */
674 }, /* DDCOLORKEY ddckCKDestBlt; */
675 {
676 0, /* DWORD dwColorSpaceLowValue; */
677 0, /* DWORD dwColorSpaceHighValue; */
678 }, /* DDCOLORKEY ddckCKSrcOverlay; */
679 {
680 0, /* DWORD dwColorSpaceLowValue; */
681 0, /* DWORD dwColorSpaceHighValue; */
682 }, /* DDCOLORKEY ddckCKSrcBlt; */
683 {
684 sizeof (DDPIXELFORMAT), /* DWORD dwSize; */
685 DDPF_RGB, /* DWORD dwFlags; */
686 0, /* DWORD dwFourCC; */
687 {
688 16, /* union */
689 /* DWORD dwRGBBitCount; */
690 /* DWORD dwYUVBitCount; */
691 /* DWORD dwZBufferBitDepth; */
692 /* DWORD dwAlphaBitDepth; */
693 /* DWORD dwLuminanceBitCount; */
694 /* DWORD dwBumpBitCount; */
695 },
696 {
697 0xf800, /* union */
698 /* DWORD dwRBitMask; */
699 /* DWORD dwYBitMask; */
700 /* DWORD dwStencilBitDepth; */
701 /* DWORD dwLuminanceBitMask; */
702 /* DWORD dwBumpDuBitMask; */
703 },
704 {
705 0x7e0,
706 /* DWORD dwGBitMask; */
707 /* DWORD dwUBitMask; */
708 /* DWORD dwZBitMask; */
709 /* DWORD dwBumpDvBitMask; */
710 },
711 {
712 0x1f,
713 /* DWORD dwBBitMask; */
714 /* DWORD dwVBitMask; */
715 /* DWORD dwStencilBitMask; */
716 /* DWORD dwBumpLuminanceBitMask; */
717 },
718 {
719 0,
720 /* DWORD dwRGBAlphaBitMask; */
721 /* DWORD dwYUVAlphaBitMask; */
722 /* DWORD dwLuminanceAlphaBitMask; */
723 /* DWORD dwRGBZBitMask; */
724 /* DWORD dwYUVZBitMask; */
725 },
726 }, /* DDPIXELFORMAT ddpfPixelFormat; */
727 {
728 DDSCAPS_BACKBUFFER
729 | DDSCAPS_COMPLEX
730 | DDSCAPS_FLIP
731 | DDSCAPS_FRONTBUFFER
732 | DDSCAPS_LOCALVIDMEM
733 | DDSCAPS_PRIMARYSURFACE
734 | DDSCAPS_VIDEOMEMORY
735 | DDSCAPS_VISIBLE /* DWORD dwCaps; */
736 } /* DDSCAPS ddsCaps; */
737 },
738};
739
740#ifdef VBOX_WITH_VIDEOHWACCEL
741
742static void vboxVhwaPopulateOverlayFourccSurfDesc(DDSURFACEDESC *pDesc, uint32_t fourcc)
743{
744 memset(pDesc, 0, sizeof (DDSURFACEDESC));
745
746 pDesc->dwSize = sizeof (DDSURFACEDESC);
747 pDesc->dwFlags = DDSD_CAPS | DDSD_PIXELFORMAT;
748 pDesc->ddpfPixelFormat.dwSize = sizeof (DDPIXELFORMAT);
749 pDesc->ddpfPixelFormat.dwFlags = DDPF_FOURCC;
750 pDesc->ddpfPixelFormat.dwFourCC = fourcc;
751 pDesc->ddsCaps.dwCaps = DDSCAPS_BACKBUFFER
752 | DDSCAPS_COMPLEX
753 | DDSCAPS_FLIP
754 | DDSCAPS_FRONTBUFFER
755 | DDSCAPS_LOCALVIDMEM
756 | DDSCAPS_OVERLAY
757 | DDSCAPS_VIDEOMEMORY
758 | DDSCAPS_VISIBLE;
759}
760
761static bool vboxPixFormatMatch(DDPIXELFORMAT *pFormat1, DDPIXELFORMAT *pFormat2)
762{
763 return !memcmp(pFormat1, pFormat2, sizeof (DDPIXELFORMAT));
764}
765
766HRESULT vboxSurfDescMerge(DDSURFACEDESC *paDescs, uint32_t *pcDescs, uint32_t cMaxDescs, DDSURFACEDESC *pDesc)
767{
768 uint32_t cDescs = *pcDescs;
769
770 Assert(cMaxDescs >= cDescs);
771 Assert(pDesc->dwFlags == (DDSD_CAPS | DDSD_PIXELFORMAT));
772 if (pDesc->dwFlags != (DDSD_CAPS | DDSD_PIXELFORMAT))
773 return E_INVALIDARG;
774
775 for (uint32_t i = 0; i < cDescs; ++i)
776 {
777 DDSURFACEDESC *pCur = &paDescs[i];
778 if (vboxPixFormatMatch(&pCur->ddpfPixelFormat, &pDesc->ddpfPixelFormat))
779 {
780 if (pDesc->dwFlags & DDSD_CAPS)
781 {
782 pCur->dwFlags |= DDSD_CAPS;
783 pCur->ddsCaps.dwCaps |= pDesc->ddsCaps.dwCaps;
784 }
785 return S_OK;
786 }
787 }
788
789 if (cMaxDescs > cDescs)
790 {
791 paDescs[cDescs] = *pDesc;
792 ++cDescs;
793 *pcDescs = cDescs;
794 return VINF_SUCCESS;
795 }
796 return E_FAIL;
797}
798
799HRESULT vboxFormatOpsMerge(FORMATOP *paOps, uint32_t *pcOps, uint32_t cMaxOps, FORMATOP *pOp)
800{
801 uint32_t cOps = *pcOps;
802
803 Assert(cMaxOps >= cOps);
804
805 for (uint32_t i = 0; i < cOps; ++i)
806 {
807 FORMATOP *pCur = &paOps[i];
808 if (pCur->Format == pOp->Format)
809 {
810 pCur->Operations |= pOp->Operations;
811 Assert(pCur->FlipMsTypes == pOp->FlipMsTypes);
812 Assert(pCur->BltMsTypes == pOp->BltMsTypes);
813 Assert(pCur->PrivateFormatBitCount == pOp->PrivateFormatBitCount);
814 return S_OK;
815 }
816 }
817
818 if (cMaxOps > cOps)
819 {
820 paOps[cOps] = *pOp;
821 ++cOps;
822 *pcOps = cOps;
823 return VINF_SUCCESS;
824 }
825 return E_FAIL;
826}
827
828HRESULT VBoxDispD3DGlobal2DFormatsInit(PVBOXWDDMDISP_ADAPTER pAdapter)
829{
830 HRESULT hr = S_OK;
831 memset(&pAdapter->D3D, 0, sizeof (pAdapter->D3D));
832 memset(&pAdapter->Formats, 0, sizeof (pAdapter->Formats));
833
834 /* just calc the max number of formats */
835 uint32_t cFormats = RT_ELEMENTS(gVBoxFormatOpsBase);
836 uint32_t cSurfDescs = RT_ELEMENTS(gVBoxSurfDescsBase);
837 uint32_t cOverlayFormats = 0;
838 for (uint32_t i = 0; i < pAdapter->cHeads; ++i)
839 {
840 VBOXDISPVHWA_INFO *pVhwa = &pAdapter->aHeads[i].Vhwa;
841 if (pVhwa->Settings.fFlags & VBOXVHWA_F_ENABLED)
842 {
843 cOverlayFormats += pVhwa->Settings.cFormats;
844 }
845 }
846
847 cFormats += cOverlayFormats;
848 cSurfDescs += cOverlayFormats;
849
850 uint32_t cbFormatOps = cFormats * sizeof (FORMATOP);
851 cbFormatOps = (cbFormatOps + 7) & ~3;
852 /* ensure the surf descs are 8 byte aligned */
853 uint32_t offSurfDescs = (cbFormatOps + 7) & ~3;
854 uint32_t cbSurfDescs = cSurfDescs * sizeof (DDSURFACEDESC);
855 uint32_t cbBuf = offSurfDescs + cbSurfDescs;
856 uint8_t* pvBuf = (uint8_t*)RTMemAllocZ(cbBuf);
857 if (pvBuf)
858 {
859 pAdapter->Formats.paFormstOps = (FORMATOP*)pvBuf;
860 memcpy ((void*)pAdapter->Formats.paFormstOps , gVBoxFormatOpsBase, sizeof (gVBoxFormatOpsBase));
861 pAdapter->Formats.cFormstOps = RT_ELEMENTS(gVBoxFormatOpsBase);
862
863 FORMATOP fo = {D3DDDIFMT_UNKNOWN, 0, 0, 0, 0};
864 for (uint32_t i = 0; i < pAdapter->cHeads; ++i)
865 {
866 VBOXDISPVHWA_INFO *pVhwa = &pAdapter->aHeads[i].Vhwa;
867 if (pVhwa->Settings.fFlags & VBOXVHWA_F_ENABLED)
868 {
869 for (uint32_t j = 0; j < pVhwa->Settings.cFormats; ++j)
870 {
871 fo.Format = pVhwa->Settings.aFormats[j];
872 fo.Operations = FORMATOP_OVERLAY;
873 hr = vboxFormatOpsMerge((FORMATOP *)pAdapter->Formats.paFormstOps, &pAdapter->Formats.cFormstOps, cFormats, &fo);
874 if (FAILED(hr))
875 {
876 WARN(("vboxFormatOpsMerge failed, hr 0x%x", hr));
877 }
878 }
879 }
880 }
881
882 pAdapter->Formats.paSurfDescs = (DDSURFACEDESC*)(pvBuf + offSurfDescs);
883 memcpy ((void*)pAdapter->Formats.paSurfDescs , gVBoxSurfDescsBase, sizeof (gVBoxSurfDescsBase));
884 pAdapter->Formats.cSurfDescs = RT_ELEMENTS(gVBoxSurfDescsBase);
885
886 DDSURFACEDESC sd;
887 for (uint32_t i = 0; i < pAdapter->cHeads; ++i)
888 {
889 VBOXDISPVHWA_INFO *pVhwa = &pAdapter->aHeads[i].Vhwa;
890 if (pVhwa->Settings.fFlags & VBOXVHWA_F_ENABLED)
891 {
892 for (uint32_t j = 0; j < pVhwa->Settings.cFormats; ++j)
893 {
894 uint32_t fourcc = vboxWddmFormatToFourcc(pVhwa->Settings.aFormats[j]);
895 if (fourcc)
896 {
897 vboxVhwaPopulateOverlayFourccSurfDesc(&sd, fourcc);
898 hr = vboxSurfDescMerge((DDSURFACEDESC *)pAdapter->Formats.paSurfDescs, &pAdapter->Formats.cSurfDescs, cSurfDescs, &sd);
899 if (FAILED(hr))
900 {
901 WARN(("vboxFormatOpsMerge failed, hr 0x%x", hr));
902 }
903 }
904 }
905 }
906 }
907 }
908 else
909 {
910 WARN(("RTMemAllocZ failed"));
911 return E_FAIL;
912 }
913 return S_OK;
914}
915
916void VBoxDispD3DGlobal2DFormatsTerm(PVBOXWDDMDISP_ADAPTER pAdapter)
917{
918 if (pAdapter->Formats.paFormstOps)
919 RTMemFree((void *)pAdapter->Formats.paFormstOps);
920}
921
922#endif
923
924static CRITICAL_SECTION g_VBoxDispD3DGlobalCritSect;
925static VBOXWDDMDISP_D3D g_VBoxDispD3DGlobalD3D;
926static VBOXWDDMDISP_FORMATS g_VBoxDispD3DGlobalD3DFormats;
927static uint32_t g_cVBoxDispD3DGlobalOpens;
928
929void vboxDispD3DGlobalLock()
930{
931 EnterCriticalSection(&g_VBoxDispD3DGlobalCritSect);
932}
933
934void vboxDispD3DGlobalUnlock()
935{
936 LeaveCriticalSection(&g_VBoxDispD3DGlobalCritSect);
937}
938
939void VBoxDispD3DGlobalInit()
940{
941 g_cVBoxDispD3DGlobalOpens = 0;
942 InitializeCriticalSection(&g_VBoxDispD3DGlobalCritSect);
943}
944
945void VBoxDispD3DGlobalTerm()
946{
947 DeleteCriticalSection(&g_VBoxDispD3DGlobalCritSect);
948}
949
950static void vboxDispD3DGlobalD3DFormatsInit(PVBOXWDDMDISP_FORMATS pFormats)
951{
952 memset(pFormats, 0, sizeof (pFormats));
953 pFormats->paFormstOps = gVBoxFormatOps3D;
954 pFormats->cFormstOps = RT_ELEMENTS(gVBoxFormatOps3D);
955}
956
957
958//#define D3DDEVCAPS_FLOATTLVERTEX 0x00000001
959//#define D3DPMISCCAPS_FOGINFVF 0x00002000
960//#define D3DPRASTERCAPS_SUBPIXEL 0x00000020
961//#define D3DPRASTERCAPS_STIPPLE 0x00000200
962//#define D3DPTEXTURECAPS_TRANSPARENCY 0x00000008
963
964static HRESULT vboxWddmGetD3D9Caps(PVBOXWDDMDISP_D3D pD3D, D3DCAPS9 *pCaps)
965{
966 HRESULT hr = pD3D->pD3D9If->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, pCaps);
967 if (FAILED(hr))
968 {
969 WARN(("GetDeviceCaps failed hr(0x%x)",hr));
970 return hr;
971 }
972
973 /* needed for Windows Media Player to work properly */
974 pCaps->Caps |= D3DCAPS_READ_SCANLINE;
975 pCaps->Caps2 |= 0x00080000 /*D3DCAPS2_CANRENDERWINDOWED*/;
976 pCaps->Caps2 |= D3DCAPS2_CANSHARERESOURCE;
977 pCaps->DevCaps |= D3DDEVCAPS_FLOATTLVERTEX /* <- must be set according to the docs */
978 /*| D3DDEVCAPS_HWVERTEXBUFFER | D3DDEVCAPS_HWINDEXBUFFER | D3DDEVCAPS_SUBVOLUMELOCK */;
979 pCaps->PrimitiveMiscCaps |= D3DPMISCCAPS_INDEPENDENTWRITEMASKS
980 | D3DPMISCCAPS_FOGINFVF
981 | D3DPMISCCAPS_SEPARATEALPHABLEND | D3DPMISCCAPS_MRTINDEPENDENTBITDEPTHS;
982 pCaps->RasterCaps |= D3DPRASTERCAPS_SUBPIXEL | D3DPRASTERCAPS_STIPPLE | D3DPRASTERCAPS_ZBIAS | D3DPRASTERCAPS_COLORPERSPECTIVE /* keep */;
983 pCaps->TextureCaps |= D3DPTEXTURECAPS_TRANSPARENCY | D3DPTEXTURECAPS_TEXREPEATNOTSCALEDBYSIZE;
984 pCaps->TextureAddressCaps |= D3DPTADDRESSCAPS_MIRRORONCE;
985 pCaps->VolumeTextureAddressCaps |= D3DPTADDRESSCAPS_MIRRORONCE;
986 pCaps->StencilCaps |= D3DSTENCILCAPS_TWOSIDED;
987 pCaps->DeclTypes |= D3DDTCAPS_FLOAT16_2 | D3DDTCAPS_FLOAT16_4;
988 pCaps->VertexTextureFilterCaps |= D3DPTFILTERCAPS_MINFPOINT | D3DPTFILTERCAPS_MAGFPOINT;
989 pCaps->GuardBandLeft = -8192.;
990 pCaps->GuardBandTop = -8192.;
991 pCaps->GuardBandRight = 8192.;
992 pCaps->GuardBandBottom = 8192.;
993 pCaps->VS20Caps.DynamicFlowControlDepth = 24;
994 pCaps->VS20Caps.NumTemps = D3DVS20_MAX_NUMTEMPS;
995 pCaps->PS20Caps.DynamicFlowControlDepth = 24;
996 pCaps->PS20Caps.NumTemps = D3DVS20_MAX_NUMTEMPS;
997
998 /* workaround for wine not returning InstructionSlots correctly for shaders v3.0 */
999 if ((pCaps->VertexShaderVersion & 0xff00) == 0x0300)
1000 {
1001 pCaps->MaxVertexShader30InstructionSlots = RT_MIN(32768, pCaps->MaxVertexShader30InstructionSlots);
1002 pCaps->MaxPixelShader30InstructionSlots = RT_MIN(32768, pCaps->MaxPixelShader30InstructionSlots);
1003 }
1004#if defined(DEBUG)
1005 if ((pCaps->VertexShaderVersion & 0xff00) == 0x0300)
1006 {
1007 Assert(pCaps->MaxVertexShader30InstructionSlots >= 512);
1008 Assert(pCaps->MaxVertexShader30InstructionSlots <= 32768);
1009 Assert(pCaps->MaxPixelShader30InstructionSlots >= 512);
1010 Assert(pCaps->MaxPixelShader30InstructionSlots <= 32768);
1011 }
1012 else if ((pCaps->VertexShaderVersion & 0xff00) == 0x0200)
1013 {
1014 Assert(pCaps->MaxVertexShader30InstructionSlots == 0);
1015 Assert(pCaps->MaxPixelShader30InstructionSlots == 0);
1016 }
1017 else
1018 {
1019 WARN(("incorect shader caps!"));
1020 }
1021#endif
1022
1023 vboxDispDumpD3DCAPS9(pCaps);
1024
1025 return S_OK;
1026}
1027
1028static void vboxDispD3DGlobalDoClose(PVBOXWDDMDISP_D3D pD3D)
1029{
1030 pD3D->pD3D9If->Release();
1031 VBoxDispD3DClose(&pD3D->D3D);
1032}
1033
1034static HRESULT vboxDispD3DGlobalDoOpen(PVBOXWDDMDISP_D3D pD3D)
1035{
1036 memset(pD3D, 0, sizeof (*pD3D));
1037 HRESULT hr = VBoxDispD3DOpen(&pD3D->D3D);
1038 if (SUCCEEDED(hr))
1039 {
1040 hr = pD3D->D3D.pfnDirect3DCreate9Ex(D3D_SDK_VERSION, &pD3D->pD3D9If);
1041 if (SUCCEEDED(hr))
1042 {
1043 hr = vboxWddmGetD3D9Caps(pD3D, &pD3D->Caps);
1044 if (SUCCEEDED(hr))
1045 {
1046 pD3D->cMaxSimRTs = pD3D->Caps.NumSimultaneousRTs;
1047 Assert(pD3D->cMaxSimRTs);
1048 Assert(pD3D->cMaxSimRTs < UINT32_MAX/2);
1049 LOG(("SUCCESS 3D Enabled, pD3D (0x%p)", pD3D));
1050 return S_OK;
1051 }
1052 else
1053 {
1054 WARN(("vboxWddmGetD3D9Caps failed hr = 0x%x", hr));
1055 }
1056 pD3D->pD3D9If->Release();
1057 }
1058 else
1059 {
1060 WARN(("pfnDirect3DCreate9Ex failed hr = 0x%x", hr));
1061 }
1062 VBoxDispD3DClose(&pD3D->D3D);
1063 }
1064 else
1065 {
1066 WARN(("VBoxDispD3DOpen failed hr = 0x%x", hr));
1067 }
1068 return hr;
1069}
1070
1071HRESULT VBoxDispD3DGlobalOpen(PVBOXWDDMDISP_D3D pD3D, PVBOXWDDMDISP_FORMATS pFormats)
1072{
1073 vboxDispD3DGlobalLock();
1074 if (!g_cVBoxDispD3DGlobalOpens)
1075 {
1076 HRESULT hr = vboxDispD3DGlobalDoOpen(&g_VBoxDispD3DGlobalD3D);
1077 if (!SUCCEEDED(hr))
1078 {
1079 WARN(("vboxDispD3DGlobalDoOpen failed hr = 0x%x", hr));
1080 return hr;
1081 }
1082
1083 vboxDispD3DGlobalD3DFormatsInit(&g_VBoxDispD3DGlobalD3DFormats);
1084 }
1085 ++g_cVBoxDispD3DGlobalOpens;
1086 vboxDispD3DGlobalUnlock();
1087
1088 *pD3D = g_VBoxDispD3DGlobalD3D;
1089 *pFormats = g_VBoxDispD3DGlobalD3DFormats;
1090 return S_OK;
1091}
1092
1093void VBoxDispD3DGlobalClose(PVBOXWDDMDISP_D3D pD3D, PVBOXWDDMDISP_FORMATS pFormats)
1094{
1095 vboxDispD3DGlobalLock();
1096 --g_cVBoxDispD3DGlobalOpens;
1097 if (!g_cVBoxDispD3DGlobalOpens)
1098 {
1099 vboxDispD3DGlobalDoClose(&g_VBoxDispD3DGlobalD3D);
1100 }
1101 vboxDispD3DGlobalUnlock();
1102}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette