1 | /* $Id: DevVGA-SVGA3d-savedstate.cpp 95008 2022-05-13 16:20:40Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * DevSVGA3d - VMWare SVGA device, 3D parts - Saved state and assocated stuff.
|
---|
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 <iprt/errcore.h>
|
---|
25 | #include <VBox/log.h>
|
---|
26 |
|
---|
27 | #include <iprt/assert.h>
|
---|
28 | #include <iprt/mem.h>
|
---|
29 |
|
---|
30 | #include <VBox/vmm/pgm.h> /* required by DevVGA.h */
|
---|
31 | #include <VBoxVideo.h> /* required by DevVGA.h */
|
---|
32 |
|
---|
33 | /* should go BEFORE any other DevVGA include to make all DevVGA.h config defines be visible */
|
---|
34 | #include "DevVGA.h"
|
---|
35 |
|
---|
36 | #include "DevVGA-SVGA.h"
|
---|
37 | #include "DevVGA-SVGA3d.h"
|
---|
38 | #define VMSVGA3D_INCL_STRUCTURE_DESCRIPTORS
|
---|
39 | #include "DevVGA-SVGA3d-internal.h"
|
---|
40 |
|
---|
41 |
|
---|
42 |
|
---|
43 | /**
|
---|
44 | * Reinitializes an active context.
|
---|
45 | *
|
---|
46 | * @returns VBox status code.
|
---|
47 | * @param pThisCC The VGA/VMSVGA state for ring-3.
|
---|
48 | * @param pContext The freshly loaded context to reinitialize.
|
---|
49 | */
|
---|
50 | static int vmsvga3dLoadReinitContext(PVGASTATECC pThisCC, PVMSVGA3DCONTEXT pContext)
|
---|
51 | {
|
---|
52 | int rc;
|
---|
53 | uint32_t cid = pContext->id;
|
---|
54 | Assert(cid != SVGA3D_INVALID_ID);
|
---|
55 |
|
---|
56 | /* First set the render targets as they change the internal state (reset viewport etc) */
|
---|
57 | Log(("vmsvga3dLoadReinitContext: Recreate render targets BEGIN [cid=%#x]\n", cid));
|
---|
58 | for (uint32_t j = 0; j < RT_ELEMENTS(pContext->state.aRenderTargets); j++)
|
---|
59 | {
|
---|
60 | if (pContext->state.aRenderTargets[j] != SVGA3D_INVALID_ID)
|
---|
61 | {
|
---|
62 | SVGA3dSurfaceImageId target;
|
---|
63 |
|
---|
64 | target.sid = pContext->state.aRenderTargets[j];
|
---|
65 | target.face = 0;
|
---|
66 | target.mipmap = 0;
|
---|
67 | rc = vmsvga3dSetRenderTarget(pThisCC, cid, (SVGA3dRenderTargetType)j, target);
|
---|
68 | AssertRCReturn(rc, rc);
|
---|
69 | }
|
---|
70 | }
|
---|
71 | Log(("vmsvga3dLoadReinitContext: Recreate render targets END\n"));
|
---|
72 |
|
---|
73 | /* Recreate the render state */
|
---|
74 | Log(("vmsvga3dLoadReinitContext: Recreate render state BEGIN\n"));
|
---|
75 | for (uint32_t j = 0; j < RT_ELEMENTS(pContext->state.aRenderState); j++)
|
---|
76 | {
|
---|
77 | SVGA3dRenderState *pRenderState = &pContext->state.aRenderState[j];
|
---|
78 |
|
---|
79 | if (pRenderState->state != SVGA3D_RS_INVALID)
|
---|
80 | vmsvga3dSetRenderState(pThisCC, pContext->id, 1, pRenderState);
|
---|
81 | }
|
---|
82 | Log(("vmsvga3dLoadReinitContext: Recreate render state END\n"));
|
---|
83 |
|
---|
84 | /* Recreate the texture state */
|
---|
85 | Log(("vmsvga3dLoadReinitContext: Recreate texture state BEGIN\n"));
|
---|
86 | for (uint32_t iStage = 0; iStage < RT_ELEMENTS(pContext->state.aTextureStates); ++iStage)
|
---|
87 | {
|
---|
88 | for (uint32_t j = 0; j < RT_ELEMENTS(pContext->state.aTextureStates[0]); ++j)
|
---|
89 | {
|
---|
90 | SVGA3dTextureState *pTextureState = &pContext->state.aTextureStates[iStage][j];
|
---|
91 |
|
---|
92 | if (pTextureState->name != SVGA3D_TS_INVALID)
|
---|
93 | vmsvga3dSetTextureState(pThisCC, pContext->id, 1, pTextureState);
|
---|
94 | }
|
---|
95 | }
|
---|
96 | Log(("vmsvga3dLoadReinitContext: Recreate texture state END\n"));
|
---|
97 |
|
---|
98 | /* Reprogram the clip planes. */
|
---|
99 | for (uint32_t j = 0; j < RT_ELEMENTS(pContext->state.aClipPlane); j++)
|
---|
100 | {
|
---|
101 | if (pContext->state.aClipPlane[j].fValid == true)
|
---|
102 | vmsvga3dSetClipPlane(pThisCC, cid, j, pContext->state.aClipPlane[j].plane);
|
---|
103 | }
|
---|
104 |
|
---|
105 | /* Reprogram the light data. */
|
---|
106 | for (uint32_t j = 0; j < RT_ELEMENTS(pContext->state.aLightData); j++)
|
---|
107 | {
|
---|
108 | if (pContext->state.aLightData[j].fValidData == true)
|
---|
109 | vmsvga3dSetLightData(pThisCC, cid, j, &pContext->state.aLightData[j].data);
|
---|
110 | if (pContext->state.aLightData[j].fEnabled)
|
---|
111 | vmsvga3dSetLightEnabled(pThisCC, cid, j, true);
|
---|
112 | }
|
---|
113 |
|
---|
114 | /* Recreate the transform state. */
|
---|
115 | if (pContext->state.u32UpdateFlags & VMSVGA3D_UPDATE_TRANSFORM)
|
---|
116 | {
|
---|
117 | for (uint32_t j = 0; j < RT_ELEMENTS(pContext->state.aTransformState); j++)
|
---|
118 | {
|
---|
119 | if (pContext->state.aTransformState[j].fValid == true)
|
---|
120 | vmsvga3dSetTransform(pThisCC, cid, (SVGA3dTransformType)j, pContext->state.aTransformState[j].matrix);
|
---|
121 | }
|
---|
122 | }
|
---|
123 |
|
---|
124 | /* Reprogram the material data. */
|
---|
125 | if (pContext->state.u32UpdateFlags & VMSVGA3D_UPDATE_MATERIAL)
|
---|
126 | {
|
---|
127 | for (uint32_t j = 0; j < RT_ELEMENTS(pContext->state.aMaterial); j++)
|
---|
128 | {
|
---|
129 | if (pContext->state.aMaterial[j].fValid == true)
|
---|
130 | vmsvga3dSetMaterial(pThisCC, cid, (SVGA3dFace)j, &pContext->state.aMaterial[j].material);
|
---|
131 | }
|
---|
132 | }
|
---|
133 |
|
---|
134 | if (pContext->state.u32UpdateFlags & VMSVGA3D_UPDATE_SCISSORRECT)
|
---|
135 | vmsvga3dSetScissorRect(pThisCC, cid, &pContext->state.RectScissor);
|
---|
136 | if (pContext->state.u32UpdateFlags & VMSVGA3D_UPDATE_ZRANGE)
|
---|
137 | vmsvga3dSetZRange(pThisCC, cid, pContext->state.zRange);
|
---|
138 | if (pContext->state.u32UpdateFlags & VMSVGA3D_UPDATE_VIEWPORT)
|
---|
139 | vmsvga3dSetViewPort(pThisCC, cid, &pContext->state.RectViewPort);
|
---|
140 | if (pContext->state.u32UpdateFlags & VMSVGA3D_UPDATE_VERTEXSHADER)
|
---|
141 | vmsvga3dShaderSet(pThisCC, pContext, cid, SVGA3D_SHADERTYPE_VS, pContext->state.shidVertex);
|
---|
142 | if (pContext->state.u32UpdateFlags & VMSVGA3D_UPDATE_PIXELSHADER)
|
---|
143 | vmsvga3dShaderSet(pThisCC, pContext, cid, SVGA3D_SHADERTYPE_PS, pContext->state.shidPixel);
|
---|
144 |
|
---|
145 | Log(("vmsvga3dLoadReinitContext: returns [cid=%#x]\n", cid));
|
---|
146 | return VINF_SUCCESS;
|
---|
147 | }
|
---|
148 |
|
---|
149 | static int vmsvga3dLoadVMSVGA3DSURFACEPreMipLevels(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, VMSVGA3DSURFACE *pSurface)
|
---|
150 | {
|
---|
151 | struct VMSVGA3DSURFACEPreMipLevels
|
---|
152 | {
|
---|
153 | uint32_t id;
|
---|
154 | uint32_t idAssociatedContext;
|
---|
155 | uint32_t surfaceFlags;
|
---|
156 | SVGA3dSurfaceFormat format;
|
---|
157 | #ifdef VMSVGA3D_OPENGL
|
---|
158 | GLint internalFormatGL;
|
---|
159 | GLint formatGL;
|
---|
160 | GLint typeGL;
|
---|
161 | #endif
|
---|
162 | SVGA3dSurfaceFace faces[SVGA3D_MAX_SURFACE_FACES];
|
---|
163 | uint32_t cFaces;
|
---|
164 | uint32_t multiSampleCount;
|
---|
165 | SVGA3dTextureFilter autogenFilter;
|
---|
166 | uint32_t cbBlock;
|
---|
167 | };
|
---|
168 |
|
---|
169 | static SSMFIELD const s_aVMSVGA3DSURFACEFieldsPreMipLevels[] =
|
---|
170 | {
|
---|
171 | SSMFIELD_ENTRY(struct VMSVGA3DSURFACEPreMipLevels, id),
|
---|
172 | SSMFIELD_ENTRY(struct VMSVGA3DSURFACEPreMipLevels, idAssociatedContext),
|
---|
173 | SSMFIELD_ENTRY(struct VMSVGA3DSURFACEPreMipLevels, surfaceFlags),
|
---|
174 | SSMFIELD_ENTRY(struct VMSVGA3DSURFACEPreMipLevels, format),
|
---|
175 | #ifdef VMSVGA3D_OPENGL
|
---|
176 | SSMFIELD_ENTRY(struct VMSVGA3DSURFACEPreMipLevels, internalFormatGL),
|
---|
177 | SSMFIELD_ENTRY(struct VMSVGA3DSURFACEPreMipLevels, formatGL),
|
---|
178 | SSMFIELD_ENTRY(struct VMSVGA3DSURFACEPreMipLevels, typeGL),
|
---|
179 | #endif
|
---|
180 | SSMFIELD_ENTRY(struct VMSVGA3DSURFACEPreMipLevels, faces),
|
---|
181 | SSMFIELD_ENTRY(struct VMSVGA3DSURFACEPreMipLevels, cFaces),
|
---|
182 | SSMFIELD_ENTRY(struct VMSVGA3DSURFACEPreMipLevels, multiSampleCount),
|
---|
183 | SSMFIELD_ENTRY(struct VMSVGA3DSURFACEPreMipLevels, autogenFilter),
|
---|
184 | #ifdef VMSVGA3D_DIRECT3D
|
---|
185 | SSMFIELD_ENTRY(struct VMSVGA3DSURFACEPreMipLevels, format), /* Yes, the 'format' field is duplicated. */
|
---|
186 | #endif
|
---|
187 | SSMFIELD_ENTRY(struct VMSVGA3DSURFACEPreMipLevels, cbBlock),
|
---|
188 | SSMFIELD_ENTRY_TERM()
|
---|
189 | };
|
---|
190 |
|
---|
191 | struct VMSVGA3DSURFACEPreMipLevels surfacePreMipLevels;
|
---|
192 | int rc = pDevIns->pHlpR3->pfnSSMGetStructEx(pSSM, &surfacePreMipLevels, sizeof(surfacePreMipLevels), 0, s_aVMSVGA3DSURFACEFieldsPreMipLevels, NULL);
|
---|
193 | if (RT_SUCCESS(rc))
|
---|
194 | {
|
---|
195 | pSurface->id = surfacePreMipLevels.id;
|
---|
196 | pSurface->idAssociatedContext = surfacePreMipLevels.idAssociatedContext;
|
---|
197 | pSurface->f.s.surface1Flags = surfacePreMipLevels.surfaceFlags;
|
---|
198 | pSurface->f.s.surface2Flags = 0;
|
---|
199 | pSurface->format = surfacePreMipLevels.format;
|
---|
200 | #ifdef VMSVGA3D_OPENGL
|
---|
201 | pSurface->internalFormatGL = surfacePreMipLevels.internalFormatGL;
|
---|
202 | pSurface->formatGL = surfacePreMipLevels.formatGL;
|
---|
203 | pSurface->typeGL = surfacePreMipLevels.typeGL;
|
---|
204 | #endif
|
---|
205 | pSurface->cLevels = surfacePreMipLevels.faces[0].numMipLevels;
|
---|
206 | pSurface->cFaces = surfacePreMipLevels.cFaces;
|
---|
207 | pSurface->multiSampleCount = surfacePreMipLevels.multiSampleCount;
|
---|
208 | pSurface->autogenFilter = surfacePreMipLevels.autogenFilter;
|
---|
209 | pSurface->cbBlock = surfacePreMipLevels.cbBlock;
|
---|
210 | }
|
---|
211 | return rc;
|
---|
212 | }
|
---|
213 |
|
---|
214 |
|
---|
215 | /*
|
---|
216 | * Load the legacy VMSVGA3DCONTEXT from saved state version VGA_SAVEDSTATE_VERSION_VMSVGA_MIPLEVELS (23)
|
---|
217 | * or earlier, i.e. 6.1 or old trunk.
|
---|
218 | *
|
---|
219 | * The saved state incompatibility has been introduced in two revisions:
|
---|
220 | *
|
---|
221 | * - r140506: which makes sure that VMSVGA structures are tightly packed (pragma pack(1)).
|
---|
222 | * This caused all structures which have a member from VMSVGA headers (like VMSVGALIGHTSTATE) to be packed too.
|
---|
223 | * For example the size of aLightData element (VMSVGALIGHTSTATE) is 2 bytes smaller on trunk (118) than on 6.1 (120),
|
---|
224 | * which happens because SVGA3dLightData member offset is 2 on trunk and 4 on 6.1.
|
---|
225 | *
|
---|
226 | * - r141385: new VMSVGA device headers.
|
---|
227 | * SVGA3D_RS_MAX is 99 with new VMSVGA headers, but it was 100 with old headers.
|
---|
228 | * 6.1 always saved 100 entries; trunk before r141385 saved 100 entries; trunk at r141385 saves 99 entries.
|
---|
229 | *
|
---|
230 | * 6.1 saved state version is VGA_SAVEDSTATE_VERSION_VMSVGA_SCREENS (21).
|
---|
231 | * Trunk r141287 introduced VGA_SAVEDSTATE_VERSION_VMSVGA_MIPLEVELS (23).
|
---|
232 | *
|
---|
233 | * Both issues has been solved by loading a compatible context structure for saved state
|
---|
234 | * version < VGA_SAVEDSTATE_VERSION_VMSVGA_MIPLEVELS.
|
---|
235 | * This means that trunk will not be able to load states created from r140506 to r141385.
|
---|
236 | */
|
---|
237 | static int vmsvga3dLoadVMSVGA3DCONTEXT23(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, VMSVGA3DCONTEXT *pContext)
|
---|
238 | {
|
---|
239 | #pragma pack(1)
|
---|
240 | struct VMSVGA3DCONTEXT23
|
---|
241 | {
|
---|
242 | uint32_t id;
|
---|
243 | #ifdef VMSVGA3D_OPENGL
|
---|
244 | uint32_t lastError;
|
---|
245 | #endif
|
---|
246 | uint32_t cPixelShaders;
|
---|
247 | uint32_t cVertexShaders;
|
---|
248 | struct
|
---|
249 | {
|
---|
250 | uint32_t u32UpdateFlags;
|
---|
251 | SVGA3dRenderState aRenderState[/*SVGA3D_RS_MAX=*/ 100];
|
---|
252 | SVGA3dTextureState aTextureStates[/*SVGA3D_MAX_TEXTURE_STAGE=*/ 8][/*SVGA3D_TS_MAX=*/ 30];
|
---|
253 | struct
|
---|
254 | {
|
---|
255 | bool fValid;
|
---|
256 | bool pad[3];
|
---|
257 | float matrix[16];
|
---|
258 | } aTransformState[SVGA3D_TRANSFORM_MAX];
|
---|
259 | struct
|
---|
260 | {
|
---|
261 | bool fValid;
|
---|
262 | bool pad[3];
|
---|
263 | SVGA3dMaterial material;
|
---|
264 | } aMaterial[SVGA3D_FACE_MAX];
|
---|
265 | struct
|
---|
266 | {
|
---|
267 | bool fValid;
|
---|
268 | bool pad[3];
|
---|
269 | float plane[4];
|
---|
270 | } aClipPlane[SVGA3D_CLIPPLANE_5];
|
---|
271 | struct
|
---|
272 | {
|
---|
273 | bool fEnabled;
|
---|
274 | bool fValidData;
|
---|
275 | bool pad[2];
|
---|
276 | SVGA3dLightData data;
|
---|
277 | } aLightData[SVGA3D_MAX_LIGHTS];
|
---|
278 | uint32_t aRenderTargets[SVGA3D_RT_MAX];
|
---|
279 | SVGA3dRect RectScissor;
|
---|
280 | SVGA3dRect RectViewPort;
|
---|
281 | SVGA3dZRange zRange;
|
---|
282 | uint32_t shidPixel;
|
---|
283 | uint32_t shidVertex;
|
---|
284 | uint32_t cPixelShaderConst;
|
---|
285 | uint32_t cVertexShaderConst;
|
---|
286 | } state;
|
---|
287 | };
|
---|
288 | #pragma pack()
|
---|
289 |
|
---|
290 | static SSMFIELD const g_aVMSVGA3DCONTEXT23Fields[] =
|
---|
291 | {
|
---|
292 | SSMFIELD_ENTRY(VMSVGA3DCONTEXT23, id),
|
---|
293 | #ifdef VMSVGA3D_OPENGL
|
---|
294 | SSMFIELD_ENTRY(VMSVGA3DCONTEXT23, lastError),
|
---|
295 | #endif
|
---|
296 | SSMFIELD_ENTRY(VMSVGA3DCONTEXT23, cPixelShaders),
|
---|
297 | SSMFIELD_ENTRY(VMSVGA3DCONTEXT23, cVertexShaders),
|
---|
298 | SSMFIELD_ENTRY(VMSVGA3DCONTEXT23, state.u32UpdateFlags),
|
---|
299 | SSMFIELD_ENTRY(VMSVGA3DCONTEXT23, state.aRenderState),
|
---|
300 | SSMFIELD_ENTRY(VMSVGA3DCONTEXT23, state.aTextureStates),
|
---|
301 | SSMFIELD_ENTRY(VMSVGA3DCONTEXT23, state.aTransformState),
|
---|
302 | SSMFIELD_ENTRY(VMSVGA3DCONTEXT23, state.aMaterial),
|
---|
303 | SSMFIELD_ENTRY(VMSVGA3DCONTEXT23, state.aClipPlane),
|
---|
304 | SSMFIELD_ENTRY(VMSVGA3DCONTEXT23, state.aLightData),
|
---|
305 | SSMFIELD_ENTRY(VMSVGA3DCONTEXT23, state.aRenderTargets),
|
---|
306 | SSMFIELD_ENTRY(VMSVGA3DCONTEXT23, state.RectScissor),
|
---|
307 | SSMFIELD_ENTRY(VMSVGA3DCONTEXT23, state.RectViewPort),
|
---|
308 | SSMFIELD_ENTRY(VMSVGA3DCONTEXT23, state.zRange),
|
---|
309 | SSMFIELD_ENTRY(VMSVGA3DCONTEXT23, state.shidPixel),
|
---|
310 | SSMFIELD_ENTRY(VMSVGA3DCONTEXT23, state.shidVertex),
|
---|
311 | SSMFIELD_ENTRY(VMSVGA3DCONTEXT23, state.cPixelShaderConst),
|
---|
312 | SSMFIELD_ENTRY(VMSVGA3DCONTEXT23, state.cVertexShaderConst),
|
---|
313 | SSMFIELD_ENTRY_TERM()
|
---|
314 | };
|
---|
315 |
|
---|
316 | struct VMSVGA3DCONTEXT23 ctx;
|
---|
317 | int rc = pDevIns->pHlpR3->pfnSSMGetStructEx(pSSM, &ctx, sizeof(ctx), 0, g_aVMSVGA3DCONTEXT23Fields, NULL);
|
---|
318 | AssertRCReturn(rc, rc);
|
---|
319 |
|
---|
320 | pContext->id = ctx.id;
|
---|
321 | #ifdef VMSVGA3D_OPENGL
|
---|
322 | pContext->lastError = (GLenum)ctx.lastError;
|
---|
323 | #endif
|
---|
324 |
|
---|
325 | pContext->cPixelShaders = ctx.cPixelShaders;
|
---|
326 | pContext->cVertexShaders = ctx.cVertexShaders;
|
---|
327 | pContext->state.u32UpdateFlags = ctx.state.u32UpdateFlags;
|
---|
328 |
|
---|
329 | AssertCompile(sizeof(SVGA3dRenderState) == 8);
|
---|
330 | AssertCompile(RT_ELEMENTS(pContext->state.aRenderState) == 99);
|
---|
331 | for (unsigned i = 0; i < RT_ELEMENTS(pContext->state.aRenderState); ++i)
|
---|
332 | pContext->state.aRenderState[i] = ctx.state.aRenderState[i];
|
---|
333 |
|
---|
334 | // Skip pContext->state.aTextureStates
|
---|
335 | AssertCompile(sizeof(SVGA3dTextureState) == 12);
|
---|
336 |
|
---|
337 | AssertCompile(sizeof(VMSVGATRANSFORMSTATE) == 68);
|
---|
338 | AssertCompile(RT_ELEMENTS(pContext->state.aTransformState) == 15);
|
---|
339 | for (unsigned i = 0; i < RT_ELEMENTS(pContext->state.aTransformState); ++i)
|
---|
340 | {
|
---|
341 | pContext->state.aTransformState[i].fValid = ctx.state.aTransformState[i].fValid;
|
---|
342 | memcpy(pContext->state.aTransformState[i].matrix, ctx.state.aTransformState[i].matrix, sizeof(pContext->state.aTransformState[i].matrix));
|
---|
343 | }
|
---|
344 |
|
---|
345 | AssertCompile(sizeof(SVGA3dMaterial) == 68);
|
---|
346 | AssertCompile(RT_ELEMENTS(pContext->state.aMaterial) == 5);
|
---|
347 | for (unsigned i = 0; i < RT_ELEMENTS(pContext->state.aMaterial); ++i)
|
---|
348 | {
|
---|
349 | pContext->state.aMaterial[i].fValid = ctx.state.aMaterial[i].fValid;
|
---|
350 | pContext->state.aMaterial[i].material = ctx.state.aMaterial[i].material;
|
---|
351 | }
|
---|
352 |
|
---|
353 | AssertCompile(sizeof(VMSVGACLIPPLANESTATE) == 20);
|
---|
354 | AssertCompile(RT_ELEMENTS(pContext->state.aClipPlane) == (1 << 5));
|
---|
355 | for (unsigned i = 0; i < RT_ELEMENTS(pContext->state.aClipPlane); ++i)
|
---|
356 | {
|
---|
357 | pContext->state.aClipPlane[i].fValid = ctx.state.aClipPlane[i].fValid;
|
---|
358 | memcpy(pContext->state.aClipPlane[i].plane, ctx.state.aClipPlane[i].plane, sizeof(pContext->state.aClipPlane[i].plane));
|
---|
359 | }
|
---|
360 |
|
---|
361 | AssertCompile(sizeof(SVGA3dLightData) == 116);
|
---|
362 | AssertCompile(RT_ELEMENTS(pContext->state.aLightData) == 32);
|
---|
363 | for (unsigned i = 0; i < RT_ELEMENTS(pContext->state.aLightData); ++i)
|
---|
364 | {
|
---|
365 | pContext->state.aLightData[i].fEnabled = ctx.state.aLightData[i].fEnabled;
|
---|
366 | pContext->state.aLightData[i].fValidData = ctx.state.aLightData[i].fValidData;
|
---|
367 | pContext->state.aLightData[i].data = ctx.state.aLightData[i].data;
|
---|
368 | }
|
---|
369 |
|
---|
370 | AssertCompile(RT_ELEMENTS(pContext->state.aRenderTargets) == 10);
|
---|
371 | memcpy(pContext->state.aRenderTargets, ctx.state.aRenderTargets, SVGA3D_RT_MAX * sizeof(uint32_t));
|
---|
372 |
|
---|
373 | AssertCompile(sizeof(SVGA3dRect) == 16);
|
---|
374 | pContext->state.RectScissor = ctx.state.RectScissor;
|
---|
375 | pContext->state.RectViewPort = ctx.state.RectViewPort;
|
---|
376 |
|
---|
377 | AssertCompile(sizeof(SVGA3dZRange) == 8);
|
---|
378 | pContext->state.zRange = ctx.state.zRange;
|
---|
379 |
|
---|
380 | pContext->state.shidPixel = ctx.state.shidPixel;
|
---|
381 | pContext->state.shidVertex = ctx.state.shidVertex;
|
---|
382 | pContext->state.cPixelShaderConst = ctx.state.cPixelShaderConst;
|
---|
383 | pContext->state.cVertexShaderConst = ctx.state.cVertexShaderConst;
|
---|
384 |
|
---|
385 | return VINF_SUCCESS;
|
---|
386 | }
|
---|
387 |
|
---|
388 | int vmsvga3dLoadExec(PPDMDEVINS pDevIns, PVGASTATE pThis, PVGASTATECC pThisCC, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
|
---|
389 | {
|
---|
390 | RT_NOREF(pDevIns, pThis, uPass);
|
---|
391 | PVMSVGA3DSTATE pState = pThisCC->svga.p3dState;
|
---|
392 | AssertReturn(pState, VERR_NO_MEMORY);
|
---|
393 | PCPDMDEVHLPR3 pHlp = pDevIns->pHlpR3;
|
---|
394 | int rc;
|
---|
395 | uint32_t cContexts, cSurfaces;
|
---|
396 | LogFlow(("vmsvga3dLoadExec:\n"));
|
---|
397 |
|
---|
398 | /* Get the generic 3d state first. */
|
---|
399 | rc = pHlp->pfnSSMGetStructEx(pSSM, pState, sizeof(*pState), 0, g_aVMSVGA3DSTATEFields, NULL);
|
---|
400 | AssertRCReturn(rc, rc);
|
---|
401 |
|
---|
402 | cContexts = pState->cContexts;
|
---|
403 | cSurfaces = pState->cSurfaces;
|
---|
404 | pState->cContexts = 0;
|
---|
405 | pState->cSurfaces = 0;
|
---|
406 |
|
---|
407 | /* Fetch all active contexts. */
|
---|
408 | for (uint32_t i = 0; i < cContexts; i++)
|
---|
409 | {
|
---|
410 | PVMSVGA3DCONTEXT pContext;
|
---|
411 | uint32_t cid;
|
---|
412 |
|
---|
413 | /* Get the context id */
|
---|
414 | rc = pHlp->pfnSSMGetU32(pSSM, &cid);
|
---|
415 | AssertRCReturn(rc, rc);
|
---|
416 |
|
---|
417 | if (cid != SVGA3D_INVALID_ID)
|
---|
418 | {
|
---|
419 | uint32_t cPixelShaderConst, cVertexShaderConst, cPixelShaders, cVertexShaders;
|
---|
420 | LogFlow(("vmsvga3dLoadExec: Loading cid=%#x\n", cid));
|
---|
421 |
|
---|
422 | #ifdef VMSVGA3D_OPENGL
|
---|
423 | if (cid == VMSVGA3D_SHARED_CTX_ID)
|
---|
424 | {
|
---|
425 | i--; /* Not included in cContexts. */
|
---|
426 | pContext = &pState->SharedCtx;
|
---|
427 | if (pContext->id != VMSVGA3D_SHARED_CTX_ID)
|
---|
428 | {
|
---|
429 | /** @todo Separate backend */
|
---|
430 | rc = vmsvga3dContextDefineOgl(pThisCC, VMSVGA3D_SHARED_CTX_ID, VMSVGA3D_DEF_CTX_F_SHARED_CTX);
|
---|
431 | AssertRCReturn(rc, rc);
|
---|
432 | }
|
---|
433 | }
|
---|
434 | else
|
---|
435 | #endif
|
---|
436 | {
|
---|
437 | rc = vmsvga3dContextDefine(pThisCC, cid);
|
---|
438 | AssertRCReturn(rc, rc);
|
---|
439 |
|
---|
440 | pContext = pState->papContexts[i];
|
---|
441 | }
|
---|
442 | AssertReturn(pContext->id == cid, VERR_INTERNAL_ERROR);
|
---|
443 |
|
---|
444 | if (uVersion >= VGA_SAVEDSTATE_VERSION_VMSVGA_MIPLEVELS)
|
---|
445 | rc = pHlp->pfnSSMGetStructEx(pSSM, pContext, sizeof(*pContext), 0, g_aVMSVGA3DCONTEXTFields, NULL);
|
---|
446 | else
|
---|
447 | rc = vmsvga3dLoadVMSVGA3DCONTEXT23(pDevIns, pSSM, pContext);
|
---|
448 | AssertRCReturn(rc, rc);
|
---|
449 |
|
---|
450 | cPixelShaders = pContext->cPixelShaders;
|
---|
451 | cVertexShaders = pContext->cVertexShaders;
|
---|
452 | cPixelShaderConst = pContext->state.cPixelShaderConst;
|
---|
453 | cVertexShaderConst = pContext->state.cVertexShaderConst;
|
---|
454 | pContext->cPixelShaders = 0;
|
---|
455 | pContext->cVertexShaders = 0;
|
---|
456 | pContext->state.cPixelShaderConst = 0;
|
---|
457 | pContext->state.cVertexShaderConst = 0;
|
---|
458 |
|
---|
459 | /* Fetch all pixel shaders. */
|
---|
460 | for (uint32_t j = 0; j < cPixelShaders; j++)
|
---|
461 | {
|
---|
462 | VMSVGA3DSHADER shader;
|
---|
463 | uint32_t shid;
|
---|
464 |
|
---|
465 | /* Fetch the id first. */
|
---|
466 | rc = pHlp->pfnSSMGetU32(pSSM, &shid);
|
---|
467 | AssertRCReturn(rc, rc);
|
---|
468 |
|
---|
469 | if (shid != SVGA3D_INVALID_ID)
|
---|
470 | {
|
---|
471 | uint32_t *pData;
|
---|
472 |
|
---|
473 | /* Fetch a copy of the shader struct. */
|
---|
474 | rc = pHlp->pfnSSMGetStructEx(pSSM, &shader, sizeof(shader), 0, g_aVMSVGA3DSHADERFields, NULL);
|
---|
475 | AssertRCReturn(rc, rc);
|
---|
476 |
|
---|
477 | pData = (uint32_t *)RTMemAlloc(shader.cbData);
|
---|
478 | AssertReturn(pData, VERR_NO_MEMORY);
|
---|
479 |
|
---|
480 | rc = pHlp->pfnSSMGetMem(pSSM, pData, shader.cbData);
|
---|
481 | AssertRCReturn(rc, rc);
|
---|
482 |
|
---|
483 | rc = vmsvga3dShaderDefine(pThisCC, cid, shid, shader.type, shader.cbData, pData);
|
---|
484 | AssertRCReturn(rc, rc);
|
---|
485 |
|
---|
486 | RTMemFree(pData);
|
---|
487 | }
|
---|
488 | }
|
---|
489 |
|
---|
490 | /* Fetch all vertex shaders. */
|
---|
491 | for (uint32_t j = 0; j < cVertexShaders; j++)
|
---|
492 | {
|
---|
493 | VMSVGA3DSHADER shader;
|
---|
494 | uint32_t shid;
|
---|
495 |
|
---|
496 | /* Fetch the id first. */
|
---|
497 | rc = pHlp->pfnSSMGetU32(pSSM, &shid);
|
---|
498 | AssertRCReturn(rc, rc);
|
---|
499 |
|
---|
500 | if (shid != SVGA3D_INVALID_ID)
|
---|
501 | {
|
---|
502 | uint32_t *pData;
|
---|
503 |
|
---|
504 | /* Fetch a copy of the shader struct. */
|
---|
505 | rc = pHlp->pfnSSMGetStructEx(pSSM, &shader, sizeof(shader), 0, g_aVMSVGA3DSHADERFields, NULL);
|
---|
506 | AssertRCReturn(rc, rc);
|
---|
507 |
|
---|
508 | pData = (uint32_t *)RTMemAlloc(shader.cbData);
|
---|
509 | AssertReturn(pData, VERR_NO_MEMORY);
|
---|
510 |
|
---|
511 | rc = pHlp->pfnSSMGetMem(pSSM, pData, shader.cbData);
|
---|
512 | AssertRCReturn(rc, rc);
|
---|
513 |
|
---|
514 | rc = vmsvga3dShaderDefine(pThisCC, cid, shid, shader.type, shader.cbData, pData);
|
---|
515 | AssertRCReturn(rc, rc);
|
---|
516 |
|
---|
517 | RTMemFree(pData);
|
---|
518 | }
|
---|
519 | }
|
---|
520 |
|
---|
521 | /* Fetch pixel shader constants. */
|
---|
522 | for (uint32_t j = 0; j < cPixelShaderConst; j++)
|
---|
523 | {
|
---|
524 | VMSVGASHADERCONST ShaderConst;
|
---|
525 |
|
---|
526 | rc = pHlp->pfnSSMGetStructEx(pSSM, &ShaderConst, sizeof(ShaderConst), 0, g_aVMSVGASHADERCONSTFields, NULL);
|
---|
527 | AssertRCReturn(rc, rc);
|
---|
528 |
|
---|
529 | if (ShaderConst.fValid)
|
---|
530 | {
|
---|
531 | rc = vmsvga3dShaderSetConst(pThisCC, cid, j, SVGA3D_SHADERTYPE_PS, ShaderConst.ctype, 1, ShaderConst.value);
|
---|
532 | AssertRCReturn(rc, rc);
|
---|
533 | }
|
---|
534 | }
|
---|
535 |
|
---|
536 | /* Fetch vertex shader constants. */
|
---|
537 | for (uint32_t j = 0; j < cVertexShaderConst; j++)
|
---|
538 | {
|
---|
539 | VMSVGASHADERCONST ShaderConst;
|
---|
540 |
|
---|
541 | rc = pHlp->pfnSSMGetStructEx(pSSM, &ShaderConst, sizeof(ShaderConst), 0, g_aVMSVGASHADERCONSTFields, NULL);
|
---|
542 | AssertRCReturn(rc, rc);
|
---|
543 |
|
---|
544 | if (ShaderConst.fValid)
|
---|
545 | {
|
---|
546 | rc = vmsvga3dShaderSetConst(pThisCC, cid, j, SVGA3D_SHADERTYPE_VS, ShaderConst.ctype, 1, ShaderConst.value);
|
---|
547 | AssertRCReturn(rc, rc);
|
---|
548 | }
|
---|
549 | }
|
---|
550 |
|
---|
551 | if (uVersion >= VGA_SAVEDSTATE_VERSION_VMSVGA_TEX_STAGES)
|
---|
552 | {
|
---|
553 | /* Load texture stage and samplers state. */
|
---|
554 |
|
---|
555 | /* Number of stages/samplers. */
|
---|
556 | uint32_t cStages;
|
---|
557 | rc = pHlp->pfnSSMGetU32(pSSM, &cStages);
|
---|
558 | AssertRCReturn(rc, rc);
|
---|
559 |
|
---|
560 | /* Number of states. */
|
---|
561 | uint32_t cTextureStates;
|
---|
562 | rc = pHlp->pfnSSMGetU32(pSSM, &cTextureStates);
|
---|
563 | AssertRCReturn(rc, rc);
|
---|
564 |
|
---|
565 | for (uint32_t iStage = 0; iStage < cStages; ++iStage)
|
---|
566 | {
|
---|
567 | for (uint32_t j = 0; j < cTextureStates; ++j)
|
---|
568 | {
|
---|
569 | SVGA3dTextureState textureState;
|
---|
570 | pHlp->pfnSSMGetU32(pSSM, &textureState.stage);
|
---|
571 | uint32_t u32Name;
|
---|
572 | pHlp->pfnSSMGetU32(pSSM, &u32Name);
|
---|
573 | textureState.name = (SVGA3dTextureStateName)u32Name;
|
---|
574 | rc = pHlp->pfnSSMGetU32(pSSM, &textureState.value);
|
---|
575 | AssertRCReturn(rc, rc);
|
---|
576 |
|
---|
577 | if ( iStage < RT_ELEMENTS(pContext->state.aTextureStates)
|
---|
578 | && j < RT_ELEMENTS(pContext->state.aTextureStates[0]))
|
---|
579 | {
|
---|
580 | pContext->state.aTextureStates[iStage][j] = textureState;
|
---|
581 | }
|
---|
582 | }
|
---|
583 | }
|
---|
584 | }
|
---|
585 |
|
---|
586 | if (uVersion >= VGA_SAVEDSTATE_VERSION_VMSVGA)
|
---|
587 | {
|
---|
588 | VMSVGA3DQUERY query;
|
---|
589 | RT_ZERO(query);
|
---|
590 |
|
---|
591 | rc = pHlp->pfnSSMGetStructEx(pSSM, &query, sizeof(query), 0, g_aVMSVGA3DQUERYFields, NULL);
|
---|
592 | AssertRCReturn(rc, rc);
|
---|
593 |
|
---|
594 | switch (query.enmQueryState)
|
---|
595 | {
|
---|
596 | case VMSVGA3DQUERYSTATE_BUILDING:
|
---|
597 | /* Start collecting data. */
|
---|
598 | vmsvga3dQueryBegin(pThisCC, cid, SVGA3D_QUERYTYPE_OCCLUSION);
|
---|
599 | /* Partial result. */
|
---|
600 | pContext->occlusion.u32QueryResult = query.u32QueryResult;
|
---|
601 | break;
|
---|
602 |
|
---|
603 | case VMSVGA3DQUERYSTATE_ISSUED:
|
---|
604 | /* Guest ended the query but did not read result. Result is restored. */
|
---|
605 | query.enmQueryState = VMSVGA3DQUERYSTATE_SIGNALED;
|
---|
606 | RT_FALL_THRU();
|
---|
607 | case VMSVGA3DQUERYSTATE_SIGNALED:
|
---|
608 | /* Create the query object. */
|
---|
609 | vmsvga3dQueryCreate(pThisCC, cid, SVGA3D_QUERYTYPE_OCCLUSION);
|
---|
610 |
|
---|
611 | /* Update result and state. */
|
---|
612 | pContext->occlusion.enmQueryState = query.enmQueryState;
|
---|
613 | pContext->occlusion.u32QueryResult = query.u32QueryResult;
|
---|
614 | break;
|
---|
615 |
|
---|
616 | default:
|
---|
617 | AssertFailed();
|
---|
618 | RT_FALL_THRU();
|
---|
619 | case VMSVGA3DQUERYSTATE_NULL:
|
---|
620 | RT_ZERO(pContext->occlusion);
|
---|
621 | break;
|
---|
622 | }
|
---|
623 | }
|
---|
624 | }
|
---|
625 | }
|
---|
626 |
|
---|
627 | #ifdef VMSVGA3D_OPENGL
|
---|
628 | /* Make the shared context the current one. */
|
---|
629 | if (pState->SharedCtx.id == VMSVGA3D_SHARED_CTX_ID)
|
---|
630 | VMSVGA3D_SET_CURRENT_CONTEXT(pState, &pState->SharedCtx);
|
---|
631 | #endif
|
---|
632 |
|
---|
633 | /* Fetch all surfaces. */
|
---|
634 | for (uint32_t i = 0; i < cSurfaces; i++)
|
---|
635 | {
|
---|
636 | uint32_t sid;
|
---|
637 |
|
---|
638 | /* Fetch the id first. */
|
---|
639 | rc = pHlp->pfnSSMGetU32(pSSM, &sid);
|
---|
640 | AssertRCReturn(rc, rc);
|
---|
641 |
|
---|
642 | if (sid != SVGA3D_INVALID_ID)
|
---|
643 | {
|
---|
644 | VMSVGA3DSURFACE surface;
|
---|
645 | LogFlow(("vmsvga3dLoadExec: Loading sid=%#x\n", sid));
|
---|
646 |
|
---|
647 | /* Fetch the surface structure first. */
|
---|
648 | if (RT_LIKELY(uVersion >= VGA_SAVEDSTATE_VERSION_VMSVGA_MIPLEVELS))
|
---|
649 | rc = pHlp->pfnSSMGetStructEx(pSSM, &surface, sizeof(surface), 0, g_aVMSVGA3DSURFACEFields, NULL);
|
---|
650 | else
|
---|
651 | rc = vmsvga3dLoadVMSVGA3DSURFACEPreMipLevels(pDevIns, pSSM, &surface);
|
---|
652 | AssertRCReturn(rc, rc);
|
---|
653 |
|
---|
654 | {
|
---|
655 | uint32_t cMipLevels = surface.cLevels * surface.cFaces;
|
---|
656 | PVMSVGA3DMIPMAPLEVEL pMipmapLevel = (PVMSVGA3DMIPMAPLEVEL)RTMemAlloc(cMipLevels * sizeof(VMSVGA3DMIPMAPLEVEL));
|
---|
657 | AssertReturn(pMipmapLevel, VERR_NO_MEMORY);
|
---|
658 | SVGA3dSize *pMipmapLevelSize = (SVGA3dSize *)RTMemAlloc(cMipLevels * sizeof(SVGA3dSize));
|
---|
659 | AssertReturn(pMipmapLevelSize, VERR_NO_MEMORY);
|
---|
660 |
|
---|
661 | /* Load the mip map level info. */
|
---|
662 | for (uint32_t face=0; face < surface.cFaces; face++)
|
---|
663 | {
|
---|
664 | for (uint32_t j = 0; j < surface.cLevels; j++)
|
---|
665 | {
|
---|
666 | uint32_t idx = j + face * surface.cLevels;
|
---|
667 | /* Load the mip map level struct. */
|
---|
668 | rc = pHlp->pfnSSMGetStructEx(pSSM, &pMipmapLevel[idx], sizeof(pMipmapLevel[idx]), 0,
|
---|
669 | g_aVMSVGA3DMIPMAPLEVELFields, NULL);
|
---|
670 | AssertRCReturn(rc, rc);
|
---|
671 |
|
---|
672 | pMipmapLevelSize[idx] = pMipmapLevel[idx].mipmapSize;
|
---|
673 | }
|
---|
674 | }
|
---|
675 |
|
---|
676 | rc = vmsvga3dSurfaceDefine(pThisCC, sid, surface.f.surfaceFlags, surface.format, surface.multiSampleCount,
|
---|
677 | surface.autogenFilter, surface.cLevels, &pMipmapLevelSize[0], /* arraySize = */ 0, /* fAllocMipLevels = */ true);
|
---|
678 | AssertRCReturn(rc, rc);
|
---|
679 |
|
---|
680 | RTMemFree(pMipmapLevelSize);
|
---|
681 | RTMemFree(pMipmapLevel);
|
---|
682 | }
|
---|
683 |
|
---|
684 | PVMSVGA3DSURFACE pSurface = pState->papSurfaces[sid];
|
---|
685 | Assert(pSurface->id == sid);
|
---|
686 |
|
---|
687 | pSurface->fDirty = false;
|
---|
688 |
|
---|
689 | /* Load the mip map level data. */
|
---|
690 | for (uint32_t j = 0; j < pSurface->cLevels * pSurface->cFaces; j++)
|
---|
691 | {
|
---|
692 | PVMSVGA3DMIPMAPLEVEL pMipmapLevel = &pSurface->paMipmapLevels[j];
|
---|
693 | bool fDataPresent = false;
|
---|
694 |
|
---|
695 | /* vmsvga3dSurfaceDefine already allocated the surface data buffer. */
|
---|
696 | Assert(pMipmapLevel->cbSurface);
|
---|
697 | AssertReturn(pMipmapLevel->pSurfaceData, VERR_INTERNAL_ERROR);
|
---|
698 |
|
---|
699 | /* Fetch the data present boolean first. */
|
---|
700 | rc = pHlp->pfnSSMGetBool(pSSM, &fDataPresent);
|
---|
701 | AssertRCReturn(rc, rc);
|
---|
702 |
|
---|
703 | Log(("Surface sid=%u: load mipmap level %d with %x bytes data (present=%d).\n", sid, j, pMipmapLevel->cbSurface, fDataPresent));
|
---|
704 |
|
---|
705 | if (fDataPresent)
|
---|
706 | {
|
---|
707 | rc = pHlp->pfnSSMGetMem(pSSM, pMipmapLevel->pSurfaceData, pMipmapLevel->cbSurface);
|
---|
708 | AssertRCReturn(rc, rc);
|
---|
709 | pMipmapLevel->fDirty = true;
|
---|
710 | pSurface->fDirty = true;
|
---|
711 | }
|
---|
712 | else
|
---|
713 | {
|
---|
714 | pMipmapLevel->fDirty = false;
|
---|
715 | }
|
---|
716 | }
|
---|
717 | }
|
---|
718 | }
|
---|
719 |
|
---|
720 | #ifdef VMSVGA3D_OPENGL
|
---|
721 | /* Reinitialize the shared context. */
|
---|
722 | LogFlow(("vmsvga3dLoadExec: pState->SharedCtx.id=%#x\n", pState->SharedCtx.id));
|
---|
723 | if (pState->SharedCtx.id == VMSVGA3D_SHARED_CTX_ID)
|
---|
724 | {
|
---|
725 | rc = vmsvga3dLoadReinitContext(pThisCC, &pState->SharedCtx);
|
---|
726 | AssertRCReturn(rc, rc);
|
---|
727 | }
|
---|
728 | #endif
|
---|
729 |
|
---|
730 | /* Reinitialize all active contexts. */
|
---|
731 | for (uint32_t i = 0; i < pState->cContexts; i++)
|
---|
732 | {
|
---|
733 | PVMSVGA3DCONTEXT pContext = pState->papContexts[i];
|
---|
734 | if (pContext->id != SVGA3D_INVALID_ID)
|
---|
735 | {
|
---|
736 | rc = vmsvga3dLoadReinitContext(pThisCC, pContext);
|
---|
737 | AssertRCReturn(rc, rc);
|
---|
738 | }
|
---|
739 | }
|
---|
740 |
|
---|
741 | LogFlow(("vmsvga3dLoadExec: return success\n"));
|
---|
742 | return VINF_SUCCESS;
|
---|
743 | }
|
---|
744 |
|
---|
745 |
|
---|
746 | static int vmsvga3dSaveContext(PCPDMDEVHLPR3 pHlp, PVGASTATECC pThisCC, PSSMHANDLE pSSM, PVMSVGA3DCONTEXT pContext)
|
---|
747 | {
|
---|
748 | uint32_t cid = pContext->id;
|
---|
749 |
|
---|
750 | /* Save the id first. */
|
---|
751 | int rc = pHlp->pfnSSMPutU32(pSSM, cid);
|
---|
752 | AssertRCReturn(rc, rc);
|
---|
753 |
|
---|
754 | if (cid != SVGA3D_INVALID_ID)
|
---|
755 | {
|
---|
756 | /* Save a copy of the context structure first. */
|
---|
757 | rc = pHlp->pfnSSMPutStructEx(pSSM, pContext, sizeof(*pContext), 0, g_aVMSVGA3DCONTEXTFields, NULL);
|
---|
758 | AssertRCReturn(rc, rc);
|
---|
759 |
|
---|
760 | /* Save all pixel shaders. */
|
---|
761 | for (uint32_t j = 0; j < pContext->cPixelShaders; j++)
|
---|
762 | {
|
---|
763 | PVMSVGA3DSHADER pShader = &pContext->paPixelShader[j];
|
---|
764 |
|
---|
765 | /* Save the id first. */
|
---|
766 | rc = pHlp->pfnSSMPutU32(pSSM, pShader->id);
|
---|
767 | AssertRCReturn(rc, rc);
|
---|
768 |
|
---|
769 | if (pShader->id != SVGA3D_INVALID_ID)
|
---|
770 | {
|
---|
771 | uint32_t cbData = pShader->cbData;
|
---|
772 |
|
---|
773 | /* Save a copy of the shader struct. */
|
---|
774 | rc = pHlp->pfnSSMPutStructEx(pSSM, pShader, sizeof(*pShader), 0, g_aVMSVGA3DSHADERFields, NULL);
|
---|
775 | AssertRCReturn(rc, rc);
|
---|
776 |
|
---|
777 | Log(("Save pixelshader shid=%d with %x bytes code.\n", pShader->id, cbData));
|
---|
778 | rc = pHlp->pfnSSMPutMem(pSSM, pShader->pShaderProgram, cbData);
|
---|
779 | AssertRCReturn(rc, rc);
|
---|
780 | }
|
---|
781 | }
|
---|
782 |
|
---|
783 | /* Save all vertex shaders. */
|
---|
784 | for (uint32_t j = 0; j < pContext->cVertexShaders; j++)
|
---|
785 | {
|
---|
786 | PVMSVGA3DSHADER pShader = &pContext->paVertexShader[j];
|
---|
787 |
|
---|
788 | /* Save the id first. */
|
---|
789 | rc = pHlp->pfnSSMPutU32(pSSM, pShader->id);
|
---|
790 | AssertRCReturn(rc, rc);
|
---|
791 |
|
---|
792 | if (pShader->id != SVGA3D_INVALID_ID)
|
---|
793 | {
|
---|
794 | uint32_t cbData = pShader->cbData;
|
---|
795 |
|
---|
796 | /* Save a copy of the shader struct. */
|
---|
797 | rc = pHlp->pfnSSMPutStructEx(pSSM, pShader, sizeof(*pShader), 0, g_aVMSVGA3DSHADERFields, NULL);
|
---|
798 | AssertRCReturn(rc, rc);
|
---|
799 |
|
---|
800 | Log(("Save vertex shader shid=%d with %x bytes code.\n", pShader->id, cbData));
|
---|
801 | /* Fetch the shader code and save it. */
|
---|
802 | rc = pHlp->pfnSSMPutMem(pSSM, pShader->pShaderProgram, cbData);
|
---|
803 | AssertRCReturn(rc, rc);
|
---|
804 | }
|
---|
805 | }
|
---|
806 |
|
---|
807 | /* Save pixel shader constants. */
|
---|
808 | for (uint32_t j = 0; j < pContext->state.cPixelShaderConst; j++)
|
---|
809 | {
|
---|
810 | rc = pHlp->pfnSSMPutStructEx(pSSM, &pContext->state.paPixelShaderConst[j], sizeof(pContext->state.paPixelShaderConst[j]), 0, g_aVMSVGASHADERCONSTFields, NULL);
|
---|
811 | AssertRCReturn(rc, rc);
|
---|
812 | }
|
---|
813 |
|
---|
814 | /* Save vertex shader constants. */
|
---|
815 | for (uint32_t j = 0; j < pContext->state.cVertexShaderConst; j++)
|
---|
816 | {
|
---|
817 | rc = pHlp->pfnSSMPutStructEx(pSSM, &pContext->state.paVertexShaderConst[j], sizeof(pContext->state.paVertexShaderConst[j]), 0, g_aVMSVGASHADERCONSTFields, NULL);
|
---|
818 | AssertRCReturn(rc, rc);
|
---|
819 | }
|
---|
820 |
|
---|
821 | /* Save texture stage and samplers state. */
|
---|
822 |
|
---|
823 | /* Number of stages/samplers. */
|
---|
824 | rc = pHlp->pfnSSMPutU32(pSSM, RT_ELEMENTS(pContext->state.aTextureStates));
|
---|
825 | AssertRCReturn(rc, rc);
|
---|
826 |
|
---|
827 | /* Number of texture states. */
|
---|
828 | rc = pHlp->pfnSSMPutU32(pSSM, RT_ELEMENTS(pContext->state.aTextureStates[0]));
|
---|
829 | AssertRCReturn(rc, rc);
|
---|
830 |
|
---|
831 | for (uint32_t iStage = 0; iStage < RT_ELEMENTS(pContext->state.aTextureStates); ++iStage)
|
---|
832 | {
|
---|
833 | for (uint32_t j = 0; j < RT_ELEMENTS(pContext->state.aTextureStates[0]); ++j)
|
---|
834 | {
|
---|
835 | SVGA3dTextureState *pTextureState = &pContext->state.aTextureStates[iStage][j];
|
---|
836 |
|
---|
837 | pHlp->pfnSSMPutU32(pSSM, pTextureState->stage);
|
---|
838 | pHlp->pfnSSMPutU32(pSSM, pTextureState->name);
|
---|
839 | rc = pHlp->pfnSSMPutU32(pSSM, pTextureState->value);
|
---|
840 | AssertRCReturn(rc, rc);
|
---|
841 | }
|
---|
842 | }
|
---|
843 |
|
---|
844 | /* Occlusion query. */
|
---|
845 | if (!VMSVGA3DQUERY_EXISTS(&pContext->occlusion))
|
---|
846 | {
|
---|
847 | pContext->occlusion.enmQueryState = VMSVGA3DQUERYSTATE_NULL;
|
---|
848 | }
|
---|
849 |
|
---|
850 | /* Save the current query state, because code below can change it. */
|
---|
851 | VMSVGA3DQUERYSTATE const enmQueryState = pContext->occlusion.enmQueryState;
|
---|
852 | switch (enmQueryState)
|
---|
853 | {
|
---|
854 | case VMSVGA3DQUERYSTATE_BUILDING:
|
---|
855 | /* Stop collecting data. Fetch partial result. Save result. */
|
---|
856 | vmsvga3dQueryEnd(pThisCC, cid, SVGA3D_QUERYTYPE_OCCLUSION);
|
---|
857 | RT_FALL_THRU();
|
---|
858 | case VMSVGA3DQUERYSTATE_ISSUED:
|
---|
859 | /* Fetch result. Save result. */
|
---|
860 | pContext->occlusion.u32QueryResult = 0;
|
---|
861 | vmsvga3dQueryWait(pThisCC, cid, SVGA3D_QUERYTYPE_OCCLUSION, NULL, NULL);
|
---|
862 | RT_FALL_THRU();
|
---|
863 | case VMSVGA3DQUERYSTATE_SIGNALED:
|
---|
864 | /* Save result. Nothing to do here. */
|
---|
865 | break;
|
---|
866 |
|
---|
867 | default:
|
---|
868 | AssertFailed();
|
---|
869 | RT_FALL_THRU();
|
---|
870 | case VMSVGA3DQUERYSTATE_NULL:
|
---|
871 | pContext->occlusion.enmQueryState = VMSVGA3DQUERYSTATE_NULL;
|
---|
872 | pContext->occlusion.u32QueryResult = 0;
|
---|
873 | break;
|
---|
874 | }
|
---|
875 |
|
---|
876 | /* Restore the current actual state. */
|
---|
877 | pContext->occlusion.enmQueryState = enmQueryState;
|
---|
878 |
|
---|
879 | rc = pHlp->pfnSSMPutStructEx(pSSM, &pContext->occlusion, sizeof(pContext->occlusion), 0, g_aVMSVGA3DQUERYFields, NULL);
|
---|
880 | AssertRCReturn(rc, rc);
|
---|
881 | }
|
---|
882 |
|
---|
883 | return VINF_SUCCESS;
|
---|
884 | }
|
---|
885 |
|
---|
886 | int vmsvga3dSaveExec(PPDMDEVINS pDevIns, PVGASTATECC pThisCC, PSSMHANDLE pSSM)
|
---|
887 | {
|
---|
888 | PVMSVGA3DSTATE pState = pThisCC->svga.p3dState;
|
---|
889 | AssertReturn(pState, VERR_NO_MEMORY);
|
---|
890 | PCPDMDEVHLPR3 pHlp = pDevIns->pHlpR3;
|
---|
891 | int rc;
|
---|
892 |
|
---|
893 | /* Save a copy of the generic 3d state first. */
|
---|
894 | rc = pHlp->pfnSSMPutStructEx(pSSM, pState, sizeof(*pState), 0, g_aVMSVGA3DSTATEFields, NULL);
|
---|
895 | AssertRCReturn(rc, rc);
|
---|
896 |
|
---|
897 | #ifdef VMSVGA3D_OPENGL
|
---|
898 | /* Save the shared context. */
|
---|
899 | if (pState->SharedCtx.id == VMSVGA3D_SHARED_CTX_ID)
|
---|
900 | {
|
---|
901 | rc = vmsvga3dSaveContext(pHlp, pThisCC, pSSM, &pState->SharedCtx);
|
---|
902 | AssertRCReturn(rc, rc);
|
---|
903 | }
|
---|
904 | #endif
|
---|
905 |
|
---|
906 | /* Save all active contexts. */
|
---|
907 | for (uint32_t i = 0; i < pState->cContexts; i++)
|
---|
908 | {
|
---|
909 | rc = vmsvga3dSaveContext(pHlp, pThisCC, pSSM, pState->papContexts[i]);
|
---|
910 | AssertRCReturn(rc, rc);
|
---|
911 | }
|
---|
912 |
|
---|
913 | /* Save all active surfaces. */
|
---|
914 | for (uint32_t sid = 0; sid < pState->cSurfaces; sid++)
|
---|
915 | {
|
---|
916 | PVMSVGA3DSURFACE pSurface = pState->papSurfaces[sid];
|
---|
917 |
|
---|
918 | /* Save the id first. */
|
---|
919 | rc = pHlp->pfnSSMPutU32(pSSM, pSurface->id);
|
---|
920 | AssertRCReturn(rc, rc);
|
---|
921 |
|
---|
922 | if (pSurface->id != SVGA3D_INVALID_ID)
|
---|
923 | {
|
---|
924 | /* Save a copy of the surface structure first. */
|
---|
925 | rc = pHlp->pfnSSMPutStructEx(pSSM, pSurface, sizeof(*pSurface), 0, g_aVMSVGA3DSURFACEFields, NULL);
|
---|
926 | AssertRCReturn(rc, rc);
|
---|
927 |
|
---|
928 | /* Save the mip map level info. */
|
---|
929 | for (uint32_t face=0; face < pSurface->cFaces; face++)
|
---|
930 | {
|
---|
931 | for (uint32_t i = 0; i < pSurface->cLevels; i++)
|
---|
932 | {
|
---|
933 | uint32_t idx = i + face * pSurface->cLevels;
|
---|
934 | PVMSVGA3DMIPMAPLEVEL pMipmapLevel = &pSurface->paMipmapLevels[idx];
|
---|
935 |
|
---|
936 | /* Save a copy of the mip map level struct. */
|
---|
937 | rc = pHlp->pfnSSMPutStructEx(pSSM, pMipmapLevel, sizeof(*pMipmapLevel), 0, g_aVMSVGA3DMIPMAPLEVELFields, NULL);
|
---|
938 | AssertRCReturn(rc, rc);
|
---|
939 | }
|
---|
940 | }
|
---|
941 |
|
---|
942 | /* Save the mip map level data. */
|
---|
943 | for (uint32_t face=0; face < pSurface->cFaces; face++)
|
---|
944 | {
|
---|
945 | for (uint32_t i = 0; i < pSurface->cLevels; i++)
|
---|
946 | {
|
---|
947 | uint32_t idx = i + face * pSurface->cLevels;
|
---|
948 | PVMSVGA3DMIPMAPLEVEL pMipmapLevel = &pSurface->paMipmapLevels[idx];
|
---|
949 |
|
---|
950 | Log(("Surface sid=%u: save mipmap level %d with %x bytes data.\n", sid, i, pMipmapLevel->cbSurface));
|
---|
951 |
|
---|
952 | if (!VMSVGA3DSURFACE_HAS_HW_SURFACE(pSurface))
|
---|
953 | {
|
---|
954 | if (pMipmapLevel->fDirty)
|
---|
955 | {
|
---|
956 | /* Data follows */
|
---|
957 | rc = pHlp->pfnSSMPutBool(pSSM, true);
|
---|
958 | AssertRCReturn(rc, rc);
|
---|
959 |
|
---|
960 | Assert(pMipmapLevel->cbSurface);
|
---|
961 | rc = pHlp->pfnSSMPutMem(pSSM, pMipmapLevel->pSurfaceData, pMipmapLevel->cbSurface);
|
---|
962 | AssertRCReturn(rc, rc);
|
---|
963 | }
|
---|
964 | else
|
---|
965 | {
|
---|
966 | /* No data follows */
|
---|
967 | rc = pHlp->pfnSSMPutBool(pSSM, false);
|
---|
968 | AssertRCReturn(rc, rc);
|
---|
969 | }
|
---|
970 | }
|
---|
971 | else if (vmsvga3dIsLegacyBackend(pThisCC))
|
---|
972 | {
|
---|
973 | #ifdef VMSVGA3D_DIRECT3D
|
---|
974 | void *pData;
|
---|
975 | bool fRenderTargetTexture = false;
|
---|
976 | bool fTexture = false;
|
---|
977 | bool fSkipSave = false;
|
---|
978 | HRESULT hr;
|
---|
979 |
|
---|
980 | Assert(pMipmapLevel->cbSurface);
|
---|
981 | pData = RTMemAllocZ(pMipmapLevel->cbSurface);
|
---|
982 | AssertReturn(pData, VERR_NO_MEMORY);
|
---|
983 |
|
---|
984 | switch (pSurface->enmD3DResType)
|
---|
985 | {
|
---|
986 | case VMSVGA3D_D3DRESTYPE_CUBE_TEXTURE:
|
---|
987 | case VMSVGA3D_D3DRESTYPE_VOLUME_TEXTURE:
|
---|
988 | AssertFailed(); /// @todo
|
---|
989 | fSkipSave = true;
|
---|
990 | break;
|
---|
991 | case VMSVGA3D_D3DRESTYPE_SURFACE:
|
---|
992 | case VMSVGA3D_D3DRESTYPE_TEXTURE:
|
---|
993 | {
|
---|
994 | if (pSurface->f.surfaceFlags & SVGA3D_SURFACE_HINT_DEPTHSTENCIL)
|
---|
995 | {
|
---|
996 | /** @todo unable to easily fetch depth surface data in d3d 9 */
|
---|
997 | fSkipSave = true;
|
---|
998 | break;
|
---|
999 | }
|
---|
1000 |
|
---|
1001 | fTexture = (pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_TEXTURE);
|
---|
1002 | fRenderTargetTexture = fTexture && (pSurface->f.surfaceFlags & SVGA3D_SURFACE_HINT_RENDERTARGET);
|
---|
1003 |
|
---|
1004 | D3DLOCKED_RECT LockedRect;
|
---|
1005 |
|
---|
1006 | if (fTexture)
|
---|
1007 | {
|
---|
1008 | if (pSurface->bounce.pTexture)
|
---|
1009 | {
|
---|
1010 | if ( !pSurface->fDirty
|
---|
1011 | && fRenderTargetTexture
|
---|
1012 | && i == 0 /* only the first time */)
|
---|
1013 | {
|
---|
1014 | IDirect3DSurface9 *pSrc, *pDest;
|
---|
1015 |
|
---|
1016 | /** @todo stricter checks for associated context */
|
---|
1017 | uint32_t cid = pSurface->idAssociatedContext;
|
---|
1018 |
|
---|
1019 | PVMSVGA3DCONTEXT pContext;
|
---|
1020 | rc = vmsvga3dContextFromCid(pState, cid, &pContext);
|
---|
1021 | AssertRCReturn(rc, rc);
|
---|
1022 |
|
---|
1023 | hr = pSurface->bounce.pTexture->GetSurfaceLevel(i, &pDest);
|
---|
1024 | AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSaveExec: GetSurfaceLevel failed with %x\n", hr), VERR_INTERNAL_ERROR);
|
---|
1025 |
|
---|
1026 | hr = pSurface->u.pTexture->GetSurfaceLevel(i, &pSrc);
|
---|
1027 | AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSaveExec: GetSurfaceLevel failed with %x\n", hr), VERR_INTERNAL_ERROR);
|
---|
1028 |
|
---|
1029 | hr = pContext->pDevice->GetRenderTargetData(pSrc, pDest);
|
---|
1030 | AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSaveExec: GetRenderTargetData failed with %x\n", hr), VERR_INTERNAL_ERROR);
|
---|
1031 |
|
---|
1032 | pSrc->Release();
|
---|
1033 | pDest->Release();
|
---|
1034 | }
|
---|
1035 |
|
---|
1036 | hr = pSurface->bounce.pTexture->LockRect(i, /* texture level */
|
---|
1037 | &LockedRect,
|
---|
1038 | NULL,
|
---|
1039 | D3DLOCK_READONLY);
|
---|
1040 | }
|
---|
1041 | else
|
---|
1042 | hr = pSurface->u.pTexture->LockRect(i, /* texture level */
|
---|
1043 | &LockedRect,
|
---|
1044 | NULL,
|
---|
1045 | D3DLOCK_READONLY);
|
---|
1046 | }
|
---|
1047 | else
|
---|
1048 | hr = pSurface->u.pSurface->LockRect(&LockedRect,
|
---|
1049 | NULL,
|
---|
1050 | D3DLOCK_READONLY);
|
---|
1051 | AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSaveExec: LockRect failed with %x\n", hr), VERR_INTERNAL_ERROR);
|
---|
1052 |
|
---|
1053 | /* Copy the data one line at a time in case the internal pitch is different. */
|
---|
1054 | for (uint32_t j = 0; j < pMipmapLevel->cBlocksY; ++j)
|
---|
1055 | {
|
---|
1056 | uint8_t *pu8Dst = (uint8_t *)pData + j * pMipmapLevel->cbSurfacePitch;
|
---|
1057 | const uint8_t *pu8Src = (uint8_t *)LockedRect.pBits + j * LockedRect.Pitch;
|
---|
1058 | memcpy(pu8Dst, pu8Src, pMipmapLevel->cbSurfacePitch);
|
---|
1059 | }
|
---|
1060 |
|
---|
1061 | if (fTexture)
|
---|
1062 | {
|
---|
1063 | if (pSurface->bounce.pTexture)
|
---|
1064 | {
|
---|
1065 | hr = pSurface->bounce.pTexture->UnlockRect(i);
|
---|
1066 | AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSaveExec: UnlockRect failed with %x\n", hr), VERR_INTERNAL_ERROR);
|
---|
1067 | }
|
---|
1068 | else
|
---|
1069 | hr = pSurface->u.pTexture->UnlockRect(i);
|
---|
1070 | }
|
---|
1071 | else
|
---|
1072 | hr = pSurface->u.pSurface->UnlockRect();
|
---|
1073 | AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSaveExec: UnlockRect failed with %x\n", hr), VERR_INTERNAL_ERROR);
|
---|
1074 | break;
|
---|
1075 | }
|
---|
1076 |
|
---|
1077 | case VMSVGA3D_D3DRESTYPE_VERTEX_BUFFER:
|
---|
1078 | case VMSVGA3D_D3DRESTYPE_INDEX_BUFFER:
|
---|
1079 | {
|
---|
1080 | /* Current type of the buffer. */
|
---|
1081 | const bool fVertex = (pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_VERTEX_BUFFER);
|
---|
1082 |
|
---|
1083 | uint8_t *pD3DData;
|
---|
1084 |
|
---|
1085 | if (fVertex)
|
---|
1086 | hr = pSurface->u.pVertexBuffer->Lock(0, 0, (void **)&pD3DData, D3DLOCK_READONLY);
|
---|
1087 | else
|
---|
1088 | hr = pSurface->u.pIndexBuffer->Lock(0, 0, (void **)&pD3DData, D3DLOCK_READONLY);
|
---|
1089 | AssertMsg(hr == D3D_OK, ("vmsvga3dSaveExec: Lock %s failed with %x\n", (fVertex) ? "vertex" : "index", hr));
|
---|
1090 |
|
---|
1091 | memcpy(pData, pD3DData, pMipmapLevel->cbSurface);
|
---|
1092 |
|
---|
1093 | if (fVertex)
|
---|
1094 | hr = pSurface->u.pVertexBuffer->Unlock();
|
---|
1095 | else
|
---|
1096 | hr = pSurface->u.pIndexBuffer->Unlock();
|
---|
1097 | AssertMsg(hr == D3D_OK, ("vmsvga3dSaveExec: Unlock %s failed with %x\n", (fVertex) ? "vertex" : "index", hr));
|
---|
1098 | break;
|
---|
1099 | }
|
---|
1100 |
|
---|
1101 | default:
|
---|
1102 | AssertFailed();
|
---|
1103 | break;
|
---|
1104 | }
|
---|
1105 |
|
---|
1106 | if (!fSkipSave)
|
---|
1107 | {
|
---|
1108 | /* Data follows */
|
---|
1109 | rc = pHlp->pfnSSMPutBool(pSSM, true);
|
---|
1110 | AssertRCReturn(rc, rc);
|
---|
1111 |
|
---|
1112 | /* And write the surface data. */
|
---|
1113 | rc = pHlp->pfnSSMPutMem(pSSM, pData, pMipmapLevel->cbSurface);
|
---|
1114 | AssertRCReturn(rc, rc);
|
---|
1115 | }
|
---|
1116 | else
|
---|
1117 | {
|
---|
1118 | /* No data follows */
|
---|
1119 | rc = pHlp->pfnSSMPutBool(pSSM, false);
|
---|
1120 | AssertRCReturn(rc, rc);
|
---|
1121 | }
|
---|
1122 |
|
---|
1123 | RTMemFree(pData);
|
---|
1124 |
|
---|
1125 | #elif defined(VMSVGA3D_OPENGL)
|
---|
1126 | void *pData = NULL;
|
---|
1127 |
|
---|
1128 | PVMSVGA3DCONTEXT pContext = &pState->SharedCtx;
|
---|
1129 | VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
|
---|
1130 |
|
---|
1131 | Assert(pMipmapLevel->cbSurface);
|
---|
1132 |
|
---|
1133 | switch (pSurface->enmOGLResType)
|
---|
1134 | {
|
---|
1135 | default:
|
---|
1136 | AssertFailed();
|
---|
1137 | RT_FALL_THRU();
|
---|
1138 | case VMSVGA3D_OGLRESTYPE_RENDERBUFFER:
|
---|
1139 | /** @todo fetch data from the renderbuffer. Not used currently. */
|
---|
1140 | /* No data follows */
|
---|
1141 | rc = pHlp->pfnSSMPutBool(pSSM, false);
|
---|
1142 | AssertRCReturn(rc, rc);
|
---|
1143 | break;
|
---|
1144 |
|
---|
1145 | case VMSVGA3D_OGLRESTYPE_TEXTURE:
|
---|
1146 | {
|
---|
1147 | GLint activeTexture;
|
---|
1148 |
|
---|
1149 | pData = RTMemAllocZ(pMipmapLevel->cbSurface);
|
---|
1150 | AssertReturn(pData, VERR_NO_MEMORY);
|
---|
1151 |
|
---|
1152 | glGetIntegerv(GL_TEXTURE_BINDING_2D, &activeTexture);
|
---|
1153 | VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext);
|
---|
1154 |
|
---|
1155 | glBindTexture(GL_TEXTURE_2D, pSurface->oglId.texture);
|
---|
1156 | VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext);
|
---|
1157 |
|
---|
1158 | /* Set row length and alignment of the output data. */
|
---|
1159 | VMSVGAPACKPARAMS SavedParams;
|
---|
1160 | vmsvga3dOglSetPackParams(pState, pContext, pSurface, &SavedParams);
|
---|
1161 |
|
---|
1162 | glGetTexImage(GL_TEXTURE_2D,
|
---|
1163 | i,
|
---|
1164 | pSurface->formatGL,
|
---|
1165 | pSurface->typeGL,
|
---|
1166 | pData);
|
---|
1167 | VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext);
|
---|
1168 |
|
---|
1169 | vmsvga3dOglRestorePackParams(pState, pContext, pSurface, &SavedParams);
|
---|
1170 |
|
---|
1171 | /* Data follows */
|
---|
1172 | rc = pHlp->pfnSSMPutBool(pSSM, true);
|
---|
1173 | AssertRCReturn(rc, rc);
|
---|
1174 |
|
---|
1175 | /* And write the surface data. */
|
---|
1176 | rc = pHlp->pfnSSMPutMem(pSSM, pData, pMipmapLevel->cbSurface);
|
---|
1177 | AssertRCReturn(rc, rc);
|
---|
1178 |
|
---|
1179 | /* Restore the old active texture. */
|
---|
1180 | glBindTexture(GL_TEXTURE_2D, activeTexture);
|
---|
1181 | VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext);
|
---|
1182 | break;
|
---|
1183 | }
|
---|
1184 |
|
---|
1185 | case VMSVGA3D_OGLRESTYPE_BUFFER:
|
---|
1186 | {
|
---|
1187 | uint8_t *pBufferData;
|
---|
1188 |
|
---|
1189 | pState->ext.glBindBuffer(GL_ARRAY_BUFFER, pSurface->oglId.buffer);
|
---|
1190 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
1191 |
|
---|
1192 | pBufferData = (uint8_t *)pState->ext.glMapBuffer(GL_ARRAY_BUFFER, GL_READ_ONLY);
|
---|
1193 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
1194 | Assert(pBufferData);
|
---|
1195 |
|
---|
1196 | /* Data follows */
|
---|
1197 | rc = pHlp->pfnSSMPutBool(pSSM, true);
|
---|
1198 | AssertRCReturn(rc, rc);
|
---|
1199 |
|
---|
1200 | /* And write the surface data. */
|
---|
1201 | rc = pHlp->pfnSSMPutMem(pSSM, pBufferData, pMipmapLevel->cbSurface);
|
---|
1202 | AssertRCReturn(rc, rc);
|
---|
1203 |
|
---|
1204 | pState->ext.glUnmapBuffer(GL_ARRAY_BUFFER);
|
---|
1205 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
1206 |
|
---|
1207 | pState->ext.glBindBuffer(GL_ARRAY_BUFFER, 0);
|
---|
1208 | VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
|
---|
1209 |
|
---|
1210 | }
|
---|
1211 | }
|
---|
1212 | if (pData)
|
---|
1213 | RTMemFree(pData);
|
---|
1214 | #else
|
---|
1215 | #error "Unexpected 3d backend"
|
---|
1216 | #endif
|
---|
1217 | }
|
---|
1218 | else
|
---|
1219 | {
|
---|
1220 | /** @todo DX backend. */
|
---|
1221 | Assert(!vmsvga3dIsLegacyBackend(pThisCC));
|
---|
1222 |
|
---|
1223 | /* No data follows */
|
---|
1224 | rc = pHlp->pfnSSMPutBool(pSSM, false);
|
---|
1225 | AssertRCReturn(rc, rc);
|
---|
1226 | }
|
---|
1227 | }
|
---|
1228 | }
|
---|
1229 | }
|
---|
1230 | }
|
---|
1231 | return VINF_SUCCESS;
|
---|
1232 | }
|
---|
1233 |
|
---|
1234 | int vmsvga3dSaveShaderConst(PVMSVGA3DCONTEXT pContext, uint32_t reg, SVGA3dShaderType type, SVGA3dShaderConstType ctype,
|
---|
1235 | uint32_t val1, uint32_t val2, uint32_t val3, uint32_t val4)
|
---|
1236 | {
|
---|
1237 | /* Choose a sane upper limit. */
|
---|
1238 | AssertReturn(reg < _32K, VERR_INVALID_PARAMETER);
|
---|
1239 |
|
---|
1240 | if (type == SVGA3D_SHADERTYPE_VS)
|
---|
1241 | {
|
---|
1242 | if (pContext->state.cVertexShaderConst <= reg)
|
---|
1243 | {
|
---|
1244 | pContext->state.paVertexShaderConst = (PVMSVGASHADERCONST)RTMemRealloc(pContext->state.paVertexShaderConst, sizeof(VMSVGASHADERCONST) * (reg + 1));
|
---|
1245 | AssertReturn(pContext->state.paVertexShaderConst, VERR_NO_MEMORY);
|
---|
1246 | for (uint32_t i = pContext->state.cVertexShaderConst; i < reg + 1; i++)
|
---|
1247 | pContext->state.paVertexShaderConst[i].fValid = false;
|
---|
1248 | pContext->state.cVertexShaderConst = reg + 1;
|
---|
1249 | }
|
---|
1250 |
|
---|
1251 | pContext->state.paVertexShaderConst[reg].fValid = true;
|
---|
1252 | pContext->state.paVertexShaderConst[reg].ctype = ctype;
|
---|
1253 | pContext->state.paVertexShaderConst[reg].value[0] = val1;
|
---|
1254 | pContext->state.paVertexShaderConst[reg].value[1] = val2;
|
---|
1255 | pContext->state.paVertexShaderConst[reg].value[2] = val3;
|
---|
1256 | pContext->state.paVertexShaderConst[reg].value[3] = val4;
|
---|
1257 | }
|
---|
1258 | else
|
---|
1259 | {
|
---|
1260 | Assert(type == SVGA3D_SHADERTYPE_PS);
|
---|
1261 | if (pContext->state.cPixelShaderConst <= reg)
|
---|
1262 | {
|
---|
1263 | pContext->state.paPixelShaderConst = (PVMSVGASHADERCONST)RTMemRealloc(pContext->state.paPixelShaderConst, sizeof(VMSVGASHADERCONST) * (reg + 1));
|
---|
1264 | AssertReturn(pContext->state.paPixelShaderConst, VERR_NO_MEMORY);
|
---|
1265 | for (uint32_t i = pContext->state.cPixelShaderConst; i < reg + 1; i++)
|
---|
1266 | pContext->state.paPixelShaderConst[i].fValid = false;
|
---|
1267 | pContext->state.cPixelShaderConst = reg + 1;
|
---|
1268 | }
|
---|
1269 |
|
---|
1270 | pContext->state.paPixelShaderConst[reg].fValid = true;
|
---|
1271 | pContext->state.paPixelShaderConst[reg].ctype = ctype;
|
---|
1272 | pContext->state.paPixelShaderConst[reg].value[0] = val1;
|
---|
1273 | pContext->state.paPixelShaderConst[reg].value[1] = val2;
|
---|
1274 | pContext->state.paPixelShaderConst[reg].value[2] = val3;
|
---|
1275 | pContext->state.paPixelShaderConst[reg].value[3] = val4;
|
---|
1276 | }
|
---|
1277 |
|
---|
1278 | return VINF_SUCCESS;
|
---|
1279 | }
|
---|
1280 |
|
---|