1 | /* $Id: DevVGA-SVGA3d.cpp 69859 2017-11-28 11:54:06Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * DevSVGA3d - VMWare SVGA device, 3D parts - Common core code.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2013-2017 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 |
|
---|
19 | /*********************************************************************************************************************************
|
---|
20 | * Header Files *
|
---|
21 | *********************************************************************************************************************************/
|
---|
22 | #define LOG_GROUP LOG_GROUP_DEV_VMSVGA
|
---|
23 | #include <VBox/vmm/pdmdev.h>
|
---|
24 | #include <VBox/err.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 | * Implements the SVGA_3D_CMD_SURFACE_DEFINE_V2 and SVGA_3D_CMD_SURFACE_DEFINE
|
---|
45 | * commands (fifo).
|
---|
46 | *
|
---|
47 | * @returns VBox status code (currently ignored).
|
---|
48 | * @param pThis The VGA device instance data.
|
---|
49 | * @param sid The ID of the surface to (re-)define.
|
---|
50 | * @param surfaceFlags .
|
---|
51 | * @param format .
|
---|
52 | * @param face .
|
---|
53 | * @param multisampleCount .
|
---|
54 | * @param autogenFilter .
|
---|
55 | * @param cMipLevels .
|
---|
56 | * @param paMipLevelSizes .
|
---|
57 | */
|
---|
58 | int vmsvga3dSurfaceDefine(PVGASTATE pThis, uint32_t sid, uint32_t surfaceFlags, SVGA3dSurfaceFormat format,
|
---|
59 | SVGA3dSurfaceFace face[SVGA3D_MAX_SURFACE_FACES], uint32_t multisampleCount,
|
---|
60 | SVGA3dTextureFilter autogenFilter, uint32_t cMipLevels, SVGA3dSize *paMipLevelSizes)
|
---|
61 | {
|
---|
62 | PVMSVGA3DSURFACE pSurface;
|
---|
63 | PVMSVGA3DSTATE pState = pThis->svga.p3dState;
|
---|
64 | AssertReturn(pState, VERR_NO_MEMORY);
|
---|
65 |
|
---|
66 | Log(("vmsvga3dSurfaceDefine: sid=%x surfaceFlags=%x format=%s (%x) multiSampleCount=%d autogenFilter=%d, cMipLevels=%d size=(%d,%d,%d)\n",
|
---|
67 | sid, surfaceFlags, vmsvgaLookupEnum((int)format, &g_SVGA3dSurfaceFormat2String), format, multisampleCount, autogenFilter,
|
---|
68 | cMipLevels, paMipLevelSizes->width, paMipLevelSizes->height, paMipLevelSizes->depth));
|
---|
69 |
|
---|
70 | AssertReturn(sid < SVGA3D_MAX_SURFACE_IDS, VERR_INVALID_PARAMETER);
|
---|
71 | AssertReturn(cMipLevels >= 1, VERR_INVALID_PARAMETER);
|
---|
72 |
|
---|
73 | /* Number of faces (cFaces) is specified as the number of the first non-zero elements in the 'face' array.
|
---|
74 | * Since only plain surfaces (cFaces == 1) and cubemaps (cFaces == 6) are supported
|
---|
75 | * (see also SVGA3dCmdDefineSurface definition in svga3d_reg.h), we ignore anything else.
|
---|
76 | */
|
---|
77 | uint32_t cRemainingMipLevels = cMipLevels;
|
---|
78 | uint32_t cFaces = 0;
|
---|
79 | for (uint32_t i = 0; i < SVGA3D_MAX_SURFACE_FACES; ++i)
|
---|
80 | {
|
---|
81 | if (face[i].numMipLevels == 0)
|
---|
82 | break;
|
---|
83 |
|
---|
84 | /* All SVGA3dSurfaceFace structures must have the same value of numMipLevels field */
|
---|
85 | AssertReturn(face[i].numMipLevels == face[0].numMipLevels, VERR_INVALID_PARAMETER);
|
---|
86 |
|
---|
87 | /* numMipLevels value can't be greater than the number of remaining elements in the paMipLevelSizes array. */
|
---|
88 | AssertReturn(face[i].numMipLevels <= cRemainingMipLevels, VERR_INVALID_PARAMETER);
|
---|
89 | cRemainingMipLevels -= face[i].numMipLevels;
|
---|
90 |
|
---|
91 | ++cFaces;
|
---|
92 | }
|
---|
93 | for (uint32_t i = cFaces; i < SVGA3D_MAX_SURFACE_FACES; ++i)
|
---|
94 | AssertReturn(face[i].numMipLevels == 0, VERR_INVALID_PARAMETER);
|
---|
95 |
|
---|
96 | /* cFaces must be 6 for a cubemap and 1 otherwise. */
|
---|
97 | AssertReturn(cFaces == (uint32_t)((surfaceFlags & SVGA3D_SURFACE_CUBEMAP) ? 6 : 1), VERR_INVALID_PARAMETER);
|
---|
98 |
|
---|
99 | /* Sum of face[i].numMipLevels must be equal to cMipLevels. */
|
---|
100 | AssertReturn(cRemainingMipLevels == 0, VERR_INVALID_PARAMETER);
|
---|
101 |
|
---|
102 | if (sid >= pState->cSurfaces)
|
---|
103 | {
|
---|
104 | /* Grow the array. */
|
---|
105 | uint32_t cNew = RT_ALIGN(sid + 15, 16);
|
---|
106 | void *pvNew = RTMemRealloc(pState->papSurfaces, sizeof(pState->papSurfaces[0]) * cNew);
|
---|
107 | AssertReturn(pvNew, VERR_NO_MEMORY);
|
---|
108 | pState->papSurfaces = (PVMSVGA3DSURFACE *)pvNew;
|
---|
109 | while (pState->cSurfaces < cNew)
|
---|
110 | {
|
---|
111 | pSurface = (PVMSVGA3DSURFACE)RTMemAllocZ(sizeof(*pSurface));
|
---|
112 | AssertReturn(pSurface, VERR_NO_MEMORY);
|
---|
113 | pSurface->id = SVGA3D_INVALID_ID;
|
---|
114 | pState->papSurfaces[pState->cSurfaces++] = pSurface;
|
---|
115 | }
|
---|
116 | }
|
---|
117 | pSurface = pState->papSurfaces[sid];
|
---|
118 |
|
---|
119 | /* If one already exists with this id, then destroy it now. */
|
---|
120 | if (pSurface->id != SVGA3D_INVALID_ID)
|
---|
121 | vmsvga3dSurfaceDestroy(pThis, sid);
|
---|
122 |
|
---|
123 | RT_ZERO(*pSurface);
|
---|
124 | pSurface->id = sid;
|
---|
125 | #ifdef VMSVGA3D_OPENGL
|
---|
126 | pSurface->idWeakContextAssociation = SVGA3D_INVALID_ID;
|
---|
127 | pSurface->oglId.buffer = OPENGL_INVALID_ID;
|
---|
128 | #else /* VMSVGA3D_DIRECT3D */
|
---|
129 | pSurface->idAssociatedContext = SVGA3D_INVALID_ID;
|
---|
130 | pSurface->hSharedObject = NULL;
|
---|
131 | pSurface->pSharedObjectTree = NULL;
|
---|
132 | #endif
|
---|
133 |
|
---|
134 | /* The surface type is sort of undefined now, even though the hints and format can help to clear that up.
|
---|
135 | * In some case we'll have to wait until the surface is used to create the D3D object.
|
---|
136 | */
|
---|
137 | switch (format)
|
---|
138 | {
|
---|
139 | case SVGA3D_Z_D32:
|
---|
140 | case SVGA3D_Z_D16:
|
---|
141 | case SVGA3D_Z_D24S8:
|
---|
142 | case SVGA3D_Z_D15S1:
|
---|
143 | case SVGA3D_Z_D24X8:
|
---|
144 | case SVGA3D_Z_DF16:
|
---|
145 | case SVGA3D_Z_DF24:
|
---|
146 | case SVGA3D_Z_D24S8_INT:
|
---|
147 | surfaceFlags |= SVGA3D_SURFACE_HINT_DEPTHSTENCIL;
|
---|
148 | break;
|
---|
149 |
|
---|
150 | /* Texture compression formats */
|
---|
151 | case SVGA3D_DXT1:
|
---|
152 | case SVGA3D_DXT2:
|
---|
153 | case SVGA3D_DXT3:
|
---|
154 | case SVGA3D_DXT4:
|
---|
155 | case SVGA3D_DXT5:
|
---|
156 | /* Bump-map formats */
|
---|
157 | case SVGA3D_BUMPU8V8:
|
---|
158 | case SVGA3D_BUMPL6V5U5:
|
---|
159 | case SVGA3D_BUMPX8L8V8U8:
|
---|
160 | case SVGA3D_BUMPL8V8U8:
|
---|
161 | case SVGA3D_V8U8:
|
---|
162 | case SVGA3D_Q8W8V8U8:
|
---|
163 | case SVGA3D_CxV8U8:
|
---|
164 | case SVGA3D_X8L8V8U8:
|
---|
165 | case SVGA3D_A2W10V10U10:
|
---|
166 | case SVGA3D_V16U16:
|
---|
167 | /* Typical render target formats; we should allow render target buffers to be used as textures. */
|
---|
168 | case SVGA3D_X8R8G8B8:
|
---|
169 | case SVGA3D_A8R8G8B8:
|
---|
170 | case SVGA3D_R5G6B5:
|
---|
171 | case SVGA3D_X1R5G5B5:
|
---|
172 | case SVGA3D_A1R5G5B5:
|
---|
173 | case SVGA3D_A4R4G4B4:
|
---|
174 | surfaceFlags |= SVGA3D_SURFACE_HINT_TEXTURE;
|
---|
175 | break;
|
---|
176 |
|
---|
177 | case SVGA3D_LUMINANCE8:
|
---|
178 | case SVGA3D_LUMINANCE4_ALPHA4:
|
---|
179 | case SVGA3D_LUMINANCE16:
|
---|
180 | case SVGA3D_LUMINANCE8_ALPHA8:
|
---|
181 | case SVGA3D_ARGB_S10E5: /* 16-bit floating-point ARGB */
|
---|
182 | case SVGA3D_ARGB_S23E8: /* 32-bit floating-point ARGB */
|
---|
183 | case SVGA3D_A2R10G10B10:
|
---|
184 | case SVGA3D_ALPHA8:
|
---|
185 | case SVGA3D_R_S10E5:
|
---|
186 | case SVGA3D_R_S23E8:
|
---|
187 | case SVGA3D_RG_S10E5:
|
---|
188 | case SVGA3D_RG_S23E8:
|
---|
189 | case SVGA3D_G16R16:
|
---|
190 | case SVGA3D_A16B16G16R16:
|
---|
191 | case SVGA3D_UYVY:
|
---|
192 | case SVGA3D_YUY2:
|
---|
193 | case SVGA3D_NV12:
|
---|
194 | case SVGA3D_AYUV:
|
---|
195 | case SVGA3D_BC4_UNORM:
|
---|
196 | case SVGA3D_BC5_UNORM:
|
---|
197 | break;
|
---|
198 |
|
---|
199 | /*
|
---|
200 | * Any surface can be used as a buffer object, but SVGA3D_BUFFER is
|
---|
201 | * the most efficient format to use when creating new surfaces
|
---|
202 | * expressly for index or vertex data.
|
---|
203 | */
|
---|
204 | case SVGA3D_BUFFER:
|
---|
205 | break;
|
---|
206 |
|
---|
207 | default:
|
---|
208 | break;
|
---|
209 | }
|
---|
210 |
|
---|
211 | pSurface->surfaceFlags = surfaceFlags;
|
---|
212 | pSurface->format = format;
|
---|
213 | memcpy(pSurface->faces, face, sizeof(pSurface->faces));
|
---|
214 | pSurface->cFaces = cFaces;
|
---|
215 | pSurface->multiSampleCount = multisampleCount;
|
---|
216 | pSurface->autogenFilter = autogenFilter;
|
---|
217 | Assert(autogenFilter != SVGA3D_TEX_FILTER_FLATCUBIC);
|
---|
218 | Assert(autogenFilter != SVGA3D_TEX_FILTER_GAUSSIANCUBIC);
|
---|
219 | pSurface->cMipmapLevels = cMipLevels;
|
---|
220 | pSurface->pMipmapLevels = (PVMSVGA3DMIPMAPLEVEL)RTMemAllocZ(cMipLevels * sizeof(VMSVGA3DMIPMAPLEVEL));
|
---|
221 | AssertReturn(pSurface->pMipmapLevels, VERR_NO_MEMORY);
|
---|
222 |
|
---|
223 | for (uint32_t i=0; i < cMipLevels; i++)
|
---|
224 | pSurface->pMipmapLevels[i].mipmapSize = paMipLevelSizes[i];
|
---|
225 |
|
---|
226 | pSurface->cbBlock = vmsvga3dSurfaceFormatSize(format, &pSurface->cxBlock, &pSurface->cyBlock);
|
---|
227 | AssertReturn(pSurface->cbBlock, VERR_INVALID_PARAMETER);
|
---|
228 |
|
---|
229 | #ifdef VMSVGA3D_DIRECT3D
|
---|
230 | /* Translate the format and usage flags to D3D. */
|
---|
231 | pSurface->formatD3D = vmsvga3dSurfaceFormat2D3D(format);
|
---|
232 | pSurface->multiSampleTypeD3D= vmsvga3dMultipeSampleCount2D3D(multisampleCount);
|
---|
233 | pSurface->fUsageD3D = 0;
|
---|
234 | if (surfaceFlags & SVGA3D_SURFACE_HINT_DYNAMIC)
|
---|
235 | pSurface->fUsageD3D |= D3DUSAGE_DYNAMIC;
|
---|
236 | if (surfaceFlags & SVGA3D_SURFACE_HINT_RENDERTARGET)
|
---|
237 | pSurface->fUsageD3D |= D3DUSAGE_RENDERTARGET;
|
---|
238 | if (surfaceFlags & SVGA3D_SURFACE_HINT_DEPTHSTENCIL)
|
---|
239 | pSurface->fUsageD3D |= D3DUSAGE_DEPTHSTENCIL;
|
---|
240 | if (surfaceFlags & SVGA3D_SURFACE_HINT_WRITEONLY)
|
---|
241 | pSurface->fUsageD3D |= D3DUSAGE_WRITEONLY;
|
---|
242 | if (surfaceFlags & SVGA3D_SURFACE_AUTOGENMIPMAPS)
|
---|
243 | pSurface->fUsageD3D |= D3DUSAGE_AUTOGENMIPMAP;
|
---|
244 | pSurface->enmD3DResType = VMSVGA3D_D3DRESTYPE_NONE;
|
---|
245 | /* pSurface->u.pSurface = NULL; */
|
---|
246 | /* pSurface->bounce.pTexture = NULL; */
|
---|
247 | #else
|
---|
248 | vmsvga3dSurfaceFormat2OGL(pSurface, format);
|
---|
249 | #endif
|
---|
250 |
|
---|
251 | LogFunc(("surface hint(s):%s%s%s%s%s%s\n",
|
---|
252 | (surfaceFlags & SVGA3D_SURFACE_HINT_INDEXBUFFER) ? " SVGA3D_SURFACE_HINT_INDEXBUFFER" : "",
|
---|
253 | (surfaceFlags & SVGA3D_SURFACE_HINT_VERTEXBUFFER) ? " SVGA3D_SURFACE_HINT_VERTEXBUFFER" : "",
|
---|
254 | (surfaceFlags & SVGA3D_SURFACE_HINT_TEXTURE) ? " SVGA3D_SURFACE_HINT_TEXTURE" : "",
|
---|
255 | (surfaceFlags & SVGA3D_SURFACE_HINT_DEPTHSTENCIL) ? " SVGA3D_SURFACE_HINT_DEPTHSTENCIL" : "",
|
---|
256 | (surfaceFlags & SVGA3D_SURFACE_HINT_RENDERTARGET) ? " SVGA3D_SURFACE_HINT_RENDERTARGET" : "",
|
---|
257 | (surfaceFlags & SVGA3D_SURFACE_CUBEMAP) ? " SVGA3D_SURFACE_CUBEMAP" : ""
|
---|
258 | ));
|
---|
259 |
|
---|
260 | Assert(!VMSVGA3DSURFACE_HAS_HW_SURFACE(pSurface));
|
---|
261 |
|
---|
262 | /* Allocate buffer to hold the surface data until we can move it into a D3D object */
|
---|
263 | uint32_t cbMemRemaining = SVGA3D_MAX_SURFACE_MEM_SIZE; /* Do not allow more than this for a surface. */
|
---|
264 | for (uint32_t i = 0; i < cMipLevels; ++i)
|
---|
265 | {
|
---|
266 | PVMSVGA3DMIPMAPLEVEL pMipmapLevel = &pSurface->pMipmapLevels[i];
|
---|
267 | LogFunc(("[%d] face %d mip level %d (%d,%d,%d) cbBlock=0x%x block %dx%d\n",
|
---|
268 | i, i / pSurface->faces[0].numMipLevels, i % pSurface->faces[0].numMipLevels,
|
---|
269 | pMipmapLevel->mipmapSize.width, pMipmapLevel->mipmapSize.height, pMipmapLevel->mipmapSize.depth,
|
---|
270 | pSurface->cbBlock, pSurface->cxBlock, pSurface->cyBlock));
|
---|
271 |
|
---|
272 | uint32_t cBlocksX;
|
---|
273 | uint32_t cBlocksY;
|
---|
274 | if (RT_LIKELY(pSurface->cxBlock == 1 && pSurface->cyBlock == 1))
|
---|
275 | {
|
---|
276 | cBlocksX = pMipmapLevel->mipmapSize.width;
|
---|
277 | cBlocksY = pMipmapLevel->mipmapSize.height;
|
---|
278 | }
|
---|
279 | else
|
---|
280 | {
|
---|
281 | cBlocksX = pMipmapLevel->mipmapSize.width / pSurface->cxBlock;
|
---|
282 | if (pMipmapLevel->mipmapSize.width % pSurface->cxBlock)
|
---|
283 | ++cBlocksX;
|
---|
284 | cBlocksY = pMipmapLevel->mipmapSize.height / pSurface->cyBlock;
|
---|
285 | if (pMipmapLevel->mipmapSize.height % pSurface->cyBlock)
|
---|
286 | ++cBlocksY;
|
---|
287 | }
|
---|
288 |
|
---|
289 | if ( cBlocksX == 0
|
---|
290 | || cBlocksY == 0
|
---|
291 | || pMipmapLevel->mipmapSize.depth == 0)
|
---|
292 | return VERR_INVALID_PARAMETER;
|
---|
293 |
|
---|
294 | const uint32_t cMaxBlocksX = cbMemRemaining / pSurface->cbBlock;
|
---|
295 | if (cBlocksX > cMaxBlocksX)
|
---|
296 | return VERR_INVALID_PARAMETER;
|
---|
297 | const uint32_t cbSurfacePitch = pSurface->cbBlock * cBlocksX;
|
---|
298 | LogFunc(("cbSurfacePitch=0x%x\n", cbSurfacePitch));
|
---|
299 |
|
---|
300 | const uint32_t cMaxBlocksY = cbMemRemaining / cbSurfacePitch;
|
---|
301 | if (cBlocksY > cMaxBlocksY)
|
---|
302 | return VERR_INVALID_PARAMETER;
|
---|
303 | const uint32_t cbSurfacePlane = cbSurfacePitch * cBlocksY;
|
---|
304 |
|
---|
305 | const uint32_t cMaxDepth = cbMemRemaining / cbSurfacePlane;
|
---|
306 | if (pMipmapLevel->mipmapSize.depth > cMaxDepth)
|
---|
307 | return VERR_INVALID_PARAMETER;
|
---|
308 | const uint32_t cbSurface = cbSurfacePlane * pMipmapLevel->mipmapSize.depth;
|
---|
309 |
|
---|
310 | pMipmapLevel->cBlocksX = cBlocksX;
|
---|
311 | pMipmapLevel->cBlocksY = cBlocksY;
|
---|
312 | pMipmapLevel->cbSurfacePitch = cbSurfacePitch;
|
---|
313 | pMipmapLevel->cbSurfacePlane = cbSurfacePlane;
|
---|
314 | pMipmapLevel->cbSurface = cbSurface;
|
---|
315 | pMipmapLevel->pSurfaceData = RTMemAllocZ(cbSurface);
|
---|
316 | AssertReturn(pMipmapLevel->pSurfaceData, VERR_NO_MEMORY);
|
---|
317 |
|
---|
318 | cbMemRemaining -= cbSurface;
|
---|
319 | }
|
---|
320 | return VINF_SUCCESS;
|
---|
321 | }
|
---|
322 |
|
---|
323 |
|
---|
324 | /**
|
---|
325 | * Implements the SVGA_3D_CMD_SURFACE_DESTROY command (fifo).
|
---|
326 | *
|
---|
327 | * @returns VBox status code (currently ignored).
|
---|
328 | * @param pThis The VGA device instance data.
|
---|
329 | * @param sid The ID of the surface to destroy.
|
---|
330 | */
|
---|
331 | int vmsvga3dSurfaceDestroy(PVGASTATE pThis, uint32_t sid)
|
---|
332 | {
|
---|
333 | PVMSVGA3DSTATE pState = pThis->svga.p3dState;
|
---|
334 | AssertReturn(pState, VERR_NO_MEMORY);
|
---|
335 |
|
---|
336 | PVMSVGA3DSURFACE pSurface;
|
---|
337 | int rc = vmsvga3dSurfaceFromSid(pState, sid, &pSurface);
|
---|
338 | AssertRCReturn(rc, rc);
|
---|
339 |
|
---|
340 | LogFunc(("sid=%x\n", sid));
|
---|
341 |
|
---|
342 | /* Check all contexts if this surface is used as a render target or active texture. */
|
---|
343 | for (uint32_t cid = 0; cid < pState->cContexts; cid++)
|
---|
344 | {
|
---|
345 | PVMSVGA3DCONTEXT pContext = pState->papContexts[cid];
|
---|
346 | if (pContext->id == cid)
|
---|
347 | {
|
---|
348 | for (uint32_t i = 0; i < RT_ELEMENTS(pContext->aSidActiveTextures); ++i)
|
---|
349 | if (pContext->aSidActiveTextures[i] == sid)
|
---|
350 | pContext->aSidActiveTextures[i] = SVGA3D_INVALID_ID;
|
---|
351 | for (uint32_t i = 0; i < RT_ELEMENTS(pContext->state.aRenderTargets); ++i)
|
---|
352 | if (pContext->state.aRenderTargets[i] == sid)
|
---|
353 | pContext->state.aRenderTargets[i] = SVGA3D_INVALID_ID;
|
---|
354 | }
|
---|
355 | }
|
---|
356 |
|
---|
357 | vmsvga3dBackSurfaceDestroy(pState, pSurface);
|
---|
358 |
|
---|
359 | if (pSurface->pMipmapLevels)
|
---|
360 | {
|
---|
361 | for (uint32_t i = 0; i < pSurface->cMipmapLevels; ++i)
|
---|
362 | RTMemFree(pSurface->pMipmapLevels[i].pSurfaceData);
|
---|
363 | RTMemFree(pSurface->pMipmapLevels);
|
---|
364 | }
|
---|
365 |
|
---|
366 | memset(pSurface, 0, sizeof(*pSurface));
|
---|
367 | pSurface->id = SVGA3D_INVALID_ID;
|
---|
368 |
|
---|
369 | return VINF_SUCCESS;
|
---|
370 | }
|
---|
371 |
|
---|
372 |
|
---|
373 | /**
|
---|
374 | * Implements the SVGA_3D_CMD_SURFACE_STRETCHBLT command (fifo).
|
---|
375 | *
|
---|
376 | * @returns VBox status code (currently ignored).
|
---|
377 | * @param pThis The VGA device instance data.
|
---|
378 | * @param pDstSfcImg
|
---|
379 | * @param pDstBox
|
---|
380 | * @param pSrcSfcImg
|
---|
381 | * @param pSrcBox
|
---|
382 | * @param enmMode
|
---|
383 | */
|
---|
384 | int vmsvga3dSurfaceStretchBlt(PVGASTATE pThis, SVGA3dSurfaceImageId const *pDstSfcImg, SVGA3dBox const *pDstBox,
|
---|
385 | SVGA3dSurfaceImageId const *pSrcSfcImg, SVGA3dBox const *pSrcBox, SVGA3dStretchBltMode enmMode)
|
---|
386 | {
|
---|
387 | PVMSVGA3DSTATE pState = pThis->svga.p3dState;
|
---|
388 | AssertReturn(pState, VERR_NO_MEMORY);
|
---|
389 |
|
---|
390 | int rc;
|
---|
391 |
|
---|
392 | uint32_t const sidSrc = pSrcSfcImg->sid;
|
---|
393 | PVMSVGA3DSURFACE pSrcSurface;
|
---|
394 | rc = vmsvga3dSurfaceFromSid(pState, sidSrc, &pSrcSurface);
|
---|
395 | AssertRCReturn(rc, rc);
|
---|
396 |
|
---|
397 | uint32_t const sidDst = pDstSfcImg->sid;
|
---|
398 | PVMSVGA3DSURFACE pDstSurface;
|
---|
399 | rc = vmsvga3dSurfaceFromSid(pState, sidDst, &pDstSurface);
|
---|
400 | AssertRCReturn(rc, rc);
|
---|
401 |
|
---|
402 | /* Can use faces[0].numMipLevels, because numMipLevels is the same for all faces. */
|
---|
403 | AssertReturn(pSrcSfcImg->face < pSrcSurface->cFaces, VERR_INVALID_PARAMETER);
|
---|
404 | AssertReturn(pSrcSfcImg->mipmap < pSrcSurface->faces[0].numMipLevels, VERR_INVALID_PARAMETER);
|
---|
405 | AssertReturn(pDstSfcImg->face < pDstSurface->cFaces, VERR_INVALID_PARAMETER);
|
---|
406 | AssertReturn(pDstSfcImg->mipmap < pDstSurface->faces[0].numMipLevels, VERR_INVALID_PARAMETER);
|
---|
407 |
|
---|
408 | PVMSVGA3DCONTEXT pContext;
|
---|
409 | #ifdef VMSVGA3D_OPENGL
|
---|
410 | LogFunc(("src sid=%x (%d,%d)(%d,%d) dest sid=%x (%d,%d)(%d,%d) mode=%x\n",
|
---|
411 | sidSrc, pSrcBox->x, pSrcBox->y, pSrcBox->x + pSrcBox->w, pSrcBox->y + pSrcBox->h,
|
---|
412 | sidDst, pDstBox->x, pDstBox->y, pDstBox->x + pDstBox->w, pDstBox->y + pDstBox->h, enmMode));
|
---|
413 | pContext = &pState->SharedCtx;
|
---|
414 | VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
|
---|
415 | #else
|
---|
416 | LogFunc(("src sid=%x cid=%x (%d,%d)(%d,%d) dest sid=%x cid=%x (%d,%d)(%d,%d) mode=%x\n",
|
---|
417 | sidSrc, pSrcSurface->idAssociatedContext, pSrcBox->x, pSrcBox->y, pSrcBox->x + pSrcBox->w, pSrcBox->y + pSrcBox->h,
|
---|
418 | sidDst, pDstSurface->idAssociatedContext, pDstBox->x, pDstBox->y, pDstBox->x + pDstBox->w, pDstBox->y + pDstBox->h, enmMode));
|
---|
419 |
|
---|
420 | uint32_t cid = pDstSurface->idAssociatedContext;
|
---|
421 | if (cid == SVGA3D_INVALID_ID)
|
---|
422 | cid = pSrcSurface->idAssociatedContext;
|
---|
423 |
|
---|
424 | /* At least one of surfaces must be in hardware. */
|
---|
425 | AssertReturn(cid != SVGA3D_INVALID_ID, VERR_INVALID_PARAMETER);
|
---|
426 |
|
---|
427 | rc = vmsvga3dContextFromCid(pState, cid, &pContext);
|
---|
428 | AssertRCReturn(rc, rc);
|
---|
429 | #endif
|
---|
430 |
|
---|
431 | if (!VMSVGA3DSURFACE_HAS_HW_SURFACE(pSrcSurface))
|
---|
432 | {
|
---|
433 | /* Unknown surface type; turn it into a texture, which can be used for other purposes too. */
|
---|
434 | LogFunc(("unknown src sid=%x type=%d format=%d -> create texture\n", sidSrc, pSrcSurface->surfaceFlags, pSrcSurface->format));
|
---|
435 | rc = vmsvga3dBackCreateTexture(pState, pContext, pContext->id, pSrcSurface);
|
---|
436 | AssertRCReturn(rc, rc);
|
---|
437 | }
|
---|
438 |
|
---|
439 | if (!VMSVGA3DSURFACE_HAS_HW_SURFACE(pDstSurface))
|
---|
440 | {
|
---|
441 | /* Unknown surface type; turn it into a texture, which can be used for other purposes too. */
|
---|
442 | LogFunc(("unknown dest sid=%x type=%d format=%d -> create texture\n", sidDst, pDstSurface->surfaceFlags, pDstSurface->format));
|
---|
443 | rc = vmsvga3dBackCreateTexture(pState, pContext, pContext->id, pDstSurface);
|
---|
444 | AssertRCReturn(rc, rc);
|
---|
445 | }
|
---|
446 |
|
---|
447 | PVMSVGA3DMIPMAPLEVEL pSrcMipmapLevel;
|
---|
448 | rc = vmsvga3dMipmapLevel(pSrcSurface, pSrcSfcImg->face, pSrcSfcImg->mipmap, &pSrcMipmapLevel);
|
---|
449 | AssertRCReturn(rc, rc);
|
---|
450 |
|
---|
451 | PVMSVGA3DMIPMAPLEVEL pDstMipmapLevel;
|
---|
452 | rc = vmsvga3dMipmapLevel(pDstSurface, pDstSfcImg->face, pDstSfcImg->mipmap, &pDstMipmapLevel);
|
---|
453 | AssertRCReturn(rc, rc);
|
---|
454 |
|
---|
455 | SVGA3dBox clipSrcBox = *pSrcBox;
|
---|
456 | SVGA3dBox clipDstBox = *pDstBox;
|
---|
457 | vmsvgaClipBox(&pSrcMipmapLevel->mipmapSize, &clipSrcBox);
|
---|
458 | vmsvgaClipBox(&pDstMipmapLevel->mipmapSize, &clipDstBox);
|
---|
459 |
|
---|
460 | return vmsvga3dBackSurfaceStretchBlt(pThis, pState,
|
---|
461 | pDstSurface, pDstSfcImg->face, pDstSfcImg->mipmap, &clipDstBox,
|
---|
462 | pSrcSurface, pSrcSfcImg->face, pSrcSfcImg->mipmap, &clipSrcBox,
|
---|
463 | enmMode, pContext);
|
---|
464 | }
|
---|
465 |
|
---|
466 | /**
|
---|
467 | * Implements the SVGA_3D_CMD_SURFACE_DMA command (fifo).
|
---|
468 | *
|
---|
469 | * @returns VBox status code (currently ignored).
|
---|
470 | * @param pThis The VGA device instance data.
|
---|
471 | * @param guest .
|
---|
472 | * @param host .
|
---|
473 | * @param transfer .
|
---|
474 | * @param cCopyBoxes .
|
---|
475 | * @param paBoxes .
|
---|
476 | */
|
---|
477 | int vmsvga3dSurfaceDMA(PVGASTATE pThis, SVGA3dGuestImage guest, SVGA3dSurfaceImageId host, SVGA3dTransferType transfer,
|
---|
478 | uint32_t cCopyBoxes, SVGA3dCopyBox *paBoxes)
|
---|
479 | {
|
---|
480 | PVMSVGA3DSTATE pState = pThis->svga.p3dState;
|
---|
481 | AssertReturn(pState, VERR_NO_MEMORY);
|
---|
482 |
|
---|
483 | PVMSVGA3DSURFACE pSurface;
|
---|
484 | int rc = vmsvga3dSurfaceFromSid(pState, host.sid, &pSurface);
|
---|
485 | AssertRCReturn(rc, rc);
|
---|
486 |
|
---|
487 | LogFunc(("%sguestptr gmr=%x offset=%x pitch=%x host sid=%x face=%d mipmap=%d transfer=%s cCopyBoxes=%d\n",
|
---|
488 | (pSurface->surfaceFlags & SVGA3D_SURFACE_HINT_TEXTURE) ? "TEXTURE " : "",
|
---|
489 | guest.ptr.gmrId, guest.ptr.offset, guest.pitch,
|
---|
490 | host.sid, host.face, host.mipmap, (transfer == SVGA3D_WRITE_HOST_VRAM) ? "READ" : "WRITE", cCopyBoxes));
|
---|
491 |
|
---|
492 | PVMSVGA3DMIPMAPLEVEL pMipLevel;
|
---|
493 | rc = vmsvga3dMipmapLevel(pSurface, host.face, host.mipmap, &pMipLevel);
|
---|
494 | AssertRCReturn(rc, rc);
|
---|
495 |
|
---|
496 | if (!VMSVGA3DSURFACE_HAS_HW_SURFACE(pSurface))
|
---|
497 | {
|
---|
498 | /*
|
---|
499 | * Not realized in host hardware/library yet, we have to work with
|
---|
500 | * the copy of the data we've got in VMSVGA3DMIMAPLEVEL::pSurfaceData.
|
---|
501 | */
|
---|
502 | AssertReturn(pMipLevel->pSurfaceData, VERR_INTERNAL_ERROR);
|
---|
503 |
|
---|
504 | for (uint32_t i = 0; i < cCopyBoxes; ++i)
|
---|
505 | {
|
---|
506 | Log(("Copy box (mem) %d (%d,%d,%d)(%d,%d,%d) dest (%d,%d)\n",
|
---|
507 | i, paBoxes[i].srcx, paBoxes[i].srcy, paBoxes[i].srcz, paBoxes[i].w, paBoxes[i].h, paBoxes[i].d, paBoxes[i].x, paBoxes[i].y));
|
---|
508 |
|
---|
509 | /* Apparently we're supposed to clip it (gmr test sample) */
|
---|
510 | SVGA3dCopyBox clipBox = paBoxes[i];
|
---|
511 | vmsvgaClipCopyBox(&pMipLevel->mipmapSize, &pMipLevel->mipmapSize, &clipBox);
|
---|
512 | if ( !clipBox.w
|
---|
513 | || !clipBox.h
|
---|
514 | || !clipBox.d)
|
---|
515 | {
|
---|
516 | Log(("Skip empty box\n"));
|
---|
517 | continue;
|
---|
518 | }
|
---|
519 |
|
---|
520 | /* Calculate memory addresses of the image blocks for the transfer. */
|
---|
521 | uint32_t u32HostBlockX;
|
---|
522 | uint32_t u32HostBlockY;
|
---|
523 | uint32_t u32GuestBlockX;
|
---|
524 | uint32_t u32GuestBlockY;
|
---|
525 | uint32_t cBlocksX;
|
---|
526 | uint32_t cBlocksY;
|
---|
527 | if (RT_LIKELY(pSurface->cxBlock == 1 && pSurface->cyBlock == 1))
|
---|
528 | {
|
---|
529 | u32HostBlockX = clipBox.x;
|
---|
530 | u32HostBlockY = clipBox.y;
|
---|
531 |
|
---|
532 | u32GuestBlockX = clipBox.srcx;
|
---|
533 | u32GuestBlockY = clipBox.srcy;
|
---|
534 |
|
---|
535 | cBlocksX = clipBox.w;
|
---|
536 | cBlocksY = clipBox.h;
|
---|
537 | }
|
---|
538 | else
|
---|
539 | {
|
---|
540 | /* Pixels to blocks. */
|
---|
541 | u32HostBlockX = clipBox.x / pSurface->cxBlock;
|
---|
542 | u32HostBlockY = clipBox.y / pSurface->cyBlock;
|
---|
543 | Assert(u32HostBlockX * pSurface->cxBlock == clipBox.x);
|
---|
544 | Assert(u32HostBlockY * pSurface->cyBlock == clipBox.y);
|
---|
545 |
|
---|
546 | u32GuestBlockX = clipBox.srcx / pSurface->cxBlock;
|
---|
547 | u32GuestBlockY = clipBox.srcy / pSurface->cyBlock;
|
---|
548 | Assert(u32GuestBlockX * pSurface->cxBlock == clipBox.srcx);
|
---|
549 | Assert(u32GuestBlockY * pSurface->cyBlock == clipBox.srcy);
|
---|
550 |
|
---|
551 | cBlocksX = (clipBox.w + pSurface->cxBlock - 1) / pSurface->cxBlock;
|
---|
552 | cBlocksY = (clipBox.h + pSurface->cyBlock - 1) / pSurface->cyBlock;
|
---|
553 | }
|
---|
554 |
|
---|
555 | uint32_t cbGuestPitch;
|
---|
556 | if (guest.pitch == 0)
|
---|
557 | cbGuestPitch = cBlocksX * pSurface->cbBlock;
|
---|
558 | else
|
---|
559 | {
|
---|
560 | cbGuestPitch = guest.pitch; /* vmsvgaGMRTransfer will verify the value. */
|
---|
561 | AssertReturn(cbGuestPitch <= SVGA3D_MAX_SURFACE_MEM_SIZE, VERR_INVALID_PARAMETER);
|
---|
562 | }
|
---|
563 |
|
---|
564 | uint64_t uGuestOffset = u32GuestBlockX * pSurface->cbBlock +
|
---|
565 | u32GuestBlockY * cbGuestPitch +
|
---|
566 | clipBox.srcz * pMipLevel->mipmapSize.height * cbGuestPitch;
|
---|
567 | AssertReturn(uGuestOffset < UINT32_MAX, VERR_INVALID_PARAMETER);
|
---|
568 |
|
---|
569 | /* vmsvga3dSurfaceDefine verifies the surface dimensions and clipBox is within them. */
|
---|
570 | uint32_t uHostOffset = u32HostBlockX * pSurface->cbBlock +
|
---|
571 | u32HostBlockY * pMipLevel->cbSurfacePitch +
|
---|
572 | clipBox.z * pMipLevel->cbSurfacePlane;
|
---|
573 | AssertReturn(uHostOffset < pMipLevel->cbSurface, VERR_INTERNAL_ERROR);
|
---|
574 |
|
---|
575 | for (uint32_t z = 0; z < clipBox.d; ++z)
|
---|
576 | {
|
---|
577 | rc = vmsvgaGMRTransfer(pThis,
|
---|
578 | transfer,
|
---|
579 | (uint8_t *)pMipLevel->pSurfaceData + uHostOffset,
|
---|
580 | (int32_t)pMipLevel->cbSurfacePitch,
|
---|
581 | guest.ptr,
|
---|
582 | (uint32_t)uGuestOffset,
|
---|
583 | cbGuestPitch,
|
---|
584 | cBlocksX * pSurface->cbBlock,
|
---|
585 | cBlocksY);
|
---|
586 | AssertRC(rc);
|
---|
587 |
|
---|
588 | Log4(("first line [z=%d]:\n%.*Rhxd\n",
|
---|
589 | z, pMipLevel->cbSurfacePitch, (uint8_t *)pMipLevel->pSurfaceData + uHostOffset));
|
---|
590 |
|
---|
591 | uHostOffset += pMipLevel->cbSurfacePlane;
|
---|
592 | uGuestOffset += pMipLevel->mipmapSize.height * cbGuestPitch;
|
---|
593 | }
|
---|
594 | }
|
---|
595 |
|
---|
596 | pMipLevel->fDirty = true;
|
---|
597 | pSurface->fDirty = true;
|
---|
598 | }
|
---|
599 | else
|
---|
600 | {
|
---|
601 | /*
|
---|
602 | * Because of the clipping below, we're doing a little more
|
---|
603 | * here before calling the backend specific code.
|
---|
604 | */
|
---|
605 | #ifdef VMSVGA3D_DIRECT3D
|
---|
606 | /* Flush the drawing pipeline for this surface as it could be used in a shared context. */
|
---|
607 | vmsvga3dSurfaceFlush(pThis, pSurface);
|
---|
608 | PVMSVGA3DCONTEXT pContext = NULL;
|
---|
609 |
|
---|
610 | #else /* VMSVGA3D_OPENGL */
|
---|
611 | PVMSVGA3DCONTEXT pContext = &pState->SharedCtx;
|
---|
612 | VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
|
---|
613 | #endif
|
---|
614 |
|
---|
615 | for (uint32_t i = 0; i < cCopyBoxes; ++i)
|
---|
616 | {
|
---|
617 | /** @todo Identical code to the above no-hw branch. Think about merging. */
|
---|
618 | Log(("Copy box (hw) %d (%d,%d,%d)(%d,%d,%d) dest (%d,%d)\n",
|
---|
619 | i, paBoxes[i].srcx, paBoxes[i].srcy, paBoxes[i].srcz, paBoxes[i].w, paBoxes[i].h, paBoxes[i].d, paBoxes[i].x, paBoxes[i].y));
|
---|
620 |
|
---|
621 | /* Apparently we're supposed to clip it (gmr test sample) */
|
---|
622 | SVGA3dCopyBox clipBox = paBoxes[i];
|
---|
623 | vmsvgaClipCopyBox(&pMipLevel->mipmapSize, &pMipLevel->mipmapSize, &clipBox);
|
---|
624 | if ( !clipBox.w
|
---|
625 | || !clipBox.h
|
---|
626 | || !clipBox.d)
|
---|
627 | {
|
---|
628 | Log(("Skip empty box\n"));
|
---|
629 | continue;
|
---|
630 | }
|
---|
631 |
|
---|
632 | /* Calculate memory addresses of the image blocks for the transfer. */
|
---|
633 | uint32_t u32HostBlockX;
|
---|
634 | uint32_t u32HostBlockY;
|
---|
635 | uint32_t u32GuestBlockX;
|
---|
636 | uint32_t u32GuestBlockY;
|
---|
637 | uint32_t cBlocksX;
|
---|
638 | uint32_t cBlocksY;
|
---|
639 | if (RT_LIKELY(pSurface->cxBlock == 1 && pSurface->cyBlock == 1))
|
---|
640 | {
|
---|
641 | u32HostBlockX = clipBox.x;
|
---|
642 | u32HostBlockY = clipBox.y;
|
---|
643 |
|
---|
644 | u32GuestBlockX = clipBox.srcx;
|
---|
645 | u32GuestBlockY = clipBox.srcy;
|
---|
646 |
|
---|
647 | cBlocksX = clipBox.w;
|
---|
648 | cBlocksY = clipBox.h;
|
---|
649 | }
|
---|
650 | else
|
---|
651 | {
|
---|
652 | /* Pixels to blocks. */
|
---|
653 | u32HostBlockX = clipBox.x / pSurface->cxBlock;
|
---|
654 | u32HostBlockY = clipBox.y / pSurface->cyBlock;
|
---|
655 | Assert(u32HostBlockX * pSurface->cxBlock == clipBox.x);
|
---|
656 | Assert(u32HostBlockY * pSurface->cyBlock == clipBox.y);
|
---|
657 |
|
---|
658 | u32GuestBlockX = clipBox.srcx / pSurface->cxBlock;
|
---|
659 | u32GuestBlockY = clipBox.srcy / pSurface->cyBlock;
|
---|
660 | Assert(u32GuestBlockX * pSurface->cxBlock == clipBox.srcx);
|
---|
661 | Assert(u32GuestBlockY * pSurface->cyBlock == clipBox.srcy);
|
---|
662 |
|
---|
663 | cBlocksX = (clipBox.w + pSurface->cxBlock - 1) / pSurface->cxBlock;
|
---|
664 | cBlocksY = (clipBox.h + pSurface->cyBlock - 1) / pSurface->cyBlock;
|
---|
665 | }
|
---|
666 |
|
---|
667 | uint32_t cbGuestPitch;
|
---|
668 | if (guest.pitch == 0)
|
---|
669 | cbGuestPitch = cBlocksX * pSurface->cbBlock;
|
---|
670 | else
|
---|
671 | {
|
---|
672 | cbGuestPitch = guest.pitch; /* vmsvgaGMRTransfer will verify the value. */
|
---|
673 | AssertReturn(cbGuestPitch <= SVGA3D_MAX_SURFACE_MEM_SIZE, VERR_INVALID_PARAMETER);
|
---|
674 | }
|
---|
675 |
|
---|
676 | rc = vmsvga3dBackSurfaceDMACopyBox(pThis, pState, pSurface, pMipLevel, host.face, host.mipmap,
|
---|
677 | guest.ptr, cbGuestPitch, transfer,
|
---|
678 | &clipBox, pContext, rc, i);
|
---|
679 | AssertRC(rc);
|
---|
680 | }
|
---|
681 | }
|
---|
682 |
|
---|
683 | return rc;
|
---|
684 | }
|
---|
685 |
|
---|
686 | static int vmsvga3dQueryWriteResult(PVGASTATE pThis, SVGAGuestPtr guestResult, SVGA3dQueryState enmState, uint32_t u32Result)
|
---|
687 | {
|
---|
688 | SVGA3dQueryResult queryResult;
|
---|
689 | queryResult.totalSize = sizeof(queryResult); /* Set by guest before query is ended. */
|
---|
690 | queryResult.state = enmState; /* Set by host or guest. See SVGA3dQueryState. */
|
---|
691 | queryResult.result32 = u32Result;
|
---|
692 |
|
---|
693 | int rc = vmsvgaGMRTransfer(pThis, SVGA3D_READ_HOST_VRAM, (uint8_t *)&queryResult, sizeof(queryResult),
|
---|
694 | guestResult, 0, sizeof(queryResult), sizeof(queryResult), 1);
|
---|
695 | AssertRC(rc);
|
---|
696 | return rc;
|
---|
697 | }
|
---|
698 |
|
---|
699 | int vmsvga3dQueryBegin(PVGASTATE pThis, uint32_t cid, SVGA3dQueryType type)
|
---|
700 | {
|
---|
701 | PVMSVGA3DSTATE pState = pThis->svga.p3dState;
|
---|
702 | AssertReturn(pState, VERR_NO_MEMORY);
|
---|
703 |
|
---|
704 | LogFunc(("cid=%x type=%d\n", cid, type));
|
---|
705 |
|
---|
706 | PVMSVGA3DCONTEXT pContext;
|
---|
707 | int rc = vmsvga3dContextFromCid(pState, cid, &pContext);
|
---|
708 | AssertRCReturn(rc, rc);
|
---|
709 |
|
---|
710 | if (type == SVGA3D_QUERYTYPE_OCCLUSION)
|
---|
711 | {
|
---|
712 | VMSVGA3DQUERY *p = &pContext->occlusion;
|
---|
713 | if (!VMSVGA3DQUERY_EXISTS(p))
|
---|
714 | {
|
---|
715 | /* Lazy creation of the query object. */
|
---|
716 | rc = vmsvga3dOcclusionQueryCreate(pState, pContext);
|
---|
717 | AssertRCReturn(rc, rc);
|
---|
718 | }
|
---|
719 |
|
---|
720 | rc = vmsvga3dOcclusionQueryBegin(pState, pContext);
|
---|
721 | AssertRCReturn(rc, rc);
|
---|
722 |
|
---|
723 | p->enmQueryState = VMSVGA3DQUERYSTATE_BUILDING;
|
---|
724 | p->u32QueryResult = 0;
|
---|
725 |
|
---|
726 | return VINF_SUCCESS;
|
---|
727 | }
|
---|
728 |
|
---|
729 | /* Nothing else for VGPU9. */
|
---|
730 | AssertFailedReturn(VERR_NOT_IMPLEMENTED);
|
---|
731 | }
|
---|
732 |
|
---|
733 | int vmsvga3dQueryEnd(PVGASTATE pThis, uint32_t cid, SVGA3dQueryType type, SVGAGuestPtr guestResult)
|
---|
734 | {
|
---|
735 | RT_NOREF(guestResult);
|
---|
736 | PVMSVGA3DSTATE pState = pThis->svga.p3dState;
|
---|
737 | AssertReturn(pState, VERR_NO_MEMORY);
|
---|
738 |
|
---|
739 | LogFunc(("cid=%x type=%d guestResult %d:0x%x\n", cid, type, guestResult.gmrId, guestResult.offset));
|
---|
740 |
|
---|
741 | PVMSVGA3DCONTEXT pContext;
|
---|
742 | int rc = vmsvga3dContextFromCid(pState, cid, &pContext);
|
---|
743 | AssertRCReturn(rc, rc);
|
---|
744 |
|
---|
745 | if (type == SVGA3D_QUERYTYPE_OCCLUSION)
|
---|
746 | {
|
---|
747 | VMSVGA3DQUERY *p = &pContext->occlusion;
|
---|
748 | Assert(p->enmQueryState == VMSVGA3DQUERYSTATE_BUILDING);
|
---|
749 | AssertMsgReturn(VMSVGA3DQUERY_EXISTS(p), ("Query is NULL\n"), VERR_INTERNAL_ERROR);
|
---|
750 |
|
---|
751 | rc = vmsvga3dOcclusionQueryEnd(pState, pContext);
|
---|
752 | AssertRCReturn(rc, rc);
|
---|
753 |
|
---|
754 | p->enmQueryState = VMSVGA3DQUERYSTATE_ISSUED;
|
---|
755 |
|
---|
756 | /* Do not touch guestResult, because the guest will call WaitForQuery. */
|
---|
757 | return VINF_SUCCESS;
|
---|
758 | }
|
---|
759 |
|
---|
760 | /* Nothing else for VGPU9. */
|
---|
761 | AssertFailedReturn(VERR_NOT_IMPLEMENTED);
|
---|
762 | }
|
---|
763 |
|
---|
764 | int vmsvga3dQueryWait(PVGASTATE pThis, uint32_t cid, SVGA3dQueryType type, SVGAGuestPtr guestResult)
|
---|
765 | {
|
---|
766 | PVMSVGA3DSTATE pState = pThis->svga.p3dState;
|
---|
767 | AssertReturn(pState, VERR_NO_MEMORY);
|
---|
768 |
|
---|
769 | LogFunc(("cid=%x type=%d guestResult GMR%d:0x%x\n", cid, type, guestResult.gmrId, guestResult.offset));
|
---|
770 |
|
---|
771 | PVMSVGA3DCONTEXT pContext;
|
---|
772 | int rc = vmsvga3dContextFromCid(pState, cid, &pContext);
|
---|
773 | AssertRCReturn(rc, rc);
|
---|
774 |
|
---|
775 | if (type == SVGA3D_QUERYTYPE_OCCLUSION)
|
---|
776 | {
|
---|
777 | VMSVGA3DQUERY *p = &pContext->occlusion;
|
---|
778 | if (VMSVGA3DQUERY_EXISTS(p))
|
---|
779 | {
|
---|
780 | if (p->enmQueryState == VMSVGA3DQUERYSTATE_ISSUED)
|
---|
781 | {
|
---|
782 | /* Only if not already in SIGNALED state,
|
---|
783 | * i.e. not a second read from the guest or after restoring saved state.
|
---|
784 | */
|
---|
785 | uint32_t u32Pixels = 0;
|
---|
786 | rc = vmsvga3dOcclusionQueryGetData(pState, pContext, &u32Pixels);
|
---|
787 | if (RT_SUCCESS(rc))
|
---|
788 | {
|
---|
789 | p->enmQueryState = VMSVGA3DQUERYSTATE_SIGNALED;
|
---|
790 | p->u32QueryResult += u32Pixels; /* += because it might contain partial result from saved state. */
|
---|
791 | }
|
---|
792 | }
|
---|
793 |
|
---|
794 | if (RT_SUCCESS(rc))
|
---|
795 | {
|
---|
796 | /* Return data to the guest. */
|
---|
797 | vmsvga3dQueryWriteResult(pThis, guestResult, SVGA3D_QUERYSTATE_SUCCEEDED, p->u32QueryResult);
|
---|
798 | return VINF_SUCCESS;
|
---|
799 | }
|
---|
800 | }
|
---|
801 | else
|
---|
802 | {
|
---|
803 | AssertMsgFailed(("GetData Query is NULL\n"));
|
---|
804 | }
|
---|
805 |
|
---|
806 | rc = VERR_INTERNAL_ERROR;
|
---|
807 | }
|
---|
808 | else
|
---|
809 | {
|
---|
810 | rc = VERR_NOT_IMPLEMENTED;
|
---|
811 | }
|
---|
812 |
|
---|
813 | vmsvga3dQueryWriteResult(pThis, guestResult, SVGA3D_QUERYSTATE_FAILED, 0);
|
---|
814 | AssertFailedReturn(rc);
|
---|
815 | }
|
---|