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