VirtualBox

source: vbox/trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d.cpp@ 88830

最後變更 在這個檔案從88830是 88787,由 vboxsync 提交於 4 年 前

Devices/Graphics: a few DX commands. bugref:9830

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 39.7 KB
 
1/* $Id: DevVGA-SVGA3d.cpp 88787 2021-04-29 15:51:13Z vboxsync $ */
2/** @file
3 * DevSVGA3d - VMWare SVGA device, 3D parts - Common core code.
4 */
5
6/*
7 * Copyright (C) 2013-2020 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.alldomusa.eu.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 * 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 pThisCC The VGA/VMSVGA state for ring-3.
49 * @param sid The ID of the surface to (re-)define.
50 * @param surfaceFlags .
51 * @param format .
52 * @param multisampleCount .
53 * @param autogenFilter .
54 * @param numMipLevels .
55 * @param pMipLevel0Size .
56 */
57int vmsvga3dSurfaceDefine(PVGASTATECC pThisCC, uint32_t sid, SVGA3dSurface1Flags surfaceFlags, SVGA3dSurfaceFormat format,
58 uint32_t multisampleCount, SVGA3dTextureFilter autogenFilter,
59 uint32_t numMipLevels, SVGA3dSize const *pMipLevel0Size)
60{
61 PVMSVGA3DSURFACE pSurface;
62 PVMSVGA3DSTATE pState = pThisCC->svga.p3dState;
63 AssertReturn(pState, VERR_INVALID_STATE);
64
65 LogFunc(("sid=%u surfaceFlags=%#x format=%s (%#x) multiSampleCount=%d autogenFilter=%d, numMipLevels=%d size=(%dx%dx%d)\n",
66 sid, surfaceFlags, vmsvgaLookupEnum((int)format, &g_SVGA3dSurfaceFormat2String), format, multisampleCount, autogenFilter,
67 numMipLevels, pMipLevel0Size->width, pMipLevel0Size->height, pMipLevel0Size->depth));
68
69 AssertReturn(sid < SVGA3D_MAX_SURFACE_IDS, VERR_INVALID_PARAMETER);
70 AssertReturn(numMipLevels >= 1, VERR_INVALID_PARAMETER);
71
72 if (sid >= pState->cSurfaces)
73 {
74 /* Grow the array. */
75 uint32_t cNew = RT_ALIGN(sid + 15, 16);
76 void *pvNew = RTMemRealloc(pState->papSurfaces, sizeof(pState->papSurfaces[0]) * cNew);
77 AssertReturn(pvNew, VERR_NO_MEMORY);
78 pState->papSurfaces = (PVMSVGA3DSURFACE *)pvNew;
79 while (pState->cSurfaces < cNew)
80 {
81 pSurface = (PVMSVGA3DSURFACE)RTMemAllocZ(sizeof(*pSurface));
82 AssertReturn(pSurface, VERR_NO_MEMORY);
83 pSurface->id = SVGA3D_INVALID_ID;
84 pState->papSurfaces[pState->cSurfaces++] = pSurface;
85 }
86 }
87 pSurface = pState->papSurfaces[sid];
88
89 /* If one already exists with this id, then destroy it now. */
90 if (pSurface->id != SVGA3D_INVALID_ID)
91 vmsvga3dSurfaceDestroy(pThisCC, sid);
92
93 RT_ZERO(*pSurface);
94 pSurface->id = SVGA3D_INVALID_ID; /* Keep this value until the surface init completes */
95#ifdef VMSVGA3D_OPENGL
96 pSurface->idWeakContextAssociation = SVGA3D_INVALID_ID;
97 pSurface->oglId.buffer = OPENGL_INVALID_ID;
98#elif defined(VMSVGA3D_D3D11)
99 pSurface->idAssociatedContext = SVGA3D_INVALID_ID;
100 // pSurface->pBackendSurface = NULL;
101#else /* VMSVGA3D_DIRECT3D */
102 pSurface->idAssociatedContext = SVGA3D_INVALID_ID;
103 pSurface->hSharedObject = NULL;
104 pSurface->pSharedObjectTree = NULL;
105#endif
106
107 /** @todo This 'switch' and the surfaceFlags tweaks should not be necessary.
108 * The actual surface type will be figured out when the surface is actually used later.
109 * The backends code must be reviewed for unnecessary dependencies on the surfaceFlags value.
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 Assert(surfaceFlags & SVGA3D_SURFACE_HINT_DEPTHSTENCIL);
125 surfaceFlags |= SVGA3D_SURFACE_HINT_DEPTHSTENCIL;
126 break;
127
128 /* Texture compression formats */
129 case SVGA3D_DXT1:
130 case SVGA3D_DXT2:
131 case SVGA3D_DXT3:
132 case SVGA3D_DXT4:
133 case SVGA3D_DXT5:
134 /* Bump-map formats */
135 case SVGA3D_BUMPU8V8:
136 case SVGA3D_BUMPL6V5U5:
137 case SVGA3D_BUMPX8L8V8U8:
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 Assert(surfaceFlags & (SVGA3D_SURFACE_HINT_TEXTURE | SVGA3D_SURFACE_SCREENTARGET));
152 surfaceFlags |= SVGA3D_SURFACE_HINT_TEXTURE;
153 break;
154
155 case SVGA3D_LUMINANCE8:
156 case SVGA3D_LUMINANCE4_ALPHA4:
157 case SVGA3D_LUMINANCE16:
158 case SVGA3D_LUMINANCE8_ALPHA8:
159 case SVGA3D_ARGB_S10E5: /* 16-bit floating-point ARGB */
160 case SVGA3D_ARGB_S23E8: /* 32-bit floating-point ARGB */
161 case SVGA3D_A2R10G10B10:
162 case SVGA3D_ALPHA8:
163 case SVGA3D_R_S10E5:
164 case SVGA3D_R_S23E8:
165 case SVGA3D_RG_S10E5:
166 case SVGA3D_RG_S23E8:
167 case SVGA3D_G16R16:
168 case SVGA3D_A16B16G16R16:
169 case SVGA3D_UYVY:
170 case SVGA3D_YUY2:
171 case SVGA3D_NV12:
172 case SVGA3D_FORMAT_DEAD2: /* Old SVGA3D_AYUV */
173 case SVGA3D_ATI1:
174 case SVGA3D_ATI2:
175 break;
176
177 /*
178 * Any surface can be used as a buffer object, but SVGA3D_BUFFER is
179 * the most efficient format to use when creating new surfaces
180 * expressly for index or vertex data.
181 */
182 case SVGA3D_BUFFER:
183 break;
184
185 default:
186 break;
187 }
188
189 pSurface->surfaceFlags = surfaceFlags;
190 pSurface->format = format;
191 /* cFaces is 6 for a cubemaps and 1 otherwise. */
192 pSurface->cFaces = (uint32_t)((surfaceFlags & SVGA3D_SURFACE_CUBEMAP) ? 6 : 1);
193 pSurface->cLevels = numMipLevels;
194 pSurface->multiSampleCount = multisampleCount;
195 pSurface->autogenFilter = autogenFilter;
196 Assert(autogenFilter != SVGA3D_TEX_FILTER_FLATCUBIC);
197 Assert(autogenFilter != SVGA3D_TEX_FILTER_GAUSSIANCUBIC);
198 pSurface->paMipmapLevels = (PVMSVGA3DMIPMAPLEVEL)RTMemAllocZ(numMipLevels * pSurface->cFaces * sizeof(VMSVGA3DMIPMAPLEVEL));
199 AssertReturn(pSurface->paMipmapLevels, VERR_NO_MEMORY);
200
201 pSurface->cbBlock = vmsvga3dSurfaceFormatSize(format, &pSurface->cxBlock, &pSurface->cyBlock);
202 AssertReturn(pSurface->cbBlock, VERR_INVALID_PARAMETER);
203
204 /** @todo cbMemRemaining = value of SVGA_REG_MOB_MAX_SIZE */
205 uint32_t cbMemRemaining = SVGA3D_MAX_SURFACE_MEM_SIZE; /* Do not allow more than this for a surface. */
206 SVGA3dSize mipmapSize = *pMipLevel0Size;
207 int rc = VINF_SUCCESS;
208
209 for (uint32_t i = 0; i < numMipLevels; ++i)
210 {
211 for (uint32_t iFace = 0; iFace < pSurface->cFaces; ++iFace)
212 {
213 uint32_t const iMipmap = iFace * numMipLevels + i;
214 LogFunc(("[%d] face %d mip level %d (%d,%d,%d) cbBlock=%#x block %dx%d\n",
215 iMipmap, iFace, i, mipmapSize.width, mipmapSize.height, mipmapSize.depth,
216 pSurface->cbBlock, pSurface->cxBlock, pSurface->cyBlock));
217
218 uint32_t cBlocksX;
219 uint32_t cBlocksY;
220 if (RT_LIKELY(pSurface->cxBlock == 1 && pSurface->cyBlock == 1))
221 {
222 cBlocksX = mipmapSize.width;
223 cBlocksY = mipmapSize.height;
224 }
225 else
226 {
227 cBlocksX = mipmapSize.width / pSurface->cxBlock;
228 if (mipmapSize.width % pSurface->cxBlock)
229 ++cBlocksX;
230 cBlocksY = mipmapSize.height / pSurface->cyBlock;
231 if (mipmapSize.height % pSurface->cyBlock)
232 ++cBlocksY;
233 }
234
235 AssertBreakStmt(cBlocksX > 0 && cBlocksY > 0 && mipmapSize.depth > 0, rc = VERR_INVALID_PARAMETER);
236
237 const uint32_t cMaxBlocksX = cbMemRemaining / pSurface->cbBlock;
238 AssertBreakStmt(cBlocksX < cMaxBlocksX, rc = VERR_INVALID_PARAMETER);
239
240 const uint32_t cbSurfacePitch = pSurface->cbBlock * cBlocksX;
241 LogFunc(("cbSurfacePitch=0x%x\n", cbSurfacePitch));
242
243 const uint32_t cMaxBlocksY = cbMemRemaining / cbSurfacePitch;
244 AssertBreakStmt(cBlocksY < cMaxBlocksY, rc = VERR_INVALID_PARAMETER);
245
246 const uint32_t cbSurfacePlane = cbSurfacePitch * cBlocksY;
247
248 const uint32_t cMaxDepth = cbMemRemaining / cbSurfacePlane;
249 AssertBreakStmt(mipmapSize.depth < cMaxDepth, rc = VERR_INVALID_PARAMETER);
250
251 const uint32_t cbSurface = cbSurfacePlane * mipmapSize.depth;
252
253 PVMSVGA3DMIPMAPLEVEL pMipmapLevel = &pSurface->paMipmapLevels[iMipmap];
254 pMipmapLevel->mipmapSize = mipmapSize;
255 pMipmapLevel->cBlocksX = cBlocksX;
256 pMipmapLevel->cBlocksY = cBlocksY;
257 pMipmapLevel->cBlocks = cBlocksX * cBlocksY * mipmapSize.depth;
258 pMipmapLevel->cbSurfacePitch = cbSurfacePitch;
259 pMipmapLevel->cbSurfacePlane = cbSurfacePlane;
260 pMipmapLevel->cbSurface = cbSurface;
261 pMipmapLevel->pSurfaceData = NULL;
262
263 cbMemRemaining -= cbSurface;
264 }
265
266 AssertRCBreak(rc);
267
268 mipmapSize.width >>= 1;
269 if (mipmapSize.width == 0) mipmapSize.width = 1;
270 mipmapSize.height >>= 1;
271 if (mipmapSize.height == 0) mipmapSize.height = 1;
272 mipmapSize.depth >>= 1;
273 if (mipmapSize.depth == 0) mipmapSize.depth = 1;
274 }
275
276 AssertLogRelRCReturnStmt(rc, RTMemFree(pSurface->paMipmapLevels), rc);
277
278#ifdef VMSVGA3D_DIRECT3D
279 /* Translate the format and usage flags to D3D. */
280 pSurface->d3dfmtRequested = vmsvga3dSurfaceFormat2D3D(format);
281 pSurface->formatD3D = D3D9GetActualFormat(pState, pSurface->d3dfmtRequested);
282 pSurface->multiSampleTypeD3D= vmsvga3dMultipeSampleCount2D3D(multisampleCount);
283 pSurface->fUsageD3D = 0;
284 if (surfaceFlags & SVGA3D_SURFACE_HINT_DYNAMIC)
285 pSurface->fUsageD3D |= D3DUSAGE_DYNAMIC;
286 if (surfaceFlags & SVGA3D_SURFACE_HINT_RENDERTARGET)
287 pSurface->fUsageD3D |= D3DUSAGE_RENDERTARGET;
288 if (surfaceFlags & SVGA3D_SURFACE_HINT_DEPTHSTENCIL)
289 pSurface->fUsageD3D |= D3DUSAGE_DEPTHSTENCIL;
290 if (surfaceFlags & SVGA3D_SURFACE_HINT_WRITEONLY)
291 pSurface->fUsageD3D |= D3DUSAGE_WRITEONLY;
292 if (surfaceFlags & SVGA3D_SURFACE_AUTOGENMIPMAPS)
293 pSurface->fUsageD3D |= D3DUSAGE_AUTOGENMIPMAP;
294 pSurface->enmD3DResType = VMSVGA3D_D3DRESTYPE_NONE;
295 /* pSurface->u.pSurface = NULL; */
296 /* pSurface->bounce.pTexture = NULL; */
297 /* pSurface->emulated.pTexture = NULL; */
298#elif defined(VMSVGA3D_D3D11)
299 /* Nothing, because all backend specific data reside in pSurface->pBackendSurface. */
300#else
301 /* pSurface->fEmulated = false; */
302 /* pSurface->idEmulated = OPENGL_INVALID_ID; */
303 vmsvga3dSurfaceFormat2OGL(pSurface, format);
304#endif
305
306 LogFunc(("surface hint(s):%s%s%s%s%s%s\n",
307 (surfaceFlags & SVGA3D_SURFACE_HINT_INDEXBUFFER) ? " SVGA3D_SURFACE_HINT_INDEXBUFFER" : "",
308 (surfaceFlags & SVGA3D_SURFACE_HINT_VERTEXBUFFER) ? " SVGA3D_SURFACE_HINT_VERTEXBUFFER" : "",
309 (surfaceFlags & SVGA3D_SURFACE_HINT_TEXTURE) ? " SVGA3D_SURFACE_HINT_TEXTURE" : "",
310 (surfaceFlags & SVGA3D_SURFACE_HINT_DEPTHSTENCIL) ? " SVGA3D_SURFACE_HINT_DEPTHSTENCIL" : "",
311 (surfaceFlags & SVGA3D_SURFACE_HINT_RENDERTARGET) ? " SVGA3D_SURFACE_HINT_RENDERTARGET" : "",
312 (surfaceFlags & SVGA3D_SURFACE_CUBEMAP) ? " SVGA3D_SURFACE_CUBEMAP" : ""
313 ));
314
315 Assert(!VMSVGA3DSURFACE_HAS_HW_SURFACE(pSurface));
316
317 /* Allocate buffer to hold the surface data until we can move it into a D3D object */
318 for (uint32_t i = 0; i < numMipLevels * pSurface->cFaces; ++i)
319 {
320 PVMSVGA3DMIPMAPLEVEL pMipmapLevel = &pSurface->paMipmapLevels[i];
321 pMipmapLevel->pSurfaceData = RTMemAllocZ(pMipmapLevel->cbSurface);
322 AssertReturn(pMipmapLevel->pSurfaceData, VERR_NO_MEMORY);
323 }
324
325 pSurface->id = sid;
326 return VINF_SUCCESS;
327}
328
329
330/**
331 * Implements the SVGA_3D_CMD_SURFACE_DESTROY command (fifo).
332 *
333 * @returns VBox status code (currently ignored).
334 * @param pThisCC The VGA/VMSVGA state for ring-3.
335 * @param sid The ID of the surface to destroy.
336 */
337int vmsvga3dSurfaceDestroy(PVGASTATECC pThisCC, uint32_t sid)
338{
339 PVMSVGA3DSTATE pState = pThisCC->svga.p3dState;
340 AssertReturn(pState, VERR_NO_MEMORY);
341
342 PVMSVGA3DSURFACE pSurface;
343 int rc = vmsvga3dSurfaceFromSid(pState, sid, &pSurface);
344 AssertRCReturn(rc, rc);
345
346 LogFunc(("sid=%u\n", sid));
347
348 /* Check all contexts if this surface is used as a render target or active texture. */
349 for (uint32_t cid = 0; cid < pState->cContexts; cid++)
350 {
351 PVMSVGA3DCONTEXT pContext = pState->papContexts[cid];
352 if (pContext->id == cid)
353 {
354 for (uint32_t i = 0; i < RT_ELEMENTS(pContext->aSidActiveTextures); ++i)
355 if (pContext->aSidActiveTextures[i] == sid)
356 pContext->aSidActiveTextures[i] = SVGA3D_INVALID_ID;
357 for (uint32_t i = 0; i < RT_ELEMENTS(pContext->state.aRenderTargets); ++i)
358 if (pContext->state.aRenderTargets[i] == sid)
359 pContext->state.aRenderTargets[i] = SVGA3D_INVALID_ID;
360 }
361 }
362
363 vmsvga3dBackSurfaceDestroy(pState, pSurface);
364
365 if (pSurface->paMipmapLevels)
366 {
367 for (uint32_t i = 0; i < pSurface->cLevels * pSurface->cFaces; ++i)
368 RTMemFreeZ(pSurface->paMipmapLevels[i].pSurfaceData, pSurface->paMipmapLevels[i].cbSurface);
369 RTMemFree(pSurface->paMipmapLevels);
370 }
371
372 memset(pSurface, 0, sizeof(*pSurface));
373 pSurface->id = SVGA3D_INVALID_ID;
374
375 return VINF_SUCCESS;
376}
377
378
379/**
380 * Implements the SVGA_3D_CMD_SURFACE_STRETCHBLT command (fifo).
381 *
382 * @returns VBox status code (currently ignored).
383 * @param pThis The shared VGA/VMSVGA state.
384 * @param pThisCC The VGA/VMSVGA state for ring-3.
385 * @param pDstSfcImg
386 * @param pDstBox
387 * @param pSrcSfcImg
388 * @param pSrcBox
389 * @param enmMode
390 */
391int vmsvga3dSurfaceStretchBlt(PVGASTATE pThis, PVGASTATECC pThisCC, SVGA3dSurfaceImageId const *pDstSfcImg, SVGA3dBox const *pDstBox,
392 SVGA3dSurfaceImageId const *pSrcSfcImg, SVGA3dBox const *pSrcBox, SVGA3dStretchBltMode enmMode)
393{
394 PVMSVGA3DSTATE pState = pThisCC->svga.p3dState;
395 AssertReturn(pState, VERR_NO_MEMORY);
396
397 int rc;
398
399 uint32_t const sidSrc = pSrcSfcImg->sid;
400 PVMSVGA3DSURFACE pSrcSurface;
401 rc = vmsvga3dSurfaceFromSid(pState, sidSrc, &pSrcSurface);
402 AssertRCReturn(rc, rc);
403
404 uint32_t const sidDst = pDstSfcImg->sid;
405 PVMSVGA3DSURFACE pDstSurface;
406 rc = vmsvga3dSurfaceFromSid(pState, sidDst, &pDstSurface);
407 AssertRCReturn(rc, rc);
408
409 AssertReturn(pSrcSfcImg->face < pSrcSurface->cFaces, VERR_INVALID_PARAMETER);
410 AssertReturn(pSrcSfcImg->mipmap < pSrcSurface->cLevels, VERR_INVALID_PARAMETER);
411 AssertReturn(pDstSfcImg->face < pDstSurface->cFaces, VERR_INVALID_PARAMETER);
412 AssertReturn(pDstSfcImg->mipmap < pDstSurface->cLevels, VERR_INVALID_PARAMETER);
413
414 PVMSVGA3DCONTEXT pContext;
415#ifdef VMSVGA3D_OPENGL
416 LogFunc(("src sid=%u (%d,%d)(%d,%d) dest sid=%u (%d,%d)(%d,%d) mode=%x\n",
417 sidSrc, pSrcBox->x, pSrcBox->y, pSrcBox->x + pSrcBox->w, pSrcBox->y + pSrcBox->h,
418 sidDst, pDstBox->x, pDstBox->y, pDstBox->x + pDstBox->w, pDstBox->y + pDstBox->h, enmMode));
419 pContext = &pState->SharedCtx;
420 VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
421#else
422 LogFunc(("src sid=%u cid=%u (%d,%d)(%d,%d) dest sid=%u cid=%u (%d,%d)(%d,%d) mode=%x\n",
423 sidSrc, pSrcSurface->idAssociatedContext, pSrcBox->x, pSrcBox->y, pSrcBox->x + pSrcBox->w, pSrcBox->y + pSrcBox->h,
424 sidDst, pDstSurface->idAssociatedContext, pDstBox->x, pDstBox->y, pDstBox->x + pDstBox->w, pDstBox->y + pDstBox->h, enmMode));
425
426 uint32_t cid = pDstSurface->idAssociatedContext;
427 if (cid == SVGA3D_INVALID_ID)
428 cid = pSrcSurface->idAssociatedContext;
429
430 /* At least one of surfaces must be in hardware. */
431 AssertReturn(cid != SVGA3D_INVALID_ID, VERR_INVALID_PARAMETER);
432
433 rc = vmsvga3dContextFromCid(pState, cid, &pContext);
434 AssertRCReturn(rc, rc);
435#endif
436
437 if (!VMSVGA3DSURFACE_HAS_HW_SURFACE(pSrcSurface))
438 {
439 /* Unknown surface type; turn it into a texture, which can be used for other purposes too. */
440 LogFunc(("unknown src sid=%u type=%d format=%d -> create texture\n", sidSrc, pSrcSurface->surfaceFlags, pSrcSurface->format));
441 rc = vmsvga3dBackCreateTexture(pState, pContext, pContext->id, pSrcSurface);
442 AssertRCReturn(rc, rc);
443 }
444
445 if (!VMSVGA3DSURFACE_HAS_HW_SURFACE(pDstSurface))
446 {
447 /* Unknown surface type; turn it into a texture, which can be used for other purposes too. */
448 LogFunc(("unknown dest sid=%u type=%d format=%d -> create texture\n", sidDst, pDstSurface->surfaceFlags, pDstSurface->format));
449 rc = vmsvga3dBackCreateTexture(pState, pContext, pContext->id, pDstSurface);
450 AssertRCReturn(rc, rc);
451 }
452
453 PVMSVGA3DMIPMAPLEVEL pSrcMipmapLevel;
454 rc = vmsvga3dMipmapLevel(pSrcSurface, pSrcSfcImg->face, pSrcSfcImg->mipmap, &pSrcMipmapLevel);
455 AssertRCReturn(rc, rc);
456
457 PVMSVGA3DMIPMAPLEVEL pDstMipmapLevel;
458 rc = vmsvga3dMipmapLevel(pDstSurface, pDstSfcImg->face, pDstSfcImg->mipmap, &pDstMipmapLevel);
459 AssertRCReturn(rc, rc);
460
461 SVGA3dBox clipSrcBox = *pSrcBox;
462 SVGA3dBox clipDstBox = *pDstBox;
463 vmsvgaR3ClipBox(&pSrcMipmapLevel->mipmapSize, &clipSrcBox);
464 vmsvgaR3ClipBox(&pDstMipmapLevel->mipmapSize, &clipDstBox);
465
466 return vmsvga3dBackSurfaceStretchBlt(pThis, pState,
467 pDstSurface, pDstSfcImg->face, pDstSfcImg->mipmap, &clipDstBox,
468 pSrcSurface, pSrcSfcImg->face, pSrcSfcImg->mipmap, &clipSrcBox,
469 enmMode, pContext);
470}
471
472/**
473 * Implements the SVGA_3D_CMD_SURFACE_DMA command (fifo).
474 *
475 * @returns VBox status code (currently ignored).
476 * @param pThis The shared VGA/VMSVGA instance data.
477 * @param pThisCC The VGA/VMSVGA state for ring-3.
478 * @param guest .
479 * @param host .
480 * @param transfer .
481 * @param cCopyBoxes .
482 * @param paBoxes .
483 */
484int vmsvga3dSurfaceDMA(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAGuestImage guest, SVGA3dSurfaceImageId host,
485 SVGA3dTransferType transfer, uint32_t cCopyBoxes, SVGA3dCopyBox *paBoxes)
486{
487 PVMSVGA3DSTATE pState = pThisCC->svga.p3dState;
488 AssertReturn(pState, VERR_NO_MEMORY);
489
490 PVMSVGA3DSURFACE pSurface;
491 int rc = vmsvga3dSurfaceFromSid(pState, host.sid, &pSurface);
492 AssertRCReturn(rc, rc);
493
494 LogFunc(("%sguestptr gmr=%x offset=%x pitch=%x host sid=%u face=%d mipmap=%d transfer=%s cCopyBoxes=%d\n",
495 (pSurface->surfaceFlags & SVGA3D_SURFACE_HINT_TEXTURE) ? "TEXTURE " : "",
496 guest.ptr.gmrId, guest.ptr.offset, guest.pitch,
497 host.sid, host.face, host.mipmap, (transfer == SVGA3D_WRITE_HOST_VRAM) ? "READ" : "WRITE", cCopyBoxes));
498
499 PVMSVGA3DMIPMAPLEVEL pMipLevel;
500 rc = vmsvga3dMipmapLevel(pSurface, host.face, host.mipmap, &pMipLevel);
501 AssertRCReturn(rc, rc);
502
503 PVMSVGA3DCONTEXT pContext = NULL;
504 if (!VMSVGA3DSURFACE_HAS_HW_SURFACE(pSurface))
505 {
506 /*
507 * Not realized in host hardware/library yet, we have to work with
508 * the copy of the data we've got in VMSVGA3DMIMAPLEVEL::pSurfaceData.
509 */
510 AssertReturn(pMipLevel->pSurfaceData, VERR_INTERNAL_ERROR);
511 }
512 else
513 {
514#ifdef VMSVGA3D_DIRECT3D
515 /* Flush the drawing pipeline for this surface as it could be used in a shared context. */
516 vmsvga3dSurfaceFlush(pSurface);
517#elif defined(VMSVGA3D_D3D11)
518 /** @todo */
519#else /* VMSVGA3D_OPENGL */
520 pContext = &pState->SharedCtx;
521 VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
522#endif
523 }
524
525 /* SVGA_3D_CMD_SURFACE_DMA:
526 * "define the 'source' in each copyBox as the guest image and the
527 * 'destination' as the host image, regardless of transfer direction."
528 */
529 for (uint32_t i = 0; i < cCopyBoxes; ++i)
530 {
531 Log(("Copy box (%s) %d (%d,%d,%d)(%d,%d,%d) dest (%d,%d)\n",
532 VMSVGA3DSURFACE_HAS_HW_SURFACE(pSurface) ? "hw" : "mem",
533 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));
534
535 /* Apparently we're supposed to clip it (gmr test sample) */
536
537 /* The copybox's "dest" is coords in the host surface. Verify them against the surface's mipmap size. */
538 SVGA3dBox hostBox;
539 hostBox.x = paBoxes[i].x;
540 hostBox.y = paBoxes[i].y;
541 hostBox.z = paBoxes[i].z;
542 hostBox.w = paBoxes[i].w;
543 hostBox.h = paBoxes[i].h;
544 hostBox.d = paBoxes[i].d;
545 vmsvgaR3ClipBox(&pMipLevel->mipmapSize, &hostBox);
546
547 if ( !hostBox.w
548 || !hostBox.h
549 || !hostBox.d)
550 {
551 Log(("Skip empty box\n"));
552 continue;
553 }
554 RT_UNTRUSTED_VALIDATED_FENCE();
555
556 /* Adjust the guest, i.e. "src", point.
557 * Do not try to verify them here because vmsvgaR3GmrTransfer takes care of this.
558 */
559 uint32_t const srcx = paBoxes[i].srcx + (hostBox.x - paBoxes[i].x);
560 uint32_t const srcy = paBoxes[i].srcy + (hostBox.y - paBoxes[i].y);
561 uint32_t const srcz = paBoxes[i].srcz + (hostBox.z - paBoxes[i].z);
562
563 /* Calculate offsets of the image blocks for the transfer. */
564 uint32_t u32HostBlockX;
565 uint32_t u32HostBlockY;
566 uint32_t u32GuestBlockX;
567 uint32_t u32GuestBlockY;
568 uint32_t cBlocksX;
569 uint32_t cBlocksY;
570 if (RT_LIKELY(pSurface->cxBlock == 1 && pSurface->cyBlock == 1))
571 {
572 u32HostBlockX = hostBox.x;
573 u32HostBlockY = hostBox.y;
574
575 u32GuestBlockX = srcx;
576 u32GuestBlockY = srcy;
577
578 cBlocksX = hostBox.w;
579 cBlocksY = hostBox.h;
580 }
581 else
582 {
583 /* Pixels to blocks. */
584 u32HostBlockX = hostBox.x / pSurface->cxBlock;
585 u32HostBlockY = hostBox.y / pSurface->cyBlock;
586 Assert(u32HostBlockX * pSurface->cxBlock == hostBox.x);
587 Assert(u32HostBlockY * pSurface->cyBlock == hostBox.y);
588
589 u32GuestBlockX = srcx / pSurface->cxBlock;
590 u32GuestBlockY = srcy / pSurface->cyBlock;
591 Assert(u32GuestBlockX * pSurface->cxBlock == srcx);
592 Assert(u32GuestBlockY * pSurface->cyBlock == srcy);
593
594 cBlocksX = (hostBox.w + pSurface->cxBlock - 1) / pSurface->cxBlock;
595 cBlocksY = (hostBox.h + pSurface->cyBlock - 1) / pSurface->cyBlock;
596 }
597
598 uint32_t cbGuestPitch = guest.pitch;
599 if (cbGuestPitch == 0)
600 {
601 /* Host must "assume image is tightly packed". Our surfaces are. */
602 cbGuestPitch = pMipLevel->cbSurfacePitch;
603 }
604 else
605 {
606 /* vmsvgaR3GmrTransfer will verify the value, just check it is sane. */
607 AssertReturn(cbGuestPitch <= SVGA3D_MAX_SURFACE_MEM_SIZE, VERR_INVALID_PARAMETER);
608 RT_UNTRUSTED_VALIDATED_FENCE();
609 }
610
611 /* srcx, srcy and srcz values are used to calculate the guest offset.
612 * The offset will be verified by vmsvgaR3GmrTransfer, so just check for overflows here.
613 */
614 AssertReturn(srcz < UINT32_MAX / pMipLevel->mipmapSize.height / cbGuestPitch, VERR_INVALID_PARAMETER);
615 AssertReturn(u32GuestBlockY < UINT32_MAX / cbGuestPitch, VERR_INVALID_PARAMETER);
616 AssertReturn(u32GuestBlockX < UINT32_MAX / pSurface->cbBlock, VERR_INVALID_PARAMETER);
617 RT_UNTRUSTED_VALIDATED_FENCE();
618
619 if ( !VMSVGA3DSURFACE_HAS_HW_SURFACE(pSurface)
620 || VMSVGA3DSURFACE_NEEDS_DATA(pSurface))
621 {
622 uint64_t uGuestOffset = u32GuestBlockX * pSurface->cbBlock +
623 u32GuestBlockY * cbGuestPitch +
624 srcz * pMipLevel->mipmapSize.height * cbGuestPitch;
625 AssertReturn(uGuestOffset < UINT32_MAX, VERR_INVALID_PARAMETER);
626
627 /* vmsvga3dSurfaceDefine verifies the surface dimensions and clipBox is within them. */
628 uint32_t uHostOffset = u32HostBlockX * pSurface->cbBlock +
629 u32HostBlockY * pMipLevel->cbSurfacePitch +
630 hostBox.z * pMipLevel->cbSurfacePlane;
631 AssertReturn(uHostOffset < pMipLevel->cbSurface, VERR_INTERNAL_ERROR);
632
633 for (uint32_t z = 0; z < hostBox.d; ++z)
634 {
635 rc = vmsvgaR3GmrTransfer(pThis,
636 pThisCC,
637 transfer,
638 (uint8_t *)pMipLevel->pSurfaceData,
639 pMipLevel->cbSurface,
640 uHostOffset,
641 (int32_t)pMipLevel->cbSurfacePitch,
642 guest.ptr,
643 (uint32_t)uGuestOffset,
644 cbGuestPitch,
645 cBlocksX * pSurface->cbBlock,
646 cBlocksY);
647 AssertRC(rc);
648
649 Log4(("first line [z=%d] (updated at offset 0x%x):\n%.*Rhxd\n",
650 z, uHostOffset, pMipLevel->cbSurfacePitch, pMipLevel->pSurfaceData));
651
652 uHostOffset += pMipLevel->cbSurfacePlane;
653 uGuestOffset += pMipLevel->mipmapSize.height * cbGuestPitch;
654 AssertReturn(uGuestOffset < UINT32_MAX, VERR_INVALID_PARAMETER);
655 }
656 }
657
658 if (VMSVGA3DSURFACE_HAS_HW_SURFACE(pSurface))
659 {
660 SVGA3dCopyBox clipBox;
661 clipBox.x = hostBox.x;
662 clipBox.y = hostBox.y;
663 clipBox.z = hostBox.z;
664 clipBox.w = hostBox.w;
665 clipBox.h = hostBox.h;
666 clipBox.d = hostBox.d;
667 clipBox.srcx = srcx;
668 clipBox.srcy = srcy;
669 clipBox.srcz = srcz;
670 rc = vmsvga3dBackSurfaceDMACopyBox(pThis, pThisCC, pState, pSurface, pMipLevel, host.face, host.mipmap,
671 guest.ptr, cbGuestPitch, transfer,
672 &clipBox, pContext, rc, i);
673 AssertRC(rc);
674 }
675 }
676
677 if (!VMSVGA3DSURFACE_HAS_HW_SURFACE(pSurface))
678 {
679 pMipLevel->fDirty = true;
680 pSurface->fDirty = true;
681 }
682
683 return rc;
684}
685
686static int vmsvga3dQueryWriteResult(PVGASTATE pThis, PVGASTATECC pThisCC, SVGAGuestPtr guestResult,
687 SVGA3dQueryState enmState, uint32_t u32Result)
688{
689 SVGA3dQueryResult queryResult;
690 queryResult.totalSize = sizeof(queryResult); /* Set by guest before query is ended. */
691 queryResult.state = enmState; /* Set by host or guest. See SVGA3dQueryState. */
692 queryResult.result32 = u32Result;
693
694 int rc = vmsvgaR3GmrTransfer(pThis, pThisCC, SVGA3D_READ_HOST_VRAM,
695 (uint8_t *)&queryResult, sizeof(queryResult), 0, sizeof(queryResult),
696 guestResult, 0, sizeof(queryResult), sizeof(queryResult), 1);
697 AssertRC(rc);
698 return rc;
699}
700
701int vmsvga3dQueryBegin(PVGASTATECC pThisCC, uint32_t cid, SVGA3dQueryType type)
702{
703 PVMSVGA3DSTATE pState = pThisCC->svga.p3dState;
704 AssertReturn(pState, VERR_NO_MEMORY);
705
706 LogFunc(("cid=%u type=%d\n", cid, type));
707
708 PVMSVGA3DCONTEXT pContext;
709 int rc = vmsvga3dContextFromCid(pState, cid, &pContext);
710 AssertRCReturn(rc, rc);
711
712 if (type == SVGA3D_QUERYTYPE_OCCLUSION)
713 {
714 VMSVGA3DQUERY *p = &pContext->occlusion;
715 if (!VMSVGA3DQUERY_EXISTS(p))
716 {
717 /* Lazy creation of the query object. */
718 rc = vmsvga3dOcclusionQueryCreate(pState, pContext);
719 AssertRCReturn(rc, rc);
720 }
721
722 rc = vmsvga3dOcclusionQueryBegin(pState, pContext);
723 AssertRCReturn(rc, rc);
724
725 p->enmQueryState = VMSVGA3DQUERYSTATE_BUILDING;
726 p->u32QueryResult = 0;
727
728 return VINF_SUCCESS;
729 }
730
731 /* Nothing else for VGPU9. */
732 AssertFailedReturn(VERR_NOT_IMPLEMENTED);
733}
734
735int vmsvga3dQueryEnd(PVGASTATECC pThisCC, uint32_t cid, SVGA3dQueryType type, SVGAGuestPtr guestResult)
736{
737 RT_NOREF(guestResult);
738 PVMSVGA3DSTATE pState = pThisCC->svga.p3dState;
739 AssertReturn(pState, VERR_NO_MEMORY);
740
741 LogFunc(("cid=%u type=%d guestResult %d:0x%x\n", cid, type, guestResult.gmrId, guestResult.offset));
742
743 PVMSVGA3DCONTEXT pContext;
744 int rc = vmsvga3dContextFromCid(pState, cid, &pContext);
745 AssertRCReturn(rc, rc);
746
747 if (type == SVGA3D_QUERYTYPE_OCCLUSION)
748 {
749 VMSVGA3DQUERY *p = &pContext->occlusion;
750 Assert(p->enmQueryState == VMSVGA3DQUERYSTATE_BUILDING);
751 AssertMsgReturn(VMSVGA3DQUERY_EXISTS(p), ("Query is NULL\n"), VERR_INTERNAL_ERROR);
752
753 rc = vmsvga3dOcclusionQueryEnd(pState, pContext);
754 AssertRCReturn(rc, rc);
755
756 p->enmQueryState = VMSVGA3DQUERYSTATE_ISSUED;
757
758 /* Do not touch guestResult, because the guest will call WaitForQuery. */
759 return VINF_SUCCESS;
760 }
761
762 /* Nothing else for VGPU9. */
763 AssertFailedReturn(VERR_NOT_IMPLEMENTED);
764}
765
766int vmsvga3dQueryWait(PVGASTATE pThis, PVGASTATECC pThisCC, uint32_t cid, SVGA3dQueryType type, SVGAGuestPtr guestResult)
767{
768 PVMSVGA3DSTATE pState = pThisCC->svga.p3dState;
769 AssertReturn(pState, VERR_NO_MEMORY);
770
771 LogFunc(("cid=%u type=%d guestResult GMR%d:0x%x\n", cid, type, guestResult.gmrId, guestResult.offset));
772
773 PVMSVGA3DCONTEXT pContext;
774 int rc = vmsvga3dContextFromCid(pState, cid, &pContext);
775 AssertRCReturn(rc, rc);
776
777 if (type == SVGA3D_QUERYTYPE_OCCLUSION)
778 {
779 VMSVGA3DQUERY *p = &pContext->occlusion;
780 if (VMSVGA3DQUERY_EXISTS(p))
781 {
782 if (p->enmQueryState == VMSVGA3DQUERYSTATE_ISSUED)
783 {
784 /* Only if not already in SIGNALED state,
785 * i.e. not a second read from the guest or after restoring saved state.
786 */
787 uint32_t u32Pixels = 0;
788 rc = vmsvga3dOcclusionQueryGetData(pState, pContext, &u32Pixels);
789 if (RT_SUCCESS(rc))
790 {
791 p->enmQueryState = VMSVGA3DQUERYSTATE_SIGNALED;
792 p->u32QueryResult += u32Pixels; /* += because it might contain partial result from saved state. */
793 }
794 }
795
796 if (RT_SUCCESS(rc))
797 {
798 /* Return data to the guest. */
799 vmsvga3dQueryWriteResult(pThis, pThisCC, guestResult, SVGA3D_QUERYSTATE_SUCCEEDED, p->u32QueryResult);
800 return VINF_SUCCESS;
801 }
802 }
803 else
804 {
805 AssertMsgFailed(("GetData Query is NULL\n"));
806 }
807
808 rc = VERR_INTERNAL_ERROR;
809 }
810 else
811 {
812 rc = VERR_NOT_IMPLEMENTED;
813 }
814
815 vmsvga3dQueryWriteResult(pThis, pThisCC, guestResult, SVGA3D_QUERYSTATE_FAILED, 0);
816 AssertFailedReturn(rc);
817}
818
819int vmsvga3dSurfaceBlitToScreen(PVGASTATE pThis, PVGASTATECC pThisCC, uint32_t idDstScreen, SVGASignedRect destRect,
820 SVGA3dSurfaceImageId srcImage, SVGASignedRect srcRect, uint32_t cRects, SVGASignedRect *pRect)
821{
822 /* Requires SVGA_FIFO_CAP_SCREEN_OBJECT support */
823 LogFunc(("dest=%d (%d,%d)(%d,%d) sid=%u (face=%d, mipmap=%d) (%d,%d)(%d,%d) cRects=%d\n",
824 idDstScreen, destRect.left, destRect.top, destRect.right, destRect.bottom, srcImage.sid, srcImage.face, srcImage.mipmap,
825 srcRect.left, srcRect.top, srcRect.right, srcRect.bottom, cRects));
826 for (uint32_t i = 0; i < cRects; i++)
827 {
828 LogFunc(("clipping rect %d (%d,%d)(%d,%d)\n", i, pRect[i].left, pRect[i].top, pRect[i].right, pRect[i].bottom));
829 }
830
831 VMSVGASCREENOBJECT *pScreen = vmsvgaR3GetScreenObject(pThisCC, idDstScreen);
832 AssertReturn(pScreen, VERR_INTERNAL_ERROR);
833
834 /* vmwgfx driver does not always initialize srcImage.mipmap and srcImage.face. They are assumed to be zero. */
835 SVGA3dSurfaceImageId src;
836 src.sid = srcImage.sid;
837 src.mipmap = 0;
838 src.face = 0;
839
840 if (pScreen->pHwScreen)
841 {
842 /* Use the backend accelerated method, if available. */
843 int rc = vmsvga3dBackSurfaceBlitToScreen(pThisCC, pScreen,
844 destRect, src, srcRect, cRects, pRect);
845 if (rc == VINF_SUCCESS)
846 {
847 return VINF_SUCCESS;
848 }
849 }
850
851 /** @todo scaling */
852 AssertReturn(destRect.right - destRect.left == srcRect.right - srcRect.left && destRect.bottom - destRect.top == srcRect.bottom - srcRect.top, VERR_INVALID_PARAMETER);
853
854 SVGA3dCopyBox box;
855 SVGAGuestImage dest;
856
857 box.srcz = 0;
858 box.z = 0;
859 box.d = 1;
860
861 dest.ptr.gmrId = SVGA_GMR_FRAMEBUFFER;
862 dest.ptr.offset = pScreen->offVRAM;
863 dest.pitch = pScreen->cbPitch;
864
865 if (cRects == 0)
866 {
867 /* easy case; no clipping */
868
869 /* SVGA_3D_CMD_SURFACE_DMA:
870 * 'define the "source" in each copyBox as the guest image and the
871 * "destination" as the host image, regardless of transfer direction.'
872 *
873 * Since the BlitToScreen operation transfers from a host surface to the guest VRAM,
874 * it must set the copyBox "source" to the guest destination coords and
875 * the copyBox "destination" to the host surface source coords.
876 */
877 /* Host image. */
878 box.x = srcRect.left;
879 box.y = srcRect.top;
880 box.w = srcRect.right - srcRect.left;
881 box.h = srcRect.bottom - srcRect.top;
882 /* Guest image. */
883 box.srcx = destRect.left;
884 box.srcy = destRect.top;
885
886 int rc = vmsvga3dSurfaceDMA(pThis, pThisCC, dest, src, SVGA3D_READ_HOST_VRAM, 1, &box);
887 AssertRCReturn(rc, rc);
888
889 /* Update the guest image, which is at box.src. */
890 vmsvgaR3UpdateScreen(pThisCC, pScreen, box.srcx, box.srcy, box.w, box.h);
891 }
892 else
893 {
894 /** @todo merge into one SurfaceDMA call */
895 for (uint32_t i = 0; i < cRects; i++)
896 {
897 /* "The clip rectangle coordinates are measured
898 * relative to the top-left corner of destRect."
899 * Therefore they are relative to the top-left corner of srcRect as well.
900 */
901
902 /* Host image. See 'SVGA_3D_CMD_SURFACE_DMA:' comment in the 'if' branch. */
903 box.x = srcRect.left + pRect[i].left;
904 box.y = srcRect.top + pRect[i].top;
905 box.w = pRect[i].right - pRect[i].left;
906 box.h = pRect[i].bottom - pRect[i].top;
907 /* Guest image. The target screen memory is currently in the guest VRAM. */
908 box.srcx = destRect.left + pRect[i].left;
909 box.srcy = destRect.top + pRect[i].top;
910
911 int rc = vmsvga3dSurfaceDMA(pThis, pThisCC, dest, src, SVGA3D_READ_HOST_VRAM, 1, &box);
912 AssertRCReturn(rc, rc);
913
914 /* Update the guest image, which is at box.src. */
915 vmsvgaR3UpdateScreen(pThisCC, pScreen, box.srcx, box.srcy, box.w, box.h);
916 }
917 }
918
919 return VINF_SUCCESS;
920}
921
922int vmsvga3dCommandPresent(PVGASTATE pThis, PVGASTATECC pThisCC, uint32_t sid, uint32_t cRects, SVGA3dCopyRect *pRect)
923{
924 /* Deprecated according to svga3d_reg.h. */
925 PVMSVGA3DSTATE pState = pThisCC->svga.p3dState;
926 AssertReturn(pState, VERR_NO_MEMORY);
927
928 PVMSVGA3DSURFACE pSurface;
929 int rc = vmsvga3dSurfaceFromSid(pState, sid, &pSurface);
930 AssertRCReturn(rc, rc);
931
932 /** @todo Detect screen from coords? Or split rect to screens? */
933 VMSVGASCREENOBJECT *pScreen = vmsvgaR3GetScreenObject(pThisCC, 0);
934 AssertReturn(pScreen, VERR_INTERNAL_ERROR);
935
936 /* If there are no recangles specified, just grab a screenful. */
937 SVGA3dCopyRect DummyRect;
938 if (cRects != 0)
939 { /* likely */ }
940 else
941 {
942 /** @todo Find the usecase for this or check what the original device does.
943 * The original code was doing some scaling based on the surface
944 * size... */
945 AssertMsgFailed(("No rects to present. Who is doing that and what do they actually expect?\n"));
946 DummyRect.x = DummyRect.srcx = 0;
947 DummyRect.y = DummyRect.srcy = 0;
948 DummyRect.w = pScreen->cWidth;
949 DummyRect.h = pScreen->cHeight;
950 cRects = 1;
951 pRect = &DummyRect;
952 }
953
954 uint32_t i;
955 for (i = 0; i < cRects; ++i)
956 {
957 uint32_t idDstScreen = 0; /** @todo Use virtual coords: SVGA_ID_INVALID. */
958 SVGASignedRect destRect;
959 destRect.left = pRect[i].x;
960 destRect.top = pRect[i].y;
961 destRect.right = pRect[i].x + pRect[i].w;
962 destRect.bottom = pRect[i].y + pRect[i].h;
963
964 SVGA3dSurfaceImageId src;
965 src.sid = sid;
966 src.face = 0;
967 src.mipmap = 0;
968
969 SVGASignedRect srcRect;
970 srcRect.left = pRect[i].srcx;
971 srcRect.top = pRect[i].srcy;
972 srcRect.right = pRect[i].srcx + pRect[i].w;
973 srcRect.bottom = pRect[i].srcy + pRect[i].h;
974
975 /* Entire rect. */
976 rc = vmsvga3dSurfaceBlitToScreen(pThis, pThisCC, idDstScreen, destRect, src, srcRect, 0, NULL);
977 AssertRCReturn(rc, rc);
978 }
979
980 return VINF_SUCCESS;
981}
982
983int vmsvga3dDefineScreen(PVGASTATE pThis, PVGASTATECC pThisCC, VMSVGASCREENOBJECT *pScreen)
984{
985 if (pScreen->pHwScreen)
986 {
987 vmsvga3dBackDestroyScreen(pThisCC, pScreen);
988 }
989
990 int rc = vmsvga3dBackDefineScreen(pThis, pThisCC, pScreen);
991 if (RT_SUCCESS(rc))
992 {
993 LogRelMax(1, ("VMSVGA: using accelerated graphics output\n"));
994 }
995 return rc;
996}
997
998int vmsvga3dDestroyScreen(PVGASTATECC pThisCC, VMSVGASCREENOBJECT *pScreen)
999{
1000 return vmsvga3dBackDestroyScreen(pThisCC, pScreen);
1001}
1002
1003int vmsvga3dSurfaceInvalidate(PVGASTATECC pThisCC, uint32_t sid, uint32_t face, uint32_t mipmap)
1004{
1005 PVMSVGA3DSTATE pState = pThisCC->svga.p3dState;
1006 AssertReturn(pState, VERR_INVALID_STATE);
1007
1008 PVMSVGA3DSURFACE pSurface;
1009 int rc = vmsvga3dSurfaceFromSid(pState, sid, &pSurface);
1010 AssertRCReturn(rc, rc);
1011
1012 if (face == SVGA_ID_INVALID && mipmap == SVGA_ID_INVALID)
1013 {
1014 for (uint32_t i = 0; i < pSurface->cLevels * pSurface->cFaces; ++i)
1015 {
1016 PVMSVGA3DMIPMAPLEVEL pMipmapLevel = &pSurface->paMipmapLevels[i];
1017 pMipmapLevel->fDirty = true;
1018 }
1019 }
1020 else
1021 {
1022 PVMSVGA3DMIPMAPLEVEL pMipmapLevel;
1023 rc = vmsvga3dMipmapLevel(pSurface, face, mipmap, &pMipmapLevel);
1024 AssertRCReturn(rc, rc);
1025
1026 pMipmapLevel->fDirty = true;
1027 }
1028 pSurface->fDirty = true;
1029
1030 return rc;
1031}
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette