VirtualBox

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

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

wddm/3d: visible regions working (more debug still needed)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 176.8 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 AssertBreakpoint();
1578 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
1579 return E_FAIL;
1580}
1581
1582static HRESULT APIENTRY vboxWddmDDevSetIndicesUm(HANDLE hDevice, UINT IndexSize, CONST VOID* pUMBuffer)
1583{
1584 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
1585 AssertBreakpoint();
1586 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
1587 return E_FAIL;
1588}
1589
1590static HRESULT APIENTRY vboxWddmDDevDrawPrimitive(HANDLE hDevice, CONST D3DDDIARG_DRAWPRIMITIVE* pData, CONST UINT* pFlagBuffer)
1591{
1592 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
1593 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
1594 Assert(pDevice);
1595 Assert(pDevice->pDevice9If);
1596 Assert(!pFlagBuffer);
1597 HRESULT hr = S_OK;
1598
1599 if (!pDevice->cStreamSources)
1600 {
1601 Assert(pDevice->aStreamSourceUm[0].pvBuffer);
1602#ifdef DEBUG
1603 for (UINT i = 1; i < RT_ELEMENTS(pDevice->aStreamSourceUm); ++i)
1604 {
1605 Assert(!pDevice->aStreamSourceUm[i].pvBuffer);
1606 }
1607#endif
1608 hr = pDevice->pDevice9If->DrawPrimitiveUP(pData->PrimitiveType,
1609 pData->PrimitiveCount,
1610 ((uint8_t*)pDevice->aStreamSourceUm[0].pvBuffer) + pData->VStart * pDevice->aStreamSourceUm[0].cbStride,
1611 pDevice->aStreamSourceUm[0].cbStride);
1612 Assert(hr == S_OK);
1613 }
1614 else
1615 {
1616 AssertBreakpoint();
1617 hr = pDevice->pDevice9If->DrawPrimitive(pData->PrimitiveType,
1618 pData->VStart,
1619 pData->PrimitiveCount);
1620#if 0
1621 IDirect3DVertexDeclaration9* pDecl;
1622 hr = pDevice->pDevice9If->GetVertexDeclaration(&pDecl);
1623 Assert(hr == S_OK);
1624 if (hr == S_OK)
1625 {
1626 Assert(pDecl);
1627 D3DVERTEXELEMENT9 aDecls9[MAXD3DDECLLENGTH];
1628 UINT cDecls9 = 0;
1629 hr = pDecl->GetDeclaration(aDecls9, &cDecls9);
1630 Assert(hr == S_OK);
1631 if (hr == S_OK)
1632 {
1633 Assert(cDecls9);
1634 for (UINT i = 0; i < cDecls9 - 1 /* the last one is D3DDECL_END */; ++i)
1635 {
1636 D3DVERTEXELEMENT9 *pDecl9 = &aDecls9[i];
1637 Assert(pDecl9->Stream < RT_ELEMENTS(pDevice->aStreamSourceUm) || pDecl9->Stream == 0xff);
1638 if (pDecl9->Stream != 0xff)
1639 {
1640 PVBOXWDDMDISP_STREAMSOURCEUM pStrSrc = &pDevice->aStreamSourceUm[pDecl9->Stream];
1641 if (pStrSrc->pvBuffer)
1642 {
1643 WORD iStream = pDecl9->Stream;
1644 D3DVERTEXELEMENT9 *pLastCDecl9 = pDecl9;
1645 for (UINT j = i+1; j < cDecls9 - 1 /* the last one is D3DDECL_END */; ++j)
1646 {
1647 pDecl9 = &aDecls9[j];
1648 if (iStream == pDecl9->Stream)
1649 {
1650 pDecl9->Stream = 0xff; /* mark as done */
1651 Assert(pDecl9->Offset != pLastCDecl9->Offset);
1652 if (pDecl9->Offset > pLastCDecl9->Offset)
1653 pLastCDecl9 = pDecl9;
1654 }
1655 }
1656 /* vertex size is MAX(all Offset's) + sizeof (data_type with MAX offset) + stride*/
1657 UINT cbVertex = pLastCDecl9->Offset + pStrSrc->cbStride;
1658 UINT cbType;
1659 switch (pLastCDecl9->Type)
1660 {
1661 case D3DDECLTYPE_FLOAT1:
1662 cbType = sizeof (float);
1663 break;
1664 case D3DDECLTYPE_FLOAT2:
1665 cbType = sizeof (float) * 2;
1666 break;
1667 case D3DDECLTYPE_FLOAT3:
1668 cbType = sizeof (float) * 3;
1669 break;
1670 case D3DDECLTYPE_FLOAT4:
1671 cbType = sizeof (float) * 4;
1672 break;
1673 case D3DDECLTYPE_D3DCOLOR:
1674 cbType = 4;
1675 break;
1676 case D3DDECLTYPE_UBYTE4:
1677 cbType = 4;
1678 break;
1679 case D3DDECLTYPE_SHORT2:
1680 cbType = sizeof (short) * 2;
1681 break;
1682 case D3DDECLTYPE_SHORT4:
1683 cbType = sizeof (short) * 4;
1684 break;
1685 case D3DDECLTYPE_UBYTE4N:
1686 cbType = 4;
1687 break;
1688 case D3DDECLTYPE_SHORT2N:
1689 cbType = sizeof (short) * 2;
1690 break;
1691 case D3DDECLTYPE_SHORT4N:
1692 cbType = sizeof (short) * 4;
1693 break;
1694 case D3DDECLTYPE_USHORT2N:
1695 cbType = sizeof (short) * 2;
1696 break;
1697 case D3DDECLTYPE_USHORT4N:
1698 cbType = sizeof (short) * 4;
1699 break;
1700 case D3DDECLTYPE_UDEC3:
1701 cbType = sizeof (signed) * 3;
1702 break;
1703 case D3DDECLTYPE_DEC3N:
1704 cbType = sizeof (unsigned) * 3;
1705 break;
1706 case D3DDECLTYPE_FLOAT16_2:
1707 cbType = 2 * 2;
1708 break;
1709 case D3DDECLTYPE_FLOAT16_4:
1710 cbType = 2 * 4;
1711 break;
1712 default:
1713 AssertBreakpoint();
1714 cbType = 1;
1715 }
1716 cbVertex += cbType;
1717
1718 UINT cVertexes;
1719 switch (pData->PrimitiveType)
1720 {
1721 case D3DPT_POINTLIST:
1722 cVertexes = pData->PrimitiveCount;
1723 break;
1724 case D3DPT_LINELIST:
1725 cVertexes = pData->PrimitiveCount * 2;
1726 break;
1727 case D3DPT_LINESTRIP:
1728 cVertexes = pData->PrimitiveCount + 1;
1729 break;
1730 case D3DPT_TRIANGLELIST:
1731 cVertexes = pData->PrimitiveCount * 3;
1732 break;
1733 case D3DPT_TRIANGLESTRIP:
1734 cVertexes = pData->PrimitiveCount + 2;
1735 break;
1736 case D3DPT_TRIANGLEFAN:
1737 cVertexes = pData->PrimitiveCount + 2;
1738 break;
1739 default:
1740 AssertBreakpoint();
1741 cVertexes = pData->PrimitiveCount;
1742 }
1743 UINT cbVertexes = cVertexes * cbVertex;
1744 IDirect3DVertexBuffer9 *pCurVb = NULL, *pVb = NULL;
1745 UINT cbOffset;
1746 UINT cbStride;
1747 hr = pDevice->pDevice9If->GetStreamSource(iStream, &pCurVb, &cbOffset, &cbStride);
1748 Assert(hr == S_OK);
1749 if (hr == S_OK)
1750 {
1751 if (pCurVb)
1752 {
1753 if (cbStride == pStrSrc->cbStride)
1754 {
1755 /* ensure our data feets in the buffer */
1756 D3DVERTEXBUFFER_DESC Desc;
1757 hr = pCurVb->GetDesc(&Desc);
1758 Assert(hr == S_OK);
1759 if (hr == S_OK)
1760 {
1761 if (Desc.Size >= cbVertexes)
1762 pVb = pCurVb;
1763 }
1764 }
1765 }
1766 }
1767 else
1768 {
1769 pCurVb = NULL;
1770 }
1771
1772 if (!pVb)
1773 {
1774 hr = pDevice->pDevice9If->CreateVertexBuffer(cbVertexes,
1775 0, /* DWORD Usage */
1776 0, /* DWORD FVF */
1777 D3DPOOL_DEFAULT, /* D3DPOOL Pool */
1778 &pVb,
1779 NULL /*HANDLE* pSharedHandle*/);
1780 Assert(hr == S_OK);
1781 if (hr == S_OK)
1782 {
1783 hr = pDevice->pDevice9If->SetStreamSource(iStream, pVb, 0, pStrSrc->cbStride);
1784 Assert(hr == S_OK);
1785 if (hr == S_OK)
1786 {
1787 if (pCurVb)
1788 pCurVb->Release();
1789 }
1790 else
1791 {
1792 pVb->Release();
1793 pVb = NULL;
1794 }
1795 }
1796 }
1797
1798 if (pVb)
1799 {
1800 Assert(hr == S_OK);
1801 VOID *pvData;
1802 hr = pVb->Lock(0, /* UINT OffsetToLock */
1803 cbVertexes,
1804 &pvData,
1805 D3DLOCK_DISCARD);
1806 Assert(hr == S_OK);
1807 if (hr == S_OK)
1808 {
1809 memcpy (pvData, ((uint8_t*)pStrSrc->pvBuffer) + pData->VStart * cbVertex, cbVertexes);
1810 HRESULT tmpHr = pVb->Unlock();
1811 Assert(tmpHr == S_OK);
1812 }
1813 }
1814 }
1815 }
1816 }
1817 }
1818 if (hr == S_OK)
1819 {
1820 hr = pDevice->pDevice9If->DrawPrimitive(pData->PrimitiveType,
1821 0 /* <- since we use our owne StreamSource buffer which has data at the very beginning*/,
1822 pData->PrimitiveCount);
1823 Assert(hr == S_OK);
1824 }
1825 }
1826#endif
1827 }
1828 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
1829 return hr;
1830}
1831
1832static HRESULT APIENTRY vboxWddmDDevDrawIndexedPrimitive(HANDLE hDevice, CONST D3DDDIARG_DRAWINDEXEDPRIMITIVE* pData)
1833{
1834 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
1835 AssertBreakpoint();
1836 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
1837 return E_FAIL;
1838}
1839
1840static HRESULT APIENTRY vboxWddmDDevDrawRectPatch(HANDLE hDevice, CONST D3DDDIARG_DRAWRECTPATCH* pData, CONST D3DDDIRECTPATCH_INFO* pInfo, CONST FLOAT* pPatch)
1841{
1842 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
1843 AssertBreakpoint();
1844 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
1845 return E_FAIL;
1846}
1847
1848static HRESULT APIENTRY vboxWddmDDevDrawTriPatch(HANDLE hDevice, CONST D3DDDIARG_DRAWTRIPATCH* pData, CONST D3DDDITRIPATCH_INFO* pInfo, CONST FLOAT* pPatch)
1849{
1850 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
1851 AssertBreakpoint();
1852 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
1853 return E_FAIL;
1854}
1855
1856static HRESULT APIENTRY vboxWddmDDevDrawPrimitive2(HANDLE hDevice, CONST D3DDDIARG_DRAWPRIMITIVE2* pData)
1857{
1858 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
1859 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
1860 Assert(pDevice);
1861 Assert(pDevice->pDevice9If);
1862 HRESULT hr;
1863
1864#if 0
1865 int stream;
1866 for (stream=0; stream<VBOXWDDMDISP_MAX_VERTEX_STREAMS; ++stream)
1867 {
1868 if (pDevice->aStreamSource[stream] && pDevice->aStreamSource[stream]->LockInfo.cLocks)
1869 {
1870 VBOXWDDMDISP_LOCKINFO *pLock = &pDevice->aStreamSource[stream]->LockInfo;
1871 if (pLock->fFlags.MightDrawFromLocked && (pLock->fFlags.Discard || pLock->fFlags.NoOverwrite))
1872 {
1873 IDirect3DVertexBuffer9 *pD3D9VBuf = (IDirect3DVertexBuffer9*)pDevice->aStreamSource[stream]->pD3DIf;
1874 Assert(pLock->fFlags.RangeValid);
1875 pD3D9VBuf->Lock(pLock->Range.Offset, pLock->Range.Size,
1876 &pLock->LockedRect.pBits,
1877 vboxDDI2D3DLockFlags(pLock->fFlags));
1878 RECT r;
1879 r.top = 0;
1880 r.left = pLock->Range.Offset;
1881 r.bottom = 1;
1882 r.right = pLock->Range.Offset + pLock->Range.Size;
1883
1884 vboxWddmLockUnlockMemSynch(pDevice->aStreamSource[stream], &pLock->LockedRect, &r, true /*bool bToLockInfo*/);
1885
1886 pD3D9VBuf->Unlock();
1887 }
1888 }
1889 }
1890
1891 hr = pDevice->pDevice9If->DrawPrimitive(pData->PrimitiveType, pData->FirstVertexOffset, pData->PrimitiveCount);
1892#else
1893 int stream;
1894 for (stream=0; stream<VBOXWDDMDISP_MAX_VERTEX_STREAMS; ++stream)
1895 {
1896 if (pDevice->aStreamSource[stream])
1897 {
1898 Assert(stream==0); /*only stream 0 should be accessed here*/
1899 Assert(pDevice->StreamSourceInfo[stream].uiStride!=0);
1900 VBOXWDDMDISP_LOCKINFO *pLock = &pDevice->aStreamSource[stream]->LockInfo;
1901
1902 if (pDevice->aStreamSource[stream]->LockInfo.cLocks)
1903 {
1904 Assert(pLock->fFlags.MightDrawFromLocked && (pLock->fFlags.Discard || pLock->fFlags.NoOverwrite));
1905 hr = pDevice->pDevice9If->DrawPrimitiveUP(pData->PrimitiveType, pData->PrimitiveCount,
1906 (void*)((uintptr_t)pDevice->aStreamSource[stream]->pvMem+pDevice->StreamSourceInfo[stream].uiOffset+pData->FirstVertexOffset),
1907 pDevice->StreamSourceInfo[stream].uiStride);
1908 Assert(hr == S_OK);
1909 hr = pDevice->pDevice9If->SetStreamSource(stream, (IDirect3DVertexBuffer9*)pDevice->aStreamSource[stream]->pD3DIf, pDevice->StreamSourceInfo[stream].uiOffset, pDevice->StreamSourceInfo[stream].uiStride);
1910 }
1911 else
1912 {
1913 hr = pDevice->pDevice9If->DrawPrimitive(pData->PrimitiveType, pData->FirstVertexOffset/pDevice->StreamSourceInfo[stream].uiStride, pData->PrimitiveCount);
1914 }
1915 }
1916 }
1917#endif
1918
1919 Assert(hr == S_OK);
1920 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
1921 return hr;
1922}
1923
1924static HRESULT APIENTRY vboxWddmDDevDrawIndexedPrimitive2(HANDLE hDevice, CONST D3DDDIARG_DRAWINDEXEDPRIMITIVE2* pData, UINT dwIndicesSize, CONST VOID* pIndexBuffer, CONST UINT* pFlagBuffer)
1925{
1926 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
1927 AssertBreakpoint();
1928 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
1929 return E_FAIL;
1930}
1931
1932static HRESULT APIENTRY vboxWddmDDevVolBlt(HANDLE hDevice, CONST D3DDDIARG_VOLUMEBLT* pData)
1933{
1934 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
1935 AssertBreakpoint();
1936 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
1937 return E_FAIL;
1938}
1939
1940static HRESULT APIENTRY vboxWddmDDevBufBlt(HANDLE hDevice, CONST D3DDDIARG_BUFFERBLT* pData)
1941{
1942 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
1943 AssertBreakpoint();
1944 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
1945 return E_FAIL;
1946}
1947
1948static HRESULT APIENTRY vboxWddmDDevTexBlt(HANDLE hDevice, CONST D3DDDIARG_TEXBLT* pData)
1949{
1950 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
1951 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
1952 Assert(pDevice);
1953 Assert(pDevice->pDevice9If);
1954 PVBOXWDDMDISP_RESOURCE pDstRc = (PVBOXWDDMDISP_RESOURCE)pData->hDstResource;
1955 PVBOXWDDMDISP_RESOURCE pSrcRc = (PVBOXWDDMDISP_RESOURCE)pData->hSrcResource;
1956 IDirect3DTexture9 *pD3DIfSrcTex = (IDirect3DTexture9*)pSrcRc->aAllocations[0].pD3DIf;
1957 IDirect3DTexture9 *pD3DIfDstTex = (IDirect3DTexture9*)pDstRc->aAllocations[0].pD3DIf;
1958 Assert(pD3DIfSrcTex);
1959 Assert(pD3DIfDstTex);
1960 HRESULT hr = S_OK;
1961
1962 if (pSrcRc->aAllocations[0].SurfDesc.width == pDstRc->aAllocations[0].SurfDesc.width
1963 && pSrcRc->aAllocations[0].SurfDesc.height == pDstRc->aAllocations[0].SurfDesc.height
1964 && pSrcRc->RcDesc.enmFormat == pDstRc->RcDesc.enmFormat)
1965 {
1966 /* first check if we can do IDirect3DDevice9::UpdateTexture */
1967 if (pData->DstPoint.x == 0 && pData->DstPoint.y == 0
1968 && pData->SrcRect.left == 0 && pData->SrcRect.top == 0
1969 && pData->SrcRect.right - pData->SrcRect.left == pSrcRc->aAllocations[0].SurfDesc.width
1970 && pData->SrcRect.bottom - pData->SrcRect.top == pSrcRc->aAllocations[0].SurfDesc.height)
1971 {
1972 hr = pDevice->pDevice9If->UpdateTexture(pD3DIfSrcTex, pD3DIfDstTex);
1973 Assert(hr == S_OK);
1974 }
1975 else
1976 {
1977 AssertBreakpoint();
1978 /* @todo: impl */
1979 }
1980 }
1981 else
1982 {
1983 AssertBreakpoint();
1984 /* @todo: impl */
1985 }
1986
1987 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
1988 return hr;
1989}
1990
1991static HRESULT APIENTRY vboxWddmDDevStateSet(HANDLE hDevice, D3DDDIARG_STATESET* pData)
1992{
1993 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
1994 AssertBreakpoint();
1995 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
1996 return E_FAIL;
1997}
1998static HRESULT APIENTRY vboxWddmDDevSetPriority(HANDLE hDevice, CONST D3DDDIARG_SETPRIORITY* pData)
1999{
2000 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
2001 AssertBreakpoint();
2002 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
2003 return E_FAIL;
2004}
2005AssertCompile(sizeof (RECT) == sizeof (D3DRECT));
2006AssertCompile(RT_SIZEOFMEMB(RECT, left) == RT_SIZEOFMEMB(D3DRECT, x1));
2007AssertCompile(RT_SIZEOFMEMB(RECT, right) == RT_SIZEOFMEMB(D3DRECT, x2));
2008AssertCompile(RT_SIZEOFMEMB(RECT, top) == RT_SIZEOFMEMB(D3DRECT, y1));
2009AssertCompile(RT_SIZEOFMEMB(RECT, bottom) == RT_SIZEOFMEMB(D3DRECT, y2));
2010AssertCompile(RT_OFFSETOF(RECT, left) == RT_OFFSETOF(D3DRECT, x1));
2011AssertCompile(RT_OFFSETOF(RECT, right) == RT_OFFSETOF(D3DRECT, x2));
2012AssertCompile(RT_OFFSETOF(RECT, top) == RT_OFFSETOF(D3DRECT, y1));
2013AssertCompile(RT_OFFSETOF(RECT, bottom) == RT_OFFSETOF(D3DRECT, y2));
2014
2015static HRESULT APIENTRY vboxWddmDDevClear(HANDLE hDevice, CONST D3DDDIARG_CLEAR* pData, UINT NumRect, CONST RECT* pRect)
2016{
2017 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
2018 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
2019 Assert(pDevice);
2020 Assert(pDevice->pDevice9If);
2021 HRESULT hr = pDevice->pDevice9If->Clear(NumRect, (D3DRECT*)pRect /* see AssertCompile above */,
2022 pData->Flags,
2023 pData->FillColor,
2024 pData->FillDepth,
2025 pData->FillStencil);
2026 Assert(hr == S_OK);
2027 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
2028 return hr;
2029}
2030static HRESULT APIENTRY vboxWddmDDevUpdatePalette(HANDLE hDevice, CONST D3DDDIARG_UPDATEPALETTE* pData, CONST PALETTEENTRY* pPaletteData)
2031{
2032 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
2033 AssertBreakpoint();
2034 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
2035 return E_FAIL;
2036}
2037
2038static HRESULT APIENTRY vboxWddmDDevSetPalette(HANDLE hDevice, CONST D3DDDIARG_SETPALETTE* pData)
2039{
2040 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
2041 AssertBreakpoint();
2042 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
2043 return E_FAIL;
2044}
2045
2046static HRESULT APIENTRY vboxWddmDDevSetVertexShaderConst(HANDLE hDevice, CONST D3DDDIARG_SETVERTEXSHADERCONST* pData , CONST VOID* pRegisters)
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->SetVertexShaderConstantF(
2053 pData->Register,
2054 (CONST float*)pRegisters,
2055 pData->Count);
2056 Assert(hr == S_OK);
2057 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
2058 return hr;
2059}
2060static HRESULT APIENTRY vboxWddmDDevMultiplyTransform(HANDLE hDevice, CONST D3DDDIARG_MULTIPLYTRANSFORM* pData)
2061{
2062 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
2063 AssertBreakpoint();
2064 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
2065 return E_FAIL;
2066}
2067static HRESULT APIENTRY vboxWddmDDevSetTransform(HANDLE hDevice, CONST D3DDDIARG_SETTRANSFORM* pData)
2068{
2069 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
2070 AssertBreakpoint();
2071 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
2072 return E_FAIL;
2073}
2074static HRESULT APIENTRY vboxWddmDDevSetViewport(HANDLE hDevice, CONST D3DDDIARG_VIEWPORTINFO* pData)
2075{
2076 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
2077 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
2078 Assert(pDevice);
2079 Assert(pDevice->pDevice9If);
2080 pDevice->ViewPort.X = pData->X;
2081 pDevice->ViewPort.Y = pData->Y;
2082 pDevice->ViewPort.Width = pData->Width;
2083 pDevice->ViewPort.Height = pData->Height;
2084 HRESULT hr = pDevice->pDevice9If->SetViewport(&pDevice->ViewPort);
2085 Assert(hr == S_OK);
2086 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
2087 return hr;
2088}
2089static HRESULT APIENTRY vboxWddmDDevSetZRange(HANDLE hDevice, CONST D3DDDIARG_ZRANGE* pData)
2090{
2091 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
2092 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
2093 Assert(pDevice);
2094 Assert(pDevice->pDevice9If);
2095 pDevice->ViewPort.MinZ = pData->MinZ;
2096 pDevice->ViewPort.MaxZ = pData->MaxZ;
2097 HRESULT hr = pDevice->pDevice9If->SetViewport(&pDevice->ViewPort);
2098 Assert(hr == S_OK);
2099 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
2100 return hr;
2101}
2102static HRESULT APIENTRY vboxWddmDDevSetMaterial(HANDLE hDevice, CONST D3DDDIARG_SETMATERIAL* pData)
2103{
2104 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
2105 AssertBreakpoint();
2106 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
2107 return E_FAIL;
2108}
2109static HRESULT APIENTRY vboxWddmDDevSetLight(HANDLE hDevice, CONST D3DDDIARG_SETLIGHT* pData, CONST D3DDDI_LIGHT* pLightProperties)
2110{
2111 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
2112 AssertBreakpoint();
2113 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
2114 return E_FAIL;
2115}
2116static HRESULT APIENTRY vboxWddmDDevCreateLight(HANDLE hDevice, CONST D3DDDIARG_CREATELIGHT* pData)
2117{
2118 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
2119 AssertBreakpoint();
2120 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
2121 return E_FAIL;
2122}
2123static HRESULT APIENTRY vboxWddmDDevDestroyLight(HANDLE hDevice, CONST D3DDDIARG_DESTROYLIGHT* pData)
2124{
2125 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
2126 AssertBreakpoint();
2127 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
2128 return E_FAIL;
2129}
2130static HRESULT APIENTRY vboxWddmDDevSetClipPlane(HANDLE hDevice, CONST D3DDDIARG_SETCLIPPLANE* pData)
2131{
2132 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
2133 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
2134 Assert(pDevice);
2135 Assert(pDevice->pDevice9If);
2136 HRESULT hr = pDevice->pDevice9If->SetClipPlane(pData->Index, pData->Plane);
2137 Assert(hr == S_OK);
2138 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
2139 return hr;
2140}
2141
2142static HRESULT APIENTRY vboxWddmDDevGetInfo(HANDLE hDevice, UINT DevInfoID, VOID* pDevInfoStruct, UINT DevInfoSize)
2143{
2144 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
2145 AssertBreakpoint();
2146 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
2147 return E_NOTIMPL;
2148}
2149
2150static HRESULT APIENTRY vboxWddmDDevLock(HANDLE hDevice, D3DDDIARG_LOCK* pData)
2151{
2152 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
2153 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
2154 PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)pData->hResource;
2155 Assert(pData->SubResourceIndex < pRc->cAllocations);
2156 if (pData->SubResourceIndex >= pRc->cAllocations)
2157 return E_INVALIDARG;
2158
2159 HRESULT hr = S_OK;
2160
2161 if (VBOXDISPMODE_IS_3D(pDevice->pAdapter))
2162 {
2163 if (pRc->RcDesc.fFlags.Texture)
2164 {
2165 PVBOXWDDMDISP_ALLOCATION pTexAlloc = &pRc->aAllocations[0];
2166 Assert(pData->SubResourceIndex < pRc->cAllocations);
2167 PVBOXWDDMDISP_ALLOCATION pLockAlloc = &pRc->aAllocations[pData->SubResourceIndex];
2168 IDirect3DTexture9 *pD3DIfTex = (IDirect3DTexture9*)pTexAlloc->pD3DIf;
2169 Assert(pD3DIfTex);
2170 RECT *pRect = NULL;
2171 bool bNeedResynch = false;
2172 Assert(!pData->Flags.RangeValid);
2173 Assert(!pData->Flags.BoxValid);
2174 if (pData->Flags.AreaValid)
2175 {
2176 pRect = &pData->Area;
2177 }
2178
2179 /* else - we lock the entire texture, pRect == NULL */
2180
2181// Assert(!pLockAlloc->LockInfo.cLocks);
2182 if (!pLockAlloc->LockInfo.cLocks)
2183 {
2184 hr = pD3DIfTex->LockRect(pData->SubResourceIndex,
2185 &pLockAlloc->LockInfo.LockedRect,
2186 pRect,
2187 vboxDDI2D3DLockFlags(pData->Flags));
2188 Assert(hr == S_OK);
2189 if (hr == S_OK)
2190 {
2191
2192// Assert(pLockAlloc->LockInfo.fFlags.Value == 0);
2193 pLockAlloc->LockInfo.fFlags = pData->Flags;
2194 if (pRect)
2195 {
2196 pLockAlloc->LockInfo.Area = *pRect;
2197 Assert(pLockAlloc->LockInfo.fFlags.AreaValid == 1);
2198// pLockAlloc->LockInfo.fFlags.AreaValid = 1;
2199 }
2200 else
2201 {
2202 Assert(pLockAlloc->LockInfo.fFlags.AreaValid == 0);
2203// pLockAlloc->LockInfo.fFlags.AreaValid = 0;
2204 }
2205
2206 bNeedResynch = !pData->Flags.Discard;
2207 }
2208 }
2209 else
2210 {
2211// Assert(pLockAlloc->LockInfo.fFlags.Value == pData->Flags.Value);
2212// if (pLockAlloc->LockInfo.fFlags.Value != pData->Flags.Value)
2213// {
2214// }
2215 Assert(pLockAlloc->LockInfo.fFlags.AreaValid == pData->Flags.AreaValid);
2216 if (pLockAlloc->LockInfo.fFlags.AreaValid && pData->Flags.AreaValid)
2217 {
2218 Assert(pLockAlloc->LockInfo.Area.left == pData->Area.left);
2219 Assert(pLockAlloc->LockInfo.Area.top == pData->Area.top);
2220 Assert(pLockAlloc->LockInfo.Area.right == pData->Area.right);
2221 Assert(pLockAlloc->LockInfo.Area.bottom == pData->Area.bottom);
2222 }
2223 Assert(pLockAlloc->LockInfo.LockedRect.pBits);
2224
2225 bNeedResynch = pLockAlloc->LockInfo.fFlags.Discard && !pData->Flags.Discard;
2226
2227 Assert(!bNeedResynch);
2228
2229 if (/*(pLockAlloc->LockInfo.fFlags.Discard && !pData->Flags.Discard)
2230 || */
2231 (pLockAlloc->LockInfo.fFlags.ReadOnly && !pData->Flags.ReadOnly))
2232 {
2233 hr = pD3DIfTex->UnlockRect(pData->SubResourceIndex);
2234 Assert(hr == S_OK);
2235 if (hr == S_OK)
2236 {
2237 hr = pD3DIfTex->LockRect(pData->SubResourceIndex,
2238 &pLockAlloc->LockInfo.LockedRect,
2239 pRect,
2240 vboxDDI2D3DLockFlags(pData->Flags));
2241 Assert(hr == S_OK);
2242 pLockAlloc->LockInfo.fFlags.ReadOnly = 0;
2243 }
2244 }
2245 }
2246
2247 if (hr == S_OK)
2248 {
2249 ++pLockAlloc->LockInfo.cLocks;
2250
2251 if (!pData->Flags.NotifyOnly)
2252 {
2253 pData->pSurfData = pLockAlloc->LockInfo.LockedRect.pBits;
2254 pData->Pitch = pLockAlloc->LockInfo.LockedRect.Pitch;
2255 pData->SlicePitch = 0;
2256 Assert(pLockAlloc->SurfDesc.slicePitch == 0);
2257 Assert(!pLockAlloc->pvMem);
2258 }
2259 else
2260 {
2261 Assert(pLockAlloc->pvMem);
2262 Assert(pRc->RcDesc.enmPool == D3DDDIPOOL_SYSTEMMEM);
2263
2264 if (bNeedResynch)
2265 vboxWddmLockUnlockMemSynch(pLockAlloc, &pLockAlloc->LockInfo.LockedRect, pRect, false /*bool bToLockInfo*/);
2266 }
2267 }
2268 }
2269 else if (pRc->RcDesc.fFlags.VertexBuffer)
2270 {
2271 Assert(pData->SubResourceIndex < pRc->cAllocations);
2272 PVBOXWDDMDISP_ALLOCATION pAlloc = &pRc->aAllocations[pData->SubResourceIndex];
2273 IDirect3DVertexBuffer9 *pD3D9VBuf = (IDirect3DVertexBuffer9*)pAlloc->pD3DIf;
2274 BOOL bLocked = false;
2275 Assert(pD3D9VBuf);
2276 Assert(!pData->Flags.AreaValid);
2277 Assert(!pData->Flags.BoxValid);
2278 D3DDDIRANGE *pRange = NULL;
2279 if (pData->Flags.RangeValid)
2280 {
2281 pRange = &pData->Range;
2282 }
2283
2284 /* else - we lock the entire vertex buffer, pRect == NULL */
2285
2286 Assert(!pAlloc->LockInfo.cLocks);
2287 if (!pAlloc->LockInfo.cLocks)
2288 {
2289 if (!pData->Flags.MightDrawFromLocked || (!pData->Flags.Discard && !pData->Flags.NoOverwrite))
2290 {
2291 hr = pD3D9VBuf->Lock(pRange ? pRange->Offset : 0,
2292 pRange ? pRange->Size : 0,
2293 &pAlloc->LockInfo.LockedRect.pBits,
2294 vboxDDI2D3DLockFlags(pData->Flags));
2295 bLocked = true;
2296 }
2297
2298 Assert(hr == S_OK);
2299 if (hr == S_OK)
2300 {
2301 pAlloc->LockInfo.LockedRect.Pitch = pAlloc->SurfDesc.width;
2302// Assert(pLockAlloc->LockInfo.fFlags.Value == 0);
2303 pAlloc->LockInfo.fFlags = pData->Flags;
2304 if (pRange)
2305 {
2306 pAlloc->LockInfo.Range = *pRange;
2307 Assert(pAlloc->LockInfo.fFlags.RangeValid == 1);
2308// pAlloc->LockInfo.fFlags.RangeValid = 1;
2309 }
2310 else
2311 {
2312 Assert(pAlloc->LockInfo.fFlags.RangeValid == 0);
2313// pAlloc->LockInfo.fFlags.RangeValid = 0;
2314 }
2315 }
2316 }
2317 else
2318 {
2319// Assert(pAlloc->LockInfo.fFlags.Value == pData->Flags.Value);
2320// if (pAlloc->LockInfo.fFlags.Value != pData->Flags.Value)
2321// {
2322// }
2323 Assert(pAlloc->LockInfo.fFlags.RangeValid == pData->Flags.RangeValid);
2324 if (pAlloc->LockInfo.fFlags.RangeValid && pData->Flags.RangeValid)
2325 {
2326 Assert(pAlloc->LockInfo.Range.Offset == pData->Range.Offset);
2327 Assert(pAlloc->LockInfo.Range.Size == pData->Range.Size);
2328 }
2329 Assert(pAlloc->LockInfo.LockedRect.pBits);
2330 }
2331
2332 if (hr == S_OK)
2333 {
2334 ++pAlloc->LockInfo.cLocks;
2335
2336 if (!pData->Flags.NotifyOnly)
2337 {
2338 pData->pSurfData = pAlloc->LockInfo.LockedRect.pBits;
2339 pData->Pitch = pAlloc->LockInfo.LockedRect.Pitch;
2340 pData->SlicePitch = 0;
2341 Assert(pAlloc->SurfDesc.slicePitch == 0);
2342 Assert(!pAlloc->pvMem);
2343 }
2344 else
2345 {
2346 Assert(pAlloc->pvMem);
2347 Assert(pRc->RcDesc.enmPool == D3DDDIPOOL_SYSTEMMEM);
2348 if (bLocked && !pData->Flags.Discard)
2349 {
2350 RECT r, *pr;
2351 if (pRange)
2352 {
2353 r.top = 0;
2354 r.left = pRange->Offset;
2355 r.bottom = 1;
2356 r.right = pRange->Offset + pRange->Size;
2357 pr = &r;
2358 }
2359 else
2360 pr = NULL;
2361 vboxWddmLockUnlockMemSynch(pAlloc, &pAlloc->LockInfo.LockedRect, pr, false /*bool bToLockInfo*/);
2362 }
2363 }
2364 }
2365 }
2366 else
2367 {
2368 AssertBreakpoint();
2369 }
2370 }
2371 else
2372 {
2373 PVBOXWDDMDISP_ALLOCATION pAlloc = &pRc->aAllocations[pData->SubResourceIndex];
2374 D3DDDICB_LOCK LockData;
2375 LockData.hAllocation = pAlloc->hAllocation;
2376 LockData.PrivateDriverData = 0;
2377 LockData.NumPages = 0;
2378 LockData.pPages = NULL;
2379 LockData.pData = NULL; /* out */
2380 LockData.Flags.Value = 0;
2381 LockData.Flags.Discard = pData->Flags.Discard;
2382 LockData.Flags.DonotWait = pData->Flags.DoNotWait;
2383
2384
2385 hr = pDevice->RtCallbacks.pfnLockCb(pDevice->hDevice, &LockData);
2386 Assert(hr == S_OK || (hr == D3DERR_WASSTILLDRAWING && pData->Flags.DoNotWait));
2387 if (hr == S_OK)
2388 {
2389 Assert(!pAlloc->LockInfo.cLocks);
2390
2391 uintptr_t offset;
2392 if (pData->Flags.AreaValid)
2393 {
2394 offset = pAlloc->SurfDesc.pitch * pData->Area.top +
2395 ((pAlloc->SurfDesc.bpp * pData->Area.left) >> 3);
2396 }
2397 else if (pData->Flags.RangeValid)
2398 {
2399 offset = pData->Range.Offset;
2400 }
2401 else if (pData->Flags.BoxValid)
2402 {
2403 vboxVDbgPrintF((__FUNCTION__": Implement Box area"));
2404 AssertBreakpoint();
2405 }
2406 else
2407 {
2408 offset = 0;
2409 }
2410
2411 if (!pData->Flags.ReadOnly)
2412 {
2413 if (pData->Flags.AreaValid)
2414 vboxWddmDirtyRegionAddRect(&pAlloc->DirtyRegion, &pData->Area);
2415 else
2416 {
2417 Assert(!pData->Flags.RangeValid);
2418 Assert(!pData->Flags.BoxValid);
2419 vboxWddmDirtyRegionAddRect(&pAlloc->DirtyRegion, NULL); /* <- NULL means the entire surface */
2420 }
2421 }
2422
2423 if (pData->Flags.Discard)
2424 {
2425 /* check if the surface was renamed */
2426 if (LockData.hAllocation)
2427 pAlloc->hAllocation = LockData.hAllocation;
2428 }
2429
2430 pData->pSurfData = ((uint8_t*)LockData.pData) + offset;
2431 pData->Pitch = pAlloc->SurfDesc.pitch;
2432 pData->SlicePitch = pAlloc->SurfDesc.slicePitch;
2433
2434 Assert(hr == S_OK);
2435 ++pAlloc->LockInfo.cLocks;
2436 }
2437 }
2438
2439 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(%d)\n", hDevice, hr));
2440 return hr;
2441}
2442static HRESULT APIENTRY vboxWddmDDevUnlock(HANDLE hDevice, CONST D3DDDIARG_UNLOCK* pData)
2443{
2444 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
2445 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
2446 PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)pData->hResource;
2447 HRESULT hr = S_OK;
2448
2449 Assert(pData->SubResourceIndex < pRc->cAllocations);
2450 if (pData->SubResourceIndex >= pRc->cAllocations)
2451 return E_INVALIDARG;
2452
2453 if (VBOXDISPMODE_IS_3D(pDevice->pAdapter))
2454 {
2455 if (pRc->RcDesc.fFlags.Texture)
2456 {
2457 Assert(pData->SubResourceIndex < pRc->cAllocations);
2458 PVBOXWDDMDISP_ALLOCATION pLockAlloc = &pRc->aAllocations[pData->SubResourceIndex];
2459
2460 --pLockAlloc->LockInfo.cLocks;
2461 Assert(pLockAlloc->LockInfo.cLocks < UINT32_MAX);
2462// pLockAlloc->LockInfo.cLocks = 0;
2463 if (!pLockAlloc->LockInfo.cLocks)
2464 {
2465 PVBOXWDDMDISP_ALLOCATION pTexAlloc = &pRc->aAllocations[0];
2466// Assert(!pLockAlloc->LockInfo.cLocks);
2467 IDirect3DTexture9 *pD3DIfTex = (IDirect3DTexture9*)pTexAlloc->pD3DIf;
2468 Assert(pD3DIfTex);
2469 /* this is a sysmem texture, update */
2470 if (pLockAlloc->pvMem && !pLockAlloc->LockInfo.fFlags.ReadOnly)
2471 {
2472 vboxWddmLockUnlockMemSynch(pLockAlloc, &pLockAlloc->LockInfo.LockedRect,
2473 pLockAlloc->LockInfo.fFlags.AreaValid ? &pLockAlloc->LockInfo.Area : NULL,
2474 true /*bool bToLockInfo*/);
2475 }
2476 hr = pD3DIfTex->UnlockRect(pData->SubResourceIndex);
2477 Assert(hr == S_OK);
2478 }
2479 else
2480 {
2481 Assert(pLockAlloc->LockInfo.cLocks < UINT32_MAX);
2482 }
2483 }
2484 else if (pRc->RcDesc.fFlags.VertexBuffer)
2485 {
2486 Assert(pData->SubResourceIndex < pRc->cAllocations);
2487 PVBOXWDDMDISP_ALLOCATION pAlloc = &pRc->aAllocations[pData->SubResourceIndex];
2488
2489 --pAlloc->LockInfo.cLocks;
2490 Assert(pAlloc->LockInfo.cLocks < UINT32_MAX);
2491 if (!pAlloc->LockInfo.cLocks
2492 && (!pAlloc->LockInfo.fFlags.MightDrawFromLocked
2493 || (!pAlloc->LockInfo.fFlags.Discard && !pAlloc->LockInfo.fFlags.NoOverwrite)))
2494 {
2495// Assert(!pAlloc->LockInfo.cLocks);
2496 IDirect3DVertexBuffer9 *pD3D9VBuf = (IDirect3DVertexBuffer9*)pAlloc->pD3DIf;
2497 Assert(pD3D9VBuf);
2498 /* this is a sysmem texture, update */
2499 if (pAlloc->pvMem && !pAlloc->LockInfo.fFlags.ReadOnly)
2500 {
2501 RECT r, *pr;
2502 if (pAlloc->LockInfo.fFlags.RangeValid)
2503 {
2504 r.top = 0;
2505 r.left = pAlloc->LockInfo.Range.Offset;
2506 r.bottom = 1;
2507 r.right = pAlloc->LockInfo.Range.Offset + pAlloc->LockInfo.Range.Size;
2508 pr = &r;
2509 }
2510 else
2511 pr = NULL;
2512 vboxWddmLockUnlockMemSynch(pAlloc, &pAlloc->LockInfo.LockedRect,
2513 pr,
2514 true /*bool bToLockInfo*/);
2515 }
2516 hr = pD3D9VBuf->Unlock();
2517 Assert(hr == S_OK);
2518 }
2519 else
2520 {
2521 Assert(pAlloc->LockInfo.cLocks < UINT32_MAX);
2522 }
2523 }
2524 else
2525 {
2526 AssertBreakpoint();
2527 }
2528 }
2529 else
2530 {
2531 struct
2532 {
2533 D3DDDICB_UNLOCK Unlock;
2534 D3DKMT_HANDLE hAllocation;
2535 } UnlockData;
2536
2537 PVBOXWDDMDISP_ALLOCATION pAlloc = &pRc->aAllocations[pData->SubResourceIndex];
2538
2539 UnlockData.Unlock.NumAllocations = 1;
2540 UnlockData.Unlock.phAllocations = &UnlockData.hAllocation;
2541 UnlockData.hAllocation = pAlloc->hAllocation;
2542
2543 hr = pDevice->RtCallbacks.pfnUnlockCb(pDevice->hDevice, &UnlockData.Unlock);
2544 Assert(hr == S_OK);
2545 if (hr == S_OK)
2546 {
2547 Assert(pAlloc->LockInfo.cLocks);
2548 --pAlloc->LockInfo.cLocks;
2549 Assert(pAlloc->LockInfo.cLocks < UINT32_MAX);
2550 }
2551 }
2552
2553 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
2554 return hr;
2555}
2556static HRESULT APIENTRY vboxWddmDDevLockAsync(HANDLE hDevice, D3DDDIARG_LOCKASYNC* pData)
2557{
2558 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
2559 AssertBreakpoint();
2560 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
2561 return E_FAIL;
2562}
2563static HRESULT APIENTRY vboxWddmDDevUnlockAsync(HANDLE hDevice, CONST D3DDDIARG_UNLOCKASYNC* pData)
2564{
2565 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
2566 AssertBreakpoint();
2567 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
2568 return E_FAIL;
2569}
2570static HRESULT APIENTRY vboxWddmDDevRename(HANDLE hDevice, CONST D3DDDIARG_RENAME* pData)
2571{
2572 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
2573 AssertBreakpoint();
2574 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
2575 return E_FAIL;
2576}
2577
2578static void vboxWddmRequestAllocFree(D3DDDICB_ALLOCATE* pAlloc)
2579{
2580 RTMemFree(pAlloc);
2581}
2582
2583static D3DDDICB_ALLOCATE* vboxWddmRequestAllocAlloc(D3DDDIARG_CREATERESOURCE* pResource)
2584{
2585 /* allocate buffer for D3DDDICB_ALLOCATE + D3DDDI_ALLOCATIONINFO * numAllocs + PVBOXWDDM_RCINFO with aAllocInfos[numAllocs] */
2586 uint32_t cbBuf = sizeof (D3DDDICB_ALLOCATE);
2587 uint32_t offDdiAllocInfos = (cbBuf + 7) & ~3;
2588 uint32_t cbDdiAllocInfos = sizeof (D3DDDI_ALLOCATIONINFO) * pResource->SurfCount;
2589 cbBuf = offDdiAllocInfos + cbDdiAllocInfos;
2590 uint32_t offRcInfo = (cbBuf + 7) & ~3;
2591 uint32_t cbRcInfo = sizeof (VBOXWDDM_RCINFO);
2592 cbBuf = offRcInfo + cbRcInfo;
2593 uint32_t offAllocInfos = (cbBuf + 7) & ~3;
2594 uint32_t cbAllocInfos = sizeof (VBOXWDDM_ALLOCINFO) * pResource->SurfCount;
2595 cbBuf = offAllocInfos + cbAllocInfos;
2596 uint8_t *pvBuf = (uint8_t*)RTMemAllocZ(cbBuf);
2597 Assert(pvBuf);
2598 if (pvBuf)
2599 {
2600 D3DDDICB_ALLOCATE* pAlloc = (D3DDDICB_ALLOCATE*)pvBuf;
2601 pAlloc->NumAllocations = pResource->SurfCount;
2602 pAlloc->pAllocationInfo = (D3DDDI_ALLOCATIONINFO*)(pvBuf + offDdiAllocInfos);
2603 PVBOXWDDM_RCINFO pRcInfo = (PVBOXWDDM_RCINFO)(pvBuf + offRcInfo);
2604 pAlloc->PrivateDriverDataSize = cbRcInfo;
2605 pAlloc->pPrivateDriverData = pRcInfo;
2606 pAlloc->hResource = pResource->hResource;
2607 PVBOXWDDM_ALLOCINFO pAllocInfos = (PVBOXWDDM_ALLOCINFO)(pvBuf + offAllocInfos);
2608 for (UINT i = 0; i < pResource->SurfCount; ++i)
2609 {
2610 D3DDDI_ALLOCATIONINFO* pDdiAllocInfo = &pAlloc->pAllocationInfo[i];
2611 PVBOXWDDM_ALLOCINFO pAllocInfo = &pAllocInfos[i];
2612 pDdiAllocInfo->pPrivateDriverData = pAllocInfo;
2613 pDdiAllocInfo->PrivateDriverDataSize = sizeof (VBOXWDDM_ALLOCINFO);
2614 }
2615 return pAlloc;
2616 }
2617 return NULL;
2618}
2619static HRESULT APIENTRY vboxWddmDDevCreateResource(HANDLE hDevice, D3DDDIARG_CREATERESOURCE* pResource)
2620{
2621 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
2622 HRESULT hr = S_OK;
2623 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
2624 Assert(pDevice);
2625 Assert(pResource);
2626 PVBOXWDDMDISP_ADAPTER pAdapter = pDevice->pAdapter;
2627
2628 PVBOXWDDMDISP_RESOURCE pRc = vboxResourceAlloc(pResource->SurfCount);
2629 Assert(pRc);
2630 if (pRc)
2631 {
2632 bool bIssueCreateResource = false;
2633
2634 pRc->hResource = pResource->hResource;
2635 pRc->hKMResource = NULL;
2636 pRc->pDevice = pDevice;
2637 pRc->fFlags = VBOXWDDM_RESOURCE_F_TYPE_GENERIC;
2638 pRc->RcDesc.fFlags = pResource->Flags;
2639 pRc->RcDesc.enmFormat = pResource->Format;
2640 pRc->RcDesc.enmPool = pResource->Pool;
2641 pRc->RcDesc.enmMultisampleType = pResource->MultisampleType;
2642 pRc->RcDesc.MultisampleQuality = pResource->MultisampleQuality;
2643 pRc->RcDesc.MipLevels = pResource->MipLevels;
2644 pRc->RcDesc.Fvf = pResource->Fvf;
2645 pRc->RcDesc.VidPnSourceId = pResource->VidPnSourceId;
2646 pRc->RcDesc.RefreshRate = pResource->RefreshRate;
2647 pRc->RcDesc.enmRotation = pResource->Rotation;
2648 pRc->cAllocations = pResource->SurfCount;
2649 for (UINT i = 0; i < pResource->SurfCount; ++i)
2650 {
2651 PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[i];
2652 CONST D3DDDI_SURFACEINFO* pSurf = &pResource->pSurfList[i];
2653 pAllocation->hAllocation = NULL;
2654 pAllocation->enmType = VBOXWDDM_ALLOC_TYPE_UMD_RC_GENERIC;
2655 pAllocation->pvMem = (void*)pSurf->pSysMem;
2656 pAllocation->SurfDesc.pitch = pSurf->SysMemPitch;
2657 pAllocation->SurfDesc.slicePitch = pSurf->SysMemSlicePitch;
2658 pAllocation->SurfDesc.depth = pSurf->Depth;
2659 pAllocation->SurfDesc.width = pSurf->Width;
2660 pAllocation->SurfDesc.height = pSurf->Height;
2661 pAllocation->SurfDesc.format = pResource->Format;
2662 }
2663
2664 if (VBOXDISPMODE_IS_3D(pAdapter))
2665 {
2666 if (pResource->Flags.RenderTarget)
2667 {
2668 HWND hWnd = NULL;
2669 Assert(pResource->SurfCount);
2670 Assert(!pDevice->pDevice9If);
2671 Assert(!pDevice->hWnd);
2672 bIssueCreateResource = true;
2673 hr = VBoxDispWndCreate(pAdapter, pResource->pSurfList[0].Width, pResource->pSurfList[0].Height, &hWnd);
2674 Assert(hr == S_OK);
2675 if (hr == S_OK)
2676 {
2677 DWORD fFlags = D3DCREATE_HARDWARE_VERTEXPROCESSING;
2678 if (pDevice->fFlags.AllowMultithreading)
2679 fFlags |= D3DCREATE_MULTITHREADED;
2680
2681 IDirect3DDevice9 *pDevice9If = NULL;
2682 D3DPRESENT_PARAMETERS params;
2683 memset(&params, 0, sizeof (params));
2684 // params.BackBufferWidth = 0;
2685 // params.BackBufferHeight = 0;
2686 params.BackBufferFormat = vboxDDI2D3DFormat(pResource->Format);
2687 Assert(pResource->SurfCount);
2688 params.BackBufferCount = pResource->SurfCount - 1;
2689 params.MultiSampleType = vboxDDI2D3DMultiSampleType(pResource->MultisampleType);
2690 if (pResource->Flags.DiscardRenderTarget)
2691 params.SwapEffect = D3DSWAPEFFECT_DISCARD;
2692 params.hDeviceWindow = hWnd;
2693 /* @todo: it seems there should be a way to detect this correctly since
2694 * our vboxWddmDDevSetDisplayMode will be called in case we are using full-screen */
2695 params.Windowed = TRUE;
2696 // params.EnableAutoDepthStencil = FALSE;
2697 // params.AutoDepthStencilFormat = D3DFMT_UNKNOWN;
2698 // params.Flags;
2699 // params.FullScreen_RefreshRateInHz;
2700 // params.FullScreen_PresentationInterval;
2701 hr = pAdapter->pD3D9If->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, fFlags, &params, &pDevice9If);
2702 Assert(hr == S_OK);
2703 if (hr == S_OK)
2704 {
2705 pDevice->pDevice9If = pDevice9If;
2706 pDevice->hWnd = hWnd;
2707 for (UINT i = 0; i < pResource->SurfCount; ++i)
2708 {
2709 PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[i];
2710
2711 IDirect3DSurface9* pD3D9Surf;
2712 hr = pDevice9If->CreateRenderTarget(pAllocation->SurfDesc.width,
2713 pAllocation->SurfDesc.height,
2714 vboxDDI2D3DFormat(pResource->Format),
2715 vboxDDI2D3DMultiSampleType(pResource->MultisampleType),
2716 pResource->MultisampleQuality,
2717 !pResource->Flags.NotLockable /* BOOL Lockable */,
2718 &pD3D9Surf,
2719 NULL /* HANDLE* pSharedHandle */
2720 );
2721 Assert(hr == S_OK);
2722 if (hr == S_OK)
2723 {
2724 Assert(pD3D9Surf);
2725 if (pResource->Pool == D3DDDIPOOL_SYSTEMMEM)
2726 {
2727 Assert(pAllocation->pvMem);
2728 D3DLOCKED_RECT lockInfo;
2729 hr = pD3D9Surf->LockRect(&lockInfo, NULL, D3DLOCK_DISCARD);
2730 Assert(hr == S_OK);
2731 if (hr == S_OK)
2732 {
2733 vboxWddmLockUnlockMemSynch(pAllocation, &lockInfo, NULL, true /*bool bToLockInfo*/);
2734 HRESULT tmpHr = pD3D9Surf->UnlockRect();
2735 Assert(tmpHr == S_OK);
2736 }
2737 }
2738 else
2739 {
2740 Assert(!pAllocation->pvMem);
2741 }
2742 pAllocation->pD3DIf = pD3D9Surf;
2743 }
2744 else
2745 {
2746 for (UINT j = 0; j < i; ++j)
2747 {
2748 pRc->aAllocations[j].pD3DIf->Release();
2749 }
2750 break;
2751 }
2752 }
2753 }
2754
2755 if (hr != S_OK)
2756 {
2757 VBoxDispWndDestroy(pAdapter, hWnd);
2758 }
2759 }
2760 }
2761 else if (pResource->Flags.ZBuffer)
2762 {
2763 Assert(pDevice->pDevice9If);
2764 for (UINT i = 0; i < pResource->SurfCount; ++i)
2765 {
2766 PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[i];
2767 IDirect3DSurface9 *pD3D9Surf;
2768 hr = pDevice->pDevice9If->CreateDepthStencilSurface(pAllocation->SurfDesc.width,
2769 pAllocation->SurfDesc.height,
2770 vboxDDI2D3DFormat(pResource->Format),
2771 vboxDDI2D3DMultiSampleType(pResource->MultisampleType),
2772 pResource->MultisampleQuality,
2773 TRUE /* @todo: BOOL Discard */,
2774 &pD3D9Surf,
2775 NULL /*HANDLE* pSharedHandle*/);
2776 Assert(hr == S_OK);
2777 if (hr == S_OK)
2778 {
2779 Assert(pD3D9Surf);
2780 if (pResource->Pool == D3DDDIPOOL_SYSTEMMEM)
2781 {
2782 Assert(pAllocation->pvMem);
2783 D3DLOCKED_RECT lockInfo;
2784 hr = pD3D9Surf->LockRect(&lockInfo, NULL, D3DLOCK_DISCARD);
2785 Assert(hr == S_OK);
2786 if (hr == S_OK)
2787 {
2788 vboxWddmLockUnlockMemSynch(pAllocation, &lockInfo, NULL, true /*bool bToLockInfo*/);
2789 HRESULT tmpHr = pD3D9Surf->UnlockRect();
2790 Assert(tmpHr == S_OK);
2791 }
2792 }
2793 else
2794 {
2795 Assert(!pAllocation->pvMem);
2796 }
2797 pAllocation->pD3DIf = pD3D9Surf;
2798 }
2799 else
2800 {
2801 for (UINT j = 0; j < i; ++j)
2802 {
2803 pRc->aAllocations[j].pD3DIf->Release();
2804 }
2805 break;
2806 }
2807 }
2808 }
2809 else if (pResource->Flags.VertexBuffer)
2810 {
2811 Assert(pDevice->pDevice9If);
2812 for (UINT i = 0; i < pResource->SurfCount; ++i)
2813 {
2814 PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[i];
2815 IDirect3DVertexBuffer9 *pD3D9VBuf;
2816 hr = pDevice->pDevice9If->CreateVertexBuffer(pAllocation->SurfDesc.width,
2817 vboxDDI2D3DUsage(pResource->Flags),
2818 pResource->Fvf,
2819 vboxDDI2D3DPool(pResource->Pool),
2820 &pD3D9VBuf,
2821 NULL /*HANDLE* pSharedHandle*/);
2822 Assert(hr == S_OK);
2823 if (hr == S_OK)
2824 {
2825 Assert(pD3D9VBuf);
2826 if (pResource->Pool == D3DDDIPOOL_SYSTEMMEM)
2827 {
2828 Assert(pAllocation->pvMem);
2829 D3DLOCKED_RECT lockInfo;
2830 hr = pD3D9VBuf->Lock(0, pAllocation->SurfDesc.width, &lockInfo.pBits, D3DLOCK_DISCARD);
2831 Assert(hr == S_OK);
2832 if (hr == S_OK)
2833 {
2834 lockInfo.Pitch = pAllocation->SurfDesc.pitch;
2835 vboxWddmLockUnlockMemSynch(pAllocation, &lockInfo, NULL, true /*bool bToLockInfo*/);
2836 HRESULT tmpHr = pD3D9VBuf->Unlock();
2837 Assert(tmpHr == S_OK);
2838 }
2839 }
2840 else
2841 {
2842 Assert(!pAllocation->pvMem);
2843 }
2844 pAllocation->pD3DIf = pD3D9VBuf;
2845 }
2846 else
2847 {
2848 for (UINT j = 0; j < i; ++j)
2849 {
2850 pRc->aAllocations[j].pD3DIf->Release();
2851 }
2852 break;
2853 }
2854 }
2855 }
2856 else if (pResource->Flags.IndexBuffer)
2857 {
2858 Assert(pDevice->pDevice9If);
2859 for (UINT i = 0; i < pResource->SurfCount; ++i)
2860 {
2861 PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[i];
2862 CONST D3DDDI_SURFACEINFO* pSurf = &pResource->pSurfList[i];
2863 IDirect3DIndexBuffer9 *pD3D9IBuf;
2864 hr = pDevice->pDevice9If->CreateIndexBuffer(pSurf->Width,
2865 vboxDDI2D3DUsage(pResource->Flags),
2866 vboxDDI2D3DFormat(pResource->Format),
2867 vboxDDI2D3DPool(pResource->Pool),
2868 &pD3D9IBuf,
2869 NULL /*HANDLE* pSharedHandle*/
2870 );
2871 Assert(hr == S_OK);
2872 if (hr == S_OK)
2873 {
2874 Assert(pD3D9IBuf);
2875 if (pResource->Pool == D3DDDIPOOL_SYSTEMMEM)
2876 {
2877 Assert(pAllocation->pvMem);
2878 D3DLOCKED_RECT lockInfo;
2879 hr = pD3D9IBuf->Lock(0, pAllocation->SurfDesc.width, &lockInfo.pBits, D3DLOCK_DISCARD);
2880 Assert(hr == S_OK);
2881 if (hr == S_OK)
2882 {
2883 lockInfo.Pitch = pAllocation->SurfDesc.pitch;
2884 vboxWddmLockUnlockMemSynch(pAllocation, &lockInfo, NULL, true /*bool bToLockInfo*/);
2885 HRESULT tmpHr = pD3D9IBuf->Unlock();
2886 Assert(tmpHr == S_OK);
2887 }
2888 }
2889 else
2890 {
2891 Assert(!pAllocation->pvMem);
2892 }
2893 pAllocation->pD3DIf = pD3D9IBuf;
2894 }
2895 else
2896 {
2897 for (UINT j = 0; j < i; ++j)
2898 {
2899 pRc->aAllocations[j].pD3DIf->Release();
2900 }
2901 break;
2902 }
2903 }
2904 }
2905 else if (pResource->Flags.Texture)
2906 {
2907 Assert(pDevice->pDevice9If);
2908#ifdef DEBUG
2909 {
2910 uint32_t tstW = pResource->pSurfList[0].Width;
2911 uint32_t tstH = pResource->pSurfList[0].Height;
2912 for (UINT i = 1; i < pResource->SurfCount; ++i)
2913 {
2914 tstW /= 2;
2915 tstH /= 2;
2916 CONST D3DDDI_SURFACEINFO* pSurf = &pResource->pSurfList[i];
2917 Assert(pSurf->Width == tstW);
2918 Assert(pSurf->Height == tstH);
2919 }
2920 }
2921#endif
2922
2923 PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[0];
2924 CONST D3DDDI_SURFACEINFO* pSurf = &pResource->pSurfList[0];
2925 IDirect3DTexture9 *pD3DIfTex;
2926 hr = pDevice->pDevice9If->CreateTexture(pSurf->Width,
2927 pSurf->Height,
2928 pResource->SurfCount,
2929 vboxDDI2D3DUsage(pResource->Flags),
2930 vboxDDI2D3DFormat(pResource->Format),
2931 vboxDDI2D3DPool(pResource->Pool),
2932 &pD3DIfTex,
2933 NULL /* HANDLE* pSharedHandle */
2934 );
2935 Assert(hr == S_OK);
2936 if (hr == S_OK)
2937 {
2938 Assert(pD3DIfTex);
2939 if (pResource->Pool == D3DDDIPOOL_SYSTEMMEM)
2940 {
2941 for (UINT i = 0; i < pResource->SurfCount; ++i)
2942 {
2943 D3DLOCKED_RECT lockInfo;
2944 PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[i];
2945 Assert(pAllocation->pvMem);
2946 hr = pD3DIfTex->LockRect(i, &lockInfo, NULL, D3DLOCK_DISCARD);
2947 Assert(hr == S_OK);
2948 if (hr == S_OK)
2949 {
2950 vboxWddmLockUnlockMemSynch(pAllocation, &lockInfo, NULL, true /*bool bToLockInfo*/);
2951 HRESULT tmpHr = pD3DIfTex->UnlockRect(i);
2952 Assert(tmpHr == S_OK);
2953 }
2954 else
2955 {
2956 pD3DIfTex->Release();
2957 break;
2958 }
2959 }
2960 }
2961 pAllocation->pD3DIf = pD3DIfTex;
2962 }
2963#ifdef DEBUG
2964 else
2965 {
2966 for (UINT i = 0; i < pResource->SurfCount; ++i)
2967 {
2968 PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[i];
2969 Assert(!pAllocation->pvMem);
2970 }
2971 }
2972#endif
2973 }
2974 else
2975 {
2976 Assert(pDevice->pDevice9If);
2977 Assert(0);
2978 }
2979 }
2980 else
2981 bIssueCreateResource = true;
2982
2983
2984 if (hr == S_OK && bIssueCreateResource)
2985 {
2986 D3DDDICB_ALLOCATE *pDdiAllocate = vboxWddmRequestAllocAlloc(pResource);
2987 Assert(pDdiAllocate);
2988 if (pDdiAllocate)
2989 {
2990 Assert(pDdiAllocate->pPrivateDriverData);
2991 Assert(pDdiAllocate->PrivateDriverDataSize == sizeof (VBOXWDDM_RCINFO));
2992 PVBOXWDDM_RCINFO pRcInfo = (PVBOXWDDM_RCINFO)pDdiAllocate->pPrivateDriverData;
2993 pRcInfo->fFlags = VBOXWDDM_RESOURCE_F_TYPE_GENERIC;
2994 pRcInfo->RcDesc = pRc->RcDesc;
2995 pRcInfo->cAllocInfos = pResource->SurfCount;
2996
2997 for (UINT i = 0; i < pResource->SurfCount; ++i)
2998 {
2999 D3DDDI_ALLOCATIONINFO *pDdiAllocI = &pDdiAllocate->pAllocationInfo[i];
3000 Assert(pDdiAllocI->pPrivateDriverData);
3001 Assert(pDdiAllocI->PrivateDriverDataSize == sizeof (VBOXWDDM_ALLOCINFO));
3002 PVBOXWDDM_ALLOCINFO pAllocInfo = (PVBOXWDDM_ALLOCINFO)pDdiAllocI->pPrivateDriverData;
3003 CONST D3DDDI_SURFACEINFO* pSurf = &pResource->pSurfList[i];
3004 pDdiAllocI->hAllocation = NULL;
3005 pDdiAllocI->pSystemMem = pSurf->pSysMem;
3006 Assert((!!(pSurf->pSysMem)) == (pResource->Pool == D3DDDIPOOL_SYSTEMMEM));
3007 pDdiAllocI->VidPnSourceId = pResource->VidPnSourceId;
3008 pDdiAllocI->Flags.Value = 0;
3009 if (pResource->Flags.Primary && pResource->Flags.RenderTarget)
3010 pDdiAllocI->Flags.Primary = 1;
3011
3012 pAllocInfo->enmType = VBOXWDDM_ALLOC_TYPE_UMD_RC_GENERIC;
3013 pAllocInfo->fFlags = pResource->Flags;
3014 pAllocInfo->SurfDesc.width = pSurf->Width;
3015 pAllocInfo->SurfDesc.height = pSurf->Height;
3016 pAllocInfo->SurfDesc.format = pResource->Format;
3017 if (!vboxWddmFormatToFourcc(pResource->Format))
3018 pAllocInfo->SurfDesc.bpp = vboxWddmCalcBitsPerPixel(pResource->Format);
3019 else
3020 pAllocInfo->SurfDesc.bpp = 0;
3021
3022 if (pSurf->SysMemPitch)
3023 {
3024 pAllocInfo->SurfDesc.pitch = pSurf->SysMemPitch;
3025#ifdef DEBUG
3026 UINT tst = vboxWddmCalcPitch(pSurf->Width, pAllocInfo->SurfDesc.bpp);
3027 Assert(tst == pSurf->SysMemPitch);
3028#endif
3029 }
3030 else
3031 pAllocInfo->SurfDesc.pitch = vboxWddmCalcPitch(pSurf->Width, pAllocInfo->SurfDesc.bpp);
3032
3033 pAllocInfo->SurfDesc.cbSize = pAllocInfo->SurfDesc.pitch * pAllocInfo->SurfDesc.height;
3034 pAllocInfo->SurfDesc.depth = pSurf->Depth;
3035 pAllocInfo->SurfDesc.slicePitch = pSurf->SysMemSlicePitch;
3036 pAllocInfo->SurfDesc.VidPnSourceId = pResource->VidPnSourceId;
3037 pAllocInfo->SurfDesc.RefreshRate = pResource->RefreshRate;
3038 }
3039
3040 hr = pDevice->RtCallbacks.pfnAllocateCb(pDevice->hDevice, pDdiAllocate);
3041 Assert(hr == S_OK);
3042 Assert(pDdiAllocate->hKMResource);
3043 if (hr == S_OK)
3044 {
3045 pRc->hKMResource = pDdiAllocate->hKMResource;
3046
3047 for (UINT i = 0; i < pResource->SurfCount; ++i)
3048 {
3049 PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[i];
3050 D3DDDI_ALLOCATIONINFO *pDdiAllocI = &pDdiAllocate->pAllocationInfo[i];
3051 PVBOXWDDM_ALLOCINFO pAllocInfo = (PVBOXWDDM_ALLOCINFO)pDdiAllocI->pPrivateDriverData;
3052 CONST D3DDDI_SURFACEINFO* pSurf = &pResource->pSurfList[i];
3053 pAllocation->hAllocation = pDdiAllocI->hAllocation;
3054 pAllocation->enmType = VBOXWDDM_ALLOC_TYPE_UMD_RC_GENERIC;
3055 pAllocation->pvMem = (void*)pSurf->pSysMem;
3056 pAllocation->SurfDesc = pAllocInfo->SurfDesc;
3057 }
3058 }
3059
3060 vboxWddmRequestAllocFree(pDdiAllocate);
3061 }
3062 else
3063 {
3064 hr = E_OUTOFMEMORY;
3065 }
3066
3067 if (hr == S_OK)
3068 pResource->hResource = pRc;
3069 else
3070 vboxResourceFree(pRc);
3071 }
3072
3073 if (hr == S_OK)
3074 pResource->hResource = pRc;
3075 else
3076 vboxResourceFree(pRc);
3077 }
3078 else
3079 {
3080 hr = E_OUTOFMEMORY;
3081 }
3082
3083
3084 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3085 return hr;
3086}
3087
3088static HRESULT APIENTRY vboxWddmDDevDestroyResource(HANDLE hDevice, HANDLE hResource)
3089{
3090 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3091 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
3092 PVBOXWDDMDISP_ADAPTER pAdapter = pDevice->pAdapter;
3093 PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)hResource;
3094
3095 HRESULT hr = S_OK;
3096
3097 Assert(pDevice);
3098 Assert(hResource);
3099
3100 if (VBOXDISPMODE_IS_3D(pAdapter))
3101 {
3102 if (pRc->RcDesc.fFlags.RenderTarget)
3103 {
3104 Assert(pDevice->hWnd);
3105 Assert(pDevice->pDevice9If);
3106 pDevice->pDevice9If->Release();
3107 HRESULT tmpHr = VBoxDispWndDestroy(pAdapter, pDevice->hWnd);
3108 Assert(tmpHr == S_OK);
3109 }
3110
3111 for (UINT i = 0; i < pRc->cAllocations; ++i)
3112 {
3113 PVBOXWDDMDISP_ALLOCATION pAlloc = &pRc->aAllocations[i];
3114 if (pAlloc->pD3DIf)
3115 pAlloc->pD3DIf->Release();
3116 }
3117 }
3118
3119 Assert(pRc->hResource);
3120 Assert(pRc->hKMResource || VBOXDISPMODE_IS_3D(pAdapter));
3121 if (pRc->hKMResource)
3122 {
3123 if (!(pRc->fFlags & VBOXWDDM_RESOURCE_F_OPENNED))
3124 {
3125 D3DDDICB_DEALLOCATE Dealloc;
3126 Dealloc.hResource = pRc->hResource;
3127 /* according to the docs the below two are ignored in case we set the hResource */
3128 Dealloc.NumAllocations = 0;
3129 Dealloc.HandleList = NULL;
3130 hr = pDevice->RtCallbacks.pfnDeallocateCb(pDevice->hDevice, &Dealloc);
3131 Assert(hr == S_OK);
3132// for (UINT j = 0; j < pRc->cAllocations; ++j)
3133// {
3134// D3DDDICB_DEALLOCATE Dealloc;
3135// Dealloc.hResource = NULL;
3136// Dealloc.NumAllocations = 1;
3137// Dealloc.HandleList = &pRc->aAllocations[j].hAllocation;
3138// HRESULT tmpHr = pDevice->RtCallbacks.pfnDeallocateCb(pDevice->hDevice, &Dealloc);
3139// Assert(tmpHr = S_OK);
3140// }
3141 }
3142 }
3143
3144 vboxResourceFree(pRc);
3145 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3146 return hr;
3147}
3148static HRESULT APIENTRY vboxWddmDDevSetDisplayMode(HANDLE hDevice, CONST D3DDDIARG_SETDISPLAYMODE* pData)
3149{
3150 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3151 AssertBreakpoint();
3152 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3153 return E_FAIL;
3154}
3155static HRESULT APIENTRY vboxWddmDDevPresent(HANDLE hDevice, CONST D3DDDIARG_PRESENT* pData)
3156{
3157 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3158 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
3159 Assert(pDevice);
3160 HRESULT hr = S_OK;
3161 if (VBOXDISPMODE_IS_3D(pDevice->pAdapter))
3162 {
3163 Assert(pDevice->pDevice9If);
3164#if 0
3165 hr = pDevice->pDevice9If->Present(NULL, /* CONST RECT * pSourceRect */
3166 NULL, /* CONST RECT * pDestRect */
3167 NULL, /* HWND hDestWindowOverride */
3168 NULL /*CONST RGNDATA * pDirtyRegion */
3169 );
3170 Assert(hr == S_OK);
3171#endif
3172 }
3173#if 0
3174 else
3175#endif
3176 {
3177 D3DDDICB_PRESENT DdiPresent = {0};
3178 if (pData->hSrcResource)
3179 {
3180 PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)pData->hSrcResource;
3181 Assert(pRc->hKMResource);
3182 Assert(pRc->cAllocations > pData->SrcSubResourceIndex);
3183 PVBOXWDDMDISP_ALLOCATION pAlloc = &pRc->aAllocations[pData->SrcSubResourceIndex];
3184 Assert(pAlloc->hAllocation);
3185 DdiPresent.hSrcAllocation = pAlloc->hAllocation;
3186 }
3187 if (pData->hDstResource)
3188 {
3189 PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)pData->hDstResource;
3190 Assert(pRc->hKMResource);
3191 Assert(pRc->cAllocations > pData->DstSubResourceIndex);
3192 PVBOXWDDMDISP_ALLOCATION pAlloc = &pRc->aAllocations[pData->DstSubResourceIndex];
3193 Assert(pAlloc->hAllocation);
3194 DdiPresent.hDstAllocation = pAlloc->hAllocation;
3195 }
3196 DdiPresent.hContext = pDevice->DefaultContext.ContextInfo.hContext;
3197// DdiPresent.BroadcastContextCount;
3198// DdiPresent.BroadcastContext[D3DDDI_MAX_BROADCAST_CONTEXT];
3199
3200 hr = pDevice->RtCallbacks.pfnPresentCb(pDevice->hDevice, &DdiPresent);
3201 Assert(hr == S_OK);
3202 }
3203 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
3204 return hr;
3205}
3206static HRESULT APIENTRY vboxWddmDDevFlush(HANDLE hDevice)
3207{
3208 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3209 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
3210 Assert(pDevice);
3211 HRESULT hr = S_OK;
3212 if (VBOXDISPMODE_IS_3D(pDevice->pAdapter))
3213 {
3214 Assert(pDevice->pDevice9If);
3215 hr = pDevice->pDevice9If->Present(NULL, /* CONST RECT * pSourceRect */
3216 NULL, /* CONST RECT * pDestRect */
3217 NULL, /* HWND hDestWindowOverride */
3218 NULL /*CONST RGNDATA * pDirtyRegion */
3219 );
3220 Assert(hr == S_OK);
3221 }
3222 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
3223 return hr;
3224}
3225
3226AssertCompile(sizeof (D3DDDIVERTEXELEMENT) == sizeof (D3DVERTEXELEMENT9));
3227AssertCompile(RT_SIZEOFMEMB(D3DDDIVERTEXELEMENT, Stream) == RT_SIZEOFMEMB(D3DVERTEXELEMENT9, Stream));
3228AssertCompile(RT_SIZEOFMEMB(D3DDDIVERTEXELEMENT, Offset) == RT_SIZEOFMEMB(D3DVERTEXELEMENT9, Offset));
3229AssertCompile(RT_SIZEOFMEMB(D3DDDIVERTEXELEMENT, Type) == RT_SIZEOFMEMB(D3DVERTEXELEMENT9, Type));
3230AssertCompile(RT_SIZEOFMEMB(D3DDDIVERTEXELEMENT, Method) == RT_SIZEOFMEMB(D3DVERTEXELEMENT9, Method));
3231AssertCompile(RT_SIZEOFMEMB(D3DDDIVERTEXELEMENT, Usage) == RT_SIZEOFMEMB(D3DVERTEXELEMENT9, Usage));
3232AssertCompile(RT_SIZEOFMEMB(D3DDDIVERTEXELEMENT, UsageIndex) == RT_SIZEOFMEMB(D3DVERTEXELEMENT9, UsageIndex));
3233
3234AssertCompile(RT_OFFSETOF(D3DDDIVERTEXELEMENT, Stream) == RT_OFFSETOF(D3DVERTEXELEMENT9, Stream));
3235AssertCompile(RT_OFFSETOF(D3DDDIVERTEXELEMENT, Offset) == RT_OFFSETOF(D3DVERTEXELEMENT9, Offset));
3236AssertCompile(RT_OFFSETOF(D3DDDIVERTEXELEMENT, Type) == RT_OFFSETOF(D3DVERTEXELEMENT9, Type));
3237AssertCompile(RT_OFFSETOF(D3DDDIVERTEXELEMENT, Method) == RT_OFFSETOF(D3DVERTEXELEMENT9, Method));
3238AssertCompile(RT_OFFSETOF(D3DDDIVERTEXELEMENT, Usage) == RT_OFFSETOF(D3DVERTEXELEMENT9, Usage));
3239AssertCompile(RT_OFFSETOF(D3DDDIVERTEXELEMENT, UsageIndex) == RT_OFFSETOF(D3DVERTEXELEMENT9, UsageIndex));
3240
3241static HRESULT APIENTRY vboxWddmDDevCreateVertexShaderDecl(HANDLE hDevice, D3DDDIARG_CREATEVERTEXSHADERDECL* pData, CONST D3DDDIVERTEXELEMENT* pVertexElements)
3242{
3243 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3244 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
3245 Assert(pDevice);
3246 Assert(pDevice->pDevice9If);
3247 IDirect3DVertexDeclaration9 *pDecl;
3248 static D3DVERTEXELEMENT9 DeclEnd = D3DDECL_END();
3249 Assert(!memcmp(&DeclEnd, &pVertexElements[pData->NumVertexElements], sizeof (DeclEnd)));
3250 HRESULT hr = pDevice->pDevice9If->CreateVertexDeclaration(
3251 (CONST D3DVERTEXELEMENT9*)pVertexElements,
3252 &pDecl
3253 );
3254 Assert(hr == S_OK);
3255 if (hr == S_OK)
3256 {
3257 Assert(pDecl);
3258 pData->ShaderHandle = pDecl;
3259 }
3260 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
3261 return hr;
3262}
3263static HRESULT APIENTRY vboxWddmDDevSetVertexShaderDecl(HANDLE hDevice, HANDLE hShaderHandle)
3264{
3265 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3266 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
3267 Assert(pDevice);
3268 Assert(pDevice->pDevice9If);
3269 IDirect3DVertexDeclaration9 *pDecl = (IDirect3DVertexDeclaration9*)hShaderHandle;
3270 Assert(pDecl);
3271 HRESULT hr = pDevice->pDevice9If->SetVertexDeclaration(pDecl);
3272 Assert(hr == S_OK);
3273 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
3274 return hr;
3275}
3276static HRESULT APIENTRY vboxWddmDDevDeleteVertexShaderDecl(HANDLE hDevice, HANDLE hShaderHandle)
3277{
3278 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3279 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
3280 Assert(pDevice);
3281 Assert(pDevice->pDevice9If);
3282 IDirect3DVertexDeclaration9 *pDecl = (IDirect3DVertexDeclaration9*)hShaderHandle;
3283 HRESULT hr = pDecl->Release();
3284 Assert(hr == S_OK);
3285 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
3286 return hr;
3287}
3288static HRESULT APIENTRY vboxWddmDDevCreateVertexShaderFunc(HANDLE hDevice, D3DDDIARG_CREATEVERTEXSHADERFUNC* pData, CONST UINT* pCode)
3289{
3290 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3291 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
3292 Assert(pDevice);
3293 Assert(pDevice->pDevice9If);
3294 IDirect3DVertexShader9 *pShader;
3295 Assert(*((UINT*)((uint8_t*)pCode + pData->Size-4)) == 0x0000FFFF /* end token */);
3296 HRESULT hr = pDevice->pDevice9If->CreateVertexShader((const DWORD *)pCode, &pShader);
3297 Assert(hr == S_OK);
3298 if (hr == S_OK)
3299 {
3300 Assert(pShader);
3301 pData->ShaderHandle = pShader;
3302 }
3303 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
3304 return hr;
3305}
3306static HRESULT APIENTRY vboxWddmDDevSetVertexShaderFunc(HANDLE hDevice, HANDLE hShaderHandle)
3307{
3308 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3309 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
3310 Assert(pDevice);
3311 Assert(pDevice->pDevice9If);
3312 IDirect3DVertexShader9 *pShader = (IDirect3DVertexShader9*)hShaderHandle;
3313 Assert(pShader);
3314 HRESULT hr = pDevice->pDevice9If->SetVertexShader(pShader);
3315 Assert(hr == S_OK);
3316 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
3317 return hr;
3318}
3319static HRESULT APIENTRY vboxWddmDDevDeleteVertexShaderFunc(HANDLE hDevice, HANDLE hShaderHandle)
3320{
3321 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3322 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
3323 Assert(pDevice);
3324 Assert(pDevice->pDevice9If);
3325 IDirect3DVertexShader9 *pShader = (IDirect3DVertexShader9*)hShaderHandle;
3326 HRESULT hr = pShader->Release();
3327 Assert(hr == S_OK);
3328 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
3329 return hr;
3330}
3331static HRESULT APIENTRY vboxWddmDDevSetVertexShaderConstI(HANDLE hDevice, CONST D3DDDIARG_SETVERTEXSHADERCONSTI* pData, CONST INT* pRegisters)
3332{
3333 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3334 AssertBreakpoint();
3335 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3336 return E_FAIL;
3337}
3338static HRESULT APIENTRY vboxWddmDDevSetVertexShaderConstB(HANDLE hDevice, CONST D3DDDIARG_SETVERTEXSHADERCONSTB* pData, CONST BOOL* pRegisters)
3339{
3340 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3341 AssertBreakpoint();
3342 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3343 return E_FAIL;
3344}
3345static HRESULT APIENTRY vboxWddmDDevSetScissorRect(HANDLE hDevice, CONST RECT* pRect)
3346{
3347 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3348 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
3349 Assert(pDevice);
3350 Assert(pDevice->pDevice9If);
3351 HRESULT hr = pDevice->pDevice9If->SetScissorRect(pRect);
3352 Assert(hr == S_OK);
3353 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
3354 return hr;
3355}
3356static HRESULT APIENTRY vboxWddmDDevSetStreamSource(HANDLE hDevice, CONST D3DDDIARG_SETSTREAMSOURCE* pData)
3357{
3358 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3359 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
3360 Assert(pDevice);
3361 Assert(pDevice->pDevice9If);
3362 PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)pData->hVertexBuffer;
3363 Assert(pRc);
3364 Assert(pRc->cAllocations == 1);
3365 PVBOXWDDMDISP_ALLOCATION pAlloc = &pRc->aAllocations[0];
3366 Assert(pAlloc->pD3DIf);
3367 IDirect3DVertexBuffer9 *pStreamData = (IDirect3DVertexBuffer9*)pAlloc->pD3DIf;
3368 HRESULT hr = pDevice->pDevice9If->SetStreamSource(pData->Stream, pStreamData, pData->Offset, pData->Stride);
3369 Assert(pData->Stream<VBOXWDDMDISP_MAX_VERTEX_STREAMS);
3370 pDevice->aStreamSource[pData->Stream] = pAlloc;
3371 pDevice->StreamSourceInfo[pData->Stream].uiOffset = pData->Offset;
3372 pDevice->StreamSourceInfo[pData->Stream].uiStride = pData->Stride;
3373 Assert(hr == S_OK);
3374 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
3375 return hr;
3376}
3377static HRESULT APIENTRY vboxWddmDDevSetStreamSourceFreq(HANDLE hDevice, CONST D3DDDIARG_SETSTREAMSOURCEFREQ* pData)
3378{
3379 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3380 AssertBreakpoint();
3381 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3382 return E_FAIL;
3383}
3384static HRESULT APIENTRY vboxWddmDDevSetConvolutionKernelMono(HANDLE hDevice, CONST D3DDDIARG_SETCONVOLUTIONKERNELMONO* pData)
3385{
3386 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3387 AssertBreakpoint();
3388 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3389 return E_FAIL;
3390}
3391static HRESULT APIENTRY vboxWddmDDevComposeRects(HANDLE hDevice, CONST D3DDDIARG_COMPOSERECTS* pData)
3392{
3393 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3394 AssertBreakpoint();
3395 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3396 return E_FAIL;
3397}
3398static HRESULT APIENTRY vboxWddmDDevBlt(HANDLE hDevice, CONST D3DDDIARG_BLT* pData)
3399{
3400 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3401 AssertBreakpoint();
3402 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3403 return E_FAIL;
3404}
3405static HRESULT APIENTRY vboxWddmDDevColorFill(HANDLE hDevice, CONST D3DDDIARG_COLORFILL* pData)
3406{
3407 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3408 AssertBreakpoint();
3409 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3410 return E_FAIL;
3411}
3412static HRESULT APIENTRY vboxWddmDDevDepthFill(HANDLE hDevice, CONST D3DDDIARG_DEPTHFILL* pData)
3413{
3414 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3415 AssertBreakpoint();
3416 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3417 return E_FAIL;
3418}
3419static HRESULT APIENTRY vboxWddmDDevCreateQuery(HANDLE hDevice, D3DDDIARG_CREATEQUERY* pData)
3420{
3421 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3422 AssertBreakpoint();
3423 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3424 return E_FAIL;
3425}
3426static HRESULT APIENTRY vboxWddmDDevDestroyQuery(HANDLE hDevice, HANDLE hQuery)
3427{
3428 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3429 AssertBreakpoint();
3430 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3431 return E_FAIL;
3432}
3433static HRESULT APIENTRY vboxWddmDDevIssueQuery(HANDLE hDevice, CONST D3DDDIARG_ISSUEQUERY* pData)
3434{
3435 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3436 AssertBreakpoint();
3437 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3438 return E_FAIL;
3439}
3440static HRESULT APIENTRY vboxWddmDDevGetQueryData(HANDLE hDevice, CONST D3DDDIARG_GETQUERYDATA* pData)
3441{
3442 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3443 AssertBreakpoint();
3444 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3445 return E_FAIL;
3446}
3447static HRESULT APIENTRY vboxWddmDDevSetRenderTarget(HANDLE hDevice, CONST D3DDDIARG_SETRENDERTARGET* pData)
3448{
3449 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3450 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
3451 Assert(pDevice);
3452 Assert(pDevice->pDevice9If);
3453 PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)pData->hRenderTarget;
3454 Assert(pRc);
3455 Assert(pData->SubResourceIndex < pRc->cAllocations);
3456 IDirect3DSurface9 *pD3D9Surf = (IDirect3DSurface9*)pRc->aAllocations[pData->SubResourceIndex].pD3DIf;
3457 Assert(pD3D9Surf);
3458 HRESULT hr = pDevice->pDevice9If->SetRenderTarget(pData->RenderTargetIndex, pD3D9Surf);
3459 Assert(hr == S_OK);
3460 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
3461 return hr;
3462}
3463static HRESULT APIENTRY vboxWddmDDevSetDepthStencil(HANDLE hDevice, CONST D3DDDIARG_SETDEPTHSTENCIL* pData)
3464{
3465 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3466 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
3467 Assert(pDevice);
3468 Assert(pDevice->pDevice9If);
3469 PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)pData->hZBuffer;
3470 Assert(pRc);
3471 Assert(pRc->cAllocations == 1);
3472 IDirect3DSurface9 *pD3D9Surf = (IDirect3DSurface9*)pRc->aAllocations[0].pD3DIf;
3473 Assert(pD3D9Surf);
3474 HRESULT hr = pDevice->pDevice9If->SetDepthStencilSurface(pD3D9Surf);
3475 Assert(hr == S_OK);
3476 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
3477 return hr;
3478}
3479static HRESULT APIENTRY vboxWddmDDevGenerateMipSubLevels(HANDLE hDevice, CONST D3DDDIARG_GENERATEMIPSUBLEVELS* pData)
3480{
3481 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3482 AssertBreakpoint();
3483 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3484 return E_FAIL;
3485}
3486static HRESULT APIENTRY vboxWddmDDevSetPixelShaderConstI(HANDLE hDevice, CONST D3DDDIARG_SETPIXELSHADERCONSTI* pData, CONST INT* pRegisters)
3487{
3488 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3489 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
3490 Assert(pDevice);
3491 Assert(pDevice->pDevice9If);
3492 HRESULT hr = pDevice->pDevice9If->SetPixelShaderConstantI(pData->Register, pRegisters, pData->Count);
3493 Assert(hr == S_OK);
3494 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
3495 return hr;
3496}
3497static HRESULT APIENTRY vboxWddmDDevSetPixelShaderConstB(HANDLE hDevice, CONST D3DDDIARG_SETPIXELSHADERCONSTB* pData, CONST BOOL* pRegisters)
3498{
3499 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3500 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
3501 Assert(pDevice);
3502 Assert(pDevice->pDevice9If);
3503 HRESULT hr = pDevice->pDevice9If->SetPixelShaderConstantB(pData->Register, pRegisters, pData->Count);
3504 Assert(hr == S_OK);
3505 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
3506 return hr;
3507}
3508static HRESULT APIENTRY vboxWddmDDevCreatePixelShader(HANDLE hDevice, D3DDDIARG_CREATEPIXELSHADER* pData, CONST UINT* pCode)
3509{
3510 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3511 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
3512 Assert(pDevice);
3513 Assert(pDevice->pDevice9If);
3514 IDirect3DPixelShader9 *pShader;
3515 Assert(*((UINT*)((uint8_t*)pCode + pData->CodeSize-4)) == 0x0000FFFF /* end token */);
3516 HRESULT hr = pDevice->pDevice9If->CreatePixelShader((const DWORD *)pCode, &pShader);
3517 Assert(hr == S_OK);
3518 if (hr == S_OK)
3519 {
3520 Assert(pShader);
3521 pData->ShaderHandle = pShader;
3522 }
3523 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
3524 return hr;
3525}
3526static HRESULT APIENTRY vboxWddmDDevDeletePixelShader(HANDLE hDevice, HANDLE hShaderHandle)
3527{
3528 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3529 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
3530 Assert(pDevice);
3531 Assert(pDevice->pDevice9If);
3532 IDirect3DPixelShader9 *pShader = (IDirect3DPixelShader9*)hShaderHandle;
3533 HRESULT hr = pShader->Release();
3534 Assert(hr == S_OK);
3535 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
3536 return hr;
3537}
3538static HRESULT APIENTRY vboxWddmDDevCreateDecodeDevice(HANDLE hDevice, D3DDDIARG_CREATEDECODEDEVICE* pData)
3539{
3540 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3541 AssertBreakpoint();
3542 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3543 return E_FAIL;
3544}
3545static HRESULT APIENTRY vboxWddmDDevDestroyDecodeDevice(HANDLE hDevice, HANDLE hDecodeDevice)
3546{
3547 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3548 AssertBreakpoint();
3549 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3550 return E_FAIL;
3551}
3552static HRESULT APIENTRY vboxWddmDDevSetDecodeRenderTarget(HANDLE hDevice, CONST D3DDDIARG_SETDECODERENDERTARGET* pData)
3553{
3554 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3555 AssertBreakpoint();
3556 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3557 return E_FAIL;
3558}
3559static HRESULT APIENTRY vboxWddmDDevDecodeBeginFrame(HANDLE hDevice, D3DDDIARG_DECODEBEGINFRAME* pData)
3560{
3561 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3562 AssertBreakpoint();
3563 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3564 return E_FAIL;
3565}
3566static HRESULT APIENTRY vboxWddmDDevDecodeEndFrame(HANDLE hDevice, D3DDDIARG_DECODEENDFRAME* pData)
3567{
3568 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3569 AssertBreakpoint();
3570 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3571 return E_FAIL;
3572}
3573static HRESULT APIENTRY vboxWddmDDevDecodeExecute(HANDLE hDevice, CONST D3DDDIARG_DECODEEXECUTE* pData)
3574{
3575 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3576 AssertBreakpoint();
3577 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3578 return E_FAIL;
3579}
3580static HRESULT APIENTRY vboxWddmDDevDecodeExtensionExecute(HANDLE hDevice, CONST D3DDDIARG_DECODEEXTENSIONEXECUTE* pData)
3581{
3582 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3583 AssertBreakpoint();
3584 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3585 return E_FAIL;
3586}
3587static HRESULT APIENTRY vboxWddmDDevCreateVideoProcessDevice(HANDLE hDevice, D3DDDIARG_CREATEVIDEOPROCESSDEVICE* pData)
3588{
3589 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3590 AssertBreakpoint();
3591 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3592 return E_FAIL;
3593}
3594static HRESULT APIENTRY vboxWddmDDevDestroyVideoProcessDevice(HANDLE hDevice, HANDLE hVideoProcessor)
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 vboxWddmDDevVideoProcessBeginFrame(HANDLE hDevice, HANDLE hVideoProcess)
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 vboxWddmDDevVideoProcessEndFrame(HANDLE hDevice, D3DDDIARG_VIDEOPROCESSENDFRAME* 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 vboxWddmDDevSetVideoProcessRenderTarget(HANDLE hDevice, CONST D3DDDIARG_SETVIDEOPROCESSRENDERTARGET* pData)
3616{
3617 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3618 AssertBreakpoint();
3619 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3620 return E_FAIL;
3621}
3622static HRESULT APIENTRY vboxWddmDDevVideoProcessBlt(HANDLE hDevice, CONST D3DDDIARG_VIDEOPROCESSBLT* pData)
3623{
3624 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3625 AssertBreakpoint();
3626 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3627 return E_FAIL;
3628}
3629static HRESULT APIENTRY vboxWddmDDevCreateExtensionDevice(HANDLE hDevice, D3DDDIARG_CREATEEXTENSIONDEVICE* pData)
3630{
3631 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3632 AssertBreakpoint();
3633 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3634 return E_FAIL;
3635}
3636static HRESULT APIENTRY vboxWddmDDevDestroyExtensionDevice(HANDLE hDevice, HANDLE hExtension)
3637{
3638 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3639 AssertBreakpoint();
3640 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3641 return E_FAIL;
3642}
3643static HRESULT APIENTRY vboxWddmDDevExtensionExecute(HANDLE hDevice, CONST D3DDDIARG_EXTENSIONEXECUTE* pData)
3644{
3645 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3646 AssertBreakpoint();
3647 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3648 return E_FAIL;
3649}
3650static HRESULT APIENTRY vboxWddmDDevDestroyDevice(IN HANDLE hDevice)
3651{
3652 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3653
3654 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
3655 HRESULT hr = vboxDispCmCtxDestroy(pDevice, &pDevice->DefaultContext);
3656 Assert(hr == S_OK);
3657 if (hr == S_OK)
3658 RTMemFree(pDevice);
3659 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3660 return hr;
3661}
3662
3663AssertCompile(sizeof (RECT) == sizeof (D3DDDIRECT));
3664AssertCompile(RT_SIZEOFMEMB(RECT, left) == RT_SIZEOFMEMB(D3DDDIRECT, left));
3665AssertCompile(RT_SIZEOFMEMB(RECT, right) == RT_SIZEOFMEMB(D3DDDIRECT, right));
3666AssertCompile(RT_SIZEOFMEMB(RECT, top) == RT_SIZEOFMEMB(D3DDDIRECT, top));
3667AssertCompile(RT_SIZEOFMEMB(RECT, bottom) == RT_SIZEOFMEMB(D3DDDIRECT, bottom));
3668AssertCompile(RT_OFFSETOF(RECT, left) == RT_OFFSETOF(D3DDDIRECT, left));
3669AssertCompile(RT_OFFSETOF(RECT, right) == RT_OFFSETOF(D3DDDIRECT, right));
3670AssertCompile(RT_OFFSETOF(RECT, top) == RT_OFFSETOF(D3DDDIRECT, top));
3671AssertCompile(RT_OFFSETOF(RECT, bottom) == RT_OFFSETOF(D3DDDIRECT, bottom));
3672
3673static HRESULT APIENTRY vboxWddmDDevCreateOverlay(HANDLE hDevice, D3DDDIARG_CREATEOVERLAY* pData)
3674{
3675 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3676 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
3677 PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)pData->OverlayInfo.hResource;
3678 Assert(pRc);
3679 Assert(pRc->cAllocations > pData->OverlayInfo.SubResourceIndex);
3680 PVBOXWDDMDISP_ALLOCATION pAlloc = &pRc->aAllocations[pData->OverlayInfo.SubResourceIndex];
3681 HRESULT hr = S_OK;
3682 PVBOXWDDMDISP_OVERLAY pOverlay = (PVBOXWDDMDISP_OVERLAY)RTMemAllocZ(sizeof (VBOXWDDMDISP_OVERLAY));
3683 Assert(pOverlay);
3684 if (pOverlay)
3685 {
3686 VBOXWDDM_OVERLAY_INFO OurInfo;
3687 OurInfo.OverlayDesc.DstColorKeyLow = pData->OverlayInfo.DstColorKeyLow;
3688 OurInfo.OverlayDesc.DstColorKeyHigh = pData->OverlayInfo.DstColorKeyHigh;
3689 OurInfo.OverlayDesc.SrcColorKeyLow = pData->OverlayInfo.SrcColorKeyLow;
3690 OurInfo.OverlayDesc.SrcColorKeyHigh = pData->OverlayInfo.SrcColorKeyHigh;
3691 OurInfo.OverlayDesc.fFlags = pData->OverlayInfo.Flags.Value;
3692 vboxWddmDirtyRegionClear(&OurInfo.DirtyRegion);
3693 Assert(!pAlloc->LockInfo.cLocks);
3694 vboxWddmDirtyRegionUnite(&OurInfo.DirtyRegion, &pAlloc->DirtyRegion);
3695 D3DDDICB_CREATEOVERLAY OverInfo;
3696 OverInfo.VidPnSourceId = pData->VidPnSourceId;
3697 OverInfo.OverlayInfo.hAllocation = pAlloc->hAllocation;
3698 Assert(pAlloc->hAllocation);
3699 OverInfo.OverlayInfo.DstRect = *(D3DDDIRECT*)((void*)&pData->OverlayInfo.DstRect);
3700 OverInfo.OverlayInfo.SrcRect = *(D3DDDIRECT*)((void*)&pData->OverlayInfo.SrcRect);
3701 OverInfo.OverlayInfo.pPrivateDriverData = &OurInfo;
3702 OverInfo.OverlayInfo.PrivateDriverDataSize = sizeof (OurInfo);
3703 OverInfo.hKernelOverlay = NULL; /* <-- out */
3704#ifndef VBOXWDDMOVERLAY_TEST
3705 hr = pDevice->RtCallbacks.pfnCreateOverlayCb(pDevice->hDevice, &OverInfo);
3706 Assert(hr == S_OK);
3707 if (hr == S_OK)
3708 {
3709 Assert(OverInfo.hKernelOverlay);
3710 pOverlay->hOverlay = OverInfo.hKernelOverlay;
3711 pOverlay->VidPnSourceId = pData->VidPnSourceId;
3712
3713 Assert(!pAlloc->LockInfo.cLocks);
3714 if (!pAlloc->LockInfo.cLocks)
3715 {
3716 /* we have reported the dirty rect, may clear it if no locks are pending currently */
3717 vboxWddmDirtyRegionClear(&pAlloc->DirtyRegion);
3718 }
3719
3720 pData->hOverlay = pOverlay;
3721 }
3722 else
3723 {
3724 RTMemFree(pOverlay);
3725 }
3726#else
3727 pData->hOverlay = pOverlay;
3728#endif
3729 }
3730 else
3731 hr = E_OUTOFMEMORY;
3732
3733 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3734 return hr;
3735}
3736static HRESULT APIENTRY vboxWddmDDevUpdateOverlay(HANDLE hDevice, CONST D3DDDIARG_UPDATEOVERLAY* pData)
3737{
3738 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3739 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
3740 PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)pData->OverlayInfo.hResource;
3741 Assert(pRc);
3742 Assert(pRc->cAllocations > pData->OverlayInfo.SubResourceIndex);
3743 PVBOXWDDMDISP_ALLOCATION pAlloc = &pRc->aAllocations[pData->OverlayInfo.SubResourceIndex];
3744 HRESULT hr = S_OK;
3745 PVBOXWDDMDISP_OVERLAY pOverlay = (PVBOXWDDMDISP_OVERLAY)pData->hOverlay;
3746 VBOXWDDM_OVERLAY_INFO OurInfo;
3747 OurInfo.OverlayDesc.DstColorKeyLow = pData->OverlayInfo.DstColorKeyLow;
3748 OurInfo.OverlayDesc.DstColorKeyHigh = pData->OverlayInfo.DstColorKeyHigh;
3749 OurInfo.OverlayDesc.SrcColorKeyLow = pData->OverlayInfo.SrcColorKeyLow;
3750 OurInfo.OverlayDesc.SrcColorKeyHigh = pData->OverlayInfo.SrcColorKeyHigh;
3751 OurInfo.OverlayDesc.fFlags = pData->OverlayInfo.Flags.Value;
3752 vboxWddmDirtyRegionClear(&OurInfo.DirtyRegion);
3753 Assert(!pAlloc->LockInfo.cLocks);
3754 vboxWddmDirtyRegionUnite(&OurInfo.DirtyRegion, &pAlloc->DirtyRegion);
3755 D3DDDICB_UPDATEOVERLAY OverInfo;
3756 OverInfo.hKernelOverlay = pOverlay->hOverlay;
3757 OverInfo.OverlayInfo.hAllocation = pAlloc->hAllocation;
3758 OverInfo.OverlayInfo.DstRect = *(D3DDDIRECT*)((void*)&pData->OverlayInfo.DstRect);
3759 OverInfo.OverlayInfo.SrcRect = *(D3DDDIRECT*)((void*)&pData->OverlayInfo.SrcRect);
3760 OverInfo.OverlayInfo.pPrivateDriverData = &OurInfo;
3761 OverInfo.OverlayInfo.PrivateDriverDataSize = sizeof (OurInfo);
3762#ifndef VBOXWDDMOVERLAY_TEST
3763 hr = pDevice->RtCallbacks.pfnUpdateOverlayCb(pDevice->hDevice, &OverInfo);
3764 Assert(hr == S_OK);
3765 if (hr == S_OK)
3766#endif
3767 {
3768 Assert(!pAlloc->LockInfo.cLocks);
3769 if (!pAlloc->LockInfo.cLocks)
3770 {
3771 /* we have reported the dirty rect, may clear it if no locks are pending currently */
3772 vboxWddmDirtyRegionClear(&pAlloc->DirtyRegion);
3773 }
3774 }
3775
3776 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3777 return hr;
3778}
3779static HRESULT APIENTRY vboxWddmDDevFlipOverlay(HANDLE hDevice, CONST D3DDDIARG_FLIPOVERLAY* pData)
3780{
3781 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3782 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
3783 PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)pData->hSource;
3784 Assert(pRc);
3785 Assert(pRc->cAllocations > pData->SourceIndex);
3786 PVBOXWDDMDISP_ALLOCATION pAlloc = &pRc->aAllocations[pData->SourceIndex];
3787 HRESULT hr = S_OK;
3788 PVBOXWDDMDISP_OVERLAY pOverlay = (PVBOXWDDMDISP_OVERLAY)pData->hOverlay;
3789 VBOXWDDM_OVERLAYFLIP_INFO OurInfo;
3790 vboxWddmDirtyRegionClear(&OurInfo.DirtyRegion);
3791 Assert(!pAlloc->LockInfo.cLocks);
3792 vboxWddmDirtyRegionUnite(&OurInfo.DirtyRegion, &pAlloc->DirtyRegion);
3793 D3DDDICB_FLIPOVERLAY OverInfo;
3794 OverInfo.hKernelOverlay = pOverlay->hOverlay;
3795 OverInfo.hSource = pAlloc->hAllocation;
3796 OverInfo.pPrivateDriverData = &OurInfo;
3797 OverInfo.PrivateDriverDataSize = sizeof (OurInfo);
3798#ifndef VBOXWDDMOVERLAY_TEST
3799 hr = pDevice->RtCallbacks.pfnFlipOverlayCb(pDevice->hDevice, &OverInfo);
3800 Assert(hr == S_OK);
3801 if (hr == S_OK)
3802#endif
3803 {
3804 Assert(!pAlloc->LockInfo.cLocks);
3805 if (!pAlloc->LockInfo.cLocks)
3806 {
3807 /* we have reported the dirty rect, may clear it if no locks are pending currently */
3808 vboxWddmDirtyRegionClear(&pAlloc->DirtyRegion);
3809 }
3810 }
3811
3812 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3813 return hr;
3814}
3815static HRESULT APIENTRY vboxWddmDDevGetOverlayColorControls(HANDLE hDevice, D3DDDIARG_GETOVERLAYCOLORCONTROLS* pData)
3816{
3817 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3818 AssertBreakpoint();
3819 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3820 return E_FAIL;
3821}
3822static HRESULT APIENTRY vboxWddmDDevSetOverlayColorControls(HANDLE hDevice, CONST D3DDDIARG_SETOVERLAYCOLORCONTROLS* pData)
3823{
3824 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3825 AssertBreakpoint();
3826 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3827 return E_FAIL;
3828}
3829static HRESULT APIENTRY vboxWddmDDevDestroyOverlay(HANDLE hDevice, CONST D3DDDIARG_DESTROYOVERLAY* pData)
3830{
3831 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3832 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
3833 PVBOXWDDMDISP_OVERLAY pOverlay = (PVBOXWDDMDISP_OVERLAY)pData->hOverlay;
3834 D3DDDICB_DESTROYOVERLAY OverInfo;
3835 OverInfo.hKernelOverlay = pOverlay->hOverlay;
3836#ifndef VBOXWDDMOVERLAY_TEST
3837 HRESULT hr = pDevice->RtCallbacks.pfnDestroyOverlayCb(pDevice->hDevice, &OverInfo);
3838 Assert(hr == S_OK);
3839 if (hr == S_OK)
3840#else
3841 HRESULT hr = S_OK;
3842#endif
3843 {
3844 RTMemFree(pOverlay);
3845 }
3846
3847 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3848 return hr;
3849}
3850static HRESULT APIENTRY vboxWddmDDevQueryResourceResidency(HANDLE hDevice, CONST D3DDDIARG_QUERYRESOURCERESIDENCY* pData)
3851{
3852 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3853 AssertBreakpoint();
3854 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3855 return E_FAIL;
3856}
3857
3858static HRESULT vboxAllocationInit(PVBOXWDDMDISP_ALLOCATION pAlloc, D3DDDI_OPENALLOCATIONINFO *pInfo)
3859{
3860 HRESULT hr = S_OK;
3861 pAlloc->hAllocation = pInfo->hAllocation;
3862 Assert(pInfo->PrivateDriverDataSize == sizeof (VBOXWDDM_ALLOCINFO));
3863 Assert(pInfo->pPrivateDriverData);
3864 if (pInfo->PrivateDriverDataSize >= sizeof (VBOXWDDM_ALLOCINFO))
3865 {
3866 PVBOXWDDM_ALLOCINFO pAllocInfo = (PVBOXWDDM_ALLOCINFO)pInfo->pPrivateDriverData;
3867 pAlloc->enmType = pAllocInfo->enmType;
3868 Assert(pAllocInfo->enmType == VBOXWDDM_ALLOC_TYPE_STD_SHAREDPRIMARYSURFACE
3869 || VBOXWDDM_ALLOC_TYPE_STD_SHADOWSURFACE
3870 || VBOXWDDM_ALLOC_TYPE_STD_STAGINGSURFACE);
3871 pAlloc->pvMem = NULL;
3872 pAlloc->SurfDesc = pAllocInfo->SurfDesc;
3873 }
3874 else
3875 {
3876 vboxVDbgPrintR((__FUNCTION__": ERROR: PrivateDriverDataSize(%d) < (%d)\n", pInfo->PrivateDriverDataSize, sizeof (VBOXWDDM_ALLOCINFO)));
3877 hr = E_INVALIDARG;
3878 }
3879 return hr;
3880}
3881
3882static HRESULT APIENTRY vboxWddmDDevOpenResource(HANDLE hDevice, D3DDDIARG_OPENRESOURCE* pData)
3883{
3884 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3885 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
3886 HRESULT hr = S_OK;
3887
3888 Assert(pDevice);
3889 Assert(pData->NumAllocations);
3890 PVBOXWDDMDISP_RESOURCE pRc = vboxResourceAlloc(pData->NumAllocations);
3891 Assert(pRc);
3892 if (pRc)
3893 {
3894 pRc->hResource = pData->hResource;
3895 pRc->hKMResource = pData->hKMResource;
3896 pRc->pDevice = pDevice;
3897 pRc->RcDesc.enmRotation = pData->Rotation;
3898 pRc->fFlags = VBOXWDDM_RESOURCE_F_OPENNED;
3899 if (!pData->pPrivateDriverData || !pData->PrivateDriverDataSize)
3900 {
3901 /* this is a "standard" allocation resource */
3902
3903 /* both should be actually zero */
3904 Assert(!pData->pPrivateDriverData && !pData->PrivateDriverDataSize);
3905 pRc->RcDesc.enmPool = D3DDDIPOOL_LOCALVIDMEM;
3906 pRc->RcDesc.enmMultisampleType = D3DDDIMULTISAMPLE_NONE;
3907 pRc->RcDesc.MultisampleQuality = 0;
3908 pRc->RcDesc.MipLevels = 0;
3909 pRc->RcDesc.Fvf;
3910 pRc->RcDesc.fFlags.Value = 0;
3911
3912 Assert(pData->NumAllocations);
3913 D3DDDI_OPENALLOCATIONINFO* pDdiAllocInfo = &pData->pOpenAllocationInfo[0];
3914 Assert(pDdiAllocInfo->pPrivateDriverData);
3915 Assert(pDdiAllocInfo->PrivateDriverDataSize >= sizeof (VBOXWDDM_ALLOCINFO));
3916 if (pDdiAllocInfo->pPrivateDriverData && pDdiAllocInfo->PrivateDriverDataSize >= sizeof (VBOXWDDM_ALLOCINFO))
3917 {
3918 PVBOXWDDM_ALLOCINFO pAllocInfo = (PVBOXWDDM_ALLOCINFO)pDdiAllocInfo->pPrivateDriverData;
3919 switch(pAllocInfo->enmType)
3920 {
3921 case VBOXWDDM_ALLOC_TYPE_STD_SHAREDPRIMARYSURFACE:
3922 pRc->RcDesc.fFlags.Primary = 1;
3923 case VBOXWDDM_ALLOC_TYPE_STD_SHADOWSURFACE:
3924 case VBOXWDDM_ALLOC_TYPE_STD_STAGINGSURFACE:
3925 pRc->RcDesc.enmFormat = pAllocInfo->SurfDesc.format;
3926 pRc->RcDesc.VidPnSourceId = pAllocInfo->SurfDesc.VidPnSourceId;
3927 pRc->RcDesc.RefreshRate = pAllocInfo->SurfDesc.RefreshRate;
3928 break;
3929 default:
3930 AssertBreakpoint();
3931 hr = E_INVALIDARG;
3932 }
3933 }
3934 else
3935 hr = E_INVALIDARG;
3936 }
3937 else
3938 {
3939 /* this is a "generic" resource whose creation is initiaded by the UMD */
3940 Assert(pData->PrivateDriverDataSize == sizeof (VBOXWDDM_RCINFO));
3941 if (pData->PrivateDriverDataSize >= sizeof (VBOXWDDM_RCINFO))
3942 {
3943 VBOXWDDM_RCINFO *pRcInfo = (VBOXWDDM_RCINFO*)pData->pPrivateDriverData;
3944 Assert(pRcInfo->fFlags == VBOXWDDM_RESOURCE_F_TYPE_GENERIC);
3945 Assert(pRcInfo->cAllocInfos == pData->NumAllocations);
3946 pRc->fFlags = pRcInfo->fFlags | VBOXWDDM_RESOURCE_F_OPENNED;
3947 pRc->RcDesc = pRcInfo->RcDesc;
3948 pRc->cAllocations = pData->NumAllocations;
3949 }
3950 else
3951 hr = E_INVALIDARG;
3952 }
3953
3954 if (hr == S_OK)
3955 {
3956 for (UINT i = 0; i < pData->NumAllocations; ++i)
3957 {
3958 hr = vboxAllocationInit(&pRc->aAllocations[i], &pData->pOpenAllocationInfo[i]);
3959 Assert(hr == S_OK);
3960 if (hr != S_OK)
3961 break;
3962 }
3963 }
3964
3965 if (hr == S_OK)
3966 pData->hResource = pRc;
3967 else
3968 vboxResourceFree(pRc);
3969 }
3970 else
3971 {
3972 vboxVDbgPrintR((__FUNCTION__": vboxResourceAlloc failed for hDevice(0x%p), NumAllocations(%d)\n", hDevice, pData->NumAllocations));
3973 hr = E_OUTOFMEMORY;
3974 }
3975
3976 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3977 return hr;
3978}
3979static HRESULT APIENTRY vboxWddmDDevGetCaptureAllocationHandle(HANDLE hDevice, D3DDDIARG_GETCAPTUREALLOCATIONHANDLE* pData)
3980{
3981 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3982 AssertBreakpoint();
3983 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3984 return E_FAIL;
3985}
3986
3987static HRESULT APIENTRY vboxWddmDDevCaptureToSysMem(HANDLE hDevice, CONST D3DDDIARG_CAPTURETOSYSMEM* pData)
3988{
3989 vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3990 AssertBreakpoint();
3991 vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
3992 return E_FAIL;
3993}
3994
3995static HRESULT APIENTRY vboxWddmDispCreateDevice (IN HANDLE hAdapter, IN D3DDDIARG_CREATEDEVICE* pCreateData)
3996{
3997 HRESULT hr = S_OK;
3998 vboxVDbgPrint(("==> "__FUNCTION__", hAdapter(0x%p), Interface(%d), Version(%d)\n", hAdapter, pCreateData->Interface, pCreateData->Version));
3999
4000// AssertBreakpoint();
4001
4002 PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)RTMemAllocZ(sizeof (VBOXWDDMDISP_DEVICE));
4003 if (pDevice)
4004 {
4005 PVBOXWDDMDISP_ADAPTER pAdapter = (PVBOXWDDMDISP_ADAPTER)hAdapter;
4006
4007 pDevice->hDevice = pCreateData->hDevice;
4008 pDevice->pAdapter = pAdapter;
4009 pDevice->u32IfVersion = pCreateData->Interface;
4010 pDevice->uRtVersion = pCreateData->Version;
4011 pDevice->RtCallbacks = *pCreateData->pCallbacks;
4012 pDevice->pvCmdBuffer = pCreateData->pCommandBuffer;
4013 pDevice->cbCmdBuffer = pCreateData->CommandBufferSize;
4014 pDevice->fFlags = pCreateData->Flags;
4015 /* Set Viewport to some default values */
4016 pDevice->ViewPort.X = 0;
4017 pDevice->ViewPort.Y = 0;
4018 pDevice->ViewPort.Width = 1;
4019 pDevice->ViewPort.Height = 1;
4020 pDevice->ViewPort.MinZ = 0.;
4021 pDevice->ViewPort.MaxZ = 1.;
4022
4023 Assert(!pCreateData->AllocationListSize);
4024 Assert(!pCreateData->PatchLocationListSize);
4025
4026 pCreateData->hDevice = pDevice;
4027
4028 pCreateData->pDeviceFuncs->pfnSetRenderState = vboxWddmDDevSetRenderState;
4029 pCreateData->pDeviceFuncs->pfnUpdateWInfo = vboxWddmDDevUpdateWInfo;
4030 pCreateData->pDeviceFuncs->pfnValidateDevice = vboxWddmDDevValidateDevice;
4031 pCreateData->pDeviceFuncs->pfnSetTextureStageState = vboxWddmDDevSetTextureStageState;
4032 pCreateData->pDeviceFuncs->pfnSetTexture = vboxWddmDDevSetTexture;
4033 pCreateData->pDeviceFuncs->pfnSetPixelShader = vboxWddmDDevSetPixelShader;
4034 pCreateData->pDeviceFuncs->pfnSetPixelShaderConst = vboxWddmDDevSetPixelShaderConst;
4035 pCreateData->pDeviceFuncs->pfnSetStreamSourceUm = vboxWddmDDevSetStreamSourceUm;
4036 pCreateData->pDeviceFuncs->pfnSetIndices = vboxWddmDDevSetIndices;
4037 pCreateData->pDeviceFuncs->pfnSetIndicesUm = vboxWddmDDevSetIndicesUm;
4038 pCreateData->pDeviceFuncs->pfnDrawPrimitive = vboxWddmDDevDrawPrimitive;
4039 pCreateData->pDeviceFuncs->pfnDrawIndexedPrimitive = vboxWddmDDevDrawIndexedPrimitive;
4040 pCreateData->pDeviceFuncs->pfnDrawRectPatch = vboxWddmDDevDrawRectPatch;
4041 pCreateData->pDeviceFuncs->pfnDrawTriPatch = vboxWddmDDevDrawTriPatch;
4042 pCreateData->pDeviceFuncs->pfnDrawPrimitive2 = vboxWddmDDevDrawPrimitive2;
4043 pCreateData->pDeviceFuncs->pfnDrawIndexedPrimitive2 = vboxWddmDDevDrawIndexedPrimitive2;
4044 pCreateData->pDeviceFuncs->pfnVolBlt = vboxWddmDDevVolBlt;
4045 pCreateData->pDeviceFuncs->pfnBufBlt = vboxWddmDDevBufBlt;
4046 pCreateData->pDeviceFuncs->pfnTexBlt = vboxWddmDDevTexBlt;
4047 pCreateData->pDeviceFuncs->pfnStateSet = vboxWddmDDevStateSet;
4048 pCreateData->pDeviceFuncs->pfnSetPriority = vboxWddmDDevSetPriority;
4049 pCreateData->pDeviceFuncs->pfnClear = vboxWddmDDevClear;
4050 pCreateData->pDeviceFuncs->pfnUpdatePalette = vboxWddmDDevUpdatePalette;
4051 pCreateData->pDeviceFuncs->pfnSetPalette = vboxWddmDDevSetPalette;
4052 pCreateData->pDeviceFuncs->pfnSetVertexShaderConst = vboxWddmDDevSetVertexShaderConst;
4053 pCreateData->pDeviceFuncs->pfnMultiplyTransform = vboxWddmDDevMultiplyTransform;
4054 pCreateData->pDeviceFuncs->pfnSetTransform = vboxWddmDDevSetTransform;
4055 pCreateData->pDeviceFuncs->pfnSetViewport = vboxWddmDDevSetViewport;
4056 pCreateData->pDeviceFuncs->pfnSetZRange = vboxWddmDDevSetZRange;
4057 pCreateData->pDeviceFuncs->pfnSetMaterial = vboxWddmDDevSetMaterial;
4058 pCreateData->pDeviceFuncs->pfnSetLight = vboxWddmDDevSetLight;
4059 pCreateData->pDeviceFuncs->pfnCreateLight = vboxWddmDDevCreateLight;
4060 pCreateData->pDeviceFuncs->pfnDestroyLight = vboxWddmDDevDestroyLight;
4061 pCreateData->pDeviceFuncs->pfnSetClipPlane = vboxWddmDDevSetClipPlane;
4062 pCreateData->pDeviceFuncs->pfnGetInfo = vboxWddmDDevGetInfo;
4063 pCreateData->pDeviceFuncs->pfnLock = vboxWddmDDevLock;
4064 pCreateData->pDeviceFuncs->pfnUnlock = vboxWddmDDevUnlock;
4065 pCreateData->pDeviceFuncs->pfnCreateResource = vboxWddmDDevCreateResource;
4066 pCreateData->pDeviceFuncs->pfnDestroyResource = vboxWddmDDevDestroyResource;
4067 pCreateData->pDeviceFuncs->pfnSetDisplayMode = vboxWddmDDevSetDisplayMode;
4068 pCreateData->pDeviceFuncs->pfnPresent = vboxWddmDDevPresent;
4069 pCreateData->pDeviceFuncs->pfnFlush = vboxWddmDDevFlush;
4070 pCreateData->pDeviceFuncs->pfnCreateVertexShaderFunc = vboxWddmDDevCreateVertexShaderFunc;
4071 pCreateData->pDeviceFuncs->pfnDeleteVertexShaderFunc = vboxWddmDDevDeleteVertexShaderFunc;
4072 pCreateData->pDeviceFuncs->pfnSetVertexShaderFunc = vboxWddmDDevSetVertexShaderFunc;
4073 pCreateData->pDeviceFuncs->pfnCreateVertexShaderDecl = vboxWddmDDevCreateVertexShaderDecl;
4074 pCreateData->pDeviceFuncs->pfnDeleteVertexShaderDecl = vboxWddmDDevDeleteVertexShaderDecl;
4075 pCreateData->pDeviceFuncs->pfnSetVertexShaderDecl = vboxWddmDDevSetVertexShaderDecl;
4076 pCreateData->pDeviceFuncs->pfnSetVertexShaderConstI = vboxWddmDDevSetVertexShaderConstI;
4077 pCreateData->pDeviceFuncs->pfnSetVertexShaderConstB = vboxWddmDDevSetVertexShaderConstB;
4078 pCreateData->pDeviceFuncs->pfnSetScissorRect = vboxWddmDDevSetScissorRect;
4079 pCreateData->pDeviceFuncs->pfnSetStreamSource = vboxWddmDDevSetStreamSource;
4080 pCreateData->pDeviceFuncs->pfnSetStreamSourceFreq = vboxWddmDDevSetStreamSourceFreq;
4081 pCreateData->pDeviceFuncs->pfnSetConvolutionKernelMono = vboxWddmDDevSetConvolutionKernelMono;
4082 pCreateData->pDeviceFuncs->pfnComposeRects = vboxWddmDDevComposeRects;
4083 pCreateData->pDeviceFuncs->pfnBlt = vboxWddmDDevBlt;
4084 pCreateData->pDeviceFuncs->pfnColorFill = vboxWddmDDevColorFill;
4085 pCreateData->pDeviceFuncs->pfnDepthFill = vboxWddmDDevDepthFill;
4086 pCreateData->pDeviceFuncs->pfnCreateQuery = vboxWddmDDevCreateQuery;
4087 pCreateData->pDeviceFuncs->pfnDestroyQuery = vboxWddmDDevDestroyQuery;
4088 pCreateData->pDeviceFuncs->pfnIssueQuery = vboxWddmDDevIssueQuery;
4089 pCreateData->pDeviceFuncs->pfnGetQueryData = vboxWddmDDevGetQueryData;
4090 pCreateData->pDeviceFuncs->pfnSetRenderTarget = vboxWddmDDevSetRenderTarget;
4091 pCreateData->pDeviceFuncs->pfnSetDepthStencil = vboxWddmDDevSetDepthStencil;
4092 pCreateData->pDeviceFuncs->pfnGenerateMipSubLevels = vboxWddmDDevGenerateMipSubLevels;
4093 pCreateData->pDeviceFuncs->pfnSetPixelShaderConstI = vboxWddmDDevSetPixelShaderConstI;
4094 pCreateData->pDeviceFuncs->pfnSetPixelShaderConstB = vboxWddmDDevSetPixelShaderConstB;
4095 pCreateData->pDeviceFuncs->pfnCreatePixelShader = vboxWddmDDevCreatePixelShader;
4096 pCreateData->pDeviceFuncs->pfnDeletePixelShader = vboxWddmDDevDeletePixelShader;
4097 pCreateData->pDeviceFuncs->pfnCreateDecodeDevice = vboxWddmDDevCreateDecodeDevice;
4098 pCreateData->pDeviceFuncs->pfnDestroyDecodeDevice = vboxWddmDDevDestroyDecodeDevice;
4099 pCreateData->pDeviceFuncs->pfnSetDecodeRenderTarget = vboxWddmDDevSetDecodeRenderTarget;
4100 pCreateData->pDeviceFuncs->pfnDecodeBeginFrame = vboxWddmDDevDecodeBeginFrame;
4101 pCreateData->pDeviceFuncs->pfnDecodeEndFrame = vboxWddmDDevDecodeEndFrame;
4102 pCreateData->pDeviceFuncs->pfnDecodeExecute = vboxWddmDDevDecodeExecute;
4103 pCreateData->pDeviceFuncs->pfnDecodeExtensionExecute = vboxWddmDDevDecodeExtensionExecute;
4104 pCreateData->pDeviceFuncs->pfnCreateVideoProcessDevice = vboxWddmDDevCreateVideoProcessDevice;
4105 pCreateData->pDeviceFuncs->pfnDestroyVideoProcessDevice = vboxWddmDDevDestroyVideoProcessDevice;
4106 pCreateData->pDeviceFuncs->pfnVideoProcessBeginFrame = vboxWddmDDevVideoProcessBeginFrame;
4107 pCreateData->pDeviceFuncs->pfnVideoProcessEndFrame = vboxWddmDDevVideoProcessEndFrame;
4108 pCreateData->pDeviceFuncs->pfnSetVideoProcessRenderTarget = vboxWddmDDevSetVideoProcessRenderTarget;
4109 pCreateData->pDeviceFuncs->pfnVideoProcessBlt = vboxWddmDDevVideoProcessBlt;
4110 pCreateData->pDeviceFuncs->pfnCreateExtensionDevice = vboxWddmDDevCreateExtensionDevice;
4111 pCreateData->pDeviceFuncs->pfnDestroyExtensionDevice = vboxWddmDDevDestroyExtensionDevice;
4112 pCreateData->pDeviceFuncs->pfnExtensionExecute = vboxWddmDDevExtensionExecute;
4113 pCreateData->pDeviceFuncs->pfnCreateOverlay = vboxWddmDDevCreateOverlay;
4114 pCreateData->pDeviceFuncs->pfnUpdateOverlay = vboxWddmDDevUpdateOverlay;
4115 pCreateData->pDeviceFuncs->pfnFlipOverlay = vboxWddmDDevFlipOverlay;
4116 pCreateData->pDeviceFuncs->pfnGetOverlayColorControls = vboxWddmDDevGetOverlayColorControls;
4117 pCreateData->pDeviceFuncs->pfnSetOverlayColorControls = vboxWddmDDevSetOverlayColorControls;
4118 pCreateData->pDeviceFuncs->pfnDestroyOverlay = vboxWddmDDevDestroyOverlay;
4119 pCreateData->pDeviceFuncs->pfnDestroyDevice = vboxWddmDDevDestroyDevice;
4120 pCreateData->pDeviceFuncs->pfnQueryResourceResidency = vboxWddmDDevQueryResourceResidency;
4121 pCreateData->pDeviceFuncs->pfnOpenResource = vboxWddmDDevOpenResource;
4122 pCreateData->pDeviceFuncs->pfnGetCaptureAllocationHandle = vboxWddmDDevGetCaptureAllocationHandle;
4123 pCreateData->pDeviceFuncs->pfnCaptureToSysMem = vboxWddmDDevCaptureToSysMem;
4124 pCreateData->pDeviceFuncs->pfnLockAsync = NULL; //vboxWddmDDevLockAsync;
4125 pCreateData->pDeviceFuncs->pfnUnlockAsync = NULL; //vboxWddmDDevUnlockAsync;
4126 pCreateData->pDeviceFuncs->pfnRename = NULL; //vboxWddmDDevRename;
4127
4128
4129 do
4130 {
4131 Assert(!pCreateData->AllocationListSize
4132 && !pCreateData->PatchLocationListSize);
4133 if (!pCreateData->AllocationListSize
4134 && !pCreateData->PatchLocationListSize)
4135 {
4136 hr = vboxDispCmCtxCreate(pDevice, &pDevice->DefaultContext);
4137 Assert(hr == S_OK);
4138 if (hr == S_OK)
4139 break;
4140 }
4141 else
4142 {
4143 vboxVDbgPrintR((__FUNCTION__": Not implemented: PatchLocationListSize(%d), AllocationListSize(%d)\n",
4144 pCreateData->PatchLocationListSize, pCreateData->AllocationListSize));
4145 //pCreateData->pAllocationList = ??
4146 hr = E_FAIL;
4147 }
4148
4149 RTMemFree(pDevice);
4150 } while (0);
4151 }
4152 else
4153 {
4154 vboxVDbgPrintR((__FUNCTION__": RTMemAllocZ returned NULL\n"));
4155 hr = E_OUTOFMEMORY;
4156 }
4157
4158 vboxVDbgPrint(("<== "__FUNCTION__", hAdapter(0x%p)\n", hAdapter));
4159
4160 return hr;
4161}
4162
4163static HRESULT APIENTRY vboxWddmDispCloseAdapter (IN HANDLE hAdapter)
4164{
4165 vboxVDbgPrint(("==> "__FUNCTION__", hAdapter(0x%p)\n", hAdapter));
4166
4167// AssertBreakpoint();
4168
4169 PVBOXWDDMDISP_ADAPTER pAdapter = (PVBOXWDDMDISP_ADAPTER)hAdapter;
4170 if (VBOXDISPMODE_IS_3D(pAdapter))
4171 {
4172 HRESULT hr = VBoxDispWorkerDestroy(&pAdapter->WndWorker);
4173 Assert(hr == S_OK);
4174 hr = pAdapter->pD3D9If->Release();
4175 Assert(hr == S_OK);
4176 VBoxDispD3DClose(&pAdapter->D3D);
4177 }
4178
4179 vboxCapsFree(pAdapter);
4180
4181 RTMemFree(pAdapter);
4182
4183 vboxVDbgPrint(("<== "__FUNCTION__", hAdapter(0x%p)\n", hAdapter));
4184
4185 return S_OK;
4186}
4187
4188HRESULT APIENTRY OpenAdapter (__inout D3DDDIARG_OPENADAPTER* pOpenData)
4189{
4190 vboxVDbgPrint(("==> "__FUNCTION__"\n"));
4191
4192 VBOXWDDM_QI Query;
4193 D3DDDICB_QUERYADAPTERINFO DdiQuery;
4194 DdiQuery.PrivateDriverDataSize = sizeof(Query);
4195 DdiQuery.pPrivateDriverData = &Query;
4196 HRESULT hr = pOpenData->pAdapterCallbacks->pfnQueryAdapterInfoCb(pOpenData->hAdapter, &DdiQuery);
4197 Assert(hr == S_OK);
4198 if (hr != S_OK)
4199 {
4200 vboxVDbgPrintR((__FUNCTION__": pfnQueryAdapterInfoCb failed, hr (%d)\n", hr));
4201 return E_FAIL;
4202 }
4203
4204 /* check the miniport version match display version */
4205 if (Query.u32Version != VBOXVIDEOIF_VERSION)
4206 {
4207 vboxVDbgPrintR((__FUNCTION__": miniport version mismatch, expected (%d), but was (%d)\n",
4208 VBOXVIDEOIF_VERSION,
4209 Query.u32Version));
4210 return E_FAIL;
4211 }
4212
4213#ifdef VBOX_WITH_VIDEOHWACCEL
4214 Assert(Query.cInfos >= 1);
4215 PVBOXWDDMDISP_ADAPTER pAdapter = (PVBOXWDDMDISP_ADAPTER)RTMemAllocZ(RT_OFFSETOF(VBOXWDDMDISP_ADAPTER, aHeads[Query.cInfos]));
4216#else
4217 PVBOXWDDMDISP_ADAPTER pAdapter = (PVBOXWDDMDISP_ADAPTER)RTMemAllocZ(sizeof (VBOXWDDMDISP_ADAPTER));
4218#endif
4219 Assert(pAdapter);
4220 if (pAdapter)
4221 {
4222 pAdapter->hAdapter = pOpenData->hAdapter;
4223 pAdapter->uIfVersion = pOpenData->Interface;
4224 pAdapter->uRtVersion= pOpenData->Version;
4225 pAdapter->RtCallbacks = *pOpenData->pAdapterCallbacks;
4226
4227 pAdapter->cHeads = Query.cInfos;
4228
4229
4230 pOpenData->hAdapter = pAdapter;
4231 pOpenData->pAdapterFuncs->pfnGetCaps = vboxWddmDispGetCaps;
4232 pOpenData->pAdapterFuncs->pfnCreateDevice = vboxWddmDispCreateDevice;
4233 pOpenData->pAdapterFuncs->pfnCloseAdapter = vboxWddmDispCloseAdapter;
4234 pOpenData->DriverVersion = D3D_UMD_INTERFACE_VERSION;
4235 /*
4236 * here we detect whether we are called by the d3d or ddraw.
4237 * in the d3d case we init our d3d environment
4238 * in the ddraw case we init 2D acceleration
4239 * if interface version is > 7, this is D3D, treat it as so
4240 * otherwise treat it as ddraw
4241 * @todo: need a more clean way of doing this */
4242
4243 if (pAdapter->uIfVersion > 7)
4244 {
4245 do
4246 {
4247 /* try enable the 3D */
4248 hr = VBoxDispD3DOpen(&pAdapter->D3D);
4249 Assert(hr == S_OK);
4250 if (hr == S_OK)
4251 {
4252 hr = pAdapter->D3D.pfnDirect3DCreate9Ex(D3D_SDK_VERSION, &pAdapter->pD3D9If);
4253 Assert(hr == S_OK);
4254 if (hr == S_OK)
4255 {
4256 hr = VBoxDispWorkerCreate(&pAdapter->WndWorker);
4257 Assert(hr == S_OK);
4258 if (hr == S_OK)
4259 {
4260 vboxVDbgPrint((__FUNCTION__": SUCCESS 3D Enabled, pAdapter (0x%p)\n", pAdapter));
4261 break;
4262 }
4263 pAdapter->pD3D9If->Release();
4264 }
4265 else
4266 vboxVDbgPrintR((__FUNCTION__": pfnDirect3DCreate9Ex failed, hr (%d)\n", hr));
4267 VBoxDispD3DClose(&pAdapter->D3D);
4268 }
4269 else
4270 vboxVDbgPrintR((__FUNCTION__": VBoxDispD3DOpen failed, hr (%d)\n", hr));
4271 } while (0);
4272 }
4273#ifdef VBOX_WITH_VIDEOHWACCEL
4274 else
4275 {
4276 for (uint32_t i = 0; i < pAdapter->cHeads; ++i)
4277 {
4278 pAdapter->aHeads[i].Vhwa.Settings = Query.aInfos[i];
4279 }
4280 }
4281#endif
4282
4283 vboxCapsInit(pAdapter);
4284 hr = S_OK;
4285// RTMemFree(pAdapter);
4286 }
4287 else
4288 {
4289 vboxVDbgPrintR((__FUNCTION__": RTMemAllocZ returned NULL\n"));
4290 hr = E_OUTOFMEMORY;
4291 }
4292
4293 vboxVDbgPrint(("<== "__FUNCTION__", hr (%d)\n", hr));
4294
4295 return hr;
4296}
4297
4298#ifdef VBOXWDDMDISP_DEBUG
4299VOID vboxVDbgDoPrint(LPCSTR szString, ...)
4300{
4301 char szBuffer[1024] = {0};
4302 va_list pArgList;
4303 va_start(pArgList, szString);
4304 _vsnprintf(szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0]), szString, pArgList);
4305 va_end(pArgList);
4306
4307 OutputDebugStringA(szBuffer);
4308}
4309#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