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