VirtualBox

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

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

wddm/crOpenGL: more TexPresent impl

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