1 | /* $Id: DevVGA-SVGA3d.cpp 65381 2017-01-20 09:23:53Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * DevSVGA3d - VMWare SVGA device, 3D parts - Common core code.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2013-2016 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 | /* Assuming all faces have the same nr of mipmaps. */
|
---|
73 | AssertReturn(!(surfaceFlags & SVGA3D_SURFACE_CUBEMAP) || cMipLevels == face[0].numMipLevels * 6, VERR_INVALID_PARAMETER);
|
---|
74 | AssertReturn((surfaceFlags & SVGA3D_SURFACE_CUBEMAP) || cMipLevels == face[0].numMipLevels, VERR_INVALID_PARAMETER);
|
---|
75 |
|
---|
76 | if (sid >= pState->cSurfaces)
|
---|
77 | {
|
---|
78 | /* Grow the array. */
|
---|
79 | uint32_t cNew = RT_ALIGN(sid + 15, 16);
|
---|
80 | void *pvNew = RTMemRealloc(pState->papSurfaces, sizeof(pState->papSurfaces[0]) * cNew);
|
---|
81 | AssertReturn(pvNew, VERR_NO_MEMORY);
|
---|
82 | pState->papSurfaces = (PVMSVGA3DSURFACE *)pvNew;
|
---|
83 | while (pState->cSurfaces < cNew)
|
---|
84 | {
|
---|
85 | pSurface = (PVMSVGA3DSURFACE)RTMemAllocZ(sizeof(*pSurface));
|
---|
86 | AssertReturn(pSurface, VERR_NO_MEMORY);
|
---|
87 | pSurface->id = SVGA3D_INVALID_ID;
|
---|
88 | pState->papSurfaces[pState->cSurfaces++] = pSurface;
|
---|
89 | }
|
---|
90 | }
|
---|
91 | pSurface = pState->papSurfaces[sid];
|
---|
92 |
|
---|
93 | /* If one already exists with this id, then destroy it now. */
|
---|
94 | if (pSurface->id != SVGA3D_INVALID_ID)
|
---|
95 | vmsvga3dSurfaceDestroy(pThis, sid);
|
---|
96 |
|
---|
97 | RT_ZERO(*pSurface);
|
---|
98 | pSurface->id = sid;
|
---|
99 | #ifdef VMSVGA3D_OPENGL
|
---|
100 | pSurface->idWeakContextAssociation = SVGA3D_INVALID_ID;
|
---|
101 | #else
|
---|
102 | pSurface->idAssociatedContext = SVGA3D_INVALID_ID;
|
---|
103 | #endif
|
---|
104 | #ifdef VMSVGA3D_DIRECT3D
|
---|
105 | pSurface->hSharedObject = NULL;
|
---|
106 | pSurface->pSharedObjectTree = NULL;
|
---|
107 | #else
|
---|
108 | pSurface->oglId.buffer = OPENGL_INVALID_ID;
|
---|
109 | #endif
|
---|
110 |
|
---|
111 | /* The surface type is sort of undefined now, even though the hints and format can help to clear that up.
|
---|
112 | * In some case we'll have to wait until the surface is used to create the D3D object.
|
---|
113 | */
|
---|
114 | switch (format)
|
---|
115 | {
|
---|
116 | case SVGA3D_Z_D32:
|
---|
117 | case SVGA3D_Z_D16:
|
---|
118 | case SVGA3D_Z_D24S8:
|
---|
119 | case SVGA3D_Z_D15S1:
|
---|
120 | case SVGA3D_Z_D24X8:
|
---|
121 | case SVGA3D_Z_DF16:
|
---|
122 | case SVGA3D_Z_DF24:
|
---|
123 | case SVGA3D_Z_D24S8_INT:
|
---|
124 | surfaceFlags |= SVGA3D_SURFACE_HINT_DEPTHSTENCIL;
|
---|
125 | break;
|
---|
126 |
|
---|
127 | /* Texture compression formats */
|
---|
128 | case SVGA3D_DXT1:
|
---|
129 | case SVGA3D_DXT2:
|
---|
130 | case SVGA3D_DXT3:
|
---|
131 | case SVGA3D_DXT4:
|
---|
132 | case SVGA3D_DXT5:
|
---|
133 | /* Bump-map formats */
|
---|
134 | case SVGA3D_BUMPU8V8:
|
---|
135 | case SVGA3D_BUMPL6V5U5:
|
---|
136 | case SVGA3D_BUMPX8L8V8U8:
|
---|
137 | case SVGA3D_BUMPL8V8U8:
|
---|
138 | case SVGA3D_V8U8:
|
---|
139 | case SVGA3D_Q8W8V8U8:
|
---|
140 | case SVGA3D_CxV8U8:
|
---|
141 | case SVGA3D_X8L8V8U8:
|
---|
142 | case SVGA3D_A2W10V10U10:
|
---|
143 | case SVGA3D_V16U16:
|
---|
144 | /* Typical render target formats; we should allow render target buffers to be used as textures. */
|
---|
145 | case SVGA3D_X8R8G8B8:
|
---|
146 | case SVGA3D_A8R8G8B8:
|
---|
147 | case SVGA3D_R5G6B5:
|
---|
148 | case SVGA3D_X1R5G5B5:
|
---|
149 | case SVGA3D_A1R5G5B5:
|
---|
150 | case SVGA3D_A4R4G4B4:
|
---|
151 | surfaceFlags |= SVGA3D_SURFACE_HINT_TEXTURE;
|
---|
152 | break;
|
---|
153 |
|
---|
154 | case SVGA3D_LUMINANCE8:
|
---|
155 | case SVGA3D_LUMINANCE4_ALPHA4:
|
---|
156 | case SVGA3D_LUMINANCE16:
|
---|
157 | case SVGA3D_LUMINANCE8_ALPHA8:
|
---|
158 | case SVGA3D_ARGB_S10E5: /* 16-bit floating-point ARGB */
|
---|
159 | case SVGA3D_ARGB_S23E8: /* 32-bit floating-point ARGB */
|
---|
160 | case SVGA3D_A2R10G10B10:
|
---|
161 | case SVGA3D_ALPHA8:
|
---|
162 | case SVGA3D_R_S10E5:
|
---|
163 | case SVGA3D_R_S23E8:
|
---|
164 | case SVGA3D_RG_S10E5:
|
---|
165 | case SVGA3D_RG_S23E8:
|
---|
166 | case SVGA3D_G16R16:
|
---|
167 | case SVGA3D_A16B16G16R16:
|
---|
168 | case SVGA3D_UYVY:
|
---|
169 | case SVGA3D_YUY2:
|
---|
170 | case SVGA3D_NV12:
|
---|
171 | case SVGA3D_AYUV:
|
---|
172 | case SVGA3D_BC4_UNORM:
|
---|
173 | case SVGA3D_BC5_UNORM:
|
---|
174 | break;
|
---|
175 |
|
---|
176 | /*
|
---|
177 | * Any surface can be used as a buffer object, but SVGA3D_BUFFER is
|
---|
178 | * the most efficient format to use when creating new surfaces
|
---|
179 | * expressly for index or vertex data.
|
---|
180 | */
|
---|
181 | case SVGA3D_BUFFER:
|
---|
182 | break;
|
---|
183 |
|
---|
184 | default:
|
---|
185 | break;
|
---|
186 | }
|
---|
187 |
|
---|
188 | pSurface->flags = surfaceFlags;
|
---|
189 | pSurface->format = format;
|
---|
190 | memcpy(pSurface->faces, face, sizeof(pSurface->faces));
|
---|
191 | pSurface->cFaces = 1; /* check for cube maps later */
|
---|
192 | pSurface->multiSampleCount = multisampleCount;
|
---|
193 | pSurface->autogenFilter = autogenFilter;
|
---|
194 | Assert(autogenFilter != SVGA3D_TEX_FILTER_FLATCUBIC);
|
---|
195 | Assert(autogenFilter != SVGA3D_TEX_FILTER_GAUSSIANCUBIC);
|
---|
196 | pSurface->pMipmapLevels = (PVMSVGA3DMIPMAPLEVEL)RTMemAllocZ(cMipLevels * sizeof(VMSVGA3DMIPMAPLEVEL));
|
---|
197 | AssertReturn(pSurface->pMipmapLevels, VERR_NO_MEMORY);
|
---|
198 |
|
---|
199 | for (uint32_t i=0; i < cMipLevels; i++)
|
---|
200 | pSurface->pMipmapLevels[i].size = paMipLevelSizes[i];
|
---|
201 |
|
---|
202 | pSurface->cbBlock = vmsvga3dSurfaceFormatSize(format);
|
---|
203 |
|
---|
204 | #ifdef VMSVGA3D_DIRECT3D
|
---|
205 | /* Translate the format and usage flags to D3D. */
|
---|
206 | pSurface->formatD3D = vmsvga3dSurfaceFormat2D3D(format);
|
---|
207 | pSurface->multiSampleTypeD3D= vmsvga3dMultipeSampleCount2D3D(multisampleCount);
|
---|
208 | pSurface->fUsageD3D = 0;
|
---|
209 | if (surfaceFlags & SVGA3D_SURFACE_HINT_DYNAMIC)
|
---|
210 | pSurface->fUsageD3D |= D3DUSAGE_DYNAMIC;
|
---|
211 | if (surfaceFlags & SVGA3D_SURFACE_HINT_RENDERTARGET)
|
---|
212 | pSurface->fUsageD3D |= D3DUSAGE_RENDERTARGET;
|
---|
213 | if (surfaceFlags & SVGA3D_SURFACE_HINT_DEPTHSTENCIL)
|
---|
214 | pSurface->fUsageD3D |= D3DUSAGE_DEPTHSTENCIL;
|
---|
215 | if (surfaceFlags & SVGA3D_SURFACE_HINT_WRITEONLY)
|
---|
216 | pSurface->fUsageD3D |= D3DUSAGE_WRITEONLY;
|
---|
217 | if (surfaceFlags & SVGA3D_SURFACE_AUTOGENMIPMAPS)
|
---|
218 | pSurface->fUsageD3D |= D3DUSAGE_AUTOGENMIPMAP;
|
---|
219 | pSurface->fu32ActualUsageFlags = 0;
|
---|
220 | #else
|
---|
221 | vmsvga3dSurfaceFormat2OGL(pSurface, format);
|
---|
222 | #endif
|
---|
223 |
|
---|
224 | switch (surfaceFlags & (SVGA3D_SURFACE_HINT_INDEXBUFFER | SVGA3D_SURFACE_HINT_VERTEXBUFFER | SVGA3D_SURFACE_HINT_TEXTURE | SVGA3D_SURFACE_HINT_RENDERTARGET | SVGA3D_SURFACE_HINT_DEPTHSTENCIL | SVGA3D_SURFACE_CUBEMAP))
|
---|
225 | {
|
---|
226 | case SVGA3D_SURFACE_CUBEMAP:
|
---|
227 | Log(("SVGA3D_SURFACE_CUBEMAP\n"));
|
---|
228 | pSurface->cFaces = 6;
|
---|
229 | break;
|
---|
230 |
|
---|
231 | case SVGA3D_SURFACE_HINT_INDEXBUFFER:
|
---|
232 | Log(("SVGA3D_SURFACE_HINT_INDEXBUFFER\n"));
|
---|
233 | /* else type unknown at this time; postpone buffer creation */
|
---|
234 | break;
|
---|
235 |
|
---|
236 | case SVGA3D_SURFACE_HINT_VERTEXBUFFER:
|
---|
237 | Log(("SVGA3D_SURFACE_HINT_VERTEXBUFFER\n"));
|
---|
238 | /* Type unknown at this time; postpone buffer creation */
|
---|
239 | break;
|
---|
240 |
|
---|
241 | case SVGA3D_SURFACE_HINT_TEXTURE:
|
---|
242 | Log(("SVGA3D_SURFACE_HINT_TEXTURE\n"));
|
---|
243 | break;
|
---|
244 |
|
---|
245 | case SVGA3D_SURFACE_HINT_RENDERTARGET:
|
---|
246 | Log(("SVGA3D_SURFACE_HINT_RENDERTARGET\n"));
|
---|
247 | break;
|
---|
248 |
|
---|
249 | case SVGA3D_SURFACE_HINT_DEPTHSTENCIL:
|
---|
250 | Log(("SVGA3D_SURFACE_HINT_DEPTHSTENCIL\n"));
|
---|
251 | break;
|
---|
252 |
|
---|
253 | default:
|
---|
254 | /* Unknown; decide later. */
|
---|
255 | break;
|
---|
256 | }
|
---|
257 |
|
---|
258 | Assert(!VMSVGA3DSURFACE_HAS_HW_SURFACE(pSurface));
|
---|
259 |
|
---|
260 | /* Allocate buffer to hold the surface data until we can move it into a D3D object */
|
---|
261 | for (uint32_t iFace=0; iFace < pSurface->cFaces; iFace++)
|
---|
262 | {
|
---|
263 | for (uint32_t i=0; i < pSurface->faces[iFace].numMipLevels; i++)
|
---|
264 | {
|
---|
265 | uint32_t idx = i + iFace * pSurface->faces[0].numMipLevels;
|
---|
266 |
|
---|
267 | Log(("vmsvga3dSurfaceDefine: face %d mip level %d (%d,%d,%d)\n", iFace, i, pSurface->pMipmapLevels[idx].size.width, pSurface->pMipmapLevels[idx].size.height, pSurface->pMipmapLevels[idx].size.depth));
|
---|
268 | Log(("vmsvga3dSurfaceDefine: cbPitch=%x cbBlock=%x \n", pSurface->cbBlock * pSurface->pMipmapLevels[idx].size.width, pSurface->cbBlock));
|
---|
269 |
|
---|
270 | pSurface->pMipmapLevels[idx].cbSurfacePitch = pSurface->cbBlock * pSurface->pMipmapLevels[idx].size.width;
|
---|
271 | pSurface->pMipmapLevels[idx].cbSurface = pSurface->pMipmapLevels[idx].cbSurfacePitch * pSurface->pMipmapLevels[idx].size.height * pSurface->pMipmapLevels[idx].size.depth;
|
---|
272 | pSurface->pMipmapLevels[idx].pSurfaceData = RTMemAllocZ(pSurface->pMipmapLevels[idx].cbSurface);
|
---|
273 | AssertReturn(pSurface->pMipmapLevels[idx].pSurfaceData, VERR_NO_MEMORY);
|
---|
274 | }
|
---|
275 | }
|
---|
276 | return VINF_SUCCESS;
|
---|
277 | }
|
---|
278 |
|
---|
279 |
|
---|
280 | /**
|
---|
281 | * Implements the SVGA_3D_CMD_SURFACE_DESTROY command (fifo).
|
---|
282 | *
|
---|
283 | * @returns VBox status code (currently ignored).
|
---|
284 | * @param pThis The VGA device instance data.
|
---|
285 | * @param sid The ID of the surface to destroy.
|
---|
286 | */
|
---|
287 | int vmsvga3dSurfaceDestroy(PVGASTATE pThis, uint32_t sid)
|
---|
288 | {
|
---|
289 | PVMSVGA3DSTATE pState = pThis->svga.p3dState;
|
---|
290 | AssertReturn(pState, VERR_NO_MEMORY);
|
---|
291 |
|
---|
292 | if ( sid < pState->cSurfaces
|
---|
293 | && pState->papSurfaces[sid]->id == sid)
|
---|
294 | {
|
---|
295 | PVMSVGA3DSURFACE pSurface = pState->papSurfaces[sid];
|
---|
296 |
|
---|
297 | Log(("vmsvga3dSurfaceDestroy id %x\n", sid));
|
---|
298 |
|
---|
299 | /* Check all contexts if this surface is used as a render target or active texture. */
|
---|
300 | for (uint32_t cid = 0; cid < pState->cContexts; cid++)
|
---|
301 | {
|
---|
302 | PVMSVGA3DCONTEXT pContext = pState->papContexts[cid];
|
---|
303 | if (pContext->id == cid)
|
---|
304 | {
|
---|
305 | for (uint32_t i = 0; i < RT_ELEMENTS(pContext->aSidActiveTexture); i++)
|
---|
306 | if (pContext->aSidActiveTexture[i] == sid)
|
---|
307 | pContext->aSidActiveTexture[i] = SVGA3D_INVALID_ID;
|
---|
308 | if (pContext->sidRenderTarget == sid)
|
---|
309 | pContext->sidRenderTarget = SVGA3D_INVALID_ID;
|
---|
310 | }
|
---|
311 | }
|
---|
312 |
|
---|
313 | vmsvga3dBackSurfaceDestroy(pState, pSurface);
|
---|
314 |
|
---|
315 | if (pSurface->pMipmapLevels)
|
---|
316 | {
|
---|
317 | for (uint32_t face=0; face < pSurface->cFaces; face++)
|
---|
318 | {
|
---|
319 | for (uint32_t i=0; i < pSurface->faces[face].numMipLevels; i++)
|
---|
320 | {
|
---|
321 | uint32_t idx = i + face * pSurface->faces[0].numMipLevels;
|
---|
322 | if (pSurface->pMipmapLevels[idx].pSurfaceData)
|
---|
323 | RTMemFree(pSurface->pMipmapLevels[idx].pSurfaceData);
|
---|
324 | }
|
---|
325 | }
|
---|
326 | RTMemFree(pSurface->pMipmapLevels);
|
---|
327 | }
|
---|
328 |
|
---|
329 | memset(pSurface, 0, sizeof(*pSurface));
|
---|
330 | pSurface->id = SVGA3D_INVALID_ID;
|
---|
331 | }
|
---|
332 | else
|
---|
333 | AssertFailedReturn(VERR_INVALID_PARAMETER);
|
---|
334 |
|
---|
335 | return VINF_SUCCESS;
|
---|
336 | }
|
---|
337 |
|
---|
338 |
|
---|
339 | /**
|
---|
340 | * Implements the SVGA_3D_CMD_SURFACE_STRETCHBLT command (fifo).
|
---|
341 | *
|
---|
342 | * @returns VBox status code (currently ignored).
|
---|
343 | * @param pThis The VGA device instance data.
|
---|
344 | * @param pDstSfcImg
|
---|
345 | * @param pDstBox
|
---|
346 | * @param pSrcSfcImg
|
---|
347 | * @param pSrcBox
|
---|
348 | * @param enmMode
|
---|
349 | */
|
---|
350 | int vmsvga3dSurfaceStretchBlt(PVGASTATE pThis, SVGA3dSurfaceImageId const *pDstSfcImg, SVGA3dBox const *pDstBox,
|
---|
351 | SVGA3dSurfaceImageId const *pSrcSfcImg, SVGA3dBox const *pSrcBox, SVGA3dStretchBltMode enmMode)
|
---|
352 | {
|
---|
353 | PVMSVGA3DSTATE pState = pThis->svga.p3dState;
|
---|
354 |
|
---|
355 | AssertReturn(pState, VERR_NO_MEMORY);
|
---|
356 |
|
---|
357 | uint32_t const sidSrc = pSrcSfcImg->sid;
|
---|
358 | Assert(sidSrc < SVGA3D_MAX_SURFACE_IDS);
|
---|
359 | AssertReturn(sidSrc < pState->cSurfaces, VERR_INVALID_PARAMETER);
|
---|
360 | PVMSVGA3DSURFACE pSrcSurface = pState->papSurfaces[sidSrc];
|
---|
361 | AssertReturn(pSrcSurface && pSrcSurface->id == sidSrc, VERR_INVALID_PARAMETER);
|
---|
362 |
|
---|
363 | uint32_t const sidDst = pDstSfcImg->sid;
|
---|
364 | Assert(sidDst < SVGA3D_MAX_SURFACE_IDS);
|
---|
365 | AssertReturn(sidDst < pState->cSurfaces, VERR_INVALID_PARAMETER);
|
---|
366 | PVMSVGA3DSURFACE pDstSurface = pState->papSurfaces[sidDst];
|
---|
367 | AssertReturn(pDstSurface && pDstSurface->id == sidDst, VERR_INVALID_PARAMETER);
|
---|
368 |
|
---|
369 | Assert(pSrcSfcImg->face == 0);
|
---|
370 | AssertReturn(pSrcSfcImg->mipmap < pSrcSurface->faces[0].numMipLevels, VERR_INVALID_PARAMETER);
|
---|
371 | Assert(pDstSfcImg->face == 0);
|
---|
372 | AssertReturn(pDstSfcImg->mipmap < pDstSurface->faces[0].numMipLevels, VERR_INVALID_PARAMETER);
|
---|
373 |
|
---|
374 | PVMSVGA3DCONTEXT pContext;
|
---|
375 | #ifdef VMSVGA3D_OPENGL
|
---|
376 | Log(("vmsvga3dSurfaceStretchBlt: src sid=%x (%d,%d)(%d,%d) dest sid=%x (%d,%d)(%d,%d) mode=%x\n",
|
---|
377 | sidSrc, pSrcBox->x, pSrcBox->y, pSrcBox->x + pSrcBox->w, pSrcBox->y + pSrcBox->h,
|
---|
378 | sidDst, pDstBox->x, pDstBox->y, pDstBox->x + pDstBox->w, pDstBox->y + pDstBox->h, enmMode));
|
---|
379 | pContext = &pState->SharedCtx;
|
---|
380 | VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
|
---|
381 | #else
|
---|
382 | Log(("vmsvga3dSurfaceStretchBlt: src sid=%x cid=%x (%d,%d)(%d,%d) dest sid=%x cid=%x (%d,%d)(%d,%d) mode=%x\n",
|
---|
383 | sidSrc, pSrcSurface->idAssociatedContext, pSrcBox->x, pSrcBox->y, pSrcBox->x + pSrcBox->w, pSrcBox->y + pSrcBox->h,
|
---|
384 | sidDst, pDstSurface->idAssociatedContext, pDstBox->x, pDstBox->y, pDstBox->x + pDstBox->w, pDstBox->y + pDstBox->h, enmMode));
|
---|
385 |
|
---|
386 | /** @todo stricter checks for associated context */
|
---|
387 | uint32_t cid = pDstSurface->idAssociatedContext;
|
---|
388 | if (cid == SVGA3D_INVALID_ID)
|
---|
389 | cid = pSrcSurface->idAssociatedContext;
|
---|
390 |
|
---|
391 | if ( cid >= pState->cContexts
|
---|
392 | || pState->papContexts[cid]->id != cid)
|
---|
393 | {
|
---|
394 | Log(("vmsvga3dSurfaceStretchBlt invalid context id!\n"));
|
---|
395 | AssertFailedReturn(VERR_INVALID_PARAMETER);
|
---|
396 | }
|
---|
397 | pContext = pState->papContexts[cid];
|
---|
398 | #endif
|
---|
399 |
|
---|
400 | int rc;
|
---|
401 | if (!VMSVGA3DSURFACE_HAS_HW_SURFACE(pSrcSurface))
|
---|
402 | {
|
---|
403 | /* Unknown surface type; turn it into a texture, which can be used for other purposes too. */
|
---|
404 | Log(("vmsvga3dSurfaceStretchBlt: unknown src surface id=%x type=%d format=%d -> create texture\n", sidSrc, pSrcSurface->flags, pSrcSurface->format));
|
---|
405 | rc = vmsvga3dBackCreateTexture(pState, pContext, pContext->id, pSrcSurface);
|
---|
406 | AssertRCReturn(rc, rc);
|
---|
407 | }
|
---|
408 |
|
---|
409 | if (!VMSVGA3DSURFACE_HAS_HW_SURFACE(pDstSurface))
|
---|
410 | {
|
---|
411 | /* Unknown surface type; turn it into a texture, which can be used for other purposes too. */
|
---|
412 | Log(("vmsvga3dSurfaceStretchBlt: unknown dest surface id=%x type=%d format=%d -> create texture\n", sidDst, pDstSurface->flags, pDstSurface->format));
|
---|
413 | rc = vmsvga3dBackCreateTexture(pState, pContext, pContext->id, pDstSurface);
|
---|
414 | AssertRCReturn(rc, rc);
|
---|
415 | }
|
---|
416 |
|
---|
417 | return vmsvga3dBackSurfaceStretchBlt(pThis, pState,
|
---|
418 | pDstSurface, pDstSfcImg->mipmap, pDstBox,
|
---|
419 | pSrcSurface, pSrcSfcImg->mipmap, pSrcBox,
|
---|
420 | enmMode, pContext);
|
---|
421 | }
|
---|
422 |
|
---|
423 |
|
---|
424 |
|
---|
425 | /**
|
---|
426 | * Implements the SVGA_3D_CMD_SURFACE_DMA command (fifo).
|
---|
427 | *
|
---|
428 | * @returns VBox status code (currently ignored).
|
---|
429 | * @param pThis The VGA device instance data.
|
---|
430 | * @param guest .
|
---|
431 | * @param host .
|
---|
432 | * @param transfer .
|
---|
433 | * @param cCopyBoxes .
|
---|
434 | * @param paBoxes .
|
---|
435 | */
|
---|
436 | int vmsvga3dSurfaceDMA(PVGASTATE pThis, SVGA3dGuestImage guest, SVGA3dSurfaceImageId host, SVGA3dTransferType transfer,
|
---|
437 | uint32_t cCopyBoxes, SVGA3dCopyBox *paBoxes)
|
---|
438 | {
|
---|
439 | int rc = VINF_SUCCESS;
|
---|
440 |
|
---|
441 | PVMSVGA3DSTATE pState = pThis->svga.p3dState;
|
---|
442 | AssertReturn(pState, VERR_NO_MEMORY);
|
---|
443 |
|
---|
444 | uint32_t sid = host.sid;
|
---|
445 | Assert(sid < SVGA3D_MAX_SURFACE_IDS);
|
---|
446 | AssertReturn(sid < pState->cSurfaces, VERR_INVALID_PARAMETER);
|
---|
447 | PVMSVGA3DSURFACE pSurface = pState->papSurfaces[sid];
|
---|
448 | AssertReturn(pSurface && pSurface->id == sid, VERR_INVALID_PARAMETER);
|
---|
449 |
|
---|
450 | if (pSurface->flags & SVGA3D_SURFACE_HINT_TEXTURE)
|
---|
451 | Log(("vmsvga3dSurfaceDMA TEXTURE guestptr gmr=%x offset=%x pitch=%x host sid=%x face=%d mipmap=%d transfer=%s cCopyBoxes=%d\n", guest.ptr.gmrId, guest.ptr.offset, guest.pitch, host.sid, host.face, host.mipmap, (transfer == SVGA3D_WRITE_HOST_VRAM) ? "READ" : "WRITE", cCopyBoxes));
|
---|
452 | else
|
---|
453 | Log(("vmsvga3dSurfaceDMA guestptr gmr=%x offset=%x pitch=%x host sid=%x face=%d mipmap=%d transfer=%s cCopyBoxes=%d\n", guest.ptr.gmrId, guest.ptr.offset, guest.pitch, host.sid, host.face, host.mipmap, (transfer == SVGA3D_WRITE_HOST_VRAM) ? "READ" : "WRITE", cCopyBoxes));
|
---|
454 |
|
---|
455 | AssertMsg(host.face == 0, ("host.face=%#x\n", host.face));
|
---|
456 | AssertMsgReturn(pSurface->faces[0].numMipLevels > host.mipmap, ("numMipLevels %d, host.mipmap %d", pSurface->faces[0].numMipLevels, host.mipmap), VERR_INVALID_PARAMETER);
|
---|
457 | PVMSVGA3DMIPMAPLEVEL pMipLevel = &pSurface->pMipmapLevels[host.mipmap];
|
---|
458 |
|
---|
459 | if (!VMSVGA3DSURFACE_HAS_HW_SURFACE(pSurface))
|
---|
460 | {
|
---|
461 | /*
|
---|
462 | * Not realized in host hardware/library yet, we have to work with
|
---|
463 | * the copy of the data we've got in VMSVGA3DMIMAPLEVEL::pvSurfaceData.
|
---|
464 | */
|
---|
465 | AssertReturn(pSurface->pMipmapLevels[host.mipmap].pSurfaceData, VERR_INTERNAL_ERROR);
|
---|
466 |
|
---|
467 | for (unsigned i = 0; i < cCopyBoxes; i++)
|
---|
468 | {
|
---|
469 | unsigned uDestOffset;
|
---|
470 | unsigned cbSrcPitch;
|
---|
471 | uint8_t *pBufferStart;
|
---|
472 |
|
---|
473 | Log(("Copy box %d (%d,%d,%d)(%d,%d,%d) dest (%d,%d)\n", 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));
|
---|
474 | /* Apparently we're supposed to clip it (gmr test sample) */
|
---|
475 | if (paBoxes[i].x + paBoxes[i].w > pMipLevel->size.width)
|
---|
476 | paBoxes[i].w = pMipLevel->size.width - paBoxes[i].x;
|
---|
477 | if (paBoxes[i].y + paBoxes[i].h > pMipLevel->size.height)
|
---|
478 | paBoxes[i].h = pMipLevel->size.height - paBoxes[i].y;
|
---|
479 | if (paBoxes[i].z + paBoxes[i].d > pMipLevel->size.depth)
|
---|
480 | paBoxes[i].d = pMipLevel->size.depth - paBoxes[i].z;
|
---|
481 |
|
---|
482 | if ( !paBoxes[i].w
|
---|
483 | || !paBoxes[i].h
|
---|
484 | || !paBoxes[i].d
|
---|
485 | || paBoxes[i].x > pMipLevel->size.width
|
---|
486 | || paBoxes[i].y > pMipLevel->size.height
|
---|
487 | || paBoxes[i].z > pMipLevel->size.depth)
|
---|
488 | {
|
---|
489 | Log(("Empty box; skip\n"));
|
---|
490 | continue;
|
---|
491 | }
|
---|
492 |
|
---|
493 | uDestOffset = paBoxes[i].x * pSurface->cbBlock + paBoxes[i].y * pMipLevel->cbSurfacePitch + paBoxes[i].z * pMipLevel->size.height * pMipLevel->cbSurfacePitch;
|
---|
494 | AssertReturn(uDestOffset + paBoxes[i].w * pSurface->cbBlock * paBoxes[i].h * paBoxes[i].d <= pMipLevel->cbSurface, VERR_INTERNAL_ERROR);
|
---|
495 |
|
---|
496 | cbSrcPitch = (guest.pitch == 0) ? paBoxes[i].w * pSurface->cbBlock : guest.pitch;
|
---|
497 | #ifdef MANUAL_FLIP_SURFACE_DATA
|
---|
498 | pBufferStart = (uint8_t *)pMipLevel->pSurfaceData
|
---|
499 | + paBoxes[i].x * pSurface->cbBlock
|
---|
500 | + pMipLevel->cbSurface - paBoxes[i].y * pMipLevel->cbSurfacePitch
|
---|
501 | - pMipLevel->cbSurfacePitch; /* flip image during copy */
|
---|
502 | #else
|
---|
503 | pBufferStart = (uint8_t *)pMipLevel->pSurfaceData + uDestOffset;
|
---|
504 | #endif
|
---|
505 | rc = vmsvgaGMRTransfer(pThis,
|
---|
506 | transfer,
|
---|
507 | pBufferStart,
|
---|
508 | #ifdef MANUAL_FLIP_SURFACE_DATA
|
---|
509 | -(int32_t)pMipLevel->cbSurfacePitch,
|
---|
510 | #else
|
---|
511 | (int32_t)pMipLevel->cbSurfacePitch,
|
---|
512 | #endif
|
---|
513 | guest.ptr,
|
---|
514 | paBoxes[i].srcx * pSurface->cbBlock + (paBoxes[i].srcy + paBoxes[i].srcz * paBoxes[i].h) * cbSrcPitch,
|
---|
515 | cbSrcPitch,
|
---|
516 | paBoxes[i].w * pSurface->cbBlock,
|
---|
517 | paBoxes[i].d * paBoxes[i].h);
|
---|
518 |
|
---|
519 | Log4(("first line:\n%.*Rhxd\n", pMipLevel->cbSurfacePitch, pMipLevel->pSurfaceData));
|
---|
520 |
|
---|
521 | AssertRC(rc);
|
---|
522 | }
|
---|
523 | pSurface->pMipmapLevels[host.mipmap].fDirty = true;
|
---|
524 | pSurface->fDirty = true;
|
---|
525 | }
|
---|
526 | else
|
---|
527 | {
|
---|
528 | /*
|
---|
529 | * Because of the clipping below, we're doing a little more
|
---|
530 | * here before calling the backend specific code.
|
---|
531 | */
|
---|
532 | #ifdef VMSVGA3D_DIRECT3D
|
---|
533 | /* Flush the drawing pipeline for this surface as it could be used in a shared context. */
|
---|
534 | vmsvga3dSurfaceFlush(pThis, pSurface);
|
---|
535 | PVMSVGA3DCONTEXT pContext = NULL;
|
---|
536 |
|
---|
537 | #else /* VMSVGA3D_OPENGL */
|
---|
538 | PVMSVGA3DCONTEXT pContext = &pState->SharedCtx;
|
---|
539 | VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
|
---|
540 | #endif
|
---|
541 |
|
---|
542 | for (unsigned i = 0; i < cCopyBoxes; i++)
|
---|
543 | {
|
---|
544 | /* Apparently we're supposed to clip it (gmr test sample) */
|
---|
545 | if (paBoxes[i].x + paBoxes[i].w > pMipLevel->size.width)
|
---|
546 | paBoxes[i].w = pMipLevel->size.width - paBoxes[i].x;
|
---|
547 | if (paBoxes[i].y + paBoxes[i].h > pMipLevel->size.height)
|
---|
548 | paBoxes[i].h = pMipLevel->size.height - paBoxes[i].y;
|
---|
549 | if (paBoxes[i].z + paBoxes[i].d > pMipLevel->size.depth)
|
---|
550 | paBoxes[i].d = pMipLevel->size.depth - paBoxes[i].z;
|
---|
551 |
|
---|
552 | Assert((paBoxes[i].d == 1 || paBoxes[i].d == 0) && paBoxes[i].z == 0);
|
---|
553 |
|
---|
554 | if ( !paBoxes[i].w
|
---|
555 | || !paBoxes[i].h
|
---|
556 | || paBoxes[i].x > pMipLevel->size.width
|
---|
557 | || paBoxes[i].y > pMipLevel->size.height)
|
---|
558 | {
|
---|
559 | Log(("Empty box; skip\n"));
|
---|
560 | continue;
|
---|
561 | }
|
---|
562 |
|
---|
563 | Log(("Copy box %d (%d,%d,%d)(%d,%d,%d) dest (%d,%d)\n", 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));
|
---|
564 |
|
---|
565 | uint32_t cbSrcPitch = (guest.pitch == 0) ? paBoxes[i].w * pSurface->cbBlock : guest.pitch;
|
---|
566 | rc = vmsvga3dBackSurfaceDMACopyBox(pThis, pState, pSurface, host.mipmap, guest.ptr, cbSrcPitch, transfer,
|
---|
567 | &paBoxes[i], pContext, rc, i);
|
---|
568 | }
|
---|
569 | }
|
---|
570 |
|
---|
571 | return rc;
|
---|
572 | }
|
---|
573 |
|
---|