VirtualBox

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

Last change on this file since 49591 was 46966, checked in by vboxsync, 12 years ago

wddm/crOpenGL: some bugfixes, more TexPresent fixes

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