Changeset 69136 in vbox for trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-win.cpp
- Timestamp:
- Oct 20, 2017 7:13:09 AM (7 years ago)
- svn:sync-xref-src-repo-rev:
- 118445
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-win.cpp
r67972 r69136 5 5 6 6 /* 7 * Copyright (C) 2013-201 6Oracle Corporation7 * Copyright (C) 2013-2017 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 161 161 static void vmsvgaDumpD3DCaps(D3DCAPS9 *pCaps); 162 162 163 164 #define D3D_RELEASE(ptr) do { \ 165 if (ptr) \ 166 { \ 167 (ptr)->Release(); \ 168 (ptr) = 0; \ 169 } \ 170 } while (0) 163 171 164 172 … … 318 326 RTSemEventDestroy(pState->WndRequestSem); 319 327 320 if (pState->pD3D9) 321 pState->pD3D9->Release(); 328 D3D_RELEASE(pState->pD3D9); 322 329 323 330 return VINF_SUCCESS; … … 1094 1101 { 1095 1102 RT_NOREF(pState); 1103 1096 1104 RTAvlU32Destroy(&pSurface->pSharedObjectTree, vmsvga3dSharedSurfaceDestroyTree, pSurface); 1097 1105 Assert(pSurface->pSharedObjectTree == NULL); … … 1100 1108 { 1101 1109 case SVGA3D_SURFACE_CUBEMAP: 1102 AssertFailed(); /** @todo */ 1110 case SVGA3D_SURFACE_CUBEMAP | SVGA3D_SURFACE_HINT_TEXTURE: 1111 case SVGA3D_SURFACE_CUBEMAP | SVGA3D_SURFACE_HINT_TEXTURE | SVGA3D_SURFACE_HINT_RENDERTARGET: 1112 D3D_RELEASE(pSurface->u.pCubeTexture); 1113 D3D_RELEASE(pSurface->bounce.pCubeTexture); 1103 1114 break; 1104 1115 … … 1107 1118 case SVGA3D_SURFACE_HINT_VERTEXBUFFER: 1108 1119 if (pSurface->fu32ActualUsageFlags == SVGA3D_SURFACE_HINT_VERTEXBUFFER) 1109 { 1110 if (pSurface->u.pVertexBuffer) 1111 pSurface->u.pVertexBuffer->Release(); 1112 } 1120 D3D_RELEASE(pSurface->u.pVertexBuffer); 1113 1121 else if (pSurface->fu32ActualUsageFlags == SVGA3D_SURFACE_HINT_INDEXBUFFER) 1114 { 1115 if (pSurface->u.pIndexBuffer) 1116 pSurface->u.pIndexBuffer->Release(); 1117 } 1122 D3D_RELEASE(pSurface->u.pIndexBuffer); 1118 1123 else 1119 1124 AssertMsg(pSurface->u.pVertexBuffer == NULL, ("fu32ActualUsageFlags %x\n", pSurface->fu32ActualUsageFlags)); … … 1122 1127 case SVGA3D_SURFACE_HINT_TEXTURE: 1123 1128 case SVGA3D_SURFACE_HINT_TEXTURE | SVGA3D_SURFACE_HINT_RENDERTARGET: 1124 if (pSurface->u.pTexture) 1125 pSurface->u.pTexture->Release(); 1126 if (pSurface->bounce.pTexture) 1127 pSurface->bounce.pTexture->Release(); 1129 D3D_RELEASE(pSurface->u.pTexture); 1130 D3D_RELEASE(pSurface->bounce.pTexture); 1128 1131 break; 1129 1132 … … 1132 1135 case SVGA3D_SURFACE_HINT_DEPTHSTENCIL | SVGA3D_SURFACE_HINT_TEXTURE: /** @todo actual texture surface not supported */ 1133 1136 if (pSurface->fStencilAsTexture) 1134 pSurface->u.pTexture->Release();1137 D3D_RELEASE(pSurface->u.pTexture); 1135 1138 else 1136 if (pSurface->u.pSurface) 1137 pSurface->u.pSurface->Release(); 1139 D3D_RELEASE(pSurface->u.pSurface); 1138 1140 break; 1139 1141 … … 1143 1145 } 1144 1146 1145 if (pSurface->pQuery) 1146 pSurface->pQuery->Release(); 1147 D3D_RELEASE(pSurface->pQuery); 1147 1148 } 1148 1149 … … 1156 1157 PVMSVGA3DSURFACE pSurface = (PVMSVGA3DSURFACE)pvParam; 1157 1158 1158 switch (pSurface->flags & (SVGA3D_SURFACE_HINT_INDEXBUFFER | SVGA3D_SURFACE_HINT_VERTEXBUFFER | SVGA3D_SURFACE_HINT_TEXTURE | SVGA3D_SURFACE_HINT_RENDERTARGET | SVGA3D_SURFACE_HINT_DEPTHSTENCIL | SVGA3D_SURFACE_CUBEMAP)) 1159 { 1159 switch (pSurface->flags & VMSVGA3D_SURFACE_HINT_SWITCH_MASK) 1160 { 1161 case SVGA3D_SURFACE_CUBEMAP: 1162 case SVGA3D_SURFACE_CUBEMAP | SVGA3D_SURFACE_HINT_TEXTURE: 1163 case SVGA3D_SURFACE_CUBEMAP | SVGA3D_SURFACE_HINT_TEXTURE | SVGA3D_SURFACE_HINT_RENDERTARGET: 1164 LogFunc(("release shared cube texture object for context %d\n", pNode->Key)); 1165 Assert(pSharedSurface->u.pCubeTexture); 1166 D3D_RELEASE(pSharedSurface->u.pCubeTexture); 1167 break; 1168 1160 1169 case SVGA3D_SURFACE_HINT_TEXTURE: 1161 1170 case SVGA3D_SURFACE_HINT_TEXTURE | SVGA3D_SURFACE_HINT_RENDERTARGET: 1162 Log (("vmsvga3dSharedSurfaceDestroyTree: release sharedobject for context %d\n", pNode->Key));1171 LogFunc(("release shared texture object for context %d\n", pNode->Key)); 1163 1172 Assert(pSharedSurface->u.pTexture); 1164 if (pSharedSurface->u.pTexture) 1165 pSharedSurface->u.pTexture->Release(); 1173 D3D_RELEASE(pSharedSurface->u.pTexture); 1166 1174 break; 1167 1175 … … 1175 1183 1176 1184 /* Get the shared surface copy or create a new one. */ 1177 static PVMSVGA3DSHAREDSURFACE vmsvga3dSurfaceGetSharedCopy(PV GASTATE pThis, PVMSVGA3DCONTEXT pContext, PVMSVGA3DSURFACE pSurface)1185 static PVMSVGA3DSHAREDSURFACE vmsvga3dSurfaceGetSharedCopy(PVMSVGA3DCONTEXT pContext, PVMSVGA3DSURFACE pSurface) 1178 1186 { 1179 RT_NOREF(pThis);1180 1187 Assert(pSurface->hSharedObject); 1181 1188 … … 1183 1190 if (!pSharedSurface) 1184 1191 { 1185 HRESULT hr; 1186 bool ret; 1187 1188 Log(("vmsvga3dSurfaceGetSharedCopy: Create shared texture copy d3d (%d,%d) cMip=%d usage %x format %x.\n", 1189 pSurface->pMipmapLevels[0].size.width, 1190 pSurface->pMipmapLevels[0].size.height, 1191 pSurface->faces[0], 1192 pSurface->fUsageD3D | D3DUSAGE_RENDERTARGET, 1193 pSurface->formatD3D)); 1192 const bool fCubeTexture = RT_BOOL(pSurface->flags & SVGA3D_SURFACE_CUBEMAP); 1193 const uint32_t cWidth = pSurface->pMipmapLevels[0].mipmapSize.width; 1194 const uint32_t cHeight = pSurface->pMipmapLevels[0].mipmapSize.height; 1195 const uint32_t numMipLevels = pSurface->faces[0].numMipLevels; 1196 1197 LogFunc(("Create shared %stexture copy d3d (%d,%d) cMip=%d usage %x format %x.\n", 1198 fCubeTexture ? "cube " : "", 1199 cWidth, 1200 cHeight, 1201 numMipLevels, 1202 pSurface->fUsageD3D | D3DUSAGE_RENDERTARGET, 1203 pSurface->formatD3D)); 1194 1204 1195 1205 pSharedSurface = (PVMSVGA3DSHAREDSURFACE)RTMemAllocZ(sizeof(*pSharedSurface)); … … 1197 1207 1198 1208 pSharedSurface->Core.Key = pContext->id; 1199 ret = RTAvlU32Insert(&pSurface->pSharedObjectTree, &pSharedSurface->Core);1209 bool ret = RTAvlU32Insert(&pSurface->pSharedObjectTree, &pSharedSurface->Core); 1200 1210 AssertReturn(ret, NULL); 1201 1211 1202 1212 /* Create shadow copy of the original shared texture. Shared d3d resources require Vista+ and have some restrictions. */ 1203 hr = pContext->pDevice->CreateTexture(pSurface->pMipmapLevels[0].size.width, 1204 pSurface->pMipmapLevels[0].size.height, 1205 pSurface->faces[0].numMipLevels, 1206 pSurface->fUsageD3D | D3DUSAGE_RENDERTARGET /* required for use as a StretchRect destination */, 1207 pSurface->formatD3D, 1208 D3DPOOL_DEFAULT, 1209 &pSharedSurface->u.pTexture, 1210 &pSurface->hSharedObject); 1211 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSurfaceGetSharedCopy: CreateTexture failed with %x\n", hr), NULL); 1213 HRESULT hr; 1214 if (fCubeTexture) 1215 hr = pContext->pDevice->CreateCubeTexture(cWidth, 1216 numMipLevels, 1217 pSurface->fUsageD3D | D3DUSAGE_RENDERTARGET /* required for use as a StretchRect destination */, 1218 pSurface->formatD3D, 1219 D3DPOOL_DEFAULT, 1220 &pSharedSurface->u.pCubeTexture, 1221 &pSurface->hSharedObject); 1222 else 1223 hr = pContext->pDevice->CreateTexture(cWidth, 1224 cHeight, 1225 numMipLevels, 1226 pSurface->fUsageD3D | D3DUSAGE_RENDERTARGET /* required for use as a StretchRect destination */, 1227 pSurface->formatD3D, 1228 D3DPOOL_DEFAULT, 1229 &pSharedSurface->u.pTexture, 1230 &pSurface->hSharedObject); 1231 AssertMsgReturn(hr == D3D_OK, ("CreateTexture failed with %x\n", hr), NULL); 1212 1232 } 1213 1233 return pSharedSurface; … … 1227 1247 return VINF_SUCCESS; 1228 1248 1229 Log (("vmsvga3dSurfaceTrackUsage: track usage of sid=%x (cid=%d) for cid=%d\n", pSurface->id, pSurface->idAssociatedContext, pContext->id));1249 LogFunc(("track usage of sid=%x (cid=%d) for cid=%d, pQuery %p\n", pSurface->id, pSurface->idAssociatedContext, pContext->id, pSurface->pQuery)); 1230 1250 1231 1251 /* Release the previous query object. */ 1232 if (pSurface->pQuery) 1233 { 1234 Log(("vmsvga3dSurfaceTrackUsage: release old query object\n")); 1235 pSurface->pQuery->Release(); 1236 pSurface->pQuery = NULL; 1237 } 1252 D3D_RELEASE(pSurface->pQuery); 1253 1238 1254 HRESULT hr = pContext->pDevice->CreateQuery(D3DQUERYTYPE_EVENT, &pSurface->pQuery); 1239 1255 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSurfaceTrackUsage: CreateQuery failed with %x\n", hr), VERR_INTERNAL_ERROR); … … 1290 1306 AssertMsgReturn(hr == S_OK, ("vmsvga3dSurfaceFinishDrawing: GetData failed with %x\n", hr), VERR_INTERNAL_ERROR); 1291 1307 1292 pSurface->pQuery->Release(); 1293 pSurface->pQuery = NULL; 1308 D3D_RELEASE(pSurface->pQuery); 1294 1309 #endif /* !VBOX_VMSVGA3D_WITH_WINE_OPENGL */ 1310 1311 return VINF_SUCCESS; 1312 } 1313 1314 DECLINLINE(D3DCUBEMAP_FACES) vmsvga3dCubemapFaceFromIndex(uint32_t iFace) 1315 { 1316 D3DCUBEMAP_FACES Face; 1317 switch (iFace) 1318 { 1319 case 0: Face = D3DCUBEMAP_FACE_POSITIVE_X; break; 1320 case 1: Face = D3DCUBEMAP_FACE_NEGATIVE_X; break; 1321 case 2: Face = D3DCUBEMAP_FACE_POSITIVE_Y; break; 1322 case 3: Face = D3DCUBEMAP_FACE_NEGATIVE_Y; break; 1323 case 4: Face = D3DCUBEMAP_FACE_POSITIVE_Z; break; 1324 default: 1325 case 5: Face = D3DCUBEMAP_FACE_NEGATIVE_Z; break; 1326 } 1327 return Face; 1328 } 1329 1330 /** Get IDirect3DSurface9 for the given face and mipmap. 1331 */ 1332 int vmsvga3dGetD3DSurface(PVMSVGA3DCONTEXT pContext, 1333 PVMSVGA3DSURFACE pSurface, 1334 uint32_t face, 1335 uint32_t mipmap, 1336 bool fLockable, 1337 IDirect3DSurface9 **ppD3DSurf) 1338 { 1339 AssertPtrReturn(pSurface->u.pSurface, VERR_INVALID_PARAMETER); 1340 1341 const bool fTexture = RT_BOOL(pSurface->flags & SVGA3D_SURFACE_HINT_TEXTURE); 1342 const bool fCubeTexture = RT_BOOL(pSurface->flags & SVGA3D_SURFACE_CUBEMAP); 1343 1344 IDirect3DBaseTexture9 *pTexture; 1345 if (fLockable && pSurface->bounce.pTexture) 1346 pTexture = pSurface->bounce.pTexture; 1347 else 1348 pTexture = pSurface->u.pTexture; 1349 1350 #ifndef VBOX_VMSVGA3D_WITH_WINE_OPENGL 1351 if (pSurface->idAssociatedContext != pContext->id) 1352 { 1353 AssertMsgReturn(!fLockable, 1354 ("Lockable surface must be from the same context (surface cid = %d, req cid = %d)", 1355 pSurface->idAssociatedContext, pContext->id), 1356 VERR_INVALID_PARAMETER); 1357 1358 if (fTexture) 1359 { 1360 LogFunc(("using texture sid=%x created for another context (%d vs %d)\n", 1361 pSurface->id, pSurface->idAssociatedContext, pContext->id)); 1362 1363 PVMSVGA3DSHAREDSURFACE pSharedSurface = vmsvga3dSurfaceGetSharedCopy(pContext, pSurface); 1364 AssertReturn(pSharedSurface, VERR_INTERNAL_ERROR); 1365 1366 pTexture = pSharedSurface->u.pTexture; 1367 } 1368 else 1369 { 1370 AssertMsgFailed(("surface sid=%x created for another context (%d vs %d)\n", 1371 pSurface->id, pSurface->idAssociatedContext, pContext->id)); 1372 } 1373 } 1374 #else 1375 RT_NOREF(pContext); 1376 #endif 1377 1378 if (fCubeTexture) 1379 { 1380 Assert(pSurface->cFaces == 6); 1381 1382 IDirect3DCubeTexture9 *p = (IDirect3DCubeTexture9 *)pTexture; 1383 D3DCUBEMAP_FACES FaceType = vmsvga3dCubemapFaceFromIndex(face); 1384 HRESULT hr = p->GetCubeMapSurface(FaceType, mipmap, ppD3DSurf); 1385 AssertMsgReturn(hr == D3D_OK, ("GetCubeMapSurface failed with %x\n", hr), VERR_INTERNAL_ERROR); 1386 } 1387 else if (fTexture) 1388 { 1389 Assert(pSurface->cFaces == 1); 1390 Assert(face == 0); 1391 1392 IDirect3DTexture9 *p = (IDirect3DTexture9 *)pTexture; 1393 HRESULT hr = p->GetSurfaceLevel(mipmap, ppD3DSurf); 1394 AssertMsgReturn(hr == D3D_OK, ("GetSurfaceLevel failed with %x\n", hr), VERR_INTERNAL_ERROR); 1395 } 1396 else 1397 { 1398 pSurface->u.pSurface->AddRef(); 1399 *ppD3DSurf = pSurface->u.pSurface; 1400 } 1295 1401 1296 1402 return VINF_SUCCESS; … … 1300 1406 uint32_t cCopyBoxes, SVGA3dCopyBox *pBox) 1301 1407 { 1302 PVMSVGA3DSTATE pState = pThis->svga.p3dState; 1303 PVMSVGA3DSURFACE pSurfaceSrc; 1304 uint32_t sidSrc = src.sid; 1305 PVMSVGA3DSURFACE pSurfaceDest; 1306 uint32_t sidDest = dest.sid; 1307 int rc = VINF_SUCCESS; 1308 1408 PVMSVGA3DSTATE pState = pThis->svga.p3dState; 1309 1409 AssertReturn(pState, VERR_NO_MEMORY); 1310 AssertReturn(sidSrc < SVGA3D_MAX_SURFACE_IDS, VERR_INVALID_PARAMETER); 1311 AssertReturn(sidSrc < pState->cSurfaces && pState->papSurfaces[sidSrc]->id == sidSrc, VERR_INVALID_PARAMETER); 1312 AssertReturn(sidDest < SVGA3D_MAX_SURFACE_IDS, VERR_INVALID_PARAMETER); 1313 AssertReturn(sidDest < pState->cSurfaces && pState->papSurfaces[sidDest]->id == sidDest, VERR_INVALID_PARAMETER); 1314 1315 pSurfaceSrc = pState->papSurfaces[sidSrc]; 1316 pSurfaceDest = pState->papSurfaces[sidDest]; 1317 1318 AssertReturn(pSurfaceSrc->faces[0].numMipLevels > src.mipmap, VERR_INVALID_PARAMETER); 1319 AssertReturn(pSurfaceDest->faces[0].numMipLevels > dest.mipmap, VERR_INVALID_PARAMETER); 1320 1321 const VMSVGA3DMIPMAPLEVEL *pMipmapLevelSrc = &pSurfaceSrc->pMipmapLevels[src.mipmap]; 1322 const VMSVGA3DMIPMAPLEVEL *pMipmapLevelDest = &pSurfaceDest->pMipmapLevels[dest.mipmap]; 1323 1324 // AssertMsgReturn(pSurfaceSrc->format == pSurfaceDest->format, ("Format mismatch (%d vs %d)!!\n", pSurfaceSrc->format, pSurfaceDest->format), VERR_INVALID_PARAMETER); 1325 1326 /** @todo Support cubemaps. */ 1327 bool fSrcTexture = !!(pSurfaceSrc->flags & SVGA3D_SURFACE_HINT_TEXTURE); 1328 bool fDestTexture = !!(pSurfaceDest->flags & SVGA3D_SURFACE_HINT_TEXTURE); 1410 1411 const uint32_t sidSrc = src.sid; 1412 const uint32_t sidDest = dest.sid; 1413 int rc; 1414 1415 PVMSVGA3DSURFACE pSurfaceSrc; 1416 rc = vmsvga3dSurfaceFromSid(pState, sidSrc, &pSurfaceSrc); 1417 AssertRCReturn(rc, rc); 1418 1419 PVMSVGA3DSURFACE pSurfaceDest; 1420 rc = vmsvga3dSurfaceFromSid(pState, sidDest, &pSurfaceDest); 1421 AssertRCReturn(rc, rc); 1422 1423 PVMSVGA3DMIPMAPLEVEL pMipmapLevelSrc; 1424 rc = vmsvga3dMipmapLevel(pSurfaceSrc, src.face, src.mipmap, &pMipmapLevelSrc); 1425 AssertRCReturn(rc, rc); 1426 1427 PVMSVGA3DMIPMAPLEVEL pMipmapLevelDest; 1428 rc = vmsvga3dMipmapLevel(pSurfaceDest, dest.face, dest.mipmap, &pMipmapLevelDest); 1429 AssertRCReturn(rc, rc); 1430 1431 const bool fDestTexture = RT_BOOL(pSurfaceDest->flags & SVGA3D_SURFACE_HINT_TEXTURE); 1329 1432 1330 1433 if ( fDestTexture … … 1332 1435 && pSurfaceSrc->u.pSurface) 1333 1436 { 1334 uint32_t cid; 1335 PVMSVGA3DCONTEXT pContext; 1336 1337 /** @todo stricter checks for associated context */ 1338 cid = pSurfaceSrc->idAssociatedContext; 1339 if ( cid >= pState->cContexts 1340 || pState->papContexts[cid]->id != cid) 1341 { 1342 Log(("vmsvga3dSurfaceCopy invalid context id!\n")); 1343 return VERR_INVALID_PARAMETER; 1344 } 1345 pContext = pState->papContexts[cid]; 1346 1347 Log(("vmsvga3dSurfaceCopy: create texture sid=%x type=%d format=%d -> create texture\n", sidDest, pSurfaceDest->flags, pSurfaceDest->format)); 1437 const uint32_t cid = pSurfaceSrc->idAssociatedContext; 1438 1439 PVMSVGA3DCONTEXT pContext; 1440 rc = vmsvga3dContextFromCid(pState, cid, &pContext); 1441 AssertRCReturn(rc, rc); 1442 1443 LogFunc(("sid=%x type=%x format=%d -> create texture\n", sidDest, pSurfaceDest->flags, pSurfaceDest->format)); 1348 1444 rc = vmsvga3dBackCreateTexture(pState, pContext, cid, pSurfaceDest); 1349 1445 AssertRCReturn(rc, rc); 1350 1446 } 1351 1447 1352 if ( pSurfaceSrc->u.pSurface 1353 && pSurfaceDest->u.pSurface) 1354 { 1355 uint32_t cid; 1356 PVMSVGA3DCONTEXT pContext; 1357 IDirect3DTexture9 *pSrcTexture = pSurfaceSrc->u.pTexture; 1358 1359 /** @todo stricter checks for associated context */ 1360 cid = pSurfaceDest->idAssociatedContext; 1361 if ( cid >= pState->cContexts 1362 || pState->papContexts[cid]->id != cid) 1363 { 1364 Log(("vmsvga3dSurfaceCopy invalid context id!\n")); 1365 return VERR_INVALID_PARAMETER; 1366 } 1367 pContext = pState->papContexts[cid]; 1448 if ( pSurfaceSrc->u.pSurface 1449 && pSurfaceDest->u.pSurface) 1450 { 1451 const uint32_t cidDst = pSurfaceDest->idAssociatedContext; 1452 1453 PVMSVGA3DCONTEXT pContextDst; 1454 rc = vmsvga3dContextFromCid(pState, cidDst, &pContextDst); 1455 AssertRCReturn(rc, rc); 1368 1456 1369 1457 /* Must flush the other context's 3d pipeline to make sure all drawing is complete for the surface we're about to use. */ … … 1371 1459 vmsvga3dSurfaceFlush(pThis, pSurfaceDest); 1372 1460 1373 #ifndef VBOX_VMSVGA3D_WITH_WINE_OPENGL 1374 if ( fSrcTexture 1375 && pSurfaceSrc->idAssociatedContext != cid) 1376 { 1377 Log(("vmsvga3dSurfaceCopy; using texture sid=%x created for another context (%d vs %d)\n", sidSrc, pSurfaceSrc->idAssociatedContext, cid)); 1378 1379 PVMSVGA3DSHAREDSURFACE pSharedSurface = vmsvga3dSurfaceGetSharedCopy(pThis, pContext, pSurfaceSrc); 1380 AssertReturn(pSharedSurface, VERR_INTERNAL_ERROR); 1381 1382 pSrcTexture = pSharedSurface->u.pTexture; 1383 } 1384 #endif 1385 1386 for (uint32_t i = 0; i < cCopyBoxes; i++) 1387 { 1388 HRESULT hr; 1389 RECT RectSrc; 1390 RECT RectDest; 1391 IDirect3DSurface9 *pSrc; 1392 IDirect3DSurface9 *pDest; 1461 IDirect3DSurface9 *pSrc; 1462 rc = vmsvga3dGetD3DSurface(pContextDst, pSurfaceSrc, src.face, src.mipmap, false, &pSrc); 1463 AssertRCReturn(rc, rc); 1464 1465 IDirect3DSurface9 *pDest; 1466 rc = vmsvga3dGetD3DSurface(pContextDst, pSurfaceDest, dest.face, dest.mipmap, false, &pDest); 1467 AssertRCReturnStmt(rc, D3D_RELEASE(pSrc), rc); 1468 1469 for (uint32_t i = 0; i < cCopyBoxes; ++i) 1470 { 1471 HRESULT hr; 1393 1472 1394 1473 SVGA3dCopyBox clipBox = pBox[i]; 1395 vmsvgaClipCopyBox(&pMipmapLevelSrc-> size, &pMipmapLevelDest->size, &clipBox);1474 vmsvgaClipCopyBox(&pMipmapLevelSrc->mipmapSize, &pMipmapLevelDest->mipmapSize, &clipBox); 1396 1475 if ( !clipBox.w 1397 1476 || !clipBox.h … … 1402 1481 } 1403 1482 1483 RECT RectSrc; 1404 1484 RectSrc.left = clipBox.srcx; 1405 1485 RectSrc.top = clipBox.srcy; 1406 1486 RectSrc.right = clipBox.srcx + clipBox.w; /* exclusive */ 1407 1487 RectSrc.bottom = clipBox.srcy + clipBox.h; /* exclusive */ 1488 1489 RECT RectDest; 1408 1490 RectDest.left = clipBox.x; 1409 1491 RectDest.top = clipBox.y; … … 1411 1493 RectDest.bottom = clipBox.y + clipBox.h; /* exclusive */ 1412 1494 1413 Log (("vmsvga3dSurfaceCopy: (StretchRect)copy src sid=%x face=%d mipmap=%d (%d,%d)(%d,%d) to dest sid=%x face=%d mipmap=%d (%d,%d)\n", sidSrc, src.face, src.mipmap, RectSrc.left, RectSrc.top, RectSrc.right, RectSrc.bottom, sidDest, dest.face, dest.mipmap, pBox[i].x, pBox[i].y));1495 LogFunc(("StretchRect copy src sid=%x face=%d mipmap=%d (%d,%d)(%d,%d) to dest sid=%x face=%d mipmap=%d (%d,%d)\n", sidSrc, src.face, src.mipmap, RectSrc.left, RectSrc.top, RectSrc.right, RectSrc.bottom, sidDest, dest.face, dest.mipmap, pBox[i].x, pBox[i].y)); 1414 1496 1415 1497 if ( sidSrc == sidDest … … 1417 1499 && clipBox.srcy == clipBox.y) 1418 1500 { 1419 Log (("vmsvga3dSurfaceCopy: redundant copy to the same surface at the same coordinates. Ignore.\n"));1501 LogFunc(("redundant copy to the same surface at the same coordinates. Ignore.\n")); 1420 1502 continue; 1421 1503 } … … 1423 1505 Assert(!clipBox.srcz && !clipBox.z); 1424 1506 1425 if (fSrcTexture) 1507 hr = pContextDst->pDevice->StretchRect(pSrc, &RectSrc, pDest, &RectDest, D3DTEXF_NONE); 1508 AssertMsgReturnStmt(hr == D3D_OK, 1509 ("StretchRect failed with %x\n", hr), 1510 D3D_RELEASE(pDest); D3D_RELEASE(pSrc), 1511 VERR_INTERNAL_ERROR); 1512 } 1513 1514 D3D_RELEASE(pDest); 1515 D3D_RELEASE(pSrc); 1516 1517 /* Track the StretchRect operation. */ 1518 vmsvga3dSurfaceTrackUsage(pState, pContextDst, pSurfaceSrc); 1519 vmsvga3dSurfaceTrackUsage(pState, pContextDst, pSurfaceDest); 1520 } 1521 else 1522 { 1523 /* 1524 * Copy from/to memory to/from a surface. Or mem->mem. 1525 * Use the context of existing HW surface, if any. 1526 */ 1527 PVMSVGA3DCONTEXT pContext = NULL; 1528 IDirect3DSurface9 *pD3DSurf = NULL; 1529 1530 if (pSurfaceSrc->u.pSurface) 1531 { 1532 AssertReturn(!pSurfaceDest->u.pSurface, VERR_INTERNAL_ERROR); 1533 1534 rc = vmsvga3dContextFromCid(pState, pSurfaceSrc->idAssociatedContext, &pContext); 1535 AssertRCReturn(rc, rc); 1536 1537 rc = vmsvga3dGetD3DSurface(pContext, pSurfaceSrc, src.face, src.mipmap, true, &pD3DSurf); 1538 AssertRCReturn(rc, rc); 1539 } 1540 else if (pSurfaceDest->u.pSurface) 1541 { 1542 AssertReturn(!pSurfaceSrc->u.pSurface, VERR_INTERNAL_ERROR); 1543 1544 rc = vmsvga3dContextFromCid(pState, pSurfaceDest->idAssociatedContext, &pContext); 1545 AssertRCReturn(rc, rc); 1546 1547 rc = vmsvga3dGetD3DSurface(pContext, pSurfaceDest, dest.face, dest.mipmap, true, &pD3DSurf); 1548 AssertRCReturn(rc, rc); 1549 } 1550 1551 for (uint32_t i = 0; i < cCopyBoxes; ++i) 1552 { 1553 HRESULT hr; 1554 1555 SVGA3dCopyBox clipBox = pBox[i]; 1556 vmsvgaClipCopyBox(&pMipmapLevelSrc->mipmapSize, &pMipmapLevelDest->mipmapSize, &clipBox); 1557 if ( !clipBox.w 1558 || !clipBox.h 1559 || !clipBox.d) 1426 1560 { 1427 hr = pSrcTexture->GetSurfaceLevel(src.mipmap /* Texture level */, 1428 &pSrc); 1429 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSurfaceCopy: GetSurfaceLevel failed with %x\n", hr), VERR_INTERNAL_ERROR); 1561 LogFunc(("Skipped empty box.\n")); 1562 continue; 1563 } 1564 1565 RECT RectSrc; 1566 RectSrc.left = clipBox.srcx; 1567 RectSrc.top = clipBox.srcy; 1568 RectSrc.right = clipBox.srcx + clipBox.w; /* exclusive */ 1569 RectSrc.bottom = clipBox.srcy + clipBox.h; /* exclusive */ 1570 1571 RECT RectDest; 1572 RectDest.left = clipBox.x; 1573 RectDest.top = clipBox.y; 1574 RectDest.right = clipBox.x + clipBox.w; /* exclusive */ 1575 RectDest.bottom = clipBox.y + clipBox.h; /* exclusive */ 1576 1577 LogFunc(("(manual) copy sid=%x face=%d mipmap=%d (%d,%d)(%d,%d) to sid=%x face=%d mipmap=%d (%d,%d)\n", 1578 sidSrc, src.face, src.mipmap, RectSrc.left, RectSrc.top, RectSrc.right, RectSrc.bottom, 1579 sidDest, dest.face, dest.mipmap, pBox[i].x, pBox[i].y)); 1580 1581 Assert(!clipBox.srcz && !clipBox.z); 1582 Assert(pSurfaceSrc->cbBlock == pSurfaceDest->cbBlock); 1583 Assert(pSurfaceSrc->cxBlock == pSurfaceDest->cxBlock); 1584 Assert(pSurfaceSrc->cyBlock == pSurfaceDest->cyBlock); 1585 1586 uint32_t cBlocksX = (clipBox.w + pSurfaceSrc->cxBlock - 1) / pSurfaceSrc->cxBlock; 1587 uint32_t cBlocksY = (clipBox.h + pSurfaceSrc->cyBlock - 1) / pSurfaceSrc->cyBlock; 1588 1589 D3DLOCKED_RECT LockedSrcRect; 1590 if (!pSurfaceSrc->u.pSurface) 1591 { 1592 uint32_t u32BlockX = clipBox.srcx / pSurfaceSrc->cxBlock; 1593 uint32_t u32BlockY = clipBox.srcy / pSurfaceSrc->cyBlock; 1594 Assert(u32BlockX * pSurfaceSrc->cxBlock == clipBox.srcx); 1595 Assert(u32BlockY * pSurfaceSrc->cyBlock == clipBox.srcy); 1596 1597 LockedSrcRect.pBits = (uint8_t *)pMipmapLevelSrc->pSurfaceData + 1598 pMipmapLevelSrc->cbSurfacePitch * u32BlockY + pSurfaceSrc->cbBlock * u32BlockX; 1599 LockedSrcRect.Pitch = pMipmapLevelSrc->cbSurfacePitch; 1430 1600 } 1431 1601 else 1432 pSrc = pSurfaceSrc->u.pSurface;1433 1434 if (fDestTexture)1435 1602 { 1436 hr = pSurfaceDest->u.pTexture->GetSurfaceLevel(dest.mipmap /* Texture level */, 1437 &pDest); 1438 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSurfaceCopy: GetSurfaceLevel failed with %x\n", hr), VERR_INTERNAL_ERROR); 1603 /* Must flush the context's 3d pipeline to make sure all drawing is complete for the surface we're about to use. */ 1604 vmsvga3dSurfaceFlush(pThis, pSurfaceSrc); 1605 1606 hr = pD3DSurf->LockRect(&LockedSrcRect, &RectSrc, D3DLOCK_READONLY); 1607 AssertMsgReturnStmt(hr == D3D_OK, ("LockRect failed with %x\n", hr), D3D_RELEASE(pD3DSurf), VERR_INTERNAL_ERROR); 1608 } 1609 1610 D3DLOCKED_RECT LockedDestRect; 1611 if (!pSurfaceDest->u.pSurface) 1612 { 1613 uint32_t u32BlockX = clipBox.x / pSurfaceDest->cxBlock; 1614 uint32_t u32BlockY = clipBox.y / pSurfaceDest->cyBlock; 1615 Assert(u32BlockX * pSurfaceDest->cxBlock == clipBox.x); 1616 Assert(u32BlockY * pSurfaceDest->cyBlock == clipBox.y); 1617 1618 LockedDestRect.pBits = (uint8_t *)pMipmapLevelDest->pSurfaceData + 1619 pMipmapLevelDest->cbSurfacePitch * u32BlockY + pSurfaceDest->cbBlock * u32BlockX; 1620 LockedDestRect.Pitch = pMipmapLevelDest->cbSurfacePitch; 1621 pSurfaceDest->fDirty = true; 1439 1622 } 1440 1623 else 1441 pDest = pSurfaceDest->u.pSurface;1442 1443 /* UpdateSurface is too picky; use StretchRect instead */1444 hr = pContext->pDevice->StretchRect(pSrc, &RectSrc, pDest, &RectDest, D3DTEXF_NONE);1445 1446 /* GetSurfaceLevel increases the reference count; release the objects again. */1447 if (fDestTexture)1448 pDest->Release();1449 if (fSrcTexture)1450 pSrc->Release();1451 1452 /* Track the StretchRect operation. */1453 vmsvga3dSurfaceTrackUsage(pState, pContext, pSurfaceSrc);1454 vmsvga3dSurfaceTrackUsage(pState, pContext, pSurfaceDest);1455 1456 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSurfaceCopy: UpdateSurface failed with %x\n", hr), VERR_INTERNAL_ERROR);1457 }1458 }1459 else1460 for (uint32_t i = 0; i < cCopyBoxes; i++)1461 {1462 HRESULT hr;1463 D3DLOCKED_RECT LockedSrcRect;1464 D3DLOCKED_RECT LockedDestRect;1465 RECT RectSrc;1466 RECT RectDest;1467 1468 SVGA3dCopyBox clipBox = pBox[i];1469 vmsvgaClipCopyBox(&pMipmapLevelSrc->size, &pMipmapLevelDest->size, &clipBox);1470 if ( !clipBox.w1471 || !clipBox.h1472 || !clipBox.d)1473 {1474 LogFunc(("Skipped empty box.\n"));1475 continue;1476 }1477 1478 RectSrc.left = clipBox.srcx;1479 RectSrc.top = clipBox.srcy;1480 RectSrc.right = clipBox.srcx + clipBox.w; /* exclusive */1481 RectSrc.bottom = clipBox.srcy + clipBox.h; /* exclusive */1482 RectDest.left = clipBox.x;1483 RectDest.top = clipBox.y;1484 RectDest.right = clipBox.x + clipBox.w; /* exclusive */1485 RectDest.bottom = clipBox.y + clipBox.h; /* exclusive */1486 1487 LogFunc(("(manual) copy sid=%x face=%d mipmap=%d (%d,%d)(%d,%d) to sid=%x face=%d mipmap=%d (%d,%d)\n",1488 sidSrc, src.face, src.mipmap, RectSrc.left, RectSrc.top, RectSrc.right, RectSrc.bottom,1489 sidDest, dest.face, dest.mipmap, pBox[i].x, pBox[i].y));1490 1491 Assert(!clipBox.srcz && !clipBox.z);1492 Assert(pSurfaceSrc->cbBlock == pSurfaceDest->cbBlock);1493 1494 if (!pSurfaceSrc->u.pSurface)1495 {1496 LockedSrcRect.pBits = (uint8_t *)pMipmapLevelSrc->pSurfaceData +1497 pMipmapLevelSrc->cbSurfacePitch * clipBox.srcy + pSurfaceSrc->cbBlock * clipBox.srcx;1498 LockedSrcRect.Pitch = pMipmapLevelSrc->cbSurfacePitch;1499 }1500 else1501 {1502 /** @todo This branch is dead code. Because if the source is a hardware surface, then1503 * the code above creates hardware surface for the destination and does the copy in hardware.1504 * I.e. we can not get here with pSurfaceSrc->u.pSurface != NULL.1505 */1506 1507 /* Must flush the context's 3d pipeline to make sure all drawing is complete for the surface we're about to use. */1508 vmsvga3dSurfaceFlush(pThis, pSurfaceSrc);1509 1510 if (fSrcTexture)1511 1624 { 1512 Assert(!pSurfaceSrc->bounce.pTexture); 1513 hr = pSurfaceSrc->u.pTexture->LockRect(src.mipmap, /* Texture level */ 1514 &LockedSrcRect, 1515 &RectSrc, 1516 D3DLOCK_READONLY); 1625 /* Must flush the context's 3d pipeline to make sure all drawing is complete for the surface we're about to use. */ 1626 vmsvga3dSurfaceFlush(pThis, pSurfaceDest); 1627 1628 hr = pD3DSurf->LockRect(&LockedDestRect, &RectDest, 0); 1629 AssertMsgReturnStmt(hr == D3D_OK, ("LockRect failed with %x\n", hr), D3D_RELEASE(pD3DSurf), VERR_INTERNAL_ERROR); 1630 } 1631 1632 uint8_t *pDest = (uint8_t *)LockedDestRect.pBits; 1633 const uint8_t *pSrc = (uint8_t *)LockedSrcRect.pBits; 1634 for (uint32_t j = 0; j < cBlocksY; ++j) 1635 { 1636 memcpy(pDest, pSrc, cBlocksX * pSurfaceSrc->cbBlock); 1637 pDest += LockedDestRect.Pitch; 1638 pSrc += LockedSrcRect.Pitch; 1639 } 1640 1641 if (pD3DSurf) 1642 { 1643 hr = pD3DSurf->UnlockRect(); 1644 AssertMsgReturn(hr == D3D_OK, ("Unlock failed with %x\n", hr), VERR_INTERNAL_ERROR); 1645 } 1646 } 1647 1648 /* If the destination bounce texture has been used, then update the actual texture. */ 1649 if ( pSurfaceDest->u.pSurface 1650 && fDestTexture 1651 && pSurfaceDest->bounce.pTexture) 1652 { 1653 AssertMsgReturn(pContext, ("Context is NULL\n"), VERR_INTERNAL_ERROR); 1654 1655 /* Copy the new content to the actual texture object. */ 1656 IDirect3DBaseTexture9 *pSourceTexture; 1657 IDirect3DBaseTexture9 *pDestinationTexture; 1658 if (pSurfaceDest->flags & SVGA3D_SURFACE_CUBEMAP) 1659 { 1660 pSourceTexture = pSurfaceDest->bounce.pCubeTexture; 1661 pDestinationTexture = pSurfaceDest->u.pCubeTexture; 1517 1662 } 1518 1663 else 1519 hr = pSurfaceSrc->u.pSurface->LockRect(&LockedSrcRect,1520 &RectSrc,1521 D3DLOCK_READONLY);1522 AssertMsgReturn(hr == D3D_OK, ("LockRect failed with %x\n", hr), VERR_INTERNAL_ERROR);1523 }1524 1525 if (!pSurfaceDest->u.pSurface)1526 {1527 LockedDestRect.pBits = (uint8_t *)pMipmapLevelDest->pSurfaceData +1528 pMipmapLevelDest->cbSurfacePitch * clipBox.y + pSurfaceDest->cbBlock * clipBox.x;1529 LockedDestRect.Pitch = pMipmapLevelDest->cbSurfacePitch;1530 }1531 else1532 {1533 /* Must flush the context's 3d pipeline to make sure all drawing is complete for the surface we're about to use. */1534 vmsvga3dSurfaceFlush(pThis, pSurfaceDest);1535 1536 if (fDestTexture)1537 1664 { 1538 if (pSurfaceDest->bounce.pTexture) 1539 { 1540 /* pSurfaceDest->u.pTexture can't be locked, see vmsvga3dBackCreateTexture */ 1541 hr = pSurfaceDest->bounce.pTexture->LockRect(dest.mipmap, /* texture level */ 1542 &LockedDestRect, 1543 &RectDest, 1544 0); 1545 } 1546 else 1547 { 1548 hr = pSurfaceDest->u.pTexture->LockRect(dest.mipmap, /* texture level */ 1549 &LockedDestRect, 1550 &RectDest, 1551 0); 1552 } 1665 pSourceTexture = pSurfaceDest->bounce.pTexture; 1666 pDestinationTexture = pSurfaceDest->u.pTexture; 1553 1667 } 1554 else 1555 hr = pSurfaceDest->u.pSurface->LockRect(&LockedDestRect, 1556 &RectDest, 1557 0); 1558 AssertMsgReturn(hr == D3D_OK, ("LockRect failed with %x\n", hr), VERR_INTERNAL_ERROR); 1559 } 1560 1561 uint8_t *pDest = (uint8_t *)LockedDestRect.pBits; 1562 const uint8_t *pSrc = (uint8_t *)LockedSrcRect.pBits; 1563 1564 for (uint32_t j = 0; j < clipBox.h; ++j) 1565 { 1566 memcpy(pDest, pSrc, clipBox.w * pSurfaceSrc->cbBlock); 1567 1568 pDest += LockedDestRect.Pitch; 1569 pSrc += LockedSrcRect.Pitch; 1570 } 1571 1572 if (pSurfaceDest->u.pSurface) 1573 { 1574 if (fDestTexture) 1575 { 1576 if (pSurfaceDest->bounce.pTexture) 1577 { 1578 hr = pSurfaceDest->bounce.pTexture->UnlockRect(dest.mipmap /* Texture level */); 1579 1580 /** @todo stricter checks for associated context */ 1581 PVMSVGA3DCONTEXT pContext = NULL; 1582 const uint32_t cid = pSurfaceDest->idAssociatedContext; 1583 if ( cid < pState->cContexts 1584 && pState->papContexts[cid]->id == cid) 1585 pContext = pState->papContexts[cid]; 1586 else 1587 AssertFailed(); 1588 1589 if (pContext) 1590 { 1591 /* Copy the new content to the actual texture object. */ 1592 HRESULT hr2 = pContext->pDevice->UpdateTexture(pSurfaceDest->bounce.pTexture, pSurfaceDest->u.pTexture); 1593 AssertMsg(hr2 == D3D_OK, ("UpdateTexture failed with %x\n", hr2)); RT_NOREF(hr2); 1594 } 1595 } 1596 else 1597 hr = pSurfaceDest->u.pTexture->UnlockRect(dest.mipmap /* Texture level */); 1598 } 1599 else 1600 hr = pSurfaceDest->u.pSurface->UnlockRect(); 1601 AssertMsgReturn(hr == D3D_OK, ("Unlock failed with %x\n", hr), VERR_INTERNAL_ERROR); 1602 } 1603 1604 if (pSurfaceSrc->u.pSurface) 1605 { 1606 if (fSrcTexture) 1607 hr = pSurfaceSrc->u.pTexture->UnlockRect(src.mipmap /* Texture level */); 1608 else 1609 hr = pSurfaceSrc->u.pSurface->UnlockRect(); 1610 AssertMsgReturn(hr == D3D_OK, ("Unlock failed with %x\n", hr), VERR_INTERNAL_ERROR); 1611 } 1668 HRESULT hr2 = pContext->pDevice->UpdateTexture(pSourceTexture, pDestinationTexture); 1669 AssertMsg(hr2 == D3D_OK, ("UpdateTexture failed with %x\n", hr2)); RT_NOREF(hr2); 1670 } 1671 1672 D3D_RELEASE(pD3DSurf); 1612 1673 } 1613 1674 … … 1632 1693 RT_NOREF(pState); 1633 1694 HRESULT hr; 1634 IDirect3DTexture9 *pTexture;1635 1695 1636 1696 Assert(pSurface->hSharedObject == NULL); 1637 1638 if ( pSurface->formatD3D == D3DFMT_D24S8 1639 || pSurface->formatD3D == D3DFMT_D24X8) 1640 { 1697 Assert(pSurface->u.pTexture == NULL); 1698 Assert(pSurface->bounce.pTexture == NULL); 1699 1700 const uint32_t cWidth = pSurface->pMipmapLevels[0].mipmapSize.width; 1701 const uint32_t cHeight = pSurface->pMipmapLevels[0].mipmapSize.height; 1702 const uint32_t numMipLevels = pSurface->faces[0].numMipLevels; 1703 1704 /* 1705 * Create D3D texture object. 1706 */ 1707 if (pSurface->flags & SVGA3D_SURFACE_CUBEMAP) 1708 { 1709 Assert(pSurface->cFaces == 6); 1710 Assert(cWidth == cHeight); 1711 1712 hr = pContext->pDevice->CreateCubeTexture(cWidth, 1713 numMipLevels, 1714 pSurface->fUsageD3D, 1715 pSurface->formatD3D, 1716 D3DPOOL_DEFAULT, 1717 &pSurface->u.pCubeTexture, 1718 &pSurface->hSharedObject); 1719 if (hr == D3D_OK) 1720 { 1721 /* Create another texture object to serve as a bounce buffer as the above texture surface can't be locked. */ 1722 hr = pContext->pDevice->CreateCubeTexture(cWidth, 1723 numMipLevels, 1724 (pSurface->fUsageD3D & ~D3DUSAGE_RENDERTARGET) | D3DUSAGE_DYNAMIC /* Lockable */, 1725 pSurface->formatD3D, 1726 D3DPOOL_SYSTEMMEM, 1727 &pSurface->bounce.pCubeTexture, 1728 NULL); 1729 AssertMsgReturnStmt(hr == D3D_OK, 1730 ("CreateCubeTexture (systemmem) failed with %x\n", hr), 1731 D3D_RELEASE(pSurface->u.pCubeTexture), 1732 VERR_INTERNAL_ERROR); 1733 } 1734 else 1735 { 1736 Log(("Format not accepted -> try old method\n")); 1737 /* The format was probably not accepted; fall back to our old mode. */ 1738 hr = pContext->pDevice->CreateCubeTexture(cWidth, 1739 numMipLevels, 1740 (pSurface->fUsageD3D & ~D3DUSAGE_RENDERTARGET) | D3DUSAGE_DYNAMIC /* Lockable */, 1741 pSurface->formatD3D, 1742 D3DPOOL_DEFAULT, 1743 &pSurface->u.pCubeTexture, 1744 &pSurface->hSharedObject); 1745 AssertMsgReturn(hr == D3D_OK, ("CreateCubeTexture (fallback) failed with %x\n", hr), VERR_INTERNAL_ERROR); 1746 } 1747 } 1748 else if ( pSurface->formatD3D == D3DFMT_D24S8 1749 || pSurface->formatD3D == D3DFMT_D24X8) 1750 { 1751 Assert(pSurface->cFaces == 1); 1641 1752 Assert(pSurface->faces[0].numMipLevels == 1); 1753 1642 1754 /* Use the INTZ format for a depth/stencil surface that will be used as a texture */ 1643 hr = pContext->pDevice->CreateTexture( pSurface->pMipmapLevels[0].size.width,1644 pSurface->pMipmapLevels[0].size.height,1755 hr = pContext->pDevice->CreateTexture(cWidth, 1756 cHeight, 1645 1757 1, 1646 1758 D3DUSAGE_DEPTHSTENCIL, … … 1649 1761 &pSurface->u.pTexture, 1650 1762 &pSurface->hSharedObject /* might result in poor performance */); 1651 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dBackCreateTexture: CreateTexture INTZ failed with %x\n", hr), VERR_INTERNAL_ERROR); 1652 pTexture = pSurface->u.pTexture; 1763 AssertMsgReturn(hr == D3D_OK, ("CreateTexture INTZ failed with %x\n", hr), VERR_INTERNAL_ERROR); 1653 1764 1654 1765 pSurface->fStencilAsTexture = true; … … 1656 1767 else 1657 1768 { 1658 hr = pContext->pDevice->CreateTexture(pSurface->pMipmapLevels[0].size.width, 1659 pSurface->pMipmapLevels[0].size.height, 1660 pSurface->faces[0].numMipLevels, 1769 /** @todo if (depth > 1) CreateVolumeTexture */ 1770 Assert(pSurface->cFaces == 1); 1771 1772 hr = pContext->pDevice->CreateTexture(cWidth, 1773 cHeight, 1774 numMipLevels, 1661 1775 pSurface->fUsageD3D | D3DUSAGE_RENDERTARGET /* required for use as a StretchRect destination */, 1662 1776 pSurface->formatD3D, … … 1667 1781 { 1668 1782 /* Create another texture object to serve as a bounce buffer as the above texture surface can't be locked. */ 1669 hr = pContext->pDevice->CreateTexture( pSurface->pMipmapLevels[0].size.width,1670 pSurface->pMipmapLevels[0].size.height,1671 pSurface->faces[0].numMipLevels,1783 hr = pContext->pDevice->CreateTexture(cWidth, 1784 cHeight, 1785 numMipLevels, 1672 1786 (pSurface->fUsageD3D & ~D3DUSAGE_RENDERTARGET) | D3DUSAGE_DYNAMIC /* Lockable */, 1673 1787 pSurface->formatD3D, … … 1675 1789 &pSurface->bounce.pTexture, 1676 1790 NULL); 1677 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dBackCreateTexture: CreateTexture (systemmem) failed with %x\n", hr), VERR_INTERNAL_ERROR); 1678 pTexture = pSurface->bounce.pTexture; 1791 AssertMsgReturn(hr == D3D_OK, ("CreateTexture (systemmem) failed with %x\n", hr), VERR_INTERNAL_ERROR); 1679 1792 } 1680 1793 else … … 1682 1795 Log(("Format not accepted -> try old method\n")); 1683 1796 /* The format was probably not accepted; fall back to our old mode. */ 1684 hr = pContext->pDevice->CreateTexture( pSurface->pMipmapLevels[0].size.width,1685 pSurface->pMipmapLevels[0].size.height,1686 pSurface->faces[0].numMipLevels,1797 hr = pContext->pDevice->CreateTexture(cWidth, 1798 cHeight, 1799 numMipLevels, 1687 1800 (pSurface->fUsageD3D & ~D3DUSAGE_RENDERTARGET) | D3DUSAGE_DYNAMIC /* Lockable */, 1688 1801 pSurface->formatD3D, … … 1690 1803 &pSurface->u.pTexture, 1691 1804 &pSurface->hSharedObject /* might result in poor performance */); 1692 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dBackCreateTexture: CreateTexture failed with %x\n", hr), VERR_INTERNAL_ERROR); 1693 pTexture = pSurface->u.pTexture; 1805 AssertMsgReturn(hr == D3D_OK, ("CreateTexture failed with %x\n", hr), VERR_INTERNAL_ERROR); 1694 1806 } 1695 1807 } … … 1698 1810 { 1699 1811 /* Set the mip map generation filter settings. */ 1700 hr = pSurface->u.pTexture->SetAutoGenFilterType((D3DTEXTUREFILTERTYPE)pSurface->autogenFilter); 1812 if (pSurface->flags & SVGA3D_SURFACE_CUBEMAP) 1813 hr = pSurface->u.pCubeTexture->SetAutoGenFilterType((D3DTEXTUREFILTERTYPE)pSurface->autogenFilter); 1814 else 1815 hr = pSurface->u.pTexture->SetAutoGenFilterType((D3DTEXTUREFILTERTYPE)pSurface->autogenFilter); 1701 1816 AssertMsg(hr == D3D_OK, ("vmsvga3dBackCreateTexture: SetAutoGenFilterType failed with %x\n", hr)); 1702 1817 } … … 1708 1823 */ 1709 1824 Log(("vmsvga3dBackCreateTexture: sync texture\n")); 1710 for (uint32_t i = 0; i < pSurface->faces[0].numMipLevels; i++) 1711 { 1712 D3DLOCKED_RECT LockedRect; 1713 1714 hr = pTexture->LockRect(i, /* texture level */ 1715 &LockedRect, 1716 NULL, /* entire texture */ 1717 0); 1718 1719 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dBackCreateTexture: LockRect failed with %x\n", hr), VERR_INTERNAL_ERROR); 1720 1721 Log(("vmsvga3dBackCreateTexture: sync texture mipmap level %d (pitch %x vs %x)\n", i, LockedRect.Pitch, pSurface->pMipmapLevels[i].cbSurfacePitch)); 1722 1723 uint8_t *pDest = (uint8_t *)LockedRect.pBits; 1724 uint8_t *pSrc = (uint8_t *)pSurface->pMipmapLevels[i].pSurfaceData; 1725 for (uint32_t j = 0; j < pSurface->pMipmapLevels[i].size.height; j++) 1726 { 1727 memcpy(pDest, pSrc, pSurface->pMipmapLevels[i].cbSurfacePitch); 1728 1729 pDest += LockedRect.Pitch; 1730 pSrc += pSurface->pMipmapLevels[i].cbSurfacePitch; 1731 } 1732 1733 hr = pTexture->UnlockRect(i /* texture level */); 1734 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dBackCreateTexture: UnlockRect failed with %x\n", hr), VERR_INTERNAL_ERROR); 1735 1736 pSurface->pMipmapLevels[i].fDirty = false; 1825 1826 if (pSurface->flags & SVGA3D_SURFACE_CUBEMAP) 1827 { 1828 IDirect3DCubeTexture9 *pCubeTexture = pSurface->bounce.pCubeTexture ? 1829 pSurface->bounce.pCubeTexture : 1830 pSurface->u.pCubeTexture; 1831 1832 for (uint32_t iFace = 0; iFace < 6; ++iFace) 1833 { 1834 const D3DCUBEMAP_FACES Face = vmsvga3dCubemapFaceFromIndex(iFace); 1835 1836 for (uint32_t i = 0; i < numMipLevels; ++i) 1837 { 1838 D3DLOCKED_RECT LockedRect; 1839 hr = pCubeTexture->LockRect(Face, 1840 i, /* texture level */ 1841 &LockedRect, 1842 NULL, /* entire texture */ 1843 0); 1844 AssertMsgBreak(hr == D3D_OK, ("LockRect failed with %x\n", hr)); 1845 1846 PVMSVGA3DMIPMAPLEVEL pMipLevel = &pSurface->pMipmapLevels[iFace * numMipLevels + i]; 1847 1848 LogFunc(("sync texture face %d mipmap level %d (pitch %x vs %x)\n", 1849 iFace, i, LockedRect.Pitch, pMipLevel->cbSurfacePitch)); 1850 1851 uint8_t *pDest = (uint8_t *)LockedRect.pBits; 1852 const uint8_t *pSrc = (uint8_t *)pMipLevel->pSurfaceData; 1853 for (uint32_t j = 0; j < pMipLevel->cBlocksY; ++j) 1854 { 1855 memcpy(pDest, pSrc, pMipLevel->cbSurfacePitch); 1856 1857 pDest += LockedRect.Pitch; 1858 pSrc += pMipLevel->cbSurfacePitch; 1859 } 1860 1861 hr = pCubeTexture->UnlockRect(Face, i /* texture level */); 1862 AssertMsgBreak(hr == D3D_OK, ("UnlockRect failed with %x\n", hr)); 1863 1864 pMipLevel->fDirty = false; 1865 } 1866 1867 if (hr != D3D_OK) 1868 break; 1869 } 1870 1871 if (hr != D3D_OK) 1872 { 1873 D3D_RELEASE(pSurface->bounce.pCubeTexture); 1874 D3D_RELEASE(pSurface->u.pCubeTexture); 1875 return VERR_INTERNAL_ERROR; 1876 } 1877 } 1878 else 1879 { 1880 IDirect3DTexture9 *pTexture = pSurface->bounce.pTexture ? pSurface->bounce.pTexture : pSurface->u.pTexture; 1881 1882 for (uint32_t i = 0; i < numMipLevels; ++i) 1883 { 1884 D3DLOCKED_RECT LockedRect; 1885 1886 hr = pTexture->LockRect(i, /* texture level */ 1887 &LockedRect, 1888 NULL, /* entire texture */ 1889 0); 1890 1891 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dBackCreateTexture: LockRect failed with %x\n", hr), VERR_INTERNAL_ERROR); 1892 1893 Log(("vmsvga3dBackCreateTexture: sync texture mipmap level %d (pitch %x vs %x)\n", i, LockedRect.Pitch, pSurface->pMipmapLevels[i].cbSurfacePitch)); 1894 1895 uint8_t *pDest = (uint8_t *)LockedRect.pBits; 1896 const uint8_t *pSrc = (uint8_t *)pSurface->pMipmapLevels[i].pSurfaceData; 1897 for (uint32_t j = 0; j < pSurface->pMipmapLevels[i].cBlocksY; ++j) 1898 { 1899 memcpy(pDest, pSrc, pSurface->pMipmapLevels[i].cbSurfacePitch); 1900 1901 pDest += LockedRect.Pitch; 1902 pSrc += pSurface->pMipmapLevels[i].cbSurfacePitch; 1903 } 1904 1905 hr = pTexture->UnlockRect(i /* texture level */); 1906 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dBackCreateTexture: UnlockRect failed with %x\n", hr), VERR_INTERNAL_ERROR); 1907 1908 pSurface->pMipmapLevels[i].fDirty = false; 1909 } 1737 1910 } 1738 1911 … … 1741 1914 Log(("vmsvga3dBackCreateTexture: sync dirty texture from bounce buffer\n")); 1742 1915 1743 hr = pContext->pDevice->UpdateTexture(pSurface->bounce.pTexture, pSurface->u.pTexture); 1916 if (pSurface->flags & SVGA3D_SURFACE_CUBEMAP) 1917 hr = pContext->pDevice->UpdateTexture(pSurface->bounce.pCubeTexture, pSurface->u.pCubeTexture); 1918 else 1919 hr = pContext->pDevice->UpdateTexture(pSurface->bounce.pTexture, pSurface->u.pTexture); 1744 1920 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dBackCreateTexture: UpdateTexture failed with %x\n", hr), VERR_INTERNAL_ERROR); 1745 1921 … … 1766 1942 * @param pState The VMSVGA3d state. 1767 1943 * @param pDstSurface The destination host surface. 1944 * @param uDstFace The destination face (valid). 1768 1945 * @param uDstMipmap The destination mipmap level (valid). 1769 1946 * @param pDstBox The destination box. 1770 1947 * @param pSrcSurface The source host surface. 1948 * @param uSrcFace The destination face (valid). 1771 1949 * @param uSrcMipmap The source mimap level (valid). 1772 1950 * @param pSrcBox The source box. … … 1775 1953 */ 1776 1954 int vmsvga3dBackSurfaceStretchBlt(PVGASTATE pThis, PVMSVGA3DSTATE pState, 1777 PVMSVGA3DSURFACE pDstSurface, uint32_t uDst Mipmap, SVGA3dBox const *pDstBox,1778 PVMSVGA3DSURFACE pSrcSurface, uint32_t uSrc Mipmap, SVGA3dBox const *pSrcBox,1955 PVMSVGA3DSURFACE pDstSurface, uint32_t uDstFace, uint32_t uDstMipmap, SVGA3dBox const *pDstBox, 1956 PVMSVGA3DSURFACE pSrcSurface, uint32_t uSrcFace, uint32_t uSrcMipmap, SVGA3dBox const *pSrcBox, 1779 1957 SVGA3dStretchBltMode enmMode, PVMSVGA3DCONTEXT pContext) 1780 1958 { 1781 1959 HRESULT hr; 1960 int rc; 1782 1961 1783 1962 /* Flush the drawing pipeline for this surface as it could be used in a shared context. */ … … 1800 1979 1801 1980 IDirect3DSurface9 *pSrc; 1802 bool const fSrcTexture = !!(pSrcSurface->flags & SVGA3D_SURFACE_HINT_TEXTURE); 1803 if (fSrcTexture) 1804 { 1805 hr = pSrcSurface->u.pTexture->GetSurfaceLevel(uSrcMipmap /* Texture level */, &pSrc); 1806 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSurfaceStretchBlt: GetSurfaceLevel failed with %x\n", hr), VERR_INTERNAL_ERROR); 1807 } 1808 else 1809 pSrc = pSrcSurface->u.pSurface; 1981 rc = vmsvga3dGetD3DSurface(pContext, pSrcSurface, uSrcFace, uSrcMipmap, false, &pSrc); 1982 AssertRCReturn(rc, rc); 1810 1983 1811 1984 IDirect3DSurface9 *pDst; 1812 bool const fDstTexture = !!(pDstSurface->flags & SVGA3D_SURFACE_HINT_TEXTURE); 1813 if (fDstTexture) 1814 { 1815 hr = pDstSurface->u.pTexture->GetSurfaceLevel(uDstMipmap /* Texture level */, &pDst); 1816 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSurfaceStretchBlt: GetSurfaceLevel failed with %x\n", hr), VERR_INTERNAL_ERROR); 1817 } 1818 else 1819 pDst = pDstSurface->u.pSurface; 1985 rc = vmsvga3dGetD3DSurface(pContext, pDstSurface, uDstFace, uDstMipmap, false, &pDst); 1986 AssertRCReturn(rc, rc); 1820 1987 1821 1988 D3DTEXTUREFILTERTYPE moded3d; … … 1838 2005 hr = pContext->pDevice->StretchRect(pSrc, &RectSrc, pDst, &RectDst, moded3d); 1839 2006 1840 /* GetSurfaceLevel increases the reference count; release the objects again. */ 1841 if (fDstTexture) 1842 pDst->Release(); 1843 if (fSrcTexture) 1844 pSrc->Release(); 1845 1846 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSurfaceStretchBlt: StretchRect failed with %x\n", hr), VERR_INTERNAL_ERROR); 2007 D3D_RELEASE(pDst); 2008 D3D_RELEASE(pSrc); 2009 2010 AssertMsgReturn(hr == D3D_OK, ("StretchRect failed with %x\n", hr), VERR_INTERNAL_ERROR); 1847 2011 1848 2012 /* Track the StretchRect operation. */ … … 1861 2025 * @param pState The VMSVGA3d state. 1862 2026 * @param pSurface The host surface. 2027 * @param pMipLevel Mipmap level. The caller knows it already. 2028 * @param uHostFace The host face (valid). 1863 2029 * @param uHostMipmap The host mipmap level (valid). 1864 2030 * @param GuestPtr The guest pointer. 1865 * @param cb SrcPitch The guest (?)pitch.2031 * @param cbGuestPitch The guest pitch. 1866 2032 * @param transfer The transfer direction. 1867 * @param pBox The box to copy .2033 * @param pBox The box to copy (clipped, valid). 1868 2034 * @param pContext The context (for OpenGL). 1869 2035 * @param rc The current rc for all boxes. 1870 2036 * @param iBox The current box number (for Direct 3D). 1871 2037 */ 1872 int vmsvga3dBackSurfaceDMACopyBox(PVGASTATE pThis, PVMSVGA3DSTATE pState, PVMSVGA3DSURFACE pSurface, uint32_t uHostMipmap, 1873 SVGAGuestPtr GuestPtr, uint32_t cbSrcPitch, SVGA3dTransferType transfer, 2038 int vmsvga3dBackSurfaceDMACopyBox(PVGASTATE pThis, PVMSVGA3DSTATE pState, PVMSVGA3DSURFACE pSurface, 2039 PVMSVGA3DMIPMAPLEVEL pMipLevel, uint32_t uHostFace, uint32_t uHostMipmap, 2040 SVGAGuestPtr GuestPtr, uint32_t cbGuestPitch, SVGA3dTransferType transfer, 1874 2041 SVGA3dCopyBox const *pBox, PVMSVGA3DCONTEXT pContext, int rc, int iBox) 1875 2042 { 1876 2043 HRESULT hr = D3D_OK; 1877 DWORD dwFlags = transfer == SVGA3D_READ_HOST_VRAM ? D3DLOCK_READONLY : 0; 1878 bool fTexture = false; 1879 bool fVertex = false; 1880 bool fRenderTargetTexture = false; 1881 switch (pSurface->flags & VMSVGA3D_SURFACE_HINT_SWITCH_MASK) 1882 { 1883 case SVGA3D_SURFACE_HINT_TEXTURE | SVGA3D_SURFACE_HINT_RENDERTARGET: 1884 fRenderTargetTexture = true; 1885 /* no break */ 1886 case SVGA3D_SURFACE_HINT_TEXTURE: 1887 fTexture = true; 1888 /* no break */ 1889 case SVGA3D_SURFACE_HINT_DEPTHSTENCIL: 1890 if (pSurface->fStencilAsTexture) 1891 fTexture = true; 1892 /* no break */ 1893 case SVGA3D_SURFACE_HINT_RENDERTARGET: 1894 { 1895 D3DLOCKED_RECT LockedRect; 2044 const uint32_t u32SurfHints = pSurface->flags & VMSVGA3D_SURFACE_HINT_SWITCH_MASK; 2045 const DWORD dwFlags = transfer == SVGA3D_READ_HOST_VRAM ? D3DLOCK_READONLY : 0; 2046 // if (u32SurfHints != 0x18 && u32SurfHints != 0x60) ASMBreakpoint(); 2047 2048 bool fTexture = RT_BOOL(u32SurfHints & (SVGA3D_SURFACE_HINT_TEXTURE | 2049 SVGA3D_SURFACE_CUBEMAP)) 2050 || pSurface->fStencilAsTexture; 2051 2052 bool fRenderTarget = RT_BOOL(u32SurfHints & SVGA3D_SURFACE_HINT_RENDERTARGET); 2053 2054 if (fTexture || fRenderTarget) 2055 { 2056 rc = vmsvga3dContextFromCid(pState, pSurface->idAssociatedContext, &pContext); 2057 AssertRCReturn(rc, rc); 2058 2059 /* Get the surface involved in the transfer. */ 2060 IDirect3DSurface9 *pSurf; 2061 rc = vmsvga3dGetD3DSurface(pContext, pSurface, uHostFace, uHostMipmap, true, &pSurf); 2062 AssertRCReturn(rc, rc); 2063 2064 /** @todo inefficient for VRAM buffers!! */ 2065 if (fTexture) 2066 { 2067 if (pSurface->bounce.pTexture) 2068 { 2069 if ( transfer == SVGA3D_READ_HOST_VRAM 2070 && fRenderTarget 2071 && iBox == 0 /* only the first time */) 2072 { 2073 /* Copy the texture mipmap level to the bounce texture. */ 2074 2075 /* Source is the texture, destination is the bounce texture. */ 2076 IDirect3DSurface9 *pSrc; 2077 rc = vmsvga3dGetD3DSurface(pContext, pSurface, uHostFace, uHostMipmap, false, &pSrc); 2078 AssertRCReturn(rc, rc); 2079 2080 Assert(pSurf != pSrc); 2081 2082 hr = pContext->pDevice->GetRenderTargetData(pSrc, pSurf); 2083 AssertMsgReturn(hr == D3D_OK, ("GetRenderTargetData failed with %x\n", hr), VERR_INTERNAL_ERROR); 2084 2085 D3D_RELEASE(pSrc); 2086 } 2087 } 2088 } 2089 1896 2090 RECT Rect; 1897 1898 2091 Rect.left = pBox->x; 1899 2092 Rect.top = pBox->y; … … 1901 2094 Rect.bottom = pBox->y + pBox->h; /* exclusive */ 1902 2095 1903 /** @todo inefficient for VRAM buffers!! */ 1904 if (fTexture) 1905 { 1906 if (pSurface->bounce.pTexture) 1907 { 1908 if ( transfer == SVGA3D_READ_HOST_VRAM 1909 && fRenderTargetTexture 1910 && iBox == 0 /* only the first time */) 1911 { 1912 IDirect3DSurface9 *pSrc, *pDest; 1913 1914 /** @todo stricter checks for associated context */ 1915 uint32_t cid = pSurface->idAssociatedContext; 1916 if ( cid >= pState->cContexts 1917 || pState->papContexts[cid]->id != cid) 1918 { 1919 Log(("vmsvga3dSurfaceDMA invalid context id (%x - %x)!\n", cid, (cid >= pState->cContexts) ? -1 : pState->papContexts[cid]->id)); 1920 AssertFailedReturn(VERR_INVALID_PARAMETER); 1921 } 1922 pContext = pState->papContexts[cid]; 1923 1924 /** @todo only sync when something was actually rendered (since the last sync) */ 1925 Log(("vmsvga3dSurfaceDMA: sync bounce buffer\n")); 1926 hr = pSurface->bounce.pTexture->GetSurfaceLevel(uHostMipmap, &pDest); 1927 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSurfaceDMA: GetSurfaceLevel failed with %x\n", hr), VERR_INTERNAL_ERROR); 1928 1929 hr = pSurface->u.pTexture->GetSurfaceLevel(uHostMipmap, &pSrc); 1930 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSurfaceDMA: GetSurfaceLevel failed with %x\n", hr), VERR_INTERNAL_ERROR); 1931 1932 hr = pContext->pDevice->GetRenderTargetData(pSrc, pDest); 1933 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSurfaceDMA: GetRenderTargetData failed with %x\n", hr), VERR_INTERNAL_ERROR); 1934 1935 pSrc->Release(); 1936 pDest->Release(); 1937 } 1938 1939 hr = pSurface->bounce.pTexture->LockRect(uHostMipmap, /* texture level */ 1940 &LockedRect, 1941 &Rect, 1942 dwFlags); 1943 } 1944 else 1945 hr = pSurface->u.pTexture->LockRect(uHostMipmap, /* texture level */ 1946 &LockedRect, 1947 &Rect, 1948 dwFlags); 1949 } 1950 else 1951 hr = pSurface->u.pSurface->LockRect(&LockedRect, 1952 &Rect, 1953 dwFlags); 1954 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSurfaceDMA: LockRect failed with %x\n", hr), VERR_INTERNAL_ERROR); 1955 1956 if (fTexture) 1957 Log(("Lock sid=%x TEXTURE (bounce=%d) memory for rectangle (%d,%d)(%d,%d)\n", pSurface->id, !!(pSurface->bounce.pTexture), Rect.left, Rect.top, Rect.right, Rect.bottom)); 1958 else 1959 Log(("Lock sid=%x %s memory for rectangle (%d,%d)(%d,%d)\n", pSurface->id, (pSurface->flags & SVGA3D_SURFACE_HINT_DEPTHSTENCIL) ? "DEPTH-STENCIL" : "RENDERTARGET", Rect.left, Rect.top, Rect.right, Rect.bottom)); 2096 D3DLOCKED_RECT LockedRect; 2097 hr = pSurf->LockRect(&LockedRect, &Rect, dwFlags); 2098 AssertMsgReturn(hr == D3D_OK, ("LockRect failed with %x\n", hr), VERR_INTERNAL_ERROR); 2099 2100 LogFunc(("Lock sid=%x %s(bounce=%d) memory for rectangle (%d,%d)(%d,%d)\n", 2101 pSurface->id, fTexture ? "TEXTURE " : "", RT_BOOL(pSurface->bounce.pTexture), 2102 Rect.left, Rect.top, Rect.right, Rect.bottom)); 2103 2104 uint32_t u32BlockX = pBox->srcx / pSurface->cxBlock; 2105 uint32_t u32BlockY = pBox->srcy / pSurface->cyBlock; 2106 Assert(u32BlockX * pSurface->cxBlock == pBox->srcx); 2107 Assert(u32BlockY * pSurface->cyBlock == pBox->srcy); 2108 uint32_t cBlocksX = (pBox->w + pSurface->cxBlock - 1) / pSurface->cxBlock; 2109 uint32_t cBlocksY = (pBox->h + pSurface->cyBlock - 1) / pSurface->cyBlock; 1960 2110 1961 2111 rc = vmsvgaGMRTransfer(pThis, … … 1964 2114 LockedRect.Pitch, 1965 2115 GuestPtr, 1966 pBox->srcx * pSurface->cbBlock + pBox->srcy * cbSrcPitch,1967 cb SrcPitch,1968 pBox->w* pSurface->cbBlock,1969 pBox->h);2116 u32BlockX * pSurface->cbBlock + u32BlockY * cbGuestPitch, 2117 cbGuestPitch, 2118 cBlocksX * pSurface->cbBlock, 2119 cBlocksY); 1970 2120 AssertRC(rc); 1971 2121 1972 Log4(("first line:\n%.*Rhxd\n", pBox->w * pSurface->cbBlock, LockedRect.pBits)); 2122 Log4(("first line:\n%.*Rhxd\n", cBlocksX * pSurface->cbBlock, LockedRect.pBits)); 2123 2124 hr = pSurf->UnlockRect(); 2125 2126 D3D_RELEASE(pSurf); 2127 2128 AssertMsgReturn(hr == D3D_OK, ("UnlockRect failed with %x\n", hr), VERR_INTERNAL_ERROR); 1973 2129 1974 2130 if (fTexture) … … 1976 2132 if (pSurface->bounce.pTexture) 1977 2133 { 1978 hr = pSurface->bounce.pTexture->UnlockRect(uHostMipmap);1979 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSurfaceDMA: UnlockRect failed with %x\n", hr), VERR_INTERNAL_ERROR);1980 1981 2134 if (transfer == SVGA3D_WRITE_HOST_VRAM) 1982 2135 { 1983 /** @todo stricter checks for associated context */ 1984 uint32_t cid = pSurface->idAssociatedContext; 1985 if ( cid >= pState->cContexts 1986 || pState->papContexts[cid]->id != cid) 1987 { 1988 Log(("vmsvga3dSurfaceDMA invalid context id!\n")); 1989 AssertFailedReturn(VERR_INVALID_PARAMETER); 1990 } 1991 pContext = pState->papContexts[cid]; 1992 1993 Log(("vmsvga3dSurfaceDMA: sync texture from bounce buffer\n")); 2136 LogFunc(("Sync texture from bounce buffer\n")); 1994 2137 1995 2138 /* Copy the new contents to the actual texture object. */ … … 2001 2144 } 2002 2145 } 2003 else 2004 hr = pSurface->u.pTexture->UnlockRect(uHostMipmap); 2005 } 2006 else 2007 hr = pSurface->u.pSurface->UnlockRect(); 2008 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSurfaceDMA: UnlockRect failed with %x\n", hr), VERR_INTERNAL_ERROR); 2009 break; 2010 } 2011 2012 case SVGA3D_SURFACE_HINT_VERTEXBUFFER | SVGA3D_SURFACE_HINT_INDEXBUFFER: 2013 case SVGA3D_SURFACE_HINT_VERTEXBUFFER: 2014 fVertex = RT_BOOL(pSurface->fu32ActualUsageFlags & SVGA3D_SURFACE_HINT_VERTEXBUFFER); 2015 /* no break */ 2016 2017 case SVGA3D_SURFACE_HINT_INDEXBUFFER: 2018 { 2019 uint8_t *pData; 2020 unsigned uDestOffset; 2021 2022 uDestOffset = pBox->x * pSurface->cbBlock + pBox->y * pSurface->pMipmapLevels[uHostMipmap].cbSurfacePitch; 2023 AssertReturn(uDestOffset + pBox->w * pSurface->cbBlock + (pBox->h - 1) * pSurface->pMipmapLevels[uHostMipmap].cbSurfacePitch <= pSurface->pMipmapLevels[uHostMipmap].cbSurface, VERR_INTERNAL_ERROR); 2024 2146 } 2147 } 2148 else if (RT_BOOL(u32SurfHints & (SVGA3D_SURFACE_HINT_VERTEXBUFFER | 2149 SVGA3D_SURFACE_HINT_INDEXBUFFER))) 2150 { 2151 /* 2152 * Mesa SVGA driver can use the same buffer either for vertex or index data. 2153 * But D3D distinguishes between index and vertex buffer objects. 2154 * Therefore it should be possible to switch the buffer type on the fly. 2155 * 2156 * Always save the data to the memory buffer in pSurface->pMipmapLevels and, 2157 * if necessary, recreate the corresponding D3D object with the data. 2158 */ 2159 2160 /* Buffers are uncompressed. */ 2161 AssertReturn(pSurface->cxBlock == 1 && pSurface->cyBlock == 1, VERR_INTERNAL_ERROR); 2162 2163 /* Current type of the buffer. */ 2164 const bool fVertex = RT_BOOL(pSurface->fu32ActualUsageFlags & SVGA3D_SURFACE_HINT_VERTEXBUFFER); 2165 2166 /* Caller already clipped pBox and buffers are 1-dimensional. */ 2167 Assert(pBox->y == 0 && pBox->h == 1 && pBox->z == 0 && pBox->d == 1); 2168 2169 const uint32_t uHostOffset = pBox->x * pSurface->cbBlock; 2170 const uint32_t cbWidth = pBox->w * pSurface->cbBlock; 2171 2172 AssertReturn(uHostOffset < pMipLevel->cbSurface, VERR_INTERNAL_ERROR); 2173 AssertReturn(cbWidth <= pMipLevel->cbSurface, VERR_INTERNAL_ERROR); 2174 AssertReturn(uHostOffset <= pMipLevel->cbSurface - cbWidth, VERR_INTERNAL_ERROR); 2175 2176 uint8_t *pu8HostData = (uint8_t *)pMipLevel->pSurfaceData + uHostOffset; 2177 2178 const uint32_t uGuestOffset = pBox->srcx * pSurface->cbBlock; 2179 2180 /* Copy data between the guest and the host buffer. */ 2181 rc = vmsvgaGMRTransfer(pThis, 2182 transfer, 2183 pu8HostData, 2184 pMipLevel->cbSurfacePitch, 2185 GuestPtr, 2186 uGuestOffset, 2187 cbGuestPitch, 2188 cbWidth, 2189 1); /* Buffers are 1-dimensional */ 2190 AssertRC(rc); 2191 2192 Log4(("Buffer first line:\n%.*Rhxd\n", cbWidth, pu8HostData)); 2193 2194 pMipLevel->fDirty = true; 2195 pSurface->fDirty = true; 2196 2197 /* Also copy the data to the current D3D buffer object. */ 2198 uint8_t *pu8Buffer = NULL; 2025 2199 /** @todo lock only as much as we really need */ 2026 2200 if (fVertex) 2027 hr = pSurface->u.pVertexBuffer->Lock(0, 0, (void **)&p Data, dwFlags);2201 hr = pSurface->u.pVertexBuffer->Lock(0, 0, (void **)&pu8Buffer, dwFlags); 2028 2202 else 2029 hr = pSurface->u.pIndexBuffer->Lock(0, 0, (void **)&pData, dwFlags); 2030 AssertMsg(hr == D3D_OK, ("vmsvga3dSurfaceDMA: Lock %s failed with %x\n", (fVertex) ? "vertex" : "index", hr)); 2031 2032 Log(("Lock %s memory for rectangle (%d,%d)(%d,%d)\n", (fVertex) ? "vertex" : "index", pBox->x, pBox->y, pBox->x + pBox->w, pBox->y + pBox->h)); 2033 2034 rc = vmsvgaGMRTransfer(pThis, 2035 transfer, 2036 pData + uDestOffset, 2037 pSurface->pMipmapLevels[uHostMipmap].cbSurfacePitch, 2038 GuestPtr, 2039 pBox->srcx * pSurface->cbBlock + pBox->srcy * cbSrcPitch, 2040 cbSrcPitch, 2041 pBox->w * pSurface->cbBlock, 2042 pBox->h); 2043 AssertRC(rc); 2044 2045 Log4(("first line:\n%.*Rhxd\n", cbSrcPitch, pData)); 2203 hr = pSurface->u.pIndexBuffer->Lock(0, 0, (void **)&pu8Buffer, dwFlags); 2204 AssertMsgReturn(hr == D3D_OK, ("Lock %s failed with %x\n", fVertex ? "vertex" : "index", hr), VERR_INTERNAL_ERROR); 2205 2206 LogFunc(("Lock %s memory for rectangle (%d,%d)(%d,%d)\n", fVertex ? "vertex" : "index", pBox->x, pBox->y, pBox->x + pBox->w, pBox->y + pBox->h)); 2207 2208 const uint8_t *pu8Src = pu8HostData; 2209 uint8_t *pu8Dst = pu8Buffer + uHostOffset; 2210 memcpy(pu8Dst, pu8Src, cbWidth); 2046 2211 2047 2212 if (fVertex) … … 2049 2214 else 2050 2215 hr = pSurface->u.pIndexBuffer->Unlock(); 2051 AssertMsg(hr == D3D_OK, ("vmsvga3dSurfaceDMA: Unlock %s failed with %x\n", (fVertex) ? "vertex" : "index", hr)); 2052 break; 2053 } 2054 2055 default: 2056 AssertMsgFailed(("Unsupported surface hint 0x%08X\n", pSurface->flags & VMSVGA3D_SURFACE_HINT_SWITCH_MASK)); 2057 break; 2216 AssertMsg(hr == D3D_OK, ("Unlock %s failed with %x\n", fVertex ? "vertex" : "index", hr)); 2217 } 2218 else 2219 { 2220 AssertMsgFailed(("Unsupported surface hint 0x%08X\n", u32SurfHints)); 2058 2221 } 2059 2222 … … 2168 2331 2169 2332 pContext->pDevice->ColorFill(pSrc, NULL, (D3DCOLOR)0x11122255); 2170 pSrc->Release();2333 D3D_RELEASE(pSrc); 2171 2334 } 2172 2335 } … … 2302 2465 * Blit the surface rectangle(s) to the back buffer. 2303 2466 */ 2304 uint32_t const cxSurface = pSurface->pMipmapLevels[0].size.width; 2305 uint32_t const cySurface = pSurface->pMipmapLevels[0].size.height; 2467 Assert(pSurface->cxBlock == 1 && pSurface->cyBlock == 1); 2468 uint32_t const cxSurface = pSurface->pMipmapLevels[0].mipmapSize.width; 2469 uint32_t const cySurface = pSurface->pMipmapLevels[0].mipmapSize.height; 2306 2470 for (uint32_t i = 0; i < cRects; i++) 2307 2471 { … … 2449 2613 2450 2614 if (pSurface->flags & SVGA3D_SURFACE_HINT_TEXTURE) 2451 pSurfaceD3D->Release();2615 D3D_RELEASE(pSurfaceD3D); 2452 2616 2453 2617 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dCommandPresent: StretchRect failed with %x\n", hr), VERR_INTERNAL_ERROR); … … 2456 2620 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dCommandPresent: Present failed with %x\n", hr), VERR_INTERNAL_ERROR); 2457 2621 2458 pBackBuffer->Release();2622 D3D_RELEASE(pBackBuffer); 2459 2623 return VINF_SUCCESS; 2460 2624 } … … 2476 2640 PVMSVGA3DSTATE pState = pThis->svga.p3dState; 2477 2641 2642 Log(("vmsvga3dContextDefine id %x\n", cid)); 2643 2478 2644 AssertReturn(pState, VERR_NO_MEMORY); 2479 2645 AssertReturn(cid < SVGA3D_MAX_CONTEXT_IDS, VERR_INVALID_PARAMETER); 2480 2481 Log(("vmsvga3dContextDefine id %x\n", cid));2482 2646 2483 2647 if (cid >= pState->cContexts) … … 2630 2794 { 2631 2795 uint32_t idx = i + face * pSurface->faces[0].numMipLevels; 2632 memcpy(&pMipLevelSize[idx], &pSurface->pMipmapLevels[idx]. size, sizeof(SVGA3dSize));2796 memcpy(&pMipLevelSize[idx], &pSurface->pMipmapLevels[idx].mipmapSize, sizeof(SVGA3dSize)); 2633 2797 } 2634 2798 } … … 2655 2819 Log(("vmsvga3dContextDestroy: remove shared dependency for surface sid=%x\n", sid)); 2656 2820 2657 switch (pSurface->flags & (SVGA3D_SURFACE_HINT_INDEXBUFFER | SVGA3D_SURFACE_HINT_VERTEXBUFFER | SVGA3D_SURFACE_HINT_TEXTURE | SVGA3D_SURFACE_HINT_RENDERTARGET | SVGA3D_SURFACE_HINT_DEPTHSTENCIL | SVGA3D_SURFACE_CUBEMAP))2821 switch (pSurface->flags & VMSVGA3D_SURFACE_HINT_SWITCH_MASK) 2658 2822 { 2659 2823 case SVGA3D_SURFACE_HINT_TEXTURE: 2660 2824 case SVGA3D_SURFACE_HINT_TEXTURE | SVGA3D_SURFACE_HINT_RENDERTARGET: 2661 2825 Assert(pSharedSurface->u.pTexture); 2662 if (pSharedSurface->u.pTexture) 2663 pSharedSurface->u.pTexture->Release(); 2826 D3D_RELEASE(pSharedSurface->u.pTexture); 2664 2827 break; 2665 2828 … … 2698 2861 2699 2862 /* Release the D3D device object */ 2700 pContext->pDevice->Release();2863 D3D_RELEASE(pContext->pDevice); 2701 2864 2702 2865 /* Destroy the window we've created. */ … … 2788 2951 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dChangeMode: GetRenderTargetData failed with %x\n", hr), VERR_INTERNAL_ERROR); 2789 2952 2790 pSrc->Release();2791 pDest->Release();2953 D3D_RELEASE(pSrc); 2954 D3D_RELEASE(pDest); 2792 2955 2793 2956 hr = pSurface->bounce.pTexture->LockRect(i, … … 2818 2981 2819 2982 2820 switch (pSurface->flags & (SVGA3D_SURFACE_HINT_INDEXBUFFER | SVGA3D_SURFACE_HINT_VERTEXBUFFER | SVGA3D_SURFACE_HINT_TEXTURE | SVGA3D_SURFACE_HINT_RENDERTARGET | SVGA3D_SURFACE_HINT_DEPTHSTENCIL | SVGA3D_SURFACE_CUBEMAP))2983 switch (pSurface->flags & VMSVGA3D_SURFACE_HINT_SWITCH_MASK) 2821 2984 { 2822 2985 case SVGA3D_SURFACE_CUBEMAP: 2823 AssertFailed(); /** @todo */ 2986 case SVGA3D_SURFACE_CUBEMAP | SVGA3D_SURFACE_HINT_TEXTURE: 2987 case SVGA3D_SURFACE_CUBEMAP | SVGA3D_SURFACE_HINT_TEXTURE | SVGA3D_SURFACE_HINT_RENDERTARGET: 2988 D3D_RELEASE(pSurface->u.pCubeTexture); 2989 D3D_RELEASE(pSurface->bounce.pCubeTexture); 2824 2990 break; 2825 2991 2992 case SVGA3D_SURFACE_HINT_INDEXBUFFER | SVGA3D_SURFACE_HINT_VERTEXBUFFER: 2826 2993 case SVGA3D_SURFACE_HINT_INDEXBUFFER: 2827 pSurface->u.pIndexBuffer->Release();2828 break;2829 2830 2994 case SVGA3D_SURFACE_HINT_VERTEXBUFFER: 2831 pSurface->u.pVertexBuffer->Release(); 2832 pSurface->u.pVertexBuffer = NULL; 2995 if (pSurface->fu32ActualUsageFlags == SVGA3D_SURFACE_HINT_VERTEXBUFFER) 2996 D3D_RELEASE(pSurface->u.pVertexBuffer); 2997 else if (pSurface->fu32ActualUsageFlags == SVGA3D_SURFACE_HINT_INDEXBUFFER) 2998 D3D_RELEASE(pSurface->u.pIndexBuffer); 2999 else 3000 AssertMsg(pSurface->u.pVertexBuffer == NULL, ("fu32ActualUsageFlags %x\n", pSurface->fu32ActualUsageFlags)); 2833 3001 break; 2834 3002 2835 3003 case SVGA3D_SURFACE_HINT_TEXTURE: 2836 3004 case SVGA3D_SURFACE_HINT_TEXTURE | SVGA3D_SURFACE_HINT_RENDERTARGET: 2837 pSurface->u.pTexture->Release(); 2838 pSurface->u.pTexture = NULL; 2839 if (pSurface->bounce.pTexture) 2840 { 2841 pSurface->bounce.pTexture->Release(); 2842 pSurface->bounce.pTexture = NULL; 2843 } 3005 D3D_RELEASE(pSurface->u.pTexture); 3006 D3D_RELEASE(pSurface->bounce.pTexture); 2844 3007 break; 2845 3008 … … 2847 3010 case SVGA3D_SURFACE_HINT_DEPTHSTENCIL: 2848 3011 if (pSurface->fStencilAsTexture) 2849 pSurface->u.pTexture->Release();3012 D3D_RELEASE(pSurface->u.pTexture); 2850 3013 else 2851 pSurface->u.pSurface->Release(); 2852 pSurface->u.pSurface = NULL; 3014 D3D_RELEASE(pSurface->u.pSurface); 2853 3015 break; 2854 3016 2855 3017 default: 3018 AssertFailed(); 2856 3019 break; 2857 3020 } … … 3882 4045 3883 4046 hr = pContext->pDevice->SetRenderTarget(type - SVGA3D_RT_COLOR0, pDummyRenderTarget); 3884 pDummyRenderTarget->Release();4047 D3D_RELEASE(pDummyRenderTarget); 3885 4048 } 3886 4049 else … … 3934 4097 { 3935 4098 Log(("vmsvga3dSetRenderTarget DEPTH/STENCIL; cQualityLevels=%d\n", cQualityLevels)); 3936 hr = pContext->pDevice->CreateDepthStencilSurface(pRenderTarget->pMipmapLevels[0]. size.width,3937 pRenderTarget->pMipmapLevels[0]. size.height,4099 hr = pContext->pDevice->CreateDepthStencilSurface(pRenderTarget->pMipmapLevels[0].mipmapSize.width, 4100 pRenderTarget->pMipmapLevels[0].mipmapSize.height, 3938 4101 pRenderTarget->formatD3D, 3939 4102 pRenderTarget->multiSampleTypeD3D, … … 4004 4167 4005 4168 hr = pContext->pDevice->SetDepthStencilSurface(pStencilSurface); 4006 pStencilSurface->Release();4169 D3D_RELEASE(pStencilSurface); 4007 4170 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSetRenderTarget: SetDepthStencilSurface failed with %x\n", hr), VERR_INTERNAL_ERROR); 4008 4171 } … … 4047 4210 Log(("vmsvga3dSetRenderTarget; using texture sid=%x created for another context (%d vs %d)\n", target.sid, pRenderTarget->idAssociatedContext, cid)); 4048 4211 4049 PVMSVGA3DSHAREDSURFACE pSharedSurface = vmsvga3dSurfaceGetSharedCopy(p This, pContext, pRenderTarget);4212 PVMSVGA3DSHAREDSURFACE pSharedSurface = vmsvga3dSurfaceGetSharedCopy(pContext, pRenderTarget); 4050 4213 AssertReturn(pSharedSurface, VERR_INTERNAL_ERROR); 4051 4214 … … 4082 4245 4083 4246 Log(("vmsvga3dSetRenderTarget COLOR; cQualityLevels=%d\n", cQualityLevels)); 4084 Log(("Create rendertarget (%d,%d) format=%x multisample=%x\n", pRenderTarget->pMipmapLevels[0]. size.width, pRenderTarget->pMipmapLevels[0].size.height, pRenderTarget->formatD3D, pRenderTarget->multiSampleTypeD3D));4085 4086 hr = pContext->pDevice->CreateRenderTarget(pRenderTarget->pMipmapLevels[0]. size.width,4087 pRenderTarget->pMipmapLevels[0]. size.height,4247 Log(("Create rendertarget (%d,%d) format=%x multisample=%x\n", pRenderTarget->pMipmapLevels[0].mipmapSize.width, pRenderTarget->pMipmapLevels[0].mipmapSize.height, pRenderTarget->formatD3D, pRenderTarget->multiSampleTypeD3D)); 4248 4249 hr = pContext->pDevice->CreateRenderTarget(pRenderTarget->pMipmapLevels[0].mipmapSize.width, 4250 pRenderTarget->pMipmapLevels[0].mipmapSize.height, 4088 4251 pRenderTarget->formatD3D, 4089 4252 pRenderTarget->multiSampleTypeD3D, … … 4111 4274 hr = pContext->pDevice->SetRenderTarget(type - SVGA3D_RT_COLOR0, pSurface); 4112 4275 if (fTexture) 4113 pSurface->Release(); /* Release reference to texture level 0 */4276 D3D_RELEASE(pSurface); /* Release reference to texture level 0 */ 4114 4277 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSetRenderTarget: SetRenderTarget failed with %x\n", hr), VERR_INTERNAL_ERROR); 4115 4278 … … 4390 4553 PVMSVGA3DSURFACE pSurface = pState->papSurfaces[sid]; 4391 4554 4392 Log(("SVGA3D_TS_BIND_TEXTURE: stage %d, texture sid=%x (%d,%d)\n", currentStage, pTextureState[i].value, pSurface->pMipmapLevels[0]. size.width, pSurface->pMipmapLevels[0].size.height));4555 Log(("SVGA3D_TS_BIND_TEXTURE: stage %d, texture sid=%x (%d,%d)\n", currentStage, pTextureState[i].value, pSurface->pMipmapLevels[0].mipmapSize.width, pSurface->pMipmapLevels[0].mipmapSize.height)); 4393 4556 4394 4557 if (!pSurface->u.pTexture) 4395 4558 { 4396 4559 Assert(pSurface->idAssociatedContext == SVGA3D_INVALID_ID); 4397 Log(("CreateTexture (%d,%d) level=%d fUsage=%x format=%x\n", pSurface->pMipmapLevels[0]. size.width, pSurface->pMipmapLevels[0].size.height, pSurface->faces[0].numMipLevels, pSurface->fUsageD3D, pSurface->formatD3D));4560 Log(("CreateTexture (%d,%d) level=%d fUsage=%x format=%x\n", pSurface->pMipmapLevels[0].mipmapSize.width, pSurface->pMipmapLevels[0].mipmapSize.height, pSurface->faces[0].numMipLevels, pSurface->fUsageD3D, pSurface->formatD3D)); 4398 4561 int rc = vmsvga3dBackCreateTexture(pState, pContext, cid, pSurface); 4399 4562 AssertRCReturn(rc, rc); … … 4410 4573 Log(("vmsvga3dSetTextureState; using texture sid=%x created for another context (%d vs %d)\n", sid, pSurface->idAssociatedContext, cid)); 4411 4574 4412 PVMSVGA3DSHAREDSURFACE pSharedSurface = vmsvga3dSurfaceGetSharedCopy(p This, pContext, pSurface);4575 PVMSVGA3DSHAREDSURFACE pSharedSurface = vmsvga3dSurfaceGetSharedCopy(pContext, pSurface); 4413 4576 AssertReturn(pSharedSurface, VERR_INTERNAL_ERROR); 4414 4577 … … 4884 5047 uVertexMinOffset = pVertexDecl[iVertex].array.offset; 4885 5048 5049 /* pVertexSurface->u. is an union, so pVertexSurface->u.pIndexBuffer and pVertexSurface->u.pVertexBuffer are the same */ 5050 if ( pVertexSurface->u.pVertexBuffer 5051 && !(pVertexSurface->fu32ActualUsageFlags & SVGA3D_SURFACE_HINT_VERTEXBUFFER)) 5052 { 5053 /* The buffer object is not an vertex one. Switch type. */ 5054 Assert(pVertexSurface->fu32ActualUsageFlags & SVGA3D_SURFACE_HINT_INDEXBUFFER); 5055 pVertexSurface->fu32ActualUsageFlags &= ~SVGA3D_SURFACE_HINT_INDEXBUFFER; 5056 5057 D3D_RELEASE(pVertexSurface->u.pIndexBuffer); 5058 LogFunc(("index -> vertex buffer sid=%x\n", sidVertex)); 5059 } 5060 4886 5061 if (!pVertexSurface->u.pVertexBuffer) 4887 5062 { … … 4916 5091 pVertexSurface->fu32ActualUsageFlags |= SVGA3D_SURFACE_HINT_VERTEXBUFFER; 4917 5092 } 4918 else4919 Assert(pVertexSurface->fDirty == false);4920 5093 } 4921 5094 … … 5085 5258 Log(("vmsvga3dDrawPrimitives: index sid=%x\n", sidIndex)); 5086 5259 5260 /* pIndexSurface->u. is an union, so pIndexSurface->u.pIndexBuffer and pIndexSurface->u.pVertexBuffer are the same */ 5261 if ( pIndexSurface->u.pIndexBuffer 5262 && !(pIndexSurface->fu32ActualUsageFlags & SVGA3D_SURFACE_HINT_INDEXBUFFER)) 5263 { 5264 /* The buffer object is not an index one. Switch type. */ 5265 Assert(pIndexSurface->fu32ActualUsageFlags & SVGA3D_SURFACE_HINT_VERTEXBUFFER); 5266 pIndexSurface->fu32ActualUsageFlags &= ~SVGA3D_SURFACE_HINT_VERTEXBUFFER; 5267 5268 D3D_RELEASE(pIndexSurface->u.pVertexBuffer); 5269 LogFunc(("vertex -> index buffer sid=%x\n", sidIndex)); 5270 } 5271 5087 5272 if (!pIndexSurface->u.pIndexBuffer) 5088 5273 { … … 5122 5307 pIndexSurface->fu32ActualUsageFlags |= SVGA3D_SURFACE_HINT_INDEXBUFFER; 5123 5308 } 5124 else5125 Assert(pIndexSurface->fDirty == false);5126 5309 5127 5310 hr = pContext->pDevice->SetIndices(pIndexSurface->u.pIndexBuffer); … … 5183 5366 } 5184 5367 } 5185 pVertexDeclD3D->Release();5368 D3D_RELEASE(pVertexDeclD3D); 5186 5369 RTMemFree(pVertexElement); 5187 5370 … … 5217 5400 AssertMsgReturn(hr == S_OK, ("vmsvga3dSurfaceFinishDrawing: GetData failed with %x\n", hr), VERR_INTERNAL_ERROR); 5218 5401 5219 pQuery->Release();5402 D3D_RELEASE(pQuery); 5220 5403 } 5221 5404 #endif … … 5239 5422 5240 5423 internal_error: 5241 if (pVertexDeclD3D) 5242 pVertexDeclD3D->Release(); 5424 D3D_RELEASE(pVertexDeclD3D); 5243 5425 if (pVertexElement) 5244 5426 RTMemFree(pVertexElement); … … 5293 5475 5294 5476 Log(("vmsvga3dShaderDefine %x shid=%x type=%s cbData=%x\n", cid, shid, (type == SVGA3D_SHADERTYPE_VS) ? "VERTEX" : "PIXEL", cbData)); 5295 Log3(("shader code:\n%.*Rhxd\n", cbData, pShaderData)); 5477 #ifdef LOG_ENABLED 5478 Log3(("Shader code:\n")); 5479 const uint32_t cTokensPerLine = 8; 5480 const uint32_t *paTokens = (uint32_t *)pShaderData; 5481 const uint32_t cTokens = cbData / sizeof(uint32_t); 5482 for (uint32_t iToken = 0; iToken < cTokens; ++iToken) 5483 { 5484 if ((iToken % cTokensPerLine) == 0) 5485 { 5486 if (iToken == 0) 5487 Log3(("%08X", paTokens[iToken])); 5488 else 5489 Log3(("\n%08X", paTokens[iToken])); 5490 } 5491 else 5492 Log3((" %08X", paTokens[iToken])); 5493 } 5494 Log3(("\n")); 5495 #endif 5296 5496 5297 5497 if ( cid >= pState->cContexts … … 5357 5557 { 5358 5558 Log(("Shader disassembly:\n%s\n", pDisassembly->GetBufferPointer())); 5359 pDisassembly->Release();5559 D3D_RELEASE(pDisassembly); 5360 5560 } 5361 5561 #endif … … 5408 5608 { 5409 5609 pShader = &pContext->paVertexShader[shid]; 5410 pShader->u.pVertexShader->Release();5610 D3D_RELEASE(pShader->u.pVertexShader); 5411 5611 } 5412 5612 } … … 5418 5618 { 5419 5619 pShader = &pContext->paPixelShader[shid]; 5420 pShader->u.pPixelShader->Release();5620 D3D_RELEASE(pShader->u.pPixelShader); 5421 5621 } 5422 5622 }
Note:
See TracChangeset
for help on using the changeset viewer.