VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxDispD3D.cpp@ 30563

Last change on this file since 30563 was 30563, checked in by vboxsync, 14 years ago

wddm/3d: more functionality impl

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 187.6 KB
Line 
1/** @file
2 *
3 * VBoxVideo Display D3D User mode dll
4 *
5 * Copyright (C) 2010 Oracle Corporation
6 *
7 * This file is part of VirtualBox Open Source Edition (OSE), as
8 * available from http://www.virtualbox.org. This file is free software;
9 * you can redistribute it and/or modify it under the terms of the GNU
10 * General Public License (GPL) as published by the Free Software
11 * Foundation, in version 2 as it comes in the "COPYING" file of the
12 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
13 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
14 */
15#include <iprt/initterm.h>
16#include <iprt/log.h>
17#include <iprt/mem.h>
18
19#include <VBox/Log.h>
20
21#include <VBox/VBoxGuestLib.h>
22
23#include "VBoxDispD3DCmn.h"
24#include "VBoxDispD3D.h"
25
26#ifdef VBOXDISPMP_TEST
27HRESULT vboxDispMpTstStart();
28HRESULT vboxDispMpTstStop();
29#endif
30
31#ifdef VBOXWDDMDISP_DEBUG
32# include <stdio.h>
33#endif
34
35#define VBOXWDDMDISP_WITH_TMPWORKAROUND 1
36
37#define VBOXWDDMOVERLAY_TEST
38
39static FORMATOP gVBoxFormatOps3D[] = {
40 {D3DDDIFMT_A8R8G8B8,
41 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|
42 FORMATOP_SAME_FORMAT_RENDERTARGET|
43 FORMATOP_SAME_FORMAT_UP_TO_ALPHA_RENDERTARGET|
44 FORMATOP_CONVERT_TO_ARGB|FORMATOP_OFFSCREENPLAIN|FORMATOP_SRGBREAD|
45 FORMATOP_MEMBEROFGROUP_ARGB|
46 FORMATOP_SRGBWRITE|FORMATOP_VERTEXTEXTURE, 0, 0, 0},
47
48 {D3DDDIFMT_X8R8G8B8,
49 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|
50 FORMATOP_SAME_FORMAT_RENDERTARGET|
51 FORMATOP_DISPLAYMODE|FORMATOP_3DACCELERATION|
52 FORMATOP_CONVERT_TO_ARGB|FORMATOP_OFFSCREENPLAIN|FORMATOP_SRGBREAD|
53 FORMATOP_MEMBEROFGROUP_ARGB|
54 FORMATOP_SRGBWRITE|FORMATOP_VERTEXTEXTURE, 0, 0, 0},
55
56 {D3DDDIFMT_A2R10G10B10,
57 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|
58 FORMATOP_SAME_FORMAT_RENDERTARGET|
59 0|
60 FORMATOP_CONVERT_TO_ARGB|FORMATOP_OFFSCREENPLAIN|
61 FORMATOP_MEMBEROFGROUP_ARGB|
62 FORMATOP_VERTEXTEXTURE, 0, 0, 0},
63
64 {D3DDDIFMT_X1R5G5B5,
65 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|
66 FORMATOP_SAME_FORMAT_RENDERTARGET|
67 0|
68 FORMATOP_CONVERT_TO_ARGB|FORMATOP_OFFSCREENPLAIN|
69 FORMATOP_MEMBEROFGROUP_ARGB|
70 FORMATOP_VERTEXTEXTURE, 0, 0, 0},
71
72 {D3DDDIFMT_A1R5G5B5,
73 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|
74 FORMATOP_SAME_FORMAT_RENDERTARGET|
75 FORMATOP_SAME_FORMAT_UP_TO_ALPHA_RENDERTARGET|
76 FORMATOP_CONVERT_TO_ARGB|FORMATOP_OFFSCREENPLAIN|
77 FORMATOP_MEMBEROFGROUP_ARGB|
78 FORMATOP_VERTEXTEXTURE, 0, 0, 0},
79
80 {D3DDDIFMT_A4R4G4B4,
81 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|
82 FORMATOP_SAME_FORMAT_RENDERTARGET|
83 FORMATOP_SAME_FORMAT_UP_TO_ALPHA_RENDERTARGET|
84 FORMATOP_OFFSCREENPLAIN|
85 0|
86 FORMATOP_VERTEXTEXTURE, 0, 0, 0},
87
88 {D3DDDIFMT_R5G6B5,
89 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|
90 FORMATOP_SAME_FORMAT_RENDERTARGET|
91 FORMATOP_DISPLAYMODE|FORMATOP_3DACCELERATION|
92 FORMATOP_CONVERT_TO_ARGB|FORMATOP_OFFSCREENPLAIN|
93 FORMATOP_MEMBEROFGROUP_ARGB|
94 FORMATOP_VERTEXTEXTURE, 0, 0, 0},
95
96 {D3DDDIFMT_L16,
97 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|
98 0|
99 0|
100 FORMATOP_OFFSCREENPLAIN|
101 0|
102 FORMATOP_VERTEXTEXTURE, 0, 0, 0},
103
104 {D3DDDIFMT_A8L8,
105 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|
106 0|
107 0|
108 FORMATOP_OFFSCREENPLAIN|
109 0|
110 FORMATOP_VERTEXTEXTURE, 0, 0, 0},
111
112 {D3DDDIFMT_A8,
113 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|
114 0|
115 0|
116 FORMATOP_OFFSCREENPLAIN|
117 0|
118 FORMATOP_VERTEXTEXTURE, 0, 0, 0},
119
120 {D3DDDIFMT_L8,
121 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|
122 0|
123 0|
124 FORMATOP_OFFSCREENPLAIN|
125 0|
126 FORMATOP_VERTEXTEXTURE, 0, 0, 0},
127
128 {D3DDDIFMT_D16, FORMATOP_TEXTURE|FORMATOP_ZSTENCIL|FORMATOP_ZSTENCIL_WITH_ARBITRARY_COLOR_DEPTH, 0, 0, 0},
129 {D3DDDIFMT_D24S8, FORMATOP_TEXTURE|FORMATOP_ZSTENCIL|FORMATOP_ZSTENCIL_WITH_ARBITRARY_COLOR_DEPTH, 0, 0, 0},
130 {D3DDDIFMT_D24X8, FORMATOP_TEXTURE|FORMATOP_ZSTENCIL|FORMATOP_ZSTENCIL_WITH_ARBITRARY_COLOR_DEPTH, 0, 0, 0},
131 {D3DDDIFMT_D16_LOCKABLE, FORMATOP_ZSTENCIL|FORMATOP_ZSTENCIL_WITH_ARBITRARY_COLOR_DEPTH, 0, 0, 0},
132 {D3DDDIFMT_X8D24, FORMATOP_TEXTURE|FORMATOP_ZSTENCIL|FORMATOP_ZSTENCIL_WITH_ARBITRARY_COLOR_DEPTH, 0, 0, 0},
133 {D3DDDIFMT_D32F_LOCKABLE, FORMATOP_TEXTURE|FORMATOP_ZSTENCIL|FORMATOP_ZSTENCIL_WITH_ARBITRARY_COLOR_DEPTH, 0, 0, 0},
134 {D3DDDIFMT_S8D24, FORMATOP_TEXTURE|FORMATOP_ZSTENCIL|FORMATOP_ZSTENCIL_WITH_ARBITRARY_COLOR_DEPTH, 0, 0, 0},
135
136 {D3DDDIFMT_DXT1,
137 FORMATOP_TEXTURE|FORMATOP_CUBETEXTURE|
138 0|
139 0|
140 FORMATOP_OFFSCREENPLAIN|FORMATOP_SRGBREAD|
141 0|
142 FORMATOP_VERTEXTEXTURE, 0, 0, 0},
143
144 {D3DDDIFMT_DXT2,
145 FORMATOP_TEXTURE|FORMATOP_CUBETEXTURE|
146 0|
147 0|
148 FORMATOP_OFFSCREENPLAIN|FORMATOP_SRGBREAD|
149 0|
150 FORMATOP_VERTEXTEXTURE, 0, 0, 0},
151
152 {D3DDDIFMT_DXT3,
153 FORMATOP_TEXTURE|FORMATOP_CUBETEXTURE|
154 0|
155 0|
156 FORMATOP_OFFSCREENPLAIN|FORMATOP_SRGBREAD|
157 0|
158 FORMATOP_VERTEXTEXTURE, 0, 0, 0},
159
160 {D3DDDIFMT_DXT4,
161 FORMATOP_TEXTURE|FORMATOP_CUBETEXTURE|
162 0|
163 0|
164 FORMATOP_OFFSCREENPLAIN|FORMATOP_SRGBREAD|
165 0|
166 FORMATOP_VERTEXTEXTURE, 0, 0, 0},
167
168 {D3DDDIFMT_DXT5,
169 FORMATOP_TEXTURE|FORMATOP_CUBETEXTURE|
170 0|
171 0|
172 FORMATOP_OFFSCREENPLAIN|FORMATOP_SRGBREAD|
173 0|
174 FORMATOP_VERTEXTEXTURE, 0, 0, 0},
175
176 {D3DDDIFMT_X8L8V8U8,
177 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|
178 0|
179 0|
180 0|
181 FORMATOP_BUMPMAP|
182 FORMATOP_VERTEXTEXTURE, 0, 0, 0},
183
184 {D3DDDIFMT_A2W10V10U10,
185 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|
186 0|
187 0|
188 0|
189 FORMATOP_BUMPMAP|
190 FORMATOP_VERTEXTEXTURE, 0, 0, 0},
191
192 {D3DDDIFMT_V8U8,
193 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|
194 0|
195 0|
196 0|
197 FORMATOP_BUMPMAP|
198 FORMATOP_VERTEXTEXTURE, 0, 0, 0},
199
200 {D3DDDIFMT_Q8W8V8U8,
201 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|
202 0|
203 0|
204 FORMATOP_OFFSCREENPLAIN|
205 FORMATOP_BUMPMAP|
206 FORMATOP_VERTEXTEXTURE, 0, 0, 0},
207
208 {D3DDDIFMT_CxV8U8, FORMATOP_NOFILTER|FORMATOP_NOALPHABLEND|FORMATOP_NOTEXCOORDWRAPNORMIP, 0, 0, 0},
209
210 {D3DDDIFMT_R16F,
211 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|
212 FORMATOP_SAME_FORMAT_RENDERTARGET|
213 0|
214 FORMATOP_OFFSCREENPLAIN|
215 0|
216 FORMATOP_VERTEXTEXTURE, 0, 0, 0},
217
218 {D3DDDIFMT_R32F,
219 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|
220 FORMATOP_SAME_FORMAT_RENDERTARGET|
221 0|
222 FORMATOP_OFFSCREENPLAIN|
223 0|
224 FORMATOP_VERTEXTEXTURE, 0, 0, 0},
225
226 {D3DDDIFMT_G16R16F,
227 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|
228 FORMATOP_SAME_FORMAT_RENDERTARGET|
229 0|
230 FORMATOP_OFFSCREENPLAIN|
231 0|
232 FORMATOP_VERTEXTEXTURE, 0, 0, 0},
233
234 {D3DDDIFMT_G32R32F,
235 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|
236 FORMATOP_SAME_FORMAT_RENDERTARGET|
237 0|
238 FORMATOP_OFFSCREENPLAIN|
239 0|
240 FORMATOP_VERTEXTEXTURE, 0, 0, 0},
241
242 {D3DDDIFMT_A16B16G16R16F,
243 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|
244 FORMATOP_SAME_FORMAT_RENDERTARGET|
245 0|
246 FORMATOP_OFFSCREENPLAIN|
247 0|
248 FORMATOP_VERTEXTEXTURE, 0, 0, 0},
249
250 {D3DDDIFMT_A32B32G32R32F,
251 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|
252 FORMATOP_SAME_FORMAT_RENDERTARGET|
253 0|
254 FORMATOP_OFFSCREENPLAIN|
255 0|
256 FORMATOP_VERTEXTEXTURE, 0, 0, 0},
257
258 {D3DDDIFMT_G16R16,
259 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|
260 FORMATOP_SAME_FORMAT_RENDERTARGET|
261 0|
262 FORMATOP_OFFSCREENPLAIN|
263 0|
264 FORMATOP_VERTEXTEXTURE, 0, 0, 0},
265
266 {D3DDDIFMT_A16B16G16R16,
267 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|
268 FORMATOP_SAME_FORMAT_RENDERTARGET|
269 0|
270 FORMATOP_OFFSCREENPLAIN|
271 0|
272 FORMATOP_VERTEXTEXTURE, 0, 0, 0},
273
274 {D3DDDIFMT_V16U16,
275 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|
276 0|
277 0|
278 0|
279 FORMATOP_BUMPMAP|
280 FORMATOP_VERTEXTEXTURE, 0, 0, 0},
281
282 {D3DDDIFMT_P8, FORMATOP_DISPLAYMODE|FORMATOP_3DACCELERATION|FORMATOP_OFFSCREENPLAIN, 0, 0, 0},
283
284 {D3DDDIFMT_UYVY,
285 0|
286 0|
287 0|
288 FORMATOP_CONVERT_TO_ARGB|FORMATOP_OFFSCREENPLAIN|
289 FORMATOP_NOFILTER|
290 FORMATOP_NOALPHABLEND|
291 FORMATOP_NOTEXCOORDWRAPNORMIP, 0, 0, 0},
292
293 {D3DDDIFMT_YUY2,
294 0|
295 0|
296 0|
297 FORMATOP_CONVERT_TO_ARGB|FORMATOP_OFFSCREENPLAIN|
298 FORMATOP_NOFILTER|
299 FORMATOP_NOALPHABLEND|
300 FORMATOP_NOTEXCOORDWRAPNORMIP, 0, 0, 0},
301
302 {D3DDDIFMT_Q16W16V16U16,
303 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|
304 FORMATOP_SAME_FORMAT_RENDERTARGET|
305 0|
306 FORMATOP_OFFSCREENPLAIN|
307 FORMATOP_BUMPMAP|FORMATOP_DMAP|
308 FORMATOP_VERTEXTEXTURE, 0, 0, 0},
309
310 {D3DDDIFMT_X8B8G8R8,
311 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|
312 FORMATOP_SAME_FORMAT_RENDERTARGET|
313 FORMATOP_SAME_FORMAT_UP_TO_ALPHA_RENDERTARGET|
314 FORMATOP_CONVERT_TO_ARGB|FORMATOP_OFFSCREENPLAIN|FORMATOP_SRGBREAD|
315 FORMATOP_DMAP|FORMATOP_MEMBEROFGROUP_ARGB|
316 FORMATOP_SRGBWRITE|FORMATOP_AUTOGENMIPMAP|FORMATOP_VERTEXTEXTURE|
317 FORMATOP_OVERLAY, 0, 0, 0},
318
319 {D3DDDIFMT_BINARYBUFFER, FORMATOP_OFFSCREENPLAIN, 0, 0, 0},
320
321 {D3DDDIFMT_A4L4,
322 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|
323 0|
324 0|
325 FORMATOP_CONVERT_TO_ARGB|FORMATOP_OFFSCREENPLAIN|
326 FORMATOP_DMAP|
327 FORMATOP_VERTEXTEXTURE, 0, 0, 0},
328
329 {D3DDDIFMT_A2B10G10R10,
330 FORMATOP_TEXTURE|FORMATOP_VOLUMETEXTURE|FORMATOP_CUBETEXTURE|FORMATOP_OFFSCREEN_RENDERTARGET|
331 FORMATOP_SAME_FORMAT_RENDERTARGET|
332 0|
333 FORMATOP_CONVERT_TO_ARGB|FORMATOP_OFFSCREENPLAIN|
334 FORMATOP_DMAP|FORMATOP_MEMBEROFGROUP_ARGB|
335 FORMATOP_AUTOGENMIPMAP|FORMATOP_VERTEXTEXTURE, 0, 0, 0},
336};
337
338static FORMATOP gVBoxFormatOpsBase[] = {
339 {D3DDDIFMT_X8R8G8B8, FORMATOP_DISPLAYMODE, 0, 0, 0},
340
341 {D3DDDIFMT_R8G8B8, FORMATOP_DISPLAYMODE, 0, 0, 0},
342
343 {D3DDDIFMT_R5G6B5, FORMATOP_DISPLAYMODE, 0, 0, 0},
344
345 {D3DDDIFMT_P8, FORMATOP_DISPLAYMODE, 0, 0, 0},
346};
347
348static DDSURFACEDESC gVBoxSurfDescsBase[] = {
349 {
350 sizeof (DDSURFACEDESC), /* DWORD dwSize; */
351 DDSD_CAPS | DDSD_PIXELFORMAT, /* DWORD dwFlags; */
352 0, /* DWORD dwHeight; */
353 0, /* DWORD dwWidth; */
354 {
355 0, /* Union */
356 /* LONG lPitch; */
357 /* DWORD dwLinearSize; */
358 },
359 0, /* DWORD dwBackBufferCount; */
360 {
361 0, /* Union */
362 /* DWORD dwMipMapCount; */
363 /* DWORD dwZBufferBitDepth; */
364 /* DWORD dwRefreshRate; */
365 },
366 0, /* DWORD dwAlphaBitDepth; */
367 0, /* DWORD dwReserved; */
368 NULL, /* LPVOID lpSurface; */
369 {
370 0, /* DWORD dwColorSpaceLowValue; */
371 0, /* DWORD dwColorSpaceHighValue; */
372 }, /* DDCOLORKEY ddckCKDestOverlay; */
373 {
374 0, /* DWORD dwColorSpaceLowValue; */
375 0, /* DWORD dwColorSpaceHighValue; */
376 }, /* DDCOLORKEY ddckCKDestBlt; */
377 {
378 0, /* DWORD dwColorSpaceLowValue; */
379 0, /* DWORD dwColorSpaceHighValue; */
380 }, /* DDCOLORKEY ddckCKSrcOverlay; */
381 {
382 0, /* DWORD dwColorSpaceLowValue; */
383 0, /* DWORD dwColorSpaceHighValue; */
384 }, /* DDCOLORKEY ddckCKSrcBlt; */
385 {
386 sizeof (DDPIXELFORMAT), /* DWORD dwSize; */
387 DDPF_RGB, /* DWORD dwFlags; */
388 0, /* DWORD dwFourCC; */
389 {
390 32, /* union */
391 /* DWORD dwRGBBitCount; */
392 /* DWORD dwYUVBitCount; */
393 /* DWORD dwZBufferBitDepth; */
394 /* DWORD dwAlphaBitDepth; */
395 /* DWORD dwLuminanceBitCount; */
396 /* DWORD dwBumpBitCount; */
397 },
398 {
399 0xff0000, /* union */
400 /* DWORD dwRBitMask; */
401 /* DWORD dwYBitMask; */
402 /* DWORD dwStencilBitDepth; */
403 /* DWORD dwLuminanceBitMask; */
404 /* DWORD dwBumpDuBitMask; */
405 },
406 {
407 0xff00,
408 /* DWORD dwGBitMask; */
409 /* DWORD dwUBitMask; */
410 /* DWORD dwZBitMask; */
411 /* DWORD dwBumpDvBitMask; */
412 },
413 {
414 0xff,
415 /* DWORD dwBBitMask; */
416 /* DWORD dwVBitMask; */
417 /* DWORD dwStencilBitMask; */
418 /* DWORD dwBumpLuminanceBitMask; */
419 },
420 {
421 0,
422 /* DWORD dwRGBAlphaBitMask; */
423 /* DWORD dwYUVAlphaBitMask; */
424 /* DWORD dwLuminanceAlphaBitMask; */
425 /* DWORD dwRGBZBitMask; */
426 /* DWORD dwYUVZBitMask; */
427 },
428 }, /* DDPIXELFORMAT ddpfPixelFormat; */
429 {
430 DDSCAPS_BACKBUFFER
431 | DDSCAPS_COMPLEX
432 | DDSCAPS_FLIP
433 | DDSCAPS_FRONTBUFFER
434 | DDSCAPS_LOCALVIDMEM
435 | DDSCAPS_PRIMARYSURFACE
436 | DDSCAPS_VIDEOMEMORY
437 | DDSCAPS_VISIBLE /* DWORD dwCaps; */
438 } /* DDSCAPS ddsCaps; */
439 },
440 {
441 sizeof (DDSURFACEDESC), /* DWORD dwSize; */
442 DDSD_CAPS | DDSD_PIXELFORMAT, /* DWORD dwFlags; */
443 0, /* DWORD dwHeight; */
444 0, /* DWORD dwWidth; */
445 {
446 0, /* Union */
447 /* LONG lPitch; */
448 /* DWORD dwLinearSize; */
449 },
450 0, /* DWORD dwBackBufferCount; */
451 {
452 0, /* Union */
453 /* DWORD dwMipMapCount; */
454 /* DWORD dwZBufferBitDepth; */
455 /* DWORD dwRefreshRate; */
456 },
457 0, /* DWORD dwAlphaBitDepth; */
458 0, /* DWORD dwReserved; */
459 NULL, /* LPVOID lpSurface; */
460 {
461 0, /* DWORD dwColorSpaceLowValue; */
462 0, /* DWORD dwColorSpaceHighValue; */
463 }, /* DDCOLORKEY ddckCKDestOverlay; */
464 {
465 0, /* DWORD dwColorSpaceLowValue; */
466 0, /* DWORD dwColorSpaceHighValue; */
467 }, /* DDCOLORKEY ddckCKDestBlt; */
468 {
469 0, /* DWORD dwColorSpaceLowValue; */
470 0, /* DWORD dwColorSpaceHighValue; */
471 }, /* DDCOLORKEY ddckCKSrcOverlay; */
472 {
473 0, /* DWORD dwColorSpaceLowValue; */
474 0, /* DWORD dwColorSpaceHighValue; */
475 }, /* DDCOLORKEY ddckCKSrcBlt; */
476 {
477 sizeof (DDPIXELFORMAT), /* DWORD dwSize; */
478 DDPF_RGB, /* DWORD dwFlags; */
479 0, /* DWORD dwFourCC; */
480 {
481 24, /* union */
482 /* DWORD dwRGBBitCount; */
483 /* DWORD dwYUVBitCount; */
484 /* DWORD dwZBufferBitDepth; */
485 /* DWORD dwAlphaBitDepth; */
486 /* DWORD dwLuminanceBitCount; */
487 /* DWORD dwBumpBitCount; */
488 },
489 {
490 0xff0000, /* union */
491 /* DWORD dwRBitMask; */
492 /* DWORD dwYBitMask; */
493 /* DWORD dwStencilBitDepth; */
494 /* DWORD dwLuminanceBitMask; */
495 /* DWORD dwBumpDuBitMask; */
496 },
497 {
498 0xff00,
499 /* DWORD dwGBitMask; */
500 /* DWORD dwUBitMask; */
501 /* DWORD dwZBitMask; */
502 /* DWORD dwBumpDvBitMask; */
503 },
504 {
505 0xff,
506 /* DWORD dwBBitMask; */
507 /* DWORD dwVBitMask; */
508 /* DWORD dwStencilBitMask; */
509 /* DWORD dwBumpLuminanceBitMask; */
510 },
511 {
512 0,
513 /* DWORD dwRGBAlphaBitMask; */
514 /* DWORD dwYUVAlphaBitMask; */
515 /* DWORD dwLuminanceAlphaBitMask; */
516 /* DWORD dwRGBZBitMask; */
517 /* DWORD dwYUVZBitMask; */
518 },
519 }, /* DDPIXELFORMAT ddpfPixelFormat; */
520 {
521 DDSCAPS_BACKBUFFER
522 | DDSCAPS_COMPLEX
523 | DDSCAPS_FLIP
524 | DDSCAPS_FRONTBUFFER
525 | DDSCAPS_LOCALVIDMEM
526 | DDSCAPS_PRIMARYSURFACE
527 | DDSCAPS_VIDEOMEMORY
528 | DDSCAPS_VISIBLE /* DWORD dwCaps; */
529 } /* DDSCAPS ddsCaps; */
530 },
531 {
532 sizeof (DDSURFACEDESC), /* DWORD dwSize; */
533 DDSD_CAPS | DDSD_PIXELFORMAT, /* DWORD dwFlags; */
534 0, /* DWORD dwHeight; */
535 0, /* DWORD dwWidth; */
536 {
537 0, /* Union */
538 /* LONG lPitch; */
539 /* DWORD dwLinearSize; */
540 },
541 0, /* DWORD dwBackBufferCount; */
542 {
543 0, /* Union */
544 /* DWORD dwMipMapCount; */
545 /* DWORD dwZBufferBitDepth; */
546 /* DWORD dwRefreshRate; */
547 },
548 0, /* DWORD dwAlphaBitDepth; */
549 0, /* DWORD dwReserved; */
550 NULL, /* LPVOID lpSurface; */
551 {
552 0, /* DWORD dwColorSpaceLowValue; */
553 0, /* DWORD dwColorSpaceHighValue; */
554 }, /* DDCOLORKEY ddckCKDestOverlay; */
555 {
556 0, /* DWORD dwColorSpaceLowValue; */
557 0, /* DWORD dwColorSpaceHighValue; */
558 }, /* DDCOLORKEY ddckCKDestBlt; */
559 {
560 0, /* DWORD dwColorSpaceLowValue; */
561 0, /* DWORD dwColorSpaceHighValue; */
562 }, /* DDCOLORKEY ddckCKSrcOverlay; */
563 {
564 0, /* DWORD dwColorSpaceLowValue; */
565 0, /* DWORD dwColorSpaceHighValue; */
566 }, /* DDCOLORKEY ddckCKSrcBlt; */
567 {
568 sizeof (DDPIXELFORMAT), /* DWORD dwSize; */
569 DDPF_RGB, /* DWORD dwFlags; */
570 0, /* DWORD dwFourCC; */
571 {
572 16, /* union */
573 /* DWORD dwRGBBitCount; */
574 /* DWORD dwYUVBitCount; */
575 /* DWORD dwZBufferBitDepth; */
576 /* DWORD dwAlphaBitDepth; */
577 /* DWORD dwLuminanceBitCount; */
578 /* DWORD dwBumpBitCount; */
579 },
580 {
581 0xf800, /* union */
582 /* DWORD dwRBitMask; */
583 /* DWORD dwYBitMask; */
584 /* DWORD dwStencilBitDepth; */
585 /* DWORD dwLuminanceBitMask; */
586 /* DWORD dwBumpDuBitMask; */
587 },
588 {
589 0x7e0,
590 /* DWORD dwGBitMask; */
591 /* DWORD dwUBitMask; */
592 /* DWORD dwZBitMask; */
593 /* DWORD dwBumpDvBitMask; */
594 },
595 {
596 0x1f,
597 /* DWORD dwBBitMask; */
598 /* DWORD dwVBitMask; */
599 /* DWORD dwStencilBitMask; */
600 /* DWORD dwBumpLuminanceBitMask; */
601 },
602 {
603 0,
604 /* DWORD dwRGBAlphaBitMask; */
605 /* DWORD dwYUVAlphaBitMask; */
606 /* DWORD dwLuminanceAlphaBitMask; */
607 /* DWORD dwRGBZBitMask; */
608 /* DWORD dwYUVZBitMask; */
609 },
610 }, /* DDPIXELFORMAT ddpfPixelFormat; */
611 {
612 DDSCAPS_BACKBUFFER
613 | DDSCAPS_COMPLEX
614 | DDSCAPS_FLIP
615 | DDSCAPS_FRONTBUFFER
616 | DDSCAPS_LOCALVIDMEM
617 | DDSCAPS_PRIMARYSURFACE
618 | DDSCAPS_VIDEOMEMORY
619 | DDSCAPS_VISIBLE /* DWORD dwCaps; */
620 } /* DDSCAPS ddsCaps; */
621 },
622};
623
624static D3DDDIQUERYTYPE gVBoxQueryTypes[] = {
625 D3DDDIQUERYTYPE_EVENT,
626 D3DDDIQUERYTYPE_OCCLUSION
627};
628
629#define VBOX_QUERYTYPE_COUNT() RT_ELEMENTS(gVBoxQueryTypes)
630
631#ifdef VBOX_WITH_VIDEOHWACCEL
632
633static bool vboxVhwaIsEnabled(PVBOXWDDMDISP_ADAPTER pAdapter)
634{
635 for (uint32_t i = 0; i < pAdapter->cHeads; ++i)
636 {
637 if (pAdapter->aHeads[i].Vhwa.Settings.fFlags & VBOXVHWA_F_ENABLED)
638 return true;
639 }
640 return false;
641}
642
643static bool vboxVhwaHasCKeying(PVBOXWDDMDISP_ADAPTER pAdapter)
644{
645 for (uint32_t i = 0; i < pAdapter->cHeads; ++i)
646 {
647 VBOXVHWA_INFO* pSettings = &pAdapter->aHeads[i].Vhwa.Settings;
648 if ((pSettings->fFlags & VBOXVHWA_F_ENABLED)
649 && ((pSettings->fFlags & VBOXVHWA_F_CKEY_DST)
650 || (pSettings->fFlags & VBOXVHWA_F_CKEY_SRC))
651 )
652 return true;
653 }
654 return false;
655}
656
657static void vboxVhwaPopulateOverlayFourccSurfDesc(DDSURFACEDESC *pDesc, uint32_t fourcc)
658{
659 memset(pDesc, 0, sizeof (DDSURFACEDESC));
660
661 pDesc->dwSize = sizeof (DDSURFACEDESC);
662 pDesc->dwFlags = DDSD_CAPS | DDSD_PIXELFORMAT;
663 pDesc->ddpfPixelFormat.dwSize = sizeof (DDPIXELFORMAT);
664 pDesc->ddpfPixelFormat.dwFlags = DDPF_FOURCC;
665 pDesc->ddpfPixelFormat.dwFourCC = fourcc;
666 pDesc->ddsCaps.dwCaps = DDSCAPS_BACKBUFFER
667 | DDSCAPS_COMPLEX
668 | DDSCAPS_FLIP
669 | DDSCAPS_FRONTBUFFER
670 | DDSCAPS_LOCALVIDMEM
671 | DDSCAPS_OVERLAY
672 | DDSCAPS_VIDEOMEMORY
673 | DDSCAPS_VISIBLE;
674}
675
676#endif
677
678static bool vboxPixFormatMatch(DDPIXELFORMAT *pFormat1, DDPIXELFORMAT *pFormat2)
679{
680 return !memcmp(pFormat1, pFormat2, sizeof (DDPIXELFORMAT));
681}
682
683int vboxSurfDescMerge(DDSURFACEDESC *paDescs, uint32_t *pcDescs, uint32_t cMaxDescs, DDSURFACEDESC *pDesc)
684{
685 uint32_t cDescs = *pcDescs;
686
687 Assert(cMaxDescs >= cDescs);
688 Assert(pDesc->dwFlags == (DDSD_CAPS | DDSD_PIXELFORMAT));
689 if (pDesc->dwFlags != (DDSD_CAPS | DDSD_PIXELFORMAT))
690 return VERR_INVALID_PARAMETER;
691
692 for (uint32_t i = 0; i < cDescs; ++i)
693 {
694 DDSURFACEDESC *pCur = &paDescs[i];
695 if (vboxPixFormatMatch(&pCur->ddpfPixelFormat, &pDesc->ddpfPixelFormat))
696 {
697 if (pDesc->dwFlags & DDSD_CAPS)
698 {
699 pCur->dwFlags |= DDSD_CAPS;
700 pCur->ddsCaps.dwCaps |= pDesc->ddsCaps.dwCaps;
701 }
702 return VINF_SUCCESS;
703 }
704 }
705
706 if (cMaxDescs > cDescs)
707 {
708 paDescs[cDescs] = *pDesc;
709 ++cDescs;
710 *pcDescs = cDescs;
711 return VINF_SUCCESS;
712 }
713 return VERR_BUFFER_OVERFLOW;
714}
715
716int vboxFormatOpsMerge(FORMATOP *paOps, uint32_t *pcOps, uint32_t cMaxOps, FORMATOP *pOp)
717{
718 uint32_t cOps = *pcOps;
719
720 Assert(cMaxOps >= cOps);
721
722 for (uint32_t i = 0; i < cOps; ++i)
723 {
724 FORMATOP *pCur = &paOps[i];
725 if (pCur->Format == pOp->Format)
726 {
727 pCur->Operations |= pOp->Operations;
728 Assert(pCur->FlipMsTypes == pOp->FlipMsTypes);
729 Assert(pCur->BltMsTypes == pOp->BltMsTypes);
730 Assert(pCur->PrivateFormatBitCount == pOp->PrivateFormatBitCount);
731 return VINF_SUCCESS;
732 }
733 }
734
735 if (cMaxOps > cOps)
736 {
737 paOps[cOps] = *pOp;
738 ++cOps;
739 *pcOps = cOps;
740 return VINF_SUCCESS;
741 }
742 return VERR_BUFFER_OVERFLOW;
743}
744
745int vboxCapsInit(PVBOXWDDMDISP_ADAPTER pAdapter)
746{
747 pAdapter->cFormstOps = 0;
748 pAdapter->paFormstOps = NULL;
749 pAdapter->cSurfDescs = 0;
750 pAdapter->paSurfDescs = NULL;
751
752 if (pAdapter->uIfVersion > 7)
753 {
754 if (pAdapter->pD3D9If)
755 {
756 pAdapter->paFormstOps = (FORMATOP*)RTMemAllocZ(sizeof (gVBoxFormatOps3D));
757 Assert(pAdapter->paFormstOps);
758 if (pAdapter->paFormstOps)
759 {
760 memcpy (pAdapter->paFormstOps , gVBoxFormatOps3D, sizeof (gVBoxFormatOps3D));
761 pAdapter->cFormstOps = RT_ELEMENTS(gVBoxFormatOps3D);
762 }
763 else
764 return VERR_OUT_OF_RESOURCES;
765
766 /* @todo: do we need surface caps here ? */
767 }
768 }
769#ifdef VBOX_WITH_VIDEOHWACCEL
770 else
771 {
772 /* just calc the max number of formats */
773 uint32_t cFormats = RT_ELEMENTS(gVBoxFormatOpsBase);
774 uint32_t cSurfDescs = RT_ELEMENTS(gVBoxSurfDescsBase);
775 uint32_t cOverlayFormats = 0;
776 for (uint32_t i = 0; i < pAdapter->cHeads; ++i)
777 {
778 VBOXDISPVHWA_INFO *pVhwa = &pAdapter->aHeads[i].Vhwa;
779 if (pVhwa->Settings.fFlags & VBOXVHWA_F_ENABLED)
780 {
781 cOverlayFormats += pVhwa->Settings.cFormats;
782 }
783 }
784
785 cFormats += cOverlayFormats;
786 cSurfDescs += cOverlayFormats;
787
788 uint32_t cbFormatOps = cFormats * sizeof (FORMATOP);
789 cbFormatOps = (cbFormatOps + 7) & ~3;
790 /* ensure the surf descs are 8 byte alligned */
791 uint32_t offSurfDescs = (cbFormatOps + 7) & ~3;
792 uint32_t cbSurfDescs = cSurfDescs * sizeof (DDSURFACEDESC);
793 uint32_t cbBuf = offSurfDescs + cbSurfDescs;
794 uint8_t* pvBuf = (uint8_t*)RTMemAllocZ(cbBuf);
795 Assert(pvBuf);
796 if (pvBuf)
797 {
798 pAdapter->paFormstOps = (FORMATOP*)pvBuf;
799 memcpy (pAdapter->paFormstOps , gVBoxFormatOpsBase, sizeof (gVBoxFormatOpsBase));
800 pAdapter->cFormstOps = RT_ELEMENTS(gVBoxFormatOpsBase);
801
802 FORMATOP fo = {D3DDDIFMT_UNKNOWN, 0, 0, 0, 0};
803 for (uint32_t i = 0; i < pAdapter->cHeads; ++i)
804 {
805 VBOXDISPVHWA_INFO *pVhwa = &pAdapter->aHeads[i].Vhwa;
806 if (pVhwa->Settings.fFlags & VBOXVHWA_F_ENABLED)
807 {
808 for (uint32_t j = 0; j < pVhwa->Settings.cFormats; ++j)
809 {
810 fo.Format = pVhwa->Settings.aFormats[j];
811 fo.Operations = FORMATOP_OVERLAY;
812 int rc = vboxFormatOpsMerge(pAdapter->paFormstOps, &pAdapter->cFormstOps, cFormats, &fo);
813 AssertRC(rc);
814 }
815 }
816 }
817
818 pAdapter->paSurfDescs = (DDSURFACEDESC*)(pvBuf + offSurfDescs);
819 memcpy (pAdapter->paSurfDescs , gVBoxSurfDescsBase, sizeof (gVBoxSurfDescsBase));
820 pAdapter->cSurfDescs = RT_ELEMENTS(gVBoxSurfDescsBase);
821
822 DDSURFACEDESC sd;
823 for (uint32_t i = 0; i < pAdapter->cHeads; ++i)
824 {
825 VBOXDISPVHWA_INFO *pVhwa = &pAdapter->aHeads[i].Vhwa;
826 if (pVhwa->Settings.fFlags & VBOXVHWA_F_ENABLED)
827 {
828 for (uint32_t j = 0; j < pVhwa->Settings.cFormats; ++j)
829 {
830 uint32_t fourcc = vboxWddmFormatToFourcc(pVhwa->Settings.aFormats[j]);
831 if (fourcc)
832 {
833 vboxVhwaPopulateOverlayFourccSurfDesc(&sd, fourcc);
834 int rc = vboxSurfDescMerge(pAdapter->paSurfDescs, &pAdapter->cSurfDescs, cSurfDescs, &sd);
835 AssertRC(rc);
836 }
837 }
838 }
839 }
840 }
841 else
842 return VERR_OUT_OF_RESOURCES;
843 }
844#endif
845
846 return VINF_SUCCESS;
847}
848
849void vboxCapsFree(PVBOXWDDMDISP_ADAPTER pAdapter)
850{
851 if (pAdapter->paFormstOps)
852 RTMemFree(pAdapter->paFormstOps);
853}
854
855static PVBOXWDDMDISP_RESOURCE vboxResourceAlloc(UINT cAllocs)
856{
857 PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)RTMemAllocZ(RT_OFFSETOF(VBOXWDDMDISP_RESOURCE, aAllocations[cAllocs]));
858 Assert(pRc);
859 if (pRc)
860 {
861 pRc->cAllocations = cAllocs;
862 return pRc;
863 }
864 return NULL;
865}
866
867static void vboxWddmLockUnlockMemSynch(PVBOXWDDMDISP_ALLOCATION pAlloc, D3DLOCKED_RECT *pLockInfo, RECT *pRect, bool bToLockInfo)
868{
869 Assert(pAlloc->SurfDesc.pitch);
870 Assert(pAlloc->pvMem);
871
872 if (!pRect)
873 {
874 if (pAlloc->SurfDesc.pitch == pLockInfo->Pitch)
875 {
876 if (bToLockInfo)
877 memcpy(pLockInfo->pBits, pAlloc->pvMem, pAlloc->SurfDesc.pitch * pAlloc->SurfDesc.height);
878 else
879 memcpy(pAlloc->pvMem, pLockInfo->pBits, pAlloc->SurfDesc.pitch * pAlloc->SurfDesc.height);
880 }
881 else
882 {
883 uint8_t *pvSrc, *pvDst;
884 uint32_t srcPitch, dstPitch;
885 if (bToLockInfo)
886 {
887 pvSrc = (uint8_t *)pAlloc->pvMem;
888 pvDst = (uint8_t *)pLockInfo->pBits;
889 srcPitch = pAlloc->SurfDesc.pitch;
890 dstPitch = pLockInfo->Pitch;
891 }
892 else
893 {
894 pvDst = (uint8_t *)pAlloc->pvMem;
895 pvSrc = (uint8_t *)pLockInfo->pBits;
896 dstPitch = pAlloc->SurfDesc.pitch;
897 srcPitch = (uint32_t)pLockInfo->Pitch;
898 }
899
900 uint32_t pitch = RT_MIN(srcPitch, dstPitch);
901 Assert(pitch);
902 for (UINT j = 0; j < pAlloc->SurfDesc.height; ++j)
903 {
904 memcpy(pvDst, pvSrc, pitch);
905 pvSrc += srcPitch;
906 pvDst += dstPitch;
907 }
908 }
909 }
910 else
911 {
912 uint8_t *pvSrc, *pvDst;
913 uint32_t srcPitch, dstPitch;
914 /* @todo: this is not entirely correct */
915 uint8_t * pvAllocMemStart = (uint8_t *)pAlloc->pvMem;
916 uint32_t cbPP = pAlloc->SurfDesc.pitch/pAlloc->SurfDesc.width;
917 pvAllocMemStart += pAlloc->SurfDesc.pitch * pRect->top + pRect->left * cbPP;
918
919 if (bToLockInfo)
920 {
921 pvSrc = (uint8_t *)pvAllocMemStart;
922 pvDst = (uint8_t *)pLockInfo->pBits;
923 srcPitch = pAlloc->SurfDesc.pitch;
924 dstPitch = pLockInfo->Pitch;
925 }
926 else
927 {
928 pvDst = (uint8_t *)pvAllocMemStart;
929 pvSrc = (uint8_t *)pLockInfo->pBits;
930 dstPitch = pAlloc->SurfDesc.pitch;
931 srcPitch = (uint32_t)pLockInfo->Pitch;
932 }
933
934 uint32_t cPixCopyLine = pRect->right - pRect->left;
935
936 if (cPixCopyLine == pAlloc->SurfDesc.width && srcPitch == dstPitch)
937 {
938 memcpy(pvDst, pvSrc, pAlloc->SurfDesc.pitch * (pRect->bottom - pRect->top));
939 }
940 else
941 {
942 uint32_t pitch = RT_MIN(srcPitch, dstPitch);
943 uint32_t cbCopyLine = cPixCopyLine * cbPP;
944 Assert(pitch);
945 for (int j = pRect->top; j < pRect->bottom; ++j)
946 {
947 memcpy(pvDst, pvSrc, cbCopyLine);
948 pvSrc += srcPitch;
949 pvDst += dstPitch;
950 }
951 }
952 }
953}
954
955static D3DFORMAT vboxDDI2D3DFormat(D3DDDIFORMAT format)
956{
957 /* @todo: check they are all equal */
958 return (D3DFORMAT)format;
959}
960
961D3DMULTISAMPLE_TYPE vboxDDI2D3DMultiSampleType(D3DDDIMULTISAMPLE_TYPE enmType)
962{
963 /* @todo: check they are all equal */
964 return (D3DMULTISAMPLE_TYPE)enmType;
965}
966
967D3DPOOL vboxDDI2D3DPool(D3DDDI_POOL enmPool)
968{
969 /* @todo: check they are all equal */
970 switch (enmPool)
971 {
972 case D3DDDIPOOL_SYSTEMMEM:
973 return D3DPOOL_SYSTEMMEM;
974 case D3DDDIPOOL_VIDEOMEMORY:
975 case D3DDDIPOOL_LOCALVIDMEM:
976 case D3DDDIPOOL_NONLOCALVIDMEM:
977 /* @todo: what would be propper here? */
978 return D3DPOOL_DEFAULT;
979 default:
980 AssertBreakpoint();
981 }
982 return D3DPOOL_DEFAULT;
983}
984
985D3DRENDERSTATETYPE vboxDDI2D3DRenderStateType(D3DDDIRENDERSTATETYPE enmType)
986{
987 /* @todo: @fixme: not entirely correct, need to check */
988 return (D3DRENDERSTATETYPE)enmType;
989}
990
991VBOXWDDMDISP_TSS_LOOKUP vboxDDI2D3DTestureStageStateType(D3DDDITEXTURESTAGESTATETYPE enmType)
992{
993 static const VBOXWDDMDISP_TSS_LOOKUP lookup[] =
994 {
995 {FALSE, D3DTSS_FORCE_DWORD}, /* 0, D3DDDITSS_TEXTUREMAP */
996 {FALSE, D3DTSS_COLOROP}, /* 1, D3DDDITSS_COLOROP */
997 {FALSE, D3DTSS_COLORARG1}, /* 2, D3DDDITSS_COLORARG1 */
998 {FALSE, D3DTSS_COLORARG2}, /* 3, D3DDDITSS_COLORARG2 */
999 {FALSE, D3DTSS_ALPHAOP}, /* 4, D3DDDITSS_ALPHAOP */
1000 {FALSE, D3DTSS_ALPHAARG1}, /* 5, D3DDDITSS_ALPHAARG1 */
1001 {FALSE, D3DTSS_ALPHAARG2}, /* 6, D3DDDITSS_ALPHAARG2 */
1002 {FALSE, D3DTSS_BUMPENVMAT00}, /* 7, D3DDDITSS_BUMPENVMAT00 */
1003 {FALSE, D3DTSS_BUMPENVMAT01}, /* 8, D3DDDITSS_BUMPENVMAT01 */
1004 {FALSE, D3DTSS_BUMPENVMAT10}, /* 9, D3DDDITSS_BUMPENVMAT10 */
1005 {FALSE, D3DTSS_BUMPENVMAT11}, /* 10, D3DDDITSS_BUMPENVMAT11 */
1006 {FALSE, D3DTSS_TEXCOORDINDEX}, /* 11, D3DDDITSS_TEXCOORDINDEX */
1007 {FALSE, D3DTSS_FORCE_DWORD}, /* 12, unused */
1008 {TRUE, D3DSAMP_ADDRESSU}, /* 13, D3DDDITSS_ADDRESSU */
1009 {TRUE, D3DSAMP_ADDRESSV}, /* 14, D3DDDITSS_ADDRESSV */
1010 {TRUE, D3DSAMP_BORDERCOLOR}, /* 15, D3DDDITSS_BORDERCOLOR */
1011 {TRUE, D3DSAMP_MAGFILTER}, /* 16, D3DDDITSS_MAGFILTER */
1012 {TRUE, D3DSAMP_MINFILTER}, /* 17, D3DDDITSS_MINFILTER */
1013 {TRUE, D3DSAMP_MIPFILTER}, /* 18, D3DDDITSS_MIPFILTER */
1014 {TRUE, D3DSAMP_MIPMAPLODBIAS}, /* 19, D3DDDITSS_MIPMAPLODBIAS */
1015 {TRUE, D3DSAMP_MAXMIPLEVEL}, /* 20, D3DDDITSS_MAXMIPLEVEL */
1016 {TRUE, D3DSAMP_MAXANISOTROPY}, /* 21, D3DDDITSS_MAXANISOTROPY */
1017 {FALSE, D3DTSS_BUMPENVLSCALE}, /* 22, D3DDDITSS_BUMPENVLSCALE */
1018 {FALSE, D3DTSS_BUMPENVLOFFSET}, /* 23, D3DDDITSS_BUMPENVLOFFSET */
1019 {FALSE, D3DTSS_TEXTURETRANSFORMFLAGS}, /* 24, D3DDDITSS_TEXTURETRANSFORMFLAGS */
1020 {TRUE, D3DSAMP_ADDRESSW}, /* 25, D3DDDITSS_ADDRESSW */
1021 {FALSE, D3DTSS_COLORARG0}, /* 26, D3DDDITSS_COLORARG0 */
1022 {FALSE, D3DTSS_ALPHAARG0}, /* 27, D3DDDITSS_ALPHAARG0 */
1023 {FALSE, D3DTSS_RESULTARG}, /* 28, D3DDDITSS_RESULTARG */
1024 {FALSE, D3DTSS_FORCE_DWORD}, /* 29, D3DDDITSS_SRGBTEXTURE */
1025 {FALSE, D3DTSS_FORCE_DWORD}, /* 30, D3DDDITSS_ELEMENTINDEX */
1026 {FALSE, D3DTSS_FORCE_DWORD}, /* 31, D3DDDITSS_DMAPOFFSET */
1027 {FALSE, D3DTSS_CONSTANT}, /* 32, D3DDDITSS_CONSTANT */
1028 {FALSE, D3DTSS_FORCE_DWORD}, /* 33, D3DDDITSS_DISABLETEXTURECOLORKEY */
1029 {FALSE, D3DTSS_FORCE_DWORD}, /* 34, D3DDDITSS_TEXTURECOLORKEYVAL */
1030 };
1031
1032 return lookup[enmType];
1033}
1034
1035DWORD vboxDDI2D3DUsage(D3DDDI_RESOURCEFLAGS fFlags)
1036{
1037 DWORD fUsage = 0;
1038 if (fFlags.Dynamic)
1039 fUsage |= D3DUSAGE_DYNAMIC;
1040 if (fFlags.AutogenMipmap)
1041 fUsage |= D3DUSAGE_AUTOGENMIPMAP;
1042 if (fFlags.DMap)
1043 fUsage |= D3DUSAGE_DMAP;
1044 if (fFlags.WriteOnly)
1045 fUsage |= D3DUSAGE_WRITEONLY;
1046 if (fFlags.NPatches)
1047 fUsage |= D3DUSAGE_NPATCHES;
1048 if (fFlags.Points)
1049 fUsage |= D3DUSAGE_POINTS;
1050 if (fFlags.RenderTarget)
1051 fUsage |= D3DUSAGE_RENDERTARGET;
1052 if (fFlags.RtPatches)
1053 fUsage |= D3DUSAGE_RTPATCHES;
1054 if (fFlags.TextApi)
1055 fUsage |= D3DUSAGE_TEXTAPI;
1056 if (fFlags.WriteOnly)
1057 fUsage |= D3DUSAGE_WRITEONLY;
1058 //below are wddm 1.1-specific
1059// if (fFlags.RestrictedContent)
1060// fUsage |= D3DUSAGE_RESTRICTED_CONTENT;
1061// if (fFlags.RestrictSharedAccess)
1062// fUsage |= D3DUSAGE_RESTRICT_SHARED_RESOURCE;
1063 return fUsage;
1064}
1065
1066DWORD vboxDDI2D3DLockFlags(D3DDDI_LOCKFLAGS fLockFlags)
1067{
1068 DWORD fFlags = 0;
1069 if (fLockFlags.Discard)
1070 fFlags |= D3DLOCK_DISCARD;
1071 if (fLockFlags.NoOverwrite)
1072 fFlags |= D3DLOCK_NOOVERWRITE;
1073 if (fLockFlags.ReadOnly)
1074 fFlags |= D3DLOCK_READONLY;
1075 if (fLockFlags.DoNotWait)
1076 fFlags |= D3DLOCK_DONOTWAIT;
1077 return fFlags;
1078}
1079
1080static void vboxResourceFree(PVBOXWDDMDISP_RESOURCE pRc)
1081{
1082 RTMemFree(pRc);
1083}
1084
1085/**
1086 * DLL entry point.
1087 */
1088BOOL WINAPI DllMain(HINSTANCE hInstance,
1089 DWORD dwReason,
1090 LPVOID lpReserved)
1091{
1092 BOOL bOk = TRUE;
1093
1094 switch (dwReason)
1095 {
1096 case DLL_PROCESS_ATTACH:
1097 {
1098 RTR3Init();
1099
1100 HRESULT hr = vboxDispCmInit();
1101 Assert(hr == S_OK);
1102#ifdef VBOXDISPMP_TEST
1103 if (hr == S_OK)
1104 {
1105 hr = vboxDispMpTstStart();
1106 Assert(hr == S_OK);
1107 }
1108#endif
1109 if (hr == S_OK)
1110 vboxVDbgPrint(("VBoxDispD3D: DLL loaded.\n"));
1111 else
1112 bOk = FALSE;
1113
1114// VbglR3Init();
1115 break;
1116 }
1117
1118 case DLL_PROCESS_DETACH:
1119 {
1120 HRESULT hr;
1121#ifdef VBOXDISPMP_TEST
1122 hr = vboxDispMpTstStop();
1123 Assert(hr == S_OK);
1124 if (hr == S_OK)
1125#endif
1126 {
1127 hr = vboxDispCmTerm();
1128 Assert(hr == S_OK);
1129 if (hr == S_OK)
1130 vboxVDbgPrint(("VBoxDispD3D: DLL unloaded.\n"));
1131 else
1132 bOk = FALSE;
1133 }
1134// VbglR3Term();
1135 /// @todo RTR3Term();
1136 break;
1137 }
1138
1139 default:
1140 break;
1141 }
1142 return bOk;
1143}
1144
1145static HRESULT APIENTRY vboxWddmDispGetCaps (HANDLE hAdapter, CONST D3DDDIARG_GETCAPS* pData)
1146{
1147 vboxVDbgPrint(("==> "__FUNCTION__", hAdapter(0x%p), caps type(%d)\n", hAdapter, pData->Type));
1148
1149 HRESULT hr = S_OK;
1150 PVBOXWDDMDISP_ADAPTER pAdapter = (PVBOXWDDMDISP_ADAPTER)hAdapter;
1151
1152 switch (pData->Type)
1153 {
1154 case D3DDDICAPS_DDRAW:
1155 {
1156 Assert(!VBOXDISPMODE_IS_3D(pAdapter));
1157 Assert(pData->DataSize == sizeof (DDRAW_CAPS));
1158 if (pData->DataSize >= sizeof (DDRAW_CAPS))
1159 {
1160 memset(pData->pData, 0, sizeof (DDRAW_CAPS));
1161#ifdef VBOX_WITH_VIDEOHWACCEL
1162 if (vboxVhwaHasCKeying(pAdapter))
1163 {
1164 DDRAW_CAPS *pCaps = (DDRAW_CAPS*)pData->pData;
1165 pCaps->Caps |= DDRAW_CAPS_COLORKEY;
1166// pCaps->Caps2 |= DDRAW_CAPS2_FLIPNOVSYNC;
1167 }
1168#endif
1169 }
1170 else
1171 hr = E_INVALIDARG;
1172 break;
1173 }
1174 case D3DDDICAPS_DDRAW_MODE_SPECIFIC:
1175 {
1176 Assert(!VBOXDISPMODE_IS_3D(pAdapter));
1177 Assert(pData->DataSize == sizeof (DDRAW_MODE_SPECIFIC_CAPS));
1178 if (pData->DataSize >= sizeof (DDRAW_MODE_SPECIFIC_CAPS))
1179 {
1180 DDRAW_MODE_SPECIFIC_CAPS * pCaps = (DDRAW_MODE_SPECIFIC_CAPS*)pData->pData;
1181 memset(&pCaps->Caps /* do not cleanup the first "Head" field,
1182 zero starting with the one following "Head", i.e. Caps */,
1183 0, sizeof (DDRAW_MODE_SPECIFIC_CAPS) - RT_OFFSETOF(DDRAW_MODE_SPECIFIC_CAPS, Caps));
1184#ifdef VBOX_WITH_VIDEOHWACCEL
1185 VBOXVHWA_INFO *pSettings = &pAdapter->aHeads[pCaps->Head].Vhwa.Settings;
1186 if (pSettings->fFlags & VBOXVHWA_F_ENABLED)
1187 {
1188 pCaps->Caps |= MODE_CAPS_OVERLAY | MODE_CAPS_OVERLAYSTRETCH;
1189
1190 if (pSettings->fFlags & VBOXVHWA_F_CKEY_DST)
1191 {
1192 pCaps->CKeyCaps |= MODE_CKEYCAPS_DESTOVERLAY
1193 | MODE_CKEYCAPS_DESTOVERLAYYUV /* ?? */
1194 ;
1195 }
1196
1197 if (pSettings->fFlags & VBOXVHWA_F_CKEY_SRC)
1198 {
1199 pCaps->CKeyCaps |= MODE_CKEYCAPS_SRCOVERLAY
1200 | MODE_CKEYCAPS_SRCOVERLAYCLRSPACE /* ?? */
1201 | MODE_CKEYCAPS_SRCOVERLAYCLRSPACEYUV /* ?? */
1202 | MODE_CKEYCAPS_SRCOVERLAYYUV /* ?? */
1203 ;
1204 }
1205
1206 pCaps->FxCaps = MODE_FXCAPS_OVERLAYSHRINKX
1207 | MODE_FXCAPS_OVERLAYSHRINKY
1208 | MODE_FXCAPS_OVERLAYSTRETCHX
1209 | MODE_FXCAPS_OVERLAYSTRETCHY;
1210
1211
1212 pCaps->MaxVisibleOverlays = pSettings->cOverlaysSupported;
1213 pCaps->MinOverlayStretch = 1;
1214 pCaps->MaxOverlayStretch = 32000;
1215 }
1216#endif
1217 }
1218 else
1219 hr = E_INVALIDARG;
1220 break;
1221 }
1222 case D3DDDICAPS_GETFORMATCOUNT:
1223 *((uint32_t*)pData->pData) = pAdapter->cFormstOps;
1224 break;
1225 case D3DDDICAPS_GETFORMATDATA:
1226 Assert(pData->DataSize == pAdapter->cFormstOps * sizeof (FORMATOP));
1227 memcpy(pData->pData, pAdapter->paFormstOps, pAdapter->cFormstOps * sizeof (FORMATOP));
1228 break;
1229 case D3DDDICAPS_GETD3DQUERYCOUNT:
1230#if 0
1231 *((uint32_t*)pData->pData) = VBOX_QUERYTYPE_COUNT();
1232#else
1233 *((uint32_t*)pData->pData) = 0;
1234#endif
1235 break;
1236 case D3DDDICAPS_GETD3DQUERYDATA:
1237#if 0
1238 Assert(pData->DataSize == VBOX_QUERYTYPE_COUNT() * sizeof (D3DDDIQUERYTYPE));
1239 memcpy(pData->pData, gVBoxQueryTypes, VBOX_QUERYTYPE_COUNT() * sizeof (D3DDDIQUERYTYPE));
1240#else
1241 AssertBreakpoint();
1242 memset(pData->pData, 0, pData->DataSize);
1243#endif
1244 break;
1245 case D3DDDICAPS_GETD3D3CAPS:
1246 Assert(!VBOXDISPMODE_IS_3D(pAdapter));
1247 Assert(pData->DataSize == sizeof (D3DHAL_GLOBALDRIVERDATA));
1248 if (pData->DataSize >= sizeof (D3DHAL_GLOBALDRIVERDATA))
1249 {
1250 D3DHAL_GLOBALDRIVERDATA *pCaps = (D3DHAL_GLOBALDRIVERDATA *)pData->pData;
1251 memset (pCaps, 0, sizeof (D3DHAL_GLOBALDRIVERDATA));
1252 pCaps->dwSize = sizeof (D3DHAL_GLOBALDRIVERDATA);
1253 pCaps->hwCaps.dwSize = sizeof (D3DDEVICEDESC_V1);
1254 pCaps->hwCaps.dwFlags = D3DDD_COLORMODEL
1255 | D3DDD_DEVCAPS
1256 | D3DDD_DEVICERENDERBITDEPTH;
1257
1258 pCaps->hwCaps.dcmColorModel = D3DCOLOR_RGB;
1259 pCaps->hwCaps.dwDevCaps = D3DDEVCAPS_CANRENDERAFTERFLIP
1260// | D3DDEVCAPS_DRAWPRIMTLVERTEX
1261 | D3DDEVCAPS_EXECUTESYSTEMMEMORY
1262 | D3DDEVCAPS_EXECUTEVIDEOMEMORY
1263// | D3DDEVCAPS_FLOATTLVERTEX
1264 | D3DDEVCAPS_HWRASTERIZATION
1265// | D3DDEVCAPS_HWTRANSFORMANDLIGHT
1266// | D3DDEVCAPS_TLVERTEXSYSTEMMEMORY
1267// | D3DDEVCAPS_TEXTUREVIDEOMEMORY
1268 ;
1269 pCaps->hwCaps.dtcTransformCaps.dwSize = sizeof (D3DTRANSFORMCAPS);
1270 pCaps->hwCaps.dtcTransformCaps.dwCaps = 0;
1271 pCaps->hwCaps.bClipping = FALSE;
1272 pCaps->hwCaps.dlcLightingCaps.dwSize = sizeof (D3DLIGHTINGCAPS);
1273 pCaps->hwCaps.dlcLightingCaps.dwCaps = 0;
1274 pCaps->hwCaps.dlcLightingCaps.dwLightingModel = 0;
1275 pCaps->hwCaps.dlcLightingCaps.dwNumLights = 0;
1276 pCaps->hwCaps.dpcLineCaps.dwSize = sizeof (D3DPRIMCAPS);
1277 pCaps->hwCaps.dpcLineCaps.dwMiscCaps = 0;
1278 pCaps->hwCaps.dpcLineCaps.dwRasterCaps = 0;
1279 pCaps->hwCaps.dpcLineCaps.dwZCmpCaps = 0;
1280 pCaps->hwCaps.dpcLineCaps.dwSrcBlendCaps = 0;
1281 pCaps->hwCaps.dpcLineCaps.dwDestBlendCaps = 0;
1282 pCaps->hwCaps.dpcLineCaps.dwAlphaCmpCaps = 0;
1283 pCaps->hwCaps.dpcLineCaps.dwShadeCaps = 0;
1284 pCaps->hwCaps.dpcLineCaps.dwTextureCaps = 0;
1285 pCaps->hwCaps.dpcLineCaps.dwTextureFilterCaps = 0;
1286 pCaps->hwCaps.dpcLineCaps.dwTextureBlendCaps = 0;
1287 pCaps->hwCaps.dpcLineCaps.dwTextureAddressCaps = 0;
1288 pCaps->hwCaps.dpcLineCaps.dwStippleWidth = 0;
1289 pCaps->hwCaps.dpcLineCaps.dwStippleHeight = 0;
1290
1291 pCaps->hwCaps.dpcTriCaps.dwSize = sizeof (D3DPRIMCAPS);
1292 pCaps->hwCaps.dpcTriCaps.dwMiscCaps = 0;
1293 pCaps->hwCaps.dpcTriCaps.dwRasterCaps = 0;
1294 pCaps->hwCaps.dpcTriCaps.dwZCmpCaps = 0;
1295 pCaps->hwCaps.dpcTriCaps.dwSrcBlendCaps = 0;
1296 pCaps->hwCaps.dpcTriCaps.dwDestBlendCaps = 0;
1297 pCaps->hwCaps.dpcTriCaps.dwAlphaCmpCaps = 0;
1298 pCaps->hwCaps.dpcTriCaps.dwShadeCaps = 0;
1299 pCaps->hwCaps.dpcTriCaps.dwTextureCaps = 0;
1300 pCaps->hwCaps.dpcTriCaps.dwTextureFilterCaps = 0;
1301 pCaps->hwCaps.dpcTriCaps.dwTextureBlendCaps = 0;
1302 pCaps->hwCaps.dpcTriCaps.dwTextureAddressCaps = 0;
1303 pCaps->hwCaps.dpcTriCaps.dwStippleWidth = 0;
1304 pCaps->hwCaps.dpcTriCaps.dwStippleHeight = 0;
1305 pCaps->hwCaps.dwDeviceRenderBitDepth = DDBD_8 | DDBD_16 | DDBD_24 | DDBD_32;
1306 pCaps->hwCaps.dwDeviceZBufferBitDepth = 0;
1307 pCaps->hwCaps.dwMaxBufferSize = 0;
1308 pCaps->hwCaps.dwMaxVertexCount = 0;
1309
1310
1311 pCaps->dwNumVertices = 0;
1312 pCaps->dwNumClipVertices = 0;
1313 pCaps->dwNumTextureFormats = 0;//pAdapter->cSurfDescs;
1314 pCaps->lpTextureFormats = NULL;//pAdapter->paSurfDescs;
1315 }
1316 else
1317 hr = E_INVALIDARG;
1318 break;
1319 case D3DDDICAPS_GETD3D7CAPS:
1320 Assert(!VBOXDISPMODE_IS_3D(pAdapter));
1321 Assert(pData->DataSize == sizeof (D3DHAL_D3DEXTENDEDCAPS));
1322 if (pData->DataSize >= sizeof (D3DHAL_D3DEXTENDEDCAPS))
1323 {
1324 memset(pData->pData, 0, sizeof (D3DHAL_D3DEXTENDEDCAPS));
1325 D3DHAL_D3DEXTENDEDCAPS *pCaps = (D3DHAL_D3DEXTENDEDCAPS*)pData->pData;
1326 pCaps->dwSize = sizeof (D3DHAL_D3DEXTENDEDCAPS);
1327 }
1328 else
1329 hr = E_INVALIDARG;
1330 break;
1331 case D3DDDICAPS_GETD3D9CAPS:
1332 {
1333 Assert(pData->DataSize >= sizeof (D3DCAPS9));
1334// AssertBreakpoint();
1335 if (pData->DataSize >= sizeof (D3DCAPS9))
1336 {
1337 Assert(VBOXDISPMODE_IS_3D(pAdapter));
1338 if (VBOXDISPMODE_IS_3D(pAdapter))
1339 {
1340 D3DCAPS9* pCaps = (D3DCAPS9*)pData->pData;
1341 hr = pAdapter->pD3D9If->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, pCaps);
1342 Assert(hr == S_OK);
1343 if (hr == S_OK)
1344 {
1345 pCaps->Caps2 |= D3DCAPS2_CANSHARERESOURCE | 0x00080000 /*D3DCAPS2_CANRENDERWINDOWED*/;
1346 pCaps->DevCaps |= D3DDEVCAPS_FLOATTLVERTEX /* <- must be set according to the docs */
1347 /*| D3DDEVCAPS_HWVERTEXBUFFER | D3DDEVCAPS_HWINDEXBUFFER | D3DDEVCAPS_SUBVOLUMELOCK */;
1348 pCaps->PrimitiveMiscCaps |= D3DPMISCCAPS_INDEPENDENTWRITEMASKS
1349 | D3DPMISCCAPS_FOGINFVF
1350 | D3DPMISCCAPS_SEPARATEALPHABLEND | D3DPMISCCAPS_MRTINDEPENDENTBITDEPTHS;
1351 pCaps->RasterCaps |= D3DPRASTERCAPS_SUBPIXEL | D3DPRASTERCAPS_STIPPLE | D3DPRASTERCAPS_ZBIAS | D3DPRASTERCAPS_COLORPERSPECTIVE /* keep */;
1352 pCaps->TextureCaps |= D3DPTEXTURECAPS_TRANSPARENCY | D3DPTEXTURECAPS_TEXREPEATNOTSCALEDBYSIZE;
1353 pCaps->TextureAddressCaps |= D3DPTADDRESSCAPS_MIRRORONCE;
1354 pCaps->VolumeTextureAddressCaps |= D3DPTADDRESSCAPS_MIRRORONCE;
1355 pCaps->GuardBandLeft = -8192.;
1356 pCaps->GuardBandTop = -8192.;
1357 pCaps->GuardBandRight = 8192.;
1358 pCaps->GuardBandBottom = 8192.;
1359 pCaps->StencilCaps |= D3DSTENCILCAPS_TWOSIDED;
1360 pCaps->DeclTypes |= D3DDTCAPS_FLOAT16_2 | D3DDTCAPS_FLOAT16_4;
1361 pCaps->VS20Caps.DynamicFlowControlDepth = 24;
1362 pCaps->VS20Caps.NumTemps = D3DVS20_MAX_NUMTEMPS;
1363 pCaps->PS20Caps.DynamicFlowControlDepth = 24;
1364 pCaps->PS20Caps.NumTemps = D3DVS20_MAX_NUMTEMPS;
1365 pCaps->VertexTextureFilterCaps |= D3DPTFILTERCAPS_MINFPOINT | D3DPTFILTERCAPS_MAGFPOINT;
1366#if 1 /* workaround for wine not returning InstructionSlots correctly for shaders v3.0 */
1367 if ((pCaps->VertexShaderVersion & 0xff00) == 0x0300)
1368 {
1369 pCaps->MaxVertexShader30InstructionSlots = RT_MIN(32768, pCaps->MaxVertexShader30InstructionSlots);
1370 pCaps->MaxPixelShader30InstructionSlots = RT_MIN(32768, pCaps->MaxPixelShader30InstructionSlots);
1371 }
1372#endif
1373#ifdef DEBUG
1374 if ((pCaps->VertexShaderVersion & 0xff00) == 0x0300)
1375 {
1376 Assert(pCaps->MaxVertexShader30InstructionSlots >= 512);
1377 Assert(pCaps->MaxVertexShader30InstructionSlots <= 32768);
1378 Assert(pCaps->MaxPixelShader30InstructionSlots >= 512);
1379 Assert(pCaps->MaxPixelShader30InstructionSlots <= 32768);
1380 }
1381 else if ((pCaps->VertexShaderVersion & 0xff00) == 0x0200)
1382 {
1383 Assert(pCaps->MaxVertexShader30InstructionSlots == 0);
1384 Assert(pCaps->MaxPixelShader30InstructionSlots == 0);
1385 }
1386 else
1387 {
1388 AssertBreakpoint();
1389 }
1390#endif
1391 break;
1392 }
1393
1394 vboxVDbgPrintR((__FUNCTION__": GetDeviceCaps hr(%d)\n", hr));
1395 /* let's fall back to the 3D disabled case */
1396 hr = S_OK;
1397 }
1398
1399 memset(pData->pData, 0, sizeof (D3DCAPS9));
1400 }
1401 else
1402 hr = E_INVALIDARG;
1403 break;
1404 }
1405 case D3DDDICAPS_GETGAMMARAMPCAPS:
1406 *((uint32_t*)pData->pData) = 0;
1407 break;
1408 case D3DDDICAPS_GETVIDEOPROCESSORCAPS:
1409 case D3DDDICAPS_GETEXTENSIONGUIDCOUNT:
1410 case D3DDDICAPS_GETDECODEGUIDCOUNT:
1411 case D3DDDICAPS_GETVIDEOPROCESSORDEVICEGUIDCOUNT:
1412 if (pData->pData && pData->DataSize)
1413 memset(pData->pData, 0, pData->DataSize);
1414 break;
1415 case D3DDDICAPS_GETMULTISAMPLEQUALITYLEVELS:
1416 case D3DDDICAPS_GETD3D5CAPS:
1417 case D3DDDICAPS_GETD3D6CAPS:
1418 case D3DDDICAPS_GETD3D8CAPS:
1419 case D3DDDICAPS_GETDECODEGUIDS:
1420 case D3DDDICAPS_GETDECODERTFORMATCOUNT:
1421 case D3DDDICAPS_GETDECODERTFORMATS:
1422 case D3DDDICAPS_GETDECODECOMPRESSEDBUFFERINFOCOUNT:
1423 case D3DDDICAPS_GETDECODECOMPRESSEDBUFFERINFO:
1424 case D3DDDICAPS_GETDECODECONFIGURATIONCOUNT:
1425 case D3DDDICAPS_GETDECODECONFIGURATIONS:
1426 case D3DDDICAPS_GETVIDEOPROCESSORDEVICEGUIDS:
1427 case D3DDDICAPS_GETVIDEOPROCESSORRTFORMATCOUNT:
1428 case D3DDDICAPS_GETVIDEOPROCESSORRTFORMATS:
1429 case D3DDDICAPS_GETVIDEOPROCESSORRTSUBSTREAMFORMATCOUNT:
1430 case D3DDDICAPS_GETVIDEOPROCESSORRTSUBSTREAMFORMATS:
1431 case D3DDDICAPS_GETPROCAMPRANGE:
1432 case D3DDDICAPS_FILTERPROPERTYRANGE:
1433 case D3DDDICAPS_GETEXTENSIONGUIDS:
1434 case D3DDDICAPS_GETEXTENSIONCAPS:
1435 vboxVDbgPrint((__FUNCTION__": unimplemented caps type(%d)\n", pData->Type));
1436 AssertBreakpoint();
1437 if (pData->pData && pData->DataSize)
1438 memset(pData->pData, 0, pData->DataSize);
1439 break;
1440 default:
1441 vboxVDbgPrint((__FUNCTION__": unknown caps type(%d)\n", pData->Type));
1442 AssertBreakpoint();
1443 }
1444
1445 vboxVDbgPrint(("<== "__FUNCTION__", hAdapter(0x%p), caps type(%d)\n", hAdapter, pData->Type));
1446
1447 return S_OK;
1448}
1449
1450static HRESULT APIENTRY vboxWddmDDevSetRenderState(HANDLE hDevice, CONST D3DDDIARG_RENDERSTATE* pData)
1451{
1452 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
1453 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
1454 Assert(pDevice);
1455 Assert(pDevice->pDevice9If);
1456 HRESULT hr = pDevice->pDevice9If->SetRenderState(vboxDDI2D3DRenderStateType(pData->State), pData->Value);
1457 Assert(hr == S_OK);
1458 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
1459 return hr;
1460}
1461
1462static HRESULT APIENTRY vboxWddmDDevUpdateWInfo(HANDLE hDevice, CONST D3DDDIARG_WINFO* pData)
1463{
1464 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
1465 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
1466 return S_OK;
1467}
1468
1469static HRESULT APIENTRY vboxWddmDDevValidateDevice(HANDLE hDevice, D3DDDIARG_VALIDATETEXTURESTAGESTATE* pData)
1470{
1471 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
1472 AssertBreakpoint();
1473 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
1474 return E_FAIL;
1475}
1476
1477static HRESULT APIENTRY vboxWddmDDevSetTextureStageState(HANDLE hDevice, CONST D3DDDIARG_TEXTURESTAGESTATE* pData)
1478{
1479 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
1480 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
1481 Assert(pDevice);
1482 Assert(pDevice->pDevice9If);
1483
1484 VBOXWDDMDISP_TSS_LOOKUP lookup = vboxDDI2D3DTestureStageStateType(pData->State);
1485 HRESULT hr;
1486
1487 if (!lookup.bSamplerState)
1488 {
1489 hr = pDevice->pDevice9If->SetTextureStageState(pData->Stage, D3DTEXTURESTAGESTATETYPE(lookup.dType), pData->Value);
1490 }
1491 else
1492 {
1493 hr = pDevice->pDevice9If->SetSamplerState(pData->Stage, D3DSAMPLERSTATETYPE(lookup.dType), pData->Value);
1494 }
1495
1496 Assert(hr == S_OK);
1497 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
1498 return hr;
1499}
1500
1501static HRESULT APIENTRY vboxWddmDDevSetTexture(HANDLE hDevice, UINT Stage, HANDLE hTexture)
1502{
1503 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
1504 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
1505 Assert(pDevice);
1506 Assert(pDevice->pDevice9If);
1507 PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)hTexture;
1508// Assert(pRc);
1509 IDirect3DTexture9 *pD3DIfTex = pRc ? (IDirect3DTexture9*)pRc->aAllocations[0].pD3DIf : NULL;
1510// Assert(pD3DIfTex);
1511 HRESULT hr = pDevice->pDevice9If->SetTexture(Stage, pD3DIfTex);
1512 Assert(hr == S_OK);
1513 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
1514 return hr;
1515}
1516
1517static HRESULT APIENTRY vboxWddmDDevSetPixelShader(HANDLE hDevice, HANDLE hShaderHandle)
1518{
1519 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
1520 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
1521 Assert(pDevice);
1522 Assert(pDevice->pDevice9If);
1523 IDirect3DPixelShader9 *pShader = (IDirect3DPixelShader9*)hShaderHandle;
1524 Assert(pShader);
1525 HRESULT hr = pDevice->pDevice9If->SetPixelShader(pShader);
1526 Assert(hr == S_OK);
1527 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
1528 return hr;
1529}
1530
1531static HRESULT APIENTRY vboxWddmDDevSetPixelShaderConst(HANDLE hDevice, CONST D3DDDIARG_SETPIXELSHADERCONST* pData, CONST FLOAT* pRegisters)
1532{
1533 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
1534 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
1535 Assert(pDevice);
1536 Assert(pDevice->pDevice9If);
1537 HRESULT hr = pDevice->pDevice9If->SetPixelShaderConstantF(pData->Register, pRegisters, pData->Count);
1538 Assert(hr == S_OK);
1539 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
1540 return hr;
1541}
1542
1543static HRESULT APIENTRY vboxWddmDDevSetStreamSourceUm(HANDLE hDevice, CONST D3DDDIARG_SETSTREAMSOURCEUM* pData, CONST VOID* pUMBuffer )
1544{
1545 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
1546 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
1547 Assert(pDevice);
1548 Assert(pDevice->pDevice9If);
1549 HRESULT hr = S_OK;
1550// IDirect3DVertexBuffer9 *pStreamData;
1551// UINT cbOffset;
1552// UINT cbStride;
1553// hr = pDevice->pDevice9If->GetStreamSource(pData->Stream, &pStreamData, &cbOffset, &cbStride);
1554// Assert(hr == S_OK);
1555// if (hr == S_OK)
1556// {
1557// if (pStreamData)
1558// {
1559// AssertBreakpoint();
1560// /* @todo: impl! */
1561// }
1562// else
1563// {
1564 Assert(pData->Stream < RT_ELEMENTS(pDevice->aStreamSourceUm));
1565 PVBOXWDDMDISP_STREAMSOURCEUM pStrSrcUm = &pDevice->aStreamSourceUm[pData->Stream];
1566 pStrSrcUm->pvBuffer = pUMBuffer;
1567 pStrSrcUm->cbStride = pData->Stride;
1568// }
1569// }
1570 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
1571 return hr;
1572}
1573
1574static HRESULT APIENTRY vboxWddmDDevSetIndices(HANDLE hDevice, CONST D3DDDIARG_SETINDICES* pData)
1575{
1576 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
1577 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
1578 Assert(pDevice);
1579 Assert(pDevice->pDevice9If);
1580 PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)pData->hIndexBuffer;
1581 PVBOXWDDMDISP_ALLOCATION pAlloc = NULL;
1582 IDirect3DIndexBuffer9 *pIndexBuffer = NULL;
1583 if (pRc)
1584 {
1585 Assert(pRc->cAllocations == 1);
1586 pAlloc = &pRc->aAllocations[0];
1587 Assert(pAlloc->pD3DIf);
1588 pIndexBuffer = (IDirect3DIndexBuffer9*)pAlloc->pD3DIf;
1589 }
1590 HRESULT hr = pDevice->pDevice9If->SetIndices(pIndexBuffer);
1591 Assert(hr == S_OK);
1592 if (hr == S_OK)
1593 {
1594 pDevice->pIndicesAlloc = pAlloc;
1595 pDevice->IndiciesInfo.uiStride = pData->Stride;
1596 }
1597 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
1598 return hr;
1599}
1600
1601static HRESULT APIENTRY vboxWddmDDevSetIndicesUm(HANDLE hDevice, UINT IndexSize, CONST VOID* pUMBuffer)
1602{
1603 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
1604 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
1605 Assert(pDevice);
1606 Assert(pDevice->pDevice9If);
1607 HRESULT hr = S_OK;
1608 pDevice->IndiciesUm.pvBuffer = pUMBuffer;
1609 pDevice->IndiciesUm.cbSize = IndexSize;
1610 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
1611 return hr;
1612}
1613
1614static HRESULT APIENTRY vboxWddmDDevDrawPrimitive(HANDLE hDevice, CONST D3DDDIARG_DRAWPRIMITIVE* pData, CONST UINT* pFlagBuffer)
1615{
1616 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
1617 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
1618 Assert(pDevice);
1619 Assert(pDevice->pDevice9If);
1620 Assert(!pFlagBuffer);
1621 HRESULT hr = S_OK;
1622
1623 if (!pDevice->cStreamSources)
1624 {
1625 if (pDevice->aStreamSourceUm[0].pvBuffer)
1626 {
1627#ifdef DEBUG
1628 for (UINT i = 1; i < RT_ELEMENTS(pDevice->aStreamSourceUm); ++i)
1629 {
1630 Assert(!pDevice->aStreamSourceUm[i].pvBuffer);
1631 }
1632#endif
1633 hr = pDevice->pDevice9If->DrawPrimitiveUP(pData->PrimitiveType,
1634 pData->PrimitiveCount,
1635 ((uint8_t*)pDevice->aStreamSourceUm[0].pvBuffer) + pData->VStart * pDevice->aStreamSourceUm[0].cbStride,
1636 pDevice->aStreamSourceUm[0].cbStride);
1637 Assert(hr == S_OK);
1638 }
1639 else
1640 {
1641 /* todo: impl */
1642 AssertBreakpoint();
1643 }
1644 }
1645 else
1646 {
1647 hr = pDevice->pDevice9If->DrawPrimitive(pData->PrimitiveType,
1648 pData->VStart,
1649 pData->PrimitiveCount);
1650 Assert(hr == S_OK);
1651#if 0
1652 IDirect3DVertexDeclaration9* pDecl;
1653 hr = pDevice->pDevice9If->GetVertexDeclaration(&pDecl);
1654 Assert(hr == S_OK);
1655 if (hr == S_OK)
1656 {
1657 Assert(pDecl);
1658 D3DVERTEXELEMENT9 aDecls9[MAXD3DDECLLENGTH];
1659 UINT cDecls9 = 0;
1660 hr = pDecl->GetDeclaration(aDecls9, &cDecls9);
1661 Assert(hr == S_OK);
1662 if (hr == S_OK)
1663 {
1664 Assert(cDecls9);
1665 for (UINT i = 0; i < cDecls9 - 1 /* the last one is D3DDECL_END */; ++i)
1666 {
1667 D3DVERTEXELEMENT9 *pDecl9 = &aDecls9[i];
1668 Assert(pDecl9->Stream < RT_ELEMENTS(pDevice->aStreamSourceUm) || pDecl9->Stream == 0xff);
1669 if (pDecl9->Stream != 0xff)
1670 {
1671 PVBOXWDDMDISP_STREAMSOURCEUM pStrSrc = &pDevice->aStreamSourceUm[pDecl9->Stream];
1672 if (pStrSrc->pvBuffer)
1673 {
1674 WORD iStream = pDecl9->Stream;
1675 D3DVERTEXELEMENT9 *pLastCDecl9 = pDecl9;
1676 for (UINT j = i+1; j < cDecls9 - 1 /* the last one is D3DDECL_END */; ++j)
1677 {
1678 pDecl9 = &aDecls9[j];
1679 if (iStream == pDecl9->Stream)
1680 {
1681 pDecl9->Stream = 0xff; /* mark as done */
1682 Assert(pDecl9->Offset != pLastCDecl9->Offset);
1683 if (pDecl9->Offset > pLastCDecl9->Offset)
1684 pLastCDecl9 = pDecl9;
1685 }
1686 }
1687 /* vertex size is MAX(all Offset's) + sizeof (data_type with MAX offset) + stride*/
1688 UINT cbVertex = pLastCDecl9->Offset + pStrSrc->cbStride;
1689 UINT cbType;
1690 switch (pLastCDecl9->Type)
1691 {
1692 case D3DDECLTYPE_FLOAT1:
1693 cbType = sizeof (float);
1694 break;
1695 case D3DDECLTYPE_FLOAT2:
1696 cbType = sizeof (float) * 2;
1697 break;
1698 case D3DDECLTYPE_FLOAT3:
1699 cbType = sizeof (float) * 3;
1700 break;
1701 case D3DDECLTYPE_FLOAT4:
1702 cbType = sizeof (float) * 4;
1703 break;
1704 case D3DDECLTYPE_D3DCOLOR:
1705 cbType = 4;
1706 break;
1707 case D3DDECLTYPE_UBYTE4:
1708 cbType = 4;
1709 break;
1710 case D3DDECLTYPE_SHORT2:
1711 cbType = sizeof (short) * 2;
1712 break;
1713 case D3DDECLTYPE_SHORT4:
1714 cbType = sizeof (short) * 4;
1715 break;
1716 case D3DDECLTYPE_UBYTE4N:
1717 cbType = 4;
1718 break;
1719 case D3DDECLTYPE_SHORT2N:
1720 cbType = sizeof (short) * 2;
1721 break;
1722 case D3DDECLTYPE_SHORT4N:
1723 cbType = sizeof (short) * 4;
1724 break;
1725 case D3DDECLTYPE_USHORT2N:
1726 cbType = sizeof (short) * 2;
1727 break;
1728 case D3DDECLTYPE_USHORT4N:
1729 cbType = sizeof (short) * 4;
1730 break;
1731 case D3DDECLTYPE_UDEC3:
1732 cbType = sizeof (signed) * 3;
1733 break;
1734 case D3DDECLTYPE_DEC3N:
1735 cbType = sizeof (unsigned) * 3;
1736 break;
1737 case D3DDECLTYPE_FLOAT16_2:
1738 cbType = 2 * 2;
1739 break;
1740 case D3DDECLTYPE_FLOAT16_4:
1741 cbType = 2 * 4;
1742 break;
1743 default:
1744 AssertBreakpoint();
1745 cbType = 1;
1746 }
1747 cbVertex += cbType;
1748
1749 UINT cVertexes;
1750 switch (pData->PrimitiveType)
1751 {
1752 case D3DPT_POINTLIST:
1753 cVertexes = pData->PrimitiveCount;
1754 break;
1755 case D3DPT_LINELIST:
1756 cVertexes = pData->PrimitiveCount * 2;
1757 break;
1758 case D3DPT_LINESTRIP:
1759 cVertexes = pData->PrimitiveCount + 1;
1760 break;
1761 case D3DPT_TRIANGLELIST:
1762 cVertexes = pData->PrimitiveCount * 3;
1763 break;
1764 case D3DPT_TRIANGLESTRIP:
1765 cVertexes = pData->PrimitiveCount + 2;
1766 break;
1767 case D3DPT_TRIANGLEFAN:
1768 cVertexes = pData->PrimitiveCount + 2;
1769 break;
1770 default:
1771 AssertBreakpoint();
1772 cVertexes = pData->PrimitiveCount;
1773 }
1774 UINT cbVertexes = cVertexes * cbVertex;
1775 IDirect3DVertexBuffer9 *pCurVb = NULL, *pVb = NULL;
1776 UINT cbOffset;
1777 UINT cbStride;
1778 hr = pDevice->pDevice9If->GetStreamSource(iStream, &pCurVb, &cbOffset, &cbStride);
1779 Assert(hr == S_OK);
1780 if (hr == S_OK)
1781 {
1782 if (pCurVb)
1783 {
1784 if (cbStride == pStrSrc->cbStride)
1785 {
1786 /* ensure our data feets in the buffer */
1787 D3DVERTEXBUFFER_DESC Desc;
1788 hr = pCurVb->GetDesc(&Desc);
1789 Assert(hr == S_OK);
1790 if (hr == S_OK)
1791 {
1792 if (Desc.Size >= cbVertexes)
1793 pVb = pCurVb;
1794 }
1795 }
1796 }
1797 }
1798 else
1799 {
1800 pCurVb = NULL;
1801 }
1802
1803 if (!pVb)
1804 {
1805 hr = pDevice->pDevice9If->CreateVertexBuffer(cbVertexes,
1806 0, /* DWORD Usage */
1807 0, /* DWORD FVF */
1808 D3DPOOL_DEFAULT, /* D3DPOOL Pool */
1809 &pVb,
1810 NULL /*HANDLE* pSharedHandle*/);
1811 Assert(hr == S_OK);
1812 if (hr == S_OK)
1813 {
1814 hr = pDevice->pDevice9If->SetStreamSource(iStream, pVb, 0, pStrSrc->cbStride);
1815 Assert(hr == S_OK);
1816 if (hr == S_OK)
1817 {
1818 if (pCurVb)
1819 pCurVb->Release();
1820 }
1821 else
1822 {
1823 pVb->Release();
1824 pVb = NULL;
1825 }
1826 }
1827 }
1828
1829 if (pVb)
1830 {
1831 Assert(hr == S_OK);
1832 VOID *pvData;
1833 hr = pVb->Lock(0, /* UINT OffsetToLock */
1834 cbVertexes,
1835 &pvData,
1836 D3DLOCK_DISCARD);
1837 Assert(hr == S_OK);
1838 if (hr == S_OK)
1839 {
1840 memcpy (pvData, ((uint8_t*)pStrSrc->pvBuffer) + pData->VStart * cbVertex, cbVertexes);
1841 HRESULT tmpHr = pVb->Unlock();
1842 Assert(tmpHr == S_OK);
1843 }
1844 }
1845 }
1846 }
1847 }
1848 }
1849 if (hr == S_OK)
1850 {
1851 hr = pDevice->pDevice9If->DrawPrimitive(pData->PrimitiveType,
1852 0 /* <- since we use our owne StreamSource buffer which has data at the very beginning*/,
1853 pData->PrimitiveCount);
1854 Assert(hr == S_OK);
1855 }
1856 }
1857#endif
1858 }
1859 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
1860 return hr;
1861}
1862
1863static HRESULT APIENTRY vboxWddmDDevDrawIndexedPrimitive(HANDLE hDevice, CONST D3DDDIARG_DRAWINDEXEDPRIMITIVE* pData)
1864{
1865 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
1866 AssertBreakpoint();
1867 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
1868 return E_FAIL;
1869}
1870
1871static HRESULT APIENTRY vboxWddmDDevDrawRectPatch(HANDLE hDevice, CONST D3DDDIARG_DRAWRECTPATCH* pData, CONST D3DDDIRECTPATCH_INFO* pInfo, CONST FLOAT* pPatch)
1872{
1873 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
1874 AssertBreakpoint();
1875 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
1876 return E_FAIL;
1877}
1878
1879static HRESULT APIENTRY vboxWddmDDevDrawTriPatch(HANDLE hDevice, CONST D3DDDIARG_DRAWTRIPATCH* pData, CONST D3DDDITRIPATCH_INFO* pInfo, CONST FLOAT* pPatch)
1880{
1881 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
1882 AssertBreakpoint();
1883 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
1884 return E_FAIL;
1885}
1886
1887static HRESULT APIENTRY vboxWddmDDevDrawPrimitive2(HANDLE hDevice, CONST D3DDDIARG_DRAWPRIMITIVE2* pData)
1888{
1889 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
1890 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
1891 Assert(pDevice);
1892 Assert(pDevice->pDevice9If);
1893 HRESULT hr;
1894
1895#if 0
1896 int stream;
1897 for (stream=0; stream<VBOXWDDMDISP_MAX_VERTEX_STREAMS; ++stream)
1898 {
1899 if (pDevice->aStreamSource[stream] && pDevice->aStreamSource[stream]->LockInfo.cLocks)
1900 {
1901 VBOXWDDMDISP_LOCKINFO *pLock = &pDevice->aStreamSource[stream]->LockInfo;
1902 if (pLock->fFlags.MightDrawFromLocked && (pLock->fFlags.Discard || pLock->fFlags.NoOverwrite))
1903 {
1904 IDirect3DVertexBuffer9 *pD3D9VBuf = (IDirect3DVertexBuffer9*)pDevice->aStreamSource[stream]->pD3DIf;
1905 Assert(pLock->fFlags.RangeValid);
1906 pD3D9VBuf->Lock(pLock->Range.Offset, pLock->Range.Size,
1907 &pLock->LockedRect.pBits,
1908 vboxDDI2D3DLockFlags(pLock->fFlags));
1909 RECT r;
1910 r.top = 0;
1911 r.left = pLock->Range.Offset;
1912 r.bottom = 1;
1913 r.right = pLock->Range.Offset + pLock->Range.Size;
1914
1915 vboxWddmLockUnlockMemSynch(pDevice->aStreamSource[stream], &pLock->LockedRect, &r, true /*bool bToLockInfo*/);
1916
1917 pD3D9VBuf->Unlock();
1918 }
1919 }
1920 }
1921
1922 hr = pDevice->pDevice9If->DrawPrimitive(pData->PrimitiveType, pData->FirstVertexOffset, pData->PrimitiveCount);
1923#else
1924 int stream;
1925 for (stream=0; stream<VBOXWDDMDISP_MAX_VERTEX_STREAMS; ++stream)
1926 {
1927 if (pDevice->aStreamSource[stream])
1928 {
1929 Assert(stream==0); /*only stream 0 should be accessed here*/
1930 Assert(pDevice->StreamSourceInfo[stream].uiStride!=0);
1931 VBOXWDDMDISP_LOCKINFO *pLock = &pDevice->aStreamSource[stream]->LockInfo;
1932
1933 if (pDevice->aStreamSource[stream]->LockInfo.cLocks)
1934 {
1935 Assert(pLock->fFlags.MightDrawFromLocked && (pLock->fFlags.Discard || pLock->fFlags.NoOverwrite));
1936 hr = pDevice->pDevice9If->DrawPrimitiveUP(pData->PrimitiveType, pData->PrimitiveCount,
1937 (void*)((uintptr_t)pDevice->aStreamSource[stream]->pvMem+pDevice->StreamSourceInfo[stream].uiOffset+pData->FirstVertexOffset),
1938 pDevice->StreamSourceInfo[stream].uiStride);
1939 Assert(hr == S_OK);
1940 hr = pDevice->pDevice9If->SetStreamSource(stream, (IDirect3DVertexBuffer9*)pDevice->aStreamSource[stream]->pD3DIf, pDevice->StreamSourceInfo[stream].uiOffset, pDevice->StreamSourceInfo[stream].uiStride);
1941 }
1942 else
1943 {
1944 hr = pDevice->pDevice9If->DrawPrimitive(pData->PrimitiveType, pData->FirstVertexOffset/pDevice->StreamSourceInfo[stream].uiStride, pData->PrimitiveCount);
1945 }
1946 }
1947 }
1948#endif
1949
1950 Assert(hr == S_OK);
1951 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
1952 return hr;
1953}
1954
1955static HRESULT APIENTRY vboxWddmDDevDrawIndexedPrimitive2(HANDLE hDevice, CONST D3DDDIARG_DRAWINDEXEDPRIMITIVE2* pData, UINT dwIndicesSize, CONST VOID* pIndexBuffer, CONST UINT* pFlagBuffer)
1956{
1957 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
1958 AssertBreakpoint();
1959 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
1960 return E_FAIL;
1961}
1962
1963static HRESULT APIENTRY vboxWddmDDevVolBlt(HANDLE hDevice, CONST D3DDDIARG_VOLUMEBLT* pData)
1964{
1965 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
1966 AssertBreakpoint();
1967 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
1968 return E_FAIL;
1969}
1970
1971static HRESULT APIENTRY vboxWddmDDevBufBlt(HANDLE hDevice, CONST D3DDDIARG_BUFFERBLT* pData)
1972{
1973 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
1974 AssertBreakpoint();
1975 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
1976 return E_FAIL;
1977}
1978
1979static HRESULT APIENTRY vboxWddmDDevTexBlt(HANDLE hDevice, CONST D3DDDIARG_TEXBLT* pData)
1980{
1981 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
1982 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
1983 Assert(pDevice);
1984 Assert(pDevice->pDevice9If);
1985 PVBOXWDDMDISP_RESOURCE pDstRc = (PVBOXWDDMDISP_RESOURCE)pData->hDstResource;
1986 PVBOXWDDMDISP_RESOURCE pSrcRc = (PVBOXWDDMDISP_RESOURCE)pData->hSrcResource;
1987 IDirect3DTexture9 *pD3DIfSrcTex = (IDirect3DTexture9*)pSrcRc->aAllocations[0].pD3DIf;
1988 IDirect3DTexture9 *pD3DIfDstTex = (IDirect3DTexture9*)pDstRc->aAllocations[0].pD3DIf;
1989 Assert(pD3DIfSrcTex);
1990 Assert(pD3DIfDstTex);
1991 HRESULT hr = S_OK;
1992
1993 if (pSrcRc->aAllocations[0].SurfDesc.width == pDstRc->aAllocations[0].SurfDesc.width
1994 && pSrcRc->aAllocations[0].SurfDesc.height == pDstRc->aAllocations[0].SurfDesc.height
1995 && pSrcRc->RcDesc.enmFormat == pDstRc->RcDesc.enmFormat)
1996 {
1997 /* first check if we can do IDirect3DDevice9::UpdateTexture */
1998 if (pData->DstPoint.x == 0 && pData->DstPoint.y == 0
1999 && pData->SrcRect.left == 0 && pData->SrcRect.top == 0
2000 && pData->SrcRect.right - pData->SrcRect.left == pSrcRc->aAllocations[0].SurfDesc.width
2001 && pData->SrcRect.bottom - pData->SrcRect.top == pSrcRc->aAllocations[0].SurfDesc.height)
2002 {
2003 hr = pDevice->pDevice9If->UpdateTexture(pD3DIfSrcTex, pD3DIfDstTex);
2004 Assert(hr == S_OK);
2005 }
2006 else
2007 {
2008 AssertBreakpoint();
2009 /* @todo: impl */
2010 }
2011 }
2012 else
2013 {
2014 AssertBreakpoint();
2015 /* @todo: impl */
2016 }
2017
2018 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
2019 return hr;
2020}
2021
2022static HRESULT APIENTRY vboxWddmDDevStateSet(HANDLE hDevice, D3DDDIARG_STATESET* pData)
2023{
2024 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
2025 AssertBreakpoint();
2026 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
2027 return E_FAIL;
2028}
2029static HRESULT APIENTRY vboxWddmDDevSetPriority(HANDLE hDevice, CONST D3DDDIARG_SETPRIORITY* pData)
2030{
2031 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
2032 AssertBreakpoint();
2033 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
2034 return E_FAIL;
2035}
2036AssertCompile(sizeof (RECT) == sizeof (D3DRECT));
2037AssertCompile(RT_SIZEOFMEMB(RECT, left) == RT_SIZEOFMEMB(D3DRECT, x1));
2038AssertCompile(RT_SIZEOFMEMB(RECT, right) == RT_SIZEOFMEMB(D3DRECT, x2));
2039AssertCompile(RT_SIZEOFMEMB(RECT, top) == RT_SIZEOFMEMB(D3DRECT, y1));
2040AssertCompile(RT_SIZEOFMEMB(RECT, bottom) == RT_SIZEOFMEMB(D3DRECT, y2));
2041AssertCompile(RT_OFFSETOF(RECT, left) == RT_OFFSETOF(D3DRECT, x1));
2042AssertCompile(RT_OFFSETOF(RECT, right) == RT_OFFSETOF(D3DRECT, x2));
2043AssertCompile(RT_OFFSETOF(RECT, top) == RT_OFFSETOF(D3DRECT, y1));
2044AssertCompile(RT_OFFSETOF(RECT, bottom) == RT_OFFSETOF(D3DRECT, y2));
2045
2046static HRESULT APIENTRY vboxWddmDDevClear(HANDLE hDevice, CONST D3DDDIARG_CLEAR* pData, UINT NumRect, CONST RECT* pRect)
2047{
2048 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
2049 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
2050 Assert(pDevice);
2051 Assert(pDevice->pDevice9If);
2052 HRESULT hr = pDevice->pDevice9If->Clear(NumRect, (D3DRECT*)pRect /* see AssertCompile above */,
2053 pData->Flags,
2054 pData->FillColor,
2055 pData->FillDepth,
2056 pData->FillStencil);
2057 Assert(hr == S_OK);
2058 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
2059 return hr;
2060}
2061static HRESULT APIENTRY vboxWddmDDevUpdatePalette(HANDLE hDevice, CONST D3DDDIARG_UPDATEPALETTE* pData, CONST PALETTEENTRY* pPaletteData)
2062{
2063 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
2064 AssertBreakpoint();
2065 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
2066 return E_FAIL;
2067}
2068
2069static HRESULT APIENTRY vboxWddmDDevSetPalette(HANDLE hDevice, CONST D3DDDIARG_SETPALETTE* pData)
2070{
2071 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
2072 AssertBreakpoint();
2073 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
2074 return E_FAIL;
2075}
2076
2077static HRESULT APIENTRY vboxWddmDDevSetVertexShaderConst(HANDLE hDevice, CONST D3DDDIARG_SETVERTEXSHADERCONST* pData , CONST VOID* pRegisters)
2078{
2079 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
2080 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
2081 Assert(pDevice);
2082 Assert(pDevice->pDevice9If);
2083 HRESULT hr = pDevice->pDevice9If->SetVertexShaderConstantF(
2084 pData->Register,
2085 (CONST float*)pRegisters,
2086 pData->Count);
2087 Assert(hr == S_OK);
2088 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
2089 return hr;
2090}
2091static HRESULT APIENTRY vboxWddmDDevMultiplyTransform(HANDLE hDevice, CONST D3DDDIARG_MULTIPLYTRANSFORM* pData)
2092{
2093 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
2094 AssertBreakpoint();
2095 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
2096 return E_FAIL;
2097}
2098static HRESULT APIENTRY vboxWddmDDevSetTransform(HANDLE hDevice, CONST D3DDDIARG_SETTRANSFORM* pData)
2099{
2100 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
2101 AssertBreakpoint();
2102 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
2103 return E_FAIL;
2104}
2105static HRESULT APIENTRY vboxWddmDDevSetViewport(HANDLE hDevice, CONST D3DDDIARG_VIEWPORTINFO* pData)
2106{
2107 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
2108 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
2109 Assert(pDevice);
2110 Assert(pDevice->pDevice9If);
2111 pDevice->ViewPort.X = pData->X;
2112 pDevice->ViewPort.Y = pData->Y;
2113 pDevice->ViewPort.Width = pData->Width;
2114 pDevice->ViewPort.Height = pData->Height;
2115 HRESULT hr = pDevice->pDevice9If->SetViewport(&pDevice->ViewPort);
2116 Assert(hr == S_OK);
2117 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
2118 return hr;
2119}
2120static HRESULT APIENTRY vboxWddmDDevSetZRange(HANDLE hDevice, CONST D3DDDIARG_ZRANGE* pData)
2121{
2122 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
2123 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
2124 Assert(pDevice);
2125 Assert(pDevice->pDevice9If);
2126 pDevice->ViewPort.MinZ = pData->MinZ;
2127 pDevice->ViewPort.MaxZ = pData->MaxZ;
2128 HRESULT hr = pDevice->pDevice9If->SetViewport(&pDevice->ViewPort);
2129 Assert(hr == S_OK);
2130 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
2131 return hr;
2132}
2133static HRESULT APIENTRY vboxWddmDDevSetMaterial(HANDLE hDevice, CONST D3DDDIARG_SETMATERIAL* pData)
2134{
2135 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
2136 AssertBreakpoint();
2137 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
2138 return E_FAIL;
2139}
2140static HRESULT APIENTRY vboxWddmDDevSetLight(HANDLE hDevice, CONST D3DDDIARG_SETLIGHT* pData, CONST D3DDDI_LIGHT* pLightProperties)
2141{
2142 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
2143 AssertBreakpoint();
2144 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
2145 return E_FAIL;
2146}
2147static HRESULT APIENTRY vboxWddmDDevCreateLight(HANDLE hDevice, CONST D3DDDIARG_CREATELIGHT* pData)
2148{
2149 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
2150 AssertBreakpoint();
2151 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
2152 return E_FAIL;
2153}
2154static HRESULT APIENTRY vboxWddmDDevDestroyLight(HANDLE hDevice, CONST D3DDDIARG_DESTROYLIGHT* pData)
2155{
2156 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
2157 AssertBreakpoint();
2158 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
2159 return E_FAIL;
2160}
2161static HRESULT APIENTRY vboxWddmDDevSetClipPlane(HANDLE hDevice, CONST D3DDDIARG_SETCLIPPLANE* pData)
2162{
2163 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
2164 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
2165 Assert(pDevice);
2166 Assert(pDevice->pDevice9If);
2167 HRESULT hr = pDevice->pDevice9If->SetClipPlane(pData->Index, pData->Plane);
2168 Assert(hr == S_OK);
2169 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
2170 return hr;
2171}
2172
2173static HRESULT APIENTRY vboxWddmDDevGetInfo(HANDLE hDevice, UINT DevInfoID, VOID* pDevInfoStruct, UINT DevInfoSize)
2174{
2175 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
2176 AssertBreakpoint();
2177 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
2178 return E_NOTIMPL;
2179}
2180
2181static HRESULT APIENTRY vboxWddmDDevLock(HANDLE hDevice, D3DDDIARG_LOCK* pData)
2182{
2183 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
2184 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
2185 PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)pData->hResource;
2186 Assert(pData->SubResourceIndex < pRc->cAllocations);
2187 if (pData->SubResourceIndex >= pRc->cAllocations)
2188 return E_INVALIDARG;
2189
2190 HRESULT hr = S_OK;
2191
2192 if (VBOXDISPMODE_IS_3D(pDevice->pAdapter))
2193 {
2194 if (pRc->RcDesc.fFlags.Texture || pRc->RcDesc.fFlags.Value == 0)
2195 {
2196 PVBOXWDDMDISP_ALLOCATION pTexAlloc = &pRc->aAllocations[0];
2197 Assert(pData->SubResourceIndex < pRc->cAllocations);
2198 PVBOXWDDMDISP_ALLOCATION pLockAlloc = &pRc->aAllocations[pData->SubResourceIndex];
2199 IDirect3DTexture9 *pD3DIfTex = (IDirect3DTexture9*)pTexAlloc->pD3DIf;
2200 Assert(pD3DIfTex);
2201 RECT *pRect = NULL;
2202 bool bNeedResynch = false;
2203 Assert(!pData->Flags.RangeValid);
2204 Assert(!pData->Flags.BoxValid);
2205 if (pData->Flags.AreaValid)
2206 {
2207 pRect = &pData->Area;
2208 }
2209
2210 /* else - we lock the entire texture, pRect == NULL */
2211
2212// Assert(!pLockAlloc->LockInfo.cLocks);
2213 if (!pLockAlloc->LockInfo.cLocks)
2214 {
2215 hr = pD3DIfTex->LockRect(pData->SubResourceIndex,
2216 &pLockAlloc->LockInfo.LockedRect,
2217 pRect,
2218 vboxDDI2D3DLockFlags(pData->Flags));
2219 Assert(hr == S_OK);
2220 if (hr == S_OK)
2221 {
2222
2223// Assert(pLockAlloc->LockInfo.fFlags.Value == 0);
2224 pLockAlloc->LockInfo.fFlags = pData->Flags;
2225 if (pRect)
2226 {
2227 pLockAlloc->LockInfo.Area = *pRect;
2228 Assert(pLockAlloc->LockInfo.fFlags.AreaValid == 1);
2229// pLockAlloc->LockInfo.fFlags.AreaValid = 1;
2230 }
2231 else
2232 {
2233 Assert(pLockAlloc->LockInfo.fFlags.AreaValid == 0);
2234// pLockAlloc->LockInfo.fFlags.AreaValid = 0;
2235 }
2236
2237 bNeedResynch = !pData->Flags.Discard;
2238 }
2239 }
2240 else
2241 {
2242// Assert(pLockAlloc->LockInfo.fFlags.Value == pData->Flags.Value);
2243// if (pLockAlloc->LockInfo.fFlags.Value != pData->Flags.Value)
2244// {
2245// }
2246 Assert(pLockAlloc->LockInfo.fFlags.AreaValid == pData->Flags.AreaValid);
2247 if (pLockAlloc->LockInfo.fFlags.AreaValid && pData->Flags.AreaValid)
2248 {
2249 Assert(pLockAlloc->LockInfo.Area.left == pData->Area.left);
2250 Assert(pLockAlloc->LockInfo.Area.top == pData->Area.top);
2251 Assert(pLockAlloc->LockInfo.Area.right == pData->Area.right);
2252 Assert(pLockAlloc->LockInfo.Area.bottom == pData->Area.bottom);
2253 }
2254 Assert(pLockAlloc->LockInfo.LockedRect.pBits);
2255
2256 bNeedResynch = pLockAlloc->LockInfo.fFlags.Discard && !pData->Flags.Discard;
2257
2258 Assert(!bNeedResynch);
2259
2260 if (/*(pLockAlloc->LockInfo.fFlags.Discard && !pData->Flags.Discard)
2261 || */
2262 (pLockAlloc->LockInfo.fFlags.ReadOnly && !pData->Flags.ReadOnly))
2263 {
2264 hr = pD3DIfTex->UnlockRect(pData->SubResourceIndex);
2265 Assert(hr == S_OK);
2266 if (hr == S_OK)
2267 {
2268 hr = pD3DIfTex->LockRect(pData->SubResourceIndex,
2269 &pLockAlloc->LockInfo.LockedRect,
2270 pRect,
2271 vboxDDI2D3DLockFlags(pData->Flags));
2272 Assert(hr == S_OK);
2273 pLockAlloc->LockInfo.fFlags.ReadOnly = 0;
2274 }
2275 }
2276 }
2277
2278 if (hr == S_OK)
2279 {
2280 ++pLockAlloc->LockInfo.cLocks;
2281
2282 if (!pData->Flags.NotifyOnly)
2283 {
2284 pData->pSurfData = pLockAlloc->LockInfo.LockedRect.pBits;
2285 pData->Pitch = pLockAlloc->LockInfo.LockedRect.Pitch;
2286 pData->SlicePitch = 0;
2287 Assert(pLockAlloc->SurfDesc.slicePitch == 0);
2288 Assert(!pLockAlloc->pvMem);
2289 }
2290 else
2291 {
2292 Assert(pLockAlloc->pvMem);
2293 Assert(pRc->RcDesc.enmPool == D3DDDIPOOL_SYSTEMMEM);
2294
2295 if (bNeedResynch)
2296 vboxWddmLockUnlockMemSynch(pLockAlloc, &pLockAlloc->LockInfo.LockedRect, pRect, false /*bool bToLockInfo*/);
2297 }
2298 }
2299 }
2300 else if (pRc->RcDesc.fFlags.VertexBuffer)
2301 {
2302 Assert(pData->SubResourceIndex < pRc->cAllocations);
2303 PVBOXWDDMDISP_ALLOCATION pAlloc = &pRc->aAllocations[pData->SubResourceIndex];
2304 IDirect3DVertexBuffer9 *pD3D9VBuf = (IDirect3DVertexBuffer9*)pAlloc->pD3DIf;
2305 BOOL bLocked = false;
2306 Assert(pD3D9VBuf);
2307 Assert(!pData->Flags.AreaValid);
2308 Assert(!pData->Flags.BoxValid);
2309 D3DDDIRANGE *pRange = NULL;
2310 if (pData->Flags.RangeValid)
2311 {
2312 pRange = &pData->Range;
2313 }
2314
2315 /* else - we lock the entire vertex buffer, pRect == NULL */
2316
2317 Assert(!pAlloc->LockInfo.cLocks);
2318 if (!pAlloc->LockInfo.cLocks)
2319 {
2320 if (!pData->Flags.MightDrawFromLocked || (!pData->Flags.Discard && !pData->Flags.NoOverwrite))
2321 {
2322 hr = pD3D9VBuf->Lock(pRange ? pRange->Offset : 0,
2323 pRange ? pRange->Size : 0,
2324 &pAlloc->LockInfo.LockedRect.pBits,
2325 vboxDDI2D3DLockFlags(pData->Flags));
2326 bLocked = true;
2327 }
2328
2329 Assert(hr == S_OK);
2330 if (hr == S_OK)
2331 {
2332 pAlloc->LockInfo.LockedRect.Pitch = pAlloc->SurfDesc.width;
2333// Assert(pLockAlloc->LockInfo.fFlags.Value == 0);
2334 pAlloc->LockInfo.fFlags = pData->Flags;
2335 if (pRange)
2336 {
2337 pAlloc->LockInfo.Range = *pRange;
2338 Assert(pAlloc->LockInfo.fFlags.RangeValid == 1);
2339// pAlloc->LockInfo.fFlags.RangeValid = 1;
2340 }
2341 else
2342 {
2343 Assert(pAlloc->LockInfo.fFlags.RangeValid == 0);
2344// pAlloc->LockInfo.fFlags.RangeValid = 0;
2345 }
2346 }
2347 }
2348 else
2349 {
2350// Assert(pAlloc->LockInfo.fFlags.Value == pData->Flags.Value);
2351// if (pAlloc->LockInfo.fFlags.Value != pData->Flags.Value)
2352// {
2353// }
2354 Assert(pAlloc->LockInfo.fFlags.RangeValid == pData->Flags.RangeValid);
2355 if (pAlloc->LockInfo.fFlags.RangeValid && pData->Flags.RangeValid)
2356 {
2357 Assert(pAlloc->LockInfo.Range.Offset == pData->Range.Offset);
2358 Assert(pAlloc->LockInfo.Range.Size == pData->Range.Size);
2359 }
2360 Assert(pAlloc->LockInfo.LockedRect.pBits);
2361 }
2362
2363 if (hr == S_OK)
2364 {
2365 ++pAlloc->LockInfo.cLocks;
2366
2367 if (!pData->Flags.NotifyOnly)
2368 {
2369 pData->pSurfData = pAlloc->LockInfo.LockedRect.pBits;
2370 pData->Pitch = pAlloc->LockInfo.LockedRect.Pitch;
2371 pData->SlicePitch = 0;
2372 Assert(pAlloc->SurfDesc.slicePitch == 0);
2373 Assert(!pAlloc->pvMem);
2374 }
2375 else
2376 {
2377 Assert(pAlloc->pvMem);
2378 Assert(pRc->RcDesc.enmPool == D3DDDIPOOL_SYSTEMMEM);
2379 if (bLocked && !pData->Flags.Discard)
2380 {
2381 RECT r, *pr;
2382 if (pRange)
2383 {
2384 r.top = 0;
2385 r.left = pRange->Offset;
2386 r.bottom = 1;
2387 r.right = pRange->Offset + pRange->Size;
2388 pr = &r;
2389 }
2390 else
2391 pr = NULL;
2392 vboxWddmLockUnlockMemSynch(pAlloc, &pAlloc->LockInfo.LockedRect, pr, false /*bool bToLockInfo*/);
2393 }
2394 }
2395 }
2396 }
2397 else if (pRc->RcDesc.fFlags.IndexBuffer)
2398 {
2399 Assert(pData->SubResourceIndex < pRc->cAllocations);
2400 PVBOXWDDMDISP_ALLOCATION pAlloc = &pRc->aAllocations[pData->SubResourceIndex];
2401 IDirect3DIndexBuffer9 *pD3D9IBuf = (IDirect3DIndexBuffer9*)pAlloc->pD3DIf;
2402 BOOL bLocked = false;
2403 Assert(pD3D9IBuf);
2404 Assert(!pData->Flags.AreaValid);
2405 Assert(!pData->Flags.BoxValid);
2406 D3DDDIRANGE *pRange = NULL;
2407 if (pData->Flags.RangeValid)
2408 {
2409 pRange = &pData->Range;
2410 }
2411
2412 /* else - we lock the entire vertex buffer, pRect == NULL */
2413
2414 Assert(!pAlloc->LockInfo.cLocks);
2415 if (!pAlloc->LockInfo.cLocks)
2416 {
2417 if (!pData->Flags.MightDrawFromLocked || (!pData->Flags.Discard && !pData->Flags.NoOverwrite))
2418 {
2419 hr = pD3D9IBuf->Lock(pRange ? pRange->Offset : 0,
2420 pRange ? pRange->Size : 0,
2421 &pAlloc->LockInfo.LockedRect.pBits,
2422 vboxDDI2D3DLockFlags(pData->Flags));
2423 bLocked = true;
2424 }
2425
2426 Assert(hr == S_OK);
2427 if (hr == S_OK)
2428 {
2429 pAlloc->LockInfo.LockedRect.Pitch = pAlloc->SurfDesc.width;
2430// Assert(pLockAlloc->LockInfo.fFlags.Value == 0);
2431 pAlloc->LockInfo.fFlags = pData->Flags;
2432 if (pRange)
2433 {
2434 pAlloc->LockInfo.Range = *pRange;
2435 Assert(pAlloc->LockInfo.fFlags.RangeValid == 1);
2436// pAlloc->LockInfo.fFlags.RangeValid = 1;
2437 }
2438 else
2439 {
2440 Assert(pAlloc->LockInfo.fFlags.RangeValid == 0);
2441// pAlloc->LockInfo.fFlags.RangeValid = 0;
2442 }
2443 }
2444 }
2445 else
2446 {
2447// Assert(pAlloc->LockInfo.fFlags.Value == pData->Flags.Value);
2448// if (pAlloc->LockInfo.fFlags.Value != pData->Flags.Value)
2449// {
2450// }
2451 Assert(pAlloc->LockInfo.fFlags.RangeValid == pData->Flags.RangeValid);
2452 if (pAlloc->LockInfo.fFlags.RangeValid && pData->Flags.RangeValid)
2453 {
2454 Assert(pAlloc->LockInfo.Range.Offset == pData->Range.Offset);
2455 Assert(pAlloc->LockInfo.Range.Size == pData->Range.Size);
2456 }
2457 Assert(pAlloc->LockInfo.LockedRect.pBits);
2458 }
2459
2460 if (hr == S_OK)
2461 {
2462 ++pAlloc->LockInfo.cLocks;
2463
2464 if (!pData->Flags.NotifyOnly)
2465 {
2466 pData->pSurfData = pAlloc->LockInfo.LockedRect.pBits;
2467 pData->Pitch = pAlloc->LockInfo.LockedRect.Pitch;
2468 pData->SlicePitch = 0;
2469 Assert(pAlloc->SurfDesc.slicePitch == 0);
2470 Assert(!pAlloc->pvMem);
2471 }
2472 else
2473 {
2474 Assert(pAlloc->pvMem);
2475 Assert(pRc->RcDesc.enmPool == D3DDDIPOOL_SYSTEMMEM);
2476 if (bLocked && !pData->Flags.Discard)
2477 {
2478 RECT r, *pr;
2479 if (pRange)
2480 {
2481 r.top = 0;
2482 r.left = pRange->Offset;
2483 r.bottom = 1;
2484 r.right = pRange->Offset + pRange->Size;
2485 pr = &r;
2486 }
2487 else
2488 pr = NULL;
2489 vboxWddmLockUnlockMemSynch(pAlloc, &pAlloc->LockInfo.LockedRect, pr, false /*bool bToLockInfo*/);
2490 }
2491 }
2492 }
2493 }
2494 else
2495 {
2496 AssertBreakpoint();
2497 }
2498 }
2499 else
2500 {
2501 PVBOXWDDMDISP_ALLOCATION pAlloc = &pRc->aAllocations[pData->SubResourceIndex];
2502 D3DDDICB_LOCK LockData;
2503 LockData.hAllocation = pAlloc->hAllocation;
2504 LockData.PrivateDriverData = 0;
2505 LockData.NumPages = 0;
2506 LockData.pPages = NULL;
2507 LockData.pData = NULL; /* out */
2508 LockData.Flags.Value = 0;
2509 LockData.Flags.Discard = pData->Flags.Discard;
2510 LockData.Flags.DonotWait = pData->Flags.DoNotWait;
2511
2512
2513 hr = pDevice->RtCallbacks.pfnLockCb(pDevice->hDevice, &LockData);
2514 Assert(hr == S_OK || (hr == D3DERR_WASSTILLDRAWING && pData->Flags.DoNotWait));
2515 if (hr == S_OK)
2516 {
2517 Assert(!pAlloc->LockInfo.cLocks);
2518
2519 uintptr_t offset;
2520 if (pData->Flags.AreaValid)
2521 {
2522 offset = pAlloc->SurfDesc.pitch * pData->Area.top +
2523 ((pAlloc->SurfDesc.bpp * pData->Area.left) >> 3);
2524 }
2525 else if (pData->Flags.RangeValid)
2526 {
2527 offset = pData->Range.Offset;
2528 }
2529 else if (pData->Flags.BoxValid)
2530 {
2531 vboxVDbgPrintF((__FUNCTION__": Implement Box area"));
2532 AssertBreakpoint();
2533 }
2534 else
2535 {
2536 offset = 0;
2537 }
2538
2539 if (!pData->Flags.ReadOnly)
2540 {
2541 if (pData->Flags.AreaValid)
2542 vboxWddmDirtyRegionAddRect(&pAlloc->DirtyRegion, &pData->Area);
2543 else
2544 {
2545 Assert(!pData->Flags.RangeValid);
2546 Assert(!pData->Flags.BoxValid);
2547 vboxWddmDirtyRegionAddRect(&pAlloc->DirtyRegion, NULL); /* <- NULL means the entire surface */
2548 }
2549 }
2550
2551 if (pData->Flags.Discard)
2552 {
2553 /* check if the surface was renamed */
2554 if (LockData.hAllocation)
2555 pAlloc->hAllocation = LockData.hAllocation;
2556 }
2557
2558 pData->pSurfData = ((uint8_t*)LockData.pData) + offset;
2559 pData->Pitch = pAlloc->SurfDesc.pitch;
2560 pData->SlicePitch = pAlloc->SurfDesc.slicePitch;
2561
2562 Assert(hr == S_OK);
2563 ++pAlloc->LockInfo.cLocks;
2564 }
2565 }
2566
2567 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(%d)\n", hDevice, hr));
2568 return hr;
2569}
2570static HRESULT APIENTRY vboxWddmDDevUnlock(HANDLE hDevice, CONST D3DDDIARG_UNLOCK* pData)
2571{
2572 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
2573 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
2574 PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)pData->hResource;
2575 HRESULT hr = S_OK;
2576
2577 Assert(pData->SubResourceIndex < pRc->cAllocations);
2578 if (pData->SubResourceIndex >= pRc->cAllocations)
2579 return E_INVALIDARG;
2580
2581 if (VBOXDISPMODE_IS_3D(pDevice->pAdapter))
2582 {
2583 if (pRc->RcDesc.fFlags.Texture || pRc->RcDesc.fFlags.Value == 0)
2584 {
2585 Assert(pData->SubResourceIndex < pRc->cAllocations);
2586 PVBOXWDDMDISP_ALLOCATION pLockAlloc = &pRc->aAllocations[pData->SubResourceIndex];
2587
2588 --pLockAlloc->LockInfo.cLocks;
2589 Assert(pLockAlloc->LockInfo.cLocks < UINT32_MAX);
2590// pLockAlloc->LockInfo.cLocks = 0;
2591 if (!pLockAlloc->LockInfo.cLocks)
2592 {
2593 PVBOXWDDMDISP_ALLOCATION pTexAlloc = &pRc->aAllocations[0];
2594// Assert(!pLockAlloc->LockInfo.cLocks);
2595 IDirect3DTexture9 *pD3DIfTex = (IDirect3DTexture9*)pTexAlloc->pD3DIf;
2596 Assert(pD3DIfTex);
2597 /* this is a sysmem texture, update */
2598 if (pLockAlloc->pvMem && !pLockAlloc->LockInfo.fFlags.ReadOnly)
2599 {
2600 vboxWddmLockUnlockMemSynch(pLockAlloc, &pLockAlloc->LockInfo.LockedRect,
2601 pLockAlloc->LockInfo.fFlags.AreaValid ? &pLockAlloc->LockInfo.Area : NULL,
2602 true /*bool bToLockInfo*/);
2603 }
2604 hr = pD3DIfTex->UnlockRect(pData->SubResourceIndex);
2605 Assert(hr == S_OK);
2606 }
2607 else
2608 {
2609 Assert(pLockAlloc->LockInfo.cLocks < UINT32_MAX);
2610 }
2611 }
2612 else if (pRc->RcDesc.fFlags.VertexBuffer)
2613 {
2614 Assert(pData->SubResourceIndex < pRc->cAllocations);
2615 PVBOXWDDMDISP_ALLOCATION pAlloc = &pRc->aAllocations[pData->SubResourceIndex];
2616
2617 --pAlloc->LockInfo.cLocks;
2618 Assert(pAlloc->LockInfo.cLocks < UINT32_MAX);
2619 if (!pAlloc->LockInfo.cLocks
2620 && (!pAlloc->LockInfo.fFlags.MightDrawFromLocked
2621 || (!pAlloc->LockInfo.fFlags.Discard && !pAlloc->LockInfo.fFlags.NoOverwrite)))
2622 {
2623// Assert(!pAlloc->LockInfo.cLocks);
2624 IDirect3DVertexBuffer9 *pD3D9VBuf = (IDirect3DVertexBuffer9*)pAlloc->pD3DIf;
2625 Assert(pD3D9VBuf);
2626 /* this is a sysmem texture, update */
2627 if (pAlloc->pvMem && !pAlloc->LockInfo.fFlags.ReadOnly)
2628 {
2629 RECT r, *pr;
2630 if (pAlloc->LockInfo.fFlags.RangeValid)
2631 {
2632 r.top = 0;
2633 r.left = pAlloc->LockInfo.Range.Offset;
2634 r.bottom = 1;
2635 r.right = pAlloc->LockInfo.Range.Offset + pAlloc->LockInfo.Range.Size;
2636 pr = &r;
2637 }
2638 else
2639 pr = NULL;
2640 vboxWddmLockUnlockMemSynch(pAlloc, &pAlloc->LockInfo.LockedRect,
2641 pr,
2642 true /*bool bToLockInfo*/);
2643 }
2644 hr = pD3D9VBuf->Unlock();
2645 Assert(hr == S_OK);
2646 }
2647 else if (pRc->RcDesc.fFlags.IndexBuffer)
2648 {
2649 IDirect3DIndexBuffer9 *pD3D9IBuf = (IDirect3DIndexBuffer9*)pAlloc->pD3DIf;
2650 Assert(pD3D9IBuf);
2651 /* this is a sysmem texture, update */
2652 if (pAlloc->pvMem && !pAlloc->LockInfo.fFlags.ReadOnly)
2653 {
2654 RECT r, *pr;
2655 if (pAlloc->LockInfo.fFlags.RangeValid)
2656 {
2657 r.top = 0;
2658 r.left = pAlloc->LockInfo.Range.Offset;
2659 r.bottom = 1;
2660 r.right = pAlloc->LockInfo.Range.Offset + pAlloc->LockInfo.Range.Size;
2661 pr = &r;
2662 }
2663 else
2664 pr = NULL;
2665 vboxWddmLockUnlockMemSynch(pAlloc, &pAlloc->LockInfo.LockedRect,
2666 pr,
2667 true /*bool bToLockInfo*/);
2668 }
2669 hr = pD3D9IBuf->Unlock();
2670 Assert(hr == S_OK);
2671 }
2672 else
2673 {
2674 Assert(pAlloc->LockInfo.cLocks < UINT32_MAX);
2675 }
2676 }
2677 else
2678 {
2679 AssertBreakpoint();
2680 }
2681 }
2682 else
2683 {
2684 struct
2685 {
2686 D3DDDICB_UNLOCK Unlock;
2687 D3DKMT_HANDLE hAllocation;
2688 } UnlockData;
2689
2690 PVBOXWDDMDISP_ALLOCATION pAlloc = &pRc->aAllocations[pData->SubResourceIndex];
2691
2692 UnlockData.Unlock.NumAllocations = 1;
2693 UnlockData.Unlock.phAllocations = &UnlockData.hAllocation;
2694 UnlockData.hAllocation = pAlloc->hAllocation;
2695
2696 hr = pDevice->RtCallbacks.pfnUnlockCb(pDevice->hDevice, &UnlockData.Unlock);
2697 Assert(hr == S_OK);
2698 if (hr == S_OK)
2699 {
2700 Assert(pAlloc->LockInfo.cLocks);
2701 --pAlloc->LockInfo.cLocks;
2702 Assert(pAlloc->LockInfo.cLocks < UINT32_MAX);
2703 }
2704 }
2705
2706 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
2707 return hr;
2708}
2709static HRESULT APIENTRY vboxWddmDDevLockAsync(HANDLE hDevice, D3DDDIARG_LOCKASYNC* pData)
2710{
2711 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
2712 AssertBreakpoint();
2713 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
2714 return E_FAIL;
2715}
2716static HRESULT APIENTRY vboxWddmDDevUnlockAsync(HANDLE hDevice, CONST D3DDDIARG_UNLOCKASYNC* pData)
2717{
2718 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
2719 AssertBreakpoint();
2720 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
2721 return E_FAIL;
2722}
2723static HRESULT APIENTRY vboxWddmDDevRename(HANDLE hDevice, CONST D3DDDIARG_RENAME* pData)
2724{
2725 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
2726 AssertBreakpoint();
2727 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
2728 return E_FAIL;
2729}
2730
2731static void vboxWddmRequestAllocFree(D3DDDICB_ALLOCATE* pAlloc)
2732{
2733 RTMemFree(pAlloc);
2734}
2735
2736static D3DDDICB_ALLOCATE* vboxWddmRequestAllocAlloc(D3DDDIARG_CREATERESOURCE* pResource)
2737{
2738 /* allocate buffer for D3DDDICB_ALLOCATE + D3DDDI_ALLOCATIONINFO * numAllocs + PVBOXWDDM_RCINFO with aAllocInfos[numAllocs] */
2739 uint32_t cbBuf = sizeof (D3DDDICB_ALLOCATE);
2740 uint32_t offDdiAllocInfos = (cbBuf + 7) & ~3;
2741 uint32_t cbDdiAllocInfos = sizeof (D3DDDI_ALLOCATIONINFO) * pResource->SurfCount;
2742 cbBuf = offDdiAllocInfos + cbDdiAllocInfos;
2743 uint32_t offRcInfo = (cbBuf + 7) & ~3;
2744 uint32_t cbRcInfo = sizeof (VBOXWDDM_RCINFO);
2745 cbBuf = offRcInfo + cbRcInfo;
2746 uint32_t offAllocInfos = (cbBuf + 7) & ~3;
2747 uint32_t cbAllocInfos = sizeof (VBOXWDDM_ALLOCINFO) * pResource->SurfCount;
2748 cbBuf = offAllocInfos + cbAllocInfos;
2749 uint8_t *pvBuf = (uint8_t*)RTMemAllocZ(cbBuf);
2750 Assert(pvBuf);
2751 if (pvBuf)
2752 {
2753 D3DDDICB_ALLOCATE* pAlloc = (D3DDDICB_ALLOCATE*)pvBuf;
2754 pAlloc->NumAllocations = pResource->SurfCount;
2755 pAlloc->pAllocationInfo = (D3DDDI_ALLOCATIONINFO*)(pvBuf + offDdiAllocInfos);
2756 PVBOXWDDM_RCINFO pRcInfo = (PVBOXWDDM_RCINFO)(pvBuf + offRcInfo);
2757 pAlloc->PrivateDriverDataSize = cbRcInfo;
2758 pAlloc->pPrivateDriverData = pRcInfo;
2759 pAlloc->hResource = pResource->hResource;
2760 PVBOXWDDM_ALLOCINFO pAllocInfos = (PVBOXWDDM_ALLOCINFO)(pvBuf + offAllocInfos);
2761 for (UINT i = 0; i < pResource->SurfCount; ++i)
2762 {
2763 D3DDDI_ALLOCATIONINFO* pDdiAllocInfo = &pAlloc->pAllocationInfo[i];
2764 PVBOXWDDM_ALLOCINFO pAllocInfo = &pAllocInfos[i];
2765 pDdiAllocInfo->pPrivateDriverData = pAllocInfo;
2766 pDdiAllocInfo->PrivateDriverDataSize = sizeof (VBOXWDDM_ALLOCINFO);
2767 }
2768 return pAlloc;
2769 }
2770 return NULL;
2771}
2772static HRESULT APIENTRY vboxWddmDDevCreateResource(HANDLE hDevice, D3DDDIARG_CREATERESOURCE* pResource)
2773{
2774 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
2775 HRESULT hr = S_OK;
2776 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
2777 Assert(pDevice);
2778 Assert(pResource);
2779 PVBOXWDDMDISP_ADAPTER pAdapter = pDevice->pAdapter;
2780
2781 PVBOXWDDMDISP_RESOURCE pRc = vboxResourceAlloc(pResource->SurfCount);
2782 Assert(pRc);
2783 if (pRc)
2784 {
2785 bool bIssueCreateResource = false;
2786
2787 pRc->hResource = pResource->hResource;
2788 pRc->hKMResource = NULL;
2789 pRc->pDevice = pDevice;
2790 pRc->fFlags = VBOXWDDM_RESOURCE_F_TYPE_GENERIC;
2791 pRc->RcDesc.fFlags = pResource->Flags;
2792 pRc->RcDesc.enmFormat = pResource->Format;
2793 pRc->RcDesc.enmPool = pResource->Pool;
2794 pRc->RcDesc.enmMultisampleType = pResource->MultisampleType;
2795 pRc->RcDesc.MultisampleQuality = pResource->MultisampleQuality;
2796 pRc->RcDesc.MipLevels = pResource->MipLevels;
2797 pRc->RcDesc.Fvf = pResource->Fvf;
2798 pRc->RcDesc.VidPnSourceId = pResource->VidPnSourceId;
2799 pRc->RcDesc.RefreshRate = pResource->RefreshRate;
2800 pRc->RcDesc.enmRotation = pResource->Rotation;
2801 pRc->cAllocations = pResource->SurfCount;
2802 for (UINT i = 0; i < pResource->SurfCount; ++i)
2803 {
2804 PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[i];
2805 CONST D3DDDI_SURFACEINFO* pSurf = &pResource->pSurfList[i];
2806 pAllocation->hAllocation = NULL;
2807 pAllocation->enmType = VBOXWDDM_ALLOC_TYPE_UMD_RC_GENERIC;
2808 pAllocation->pvMem = (void*)pSurf->pSysMem;
2809 pAllocation->SurfDesc.pitch = pSurf->SysMemPitch;
2810 pAllocation->SurfDesc.slicePitch = pSurf->SysMemSlicePitch;
2811 pAllocation->SurfDesc.depth = pSurf->Depth;
2812 pAllocation->SurfDesc.width = pSurf->Width;
2813 pAllocation->SurfDesc.height = pSurf->Height;
2814 pAllocation->SurfDesc.format = pResource->Format;
2815 }
2816
2817 if (VBOXDISPMODE_IS_3D(pAdapter))
2818 {
2819 if (pResource->Flags.SharedResource)
2820 {
2821 AssertBreakpoint(); /* <-- need to test that */
2822 bIssueCreateResource = true;
2823 }
2824
2825 if (pResource->Flags.ZBuffer)
2826 {
2827 Assert(pDevice->pDevice9If);
2828 for (UINT i = 0; i < pResource->SurfCount; ++i)
2829 {
2830 PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[i];
2831 IDirect3DSurface9 *pD3D9Surf;
2832 hr = pDevice->pDevice9If->CreateDepthStencilSurface(pAllocation->SurfDesc.width,
2833 pAllocation->SurfDesc.height,
2834 vboxDDI2D3DFormat(pResource->Format),
2835 vboxDDI2D3DMultiSampleType(pResource->MultisampleType),
2836 pResource->MultisampleQuality,
2837 TRUE /* @todo: BOOL Discard */,
2838 &pD3D9Surf,
2839 NULL /*HANDLE* pSharedHandle*/);
2840 Assert(hr == S_OK);
2841 if (hr == S_OK)
2842 {
2843 Assert(pD3D9Surf);
2844 if (pResource->Pool == D3DDDIPOOL_SYSTEMMEM)
2845 {
2846 Assert(pAllocation->pvMem);
2847 D3DLOCKED_RECT lockInfo;
2848 hr = pD3D9Surf->LockRect(&lockInfo, NULL, D3DLOCK_DISCARD);
2849 Assert(hr == S_OK);
2850 if (hr == S_OK)
2851 {
2852 vboxWddmLockUnlockMemSynch(pAllocation, &lockInfo, NULL, true /*bool bToLockInfo*/);
2853 HRESULT tmpHr = pD3D9Surf->UnlockRect();
2854 Assert(tmpHr == S_OK);
2855 }
2856 }
2857 else
2858 {
2859 Assert(!pAllocation->pvMem);
2860 }
2861 pAllocation->pD3DIf = pD3D9Surf;
2862 }
2863 else
2864 {
2865 for (UINT j = 0; j < i; ++j)
2866 {
2867 pRc->aAllocations[j].pD3DIf->Release();
2868 }
2869 break;
2870 }
2871 }
2872 }
2873 else if (pResource->Flags.VertexBuffer)
2874 {
2875 Assert(pDevice->pDevice9If);
2876 for (UINT i = 0; i < pResource->SurfCount; ++i)
2877 {
2878 PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[i];
2879 IDirect3DVertexBuffer9 *pD3D9VBuf;
2880 hr = pDevice->pDevice9If->CreateVertexBuffer(pAllocation->SurfDesc.width,
2881 vboxDDI2D3DUsage(pResource->Flags),
2882 pResource->Fvf,
2883 vboxDDI2D3DPool(pResource->Pool),
2884 &pD3D9VBuf,
2885 NULL /*HANDLE* pSharedHandle*/);
2886 Assert(hr == S_OK);
2887 if (hr == S_OK)
2888 {
2889 Assert(pD3D9VBuf);
2890 if (pResource->Pool == D3DDDIPOOL_SYSTEMMEM)
2891 {
2892 Assert(pAllocation->pvMem);
2893 D3DLOCKED_RECT lockInfo;
2894 hr = pD3D9VBuf->Lock(0, pAllocation->SurfDesc.width, &lockInfo.pBits, D3DLOCK_DISCARD);
2895 Assert(hr == S_OK);
2896 if (hr == S_OK)
2897 {
2898 lockInfo.Pitch = pAllocation->SurfDesc.pitch;
2899 vboxWddmLockUnlockMemSynch(pAllocation, &lockInfo, NULL, true /*bool bToLockInfo*/);
2900 HRESULT tmpHr = pD3D9VBuf->Unlock();
2901 Assert(tmpHr == S_OK);
2902 }
2903 }
2904 else
2905 {
2906 Assert(!pAllocation->pvMem);
2907 }
2908 pAllocation->pD3DIf = pD3D9VBuf;
2909 }
2910 else
2911 {
2912 for (UINT j = 0; j < i; ++j)
2913 {
2914 pRc->aAllocations[j].pD3DIf->Release();
2915 }
2916 break;
2917 }
2918 }
2919 }
2920 else if (pResource->Flags.IndexBuffer)
2921 {
2922 Assert(pDevice->pDevice9If);
2923 for (UINT i = 0; i < pResource->SurfCount; ++i)
2924 {
2925 PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[i];
2926 CONST D3DDDI_SURFACEINFO* pSurf = &pResource->pSurfList[i];
2927 IDirect3DIndexBuffer9 *pD3D9IBuf;
2928 hr = pDevice->pDevice9If->CreateIndexBuffer(pSurf->Width,
2929 vboxDDI2D3DUsage(pResource->Flags),
2930 vboxDDI2D3DFormat(pResource->Format),
2931 vboxDDI2D3DPool(pResource->Pool),
2932 &pD3D9IBuf,
2933 NULL /*HANDLE* pSharedHandle*/
2934 );
2935 Assert(hr == S_OK);
2936 if (hr == S_OK)
2937 {
2938 Assert(pD3D9IBuf);
2939 if (pResource->Pool == D3DDDIPOOL_SYSTEMMEM)
2940 {
2941 Assert(pAllocation->pvMem);
2942 D3DLOCKED_RECT lockInfo;
2943 hr = pD3D9IBuf->Lock(0, pAllocation->SurfDesc.width, &lockInfo.pBits, D3DLOCK_DISCARD);
2944 Assert(hr == S_OK);
2945 if (hr == S_OK)
2946 {
2947 lockInfo.Pitch = pAllocation->SurfDesc.pitch;
2948 vboxWddmLockUnlockMemSynch(pAllocation, &lockInfo, NULL, true /*bool bToLockInfo*/);
2949 HRESULT tmpHr = pD3D9IBuf->Unlock();
2950 Assert(tmpHr == S_OK);
2951 }
2952 }
2953 else
2954 {
2955 Assert(!pAllocation->pvMem);
2956 }
2957 pAllocation->pD3DIf = pD3D9IBuf;
2958 }
2959 else
2960 {
2961 for (UINT j = 0; j < i; ++j)
2962 {
2963 pRc->aAllocations[j].pD3DIf->Release();
2964 }
2965 break;
2966 }
2967 }
2968 }
2969 else if (pResource->Flags.Texture || pResource->Flags.Value == 0)
2970 {
2971 Assert(pDevice->pDevice9If);
2972#ifdef DEBUG
2973 {
2974 uint32_t tstW = pResource->pSurfList[0].Width;
2975 uint32_t tstH = pResource->pSurfList[0].Height;
2976 for (UINT i = 1; i < pResource->SurfCount; ++i)
2977 {
2978 tstW /= 2;
2979 tstH /= 2;
2980 CONST D3DDDI_SURFACEINFO* pSurf = &pResource->pSurfList[i];
2981 Assert(pSurf->Width == tstW);
2982 Assert(pSurf->Height == tstH);
2983 }
2984 }
2985#endif
2986
2987 PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[0];
2988 CONST D3DDDI_SURFACEINFO* pSurf = &pResource->pSurfList[0];
2989 IDirect3DTexture9 *pD3DIfTex;
2990 hr = pDevice->pDevice9If->CreateTexture(pSurf->Width,
2991 pSurf->Height,
2992 pResource->SurfCount,
2993 vboxDDI2D3DUsage(pResource->Flags),
2994 vboxDDI2D3DFormat(pResource->Format),
2995 vboxDDI2D3DPool(pResource->Pool),
2996 &pD3DIfTex,
2997 NULL /* HANDLE* pSharedHandle */
2998 );
2999 Assert(hr == S_OK);
3000 if (hr == S_OK)
3001 {
3002 Assert(pD3DIfTex);
3003 if (pResource->Pool == D3DDDIPOOL_SYSTEMMEM)
3004 {
3005 for (UINT i = 0; i < pResource->SurfCount; ++i)
3006 {
3007 D3DLOCKED_RECT lockInfo;
3008 PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[i];
3009 Assert(pAllocation->pvMem);
3010 hr = pD3DIfTex->LockRect(i, &lockInfo, NULL, D3DLOCK_DISCARD);
3011 Assert(hr == S_OK);
3012 if (hr == S_OK)
3013 {
3014 vboxWddmLockUnlockMemSynch(pAllocation, &lockInfo, NULL, true /*bool bToLockInfo*/);
3015 HRESULT tmpHr = pD3DIfTex->UnlockRect(i);
3016 Assert(tmpHr == S_OK);
3017 }
3018 else
3019 {
3020 pD3DIfTex->Release();
3021 break;
3022 }
3023 }
3024 }
3025 pAllocation->pD3DIf = pD3DIfTex;
3026 }
3027#ifdef DEBUG
3028 else
3029 {
3030 for (UINT i = 0; i < pResource->SurfCount; ++i)
3031 {
3032 PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[i];
3033 Assert(!pAllocation->pvMem);
3034 }
3035 }
3036#endif
3037 }
3038 else if (pResource->Flags.RenderTarget)
3039 {
3040 HWND hWnd = NULL;
3041 bool bDevCreated = false;
3042 Assert(pResource->SurfCount);
3043 if (!pDevice->pDevice9If)
3044 {
3045 Assert(!pDevice->hWnd);
3046 hr = VBoxDispWndCreate(pAdapter, pResource->pSurfList[0].Width, pResource->pSurfList[0].Height, &hWnd);
3047 Assert(hr == S_OK);
3048 if (hr == S_OK)
3049 {
3050 DWORD fFlags = D3DCREATE_HARDWARE_VERTEXPROCESSING;
3051 if (pDevice->fFlags.AllowMultithreading)
3052 fFlags |= D3DCREATE_MULTITHREADED;
3053
3054 IDirect3DDevice9 *pDevice9If = NULL;
3055 D3DPRESENT_PARAMETERS params;
3056 memset(&params, 0, sizeof (params));
3057 // params.BackBufferWidth = 0;
3058 // params.BackBufferHeight = 0;
3059 params.BackBufferFormat = vboxDDI2D3DFormat(pResource->Format);
3060 Assert(pResource->SurfCount);
3061 params.BackBufferCount = pResource->SurfCount - 1;
3062 params.MultiSampleType = vboxDDI2D3DMultiSampleType(pResource->MultisampleType);
3063 if (pResource->Flags.DiscardRenderTarget)
3064 params.SwapEffect = D3DSWAPEFFECT_DISCARD;
3065 params.hDeviceWindow = hWnd;
3066 /* @todo: it seems there should be a way to detect this correctly since
3067 * our vboxWddmDDevSetDisplayMode will be called in case we are using full-screen */
3068 params.Windowed = TRUE;
3069 // params.EnableAutoDepthStencil = FALSE;
3070 // params.AutoDepthStencilFormat = D3DFMT_UNKNOWN;
3071 // params.Flags;
3072 // params.FullScreen_RefreshRateInHz;
3073 // params.FullScreen_PresentationInterval;
3074 hr = pAdapter->pD3D9If->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, fFlags, &params, &pDevice9If);
3075 Assert(hr == S_OK);
3076 if (hr == S_OK)
3077 {
3078 pDevice->pDevice9If = pDevice9If;
3079 pDevice->hWnd = hWnd;
3080 bDevCreated = true;
3081 }
3082 }
3083 }
3084 else
3085 {
3086 Assert(pDevice->hWnd);
3087
3088 }
3089
3090 if (hr == S_OK)
3091 {
3092 Assert(pDevice->pDevice9If);
3093 bIssueCreateResource = true;
3094 for (UINT i = 0; i < pResource->SurfCount; ++i)
3095 {
3096 PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[i];
3097
3098 IDirect3DSurface9* pD3D9Surf;
3099 hr = pDevice->pDevice9If->CreateRenderTarget(pAllocation->SurfDesc.width,
3100 pAllocation->SurfDesc.height,
3101 vboxDDI2D3DFormat(pResource->Format),
3102 vboxDDI2D3DMultiSampleType(pResource->MultisampleType),
3103 pResource->MultisampleQuality,
3104 !pResource->Flags.NotLockable /* BOOL Lockable */,
3105 &pD3D9Surf,
3106 NULL /* HANDLE* pSharedHandle */
3107 );
3108 Assert(hr == S_OK);
3109 if (hr == S_OK)
3110 {
3111 Assert(pD3D9Surf);
3112 if (pResource->Pool == D3DDDIPOOL_SYSTEMMEM)
3113 {
3114 Assert(pAllocation->pvMem);
3115 D3DLOCKED_RECT lockInfo;
3116 hr = pD3D9Surf->LockRect(&lockInfo, NULL, D3DLOCK_DISCARD);
3117 Assert(hr == S_OK);
3118 if (hr == S_OK)
3119 {
3120 vboxWddmLockUnlockMemSynch(pAllocation, &lockInfo, NULL, true /*bool bToLockInfo*/);
3121 HRESULT tmpHr = pD3D9Surf->UnlockRect();
3122 Assert(tmpHr == S_OK);
3123 }
3124 }
3125 else
3126 {
3127 Assert(!pAllocation->pvMem);
3128 }
3129 pAllocation->pD3DIf = pD3D9Surf;
3130 }
3131 else
3132 {
3133 for (UINT j = 0; j < i; ++j)
3134 {
3135 pRc->aAllocations[j].pD3DIf->Release();
3136 }
3137 break;
3138 }
3139 }
3140 }
3141
3142 if (hr != S_OK)
3143 {
3144 if (bDevCreated)
3145 {
3146 VBoxDispWndDestroy(pAdapter, hWnd);
3147 pDevice->pDevice9If->Release();
3148 }
3149 }
3150 }
3151 else
3152 {
3153 Assert(pDevice->pDevice9If);
3154 Assert(0);
3155 }
3156 }
3157 else
3158 bIssueCreateResource = true;
3159
3160
3161 if (hr == S_OK && bIssueCreateResource)
3162 {
3163 D3DDDICB_ALLOCATE *pDdiAllocate = vboxWddmRequestAllocAlloc(pResource);
3164 Assert(pDdiAllocate);
3165 if (pDdiAllocate)
3166 {
3167 Assert(pDdiAllocate->pPrivateDriverData);
3168 Assert(pDdiAllocate->PrivateDriverDataSize == sizeof (VBOXWDDM_RCINFO));
3169 PVBOXWDDM_RCINFO pRcInfo = (PVBOXWDDM_RCINFO)pDdiAllocate->pPrivateDriverData;
3170 pRcInfo->fFlags = VBOXWDDM_RESOURCE_F_TYPE_GENERIC;
3171 pRcInfo->RcDesc = pRc->RcDesc;
3172 pRcInfo->cAllocInfos = pResource->SurfCount;
3173
3174 for (UINT i = 0; i < pResource->SurfCount; ++i)
3175 {
3176 D3DDDI_ALLOCATIONINFO *pDdiAllocI = &pDdiAllocate->pAllocationInfo[i];
3177 Assert(pDdiAllocI->pPrivateDriverData);
3178 Assert(pDdiAllocI->PrivateDriverDataSize == sizeof (VBOXWDDM_ALLOCINFO));
3179 PVBOXWDDM_ALLOCINFO pAllocInfo = (PVBOXWDDM_ALLOCINFO)pDdiAllocI->pPrivateDriverData;
3180 CONST D3DDDI_SURFACEINFO* pSurf = &pResource->pSurfList[i];
3181 pDdiAllocI->hAllocation = NULL;
3182 pDdiAllocI->pSystemMem = pSurf->pSysMem;
3183 Assert((!!(pSurf->pSysMem)) == (pResource->Pool == D3DDDIPOOL_SYSTEMMEM));
3184 pDdiAllocI->VidPnSourceId = pResource->VidPnSourceId;
3185 pDdiAllocI->Flags.Value = 0;
3186 if (pResource->Flags.Primary)
3187 {
3188 Assert(pResource->Flags.RenderTarget);
3189 pDdiAllocI->Flags.Primary = 1;
3190 }
3191
3192 pAllocInfo->enmType = VBOXWDDM_ALLOC_TYPE_UMD_RC_GENERIC;
3193 pAllocInfo->fFlags = pResource->Flags;
3194 pAllocInfo->SurfDesc.width = pSurf->Width;
3195 pAllocInfo->SurfDesc.height = pSurf->Height;
3196 pAllocInfo->SurfDesc.format = pResource->Format;
3197 if (!vboxWddmFormatToFourcc(pResource->Format))
3198 pAllocInfo->SurfDesc.bpp = vboxWddmCalcBitsPerPixel(pResource->Format);
3199 else
3200 pAllocInfo->SurfDesc.bpp = 0;
3201
3202 if (pSurf->SysMemPitch)
3203 {
3204 pAllocInfo->SurfDesc.pitch = pSurf->SysMemPitch;
3205#ifdef DEBUG
3206 UINT tst = vboxWddmCalcPitch(pSurf->Width, pAllocInfo->SurfDesc.bpp);
3207 Assert(tst == pSurf->SysMemPitch);
3208#endif
3209 }
3210 else
3211 pAllocInfo->SurfDesc.pitch = vboxWddmCalcPitch(pSurf->Width, pAllocInfo->SurfDesc.bpp);
3212
3213 pAllocInfo->SurfDesc.cbSize = pAllocInfo->SurfDesc.pitch * pAllocInfo->SurfDesc.height;
3214 pAllocInfo->SurfDesc.depth = pSurf->Depth;
3215 pAllocInfo->SurfDesc.slicePitch = pSurf->SysMemSlicePitch;
3216 pAllocInfo->SurfDesc.VidPnSourceId = pResource->VidPnSourceId;
3217 pAllocInfo->SurfDesc.RefreshRate = pResource->RefreshRate;
3218 }
3219
3220 hr = pDevice->RtCallbacks.pfnAllocateCb(pDevice->hDevice, pDdiAllocate);
3221 Assert(hr == S_OK);
3222 Assert(pDdiAllocate->hKMResource);
3223 if (hr == S_OK)
3224 {
3225 pRc->hKMResource = pDdiAllocate->hKMResource;
3226
3227 for (UINT i = 0; i < pResource->SurfCount; ++i)
3228 {
3229 PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[i];
3230 D3DDDI_ALLOCATIONINFO *pDdiAllocI = &pDdiAllocate->pAllocationInfo[i];
3231 PVBOXWDDM_ALLOCINFO pAllocInfo = (PVBOXWDDM_ALLOCINFO)pDdiAllocI->pPrivateDriverData;
3232 CONST D3DDDI_SURFACEINFO* pSurf = &pResource->pSurfList[i];
3233 pAllocation->hAllocation = pDdiAllocI->hAllocation;
3234 pAllocation->enmType = VBOXWDDM_ALLOC_TYPE_UMD_RC_GENERIC;
3235 pAllocation->pvMem = (void*)pSurf->pSysMem;
3236 pAllocation->SurfDesc = pAllocInfo->SurfDesc;
3237 }
3238 }
3239
3240 vboxWddmRequestAllocFree(pDdiAllocate);
3241 }
3242 else
3243 {
3244 hr = E_OUTOFMEMORY;
3245 }
3246
3247 if (hr == S_OK)
3248 pResource->hResource = pRc;
3249 else
3250 vboxResourceFree(pRc);
3251 }
3252
3253 if (hr == S_OK)
3254 pResource->hResource = pRc;
3255 else
3256 vboxResourceFree(pRc);
3257 }
3258 else
3259 {
3260 hr = E_OUTOFMEMORY;
3261 }
3262
3263
3264 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3265 return hr;
3266}
3267
3268static HRESULT APIENTRY vboxWddmDDevDestroyResource(HANDLE hDevice, HANDLE hResource)
3269{
3270 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3271 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
3272 PVBOXWDDMDISP_ADAPTER pAdapter = pDevice->pAdapter;
3273 PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)hResource;
3274
3275 HRESULT hr = S_OK;
3276
3277 Assert(pDevice);
3278 Assert(hResource);
3279
3280 if (VBOXDISPMODE_IS_3D(pAdapter))
3281 {
3282 if (pRc->RcDesc.fFlags.RenderTarget)
3283 {
3284 Assert(pDevice->hWnd);
3285 Assert(pDevice->pDevice9If);
3286 }
3287
3288 for (UINT i = 0; i < pRc->cAllocations; ++i)
3289 {
3290 PVBOXWDDMDISP_ALLOCATION pAlloc = &pRc->aAllocations[i];
3291 if (pAlloc->pD3DIf)
3292 pAlloc->pD3DIf->Release();
3293 }
3294 }
3295
3296 Assert(pRc->hResource);
3297 Assert(pRc->hKMResource || VBOXDISPMODE_IS_3D(pAdapter));
3298 if (pRc->hKMResource)
3299 {
3300 if (!(pRc->fFlags & VBOXWDDM_RESOURCE_F_OPENNED))
3301 {
3302 D3DDDICB_DEALLOCATE Dealloc;
3303 Dealloc.hResource = pRc->hResource;
3304 /* according to the docs the below two are ignored in case we set the hResource */
3305 Dealloc.NumAllocations = 0;
3306 Dealloc.HandleList = NULL;
3307 hr = pDevice->RtCallbacks.pfnDeallocateCb(pDevice->hDevice, &Dealloc);
3308 Assert(hr == S_OK);
3309// for (UINT j = 0; j < pRc->cAllocations; ++j)
3310// {
3311// D3DDDICB_DEALLOCATE Dealloc;
3312// Dealloc.hResource = NULL;
3313// Dealloc.NumAllocations = 1;
3314// Dealloc.HandleList = &pRc->aAllocations[j].hAllocation;
3315// HRESULT tmpHr = pDevice->RtCallbacks.pfnDeallocateCb(pDevice->hDevice, &Dealloc);
3316// Assert(tmpHr = S_OK);
3317// }
3318 }
3319 }
3320
3321 vboxResourceFree(pRc);
3322 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3323 return hr;
3324}
3325static HRESULT APIENTRY vboxWddmDDevSetDisplayMode(HANDLE hDevice, CONST D3DDDIARG_SETDISPLAYMODE* pData)
3326{
3327 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3328 HRESULT hr = S_OK;
3329 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
3330 Assert(pDevice);
3331 Assert(VBOXDISPMODE_IS_3D(pDevice->pAdapter));
3332 PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)pData->hResource;
3333 Assert(pRc);
3334 Assert(pRc->cAllocations > pData->SubResourceIndex);
3335 PVBOXWDDMDISP_ALLOCATION pAlloc = &pRc->aAllocations[pData->SubResourceIndex];
3336 Assert(pRc->RcDesc.fFlags.RenderTarget);
3337 Assert(pAlloc->hAllocation);
3338 D3DDDICB_SETDISPLAYMODE DdiDm = {0};
3339 DdiDm.hPrimaryAllocation = pAlloc->hAllocation;
3340// DdiDm.PrivateDriverFormatAttribute = 0;
3341 hr = pDevice->RtCallbacks.pfnSetDisplayModeCb(pDevice->hDevice, &DdiDm);
3342 Assert(hr == S_OK);
3343
3344 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3345 return hr;
3346}
3347static HRESULT APIENTRY vboxWddmDDevPresent(HANDLE hDevice, CONST D3DDDIARG_PRESENT* pData)
3348{
3349 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3350 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
3351 Assert(pDevice);
3352 HRESULT hr = S_OK;
3353 if (VBOXDISPMODE_IS_3D(pDevice->pAdapter))
3354 {
3355 Assert(pDevice->pDevice9If);
3356#if 0
3357 hr = pDevice->pDevice9If->Present(NULL, /* CONST RECT * pSourceRect */
3358 NULL, /* CONST RECT * pDestRect */
3359 NULL, /* HWND hDestWindowOverride */
3360 NULL /*CONST RGNDATA * pDirtyRegion */
3361 );
3362 Assert(hr == S_OK);
3363#endif
3364 }
3365#if 0
3366 else
3367#endif
3368 {
3369 D3DDDICB_PRESENT DdiPresent = {0};
3370 if (pData->hSrcResource)
3371 {
3372 PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)pData->hSrcResource;
3373 Assert(pRc->hKMResource);
3374 Assert(pRc->cAllocations > pData->SrcSubResourceIndex);
3375 PVBOXWDDMDISP_ALLOCATION pAlloc = &pRc->aAllocations[pData->SrcSubResourceIndex];
3376 Assert(pAlloc->hAllocation);
3377 DdiPresent.hSrcAllocation = pAlloc->hAllocation;
3378 }
3379 if (pData->hDstResource)
3380 {
3381 PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)pData->hDstResource;
3382 Assert(pRc->hKMResource);
3383 Assert(pRc->cAllocations > pData->DstSubResourceIndex);
3384 PVBOXWDDMDISP_ALLOCATION pAlloc = &pRc->aAllocations[pData->DstSubResourceIndex];
3385 Assert(pAlloc->hAllocation);
3386 DdiPresent.hDstAllocation = pAlloc->hAllocation;
3387 }
3388 DdiPresent.hContext = pDevice->DefaultContext.ContextInfo.hContext;
3389// DdiPresent.BroadcastContextCount;
3390// DdiPresent.BroadcastContext[D3DDDI_MAX_BROADCAST_CONTEXT];
3391
3392 hr = pDevice->RtCallbacks.pfnPresentCb(pDevice->hDevice, &DdiPresent);
3393 Assert(hr == S_OK);
3394 }
3395 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
3396 return hr;
3397}
3398static HRESULT APIENTRY vboxWddmDDevFlush(HANDLE hDevice)
3399{
3400 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3401 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
3402 Assert(pDevice);
3403 HRESULT hr = S_OK;
3404 if (VBOXDISPMODE_IS_3D(pDevice->pAdapter))
3405 {
3406 Assert(pDevice->pDevice9If);
3407 hr = pDevice->pDevice9If->Present(NULL, /* CONST RECT * pSourceRect */
3408 NULL, /* CONST RECT * pDestRect */
3409 NULL, /* HWND hDestWindowOverride */
3410 NULL /*CONST RGNDATA * pDirtyRegion */
3411 );
3412 Assert(hr == S_OK);
3413 }
3414 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
3415 return hr;
3416}
3417
3418AssertCompile(sizeof (D3DDDIVERTEXELEMENT) == sizeof (D3DVERTEXELEMENT9));
3419AssertCompile(RT_SIZEOFMEMB(D3DDDIVERTEXELEMENT, Stream) == RT_SIZEOFMEMB(D3DVERTEXELEMENT9, Stream));
3420AssertCompile(RT_SIZEOFMEMB(D3DDDIVERTEXELEMENT, Offset) == RT_SIZEOFMEMB(D3DVERTEXELEMENT9, Offset));
3421AssertCompile(RT_SIZEOFMEMB(D3DDDIVERTEXELEMENT, Type) == RT_SIZEOFMEMB(D3DVERTEXELEMENT9, Type));
3422AssertCompile(RT_SIZEOFMEMB(D3DDDIVERTEXELEMENT, Method) == RT_SIZEOFMEMB(D3DVERTEXELEMENT9, Method));
3423AssertCompile(RT_SIZEOFMEMB(D3DDDIVERTEXELEMENT, Usage) == RT_SIZEOFMEMB(D3DVERTEXELEMENT9, Usage));
3424AssertCompile(RT_SIZEOFMEMB(D3DDDIVERTEXELEMENT, UsageIndex) == RT_SIZEOFMEMB(D3DVERTEXELEMENT9, UsageIndex));
3425
3426AssertCompile(RT_OFFSETOF(D3DDDIVERTEXELEMENT, Stream) == RT_OFFSETOF(D3DVERTEXELEMENT9, Stream));
3427AssertCompile(RT_OFFSETOF(D3DDDIVERTEXELEMENT, Offset) == RT_OFFSETOF(D3DVERTEXELEMENT9, Offset));
3428AssertCompile(RT_OFFSETOF(D3DDDIVERTEXELEMENT, Type) == RT_OFFSETOF(D3DVERTEXELEMENT9, Type));
3429AssertCompile(RT_OFFSETOF(D3DDDIVERTEXELEMENT, Method) == RT_OFFSETOF(D3DVERTEXELEMENT9, Method));
3430AssertCompile(RT_OFFSETOF(D3DDDIVERTEXELEMENT, Usage) == RT_OFFSETOF(D3DVERTEXELEMENT9, Usage));
3431AssertCompile(RT_OFFSETOF(D3DDDIVERTEXELEMENT, UsageIndex) == RT_OFFSETOF(D3DVERTEXELEMENT9, UsageIndex));
3432
3433static HRESULT APIENTRY vboxWddmDDevCreateVertexShaderDecl(HANDLE hDevice, D3DDDIARG_CREATEVERTEXSHADERDECL* pData, CONST D3DDDIVERTEXELEMENT* pVertexElements)
3434{
3435 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3436 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
3437 Assert(pDevice);
3438 Assert(pDevice->pDevice9If);
3439 IDirect3DVertexDeclaration9 *pDecl;
3440 static D3DVERTEXELEMENT9 DeclEnd = D3DDECL_END();
3441 Assert(!memcmp(&DeclEnd, &pVertexElements[pData->NumVertexElements], sizeof (DeclEnd)));
3442 HRESULT hr = pDevice->pDevice9If->CreateVertexDeclaration(
3443 (CONST D3DVERTEXELEMENT9*)pVertexElements,
3444 &pDecl
3445 );
3446 Assert(hr == S_OK);
3447 if (hr == S_OK)
3448 {
3449 Assert(pDecl);
3450 pData->ShaderHandle = pDecl;
3451 }
3452 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
3453 return hr;
3454}
3455static HRESULT APIENTRY vboxWddmDDevSetVertexShaderDecl(HANDLE hDevice, HANDLE hShaderHandle)
3456{
3457 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3458 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
3459 Assert(pDevice);
3460 Assert(pDevice->pDevice9If);
3461 IDirect3DVertexDeclaration9 *pDecl = (IDirect3DVertexDeclaration9*)hShaderHandle;
3462 Assert(pDecl);
3463 HRESULT hr = pDevice->pDevice9If->SetVertexDeclaration(pDecl);
3464 Assert(hr == S_OK);
3465 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
3466 return hr;
3467}
3468static HRESULT APIENTRY vboxWddmDDevDeleteVertexShaderDecl(HANDLE hDevice, HANDLE hShaderHandle)
3469{
3470 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3471 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
3472 Assert(pDevice);
3473 Assert(pDevice->pDevice9If);
3474 IDirect3DVertexDeclaration9 *pDecl = (IDirect3DVertexDeclaration9*)hShaderHandle;
3475 HRESULT hr = pDecl->Release();
3476 Assert(hr == S_OK);
3477 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
3478 return hr;
3479}
3480static HRESULT APIENTRY vboxWddmDDevCreateVertexShaderFunc(HANDLE hDevice, D3DDDIARG_CREATEVERTEXSHADERFUNC* pData, CONST UINT* pCode)
3481{
3482 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3483 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
3484 Assert(pDevice);
3485 Assert(pDevice->pDevice9If);
3486 IDirect3DVertexShader9 *pShader;
3487 Assert(*((UINT*)((uint8_t*)pCode + pData->Size-4)) == 0x0000FFFF /* end token */);
3488 HRESULT hr = pDevice->pDevice9If->CreateVertexShader((const DWORD *)pCode, &pShader);
3489 Assert(hr == S_OK);
3490 if (hr == S_OK)
3491 {
3492 Assert(pShader);
3493 pData->ShaderHandle = pShader;
3494 }
3495 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
3496 return hr;
3497}
3498static HRESULT APIENTRY vboxWddmDDevSetVertexShaderFunc(HANDLE hDevice, HANDLE hShaderHandle)
3499{
3500 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3501 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
3502 Assert(pDevice);
3503 Assert(pDevice->pDevice9If);
3504 IDirect3DVertexShader9 *pShader = (IDirect3DVertexShader9*)hShaderHandle;
3505 Assert(pShader);
3506 HRESULT hr = pDevice->pDevice9If->SetVertexShader(pShader);
3507 Assert(hr == S_OK);
3508 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
3509 return hr;
3510}
3511static HRESULT APIENTRY vboxWddmDDevDeleteVertexShaderFunc(HANDLE hDevice, HANDLE hShaderHandle)
3512{
3513 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3514 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
3515 Assert(pDevice);
3516 Assert(pDevice->pDevice9If);
3517 IDirect3DVertexShader9 *pShader = (IDirect3DVertexShader9*)hShaderHandle;
3518 HRESULT hr = pShader->Release();
3519 Assert(hr == S_OK);
3520 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
3521 return hr;
3522}
3523static HRESULT APIENTRY vboxWddmDDevSetVertexShaderConstI(HANDLE hDevice, CONST D3DDDIARG_SETVERTEXSHADERCONSTI* pData, CONST INT* pRegisters)
3524{
3525 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3526 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
3527 Assert(pDevice);
3528 Assert(pDevice->pDevice9If);
3529 HRESULT hr = pDevice->pDevice9If->SetVertexShaderConstantI(pData->Register, pRegisters, pData->Count);
3530 Assert(hr == S_OK);
3531 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
3532 return hr;
3533}
3534static HRESULT APIENTRY vboxWddmDDevSetVertexShaderConstB(HANDLE hDevice, CONST D3DDDIARG_SETVERTEXSHADERCONSTB* pData, CONST BOOL* pRegisters)
3535{
3536 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3537 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
3538 Assert(pDevice);
3539 Assert(pDevice->pDevice9If);
3540 HRESULT hr = pDevice->pDevice9If->SetVertexShaderConstantB(pData->Register, pRegisters, pData->Count);
3541 Assert(hr == S_OK);
3542 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
3543 return hr;
3544}
3545static HRESULT APIENTRY vboxWddmDDevSetScissorRect(HANDLE hDevice, CONST RECT* pRect)
3546{
3547 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3548 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
3549 Assert(pDevice);
3550 Assert(pDevice->pDevice9If);
3551 HRESULT hr = pDevice->pDevice9If->SetScissorRect(pRect);
3552 Assert(hr == S_OK);
3553 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
3554 return hr;
3555}
3556static HRESULT APIENTRY vboxWddmDDevSetStreamSource(HANDLE hDevice, CONST D3DDDIARG_SETSTREAMSOURCE* pData)
3557{
3558 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3559 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
3560 Assert(pDevice);
3561 Assert(pDevice->pDevice9If);
3562 PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)pData->hVertexBuffer;
3563 PVBOXWDDMDISP_ALLOCATION pAlloc = NULL;
3564 IDirect3DVertexBuffer9 *pStreamData = NULL;
3565 if (pRc)
3566 {
3567 Assert(pRc->cAllocations == 1);
3568 pAlloc = &pRc->aAllocations[0];
3569 Assert(pAlloc->pD3DIf);
3570 pStreamData = (IDirect3DVertexBuffer9*)pAlloc->pD3DIf;
3571 }
3572 HRESULT hr = pDevice->pDevice9If->SetStreamSource(pData->Stream, pStreamData, pData->Offset, pData->Stride);
3573 Assert(hr == S_OK);
3574 Assert(pData->Stream<VBOXWDDMDISP_MAX_VERTEX_STREAMS);
3575 if (hr == S_OK)
3576 {
3577 if (pDevice->aStreamSource[pData->Stream] && !pAlloc)
3578 {
3579 --pDevice->cStreamSources;
3580 Assert(pDevice->cStreamSources < UINT32_MAX/2);
3581 }
3582 else if (!pDevice->aStreamSource[pData->Stream] && pAlloc)
3583 {
3584 ++pDevice->cStreamSources;
3585 Assert(pDevice->cStreamSources <= RT_ELEMENTS(pDevice->aStreamSource));
3586 }
3587 pDevice->aStreamSource[pData->Stream] = pAlloc;
3588 pDevice->StreamSourceInfo[pData->Stream].uiOffset = pData->Offset;
3589 pDevice->StreamSourceInfo[pData->Stream].uiStride = pData->Stride;
3590 }
3591 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
3592 return hr;
3593}
3594static HRESULT APIENTRY vboxWddmDDevSetStreamSourceFreq(HANDLE hDevice, CONST D3DDDIARG_SETSTREAMSOURCEFREQ* pData)
3595{
3596 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3597 AssertBreakpoint();
3598 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3599 return E_FAIL;
3600}
3601static HRESULT APIENTRY vboxWddmDDevSetConvolutionKernelMono(HANDLE hDevice, CONST D3DDDIARG_SETCONVOLUTIONKERNELMONO* pData)
3602{
3603 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3604 AssertBreakpoint();
3605 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3606 return E_FAIL;
3607}
3608static HRESULT APIENTRY vboxWddmDDevComposeRects(HANDLE hDevice, CONST D3DDDIARG_COMPOSERECTS* pData)
3609{
3610 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3611 AssertBreakpoint();
3612 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3613 return E_FAIL;
3614}
3615static HRESULT APIENTRY vboxWddmDDevBlt(HANDLE hDevice, CONST D3DDDIARG_BLT* pData)
3616{
3617 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3618 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
3619 Assert(pDevice);
3620 Assert(pDevice->pDevice9If);
3621 PVBOXWDDMDISP_RESOURCE pDstRc = (PVBOXWDDMDISP_RESOURCE)pData->hDstResource;
3622 PVBOXWDDMDISP_RESOURCE pSrcRc = (PVBOXWDDMDISP_RESOURCE)pData->hSrcResource;
3623 HRESULT hr = S_OK;
3624 if ((pDstRc->RcDesc.fFlags.Texture || pDstRc->RcDesc.fFlags.Value == 0)
3625 && (pSrcRc->RcDesc.fFlags.Texture || pSrcRc->RcDesc.fFlags.Value == 0))
3626 {
3627 IDirect3DTexture9 *pD3DIfSrcTex = (IDirect3DTexture9*)pSrcRc->aAllocations[0].pD3DIf;
3628 IDirect3DTexture9 *pD3DIfDstTex = (IDirect3DTexture9*)pDstRc->aAllocations[0].pD3DIf;
3629 Assert(pD3DIfSrcTex);
3630 Assert(pD3DIfDstTex);
3631
3632 if (pSrcRc->aAllocations[0].SurfDesc.width == pDstRc->aAllocations[0].SurfDesc.width
3633 && pSrcRc->aAllocations[0].SurfDesc.height == pDstRc->aAllocations[0].SurfDesc.height
3634 && pSrcRc->RcDesc.enmFormat == pDstRc->RcDesc.enmFormat)
3635 {
3636 /* first check if we can do IDirect3DDevice9::UpdateTexture */
3637 if (pData->DstRect.left == 0 && pData->DstRect.top == 0
3638 && pData->SrcRect.left == 0 && pData->SrcRect.top == 0
3639 && pData->SrcRect.right - pData->SrcRect.left == pSrcRc->aAllocations[0].SurfDesc.width
3640 && pData->SrcRect.bottom - pData->SrcRect.top == pSrcRc->aAllocations[0].SurfDesc.height
3641 && pData->DstRect.right - pData->DstRect.left == pDstRc->aAllocations[0].SurfDesc.width
3642 && pData->DstRect.bottom - pData->DstRect.top == pDstRc->aAllocations[0].SurfDesc.height
3643 )
3644 {
3645 hr = pDevice->pDevice9If->UpdateTexture(pD3DIfSrcTex, pD3DIfDstTex);
3646 Assert(hr == S_OK);
3647 }
3648 else
3649 {
3650 AssertBreakpoint();
3651 /* @todo: impl */
3652 }
3653 }
3654 else
3655 {
3656 AssertBreakpoint();
3657 /* @todo: impl */
3658 }
3659 }
3660 else
3661 {
3662 AssertBreakpoint();
3663 /* @todo: impl */
3664 }
3665
3666 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
3667 return hr;
3668}
3669static HRESULT APIENTRY vboxWddmDDevColorFill(HANDLE hDevice, CONST D3DDDIARG_COLORFILL* pData)
3670{
3671 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3672 AssertBreakpoint();
3673 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3674 return E_FAIL;
3675}
3676static HRESULT APIENTRY vboxWddmDDevDepthFill(HANDLE hDevice, CONST D3DDDIARG_DEPTHFILL* pData)
3677{
3678 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3679 AssertBreakpoint();
3680 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3681 return E_FAIL;
3682}
3683static HRESULT APIENTRY vboxWddmDDevCreateQuery(HANDLE hDevice, D3DDDIARG_CREATEQUERY* pData)
3684{
3685 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3686 AssertBreakpoint();
3687 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3688 return E_FAIL;
3689}
3690static HRESULT APIENTRY vboxWddmDDevDestroyQuery(HANDLE hDevice, HANDLE hQuery)
3691{
3692 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3693 AssertBreakpoint();
3694 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3695 return E_FAIL;
3696}
3697static HRESULT APIENTRY vboxWddmDDevIssueQuery(HANDLE hDevice, CONST D3DDDIARG_ISSUEQUERY* pData)
3698{
3699 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3700 AssertBreakpoint();
3701 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3702 return E_FAIL;
3703}
3704static HRESULT APIENTRY vboxWddmDDevGetQueryData(HANDLE hDevice, CONST D3DDDIARG_GETQUERYDATA* pData)
3705{
3706 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3707 AssertBreakpoint();
3708 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3709 return E_FAIL;
3710}
3711static HRESULT APIENTRY vboxWddmDDevSetRenderTarget(HANDLE hDevice, CONST D3DDDIARG_SETRENDERTARGET* pData)
3712{
3713 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3714 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
3715 Assert(pDevice);
3716 Assert(pDevice->pDevice9If);
3717 PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)pData->hRenderTarget;
3718 Assert(pRc);
3719 Assert(pData->SubResourceIndex < pRc->cAllocations);
3720 IDirect3DSurface9 *pD3D9Surf = (IDirect3DSurface9*)pRc->aAllocations[pData->SubResourceIndex].pD3DIf;
3721 Assert(pD3D9Surf);
3722 HRESULT hr = pDevice->pDevice9If->SetRenderTarget(pData->RenderTargetIndex, pD3D9Surf);
3723 Assert(hr == S_OK);
3724 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
3725 return hr;
3726}
3727static HRESULT APIENTRY vboxWddmDDevSetDepthStencil(HANDLE hDevice, CONST D3DDDIARG_SETDEPTHSTENCIL* pData)
3728{
3729 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3730 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
3731 Assert(pDevice);
3732 Assert(pDevice->pDevice9If);
3733 PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)pData->hZBuffer;
3734 IDirect3DSurface9 *pD3D9Surf = NULL;
3735 if (pRc)
3736 {
3737 Assert(pRc->cAllocations == 1);
3738 pD3D9Surf = (IDirect3DSurface9*)pRc->aAllocations[0].pD3DIf;
3739 Assert(pD3D9Surf);
3740 }
3741 HRESULT hr = pDevice->pDevice9If->SetDepthStencilSurface(pD3D9Surf);
3742 Assert(hr == S_OK);
3743 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
3744 return hr;
3745}
3746static HRESULT APIENTRY vboxWddmDDevGenerateMipSubLevels(HANDLE hDevice, CONST D3DDDIARG_GENERATEMIPSUBLEVELS* pData)
3747{
3748 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3749 AssertBreakpoint();
3750 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3751 return E_FAIL;
3752}
3753static HRESULT APIENTRY vboxWddmDDevSetPixelShaderConstI(HANDLE hDevice, CONST D3DDDIARG_SETPIXELSHADERCONSTI* pData, CONST INT* pRegisters)
3754{
3755 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3756 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
3757 Assert(pDevice);
3758 Assert(pDevice->pDevice9If);
3759 HRESULT hr = pDevice->pDevice9If->SetPixelShaderConstantI(pData->Register, pRegisters, pData->Count);
3760 Assert(hr == S_OK);
3761 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
3762 return hr;
3763}
3764static HRESULT APIENTRY vboxWddmDDevSetPixelShaderConstB(HANDLE hDevice, CONST D3DDDIARG_SETPIXELSHADERCONSTB* pData, CONST BOOL* pRegisters)
3765{
3766 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3767 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
3768 Assert(pDevice);
3769 Assert(pDevice->pDevice9If);
3770 HRESULT hr = pDevice->pDevice9If->SetPixelShaderConstantB(pData->Register, pRegisters, pData->Count);
3771 Assert(hr == S_OK);
3772 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
3773 return hr;
3774}
3775static HRESULT APIENTRY vboxWddmDDevCreatePixelShader(HANDLE hDevice, D3DDDIARG_CREATEPIXELSHADER* pData, CONST UINT* pCode)
3776{
3777 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3778 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
3779 Assert(pDevice);
3780 Assert(pDevice->pDevice9If);
3781 IDirect3DPixelShader9 *pShader;
3782 Assert(*((UINT*)((uint8_t*)pCode + pData->CodeSize-4)) == 0x0000FFFF /* end token */);
3783 HRESULT hr = pDevice->pDevice9If->CreatePixelShader((const DWORD *)pCode, &pShader);
3784 Assert(hr == S_OK);
3785 if (hr == S_OK)
3786 {
3787 Assert(pShader);
3788 pData->ShaderHandle = pShader;
3789 }
3790 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
3791 return hr;
3792}
3793static HRESULT APIENTRY vboxWddmDDevDeletePixelShader(HANDLE hDevice, HANDLE hShaderHandle)
3794{
3795 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3796 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
3797 Assert(pDevice);
3798 Assert(pDevice->pDevice9If);
3799 IDirect3DPixelShader9 *pShader = (IDirect3DPixelShader9*)hShaderHandle;
3800 HRESULT hr = pShader->Release();
3801 Assert(hr == S_OK);
3802 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
3803 return hr;
3804}
3805static HRESULT APIENTRY vboxWddmDDevCreateDecodeDevice(HANDLE hDevice, D3DDDIARG_CREATEDECODEDEVICE* pData)
3806{
3807 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3808 AssertBreakpoint();
3809 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3810 return E_FAIL;
3811}
3812static HRESULT APIENTRY vboxWddmDDevDestroyDecodeDevice(HANDLE hDevice, HANDLE hDecodeDevice)
3813{
3814 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3815 AssertBreakpoint();
3816 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3817 return E_FAIL;
3818}
3819static HRESULT APIENTRY vboxWddmDDevSetDecodeRenderTarget(HANDLE hDevice, CONST D3DDDIARG_SETDECODERENDERTARGET* pData)
3820{
3821 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3822 AssertBreakpoint();
3823 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3824 return E_FAIL;
3825}
3826static HRESULT APIENTRY vboxWddmDDevDecodeBeginFrame(HANDLE hDevice, D3DDDIARG_DECODEBEGINFRAME* pData)
3827{
3828 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3829 AssertBreakpoint();
3830 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3831 return E_FAIL;
3832}
3833static HRESULT APIENTRY vboxWddmDDevDecodeEndFrame(HANDLE hDevice, D3DDDIARG_DECODEENDFRAME* pData)
3834{
3835 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3836 AssertBreakpoint();
3837 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3838 return E_FAIL;
3839}
3840static HRESULT APIENTRY vboxWddmDDevDecodeExecute(HANDLE hDevice, CONST D3DDDIARG_DECODEEXECUTE* pData)
3841{
3842 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3843 AssertBreakpoint();
3844 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3845 return E_FAIL;
3846}
3847static HRESULT APIENTRY vboxWddmDDevDecodeExtensionExecute(HANDLE hDevice, CONST D3DDDIARG_DECODEEXTENSIONEXECUTE* pData)
3848{
3849 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3850 AssertBreakpoint();
3851 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3852 return E_FAIL;
3853}
3854static HRESULT APIENTRY vboxWddmDDevCreateVideoProcessDevice(HANDLE hDevice, D3DDDIARG_CREATEVIDEOPROCESSDEVICE* pData)
3855{
3856 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3857 AssertBreakpoint();
3858 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3859 return E_FAIL;
3860}
3861static HRESULT APIENTRY vboxWddmDDevDestroyVideoProcessDevice(HANDLE hDevice, HANDLE hVideoProcessor)
3862{
3863 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3864 AssertBreakpoint();
3865 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3866 return E_FAIL;
3867}
3868static HRESULT APIENTRY vboxWddmDDevVideoProcessBeginFrame(HANDLE hDevice, HANDLE hVideoProcess)
3869{
3870 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3871 AssertBreakpoint();
3872 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3873 return E_FAIL;
3874}
3875static HRESULT APIENTRY vboxWddmDDevVideoProcessEndFrame(HANDLE hDevice, D3DDDIARG_VIDEOPROCESSENDFRAME* pData)
3876{
3877 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3878 AssertBreakpoint();
3879 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3880 return E_FAIL;
3881}
3882static HRESULT APIENTRY vboxWddmDDevSetVideoProcessRenderTarget(HANDLE hDevice, CONST D3DDDIARG_SETVIDEOPROCESSRENDERTARGET* pData)
3883{
3884 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3885 AssertBreakpoint();
3886 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3887 return E_FAIL;
3888}
3889static HRESULT APIENTRY vboxWddmDDevVideoProcessBlt(HANDLE hDevice, CONST D3DDDIARG_VIDEOPROCESSBLT* pData)
3890{
3891 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3892 AssertBreakpoint();
3893 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3894 return E_FAIL;
3895}
3896static HRESULT APIENTRY vboxWddmDDevCreateExtensionDevice(HANDLE hDevice, D3DDDIARG_CREATEEXTENSIONDEVICE* pData)
3897{
3898 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3899 AssertBreakpoint();
3900 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3901 return E_FAIL;
3902}
3903static HRESULT APIENTRY vboxWddmDDevDestroyExtensionDevice(HANDLE hDevice, HANDLE hExtension)
3904{
3905 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3906 AssertBreakpoint();
3907 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3908 return E_FAIL;
3909}
3910static HRESULT APIENTRY vboxWddmDDevExtensionExecute(HANDLE hDevice, CONST D3DDDIARG_EXTENSIONEXECUTE* pData)
3911{
3912 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3913 AssertBreakpoint();
3914 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3915 return E_FAIL;
3916}
3917static HRESULT APIENTRY vboxWddmDDevDestroyDevice(IN HANDLE hDevice)
3918{
3919 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3920
3921 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
3922 PVBOXWDDMDISP_ADAPTER pAdapter = pDevice->pAdapter;
3923 if (pDevice->pDevice9If)
3924 {
3925 pDevice->pDevice9If->Release();
3926 Assert(pDevice->hWnd);
3927 HRESULT tmpHr = VBoxDispWndDestroy(pAdapter, pDevice->hWnd);
3928 Assert(tmpHr == S_OK);
3929 }
3930 HRESULT hr = vboxDispCmCtxDestroy(pDevice, &pDevice->DefaultContext);
3931 Assert(hr == S_OK);
3932 if (hr == S_OK)
3933 RTMemFree(pDevice);
3934 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3935 return hr;
3936}
3937
3938AssertCompile(sizeof (RECT) == sizeof (D3DDDIRECT));
3939AssertCompile(RT_SIZEOFMEMB(RECT, left) == RT_SIZEOFMEMB(D3DDDIRECT, left));
3940AssertCompile(RT_SIZEOFMEMB(RECT, right) == RT_SIZEOFMEMB(D3DDDIRECT, right));
3941AssertCompile(RT_SIZEOFMEMB(RECT, top) == RT_SIZEOFMEMB(D3DDDIRECT, top));
3942AssertCompile(RT_SIZEOFMEMB(RECT, bottom) == RT_SIZEOFMEMB(D3DDDIRECT, bottom));
3943AssertCompile(RT_OFFSETOF(RECT, left) == RT_OFFSETOF(D3DDDIRECT, left));
3944AssertCompile(RT_OFFSETOF(RECT, right) == RT_OFFSETOF(D3DDDIRECT, right));
3945AssertCompile(RT_OFFSETOF(RECT, top) == RT_OFFSETOF(D3DDDIRECT, top));
3946AssertCompile(RT_OFFSETOF(RECT, bottom) == RT_OFFSETOF(D3DDDIRECT, bottom));
3947
3948static HRESULT APIENTRY vboxWddmDDevCreateOverlay(HANDLE hDevice, D3DDDIARG_CREATEOVERLAY* pData)
3949{
3950 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3951 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
3952 PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)pData->OverlayInfo.hResource;
3953 Assert(pRc);
3954 Assert(pRc->cAllocations > pData->OverlayInfo.SubResourceIndex);
3955 PVBOXWDDMDISP_ALLOCATION pAlloc = &pRc->aAllocations[pData->OverlayInfo.SubResourceIndex];
3956 HRESULT hr = S_OK;
3957 PVBOXWDDMDISP_OVERLAY pOverlay = (PVBOXWDDMDISP_OVERLAY)RTMemAllocZ(sizeof (VBOXWDDMDISP_OVERLAY));
3958 Assert(pOverlay);
3959 if (pOverlay)
3960 {
3961 VBOXWDDM_OVERLAY_INFO OurInfo;
3962 OurInfo.OverlayDesc.DstColorKeyLow = pData->OverlayInfo.DstColorKeyLow;
3963 OurInfo.OverlayDesc.DstColorKeyHigh = pData->OverlayInfo.DstColorKeyHigh;
3964 OurInfo.OverlayDesc.SrcColorKeyLow = pData->OverlayInfo.SrcColorKeyLow;
3965 OurInfo.OverlayDesc.SrcColorKeyHigh = pData->OverlayInfo.SrcColorKeyHigh;
3966 OurInfo.OverlayDesc.fFlags = pData->OverlayInfo.Flags.Value;
3967 vboxWddmDirtyRegionClear(&OurInfo.DirtyRegion);
3968 Assert(!pAlloc->LockInfo.cLocks);
3969 vboxWddmDirtyRegionUnite(&OurInfo.DirtyRegion, &pAlloc->DirtyRegion);
3970 D3DDDICB_CREATEOVERLAY OverInfo;
3971 OverInfo.VidPnSourceId = pData->VidPnSourceId;
3972 OverInfo.OverlayInfo.hAllocation = pAlloc->hAllocation;
3973 Assert(pAlloc->hAllocation);
3974 OverInfo.OverlayInfo.DstRect = *(D3DDDIRECT*)((void*)&pData->OverlayInfo.DstRect);
3975 OverInfo.OverlayInfo.SrcRect = *(D3DDDIRECT*)((void*)&pData->OverlayInfo.SrcRect);
3976 OverInfo.OverlayInfo.pPrivateDriverData = &OurInfo;
3977 OverInfo.OverlayInfo.PrivateDriverDataSize = sizeof (OurInfo);
3978 OverInfo.hKernelOverlay = NULL; /* <-- out */
3979#ifndef VBOXWDDMOVERLAY_TEST
3980 hr = pDevice->RtCallbacks.pfnCreateOverlayCb(pDevice->hDevice, &OverInfo);
3981 Assert(hr == S_OK);
3982 if (hr == S_OK)
3983 {
3984 Assert(OverInfo.hKernelOverlay);
3985 pOverlay->hOverlay = OverInfo.hKernelOverlay;
3986 pOverlay->VidPnSourceId = pData->VidPnSourceId;
3987
3988 Assert(!pAlloc->LockInfo.cLocks);
3989 if (!pAlloc->LockInfo.cLocks)
3990 {
3991 /* we have reported the dirty rect, may clear it if no locks are pending currently */
3992 vboxWddmDirtyRegionClear(&pAlloc->DirtyRegion);
3993 }
3994
3995 pData->hOverlay = pOverlay;
3996 }
3997 else
3998 {
3999 RTMemFree(pOverlay);
4000 }
4001#else
4002 pData->hOverlay = pOverlay;
4003#endif
4004 }
4005 else
4006 hr = E_OUTOFMEMORY;
4007
4008 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
4009 return hr;
4010}
4011static HRESULT APIENTRY vboxWddmDDevUpdateOverlay(HANDLE hDevice, CONST D3DDDIARG_UPDATEOVERLAY* pData)
4012{
4013 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
4014 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
4015 PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)pData->OverlayInfo.hResource;
4016 Assert(pRc);
4017 Assert(pRc->cAllocations > pData->OverlayInfo.SubResourceIndex);
4018 PVBOXWDDMDISP_ALLOCATION pAlloc = &pRc->aAllocations[pData->OverlayInfo.SubResourceIndex];
4019 HRESULT hr = S_OK;
4020 PVBOXWDDMDISP_OVERLAY pOverlay = (PVBOXWDDMDISP_OVERLAY)pData->hOverlay;
4021 VBOXWDDM_OVERLAY_INFO OurInfo;
4022 OurInfo.OverlayDesc.DstColorKeyLow = pData->OverlayInfo.DstColorKeyLow;
4023 OurInfo.OverlayDesc.DstColorKeyHigh = pData->OverlayInfo.DstColorKeyHigh;
4024 OurInfo.OverlayDesc.SrcColorKeyLow = pData->OverlayInfo.SrcColorKeyLow;
4025 OurInfo.OverlayDesc.SrcColorKeyHigh = pData->OverlayInfo.SrcColorKeyHigh;
4026 OurInfo.OverlayDesc.fFlags = pData->OverlayInfo.Flags.Value;
4027 vboxWddmDirtyRegionClear(&OurInfo.DirtyRegion);
4028 Assert(!pAlloc->LockInfo.cLocks);
4029 vboxWddmDirtyRegionUnite(&OurInfo.DirtyRegion, &pAlloc->DirtyRegion);
4030 D3DDDICB_UPDATEOVERLAY OverInfo;
4031 OverInfo.hKernelOverlay = pOverlay->hOverlay;
4032 OverInfo.OverlayInfo.hAllocation = pAlloc->hAllocation;
4033 OverInfo.OverlayInfo.DstRect = *(D3DDDIRECT*)((void*)&pData->OverlayInfo.DstRect);
4034 OverInfo.OverlayInfo.SrcRect = *(D3DDDIRECT*)((void*)&pData->OverlayInfo.SrcRect);
4035 OverInfo.OverlayInfo.pPrivateDriverData = &OurInfo;
4036 OverInfo.OverlayInfo.PrivateDriverDataSize = sizeof (OurInfo);
4037#ifndef VBOXWDDMOVERLAY_TEST
4038 hr = pDevice->RtCallbacks.pfnUpdateOverlayCb(pDevice->hDevice, &OverInfo);
4039 Assert(hr == S_OK);
4040 if (hr == S_OK)
4041#endif
4042 {
4043 Assert(!pAlloc->LockInfo.cLocks);
4044 if (!pAlloc->LockInfo.cLocks)
4045 {
4046 /* we have reported the dirty rect, may clear it if no locks are pending currently */
4047 vboxWddmDirtyRegionClear(&pAlloc->DirtyRegion);
4048 }
4049 }
4050
4051 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
4052 return hr;
4053}
4054static HRESULT APIENTRY vboxWddmDDevFlipOverlay(HANDLE hDevice, CONST D3DDDIARG_FLIPOVERLAY* pData)
4055{
4056 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
4057 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
4058 PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)pData->hSource;
4059 Assert(pRc);
4060 Assert(pRc->cAllocations > pData->SourceIndex);
4061 PVBOXWDDMDISP_ALLOCATION pAlloc = &pRc->aAllocations[pData->SourceIndex];
4062 HRESULT hr = S_OK;
4063 PVBOXWDDMDISP_OVERLAY pOverlay = (PVBOXWDDMDISP_OVERLAY)pData->hOverlay;
4064 VBOXWDDM_OVERLAYFLIP_INFO OurInfo;
4065 vboxWddmDirtyRegionClear(&OurInfo.DirtyRegion);
4066 Assert(!pAlloc->LockInfo.cLocks);
4067 vboxWddmDirtyRegionUnite(&OurInfo.DirtyRegion, &pAlloc->DirtyRegion);
4068 D3DDDICB_FLIPOVERLAY OverInfo;
4069 OverInfo.hKernelOverlay = pOverlay->hOverlay;
4070 OverInfo.hSource = pAlloc->hAllocation;
4071 OverInfo.pPrivateDriverData = &OurInfo;
4072 OverInfo.PrivateDriverDataSize = sizeof (OurInfo);
4073#ifndef VBOXWDDMOVERLAY_TEST
4074 hr = pDevice->RtCallbacks.pfnFlipOverlayCb(pDevice->hDevice, &OverInfo);
4075 Assert(hr == S_OK);
4076 if (hr == S_OK)
4077#endif
4078 {
4079 Assert(!pAlloc->LockInfo.cLocks);
4080 if (!pAlloc->LockInfo.cLocks)
4081 {
4082 /* we have reported the dirty rect, may clear it if no locks are pending currently */
4083 vboxWddmDirtyRegionClear(&pAlloc->DirtyRegion);
4084 }
4085 }
4086
4087 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
4088 return hr;
4089}
4090static HRESULT APIENTRY vboxWddmDDevGetOverlayColorControls(HANDLE hDevice, D3DDDIARG_GETOVERLAYCOLORCONTROLS* pData)
4091{
4092 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
4093 AssertBreakpoint();
4094 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
4095 return E_FAIL;
4096}
4097static HRESULT APIENTRY vboxWddmDDevSetOverlayColorControls(HANDLE hDevice, CONST D3DDDIARG_SETOVERLAYCOLORCONTROLS* pData)
4098{
4099 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
4100 AssertBreakpoint();
4101 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
4102 return E_FAIL;
4103}
4104static HRESULT APIENTRY vboxWddmDDevDestroyOverlay(HANDLE hDevice, CONST D3DDDIARG_DESTROYOVERLAY* pData)
4105{
4106 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
4107 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
4108 PVBOXWDDMDISP_OVERLAY pOverlay = (PVBOXWDDMDISP_OVERLAY)pData->hOverlay;
4109 D3DDDICB_DESTROYOVERLAY OverInfo;
4110 OverInfo.hKernelOverlay = pOverlay->hOverlay;
4111#ifndef VBOXWDDMOVERLAY_TEST
4112 HRESULT hr = pDevice->RtCallbacks.pfnDestroyOverlayCb(pDevice->hDevice, &OverInfo);
4113 Assert(hr == S_OK);
4114 if (hr == S_OK)
4115#else
4116 HRESULT hr = S_OK;
4117#endif
4118 {
4119 RTMemFree(pOverlay);
4120 }
4121
4122 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
4123 return hr;
4124}
4125static HRESULT APIENTRY vboxWddmDDevQueryResourceResidency(HANDLE hDevice, CONST D3DDDIARG_QUERYRESOURCERESIDENCY* pData)
4126{
4127 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
4128 AssertBreakpoint();
4129 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
4130 return E_FAIL;
4131}
4132
4133static HRESULT vboxAllocationInit(PVBOXWDDMDISP_ALLOCATION pAlloc, D3DDDI_OPENALLOCATIONINFO *pInfo)
4134{
4135 HRESULT hr = S_OK;
4136 pAlloc->hAllocation = pInfo->hAllocation;
4137 Assert(pInfo->PrivateDriverDataSize == sizeof (VBOXWDDM_ALLOCINFO));
4138 Assert(pInfo->pPrivateDriverData);
4139 if (pInfo->PrivateDriverDataSize >= sizeof (VBOXWDDM_ALLOCINFO))
4140 {
4141 PVBOXWDDM_ALLOCINFO pAllocInfo = (PVBOXWDDM_ALLOCINFO)pInfo->pPrivateDriverData;
4142 pAlloc->enmType = pAllocInfo->enmType;
4143 Assert(pAllocInfo->enmType == VBOXWDDM_ALLOC_TYPE_STD_SHAREDPRIMARYSURFACE
4144 || VBOXWDDM_ALLOC_TYPE_STD_SHADOWSURFACE
4145 || VBOXWDDM_ALLOC_TYPE_STD_STAGINGSURFACE);
4146 pAlloc->pvMem = NULL;
4147 pAlloc->SurfDesc = pAllocInfo->SurfDesc;
4148 }
4149 else
4150 {
4151 vboxVDbgPrintR((__FUNCTION__": ERROR: PrivateDriverDataSize(%d) < (%d)\n", pInfo->PrivateDriverDataSize, sizeof (VBOXWDDM_ALLOCINFO)));
4152 hr = E_INVALIDARG;
4153 }
4154 return hr;
4155}
4156
4157static HRESULT APIENTRY vboxWddmDDevOpenResource(HANDLE hDevice, D3DDDIARG_OPENRESOURCE* pData)
4158{
4159 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
4160 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
4161 HRESULT hr = S_OK;
4162
4163 Assert(pDevice);
4164 Assert(pData->NumAllocations);
4165 PVBOXWDDMDISP_RESOURCE pRc = vboxResourceAlloc(pData->NumAllocations);
4166 Assert(pRc);
4167 if (pRc)
4168 {
4169 pRc->hResource = pData->hResource;
4170 pRc->hKMResource = pData->hKMResource;
4171 pRc->pDevice = pDevice;
4172 pRc->RcDesc.enmRotation = pData->Rotation;
4173 pRc->fFlags = VBOXWDDM_RESOURCE_F_OPENNED;
4174 if (!pData->pPrivateDriverData || !pData->PrivateDriverDataSize)
4175 {
4176 /* this is a "standard" allocation resource */
4177
4178 /* both should be actually zero */
4179 Assert(!pData->pPrivateDriverData && !pData->PrivateDriverDataSize);
4180 pRc->RcDesc.enmPool = D3DDDIPOOL_LOCALVIDMEM;
4181 pRc->RcDesc.enmMultisampleType = D3DDDIMULTISAMPLE_NONE;
4182 pRc->RcDesc.MultisampleQuality = 0;
4183 pRc->RcDesc.MipLevels = 0;
4184 pRc->RcDesc.Fvf;
4185 pRc->RcDesc.fFlags.Value = 0;
4186
4187 Assert(pData->NumAllocations);
4188 D3DDDI_OPENALLOCATIONINFO* pDdiAllocInfo = &pData->pOpenAllocationInfo[0];
4189 Assert(pDdiAllocInfo->pPrivateDriverData);
4190 Assert(pDdiAllocInfo->PrivateDriverDataSize >= sizeof (VBOXWDDM_ALLOCINFO));
4191 if (pDdiAllocInfo->pPrivateDriverData && pDdiAllocInfo->PrivateDriverDataSize >= sizeof (VBOXWDDM_ALLOCINFO))
4192 {
4193 PVBOXWDDM_ALLOCINFO pAllocInfo = (PVBOXWDDM_ALLOCINFO)pDdiAllocInfo->pPrivateDriverData;
4194 switch(pAllocInfo->enmType)
4195 {
4196 case VBOXWDDM_ALLOC_TYPE_STD_SHAREDPRIMARYSURFACE:
4197 pRc->RcDesc.fFlags.Primary = 1;
4198 case VBOXWDDM_ALLOC_TYPE_STD_SHADOWSURFACE:
4199 case VBOXWDDM_ALLOC_TYPE_STD_STAGINGSURFACE:
4200 pRc->RcDesc.enmFormat = pAllocInfo->SurfDesc.format;
4201 pRc->RcDesc.VidPnSourceId = pAllocInfo->SurfDesc.VidPnSourceId;
4202 pRc->RcDesc.RefreshRate = pAllocInfo->SurfDesc.RefreshRate;
4203 break;
4204 default:
4205 AssertBreakpoint();
4206 hr = E_INVALIDARG;
4207 }
4208 }
4209 else
4210 hr = E_INVALIDARG;
4211 }
4212 else
4213 {
4214 AssertBreakpoint(); /* <-- need to test that */
4215
4216 /* this is a "generic" resource whose creation is initiaded by the UMD */
4217 Assert(pData->PrivateDriverDataSize == sizeof (VBOXWDDM_RCINFO));
4218 if (pData->PrivateDriverDataSize >= sizeof (VBOXWDDM_RCINFO))
4219 {
4220 VBOXWDDM_RCINFO *pRcInfo = (VBOXWDDM_RCINFO*)pData->pPrivateDriverData;
4221 Assert(pRcInfo->fFlags == VBOXWDDM_RESOURCE_F_TYPE_GENERIC);
4222 Assert(pRcInfo->cAllocInfos == pData->NumAllocations);
4223 pRc->fFlags = pRcInfo->fFlags | VBOXWDDM_RESOURCE_F_OPENNED;
4224 pRc->RcDesc = pRcInfo->RcDesc;
4225 pRc->cAllocations = pData->NumAllocations;
4226 }
4227 else
4228 hr = E_INVALIDARG;
4229 }
4230
4231 if (hr == S_OK)
4232 {
4233 for (UINT i = 0; i < pData->NumAllocations; ++i)
4234 {
4235 hr = vboxAllocationInit(&pRc->aAllocations[i], &pData->pOpenAllocationInfo[i]);
4236 Assert(hr == S_OK);
4237 if (hr != S_OK)
4238 break;
4239 }
4240 }
4241
4242 if (hr == S_OK)
4243 pData->hResource = pRc;
4244 else
4245 vboxResourceFree(pRc);
4246 }
4247 else
4248 {
4249 vboxVDbgPrintR((__FUNCTION__": vboxResourceAlloc failed for hDevice(0x%p), NumAllocations(%d)\n", hDevice, pData->NumAllocations));
4250 hr = E_OUTOFMEMORY;
4251 }
4252
4253 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
4254 return hr;
4255}
4256static HRESULT APIENTRY vboxWddmDDevGetCaptureAllocationHandle(HANDLE hDevice, D3DDDIARG_GETCAPTUREALLOCATIONHANDLE* pData)
4257{
4258 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
4259 AssertBreakpoint();
4260 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
4261 return E_FAIL;
4262}
4263
4264static HRESULT APIENTRY vboxWddmDDevCaptureToSysMem(HANDLE hDevice, CONST D3DDDIARG_CAPTURETOSYSMEM* pData)
4265{
4266 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
4267 AssertBreakpoint();
4268 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
4269 return E_FAIL;
4270}
4271
4272static HRESULT APIENTRY vboxWddmDispCreateDevice (IN HANDLE hAdapter, IN D3DDDIARG_CREATEDEVICE* pCreateData)
4273{
4274 HRESULT hr = S_OK;
4275 vboxVDbgPrint(("==> "__FUNCTION__", hAdapter(0x%p), Interface(%d), Version(%d)\n", hAdapter, pCreateData->Interface, pCreateData->Version));
4276
4277// AssertBreakpoint();
4278
4279 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)RTMemAllocZ(sizeof (VBOXWDDMDISP_DEVICE));
4280 if (pDevice)
4281 {
4282 PVBOXWDDMDISP_ADAPTER pAdapter = (PVBOXWDDMDISP_ADAPTER)hAdapter;
4283
4284 pDevice->hDevice = pCreateData->hDevice;
4285 pDevice->pAdapter = pAdapter;
4286 pDevice->u32IfVersion = pCreateData->Interface;
4287 pDevice->uRtVersion = pCreateData->Version;
4288 pDevice->RtCallbacks = *pCreateData->pCallbacks;
4289 pDevice->pvCmdBuffer = pCreateData->pCommandBuffer;
4290 pDevice->cbCmdBuffer = pCreateData->CommandBufferSize;
4291 pDevice->fFlags = pCreateData->Flags;
4292 /* Set Viewport to some default values */
4293 pDevice->ViewPort.X = 0;
4294 pDevice->ViewPort.Y = 0;
4295 pDevice->ViewPort.Width = 1;
4296 pDevice->ViewPort.Height = 1;
4297 pDevice->ViewPort.MinZ = 0.;
4298 pDevice->ViewPort.MaxZ = 1.;
4299
4300 Assert(!pCreateData->AllocationListSize);
4301 Assert(!pCreateData->PatchLocationListSize);
4302
4303 pCreateData->hDevice = pDevice;
4304
4305 pCreateData->pDeviceFuncs->pfnSetRenderState = vboxWddmDDevSetRenderState;
4306 pCreateData->pDeviceFuncs->pfnUpdateWInfo = vboxWddmDDevUpdateWInfo;
4307 pCreateData->pDeviceFuncs->pfnValidateDevice = vboxWddmDDevValidateDevice;
4308 pCreateData->pDeviceFuncs->pfnSetTextureStageState = vboxWddmDDevSetTextureStageState;
4309 pCreateData->pDeviceFuncs->pfnSetTexture = vboxWddmDDevSetTexture;
4310 pCreateData->pDeviceFuncs->pfnSetPixelShader = vboxWddmDDevSetPixelShader;
4311 pCreateData->pDeviceFuncs->pfnSetPixelShaderConst = vboxWddmDDevSetPixelShaderConst;
4312 pCreateData->pDeviceFuncs->pfnSetStreamSourceUm = vboxWddmDDevSetStreamSourceUm;
4313 pCreateData->pDeviceFuncs->pfnSetIndices = vboxWddmDDevSetIndices;
4314 pCreateData->pDeviceFuncs->pfnSetIndicesUm = vboxWddmDDevSetIndicesUm;
4315 pCreateData->pDeviceFuncs->pfnDrawPrimitive = vboxWddmDDevDrawPrimitive;
4316 pCreateData->pDeviceFuncs->pfnDrawIndexedPrimitive = vboxWddmDDevDrawIndexedPrimitive;
4317 pCreateData->pDeviceFuncs->pfnDrawRectPatch = vboxWddmDDevDrawRectPatch;
4318 pCreateData->pDeviceFuncs->pfnDrawTriPatch = vboxWddmDDevDrawTriPatch;
4319 pCreateData->pDeviceFuncs->pfnDrawPrimitive2 = vboxWddmDDevDrawPrimitive2;
4320 pCreateData->pDeviceFuncs->pfnDrawIndexedPrimitive2 = vboxWddmDDevDrawIndexedPrimitive2;
4321 pCreateData->pDeviceFuncs->pfnVolBlt = vboxWddmDDevVolBlt;
4322 pCreateData->pDeviceFuncs->pfnBufBlt = vboxWddmDDevBufBlt;
4323 pCreateData->pDeviceFuncs->pfnTexBlt = vboxWddmDDevTexBlt;
4324 pCreateData->pDeviceFuncs->pfnStateSet = vboxWddmDDevStateSet;
4325 pCreateData->pDeviceFuncs->pfnSetPriority = vboxWddmDDevSetPriority;
4326 pCreateData->pDeviceFuncs->pfnClear = vboxWddmDDevClear;
4327 pCreateData->pDeviceFuncs->pfnUpdatePalette = vboxWddmDDevUpdatePalette;
4328 pCreateData->pDeviceFuncs->pfnSetPalette = vboxWddmDDevSetPalette;
4329 pCreateData->pDeviceFuncs->pfnSetVertexShaderConst = vboxWddmDDevSetVertexShaderConst;
4330 pCreateData->pDeviceFuncs->pfnMultiplyTransform = vboxWddmDDevMultiplyTransform;
4331 pCreateData->pDeviceFuncs->pfnSetTransform = vboxWddmDDevSetTransform;
4332 pCreateData->pDeviceFuncs->pfnSetViewport = vboxWddmDDevSetViewport;
4333 pCreateData->pDeviceFuncs->pfnSetZRange = vboxWddmDDevSetZRange;
4334 pCreateData->pDeviceFuncs->pfnSetMaterial = vboxWddmDDevSetMaterial;
4335 pCreateData->pDeviceFuncs->pfnSetLight = vboxWddmDDevSetLight;
4336 pCreateData->pDeviceFuncs->pfnCreateLight = vboxWddmDDevCreateLight;
4337 pCreateData->pDeviceFuncs->pfnDestroyLight = vboxWddmDDevDestroyLight;
4338 pCreateData->pDeviceFuncs->pfnSetClipPlane = vboxWddmDDevSetClipPlane;
4339 pCreateData->pDeviceFuncs->pfnGetInfo = vboxWddmDDevGetInfo;
4340 pCreateData->pDeviceFuncs->pfnLock = vboxWddmDDevLock;
4341 pCreateData->pDeviceFuncs->pfnUnlock = vboxWddmDDevUnlock;
4342 pCreateData->pDeviceFuncs->pfnCreateResource = vboxWddmDDevCreateResource;
4343 pCreateData->pDeviceFuncs->pfnDestroyResource = vboxWddmDDevDestroyResource;
4344 pCreateData->pDeviceFuncs->pfnSetDisplayMode = vboxWddmDDevSetDisplayMode;
4345 pCreateData->pDeviceFuncs->pfnPresent = vboxWddmDDevPresent;
4346 pCreateData->pDeviceFuncs->pfnFlush = vboxWddmDDevFlush;
4347 pCreateData->pDeviceFuncs->pfnCreateVertexShaderFunc = vboxWddmDDevCreateVertexShaderFunc;
4348 pCreateData->pDeviceFuncs->pfnDeleteVertexShaderFunc = vboxWddmDDevDeleteVertexShaderFunc;
4349 pCreateData->pDeviceFuncs->pfnSetVertexShaderFunc = vboxWddmDDevSetVertexShaderFunc;
4350 pCreateData->pDeviceFuncs->pfnCreateVertexShaderDecl = vboxWddmDDevCreateVertexShaderDecl;
4351 pCreateData->pDeviceFuncs->pfnDeleteVertexShaderDecl = vboxWddmDDevDeleteVertexShaderDecl;
4352 pCreateData->pDeviceFuncs->pfnSetVertexShaderDecl = vboxWddmDDevSetVertexShaderDecl;
4353 pCreateData->pDeviceFuncs->pfnSetVertexShaderConstI = vboxWddmDDevSetVertexShaderConstI;
4354 pCreateData->pDeviceFuncs->pfnSetVertexShaderConstB = vboxWddmDDevSetVertexShaderConstB;
4355 pCreateData->pDeviceFuncs->pfnSetScissorRect = vboxWddmDDevSetScissorRect;
4356 pCreateData->pDeviceFuncs->pfnSetStreamSource = vboxWddmDDevSetStreamSource;
4357 pCreateData->pDeviceFuncs->pfnSetStreamSourceFreq = vboxWddmDDevSetStreamSourceFreq;
4358 pCreateData->pDeviceFuncs->pfnSetConvolutionKernelMono = vboxWddmDDevSetConvolutionKernelMono;
4359 pCreateData->pDeviceFuncs->pfnComposeRects = vboxWddmDDevComposeRects;
4360 pCreateData->pDeviceFuncs->pfnBlt = vboxWddmDDevBlt;
4361 pCreateData->pDeviceFuncs->pfnColorFill = vboxWddmDDevColorFill;
4362 pCreateData->pDeviceFuncs->pfnDepthFill = vboxWddmDDevDepthFill;
4363 pCreateData->pDeviceFuncs->pfnCreateQuery = vboxWddmDDevCreateQuery;
4364 pCreateData->pDeviceFuncs->pfnDestroyQuery = vboxWddmDDevDestroyQuery;
4365 pCreateData->pDeviceFuncs->pfnIssueQuery = vboxWddmDDevIssueQuery;
4366 pCreateData->pDeviceFuncs->pfnGetQueryData = vboxWddmDDevGetQueryData;
4367 pCreateData->pDeviceFuncs->pfnSetRenderTarget = vboxWddmDDevSetRenderTarget;
4368 pCreateData->pDeviceFuncs->pfnSetDepthStencil = vboxWddmDDevSetDepthStencil;
4369 pCreateData->pDeviceFuncs->pfnGenerateMipSubLevels = vboxWddmDDevGenerateMipSubLevels;
4370 pCreateData->pDeviceFuncs->pfnSetPixelShaderConstI = vboxWddmDDevSetPixelShaderConstI;
4371 pCreateData->pDeviceFuncs->pfnSetPixelShaderConstB = vboxWddmDDevSetPixelShaderConstB;
4372 pCreateData->pDeviceFuncs->pfnCreatePixelShader = vboxWddmDDevCreatePixelShader;
4373 pCreateData->pDeviceFuncs->pfnDeletePixelShader = vboxWddmDDevDeletePixelShader;
4374 pCreateData->pDeviceFuncs->pfnCreateDecodeDevice = vboxWddmDDevCreateDecodeDevice;
4375 pCreateData->pDeviceFuncs->pfnDestroyDecodeDevice = vboxWddmDDevDestroyDecodeDevice;
4376 pCreateData->pDeviceFuncs->pfnSetDecodeRenderTarget = vboxWddmDDevSetDecodeRenderTarget;
4377 pCreateData->pDeviceFuncs->pfnDecodeBeginFrame = vboxWddmDDevDecodeBeginFrame;
4378 pCreateData->pDeviceFuncs->pfnDecodeEndFrame = vboxWddmDDevDecodeEndFrame;
4379 pCreateData->pDeviceFuncs->pfnDecodeExecute = vboxWddmDDevDecodeExecute;
4380 pCreateData->pDeviceFuncs->pfnDecodeExtensionExecute = vboxWddmDDevDecodeExtensionExecute;
4381 pCreateData->pDeviceFuncs->pfnCreateVideoProcessDevice = vboxWddmDDevCreateVideoProcessDevice;
4382 pCreateData->pDeviceFuncs->pfnDestroyVideoProcessDevice = vboxWddmDDevDestroyVideoProcessDevice;
4383 pCreateData->pDeviceFuncs->pfnVideoProcessBeginFrame = vboxWddmDDevVideoProcessBeginFrame;
4384 pCreateData->pDeviceFuncs->pfnVideoProcessEndFrame = vboxWddmDDevVideoProcessEndFrame;
4385 pCreateData->pDeviceFuncs->pfnSetVideoProcessRenderTarget = vboxWddmDDevSetVideoProcessRenderTarget;
4386 pCreateData->pDeviceFuncs->pfnVideoProcessBlt = vboxWddmDDevVideoProcessBlt;
4387 pCreateData->pDeviceFuncs->pfnCreateExtensionDevice = vboxWddmDDevCreateExtensionDevice;
4388 pCreateData->pDeviceFuncs->pfnDestroyExtensionDevice = vboxWddmDDevDestroyExtensionDevice;
4389 pCreateData->pDeviceFuncs->pfnExtensionExecute = vboxWddmDDevExtensionExecute;
4390 pCreateData->pDeviceFuncs->pfnCreateOverlay = vboxWddmDDevCreateOverlay;
4391 pCreateData->pDeviceFuncs->pfnUpdateOverlay = vboxWddmDDevUpdateOverlay;
4392 pCreateData->pDeviceFuncs->pfnFlipOverlay = vboxWddmDDevFlipOverlay;
4393 pCreateData->pDeviceFuncs->pfnGetOverlayColorControls = vboxWddmDDevGetOverlayColorControls;
4394 pCreateData->pDeviceFuncs->pfnSetOverlayColorControls = vboxWddmDDevSetOverlayColorControls;
4395 pCreateData->pDeviceFuncs->pfnDestroyOverlay = vboxWddmDDevDestroyOverlay;
4396 pCreateData->pDeviceFuncs->pfnDestroyDevice = vboxWddmDDevDestroyDevice;
4397 pCreateData->pDeviceFuncs->pfnQueryResourceResidency = vboxWddmDDevQueryResourceResidency;
4398 pCreateData->pDeviceFuncs->pfnOpenResource = vboxWddmDDevOpenResource;
4399 pCreateData->pDeviceFuncs->pfnGetCaptureAllocationHandle = vboxWddmDDevGetCaptureAllocationHandle;
4400 pCreateData->pDeviceFuncs->pfnCaptureToSysMem = vboxWddmDDevCaptureToSysMem;
4401 pCreateData->pDeviceFuncs->pfnLockAsync = NULL; //vboxWddmDDevLockAsync;
4402 pCreateData->pDeviceFuncs->pfnUnlockAsync = NULL; //vboxWddmDDevUnlockAsync;
4403 pCreateData->pDeviceFuncs->pfnRename = NULL; //vboxWddmDDevRename;
4404
4405
4406 do
4407 {
4408 Assert(!pCreateData->AllocationListSize
4409 && !pCreateData->PatchLocationListSize);
4410 if (!pCreateData->AllocationListSize
4411 && !pCreateData->PatchLocationListSize)
4412 {
4413 hr = vboxDispCmCtxCreate(pDevice, &pDevice->DefaultContext);
4414 Assert(hr == S_OK);
4415 if (hr == S_OK)
4416 break;
4417 }
4418 else
4419 {
4420 vboxVDbgPrintR((__FUNCTION__": Not implemented: PatchLocationListSize(%d), AllocationListSize(%d)\n",
4421 pCreateData->PatchLocationListSize, pCreateData->AllocationListSize));
4422 //pCreateData->pAllocationList = ??
4423 hr = E_FAIL;
4424 }
4425
4426 RTMemFree(pDevice);
4427 } while (0);
4428 }
4429 else
4430 {
4431 vboxVDbgPrintR((__FUNCTION__": RTMemAllocZ returned NULL\n"));
4432 hr = E_OUTOFMEMORY;
4433 }
4434
4435 vboxVDbgPrint(("<== "__FUNCTION__", hAdapter(0x%p)\n", hAdapter));
4436
4437 return hr;
4438}
4439
4440static HRESULT APIENTRY vboxWddmDispCloseAdapter (IN HANDLE hAdapter)
4441{
4442 vboxVDbgPrint(("==> "__FUNCTION__", hAdapter(0x%p)\n", hAdapter));
4443
4444// AssertBreakpoint();
4445
4446 PVBOXWDDMDISP_ADAPTER pAdapter = (PVBOXWDDMDISP_ADAPTER)hAdapter;
4447 if (VBOXDISPMODE_IS_3D(pAdapter))
4448 {
4449 HRESULT hr = VBoxDispWorkerDestroy(&pAdapter->WndWorker);
4450 Assert(hr == S_OK);
4451 hr = pAdapter->pD3D9If->Release();
4452 Assert(hr == S_OK);
4453 VBoxDispD3DClose(&pAdapter->D3D);
4454 }
4455
4456 vboxCapsFree(pAdapter);
4457
4458 RTMemFree(pAdapter);
4459
4460 vboxVDbgPrint(("<== "__FUNCTION__", hAdapter(0x%p)\n", hAdapter));
4461
4462 return S_OK;
4463}
4464
4465HRESULT APIENTRY OpenAdapter (__inout D3DDDIARG_OPENADAPTER* pOpenData)
4466{
4467 vboxVDbgPrint(("==> "__FUNCTION__"\n"));
4468
4469 VBOXWDDM_QI Query;
4470 D3DDDICB_QUERYADAPTERINFO DdiQuery;
4471 DdiQuery.PrivateDriverDataSize = sizeof(Query);
4472 DdiQuery.pPrivateDriverData = &Query;
4473 HRESULT hr = pOpenData->pAdapterCallbacks->pfnQueryAdapterInfoCb(pOpenData->hAdapter, &DdiQuery);
4474 Assert(hr == S_OK);
4475 if (hr != S_OK)
4476 {
4477 vboxVDbgPrintR((__FUNCTION__": pfnQueryAdapterInfoCb failed, hr (%d)\n", hr));
4478 return E_FAIL;
4479 }
4480
4481 /* check the miniport version match display version */
4482 if (Query.u32Version != VBOXVIDEOIF_VERSION)
4483 {
4484 vboxVDbgPrintR((__FUNCTION__": miniport version mismatch, expected (%d), but was (%d)\n",
4485 VBOXVIDEOIF_VERSION,
4486 Query.u32Version));
4487 return E_FAIL;
4488 }
4489
4490#ifdef VBOX_WITH_VIDEOHWACCEL
4491 Assert(Query.cInfos >= 1);
4492 PVBOXWDDMDISP_ADAPTER pAdapter = (PVBOXWDDMDISP_ADAPTER)RTMemAllocZ(RT_OFFSETOF(VBOXWDDMDISP_ADAPTER, aHeads[Query.cInfos]));
4493#else
4494 PVBOXWDDMDISP_ADAPTER pAdapter = (PVBOXWDDMDISP_ADAPTER)RTMemAllocZ(sizeof (VBOXWDDMDISP_ADAPTER));
4495#endif
4496 Assert(pAdapter);
4497 if (pAdapter)
4498 {
4499 pAdapter->hAdapter = pOpenData->hAdapter;
4500 pAdapter->uIfVersion = pOpenData->Interface;
4501 pAdapter->uRtVersion= pOpenData->Version;
4502 pAdapter->RtCallbacks = *pOpenData->pAdapterCallbacks;
4503
4504 pAdapter->cHeads = Query.cInfos;
4505
4506
4507 pOpenData->hAdapter = pAdapter;
4508 pOpenData->pAdapterFuncs->pfnGetCaps = vboxWddmDispGetCaps;
4509 pOpenData->pAdapterFuncs->pfnCreateDevice = vboxWddmDispCreateDevice;
4510 pOpenData->pAdapterFuncs->pfnCloseAdapter = vboxWddmDispCloseAdapter;
4511 pOpenData->DriverVersion = D3D_UMD_INTERFACE_VERSION;
4512 /*
4513 * here we detect whether we are called by the d3d or ddraw.
4514 * in the d3d case we init our d3d environment
4515 * in the ddraw case we init 2D acceleration
4516 * if interface version is > 7, this is D3D, treat it as so
4517 * otherwise treat it as ddraw
4518 * @todo: need a more clean way of doing this */
4519
4520 if (pAdapter->uIfVersion > 7)
4521 {
4522 do
4523 {
4524 /* try enable the 3D */
4525 hr = VBoxDispD3DOpen(&pAdapter->D3D);
4526 Assert(hr == S_OK);
4527 if (hr == S_OK)
4528 {
4529 hr = pAdapter->D3D.pfnDirect3DCreate9Ex(D3D_SDK_VERSION, &pAdapter->pD3D9If);
4530 Assert(hr == S_OK);
4531 if (hr == S_OK)
4532 {
4533 hr = VBoxDispWorkerCreate(&pAdapter->WndWorker);
4534 Assert(hr == S_OK);
4535 if (hr == S_OK)
4536 {
4537 vboxVDbgPrint((__FUNCTION__": SUCCESS 3D Enabled, pAdapter (0x%p)\n", pAdapter));
4538 break;
4539 }
4540 pAdapter->pD3D9If->Release();
4541 }
4542 else
4543 vboxVDbgPrintR((__FUNCTION__": pfnDirect3DCreate9Ex failed, hr (%d)\n", hr));
4544 VBoxDispD3DClose(&pAdapter->D3D);
4545 }
4546 else
4547 vboxVDbgPrintR((__FUNCTION__": VBoxDispD3DOpen failed, hr (%d)\n", hr));
4548 } while (0);
4549 }
4550#ifdef VBOX_WITH_VIDEOHWACCEL
4551 else
4552 {
4553 for (uint32_t i = 0; i < pAdapter->cHeads; ++i)
4554 {
4555 pAdapter->aHeads[i].Vhwa.Settings = Query.aInfos[i];
4556 }
4557 }
4558#endif
4559
4560 vboxCapsInit(pAdapter);
4561 hr = S_OK;
4562// RTMemFree(pAdapter);
4563 }
4564 else
4565 {
4566 vboxVDbgPrintR((__FUNCTION__": RTMemAllocZ returned NULL\n"));
4567 hr = E_OUTOFMEMORY;
4568 }
4569
4570 vboxVDbgPrint(("<== "__FUNCTION__", hr (%d)\n", hr));
4571
4572 return hr;
4573}
4574
4575#ifdef VBOXWDDMDISP_DEBUG
4576VOID vboxVDbgDoPrint(LPCSTR szString, ...)
4577{
4578 char szBuffer[1024] = {0};
4579 va_list pArgList;
4580 va_start(pArgList, szString);
4581 _vsnprintf(szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0]), szString, pArgList);
4582 va_end(pArgList);
4583
4584 OutputDebugStringA(szBuffer);
4585}
4586#endif
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