- Timestamp:
- Oct 22, 2017 9:38:04 AM (7 years ago)
- svn:sync-xref-src-repo-rev:
- 118464
- Location:
- trunk/src/VBox/Devices/Graphics
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-info.cpp
r69136 r69153 267 267 * wast memory on them). 268 268 */ 269 uint32_t const fSwitchFlags = pSurface-> flags & VMSVGA3D_SURFACE_HINT_SWITCH_MASK;269 uint32_t const fSwitchFlags = pSurface->surfaceFlags & VMSVGA3D_SURFACE_HINT_SWITCH_MASK; 270 270 if ( fSwitchFlags != SVGA3D_SURFACE_HINT_DEPTHSTENCIL 271 271 && fSwitchFlags != (SVGA3D_SURFACE_HINT_DEPTHSTENCIL | SVGA3D_SURFACE_HINT_TEXTURE)) … … 312 312 * D3D specifics. 313 313 */ 314 HRESULT hr; 315 switch (fSwitchFlags) 314 Assert(pSurface->enmD3DResType != VMSVGA3D_D3DRESTYPE_NONE); 315 316 HRESULT hr; 317 switch (pSurface->enmD3DResType) 316 318 { 317 case SVGA3D_SURFACE_HINT_TEXTURE: 318 case SVGA3D_SURFACE_HINT_RENDERTARGET: 319 case SVGA3D_SURFACE_HINT_TEXTURE | SVGA3D_SURFACE_HINT_RENDERTARGET: 319 case VMSVGA3D_D3DRESTYPE_VOLUME_TEXTURE: 320 AssertFailed(); ///@todo 321 break; 322 323 case VMSVGA3D_D3DRESTYPE_SURFACE: 324 case VMSVGA3D_D3DRESTYPE_TEXTURE: 325 case VMSVGA3D_D3DRESTYPE_CUBE_TEXTURE: 320 326 { 321 327 /* … … 323 329 */ 324 330 D3DLOCKED_RECT LockedRect; 325 if (fSwitchFlags & SVGA3D_SURFACE_HINT_TEXTURE) 331 if (pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_CUBE_TEXTURE) 332 { 333 hr = pSurface->u.pCubeTexture->LockRect(vmsvga3dCubemapFaceFromIndex(iFace), 334 i, /* texture level */ 335 &LockedRect, 336 NULL, 337 D3DLOCK_READONLY); 338 } 339 else if (pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_TEXTURE) 326 340 { 327 341 if (pSurface->bounce.pTexture) 328 342 { 329 343 if ( !pSurface->fDirty 330 && fSwitchFlags == (SVGA3D_SURFACE_HINT_TEXTURE |SVGA3D_SURFACE_HINT_RENDERTARGET)344 && RT_BOOL(fSwitchFlags & SVGA3D_SURFACE_HINT_RENDERTARGET) 331 345 && i == 0 /* only the first time */) 332 346 { … … 403 417 } 404 418 405 case SVGA3D_SURFACE_HINT_VERTEXBUFFER | SVGA3D_SURFACE_HINT_INDEXBUFFER: 406 case SVGA3D_SURFACE_HINT_VERTEXBUFFER: 407 case SVGA3D_SURFACE_HINT_INDEXBUFFER: 419 case VMSVGA3D_D3DRESTYPE_VERTEX_BUFFER: 420 case VMSVGA3D_D3DRESTYPE_INDEX_BUFFER: 408 421 { 409 422 /* Current type of the buffer. */ 410 const bool fVertex = RT_BOOL(pSurface->fu32ActualUsageFlags & SVGA3D_SURFACE_HINT_VERTEXBUFFER);423 const bool fVertex = (pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_VERTEX_BUFFER); 411 424 412 425 void *pvD3DData = NULL; … … 428 441 429 442 default: 430 AssertMsgFailed((" %#x\n", fSwitchFlags));443 AssertMsgFailed(("flags %#x, type %d\n", fSwitchFlags, pSurface->enmD3DResType)); 431 444 } 432 445 … … 1811 1824 pHlp->pfnPrintf(pHlp, "Format: %s\n", 1812 1825 vmsvgaFormatEnumValueEx(szTmp, sizeof(szTmp), NULL, (int)pSurface->format, false, &g_SVGA3dSurfaceFormat2String)); 1813 pHlp->pfnPrintf(pHlp, "Flags: %#x", pSurface-> flags);1814 vmsvga3dInfoU32Flags(pHlp, pSurface-> flags, "SVGA3D_SURFACE_", g_aSvga3DSurfaceFlags, RT_ELEMENTS(g_aSvga3DSurfaceFlags));1826 pHlp->pfnPrintf(pHlp, "Flags: %#x", pSurface->surfaceFlags); 1827 vmsvga3dInfoU32Flags(pHlp, pSurface->surfaceFlags, "SVGA3D_SURFACE_", g_aSvga3DSurfaceFlags, RT_ELEMENTS(g_aSvga3DSurfaceFlags)); 1815 1828 pHlp->pfnPrintf(pHlp, "\n"); 1816 1829 if (pSurface->cFaces == 0) -
trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-internal.h
r69136 r69153 486 486 487 487 #ifdef VMSVGA3D_DIRECT3D 488 489 /* What kind of Direct3D resource has been created for the VMSVGA3D surface. */ 490 typedef enum VMSVGA3DD3DRESTYPE 491 { 492 VMSVGA3D_D3DRESTYPE_NONE = 0, 493 VMSVGA3D_D3DRESTYPE_SURFACE = 1, 494 VMSVGA3D_D3DRESTYPE_TEXTURE = 2, 495 VMSVGA3D_D3DRESTYPE_CUBE_TEXTURE = 3, 496 VMSVGA3D_D3DRESTYPE_VOLUME_TEXTURE = 4, 497 VMSVGA3D_D3DRESTYPE_VERTEX_BUFFER = 5, 498 VMSVGA3D_D3DRESTYPE_INDEX_BUFFER = 6 499 } VMSVGA3DD3DRESTYPE; 500 488 501 /** 489 502 * … … 498 511 IDirect3DTexture9 *pTexture; 499 512 IDirect3DCubeTexture9 *pCubeTexture; 513 IDirect3DVolumeTexture9 *pVolumeTexture; 500 514 } u; 501 515 } VMSVGA3DSHAREDSURFACE; … … 514 528 uint32_t idAssociatedContext; 515 529 #endif 516 uint32_t flags;530 uint32_t surfaceFlags; 517 531 SVGA3dSurfaceFormat format; 518 532 #ifdef VMSVGA3D_OPENGL … … 552 566 /** Event query inserted after each GPU operation that updates or uses this surface. */ 553 567 IDirect3DQuery9 *pQuery; 554 /* * @todo Just remember the type of actually created D3D object. Do not always guess from flags.555 * Replace fu32ActualUsageFlags and possibly fStencilAsTexture. */568 /* The type of actually created D3D resource. */ 569 VMSVGA3DD3DRESTYPE enmD3DResType; 556 570 union 557 571 { 558 572 IDirect3DSurface9 *pSurface; 573 IDirect3DTexture9 *pTexture; 559 574 IDirect3DCubeTexture9 *pCubeTexture; 575 IDirect3DVolumeTexture9 *pVolumeTexture; 576 IDirect3DVertexBuffer9 *pVertexBuffer; 560 577 IDirect3DIndexBuffer9 *pIndexBuffer; 561 IDirect3DTexture9 *pTexture;562 IDirect3DVertexBuffer9 *pVertexBuffer;563 578 } u; 564 579 union … … 566 581 IDirect3DTexture9 *pTexture; 567 582 IDirect3DCubeTexture9 *pCubeTexture; 583 IDirect3DVolumeTexture9 *pVolumeTexture; 568 584 } bounce; 569 585 /** AVL tree containing VMSVGA3DSHAREDSURFACE structures. */ 570 586 AVLU32TREE pSharedObjectTree; 571 587 bool fStencilAsTexture; 572 uint32_t fu32ActualUsageFlags;573 588 #endif 574 589 } VMSVGA3DSURFACE; … … 588 603 SSMFIELD_ENTRY( VMSVGA3DSURFACE, idAssociatedContext), 589 604 # endif 590 SSMFIELD_ENTRY( VMSVGA3DSURFACE, flags),605 SSMFIELD_ENTRY( VMSVGA3DSURFACE, surfaceFlags), 591 606 SSMFIELD_ENTRY( VMSVGA3DSURFACE, format), 592 607 # ifdef VMSVGA3D_OPENGL … … 1122 1137 } 1123 1138 1124 1125 #endif 1126 1139 #ifdef VMSVGA3D_DIRECT3D 1140 DECLINLINE(D3DCUBEMAP_FACES) vmsvga3dCubemapFaceFromIndex(uint32_t iFace) 1141 { 1142 D3DCUBEMAP_FACES Face; 1143 switch (iFace) 1144 { 1145 case 0: Face = D3DCUBEMAP_FACE_POSITIVE_X; break; 1146 case 1: Face = D3DCUBEMAP_FACE_NEGATIVE_X; break; 1147 case 2: Face = D3DCUBEMAP_FACE_POSITIVE_Y; break; 1148 case 3: Face = D3DCUBEMAP_FACE_NEGATIVE_Y; break; 1149 case 4: Face = D3DCUBEMAP_FACE_POSITIVE_Z; break; 1150 default: 1151 case 5: Face = D3DCUBEMAP_FACE_NEGATIVE_Z; break; 1152 } 1153 return Face; 1154 } 1155 #endif /* VMSVGA3D_DIRECT3D */ 1156 1157 #endif 1158 -
trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-ogl.cpp
r69136 r69153 1855 1855 VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext); 1856 1856 1857 switch (pSurface-> flags & VMSVGA3D_SURFACE_HINT_SWITCH_MASK)1857 switch (pSurface->surfaceFlags & VMSVGA3D_SURFACE_HINT_SWITCH_MASK) 1858 1858 { 1859 1859 case SVGA3D_SURFACE_CUBEMAP: … … 1891 1891 1892 1892 default: 1893 AssertMsg(!VMSVGA3DSURFACE_HAS_HW_SURFACE(pSurface), ("type=%x\n", (pSurface-> flags & VMSVGA3D_SURFACE_HINT_SWITCH_MASK)));1893 AssertMsg(!VMSVGA3DSURFACE_HAS_HW_SURFACE(pSurface), ("type=%x\n", (pSurface->surfaceFlags & VMSVGA3D_SURFACE_HINT_SWITCH_MASK))); 1894 1894 break; 1895 1895 } … … 2122 2122 VMSVGA3D_CHECK_LAST_ERROR(pState, pContext); 2123 2123 2124 pSurface-> flags|= SVGA3D_SURFACE_HINT_TEXTURE;2124 pSurface->surfaceFlags |= SVGA3D_SURFACE_HINT_TEXTURE; 2125 2125 2126 2126 if (idPrevCtx < pState->cContexts && pState->papContexts[idPrevCtx]->id == idPrevCtx) … … 2344 2344 RT_NOREF(uHostFace); ///@todo 2345 2345 2346 switch (pSurface-> flags & VMSVGA3D_SURFACE_HINT_SWITCH_MASK)2346 switch (pSurface->surfaceFlags & VMSVGA3D_SURFACE_HINT_SWITCH_MASK) 2347 2347 { 2348 2348 case SVGA3D_SURFACE_HINT_TEXTURE | SVGA3D_SURFACE_HINT_RENDERTARGET: … … 2503 2503 { 2504 2504 Log(("Lock %s memory for rectangle (%d,%d)(%d,%d)\n", 2505 (pSurface-> flags & VMSVGA3D_SURFACE_HINT_SWITCH_MASK) == SVGA3D_SURFACE_HINT_VERTEXBUFFER ? "vertex" :2506 (pSurface-> flags & VMSVGA3D_SURFACE_HINT_SWITCH_MASK) == SVGA3D_SURFACE_HINT_INDEXBUFFER ? "index" : "buffer",2505 (pSurface->surfaceFlags & VMSVGA3D_SURFACE_HINT_SWITCH_MASK) == SVGA3D_SURFACE_HINT_VERTEXBUFFER ? "vertex" : 2506 (pSurface->surfaceFlags & VMSVGA3D_SURFACE_HINT_SWITCH_MASK) == SVGA3D_SURFACE_HINT_INDEXBUFFER ? "index" : "buffer", 2507 2507 pBox->x, pBox->y, pBox->x + pBox->w, pBox->y + pBox->h)); 2508 2508 … … 2653 2653 { 2654 2654 /* Unknown surface type; turn it into a texture. */ 2655 Log(("vmsvga3dGenerateMipmaps: unknown src surface id=%x type=%d format=%d -> create texture\n", sid, pSurface-> flags, pSurface->format));2655 Log(("vmsvga3dGenerateMipmaps: unknown src surface id=%x type=%d format=%d -> create texture\n", sid, pSurface->surfaceFlags, pSurface->format)); 2656 2656 rc = vmsvga3dBackCreateTexture(pState, pContext, cid, pSurface); 2657 2657 AssertRCReturn(rc, rc); … … 4802 4802 if (pRenderTarget->oglId.texture == OPENGL_INVALID_ID) 4803 4803 { 4804 Log(("vmsvga3dSetRenderTarget: create renderbuffer to be used as render target; surface id=%x type=%d format=%d\n", target.sid, pRenderTarget-> flags, pRenderTarget->internalFormatGL));4804 Log(("vmsvga3dSetRenderTarget: create renderbuffer to be used as render target; surface id=%x type=%d format=%d\n", target.sid, pRenderTarget->surfaceFlags, pRenderTarget->internalFormatGL)); 4805 4805 pContext = &pState->SharedCtx; 4806 4806 VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext); … … 4831 4831 AssertReturn(pRenderTarget->oglId.texture != OPENGL_INVALID_ID, VERR_INVALID_PARAMETER); 4832 4832 4833 pRenderTarget-> flags |= SVGA3D_SURFACE_HINT_DEPTHSTENCIL;4833 pRenderTarget->surfaceFlags |= SVGA3D_SURFACE_HINT_DEPTHSTENCIL; 4834 4834 4835 4835 pState->ext.glFramebufferRenderbuffer(GL_FRAMEBUFFER, … … 4851 4851 if (pRenderTarget->oglId.texture == OPENGL_INVALID_ID) 4852 4852 { 4853 Log(("vmsvga3dSetRenderTarget: create texture to be used as render target; surface id=%x type=%d format=%d -> create texture\n", target.sid, pRenderTarget-> flags, pRenderTarget->format));4853 Log(("vmsvga3dSetRenderTarget: create texture to be used as render target; surface id=%x type=%d format=%d -> create texture\n", target.sid, pRenderTarget->surfaceFlags, pRenderTarget->format)); 4854 4854 int rc = vmsvga3dBackCreateTexture(pState, pContext, cid, pRenderTarget); 4855 4855 AssertRCReturn(rc, rc); … … 4859 4859 Assert(!pRenderTarget->fDirty); 4860 4860 4861 pRenderTarget-> flags |= SVGA3D_SURFACE_HINT_RENDERTARGET;4861 pRenderTarget->surfaceFlags |= SVGA3D_SURFACE_HINT_RENDERTARGET; 4862 4862 4863 4863 pState->ext.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + type - SVGA3D_RT_COLOR0, GL_TEXTURE_2D, pRenderTarget->oglId.texture, target.mipmap); … … 5978 5978 pVertexSurface->fDirty = false; 5979 5979 5980 pVertexSurface-> flags |= SVGA3D_SURFACE_HINT_VERTEXBUFFER;5980 pVertexSurface->surfaceFlags |= SVGA3D_SURFACE_HINT_VERTEXBUFFER; 5981 5981 5982 5982 pState->ext.glBindBuffer(GL_ARRAY_BUFFER, OPENGL_INVALID_ID); … … 6312 6312 pIndexSurface->fDirty = false; 6313 6313 6314 pIndexSurface-> flags |= SVGA3D_SURFACE_HINT_INDEXBUFFER;6314 pIndexSurface->surfaceFlags |= SVGA3D_SURFACE_HINT_INDEXBUFFER; 6315 6315 6316 6316 pState->ext.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, OPENGL_INVALID_ID); -
trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-savedstate.cpp
r69136 r69153 357 357 } 358 358 359 rc = vmsvga3dSurfaceDefine(pThis, sid, surface. flags, surface.format, surface.faces, surface.multiSampleCount, surface.autogenFilter, cMipLevels, pMipmapLevelSize);359 rc = vmsvga3dSurfaceDefine(pThis, sid, surface.surfaceFlags, surface.format, surface.faces, surface.multiSampleCount, surface.autogenFilter, cMipLevels, pMipmapLevelSize); 360 360 AssertRCReturn(rc, rc); 361 361 … … 607 607 AssertReturn(pData, VERR_NO_MEMORY); 608 608 609 switch (pSurface-> flags & VMSVGA3D_SURFACE_HINT_SWITCH_MASK)609 switch (pSurface->enmD3DResType) 610 610 { 611 case SVGA3D_SURFACE_HINT_DEPTHSTENCIL:612 case SVGA3D_SURFACE_HINT_DEPTHSTENCIL | SVGA3D_SURFACE_HINT_TEXTURE:613 /** @todo unable to easily fetch depth surface data in d3d 9 */611 case VMSVGA3D_D3DRESTYPE_CUBE_TEXTURE: 612 case VMSVGA3D_D3DRESTYPE_VOLUME_TEXTURE: 613 AssertFailed(); ///@todo 614 614 fSkipSave = true; 615 615 break; 616 case SVGA3D_SURFACE_HINT_TEXTURE | SVGA3D_SURFACE_HINT_RENDERTARGET: 617 fRenderTargetTexture = true; 618 /* no break */ 619 case SVGA3D_SURFACE_HINT_TEXTURE: 620 fTexture = true; 621 /* no break */ 622 case SVGA3D_SURFACE_HINT_RENDERTARGET: 616 case VMSVGA3D_D3DRESTYPE_SURFACE: 617 case VMSVGA3D_D3DRESTYPE_TEXTURE: 623 618 { 619 if (pSurface->surfaceFlags & SVGA3D_SURFACE_HINT_DEPTHSTENCIL) 620 { 621 /** @todo unable to easily fetch depth surface data in d3d 9 */ 622 fSkipSave = true; 623 break; 624 } 625 626 fTexture = (pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_TEXTURE); 627 fRenderTargetTexture = fTexture && (pSurface->surfaceFlags & SVGA3D_SURFACE_HINT_RENDERTARGET); 628 624 629 D3DLOCKED_RECT LockedRect; 625 630 … … 698 703 } 699 704 700 case SVGA3D_SURFACE_HINT_VERTEXBUFFER | SVGA3D_SURFACE_HINT_INDEXBUFFER: 701 case SVGA3D_SURFACE_HINT_VERTEXBUFFER: 702 case SVGA3D_SURFACE_HINT_INDEXBUFFER: 705 case VMSVGA3D_D3DRESTYPE_VERTEX_BUFFER: 706 case VMSVGA3D_D3DRESTYPE_INDEX_BUFFER: 703 707 { 704 708 /* Current type of the buffer. */ 705 const bool fVertex = RT_BOOL(pSurface->fu32ActualUsageFlags & SVGA3D_SURFACE_HINT_VERTEXBUFFER);709 const bool fVertex = (pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_VERTEX_BUFFER); 706 710 707 711 uint8_t *pD3DData; … … 754 758 Assert(pMipmapLevel->cbSurface); 755 759 756 switch (pSurface-> flags & VMSVGA3D_SURFACE_HINT_SWITCH_MASK)760 switch (pSurface->surfaceFlags & VMSVGA3D_SURFACE_HINT_SWITCH_MASK) 757 761 { 758 762 default: -
trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-win.cpp
r69136 r69153 1105 1105 Assert(pSurface->pSharedObjectTree == NULL); 1106 1106 1107 switch (pSurface->flags & VMSVGA3D_SURFACE_HINT_SWITCH_MASK) 1108 { 1109 case SVGA3D_SURFACE_CUBEMAP: 1110 case SVGA3D_SURFACE_CUBEMAP | SVGA3D_SURFACE_HINT_TEXTURE: 1111 case SVGA3D_SURFACE_CUBEMAP | SVGA3D_SURFACE_HINT_TEXTURE | SVGA3D_SURFACE_HINT_RENDERTARGET: 1107 switch (pSurface->enmD3DResType) 1108 { 1109 case VMSVGA3D_D3DRESTYPE_SURFACE: 1110 D3D_RELEASE(pSurface->u.pSurface); 1111 break; 1112 1113 case VMSVGA3D_D3DRESTYPE_TEXTURE: 1114 D3D_RELEASE(pSurface->u.pTexture); 1115 D3D_RELEASE(pSurface->bounce.pTexture); 1116 break; 1117 1118 case VMSVGA3D_D3DRESTYPE_CUBE_TEXTURE: 1112 1119 D3D_RELEASE(pSurface->u.pCubeTexture); 1113 1120 D3D_RELEASE(pSurface->bounce.pCubeTexture); 1114 1121 break; 1115 1122 1116 case SVGA3D_SURFACE_HINT_INDEXBUFFER | SVGA3D_SURFACE_HINT_VERTEXBUFFER: 1117 case SVGA3D_SURFACE_HINT_INDEXBUFFER: 1118 case SVGA3D_SURFACE_HINT_VERTEXBUFFER: 1119 if (pSurface->fu32ActualUsageFlags == SVGA3D_SURFACE_HINT_VERTEXBUFFER) 1120 D3D_RELEASE(pSurface->u.pVertexBuffer); 1121 else if (pSurface->fu32ActualUsageFlags == SVGA3D_SURFACE_HINT_INDEXBUFFER) 1122 D3D_RELEASE(pSurface->u.pIndexBuffer); 1123 else 1124 AssertMsg(pSurface->u.pVertexBuffer == NULL, ("fu32ActualUsageFlags %x\n", pSurface->fu32ActualUsageFlags)); 1125 break; 1126 1127 case SVGA3D_SURFACE_HINT_TEXTURE: 1128 case SVGA3D_SURFACE_HINT_TEXTURE | SVGA3D_SURFACE_HINT_RENDERTARGET: 1129 D3D_RELEASE(pSurface->u.pTexture); 1130 D3D_RELEASE(pSurface->bounce.pTexture); 1131 break; 1132 1133 case SVGA3D_SURFACE_HINT_RENDERTARGET: 1134 case SVGA3D_SURFACE_HINT_DEPTHSTENCIL: 1135 case SVGA3D_SURFACE_HINT_DEPTHSTENCIL | SVGA3D_SURFACE_HINT_TEXTURE: /** @todo actual texture surface not supported */ 1136 if (pSurface->fStencilAsTexture) 1137 D3D_RELEASE(pSurface->u.pTexture); 1138 else 1139 D3D_RELEASE(pSurface->u.pSurface); 1123 case VMSVGA3D_D3DRESTYPE_VOLUME_TEXTURE: 1124 D3D_RELEASE(pSurface->u.pVolumeTexture); 1125 D3D_RELEASE(pSurface->bounce.pVolumeTexture); 1126 break; 1127 1128 case VMSVGA3D_D3DRESTYPE_VERTEX_BUFFER: 1129 D3D_RELEASE(pSurface->u.pVertexBuffer); 1130 break; 1131 1132 case VMSVGA3D_D3DRESTYPE_INDEX_BUFFER: 1133 D3D_RELEASE(pSurface->u.pIndexBuffer); 1140 1134 break; 1141 1135 1142 1136 default: 1143 AssertMsg(!VMSVGA3DSURFACE_HAS_HW_SURFACE(pSurface), ("type=%x\n", (pSurface->flags & VMSVGA3D_SURFACE_HINT_SWITCH_MASK))); 1137 AssertMsg(!VMSVGA3DSURFACE_HAS_HW_SURFACE(pSurface), 1138 ("surfaceFlags=0x%x\n", (pSurface->surfaceFlags & VMSVGA3D_SURFACE_HINT_SWITCH_MASK))); 1144 1139 break; 1145 1140 } … … 1157 1152 PVMSVGA3DSURFACE pSurface = (PVMSVGA3DSURFACE)pvParam; 1158 1153 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: 1154 switch (pSurface->enmD3DResType) 1155 { 1156 case VMSVGA3D_D3DRESTYPE_TEXTURE: 1157 LogFunc(("release shared texture object for context %d\n", pNode->Key)); 1158 Assert(pSharedSurface->u.pTexture); 1159 D3D_RELEASE(pSharedSurface->u.pTexture); 1160 break; 1161 1162 case VMSVGA3D_D3DRESTYPE_CUBE_TEXTURE: 1164 1163 LogFunc(("release shared cube texture object for context %d\n", pNode->Key)); 1165 1164 Assert(pSharedSurface->u.pCubeTexture); … … 1167 1166 break; 1168 1167 1169 case SVGA3D_SURFACE_HINT_TEXTURE: 1170 case SVGA3D_SURFACE_HINT_TEXTURE | SVGA3D_SURFACE_HINT_RENDERTARGET: 1171 LogFunc(("release shared texture object for context %d\n", pNode->Key)); 1172 Assert(pSharedSurface->u.pTexture); 1173 D3D_RELEASE(pSharedSurface->u.pTexture); 1168 case VMSVGA3D_D3DRESTYPE_VOLUME_TEXTURE: 1169 LogFunc(("release shared volume texture object for context %d\n", pNode->Key)); 1170 Assert(pSharedSurface->u.pVolumeTexture); 1171 D3D_RELEASE(pSharedSurface->u.pVolumeTexture); 1174 1172 break; 1175 1173 … … 1190 1188 if (!pSharedSurface) 1191 1189 { 1192 const bool fCubeTexture = RT_BOOL(pSurface->flags & SVGA3D_SURFACE_CUBEMAP);1193 1190 const uint32_t cWidth = pSurface->pMipmapLevels[0].mipmapSize.width; 1194 1191 const uint32_t cHeight = pSurface->pMipmapLevels[0].mipmapSize.height; 1192 const uint32_t cDepth = pSurface->pMipmapLevels[0].mipmapSize.depth; 1195 1193 const uint32_t numMipLevels = pSurface->faces[0].numMipLevels; 1196 1194 1197 LogFunc(("Create shared %stexture copy d3d (%d,%d) cMip=%d usage %x format %x.\n", 1198 fCubeTexture ? "cube " : "", 1195 LogFunc(("Create shared %stexture copy d3d (%d,%d,%d) cMip=%d usage %x format %x.\n", 1196 pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_VOLUME_TEXTURE ? "volume " : 1197 pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_CUBE_TEXTURE ? "cube " : 1198 pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_TEXTURE ? "" : "UNKNOWN!!!", 1199 1199 cWidth, 1200 1200 cHeight, 1201 cDepth, 1201 1202 numMipLevels, 1202 1203 pSurface->fUsageD3D | D3DUSAGE_RENDERTARGET, … … 1210 1211 AssertReturn(ret, NULL); 1211 1212 1212 /* Create shadow copy of the original shared texture. Shared d3d resources require Vista+ and have some restrictions. */ 1213 /* Create shadow copy of the original shared texture. 1214 * Shared d3d resources require Vista+ and have some restrictions. 1215 * D3DUSAGE_RENDERTARGET is required for use as a StretchRect destination. 1216 */ 1213 1217 HRESULT hr; 1214 if (fCubeTexture) 1218 if (pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_VOLUME_TEXTURE) 1219 hr = pContext->pDevice->CreateVolumeTexture(cWidth, 1220 cHeight, 1221 cDepth, 1222 numMipLevels, 1223 pSurface->fUsageD3D | D3DUSAGE_RENDERTARGET, 1224 pSurface->formatD3D, 1225 D3DPOOL_DEFAULT, 1226 &pSharedSurface->u.pVolumeTexture, 1227 &pSurface->hSharedObject); 1228 else if (pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_CUBE_TEXTURE) 1215 1229 hr = pContext->pDevice->CreateCubeTexture(cWidth, 1216 1230 numMipLevels, 1217 pSurface->fUsageD3D | D3DUSAGE_RENDERTARGET /* required for use as a StretchRect destination */,1231 pSurface->fUsageD3D | D3DUSAGE_RENDERTARGET, 1218 1232 pSurface->formatD3D, 1219 1233 D3DPOOL_DEFAULT, 1220 1234 &pSharedSurface->u.pCubeTexture, 1221 1235 &pSurface->hSharedObject); 1222 else 1236 else if (pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_TEXTURE) 1223 1237 hr = pContext->pDevice->CreateTexture(cWidth, 1224 1238 cHeight, 1225 1239 numMipLevels, 1226 pSurface->fUsageD3D | D3DUSAGE_RENDERTARGET /* required for use as a StretchRect destination */,1240 pSurface->fUsageD3D | D3DUSAGE_RENDERTARGET, 1227 1241 pSurface->formatD3D, 1228 1242 D3DPOOL_DEFAULT, 1229 1243 &pSharedSurface->u.pTexture, 1230 1244 &pSurface->hSharedObject); 1231 AssertMsgReturn(hr == D3D_OK, ("CreateTexture failed with %x\n", hr), NULL); 1245 else 1246 hr = E_FAIL; 1247 1248 if (RT_LIKELY(hr == D3D_OK)) 1249 /* likely */; 1250 else 1251 { 1252 AssertMsgFailed(("CreateTexture type %d failed with %x\n", pSurface->enmD3DResType, hr)); 1253 RTAvlU32Remove(&pSurface->pSharedObjectTree, pContext->id); 1254 RTMemFree(pSharedSurface); 1255 return NULL; 1256 } 1232 1257 } 1233 1258 return pSharedSurface; … … 1312 1337 } 1313 1338 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 1339 /** Get IDirect3DSurface9 for the given face and mipmap. 1331 1340 */ … … 1339 1348 AssertPtrReturn(pSurface->u.pSurface, VERR_INVALID_PARAMETER); 1340 1349 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 1350 IDirect3DBaseTexture9 *pTexture; 1345 1351 if (fLockable && pSurface->bounce.pTexture) … … 1356 1362 VERR_INVALID_PARAMETER); 1357 1363 1358 if (fTexture) 1364 if ( pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_TEXTURE 1365 || pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_CUBE_TEXTURE) 1359 1366 { 1360 1367 LogFunc(("using texture sid=%x created for another context (%d vs %d)\n", … … 1376 1383 #endif 1377 1384 1378 if ( fCubeTexture)1385 if (pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_CUBE_TEXTURE) 1379 1386 { 1380 1387 Assert(pSurface->cFaces == 6); … … 1385 1392 AssertMsgReturn(hr == D3D_OK, ("GetCubeMapSurface failed with %x\n", hr), VERR_INTERNAL_ERROR); 1386 1393 } 1387 else if ( fTexture)1394 else if (pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_TEXTURE) 1388 1395 { 1389 1396 Assert(pSurface->cFaces == 1); … … 1394 1401 AssertMsgReturn(hr == D3D_OK, ("GetSurfaceLevel failed with %x\n", hr), VERR_INTERNAL_ERROR); 1395 1402 } 1396 else 1403 else if (pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_SURFACE) 1397 1404 { 1398 1405 pSurface->u.pSurface->AddRef(); 1399 1406 *ppD3DSurf = pSurface->u.pSurface; 1407 } 1408 else 1409 { 1410 AssertMsgFailedReturn(("No surface for type %d\n", pSurface->enmD3DResType), VERR_INTERNAL_ERROR); 1400 1411 } 1401 1412 … … 1429 1440 AssertRCReturn(rc, rc); 1430 1441 1431 const bool fDestTexture = RT_BOOL(pSurfaceDest->flags & SVGA3D_SURFACE_HINT_TEXTURE); 1432 1433 if ( fDestTexture 1434 && !pSurfaceDest->u.pSurface 1435 && pSurfaceSrc->u.pSurface) 1442 /* If src is HW and dst is not, then create the dst texture. */ 1443 if ( pSurfaceSrc->u.pSurface 1444 && !pSurfaceDest->u.pSurface 1445 && RT_BOOL(pSurfaceDest->surfaceFlags & SVGA3D_SURFACE_HINT_TEXTURE)) 1436 1446 { 1437 1447 const uint32_t cid = pSurfaceSrc->idAssociatedContext; … … 1441 1451 AssertRCReturn(rc, rc); 1442 1452 1443 LogFunc(("sid=%x type=%x format=%d -> create texture\n", sidDest, pSurfaceDest-> flags, pSurfaceDest->format));1453 LogFunc(("sid=%x type=%x format=%d -> create texture\n", sidDest, pSurfaceDest->surfaceFlags, pSurfaceDest->format)); 1444 1454 rc = vmsvga3dBackCreateTexture(pState, pContext, cid, pSurfaceDest); 1445 1455 AssertRCReturn(rc, rc); 1446 1456 } 1457 1458 Assert(pSurfaceSrc->enmD3DResType != VMSVGA3D_D3DRESTYPE_VOLUME_TEXTURE); ///@todo 1459 Assert(pSurfaceDest->enmD3DResType != VMSVGA3D_D3DRESTYPE_VOLUME_TEXTURE); ///@todo 1447 1460 1448 1461 if ( pSurfaceSrc->u.pSurface … … 1647 1660 1648 1661 /* If the destination bounce texture has been used, then update the actual texture. */ 1649 if ( pSurfaceDest->u.pSurface 1650 && fDestTexture 1651 && pSurfaceDest->bounce.pTexture) 1662 if ( pSurfaceDest->u.pTexture 1663 && pSurfaceDest->bounce.pTexture 1664 && ( pSurfaceDest->enmD3DResType == VMSVGA3D_D3DRESTYPE_TEXTURE 1665 || pSurfaceDest->enmD3DResType == VMSVGA3D_D3DRESTYPE_CUBE_TEXTURE)) 1652 1666 { 1653 1667 AssertMsgReturn(pContext, ("Context is NULL\n"), VERR_INTERNAL_ERROR); … … 1656 1670 IDirect3DBaseTexture9 *pSourceTexture; 1657 1671 IDirect3DBaseTexture9 *pDestinationTexture; 1658 if (pSurfaceDest-> flags & SVGA3D_SURFACE_CUBEMAP)1672 if (pSurfaceDest->enmD3DResType == VMSVGA3D_D3DRESTYPE_CUBE_TEXTURE) 1659 1673 { 1660 1674 pSourceTexture = pSurfaceDest->bounce.pCubeTexture; … … 1697 1711 Assert(pSurface->u.pTexture == NULL); 1698 1712 Assert(pSurface->bounce.pTexture == NULL); 1713 Assert(pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_NONE); 1699 1714 1700 1715 const uint32_t cWidth = pSurface->pMipmapLevels[0].mipmapSize.width; 1701 1716 const uint32_t cHeight = pSurface->pMipmapLevels[0].mipmapSize.height; 1717 const uint32_t cDepth = pSurface->pMipmapLevels[0].mipmapSize.depth; 1702 1718 const uint32_t numMipLevels = pSurface->faces[0].numMipLevels; 1703 1719 … … 1705 1721 * Create D3D texture object. 1706 1722 */ 1707 if (pSurface-> flags & SVGA3D_SURFACE_CUBEMAP)1723 if (pSurface->surfaceFlags & SVGA3D_SURFACE_CUBEMAP) 1708 1724 { 1709 1725 Assert(pSurface->cFaces == 6); 1710 1726 Assert(cWidth == cHeight); 1727 Assert(cDepth == 1); 1711 1728 1712 1729 hr = pContext->pDevice->CreateCubeTexture(cWidth, … … 1745 1762 AssertMsgReturn(hr == D3D_OK, ("CreateCubeTexture (fallback) failed with %x\n", hr), VERR_INTERNAL_ERROR); 1746 1763 } 1764 1765 pSurface->enmD3DResType = VMSVGA3D_D3DRESTYPE_CUBE_TEXTURE; 1747 1766 } 1748 1767 else if ( pSurface->formatD3D == D3DFMT_D24S8 … … 1751 1770 Assert(pSurface->cFaces == 1); 1752 1771 Assert(pSurface->faces[0].numMipLevels == 1); 1772 Assert(cDepth == 1); 1753 1773 1754 1774 /* Use the INTZ format for a depth/stencil surface that will be used as a texture */ 1755 1775 hr = pContext->pDevice->CreateTexture(cWidth, 1756 1776 cHeight, 1757 1, 1777 1, /* mip levels */ 1758 1778 D3DUSAGE_DEPTHSTENCIL, 1759 1779 FOURCC_INTZ, … … 1764 1784 1765 1785 pSurface->fStencilAsTexture = true; 1786 pSurface->enmD3DResType = VMSVGA3D_D3DRESTYPE_TEXTURE; 1766 1787 } 1767 1788 else 1768 1789 { 1769 /** @todo if (depth > 1) CreateVolumeTexture */ 1770 Assert(pSurface->cFaces == 1); 1771 1772 hr = pContext->pDevice->CreateTexture(cWidth, 1773 cHeight, 1774 numMipLevels, 1775 pSurface->fUsageD3D | D3DUSAGE_RENDERTARGET /* required for use as a StretchRect destination */, 1776 pSurface->formatD3D, 1777 D3DPOOL_DEFAULT, 1778 &pSurface->u.pTexture, 1779 &pSurface->hSharedObject); 1780 if (hr == D3D_OK) 1781 { 1782 /* Create another texture object to serve as a bounce buffer as the above texture surface can't be locked. */ 1790 if (cDepth > 1) 1791 { 1792 hr = pContext->pDevice->CreateVolumeTexture(cWidth, 1793 cHeight, 1794 cDepth, 1795 numMipLevels, 1796 pSurface->fUsageD3D, 1797 pSurface->formatD3D, 1798 D3DPOOL_DEFAULT, 1799 &pSurface->u.pVolumeTexture, 1800 &pSurface->hSharedObject); 1801 if (hr == D3D_OK) 1802 { 1803 /* Create another texture object to serve as a bounce buffer as the above texture surface can't be locked. */ 1804 hr = pContext->pDevice->CreateVolumeTexture(cWidth, 1805 cHeight, 1806 cDepth, 1807 numMipLevels, 1808 (pSurface->fUsageD3D & ~D3DUSAGE_RENDERTARGET) | D3DUSAGE_DYNAMIC /* Lockable */, 1809 pSurface->formatD3D, 1810 D3DPOOL_SYSTEMMEM, 1811 &pSurface->bounce.pVolumeTexture, 1812 NULL); 1813 AssertMsgReturnStmt(hr == D3D_OK, 1814 ("CreateVolumeTexture (systemmem) failed with %x\n", hr), 1815 D3D_RELEASE(pSurface->u.pVolumeTexture), 1816 VERR_INTERNAL_ERROR); 1817 } 1818 else 1819 { 1820 Log(("Format not accepted -> try old method\n")); 1821 /* The format was probably not accepted; fall back to our old mode. */ 1822 hr = pContext->pDevice->CreateVolumeTexture(cWidth, 1823 cHeight, 1824 cDepth, 1825 numMipLevels, 1826 (pSurface->fUsageD3D & ~D3DUSAGE_RENDERTARGET) | D3DUSAGE_DYNAMIC /* Lockable */, 1827 pSurface->formatD3D, 1828 D3DPOOL_DEFAULT, 1829 &pSurface->u.pVolumeTexture, 1830 &pSurface->hSharedObject); 1831 AssertMsgReturn(hr == D3D_OK, ("CreateVolumeTexture (fallback) failed with %x\n", hr), VERR_INTERNAL_ERROR); 1832 } 1833 1834 pSurface->enmD3DResType = VMSVGA3D_D3DRESTYPE_VOLUME_TEXTURE; 1835 } 1836 else 1837 { 1838 Assert(pSurface->cFaces == 1); 1839 1783 1840 hr = pContext->pDevice->CreateTexture(cWidth, 1784 1841 cHeight, 1785 1842 numMipLevels, 1786 (pSurface->fUsageD3D & ~D3DUSAGE_RENDERTARGET) | D3DUSAGE_DYNAMIC /* Lockable */, 1787 pSurface->formatD3D, 1788 D3DPOOL_SYSTEMMEM, 1789 &pSurface->bounce.pTexture, 1790 NULL); 1791 AssertMsgReturn(hr == D3D_OK, ("CreateTexture (systemmem) failed with %x\n", hr), VERR_INTERNAL_ERROR); 1792 } 1793 else 1794 { 1795 Log(("Format not accepted -> try old method\n")); 1796 /* The format was probably not accepted; fall back to our old mode. */ 1797 hr = pContext->pDevice->CreateTexture(cWidth, 1798 cHeight, 1799 numMipLevels, 1800 (pSurface->fUsageD3D & ~D3DUSAGE_RENDERTARGET) | D3DUSAGE_DYNAMIC /* Lockable */, 1843 pSurface->fUsageD3D | D3DUSAGE_RENDERTARGET /* required for use as a StretchRect destination */, 1801 1844 pSurface->formatD3D, 1802 1845 D3DPOOL_DEFAULT, 1803 1846 &pSurface->u.pTexture, 1804 &pSurface->hSharedObject /* might result in poor performance */); 1805 AssertMsgReturn(hr == D3D_OK, ("CreateTexture failed with %x\n", hr), VERR_INTERNAL_ERROR); 1806 } 1807 } 1847 &pSurface->hSharedObject); 1848 if (hr == D3D_OK) 1849 { 1850 /* Create another texture object to serve as a bounce buffer as the above texture surface can't be locked. */ 1851 hr = pContext->pDevice->CreateTexture(cWidth, 1852 cHeight, 1853 numMipLevels, 1854 (pSurface->fUsageD3D & ~D3DUSAGE_RENDERTARGET) | D3DUSAGE_DYNAMIC /* Lockable */, 1855 pSurface->formatD3D, 1856 D3DPOOL_SYSTEMMEM, 1857 &pSurface->bounce.pTexture, 1858 NULL); 1859 AssertMsgReturn(hr == D3D_OK, ("CreateTexture (systemmem) failed with %x\n", hr), VERR_INTERNAL_ERROR); 1860 } 1861 else 1862 { 1863 Log(("Format not accepted -> try old method\n")); 1864 /* The format was probably not accepted; fall back to our old mode. */ 1865 hr = pContext->pDevice->CreateTexture(cWidth, 1866 cHeight, 1867 numMipLevels, 1868 (pSurface->fUsageD3D & ~D3DUSAGE_RENDERTARGET) | D3DUSAGE_DYNAMIC /* Lockable */, 1869 pSurface->formatD3D, 1870 D3DPOOL_DEFAULT, 1871 &pSurface->u.pTexture, 1872 &pSurface->hSharedObject /* might result in poor performance */); 1873 AssertMsgReturn(hr == D3D_OK, ("CreateTexture failed with %x\n", hr), VERR_INTERNAL_ERROR); 1874 } 1875 1876 pSurface->enmD3DResType = VMSVGA3D_D3DRESTYPE_TEXTURE; 1877 } 1878 } 1879 1880 Assert(hr == D3D_OK); 1808 1881 1809 1882 if (pSurface->autogenFilter != SVGA3D_TEX_FILTER_NONE) 1810 1883 { 1811 1884 /* Set the mip map generation filter settings. */ 1812 if (pSurface->flags & SVGA3D_SURFACE_CUBEMAP) 1813 hr = pSurface->u.pCubeTexture->SetAutoGenFilterType((D3DTEXTUREFILTERTYPE)pSurface->autogenFilter); 1885 IDirect3DBaseTexture9 *pBaseTexture; 1886 if (pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_VOLUME_TEXTURE) 1887 pBaseTexture = pSurface->u.pVolumeTexture; 1888 else if (pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_CUBE_TEXTURE) 1889 pBaseTexture = pSurface->u.pCubeTexture; 1814 1890 else 1815 hr = pSurface->u.pTexture->SetAutoGenFilterType((D3DTEXTUREFILTERTYPE)pSurface->autogenFilter); 1891 pBaseTexture = pSurface->u.pTexture; 1892 hr = pBaseTexture->SetAutoGenFilterType((D3DTEXTUREFILTERTYPE)pSurface->autogenFilter); 1816 1893 AssertMsg(hr == D3D_OK, ("vmsvga3dBackCreateTexture: SetAutoGenFilterType failed with %x\n", hr)); 1817 1894 } … … 1824 1901 Log(("vmsvga3dBackCreateTexture: sync texture\n")); 1825 1902 1826 if (pSurface->flags & SVGA3D_SURFACE_CUBEMAP) 1903 if (pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_VOLUME_TEXTURE) 1904 { 1905 IDirect3DVolumeTexture9 *pVolumeTexture = pSurface->bounce.pVolumeTexture ? 1906 pSurface->bounce.pVolumeTexture : 1907 pSurface->u.pVolumeTexture; 1908 1909 for (uint32_t i = 0; i < numMipLevels; ++i) 1910 { 1911 D3DLOCKED_BOX LockedVolume; 1912 hr = pVolumeTexture->LockBox(i, &LockedVolume, NULL, D3DLOCK_DISCARD); 1913 AssertMsgBreak(hr == D3D_OK, ("LockBox failed with %x\n", hr)); 1914 1915 PVMSVGA3DMIPMAPLEVEL pMipLevel = &pSurface->pMipmapLevels[i]; 1916 1917 LogFunc(("sync volume texture mipmap level %d (pitch row %x vs %x, slice %x vs %x)\n", 1918 i, LockedVolume.RowPitch, pMipLevel->cbSurfacePitch, LockedVolume.SlicePitch, pMipLevel->cbSurfacePlane)); 1919 1920 1921 uint8_t *pDst = (uint8_t *)LockedVolume.pBits; 1922 const uint8_t *pSrc = (uint8_t *)pMipLevel->pSurfaceData; 1923 for (uint32_t d = 0; d < cDepth; ++d) 1924 { 1925 uint8_t *pRowDst = pDst; 1926 const uint8_t *pRowSrc = pSrc; 1927 for (uint32_t h = 0; h < pMipLevel->cBlocksY; ++h) 1928 { 1929 // memcpy(pRowDst, pRowSrc, pMipLevel->cbSurfacePitch); 1930 pRowDst += LockedVolume.RowPitch; 1931 pRowSrc += pMipLevel->cbSurfacePitch; 1932 } 1933 pDst += LockedVolume.SlicePitch; 1934 pSrc += pMipLevel->cbSurfacePlane; 1935 } 1936 1937 hr = pVolumeTexture->UnlockBox(i); 1938 AssertMsgBreak(hr == D3D_OK, ("UnlockBox failed with %x\n", hr)); 1939 1940 pMipLevel->fDirty = false; 1941 } 1942 } 1943 else if (pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_CUBE_TEXTURE) 1827 1944 { 1828 1945 IDirect3DCubeTexture9 *pCubeTexture = pSurface->bounce.pCubeTexture ? … … 1891 2008 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dBackCreateTexture: LockRect failed with %x\n", hr), VERR_INTERNAL_ERROR); 1892 2009 1893 Log (("vmsvga3dBackCreateTexture:sync texture mipmap level %d (pitch %x vs %x)\n", i, LockedRect.Pitch, pSurface->pMipmapLevels[i].cbSurfacePitch));2010 LogFunc(("sync texture mipmap level %d (pitch %x vs %x)\n", i, LockedRect.Pitch, pSurface->pMipmapLevels[i].cbSurfacePitch)); 1894 2011 1895 2012 uint8_t *pDest = (uint8_t *)LockedRect.pBits; … … 1914 2031 Log(("vmsvga3dBackCreateTexture: sync dirty texture from bounce buffer\n")); 1915 2032 1916 if (pSurface->flags & SVGA3D_SURFACE_CUBEMAP) 2033 if (pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_VOLUME_TEXTURE) 2034 hr = pContext->pDevice->UpdateTexture(pSurface->bounce.pVolumeTexture, pSurface->u.pVolumeTexture); 2035 else if (pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_CUBE_TEXTURE) 1917 2036 hr = pContext->pDevice->UpdateTexture(pSurface->bounce.pCubeTexture, pSurface->u.pCubeTexture); 1918 2037 else 1919 2038 hr = pContext->pDevice->UpdateTexture(pSurface->bounce.pTexture, pSurface->u.pTexture); 1920 AssertMsgReturn(hr == D3D_OK, (" vmsvga3dBackCreateTexture:UpdateTexture failed with %x\n", hr), VERR_INTERNAL_ERROR);2039 AssertMsgReturn(hr == D3D_OK, ("UpdateTexture failed with %x\n", hr), VERR_INTERNAL_ERROR); 1921 2040 1922 2041 /* We will now use the bounce texture for all memory accesses, so free our surface memory buffer. */ … … 1929 2048 pSurface->fDirty = false; 1930 2049 1931 pSurface->flags |= SVGA3D_SURFACE_HINT_TEXTURE; 2050 Assert(pSurface->enmD3DResType != VMSVGA3D_D3DRESTYPE_NONE); 2051 2052 pSurface->surfaceFlags |= SVGA3D_SURFACE_HINT_TEXTURE; 1932 2053 pSurface->idAssociatedContext = idAssociatedContext; 1933 2054 return VINF_SUCCESS; … … 1960 2081 int rc; 1961 2082 2083 AssertReturn(pSrcSurface->enmD3DResType != VMSVGA3D_D3DRESTYPE_VOLUME_TEXTURE, VERR_NOT_IMPLEMENTED); 2084 AssertReturn(pDstSurface->enmD3DResType != VMSVGA3D_D3DRESTYPE_VOLUME_TEXTURE, VERR_NOT_IMPLEMENTED); 2085 1962 2086 /* Flush the drawing pipeline for this surface as it could be used in a shared context. */ 1963 2087 vmsvga3dSurfaceFlush(pThis, pSrcSurface); … … 2042 2166 { 2043 2167 HRESULT hr = D3D_OK; 2044 const uint32_t u32SurfHints = pSurface-> flags & VMSVGA3D_SURFACE_HINT_SWITCH_MASK;2168 const uint32_t u32SurfHints = pSurface->surfaceFlags & VMSVGA3D_SURFACE_HINT_SWITCH_MASK; 2045 2169 const DWORD dwFlags = transfer == SVGA3D_READ_HOST_VRAM ? D3DLOCK_READONLY : 0; 2046 2170 // if (u32SurfHints != 0x18 && u32SurfHints != 0x60) ASMBreakpoint(); 2047 2171 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) 2172 AssertReturn(pSurface->enmD3DResType != VMSVGA3D_D3DRESTYPE_VOLUME_TEXTURE, VERR_NOT_IMPLEMENTED); 2173 2174 const bool fTexture = pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_TEXTURE 2175 || pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_CUBE_TEXTURE; 2176 if ( pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_SURFACE 2177 || fTexture) 2055 2178 { 2056 2179 rc = vmsvga3dContextFromCid(pState, pSurface->idAssociatedContext, &pContext); … … 2068 2191 { 2069 2192 if ( transfer == SVGA3D_READ_HOST_VRAM 2070 && fRenderTarget2193 && RT_BOOL(u32SurfHints & SVGA3D_SURFACE_HINT_RENDERTARGET) 2071 2194 && iBox == 0 /* only the first time */) 2072 2195 { … … 2146 2269 } 2147 2270 } 2148 else if ( RT_BOOL(u32SurfHints & (SVGA3D_SURFACE_HINT_VERTEXBUFFER |2149 SVGA3D_SURFACE_HINT_INDEXBUFFER)))2271 else if ( pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_VERTEX_BUFFER 2272 || pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_INDEX_BUFFER) 2150 2273 { 2151 2274 /* … … 2162 2285 2163 2286 /* Current type of the buffer. */ 2164 const bool fVertex = RT_BOOL(pSurface->fu32ActualUsageFlags & SVGA3D_SURFACE_HINT_VERTEXBUFFER);2287 const bool fVertex = pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_VERTEX_BUFFER; 2165 2288 2166 2289 /* Caller already clipped pBox and buffers are 1-dimensional. */ … … 2218 2341 else 2219 2342 { 2220 AssertMsgFailed(("Unsupported surface hint 0x%08X \n", u32SurfHints));2343 AssertMsgFailed(("Unsupported surface hint 0x%08X, type %d\n", u32SurfHints, pSurface->enmD3DResType)); 2221 2344 } 2222 2345 … … 2377 2500 2378 2501 /* Unknown surface type; turn it into a texture. */ 2379 Log (("vmsvga3dGenerateMipmaps: unknown src surface sid=%x type=%d format=%d -> create texture\n", sid, pSurface->flags, pSurface->format));2502 LogFunc(("unknown src surface sid=%x type=%d format=%d -> create texture\n", sid, pSurface->surfaceFlags, pSurface->format)); 2380 2503 rc = vmsvga3dBackCreateTexture(pState, pContext, cid, pSurface); 2381 2504 AssertRCReturn(rc, rc); … … 2384 2507 { 2385 2508 hr = pSurface->u.pTexture->SetAutoGenFilterType((D3DTEXTUREFILTERTYPE)filter); 2386 AssertMsg(hr == D3D_OK, (" vmsvga3dGenerateMipmaps:SetAutoGenFilterType failed with %x\n", hr));2509 AssertMsg(hr == D3D_OK, ("SetAutoGenFilterType failed with %x\n", hr)); 2387 2510 } 2388 2511 … … 2398 2521 PVMSVGA3DSURFACE pSurface; 2399 2522 PVMSVGA3DCONTEXT pContext; 2400 uint32_t cid;2401 2523 HRESULT hr; 2524 int rc; 2402 2525 IDirect3DSurface9 *pBackBuffer; 2403 2526 IDirect3DSurface9 *pSurfaceD3D; 2404 2527 2405 2528 AssertReturn(pState, VERR_NO_MEMORY); 2406 AssertReturn(sid < SVGA3D_MAX_SURFACE_IDS, VERR_INVALID_PARAMETER); 2407 AssertReturn(sid < pState->cSurfaces && pState->papSurfaces[sid]->id == sid, VERR_INVALID_PARAMETER);2408 2409 pSurface = pState->papSurfaces[sid]; 2529 2530 rc = vmsvga3dSurfaceFromSid(pState, sid, &pSurface); 2531 AssertRCReturn(rc, rc); 2532 2410 2533 AssertReturn(pSurface->idAssociatedContext != SVGA3D_INVALID_ID, VERR_INTERNAL_ERROR); 2411 2534 2412 /** @todo stricter checks for associated context */ 2413 cid = pSurface->idAssociatedContext; 2414 Log(("vmsvga3dCommandPresent: sid=%x cRects=%d cid=%x\n", sid, cRects, cid)); 2415 for (uint32_t i=0; i < cRects; i++) 2416 { 2417 Log(("vmsvga3dCommandPresent: rectangle %d src=(%d,%d) (%d,%d)(%d,%d)\n", i, pRect[i].srcx, pRect[i].srcy, pRect[i].x, pRect[i].y, pRect[i].x + pRect[i].w, pRect[i].y + pRect[i].h)); 2418 } 2419 2420 if ( cid >= pState->cContexts 2421 || pState->papContexts[cid]->id != cid) 2422 { 2423 Log(("vmsvga3dCommandPresent invalid context id!\n")); 2424 return VERR_INVALID_PARAMETER; 2425 } 2426 pContext = pState->papContexts[cid]; 2535 LogFunc(("sid=%x cRects=%d cid=%x\n", sid, cRects, pSurface->idAssociatedContext)); 2536 for (uint32_t i = 0; i < cRects; ++i) 2537 { 2538 LogFunc(("rectangle %d src=(%d,%d) (%d,%d)(%d,%d)\n", i, pRect[i].srcx, pRect[i].srcy, pRect[i].x, pRect[i].y, pRect[i].x + pRect[i].w, pRect[i].y + pRect[i].h)); 2539 } 2540 2541 rc = vmsvga3dContextFromCid(pState, pSurface->idAssociatedContext, &pContext); 2542 AssertRCReturn(rc, rc); 2427 2543 2428 2544 hr = pContext->pDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer); 2429 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dCommandPresent: GetBackBuffer failed with %x\n", hr), VERR_INTERNAL_ERROR); 2430 2431 if (pSurface->flags & SVGA3D_SURFACE_HINT_TEXTURE) 2432 { 2433 hr = pSurface->u.pTexture->GetSurfaceLevel(0, &pSurfaceD3D); 2434 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dCommandPresent: GetSurfaceLevel failed with %x\n", hr), VERR_INTERNAL_ERROR); 2435 } 2436 else 2437 pSurfaceD3D = pSurface->u.pSurface; 2545 AssertMsgReturn(hr == D3D_OK, ("GetBackBuffer failed with %x\n", hr), VERR_INTERNAL_ERROR); 2546 2547 rc = vmsvga3dGetD3DSurface(pContext, pSurface, 0, 0, false, &pSurfaceD3D); 2548 AssertRCReturn(rc, rc); 2438 2549 2439 2550 /* Read the destination viewport specs in one go to try avoid some unnecessary update races. */ … … 2612 2723 } 2613 2724 2614 if (pSurface->flags & SVGA3D_SURFACE_HINT_TEXTURE)2615 D3D_RELEASE(pSurfaceD3D);2616 2617 AssertMsgReturn(hr == D3D_OK, (" vmsvga3dCommandPresent:StretchRect failed with %x\n", hr), VERR_INTERNAL_ERROR);2725 D3D_RELEASE(pSurfaceD3D); 2726 D3D_RELEASE(pBackBuffer); 2727 2728 AssertMsgReturn(hr == D3D_OK, ("StretchRect failed with %x\n", hr), VERR_INTERNAL_ERROR); 2618 2729 2619 2730 hr = pContext->pDevice->Present(NULL, NULL, NULL, NULL); 2620 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dCommandPresent: Present failed with %x\n", hr), VERR_INTERNAL_ERROR); 2621 2622 D3D_RELEASE(pBackBuffer); 2731 AssertMsgReturn(hr == D3D_OK, ("Present failed with %x\n", hr), VERR_INTERNAL_ERROR); 2732 2623 2733 return VINF_SUCCESS; 2624 2734 } … … 2776 2886 int rc; 2777 2887 2778 Log (("vmsvga3dContextDestroy: remove all dependencies for surface sid=%x\n", sid));2779 2780 uint32_t surfaceFlags = pSurface-> flags;2888 LogFunc(("Remove all dependencies for surface sid=%x\n", sid)); 2889 2890 uint32_t surfaceFlags = pSurface->surfaceFlags; 2781 2891 SVGA3dSurfaceFormat format = pSurface->format; 2782 2892 SVGA3dSurfaceFace face[SVGA3D_MAX_SURFACE_FACES]; … … 2817 2927 if (pSharedSurface) 2818 2928 { 2819 Log (("vmsvga3dContextDestroy: remove shared dependency for surface sid=%x\n", sid));2820 2821 switch (pSurface-> flags & VMSVGA3D_SURFACE_HINT_SWITCH_MASK)2929 LogFunc(("Remove shared dependency for surface sid=%x\n", sid)); 2930 2931 switch (pSurface->enmD3DResType) 2822 2932 { 2823 case SVGA3D_SURFACE_HINT_TEXTURE: 2824 case SVGA3D_SURFACE_HINT_TEXTURE | SVGA3D_SURFACE_HINT_RENDERTARGET: 2933 case VMSVGA3D_D3DRESTYPE_TEXTURE: 2825 2934 Assert(pSharedSurface->u.pTexture); 2826 2935 D3D_RELEASE(pSharedSurface->u.pTexture); 2936 break; 2937 2938 case VMSVGA3D_D3DRESTYPE_CUBE_TEXTURE: 2939 Assert(pSharedSurface->u.pCubeTexture); 2940 D3D_RELEASE(pSharedSurface->u.pCubeTexture); 2941 break; 2942 2943 case VMSVGA3D_D3DRESTYPE_VOLUME_TEXTURE: 2944 Assert(pSharedSurface->u.pVolumeTexture); 2945 D3D_RELEASE(pSharedSurface->u.pVolumeTexture); 2827 2946 break; 2828 2947 … … 3988 4107 AssertReturn(pState, VERR_NO_MEMORY); 3989 4108 AssertReturn(type < SVGA3D_RT_MAX, VERR_INVALID_PARAMETER); 3990 AssertReturn(target.face == 0, VERR_INVALID_PARAMETER); 3991 3992 Log(("vmsvga3dSetRenderTarget cid=%x type=%x sid=%x\n", cid, type, target.sid)); 3993 3994 if ( cid >= pState->cContexts 3995 || pState->papContexts[cid]->id != cid) 3996 { 3997 Log(("vmsvga3dSetRenderTarget invalid context id!\n")); 3998 return VERR_INVALID_PARAMETER; 3999 } 4000 pContext = pState->papContexts[cid]; 4109 4110 LogFunc(("cid=%x type=%x sid=%x\n", cid, type, target.sid)); 4111 4112 int rc = vmsvga3dContextFromCid(pState, cid, &pContext); 4113 AssertRCReturn(rc, rc); 4001 4114 4002 4115 /* Save for vm state save/restore. */ … … 4010 4123 case SVGA3D_RT_DEPTH: 4011 4124 hr = pContext->pDevice->SetDepthStencilSurface(NULL); 4012 AssertMsgReturn(hr == D3D_OK, (" vmsvga3dSetRenderTarget:SetDepthStencilSurface failed with %x\n", hr), VERR_INTERNAL_ERROR);4125 AssertMsgReturn(hr == D3D_OK, ("SetDepthStencilSurface failed with %x\n", hr), VERR_INTERNAL_ERROR); 4013 4126 break; 4014 4127 … … 4029 4142 if (pState->fSupportedSurfaceNULL) 4030 4143 { 4031 /* Create a dummy render target to satisfy D3D. This path is usually taken only to render into a depth buffer without4032 * wishing to update an actual color render target4144 /* Create a dummy render target to satisfy D3D. This path is usually taken only to render 4145 * into a depth buffer without wishing to update an actual color render target. 4033 4146 */ 4034 IDirect3DSurface9 *pDummyRenderTarget;4147 IDirect3DSurface9 *pDummyRenderTarget; 4035 4148 hr = pContext->pDevice->CreateRenderTarget(pThis->svga.uWidth, 4036 4149 pThis->svga.uHeight, … … 4042 4155 NULL); 4043 4156 4044 AssertMsgReturn(hr == D3D_OK, (" vmsvga3dSetRenderTarget:CreateRenderTarget failed with %x\n", hr), VERR_INTERNAL_ERROR);4157 AssertMsgReturn(hr == D3D_OK, ("CreateRenderTarget failed with %x\n", hr), VERR_INTERNAL_ERROR); 4045 4158 4046 4159 hr = pContext->pDevice->SetRenderTarget(type - SVGA3D_RT_COLOR0, pDummyRenderTarget); … … 4050 4163 hr = pContext->pDevice->SetRenderTarget(type - SVGA3D_RT_COLOR0, NULL); 4051 4164 4052 AssertMsgReturn(hr == D3D_OK, (" vmsvga3dSetRenderTarget:SetRenderTarget failed with %x\n", hr), VERR_INTERNAL_ERROR);4165 AssertMsgReturn(hr == D3D_OK, ("SetRenderTarget failed with %x\n", hr), VERR_INTERNAL_ERROR); 4053 4166 break; 4054 4167 … … 4059 4172 } 4060 4173 4061 AssertReturn(target.sid < SVGA3D_MAX_SURFACE_IDS, VERR_INVALID_PARAMETER); 4062 AssertReturn(target.sid < pState->cSurfaces && pState->papSurfaces[target.sid]->id == target.sid, VERR_INVALID_PARAMETER); 4063 pRenderTarget = pState->papSurfaces[target.sid]; 4174 rc = vmsvga3dSurfaceFromSid(pState, target.sid, &pRenderTarget); 4175 AssertRCReturn(rc, rc); 4064 4176 4065 4177 switch (type) … … 4067 4179 case SVGA3D_RT_DEPTH: 4068 4180 case SVGA3D_RT_STENCIL: 4069 AssertReturn(target. mipmap == 0, VERR_INVALID_PARAMETER);4181 AssertReturn(target.face == 0 && target.mipmap == 0, VERR_INVALID_PARAMETER); 4070 4182 if (!pRenderTarget->u.pSurface) 4071 4183 { … … 4089 4201 || pRenderTarget->formatD3D == D3DFMT_D24X8)) 4090 4202 { 4091 Log (("vmsvga3dSetRenderTarget:Creating stencil surface as texture!\n"));4203 LogFunc(("Creating stencil surface as texture!\n")); 4092 4204 int rc = vmsvga3dBackCreateTexture(pState, pContext, cid, pRenderTarget); 4093 AssertRC(rc); /* non-fatal */4205 AssertRC(rc); /* non-fatal, will use CreateDepthStencilSurface */ 4094 4206 } 4095 4207 4096 4208 if (!pRenderTarget->fStencilAsTexture) 4097 4209 { 4098 Log(("vmsvga3dSetRenderTarget DEPTH/STENCIL; cQualityLevels=%d\n", cQualityLevels)); 4210 Assert(!pRenderTarget->u.pSurface); 4211 4212 LogFunc(("DEPTH/STENCIL; cQualityLevels=%d\n", cQualityLevels)); 4099 4213 hr = pContext->pDevice->CreateDepthStencilSurface(pRenderTarget->pMipmapLevels[0].mipmapSize.width, 4100 4214 pRenderTarget->pMipmapLevels[0].mipmapSize.height, … … 4105 4219 &pRenderTarget->u.pSurface, 4106 4220 NULL); 4107 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSetRenderTarget: CreateDepthStencilSurface failed with %x\n", hr), VERR_INTERNAL_ERROR); 4221 AssertMsgReturn(hr == D3D_OK, ("CreateDepthStencilSurface failed with %x\n", hr), VERR_INTERNAL_ERROR); 4222 pRenderTarget->enmD3DResType = VMSVGA3D_D3DRESTYPE_SURFACE; 4108 4223 } 4109 4224 … … 4157 4272 4158 4273 pRenderTarget->fUsageD3D |= D3DUSAGE_DEPTHSTENCIL; 4159 pRenderTarget-> flags|= SVGA3D_SURFACE_HINT_DEPTHSTENCIL;4274 pRenderTarget->surfaceFlags |= SVGA3D_SURFACE_HINT_DEPTHSTENCIL; 4160 4275 4161 4276 if (pRenderTarget->fStencilAsTexture) … … 4164 4279 4165 4280 hr = pRenderTarget->u.pTexture->GetSurfaceLevel(0, &pStencilSurface); 4166 AssertMsgReturn(hr == D3D_OK, (" vmsvga3dSetRenderTarget:GetSurfaceLevel failed with %x\n", hr), VERR_INTERNAL_ERROR);4281 AssertMsgReturn(hr == D3D_OK, ("GetSurfaceLevel failed with %x\n", hr), VERR_INTERNAL_ERROR); 4167 4282 4168 4283 hr = pContext->pDevice->SetDepthStencilSurface(pStencilSurface); 4169 4284 D3D_RELEASE(pStencilSurface); 4170 AssertMsgReturn(hr == D3D_OK, (" vmsvga3dSetRenderTarget:SetDepthStencilSurface failed with %x\n", hr), VERR_INTERNAL_ERROR);4285 AssertMsgReturn(hr == D3D_OK, ("SetDepthStencilSurface failed with %x\n", hr), VERR_INTERNAL_ERROR); 4171 4286 } 4172 4287 else 4173 4288 { 4174 4289 hr = pContext->pDevice->SetDepthStencilSurface(pRenderTarget->u.pSurface); 4175 AssertMsgReturn(hr == D3D_OK, (" vmsvga3dSetRenderTarget:SetDepthStencilSurface failed with %x\n", hr), VERR_INTERNAL_ERROR);4290 AssertMsgReturn(hr == D3D_OK, ("SetDepthStencilSurface failed with %x\n", hr), VERR_INTERNAL_ERROR); 4176 4291 } 4177 4292 break; … … 4188 4303 IDirect3DSurface9 *pSurface; 4189 4304 bool fTexture = false; 4190 bool fShared = false;4191 4305 4192 4306 /* Must flush the other context's 3d pipeline to make sure all drawing is complete for the surface we're about to use. */ 4193 4307 vmsvga3dSurfaceFlush(pThis, pRenderTarget); 4194 4308 4195 if (pRenderTarget-> flags & SVGA3D_SURFACE_HINT_TEXTURE)4309 if (pRenderTarget->surfaceFlags & SVGA3D_SURFACE_HINT_TEXTURE) 4196 4310 { 4197 4311 fTexture = true; … … 4200 4314 if (!pRenderTarget->u.pTexture) 4201 4315 { 4202 Log (("vmsvga3dSetRenderTarget: create texture to be used as render target; sid=%x type=%d format=%d -> create texture\n", target.sid, pRenderTarget->flags, pRenderTarget->format));4316 LogFunc(("Create texture to be used as render target; sid=%x type=%d format=%d -> create texture\n", target.sid, pRenderTarget->surfaceFlags, pRenderTarget->format)); 4203 4317 int rc = vmsvga3dBackCreateTexture(pState, pContext, cid, pRenderTarget); 4204 4318 AssertRCReturn(rc, rc); 4205 4319 } 4206 4320 4207 #ifndef VBOX_VMSVGA3D_WITH_WINE_OPENGL 4208 if (pRenderTarget->idAssociatedContext != cid) 4209 { 4210 Log(("vmsvga3dSetRenderTarget; using texture sid=%x created for another context (%d vs %d)\n", target.sid, pRenderTarget->idAssociatedContext, cid)); 4211 4212 PVMSVGA3DSHAREDSURFACE pSharedSurface = vmsvga3dSurfaceGetSharedCopy(pContext, pRenderTarget); 4213 AssertReturn(pSharedSurface, VERR_INTERNAL_ERROR); 4214 4215 hr = pSharedSurface->u.pTexture->GetSurfaceLevel(target.mipmap, 4216 &pSurface); 4217 4218 fShared = true; 4219 } 4220 else 4221 #endif 4222 hr = pRenderTarget->u.pTexture->GetSurfaceLevel(target.mipmap, 4223 &pSurface); 4224 4225 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSetRenderTarget: GetSurfaceLevel failed with %x\n", hr), VERR_INTERNAL_ERROR); 4321 rc = vmsvga3dGetD3DSurface(pContext, pRenderTarget, target.face, target.mipmap, false, &pSurface); 4322 AssertRCReturn(rc, rc); 4226 4323 } 4227 4324 else 4228 4325 { 4229 AssertReturn(target. mipmap == 0, VERR_INVALID_PARAMETER);4326 AssertReturn(target.face == 0 && target.mipmap == 0, VERR_INVALID_PARAMETER); 4230 4327 if (!pRenderTarget->u.pSurface) 4231 4328 { … … 4244 4341 } 4245 4342 4246 Log(("vmsvga3dSetRenderTarget COLOR; cQualityLevels=%d\n", cQualityLevels)); 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)); 4343 LogFunc(("COLOR; cQualityLevels=%d\n", cQualityLevels)); 4344 LogFunc(("Create rendertarget (%d,%d) formatD3D=%x multisample=%x\n", 4345 pRenderTarget->pMipmapLevels[0].mipmapSize.width, pRenderTarget->pMipmapLevels[0].mipmapSize.height, pRenderTarget->formatD3D, pRenderTarget->multiSampleTypeD3D)); 4248 4346 4249 4347 hr = pContext->pDevice->CreateRenderTarget(pRenderTarget->pMipmapLevels[0].mipmapSize.width, … … 4257 4355 AssertReturn(hr == D3D_OK, VERR_INTERNAL_ERROR); 4258 4356 4259 pRenderTarget->idAssociatedContext = cid; 4357 pRenderTarget->idAssociatedContext = cid; 4358 pRenderTarget->enmD3DResType = VMSVGA3D_D3DRESTYPE_SURFACE; 4260 4359 } 4261 4360 else … … 4263 4362 4264 4363 Assert(pRenderTarget->idAssociatedContext == cid); 4364 Assert(pRenderTarget->enmD3DResType == VMSVGA3D_D3DRESTYPE_SURFACE); 4265 4365 pSurface = pRenderTarget->u.pSurface; 4266 4366 } … … 4270 4370 4271 4371 pRenderTarget->fUsageD3D |= D3DUSAGE_RENDERTARGET; 4272 pRenderTarget-> flags|= SVGA3D_SURFACE_HINT_RENDERTARGET;4372 pRenderTarget->surfaceFlags |= SVGA3D_SURFACE_HINT_RENDERTARGET; 4273 4373 4274 4374 hr = pContext->pDevice->SetRenderTarget(type - SVGA3D_RT_COLOR0, pSurface); 4275 4375 if (fTexture) 4276 4376 D3D_RELEASE(pSurface); /* Release reference to texture level 0 */ 4277 AssertMsgReturn(hr == D3D_OK, (" vmsvga3dSetRenderTarget:SetRenderTarget failed with %x\n", hr), VERR_INTERNAL_ERROR);4377 AssertMsgReturn(hr == D3D_OK, ("SetRenderTarget failed with %x\n", hr), VERR_INTERNAL_ERROR); 4278 4378 4279 4379 pContext->sidRenderTarget = target.sid; … … 4418 4518 AssertReturn(pState, VERR_NO_MEMORY); 4419 4519 4420 Log(("vmsvga3dSetTextureState %x cTextureState=%d\n", cid, cTextureStates)); 4421 4422 if ( cid >= pState->cContexts 4423 || pState->papContexts[cid]->id != cid) 4424 { 4425 Log(("vmsvga3dSetTextureState invalid context id!\n")); 4426 return VERR_INVALID_PARAMETER; 4427 } 4428 pContext = pState->papContexts[cid]; 4520 LogFunc(("%x cTextureState=%d\n", cid, cTextureStates)); 4521 4522 int rc = vmsvga3dContextFromCid(pState, cid, &pContext); 4523 AssertRCReturn(rc, rc); 4429 4524 4430 4525 for (unsigned i = 0; i < cTextureStates; i++) … … 4434 4529 uint32_t currentStage = pTextureState[i].stage; 4435 4530 4436 Log (("vmsvga3dSetTextureState:cid=%x stage=%d type=%s (%x) val=%x\n", cid, currentStage, vmsvga3dTextureStateToString(pTextureState[i].name), pTextureState[i].name, pTextureState[i].value));4531 LogFunc(("cid=%x stage=%d type=%s (%x) val=%x\n", cid, currentStage, vmsvga3dTextureStateToString(pTextureState[i].name), pTextureState[i].name, pTextureState[i].value)); 4437 4532 4438 4533 /** @todo Is this the appropriate limit for all kinds of textures? It is the … … 4440 4535 if (RT_UNLIKELY(currentStage >= SVGA3D_MAX_TEXTURE_STAGE)) 4441 4536 { 4442 AssertMsgFailed(("pTextureState[%d].stage=%#x name=%#x \n", i, pTextureState[i].stage, pTextureState[i].name));4537 AssertMsgFailed(("pTextureState[%d].stage=%#x name=%#x value=%#x\n", i, pTextureState[i].stage, pTextureState[i].name, pTextureState[i].value)); 4443 4538 continue; 4444 4539 } … … 4541 4636 /* Unselect the currently associated texture. */ 4542 4637 hr = pContext->pDevice->SetTexture(currentStage, NULL); 4543 AssertMsgReturn(hr == D3D_OK, (" vmsvga3dSetTextureState:SetTexture failed with %x\n", hr), VERR_INTERNAL_ERROR);4638 AssertMsgReturn(hr == D3D_OK, ("SetTexture failed with %x\n", hr), VERR_INTERNAL_ERROR); 4544 4639 } 4545 4640 else 4546 4641 { 4547 HRESULT hr; 4548 uint32_t sid = pTextureState[i].value; 4549 4550 AssertReturn(sid < SVGA3D_MAX_SURFACE_IDS, VERR_INVALID_PARAMETER); 4551 AssertReturn(sid < pState->cSurfaces && pState->papSurfaces[sid]->id == sid, VERR_INVALID_PARAMETER); 4552 4553 PVMSVGA3DSURFACE pSurface = pState->papSurfaces[sid]; 4642 PVMSVGA3DSURFACE pSurface; 4643 const uint32_t sid = pTextureState[i].value; 4644 4645 rc = vmsvga3dSurfaceFromSid(pState, sid, &pSurface); 4646 AssertRCReturn(rc, rc); 4554 4647 4555 4648 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)); … … 4558 4651 { 4559 4652 Assert(pSurface->idAssociatedContext == SVGA3D_INVALID_ID); 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));4561 intrc = vmsvga3dBackCreateTexture(pState, pContext, cid, pSurface);4653 LogFunc(("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)); 4654 rc = vmsvga3dBackCreateTexture(pState, pContext, cid, pSurface); 4562 4655 AssertRCReturn(rc, rc); 4563 4656 } … … 4571 4664 if (pSurface->idAssociatedContext != cid) 4572 4665 { 4573 Log (("vmsvga3dSetTextureState;using texture sid=%x created for another context (%d vs %d)\n", sid, pSurface->idAssociatedContext, cid));4666 LogFunc(("using texture sid=%x created for another context (%d vs %d)\n", sid, pSurface->idAssociatedContext, cid)); 4574 4667 4575 4668 PVMSVGA3DSHAREDSURFACE pSharedSurface = vmsvga3dSurfaceGetSharedCopy(pContext, pSurface); … … 4582 4675 hr = pContext->pDevice->SetTexture(currentStage, pSurface->u.pTexture); 4583 4676 4584 AssertMsgReturn(hr == D3D_OK, (" vmsvga3dSetTextureState:SetTexture failed with %x\n", hr), VERR_INTERNAL_ERROR);4677 AssertMsgReturn(hr == D3D_OK, ("SetTexture failed with %x\n", hr), VERR_INTERNAL_ERROR); 4585 4678 4586 4679 pContext->aSidActiveTexture[currentStage] = sid; … … 4691 4784 AssertReturn(pState, VERR_NO_MEMORY); 4692 4785 4693 Log(("vmsvga3dSetMaterial %x face %d\n", cid, face)); 4694 4695 if ( cid >= pState->cContexts 4696 || pState->papContexts[cid]->id != cid) 4697 { 4698 Log(("vmsvga3dSetMaterial invalid context id!\n")); 4699 return VERR_INVALID_PARAMETER; 4700 } 4701 pContext = pState->papContexts[cid]; 4786 LogFunc(("cid=%x face %d\n", cid, face)); 4787 4788 int rc = vmsvga3dContextFromCid(pState, cid, &pContext); 4789 AssertRCReturn(rc, rc); 4702 4790 4703 4791 AssertReturn(face < SVGA3D_FACE_MAX, VERR_INVALID_PARAMETER); … … 4733 4821 4734 4822 hr = pContext->pDevice->SetMaterial(&material); 4735 AssertMsgReturn(hr == D3D_OK, (" vmsvga3dSetMaterial:SetMaterial failed with %x\n", hr), VERR_INTERNAL_ERROR);4823 AssertMsgReturn(hr == D3D_OK, ("SetMaterial failed with %x\n", hr), VERR_INTERNAL_ERROR); 4736 4824 4737 4825 return VINF_SUCCESS; … … 4748 4836 Log(("vmsvga3dSetLightData %x index=%d\n", cid, index)); 4749 4837 4750 if ( cid >= pState->cContexts 4751 || pState->papContexts[cid]->id != cid) 4752 { 4753 Log(("vmsvga3dSetLightData invalid context id!\n")); 4754 return VERR_INVALID_PARAMETER; 4755 } 4756 pContext = pState->papContexts[cid]; 4838 int rc = vmsvga3dContextFromCid(pState, cid, &pContext); 4839 AssertRCReturn(rc, rc); 4757 4840 4758 4841 switch (pData->type) … … 4812 4895 4813 4896 hr = pContext->pDevice->SetLight(index, &light); 4814 AssertMsgReturn(hr == D3D_OK, (" vmsvga3dSetLightData:SetLight failed with %x\n", hr), VERR_INTERNAL_ERROR);4897 AssertMsgReturn(hr == D3D_OK, ("SetLight failed with %x\n", hr), VERR_INTERNAL_ERROR); 4815 4898 4816 4899 return VINF_SUCCESS; … … 4826 4909 Log(("vmsvga3dSetLightEnabled %x %d -> %d\n", cid, index, enabled)); 4827 4910 4828 if ( cid >= pState->cContexts 4829 || pState->papContexts[cid]->id != cid) 4830 { 4831 Log(("vmsvga3dSetLightEnabled invalid context id!\n")); 4832 return VERR_INVALID_PARAMETER; 4833 } 4834 pContext = pState->papContexts[cid]; 4911 int rc = vmsvga3dContextFromCid(pState, cid, &pContext); 4912 AssertRCReturn(rc, rc); 4835 4913 4836 4914 /* Store for vm state save/restore */ … … 4841 4919 4842 4920 hr = pContext->pDevice->LightEnable(index, (BOOL)enabled); 4843 AssertMsgReturn(hr == D3D_OK, (" vmsvga3dSetLightEnabled:LightEnable failed with %x\n", hr), VERR_INTERNAL_ERROR);4921 AssertMsgReturn(hr == D3D_OK, ("LightEnable failed with %x\n", hr), VERR_INTERNAL_ERROR); 4844 4922 4845 4923 return VINF_SUCCESS; … … 4856 4934 Log(("vmsvga3dSetViewPort %x (%d,%d)(%d,%d)\n", cid, pRect->x, pRect->y, pRect->w, pRect->h)); 4857 4935 4858 if ( cid >= pState->cContexts 4859 || pState->papContexts[cid]->id != cid) 4860 { 4861 Log(("vmsvga3dSetViewPort invalid context id!\n")); 4862 return VERR_INVALID_PARAMETER; 4863 } 4936 int rc = vmsvga3dContextFromCid(pState, cid, &pContext); 4937 AssertRCReturn(rc, rc); 4938 4864 4939 /* Save for vm state save/restore. */ 4865 pContext = pState->papContexts[cid];4866 4940 pContext->state.RectViewPort = *pRect; 4867 4941 pContext->state.u32UpdateFlags |= VMSVGA3D_UPDATE_VIEWPORT; 4868 4942 4869 4943 hr = pContext->pDevice->GetViewport(&viewPort); 4870 AssertMsgReturn(hr == D3D_OK, (" vmsvga3dSetViewPort:GetViewport failed with %x\n", hr), VERR_INTERNAL_ERROR);4944 AssertMsgReturn(hr == D3D_OK, ("GetViewport failed with %x\n", hr), VERR_INTERNAL_ERROR); 4871 4945 4872 4946 viewPort.X = pRect->x; … … 4877 4951 4878 4952 hr = pContext->pDevice->SetViewport(&viewPort); 4879 AssertMsgReturn(hr == D3D_OK, (" vmsvga3dSetViewPort:SetViewport failed with %x\n", hr), VERR_INTERNAL_ERROR);4953 AssertMsgReturn(hr == D3D_OK, ("SetViewport failed with %x\n", hr), VERR_INTERNAL_ERROR); 4880 4954 4881 4955 return VINF_SUCCESS; 4882 4956 } 4883 4957 4884 int vmsvga3dSetClipPlane(PVGASTATE pThis, uint32_t cid, 4958 int vmsvga3dSetClipPlane(PVGASTATE pThis, uint32_t cid, uint32_t index, float plane[4]) 4885 4959 { 4886 4960 HRESULT hr; … … 4892 4966 AssertReturn(index < SVGA3D_CLIPPLANE_MAX, VERR_INVALID_PARAMETER); 4893 4967 4894 if ( cid >= pState->cContexts 4895 || pState->papContexts[cid]->id != cid) 4896 { 4897 Log(("vmsvga3dSetClipPlane invalid context id!\n")); 4898 return VERR_INVALID_PARAMETER; 4899 } 4900 pContext = pState->papContexts[cid]; 4968 int rc = vmsvga3dContextFromCid(pState, cid, &pContext); 4969 AssertRCReturn(rc, rc); 4901 4970 4902 4971 /* Store for vm state save/restore. */ … … 4905 4974 4906 4975 hr = pContext->pDevice->SetClipPlane(index, plane); 4907 AssertMsgReturn(hr == D3D_OK, (" vmsvga3dSetClipPlane:SetClipPlane failed with %x\n", hr), VERR_INTERNAL_ERROR);4976 AssertMsgReturn(hr == D3D_OK, ("SetClipPlane failed with %x\n", hr), VERR_INTERNAL_ERROR); 4908 4977 return VINF_SUCCESS; 4909 4978 } … … 4920 4989 Log(("vmsvga3dCommandClear %x clearFlag=%x color=%x depth=%d stencil=%x cRects=%d\n", cid, clearFlag, color, (uint32_t)(depth * 100.0), stencil, cRects)); 4921 4990 4922 if ( cid >= pState->cContexts 4923 || pState->papContexts[cid]->id != cid) 4924 { 4925 Log(("vmsvga3dCommandClear invalid context id!\n")); 4926 return VERR_INVALID_PARAMETER; 4927 } 4928 pContext = pState->papContexts[cid]; 4991 int rc = vmsvga3dContextFromCid(pState, cid, &pContext); 4992 AssertRCReturn(rc, rc); 4929 4993 4930 4994 if (clearFlag & SVGA3D_CLEAR_COLOR) … … 4954 5018 RTMemFree(pRectD3D); 4955 5019 4956 AssertMsgReturn(hr == D3D_OK, (" vmsvga3dCommandClear:Clear failed with %x\n", hr), VERR_INTERNAL_ERROR);5020 AssertMsgReturn(hr == D3D_OK, ("Clear failed with %x\n", hr), VERR_INTERNAL_ERROR); 4957 5021 4958 5022 /* Make sure we can track drawing usage of active render targets. */ … … 4964 5028 4965 5029 /* Convert VMWare vertex declaration to its D3D equivalent. */ 4966 int vmsvga3dVertexDecl2D3D(SVGA3dVertexArrayIdentity &identity, D3DVERTEXELEMENT9 *pVertexElement)5030 static int vmsvga3dVertexDecl2D3D(SVGA3dVertexArrayIdentity &identity, D3DVERTEXELEMENT9 *pVertexElement) 4967 5031 { 4968 5032 /* usage, method and type are identical; make sure. */ … … 4984 5048 4985 5049 /* Convert VMWare primitive type to its D3D equivalent. */ 4986 int vmsvga3dPrimitiveType2D3D(SVGA3dPrimitiveType PrimitiveType, D3DPRIMITIVETYPE *pPrimitiveTypeD3D)5050 static int vmsvga3dPrimitiveType2D3D(SVGA3dPrimitiveType PrimitiveType, D3DPRIMITIVETYPE *pPrimitiveTypeD3D) 4987 5051 { 4988 5052 switch (PrimitiveType) … … 5012 5076 } 5013 5077 5014 int vmsvga3dDrawPrimitivesProcessVertexDecls(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext, uint32_t numVertexDecls, SVGA3dVertexDecl *pVertexDecl, uint32_t idStream, D3DVERTEXELEMENT9 *pVertexElement)5078 static int vmsvga3dDrawPrimitivesProcessVertexDecls(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext, uint32_t numVertexDecls, SVGA3dVertexDecl *pVertexDecl, uint32_t idStream, D3DVERTEXELEMENT9 *pVertexElement) 5015 5079 { 5016 5080 HRESULT hr; … … 5047 5111 uVertexMinOffset = pVertexDecl[iVertex].array.offset; 5048 5112 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)) 5113 if ( pVertexSurface->u.pSurface 5114 && pVertexSurface->enmD3DResType != VMSVGA3D_D3DRESTYPE_VERTEX_BUFFER) 5052 5115 { 5053 5116 /* 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 5117 Assert(pVertexSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_INDEX_BUFFER); 5057 5118 D3D_RELEASE(pVertexSurface->u.pIndexBuffer); 5119 pVertexSurface->enmD3DResType = VMSVGA3D_D3DRESTYPE_NONE; 5120 5058 5121 LogFunc(("index -> vertex buffer sid=%x\n", sidVertex)); 5059 5122 } … … 5063 5126 Assert(iVertex == 0); 5064 5127 5065 Log (("vmsvga3dDrawPrimitives:create vertex buffer fDirty=%d\n", pVertexSurface->fDirty));5128 LogFunc(("create vertex buffer fDirty=%d\n", pVertexSurface->fDirty)); 5066 5129 hr = pContext->pDevice->CreateVertexBuffer(pVertexSurface->pMipmapLevels[0].cbSurface, 5067 5130 D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY /* possible severe performance penalty otherwise (according to d3d debug output) */, … … 5070 5133 &pVertexSurface->u.pVertexBuffer, 5071 5134 NULL); 5072 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dDrawPrimitives: CreateVertexBuffer failed with %x\n", hr), VERR_INTERNAL_ERROR); 5073 5135 AssertMsgReturn(hr == D3D_OK, ("CreateVertexBuffer failed with %x\n", hr), VERR_INTERNAL_ERROR); 5136 5137 pVertexSurface->enmD3DResType = VMSVGA3D_D3DRESTYPE_VERTEX_BUFFER; 5074 5138 pVertexSurface->idAssociatedContext = pContext->id; 5075 5139 … … 5079 5143 5080 5144 hr = pVertexSurface->u.pVertexBuffer->Lock(0, 0, &pData, 0); 5081 AssertMsgReturn(hr == D3D_OK, (" vmsvga3dDrawPrimitives:Lock vertex failed with %x\n", hr), VERR_INTERNAL_ERROR);5145 AssertMsgReturn(hr == D3D_OK, ("Lock vertex failed with %x\n", hr), VERR_INTERNAL_ERROR); 5082 5146 5083 5147 memcpy(pData, pVertexSurface->pMipmapLevels[0].pSurfaceData, pVertexSurface->pMipmapLevels[0].cbSurface); 5084 5148 5085 5149 hr = pVertexSurface->u.pVertexBuffer->Unlock(); 5086 AssertMsgReturn(hr == D3D_OK, (" vmsvga3dDrawPrimitives:Unlock vertex failed with %x\n", hr), VERR_INTERNAL_ERROR);5150 AssertMsgReturn(hr == D3D_OK, ("Unlock vertex failed with %x\n", hr), VERR_INTERNAL_ERROR); 5087 5151 pVertexSurface->pMipmapLevels[0].fDirty = false; 5088 5152 pVertexSurface->fDirty = false; 5089 5153 } 5090 pVertexSurface->flags |= SVGA3D_SURFACE_HINT_VERTEXBUFFER; 5091 pVertexSurface->fu32ActualUsageFlags |= SVGA3D_SURFACE_HINT_VERTEXBUFFER; 5154 pVertexSurface->surfaceFlags |= SVGA3D_SURFACE_HINT_VERTEXBUFFER; 5092 5155 } 5093 5156 } … … 5099 5162 #ifdef LOG_ENABLED 5100 5163 if (pVertexElement[iVertex].Offset >= pVertexDecl[0].array.stride) 5101 Log (("vmsvga3dDrawPrimitives:WARNING: offset > stride!!\n"));5164 LogFunc(("WARNING: offset > stride!!\n")); 5102 5165 #endif 5103 5166 5104 Log (("vmsvga3dDrawPrimitives:vertex %d offset = %d (stride %d) (min=%d max=%d)\n", iVertex, pVertexDecl[iVertex].array.offset, pVertexDecl[iVertex].array.stride, uVertexMinOffset, uVertexMaxOffset));5167 LogFunc(("vertex %d offset = %d (stride %d) (min=%d max=%d)\n", iVertex, pVertexDecl[iVertex].array.offset, pVertexDecl[iVertex].array.stride, uVertexMinOffset, uVertexMaxOffset)); 5105 5168 } 5106 5169 … … 5111 5174 pVertexSurface = pState->papSurfaces[sidVertex]; 5112 5175 5113 Log (("vmsvga3dDrawPrimitives:SetStreamSource %d min offset=%d stride=%d\n", idStream, uVertexMinOffset, strideVertex));5176 LogFunc(("SetStreamSource %d min offset=%d stride=%d\n", idStream, uVertexMinOffset, strideVertex)); 5114 5177 hr = pContext->pDevice->SetStreamSource(idStream, 5115 5178 pVertexSurface->u.pVertexBuffer, … … 5117 5180 strideVertex); 5118 5181 5119 AssertMsgReturn(hr == D3D_OK, (" vmsvga3dDrawPrimitives:SetStreamSource failed with %x\n", hr), VERR_INTERNAL_ERROR);5182 AssertMsgReturn(hr == D3D_OK, ("SetStreamSource failed with %x\n", hr), VERR_INTERNAL_ERROR); 5120 5183 return VINF_SUCCESS; 5121 5184 } … … 5136 5199 D3DVERTEXELEMENT9 VertexEnd = D3DDECL_END(); 5137 5200 5138 Log (("vmsvga3dDrawPrimitives%x numVertexDecls=%d numRanges=%d, cVertexDivisor=%d\n", cid, numVertexDecls, numRanges, cVertexDivisor));5201 LogFunc(("%x numVertexDecls=%d numRanges=%d, cVertexDivisor=%d\n", cid, numVertexDecls, numRanges, cVertexDivisor)); 5139 5202 5140 5203 AssertReturn(numVertexDecls && numVertexDecls <= SVGA3D_MAX_VERTEX_ARRAYS, VERR_INVALID_PARAMETER); … … 5144 5207 Assert(!cVertexDivisor); 5145 5208 5146 if ( cid >= pState->cContexts 5147 || pState->papContexts[cid]->id != cid) 5148 { 5149 Log(("vmsvga3dDrawPrimitives invalid context id!\n")); 5150 return VERR_INVALID_PARAMETER; 5151 } 5152 5153 pContext = pState->papContexts[cid]; 5209 rc = vmsvga3dContextFromCid(pState, cid, &pContext); 5210 AssertRCReturn(rc, rc); 5154 5211 5155 5212 /* Begin a scene before rendering anything. */ … … 5246 5303 AssertMsg(pRange[iPrimitive].indexWidth == sizeof(uint32_t) || pRange[iPrimitive].indexWidth == sizeof(uint16_t), ("Unsupported primitive width %d\n", pRange[iPrimitive].indexWidth)); 5247 5304 5248 if ( sidIndex >= SVGA3D_MAX_SURFACE_IDS 5249 || sidIndex >= pState->cSurfaces 5250 || pState->papSurfaces[sidIndex]->id != sidIndex) 5251 { 5252 Assert(sidIndex < SVGA3D_MAX_SURFACE_IDS); 5253 Assert(sidIndex < pState->cSurfaces && pState->papSurfaces[sidIndex]->id == sidIndex); 5254 rc = VERR_INVALID_PARAMETER; 5305 rc = vmsvga3dSurfaceFromSid(pState, sidIndex, &pIndexSurface); 5306 if (RT_FAILURE(rc)) 5255 5307 goto internal_error; 5256 } 5257 pIndexSurface = pState->papSurfaces[sidIndex]; 5308 5258 5309 Log(("vmsvga3dDrawPrimitives: index sid=%x\n", sidIndex)); 5259 5310 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)) 5311 if ( pIndexSurface->u.pSurface 5312 && pIndexSurface->enmD3DResType != VMSVGA3D_D3DRESTYPE_INDEX_BUFFER) 5263 5313 { 5264 5314 /* 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 5315 Assert(pIndexSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_VERTEX_BUFFER); 5268 5316 D3D_RELEASE(pIndexSurface->u.pVertexBuffer); 5317 pIndexSurface->enmD3DResType = VMSVGA3D_D3DRESTYPE_NONE; 5318 5269 5319 LogFunc(("vertex -> index buffer sid=%x\n", sidIndex)); 5270 5320 } … … 5286 5336 goto internal_error; 5287 5337 } 5338 pIndexSurface->enmD3DResType = VMSVGA3D_D3DRESTYPE_INDEX_BUFFER; 5288 5339 5289 5340 if (pIndexSurface->fDirty) … … 5304 5355 pIndexSurface->fDirty = false; 5305 5356 } 5306 pIndexSurface->flags |= SVGA3D_SURFACE_HINT_INDEXBUFFER; 5307 pIndexSurface->fu32ActualUsageFlags |= SVGA3D_SURFACE_HINT_INDEXBUFFER; 5357 pIndexSurface->surfaceFlags |= SVGA3D_SURFACE_HINT_INDEXBUFFER; 5308 5358 } 5309 5359 5310 5360 hr = pContext->pDevice->SetIndices(pIndexSurface->u.pIndexBuffer); 5311 AssertMsg(hr == D3D_OK, (" vmsvga3dDrawPrimitives:SetIndices vertex failed with %x\n", hr));5361 AssertMsg(hr == D3D_OK, ("SetIndices vertex failed with %x\n", hr)); 5312 5362 } 5313 5363 else 5314 5364 { 5315 5365 hr = pContext->pDevice->SetIndices(NULL); 5316 AssertMsg(hr == D3D_OK, (" vmsvga3dDrawPrimitives:SetIndices vertex (NULL) failed with %x\n", hr));5366 AssertMsg(hr == D3D_OK, ("SetIndices vertex (NULL) failed with %x\n", hr)); 5317 5367 } 5318 5368 -
trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d.cpp
r69136 r69153 209 209 } 210 210 211 pSurface-> flags= surfaceFlags;211 pSurface->surfaceFlags = surfaceFlags; 212 212 pSurface->format = format; 213 213 memcpy(pSurface->faces, face, sizeof(pSurface->faces)); … … 242 242 if (surfaceFlags & SVGA3D_SURFACE_AUTOGENMIPMAPS) 243 243 pSurface->fUsageD3D |= D3DUSAGE_AUTOGENMIPMAP; 244 pSurface->fu32ActualUsageFlags = 0; 244 pSurface->enmD3DResType = VMSVGA3D_D3DRESTYPE_NONE; 245 /* pSurface->u.pSurface = NULL; */ 246 /* pSurface->bounce.pTexture = NULL; */ 245 247 #else 246 248 vmsvga3dSurfaceFormat2OGL(pSurface, format); … … 429 431 { 430 432 /* Unknown surface type; turn it into a texture, which can be used for other purposes too. */ 431 LogFunc(("unknown src sid=%x type=%d format=%d -> create texture\n", sidSrc, pSrcSurface-> flags, pSrcSurface->format));433 LogFunc(("unknown src sid=%x type=%d format=%d -> create texture\n", sidSrc, pSrcSurface->surfaceFlags, pSrcSurface->format)); 432 434 rc = vmsvga3dBackCreateTexture(pState, pContext, pContext->id, pSrcSurface); 433 435 AssertRCReturn(rc, rc); … … 437 439 { 438 440 /* Unknown surface type; turn it into a texture, which can be used for other purposes too. */ 439 LogFunc(("unknown dest sid=%x type=%d format=%d -> create texture\n", sidDst, pDstSurface-> flags, pDstSurface->format));441 LogFunc(("unknown dest sid=%x type=%d format=%d -> create texture\n", sidDst, pDstSurface->surfaceFlags, pDstSurface->format)); 440 442 rc = vmsvga3dBackCreateTexture(pState, pContext, pContext->id, pDstSurface); 441 443 AssertRCReturn(rc, rc); … … 483 485 484 486 LogFunc(("%sguestptr gmr=%x offset=%x pitch=%x host sid=%x face=%d mipmap=%d transfer=%s cCopyBoxes=%d\n", 485 (pSurface-> flags & SVGA3D_SURFACE_HINT_TEXTURE) ? "TEXTURE " : "",487 (pSurface->surfaceFlags & SVGA3D_SURFACE_HINT_TEXTURE) ? "TEXTURE " : "", 486 488 guest.ptr.gmrId, guest.ptr.offset, guest.pitch, 487 489 host.sid, host.face, host.mipmap, (transfer == SVGA3D_WRITE_HOST_VRAM) ? "READ" : "WRITE", cCopyBoxes));
Note:
See TracChangeset
for help on using the changeset viewer.