VirtualBox

source: vbox/trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-win.cpp@ 69136

Last change on this file since 69136 was 69136, checked in by vboxsync, 7 years ago

Devices/Graphics: VMSVGA support for cubemaps and compressed textures (incomplete, only D3D backend); vertex/index buffer fixes; saved state fixes; cleanup.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 243.0 KB
Line 
1/* $Id: DevVGA-SVGA3d-win.cpp 69136 2017-10-20 07:13:09Z vboxsync $ */
2/** @file
3 * DevVMWare - VMWare SVGA device
4 */
5
6/*
7 * Copyright (C) 2013-2017 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18
19/*********************************************************************************************************************************
20* Header Files *
21*********************************************************************************************************************************/
22#define LOG_GROUP LOG_GROUP_DEV_VMSVGA
23#include <VBox/vmm/pdmdev.h>
24#include <VBox/version.h>
25#include <VBox/err.h>
26#include <VBox/log.h>
27#include <VBox/vmm/pgm.h>
28
29#include <iprt/assert.h>
30#include <iprt/semaphore.h>
31#include <iprt/uuid.h>
32#include <iprt/mem.h>
33#include <iprt/avl.h>
34
35#include <VBoxVideo.h> /* required by DevVGA.h */
36
37/* should go BEFORE any other DevVGA include to make all DevVGA.h config defines be visible */
38#include "DevVGA.h"
39
40#include "DevVGA-SVGA.h"
41#include "DevVGA-SVGA3d.h"
42#include "DevVGA-SVGA3d-internal.h"
43
44/* Enable to disassemble defined shaders. */
45#if defined(DEBUG) && 0 /* Disabled as we don't have the DirectX SDK avaible atm. */
46#define DUMP_SHADER_DISASSEMBLY
47#endif
48
49#ifdef DUMP_SHADER_DISASSEMBLY
50#include <d3dx9shader.h>
51#endif
52
53
54/*********************************************************************************************************************************
55* Defined Constants And Macros *
56*********************************************************************************************************************************/
57/* Enable to render the result of DrawPrimitive in a seperate window. */
58//#define DEBUG_GFX_WINDOW
59
60#define FOURCC_INTZ (D3DFORMAT)MAKEFOURCC('I', 'N', 'T', 'Z')
61#define FOURCC_NULL (D3DFORMAT)MAKEFOURCC('N', 'U', 'L', 'L')
62
63
64/*********************************************************************************************************************************
65* Structures and Typedefs *
66*********************************************************************************************************************************/
67
68typedef struct
69{
70 DWORD Usage;
71 D3DRESOURCETYPE ResourceType;
72 SVGA3dFormatOp FormatOp;
73} VMSVGA3DFORMATSUPPORT;
74
75
76/*********************************************************************************************************************************
77* Global Variables *
78*********************************************************************************************************************************/
79static VMSVGA3DFORMATSUPPORT const g_aFormatSupport[] =
80{
81 {
82 0,
83 D3DRTYPE_SURFACE,
84 SVGA3DFORMAT_OP_OFFSCREENPLAIN,
85 },
86 {
87 D3DUSAGE_RENDERTARGET,
88 D3DRTYPE_SURFACE,
89 (SVGA3dFormatOp) (SVGA3DFORMAT_OP_OFFSCREEN_RENDERTARGET | SVGA3DFORMAT_OP_SAME_FORMAT_RENDERTARGET),
90 },
91 {
92 D3DUSAGE_AUTOGENMIPMAP,
93 D3DRTYPE_TEXTURE,
94 SVGA3DFORMAT_OP_AUTOGENMIPMAP,
95 },
96 {
97 D3DUSAGE_DMAP,
98 D3DRTYPE_TEXTURE,
99 SVGA3DFORMAT_OP_DMAP,
100 },
101 {
102 0,
103 D3DRTYPE_TEXTURE,
104 SVGA3DFORMAT_OP_TEXTURE,
105 },
106 {
107 0,
108 D3DRTYPE_CUBETEXTURE,
109 SVGA3DFORMAT_OP_CUBETEXTURE,
110 },
111 {
112 0,
113 D3DRTYPE_VOLUMETEXTURE,
114 SVGA3DFORMAT_OP_VOLUMETEXTURE,
115 },
116 {
117 D3DUSAGE_QUERY_VERTEXTEXTURE,
118 D3DRTYPE_TEXTURE,
119 SVGA3DFORMAT_OP_VERTEXTEXTURE,
120 },
121 {
122 D3DUSAGE_QUERY_LEGACYBUMPMAP,
123 D3DRTYPE_TEXTURE,
124 SVGA3DFORMAT_OP_BUMPMAP,
125 },
126 {
127 D3DUSAGE_QUERY_SRGBREAD,
128 D3DRTYPE_TEXTURE,
129 SVGA3DFORMAT_OP_SRGBREAD,
130 },
131 {
132 D3DUSAGE_QUERY_SRGBWRITE,
133 D3DRTYPE_TEXTURE,
134 SVGA3DFORMAT_OP_SRGBWRITE,
135 }
136};
137
138static VMSVGA3DFORMATSUPPORT const g_aFeatureReject[] =
139{
140 {
141 D3DUSAGE_QUERY_WRAPANDMIP,
142 D3DRTYPE_TEXTURE,
143 SVGA3DFORMAT_OP_NOTEXCOORDWRAPNORMIP
144 },
145 {
146 D3DUSAGE_QUERY_FILTER,
147 D3DRTYPE_TEXTURE,
148 SVGA3DFORMAT_OP_NOFILTER
149 },
150 {
151 D3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING,
152 D3DRTYPE_TEXTURE, /* ?? */
153 SVGA3DFORMAT_OP_NOALPHABLEND
154 },
155};
156
157
158/*********************************************************************************************************************************
159* Internal Functions *
160*********************************************************************************************************************************/
161static void vmsvgaDumpD3DCaps(D3DCAPS9 *pCaps);
162
163
164#define D3D_RELEASE(ptr) do { \
165 if (ptr) \
166 { \
167 (ptr)->Release(); \
168 (ptr) = 0; \
169 } \
170} while (0)
171
172
173int vmsvga3dInit(PVGASTATE pThis)
174{
175 PVMSVGA3DSTATE pState;
176 int rc;
177
178 pThis->svga.p3dState = pState = (PVMSVGA3DSTATE)RTMemAllocZ(sizeof(VMSVGA3DSTATE));
179 AssertReturn(pThis->svga.p3dState, VERR_NO_MEMORY);
180
181 /* Create event semaphore. */
182 rc = RTSemEventCreate(&pState->WndRequestSem);
183 if (RT_FAILURE(rc))
184 {
185 Log(("%s: Failed to create event semaphore for window handling.\n", __FUNCTION__));
186 return rc;
187 }
188
189 /* Create the async IO thread. */
190 rc = RTThreadCreate(&pState->pWindowThread, vmsvga3dWindowThread, pState->WndRequestSem, 0, RTTHREADTYPE_GUI, 0, "VMSVGA3DWND");
191 if (RT_FAILURE(rc))
192 {
193 AssertMsgFailed(("%s: Async IO Thread creation for 3d window handling failed rc=%d\n", __FUNCTION__, rc));
194 return rc;
195 }
196
197 return VINF_SUCCESS;
198}
199
200int vmsvga3dPowerOn(PVGASTATE pThis)
201{
202 PVMSVGA3DSTATE pState = pThis->svga.p3dState;
203 AssertReturn(pThis->svga.p3dState, VERR_NO_MEMORY);
204 HRESULT hr;
205
206 if (pState->pD3D9)
207 return VINF_SUCCESS; /* already initialized (load state) */
208
209#ifdef VBOX_VMSVGA3D_WITH_WINE_OPENGL
210 pState->pD3D9 = Direct3DCreate9(D3D_SDK_VERSION);
211 AssertReturn(pState->pD3D9, VERR_INTERNAL_ERROR);
212#else
213 /* Direct3DCreate9Ex was introduced in Vista, so resolve it dynamically. */
214 typedef HRESULT (WINAPI *PFNDIRECT3DCREATE9EX)(UINT, IDirect3D9Ex **);
215 PFNDIRECT3DCREATE9EX pfnDirect3dCreate9Ex = (PFNDIRECT3DCREATE9EX)RTLdrGetSystemSymbol("d3d9.dll", "Direct3DCreate9Ex");
216 if (!pfnDirect3dCreate9Ex)
217 return PDMDevHlpVMSetError(pThis->CTX_SUFF(pDevIns), VERR_SYMBOL_NOT_FOUND, RT_SRC_POS,
218 "vmsvga3d: Unable to locate Direct3DCreate9Ex. This feature requires Vista and later.");
219 hr = pfnDirect3dCreate9Ex(D3D_SDK_VERSION, &pState->pD3D9);
220 AssertReturn(hr == D3D_OK, VERR_INTERNAL_ERROR);
221#endif
222 hr = pState->pD3D9->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &pState->caps);
223 AssertReturn(hr == D3D_OK, VERR_INTERNAL_ERROR);
224
225 vmsvgaDumpD3DCaps(&pState->caps);
226
227 /* Check if INTZ is supported. */
228 hr = pState->pD3D9->CheckDeviceFormat(D3DADAPTER_DEFAULT,
229 D3DDEVTYPE_HAL,
230 D3DFMT_X8R8G8B8, /* assume standard 32-bit display mode */
231 0,
232 D3DRTYPE_TEXTURE,
233 FOURCC_INTZ);
234 if (hr != D3D_OK)
235 {
236 /* INTZ support is essential to support depth surfaces used as textures. */
237 LogRel(("VMSVGA: texture format INTZ not supported!!!\n"));
238 }
239 else
240 pState->fSupportedSurfaceINTZ = true;
241
242 /* Check if NULL is supported. */
243 hr = pState->pD3D9->CheckDeviceFormat(D3DADAPTER_DEFAULT,
244 D3DDEVTYPE_HAL,
245 D3DFMT_X8R8G8B8, /* assume standard 32-bit display mode */
246 D3DUSAGE_RENDERTARGET,
247 D3DRTYPE_SURFACE,
248 FOURCC_NULL);
249 if (hr != D3D_OK)
250 {
251 /* NULL is a dummy surface which can be used as a render target to save memory. */
252 LogRel(("VMSVGA: surface format NULL not supported!!!\n"));
253 }
254 else
255 pState->fSupportedSurfaceNULL = true;
256
257
258 /* Check if DX9 depth stencil textures are supported */
259 hr = pState->pD3D9->CheckDeviceFormat(D3DADAPTER_DEFAULT,
260 D3DDEVTYPE_HAL,
261 D3DFMT_X8R8G8B8, /* assume standard 32-bit display mode */
262 D3DUSAGE_DEPTHSTENCIL,
263 D3DRTYPE_TEXTURE,
264 D3DFMT_D16);
265 if (hr != D3D_OK)
266 {
267 LogRel(("VMSVGA: texture format D3DFMT_D16 not supported\n"));
268 }
269
270 hr = pState->pD3D9->CheckDeviceFormat(D3DADAPTER_DEFAULT,
271 D3DDEVTYPE_HAL,
272 D3DFMT_X8R8G8B8, /* assume standard 32-bit display mode */
273 D3DUSAGE_DEPTHSTENCIL,
274 D3DRTYPE_TEXTURE,
275 D3DFMT_D24X8);
276 if (hr != D3D_OK)
277 {
278 LogRel(("VMSVGA: texture format D3DFMT_D24X8 not supported\n"));
279 }
280 hr = pState->pD3D9->CheckDeviceFormat(D3DADAPTER_DEFAULT,
281 D3DDEVTYPE_HAL,
282 D3DFMT_X8R8G8B8, /* assume standard 32-bit display mode */
283 D3DUSAGE_DEPTHSTENCIL,
284 D3DRTYPE_TEXTURE,
285 D3DFMT_D24S8);
286 if (hr != D3D_OK)
287 {
288 LogRel(("VMSVGA: texture format D3DFMT_D24S8 not supported\n"));
289 }
290 return VINF_SUCCESS;
291}
292
293int vmsvga3dReset(PVGASTATE pThis)
294{
295 PVMSVGA3DSTATE pState = pThis->svga.p3dState;
296 AssertReturn(pThis->svga.p3dState, VERR_NO_MEMORY);
297
298 /* Destroy all leftover surfaces. */
299 for (uint32_t i = 0; i < pState->cSurfaces; i++)
300 {
301 if (pState->papSurfaces[i]->id != SVGA3D_INVALID_ID)
302 vmsvga3dSurfaceDestroy(pThis, pState->papSurfaces[i]->id);
303 }
304
305 /* Destroy all leftover contexts. */
306 for (uint32_t i = 0; i < pState->cContexts; i++)
307 {
308 if (pState->papContexts[i]->id != SVGA3D_INVALID_ID)
309 vmsvga3dContextDestroy(pThis, pState->papContexts[i]->id);
310 }
311 return VINF_SUCCESS;
312}
313
314int vmsvga3dTerminate(PVGASTATE pThis)
315{
316 PVMSVGA3DSTATE pState = pThis->svga.p3dState;
317 AssertReturn(pThis->svga.p3dState, VERR_NO_MEMORY);
318
319 int rc = vmsvga3dReset(pThis);
320 AssertRCReturn(rc, rc);
321
322 /* Terminate the window creation thread. */
323 rc = vmsvga3dSendThreadMessage(pState->pWindowThread, pState->WndRequestSem, WM_VMSVGA3D_EXIT, 0, 0);
324 AssertRCReturn(rc, rc);
325
326 RTSemEventDestroy(pState->WndRequestSem);
327
328 D3D_RELEASE(pState->pD3D9);
329
330 return VINF_SUCCESS;
331}
332
333void vmsvga3dUpdateHostScreenViewport(PVGASTATE pThis, uint32_t idScreen, VMSVGAVIEWPORT const *pOldViewport)
334{
335 /** @todo Scroll the screen content without requiring the guest to redraw. */
336 NOREF(pThis); NOREF(idScreen); NOREF(pOldViewport);
337}
338
339static uint32_t vmsvga3dGetSurfaceFormatSupport(PVMSVGA3DSTATE pState3D, uint32_t idx3dCaps, D3DFORMAT format)
340{
341 NOREF(idx3dCaps);
342 HRESULT hr;
343 uint32_t result = 0;
344
345 /* Try if the format can be used for the primary display. */
346 hr = pState3D->pD3D9->CheckDeviceFormat(D3DADAPTER_DEFAULT,
347 D3DDEVTYPE_HAL,
348 format,
349 0,
350 D3DRTYPE_SURFACE,
351 format);
352
353 for (unsigned i = 0; i < RT_ELEMENTS(g_aFormatSupport); i++)
354 {
355 hr = pState3D->pD3D9->CheckDeviceFormat(D3DADAPTER_DEFAULT,
356 D3DDEVTYPE_HAL,
357 D3DFMT_X8R8G8B8, /* assume standard 32-bit display mode */
358 g_aFormatSupport[i].Usage,
359 g_aFormatSupport[i].ResourceType,
360 format);
361 if (hr == D3D_OK)
362 result |= g_aFormatSupport[i].FormatOp;
363 }
364
365 /* Check for features only if the format is supported in any form. */
366 if (result)
367 {
368 for (unsigned i = 0; i < RT_ELEMENTS(g_aFeatureReject); i++)
369 {
370 hr = pState3D->pD3D9->CheckDeviceFormat(D3DADAPTER_DEFAULT,
371 D3DDEVTYPE_HAL,
372 D3DFMT_X8R8G8B8, /* assume standard 32-bit display mode */
373 g_aFeatureReject[i].Usage,
374 g_aFeatureReject[i].ResourceType,
375 format);
376 if (hr != D3D_OK)
377 result |= g_aFeatureReject[i].FormatOp;
378 }
379 }
380
381 /** @todo missing:
382 *
383 * SVGA3DFORMAT_OP_PIXELSIZE
384 */
385
386 switch (idx3dCaps)
387 {
388 case SVGA3D_DEVCAP_SURFACEFMT_X8R8G8B8:
389 case SVGA3D_DEVCAP_SURFACEFMT_X1R5G5B5:
390 case SVGA3D_DEVCAP_SURFACEFMT_R5G6B5:
391 result |= SVGA3DFORMAT_OP_MEMBEROFGROUP_ARGB
392 | SVGA3DFORMAT_OP_CONVERT_TO_ARGB
393 | SVGA3DFORMAT_OP_DISPLAYMODE /* Should not be set for alpha formats. */
394 | SVGA3DFORMAT_OP_3DACCELERATION; /* implies OP_DISPLAYMODE */
395 break;
396
397 case SVGA3D_DEVCAP_SURFACEFMT_A8R8G8B8:
398 case SVGA3D_DEVCAP_SURFACEFMT_A2R10G10B10:
399 case SVGA3D_DEVCAP_SURFACEFMT_A1R5G5B5:
400 case SVGA3D_DEVCAP_SURFACEFMT_A4R4G4B4:
401 result |= SVGA3DFORMAT_OP_MEMBEROFGROUP_ARGB
402 | SVGA3DFORMAT_OP_CONVERT_TO_ARGB
403 | SVGA3DFORMAT_OP_SAME_FORMAT_UP_TO_ALPHA_RENDERTARGET;
404 break;
405
406 }
407 Log(("CAPS: %s =\n%s\n", vmsvga3dGetCapString(idx3dCaps), vmsvga3dGet3dFormatString(result)));
408
409 return result;
410}
411
412static uint32_t vmsvga3dGetDepthFormatSupport(PVMSVGA3DSTATE pState3D, uint32_t idx3dCaps, D3DFORMAT format)
413{
414 RT_NOREF(idx3dCaps);
415 HRESULT hr;
416 uint32_t result = 0;
417
418 hr = pState3D->pD3D9->CheckDeviceFormat(D3DADAPTER_DEFAULT,
419 D3DDEVTYPE_HAL,
420 D3DFMT_X8R8G8B8, /* assume standard 32-bit display mode */
421 D3DUSAGE_DEPTHSTENCIL,
422 D3DRTYPE_SURFACE,
423 format);
424 if (hr == D3D_OK)
425 result = SVGA3DFORMAT_OP_ZSTENCIL
426 | SVGA3DFORMAT_OP_ZSTENCIL_WITH_ARBITRARY_COLOR_DEPTH
427 | SVGA3DFORMAT_OP_TEXTURE /* Necessary for Ubuntu Unity */;
428
429 Log(("CAPS: %s =\n%s\n", vmsvga3dGetCapString(idx3dCaps), vmsvga3dGet3dFormatString(result)));
430 return result;
431}
432
433
434int vmsvga3dQueryCaps(PVGASTATE pThis, uint32_t idx3dCaps, uint32_t *pu32Val)
435{
436 PVMSVGA3DSTATE pState = pThis->svga.p3dState;
437 AssertReturn(pState, VERR_NO_MEMORY);
438 D3DCAPS9 *pCaps = &pState->caps;
439 int rc = VINF_SUCCESS;
440
441 *pu32Val = 0;
442
443 switch (idx3dCaps)
444 {
445 case SVGA3D_DEVCAP_3D:
446 *pu32Val = 1; /* boolean? */
447 break;
448
449 case SVGA3D_DEVCAP_MAX_LIGHTS:
450 *pu32Val = pCaps->MaxActiveLights;
451 break;
452
453 case SVGA3D_DEVCAP_MAX_TEXTURES:
454 *pu32Val = pCaps->MaxSimultaneousTextures;
455 break;
456
457 case SVGA3D_DEVCAP_MAX_CLIP_PLANES:
458 *pu32Val = pCaps->MaxUserClipPlanes;
459 break;
460
461 case SVGA3D_DEVCAP_VERTEX_SHADER_VERSION:
462 switch (pCaps->VertexShaderVersion)
463 {
464 case D3DVS_VERSION(1,1):
465 *pu32Val = SVGA3DVSVERSION_11;
466 break;
467 case D3DVS_VERSION(2,0):
468 *pu32Val = SVGA3DVSVERSION_20;
469 break;
470 case D3DVS_VERSION(3,0):
471 *pu32Val = SVGA3DVSVERSION_30;
472 break;
473 case D3DVS_VERSION(4,0):
474 *pu32Val = SVGA3DVSVERSION_40;
475 break;
476 default:
477 LogRel(("VMSVGA: Unsupported vertex shader version %x\n", pCaps->VertexShaderVersion));
478 break;
479 }
480 break;
481
482 case SVGA3D_DEVCAP_VERTEX_SHADER:
483 /* boolean? */
484 *pu32Val = 1;
485 break;
486
487 case SVGA3D_DEVCAP_FRAGMENT_SHADER_VERSION:
488 switch (pCaps->PixelShaderVersion)
489 {
490 case D3DPS_VERSION(1,1):
491 *pu32Val = SVGA3DPSVERSION_11;
492 break;
493 case D3DPS_VERSION(1,2):
494 *pu32Val = SVGA3DPSVERSION_12;
495 break;
496 case D3DPS_VERSION(1,3):
497 *pu32Val = SVGA3DPSVERSION_13;
498 break;
499 case D3DPS_VERSION(1,4):
500 *pu32Val = SVGA3DPSVERSION_14;
501 break;
502 case D3DPS_VERSION(2,0):
503 *pu32Val = SVGA3DPSVERSION_20;
504 break;
505 case D3DPS_VERSION(3,0):
506 *pu32Val = SVGA3DPSVERSION_30;
507 break;
508 case D3DPS_VERSION(4,0):
509 *pu32Val = SVGA3DPSVERSION_40;
510 break;
511 default:
512 LogRel(("VMSVGA: Unsupported pixel shader version %x\n", pCaps->PixelShaderVersion));
513 break;
514 }
515 break;
516
517 case SVGA3D_DEVCAP_FRAGMENT_SHADER:
518 /* boolean? */
519 *pu32Val = 1;
520 break;
521
522 case SVGA3D_DEVCAP_S23E8_TEXTURES:
523 case SVGA3D_DEVCAP_S10E5_TEXTURES:
524 /* Must be obsolete by now; surface format caps specify the same thing. */
525 rc = VERR_INVALID_PARAMETER;
526 break;
527
528 case SVGA3D_DEVCAP_MAX_FIXED_VERTEXBLEND:
529 break;
530
531 /*
532 * 2. The BUFFER_FORMAT capabilities are deprecated, and they always
533 * return TRUE. Even on physical hardware that does not support
534 * these formats natively, the SVGA3D device will provide an emulation
535 * which should be invisible to the guest OS.
536 */
537 case SVGA3D_DEVCAP_D16_BUFFER_FORMAT:
538 case SVGA3D_DEVCAP_D24S8_BUFFER_FORMAT:
539 case SVGA3D_DEVCAP_D24X8_BUFFER_FORMAT:
540 *pu32Val = 1;
541 break;
542
543 case SVGA3D_DEVCAP_QUERY_TYPES:
544 break;
545
546 case SVGA3D_DEVCAP_TEXTURE_GRADIENT_SAMPLING:
547 break;
548
549 case SVGA3D_DEVCAP_MAX_POINT_SIZE:
550 AssertCompile(sizeof(uint32_t) == sizeof(float));
551 *(float *)pu32Val = pCaps->MaxPointSize;
552 break;
553
554 case SVGA3D_DEVCAP_MAX_SHADER_TEXTURES:
555 /** @todo ?? */
556 rc = VERR_INVALID_PARAMETER;
557 break;
558
559 case SVGA3D_DEVCAP_MAX_TEXTURE_WIDTH:
560 *pu32Val = pCaps->MaxTextureWidth;
561 break;
562
563 case SVGA3D_DEVCAP_MAX_TEXTURE_HEIGHT:
564 *pu32Val = pCaps->MaxTextureHeight;
565 break;
566
567 case SVGA3D_DEVCAP_MAX_VOLUME_EXTENT:
568 *pu32Val = pCaps->MaxVolumeExtent;
569 break;
570
571 case SVGA3D_DEVCAP_MAX_TEXTURE_REPEAT:
572 *pu32Val = pCaps->MaxTextureRepeat;
573 break;
574
575 case SVGA3D_DEVCAP_MAX_TEXTURE_ASPECT_RATIO:
576 *pu32Val = pCaps->MaxTextureAspectRatio;
577 break;
578
579 case SVGA3D_DEVCAP_MAX_TEXTURE_ANISOTROPY:
580 *pu32Val = pCaps->MaxAnisotropy;
581 break;
582
583 case SVGA3D_DEVCAP_MAX_PRIMITIVE_COUNT:
584 *pu32Val = pCaps->MaxPrimitiveCount;
585 break;
586
587 case SVGA3D_DEVCAP_MAX_VERTEX_INDEX:
588 *pu32Val = pCaps->MaxVertexIndex;
589 break;
590
591 case SVGA3D_DEVCAP_MAX_VERTEX_SHADER_INSTRUCTIONS:
592 *pu32Val = pCaps->MaxVertexShader30InstructionSlots;
593 break;
594
595 case SVGA3D_DEVCAP_MAX_FRAGMENT_SHADER_INSTRUCTIONS:
596 *pu32Val = pCaps->MaxPixelShader30InstructionSlots;
597 break;
598
599 case SVGA3D_DEVCAP_MAX_VERTEX_SHADER_TEMPS:
600 *pu32Val = pCaps->VS20Caps.NumTemps;
601 break;
602
603 case SVGA3D_DEVCAP_MAX_FRAGMENT_SHADER_TEMPS:
604 *pu32Val = pCaps->PS20Caps.NumTemps;
605 break;
606
607 case SVGA3D_DEVCAP_TEXTURE_OPS:
608 break;
609
610 case SVGA3D_DEVCAP_MULTISAMPLE_NONMASKABLESAMPLES:
611 break;
612
613 case SVGA3D_DEVCAP_MULTISAMPLE_MASKABLESAMPLES:
614 break;
615
616 case SVGA3D_DEVCAP_ALPHATOCOVERAGE:
617 break;
618
619 case SVGA3D_DEVCAP_SUPERSAMPLE:
620 break;
621
622 case SVGA3D_DEVCAP_AUTOGENMIPMAPS:
623 *pu32Val = !!(pCaps->Caps2 & D3DCAPS2_CANAUTOGENMIPMAP);
624 break;
625
626 case SVGA3D_DEVCAP_MAX_VERTEX_SHADER_TEXTURES:
627 break;
628
629 case SVGA3D_DEVCAP_MAX_RENDER_TARGETS: /** @todo same thing? */
630 case SVGA3D_DEVCAP_MAX_SIMULTANEOUS_RENDER_TARGETS:
631 *pu32Val = pCaps->NumSimultaneousRTs;
632 break;
633
634 /*
635 * This is the maximum number of SVGA context IDs that the guest
636 * can define using SVGA_3D_CMD_CONTEXT_DEFINE.
637 */
638 case SVGA3D_DEVCAP_MAX_CONTEXT_IDS:
639 *pu32Val = SVGA3D_MAX_CONTEXT_IDS;
640 break;
641
642 /*
643 * This is the maximum number of SVGA surface IDs that the guest
644 * can define using SVGA_3D_CMD_SURFACE_DEFINE*.
645 */
646 case SVGA3D_DEVCAP_MAX_SURFACE_IDS:
647 *pu32Val = SVGA3D_MAX_SURFACE_IDS;
648 break;
649
650 /* Supported surface formats. */
651 case SVGA3D_DEVCAP_SURFACEFMT_X8R8G8B8:
652 *pu32Val = vmsvga3dGetSurfaceFormatSupport(pState, idx3dCaps, D3DFMT_X8R8G8B8);
653 break;
654
655 case SVGA3D_DEVCAP_SURFACEFMT_A8R8G8B8:
656 *pu32Val = vmsvga3dGetSurfaceFormatSupport(pState, idx3dCaps, D3DFMT_A8R8G8B8);
657 break;
658
659 case SVGA3D_DEVCAP_SURFACEFMT_A2R10G10B10:
660 *pu32Val = vmsvga3dGetSurfaceFormatSupport(pState, idx3dCaps, D3DFMT_A2R10G10B10);
661 break;
662
663 case SVGA3D_DEVCAP_SURFACEFMT_X1R5G5B5:
664 *pu32Val = vmsvga3dGetSurfaceFormatSupport(pState, idx3dCaps, D3DFMT_X1R5G5B5);
665 break;
666
667 case SVGA3D_DEVCAP_SURFACEFMT_A1R5G5B5:
668 *pu32Val = vmsvga3dGetSurfaceFormatSupport(pState, idx3dCaps, D3DFMT_A1R5G5B5);
669 break;
670
671 case SVGA3D_DEVCAP_SURFACEFMT_A4R4G4B4:
672 *pu32Val = vmsvga3dGetSurfaceFormatSupport(pState, idx3dCaps, D3DFMT_A4R4G4B4);
673 break;
674
675 case SVGA3D_DEVCAP_SURFACEFMT_R5G6B5:
676 *pu32Val = vmsvga3dGetSurfaceFormatSupport(pState, idx3dCaps, D3DFMT_A4R4G4B4);
677 break;
678
679 case SVGA3D_DEVCAP_SURFACEFMT_LUMINANCE16:
680 *pu32Val = vmsvga3dGetSurfaceFormatSupport(pState, idx3dCaps, D3DFMT_L16);
681 break;
682
683 case SVGA3D_DEVCAP_SURFACEFMT_LUMINANCE8_ALPHA8:
684 *pu32Val = vmsvga3dGetSurfaceFormatSupport(pState, idx3dCaps, D3DFMT_A8L8);
685 break;
686
687 case SVGA3D_DEVCAP_SURFACEFMT_ALPHA8:
688 *pu32Val = vmsvga3dGetSurfaceFormatSupport(pState, idx3dCaps, D3DFMT_A8);
689 break;
690
691 case SVGA3D_DEVCAP_SURFACEFMT_LUMINANCE8:
692 *pu32Val = vmsvga3dGetSurfaceFormatSupport(pState, idx3dCaps, D3DFMT_L8);
693 break;
694
695 case SVGA3D_DEVCAP_SURFACEFMT_Z_D16:
696 *pu32Val = vmsvga3dGetDepthFormatSupport(pState, idx3dCaps, D3DFMT_D16);
697 break;
698
699 case SVGA3D_DEVCAP_SURFACEFMT_Z_D24S8:
700 case SVGA3D_DEVCAP_SURFACEFMT_Z_D24S8_INT: /** @todo not correct */
701 *pu32Val = vmsvga3dGetDepthFormatSupport(pState, idx3dCaps, D3DFMT_D24S8);
702 break;
703
704 case SVGA3D_DEVCAP_SURFACEFMT_Z_D24X8:
705 *pu32Val = vmsvga3dGetDepthFormatSupport(pState, idx3dCaps, D3DFMT_D24X8);
706 break;
707
708 case SVGA3D_DEVCAP_SURFACEFMT_Z_DF16:
709 /** @todo supposed to be floating-point, but unable to find a match for D3D9... */
710 *pu32Val = 0;
711 break;
712
713 case SVGA3D_DEVCAP_SURFACEFMT_Z_DF24:
714 *pu32Val = vmsvga3dGetDepthFormatSupport(pState, idx3dCaps, D3DFMT_D24FS8);
715 break;
716
717 case SVGA3D_DEVCAP_SURFACEFMT_DXT1:
718 *pu32Val = vmsvga3dGetSurfaceFormatSupport(pState, idx3dCaps, D3DFMT_DXT1);
719 break;
720
721 case SVGA3D_DEVCAP_SURFACEFMT_DXT2:
722 *pu32Val = vmsvga3dGetSurfaceFormatSupport(pState, idx3dCaps, D3DFMT_DXT2);
723 break;
724
725 case SVGA3D_DEVCAP_SURFACEFMT_DXT3:
726 *pu32Val = vmsvga3dGetSurfaceFormatSupport(pState, idx3dCaps, D3DFMT_DXT3);
727 break;
728
729 case SVGA3D_DEVCAP_SURFACEFMT_DXT4:
730 *pu32Val = vmsvga3dGetSurfaceFormatSupport(pState, idx3dCaps, D3DFMT_DXT4);
731 break;
732
733 case SVGA3D_DEVCAP_SURFACEFMT_DXT5:
734 *pu32Val = vmsvga3dGetSurfaceFormatSupport(pState, idx3dCaps, D3DFMT_DXT5);
735 break;
736
737 case SVGA3D_DEVCAP_SURFACEFMT_BUMPX8L8V8U8:
738 *pu32Val = vmsvga3dGetSurfaceFormatSupport(pState, idx3dCaps, D3DFMT_X8L8V8U8);
739 break;
740
741 case SVGA3D_DEVCAP_SURFACEFMT_A2W10V10U10:
742 *pu32Val = vmsvga3dGetSurfaceFormatSupport(pState, idx3dCaps, D3DFMT_A2W10V10U10);
743 break;
744
745 case SVGA3D_DEVCAP_SURFACEFMT_BUMPU8V8:
746 *pu32Val = vmsvga3dGetSurfaceFormatSupport(pState, idx3dCaps, D3DFMT_V8U8);
747 break;
748
749 case SVGA3D_DEVCAP_SURFACEFMT_Q8W8V8U8:
750 *pu32Val = vmsvga3dGetSurfaceFormatSupport(pState, idx3dCaps, D3DFMT_Q8W8V8U8);
751 break;
752
753 case SVGA3D_DEVCAP_SURFACEFMT_CxV8U8:
754 *pu32Val = vmsvga3dGetSurfaceFormatSupport(pState, idx3dCaps, D3DFMT_CxV8U8);
755 break;
756
757 case SVGA3D_DEVCAP_SURFACEFMT_R_S10E5:
758 *pu32Val = vmsvga3dGetSurfaceFormatSupport(pState, idx3dCaps, D3DFMT_R16F);
759 break;
760
761 case SVGA3D_DEVCAP_SURFACEFMT_R_S23E8:
762 *pu32Val = vmsvga3dGetSurfaceFormatSupport(pState, idx3dCaps, D3DFMT_R32F);
763 break;
764
765 case SVGA3D_DEVCAP_SURFACEFMT_RG_S10E5:
766 *pu32Val = vmsvga3dGetSurfaceFormatSupport(pState, idx3dCaps, D3DFMT_G16R16F);
767 break;
768
769 case SVGA3D_DEVCAP_SURFACEFMT_RG_S23E8:
770 *pu32Val = vmsvga3dGetSurfaceFormatSupport(pState, idx3dCaps, D3DFMT_G32R32F);
771 break;
772
773 case SVGA3D_DEVCAP_SURFACEFMT_ARGB_S10E5:
774 *pu32Val = vmsvga3dGetSurfaceFormatSupport(pState, idx3dCaps, D3DFMT_A16B16G16R16F);
775 break;
776
777 case SVGA3D_DEVCAP_SURFACEFMT_ARGB_S23E8:
778 *pu32Val = vmsvga3dGetSurfaceFormatSupport(pState, idx3dCaps, D3DFMT_A32B32G32R32F);
779 break;
780
781 case SVGA3D_DEVCAP_SURFACEFMT_V16U16:
782 *pu32Val = vmsvga3dGetSurfaceFormatSupport(pState, idx3dCaps, D3DFMT_V16U16);
783 break;
784
785 case SVGA3D_DEVCAP_SURFACEFMT_G16R16:
786 *pu32Val = vmsvga3dGetSurfaceFormatSupport(pState, idx3dCaps, D3DFMT_G16R16);
787 break;
788
789 case SVGA3D_DEVCAP_SURFACEFMT_A16B16G16R16:
790 *pu32Val = vmsvga3dGetSurfaceFormatSupport(pState, idx3dCaps, D3DFMT_A16B16G16R16);
791 break;
792
793 case SVGA3D_DEVCAP_SURFACEFMT_UYVY:
794 *pu32Val = vmsvga3dGetSurfaceFormatSupport(pState, idx3dCaps, D3DFMT_UYVY);
795 break;
796
797 case SVGA3D_DEVCAP_SURFACEFMT_YUY2:
798 *pu32Val = vmsvga3dGetSurfaceFormatSupport(pState, idx3dCaps, D3DFMT_YUY2);
799 break;
800
801 case SVGA3D_DEVCAP_SURFACEFMT_NV12:
802 *pu32Val = vmsvga3dGetSurfaceFormatSupport(pState, idx3dCaps, (D3DFORMAT)MAKEFOURCC('N', 'V', '1', '2'));
803 break;
804
805 case SVGA3D_DEVCAP_SURFACEFMT_AYUV:
806 *pu32Val = vmsvga3dGetSurfaceFormatSupport(pState, idx3dCaps, (D3DFORMAT)MAKEFOURCC('A', 'Y', 'U', 'V'));
807 break;
808
809 case SVGA3D_DEVCAP_SURFACEFMT_BC4_UNORM:
810 case SVGA3D_DEVCAP_SURFACEFMT_BC5_UNORM:
811 /* Unknown; only in DX10 & 11 */
812 Log(("CAPS: Unknown CAP %s\n", vmsvga3dGetCapString(idx3dCaps)));
813 rc = VERR_INVALID_PARAMETER;
814 *pu32Val = 0;
815 break;
816
817 default:
818 Log(("CAPS: Unexpected CAP %d\n", idx3dCaps));
819 rc = VERR_INVALID_PARAMETER;
820 break;
821 }
822#if 0
823 /* Dump of VMWare Player caps (from their log); for debugging purposes */
824 switch (idx3dCaps)
825 {
826 case 0:
827 *pu32Val = 0x00000001;
828 break;
829 case 1:
830 *pu32Val = 0x0000000a;
831 break;
832 case 2:
833 *pu32Val = 0x00000008;
834 break;
835 case 3: *pu32Val = 0x00000006; break;
836 case 4: *pu32Val = 0x00000007; break;
837 case 5: *pu32Val = 0x00000001; break;
838 case 6: *pu32Val = 0x0000000d; break;
839 case 7: *pu32Val = 0x00000001; break;
840 case 8: *pu32Val = 0x00000004; break;
841 case 9: *pu32Val = 0x00000001; break;
842 case 10: *pu32Val = 0x00000001; break;
843 case 11: *pu32Val = 0x00000004; break;
844 case 12: *pu32Val = 0x00000001; break;
845 case 13: *pu32Val = 0x00000001; break;
846 case 14: *pu32Val = 0x00000001; break;
847 case 15: *pu32Val = 0x00000001; break;
848 case 16: *pu32Val = 0x00000001; break;
849 case 17: *pu32Val = (uint32_t)256.000000; break;
850 case 18: *pu32Val = 0x00000014; break;
851 case 19: *pu32Val = 0x00001000; break;
852 case 20: *pu32Val = 0x00001000; break;
853 case 21: *pu32Val = 0x00000800; break;
854 case 22: *pu32Val = 0x00002000; break;
855 case 23: *pu32Val = 0x00000800; break;
856 case 24: *pu32Val = 0x00000010; break;
857 case 25: *pu32Val = 0x000fffff; break;
858 case 26: *pu32Val = 0x00ffffff; break;
859 case 27: *pu32Val = 0xffffffff; break;
860 case 28: *pu32Val = 0xffffffff; break;
861 case 29: *pu32Val = 0x00000020; break;
862 case 30: *pu32Val = 0x00000020; break;
863 case 31: *pu32Val = 0x03ffffff; break;
864 case 32: *pu32Val = 0x0098ec1f; break;
865 case 33: *pu32Val = 0x0098e11f; break;
866 case 34: *pu32Val = 0x0098e01f; break;
867 case 35: *pu32Val = 0x012c2000; break;
868 case 36: *pu32Val = 0x0098e11f; break;
869 case 37: *pu32Val = 0x0090c11f; break;
870 case 38: *pu32Val = 0x0098ec1f; break;
871 case 39: *pu32Val = 0x00804007; break;
872 case 40: *pu32Val = 0x0080c007; break;
873 case 41: *pu32Val = 0x00804007; break;
874 case 42: *pu32Val = 0x0080c007; break;
875 case 43: *pu32Val = 0x000000c1; break;
876 case 44: *pu32Val = 0x000000c1; break;
877 case 45: *pu32Val = 0x000000c1; break;
878 case 46: *pu32Val = 0x00808005; break;
879 case 47: *pu32Val = 0x00808005; break;
880 case 48: *pu32Val = 0x00808005; break;
881 case 49: *pu32Val = 0x00808005; break;
882 case 50: *pu32Val = 0x00808005; break;
883 case 51: *pu32Val = 0x01240000; break;
884 case 52: *pu32Val = 0x00814007; break;
885 case 53: *pu32Val = 0x00814007; break;
886 case 54: *pu32Val = 0x00814007; break;
887 case 55: *pu32Val = 0x01240000; break;
888 case 56: *pu32Val = 0x0080401f; break;
889 case 57: *pu32Val = 0x0080401f; break;
890 case 58: *pu32Val = 0x0080401f; break;
891 case 59: *pu32Val = 0x0080401f; break;
892 case 60: *pu32Val = 0x0080601f; break;
893 case 61: *pu32Val = 0x0080401f; break;
894 case 62: *pu32Val = 0x00000000; break;
895 case 63: *pu32Val = 0x00000004; break;
896 case 64: *pu32Val = 0x00000004; break;
897 case 65: *pu32Val = 0x00814005; break;
898 case 66: *pu32Val = 0x0080401f; break;
899 case 67: *pu32Val = 0x0080601f; break;
900 case 68: *pu32Val = 0x00006009; break;
901 case 69: *pu32Val = 0x00006001; break;
902 case 70: *pu32Val = 0x00000001; break;
903 case 71: *pu32Val = 0x0000000b; break;
904 case 72: *pu32Val = 0x00000001; break;
905 case 73: *pu32Val = 0x00000000; break;
906 case 74: *pu32Val = 0x00000000; break;
907 case 75: *pu32Val = 0x01246000; break;
908 case 76: *pu32Val = 0x00004009; break;
909 case 77: *pu32Val = 0x00000100; break;
910 case 78: *pu32Val = 0x00008000; break;
911 case 79: *pu32Val = 0x000000c1; break;
912 case 80: *pu32Val = 0x01240000; break;
913 case 81: *pu32Val = 0x000000c1; break;
914 case 82: *pu32Val = 0x00800005; break;
915 case 83: *pu32Val = 0x00800005; break;
916 case 84: *pu32Val = 0x00000000; break;
917 case 85: *pu32Val = 0x00000000; break;
918 case 86: *pu32Val = 0x00000000; break;
919 case 87: *pu32Val = 0x00000000; break;
920 case 88: *pu32Val = 0x00000000; break;
921 case 89: *pu32Val = (uint32_t) 0.000000; break;
922 case 90: *pu32Val = (uint32_t) 0.000000; break;
923 case 91: *pu32Val = 0x00006009; break;
924 default:
925// Log(("CAPS: Unexpected CAP %d\n", idx3dCaps));
926// rc = VERR_INVALID_PARAMETER;
927 break;
928 }
929#endif
930 Log(("CAPS: %d=%s - %x\n", idx3dCaps, vmsvga3dGetCapString(idx3dCaps), *pu32Val));
931 return rc;
932}
933
934/**
935 * Convert SVGA format value to its D3D equivalent
936 */
937D3DFORMAT vmsvga3dSurfaceFormat2D3D(SVGA3dSurfaceFormat format)
938{
939 switch (format)
940 {
941 case SVGA3D_X8R8G8B8:
942 return D3DFMT_X8R8G8B8;
943 case SVGA3D_A8R8G8B8:
944 return D3DFMT_A8R8G8B8;
945 case SVGA3D_R5G6B5:
946 return D3DFMT_R5G6B5;
947 case SVGA3D_X1R5G5B5:
948 return D3DFMT_X1R5G5B5;
949 case SVGA3D_A1R5G5B5:
950 return D3DFMT_A1R5G5B5;
951 case SVGA3D_A4R4G4B4:
952 return D3DFMT_A4R4G4B4;
953
954 case SVGA3D_Z_D32:
955 return D3DFMT_D32;
956 case SVGA3D_Z_D16:
957 return D3DFMT_D16;
958 case SVGA3D_Z_D24S8_INT: /** @todo not correct */
959 case SVGA3D_Z_D24S8:
960 return D3DFMT_D24S8;
961 case SVGA3D_Z_D15S1:
962 return D3DFMT_D15S1;
963 case SVGA3D_Z_D24X8:
964 return D3DFMT_D24X8;
965 /* Advanced D3D9 depth formats. */
966 case SVGA3D_Z_DF16:
967 /** @todo supposed to be floating-point, but unable to find a match for D3D9... */
968 AssertFailedReturn(D3DFMT_UNKNOWN);
969 case SVGA3D_Z_DF24:
970 return D3DFMT_D24FS8;
971
972 case SVGA3D_LUMINANCE8:
973 return D3DFMT_L8;
974 case SVGA3D_LUMINANCE4_ALPHA4:
975 return D3DFMT_A4L4;
976 case SVGA3D_LUMINANCE16:
977 return D3DFMT_L16;
978 case SVGA3D_LUMINANCE8_ALPHA8:
979 return D3DFMT_A8L8;
980
981 case SVGA3D_DXT1:
982 return D3DFMT_DXT1;
983 case SVGA3D_DXT2:
984 return D3DFMT_DXT2;
985 case SVGA3D_DXT3:
986 return D3DFMT_DXT3;
987 case SVGA3D_DXT4:
988 return D3DFMT_DXT4;
989 case SVGA3D_DXT5:
990 return D3DFMT_DXT5;
991
992 /* Bump-map formats */
993 case SVGA3D_BUMPU8V8:
994 return D3DFMT_V8U8;
995 case SVGA3D_BUMPL6V5U5:
996 return D3DFMT_L6V5U5;
997 case SVGA3D_BUMPX8L8V8U8:
998 return D3DFMT_X8L8V8U8;
999 case SVGA3D_BUMPL8V8U8:
1000 /* No corresponding D3D9 equivalent. */
1001 AssertFailedReturn(D3DFMT_UNKNOWN);
1002 /* signed bump-map formats */
1003 case SVGA3D_V8U8:
1004 return D3DFMT_V8U8;
1005 case SVGA3D_Q8W8V8U8:
1006 return D3DFMT_Q8W8V8U8;
1007 case SVGA3D_CxV8U8:
1008 return D3DFMT_CxV8U8;
1009 /* mixed bump-map formats */
1010 case SVGA3D_X8L8V8U8:
1011 return D3DFMT_X8L8V8U8;
1012 case SVGA3D_A2W10V10U10:
1013 return D3DFMT_A2W10V10U10;
1014
1015 case SVGA3D_ARGB_S10E5: /* 16-bit floating-point ARGB */
1016 return D3DFMT_A16B16G16R16F;
1017 case SVGA3D_ARGB_S23E8: /* 32-bit floating-point ARGB */
1018 return D3DFMT_A32B32G32R32F;
1019
1020 case SVGA3D_A2R10G10B10:
1021 return D3DFMT_A2R10G10B10;
1022
1023 case SVGA3D_ALPHA8:
1024 return D3DFMT_A8;
1025
1026 /* Single- and dual-component floating point formats */
1027 case SVGA3D_R_S10E5:
1028 return D3DFMT_R16F;
1029 case SVGA3D_R_S23E8:
1030 return D3DFMT_R32F;
1031 case SVGA3D_RG_S10E5:
1032 return D3DFMT_G16R16F;
1033 case SVGA3D_RG_S23E8:
1034 return D3DFMT_G32R32F;
1035
1036 /*
1037 * Any surface can be used as a buffer object, but SVGA3D_BUFFER is
1038 * the most efficient format to use when creating new surfaces
1039 * expressly for index or vertex data.
1040 */
1041 case SVGA3D_BUFFER:
1042 return D3DFMT_UNKNOWN;
1043
1044 case SVGA3D_V16U16:
1045 return D3DFMT_V16U16;
1046
1047 case SVGA3D_G16R16:
1048 return D3DFMT_G16R16;
1049 case SVGA3D_A16B16G16R16:
1050 return D3DFMT_A16B16G16R16;
1051
1052 /* Packed Video formats */
1053 case SVGA3D_UYVY:
1054 return D3DFMT_UYVY;
1055 case SVGA3D_YUY2:
1056 return D3DFMT_YUY2;
1057
1058 /* Planar video formats */
1059 case SVGA3D_NV12:
1060 return (D3DFORMAT)MAKEFOURCC('N', 'V', '1', '2');
1061
1062 /* Video format with alpha */
1063 case SVGA3D_AYUV:
1064 return (D3DFORMAT)MAKEFOURCC('A', 'Y', 'U', 'V');
1065
1066 case SVGA3D_BC4_UNORM:
1067 case SVGA3D_BC5_UNORM:
1068 /* Unknown; only in DX10 & 11 */
1069 break;
1070
1071 case SVGA3D_FORMAT_MAX: /* shut up MSC */
1072 case SVGA3D_FORMAT_INVALID:
1073 break;
1074 }
1075 AssertFailedReturn(D3DFMT_UNKNOWN);
1076}
1077
1078/**
1079 * Convert SVGA multi sample count value to its D3D equivalent
1080 */
1081D3DMULTISAMPLE_TYPE vmsvga3dMultipeSampleCount2D3D(uint32_t multisampleCount)
1082{
1083 AssertCompile(D3DMULTISAMPLE_2_SAMPLES == 2);
1084 AssertCompile(D3DMULTISAMPLE_16_SAMPLES == 16);
1085
1086 if (multisampleCount > 16)
1087 return D3DMULTISAMPLE_NONE;
1088
1089 /** @todo exact same mapping as d3d? */
1090 return (D3DMULTISAMPLE_TYPE)multisampleCount;
1091}
1092
1093
1094/**
1095 * Destroy backend specific surface bits (part of SVGA_3D_CMD_SURFACE_DESTROY).
1096 *
1097 * @param pState The VMSVGA3d state.
1098 * @param pSurface The surface being destroyed.
1099 */
1100void vmsvga3dBackSurfaceDestroy(PVMSVGA3DSTATE pState, PVMSVGA3DSURFACE pSurface)
1101{
1102 RT_NOREF(pState);
1103
1104 RTAvlU32Destroy(&pSurface->pSharedObjectTree, vmsvga3dSharedSurfaceDestroyTree, pSurface);
1105 Assert(pSurface->pSharedObjectTree == NULL);
1106
1107 switch (pSurface->flags & VMSVGA3D_SURFACE_HINT_SWITCH_MASK)
1108 {
1109 case SVGA3D_SURFACE_CUBEMAP:
1110 case SVGA3D_SURFACE_CUBEMAP | SVGA3D_SURFACE_HINT_TEXTURE:
1111 case SVGA3D_SURFACE_CUBEMAP | SVGA3D_SURFACE_HINT_TEXTURE | SVGA3D_SURFACE_HINT_RENDERTARGET:
1112 D3D_RELEASE(pSurface->u.pCubeTexture);
1113 D3D_RELEASE(pSurface->bounce.pCubeTexture);
1114 break;
1115
1116 case SVGA3D_SURFACE_HINT_INDEXBUFFER | SVGA3D_SURFACE_HINT_VERTEXBUFFER:
1117 case SVGA3D_SURFACE_HINT_INDEXBUFFER:
1118 case SVGA3D_SURFACE_HINT_VERTEXBUFFER:
1119 if (pSurface->fu32ActualUsageFlags == SVGA3D_SURFACE_HINT_VERTEXBUFFER)
1120 D3D_RELEASE(pSurface->u.pVertexBuffer);
1121 else if (pSurface->fu32ActualUsageFlags == SVGA3D_SURFACE_HINT_INDEXBUFFER)
1122 D3D_RELEASE(pSurface->u.pIndexBuffer);
1123 else
1124 AssertMsg(pSurface->u.pVertexBuffer == NULL, ("fu32ActualUsageFlags %x\n", pSurface->fu32ActualUsageFlags));
1125 break;
1126
1127 case SVGA3D_SURFACE_HINT_TEXTURE:
1128 case SVGA3D_SURFACE_HINT_TEXTURE | SVGA3D_SURFACE_HINT_RENDERTARGET:
1129 D3D_RELEASE(pSurface->u.pTexture);
1130 D3D_RELEASE(pSurface->bounce.pTexture);
1131 break;
1132
1133 case SVGA3D_SURFACE_HINT_RENDERTARGET:
1134 case SVGA3D_SURFACE_HINT_DEPTHSTENCIL:
1135 case SVGA3D_SURFACE_HINT_DEPTHSTENCIL | SVGA3D_SURFACE_HINT_TEXTURE: /** @todo actual texture surface not supported */
1136 if (pSurface->fStencilAsTexture)
1137 D3D_RELEASE(pSurface->u.pTexture);
1138 else
1139 D3D_RELEASE(pSurface->u.pSurface);
1140 break;
1141
1142 default:
1143 AssertMsg(!VMSVGA3DSURFACE_HAS_HW_SURFACE(pSurface), ("type=%x\n", (pSurface->flags & VMSVGA3D_SURFACE_HINT_SWITCH_MASK)));
1144 break;
1145 }
1146
1147 D3D_RELEASE(pSurface->pQuery);
1148}
1149
1150
1151/*
1152 * Release all shared surface objects.
1153 */
1154DECLCALLBACK(int) vmsvga3dSharedSurfaceDestroyTree(PAVLU32NODECORE pNode, void *pvParam)
1155{
1156 PVMSVGA3DSHAREDSURFACE pSharedSurface = (PVMSVGA3DSHAREDSURFACE)pNode;
1157 PVMSVGA3DSURFACE pSurface = (PVMSVGA3DSURFACE)pvParam;
1158
1159 switch (pSurface->flags & VMSVGA3D_SURFACE_HINT_SWITCH_MASK)
1160 {
1161 case SVGA3D_SURFACE_CUBEMAP:
1162 case SVGA3D_SURFACE_CUBEMAP | SVGA3D_SURFACE_HINT_TEXTURE:
1163 case SVGA3D_SURFACE_CUBEMAP | SVGA3D_SURFACE_HINT_TEXTURE | SVGA3D_SURFACE_HINT_RENDERTARGET:
1164 LogFunc(("release shared cube texture object for context %d\n", pNode->Key));
1165 Assert(pSharedSurface->u.pCubeTexture);
1166 D3D_RELEASE(pSharedSurface->u.pCubeTexture);
1167 break;
1168
1169 case SVGA3D_SURFACE_HINT_TEXTURE:
1170 case SVGA3D_SURFACE_HINT_TEXTURE | SVGA3D_SURFACE_HINT_RENDERTARGET:
1171 LogFunc(("release shared texture object for context %d\n", pNode->Key));
1172 Assert(pSharedSurface->u.pTexture);
1173 D3D_RELEASE(pSharedSurface->u.pTexture);
1174 break;
1175
1176 default:
1177 AssertFailed();
1178 break;
1179 }
1180 RTMemFree(pNode);
1181 return 0;
1182}
1183
1184/* Get the shared surface copy or create a new one. */
1185static PVMSVGA3DSHAREDSURFACE vmsvga3dSurfaceGetSharedCopy(PVMSVGA3DCONTEXT pContext, PVMSVGA3DSURFACE pSurface)
1186{
1187 Assert(pSurface->hSharedObject);
1188
1189 PVMSVGA3DSHAREDSURFACE pSharedSurface = (PVMSVGA3DSHAREDSURFACE)RTAvlU32Get(&pSurface->pSharedObjectTree, pContext->id);
1190 if (!pSharedSurface)
1191 {
1192 const bool fCubeTexture = RT_BOOL(pSurface->flags & SVGA3D_SURFACE_CUBEMAP);
1193 const uint32_t cWidth = pSurface->pMipmapLevels[0].mipmapSize.width;
1194 const uint32_t cHeight = pSurface->pMipmapLevels[0].mipmapSize.height;
1195 const uint32_t numMipLevels = pSurface->faces[0].numMipLevels;
1196
1197 LogFunc(("Create shared %stexture copy d3d (%d,%d) cMip=%d usage %x format %x.\n",
1198 fCubeTexture ? "cube " : "",
1199 cWidth,
1200 cHeight,
1201 numMipLevels,
1202 pSurface->fUsageD3D | D3DUSAGE_RENDERTARGET,
1203 pSurface->formatD3D));
1204
1205 pSharedSurface = (PVMSVGA3DSHAREDSURFACE)RTMemAllocZ(sizeof(*pSharedSurface));
1206 AssertReturn(pSharedSurface, NULL);
1207
1208 pSharedSurface->Core.Key = pContext->id;
1209 bool ret = RTAvlU32Insert(&pSurface->pSharedObjectTree, &pSharedSurface->Core);
1210 AssertReturn(ret, NULL);
1211
1212 /* Create shadow copy of the original shared texture. Shared d3d resources require Vista+ and have some restrictions. */
1213 HRESULT hr;
1214 if (fCubeTexture)
1215 hr = pContext->pDevice->CreateCubeTexture(cWidth,
1216 numMipLevels,
1217 pSurface->fUsageD3D | D3DUSAGE_RENDERTARGET /* required for use as a StretchRect destination */,
1218 pSurface->formatD3D,
1219 D3DPOOL_DEFAULT,
1220 &pSharedSurface->u.pCubeTexture,
1221 &pSurface->hSharedObject);
1222 else
1223 hr = pContext->pDevice->CreateTexture(cWidth,
1224 cHeight,
1225 numMipLevels,
1226 pSurface->fUsageD3D | D3DUSAGE_RENDERTARGET /* required for use as a StretchRect destination */,
1227 pSurface->formatD3D,
1228 D3DPOOL_DEFAULT,
1229 &pSharedSurface->u.pTexture,
1230 &pSurface->hSharedObject);
1231 AssertMsgReturn(hr == D3D_OK, ("CreateTexture failed with %x\n", hr), NULL);
1232 }
1233 return pSharedSurface;
1234}
1235
1236/* Inject a query event into the D3D pipeline so we can check when usage of this surface has finished.
1237 * (D3D does not synchronize shared surface usage)
1238 */
1239static int vmsvga3dSurfaceTrackUsage(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext, PVMSVGA3DSURFACE pSurface)
1240{
1241 RT_NOREF(pState);
1242#ifndef VBOX_VMSVGA3D_WITH_WINE_OPENGL
1243 Assert(pSurface->id != SVGA3D_INVALID_ID);
1244
1245 /* Nothing to do if this surface hasn't been shared. */
1246 if (pSurface->pSharedObjectTree == NULL)
1247 return VINF_SUCCESS;
1248
1249 LogFunc(("track usage of sid=%x (cid=%d) for cid=%d, pQuery %p\n", pSurface->id, pSurface->idAssociatedContext, pContext->id, pSurface->pQuery));
1250
1251 /* Release the previous query object. */
1252 D3D_RELEASE(pSurface->pQuery);
1253
1254 HRESULT hr = pContext->pDevice->CreateQuery(D3DQUERYTYPE_EVENT, &pSurface->pQuery);
1255 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSurfaceTrackUsage: CreateQuery failed with %x\n", hr), VERR_INTERNAL_ERROR);
1256
1257 hr = pSurface->pQuery->Issue(D3DISSUE_END);
1258 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSurfaceTrackUsage: Issue failed with %x\n", hr), VERR_INTERNAL_ERROR);
1259#endif /* !VBOX_VMSVGA3D_WITH_WINE_OPENGL */
1260
1261 return VINF_SUCCESS;
1262}
1263
1264
1265/**
1266 * Surface ID based version of vmsvga3dSurfaceTrackUsage.
1267 *
1268 * @returns VBox status code.
1269 * @param pState The VMSVGA3d state.
1270 * @param pContext The context.
1271 * @param sid The surface ID.
1272 */
1273static int vmsvga3dSurfaceTrackUsageById(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext, uint32_t sid)
1274{
1275 Assert(sid < SVGA3D_MAX_SURFACE_IDS);
1276 AssertReturn(sid < pState->cSurfaces, VERR_INVALID_PARAMETER);
1277 PVMSVGA3DSURFACE pSurface = pState->papSurfaces[sid];
1278 AssertReturn(pSurface && pSurface->id == sid, VERR_INVALID_PARAMETER);
1279
1280 return vmsvga3dSurfaceTrackUsage(pState, pContext, pSurface);
1281}
1282
1283
1284/* Wait for all drawing, that uses this surface, to finish. */
1285int vmsvga3dSurfaceFlush(PVGASTATE pThis, PVMSVGA3DSURFACE pSurface)
1286{
1287 RT_NOREF(pThis);
1288#ifndef VBOX_VMSVGA3D_WITH_WINE_OPENGL
1289 HRESULT hr;
1290
1291 if (!pSurface->pQuery)
1292 {
1293 LogFlow(("vmsvga3dSurfaceFlush: no query object\n"));
1294 return VINF_SUCCESS; /* nothing to wait for */
1295 }
1296 Assert(pSurface->pSharedObjectTree);
1297
1298 Log(("vmsvga3dSurfaceFlush: wait for draw to finish (sid=%x)\n", pSurface->id));
1299 while (true)
1300 {
1301 hr = pSurface->pQuery->GetData(NULL, 0, D3DGETDATA_FLUSH);
1302 if (hr != S_FALSE) break;
1303
1304 RTThreadSleep(1);
1305 }
1306 AssertMsgReturn(hr == S_OK, ("vmsvga3dSurfaceFinishDrawing: GetData failed with %x\n", hr), VERR_INTERNAL_ERROR);
1307
1308 D3D_RELEASE(pSurface->pQuery);
1309#endif /* !VBOX_VMSVGA3D_WITH_WINE_OPENGL */
1310
1311 return VINF_SUCCESS;
1312}
1313
1314DECLINLINE(D3DCUBEMAP_FACES) vmsvga3dCubemapFaceFromIndex(uint32_t iFace)
1315{
1316 D3DCUBEMAP_FACES Face;
1317 switch (iFace)
1318 {
1319 case 0: Face = D3DCUBEMAP_FACE_POSITIVE_X; break;
1320 case 1: Face = D3DCUBEMAP_FACE_NEGATIVE_X; break;
1321 case 2: Face = D3DCUBEMAP_FACE_POSITIVE_Y; break;
1322 case 3: Face = D3DCUBEMAP_FACE_NEGATIVE_Y; break;
1323 case 4: Face = D3DCUBEMAP_FACE_POSITIVE_Z; break;
1324 default:
1325 case 5: Face = D3DCUBEMAP_FACE_NEGATIVE_Z; break;
1326 }
1327 return Face;
1328}
1329
1330/** Get IDirect3DSurface9 for the given face and mipmap.
1331 */
1332int vmsvga3dGetD3DSurface(PVMSVGA3DCONTEXT pContext,
1333 PVMSVGA3DSURFACE pSurface,
1334 uint32_t face,
1335 uint32_t mipmap,
1336 bool fLockable,
1337 IDirect3DSurface9 **ppD3DSurf)
1338{
1339 AssertPtrReturn(pSurface->u.pSurface, VERR_INVALID_PARAMETER);
1340
1341 const bool fTexture = RT_BOOL(pSurface->flags & SVGA3D_SURFACE_HINT_TEXTURE);
1342 const bool fCubeTexture = RT_BOOL(pSurface->flags & SVGA3D_SURFACE_CUBEMAP);
1343
1344 IDirect3DBaseTexture9 *pTexture;
1345 if (fLockable && pSurface->bounce.pTexture)
1346 pTexture = pSurface->bounce.pTexture;
1347 else
1348 pTexture = pSurface->u.pTexture;
1349
1350#ifndef VBOX_VMSVGA3D_WITH_WINE_OPENGL
1351 if (pSurface->idAssociatedContext != pContext->id)
1352 {
1353 AssertMsgReturn(!fLockable,
1354 ("Lockable surface must be from the same context (surface cid = %d, req cid = %d)",
1355 pSurface->idAssociatedContext, pContext->id),
1356 VERR_INVALID_PARAMETER);
1357
1358 if (fTexture)
1359 {
1360 LogFunc(("using texture sid=%x created for another context (%d vs %d)\n",
1361 pSurface->id, pSurface->idAssociatedContext, pContext->id));
1362
1363 PVMSVGA3DSHAREDSURFACE pSharedSurface = vmsvga3dSurfaceGetSharedCopy(pContext, pSurface);
1364 AssertReturn(pSharedSurface, VERR_INTERNAL_ERROR);
1365
1366 pTexture = pSharedSurface->u.pTexture;
1367 }
1368 else
1369 {
1370 AssertMsgFailed(("surface sid=%x created for another context (%d vs %d)\n",
1371 pSurface->id, pSurface->idAssociatedContext, pContext->id));
1372 }
1373 }
1374#else
1375 RT_NOREF(pContext);
1376#endif
1377
1378 if (fCubeTexture)
1379 {
1380 Assert(pSurface->cFaces == 6);
1381
1382 IDirect3DCubeTexture9 *p = (IDirect3DCubeTexture9 *)pTexture;
1383 D3DCUBEMAP_FACES FaceType = vmsvga3dCubemapFaceFromIndex(face);
1384 HRESULT hr = p->GetCubeMapSurface(FaceType, mipmap, ppD3DSurf);
1385 AssertMsgReturn(hr == D3D_OK, ("GetCubeMapSurface failed with %x\n", hr), VERR_INTERNAL_ERROR);
1386 }
1387 else if (fTexture)
1388 {
1389 Assert(pSurface->cFaces == 1);
1390 Assert(face == 0);
1391
1392 IDirect3DTexture9 *p = (IDirect3DTexture9 *)pTexture;
1393 HRESULT hr = p->GetSurfaceLevel(mipmap, ppD3DSurf);
1394 AssertMsgReturn(hr == D3D_OK, ("GetSurfaceLevel failed with %x\n", hr), VERR_INTERNAL_ERROR);
1395 }
1396 else
1397 {
1398 pSurface->u.pSurface->AddRef();
1399 *ppD3DSurf = pSurface->u.pSurface;
1400 }
1401
1402 return VINF_SUCCESS;
1403}
1404
1405int vmsvga3dSurfaceCopy(PVGASTATE pThis, SVGA3dSurfaceImageId dest, SVGA3dSurfaceImageId src,
1406 uint32_t cCopyBoxes, SVGA3dCopyBox *pBox)
1407{
1408 PVMSVGA3DSTATE pState = pThis->svga.p3dState;
1409 AssertReturn(pState, VERR_NO_MEMORY);
1410
1411 const uint32_t sidSrc = src.sid;
1412 const uint32_t sidDest = dest.sid;
1413 int rc;
1414
1415 PVMSVGA3DSURFACE pSurfaceSrc;
1416 rc = vmsvga3dSurfaceFromSid(pState, sidSrc, &pSurfaceSrc);
1417 AssertRCReturn(rc, rc);
1418
1419 PVMSVGA3DSURFACE pSurfaceDest;
1420 rc = vmsvga3dSurfaceFromSid(pState, sidDest, &pSurfaceDest);
1421 AssertRCReturn(rc, rc);
1422
1423 PVMSVGA3DMIPMAPLEVEL pMipmapLevelSrc;
1424 rc = vmsvga3dMipmapLevel(pSurfaceSrc, src.face, src.mipmap, &pMipmapLevelSrc);
1425 AssertRCReturn(rc, rc);
1426
1427 PVMSVGA3DMIPMAPLEVEL pMipmapLevelDest;
1428 rc = vmsvga3dMipmapLevel(pSurfaceDest, dest.face, dest.mipmap, &pMipmapLevelDest);
1429 AssertRCReturn(rc, rc);
1430
1431 const bool fDestTexture = RT_BOOL(pSurfaceDest->flags & SVGA3D_SURFACE_HINT_TEXTURE);
1432
1433 if ( fDestTexture
1434 && !pSurfaceDest->u.pSurface
1435 && pSurfaceSrc->u.pSurface)
1436 {
1437 const uint32_t cid = pSurfaceSrc->idAssociatedContext;
1438
1439 PVMSVGA3DCONTEXT pContext;
1440 rc = vmsvga3dContextFromCid(pState, cid, &pContext);
1441 AssertRCReturn(rc, rc);
1442
1443 LogFunc(("sid=%x type=%x format=%d -> create texture\n", sidDest, pSurfaceDest->flags, pSurfaceDest->format));
1444 rc = vmsvga3dBackCreateTexture(pState, pContext, cid, pSurfaceDest);
1445 AssertRCReturn(rc, rc);
1446 }
1447
1448 if ( pSurfaceSrc->u.pSurface
1449 && pSurfaceDest->u.pSurface)
1450 {
1451 const uint32_t cidDst = pSurfaceDest->idAssociatedContext;
1452
1453 PVMSVGA3DCONTEXT pContextDst;
1454 rc = vmsvga3dContextFromCid(pState, cidDst, &pContextDst);
1455 AssertRCReturn(rc, rc);
1456
1457 /* Must flush the other context's 3d pipeline to make sure all drawing is complete for the surface we're about to use. */
1458 vmsvga3dSurfaceFlush(pThis, pSurfaceSrc);
1459 vmsvga3dSurfaceFlush(pThis, pSurfaceDest);
1460
1461 IDirect3DSurface9 *pSrc;
1462 rc = vmsvga3dGetD3DSurface(pContextDst, pSurfaceSrc, src.face, src.mipmap, false, &pSrc);
1463 AssertRCReturn(rc, rc);
1464
1465 IDirect3DSurface9 *pDest;
1466 rc = vmsvga3dGetD3DSurface(pContextDst, pSurfaceDest, dest.face, dest.mipmap, false, &pDest);
1467 AssertRCReturnStmt(rc, D3D_RELEASE(pSrc), rc);
1468
1469 for (uint32_t i = 0; i < cCopyBoxes; ++i)
1470 {
1471 HRESULT hr;
1472
1473 SVGA3dCopyBox clipBox = pBox[i];
1474 vmsvgaClipCopyBox(&pMipmapLevelSrc->mipmapSize, &pMipmapLevelDest->mipmapSize, &clipBox);
1475 if ( !clipBox.w
1476 || !clipBox.h
1477 || !clipBox.d)
1478 {
1479 LogFunc(("Skipped empty box.\n"));
1480 continue;
1481 }
1482
1483 RECT RectSrc;
1484 RectSrc.left = clipBox.srcx;
1485 RectSrc.top = clipBox.srcy;
1486 RectSrc.right = clipBox.srcx + clipBox.w; /* exclusive */
1487 RectSrc.bottom = clipBox.srcy + clipBox.h; /* exclusive */
1488
1489 RECT RectDest;
1490 RectDest.left = clipBox.x;
1491 RectDest.top = clipBox.y;
1492 RectDest.right = clipBox.x + clipBox.w; /* exclusive */
1493 RectDest.bottom = clipBox.y + clipBox.h; /* exclusive */
1494
1495 LogFunc(("StretchRect copy src sid=%x face=%d mipmap=%d (%d,%d)(%d,%d) to dest sid=%x face=%d mipmap=%d (%d,%d)\n", sidSrc, src.face, src.mipmap, RectSrc.left, RectSrc.top, RectSrc.right, RectSrc.bottom, sidDest, dest.face, dest.mipmap, pBox[i].x, pBox[i].y));
1496
1497 if ( sidSrc == sidDest
1498 && clipBox.srcx == clipBox.x
1499 && clipBox.srcy == clipBox.y)
1500 {
1501 LogFunc(("redundant copy to the same surface at the same coordinates. Ignore.\n"));
1502 continue;
1503 }
1504 Assert(sidSrc != sidDest);
1505 Assert(!clipBox.srcz && !clipBox.z);
1506
1507 hr = pContextDst->pDevice->StretchRect(pSrc, &RectSrc, pDest, &RectDest, D3DTEXF_NONE);
1508 AssertMsgReturnStmt(hr == D3D_OK,
1509 ("StretchRect failed with %x\n", hr),
1510 D3D_RELEASE(pDest); D3D_RELEASE(pSrc),
1511 VERR_INTERNAL_ERROR);
1512 }
1513
1514 D3D_RELEASE(pDest);
1515 D3D_RELEASE(pSrc);
1516
1517 /* Track the StretchRect operation. */
1518 vmsvga3dSurfaceTrackUsage(pState, pContextDst, pSurfaceSrc);
1519 vmsvga3dSurfaceTrackUsage(pState, pContextDst, pSurfaceDest);
1520 }
1521 else
1522 {
1523 /*
1524 * Copy from/to memory to/from a surface. Or mem->mem.
1525 * Use the context of existing HW surface, if any.
1526 */
1527 PVMSVGA3DCONTEXT pContext = NULL;
1528 IDirect3DSurface9 *pD3DSurf = NULL;
1529
1530 if (pSurfaceSrc->u.pSurface)
1531 {
1532 AssertReturn(!pSurfaceDest->u.pSurface, VERR_INTERNAL_ERROR);
1533
1534 rc = vmsvga3dContextFromCid(pState, pSurfaceSrc->idAssociatedContext, &pContext);
1535 AssertRCReturn(rc, rc);
1536
1537 rc = vmsvga3dGetD3DSurface(pContext, pSurfaceSrc, src.face, src.mipmap, true, &pD3DSurf);
1538 AssertRCReturn(rc, rc);
1539 }
1540 else if (pSurfaceDest->u.pSurface)
1541 {
1542 AssertReturn(!pSurfaceSrc->u.pSurface, VERR_INTERNAL_ERROR);
1543
1544 rc = vmsvga3dContextFromCid(pState, pSurfaceDest->idAssociatedContext, &pContext);
1545 AssertRCReturn(rc, rc);
1546
1547 rc = vmsvga3dGetD3DSurface(pContext, pSurfaceDest, dest.face, dest.mipmap, true, &pD3DSurf);
1548 AssertRCReturn(rc, rc);
1549 }
1550
1551 for (uint32_t i = 0; i < cCopyBoxes; ++i)
1552 {
1553 HRESULT hr;
1554
1555 SVGA3dCopyBox clipBox = pBox[i];
1556 vmsvgaClipCopyBox(&pMipmapLevelSrc->mipmapSize, &pMipmapLevelDest->mipmapSize, &clipBox);
1557 if ( !clipBox.w
1558 || !clipBox.h
1559 || !clipBox.d)
1560 {
1561 LogFunc(("Skipped empty box.\n"));
1562 continue;
1563 }
1564
1565 RECT RectSrc;
1566 RectSrc.left = clipBox.srcx;
1567 RectSrc.top = clipBox.srcy;
1568 RectSrc.right = clipBox.srcx + clipBox.w; /* exclusive */
1569 RectSrc.bottom = clipBox.srcy + clipBox.h; /* exclusive */
1570
1571 RECT RectDest;
1572 RectDest.left = clipBox.x;
1573 RectDest.top = clipBox.y;
1574 RectDest.right = clipBox.x + clipBox.w; /* exclusive */
1575 RectDest.bottom = clipBox.y + clipBox.h; /* exclusive */
1576
1577 LogFunc(("(manual) copy sid=%x face=%d mipmap=%d (%d,%d)(%d,%d) to sid=%x face=%d mipmap=%d (%d,%d)\n",
1578 sidSrc, src.face, src.mipmap, RectSrc.left, RectSrc.top, RectSrc.right, RectSrc.bottom,
1579 sidDest, dest.face, dest.mipmap, pBox[i].x, pBox[i].y));
1580
1581 Assert(!clipBox.srcz && !clipBox.z);
1582 Assert(pSurfaceSrc->cbBlock == pSurfaceDest->cbBlock);
1583 Assert(pSurfaceSrc->cxBlock == pSurfaceDest->cxBlock);
1584 Assert(pSurfaceSrc->cyBlock == pSurfaceDest->cyBlock);
1585
1586 uint32_t cBlocksX = (clipBox.w + pSurfaceSrc->cxBlock - 1) / pSurfaceSrc->cxBlock;
1587 uint32_t cBlocksY = (clipBox.h + pSurfaceSrc->cyBlock - 1) / pSurfaceSrc->cyBlock;
1588
1589 D3DLOCKED_RECT LockedSrcRect;
1590 if (!pSurfaceSrc->u.pSurface)
1591 {
1592 uint32_t u32BlockX = clipBox.srcx / pSurfaceSrc->cxBlock;
1593 uint32_t u32BlockY = clipBox.srcy / pSurfaceSrc->cyBlock;
1594 Assert(u32BlockX * pSurfaceSrc->cxBlock == clipBox.srcx);
1595 Assert(u32BlockY * pSurfaceSrc->cyBlock == clipBox.srcy);
1596
1597 LockedSrcRect.pBits = (uint8_t *)pMipmapLevelSrc->pSurfaceData +
1598 pMipmapLevelSrc->cbSurfacePitch * u32BlockY + pSurfaceSrc->cbBlock * u32BlockX;
1599 LockedSrcRect.Pitch = pMipmapLevelSrc->cbSurfacePitch;
1600 }
1601 else
1602 {
1603 /* Must flush the context's 3d pipeline to make sure all drawing is complete for the surface we're about to use. */
1604 vmsvga3dSurfaceFlush(pThis, pSurfaceSrc);
1605
1606 hr = pD3DSurf->LockRect(&LockedSrcRect, &RectSrc, D3DLOCK_READONLY);
1607 AssertMsgReturnStmt(hr == D3D_OK, ("LockRect failed with %x\n", hr), D3D_RELEASE(pD3DSurf), VERR_INTERNAL_ERROR);
1608 }
1609
1610 D3DLOCKED_RECT LockedDestRect;
1611 if (!pSurfaceDest->u.pSurface)
1612 {
1613 uint32_t u32BlockX = clipBox.x / pSurfaceDest->cxBlock;
1614 uint32_t u32BlockY = clipBox.y / pSurfaceDest->cyBlock;
1615 Assert(u32BlockX * pSurfaceDest->cxBlock == clipBox.x);
1616 Assert(u32BlockY * pSurfaceDest->cyBlock == clipBox.y);
1617
1618 LockedDestRect.pBits = (uint8_t *)pMipmapLevelDest->pSurfaceData +
1619 pMipmapLevelDest->cbSurfacePitch * u32BlockY + pSurfaceDest->cbBlock * u32BlockX;
1620 LockedDestRect.Pitch = pMipmapLevelDest->cbSurfacePitch;
1621 pSurfaceDest->fDirty = true;
1622 }
1623 else
1624 {
1625 /* Must flush the context's 3d pipeline to make sure all drawing is complete for the surface we're about to use. */
1626 vmsvga3dSurfaceFlush(pThis, pSurfaceDest);
1627
1628 hr = pD3DSurf->LockRect(&LockedDestRect, &RectDest, 0);
1629 AssertMsgReturnStmt(hr == D3D_OK, ("LockRect failed with %x\n", hr), D3D_RELEASE(pD3DSurf), VERR_INTERNAL_ERROR);
1630 }
1631
1632 uint8_t *pDest = (uint8_t *)LockedDestRect.pBits;
1633 const uint8_t *pSrc = (uint8_t *)LockedSrcRect.pBits;
1634 for (uint32_t j = 0; j < cBlocksY; ++j)
1635 {
1636 memcpy(pDest, pSrc, cBlocksX * pSurfaceSrc->cbBlock);
1637 pDest += LockedDestRect.Pitch;
1638 pSrc += LockedSrcRect.Pitch;
1639 }
1640
1641 if (pD3DSurf)
1642 {
1643 hr = pD3DSurf->UnlockRect();
1644 AssertMsgReturn(hr == D3D_OK, ("Unlock failed with %x\n", hr), VERR_INTERNAL_ERROR);
1645 }
1646 }
1647
1648 /* If the destination bounce texture has been used, then update the actual texture. */
1649 if ( pSurfaceDest->u.pSurface
1650 && fDestTexture
1651 && pSurfaceDest->bounce.pTexture)
1652 {
1653 AssertMsgReturn(pContext, ("Context is NULL\n"), VERR_INTERNAL_ERROR);
1654
1655 /* Copy the new content to the actual texture object. */
1656 IDirect3DBaseTexture9 *pSourceTexture;
1657 IDirect3DBaseTexture9 *pDestinationTexture;
1658 if (pSurfaceDest->flags & SVGA3D_SURFACE_CUBEMAP)
1659 {
1660 pSourceTexture = pSurfaceDest->bounce.pCubeTexture;
1661 pDestinationTexture = pSurfaceDest->u.pCubeTexture;
1662 }
1663 else
1664 {
1665 pSourceTexture = pSurfaceDest->bounce.pTexture;
1666 pDestinationTexture = pSurfaceDest->u.pTexture;
1667 }
1668 HRESULT hr2 = pContext->pDevice->UpdateTexture(pSourceTexture, pDestinationTexture);
1669 AssertMsg(hr2 == D3D_OK, ("UpdateTexture failed with %x\n", hr2)); RT_NOREF(hr2);
1670 }
1671
1672 D3D_RELEASE(pD3DSurf);
1673 }
1674
1675 return VINF_SUCCESS;
1676}
1677
1678
1679/**
1680 * Create D3D/OpenGL texture object for the specified surface.
1681 *
1682 * Surfaces are created when needed.
1683 *
1684 * @param pState The VMSVGA3d state.
1685 * @param pContext The context.
1686 * @param idAssociatedContext Probably the same as pContext->id.
1687 * @param pSurface The surface to create the texture for.
1688 */
1689int vmsvga3dBackCreateTexture(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext, uint32_t idAssociatedContext,
1690 PVMSVGA3DSURFACE pSurface)
1691
1692{
1693 RT_NOREF(pState);
1694 HRESULT hr;
1695
1696 Assert(pSurface->hSharedObject == NULL);
1697 Assert(pSurface->u.pTexture == NULL);
1698 Assert(pSurface->bounce.pTexture == NULL);
1699
1700 const uint32_t cWidth = pSurface->pMipmapLevels[0].mipmapSize.width;
1701 const uint32_t cHeight = pSurface->pMipmapLevels[0].mipmapSize.height;
1702 const uint32_t numMipLevels = pSurface->faces[0].numMipLevels;
1703
1704 /*
1705 * Create D3D texture object.
1706 */
1707 if (pSurface->flags & SVGA3D_SURFACE_CUBEMAP)
1708 {
1709 Assert(pSurface->cFaces == 6);
1710 Assert(cWidth == cHeight);
1711
1712 hr = pContext->pDevice->CreateCubeTexture(cWidth,
1713 numMipLevels,
1714 pSurface->fUsageD3D,
1715 pSurface->formatD3D,
1716 D3DPOOL_DEFAULT,
1717 &pSurface->u.pCubeTexture,
1718 &pSurface->hSharedObject);
1719 if (hr == D3D_OK)
1720 {
1721 /* Create another texture object to serve as a bounce buffer as the above texture surface can't be locked. */
1722 hr = pContext->pDevice->CreateCubeTexture(cWidth,
1723 numMipLevels,
1724 (pSurface->fUsageD3D & ~D3DUSAGE_RENDERTARGET) | D3DUSAGE_DYNAMIC /* Lockable */,
1725 pSurface->formatD3D,
1726 D3DPOOL_SYSTEMMEM,
1727 &pSurface->bounce.pCubeTexture,
1728 NULL);
1729 AssertMsgReturnStmt(hr == D3D_OK,
1730 ("CreateCubeTexture (systemmem) failed with %x\n", hr),
1731 D3D_RELEASE(pSurface->u.pCubeTexture),
1732 VERR_INTERNAL_ERROR);
1733 }
1734 else
1735 {
1736 Log(("Format not accepted -> try old method\n"));
1737 /* The format was probably not accepted; fall back to our old mode. */
1738 hr = pContext->pDevice->CreateCubeTexture(cWidth,
1739 numMipLevels,
1740 (pSurface->fUsageD3D & ~D3DUSAGE_RENDERTARGET) | D3DUSAGE_DYNAMIC /* Lockable */,
1741 pSurface->formatD3D,
1742 D3DPOOL_DEFAULT,
1743 &pSurface->u.pCubeTexture,
1744 &pSurface->hSharedObject);
1745 AssertMsgReturn(hr == D3D_OK, ("CreateCubeTexture (fallback) failed with %x\n", hr), VERR_INTERNAL_ERROR);
1746 }
1747 }
1748 else if ( pSurface->formatD3D == D3DFMT_D24S8
1749 || pSurface->formatD3D == D3DFMT_D24X8)
1750 {
1751 Assert(pSurface->cFaces == 1);
1752 Assert(pSurface->faces[0].numMipLevels == 1);
1753
1754 /* Use the INTZ format for a depth/stencil surface that will be used as a texture */
1755 hr = pContext->pDevice->CreateTexture(cWidth,
1756 cHeight,
1757 1,
1758 D3DUSAGE_DEPTHSTENCIL,
1759 FOURCC_INTZ,
1760 D3DPOOL_DEFAULT,
1761 &pSurface->u.pTexture,
1762 &pSurface->hSharedObject /* might result in poor performance */);
1763 AssertMsgReturn(hr == D3D_OK, ("CreateTexture INTZ failed with %x\n", hr), VERR_INTERNAL_ERROR);
1764
1765 pSurface->fStencilAsTexture = true;
1766 }
1767 else
1768 {
1769 /** @todo if (depth > 1) CreateVolumeTexture */
1770 Assert(pSurface->cFaces == 1);
1771
1772 hr = pContext->pDevice->CreateTexture(cWidth,
1773 cHeight,
1774 numMipLevels,
1775 pSurface->fUsageD3D | D3DUSAGE_RENDERTARGET /* required for use as a StretchRect destination */,
1776 pSurface->formatD3D,
1777 D3DPOOL_DEFAULT,
1778 &pSurface->u.pTexture,
1779 &pSurface->hSharedObject);
1780 if (hr == D3D_OK)
1781 {
1782 /* Create another texture object to serve as a bounce buffer as the above texture surface can't be locked. */
1783 hr = pContext->pDevice->CreateTexture(cWidth,
1784 cHeight,
1785 numMipLevels,
1786 (pSurface->fUsageD3D & ~D3DUSAGE_RENDERTARGET) | D3DUSAGE_DYNAMIC /* Lockable */,
1787 pSurface->formatD3D,
1788 D3DPOOL_SYSTEMMEM,
1789 &pSurface->bounce.pTexture,
1790 NULL);
1791 AssertMsgReturn(hr == D3D_OK, ("CreateTexture (systemmem) failed with %x\n", hr), VERR_INTERNAL_ERROR);
1792 }
1793 else
1794 {
1795 Log(("Format not accepted -> try old method\n"));
1796 /* The format was probably not accepted; fall back to our old mode. */
1797 hr = pContext->pDevice->CreateTexture(cWidth,
1798 cHeight,
1799 numMipLevels,
1800 (pSurface->fUsageD3D & ~D3DUSAGE_RENDERTARGET) | D3DUSAGE_DYNAMIC /* Lockable */,
1801 pSurface->formatD3D,
1802 D3DPOOL_DEFAULT,
1803 &pSurface->u.pTexture,
1804 &pSurface->hSharedObject /* might result in poor performance */);
1805 AssertMsgReturn(hr == D3D_OK, ("CreateTexture failed with %x\n", hr), VERR_INTERNAL_ERROR);
1806 }
1807 }
1808
1809 if (pSurface->autogenFilter != SVGA3D_TEX_FILTER_NONE)
1810 {
1811 /* Set the mip map generation filter settings. */
1812 if (pSurface->flags & SVGA3D_SURFACE_CUBEMAP)
1813 hr = pSurface->u.pCubeTexture->SetAutoGenFilterType((D3DTEXTUREFILTERTYPE)pSurface->autogenFilter);
1814 else
1815 hr = pSurface->u.pTexture->SetAutoGenFilterType((D3DTEXTUREFILTERTYPE)pSurface->autogenFilter);
1816 AssertMsg(hr == D3D_OK, ("vmsvga3dBackCreateTexture: SetAutoGenFilterType failed with %x\n", hr));
1817 }
1818
1819 /*
1820 * Always initialize all mipmap levels using the in memory data
1821 * to make sure that the just created texture has the up-to-date content.
1822 * The OpenGL backend does this too.
1823 */
1824 Log(("vmsvga3dBackCreateTexture: sync texture\n"));
1825
1826 if (pSurface->flags & SVGA3D_SURFACE_CUBEMAP)
1827 {
1828 IDirect3DCubeTexture9 *pCubeTexture = pSurface->bounce.pCubeTexture ?
1829 pSurface->bounce.pCubeTexture :
1830 pSurface->u.pCubeTexture;
1831
1832 for (uint32_t iFace = 0; iFace < 6; ++iFace)
1833 {
1834 const D3DCUBEMAP_FACES Face = vmsvga3dCubemapFaceFromIndex(iFace);
1835
1836 for (uint32_t i = 0; i < numMipLevels; ++i)
1837 {
1838 D3DLOCKED_RECT LockedRect;
1839 hr = pCubeTexture->LockRect(Face,
1840 i, /* texture level */
1841 &LockedRect,
1842 NULL, /* entire texture */
1843 0);
1844 AssertMsgBreak(hr == D3D_OK, ("LockRect failed with %x\n", hr));
1845
1846 PVMSVGA3DMIPMAPLEVEL pMipLevel = &pSurface->pMipmapLevels[iFace * numMipLevels + i];
1847
1848 LogFunc(("sync texture face %d mipmap level %d (pitch %x vs %x)\n",
1849 iFace, i, LockedRect.Pitch, pMipLevel->cbSurfacePitch));
1850
1851 uint8_t *pDest = (uint8_t *)LockedRect.pBits;
1852 const uint8_t *pSrc = (uint8_t *)pMipLevel->pSurfaceData;
1853 for (uint32_t j = 0; j < pMipLevel->cBlocksY; ++j)
1854 {
1855 memcpy(pDest, pSrc, pMipLevel->cbSurfacePitch);
1856
1857 pDest += LockedRect.Pitch;
1858 pSrc += pMipLevel->cbSurfacePitch;
1859 }
1860
1861 hr = pCubeTexture->UnlockRect(Face, i /* texture level */);
1862 AssertMsgBreak(hr == D3D_OK, ("UnlockRect failed with %x\n", hr));
1863
1864 pMipLevel->fDirty = false;
1865 }
1866
1867 if (hr != D3D_OK)
1868 break;
1869 }
1870
1871 if (hr != D3D_OK)
1872 {
1873 D3D_RELEASE(pSurface->bounce.pCubeTexture);
1874 D3D_RELEASE(pSurface->u.pCubeTexture);
1875 return VERR_INTERNAL_ERROR;
1876 }
1877 }
1878 else
1879 {
1880 IDirect3DTexture9 *pTexture = pSurface->bounce.pTexture ? pSurface->bounce.pTexture : pSurface->u.pTexture;
1881
1882 for (uint32_t i = 0; i < numMipLevels; ++i)
1883 {
1884 D3DLOCKED_RECT LockedRect;
1885
1886 hr = pTexture->LockRect(i, /* texture level */
1887 &LockedRect,
1888 NULL, /* entire texture */
1889 0);
1890
1891 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dBackCreateTexture: LockRect failed with %x\n", hr), VERR_INTERNAL_ERROR);
1892
1893 Log(("vmsvga3dBackCreateTexture: sync texture mipmap level %d (pitch %x vs %x)\n", i, LockedRect.Pitch, pSurface->pMipmapLevels[i].cbSurfacePitch));
1894
1895 uint8_t *pDest = (uint8_t *)LockedRect.pBits;
1896 const uint8_t *pSrc = (uint8_t *)pSurface->pMipmapLevels[i].pSurfaceData;
1897 for (uint32_t j = 0; j < pSurface->pMipmapLevels[i].cBlocksY; ++j)
1898 {
1899 memcpy(pDest, pSrc, pSurface->pMipmapLevels[i].cbSurfacePitch);
1900
1901 pDest += LockedRect.Pitch;
1902 pSrc += pSurface->pMipmapLevels[i].cbSurfacePitch;
1903 }
1904
1905 hr = pTexture->UnlockRect(i /* texture level */);
1906 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dBackCreateTexture: UnlockRect failed with %x\n", hr), VERR_INTERNAL_ERROR);
1907
1908 pSurface->pMipmapLevels[i].fDirty = false;
1909 }
1910 }
1911
1912 if (pSurface->bounce.pTexture)
1913 {
1914 Log(("vmsvga3dBackCreateTexture: sync dirty texture from bounce buffer\n"));
1915
1916 if (pSurface->flags & SVGA3D_SURFACE_CUBEMAP)
1917 hr = pContext->pDevice->UpdateTexture(pSurface->bounce.pCubeTexture, pSurface->u.pCubeTexture);
1918 else
1919 hr = pContext->pDevice->UpdateTexture(pSurface->bounce.pTexture, pSurface->u.pTexture);
1920 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dBackCreateTexture: UpdateTexture failed with %x\n", hr), VERR_INTERNAL_ERROR);
1921
1922 /* We will now use the bounce texture for all memory accesses, so free our surface memory buffer. */
1923 for (uint32_t i = 0; i < pSurface->faces[0].numMipLevels; i++)
1924 {
1925 RTMemFree(pSurface->pMipmapLevels[i].pSurfaceData);
1926 pSurface->pMipmapLevels[i].pSurfaceData = NULL;
1927 }
1928 }
1929 pSurface->fDirty = false;
1930
1931 pSurface->flags |= SVGA3D_SURFACE_HINT_TEXTURE;
1932 pSurface->idAssociatedContext = idAssociatedContext;
1933 return VINF_SUCCESS;
1934}
1935
1936
1937/**
1938 * Backend worker for implementing SVGA_3D_CMD_SURFACE_STRETCHBLT.
1939 *
1940 * @returns VBox status code.
1941 * @param pThis The VGA device instance.
1942 * @param pState The VMSVGA3d state.
1943 * @param pDstSurface The destination host surface.
1944 * @param uDstFace The destination face (valid).
1945 * @param uDstMipmap The destination mipmap level (valid).
1946 * @param pDstBox The destination box.
1947 * @param pSrcSurface The source host surface.
1948 * @param uSrcFace The destination face (valid).
1949 * @param uSrcMipmap The source mimap level (valid).
1950 * @param pSrcBox The source box.
1951 * @param enmMode The strecht blt mode .
1952 * @param pContext The VMSVGA3d context (already current for OGL).
1953 */
1954int vmsvga3dBackSurfaceStretchBlt(PVGASTATE pThis, PVMSVGA3DSTATE pState,
1955 PVMSVGA3DSURFACE pDstSurface, uint32_t uDstFace, uint32_t uDstMipmap, SVGA3dBox const *pDstBox,
1956 PVMSVGA3DSURFACE pSrcSurface, uint32_t uSrcFace, uint32_t uSrcMipmap, SVGA3dBox const *pSrcBox,
1957 SVGA3dStretchBltMode enmMode, PVMSVGA3DCONTEXT pContext)
1958{
1959 HRESULT hr;
1960 int rc;
1961
1962 /* Flush the drawing pipeline for this surface as it could be used in a shared context. */
1963 vmsvga3dSurfaceFlush(pThis, pSrcSurface);
1964 vmsvga3dSurfaceFlush(pThis, pDstSurface);
1965
1966 RECT RectSrc;
1967 RectSrc.left = pSrcBox->x;
1968 RectSrc.top = pSrcBox->y;
1969 RectSrc.right = pSrcBox->x + pSrcBox->w; /* exclusive */
1970 RectSrc.bottom = pSrcBox->y + pSrcBox->h; /* exclusive */
1971 Assert(!pSrcBox->z);
1972
1973 RECT RectDst;
1974 RectDst.left = pDstBox->x;
1975 RectDst.top = pDstBox->y;
1976 RectDst.right = pDstBox->x + pDstBox->w; /* exclusive */
1977 RectDst.bottom = pDstBox->y + pDstBox->h; /* exclusive */
1978 Assert(!pDstBox->z);
1979
1980 IDirect3DSurface9 *pSrc;
1981 rc = vmsvga3dGetD3DSurface(pContext, pSrcSurface, uSrcFace, uSrcMipmap, false, &pSrc);
1982 AssertRCReturn(rc, rc);
1983
1984 IDirect3DSurface9 *pDst;
1985 rc = vmsvga3dGetD3DSurface(pContext, pDstSurface, uDstFace, uDstMipmap, false, &pDst);
1986 AssertRCReturn(rc, rc);
1987
1988 D3DTEXTUREFILTERTYPE moded3d;
1989 switch (enmMode)
1990 {
1991 case SVGA3D_STRETCH_BLT_POINT:
1992 moded3d = D3DTEXF_POINT;
1993 break;
1994
1995 case SVGA3D_STRETCH_BLT_LINEAR:
1996 moded3d = D3DTEXF_LINEAR;
1997 break;
1998
1999 default:
2000 AssertFailed();
2001 moded3d = D3DTEXF_NONE;
2002 break;
2003 }
2004
2005 hr = pContext->pDevice->StretchRect(pSrc, &RectSrc, pDst, &RectDst, moded3d);
2006
2007 D3D_RELEASE(pDst);
2008 D3D_RELEASE(pSrc);
2009
2010 AssertMsgReturn(hr == D3D_OK, ("StretchRect failed with %x\n", hr), VERR_INTERNAL_ERROR);
2011
2012 /* Track the StretchRect operation. */
2013 vmsvga3dSurfaceTrackUsage(pState, pContext, pSrcSurface);
2014 vmsvga3dSurfaceTrackUsage(pState, pContext, pDstSurface);
2015
2016 return VINF_SUCCESS;
2017}
2018
2019
2020/**
2021 * Backend worker for implementing SVGA_3D_CMD_SURFACE_DMA that copies one box.
2022 *
2023 * @returns Failure status code or @a rc.
2024 * @param pThis The VGA device instance data.
2025 * @param pState The VMSVGA3d state.
2026 * @param pSurface The host surface.
2027 * @param pMipLevel Mipmap level. The caller knows it already.
2028 * @param uHostFace The host face (valid).
2029 * @param uHostMipmap The host mipmap level (valid).
2030 * @param GuestPtr The guest pointer.
2031 * @param cbGuestPitch The guest pitch.
2032 * @param transfer The transfer direction.
2033 * @param pBox The box to copy (clipped, valid).
2034 * @param pContext The context (for OpenGL).
2035 * @param rc The current rc for all boxes.
2036 * @param iBox The current box number (for Direct 3D).
2037 */
2038int vmsvga3dBackSurfaceDMACopyBox(PVGASTATE pThis, PVMSVGA3DSTATE pState, PVMSVGA3DSURFACE pSurface,
2039 PVMSVGA3DMIPMAPLEVEL pMipLevel, uint32_t uHostFace, uint32_t uHostMipmap,
2040 SVGAGuestPtr GuestPtr, uint32_t cbGuestPitch, SVGA3dTransferType transfer,
2041 SVGA3dCopyBox const *pBox, PVMSVGA3DCONTEXT pContext, int rc, int iBox)
2042{
2043 HRESULT hr = D3D_OK;
2044 const uint32_t u32SurfHints = pSurface->flags & VMSVGA3D_SURFACE_HINT_SWITCH_MASK;
2045 const DWORD dwFlags = transfer == SVGA3D_READ_HOST_VRAM ? D3DLOCK_READONLY : 0;
2046 // if (u32SurfHints != 0x18 && u32SurfHints != 0x60) ASMBreakpoint();
2047
2048 bool fTexture = RT_BOOL(u32SurfHints & (SVGA3D_SURFACE_HINT_TEXTURE |
2049 SVGA3D_SURFACE_CUBEMAP))
2050 || pSurface->fStencilAsTexture;
2051
2052 bool fRenderTarget = RT_BOOL(u32SurfHints & SVGA3D_SURFACE_HINT_RENDERTARGET);
2053
2054 if (fTexture || fRenderTarget)
2055 {
2056 rc = vmsvga3dContextFromCid(pState, pSurface->idAssociatedContext, &pContext);
2057 AssertRCReturn(rc, rc);
2058
2059 /* Get the surface involved in the transfer. */
2060 IDirect3DSurface9 *pSurf;
2061 rc = vmsvga3dGetD3DSurface(pContext, pSurface, uHostFace, uHostMipmap, true, &pSurf);
2062 AssertRCReturn(rc, rc);
2063
2064 /** @todo inefficient for VRAM buffers!! */
2065 if (fTexture)
2066 {
2067 if (pSurface->bounce.pTexture)
2068 {
2069 if ( transfer == SVGA3D_READ_HOST_VRAM
2070 && fRenderTarget
2071 && iBox == 0 /* only the first time */)
2072 {
2073 /* Copy the texture mipmap level to the bounce texture. */
2074
2075 /* Source is the texture, destination is the bounce texture. */
2076 IDirect3DSurface9 *pSrc;
2077 rc = vmsvga3dGetD3DSurface(pContext, pSurface, uHostFace, uHostMipmap, false, &pSrc);
2078 AssertRCReturn(rc, rc);
2079
2080 Assert(pSurf != pSrc);
2081
2082 hr = pContext->pDevice->GetRenderTargetData(pSrc, pSurf);
2083 AssertMsgReturn(hr == D3D_OK, ("GetRenderTargetData failed with %x\n", hr), VERR_INTERNAL_ERROR);
2084
2085 D3D_RELEASE(pSrc);
2086 }
2087 }
2088 }
2089
2090 RECT Rect;
2091 Rect.left = pBox->x;
2092 Rect.top = pBox->y;
2093 Rect.right = pBox->x + pBox->w; /* exclusive */
2094 Rect.bottom = pBox->y + pBox->h; /* exclusive */
2095
2096 D3DLOCKED_RECT LockedRect;
2097 hr = pSurf->LockRect(&LockedRect, &Rect, dwFlags);
2098 AssertMsgReturn(hr == D3D_OK, ("LockRect failed with %x\n", hr), VERR_INTERNAL_ERROR);
2099
2100 LogFunc(("Lock sid=%x %s(bounce=%d) memory for rectangle (%d,%d)(%d,%d)\n",
2101 pSurface->id, fTexture ? "TEXTURE " : "", RT_BOOL(pSurface->bounce.pTexture),
2102 Rect.left, Rect.top, Rect.right, Rect.bottom));
2103
2104 uint32_t u32BlockX = pBox->srcx / pSurface->cxBlock;
2105 uint32_t u32BlockY = pBox->srcy / pSurface->cyBlock;
2106 Assert(u32BlockX * pSurface->cxBlock == pBox->srcx);
2107 Assert(u32BlockY * pSurface->cyBlock == pBox->srcy);
2108 uint32_t cBlocksX = (pBox->w + pSurface->cxBlock - 1) / pSurface->cxBlock;
2109 uint32_t cBlocksY = (pBox->h + pSurface->cyBlock - 1) / pSurface->cyBlock;
2110
2111 rc = vmsvgaGMRTransfer(pThis,
2112 transfer,
2113 (uint8_t *)LockedRect.pBits,
2114 LockedRect.Pitch,
2115 GuestPtr,
2116 u32BlockX * pSurface->cbBlock + u32BlockY * cbGuestPitch,
2117 cbGuestPitch,
2118 cBlocksX * pSurface->cbBlock,
2119 cBlocksY);
2120 AssertRC(rc);
2121
2122 Log4(("first line:\n%.*Rhxd\n", cBlocksX * pSurface->cbBlock, LockedRect.pBits));
2123
2124 hr = pSurf->UnlockRect();
2125
2126 D3D_RELEASE(pSurf);
2127
2128 AssertMsgReturn(hr == D3D_OK, ("UnlockRect failed with %x\n", hr), VERR_INTERNAL_ERROR);
2129
2130 if (fTexture)
2131 {
2132 if (pSurface->bounce.pTexture)
2133 {
2134 if (transfer == SVGA3D_WRITE_HOST_VRAM)
2135 {
2136 LogFunc(("Sync texture from bounce buffer\n"));
2137
2138 /* Copy the new contents to the actual texture object. */
2139 hr = pContext->pDevice->UpdateTexture(pSurface->bounce.pTexture, pSurface->u.pTexture);
2140 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSurfaceDMA: UpdateTexture failed with %x\n", hr), VERR_INTERNAL_ERROR);
2141
2142 /* Track the copy operation. */
2143 vmsvga3dSurfaceTrackUsage(pState, pContext, pSurface);
2144 }
2145 }
2146 }
2147 }
2148 else if (RT_BOOL(u32SurfHints & (SVGA3D_SURFACE_HINT_VERTEXBUFFER |
2149 SVGA3D_SURFACE_HINT_INDEXBUFFER)))
2150 {
2151 /*
2152 * Mesa SVGA driver can use the same buffer either for vertex or index data.
2153 * But D3D distinguishes between index and vertex buffer objects.
2154 * Therefore it should be possible to switch the buffer type on the fly.
2155 *
2156 * Always save the data to the memory buffer in pSurface->pMipmapLevels and,
2157 * if necessary, recreate the corresponding D3D object with the data.
2158 */
2159
2160 /* Buffers are uncompressed. */
2161 AssertReturn(pSurface->cxBlock == 1 && pSurface->cyBlock == 1, VERR_INTERNAL_ERROR);
2162
2163 /* Current type of the buffer. */
2164 const bool fVertex = RT_BOOL(pSurface->fu32ActualUsageFlags & SVGA3D_SURFACE_HINT_VERTEXBUFFER);
2165
2166 /* Caller already clipped pBox and buffers are 1-dimensional. */
2167 Assert(pBox->y == 0 && pBox->h == 1 && pBox->z == 0 && pBox->d == 1);
2168
2169 const uint32_t uHostOffset = pBox->x * pSurface->cbBlock;
2170 const uint32_t cbWidth = pBox->w * pSurface->cbBlock;
2171
2172 AssertReturn(uHostOffset < pMipLevel->cbSurface, VERR_INTERNAL_ERROR);
2173 AssertReturn(cbWidth <= pMipLevel->cbSurface, VERR_INTERNAL_ERROR);
2174 AssertReturn(uHostOffset <= pMipLevel->cbSurface - cbWidth, VERR_INTERNAL_ERROR);
2175
2176 uint8_t *pu8HostData = (uint8_t *)pMipLevel->pSurfaceData + uHostOffset;
2177
2178 const uint32_t uGuestOffset = pBox->srcx * pSurface->cbBlock;
2179
2180 /* Copy data between the guest and the host buffer. */
2181 rc = vmsvgaGMRTransfer(pThis,
2182 transfer,
2183 pu8HostData,
2184 pMipLevel->cbSurfacePitch,
2185 GuestPtr,
2186 uGuestOffset,
2187 cbGuestPitch,
2188 cbWidth,
2189 1); /* Buffers are 1-dimensional */
2190 AssertRC(rc);
2191
2192 Log4(("Buffer first line:\n%.*Rhxd\n", cbWidth, pu8HostData));
2193
2194 pMipLevel->fDirty = true;
2195 pSurface->fDirty = true;
2196
2197 /* Also copy the data to the current D3D buffer object. */
2198 uint8_t *pu8Buffer = NULL;
2199 /** @todo lock only as much as we really need */
2200 if (fVertex)
2201 hr = pSurface->u.pVertexBuffer->Lock(0, 0, (void **)&pu8Buffer, dwFlags);
2202 else
2203 hr = pSurface->u.pIndexBuffer->Lock(0, 0, (void **)&pu8Buffer, dwFlags);
2204 AssertMsgReturn(hr == D3D_OK, ("Lock %s failed with %x\n", fVertex ? "vertex" : "index", hr), VERR_INTERNAL_ERROR);
2205
2206 LogFunc(("Lock %s memory for rectangle (%d,%d)(%d,%d)\n", fVertex ? "vertex" : "index", pBox->x, pBox->y, pBox->x + pBox->w, pBox->y + pBox->h));
2207
2208 const uint8_t *pu8Src = pu8HostData;
2209 uint8_t *pu8Dst = pu8Buffer + uHostOffset;
2210 memcpy(pu8Dst, pu8Src, cbWidth);
2211
2212 if (fVertex)
2213 hr = pSurface->u.pVertexBuffer->Unlock();
2214 else
2215 hr = pSurface->u.pIndexBuffer->Unlock();
2216 AssertMsg(hr == D3D_OK, ("Unlock %s failed with %x\n", fVertex ? "vertex" : "index", hr));
2217 }
2218 else
2219 {
2220 AssertMsgFailed(("Unsupported surface hint 0x%08X\n", u32SurfHints));
2221 }
2222
2223 return rc;
2224}
2225
2226
2227int vmsvga3dSurfaceBlitToScreen(PVGASTATE pThis, uint32_t dest, SVGASignedRect destRect, SVGA3dSurfaceImageId src, SVGASignedRect srcRect, uint32_t cRects, SVGASignedRect *pRect)
2228{
2229 /* Requires SVGA_FIFO_CAP_SCREEN_OBJECT support */
2230 Log(("vmsvga3dSurfaceBlitToScreen: dest=%d (%d,%d)(%d,%d) sid=%x (face=%d, mipmap=%d) (%d,%d)(%d,%d) cRects=%d\n", dest, destRect.left, destRect.top, destRect.right, destRect.bottom, src.sid, src.face, src.mipmap, srcRect.left, srcRect.top, srcRect.right, srcRect.bottom, cRects));
2231 for (uint32_t i = 0; i < cRects; i++)
2232 {
2233 Log(("vmsvga3dSurfaceBlitToScreen: clipping rect %d (%d,%d)(%d,%d)\n", i, pRect[i].left, pRect[i].top, pRect[i].right, pRect[i].bottom));
2234 }
2235
2236 /** @todo Only screen 0 for now. */
2237 AssertReturn(dest == 0, VERR_INTERNAL_ERROR);
2238 AssertReturn(src.mipmap == 0 && src.face == 0, VERR_INVALID_PARAMETER);
2239 /** @todo scaling */
2240 AssertReturn(destRect.right - destRect.left == srcRect.right - srcRect.left && destRect.bottom - destRect.top == srcRect.bottom - srcRect.top, VERR_INVALID_PARAMETER);
2241
2242 if (cRects == 0)
2243 {
2244 /* easy case; no clipping */
2245 SVGA3dCopyBox box;
2246 SVGA3dGuestImage dest;
2247
2248 box.x = destRect.left;
2249 box.y = destRect.top;
2250 box.z = 0;
2251 box.w = destRect.right - destRect.left;
2252 box.h = destRect.bottom - destRect.top;
2253 box.d = 1;
2254 box.srcx = srcRect.left;
2255 box.srcy = srcRect.top;
2256 box.srcz = 0;
2257
2258 dest.ptr.gmrId = SVGA_GMR_FRAMEBUFFER;
2259 dest.ptr.offset = 0;
2260 dest.pitch = pThis->svga.cbScanline;
2261
2262 int rc = vmsvga3dSurfaceDMA(pThis, dest, src, SVGA3D_READ_HOST_VRAM, 1, &box);
2263 AssertRCReturn(rc, rc);
2264
2265 vgaR3UpdateDisplay(pThis, box.x, box.y, box.w, box.h);
2266 return VINF_SUCCESS;
2267 }
2268 else
2269 {
2270 SVGA3dGuestImage dest;
2271 SVGA3dCopyBox box;
2272
2273 box.srcz = 0;
2274 box.z = 0;
2275 box.d = 1;
2276
2277 dest.ptr.gmrId = SVGA_GMR_FRAMEBUFFER;
2278 dest.ptr.offset = 0;
2279 dest.pitch = pThis->svga.cbScanline;
2280
2281 /** @todo merge into one SurfaceDMA call */
2282 for (uint32_t i = 0; i < cRects; i++)
2283 {
2284 /* The clipping rectangle is relative to the top-left corner of srcRect & destRect. Adjust here. */
2285 box.srcx = srcRect.left + pRect[i].left;
2286 box.srcy = srcRect.top + pRect[i].top;
2287
2288 box.x = pRect[i].left + destRect.left;
2289 box.y = pRect[i].top + destRect.top;
2290 box.z = 0;
2291 box.w = pRect[i].right - pRect[i].left;
2292 box.h = pRect[i].bottom - pRect[i].top;
2293
2294 int rc = vmsvga3dSurfaceDMA(pThis, dest, src, SVGA3D_READ_HOST_VRAM, 1, &box);
2295 AssertRCReturn(rc, rc);
2296
2297 vgaR3UpdateDisplay(pThis, box.x, box.y, box.w, box.h);
2298 }
2299
2300#if 0
2301 {
2302 PVMSVGA3DSTATE pState = pThis->svga.p3dState;
2303 HRESULT hr;
2304 PVMSVGA3DSURFACE pSurface;
2305 PVMSVGA3DCONTEXT pContext;
2306 uint32_t sid = src.sid;
2307 AssertReturn(sid < SVGA3D_MAX_SURFACE_IDS, VERR_INVALID_PARAMETER);
2308 AssertReturn(sid < pState->cSurfaces && pState->papSurfaces[sid]->id == sid, VERR_INVALID_PARAMETER);
2309
2310 pSurface = pState->papSurfaces[sid];
2311 uint32_t cid;
2312
2313 /** @todo stricter checks for associated context */
2314 cid = pSurface->idAssociatedContext;
2315
2316 if ( cid >= pState->cContexts
2317 || pState->papContexts[cid]->id != cid)
2318 {
2319 Log(("vmsvga3dGenerateMipmaps invalid context id!\n"));
2320 return VERR_INVALID_PARAMETER;
2321 }
2322 pContext = pState->papContexts[cid];
2323
2324 if (pSurface->id == 0x5e)
2325 {
2326 IDirect3DSurface9 *pSrc;
2327
2328 hr = pSurface->u.pTexture->GetSurfaceLevel(0/* Texture level */,
2329 &pSrc);
2330 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSurfaceStretchBlt: GetSurfaceLevel failed with %x\n", hr), VERR_INTERNAL_ERROR);
2331
2332 pContext->pDevice->ColorFill(pSrc, NULL, (D3DCOLOR)0x11122255);
2333 D3D_RELEASE(pSrc);
2334 }
2335 }
2336#endif
2337
2338 return VINF_SUCCESS;
2339 }
2340}
2341
2342int vmsvga3dGenerateMipmaps(PVGASTATE pThis, uint32_t sid, SVGA3dTextureFilter filter)
2343{
2344 PVMSVGA3DSTATE pState = pThis->svga.p3dState;
2345 PVMSVGA3DSURFACE pSurface;
2346 int rc = VINF_SUCCESS;
2347 HRESULT hr;
2348
2349 AssertReturn(pState, VERR_NO_MEMORY);
2350 AssertReturn(sid < SVGA3D_MAX_SURFACE_IDS, VERR_INVALID_PARAMETER);
2351 AssertReturn(sid < pState->cSurfaces && pState->papSurfaces[sid]->id == sid, VERR_INVALID_PARAMETER);
2352
2353 pSurface = pState->papSurfaces[sid];
2354 AssertReturn(pSurface->idAssociatedContext != SVGA3D_INVALID_ID, VERR_INTERNAL_ERROR);
2355
2356 Assert(filter != SVGA3D_TEX_FILTER_FLATCUBIC);
2357 Assert(filter != SVGA3D_TEX_FILTER_GAUSSIANCUBIC);
2358 pSurface->autogenFilter = filter;
2359
2360 Log(("vmsvga3dGenerateMipmaps: sid=%x filter=%d\n", sid, filter));
2361
2362 if (!pSurface->u.pSurface)
2363 {
2364 PVMSVGA3DCONTEXT pContext;
2365 uint32_t cid;
2366
2367 /** @todo stricter checks for associated context */
2368 cid = pSurface->idAssociatedContext;
2369
2370 if ( cid >= pState->cContexts
2371 || pState->papContexts[cid]->id != cid)
2372 {
2373 Log(("vmsvga3dGenerateMipmaps invalid context id!\n"));
2374 return VERR_INVALID_PARAMETER;
2375 }
2376 pContext = pState->papContexts[cid];
2377
2378 /* Unknown surface type; turn it into a texture. */
2379 Log(("vmsvga3dGenerateMipmaps: unknown src surface sid=%x type=%d format=%d -> create texture\n", sid, pSurface->flags, pSurface->format));
2380 rc = vmsvga3dBackCreateTexture(pState, pContext, cid, pSurface);
2381 AssertRCReturn(rc, rc);
2382 }
2383 else
2384 {
2385 hr = pSurface->u.pTexture->SetAutoGenFilterType((D3DTEXTUREFILTERTYPE)filter);
2386 AssertMsg(hr == D3D_OK, ("vmsvga3dGenerateMipmaps: SetAutoGenFilterType failed with %x\n", hr));
2387 }
2388
2389 /* Generate the mip maps. */
2390 pSurface->u.pTexture->GenerateMipSubLevels();
2391
2392 return VINF_SUCCESS;
2393}
2394
2395int vmsvga3dCommandPresent(PVGASTATE pThis, uint32_t sid, uint32_t cRects, SVGA3dCopyRect *pRect)
2396{
2397 PVMSVGA3DSTATE pState = pThis->svga.p3dState;
2398 PVMSVGA3DSURFACE pSurface;
2399 PVMSVGA3DCONTEXT pContext;
2400 uint32_t cid;
2401 HRESULT hr;
2402 IDirect3DSurface9 *pBackBuffer;
2403 IDirect3DSurface9 *pSurfaceD3D;
2404
2405 AssertReturn(pState, VERR_NO_MEMORY);
2406 AssertReturn(sid < SVGA3D_MAX_SURFACE_IDS, VERR_INVALID_PARAMETER);
2407 AssertReturn(sid < pState->cSurfaces && pState->papSurfaces[sid]->id == sid, VERR_INVALID_PARAMETER);
2408
2409 pSurface = pState->papSurfaces[sid];
2410 AssertReturn(pSurface->idAssociatedContext != SVGA3D_INVALID_ID, VERR_INTERNAL_ERROR);
2411
2412 /** @todo stricter checks for associated context */
2413 cid = pSurface->idAssociatedContext;
2414 Log(("vmsvga3dCommandPresent: sid=%x cRects=%d cid=%x\n", sid, cRects, cid));
2415 for (uint32_t i=0; i < cRects; i++)
2416 {
2417 Log(("vmsvga3dCommandPresent: rectangle %d src=(%d,%d) (%d,%d)(%d,%d)\n", i, pRect[i].srcx, pRect[i].srcy, pRect[i].x, pRect[i].y, pRect[i].x + pRect[i].w, pRect[i].y + pRect[i].h));
2418 }
2419
2420 if ( cid >= pState->cContexts
2421 || pState->papContexts[cid]->id != cid)
2422 {
2423 Log(("vmsvga3dCommandPresent invalid context id!\n"));
2424 return VERR_INVALID_PARAMETER;
2425 }
2426 pContext = pState->papContexts[cid];
2427
2428 hr = pContext->pDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer);
2429 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dCommandPresent: GetBackBuffer failed with %x\n", hr), VERR_INTERNAL_ERROR);
2430
2431 if (pSurface->flags & SVGA3D_SURFACE_HINT_TEXTURE)
2432 {
2433 hr = pSurface->u.pTexture->GetSurfaceLevel(0, &pSurfaceD3D);
2434 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dCommandPresent: GetSurfaceLevel failed with %x\n", hr), VERR_INTERNAL_ERROR);
2435 }
2436 else
2437 pSurfaceD3D = pSurface->u.pSurface;
2438
2439 /* Read the destination viewport specs in one go to try avoid some unnecessary update races. */
2440 VMSVGAVIEWPORT const DstViewport = pThis->svga.viewport;
2441 ASMCompilerBarrier(); /* paranoia */
2442 Assert(DstViewport.yHighWC >= DstViewport.yLowWC);
2443
2444 /* If there are no recangles specified, just grab a screenful. */
2445 SVGA3dCopyRect DummyRect;
2446 if (cRects != 0)
2447 { /* likely */ }
2448 else
2449 {
2450 /** @todo Find the usecase for this or check what the original device does.
2451 * The original code was doing some scaling based on the surface
2452 * size... */
2453# ifdef DEBUG_bird
2454 AssertMsgFailed(("No rects to present. Who is doing that and what do they actually expect?\n"));
2455# endif
2456 DummyRect.x = DummyRect.srcx = 0;
2457 DummyRect.y = DummyRect.srcy = 0;
2458 DummyRect.w = pThis->svga.uWidth;
2459 DummyRect.h = pThis->svga.uHeight;
2460 cRects = 1;
2461 pRect = &DummyRect;
2462 }
2463
2464 /*
2465 * Blit the surface rectangle(s) to the back buffer.
2466 */
2467 Assert(pSurface->cxBlock == 1 && pSurface->cyBlock == 1);
2468 uint32_t const cxSurface = pSurface->pMipmapLevels[0].mipmapSize.width;
2469 uint32_t const cySurface = pSurface->pMipmapLevels[0].mipmapSize.height;
2470 for (uint32_t i = 0; i < cRects; i++)
2471 {
2472 SVGA3dCopyRect ClippedRect = pRect[i];
2473
2474 /*
2475 * Do some sanity checking and limit width and height, all so we
2476 * don't need to think about wrap-arounds below.
2477 */
2478 if (RT_LIKELY( ClippedRect.w
2479 && ClippedRect.x < VMSVGA_MAX_X
2480 && ClippedRect.srcx < VMSVGA_MAX_X
2481 && ClippedRect.h
2482 && ClippedRect.y < VMSVGA_MAX_Y
2483 && ClippedRect.srcy < VMSVGA_MAX_Y
2484 ))
2485 { /* likely */ }
2486 else
2487 continue;
2488
2489 if (RT_LIKELY(ClippedRect.w < VMSVGA_MAX_Y))
2490 { /* likely */ }
2491 else
2492 ClippedRect.w = VMSVGA_MAX_Y;
2493 if (RT_LIKELY(ClippedRect.w < VMSVGA_MAX_Y))
2494 { /* likely */ }
2495 else
2496 ClippedRect.w = VMSVGA_MAX_Y;
2497
2498 /*
2499 * Source surface clipping (paranoia). Straight forward.
2500 */
2501 if (RT_LIKELY(ClippedRect.srcx < cxSurface))
2502 { /* likely */ }
2503 else
2504 continue;
2505 if (RT_LIKELY(ClippedRect.srcx + ClippedRect.w <= cxSurface))
2506 { /* likely */ }
2507 else
2508 {
2509 AssertFailed(); /* remove if annoying. */
2510 ClippedRect.w = cxSurface - ClippedRect.srcx;
2511 }
2512
2513 if (RT_LIKELY(ClippedRect.srcy < cySurface))
2514 { /* likely */ }
2515 else
2516 continue;
2517 if (RT_LIKELY(ClippedRect.srcy + ClippedRect.h <= cySurface))
2518 { /* likely */ }
2519 else
2520 {
2521 AssertFailed(); /* remove if annoying. */
2522 ClippedRect.h = cySurface - ClippedRect.srcy;
2523 }
2524
2525 /*
2526 * Destination viewport clipping.
2527 *
2528 * This is very straight forward compared to OpenGL. There is no Y
2529 * inversion anywhere and all the coordinate systems are the same.
2530 */
2531 /* X */
2532 if (ClippedRect.x >= DstViewport.x)
2533 {
2534 if (ClippedRect.x + ClippedRect.w <= DstViewport.xRight)
2535 { /* typical */ }
2536 else if (ClippedRect.x < DstViewport.xRight)
2537 ClippedRect.w = DstViewport.xRight - ClippedRect.x;
2538 else
2539 continue;
2540 }
2541 else
2542 {
2543 uint32_t cxAdjust = DstViewport.x - ClippedRect.x;
2544 if (cxAdjust < ClippedRect.w)
2545 {
2546 ClippedRect.w -= cxAdjust;
2547 ClippedRect.x += cxAdjust;
2548 ClippedRect.srcx += cxAdjust;
2549 }
2550 else
2551 continue;
2552
2553 if (ClippedRect.x + ClippedRect.w <= DstViewport.xRight)
2554 { /* typical */ }
2555 else
2556 ClippedRect.w = DstViewport.xRight - ClippedRect.x;
2557 }
2558
2559 /* Y */
2560 if (ClippedRect.y >= DstViewport.y)
2561 {
2562 if (ClippedRect.y + ClippedRect.h <= DstViewport.y + DstViewport.cy)
2563 { /* typical */ }
2564 else if (ClippedRect.x < DstViewport.y + DstViewport.cy)
2565 ClippedRect.h = DstViewport.y + DstViewport.cy - ClippedRect.y;
2566 else
2567 continue;
2568 }
2569 else
2570 {
2571 uint32_t cyAdjust = DstViewport.y - ClippedRect.y;
2572 if (cyAdjust < ClippedRect.h)
2573 {
2574 ClippedRect.h -= cyAdjust;
2575 ClippedRect.y += cyAdjust;
2576 ClippedRect.srcy += cyAdjust;
2577 }
2578 else
2579 continue;
2580
2581 if (ClippedRect.y + ClippedRect.h <= DstViewport.y + DstViewport.cy)
2582 { /* typical */ }
2583 else
2584 ClippedRect.h = DstViewport.y + DstViewport.cy - ClippedRect.y;
2585 }
2586
2587 /* Calc source rectangle. */
2588 RECT SrcRect;
2589 SrcRect.left = ClippedRect.srcx;
2590 SrcRect.right = ClippedRect.srcx + ClippedRect.w;
2591 SrcRect.top = ClippedRect.srcy;
2592 SrcRect.bottom = ClippedRect.srcy + ClippedRect.h;
2593
2594 /* Calc destination rectangle. */
2595 RECT DstRect;
2596 DstRect.left = ClippedRect.x;
2597 DstRect.right = ClippedRect.x + ClippedRect.w;
2598 DstRect.top = ClippedRect.y;
2599 DstRect.bottom = ClippedRect.y + ClippedRect.h;
2600
2601 /* Adjust for viewport. */
2602 DstRect.left -= DstViewport.x;
2603 DstRect.right -= DstViewport.x;
2604 DstRect.bottom -= DstViewport.y;
2605 DstRect.top -= DstViewport.y;
2606
2607 Log(("SrcRect: (%d,%d)(%d,%d) DstRect: (%d,%d)(%d,%d)\n",
2608 SrcRect.left, SrcRect.bottom, SrcRect.right, SrcRect.top,
2609 DstRect.left, DstRect.bottom, DstRect.right, DstRect.top));
2610 hr = pContext->pDevice->StretchRect(pSurfaceD3D, &SrcRect, pBackBuffer, &DstRect, D3DTEXF_NONE);
2611 AssertBreak(hr == D3D_OK);
2612 }
2613
2614 if (pSurface->flags & SVGA3D_SURFACE_HINT_TEXTURE)
2615 D3D_RELEASE(pSurfaceD3D);
2616
2617 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dCommandPresent: StretchRect failed with %x\n", hr), VERR_INTERNAL_ERROR);
2618
2619 hr = pContext->pDevice->Present(NULL, NULL, NULL, NULL);
2620 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dCommandPresent: Present failed with %x\n", hr), VERR_INTERNAL_ERROR);
2621
2622 D3D_RELEASE(pBackBuffer);
2623 return VINF_SUCCESS;
2624}
2625
2626
2627/**
2628 * Create a new 3d context
2629 *
2630 * @returns VBox status code.
2631 * @param pThis VGA device instance data.
2632 * @param cid Context id
2633 */
2634int vmsvga3dContextDefine(PVGASTATE pThis, uint32_t cid)
2635{
2636 int rc;
2637 PVMSVGA3DCONTEXT pContext;
2638 HRESULT hr;
2639 D3DPRESENT_PARAMETERS PresParam;
2640 PVMSVGA3DSTATE pState = pThis->svga.p3dState;
2641
2642 Log(("vmsvga3dContextDefine id %x\n", cid));
2643
2644 AssertReturn(pState, VERR_NO_MEMORY);
2645 AssertReturn(cid < SVGA3D_MAX_CONTEXT_IDS, VERR_INVALID_PARAMETER);
2646
2647 if (cid >= pState->cContexts)
2648 {
2649 /* Grow the array. */
2650 uint32_t cNew = RT_ALIGN(cid + 15, 16);
2651 void *pvNew = RTMemRealloc(pState->papContexts, sizeof(pState->papContexts[0]) * cNew);
2652 AssertReturn(pvNew, VERR_NO_MEMORY);
2653 pState->papContexts = (PVMSVGA3DCONTEXT *)pvNew;
2654 while (pState->cContexts < cNew)
2655 {
2656 pContext = (PVMSVGA3DCONTEXT)RTMemAllocZ(sizeof(*pContext));
2657 AssertReturn(pContext, VERR_NO_MEMORY);
2658 pContext->id = SVGA3D_INVALID_ID;
2659 pState->papContexts[pState->cContexts++] = pContext;
2660 }
2661 }
2662 /* If one already exists with this id, then destroy it now. */
2663 if (pState->papContexts[cid]->id != SVGA3D_INVALID_ID)
2664 vmsvga3dContextDestroy(pThis, cid);
2665
2666 pContext = pState->papContexts[cid];
2667 memset(pContext, 0, sizeof(*pContext));
2668 pContext->id = cid;
2669 for (uint32_t i = 0; i< RT_ELEMENTS(pContext->aSidActiveTexture); i++)
2670 pContext->aSidActiveTexture[i] = SVGA3D_INVALID_ID;
2671 pContext->sidRenderTarget = SVGA3D_INVALID_ID;
2672 pContext->state.shidVertex = SVGA3D_INVALID_ID;
2673 pContext->state.shidPixel = SVGA3D_INVALID_ID;
2674
2675 for (uint32_t i = 0; i < RT_ELEMENTS(pContext->state.aRenderTargets); i++)
2676 pContext->state.aRenderTargets[i] = SVGA3D_INVALID_ID;
2677
2678 /* Create a context window. */
2679 CREATESTRUCT cs;
2680
2681 AssertReturn(pThis->svga.u64HostWindowId, VERR_INTERNAL_ERROR);
2682
2683 cs.lpCreateParams = NULL;
2684 cs.dwExStyle = WS_EX_NOACTIVATE | WS_EX_NOPARENTNOTIFY | WS_EX_TRANSPARENT;
2685#ifdef DEBUG_GFX_WINDOW
2686 cs.lpszName = (char *)RTMemAllocZ(256);
2687 RTStrPrintf((char *)cs.lpszName, 256, "Context %d OpenGL Window", cid);
2688#else
2689 cs.lpszName = NULL;
2690#endif
2691 cs.lpszClass = NULL;
2692#ifdef DEBUG_GFX_WINDOW
2693 cs.style = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE | WS_CAPTION;
2694#else
2695 cs.style = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_DISABLED | WS_CHILD | WS_VISIBLE;
2696#endif
2697 cs.x = 0;
2698 cs.y = 0;
2699 cs.cx = pThis->svga.uWidth;
2700 cs.cy = pThis->svga.uHeight;
2701 cs.hwndParent = (HWND)pThis->svga.u64HostWindowId;
2702 cs.hMenu = NULL;
2703 cs.hInstance = pState->hInstance;
2704
2705 rc = vmsvga3dSendThreadMessage(pState->pWindowThread, pState->WndRequestSem, WM_VMSVGA3D_CREATEWINDOW, (WPARAM)&pContext->hwnd, (LPARAM)&cs);
2706 AssertRCReturn(rc, rc);
2707
2708 /* Changed when the function returns. */
2709 PresParam.BackBufferWidth = 0;
2710 PresParam.BackBufferHeight = 0;
2711 PresParam.BackBufferFormat = D3DFMT_UNKNOWN;
2712 PresParam.BackBufferCount = 0;
2713
2714 PresParam.MultiSampleType = D3DMULTISAMPLE_NONE;
2715 PresParam.MultiSampleQuality = 0;
2716 PresParam.SwapEffect = D3DSWAPEFFECT_FLIP;
2717 PresParam.hDeviceWindow = pContext->hwnd;
2718 PresParam.Windowed = TRUE; /** @todo */
2719 PresParam.EnableAutoDepthStencil = FALSE;
2720 PresParam.AutoDepthStencilFormat = D3DFMT_UNKNOWN; /* not relevant */
2721 PresParam.Flags = 0;
2722 PresParam.FullScreen_RefreshRateInHz = 0; /* windowed -> 0 */
2723 /** @todo consider using D3DPRESENT_DONOTWAIT so we don't wait for the GPU during Present calls. */
2724 PresParam.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
2725
2726#ifdef VBOX_VMSVGA3D_WITH_WINE_OPENGL
2727 hr = pState->pD3D9->CreateDevice(D3DADAPTER_DEFAULT,
2728 D3DDEVTYPE_HAL,
2729 pContext->hwnd,
2730 D3DCREATE_MULTITHREADED | D3DCREATE_MIXED_VERTEXPROCESSING, //D3DCREATE_HARDWARE_VERTEXPROCESSING,
2731 &PresParam,
2732 &pContext->pDevice);
2733#else
2734 hr = pState->pD3D9->CreateDeviceEx(D3DADAPTER_DEFAULT,
2735 D3DDEVTYPE_HAL,
2736 pContext->hwnd,
2737 D3DCREATE_MULTITHREADED | D3DCREATE_MIXED_VERTEXPROCESSING, //D3DCREATE_HARDWARE_VERTEXPROCESSING,
2738 &PresParam,
2739 NULL,
2740 &pContext->pDevice);
2741#endif
2742 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dContextDefine: CreateDevice failed with %x\n", hr), VERR_INTERNAL_ERROR);
2743
2744 Log(("vmsvga3dContextDefine: Backbuffer (%d,%d) count=%d format=%x\n", PresParam.BackBufferWidth, PresParam.BackBufferHeight, PresParam.BackBufferCount, PresParam.BackBufferFormat));
2745 return VINF_SUCCESS;
2746}
2747
2748/**
2749 * Destroy an existing 3d context
2750 *
2751 * @returns VBox status code.
2752 * @param pThis VGA device instance data.
2753 * @param cid Context id
2754 */
2755int vmsvga3dContextDestroy(PVGASTATE pThis, uint32_t cid)
2756{
2757 PVMSVGA3DSTATE pState = pThis->svga.p3dState;
2758 AssertReturn(pState, VERR_NO_MEMORY);
2759
2760 AssertReturn(cid < SVGA3D_MAX_CONTEXT_IDS, VERR_INVALID_PARAMETER);
2761
2762 if ( cid < pState->cContexts
2763 && pState->papContexts[cid]->id == cid)
2764 {
2765 PVMSVGA3DCONTEXT pContext = pState->papContexts[cid];
2766
2767 Log(("vmsvga3dContextDestroy id %x\n", cid));
2768
2769 /* Check for all surfaces that are associated with this context to remove all dependencies */
2770 for (uint32_t sid = 0; sid < pState->cSurfaces; sid++)
2771 {
2772 PVMSVGA3DSURFACE pSurface = pState->papSurfaces[sid];
2773 if ( pSurface->id == sid
2774 && pSurface->idAssociatedContext == cid)
2775 {
2776 int rc;
2777
2778 Log(("vmsvga3dContextDestroy: remove all dependencies for surface sid=%x\n", sid));
2779
2780 uint32_t surfaceFlags = pSurface->flags;
2781 SVGA3dSurfaceFormat format = pSurface->format;
2782 SVGA3dSurfaceFace face[SVGA3D_MAX_SURFACE_FACES];
2783 uint32_t multisampleCount = pSurface->multiSampleCount;
2784 SVGA3dTextureFilter autogenFilter = pSurface->autogenFilter;
2785 SVGA3dSize *pMipLevelSize;
2786 uint32_t cFaces = pSurface->cFaces;
2787
2788 pMipLevelSize = (SVGA3dSize *)RTMemAllocZ(pSurface->faces[0].numMipLevels * pSurface->cFaces * sizeof(SVGA3dSize));
2789 AssertReturn(pMipLevelSize, VERR_NO_MEMORY);
2790
2791 for (uint32_t face=0; face < pSurface->cFaces; face++)
2792 {
2793 for (uint32_t i = 0; i < pSurface->faces[0].numMipLevels; i++)
2794 {
2795 uint32_t idx = i + face * pSurface->faces[0].numMipLevels;
2796 memcpy(&pMipLevelSize[idx], &pSurface->pMipmapLevels[idx].mipmapSize, sizeof(SVGA3dSize));
2797 }
2798 }
2799 memcpy(face, pSurface->faces, sizeof(pSurface->faces));
2800
2801 /* Recreate the surface with the original settings; destroys the contents, but that seems fairly safe since the context is also destroyed. */
2802 /** @todo not safe with shared objects */
2803 Assert(pSurface->pSharedObjectTree == NULL);
2804
2805 rc = vmsvga3dSurfaceDestroy(pThis, sid);
2806 AssertRC(rc);
2807
2808 rc = vmsvga3dSurfaceDefine(pThis, sid, surfaceFlags, format, face, multisampleCount, autogenFilter, face[0].numMipLevels * cFaces, pMipLevelSize);
2809 AssertRC(rc);
2810
2811 Assert(!pSurface->u.pSurface);
2812 }
2813 else
2814 {
2815 /* Check for a shared surface object. */
2816 PVMSVGA3DSHAREDSURFACE pSharedSurface = (PVMSVGA3DSHAREDSURFACE)RTAvlU32Get(&pSurface->pSharedObjectTree, cid);
2817 if (pSharedSurface)
2818 {
2819 Log(("vmsvga3dContextDestroy: remove shared dependency for surface sid=%x\n", sid));
2820
2821 switch (pSurface->flags & VMSVGA3D_SURFACE_HINT_SWITCH_MASK)
2822 {
2823 case SVGA3D_SURFACE_HINT_TEXTURE:
2824 case SVGA3D_SURFACE_HINT_TEXTURE | SVGA3D_SURFACE_HINT_RENDERTARGET:
2825 Assert(pSharedSurface->u.pTexture);
2826 D3D_RELEASE(pSharedSurface->u.pTexture);
2827 break;
2828
2829 default:
2830 AssertFailed();
2831 break;
2832 }
2833 RTAvlU32Remove(&pSurface->pSharedObjectTree, cid);
2834 RTMemFree(pSharedSurface);
2835 }
2836 }
2837 }
2838
2839 /* Destroy all leftover pixel shaders. */
2840 for (uint32_t i = 0; i < pContext->cPixelShaders; i++)
2841 {
2842 if (pContext->paPixelShader[i].id != SVGA3D_INVALID_ID)
2843 vmsvga3dShaderDestroy(pThis, pContext->paPixelShader[i].cid, pContext->paPixelShader[i].id, pContext->paPixelShader[i].type);
2844 }
2845 if (pContext->paPixelShader)
2846 RTMemFree(pContext->paPixelShader);
2847
2848 /* Destroy all leftover vertex shaders. */
2849 for (uint32_t i = 0; i < pContext->cVertexShaders; i++)
2850 {
2851 if (pContext->paVertexShader[i].id != SVGA3D_INVALID_ID)
2852 vmsvga3dShaderDestroy(pThis, pContext->paVertexShader[i].cid, pContext->paVertexShader[i].id, pContext->paVertexShader[i].type);
2853 }
2854 if (pContext->paVertexShader)
2855 RTMemFree(pContext->paVertexShader);
2856
2857 if (pContext->state.paVertexShaderConst)
2858 RTMemFree(pContext->state.paVertexShaderConst);
2859 if (pContext->state.paPixelShaderConst)
2860 RTMemFree(pContext->state.paPixelShaderConst);
2861
2862 /* Release the D3D device object */
2863 D3D_RELEASE(pContext->pDevice);
2864
2865 /* Destroy the window we've created. */
2866 int rc = vmsvga3dSendThreadMessage(pState->pWindowThread, pState->WndRequestSem, WM_VMSVGA3D_DESTROYWINDOW, (WPARAM)pContext->hwnd, 0);
2867 AssertRC(rc);
2868
2869 memset(pContext, 0, sizeof(*pContext));
2870 pContext->id = SVGA3D_INVALID_ID;
2871 }
2872 else
2873 AssertFailed();
2874
2875 return VINF_SUCCESS;
2876}
2877
2878static int vmsvga3dContextTrackUsage(PVGASTATE pThis, PVMSVGA3DCONTEXT pContext)
2879{
2880#ifndef VBOX_VMSVGA3D_WITH_WINE_OPENGL
2881 PVMSVGA3DSTATE pState = pThis->svga.p3dState;
2882 AssertReturn(pState, VERR_NO_MEMORY);
2883
2884 /* Inject fences to make sure we can track surface usage in case the client wants to reuse it in another context. */
2885 for (uint32_t i = 0; i < RT_ELEMENTS(pContext->aSidActiveTexture); i++)
2886 {
2887 if (pContext->aSidActiveTexture[i] != SVGA3D_INVALID_ID)
2888 vmsvga3dSurfaceTrackUsageById(pState, pContext, pContext->aSidActiveTexture[i]);
2889 }
2890 if (pContext->sidRenderTarget != SVGA3D_INVALID_ID)
2891 vmsvga3dSurfaceTrackUsageById(pState, pContext, pContext->sidRenderTarget);
2892#endif
2893 return VINF_SUCCESS;
2894}
2895
2896/* Handle resize */
2897int vmsvga3dChangeMode(PVGASTATE pThis)
2898{
2899 PVMSVGA3DSTATE pState = pThis->svga.p3dState;
2900 AssertReturn(pState, VERR_NO_MEMORY);
2901
2902 /* Resize all active contexts. */
2903 for (uint32_t i = 0; i < pState->cContexts; i++)
2904 {
2905 PVMSVGA3DCONTEXT pContext = pState->papContexts[i];
2906 uint32_t cid = pContext->id;
2907
2908 if (cid != SVGA3D_INVALID_ID)
2909 {
2910 CREATESTRUCT cs;
2911 D3DPRESENT_PARAMETERS PresParam;
2912 D3DVIEWPORT9 viewportOrg;
2913 HRESULT hr;
2914
2915#ifdef VMSVGA3D_DIRECT3D9_RESET
2916 /* Sync back all surface data as everything is lost after the Reset. */
2917 for (uint32_t sid = 0; sid < pState->cSurfaces; sid++)
2918 {
2919 PVMSVGA3DSURFACE pSurface = pState->papSurfaces[sid];
2920 if ( pSurface->id == sid
2921 && pSurface->idAssociatedContext == cid
2922 && pSurface->u.pSurface)
2923 {
2924 Log(("vmsvga3dChangeMode: sync back data of surface sid=%x (fDirty=%d)\n", sid, pSurface->fDirty));
2925
2926 /* Reallocate our surface memory buffers. */
2927 for (uint32_t i = 0; i < pSurface->cMipLevels; i++)
2928 {
2929 PVMSVGA3DMIPMAPLEVEL pMipmapLevel = &pSurface->pMipmapLevels[i];
2930
2931 pMipmapLevel->pSurfaceData = RTMemAllocZ(pMipmapLevel->cbSurface);
2932 AssertReturn(pMipmapLevel->pSurfaceData, VERR_NO_MEMORY);
2933
2934 if (!pSurface->fDirty)
2935 {
2936 D3DLOCKED_RECT LockedRect;
2937
2938 if (pSurface->bounce.pTexture)
2939 {
2940 IDirect3DSurface9 *pSrc, *pDest;
2941
2942 /** @todo only sync when something was actually rendered (since the last sync) */
2943 Log(("vmsvga3dChangeMode: sync bounce buffer (level %d)\n", i));
2944 hr = pSurface->bounce.pTexture->GetSurfaceLevel(i, &pDest);
2945 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dChangeMode: GetSurfaceLevel failed with %x\n", hr), VERR_INTERNAL_ERROR);
2946
2947 hr = pSurface->u.pTexture->GetSurfaceLevel(i, &pSrc);
2948 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dChangeMode: GetSurfaceLevel failed with %x\n", hr), VERR_INTERNAL_ERROR);
2949
2950 hr = pContext->pDevice->GetRenderTargetData(pSrc, pDest);
2951 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dChangeMode: GetRenderTargetData failed with %x\n", hr), VERR_INTERNAL_ERROR);
2952
2953 D3D_RELEASE(pSrc);
2954 D3D_RELEASE(pDest);
2955
2956 hr = pSurface->bounce.pTexture->LockRect(i,
2957 &LockedRect,
2958 NULL,
2959 D3DLOCK_READONLY);
2960 }
2961 else
2962 hr = pSurface->u.pTexture->LockRect(i,
2963 &LockedRect,
2964 NULL,
2965 D3DLOCK_READONLY);
2966 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dChangeMode: LockRect failed with %x\n", hr), VERR_INTERNAL_ERROR);
2967
2968 /* Copy the data one line at a time in case the internal pitch is different. */
2969 for (uint32_t j = 0; j < pMipmapLevel->size.height; j++)
2970 {
2971 memcpy((uint8_t *)pMipmapLevel->pSurfaceData + j * pMipmapLevel->cbSurfacePitch, (uint8_t *)LockedRect.pBits + j * LockedRect.Pitch, pMipmapLevel->cbSurfacePitch);
2972 }
2973
2974 if (pSurface->bounce.pTexture)
2975 hr = pSurface->bounce.pTexture->UnlockRect(i);
2976 else
2977 hr = pSurface->u.pTexture->UnlockRect(i);
2978 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dChangeMode: UnlockRect failed with %x\n", hr), VERR_INTERNAL_ERROR);
2979 }
2980 }
2981
2982
2983 switch (pSurface->flags & VMSVGA3D_SURFACE_HINT_SWITCH_MASK)
2984 {
2985 case SVGA3D_SURFACE_CUBEMAP:
2986 case SVGA3D_SURFACE_CUBEMAP | SVGA3D_SURFACE_HINT_TEXTURE:
2987 case SVGA3D_SURFACE_CUBEMAP | SVGA3D_SURFACE_HINT_TEXTURE | SVGA3D_SURFACE_HINT_RENDERTARGET:
2988 D3D_RELEASE(pSurface->u.pCubeTexture);
2989 D3D_RELEASE(pSurface->bounce.pCubeTexture);
2990 break;
2991
2992 case SVGA3D_SURFACE_HINT_INDEXBUFFER | SVGA3D_SURFACE_HINT_VERTEXBUFFER:
2993 case SVGA3D_SURFACE_HINT_INDEXBUFFER:
2994 case SVGA3D_SURFACE_HINT_VERTEXBUFFER:
2995 if (pSurface->fu32ActualUsageFlags == SVGA3D_SURFACE_HINT_VERTEXBUFFER)
2996 D3D_RELEASE(pSurface->u.pVertexBuffer);
2997 else if (pSurface->fu32ActualUsageFlags == SVGA3D_SURFACE_HINT_INDEXBUFFER)
2998 D3D_RELEASE(pSurface->u.pIndexBuffer);
2999 else
3000 AssertMsg(pSurface->u.pVertexBuffer == NULL, ("fu32ActualUsageFlags %x\n", pSurface->fu32ActualUsageFlags));
3001 break;
3002
3003 case SVGA3D_SURFACE_HINT_TEXTURE:
3004 case SVGA3D_SURFACE_HINT_TEXTURE | SVGA3D_SURFACE_HINT_RENDERTARGET:
3005 D3D_RELEASE(pSurface->u.pTexture);
3006 D3D_RELEASE(pSurface->bounce.pTexture);
3007 break;
3008
3009 case SVGA3D_SURFACE_HINT_RENDERTARGET:
3010 case SVGA3D_SURFACE_HINT_DEPTHSTENCIL:
3011 if (pSurface->fStencilAsTexture)
3012 D3D_RELEASE(pSurface->u.pTexture);
3013 else
3014 D3D_RELEASE(pSurface->u.pSurface);
3015 break;
3016
3017 default:
3018 AssertFailed();
3019 break;
3020 }
3021 RTAvlU32Destroy(&pSurface->pSharedObjectTree, vmsvga3dSharedSurfaceDestroyTree, pSurface);
3022 Assert(pSurface->pSharedObjectTree == NULL);
3023
3024 pSurface->idAssociatedContext = SVGA3D_INVALID_ID;
3025 pSurface->hSharedObject = 0;
3026 }
3027 }
3028#endif /* #ifdef VMSVGA3D_DIRECT3D9_RESET */
3029 memset(&cs, 0, sizeof(cs));
3030 cs.cx = pThis->svga.uWidth;
3031 cs.cy = pThis->svga.uHeight;
3032
3033 Log(("vmsvga3dChangeMode: Resize window %x of context %d to (%d,%d)\n", pContext->hwnd, pContext->id, cs.cx, cs.cy));
3034
3035 AssertReturn(pContext->pDevice, VERR_INTERNAL_ERROR);
3036 hr = pContext->pDevice->GetViewport(&viewportOrg);
3037 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dChangeMode: GetViewport failed with %x\n", hr), VERR_INTERNAL_ERROR);
3038
3039 Log(("vmsvga3dChangeMode: old viewport settings (%d,%d)(%d,%d) z=%d/%d\n", viewportOrg.X, viewportOrg.Y, viewportOrg.Width, viewportOrg.Height, (uint32_t)(viewportOrg.MinZ * 100.0), (uint32_t)(viewportOrg.MaxZ * 100.0)));
3040
3041 /* Resize the window. */
3042 int rc = vmsvga3dSendThreadMessage(pState->pWindowThread, pState->WndRequestSem, WM_VMSVGA3D_RESIZEWINDOW, (WPARAM)pContext->hwnd, (LPARAM)&cs);
3043 AssertRC(rc);
3044
3045 /* Changed when the function returns. */
3046 PresParam.BackBufferWidth = 0;
3047 PresParam.BackBufferHeight = 0;
3048 PresParam.BackBufferFormat = D3DFMT_UNKNOWN;
3049 PresParam.BackBufferCount = 0;
3050
3051 PresParam.MultiSampleType = D3DMULTISAMPLE_NONE;
3052 PresParam.MultiSampleQuality = 0;
3053 PresParam.SwapEffect = D3DSWAPEFFECT_FLIP;
3054 PresParam.hDeviceWindow = pContext->hwnd;
3055 PresParam.Windowed = TRUE; /** @todo */
3056 PresParam.EnableAutoDepthStencil = FALSE;
3057 PresParam.AutoDepthStencilFormat = D3DFMT_UNKNOWN; /* not relevant */
3058 PresParam.Flags = 0;
3059 PresParam.FullScreen_RefreshRateInHz = 0; /* windowed -> 0 */
3060 /** @todo consider using D3DPRESENT_DONOTWAIT so we don't wait for the GPU during Present calls. */
3061 PresParam.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;;
3062
3063#ifdef VBOX_VMSVGA3D_WITH_WINE_OPENGL
3064 hr = pContext->pDevice->Reset(&PresParam);
3065 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dChangeMode: Reset failed with %x\n", hr), VERR_INTERNAL_ERROR);
3066#else
3067 /* ResetEx does not trash the device state */
3068 hr = pContext->pDevice->ResetEx(&PresParam, NULL);
3069 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dChangeMode: Reset failed with %x\n", hr), VERR_INTERNAL_ERROR);
3070#endif
3071 Log(("vmsvga3dChangeMode: Backbuffer (%d,%d) count=%d format=%x\n", PresParam.BackBufferWidth, PresParam.BackBufferHeight, PresParam.BackBufferCount, PresParam.BackBufferFormat));
3072
3073 /* ResetEx changes the viewport; restore it again. */
3074 hr = pContext->pDevice->SetViewport(&viewportOrg);
3075 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dChangeMode: SetViewport failed with %x\n", hr), VERR_INTERNAL_ERROR);
3076
3077#ifdef LOG_ENABLED
3078 {
3079 D3DVIEWPORT9 viewport;
3080 hr = pContext->pDevice->GetViewport(&viewport);
3081 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dChangeMode: GetViewport failed with %x\n", hr), VERR_INTERNAL_ERROR);
3082
3083 Log(("vmsvga3dChangeMode: changed viewport settings (%d,%d)(%d,%d) z=%d/%d\n", viewport.X, viewport.Y, viewport.Width, viewport.Height, (uint32_t)(viewport.MinZ * 100.0), (uint32_t)(viewport.MaxZ * 100.0)));
3084 }
3085#endif
3086
3087 /* First set the render targets as they change the internal state (reset viewport etc) */
3088 Log(("vmsvga3dChangeMode: Recreate render targets BEGIN\n"));
3089 for (uint32_t j = 0; j < RT_ELEMENTS(pContext->state.aRenderTargets); j++)
3090 {
3091 if (pContext->state.aRenderTargets[j] != SVGA3D_INVALID_ID)
3092 {
3093 SVGA3dSurfaceImageId target;
3094
3095 target.sid = pContext->state.aRenderTargets[j];
3096 target.face = 0;
3097 target.mipmap = 0;
3098 rc = vmsvga3dSetRenderTarget(pThis, cid, (SVGA3dRenderTargetType)j, target);
3099 AssertRCReturn(rc, rc);
3100 }
3101 }
3102
3103#ifdef VMSVGA3D_DIRECT3D9_RESET
3104 /* Recreate the render state */
3105 Log(("vmsvga3dChangeMode: Recreate render state BEGIN\n"));
3106 for (uint32_t i = 0; i < RT_ELEMENTS(pContext->state.aRenderState); i++)
3107 {
3108 SVGA3dRenderState *pRenderState = &pContext->state.aRenderState[i];
3109
3110 if (pRenderState->state != SVGA3D_RS_INVALID)
3111 vmsvga3dSetRenderState(pThis, pContext->id, 1, pRenderState);
3112 }
3113 Log(("vmsvga3dChangeMode: Recreate render state END\n"));
3114
3115 /* Recreate the texture state */
3116 Log(("vmsvga3dChangeMode: Recreate texture state BEGIN\n"));
3117 for (uint32_t iStage = 0; iStage < SVGA3D_MAX_TEXTURE_STAGE; iStage++)
3118 {
3119 for (uint32_t j = 0; j < SVGA3D_TS_MAX; j++)
3120 {
3121 SVGA3dTextureState *pTextureState = &pContext->state.aTextureState[iStage][j];
3122
3123 if (pTextureState->name != SVGA3D_RS_INVALID)
3124 vmsvga3dSetTextureState(pThis, pContext->id, 1, pTextureState);
3125 }
3126 }
3127 Log(("vmsvga3dChangeMode: Recreate texture state END\n"));
3128
3129 if (pContext->state.u32UpdateFlags & VMSVGA3D_UPDATE_SCISSORRECT)
3130 vmsvga3dSetScissorRect(pThis, cid, &pContext->state.RectScissor);
3131 if (pContext->state.u32UpdateFlags & VMSVGA3D_UPDATE_ZRANGE)
3132 vmsvga3dSetZRange(pThis, cid, pContext->state.zRange);
3133 if (pContext->state.u32UpdateFlags & VMSVGA3D_UPDATE_VIEWPORT)
3134 vmsvga3dSetViewPort(pThis, cid, &pContext->state.RectViewPort);
3135 if (pContext->state.u32UpdateFlags & VMSVGA3D_UPDATE_VERTEXSHADER)
3136 vmsvga3dShaderSet(pThis, pContext, cid, SVGA3D_SHADERTYPE_VS, pContext->state.shidVertex);
3137 if (pContext->state.u32UpdateFlags & VMSVGA3D_UPDATE_PIXELSHADER)
3138 vmsvga3dShaderSet(pThis, pContext, cid, SVGA3D_SHADERTYPE_PS, pContext->state.shidPixel);
3139 /** @todo restore more state data */
3140#endif /* #ifdef VMSVGA3D_DIRECT3D9_RESET */
3141 }
3142 }
3143 return VINF_SUCCESS;
3144}
3145
3146
3147int vmsvga3dSetTransform(PVGASTATE pThis, uint32_t cid, SVGA3dTransformType type, float matrix[16])
3148{
3149 D3DTRANSFORMSTATETYPE d3dState;
3150 HRESULT hr;
3151 PVMSVGA3DCONTEXT pContext;
3152 PVMSVGA3DSTATE pState = pThis->svga.p3dState;
3153 AssertReturn(pState, VERR_NO_MEMORY);
3154
3155 Log(("vmsvga3dSetTransform %x %s\n", cid, vmsvgaTransformToString(type)));
3156
3157 if ( cid >= pState->cContexts
3158 || pState->papContexts[cid]->id != cid)
3159 {
3160 Log(("vmsvga3dSetTransform invalid context id!\n"));
3161 return VERR_INVALID_PARAMETER;
3162 }
3163 pContext = pState->papContexts[cid];
3164
3165 switch (type)
3166 {
3167 case SVGA3D_TRANSFORM_VIEW:
3168 d3dState = D3DTS_VIEW;
3169 break;
3170 case SVGA3D_TRANSFORM_PROJECTION:
3171 d3dState = D3DTS_PROJECTION;
3172 break;
3173 case SVGA3D_TRANSFORM_TEXTURE0:
3174 d3dState = D3DTS_TEXTURE0;
3175 break;
3176 case SVGA3D_TRANSFORM_TEXTURE1:
3177 d3dState = D3DTS_TEXTURE1;
3178 break;
3179 case SVGA3D_TRANSFORM_TEXTURE2:
3180 d3dState = D3DTS_TEXTURE2;
3181 break;
3182 case SVGA3D_TRANSFORM_TEXTURE3:
3183 d3dState = D3DTS_TEXTURE3;
3184 break;
3185 case SVGA3D_TRANSFORM_TEXTURE4:
3186 d3dState = D3DTS_TEXTURE4;
3187 break;
3188 case SVGA3D_TRANSFORM_TEXTURE5:
3189 d3dState = D3DTS_TEXTURE5;
3190 break;
3191 case SVGA3D_TRANSFORM_TEXTURE6:
3192 d3dState = D3DTS_TEXTURE6;
3193 break;
3194 case SVGA3D_TRANSFORM_TEXTURE7:
3195 d3dState = D3DTS_TEXTURE7;
3196 break;
3197 case SVGA3D_TRANSFORM_WORLD:
3198 d3dState = D3DTS_WORLD;
3199 break;
3200 case SVGA3D_TRANSFORM_WORLD1:
3201 d3dState = D3DTS_WORLD1;
3202 break;
3203 case SVGA3D_TRANSFORM_WORLD2:
3204 d3dState = D3DTS_WORLD2;
3205 break;
3206 case SVGA3D_TRANSFORM_WORLD3:
3207 d3dState = D3DTS_WORLD3;
3208 break;
3209
3210 default:
3211 Log(("vmsvga3dSetTransform: unknown type!!\n"));
3212 return VERR_INVALID_PARAMETER;
3213 }
3214
3215 /* Save this matrix for vm state save/restore. */
3216 pContext->state.aTransformState[type].fValid = true;
3217 memcpy(pContext->state.aTransformState[type].matrix, matrix, sizeof(pContext->state.aTransformState[type].matrix));
3218 pContext->state.u32UpdateFlags |= VMSVGA3D_UPDATE_TRANSFORM;
3219
3220 Log(("Matrix [%d %d %d %d]\n", (int)(matrix[0] * 10.0), (int)(matrix[1] * 10.0), (int)(matrix[2] * 10.0), (int)(matrix[3] * 10.0)));
3221 Log((" [%d %d %d %d]\n", (int)(matrix[4] * 10.0), (int)(matrix[5] * 10.0), (int)(matrix[6] * 10.0), (int)(matrix[7] * 10.0)));
3222 Log((" [%d %d %d %d]\n", (int)(matrix[8] * 10.0), (int)(matrix[9] * 10.0), (int)(matrix[10] * 10.0), (int)(matrix[11] * 10.0)));
3223 Log((" [%d %d %d %d]\n", (int)(matrix[12] * 10.0), (int)(matrix[13] * 10.0), (int)(matrix[14] * 10.0), (int)(matrix[15] * 10.0)));
3224 hr = pContext->pDevice->SetTransform(d3dState, (const D3DMATRIX *)matrix);
3225 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSetTransform: SetTransform failed with %x\n", hr), VERR_INTERNAL_ERROR);
3226 return VINF_SUCCESS;
3227}
3228
3229int vmsvga3dSetZRange(PVGASTATE pThis, uint32_t cid, SVGA3dZRange zRange)
3230{
3231 D3DVIEWPORT9 viewport;
3232 HRESULT hr;
3233 PVMSVGA3DCONTEXT pContext;
3234 PVMSVGA3DSTATE pState = pThis->svga.p3dState;
3235 AssertReturn(pState, VERR_NO_MEMORY);
3236
3237 Log(("vmsvga3dSetZRange %x min=%d max=%d\n", cid, (uint32_t)(zRange.min * 100.0), (uint32_t)(zRange.max * 100.0)));
3238
3239 if ( cid >= pState->cContexts
3240 || pState->papContexts[cid]->id != cid)
3241 {
3242 Log(("vmsvga3dSetZRange invalid context id!\n"));
3243 return VERR_INVALID_PARAMETER;
3244 }
3245 pContext = pState->papContexts[cid];
3246 pContext->state.zRange = zRange;
3247 pContext->state.u32UpdateFlags |= VMSVGA3D_UPDATE_ZRANGE;
3248
3249 hr = pContext->pDevice->GetViewport(&viewport);
3250 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSetZRange: GetViewport failed with %x\n", hr), VERR_INTERNAL_ERROR);
3251
3252 Log(("vmsvga3dSetZRange: old viewport settings (%d,%d)(%d,%d) z=%d/%d\n", viewport.X, viewport.Y, viewport.Width, viewport.Height, (uint32_t)(viewport.MinZ * 100.0), (uint32_t)(viewport.MaxZ * 100.0)));
3253 /** @todo convert the depth range from -1-1 to 0-1 although we shouldn't be getting such values in the first place... */
3254 if (zRange.min < 0.0)
3255 zRange.min = 0.0;
3256 if (zRange.max > 1.0)
3257 zRange.max = 1.0;
3258
3259 viewport.MinZ = zRange.min;
3260 viewport.MaxZ = zRange.max;
3261 hr = pContext->pDevice->SetViewport(&viewport);
3262 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSetZRange: SetViewport failed with %x\n", hr), VERR_INTERNAL_ERROR);
3263 return VINF_SUCCESS;
3264}
3265
3266/**
3267 * Convert SVGA blend op value to its D3D equivalent
3268 */
3269static DWORD vmsvga3dBlendOp2D3D(uint32_t blendOp, DWORD defaultBlendOp)
3270{
3271 switch (blendOp)
3272 {
3273 case SVGA3D_BLENDOP_ZERO:
3274 return D3DBLEND_ZERO;
3275 case SVGA3D_BLENDOP_ONE:
3276 return D3DBLEND_ONE;
3277 case SVGA3D_BLENDOP_SRCCOLOR:
3278 return D3DBLEND_SRCCOLOR;
3279 case SVGA3D_BLENDOP_INVSRCCOLOR:
3280 return D3DBLEND_INVSRCCOLOR;
3281 case SVGA3D_BLENDOP_SRCALPHA:
3282 return D3DBLEND_SRCALPHA;
3283 case SVGA3D_BLENDOP_INVSRCALPHA:
3284 return D3DBLEND_INVSRCALPHA;
3285 case SVGA3D_BLENDOP_DESTALPHA:
3286 return D3DBLEND_DESTALPHA;
3287 case SVGA3D_BLENDOP_INVDESTALPHA:
3288 return D3DBLEND_INVDESTALPHA;
3289 case SVGA3D_BLENDOP_DESTCOLOR:
3290 return D3DBLEND_DESTCOLOR;
3291 case SVGA3D_BLENDOP_INVDESTCOLOR:
3292 return D3DBLEND_INVDESTCOLOR;
3293 case SVGA3D_BLENDOP_SRCALPHASAT:
3294 return D3DBLEND_SRCALPHASAT;
3295 case SVGA3D_BLENDOP_BLENDFACTOR:
3296 return D3DBLEND_BLENDFACTOR;
3297 case SVGA3D_BLENDOP_INVBLENDFACTOR:
3298 return D3DBLEND_INVBLENDFACTOR;
3299 default:
3300 AssertFailed();
3301 return defaultBlendOp;
3302 }
3303}
3304
3305int vmsvga3dSetRenderState(PVGASTATE pThis, uint32_t cid, uint32_t cRenderStates, SVGA3dRenderState *pRenderState)
3306{
3307 DWORD val = 0; /* Shut up MSC */
3308 HRESULT hr;
3309 PVMSVGA3DCONTEXT pContext;
3310 PVMSVGA3DSTATE pState = pThis->svga.p3dState;
3311 AssertReturn(pState, VERR_NO_MEMORY);
3312
3313 Log(("vmsvga3dSetRenderState cid=%x cRenderStates=%d\n", cid, cRenderStates));
3314
3315 if ( cid >= pState->cContexts
3316 || pState->papContexts[cid]->id != cid)
3317 {
3318 Log(("vmsvga3dSetRenderState invalid context id!\n"));
3319 return VERR_INVALID_PARAMETER;
3320 }
3321 pContext = pState->papContexts[cid];
3322
3323 for (unsigned i = 0; i < cRenderStates; i++)
3324 {
3325 D3DRENDERSTATETYPE renderState = D3DRS_FORCE_DWORD;
3326
3327 Log(("vmsvga3dSetRenderState: state=%s (%d) val=%x\n", vmsvga3dGetRenderStateName(pRenderState[i].state), pRenderState[i].state, pRenderState[i].uintValue));
3328 /* Save the render state for vm state saving. */
3329 if (pRenderState[i].state < SVGA3D_RS_MAX)
3330 pContext->state.aRenderState[pRenderState[i].state] = pRenderState[i];
3331
3332 switch (pRenderState[i].state)
3333 {
3334 case SVGA3D_RS_ZENABLE: /* SVGA3dBool */
3335 renderState = D3DRS_ZENABLE;
3336 val = pRenderState[i].uintValue;
3337 Assert(val == D3DZB_FALSE || val == D3DZB_TRUE);
3338 break;
3339
3340 case SVGA3D_RS_ZWRITEENABLE: /* SVGA3dBool */
3341 renderState = D3DRS_ZWRITEENABLE;
3342 val = pRenderState[i].uintValue;
3343 break;
3344
3345 case SVGA3D_RS_ALPHATESTENABLE: /* SVGA3dBool */
3346 renderState = D3DRS_ALPHATESTENABLE;
3347 val = pRenderState[i].uintValue;
3348 break;
3349
3350 case SVGA3D_RS_DITHERENABLE: /* SVGA3dBool */
3351 renderState = D3DRS_DITHERENABLE;
3352 val = pRenderState[i].uintValue;
3353 break;
3354
3355 case SVGA3D_RS_BLENDENABLE: /* SVGA3dBool */
3356 renderState = D3DRS_ALPHABLENDENABLE;
3357 val = pRenderState[i].uintValue;
3358 break;
3359
3360 case SVGA3D_RS_FOGENABLE: /* SVGA3dBool */
3361 renderState = D3DRS_FOGENABLE;
3362 val = pRenderState[i].uintValue;
3363 break;
3364
3365 case SVGA3D_RS_SPECULARENABLE: /* SVGA3dBool */
3366 renderState = D3DRS_SPECULARENABLE;
3367 val = pRenderState[i].uintValue;
3368 break;
3369
3370 case SVGA3D_RS_LIGHTINGENABLE: /* SVGA3dBool */
3371 renderState = D3DRS_LIGHTING;
3372 val = pRenderState[i].uintValue;
3373 break;
3374
3375 case SVGA3D_RS_NORMALIZENORMALS: /* SVGA3dBool */
3376 renderState = D3DRS_NORMALIZENORMALS;
3377 val = pRenderState[i].uintValue;
3378 break;
3379
3380 case SVGA3D_RS_POINTSPRITEENABLE: /* SVGA3dBool */
3381 renderState = D3DRS_POINTSPRITEENABLE;
3382 val = pRenderState[i].uintValue;
3383 break;
3384
3385 case SVGA3D_RS_POINTSCALEENABLE: /* SVGA3dBool */
3386 renderState = D3DRS_POINTSCALEENABLE;
3387 val = pRenderState[i].uintValue;
3388 break;
3389
3390 case SVGA3D_RS_POINTSIZE: /* float */
3391 renderState = D3DRS_POINTSIZE;
3392 val = pRenderState[i].uintValue;
3393 Log(("SVGA3D_RS_POINTSIZE: %d\n", (uint32_t) (pRenderState[i].floatValue * 100.0)));
3394 break;
3395
3396 case SVGA3D_RS_POINTSIZEMIN: /* float */
3397 renderState = D3DRS_POINTSIZE_MIN;
3398 val = pRenderState[i].uintValue;
3399 Log(("SVGA3D_RS_POINTSIZEMIN: %d\n", (uint32_t) (pRenderState[i].floatValue * 100.0)));
3400 break;
3401
3402 case SVGA3D_RS_POINTSIZEMAX: /* float */
3403 renderState = D3DRS_POINTSIZE_MAX;
3404 val = pRenderState[i].uintValue;
3405 Log(("SVGA3D_RS_POINTSIZEMAX: %d\n", (uint32_t) (pRenderState[i].floatValue * 100.0)));
3406 break;
3407
3408 case SVGA3D_RS_POINTSCALE_A: /* float */
3409 renderState = D3DRS_POINTSCALE_A;
3410 val = pRenderState[i].uintValue;
3411 break;
3412
3413 case SVGA3D_RS_POINTSCALE_B: /* float */
3414 renderState = D3DRS_POINTSCALE_B;
3415 val = pRenderState[i].uintValue;
3416 break;
3417
3418 case SVGA3D_RS_POINTSCALE_C: /* float */
3419 renderState = D3DRS_POINTSCALE_C;
3420 val = pRenderState[i].uintValue;
3421 break;
3422
3423 case SVGA3D_RS_AMBIENT: /* SVGA3dColor - identical */
3424 renderState = D3DRS_AMBIENT;
3425 val = pRenderState[i].uintValue;
3426 break;
3427
3428 case SVGA3D_RS_CLIPPLANEENABLE: /* SVGA3dClipPlanes - identical */
3429 renderState = D3DRS_CLIPPLANEENABLE;
3430 val = pRenderState[i].uintValue;
3431 break;
3432
3433 case SVGA3D_RS_FOGCOLOR: /* SVGA3dColor - identical */
3434 renderState = D3DRS_FOGCOLOR;
3435 val = pRenderState[i].uintValue;
3436 break;
3437
3438 case SVGA3D_RS_FOGSTART: /* float */
3439 renderState = D3DRS_FOGSTART;
3440 val = pRenderState[i].uintValue;
3441 break;
3442
3443 case SVGA3D_RS_FOGEND: /* float */
3444 renderState = D3DRS_FOGEND;
3445 val = pRenderState[i].uintValue;
3446 break;
3447
3448 case SVGA3D_RS_FOGDENSITY: /* float */
3449 renderState = D3DRS_FOGDENSITY;
3450 val = pRenderState[i].uintValue;
3451 break;
3452
3453 case SVGA3D_RS_RANGEFOGENABLE: /* SVGA3dBool */
3454 renderState = D3DRS_RANGEFOGENABLE;
3455 val = pRenderState[i].uintValue;
3456 break;
3457
3458 case SVGA3D_RS_FOGMODE: /* SVGA3dFogMode */
3459 {
3460 SVGA3dFogMode mode;
3461 mode.uintValue = pRenderState[i].uintValue;
3462
3463 switch (mode.s.function)
3464 {
3465 case SVGA3D_FOGFUNC_INVALID:
3466 val = D3DFOG_NONE;
3467 break;
3468 case SVGA3D_FOGFUNC_EXP:
3469 val = D3DFOG_EXP;
3470 break;
3471 case SVGA3D_FOGFUNC_EXP2:
3472 val = D3DFOG_EXP2;
3473 break;
3474 case SVGA3D_FOGFUNC_LINEAR:
3475 val = D3DFOG_LINEAR;
3476 break;
3477 case SVGA3D_FOGFUNC_PER_VERTEX: /* unable to find a d3d9 equivalent */
3478 AssertMsgFailedReturn(("Unsupported fog function SVGA3D_FOGFUNC_PER_VERTEX\n"), VERR_INTERNAL_ERROR);
3479 break;
3480 default:
3481 AssertMsgFailedReturn(("Unexpected fog function %d\n", mode.s.function), VERR_INTERNAL_ERROR);
3482 break;
3483 }
3484
3485 /* The fog type determines the render state. */
3486 switch (mode.s.type)
3487 {
3488 case SVGA3D_FOGTYPE_VERTEX:
3489 renderState = D3DRS_FOGVERTEXMODE;
3490 break;
3491 case SVGA3D_FOGTYPE_PIXEL:
3492 renderState = D3DRS_FOGTABLEMODE;
3493 break;
3494 default:
3495 AssertMsgFailedReturn(("Unexpected fog type %d\n", mode.s.type), VERR_INTERNAL_ERROR);
3496 break;
3497 }
3498
3499 /* Set the fog base to depth or range. */
3500 switch (mode.s.base)
3501 {
3502 case SVGA3D_FOGBASE_DEPTHBASED:
3503 hr = pContext->pDevice->SetRenderState(D3DRS_RANGEFOGENABLE, FALSE);
3504 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSetRenderState: SetRenderState SVGA3D_FOGBASE_DEPTHBASED failed with %x\n", hr), VERR_INTERNAL_ERROR);
3505 break;
3506 case SVGA3D_FOGBASE_RANGEBASED:
3507 hr = pContext->pDevice->SetRenderState(D3DRS_RANGEFOGENABLE, TRUE);
3508 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSetRenderState: SetRenderState SVGA3D_FOGBASE_RANGEBASED failed with %x\n", hr), VERR_INTERNAL_ERROR);
3509 break;
3510 default:
3511 /* ignore */
3512 AssertMsgFailed(("Unexpected fog base %d\n", mode.s.base));
3513 break;
3514 }
3515 break;
3516 }
3517
3518 case SVGA3D_RS_FILLMODE: /* SVGA3dFillMode */
3519 {
3520 SVGA3dFillMode mode;
3521
3522 mode.uintValue = pRenderState[i].uintValue;
3523
3524 switch (mode.s.mode)
3525 {
3526 case SVGA3D_FILLMODE_POINT:
3527 val = D3DFILL_POINT;
3528 break;
3529 case SVGA3D_FILLMODE_LINE:
3530 val = D3DFILL_WIREFRAME;
3531 break;
3532 case SVGA3D_FILLMODE_FILL:
3533 val = D3DFILL_SOLID;
3534 break;
3535 default:
3536 AssertMsgFailedReturn(("Unexpected fill mode %d\n", mode.s.mode), VERR_INTERNAL_ERROR);
3537 break;
3538 }
3539 /** @todo ignoring face for now. */
3540 renderState = D3DRS_FILLMODE;
3541 break;
3542 }
3543
3544 case SVGA3D_RS_SHADEMODE: /* SVGA3dShadeMode */
3545 renderState = D3DRS_SHADEMODE;
3546 AssertCompile(D3DSHADE_FLAT == SVGA3D_SHADEMODE_FLAT);
3547 val = pRenderState[i].uintValue; /* SVGA3dShadeMode == D3DSHADEMODE */
3548 break;
3549
3550 case SVGA3D_RS_LINEPATTERN: /* SVGA3dLinePattern */
3551 /* No longer supported by d3d; mesagl comments suggest not all backends support it */
3552 /** @todo */
3553 Log(("WARNING: SVGA3D_RS_LINEPATTERN %x not supported!!\n", pRenderState[i].uintValue));
3554 /*
3555 renderState = D3DRS_LINEPATTERN;
3556 val = pRenderState[i].uintValue;
3557 */
3558 break;
3559
3560 case SVGA3D_RS_SRCBLEND: /* SVGA3dBlendOp */
3561 renderState = D3DRS_SRCBLEND;
3562 val = vmsvga3dBlendOp2D3D(pRenderState[i].uintValue, D3DBLEND_ONE /* default */);
3563 break;
3564
3565 case SVGA3D_RS_DSTBLEND: /* SVGA3dBlendOp */
3566 renderState = D3DRS_DESTBLEND;
3567 val = vmsvga3dBlendOp2D3D(pRenderState[i].uintValue, D3DBLEND_ZERO /* default */);
3568 break;
3569
3570 case SVGA3D_RS_BLENDEQUATION: /* SVGA3dBlendEquation - identical */
3571 AssertCompile(SVGA3D_BLENDEQ_MAXIMUM == D3DBLENDOP_MAX);
3572 renderState = D3DRS_BLENDOP;
3573 val = pRenderState[i].uintValue;
3574 break;
3575
3576 case SVGA3D_RS_CULLMODE: /* SVGA3dFace */
3577 {
3578 switch (pRenderState[i].uintValue)
3579 {
3580 case SVGA3D_FACE_NONE:
3581 val = D3DCULL_NONE;
3582 break;
3583 case SVGA3D_FACE_FRONT:
3584 val = D3DCULL_CW;
3585 break;
3586 case SVGA3D_FACE_BACK:
3587 val = D3DCULL_CCW;
3588 break;
3589 case SVGA3D_FACE_FRONT_BACK:
3590 AssertFailed();
3591 val = D3DCULL_CW;
3592 break;
3593 default:
3594 AssertMsgFailedReturn(("Unexpected cull mode %d\n", pRenderState[i].uintValue), VERR_INTERNAL_ERROR);
3595 break;
3596 }
3597 renderState = D3DRS_CULLMODE;
3598 break;
3599 }
3600
3601 case SVGA3D_RS_ZFUNC: /* SVGA3dCmpFunc - identical */
3602 AssertCompile(SVGA3D_CMP_ALWAYS == D3DCMP_ALWAYS);
3603 renderState = D3DRS_ZFUNC;
3604 val = pRenderState[i].uintValue;
3605 break;
3606
3607 case SVGA3D_RS_ALPHAFUNC: /* SVGA3dCmpFunc - identical */
3608 renderState = D3DRS_ALPHAFUNC;
3609 val = pRenderState[i].uintValue;
3610 break;
3611
3612 case SVGA3D_RS_STENCILENABLE: /* SVGA3dBool */
3613 renderState = D3DRS_STENCILENABLE;
3614 val = pRenderState[i].uintValue;
3615 break;
3616
3617 case SVGA3D_RS_STENCILREF: /* uint32_t */
3618 renderState = D3DRS_STENCILREF;
3619 val = pRenderState[i].uintValue;
3620 break;
3621
3622 case SVGA3D_RS_STENCILMASK: /* uint32_t */
3623 renderState = D3DRS_STENCILMASK;
3624 val = pRenderState[i].uintValue;
3625 break;
3626
3627 case SVGA3D_RS_STENCILWRITEMASK: /* uint32_t */
3628 renderState = D3DRS_STENCILWRITEMASK;
3629 val = pRenderState[i].uintValue;
3630 break;
3631
3632 case SVGA3D_RS_STENCILFUNC: /* SVGA3dCmpFunc - identical */
3633 renderState = D3DRS_STENCILFUNC;
3634 val = pRenderState[i].uintValue;
3635 break;
3636
3637 case SVGA3D_RS_STENCILFAIL: /* SVGA3dStencilOp - identical */
3638 AssertCompile(D3DSTENCILOP_KEEP == SVGA3D_STENCILOP_KEEP);
3639 AssertCompile(D3DSTENCILOP_DECR == SVGA3D_STENCILOP_DECR);
3640 renderState = D3DRS_STENCILFAIL;
3641 val = pRenderState[i].uintValue;
3642 break;
3643
3644 case SVGA3D_RS_STENCILZFAIL: /* SVGA3dStencilOp - identical */
3645 renderState = D3DRS_STENCILZFAIL;
3646 val = pRenderState[i].uintValue;
3647 break;
3648
3649 case SVGA3D_RS_STENCILPASS: /* SVGA3dStencilOp - identical */
3650 renderState = D3DRS_STENCILPASS;
3651 val = pRenderState[i].uintValue;
3652 break;
3653
3654 case SVGA3D_RS_ALPHAREF: /* float (0.0 .. 1.0) */
3655 renderState = D3DRS_ALPHAREF;
3656 val = pRenderState[i].uintValue;
3657 break;
3658
3659 case SVGA3D_RS_FRONTWINDING: /* SVGA3dFrontWinding */
3660 Assert(pRenderState[i].uintValue == SVGA3D_FRONTWINDING_CW);
3661 /*
3662 renderState = D3DRS_FRONTWINDING; //D3DRS_TWOSIDEDSTENCILMODE
3663 val = pRenderState[i].uintValue;
3664 */
3665 break;
3666
3667 case SVGA3D_RS_COORDINATETYPE: /* SVGA3dCoordinateType */
3668 Assert(pRenderState[i].uintValue == SVGA3D_COORDINATE_LEFTHANDED);
3669 /** @todo setup a view matrix to scale the world space by -1 in the z-direction for right handed coordinates. */
3670 /*
3671 renderState = D3DRS_COORDINATETYPE;
3672 val = pRenderState[i].uintValue;
3673 */
3674 break;
3675
3676 case SVGA3D_RS_ZBIAS: /* float */
3677 /** @todo unknown meaning; depth bias is not identical
3678 renderState = D3DRS_DEPTHBIAS;
3679 val = pRenderState[i].uintValue;
3680 */
3681 Log(("vmsvga3dSetRenderState: WARNING unsupported SVGA3D_RS_ZBIAS\n"));
3682 break;
3683
3684 case SVGA3D_RS_SLOPESCALEDEPTHBIAS: /* float */
3685 renderState = D3DRS_SLOPESCALEDEPTHBIAS;
3686 val = pRenderState[i].uintValue;
3687 break;
3688
3689 case SVGA3D_RS_DEPTHBIAS: /* float */
3690 renderState = D3DRS_DEPTHBIAS;
3691 val = pRenderState[i].uintValue;
3692 break;
3693
3694 case SVGA3D_RS_COLORWRITEENABLE: /* SVGA3dColorMask - identical to D3DCOLORWRITEENABLE_* */
3695 renderState = D3DRS_COLORWRITEENABLE;
3696 val = pRenderState[i].uintValue;
3697 break;
3698
3699 case SVGA3D_RS_VERTEXMATERIALENABLE: /* SVGA3dBool */
3700 //AssertFailed();
3701 renderState = D3DRS_INDEXEDVERTEXBLENDENABLE; /* correct?? */
3702 val = pRenderState[i].uintValue;
3703 break;
3704
3705 case SVGA3D_RS_DIFFUSEMATERIALSOURCE: /* SVGA3dVertexMaterial - identical */
3706 AssertCompile(D3DMCS_COLOR2 == SVGA3D_VERTEXMATERIAL_SPECULAR);
3707 renderState = D3DRS_DIFFUSEMATERIALSOURCE;
3708 val = pRenderState[i].uintValue;
3709 break;
3710
3711 case SVGA3D_RS_SPECULARMATERIALSOURCE: /* SVGA3dVertexMaterial - identical */
3712 renderState = D3DRS_SPECULARMATERIALSOURCE;
3713 val = pRenderState[i].uintValue;
3714 break;
3715
3716 case SVGA3D_RS_AMBIENTMATERIALSOURCE: /* SVGA3dVertexMaterial - identical */
3717 renderState = D3DRS_AMBIENTMATERIALSOURCE;
3718 val = pRenderState[i].uintValue;
3719 break;
3720
3721 case SVGA3D_RS_EMISSIVEMATERIALSOURCE: /* SVGA3dVertexMaterial - identical */
3722 renderState = D3DRS_EMISSIVEMATERIALSOURCE;
3723 val = pRenderState[i].uintValue;
3724 break;
3725
3726 case SVGA3D_RS_TEXTUREFACTOR: /* SVGA3dColor - identical */
3727 renderState = D3DRS_TEXTUREFACTOR;
3728 val = pRenderState[i].uintValue;
3729 break;
3730
3731 case SVGA3D_RS_LOCALVIEWER: /* SVGA3dBool */
3732 renderState = D3DRS_LOCALVIEWER;
3733 val = pRenderState[i].uintValue;
3734 break;
3735
3736 case SVGA3D_RS_SCISSORTESTENABLE: /* SVGA3dBool */
3737 renderState = D3DRS_SCISSORTESTENABLE;
3738 val = pRenderState[i].uintValue;
3739 break;
3740
3741 case SVGA3D_RS_BLENDCOLOR: /* SVGA3dColor - identical */
3742 renderState = D3DRS_BLENDFACTOR;
3743 val = pRenderState[i].uintValue;
3744 break;
3745
3746 case SVGA3D_RS_STENCILENABLE2SIDED: /* SVGA3dBool */
3747 renderState = D3DRS_TWOSIDEDSTENCILMODE;
3748 val = pRenderState[i].uintValue;
3749 break;
3750
3751 case SVGA3D_RS_CCWSTENCILFUNC: /* SVGA3dCmpFunc - identical */
3752 renderState = D3DRS_CCW_STENCILFUNC;
3753 val = pRenderState[i].uintValue;
3754 break;
3755
3756 case SVGA3D_RS_CCWSTENCILFAIL: /* SVGA3dStencilOp - identical */
3757 renderState = D3DRS_CCW_STENCILFAIL;
3758 val = pRenderState[i].uintValue;
3759 break;
3760
3761 case SVGA3D_RS_CCWSTENCILZFAIL: /* SVGA3dStencilOp - identical */
3762 renderState = D3DRS_CCW_STENCILZFAIL;
3763 val = pRenderState[i].uintValue;
3764 break;
3765
3766 case SVGA3D_RS_CCWSTENCILPASS: /* SVGA3dStencilOp - identical */
3767 renderState = D3DRS_CCW_STENCILPASS;
3768 val = pRenderState[i].uintValue;
3769 break;
3770
3771 case SVGA3D_RS_VERTEXBLEND: /* SVGA3dVertexBlendFlags - identical */
3772 AssertCompile(SVGA3D_VBLEND_DISABLE == D3DVBF_DISABLE);
3773 renderState = D3DRS_VERTEXBLEND;
3774 val = pRenderState[i].uintValue;
3775 break;
3776
3777 case SVGA3D_RS_OUTPUTGAMMA: /* float */
3778 //AssertFailed();
3779 /*
3780 D3DRS_SRGBWRITEENABLE ??
3781 renderState = D3DRS_OUTPUTGAMMA;
3782 val = pRenderState[i].uintValue;
3783 */
3784 break;
3785
3786 case SVGA3D_RS_ZVISIBLE: /* SVGA3dBool */
3787 AssertFailed();
3788 /*
3789 renderState = D3DRS_ZVISIBLE;
3790 val = pRenderState[i].uintValue;
3791 */
3792 break;
3793
3794 case SVGA3D_RS_LASTPIXEL: /* SVGA3dBool */
3795 renderState = D3DRS_LASTPIXEL;
3796 val = pRenderState[i].uintValue;
3797 break;
3798
3799 case SVGA3D_RS_CLIPPING: /* SVGA3dBool */
3800 renderState = D3DRS_CLIPPING;
3801 val = pRenderState[i].uintValue;
3802 break;
3803
3804 case SVGA3D_RS_WRAP0: /* SVGA3dWrapFlags - identical */
3805 Assert(SVGA3D_WRAPCOORD_3 == D3DWRAPCOORD_3);
3806 renderState = D3DRS_WRAP0;
3807 val = pRenderState[i].uintValue;
3808 break;
3809
3810 case SVGA3D_RS_WRAP1: /* SVGA3dWrapFlags - identical */
3811 renderState = D3DRS_WRAP1;
3812 val = pRenderState[i].uintValue;
3813 break;
3814
3815 case SVGA3D_RS_WRAP2: /* SVGA3dWrapFlags - identical */
3816 renderState = D3DRS_WRAP2;
3817 val = pRenderState[i].uintValue;
3818 break;
3819
3820 case SVGA3D_RS_WRAP3: /* SVGA3dWrapFlags - identical */
3821 renderState = D3DRS_WRAP3;
3822 val = pRenderState[i].uintValue;
3823 break;
3824
3825 case SVGA3D_RS_WRAP4: /* SVGA3dWrapFlags - identical */
3826 renderState = D3DRS_WRAP4;
3827 val = pRenderState[i].uintValue;
3828 break;
3829
3830 case SVGA3D_RS_WRAP5: /* SVGA3dWrapFlags - identical */
3831 renderState = D3DRS_WRAP5;
3832 val = pRenderState[i].uintValue;
3833 break;
3834
3835 case SVGA3D_RS_WRAP6: /* SVGA3dWrapFlags - identical */
3836 renderState = D3DRS_WRAP6;
3837 val = pRenderState[i].uintValue;
3838 break;
3839
3840 case SVGA3D_RS_WRAP7: /* SVGA3dWrapFlags - identical */
3841 renderState = D3DRS_WRAP7;
3842 val = pRenderState[i].uintValue;
3843 break;
3844
3845 case SVGA3D_RS_WRAP8: /* SVGA3dWrapFlags - identical */
3846 renderState = D3DRS_WRAP8;
3847 val = pRenderState[i].uintValue;
3848 break;
3849
3850 case SVGA3D_RS_WRAP9: /* SVGA3dWrapFlags - identical */
3851 renderState = D3DRS_WRAP9;
3852 val = pRenderState[i].uintValue;
3853 break;
3854
3855 case SVGA3D_RS_WRAP10: /* SVGA3dWrapFlags - identical */
3856 renderState = D3DRS_WRAP10;
3857 val = pRenderState[i].uintValue;
3858 break;
3859
3860 case SVGA3D_RS_WRAP11: /* SVGA3dWrapFlags - identical */
3861 renderState = D3DRS_WRAP11;
3862 val = pRenderState[i].uintValue;
3863 break;
3864
3865 case SVGA3D_RS_WRAP12: /* SVGA3dWrapFlags - identical */
3866 renderState = D3DRS_WRAP12;
3867 val = pRenderState[i].uintValue;
3868 break;
3869
3870 case SVGA3D_RS_WRAP13: /* SVGA3dWrapFlags - identical */
3871 renderState = D3DRS_WRAP13;
3872 val = pRenderState[i].uintValue;
3873 break;
3874
3875 case SVGA3D_RS_WRAP14: /* SVGA3dWrapFlags - identical */
3876 renderState = D3DRS_WRAP14;
3877 val = pRenderState[i].uintValue;
3878 break;
3879
3880 case SVGA3D_RS_WRAP15: /* SVGA3dWrapFlags - identical */
3881 renderState = D3DRS_WRAP15;
3882 val = pRenderState[i].uintValue;
3883 break;
3884
3885 case SVGA3D_RS_MULTISAMPLEANTIALIAS: /* SVGA3dBool */
3886 renderState = D3DRS_MULTISAMPLEANTIALIAS;
3887 val = pRenderState[i].uintValue;
3888 break;
3889
3890 case SVGA3D_RS_MULTISAMPLEMASK: /* uint32_t */
3891 renderState = D3DRS_MULTISAMPLEMASK;
3892 val = pRenderState[i].uintValue;
3893 break;
3894
3895 case SVGA3D_RS_INDEXEDVERTEXBLENDENABLE: /* SVGA3dBool */
3896 renderState = D3DRS_INDEXEDVERTEXBLENDENABLE;
3897 val = pRenderState[i].uintValue;
3898 break;
3899
3900 case SVGA3D_RS_TWEENFACTOR: /* float */
3901 renderState = D3DRS_TWEENFACTOR;
3902 val = pRenderState[i].uintValue;
3903 break;
3904
3905 case SVGA3D_RS_ANTIALIASEDLINEENABLE: /* SVGA3dBool */
3906 renderState = D3DRS_ANTIALIASEDLINEENABLE;
3907 val = pRenderState[i].uintValue;
3908 break;
3909
3910 case SVGA3D_RS_COLORWRITEENABLE1: /* SVGA3dColorMask - identical to D3DCOLORWRITEENABLE_* */
3911 renderState = D3DRS_COLORWRITEENABLE1;
3912 val = pRenderState[i].uintValue;
3913 break;
3914
3915 case SVGA3D_RS_COLORWRITEENABLE2: /* SVGA3dColorMask - identical to D3DCOLORWRITEENABLE_* */
3916 renderState = D3DRS_COLORWRITEENABLE2;
3917 val = pRenderState[i].uintValue;
3918 break;
3919
3920 case SVGA3D_RS_COLORWRITEENABLE3: /* SVGA3dColorMask - identical to D3DCOLORWRITEENABLE_* */
3921 renderState = D3DRS_COLORWRITEENABLE3;
3922 val = pRenderState[i].uintValue;
3923 break;
3924
3925 case SVGA3D_RS_SEPARATEALPHABLENDENABLE: /* SVGA3dBool */
3926 renderState = D3DRS_SEPARATEALPHABLENDENABLE;
3927 val = pRenderState[i].uintValue;
3928 break;
3929
3930 case SVGA3D_RS_SRCBLENDALPHA: /* SVGA3dBlendOp */
3931 renderState = D3DRS_SRCBLENDALPHA;
3932 val = vmsvga3dBlendOp2D3D(pRenderState[i].uintValue, D3DBLEND_ONE /* default */);
3933 break;
3934
3935 case SVGA3D_RS_DSTBLENDALPHA: /* SVGA3dBlendOp */
3936 renderState = D3DRS_DESTBLENDALPHA;
3937 val = vmsvga3dBlendOp2D3D(pRenderState[i].uintValue, D3DBLEND_ZERO /* default */);
3938 break;
3939
3940 case SVGA3D_RS_BLENDEQUATIONALPHA: /* SVGA3dBlendEquation - identical */
3941 renderState = D3DRS_BLENDOPALPHA;
3942 val = pRenderState[i].uintValue;
3943 break;
3944
3945 case SVGA3D_RS_TRANSPARENCYANTIALIAS: /* SVGA3dTransparencyAntialiasType */
3946 AssertFailed();
3947 /*
3948 renderState = D3DRS_TRANSPARENCYANTIALIAS;
3949 val = pRenderState[i].uintValue;
3950 */
3951 break;
3952
3953 case SVGA3D_RS_LINEAA: /* SVGA3dBool */
3954 renderState = D3DRS_ANTIALIASEDLINEENABLE;
3955 val = pRenderState[i].uintValue;
3956 break;
3957
3958 case SVGA3D_RS_LINEWIDTH: /* float */
3959 AssertFailed();
3960 /*
3961 renderState = D3DRS_LINEWIDTH;
3962 val = pRenderState[i].uintValue;
3963 */
3964 break;
3965
3966 case SVGA3D_RS_MAX: /* shut up MSC */
3967 case SVGA3D_RS_INVALID:
3968 AssertFailedBreak();
3969 }
3970
3971 if (renderState != D3DRS_FORCE_DWORD)
3972 {
3973 hr = pContext->pDevice->SetRenderState(renderState, val);
3974 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSetRenderState: SetRenderState failed with %x\n", hr), VERR_INTERNAL_ERROR);
3975 }
3976 }
3977
3978 return VINF_SUCCESS;
3979}
3980
3981int vmsvga3dSetRenderTarget(PVGASTATE pThis, uint32_t cid, SVGA3dRenderTargetType type, SVGA3dSurfaceImageId target)
3982{
3983 HRESULT hr;
3984 PVMSVGA3DCONTEXT pContext;
3985 PVMSVGA3DSTATE pState = pThis->svga.p3dState;
3986 PVMSVGA3DSURFACE pRenderTarget;
3987
3988 AssertReturn(pState, VERR_NO_MEMORY);
3989 AssertReturn(type < SVGA3D_RT_MAX, VERR_INVALID_PARAMETER);
3990 AssertReturn(target.face == 0, VERR_INVALID_PARAMETER);
3991
3992 Log(("vmsvga3dSetRenderTarget cid=%x type=%x sid=%x\n", cid, type, target.sid));
3993
3994 if ( cid >= pState->cContexts
3995 || pState->papContexts[cid]->id != cid)
3996 {
3997 Log(("vmsvga3dSetRenderTarget invalid context id!\n"));
3998 return VERR_INVALID_PARAMETER;
3999 }
4000 pContext = pState->papContexts[cid];
4001
4002 /* Save for vm state save/restore. */
4003 pContext->state.aRenderTargets[type] = target.sid;
4004
4005 if (target.sid == SVGA3D_INVALID_ID)
4006 {
4007 /* Disable render target. */
4008 switch (type)
4009 {
4010 case SVGA3D_RT_DEPTH:
4011 hr = pContext->pDevice->SetDepthStencilSurface(NULL);
4012 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSetRenderTarget: SetDepthStencilSurface failed with %x\n", hr), VERR_INTERNAL_ERROR);
4013 break;
4014
4015 case SVGA3D_RT_STENCIL:
4016 /* ignore; correct?? */
4017 break;
4018
4019 case SVGA3D_RT_COLOR0:
4020 case SVGA3D_RT_COLOR1:
4021 case SVGA3D_RT_COLOR2:
4022 case SVGA3D_RT_COLOR3:
4023 case SVGA3D_RT_COLOR4:
4024 case SVGA3D_RT_COLOR5:
4025 case SVGA3D_RT_COLOR6:
4026 case SVGA3D_RT_COLOR7:
4027 pContext->sidRenderTarget = SVGA3D_INVALID_ID;
4028
4029 if (pState->fSupportedSurfaceNULL)
4030 {
4031 /* Create a dummy render target to satisfy D3D. This path is usually taken only to render into a depth buffer without
4032 * wishing to update an actual color render target
4033 */
4034 IDirect3DSurface9* pDummyRenderTarget;
4035 hr = pContext->pDevice->CreateRenderTarget(pThis->svga.uWidth,
4036 pThis->svga.uHeight,
4037 FOURCC_NULL,
4038 D3DMULTISAMPLE_NONE,
4039 0,
4040 FALSE,
4041 &pDummyRenderTarget,
4042 NULL);
4043
4044 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSetRenderTarget: CreateRenderTarget failed with %x\n", hr), VERR_INTERNAL_ERROR);
4045
4046 hr = pContext->pDevice->SetRenderTarget(type - SVGA3D_RT_COLOR0, pDummyRenderTarget);
4047 D3D_RELEASE(pDummyRenderTarget);
4048 }
4049 else
4050 hr = pContext->pDevice->SetRenderTarget(type - SVGA3D_RT_COLOR0, NULL);
4051
4052 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSetRenderTarget: SetRenderTarget failed with %x\n", hr), VERR_INTERNAL_ERROR);
4053 break;
4054
4055 default:
4056 AssertFailedReturn(VERR_INVALID_PARAMETER);
4057 }
4058 return VINF_SUCCESS;
4059 }
4060
4061 AssertReturn(target.sid < SVGA3D_MAX_SURFACE_IDS, VERR_INVALID_PARAMETER);
4062 AssertReturn(target.sid < pState->cSurfaces && pState->papSurfaces[target.sid]->id == target.sid, VERR_INVALID_PARAMETER);
4063 pRenderTarget = pState->papSurfaces[target.sid];
4064
4065 switch (type)
4066 {
4067 case SVGA3D_RT_DEPTH:
4068 case SVGA3D_RT_STENCIL:
4069 AssertReturn(target.mipmap == 0, VERR_INVALID_PARAMETER);
4070 if (!pRenderTarget->u.pSurface)
4071 {
4072 DWORD cQualityLevels = 0;
4073
4074 /* Query the nr of quality levels for this particular format */
4075 if (pRenderTarget->multiSampleTypeD3D != D3DMULTISAMPLE_NONE)
4076 {
4077 hr = pState->pD3D9->CheckDeviceMultiSampleType(D3DADAPTER_DEFAULT,
4078 D3DDEVTYPE_HAL,
4079 pRenderTarget->formatD3D,
4080 TRUE, /* Windowed */
4081 pRenderTarget->multiSampleTypeD3D,
4082 &cQualityLevels);
4083 Assert(hr == D3D_OK || hr == D3DERR_NOTAVAILABLE);
4084 }
4085
4086 if ( pState->fSupportedSurfaceINTZ
4087 && pRenderTarget->multiSampleTypeD3D == D3DMULTISAMPLE_NONE
4088 && ( pRenderTarget->formatD3D == D3DFMT_D24S8
4089 || pRenderTarget->formatD3D == D3DFMT_D24X8))
4090 {
4091 Log(("vmsvga3dSetRenderTarget: Creating stencil surface as texture!\n"));
4092 int rc = vmsvga3dBackCreateTexture(pState, pContext, cid, pRenderTarget);
4093 AssertRC(rc); /* non-fatal */
4094 }
4095
4096 if (!pRenderTarget->fStencilAsTexture)
4097 {
4098 Log(("vmsvga3dSetRenderTarget DEPTH/STENCIL; cQualityLevels=%d\n", cQualityLevels));
4099 hr = pContext->pDevice->CreateDepthStencilSurface(pRenderTarget->pMipmapLevels[0].mipmapSize.width,
4100 pRenderTarget->pMipmapLevels[0].mipmapSize.height,
4101 pRenderTarget->formatD3D,
4102 pRenderTarget->multiSampleTypeD3D,
4103 ((cQualityLevels >= 1) ? cQualityLevels - 1 : 0), /* 0 - (levels-1) */
4104 FALSE, /* not discardable */
4105 &pRenderTarget->u.pSurface,
4106 NULL);
4107 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSetRenderTarget: CreateDepthStencilSurface failed with %x\n", hr), VERR_INTERNAL_ERROR);
4108 }
4109
4110 pRenderTarget->idAssociatedContext = cid;
4111
4112#if 0 /* doesn't work */
4113 if ( !pRenderTarget->fStencilAsTexture
4114 && pRenderTarget->fDirty)
4115 {
4116 Log(("vmsvga3dSetRenderTarget: sync dirty depth/stencil buffer\n"));
4117 Assert(pRenderTarget->faces[0].numMipLevels == 1);
4118
4119 for (uint32_t i = 0; i < pRenderTarget->faces[0].numMipLevels; i++)
4120 {
4121 if (pRenderTarget->pMipmapLevels[i].fDirty)
4122 {
4123 D3DLOCKED_RECT LockedRect;
4124
4125 hr = pRenderTarget->u.pSurface->LockRect(&LockedRect,
4126 NULL, /* entire surface */
4127 0);
4128
4129 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSetRenderTarget: LockRect failed with %x\n", hr), VERR_INTERNAL_ERROR);
4130
4131 Log(("vmsvga3dSetRenderTarget: sync dirty texture mipmap level %d (pitch %x vs %x)\n", i, LockedRect.Pitch, pRenderTarget->pMipmapLevels[i].cbSurfacePitch));
4132
4133 uint8_t *pDest = (uint8_t *)LockedRect.pBits;
4134 uint8_t *pSrc = (uint8_t *)pRenderTarget->pMipmapLevels[i].pSurfaceData;
4135 for (uint32_t j = 0; j < pRenderTarget->pMipmapLevels[i].size.height; j++)
4136 {
4137 memcpy(pDest, pSrc, pRenderTarget->pMipmapLevels[i].cbSurfacePitch);
4138
4139 pDest += LockedRect.Pitch;
4140 pSrc += pRenderTarget->pMipmapLevels[i].cbSurfacePitch;
4141 }
4142
4143 hr = pRenderTarget->u.pSurface->UnlockRect();
4144 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSetRenderTarget: UnlockRect failed with %x\n", hr), VERR_INTERNAL_ERROR);
4145
4146 pRenderTarget->pMipmapLevels[i].fDirty = false;
4147 }
4148 }
4149 }
4150#endif
4151 }
4152 Assert(pRenderTarget->idAssociatedContext == cid);
4153
4154 /** @todo Assert(!pRenderTarget->fDirty); */
4155
4156 AssertReturn(pRenderTarget->u.pSurface, VERR_INVALID_PARAMETER);
4157
4158 pRenderTarget->fUsageD3D |= D3DUSAGE_DEPTHSTENCIL;
4159 pRenderTarget->flags |= SVGA3D_SURFACE_HINT_DEPTHSTENCIL;
4160
4161 if (pRenderTarget->fStencilAsTexture)
4162 {
4163 IDirect3DSurface9 *pStencilSurface;
4164
4165 hr = pRenderTarget->u.pTexture->GetSurfaceLevel(0, &pStencilSurface);
4166 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSetRenderTarget: GetSurfaceLevel failed with %x\n", hr), VERR_INTERNAL_ERROR);
4167
4168 hr = pContext->pDevice->SetDepthStencilSurface(pStencilSurface);
4169 D3D_RELEASE(pStencilSurface);
4170 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSetRenderTarget: SetDepthStencilSurface failed with %x\n", hr), VERR_INTERNAL_ERROR);
4171 }
4172 else
4173 {
4174 hr = pContext->pDevice->SetDepthStencilSurface(pRenderTarget->u.pSurface);
4175 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSetRenderTarget: SetDepthStencilSurface failed with %x\n", hr), VERR_INTERNAL_ERROR);
4176 }
4177 break;
4178
4179 case SVGA3D_RT_COLOR0:
4180 case SVGA3D_RT_COLOR1:
4181 case SVGA3D_RT_COLOR2:
4182 case SVGA3D_RT_COLOR3:
4183 case SVGA3D_RT_COLOR4:
4184 case SVGA3D_RT_COLOR5:
4185 case SVGA3D_RT_COLOR6:
4186 case SVGA3D_RT_COLOR7:
4187 {
4188 IDirect3DSurface9 *pSurface;
4189 bool fTexture = false;
4190 bool fShared = false;
4191
4192 /* Must flush the other context's 3d pipeline to make sure all drawing is complete for the surface we're about to use. */
4193 vmsvga3dSurfaceFlush(pThis, pRenderTarget);
4194
4195 if (pRenderTarget->flags & SVGA3D_SURFACE_HINT_TEXTURE)
4196 {
4197 fTexture = true;
4198
4199 /* A texture surface can be used as a render target to fill it and later on used as a texture. */
4200 if (!pRenderTarget->u.pTexture)
4201 {
4202 Log(("vmsvga3dSetRenderTarget: create texture to be used as render target; sid=%x type=%d format=%d -> create texture\n", target.sid, pRenderTarget->flags, pRenderTarget->format));
4203 int rc = vmsvga3dBackCreateTexture(pState, pContext, cid, pRenderTarget);
4204 AssertRCReturn(rc, rc);
4205 }
4206
4207#ifndef VBOX_VMSVGA3D_WITH_WINE_OPENGL
4208 if (pRenderTarget->idAssociatedContext != cid)
4209 {
4210 Log(("vmsvga3dSetRenderTarget; using texture sid=%x created for another context (%d vs %d)\n", target.sid, pRenderTarget->idAssociatedContext, cid));
4211
4212 PVMSVGA3DSHAREDSURFACE pSharedSurface = vmsvga3dSurfaceGetSharedCopy(pContext, pRenderTarget);
4213 AssertReturn(pSharedSurface, VERR_INTERNAL_ERROR);
4214
4215 hr = pSharedSurface->u.pTexture->GetSurfaceLevel(target.mipmap,
4216 &pSurface);
4217
4218 fShared = true;
4219 }
4220 else
4221#endif
4222 hr = pRenderTarget->u.pTexture->GetSurfaceLevel(target.mipmap,
4223 &pSurface);
4224
4225 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSetRenderTarget: GetSurfaceLevel failed with %x\n", hr), VERR_INTERNAL_ERROR);
4226 }
4227 else
4228 {
4229 AssertReturn(target.mipmap == 0, VERR_INVALID_PARAMETER);
4230 if (!pRenderTarget->u.pSurface)
4231 {
4232 DWORD cQualityLevels = 0;
4233
4234 /* Query the nr of quality levels for this particular format */
4235 if (pRenderTarget->multiSampleTypeD3D != D3DMULTISAMPLE_NONE)
4236 {
4237 hr = pState->pD3D9->CheckDeviceMultiSampleType(D3DADAPTER_DEFAULT,
4238 D3DDEVTYPE_HAL,
4239 pRenderTarget->formatD3D,
4240 TRUE, /* Windowed */
4241 pRenderTarget->multiSampleTypeD3D,
4242 &cQualityLevels);
4243 Assert(hr == D3D_OK || hr == D3DERR_NOTAVAILABLE);
4244 }
4245
4246 Log(("vmsvga3dSetRenderTarget COLOR; cQualityLevels=%d\n", cQualityLevels));
4247 Log(("Create rendertarget (%d,%d) format=%x multisample=%x\n", pRenderTarget->pMipmapLevels[0].mipmapSize.width, pRenderTarget->pMipmapLevels[0].mipmapSize.height, pRenderTarget->formatD3D, pRenderTarget->multiSampleTypeD3D));
4248
4249 hr = pContext->pDevice->CreateRenderTarget(pRenderTarget->pMipmapLevels[0].mipmapSize.width,
4250 pRenderTarget->pMipmapLevels[0].mipmapSize.height,
4251 pRenderTarget->formatD3D,
4252 pRenderTarget->multiSampleTypeD3D,
4253 ((cQualityLevels >= 1) ? cQualityLevels - 1 : 0), /* 0 - (levels-1) */
4254 TRUE, /* lockable */
4255 &pRenderTarget->u.pSurface,
4256 NULL);
4257 AssertReturn(hr == D3D_OK, VERR_INTERNAL_ERROR);
4258
4259 pRenderTarget->idAssociatedContext = cid;
4260 }
4261 else
4262 AssertReturn(pRenderTarget->fUsageD3D & D3DUSAGE_RENDERTARGET, VERR_INVALID_PARAMETER);
4263
4264 Assert(pRenderTarget->idAssociatedContext == cid);
4265 pSurface = pRenderTarget->u.pSurface;
4266 }
4267
4268 AssertReturn(pRenderTarget->u.pSurface, VERR_INVALID_PARAMETER);
4269 Assert(!pRenderTarget->fDirty);
4270
4271 pRenderTarget->fUsageD3D |= D3DUSAGE_RENDERTARGET;
4272 pRenderTarget->flags |= SVGA3D_SURFACE_HINT_RENDERTARGET;
4273
4274 hr = pContext->pDevice->SetRenderTarget(type - SVGA3D_RT_COLOR0, pSurface);
4275 if (fTexture)
4276 D3D_RELEASE(pSurface); /* Release reference to texture level 0 */
4277 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSetRenderTarget: SetRenderTarget failed with %x\n", hr), VERR_INTERNAL_ERROR);
4278
4279 pContext->sidRenderTarget = target.sid;
4280
4281 /* Changing the render target resets the viewport; restore it here. */
4282 if (pContext->state.u32UpdateFlags & VMSVGA3D_UPDATE_VIEWPORT)
4283 vmsvga3dSetViewPort(pThis, cid, &pContext->state.RectViewPort);
4284 /* Changing the render target also resets the scissor rectangle; restore it as well. */
4285 if (pContext->state.u32UpdateFlags & VMSVGA3D_UPDATE_SCISSORRECT)
4286 vmsvga3dSetScissorRect(pThis, cid, &pContext->state.RectScissor);
4287
4288 break;
4289 }
4290
4291 default:
4292 AssertFailedReturn(VERR_INVALID_PARAMETER);
4293 }
4294
4295 return VINF_SUCCESS;
4296}
4297
4298/**
4299 * Convert SVGA texture combiner value to its D3D equivalent
4300 */
4301static DWORD vmsvga3dTextureCombiner2D3D(uint32_t value)
4302{
4303 switch (value)
4304 {
4305 case SVGA3D_TC_DISABLE:
4306 return D3DTOP_DISABLE;
4307 case SVGA3D_TC_SELECTARG1:
4308 return D3DTOP_SELECTARG1;
4309 case SVGA3D_TC_SELECTARG2:
4310 return D3DTOP_SELECTARG2;
4311 case SVGA3D_TC_MODULATE:
4312 return D3DTOP_MODULATE;
4313 case SVGA3D_TC_ADD:
4314 return D3DTOP_ADD;
4315 case SVGA3D_TC_ADDSIGNED:
4316 return D3DTOP_ADDSIGNED;
4317 case SVGA3D_TC_SUBTRACT:
4318 return D3DTOP_SUBTRACT;
4319 case SVGA3D_TC_BLENDTEXTUREALPHA:
4320 return D3DTOP_BLENDTEXTUREALPHA;
4321 case SVGA3D_TC_BLENDDIFFUSEALPHA:
4322 return D3DTOP_BLENDDIFFUSEALPHA;
4323 case SVGA3D_TC_BLENDCURRENTALPHA:
4324 return D3DTOP_BLENDCURRENTALPHA;
4325 case SVGA3D_TC_BLENDFACTORALPHA:
4326 return D3DTOP_BLENDFACTORALPHA;
4327 case SVGA3D_TC_MODULATE2X:
4328 return D3DTOP_MODULATE2X;
4329 case SVGA3D_TC_MODULATE4X:
4330 return D3DTOP_MODULATE4X;
4331 case SVGA3D_TC_DSDT:
4332 AssertFailed(); /** @todo ??? */
4333 return D3DTOP_DISABLE;
4334 case SVGA3D_TC_DOTPRODUCT3:
4335 return D3DTOP_DOTPRODUCT3;
4336 case SVGA3D_TC_BLENDTEXTUREALPHAPM:
4337 return D3DTOP_BLENDTEXTUREALPHAPM;
4338 case SVGA3D_TC_ADDSIGNED2X:
4339 return D3DTOP_ADDSIGNED2X;
4340 case SVGA3D_TC_ADDSMOOTH:
4341 return D3DTOP_ADDSMOOTH;
4342 case SVGA3D_TC_PREMODULATE:
4343 return D3DTOP_PREMODULATE;
4344 case SVGA3D_TC_MODULATEALPHA_ADDCOLOR:
4345 return D3DTOP_MODULATEALPHA_ADDCOLOR;
4346 case SVGA3D_TC_MODULATECOLOR_ADDALPHA:
4347 return D3DTOP_MODULATECOLOR_ADDALPHA;
4348 case SVGA3D_TC_MODULATEINVALPHA_ADDCOLOR:
4349 return D3DTOP_MODULATEINVALPHA_ADDCOLOR;
4350 case SVGA3D_TC_MODULATEINVCOLOR_ADDALPHA:
4351 return D3DTOP_MODULATEINVCOLOR_ADDALPHA;
4352 case SVGA3D_TC_BUMPENVMAPLUMINANCE:
4353 return D3DTOP_BUMPENVMAPLUMINANCE;
4354 case SVGA3D_TC_MULTIPLYADD:
4355 return D3DTOP_MULTIPLYADD;
4356 case SVGA3D_TC_LERP:
4357 return D3DTOP_LERP;
4358 default:
4359 AssertFailed();
4360 return D3DTOP_DISABLE;
4361 }
4362}
4363
4364/**
4365 * Convert SVGA texture arg data value to its D3D equivalent
4366 */
4367static DWORD vmsvga3dTextureArgData2D3D(uint32_t value)
4368{
4369 switch (value)
4370 {
4371 case SVGA3D_TA_CONSTANT:
4372 return D3DTA_CONSTANT;
4373 case SVGA3D_TA_PREVIOUS:
4374 return D3DTA_CURRENT; /* current = previous */
4375 case SVGA3D_TA_DIFFUSE:
4376 return D3DTA_DIFFUSE;
4377 case SVGA3D_TA_TEXTURE:
4378 return D3DTA_TEXTURE;
4379 case SVGA3D_TA_SPECULAR:
4380 return D3DTA_SPECULAR;
4381 default:
4382 AssertFailed();
4383 return 0;
4384 }
4385}
4386
4387/**
4388 * Convert SVGA texture transform flag value to its D3D equivalent
4389 */
4390static DWORD vmsvga3dTextTransformFlags2D3D(uint32_t value)
4391{
4392 switch (value)
4393 {
4394 case SVGA3D_TEX_TRANSFORM_OFF:
4395 return D3DTTFF_DISABLE;
4396 case SVGA3D_TEX_TRANSFORM_S:
4397 return D3DTTFF_COUNT1; /** @todo correct? */
4398 case SVGA3D_TEX_TRANSFORM_T:
4399 return D3DTTFF_COUNT2; /** @todo correct? */
4400 case SVGA3D_TEX_TRANSFORM_R:
4401 return D3DTTFF_COUNT3; /** @todo correct? */
4402 case SVGA3D_TEX_TRANSFORM_Q:
4403 return D3DTTFF_COUNT4; /** @todo correct? */
4404 case SVGA3D_TEX_PROJECTED:
4405 return D3DTTFF_PROJECTED;
4406 default:
4407 AssertFailed();
4408 return 0;
4409 }
4410}
4411
4412int vmsvga3dSetTextureState(PVGASTATE pThis, uint32_t cid, uint32_t cTextureStates, SVGA3dTextureState *pTextureState)
4413{
4414 DWORD val = 0; /* Shut up MSC */
4415 HRESULT hr;
4416 PVMSVGA3DCONTEXT pContext;
4417 PVMSVGA3DSTATE pState = pThis->svga.p3dState;
4418 AssertReturn(pState, VERR_NO_MEMORY);
4419
4420 Log(("vmsvga3dSetTextureState %x cTextureState=%d\n", cid, cTextureStates));
4421
4422 if ( cid >= pState->cContexts
4423 || pState->papContexts[cid]->id != cid)
4424 {
4425 Log(("vmsvga3dSetTextureState invalid context id!\n"));
4426 return VERR_INVALID_PARAMETER;
4427 }
4428 pContext = pState->papContexts[cid];
4429
4430 for (unsigned i = 0; i < cTextureStates; i++)
4431 {
4432 D3DTEXTURESTAGESTATETYPE textureType = D3DTSS_FORCE_DWORD;
4433 D3DSAMPLERSTATETYPE samplerType = D3DSAMP_FORCE_DWORD;
4434 uint32_t currentStage = pTextureState[i].stage;
4435
4436 Log(("vmsvga3dSetTextureState: cid=%x stage=%d type=%s (%x) val=%x\n", cid, currentStage, vmsvga3dTextureStateToString(pTextureState[i].name), pTextureState[i].name, pTextureState[i].value));
4437
4438 /** @todo Is this the appropriate limit for all kinds of textures? It is the
4439 * size of aSidActiveTexture and for binding/unbinding we cannot exceed it. */
4440 if (RT_UNLIKELY(currentStage >= SVGA3D_MAX_TEXTURE_STAGE))
4441 {
4442 AssertMsgFailed(("pTextureState[%d].stage=%#x name=%#x\n", i, pTextureState[i].stage, pTextureState[i].name));
4443 continue;
4444 }
4445
4446 /* Record the texture state for vm state saving. */
4447 if ( currentStage < SVGA3D_MAX_TEXTURE_STAGE
4448 && pTextureState[i].name < SVGA3D_TS_MAX)
4449 {
4450 pContext->state.aTextureState[currentStage][pTextureState[i].name] = pTextureState[i];
4451 }
4452
4453 switch (pTextureState[i].name)
4454 {
4455 case SVGA3D_TS_COLOROP: /* SVGA3dTextureCombiner */
4456 textureType = D3DTSS_COLOROP;
4457 val = vmsvga3dTextureCombiner2D3D(pTextureState[i].value);
4458 break;
4459
4460 case SVGA3D_TS_COLORARG0: /* SVGA3dTextureArgData */
4461 textureType = D3DTSS_COLORARG0;
4462 val = vmsvga3dTextureArgData2D3D(pTextureState[i].value);
4463 break;
4464
4465 case SVGA3D_TS_COLORARG1: /* SVGA3dTextureArgData */
4466 textureType = D3DTSS_COLORARG1;
4467 val = vmsvga3dTextureArgData2D3D(pTextureState[i].value);
4468 break;
4469
4470 case SVGA3D_TS_COLORARG2: /* SVGA3dTextureArgData */
4471 textureType = D3DTSS_COLORARG2;
4472 val = vmsvga3dTextureArgData2D3D(pTextureState[i].value);
4473 break;
4474
4475 case SVGA3D_TS_ALPHAOP: /* SVGA3dTextureCombiner */
4476 textureType = D3DTSS_ALPHAOP;
4477 val = vmsvga3dTextureCombiner2D3D(pTextureState[i].value);
4478 break;
4479
4480 case SVGA3D_TS_ALPHAARG0: /* SVGA3dTextureArgData */
4481 textureType = D3DTSS_ALPHAARG0;
4482 val = vmsvga3dTextureArgData2D3D(pTextureState[i].value);
4483 break;
4484
4485 case SVGA3D_TS_ALPHAARG1: /* SVGA3dTextureArgData */
4486 textureType = D3DTSS_ALPHAARG1;
4487 val = vmsvga3dTextureArgData2D3D(pTextureState[i].value);
4488 break;
4489
4490 case SVGA3D_TS_ALPHAARG2: /* SVGA3dTextureArgData */
4491 textureType = D3DTSS_ALPHAARG2;
4492 val = vmsvga3dTextureArgData2D3D(pTextureState[i].value);
4493 break;
4494
4495 case SVGA3D_TS_BUMPENVMAT00: /* float */
4496 textureType = D3DTSS_BUMPENVMAT00;
4497 val = pTextureState[i].value;
4498 break;
4499
4500 case SVGA3D_TS_BUMPENVMAT01: /* float */
4501 textureType = D3DTSS_BUMPENVMAT01;
4502 val = pTextureState[i].value;
4503 break;
4504
4505 case SVGA3D_TS_BUMPENVMAT10: /* float */
4506 textureType = D3DTSS_BUMPENVMAT10;
4507 val = pTextureState[i].value;
4508 break;
4509
4510 case SVGA3D_TS_BUMPENVMAT11: /* float */
4511 textureType = D3DTSS_BUMPENVMAT11;
4512 val = pTextureState[i].value;
4513 break;
4514
4515 case SVGA3D_TS_TEXCOORDINDEX: /* uint32_t */
4516 textureType = D3DTSS_TEXCOORDINDEX;
4517 val = pTextureState[i].value;
4518 break;
4519
4520 case SVGA3D_TS_BUMPENVLSCALE: /* float */
4521 textureType = D3DTSS_BUMPENVLSCALE;
4522 val = pTextureState[i].value;
4523 break;
4524
4525 case SVGA3D_TS_BUMPENVLOFFSET: /* float */
4526 textureType = D3DTSS_BUMPENVLOFFSET;
4527 val = pTextureState[i].value;
4528 break;
4529
4530 case SVGA3D_TS_TEXTURETRANSFORMFLAGS: /* SVGA3dTexTransformFlags */
4531 textureType = D3DTSS_TEXTURETRANSFORMFLAGS;
4532 val = vmsvga3dTextTransformFlags2D3D(pTextureState[i].value);
4533 break;
4534
4535 case SVGA3D_TS_BIND_TEXTURE: /* SVGA3dSurfaceId */
4536 if (pTextureState[i].value == SVGA3D_INVALID_ID)
4537 {
4538 Log(("SVGA3D_TS_BIND_TEXTURE: stage %d, texture sid=%x\n", currentStage, pTextureState[i].value));
4539
4540 pContext->aSidActiveTexture[currentStage] = SVGA3D_INVALID_ID;
4541 /* Unselect the currently associated texture. */
4542 hr = pContext->pDevice->SetTexture(currentStage, NULL);
4543 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSetTextureState: SetTexture failed with %x\n", hr), VERR_INTERNAL_ERROR);
4544 }
4545 else
4546 {
4547 HRESULT hr;
4548 uint32_t sid = pTextureState[i].value;
4549
4550 AssertReturn(sid < SVGA3D_MAX_SURFACE_IDS, VERR_INVALID_PARAMETER);
4551 AssertReturn(sid < pState->cSurfaces && pState->papSurfaces[sid]->id == sid, VERR_INVALID_PARAMETER);
4552
4553 PVMSVGA3DSURFACE pSurface = pState->papSurfaces[sid];
4554
4555 Log(("SVGA3D_TS_BIND_TEXTURE: stage %d, texture sid=%x (%d,%d)\n", currentStage, pTextureState[i].value, pSurface->pMipmapLevels[0].mipmapSize.width, pSurface->pMipmapLevels[0].mipmapSize.height));
4556
4557 if (!pSurface->u.pTexture)
4558 {
4559 Assert(pSurface->idAssociatedContext == SVGA3D_INVALID_ID);
4560 Log(("CreateTexture (%d,%d) level=%d fUsage=%x format=%x\n", pSurface->pMipmapLevels[0].mipmapSize.width, pSurface->pMipmapLevels[0].mipmapSize.height, pSurface->faces[0].numMipLevels, pSurface->fUsageD3D, pSurface->formatD3D));
4561 int rc = vmsvga3dBackCreateTexture(pState, pContext, cid, pSurface);
4562 AssertRCReturn(rc, rc);
4563 }
4564 else
4565 {
4566 /* Must flush the other context's 3d pipeline to make sure all drawing is complete for the surface we're about to use. */
4567 vmsvga3dSurfaceFlush(pThis, pSurface);
4568 }
4569
4570#ifndef VBOX_VMSVGA3D_WITH_WINE_OPENGL
4571 if (pSurface->idAssociatedContext != cid)
4572 {
4573 Log(("vmsvga3dSetTextureState; using texture sid=%x created for another context (%d vs %d)\n", sid, pSurface->idAssociatedContext, cid));
4574
4575 PVMSVGA3DSHAREDSURFACE pSharedSurface = vmsvga3dSurfaceGetSharedCopy(pContext, pSurface);
4576 AssertReturn(pSharedSurface, VERR_INTERNAL_ERROR);
4577
4578 hr = pContext->pDevice->SetTexture(currentStage, pSharedSurface->u.pTexture);
4579 }
4580 else
4581#endif
4582 hr = pContext->pDevice->SetTexture(currentStage, pSurface->u.pTexture);
4583
4584 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSetTextureState: SetTexture failed with %x\n", hr), VERR_INTERNAL_ERROR);
4585
4586 pContext->aSidActiveTexture[currentStage] = sid;
4587 }
4588 /* Finished; continue with the next one. */
4589 continue;
4590
4591 case SVGA3D_TS_ADDRESSW: /* SVGA3dTextureAddress */
4592 samplerType = D3DSAMP_ADDRESSW;
4593 val = pTextureState[i].value; /* Identical otherwise */
4594 Assert(pTextureState[i].value != SVGA3D_TEX_ADDRESS_EDGE);
4595 break;
4596
4597 case SVGA3D_TS_ADDRESSU: /* SVGA3dTextureAddress */
4598 samplerType = D3DSAMP_ADDRESSU;
4599 val = pTextureState[i].value; /* Identical otherwise */
4600 Assert(pTextureState[i].value != SVGA3D_TEX_ADDRESS_EDGE);
4601 break;
4602
4603 case SVGA3D_TS_ADDRESSV: /* SVGA3dTextureAddress */
4604 samplerType = D3DSAMP_ADDRESSV;
4605 val = pTextureState[i].value; /* Identical otherwise */
4606 Assert(pTextureState[i].value != SVGA3D_TEX_ADDRESS_EDGE);
4607 break;
4608
4609 case SVGA3D_TS_MIPFILTER: /* SVGA3dTextureFilter */
4610 samplerType = D3DSAMP_MIPFILTER;
4611 val = pTextureState[i].value; /* Identical otherwise */
4612 Assert(pTextureState[i].value != SVGA3D_TEX_FILTER_FLATCUBIC);
4613 Assert(pTextureState[i].value != SVGA3D_TEX_FILTER_GAUSSIANCUBIC);
4614 break;
4615
4616 case SVGA3D_TS_MAGFILTER: /* SVGA3dTextureFilter */
4617 samplerType = D3DSAMP_MAGFILTER;
4618 val = pTextureState[i].value; /* Identical otherwise */
4619 Assert(pTextureState[i].value != SVGA3D_TEX_FILTER_FLATCUBIC);
4620 Assert(pTextureState[i].value != SVGA3D_TEX_FILTER_GAUSSIANCUBIC);
4621 break;
4622
4623 case SVGA3D_TS_MINFILTER: /* SVGA3dTextureFilter */
4624 samplerType = D3DSAMP_MINFILTER;
4625 val = pTextureState[i].value; /* Identical otherwise */
4626 Assert(pTextureState[i].value != SVGA3D_TEX_FILTER_FLATCUBIC);
4627 Assert(pTextureState[i].value != SVGA3D_TEX_FILTER_GAUSSIANCUBIC);
4628 break;
4629
4630 case SVGA3D_TS_BORDERCOLOR: /* SVGA3dColor */
4631 samplerType = D3DSAMP_BORDERCOLOR;
4632 val = pTextureState[i].value; /* Identical */
4633 break;
4634
4635 case SVGA3D_TS_TEXTURE_LOD_BIAS: /* float */
4636 samplerType = D3DSAMP_MIPMAPLODBIAS;
4637 val = pTextureState[i].value; /* Identical */
4638 break;
4639
4640 case SVGA3D_TS_TEXTURE_MIPMAP_LEVEL: /* uint32_t */
4641 samplerType = D3DSAMP_MAXMIPLEVEL;
4642 val = pTextureState[i].value; /* Identical?? */
4643 break;
4644
4645 case SVGA3D_TS_TEXTURE_ANISOTROPIC_LEVEL: /* uint32_t */
4646 samplerType = D3DSAMP_MAXANISOTROPY;
4647 val = pTextureState[i].value; /* Identical?? */
4648 break;
4649
4650 case SVGA3D_TS_GAMMA: /* float */
4651 samplerType = D3DSAMP_SRGBTEXTURE;
4652 /* Boolean in D3D */
4653 if (pTextureState[i].floatValue == 1.0f)
4654 val = FALSE;
4655 else
4656 val = TRUE;
4657 break;
4658
4659 /* Internal commands, that don't map directly to the SetTextureStageState API. */
4660 case SVGA3D_TS_TEXCOORDGEN: /* SVGA3dTextureCoordGen */
4661 AssertFailed();
4662 break;
4663
4664 case SVGA3D_TS_MAX: /* shut up MSC */
4665 case SVGA3D_TS_INVALID:
4666 AssertFailedBreak();
4667 }
4668
4669 if (textureType != D3DTSS_FORCE_DWORD)
4670 {
4671 hr = pContext->pDevice->SetTextureStageState(currentStage, textureType, val);
4672 }
4673 else
4674 {
4675 Assert(samplerType != D3DSAMP_FORCE_DWORD);
4676 hr = pContext->pDevice->SetSamplerState(currentStage, samplerType, val);
4677 }
4678
4679 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSetTextureState: SetTextureStageState failed with %x\n", hr), VERR_INTERNAL_ERROR);
4680 }
4681
4682 return VINF_SUCCESS;
4683}
4684
4685int vmsvga3dSetMaterial(PVGASTATE pThis, uint32_t cid, SVGA3dFace face, SVGA3dMaterial *pMaterial)
4686{
4687 HRESULT hr;
4688 D3DMATERIAL9 material;
4689 PVMSVGA3DCONTEXT pContext;
4690 PVMSVGA3DSTATE pState = pThis->svga.p3dState;
4691 AssertReturn(pState, VERR_NO_MEMORY);
4692
4693 Log(("vmsvga3dSetMaterial %x face %d\n", cid, face));
4694
4695 if ( cid >= pState->cContexts
4696 || pState->papContexts[cid]->id != cid)
4697 {
4698 Log(("vmsvga3dSetMaterial invalid context id!\n"));
4699 return VERR_INVALID_PARAMETER;
4700 }
4701 pContext = pState->papContexts[cid];
4702
4703 AssertReturn(face < SVGA3D_FACE_MAX, VERR_INVALID_PARAMETER);
4704
4705 /* Save for vm state save/restore. */
4706 pContext->state.aMaterial[face].fValid = true;
4707 pContext->state.aMaterial[face].material = *pMaterial;
4708 pContext->state.u32UpdateFlags |= VMSVGA3D_UPDATE_MATERIAL;
4709
4710 /* @note face not used for D3D9 */
4711 /** @todo ignore everything except SVGA3D_FACE_NONE? */
4712 //Assert(face == SVGA3D_FACE_NONE);
4713 if (face != SVGA3D_FACE_NONE)
4714 Log(("Unsupported face %d!!\n", face));
4715
4716 material.Diffuse.r = pMaterial->diffuse[0];
4717 material.Diffuse.g = pMaterial->diffuse[1];
4718 material.Diffuse.b = pMaterial->diffuse[2];
4719 material.Diffuse.a = pMaterial->diffuse[3];
4720 material.Ambient.r = pMaterial->ambient[0];
4721 material.Ambient.g = pMaterial->ambient[1];
4722 material.Ambient.b = pMaterial->ambient[2];
4723 material.Ambient.a = pMaterial->ambient[3];
4724 material.Specular.r = pMaterial->specular[0];
4725 material.Specular.g = pMaterial->specular[1];
4726 material.Specular.b = pMaterial->specular[2];
4727 material.Specular.a = pMaterial->specular[3];
4728 material.Emissive.r = pMaterial->emissive[0];
4729 material.Emissive.g = pMaterial->emissive[1];
4730 material.Emissive.b = pMaterial->emissive[2];
4731 material.Emissive.a = pMaterial->emissive[3];
4732 material.Power = pMaterial->shininess;
4733
4734 hr = pContext->pDevice->SetMaterial(&material);
4735 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSetMaterial: SetMaterial failed with %x\n", hr), VERR_INTERNAL_ERROR);
4736
4737 return VINF_SUCCESS;
4738}
4739
4740int vmsvga3dSetLightData(PVGASTATE pThis, uint32_t cid, uint32_t index, SVGA3dLightData *pData)
4741{
4742 HRESULT hr;
4743 D3DLIGHT9 light;
4744 PVMSVGA3DCONTEXT pContext;
4745 PVMSVGA3DSTATE pState = pThis->svga.p3dState;
4746 AssertReturn(pState, VERR_NO_MEMORY);
4747
4748 Log(("vmsvga3dSetLightData %x index=%d\n", cid, index));
4749
4750 if ( cid >= pState->cContexts
4751 || pState->papContexts[cid]->id != cid)
4752 {
4753 Log(("vmsvga3dSetLightData invalid context id!\n"));
4754 return VERR_INVALID_PARAMETER;
4755 }
4756 pContext = pState->papContexts[cid];
4757
4758 switch (pData->type)
4759 {
4760 case SVGA3D_LIGHTTYPE_POINT:
4761 light.Type = D3DLIGHT_POINT;
4762 break;
4763
4764 case SVGA3D_LIGHTTYPE_SPOT1: /* 1-cone, in degrees */
4765 light.Type = D3DLIGHT_SPOT;
4766 break;
4767
4768 case SVGA3D_LIGHTTYPE_DIRECTIONAL:
4769 light.Type = D3DLIGHT_DIRECTIONAL;
4770 break;
4771
4772 case SVGA3D_LIGHTTYPE_SPOT2: /* 2-cone, in radians */
4773 default:
4774 Log(("Unsupported light type!!\n"));
4775 return VERR_INVALID_PARAMETER;
4776 }
4777
4778 /* Store for vm state save/restore */
4779 if (index < SVGA3D_MAX_LIGHTS)
4780 {
4781 pContext->state.aLightData[index].fValidData = true;
4782 pContext->state.aLightData[index].data = *pData;
4783 }
4784 else
4785 AssertFailed();
4786
4787 light.Diffuse.r = pData->diffuse[0];
4788 light.Diffuse.g = pData->diffuse[1];
4789 light.Diffuse.b = pData->diffuse[2];
4790 light.Diffuse.a = pData->diffuse[3];
4791 light.Specular.r = pData->specular[0];
4792 light.Specular.g = pData->specular[1];
4793 light.Specular.b = pData->specular[2];
4794 light.Specular.a = pData->specular[3];
4795 light.Ambient.r = pData->ambient[0];
4796 light.Ambient.g = pData->ambient[1];
4797 light.Ambient.b = pData->ambient[2];
4798 light.Ambient.a = pData->ambient[3];
4799 light.Position.x = pData->position[0];
4800 light.Position.y = pData->position[1];
4801 light.Position.z = pData->position[2]; /* @note 4th position not available in D3D9 */
4802 light.Direction.x = pData->direction[0];
4803 light.Direction.y = pData->direction[1];
4804 light.Direction.z = pData->direction[2]; /* @note 4th position not available in D3D9 */
4805 light.Range = pData->range;
4806 light.Falloff = pData->falloff;
4807 light.Attenuation0 = pData->attenuation0;
4808 light.Attenuation1 = pData->attenuation1;
4809 light.Attenuation2 = pData->attenuation2;
4810 light.Theta = pData->theta;
4811 light.Phi = pData->phi;
4812
4813 hr = pContext->pDevice->SetLight(index, &light);
4814 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSetLightData: SetLight failed with %x\n", hr), VERR_INTERNAL_ERROR);
4815
4816 return VINF_SUCCESS;
4817}
4818
4819int vmsvga3dSetLightEnabled(PVGASTATE pThis, uint32_t cid, uint32_t index, uint32_t enabled)
4820{
4821 HRESULT hr;
4822 PVMSVGA3DCONTEXT pContext;
4823 PVMSVGA3DSTATE pState = pThis->svga.p3dState;
4824 AssertReturn(pState, VERR_NO_MEMORY);
4825
4826 Log(("vmsvga3dSetLightEnabled %x %d -> %d\n", cid, index, enabled));
4827
4828 if ( cid >= pState->cContexts
4829 || pState->papContexts[cid]->id != cid)
4830 {
4831 Log(("vmsvga3dSetLightEnabled invalid context id!\n"));
4832 return VERR_INVALID_PARAMETER;
4833 }
4834 pContext = pState->papContexts[cid];
4835
4836 /* Store for vm state save/restore */
4837 if (index < SVGA3D_MAX_LIGHTS)
4838 pContext->state.aLightData[index].fEnabled = !!enabled;
4839 else
4840 AssertFailed();
4841
4842 hr = pContext->pDevice->LightEnable(index, (BOOL)enabled);
4843 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSetLightEnabled: LightEnable failed with %x\n", hr), VERR_INTERNAL_ERROR);
4844
4845 return VINF_SUCCESS;
4846}
4847
4848int vmsvga3dSetViewPort(PVGASTATE pThis, uint32_t cid, SVGA3dRect *pRect)
4849{
4850 HRESULT hr;
4851 D3DVIEWPORT9 viewPort;
4852 PVMSVGA3DCONTEXT pContext;
4853 PVMSVGA3DSTATE pState = pThis->svga.p3dState;
4854 AssertReturn(pState, VERR_NO_MEMORY);
4855
4856 Log(("vmsvga3dSetViewPort %x (%d,%d)(%d,%d)\n", cid, pRect->x, pRect->y, pRect->w, pRect->h));
4857
4858 if ( cid >= pState->cContexts
4859 || pState->papContexts[cid]->id != cid)
4860 {
4861 Log(("vmsvga3dSetViewPort invalid context id!\n"));
4862 return VERR_INVALID_PARAMETER;
4863 }
4864 /* Save for vm state save/restore. */
4865 pContext = pState->papContexts[cid];
4866 pContext->state.RectViewPort = *pRect;
4867 pContext->state.u32UpdateFlags |= VMSVGA3D_UPDATE_VIEWPORT;
4868
4869 hr = pContext->pDevice->GetViewport(&viewPort);
4870 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSetViewPort: GetViewport failed with %x\n", hr), VERR_INTERNAL_ERROR);
4871
4872 viewPort.X = pRect->x;
4873 viewPort.Y = pRect->y;
4874 viewPort.Width = pRect->w;
4875 viewPort.Height = pRect->h;
4876 /* viewPort.MinZ & MaxZ are not changed from the current setting. */
4877
4878 hr = pContext->pDevice->SetViewport(&viewPort);
4879 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSetViewPort: SetViewport failed with %x\n", hr), VERR_INTERNAL_ERROR);
4880
4881 return VINF_SUCCESS;
4882}
4883
4884int vmsvga3dSetClipPlane(PVGASTATE pThis, uint32_t cid, uint32_t index, float plane[4])
4885{
4886 HRESULT hr;
4887 PVMSVGA3DCONTEXT pContext;
4888 PVMSVGA3DSTATE pState = pThis->svga.p3dState;
4889 AssertReturn(pState, VERR_NO_MEMORY);
4890
4891 Log(("vmsvga3dSetClipPlane %x %d (%d,%d)(%d,%d)\n", cid, index, (unsigned)(plane[0] * 100.0), (unsigned)(plane[1] * 100.0), (unsigned)(plane[2] * 100.0), (unsigned)(plane[3] * 100.0)));
4892 AssertReturn(index < SVGA3D_CLIPPLANE_MAX, VERR_INVALID_PARAMETER);
4893
4894 if ( cid >= pState->cContexts
4895 || pState->papContexts[cid]->id != cid)
4896 {
4897 Log(("vmsvga3dSetClipPlane invalid context id!\n"));
4898 return VERR_INVALID_PARAMETER;
4899 }
4900 pContext = pState->papContexts[cid];
4901
4902 /* Store for vm state save/restore. */
4903 pContext->state.aClipPlane[index].fValid = true;
4904 memcpy(pContext->state.aClipPlane[index].plane, plane, sizeof(pContext->state.aClipPlane[index].plane));
4905
4906 hr = pContext->pDevice->SetClipPlane(index, plane);
4907 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSetClipPlane: SetClipPlane failed with %x\n", hr), VERR_INTERNAL_ERROR);
4908 return VINF_SUCCESS;
4909}
4910
4911int vmsvga3dCommandClear(PVGASTATE pThis, uint32_t cid, SVGA3dClearFlag clearFlag, uint32_t color, float depth, uint32_t stencil, uint32_t cRects, SVGA3dRect *pRect)
4912{
4913 DWORD clearFlagD3D = 0;
4914 D3DRECT *pRectD3D = NULL;
4915 HRESULT hr;
4916 PVMSVGA3DCONTEXT pContext;
4917 PVMSVGA3DSTATE pState = pThis->svga.p3dState;
4918 AssertReturn(pState, VERR_NO_MEMORY);
4919
4920 Log(("vmsvga3dCommandClear %x clearFlag=%x color=%x depth=%d stencil=%x cRects=%d\n", cid, clearFlag, color, (uint32_t)(depth * 100.0), stencil, cRects));
4921
4922 if ( cid >= pState->cContexts
4923 || pState->papContexts[cid]->id != cid)
4924 {
4925 Log(("vmsvga3dCommandClear invalid context id!\n"));
4926 return VERR_INVALID_PARAMETER;
4927 }
4928 pContext = pState->papContexts[cid];
4929
4930 if (clearFlag & SVGA3D_CLEAR_COLOR)
4931 clearFlagD3D |= D3DCLEAR_TARGET;
4932 if (clearFlag & SVGA3D_CLEAR_STENCIL)
4933 clearFlagD3D |= D3DCLEAR_STENCIL;
4934 if (clearFlag & SVGA3D_CLEAR_DEPTH)
4935 clearFlagD3D |= D3DCLEAR_ZBUFFER;
4936
4937 if (cRects)
4938 {
4939 pRectD3D = (D3DRECT *)RTMemAlloc(sizeof(D3DRECT) * cRects);
4940 AssertReturn(pRectD3D, VERR_NO_MEMORY);
4941
4942 for (unsigned i=0; i < cRects; i++)
4943 {
4944 Log(("vmsvga3dCommandClear: rect %d (%d,%d)(%d,%d)\n", i, pRect[i].x, pRect[i].y, pRect[i].x + pRect[i].w, pRect[i].y + pRect[i].h));
4945 pRectD3D[i].x1 = pRect[i].x;
4946 pRectD3D[i].y1 = pRect[i].y;
4947 pRectD3D[i].x2 = pRect[i].x + pRect[i].w; /* exclusive */
4948 pRectD3D[i].y2 = pRect[i].y + pRect[i].h; /* exclusive */
4949 }
4950 }
4951
4952 hr = pContext->pDevice->Clear(cRects, pRectD3D, clearFlagD3D, (D3DCOLOR)color, depth, stencil);
4953 if (pRectD3D)
4954 RTMemFree(pRectD3D);
4955
4956 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dCommandClear: Clear failed with %x\n", hr), VERR_INTERNAL_ERROR);
4957
4958 /* Make sure we can track drawing usage of active render targets. */
4959 if (pContext->sidRenderTarget != SVGA3D_INVALID_ID)
4960 vmsvga3dSurfaceTrackUsageById(pState, pContext, pContext->sidRenderTarget);
4961
4962 return VINF_SUCCESS;
4963}
4964
4965/* Convert VMWare vertex declaration to its D3D equivalent. */
4966int vmsvga3dVertexDecl2D3D(SVGA3dVertexArrayIdentity &identity, D3DVERTEXELEMENT9 *pVertexElement)
4967{
4968 /* usage, method and type are identical; make sure. */
4969 AssertCompile(SVGA3D_DECLTYPE_FLOAT1 == D3DDECLTYPE_FLOAT1);
4970 AssertCompile(SVGA3D_DECLTYPE_FLOAT16_4 == D3DDECLTYPE_FLOAT16_4);
4971 AssertCompile(SVGA3D_DECLMETHOD_DEFAULT == D3DDECLMETHOD_DEFAULT);
4972 AssertCompile(SVGA3D_DECLMETHOD_LOOKUPPRESAMPLED == D3DDECLMETHOD_LOOKUPPRESAMPLED);
4973 AssertCompile(D3DDECLUSAGE_POSITION == SVGA3D_DECLUSAGE_POSITION);
4974 AssertCompile(D3DDECLUSAGE_SAMPLE == SVGA3D_DECLUSAGE_SAMPLE);
4975
4976 pVertexElement->Stream = 0;
4977 pVertexElement->Offset = 0;
4978 pVertexElement->Type = identity.type;
4979 pVertexElement->Method = identity.method;
4980 pVertexElement->Usage = identity.usage;
4981 pVertexElement->UsageIndex = identity.usageIndex;
4982 return VINF_SUCCESS;
4983}
4984
4985/* Convert VMWare primitive type to its D3D equivalent. */
4986int vmsvga3dPrimitiveType2D3D(SVGA3dPrimitiveType PrimitiveType, D3DPRIMITIVETYPE *pPrimitiveTypeD3D)
4987{
4988 switch (PrimitiveType)
4989 {
4990 case SVGA3D_PRIMITIVE_TRIANGLELIST:
4991 *pPrimitiveTypeD3D = D3DPT_TRIANGLELIST;
4992 break;
4993 case SVGA3D_PRIMITIVE_POINTLIST:
4994 *pPrimitiveTypeD3D = D3DPT_POINTLIST;
4995 break;
4996 case SVGA3D_PRIMITIVE_LINELIST:
4997 *pPrimitiveTypeD3D = D3DPT_LINELIST;
4998 break;
4999 case SVGA3D_PRIMITIVE_LINESTRIP:
5000 *pPrimitiveTypeD3D = D3DPT_LINESTRIP;
5001 break;
5002 case SVGA3D_PRIMITIVE_TRIANGLESTRIP:
5003 *pPrimitiveTypeD3D = D3DPT_TRIANGLESTRIP;
5004 break;
5005 case SVGA3D_PRIMITIVE_TRIANGLEFAN:
5006 *pPrimitiveTypeD3D = D3DPT_TRIANGLEFAN;
5007 break;
5008 default:
5009 return VERR_INVALID_PARAMETER;
5010 }
5011 return VINF_SUCCESS;
5012}
5013
5014int vmsvga3dDrawPrimitivesProcessVertexDecls(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext, uint32_t numVertexDecls, SVGA3dVertexDecl *pVertexDecl, uint32_t idStream, D3DVERTEXELEMENT9 *pVertexElement)
5015{
5016 HRESULT hr;
5017 int rc;
5018 uint32_t uVertexMinOffset = 0xffffffff;
5019 uint32_t uVertexMaxOffset = 0;
5020
5021 /* Create a vertex declaration array */
5022 for (unsigned iVertex = 0; iVertex < numVertexDecls; iVertex++)
5023 {
5024 unsigned sidVertex = pVertexDecl[iVertex].array.surfaceId;
5025 PVMSVGA3DSURFACE pVertexSurface;
5026
5027 AssertReturn(sidVertex < SVGA3D_MAX_SURFACE_IDS, VERR_INVALID_PARAMETER);
5028 AssertReturn(sidVertex < pState->cSurfaces && pState->papSurfaces[sidVertex]->id == sidVertex, VERR_INVALID_PARAMETER);
5029
5030 pVertexSurface = pState->papSurfaces[sidVertex];
5031 Log(("vmsvga3dDrawPrimitives: vertex sid=%x stream %d\n", sidVertex, idStream));
5032 Log(("vmsvga3dDrawPrimitives: type=%s (%d) method=%s (%d) usage=%s (%d) usageIndex=%d stride=%d offset=%d\n", vmsvgaDeclType2String(pVertexDecl[iVertex].identity.type), pVertexDecl[iVertex].identity.type, vmsvgaDeclMethod2String(pVertexDecl[iVertex].identity.method), pVertexDecl[iVertex].identity.method, vmsvgaDeclUsage2String(pVertexDecl[iVertex].identity.usage), pVertexDecl[iVertex].identity.usage, pVertexDecl[iVertex].identity.usageIndex, pVertexDecl[iVertex].array.stride, pVertexDecl[iVertex].array.offset));
5033
5034 rc = vmsvga3dVertexDecl2D3D(pVertexDecl[iVertex].identity, &pVertexElement[iVertex]);
5035 AssertRCReturn(rc, rc);
5036 pVertexElement[iVertex].Stream = idStream;
5037
5038#ifdef LOG_ENABLED
5039 if (pVertexDecl[iVertex].array.stride == 0)
5040 Log(("vmsvga3dDrawPrimitives: stride == 0! Can be valid\n"));
5041#endif
5042
5043 /* Find the min and max vertex offset to determine the right base offset to use in the vertex declaration. */
5044 if (pVertexDecl[iVertex].array.offset > uVertexMaxOffset)
5045 uVertexMaxOffset = pVertexDecl[iVertex].array.offset;
5046 if (pVertexDecl[iVertex].array.offset < uVertexMinOffset)
5047 uVertexMinOffset = pVertexDecl[iVertex].array.offset;
5048
5049 /* pVertexSurface->u. is an union, so pVertexSurface->u.pIndexBuffer and pVertexSurface->u.pVertexBuffer are the same */
5050 if ( pVertexSurface->u.pVertexBuffer
5051 && !(pVertexSurface->fu32ActualUsageFlags & SVGA3D_SURFACE_HINT_VERTEXBUFFER))
5052 {
5053 /* The buffer object is not an vertex one. Switch type. */
5054 Assert(pVertexSurface->fu32ActualUsageFlags & SVGA3D_SURFACE_HINT_INDEXBUFFER);
5055 pVertexSurface->fu32ActualUsageFlags &= ~SVGA3D_SURFACE_HINT_INDEXBUFFER;
5056
5057 D3D_RELEASE(pVertexSurface->u.pIndexBuffer);
5058 LogFunc(("index -> vertex buffer sid=%x\n", sidVertex));
5059 }
5060
5061 if (!pVertexSurface->u.pVertexBuffer)
5062 {
5063 Assert(iVertex == 0);
5064
5065 Log(("vmsvga3dDrawPrimitives: create vertex buffer fDirty=%d\n", pVertexSurface->fDirty));
5066 hr = pContext->pDevice->CreateVertexBuffer(pVertexSurface->pMipmapLevels[0].cbSurface,
5067 D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY /* possible severe performance penalty otherwise (according to d3d debug output) */,
5068 0, /* non-FVF */
5069 D3DPOOL_DEFAULT,
5070 &pVertexSurface->u.pVertexBuffer,
5071 NULL);
5072 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dDrawPrimitives: CreateVertexBuffer failed with %x\n", hr), VERR_INTERNAL_ERROR);
5073
5074 pVertexSurface->idAssociatedContext = pContext->id;
5075
5076 if (pVertexSurface->fDirty)
5077 {
5078 void *pData;
5079
5080 hr = pVertexSurface->u.pVertexBuffer->Lock(0, 0, &pData, 0);
5081 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dDrawPrimitives: Lock vertex failed with %x\n", hr), VERR_INTERNAL_ERROR);
5082
5083 memcpy(pData, pVertexSurface->pMipmapLevels[0].pSurfaceData, pVertexSurface->pMipmapLevels[0].cbSurface);
5084
5085 hr = pVertexSurface->u.pVertexBuffer->Unlock();
5086 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dDrawPrimitives: Unlock vertex failed with %x\n", hr), VERR_INTERNAL_ERROR);
5087 pVertexSurface->pMipmapLevels[0].fDirty = false;
5088 pVertexSurface->fDirty = false;
5089 }
5090 pVertexSurface->flags |= SVGA3D_SURFACE_HINT_VERTEXBUFFER;
5091 pVertexSurface->fu32ActualUsageFlags |= SVGA3D_SURFACE_HINT_VERTEXBUFFER;
5092 }
5093 }
5094
5095 /* Set the right vertex offset values for each declaration. */
5096 for (unsigned iVertex = 0; iVertex < numVertexDecls; iVertex++)
5097 {
5098 pVertexElement[iVertex].Offset = pVertexDecl[iVertex].array.offset - uVertexMinOffset;
5099#ifdef LOG_ENABLED
5100 if (pVertexElement[iVertex].Offset >= pVertexDecl[0].array.stride)
5101 Log(("vmsvga3dDrawPrimitives: WARNING: offset > stride!!\n"));
5102#endif
5103
5104 Log(("vmsvga3dDrawPrimitives: vertex %d offset = %d (stride %d) (min=%d max=%d)\n", iVertex, pVertexDecl[iVertex].array.offset, pVertexDecl[iVertex].array.stride, uVertexMinOffset, uVertexMaxOffset));
5105 }
5106
5107 PVMSVGA3DSURFACE pVertexSurface;
5108 unsigned sidVertex = pVertexDecl[0].array.surfaceId;
5109 unsigned strideVertex = pVertexDecl[0].array.stride;
5110
5111 pVertexSurface = pState->papSurfaces[sidVertex];
5112
5113 Log(("vmsvga3dDrawPrimitives: SetStreamSource %d min offset=%d stride=%d\n", idStream, uVertexMinOffset, strideVertex));
5114 hr = pContext->pDevice->SetStreamSource(idStream,
5115 pVertexSurface->u.pVertexBuffer,
5116 uVertexMinOffset,
5117 strideVertex);
5118
5119 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dDrawPrimitives: SetStreamSource failed with %x\n", hr), VERR_INTERNAL_ERROR);
5120 return VINF_SUCCESS;
5121}
5122
5123int vmsvga3dDrawPrimitives(PVGASTATE pThis, uint32_t cid, uint32_t numVertexDecls, SVGA3dVertexDecl *pVertexDecl,
5124 uint32_t numRanges, SVGA3dPrimitiveRange *pRange,
5125 uint32_t cVertexDivisor, SVGA3dVertexDivisor *pVertexDivisor)
5126{
5127 RT_NOREF(pVertexDivisor);
5128 PVMSVGA3DCONTEXT pContext;
5129 PVMSVGA3DSTATE pState = pThis->svga.p3dState;
5130 AssertReturn(pState, VERR_INTERNAL_ERROR);
5131 int rc = VINF_SUCCESS;
5132 HRESULT hr;
5133 uint32_t iCurrentVertex, iCurrentStreamId;
5134 IDirect3DVertexDeclaration9 *pVertexDeclD3D = NULL;
5135 D3DVERTEXELEMENT9 *pVertexElement = NULL;
5136 D3DVERTEXELEMENT9 VertexEnd = D3DDECL_END();
5137
5138 Log(("vmsvga3dDrawPrimitives %x numVertexDecls=%d numRanges=%d, cVertexDivisor=%d\n", cid, numVertexDecls, numRanges, cVertexDivisor));
5139
5140 AssertReturn(numVertexDecls && numVertexDecls <= SVGA3D_MAX_VERTEX_ARRAYS, VERR_INVALID_PARAMETER);
5141 AssertReturn(numRanges && numRanges <= SVGA3D_MAX_DRAW_PRIMITIVE_RANGES, VERR_INVALID_PARAMETER);
5142 AssertReturn(!cVertexDivisor || cVertexDivisor == numVertexDecls, VERR_INVALID_PARAMETER);
5143 /** @todo */
5144 Assert(!cVertexDivisor);
5145
5146 if ( cid >= pState->cContexts
5147 || pState->papContexts[cid]->id != cid)
5148 {
5149 Log(("vmsvga3dDrawPrimitives invalid context id!\n"));
5150 return VERR_INVALID_PARAMETER;
5151 }
5152
5153 pContext = pState->papContexts[cid];
5154
5155 /* Begin a scene before rendering anything. */
5156 hr = pContext->pDevice->BeginScene();
5157 AssertMsgReturn(hr == D3D_OK, ("BeginScene failed with %x\n", hr), VERR_INTERNAL_ERROR);
5158
5159 pVertexElement = (D3DVERTEXELEMENT9 *)RTMemAllocZ(sizeof(D3DVERTEXELEMENT9) * (numVertexDecls + 1));
5160 if (!pVertexElement)
5161 {
5162 Assert(pVertexElement);
5163 rc = VERR_INTERNAL_ERROR;
5164 goto internal_error;
5165 }
5166
5167 /* Process all vertex declarations. Each vertex buffer is represented by one stream source id. */
5168 iCurrentVertex = 0;
5169 iCurrentStreamId = 0;
5170 while (iCurrentVertex < numVertexDecls)
5171 {
5172 uint32_t sidVertex = SVGA_ID_INVALID;
5173 uint32_t iVertex;
5174 uint32_t uVertexMinOffset = 0xffffffff;
5175
5176 for (iVertex = iCurrentVertex; iVertex < numVertexDecls; iVertex++)
5177 {
5178 if ( ( sidVertex != SVGA_ID_INVALID
5179 && pVertexDecl[iVertex].array.surfaceId != sidVertex
5180 )
5181 /* We must put vertex declarations that start at a different element in another stream as d3d only handles offsets < stride. */
5182 || ( uVertexMinOffset != 0xffffffff
5183 && pVertexDecl[iVertex].array.offset >= uVertexMinOffset + pVertexDecl[iCurrentVertex].array.stride
5184 )
5185 )
5186 break;
5187 sidVertex = pVertexDecl[iVertex].array.surfaceId;
5188
5189 if (uVertexMinOffset > pVertexDecl[iVertex].array.offset)
5190 uVertexMinOffset = pVertexDecl[iVertex].array.offset;
5191 }
5192
5193 rc = vmsvga3dDrawPrimitivesProcessVertexDecls(pState, pContext, iVertex - iCurrentVertex, &pVertexDecl[iCurrentVertex], iCurrentStreamId, &pVertexElement[iCurrentVertex]);
5194 if (RT_FAILURE(rc))
5195 goto internal_error;
5196
5197 iCurrentVertex = iVertex;
5198 iCurrentStreamId++;
5199 }
5200
5201 /* Mark the end. */
5202 memcpy(&pVertexElement[numVertexDecls], &VertexEnd, sizeof(VertexEnd));
5203
5204 hr = pContext->pDevice->CreateVertexDeclaration(&pVertexElement[0],
5205 &pVertexDeclD3D);
5206 if (hr != D3D_OK)
5207 {
5208 AssertMsg(hr == D3D_OK, ("vmsvga3dDrawPrimitives: CreateVertexDeclaration failed with %x\n", hr));
5209 rc = VERR_INTERNAL_ERROR;
5210 goto internal_error;
5211 }
5212
5213 hr = pContext->pDevice->SetVertexDeclaration(pVertexDeclD3D);
5214 if (hr != D3D_OK)
5215 {
5216 AssertMsg(hr == D3D_OK, ("vmsvga3dDrawPrimitives: SetVertexDeclaration failed with %x\n", hr));
5217 rc = VERR_INTERNAL_ERROR;
5218 goto internal_error;
5219 }
5220
5221 /* Now draw the primitives. */
5222 for (unsigned iPrimitive = 0; iPrimitive < numRanges; iPrimitive++)
5223 {
5224 D3DPRIMITIVETYPE PrimitiveTypeD3D;
5225 unsigned sidIndex = pRange[iPrimitive].indexArray.surfaceId;
5226 PVMSVGA3DSURFACE pIndexSurface = NULL;
5227
5228 Log(("Primitive %d: type %s\n", iPrimitive, vmsvga3dPrimitiveType2String(pRange[iPrimitive].primType)));
5229 rc = vmsvga3dPrimitiveType2D3D(pRange[iPrimitive].primType, &PrimitiveTypeD3D);
5230 if (RT_FAILURE(rc))
5231 {
5232 AssertRC(rc);
5233 goto internal_error;
5234 }
5235
5236 /* Triangle strips or fans with just one primitive don't make much sense and are identical to triangle lists.
5237 * Workaround for NVidia driver crash when encountering some of these.
5238 */
5239 if ( pRange[iPrimitive].primitiveCount == 1
5240 && ( PrimitiveTypeD3D == D3DPT_TRIANGLESTRIP
5241 || PrimitiveTypeD3D == D3DPT_TRIANGLEFAN))
5242 PrimitiveTypeD3D = D3DPT_TRIANGLELIST;
5243
5244 if (sidIndex != SVGA3D_INVALID_ID)
5245 {
5246 AssertMsg(pRange[iPrimitive].indexWidth == sizeof(uint32_t) || pRange[iPrimitive].indexWidth == sizeof(uint16_t), ("Unsupported primitive width %d\n", pRange[iPrimitive].indexWidth));
5247
5248 if ( sidIndex >= SVGA3D_MAX_SURFACE_IDS
5249 || sidIndex >= pState->cSurfaces
5250 || pState->papSurfaces[sidIndex]->id != sidIndex)
5251 {
5252 Assert(sidIndex < SVGA3D_MAX_SURFACE_IDS);
5253 Assert(sidIndex < pState->cSurfaces && pState->papSurfaces[sidIndex]->id == sidIndex);
5254 rc = VERR_INVALID_PARAMETER;
5255 goto internal_error;
5256 }
5257 pIndexSurface = pState->papSurfaces[sidIndex];
5258 Log(("vmsvga3dDrawPrimitives: index sid=%x\n", sidIndex));
5259
5260 /* pIndexSurface->u. is an union, so pIndexSurface->u.pIndexBuffer and pIndexSurface->u.pVertexBuffer are the same */
5261 if ( pIndexSurface->u.pIndexBuffer
5262 && !(pIndexSurface->fu32ActualUsageFlags & SVGA3D_SURFACE_HINT_INDEXBUFFER))
5263 {
5264 /* The buffer object is not an index one. Switch type. */
5265 Assert(pIndexSurface->fu32ActualUsageFlags & SVGA3D_SURFACE_HINT_VERTEXBUFFER);
5266 pIndexSurface->fu32ActualUsageFlags &= ~SVGA3D_SURFACE_HINT_VERTEXBUFFER;
5267
5268 D3D_RELEASE(pIndexSurface->u.pVertexBuffer);
5269 LogFunc(("vertex -> index buffer sid=%x\n", sidIndex));
5270 }
5271
5272 if (!pIndexSurface->u.pIndexBuffer)
5273 {
5274 Log(("vmsvga3dDrawPrimitives: create index buffer fDirty=%d\n", pIndexSurface->fDirty));
5275
5276 hr = pContext->pDevice->CreateIndexBuffer(pIndexSurface->pMipmapLevels[0].cbSurface,
5277 D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY /* possible severe performance penalty otherwise (according to d3d debug output */,
5278 (pRange[iPrimitive].indexWidth == sizeof(uint16_t)) ? D3DFMT_INDEX16 : D3DFMT_INDEX32,
5279 D3DPOOL_DEFAULT,
5280 &pIndexSurface->u.pIndexBuffer,
5281 NULL);
5282 if (hr != D3D_OK)
5283 {
5284 AssertMsg(hr == D3D_OK, ("vmsvga3dDrawPrimitives: CreateIndexBuffer failed with %x\n", hr));
5285 rc = VERR_INTERNAL_ERROR;
5286 goto internal_error;
5287 }
5288
5289 if (pIndexSurface->fDirty)
5290 {
5291 void *pData;
5292
5293 Log(("vmsvga3dDrawPrimitives: sync index buffer\n"));
5294
5295 hr = pIndexSurface->u.pIndexBuffer->Lock(0, 0, &pData, 0);
5296 AssertMsg(hr == D3D_OK, ("vmsvga3dDrawPrimitives: Lock vertex failed with %x\n", hr));
5297
5298 memcpy(pData, pIndexSurface->pMipmapLevels[0].pSurfaceData, pIndexSurface->pMipmapLevels[0].cbSurface);
5299
5300 hr = pIndexSurface->u.pIndexBuffer->Unlock();
5301 AssertMsg(hr == D3D_OK, ("vmsvga3dDrawPrimitives: Unlock vertex failed with %x\n", hr));
5302
5303 pIndexSurface->pMipmapLevels[0].fDirty = false;
5304 pIndexSurface->fDirty = false;
5305 }
5306 pIndexSurface->flags |= SVGA3D_SURFACE_HINT_INDEXBUFFER;
5307 pIndexSurface->fu32ActualUsageFlags |= SVGA3D_SURFACE_HINT_INDEXBUFFER;
5308 }
5309
5310 hr = pContext->pDevice->SetIndices(pIndexSurface->u.pIndexBuffer);
5311 AssertMsg(hr == D3D_OK, ("vmsvga3dDrawPrimitives: SetIndices vertex failed with %x\n", hr));
5312 }
5313 else
5314 {
5315 hr = pContext->pDevice->SetIndices(NULL);
5316 AssertMsg(hr == D3D_OK, ("vmsvga3dDrawPrimitives: SetIndices vertex (NULL) failed with %x\n", hr));
5317 }
5318
5319 PVMSVGA3DSURFACE pVertexSurface;
5320 unsigned sidVertex = pVertexDecl[0].array.surfaceId;
5321 unsigned strideVertex = pVertexDecl[0].array.stride;
5322
5323 pVertexSurface = pState->papSurfaces[sidVertex];
5324
5325 if (!pIndexSurface)
5326 {
5327 /* Render without an index buffer */
5328 Log(("DrawPrimitive %x primitivecount=%d index index bias=%d stride=%d\n", PrimitiveTypeD3D, pRange[iPrimitive].primitiveCount, pRange[iPrimitive].indexBias, strideVertex));
5329
5330 hr = pContext->pDevice->DrawPrimitive(PrimitiveTypeD3D,
5331 pRange[iPrimitive].indexBias,
5332 pRange[iPrimitive].primitiveCount);
5333 if (hr != D3D_OK)
5334 {
5335 AssertMsg(hr == D3D_OK, ("vmsvga3dDrawPrimitives: DrawPrimitive failed with %x\n", hr));
5336 rc = VERR_INTERNAL_ERROR;
5337 goto internal_error;
5338 }
5339 }
5340 else
5341 {
5342 Assert(pRange[iPrimitive].indexBias >= 0); /** @todo */
5343
5344 UINT numVertices;
5345
5346 if (pVertexDecl[0].rangeHint.last)
5347 numVertices = pVertexDecl[0].rangeHint.last - pVertexDecl[0].rangeHint.first + 1;
5348 else
5349 numVertices = pVertexSurface->pMipmapLevels[0].cbSurface / strideVertex - pVertexDecl[0].array.offset / strideVertex - pVertexDecl[0].rangeHint.first - pRange[iPrimitive].indexBias;
5350
5351 /* Render with an index buffer */
5352 Log(("DrawIndexedPrimitive %x startindex=%d numVertices=%d, primitivecount=%d index format=%d index bias=%d stride=%d\n", PrimitiveTypeD3D, pVertexDecl[0].rangeHint.first, numVertices, pRange[iPrimitive].primitiveCount, (pRange[iPrimitive].indexWidth == sizeof(uint16_t)) ? D3DFMT_INDEX16 : D3DFMT_INDEX32, pRange[iPrimitive].indexBias, strideVertex));
5353
5354 hr = pContext->pDevice->DrawIndexedPrimitive(PrimitiveTypeD3D,
5355 pRange[iPrimitive].indexBias, /* BaseVertexIndex */
5356 0, /* MinVertexIndex */
5357 numVertices,
5358 pRange[iPrimitive].indexArray.offset / pRange[iPrimitive].indexWidth, /* StartIndex */
5359 pRange[iPrimitive].primitiveCount);
5360 if (hr != D3D_OK)
5361 {
5362 AssertMsg(hr == D3D_OK, ("vmsvga3dDrawPrimitives: DrawIndexedPrimitive failed with %x\n", hr));
5363 rc = VERR_INTERNAL_ERROR;
5364 goto internal_error;
5365 }
5366 }
5367 }
5368 D3D_RELEASE(pVertexDeclD3D);
5369 RTMemFree(pVertexElement);
5370
5371 hr = pContext->pDevice->EndScene();
5372 AssertMsgReturn(hr == D3D_OK, ("EndScene failed with %x\n", hr), VERR_INTERNAL_ERROR);
5373
5374 /* Clear streams above 1 as they might accidentally be reused in the future. */
5375 if (iCurrentStreamId > 1)
5376 {
5377 for (uint32_t i = 1; i < iCurrentStreamId; i++)
5378 {
5379 Log(("vmsvga3dDrawPrimitives: clear stream %d\n", i));
5380 hr = pContext->pDevice->SetStreamSource(i, NULL, 0, 0);
5381 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dDrawPrimitives: SetStreamSource failed with %x\n", hr), VERR_INTERNAL_ERROR);
5382 }
5383 }
5384
5385#if 0 /* Flush queue */
5386 {
5387 IDirect3DQuery9 *pQuery;
5388 hr = pContext->pDevice->CreateQuery(D3DQUERYTYPE_EVENT, &pQuery);
5389 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSurfaceTrackUsage: CreateQuery failed with %x\n", hr), VERR_INTERNAL_ERROR);
5390
5391 hr = pQuery->Issue(D3DISSUE_END);
5392 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSurfaceTrackUsage: Issue failed with %x\n", hr), VERR_INTERNAL_ERROR);
5393 while (true)
5394 {
5395 hr = pQuery->GetData(NULL, 0, D3DGETDATA_FLUSH);
5396 if (hr != S_FALSE) break;
5397
5398 RTThreadSleep(1);
5399 }
5400 AssertMsgReturn(hr == S_OK, ("vmsvga3dSurfaceFinishDrawing: GetData failed with %x\n", hr), VERR_INTERNAL_ERROR);
5401
5402 D3D_RELEASE(pQuery);
5403 }
5404#endif
5405
5406 /* Make sure we can track drawing usage of active render targets and textures. */
5407 vmsvga3dContextTrackUsage(pThis, pContext);
5408
5409#ifdef DEBUG_GFX_WINDOW
5410 if (pContext->aSidActiveTexture[0] == 0x62)
5411//// if (pContext->sidActiveTexture == 0x3d)
5412 {
5413 SVGA3dCopyRect rect;
5414
5415 rect.srcx = rect.srcy = rect.x = rect.y = 0;
5416 rect.w = 800;
5417 rect.h = 600;
5418 vmsvga3dCommandPresent(pThis, pContext->sidRenderTarget /*pContext->aSidActiveTexture[0] */, 0, &rect);
5419 }
5420#endif
5421 return rc;
5422
5423internal_error:
5424 D3D_RELEASE(pVertexDeclD3D);
5425 if (pVertexElement)
5426 RTMemFree(pVertexElement);
5427
5428 hr = pContext->pDevice->EndScene();
5429 AssertMsgReturn(hr == D3D_OK, ("EndScene failed with %x\n", hr), VERR_INTERNAL_ERROR);
5430
5431 return rc;
5432}
5433
5434int vmsvga3dSetScissorRect(PVGASTATE pThis, uint32_t cid, SVGA3dRect *pRect)
5435{
5436 HRESULT hr;
5437 RECT rect;
5438 PVMSVGA3DCONTEXT pContext;
5439 PVMSVGA3DSTATE pState = pThis->svga.p3dState;
5440 AssertReturn(pState, VERR_NO_MEMORY);
5441
5442 Log(("vmsvga3dSetScissorRect %x (%d,%d)(%d,%d)\n", cid, pRect->x, pRect->y, pRect->w, pRect->h));
5443
5444 if ( cid >= pState->cContexts
5445 || pState->papContexts[cid]->id != cid)
5446 {
5447 Log(("vmsvga3dSetScissorRect invalid context id!\n"));
5448 return VERR_INVALID_PARAMETER;
5449 }
5450 pContext = pState->papContexts[cid];
5451
5452 /* Store for vm state save/restore. */
5453 pContext->state.u32UpdateFlags |= VMSVGA3D_UPDATE_SCISSORRECT;
5454 pContext->state.RectScissor = *pRect;
5455
5456 rect.left = pRect->x;
5457 rect.top = pRect->y;
5458 rect.right = rect.left + pRect->w; /* exclusive */
5459 rect.bottom = rect.top + pRect->h; /* exclusive */
5460
5461 hr = pContext->pDevice->SetScissorRect(&rect);
5462 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSetScissorRect: SetScissorRect failed with %x\n", hr), VERR_INTERNAL_ERROR);
5463
5464 return VINF_SUCCESS;
5465}
5466
5467
5468int vmsvga3dShaderDefine(PVGASTATE pThis, uint32_t cid, uint32_t shid, SVGA3dShaderType type, uint32_t cbData, uint32_t *pShaderData)
5469{
5470 HRESULT hr;
5471 PVMSVGA3DCONTEXT pContext;
5472 PVMSVGA3DSHADER pShader;
5473 PVMSVGA3DSTATE pState = pThis->svga.p3dState;
5474 AssertReturn(pState, VERR_NO_MEMORY);
5475
5476 Log(("vmsvga3dShaderDefine %x shid=%x type=%s cbData=%x\n", cid, shid, (type == SVGA3D_SHADERTYPE_VS) ? "VERTEX" : "PIXEL", cbData));
5477#ifdef LOG_ENABLED
5478 Log3(("Shader code:\n"));
5479 const uint32_t cTokensPerLine = 8;
5480 const uint32_t *paTokens = (uint32_t *)pShaderData;
5481 const uint32_t cTokens = cbData / sizeof(uint32_t);
5482 for (uint32_t iToken = 0; iToken < cTokens; ++iToken)
5483 {
5484 if ((iToken % cTokensPerLine) == 0)
5485 {
5486 if (iToken == 0)
5487 Log3(("%08X", paTokens[iToken]));
5488 else
5489 Log3(("\n%08X", paTokens[iToken]));
5490 }
5491 else
5492 Log3((" %08X", paTokens[iToken]));
5493 }
5494 Log3(("\n"));
5495#endif
5496
5497 if ( cid >= pState->cContexts
5498 || pState->papContexts[cid]->id != cid)
5499 {
5500 Log(("vmsvga3dShaderDefine invalid context id!\n"));
5501 return VERR_INVALID_PARAMETER;
5502 }
5503 pContext = pState->papContexts[cid];
5504
5505 AssertReturn(shid < SVGA3D_MAX_SHADER_IDS, VERR_INVALID_PARAMETER);
5506 if (type == SVGA3D_SHADERTYPE_VS)
5507 {
5508 if (shid >= pContext->cVertexShaders)
5509 {
5510 void *pvNew = RTMemRealloc(pContext->paVertexShader, sizeof(VMSVGA3DSHADER) * (shid + 1));
5511 AssertReturn(pvNew, VERR_NO_MEMORY);
5512 pContext->paVertexShader = (PVMSVGA3DSHADER)pvNew;
5513 memset(&pContext->paVertexShader[pContext->cVertexShaders], 0, sizeof(VMSVGA3DSHADER) * (shid + 1 - pContext->cVertexShaders));
5514 for (uint32_t i = pContext->cVertexShaders; i < shid + 1; i++)
5515 pContext->paVertexShader[i].id = SVGA3D_INVALID_ID;
5516 pContext->cVertexShaders = shid + 1;
5517 }
5518 /* If one already exists with this id, then destroy it now. */
5519 if (pContext->paVertexShader[shid].id != SVGA3D_INVALID_ID)
5520 vmsvga3dShaderDestroy(pThis, cid, shid, pContext->paVertexShader[shid].type);
5521
5522 pShader = &pContext->paVertexShader[shid];
5523 }
5524 else
5525 {
5526 Assert(type == SVGA3D_SHADERTYPE_PS);
5527 if (shid >= pContext->cPixelShaders)
5528 {
5529 void *pvNew = RTMemRealloc(pContext->paPixelShader, sizeof(VMSVGA3DSHADER) * (shid + 1));
5530 AssertReturn(pvNew, VERR_NO_MEMORY);
5531 pContext->paPixelShader = (PVMSVGA3DSHADER)pvNew;
5532 memset(&pContext->paPixelShader[pContext->cPixelShaders], 0, sizeof(VMSVGA3DSHADER) * (shid + 1 - pContext->cPixelShaders));
5533 for (uint32_t i = pContext->cPixelShaders; i < shid + 1; i++)
5534 pContext->paPixelShader[i].id = SVGA3D_INVALID_ID;
5535 pContext->cPixelShaders = shid + 1;
5536 }
5537 /* If one already exists with this id, then destroy it now. */
5538 if (pContext->paPixelShader[shid].id != SVGA3D_INVALID_ID)
5539 vmsvga3dShaderDestroy(pThis, cid, shid, pContext->paPixelShader[shid].type);
5540
5541 pShader = &pContext->paPixelShader[shid];
5542 }
5543
5544 memset(pShader, 0, sizeof(*pShader));
5545 pShader->id = shid;
5546 pShader->cid = cid;
5547 pShader->type = type;
5548 pShader->cbData = cbData;
5549 pShader->pShaderProgram = RTMemAllocZ(cbData);
5550 AssertReturn(pShader->pShaderProgram, VERR_NO_MEMORY);
5551 memcpy(pShader->pShaderProgram, pShaderData, cbData);
5552
5553#ifdef DUMP_SHADER_DISASSEMBLY
5554 LPD3DXBUFFER pDisassembly;
5555 hr = D3DXDisassembleShader((const DWORD *)pShaderData, FALSE, NULL, &pDisassembly);
5556 if (hr == D3D_OK)
5557 {
5558 Log(("Shader disassembly:\n%s\n", pDisassembly->GetBufferPointer()));
5559 D3D_RELEASE(pDisassembly);
5560 }
5561#endif
5562
5563 switch (type)
5564 {
5565 case SVGA3D_SHADERTYPE_VS:
5566 hr = pContext->pDevice->CreateVertexShader((const DWORD *)pShaderData, &pShader->u.pVertexShader);
5567 break;
5568
5569 case SVGA3D_SHADERTYPE_PS:
5570 hr = pContext->pDevice->CreatePixelShader((const DWORD *)pShaderData, &pShader->u.pPixelShader);
5571 break;
5572
5573 default:
5574 AssertFailedReturn(VERR_INVALID_PARAMETER);
5575 }
5576 if (hr != D3D_OK)
5577 {
5578 RTMemFree(pShader->pShaderProgram);
5579 memset(pShader, 0, sizeof(*pShader));
5580 pShader->id = SVGA3D_INVALID_ID;
5581 }
5582
5583 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dShaderDefine: CreateVertex/PixelShader failed with %x\n", hr), VERR_INTERNAL_ERROR);
5584 return VINF_SUCCESS;
5585}
5586
5587int vmsvga3dShaderDestroy(PVGASTATE pThis, uint32_t cid, uint32_t shid, SVGA3dShaderType type)
5588{
5589 PVMSVGA3DCONTEXT pContext;
5590 PVMSVGA3DSTATE pState = pThis->svga.p3dState;
5591 AssertReturn(pState, VERR_NO_MEMORY);
5592 PVMSVGA3DSHADER pShader = NULL;
5593
5594 Log(("vmsvga3dShaderDestroy %x shid=%x type=%s\n", cid, shid, (type == SVGA3D_SHADERTYPE_VS) ? "VERTEX" : "PIXEL"));
5595
5596 if ( cid >= pState->cContexts
5597 || pState->papContexts[cid]->id != cid)
5598 {
5599 Log(("vmsvga3dShaderDestroy invalid context id!\n"));
5600 return VERR_INVALID_PARAMETER;
5601 }
5602 pContext = pState->papContexts[cid];
5603
5604 if (type == SVGA3D_SHADERTYPE_VS)
5605 {
5606 if ( shid < pContext->cVertexShaders
5607 && pContext->paVertexShader[shid].id == shid)
5608 {
5609 pShader = &pContext->paVertexShader[shid];
5610 D3D_RELEASE(pShader->u.pVertexShader);
5611 }
5612 }
5613 else
5614 {
5615 Assert(type == SVGA3D_SHADERTYPE_PS);
5616 if ( shid < pContext->cPixelShaders
5617 && pContext->paPixelShader[shid].id == shid)
5618 {
5619 pShader = &pContext->paPixelShader[shid];
5620 D3D_RELEASE(pShader->u.pPixelShader);
5621 }
5622 }
5623
5624 if (pShader)
5625 {
5626 if (pShader->pShaderProgram)
5627 RTMemFree(pShader->pShaderProgram);
5628
5629 memset(pShader, 0, sizeof(*pShader));
5630 pShader->id = SVGA3D_INVALID_ID;
5631 }
5632 else
5633 AssertFailedReturn(VERR_INVALID_PARAMETER);
5634
5635 return VINF_SUCCESS;
5636}
5637
5638int vmsvga3dShaderSet(PVGASTATE pThis, PVMSVGA3DCONTEXT pContext, uint32_t cid, SVGA3dShaderType type, uint32_t shid)
5639{
5640 PVMSVGA3DSTATE pState = pThis->svga.p3dState;
5641 AssertReturn(pState, VERR_NO_MEMORY);
5642 HRESULT hr;
5643
5644 Log(("vmsvga3dShaderSet %x type=%s shid=%d\n", cid, (type == SVGA3D_SHADERTYPE_VS) ? "VERTEX" : "PIXEL", shid));
5645
5646 NOREF(pContext);
5647 if ( cid >= pState->cContexts
5648 || pState->papContexts[cid]->id != cid)
5649 {
5650 Log(("vmsvga3dShaderSet invalid context id!\n"));
5651 return VERR_INVALID_PARAMETER;
5652 }
5653 pContext = pState->papContexts[cid];
5654
5655 if (type == SVGA3D_SHADERTYPE_VS)
5656 {
5657 /* Save for vm state save/restore. */
5658 pContext->state.shidVertex = shid;
5659 pContext->state.u32UpdateFlags |= VMSVGA3D_UPDATE_VERTEXSHADER;
5660
5661 if ( shid < pContext->cVertexShaders
5662 && pContext->paVertexShader[shid].id == shid)
5663 {
5664 PVMSVGA3DSHADER pShader = &pContext->paVertexShader[shid];
5665 Assert(type == pShader->type);
5666
5667 hr = pContext->pDevice->SetVertexShader(pShader->u.pVertexShader);
5668 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dShaderSet: SetVertex/PixelShader failed with %x\n", hr), VERR_INTERNAL_ERROR);
5669 }
5670 else
5671 if (shid == SVGA_ID_INVALID)
5672 {
5673 /* Unselect shader. */
5674 hr = pContext->pDevice->SetVertexShader(NULL);
5675 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dShaderSet: SetVertex/PixelShader failed with %x\n", hr), VERR_INTERNAL_ERROR);
5676 }
5677 else
5678 AssertFailedReturn(VERR_INVALID_PARAMETER);
5679 }
5680 else
5681 {
5682 /* Save for vm state save/restore. */
5683 pContext->state.shidPixel = shid;
5684 pContext->state.u32UpdateFlags |= VMSVGA3D_UPDATE_PIXELSHADER;
5685
5686 Assert(type == SVGA3D_SHADERTYPE_PS);
5687 if ( shid < pContext->cPixelShaders
5688 && pContext->paPixelShader[shid].id == shid)
5689 {
5690 PVMSVGA3DSHADER pShader = &pContext->paPixelShader[shid];
5691 Assert(type == pShader->type);
5692
5693 hr = pContext->pDevice->SetPixelShader(pShader->u.pPixelShader);
5694 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dShaderSet: SetVertex/PixelShader failed with %x\n", hr), VERR_INTERNAL_ERROR);
5695 }
5696 else
5697 if (shid == SVGA_ID_INVALID)
5698 {
5699 /* Unselect shader. */
5700 hr = pContext->pDevice->SetPixelShader(NULL);
5701 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dShaderSet: SetVertex/PixelShader failed with %x\n", hr), VERR_INTERNAL_ERROR);
5702 }
5703 else
5704 AssertFailedReturn(VERR_INVALID_PARAMETER);
5705 }
5706
5707 return VINF_SUCCESS;
5708}
5709
5710int vmsvga3dShaderSetConst(PVGASTATE pThis, uint32_t cid, uint32_t reg, SVGA3dShaderType type, SVGA3dShaderConstType ctype, uint32_t cRegisters, uint32_t *pValues)
5711{
5712 HRESULT hr;
5713 PVMSVGA3DCONTEXT pContext;
5714 PVMSVGA3DSTATE pState = pThis->svga.p3dState;
5715 AssertReturn(pState, VERR_NO_MEMORY);
5716
5717 Log(("vmsvga3dShaderSetConst %x reg=%x type=%s ctype=%x\n", cid, reg, (type == SVGA3D_SHADERTYPE_VS) ? "VERTEX" : "PIXEL", ctype));
5718
5719 if ( cid >= pState->cContexts
5720 || pState->papContexts[cid]->id != cid)
5721 {
5722 Log(("vmsvga3dShaderSetConst invalid context id!\n"));
5723 return VERR_INVALID_PARAMETER;
5724 }
5725 pContext = pState->papContexts[cid];
5726
5727 for (uint32_t i = 0; i < cRegisters; i++)
5728 {
5729 Log(("Constant %d: value=%x-%x-%x-%x\n", reg + i, pValues[i*4 + 0], pValues[i*4 + 1], pValues[i*4 + 2], pValues[i*4 + 3]));
5730 vmsvga3dSaveShaderConst(pContext, reg + i, type, ctype, pValues[i*4 + 0], pValues[i*4 + 1], pValues[i*4 + 2], pValues[i*4 + 3]);
5731 }
5732
5733 switch (type)
5734 {
5735 case SVGA3D_SHADERTYPE_VS:
5736 switch (ctype)
5737 {
5738 case SVGA3D_CONST_TYPE_FLOAT:
5739 hr = pContext->pDevice->SetVertexShaderConstantF(reg, (const float *)pValues, cRegisters);
5740 break;
5741
5742 case SVGA3D_CONST_TYPE_INT:
5743 hr = pContext->pDevice->SetVertexShaderConstantI(reg, (const int *)pValues, cRegisters);
5744 break;
5745
5746 case SVGA3D_CONST_TYPE_BOOL:
5747 hr = pContext->pDevice->SetVertexShaderConstantB(reg, (const BOOL *)pValues, cRegisters);
5748 break;
5749
5750 default:
5751 AssertFailedReturn(VERR_INVALID_PARAMETER);
5752 }
5753 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dShaderSetConst: SetVertexShader failed with %x\n", hr), VERR_INTERNAL_ERROR);
5754 break;
5755
5756 case SVGA3D_SHADERTYPE_PS:
5757 switch (ctype)
5758 {
5759 case SVGA3D_CONST_TYPE_FLOAT:
5760 {
5761 hr = pContext->pDevice->SetPixelShaderConstantF(reg, (const float *)pValues, cRegisters);
5762 break;
5763 }
5764
5765 case SVGA3D_CONST_TYPE_INT:
5766 hr = pContext->pDevice->SetPixelShaderConstantI(reg, (const int *)pValues, cRegisters);
5767 break;
5768
5769 case SVGA3D_CONST_TYPE_BOOL:
5770 hr = pContext->pDevice->SetPixelShaderConstantB(reg, (const BOOL *)pValues, cRegisters);
5771 break;
5772
5773 default:
5774 AssertFailedReturn(VERR_INVALID_PARAMETER);
5775 }
5776 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dShaderSetConst: SetPixelShader failed with %x\n", hr), VERR_INTERNAL_ERROR);
5777 break;
5778
5779 default:
5780 AssertFailedReturn(VERR_INVALID_PARAMETER);
5781 }
5782 return VINF_SUCCESS;
5783}
5784
5785
5786int vmsvga3dQueryBegin(PVGASTATE pThis, uint32_t cid, SVGA3dQueryType type)
5787{
5788 RT_NOREF(pThis, cid, type);
5789 AssertFailed();
5790 return VERR_NOT_IMPLEMENTED;
5791}
5792
5793int vmsvga3dQueryEnd(PVGASTATE pThis, uint32_t cid, SVGA3dQueryType type, SVGAGuestPtr guestResult)
5794{
5795 RT_NOREF(pThis, cid, type, guestResult);
5796 AssertFailed();
5797 return VERR_NOT_IMPLEMENTED;
5798}
5799
5800int vmsvga3dQueryWait(PVGASTATE pThis, uint32_t cid, SVGA3dQueryType type, SVGAGuestPtr guestResult)
5801{
5802 RT_NOREF(pThis, cid, type, guestResult);
5803 AssertFailed();
5804 return VERR_NOT_IMPLEMENTED;
5805}
5806
5807static void vmsvgaDumpD3DCaps(D3DCAPS9 *pCaps)
5808{
5809 bool const fBufferingSaved = RTLogRelSetBuffering(true /*fBuffered*/);
5810
5811 LogRel(("\nD3D device caps: DevCaps2:\n"));
5812 if (pCaps->DevCaps2 & D3DDEVCAPS2_ADAPTIVETESSRTPATCH)
5813 LogRel((" - D3DDEVCAPS2_ADAPTIVETESSRTPATCH\n"));
5814 if (pCaps->DevCaps2 & D3DDEVCAPS2_ADAPTIVETESSNPATCH)
5815 LogRel((" - D3DDEVCAPS2_ADAPTIVETESSNPATCH\n"));
5816 if (pCaps->DevCaps2 & D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES)
5817 LogRel((" - D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES\n"));
5818 if (pCaps->DevCaps2 & D3DDEVCAPS2_DMAPNPATCH)
5819 LogRel((" - D3DDEVCAPS2_DMAPNPATCH\n"));
5820 if (pCaps->DevCaps2 & D3DDEVCAPS2_PRESAMPLEDDMAPNPATCH)
5821 LogRel((" - D3DDEVCAPS2_PRESAMPLEDDMAPNPATCH\n"));
5822 if (pCaps->DevCaps2 & D3DDEVCAPS2_STREAMOFFSET)
5823 LogRel((" - D3DDEVCAPS2_STREAMOFFSET\n"));
5824 if (pCaps->DevCaps2 & D3DDEVCAPS2_VERTEXELEMENTSCANSHARESTREAMOFFSET)
5825 LogRel((" - D3DDEVCAPS2_VERTEXELEMENTSCANSHARESTREAMOFFSET\n"));
5826
5827 LogRel(("\nCaps2:\n"));
5828 if (pCaps->Caps2 & D3DCAPS2_CANAUTOGENMIPMAP)
5829 LogRel((" - D3DCAPS2_CANAUTOGENMIPMAP\n"));
5830 if (pCaps->Caps2 & D3DCAPS2_CANCALIBRATEGAMMA)
5831 LogRel((" - D3DCAPS2_CANCALIBRATEGAMMA\n"));
5832 if (pCaps->Caps2 & D3DCAPS2_CANSHARERESOURCE)
5833 LogRel((" - D3DCAPS2_CANSHARERESOURCE\n"));
5834 if (pCaps->Caps2 & D3DCAPS2_CANMANAGERESOURCE)
5835 LogRel((" - D3DCAPS2_CANMANAGERESOURCE\n"));
5836 if (pCaps->Caps2 & D3DCAPS2_DYNAMICTEXTURES)
5837 LogRel((" - D3DCAPS2_DYNAMICTEXTURES\n"));
5838 if (pCaps->Caps2 & D3DCAPS2_FULLSCREENGAMMA)
5839 LogRel((" - D3DCAPS2_FULLSCREENGAMMA\n"));
5840
5841 LogRel(("\nCaps3:\n"));
5842 if (pCaps->Caps3 & D3DCAPS3_ALPHA_FULLSCREEN_FLIP_OR_DISCARD)
5843 LogRel((" - D3DCAPS3_ALPHA_FULLSCREEN_FLIP_OR_DISCARD\n"));
5844 if (pCaps->Caps3 & D3DCAPS3_COPY_TO_VIDMEM)
5845 LogRel((" - D3DCAPS3_COPY_TO_VIDMEM\n"));
5846 if (pCaps->Caps3 & D3DCAPS3_COPY_TO_SYSTEMMEM)
5847 LogRel((" - D3DCAPS3_COPY_TO_SYSTEMMEM\n"));
5848 if (pCaps->Caps3 & D3DCAPS3_DXVAHD)
5849 LogRel((" - D3DCAPS3_DXVAHD\n"));
5850 if (pCaps->Caps3 & D3DCAPS3_LINEAR_TO_SRGB_PRESENTATION)
5851 LogRel((" - D3DCAPS3_LINEAR_TO_SRGB_PRESENTATION\n"));
5852
5853 LogRel(("\nPresentationIntervals:\n"));
5854 if (pCaps->PresentationIntervals & D3DPRESENT_INTERVAL_IMMEDIATE)
5855 LogRel((" - D3DPRESENT_INTERVAL_IMMEDIATE\n"));
5856 if (pCaps->PresentationIntervals & D3DPRESENT_INTERVAL_ONE)
5857 LogRel((" - D3DPRESENT_INTERVAL_ONE\n"));
5858 if (pCaps->PresentationIntervals & D3DPRESENT_INTERVAL_TWO)
5859 LogRel((" - D3DPRESENT_INTERVAL_TWO\n"));
5860 if (pCaps->PresentationIntervals & D3DPRESENT_INTERVAL_THREE)
5861 LogRel((" - D3DPRESENT_INTERVAL_THREE\n"));
5862 if (pCaps->PresentationIntervals & D3DPRESENT_INTERVAL_FOUR)
5863 LogRel((" - D3DPRESENT_INTERVAL_FOUR\n"));
5864
5865 LogRel(("\nDevcaps:\n"));
5866 if (pCaps->DevCaps & D3DDEVCAPS_CANBLTSYSTONONLOCAL)
5867 LogRel((" - D3DDEVCAPS_CANBLTSYSTONONLOCAL\n"));
5868 if (pCaps->DevCaps & D3DDEVCAPS_CANRENDERAFTERFLIP)
5869 LogRel((" - D3DDEVCAPS_CANRENDERAFTERFLIP\n"));
5870 if (pCaps->DevCaps & D3DDEVCAPS_DRAWPRIMITIVES2)
5871 LogRel((" - D3DDEVCAPS_DRAWPRIMITIVES2\n"));
5872 if (pCaps->DevCaps & D3DDEVCAPS_DRAWPRIMITIVES2EX)
5873 LogRel((" - D3DDEVCAPS_DRAWPRIMITIVES2EX\n"));
5874 if (pCaps->DevCaps & D3DDEVCAPS_DRAWPRIMTLVERTEX)
5875 LogRel((" - D3DDEVCAPS_DRAWPRIMTLVERTEX\n"));
5876 if (pCaps->DevCaps & D3DDEVCAPS_EXECUTESYSTEMMEMORY)
5877 LogRel((" - D3DDEVCAPS_EXECUTESYSTEMMEMORY\n"));
5878 if (pCaps->DevCaps & D3DDEVCAPS_EXECUTEVIDEOMEMORY)
5879 LogRel((" - D3DDEVCAPS_EXECUTEVIDEOMEMORY\n"));
5880 if (pCaps->DevCaps & D3DDEVCAPS_HWRASTERIZATION)
5881 LogRel((" - D3DDEVCAPS_HWRASTERIZATION\n"));
5882 if (pCaps->DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT)
5883 LogRel((" - D3DDEVCAPS_HWTRANSFORMANDLIGHT\n"));
5884 if (pCaps->DevCaps & D3DDEVCAPS_NPATCHES)
5885 LogRel((" - D3DDEVCAPS_NPATCHES\n"));
5886 if (pCaps->DevCaps & D3DDEVCAPS_PUREDEVICE)
5887 LogRel((" - D3DDEVCAPS_PUREDEVICE\n"));
5888 if (pCaps->DevCaps & D3DDEVCAPS_QUINTICRTPATCHES)
5889 LogRel((" - D3DDEVCAPS_QUINTICRTPATCHES\n"));
5890 if (pCaps->DevCaps & D3DDEVCAPS_RTPATCHES)
5891 LogRel((" - D3DDEVCAPS_RTPATCHES\n"));
5892 if (pCaps->DevCaps & D3DDEVCAPS_RTPATCHHANDLEZERO)
5893 LogRel((" - D3DDEVCAPS_RTPATCHHANDLEZERO\n"));
5894 if (pCaps->DevCaps & D3DDEVCAPS_SEPARATETEXTUREMEMORIES)
5895 LogRel((" - D3DDEVCAPS_SEPARATETEXTUREMEMORIES\n"));
5896 if (pCaps->DevCaps & D3DDEVCAPS_TEXTURENONLOCALVIDMEM)
5897 LogRel((" - D3DDEVCAPS_TEXTURENONLOCALVIDMEM\n"));
5898 if (pCaps->DevCaps & D3DDEVCAPS_TEXTURESYSTEMMEMORY)
5899 LogRel((" - D3DDEVCAPS_TEXTURESYSTEMMEMORY\n"));
5900 if (pCaps->DevCaps & D3DDEVCAPS_TEXTUREVIDEOMEMORY)
5901 LogRel((" - D3DDEVCAPS_TEXTUREVIDEOMEMORY\n"));
5902 if (pCaps->DevCaps & D3DDEVCAPS_TLVERTEXSYSTEMMEMORY)
5903 LogRel((" - D3DDEVCAPS_TLVERTEXSYSTEMMEMORY\n"));
5904 if (pCaps->DevCaps & D3DDEVCAPS_TLVERTEXVIDEOMEMORY)
5905 LogRel((" - D3DDEVCAPS_TLVERTEXVIDEOMEMORY\n"));
5906
5907 LogRel(("\nTextureCaps:\n"));
5908 if (pCaps->TextureCaps & D3DPTEXTURECAPS_ALPHA)
5909 LogRel((" - D3DPTEXTURECAPS_ALPHA\n"));
5910 if (pCaps->TextureCaps & D3DPTEXTURECAPS_ALPHAPALETTE)
5911 LogRel((" - D3DPTEXTURECAPS_ALPHAPALETTE\n"));
5912 if (pCaps->TextureCaps & D3DPTEXTURECAPS_CUBEMAP)
5913 LogRel((" - D3DPTEXTURECAPS_CUBEMAP\n"));
5914 if (pCaps->TextureCaps & D3DPTEXTURECAPS_CUBEMAP_POW2)
5915 LogRel((" - D3DPTEXTURECAPS_CUBEMAP_POW2\n"));
5916 if (pCaps->TextureCaps & D3DPTEXTURECAPS_MIPCUBEMAP)
5917 LogRel((" - D3DPTEXTURECAPS_MIPCUBEMAP\n"));
5918 if (pCaps->TextureCaps & D3DPTEXTURECAPS_MIPMAP)
5919 LogRel((" - D3DPTEXTURECAPS_MIPMAP\n"));
5920 if (pCaps->TextureCaps & D3DPTEXTURECAPS_MIPVOLUMEMAP)
5921 LogRel((" - D3DPTEXTURECAPS_MIPVOLUMEMAP\n"));
5922 if (pCaps->TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL)
5923 LogRel((" - D3DPTEXTURECAPS_NONPOW2CONDITIONAL\n"));
5924 if (pCaps->TextureCaps & D3DPTEXTURECAPS_POW2)
5925 LogRel((" - D3DPTEXTURECAPS_POW2\n"));
5926 if (pCaps->TextureCaps & D3DPTEXTURECAPS_NOPROJECTEDBUMPENV)
5927 LogRel((" - D3DPTEXTURECAPS_NOPROJECTEDBUMPENV\n"));
5928 if (pCaps->TextureCaps & D3DPTEXTURECAPS_PERSPECTIVE)
5929 LogRel((" - D3DPTEXTURECAPS_PERSPECTIVE\n"));
5930 if (pCaps->TextureCaps & D3DPTEXTURECAPS_POW2)
5931 LogRel((" - D3DPTEXTURECAPS_POW2\n"));
5932 if (pCaps->TextureCaps & D3DPTEXTURECAPS_PROJECTED)
5933 LogRel((" - D3DPTEXTURECAPS_PROJECTED\n"));
5934 if (pCaps->TextureCaps & D3DPTEXTURECAPS_SQUAREONLY)
5935 LogRel((" - D3DPTEXTURECAPS_SQUAREONLY\n"));
5936 if (pCaps->TextureCaps & D3DPTEXTURECAPS_TEXREPEATNOTSCALEDBYSIZE)
5937 LogRel((" - D3DPTEXTURECAPS_TEXREPEATNOTSCALEDBYSIZE\n"));
5938 if (pCaps->TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP)
5939 LogRel((" - D3DPTEXTURECAPS_VOLUMEMAP\n"));
5940 if (pCaps->TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP_POW2)
5941 LogRel((" - D3DPTEXTURECAPS_VOLUMEMAP_POW2\n"));
5942
5943 LogRel(("\nTextureFilterCaps\n"));
5944 if (pCaps->TextureFilterCaps & D3DPTFILTERCAPS_CONVOLUTIONMONO)
5945 LogRel((" - D3DPTFILTERCAPS_CONVOLUTIONMONO\n"));
5946 if (pCaps->TextureFilterCaps & D3DPTFILTERCAPS_MAGFPOINT)
5947 LogRel((" - D3DPTFILTERCAPS_MAGFPOINT\n"));
5948 if (pCaps->TextureFilterCaps & D3DPTFILTERCAPS_MAGFLINEAR)
5949 LogRel((" - D3DPTFILTERCAPS_MAGFLINEAR\n"));
5950 if (pCaps->TextureFilterCaps & D3DPTFILTERCAPS_MAGFANISOTROPIC)
5951 LogRel((" - D3DPTFILTERCAPS_MAGFANISOTROPIC\n"));
5952 if (pCaps->TextureFilterCaps & D3DPTFILTERCAPS_MAGFPYRAMIDALQUAD)
5953 LogRel((" - D3DPTFILTERCAPS_MAGFPYRAMIDALQUAD\n"));
5954 if (pCaps->TextureFilterCaps & D3DPTFILTERCAPS_MAGFGAUSSIANQUAD)
5955 LogRel((" - D3DPTFILTERCAPS_MAGFGAUSSIANQUAD\n"));
5956 if (pCaps->TextureFilterCaps & D3DPTFILTERCAPS_MINFPOINT)
5957 LogRel((" - D3DPTFILTERCAPS_MINFPOINT\n"));
5958 if (pCaps->TextureFilterCaps & D3DPTFILTERCAPS_MINFLINEAR)
5959 LogRel((" - D3DPTFILTERCAPS_MINFLINEAR\n"));
5960 if (pCaps->TextureFilterCaps & D3DPTFILTERCAPS_MINFANISOTROPIC)
5961 LogRel((" - D3DPTFILTERCAPS_MINFANISOTROPIC\n"));
5962 if (pCaps->TextureFilterCaps & D3DPTFILTERCAPS_MINFPYRAMIDALQUAD)
5963 LogRel((" - D3DPTFILTERCAPS_MINFPYRAMIDALQUAD\n"));
5964 if (pCaps->TextureFilterCaps & D3DPTFILTERCAPS_MINFGAUSSIANQUAD)
5965 LogRel((" - D3DPTFILTERCAPS_MINFGAUSSIANQUAD\n"));
5966 if (pCaps->TextureFilterCaps & D3DPTFILTERCAPS_MIPFPOINT)
5967 LogRel((" - D3DPTFILTERCAPS_MIPFPOINT\n"));
5968 if (pCaps->TextureFilterCaps & D3DPTFILTERCAPS_MIPFLINEAR)
5969 LogRel((" - D3DPTFILTERCAPS_MIPFLINEAR\n"));
5970
5971 LogRel(("\nCubeTextureFilterCaps\n"));
5972 if (pCaps->CubeTextureFilterCaps & D3DPTFILTERCAPS_CONVOLUTIONMONO)
5973 LogRel((" - D3DPTFILTERCAPS_CONVOLUTIONMONO\n"));
5974 if (pCaps->CubeTextureFilterCaps & D3DPTFILTERCAPS_MAGFPOINT)
5975 LogRel((" - D3DPTFILTERCAPS_MAGFPOINT\n"));
5976 if (pCaps->CubeTextureFilterCaps & D3DPTFILTERCAPS_MAGFLINEAR)
5977 LogRel((" - D3DPTFILTERCAPS_MAGFLINEAR\n"));
5978 if (pCaps->CubeTextureFilterCaps & D3DPTFILTERCAPS_MAGFANISOTROPIC)
5979 LogRel((" - D3DPTFILTERCAPS_MAGFANISOTROPIC\n"));
5980 if (pCaps->CubeTextureFilterCaps & D3DPTFILTERCAPS_MAGFPYRAMIDALQUAD)
5981 LogRel((" - D3DPTFILTERCAPS_MAGFPYRAMIDALQUAD\n"));
5982 if (pCaps->CubeTextureFilterCaps & D3DPTFILTERCAPS_MAGFGAUSSIANQUAD)
5983 LogRel((" - D3DPTFILTERCAPS_MAGFGAUSSIANQUAD\n"));
5984 if (pCaps->CubeTextureFilterCaps & D3DPTFILTERCAPS_MINFPOINT)
5985 LogRel((" - D3DPTFILTERCAPS_MINFPOINT\n"));
5986 if (pCaps->CubeTextureFilterCaps & D3DPTFILTERCAPS_MINFLINEAR)
5987 LogRel((" - D3DPTFILTERCAPS_MINFLINEAR\n"));
5988 if (pCaps->CubeTextureFilterCaps & D3DPTFILTERCAPS_MINFANISOTROPIC)
5989 LogRel((" - D3DPTFILTERCAPS_MINFANISOTROPIC\n"));
5990 if (pCaps->CubeTextureFilterCaps & D3DPTFILTERCAPS_MINFPYRAMIDALQUAD)
5991 LogRel((" - D3DPTFILTERCAPS_MINFPYRAMIDALQUAD\n"));
5992 if (pCaps->CubeTextureFilterCaps & D3DPTFILTERCAPS_MINFGAUSSIANQUAD)
5993 LogRel((" - D3DPTFILTERCAPS_MINFGAUSSIANQUAD\n"));
5994 if (pCaps->CubeTextureFilterCaps & D3DPTFILTERCAPS_MIPFPOINT)
5995 LogRel((" - D3DPTFILTERCAPS_MIPFPOINT\n"));
5996 if (pCaps->CubeTextureFilterCaps & D3DPTFILTERCAPS_MIPFLINEAR)
5997 LogRel((" - D3DPTFILTERCAPS_MIPFLINEAR\n"));
5998
5999 LogRel(("\nVolumeTextureFilterCaps\n"));
6000 if (pCaps->VolumeTextureFilterCaps & D3DPTFILTERCAPS_CONVOLUTIONMONO)
6001 LogRel((" - D3DPTFILTERCAPS_CONVOLUTIONMONO\n"));
6002 if (pCaps->VolumeTextureFilterCaps & D3DPTFILTERCAPS_MAGFPOINT)
6003 LogRel((" - D3DPTFILTERCAPS_MAGFPOINT\n"));
6004 if (pCaps->VolumeTextureFilterCaps & D3DPTFILTERCAPS_MAGFLINEAR)
6005 LogRel((" - D3DPTFILTERCAPS_MAGFLINEAR\n"));
6006 if (pCaps->VolumeTextureFilterCaps & D3DPTFILTERCAPS_MAGFANISOTROPIC)
6007 LogRel((" - D3DPTFILTERCAPS_MAGFANISOTROPIC\n"));
6008 if (pCaps->VolumeTextureFilterCaps & D3DPTFILTERCAPS_MAGFPYRAMIDALQUAD)
6009 LogRel((" - D3DPTFILTERCAPS_MAGFPYRAMIDALQUAD\n"));
6010 if (pCaps->VolumeTextureFilterCaps & D3DPTFILTERCAPS_MAGFGAUSSIANQUAD)
6011 LogRel((" - D3DPTFILTERCAPS_MAGFGAUSSIANQUAD\n"));
6012 if (pCaps->VolumeTextureFilterCaps & D3DPTFILTERCAPS_MINFPOINT)
6013 LogRel((" - D3DPTFILTERCAPS_MINFPOINT\n"));
6014 if (pCaps->VolumeTextureFilterCaps & D3DPTFILTERCAPS_MINFLINEAR)
6015 LogRel((" - D3DPTFILTERCAPS_MINFLINEAR\n"));
6016 if (pCaps->VolumeTextureFilterCaps & D3DPTFILTERCAPS_MINFANISOTROPIC)
6017 LogRel((" - D3DPTFILTERCAPS_MINFANISOTROPIC\n"));
6018 if (pCaps->VolumeTextureFilterCaps & D3DPTFILTERCAPS_MINFPYRAMIDALQUAD)
6019 LogRel((" - D3DPTFILTERCAPS_MINFPYRAMIDALQUAD\n"));
6020 if (pCaps->VolumeTextureFilterCaps & D3DPTFILTERCAPS_MINFGAUSSIANQUAD)
6021 LogRel((" - D3DPTFILTERCAPS_MINFGAUSSIANQUAD\n"));
6022 if (pCaps->VolumeTextureFilterCaps & D3DPTFILTERCAPS_MIPFPOINT)
6023 LogRel((" - D3DPTFILTERCAPS_MIPFPOINT\n"));
6024 if (pCaps->VolumeTextureFilterCaps & D3DPTFILTERCAPS_MIPFLINEAR)
6025 LogRel((" - D3DPTFILTERCAPS_MIPFLINEAR\n"));
6026
6027 LogRel(("\nTextureAddressCaps:\n"));
6028 if (pCaps->TextureAddressCaps & D3DPTADDRESSCAPS_BORDER)
6029 LogRel((" - D3DPTADDRESSCAPS_BORDER\n"));
6030 if (pCaps->TextureAddressCaps & D3DPTADDRESSCAPS_CLAMP)
6031 LogRel((" - D3DPTADDRESSCAPS_CLAMP\n"));
6032 if (pCaps->TextureAddressCaps & D3DPTADDRESSCAPS_INDEPENDENTUV)
6033 LogRel((" - D3DPTADDRESSCAPS_INDEPENDENTUV\n"));
6034 if (pCaps->TextureAddressCaps & D3DPTADDRESSCAPS_MIRROR)
6035 LogRel((" - D3DPTADDRESSCAPS_MIRROR\n"));
6036 if (pCaps->TextureAddressCaps & D3DPTADDRESSCAPS_MIRRORONCE)
6037 LogRel((" - D3DPTADDRESSCAPS_MIRRORONCE\n"));
6038 if (pCaps->TextureAddressCaps & D3DPTADDRESSCAPS_WRAP)
6039 LogRel((" - D3DPTADDRESSCAPS_WRAP\n"));
6040
6041 LogRel(("\nTextureOpCaps:\n"));
6042 if (pCaps->TextureOpCaps & D3DTEXOPCAPS_DISABLE)
6043 LogRel((" - D3DTEXOPCAPS_DISABLE\n"));
6044 if (pCaps->TextureOpCaps & D3DTEXOPCAPS_SELECTARG1)
6045 LogRel((" - D3DTEXOPCAPS_SELECTARG1\n"));
6046 if (pCaps->TextureOpCaps & D3DTEXOPCAPS_SELECTARG2)
6047 LogRel((" - D3DTEXOPCAPS_SELECTARG2\n"));
6048 if (pCaps->TextureOpCaps & D3DTEXOPCAPS_MODULATE)
6049 LogRel((" - D3DTEXOPCAPS_MODULATE\n"));
6050 if (pCaps->TextureOpCaps & D3DTEXOPCAPS_MODULATE2X)
6051 LogRel((" - D3DTEXOPCAPS_MODULATE2X\n"));
6052 if (pCaps->TextureOpCaps & D3DTEXOPCAPS_MODULATE4X)
6053 LogRel((" - D3DTEXOPCAPS_MODULATE4X\n"));
6054 if (pCaps->TextureOpCaps & D3DTEXOPCAPS_ADD)
6055 LogRel((" - D3DTEXOPCAPS_ADD\n"));
6056 if (pCaps->TextureOpCaps & D3DTEXOPCAPS_ADDSIGNED)
6057 LogRel((" - D3DTEXOPCAPS_ADDSIGNED\n"));
6058 if (pCaps->TextureOpCaps & D3DTEXOPCAPS_ADDSIGNED2X)
6059 LogRel((" - D3DTEXOPCAPS_ADDSIGNED2X\n"));
6060 if (pCaps->TextureOpCaps & D3DTEXOPCAPS_SUBTRACT)
6061 LogRel((" - D3DTEXOPCAPS_SUBTRACT\n"));
6062 if (pCaps->TextureOpCaps & D3DTEXOPCAPS_ADDSMOOTH)
6063 LogRel((" - D3DTEXOPCAPS_ADDSMOOTH\n"));
6064 if (pCaps->TextureOpCaps & D3DTEXOPCAPS_BLENDDIFFUSEALPHA)
6065 LogRel((" - D3DTEXOPCAPS_BLENDDIFFUSEALPHA\n"));
6066 if (pCaps->TextureOpCaps & D3DTEXOPCAPS_BLENDTEXTUREALPHA)
6067 LogRel((" - D3DTEXOPCAPS_BLENDTEXTUREALPHA\n"));
6068 if (pCaps->TextureOpCaps & D3DTEXOPCAPS_BLENDFACTORALPHA)
6069 LogRel((" - D3DTEXOPCAPS_BLENDFACTORALPHA\n"));
6070 if (pCaps->TextureOpCaps & D3DTEXOPCAPS_BLENDTEXTUREALPHAPM)
6071 LogRel((" - D3DTEXOPCAPS_BLENDTEXTUREALPHAPM\n"));
6072 if (pCaps->TextureOpCaps & D3DTEXOPCAPS_BLENDCURRENTALPHA)
6073 LogRel((" - D3DTEXOPCAPS_BLENDCURRENTALPHA\n"));
6074 if (pCaps->TextureOpCaps & D3DTEXOPCAPS_PREMODULATE)
6075 LogRel((" - D3DTEXOPCAPS_PREMODULATE\n"));
6076 if (pCaps->TextureOpCaps & D3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR)
6077 LogRel((" - D3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR\n"));
6078 if (pCaps->TextureOpCaps & D3DTEXOPCAPS_MODULATECOLOR_ADDALPHA)
6079 LogRel((" - D3DTEXOPCAPS_MODULATECOLOR_ADDALPHA\n"));
6080 if (pCaps->TextureOpCaps & D3DTEXOPCAPS_MODULATEINVALPHA_ADDCOLOR)
6081 LogRel((" - D3DTEXOPCAPS_MODULATEINVALPHA_ADDCOLOR\n"));
6082 if (pCaps->TextureOpCaps & D3DTEXOPCAPS_MODULATEINVCOLOR_ADDALPHA)
6083 LogRel((" - D3DTEXOPCAPS_MODULATEINVCOLOR_ADDALPHA\n"));
6084 if (pCaps->TextureOpCaps & D3DTEXOPCAPS_BUMPENVMAP)
6085 LogRel((" - D3DTEXOPCAPS_BUMPENVMAP\n"));
6086 if (pCaps->TextureOpCaps & D3DTEXOPCAPS_BUMPENVMAPLUMINANCE)
6087 LogRel((" - D3DTEXOPCAPS_BUMPENVMAPLUMINANCE\n"));
6088 if (pCaps->TextureOpCaps & D3DTEXOPCAPS_DOTPRODUCT3)
6089 LogRel((" - D3DTEXOPCAPS_DOTPRODUCT3\n"));
6090 if (pCaps->TextureOpCaps & D3DTEXOPCAPS_MULTIPLYADD)
6091 LogRel((" - D3DTEXOPCAPS_MULTIPLYADD\n"));
6092 if (pCaps->TextureOpCaps & D3DTEXOPCAPS_LERP)
6093 LogRel((" - D3DTEXOPCAPS_LERP\n"));
6094
6095
6096 LogRel(("\n"));
6097 LogRel(("PixelShaderVersion: %#x (%u.%u)\n", pCaps->PixelShaderVersion,
6098 D3DSHADER_VERSION_MAJOR(pCaps->PixelShaderVersion), D3DSHADER_VERSION_MINOR(pCaps->PixelShaderVersion)));
6099 LogRel(("VertexShaderVersion: %#x (%u.%u)\n", pCaps->VertexShaderVersion,
6100 D3DSHADER_VERSION_MAJOR(pCaps->VertexShaderVersion), D3DSHADER_VERSION_MINOR(pCaps->VertexShaderVersion)));
6101
6102 LogRel(("\n"));
6103 RTLogRelSetBuffering(fBufferingSaved);
6104}
6105
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