Changeset 89163 in vbox
- Timestamp:
- May 19, 2021 1:12:44 PM (4 years ago)
- svn:sync-xref-src-repo-rev:
- 144504
- Location:
- trunk/src/VBox/Devices
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Graphics/DevVGA-SVGA.cpp
r89124 r89163 5823 5823 } VMSVGA3DINTERFACE; 5824 5824 5825 extern VMSVGA3DBACKENDDESC const g_BackendLegacy; 5826 #ifdef VMSVGA3D_DX 5827 extern VMSVGA3DBACKENDDESC const g_BackendDX; 5828 #endif 5829 5825 5830 /** 5826 5831 * Initializes the optional host 3D backend interfaces. … … 5829 5834 * @param pThisCC The VGA/VMSVGA state for ring-3. 5830 5835 */ 5831 static int vmsvgaR3Init3dInterfaces(PVGASTATECC pThisCC) 5832 { 5836 static int vmsvgaR3Init3dInterfaces(PVGASTATE pThis, PVGASTATECC pThisCC) 5837 { 5838 #ifndef VMSVGA3D_DX 5839 RT_NOREF(pThis); 5840 #endif 5841 5833 5842 PVMSVGAR3STATE pSVGAState = pThisCC->svga.pSvgaR3State; 5834 5843 … … 5844 5853 #undef ENTRY_3D_INTERFACE 5845 5854 5855 VMSVGA3DBACKENDDESC const *pBackend = NULL; 5856 #ifdef VMSVGA3D_DX 5857 if (pThis->fVMSVGA10) 5858 pBackend = &g_BackendDX; 5859 else 5860 #endif 5861 pBackend = &g_BackendLegacy; 5862 5846 5863 int rc = VINF_SUCCESS; 5847 5864 for (uint32_t i = 0; i < RT_ELEMENTS(a3dInterface); ++i) … … 5849 5866 VMSVGA3DINTERFACE *p = &a3dInterface[i]; 5850 5867 5851 int rc2 = vmsvga3dQueryInterface(pThisCC, p->pcszName, NULL, p->cbFuncs);5868 int rc2 = pBackend->pfnQueryInterface(pThisCC, p->pcszName, NULL, p->cbFuncs); 5852 5869 if (RT_SUCCESS(rc2)) 5853 5870 { … … 5855 5872 AssertBreakStmt(*p->ppvFuncs, rc = VERR_NO_MEMORY); 5856 5873 5857 vmsvga3dQueryInterface(pThisCC, p->pcszName, *p->ppvFuncs, p->cbFuncs);5874 pBackend->pfnQueryInterface(pThisCC, p->pcszName, *p->ppvFuncs, p->cbFuncs); 5858 5875 } 5859 5876 } … … 6189 6206 { 6190 6207 /* Load a 3D backend. */ 6191 rc = vmsvgaR3Init3dInterfaces(pThis CC);6208 rc = vmsvgaR3Init3dInterfaces(pThis, pThisCC); 6192 6209 if (RT_SUCCESS(rc)) 6193 6210 rc = pSVGAState->pFuncs3D->pfnInit(pDevIns, pThis, pThisCC); -
trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-info.cpp
r88787 r89163 354 354 355 355 356 /**357 * Worker for vmsvga3dUpdateHeapBuffersForSurfaces.358 *359 * This will allocate heap buffers if necessary, thus increasing the memory360 * usage of the process.361 *362 * @todo Would be interesting to share this code with the saved state code.363 *364 * @returns VBox status code.365 * @param pState The 3D state structure.366 * @param pSurface The surface to refresh the heap buffers for.367 */368 static int vmsvga3dSurfaceUpdateHeapBuffers(PVMSVGA3DSTATE pState, PVMSVGA3DSURFACE pSurface)369 {370 /*371 * Currently we've got trouble retreving bit for DEPTHSTENCIL372 * surfaces both for OpenGL and D3D, so skip these here (don't373 * wast memory on them).374 */375 uint32_t const fSwitchFlags = pSurface->surfaceFlags & VMSVGA3D_SURFACE_HINT_SWITCH_MASK;376 if ( fSwitchFlags != SVGA3D_SURFACE_HINT_DEPTHSTENCIL377 && fSwitchFlags != (SVGA3D_SURFACE_HINT_DEPTHSTENCIL | SVGA3D_SURFACE_HINT_TEXTURE))378 {379 380 #ifdef VMSVGA3D_OPENGL381 /*382 * Change OpenGL context to the one the surface is associated with.383 */384 PVMSVGA3DCONTEXT pContext = &pState->SharedCtx;385 VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);386 #endif387 388 /*389 * Work thru each mipmap level for each face.390 */391 for (uint32_t iFace = 0; iFace < pSurface->cFaces; iFace++)392 {393 PVMSVGA3DMIPMAPLEVEL pMipmapLevel = &pSurface->paMipmapLevels[iFace * pSurface->cLevels];394 for (uint32_t i = 0; i < pSurface->cLevels; i++, pMipmapLevel++)395 {396 if (VMSVGA3DSURFACE_HAS_HW_SURFACE(pSurface))397 {398 Assert(pMipmapLevel->cbSurface);399 Assert(pMipmapLevel->cbSurface == pMipmapLevel->cbSurfacePlane * pMipmapLevel->mipmapSize.depth);400 401 /*402 * Make sure we've got surface memory buffer.403 */404 uint8_t *pbDst = (uint8_t *)pMipmapLevel->pSurfaceData;405 if (!pbDst)406 {407 pMipmapLevel->pSurfaceData = pbDst = (uint8_t *)RTMemAllocZ(pMipmapLevel->cbSurface);408 AssertReturn(pbDst, VERR_NO_MEMORY);409 }410 411 #ifdef VMSVGA3D_DIRECT3D412 /*413 * D3D specifics.414 */415 Assert(pSurface->enmD3DResType != VMSVGA3D_D3DRESTYPE_NONE);416 417 HRESULT hr;418 switch (pSurface->enmD3DResType)419 {420 case VMSVGA3D_D3DRESTYPE_VOLUME_TEXTURE:421 AssertFailed(); /// @todo422 break;423 424 case VMSVGA3D_D3DRESTYPE_SURFACE:425 case VMSVGA3D_D3DRESTYPE_TEXTURE:426 case VMSVGA3D_D3DRESTYPE_CUBE_TEXTURE:427 {428 /*429 * Lock the buffer and make it accessible to memcpy.430 */431 D3DLOCKED_RECT LockedRect;432 if (pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_CUBE_TEXTURE)433 {434 hr = pSurface->u.pCubeTexture->LockRect(vmsvga3dCubemapFaceFromIndex(iFace),435 i, /* texture level */436 &LockedRect,437 NULL,438 D3DLOCK_READONLY);439 }440 else if (pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_TEXTURE)441 {442 if (pSurface->bounce.pTexture)443 {444 if ( !pSurface->fDirty445 && RT_BOOL(fSwitchFlags & SVGA3D_SURFACE_HINT_RENDERTARGET))446 {447 /** @todo stricter checks for associated context */448 uint32_t cid = pSurface->idAssociatedContext;449 PVMSVGA3DCONTEXT pContext;450 int rc = vmsvga3dContextFromCid(pState, cid, &pContext);451 AssertRCReturn(rc, rc);452 453 IDirect3DSurface9 *pDst = NULL;454 hr = pSurface->bounce.pTexture->GetSurfaceLevel(i, &pDst);455 AssertMsgReturn(hr == D3D_OK, ("GetSurfaceLevel failed with %#x\n", hr), VERR_INTERNAL_ERROR);456 457 IDirect3DSurface9 *pSrc = NULL;458 hr = pSurface->u.pTexture->GetSurfaceLevel(i, &pSrc);459 AssertMsgReturn(hr == D3D_OK, ("GetSurfaceLevel failed with %#x\n", hr), VERR_INTERNAL_ERROR);460 461 hr = pContext->pDevice->GetRenderTargetData(pSrc, pDst);462 AssertMsgReturn(hr == D3D_OK, ("GetRenderTargetData failed with %#x\n", hr), VERR_INTERNAL_ERROR);463 464 pSrc->Release();465 pDst->Release();466 }467 468 hr = pSurface->bounce.pTexture->LockRect(i, /* texture level */469 &LockedRect,470 NULL,471 D3DLOCK_READONLY);472 }473 else474 hr = pSurface->u.pTexture->LockRect(i, /* texture level */475 &LockedRect,476 NULL,477 D3DLOCK_READONLY);478 }479 else480 hr = pSurface->u.pSurface->LockRect(&LockedRect,481 NULL,482 D3DLOCK_READONLY);483 AssertMsgReturn(hr == D3D_OK, ("LockRect failed with %x\n", hr), VERR_INTERNAL_ERROR);484 485 /*486 * Copy the data. Take care in case the pitch differs.487 */488 if (pMipmapLevel->cbSurfacePitch == (uint32_t)LockedRect.Pitch)489 memcpy(pbDst, LockedRect.pBits, pMipmapLevel->cbSurface);490 else491 for (uint32_t j = 0; j < pMipmapLevel->cBlocksY; j++)492 memcpy(pbDst + j * pMipmapLevel->cbSurfacePitch,493 (uint8_t *)LockedRect.pBits + j * LockedRect.Pitch,494 pMipmapLevel->cbSurfacePitch);495 496 /*497 * Release the buffer.498 */499 if (fSwitchFlags & SVGA3D_SURFACE_HINT_TEXTURE)500 {501 if (pSurface->bounce.pTexture)502 {503 hr = pSurface->bounce.pTexture->UnlockRect(i);504 AssertMsgReturn(hr == D3D_OK, ("UnlockRect failed with %#x\n", hr), VERR_INTERNAL_ERROR);505 }506 else507 hr = pSurface->u.pTexture->UnlockRect(i);508 }509 else510 hr = pSurface->u.pSurface->UnlockRect();511 AssertMsgReturn(hr == D3D_OK, ("UnlockRect failed with %#x\n", hr), VERR_INTERNAL_ERROR);512 break;513 }514 515 case VMSVGA3D_D3DRESTYPE_VERTEX_BUFFER:516 case VMSVGA3D_D3DRESTYPE_INDEX_BUFFER:517 {518 /* Current type of the buffer. */519 const bool fVertex = (pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_VERTEX_BUFFER);520 521 void *pvD3DData = NULL;522 if (fVertex)523 hr = pSurface->u.pVertexBuffer->Lock(0, 0, &pvD3DData, D3DLOCK_READONLY);524 else525 hr = pSurface->u.pIndexBuffer->Lock(0, 0, &pvD3DData, D3DLOCK_READONLY);526 AssertMsgReturn(hr == D3D_OK, ("Lock %s failed with %x\n", fVertex ? "vertex" : "index", hr), VERR_INTERNAL_ERROR);527 528 memcpy(pbDst, pvD3DData, pMipmapLevel->cbSurface);529 530 if (fVertex)531 hr = pSurface->u.pVertexBuffer->Unlock();532 else533 hr = pSurface->u.pIndexBuffer->Unlock();534 AssertMsg(hr == D3D_OK, ("Unlock %s failed with %x\n", fVertex ? "vertex" : "index", hr));535 break;536 }537 538 default:539 AssertMsgFailed(("flags %#x, type %d\n", fSwitchFlags, pSurface->enmD3DResType));540 }541 542 #elif defined(VMSVGA3D_OPENGL)543 /*544 * OpenGL specifics.545 */546 switch (pSurface->enmOGLResType)547 {548 case VMSVGA3D_OGLRESTYPE_TEXTURE:549 {550 GLint activeTexture;551 glGetIntegerv(GL_TEXTURE_BINDING_2D, &activeTexture);552 VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext);553 554 glBindTexture(GL_TEXTURE_2D, pSurface->oglId.texture);555 VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext);556 557 /* Set row length and alignment of the output data. */558 VMSVGAPACKPARAMS SavedParams;559 vmsvga3dOglSetPackParams(pState, pContext, pSurface, &SavedParams);560 561 glGetTexImage(GL_TEXTURE_2D,562 i,563 pSurface->formatGL,564 pSurface->typeGL,565 pbDst);566 VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext);567 568 vmsvga3dOglRestorePackParams(pState, pContext, pSurface, &SavedParams);569 570 /* Restore the old active texture. */571 glBindTexture(GL_TEXTURE_2D, activeTexture);572 VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext);573 break;574 }575 576 case VMSVGA3D_OGLRESTYPE_BUFFER:577 {578 pState->ext.glBindBuffer(GL_ARRAY_BUFFER, pSurface->oglId.buffer);579 VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);580 581 void *pvSrc = pState->ext.glMapBuffer(GL_ARRAY_BUFFER, GL_READ_ONLY);582 VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);583 if (RT_VALID_PTR(pvSrc))584 memcpy(pbDst, pvSrc, pMipmapLevel->cbSurface);585 else586 AssertPtr(pvSrc);587 588 pState->ext.glUnmapBuffer(GL_ARRAY_BUFFER);589 VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);590 591 pState->ext.glBindBuffer(GL_ARRAY_BUFFER, 0);592 VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);593 break;594 }595 596 default:597 AssertMsgFailed(("%#x\n", fSwitchFlags));598 }599 #elif defined(VMSVGA3D_D3D11)600 /** @todo */601 RT_NOREF(pState);602 #else603 # error "misconfigured"604 #endif605 }606 /* else: There is no data in hardware yet, so whatever we got is already current. */607 }608 }609 }610 611 return VINF_SUCCESS;612 }613 614 615 /**616 * Updates the heap buffers for all surfaces or one specific one.617 *618 * @param pThisCC The VGA/VMSVGA state for ring-3.619 * @param sid The surface ID, UINT32_MAX if all.620 * @thread VMSVGAFIFO621 */622 void vmsvga3dUpdateHeapBuffersForSurfaces(PVGASTATECC pThisCC, uint32_t sid)623 {624 PVMSVGA3DSTATE pState = pThisCC->svga.p3dState;625 AssertReturnVoid(pState);626 627 if (sid == UINT32_MAX)628 {629 uint32_t cSurfaces = pState->cSurfaces;630 for (sid = 0; sid < cSurfaces; sid++)631 {632 PVMSVGA3DSURFACE pSurface = pState->papSurfaces[sid];633 if (pSurface && pSurface->id == sid)634 vmsvga3dSurfaceUpdateHeapBuffers(pState, pSurface);635 }636 }637 else if (sid < pState->cSurfaces)638 {639 PVMSVGA3DSURFACE pSurface = pState->papSurfaces[sid];640 if (pSurface && pSurface->id == sid)641 vmsvga3dSurfaceUpdateHeapBuffers(pState, pSurface);642 }643 }644 645 646 647 648 356 void vmsvga3dInfoU32Flags(PCDBGFINFOHLP pHlp, uint32_t fFlags, const char *pszPrefix, PCVMSVGAINFOFLAGS32 paFlags, uint32_t cFlags) 649 357 { … … 1624 1332 # ifdef VMSVGA3D_DIRECT3D 1625 1333 pHlp->pfnPrintf(pHlp, "pDevice: %p\n", pContext->pDevice); 1626 # elif defined(VMSVGA3D_D3D11)1627 /** @todo */1628 1334 # else 1629 1335 pHlp->pfnPrintf(pHlp, "hdc: %p\n", pContext->hdc); … … 2072 1778 2073 1779 pHlp->pfnPrintf(pHlp, "*** VMSVGA 3d surface %#x (%d)%s ***\n", pSurface->id, pSurface->id, pSurface->fDirty ? " - dirty" : ""); 2074 #ifdef VMSVGA3D_OPENGL2075 pHlp->pfnPrintf(pHlp, "idWeakContextAssociation: %#x\n", pSurface->idWeakContextAssociation);2076 #else2077 1780 pHlp->pfnPrintf(pHlp, "idAssociatedContext: %#x\n", pSurface->idAssociatedContext); 2078 #endif2079 1781 pHlp->pfnPrintf(pHlp, "Format: %s\n", 2080 1782 vmsvgaFormatEnumValueEx(szTmp, sizeof(szTmp), NULL, (int)pSurface->format, false, &g_SVGA3dSurfaceFormat2String)); … … 2132 1834 pHlp->pfnPrintf(pHlp, "fStencilAsTexture: %RTbool\n", pSurface->fStencilAsTexture); 2133 1835 2134 #elif defined(VMSVGA3D_D3D11)2135 /** @todo */2136 1836 #elif defined(VMSVGA3D_OPENGL) 2137 1837 /** @todo */ -
trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-internal.h
r89121 r89163 29 29 #endif 30 30 #ifdef VMSVGA3D_OPENGL 31 # if defined(VMSVGA3D_DIRECT3D) || defined(VMSVGA3D_D3D11)31 # if defined(VMSVGA3D_DIRECT3D) 32 32 # error "Both VMSVGA3D_DIRECT3D and VMSVGA3D_OPENGL cannot be defined at the same time." 33 33 # endif 34 #elif !defined(VMSVGA3D_DIRECT3D) && !defined(VMSVGA3D_D3D11)34 #elif !defined(VMSVGA3D_DIRECT3D) 35 35 # error "Either VMSVGA3D_OPENGL or VMSVGA3D_DIRECT3D must be defined." 36 36 #endif … … 51 51 # include <d3d9.h> 52 52 # include <iprt/avl.h> 53 # elif defined(VMSVGA3D_D3D11)54 # include <d3d11.h>55 53 # else 56 54 # include <GL/gl.h> … … 552 550 PVMSVGA3DBACKENDSURFACE pBackendSurface; 553 551 554 uint32_t id; 555 #ifdef VMSVGA3D_OPENGL 556 uint32_t idWeakContextAssociation; 557 #else 552 uint32_t id; /** @todo sid */ 553 /* Which context created the corresponding resource. 554 * SVGA_ID_INVALID means that resource has not been created yet, or has been created by the shared context. 555 * A resource has been created if VMSVGA3DSURFACE_HAS_HW_SURFACE is true. 556 * 557 */ 558 558 uint32_t idAssociatedContext; 559 #endif 560 SVGA3dSurface1Flags surfaceFlags; /* @todo SVGA3dSurfaceAllFlags as an union. */559 560 SVGA3dSurface1Flags surfaceFlags; /** @todo SVGA3dSurfaceAllFlags as an union. */ 561 561 SVGA3dSurfaceFormat format; 562 562 #ifdef VMSVGA3D_OPENGL … … 645 645 { 646 646 SSMFIELD_ENTRY( VMSVGA3DSURFACE, id), 647 # ifdef VMSVGA3D_OPENGL648 SSMFIELD_ENTRY( VMSVGA3DSURFACE, idWeakContextAssociation),649 # else650 647 SSMFIELD_ENTRY( VMSVGA3DSURFACE, idAssociatedContext), 651 # endif652 648 SSMFIELD_ENTRY( VMSVGA3DSURFACE, surfaceFlags), 653 649 SSMFIELD_ENTRY( VMSVGA3DSURFACE, format), … … 679 675 */ 680 676 #ifdef VMSVGA3D_DIRECT3D 681 # define VMSVGA3DSURFACE_HAS_HW_SURFACE(a_pSurface) ((a_pSurface)->u.pSurface != NULL) 682 #elif defined(VMSVGA3D_D3D11) 683 # define VMSVGA3DSURFACE_HAS_HW_SURFACE(a_pSurface) ((a_pSurface)->pBackendSurface != NULL) 677 # define VMSVGA3DSURFACE_HAS_HW_SURFACE(a_pSurface) ((a_pSurface)->pBackendSurface != NULL || (a_pSurface)->u.pSurface != NULL) 684 678 #else 685 # define VMSVGA3DSURFACE_HAS_HW_SURFACE(a_pSurface) ((a_pSurface)-> oglId.texture != OPENGL_INVALID_ID)679 # define VMSVGA3DSURFACE_HAS_HW_SURFACE(a_pSurface) ((a_pSurface)->pBackendSurface != NULL || (a_pSurface)->oglId.texture != OPENGL_INVALID_ID) 686 680 #endif 687 681 … … 696 690 ( (a_pSurface)->enmD3DResType == VMSVGA3D_D3DRESTYPE_VERTEX_BUFFER \ 697 691 || (a_pSurface)->enmD3DResType == VMSVGA3D_D3DRESTYPE_INDEX_BUFFER) 698 #elif defined(VMSVGA3D_D3D11)699 /** @todo */700 # define VMSVGA3DSURFACE_NEEDS_DATA(a_pSurface) (false)701 692 #else 702 693 # define VMSVGA3DSURFACE_NEEDS_DATA(a_pSurface) \ … … 717 708 IDirect3DVertexShader9 *pVertexShader; 718 709 IDirect3DPixelShader9 *pPixelShader; 719 #elif defined(VMSVGA3D_D3D11)720 /* Nothing */721 710 #else 722 711 void *pVertexShader; … … 773 762 #ifdef VMSVGA3D_DIRECT3D 774 763 IDirect3DQuery9 *pQuery; 775 #elif defined(VMSVGA3D_D3D11)776 /** @todo */777 764 #else /* VMSVGA3D_OPENGL */ 778 765 GLuint idQuery; … … 790 777 #ifdef VMSVGA3D_DIRECT3D 791 778 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DQUERY, pQuery), 792 #elif defined(VMSVGA3D_D3D11)793 /** @todo */794 779 #else /* VMSVGA3D_OPENGL */ 795 780 SSMFIELD_ENTRY_IGNORE( VMSVGA3DQUERY, idQuery), … … 803 788 #ifdef VMSVGA3D_DIRECT3D 804 789 #define VMSVGA3DQUERY_EXISTS(p) ((p)->pQuery && (p)->enmQueryState != VMSVGA3DQUERYSTATE_NULL) 805 #elif defined(VMSVGA3D_D3D11)806 /** @todo */807 #define VMSVGA3DQUERY_EXISTS(p) ((p)->enmQueryState != VMSVGA3DQUERYSTATE_NULL)808 790 #else 809 791 #define VMSVGA3DQUERY_EXISTS(p) ((p)->idQuery && (p)->enmQueryState != VMSVGA3DQUERYSTATE_NULL) … … 815 797 typedef struct VMSVGA3DCONTEXT 816 798 { 799 /** @todo Legacy contexts with DX backend. */ 800 817 801 uint32_t id; 818 802 #ifdef RT_OS_WINDOWS … … 823 807 IDirect3DDevice9Ex *pDevice; 824 808 # endif 825 # elif defined(VMSVGA3D_D3D11)826 /** @todo Legacy contexts with DX backend. */827 809 # else 828 810 /* Device context of the context window. */ … … 923 905 # ifdef VMSVGA3D_DIRECT3D 924 906 SSMFIELD_ENTRY_IGN_HCPTR( VMSVGA3DCONTEXT, pDevice), 925 # elif defined(VMSVGA3D_D3D11)926 /** @todo */927 907 # else 928 908 SSMFIELD_ENTRY_IGNORE( VMSVGA3DCONTEXT, hdc), … … 1045 1025 typedef struct VMSVGA3DSTATE 1046 1026 { 1027 /** Backend specific data. */ 1028 PVMSVGA3DBACKEND pBackend; 1029 1047 1030 /** The size of papContexts. */ 1048 1031 uint32_t cContexts; … … 1077 1060 bool fSupportedFormatYUY2 : 1; 1078 1061 bool fSupportedFormatA8B8G8R8 : 1; 1079 # elif defined(VMSVGA3D_D3D11)1080 PVMSVGA3DBACKEND pBackend;1081 1062 # endif 1082 1063 /** Window Thread. */ … … 1388 1369 } 1389 1370 1390 #ifdef VMSVGA3D_DIRECT3D1391 DECLINLINE(D3DCUBEMAP_FACES) vmsvga3dCubemapFaceFromIndex(uint32_t iFace)1392 {1393 D3DCUBEMAP_FACES Face;1394 switch (iFace)1395 {1396 case 0: Face = D3DCUBEMAP_FACE_POSITIVE_X; break;1397 case 1: Face = D3DCUBEMAP_FACE_NEGATIVE_X; break;1398 case 2: Face = D3DCUBEMAP_FACE_POSITIVE_Y; break;1399 case 3: Face = D3DCUBEMAP_FACE_NEGATIVE_Y; break;1400 case 4: Face = D3DCUBEMAP_FACE_POSITIVE_Z; break;1401 default:1402 case 5: Face = D3DCUBEMAP_FACE_NEGATIVE_Z; break;1403 }1404 return Face;1405 }1406 #elif defined(VMSVGA3D_D3D11)1407 DECLINLINE(D3D11_TEXTURECUBE_FACE) vmsvga3dCubemapFaceFromIndex(uint32_t iFace)1408 {1409 D3D11_TEXTURECUBE_FACE Face;1410 switch (iFace)1411 {1412 case 0: Face = D3D11_TEXTURECUBE_FACE_POSITIVE_X; break;1413 case 1: Face = D3D11_TEXTURECUBE_FACE_NEGATIVE_X; break;1414 case 2: Face = D3D11_TEXTURECUBE_FACE_POSITIVE_Y; break;1415 case 3: Face = D3D11_TEXTURECUBE_FACE_NEGATIVE_Y; break;1416 case 4: Face = D3D11_TEXTURECUBE_FACE_POSITIVE_Z; break;1417 default:1418 case 5: Face = D3D11_TEXTURECUBE_FACE_NEGATIVE_Z; break;1419 }1420 return Face;1421 }1422 #else /* VMSVGA3D_OPENGL */1423 DECLINLINE(GLenum) vmsvga3dCubemapFaceFromIndex(uint32_t iFace)1424 {1425 GLint Face;1426 switch (iFace)1427 {1428 case 0: Face = GL_TEXTURE_CUBE_MAP_POSITIVE_X; break;1429 case 1: Face = GL_TEXTURE_CUBE_MAP_NEGATIVE_X; break;1430 case 2: Face = GL_TEXTURE_CUBE_MAP_POSITIVE_Y; break;1431 case 3: Face = GL_TEXTURE_CUBE_MAP_NEGATIVE_Y; break;1432 case 4: Face = GL_TEXTURE_CUBE_MAP_POSITIVE_Z; break;1433 default:1434 case 5: Face = GL_TEXTURE_CUBE_MAP_NEGATIVE_Z; break;1435 }1436 return Face;1437 }1438 #endif1439 1440 1371 void vmsvga3dInfoSurfaceToBitmap(PCDBGFINFOHLP pHlp, PVMSVGA3DSURFACE pSurface, 1441 1372 const char *pszPath, const char *pszNamePrefix, const char *pszNameSuffix); 1442 1373 1443 #if defined( VMSVGA3D_DIRECT3D) || defined(VMSVGA3D_D3D11)1374 #if defined(RT_OS_WINDOWS) 1444 1375 #define D3D_RELEASE(ptr) do { \ 1445 if (ptr) 1446 { 1447 (ptr)->Release(); 1448 (ptr) = 0; 1449 } 1376 if (ptr) \ 1377 { \ 1378 (ptr)->Release(); \ 1379 (ptr) = 0; \ 1380 } \ 1450 1381 } while (0) 1451 1382 #endif -
trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-ogl.cpp
r89123 r89163 824 824 825 825 return VINF_SUCCESS; 826 } 827 828 829 DECLINLINE(GLenum) vmsvga3dCubemapFaceFromIndex(uint32_t iFace) 830 { 831 GLint Face; 832 switch (iFace) 833 { 834 case 0: Face = GL_TEXTURE_CUBE_MAP_POSITIVE_X; break; 835 case 1: Face = GL_TEXTURE_CUBE_MAP_NEGATIVE_X; break; 836 case 2: Face = GL_TEXTURE_CUBE_MAP_POSITIVE_Y; break; 837 case 3: Face = GL_TEXTURE_CUBE_MAP_NEGATIVE_Y; break; 838 case 4: Face = GL_TEXTURE_CUBE_MAP_POSITIVE_Z; break; 839 default: 840 case 5: Face = GL_TEXTURE_CUBE_MAP_NEGATIVE_Z; break; 841 } 842 return Face; 826 843 } 827 844 … … 5361 5378 pContext = pState->papContexts[cid]; 5362 5379 VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext); 5363 pRenderTarget->idWeakContextAssociation = cid;5364 5380 } 5365 5381 … … 7734 7750 } 7735 7751 7736 int vmsvga3dQueryInterface(PVGASTATECC pThisCC, char const *pszInterfaceName, void *pvInterfaceFuncs, size_t cbInterfaceFuncs) 7752 /** 7753 * Worker for vmsvga3dUpdateHeapBuffersForSurfaces. 7754 * 7755 * This will allocate heap buffers if necessary, thus increasing the memory 7756 * usage of the process. 7757 * 7758 * @todo Would be interesting to share this code with the saved state code. 7759 * 7760 * @returns VBox status code. 7761 * @param pThisCC The VGA/VMSVGA context. 7762 * @param pSurface The surface to refresh the heap buffers for. 7763 */ 7764 static DECLCALLBACK(int) vmsvga3dBackSurfaceUpdateHeapBuffers(PVGASTATECC pThisCC, PVMSVGA3DSURFACE pSurface) 7765 { 7766 PVMSVGA3DSTATE pState = pThisCC->svga.p3dState; 7767 AssertReturn(pState, VERR_INVALID_STATE); 7768 7769 /* 7770 * Currently we've got trouble retreving bit for DEPTHSTENCIL 7771 * surfaces both for OpenGL and D3D, so skip these here (don't 7772 * wast memory on them). 7773 */ 7774 uint32_t const fSwitchFlags = pSurface->surfaceFlags & VMSVGA3D_SURFACE_HINT_SWITCH_MASK; 7775 if ( fSwitchFlags != SVGA3D_SURFACE_HINT_DEPTHSTENCIL 7776 && fSwitchFlags != (SVGA3D_SURFACE_HINT_DEPTHSTENCIL | SVGA3D_SURFACE_HINT_TEXTURE)) 7777 { 7778 /* 7779 * Change OpenGL context to the one the surface is associated with. 7780 */ 7781 PVMSVGA3DCONTEXT pContext = &pState->SharedCtx; 7782 VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext); 7783 7784 /* 7785 * Work thru each mipmap level for each face. 7786 */ 7787 for (uint32_t iFace = 0; iFace < pSurface->cFaces; iFace++) 7788 { 7789 PVMSVGA3DMIPMAPLEVEL pMipmapLevel = &pSurface->paMipmapLevels[iFace * pSurface->cLevels]; 7790 for (uint32_t i = 0; i < pSurface->cLevels; i++, pMipmapLevel++) 7791 { 7792 if (VMSVGA3DSURFACE_HAS_HW_SURFACE(pSurface)) 7793 { 7794 Assert(pMipmapLevel->cbSurface); 7795 Assert(pMipmapLevel->cbSurface == pMipmapLevel->cbSurfacePlane * pMipmapLevel->mipmapSize.depth); 7796 7797 /* 7798 * Make sure we've got surface memory buffer. 7799 */ 7800 uint8_t *pbDst = (uint8_t *)pMipmapLevel->pSurfaceData; 7801 if (!pbDst) 7802 { 7803 pMipmapLevel->pSurfaceData = pbDst = (uint8_t *)RTMemAllocZ(pMipmapLevel->cbSurface); 7804 AssertReturn(pbDst, VERR_NO_MEMORY); 7805 } 7806 7807 /* 7808 * OpenGL specifics. 7809 */ 7810 switch (pSurface->enmOGLResType) 7811 { 7812 case VMSVGA3D_OGLRESTYPE_TEXTURE: 7813 { 7814 GLint activeTexture; 7815 glGetIntegerv(GL_TEXTURE_BINDING_2D, &activeTexture); 7816 VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext); 7817 7818 glBindTexture(GL_TEXTURE_2D, pSurface->oglId.texture); 7819 VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext); 7820 7821 /* Set row length and alignment of the output data. */ 7822 VMSVGAPACKPARAMS SavedParams; 7823 vmsvga3dOglSetPackParams(pState, pContext, pSurface, &SavedParams); 7824 7825 glGetTexImage(GL_TEXTURE_2D, 7826 i, 7827 pSurface->formatGL, 7828 pSurface->typeGL, 7829 pbDst); 7830 VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext); 7831 7832 vmsvga3dOglRestorePackParams(pState, pContext, pSurface, &SavedParams); 7833 7834 /* Restore the old active texture. */ 7835 glBindTexture(GL_TEXTURE_2D, activeTexture); 7836 VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext); 7837 break; 7838 } 7839 7840 case VMSVGA3D_OGLRESTYPE_BUFFER: 7841 { 7842 pState->ext.glBindBuffer(GL_ARRAY_BUFFER, pSurface->oglId.buffer); 7843 VMSVGA3D_CHECK_LAST_ERROR(pState, pContext); 7844 7845 void *pvSrc = pState->ext.glMapBuffer(GL_ARRAY_BUFFER, GL_READ_ONLY); 7846 VMSVGA3D_CHECK_LAST_ERROR(pState, pContext); 7847 if (RT_VALID_PTR(pvSrc)) 7848 memcpy(pbDst, pvSrc, pMipmapLevel->cbSurface); 7849 else 7850 AssertPtr(pvSrc); 7851 7852 pState->ext.glUnmapBuffer(GL_ARRAY_BUFFER); 7853 VMSVGA3D_CHECK_LAST_ERROR(pState, pContext); 7854 7855 pState->ext.glBindBuffer(GL_ARRAY_BUFFER, 0); 7856 VMSVGA3D_CHECK_LAST_ERROR(pState, pContext); 7857 break; 7858 } 7859 7860 default: 7861 AssertMsgFailed(("%#x\n", fSwitchFlags)); 7862 } 7863 } 7864 /* else: There is no data in hardware yet, so whatever we got is already current. */ 7865 } 7866 } 7867 } 7868 7869 return VINF_SUCCESS; 7870 } 7871 7872 static DECLCALLBACK(int) vmsvga3dBackQueryInterface(PVGASTATECC pThisCC, char const *pszInterfaceName, void *pvInterfaceFuncs, size_t cbInterfaceFuncs) 7737 7873 { 7738 7874 RT_NOREF(pThisCC); … … 7761 7897 p->pfnDestroyScreen = vmsvga3dBackDestroyScreen; 7762 7898 p->pfnSurfaceBlitToScreen = vmsvga3dBackSurfaceBlitToScreen; 7899 p->pfnSurfaceUpdateHeapBuffers = vmsvga3dBackSurfaceUpdateHeapBuffers; 7763 7900 } 7764 7901 } … … 7813 7950 return rc; 7814 7951 } 7952 7953 7954 extern VMSVGA3DBACKENDDESC const g_BackendLegacy = 7955 { 7956 "LEGACY", 7957 vmsvga3dBackQueryInterface 7958 }; -
trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-savedstate.cpp
r89121 r89163 152 152 { 153 153 uint32_t id; 154 #ifdef VMSVGA3D_OPENGL155 uint32_t idWeakContextAssociation;156 #else157 154 uint32_t idAssociatedContext; 158 #endif159 155 uint32_t surfaceFlags; 160 156 SVGA3dSurfaceFormat format; … … 174 170 { 175 171 SSMFIELD_ENTRY(struct VMSVGA3DSURFACEPreMipLevels, id), 176 #ifdef VMSVGA3D_OPENGL177 SSMFIELD_ENTRY(struct VMSVGA3DSURFACEPreMipLevels, idWeakContextAssociation),178 #else179 172 SSMFIELD_ENTRY(struct VMSVGA3DSURFACEPreMipLevels, idAssociatedContext), 180 #endif181 173 SSMFIELD_ENTRY(struct VMSVGA3DSURFACEPreMipLevels, surfaceFlags), 182 174 SSMFIELD_ENTRY(struct VMSVGA3DSURFACEPreMipLevels, format), … … 202 194 { 203 195 pSurface->id = surfacePreMipLevels.id; 204 #ifdef VMSVGA3D_OPENGL205 pSurface->idWeakContextAssociation = surfacePreMipLevels.idWeakContextAssociation;206 #else207 196 pSurface->idAssociatedContext = surfacePreMipLevels.idAssociatedContext; 208 #endif209 197 pSurface->surfaceFlags = surfacePreMipLevels.surfaceFlags; 210 198 pSurface->format = surfacePreMipLevels.format; … … 803 791 } 804 792 } 805 else 793 else if (vmsvga3dIsLegacyBackend(pThisCC)) 806 794 { 807 795 #ifdef VMSVGA3D_DIRECT3D … … 956 944 957 945 RTMemFree(pData); 958 #elif defined(VMSVGA3D_D3D11) 959 /** @todo */ 946 960 947 #elif defined(VMSVGA3D_OPENGL) 961 948 void *pData = NULL; … … 1051 1038 #endif 1052 1039 } 1040 else 1041 { 1042 /** @todo DX backend. */ 1043 Assert(!vmsvga3dIsLegacyBackend(pThisCC)); 1044 1045 /* No data follows */ 1046 rc = pHlp->pfnSSMPutBool(pSSM, false); 1047 AssertRCReturn(rc, rc); 1048 } 1053 1049 } 1054 1050 } -
trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-win-d3d9.cpp
r82968 r89163 31 31 D3D9TextureType_Emulated 32 32 } D3D9TextureType; 33 34 DECLINLINE(D3DCUBEMAP_FACES) vmsvga3dCubemapFaceFromIndex(uint32_t iFace) 35 { 36 D3DCUBEMAP_FACES Face; 37 switch (iFace) 38 { 39 case 0: Face = D3DCUBEMAP_FACE_POSITIVE_X; break; 40 case 1: Face = D3DCUBEMAP_FACE_NEGATIVE_X; break; 41 case 2: Face = D3DCUBEMAP_FACE_POSITIVE_Y; break; 42 case 3: Face = D3DCUBEMAP_FACE_NEGATIVE_Y; break; 43 case 4: Face = D3DCUBEMAP_FACE_POSITIVE_Z; break; 44 default: 45 case 5: Face = D3DCUBEMAP_FACE_NEGATIVE_Z; break; 46 } 47 return Face; 48 } 33 49 34 50 IDirect3DTexture9 *D3D9GetTexture(PVMSVGA3DSURFACE pSurface, -
trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-win-dx.cpp
r89123 r89163 188 188 189 189 static DECLCALLBACK(void) vmsvga3dBackSurfaceDestroy(PVGASTATECC pThisCC, PVMSVGA3DSURFACE pSurface); 190 191 192 DECLINLINE(D3D11_TEXTURECUBE_FACE) vmsvga3dCubemapFaceFromIndex(uint32_t iFace) 193 { 194 D3D11_TEXTURECUBE_FACE Face; 195 switch (iFace) 196 { 197 case 0: Face = D3D11_TEXTURECUBE_FACE_POSITIVE_X; break; 198 case 1: Face = D3D11_TEXTURECUBE_FACE_NEGATIVE_X; break; 199 case 2: Face = D3D11_TEXTURECUBE_FACE_POSITIVE_Y; break; 200 case 3: Face = D3D11_TEXTURECUBE_FACE_NEGATIVE_Y; break; 201 case 4: Face = D3D11_TEXTURECUBE_FACE_POSITIVE_Z; break; 202 default: 203 case 5: Face = D3D11_TEXTURECUBE_FACE_NEGATIVE_Z; break; 204 } 205 return Face; 206 } 190 207 191 208 … … 3096 3113 } 3097 3114 3115 3116 static DECLCALLBACK(int) vmsvga3dBackSurfaceUpdateHeapBuffers(PVGASTATECC pThisCC, PVMSVGA3DSURFACE pSurface) 3117 { 3118 /** @todo */ 3119 RT_NOREF(pThisCC, pSurface); 3120 return VERR_NOT_IMPLEMENTED; 3121 } 3122 3123 3098 3124 /** 3099 3125 * Create a new 3d context … … 5781 5807 5782 5808 5783 int vmsvga3dQueryInterface(PVGASTATECC pThisCC, char const *pszInterfaceName, void *pvInterfaceFuncs, size_t cbInterfaceFuncs)5809 static DECLCALLBACK(int) vmsvga3dBackQueryInterface(PVGASTATECC pThisCC, char const *pszInterfaceName, void *pvInterfaceFuncs, size_t cbInterfaceFuncs) 5784 5810 { 5785 5811 RT_NOREF(pThisCC); … … 5978 6004 p->pfnDestroyScreen = vmsvga3dBackDestroyScreen; 5979 6005 p->pfnSurfaceBlitToScreen = vmsvga3dBackSurfaceBlitToScreen; 6006 p->pfnSurfaceUpdateHeapBuffers = vmsvga3dBackSurfaceUpdateHeapBuffers; 5980 6007 } 5981 6008 } … … 5990 6017 return rc; 5991 6018 } 6019 6020 6021 extern VMSVGA3DBACKENDDESC const g_BackendDX = 6022 { 6023 "DX", 6024 vmsvga3dBackQueryInterface 6025 }; -
trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-win.cpp
r89123 r89163 170 170 static DECLCALLBACK(int) vmsvga3dBackCreateTexture(PVGASTATECC pThisCC, PVMSVGA3DCONTEXT pContext, uint32_t idAssociatedContext, PVMSVGA3DSURFACE pSurface); 171 171 172 173 DECLINLINE(D3DCUBEMAP_FACES) vmsvga3dCubemapFaceFromIndex(uint32_t iFace) 174 { 175 D3DCUBEMAP_FACES Face; 176 switch (iFace) 177 { 178 case 0: Face = D3DCUBEMAP_FACE_POSITIVE_X; break; 179 case 1: Face = D3DCUBEMAP_FACE_NEGATIVE_X; break; 180 case 2: Face = D3DCUBEMAP_FACE_POSITIVE_Y; break; 181 case 3: Face = D3DCUBEMAP_FACE_NEGATIVE_Y; break; 182 case 4: Face = D3DCUBEMAP_FACE_POSITIVE_Z; break; 183 default: 184 case 5: Face = D3DCUBEMAP_FACE_NEGATIVE_Z; break; 185 } 186 return Face; 187 } 172 188 173 189 static DECLCALLBACK(int) vmsvga3dBackInit(PPDMDEVINS pDevIns, PVGASTATE pThis, PVGASTATECC pThisCC) … … 6184 6200 } 6185 6201 6186 int vmsvga3dQueryInterface(PVGASTATECC pThisCC, char const *pszInterfaceName, void *pvInterfaceFuncs, size_t cbInterfaceFuncs) 6202 /** 6203 * Worker for vmsvga3dUpdateHeapBuffersForSurfaces. 6204 * 6205 * This will allocate heap buffers if necessary, thus increasing the memory 6206 * usage of the process. 6207 * 6208 * @todo Would be interesting to share this code with the saved state code. 6209 * 6210 * @returns VBox status code. 6211 * @param pThisCC The VGA/VMSVGA context. 6212 * @param pSurface The surface to refresh the heap buffers for. 6213 */ 6214 static DECLCALLBACK(int) vmsvga3dBackSurfaceUpdateHeapBuffers(PVGASTATECC pThisCC, PVMSVGA3DSURFACE pSurface) 6215 { 6216 PVMSVGA3DSTATE pState = pThisCC->svga.p3dState; 6217 AssertReturn(pState, VERR_INVALID_STATE); 6218 6219 /* 6220 * Currently we've got trouble retreving bit for DEPTHSTENCIL 6221 * surfaces both for OpenGL and D3D, so skip these here (don't 6222 * wast memory on them). 6223 */ 6224 uint32_t const fSwitchFlags = pSurface->surfaceFlags & VMSVGA3D_SURFACE_HINT_SWITCH_MASK; 6225 if ( fSwitchFlags != SVGA3D_SURFACE_HINT_DEPTHSTENCIL 6226 && fSwitchFlags != (SVGA3D_SURFACE_HINT_DEPTHSTENCIL | SVGA3D_SURFACE_HINT_TEXTURE)) 6227 { 6228 6229 /* 6230 * Work thru each mipmap level for each face. 6231 */ 6232 for (uint32_t iFace = 0; iFace < pSurface->cFaces; iFace++) 6233 { 6234 PVMSVGA3DMIPMAPLEVEL pMipmapLevel = &pSurface->paMipmapLevels[iFace * pSurface->cLevels]; 6235 for (uint32_t i = 0; i < pSurface->cLevels; i++, pMipmapLevel++) 6236 { 6237 if (VMSVGA3DSURFACE_HAS_HW_SURFACE(pSurface)) 6238 { 6239 Assert(pMipmapLevel->cbSurface); 6240 Assert(pMipmapLevel->cbSurface == pMipmapLevel->cbSurfacePlane * pMipmapLevel->mipmapSize.depth); 6241 6242 /* 6243 * Make sure we've got surface memory buffer. 6244 */ 6245 uint8_t *pbDst = (uint8_t *)pMipmapLevel->pSurfaceData; 6246 if (!pbDst) 6247 { 6248 pMipmapLevel->pSurfaceData = pbDst = (uint8_t *)RTMemAllocZ(pMipmapLevel->cbSurface); 6249 AssertReturn(pbDst, VERR_NO_MEMORY); 6250 } 6251 6252 /* 6253 * D3D specifics. 6254 */ 6255 Assert(pSurface->enmD3DResType != VMSVGA3D_D3DRESTYPE_NONE); 6256 6257 HRESULT hr; 6258 switch (pSurface->enmD3DResType) 6259 { 6260 case VMSVGA3D_D3DRESTYPE_VOLUME_TEXTURE: 6261 AssertFailed(); /// @todo 6262 break; 6263 6264 case VMSVGA3D_D3DRESTYPE_SURFACE: 6265 case VMSVGA3D_D3DRESTYPE_TEXTURE: 6266 case VMSVGA3D_D3DRESTYPE_CUBE_TEXTURE: 6267 { 6268 /* 6269 * Lock the buffer and make it accessible to memcpy. 6270 */ 6271 D3DLOCKED_RECT LockedRect; 6272 if (pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_CUBE_TEXTURE) 6273 { 6274 hr = pSurface->u.pCubeTexture->LockRect(vmsvga3dCubemapFaceFromIndex(iFace), 6275 i, /* texture level */ 6276 &LockedRect, 6277 NULL, 6278 D3DLOCK_READONLY); 6279 } 6280 else if (pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_TEXTURE) 6281 { 6282 if (pSurface->bounce.pTexture) 6283 { 6284 if ( !pSurface->fDirty 6285 && RT_BOOL(fSwitchFlags & SVGA3D_SURFACE_HINT_RENDERTARGET)) 6286 { 6287 /** @todo stricter checks for associated context */ 6288 uint32_t cid = pSurface->idAssociatedContext; 6289 PVMSVGA3DCONTEXT pContext; 6290 int rc = vmsvga3dContextFromCid(pState, cid, &pContext); 6291 AssertRCReturn(rc, rc); 6292 6293 IDirect3DSurface9 *pDst = NULL; 6294 hr = pSurface->bounce.pTexture->GetSurfaceLevel(i, &pDst); 6295 AssertMsgReturn(hr == D3D_OK, ("GetSurfaceLevel failed with %#x\n", hr), VERR_INTERNAL_ERROR); 6296 6297 IDirect3DSurface9 *pSrc = NULL; 6298 hr = pSurface->u.pTexture->GetSurfaceLevel(i, &pSrc); 6299 AssertMsgReturn(hr == D3D_OK, ("GetSurfaceLevel failed with %#x\n", hr), VERR_INTERNAL_ERROR); 6300 6301 hr = pContext->pDevice->GetRenderTargetData(pSrc, pDst); 6302 AssertMsgReturn(hr == D3D_OK, ("GetRenderTargetData failed with %#x\n", hr), VERR_INTERNAL_ERROR); 6303 6304 pSrc->Release(); 6305 pDst->Release(); 6306 } 6307 6308 hr = pSurface->bounce.pTexture->LockRect(i, /* texture level */ 6309 &LockedRect, 6310 NULL, 6311 D3DLOCK_READONLY); 6312 } 6313 else 6314 hr = pSurface->u.pTexture->LockRect(i, /* texture level */ 6315 &LockedRect, 6316 NULL, 6317 D3DLOCK_READONLY); 6318 } 6319 else 6320 hr = pSurface->u.pSurface->LockRect(&LockedRect, 6321 NULL, 6322 D3DLOCK_READONLY); 6323 AssertMsgReturn(hr == D3D_OK, ("LockRect failed with %x\n", hr), VERR_INTERNAL_ERROR); 6324 6325 /* 6326 * Copy the data. Take care in case the pitch differs. 6327 */ 6328 if (pMipmapLevel->cbSurfacePitch == (uint32_t)LockedRect.Pitch) 6329 memcpy(pbDst, LockedRect.pBits, pMipmapLevel->cbSurface); 6330 else 6331 for (uint32_t j = 0; j < pMipmapLevel->cBlocksY; j++) 6332 memcpy(pbDst + j * pMipmapLevel->cbSurfacePitch, 6333 (uint8_t *)LockedRect.pBits + j * LockedRect.Pitch, 6334 pMipmapLevel->cbSurfacePitch); 6335 6336 /* 6337 * Release the buffer. 6338 */ 6339 if (fSwitchFlags & SVGA3D_SURFACE_HINT_TEXTURE) 6340 { 6341 if (pSurface->bounce.pTexture) 6342 { 6343 hr = pSurface->bounce.pTexture->UnlockRect(i); 6344 AssertMsgReturn(hr == D3D_OK, ("UnlockRect failed with %#x\n", hr), VERR_INTERNAL_ERROR); 6345 } 6346 else 6347 hr = pSurface->u.pTexture->UnlockRect(i); 6348 } 6349 else 6350 hr = pSurface->u.pSurface->UnlockRect(); 6351 AssertMsgReturn(hr == D3D_OK, ("UnlockRect failed with %#x\n", hr), VERR_INTERNAL_ERROR); 6352 break; 6353 } 6354 6355 case VMSVGA3D_D3DRESTYPE_VERTEX_BUFFER: 6356 case VMSVGA3D_D3DRESTYPE_INDEX_BUFFER: 6357 { 6358 /* Current type of the buffer. */ 6359 const bool fVertex = (pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_VERTEX_BUFFER); 6360 6361 void *pvD3DData = NULL; 6362 if (fVertex) 6363 hr = pSurface->u.pVertexBuffer->Lock(0, 0, &pvD3DData, D3DLOCK_READONLY); 6364 else 6365 hr = pSurface->u.pIndexBuffer->Lock(0, 0, &pvD3DData, D3DLOCK_READONLY); 6366 AssertMsgReturn(hr == D3D_OK, ("Lock %s failed with %x\n", fVertex ? "vertex" : "index", hr), VERR_INTERNAL_ERROR); 6367 6368 memcpy(pbDst, pvD3DData, pMipmapLevel->cbSurface); 6369 6370 if (fVertex) 6371 hr = pSurface->u.pVertexBuffer->Unlock(); 6372 else 6373 hr = pSurface->u.pIndexBuffer->Unlock(); 6374 AssertMsg(hr == D3D_OK, ("Unlock %s failed with %x\n", fVertex ? "vertex" : "index", hr)); 6375 break; 6376 } 6377 6378 default: 6379 AssertMsgFailed(("flags %#x, type %d\n", fSwitchFlags, pSurface->enmD3DResType)); 6380 } 6381 6382 } 6383 /* else: There is no data in hardware yet, so whatever we got is already current. */ 6384 } 6385 } 6386 } 6387 6388 return VINF_SUCCESS; 6389 } 6390 6391 6392 static DECLCALLBACK(int) vmsvga3dBackQueryInterface(PVGASTATECC pThisCC, char const *pszInterfaceName, void *pvInterfaceFuncs, size_t cbInterfaceFuncs) 6187 6393 { 6188 6394 RT_NOREF(pThisCC); … … 6211 6417 p->pfnDestroyScreen = vmsvga3dBackDestroyScreen; 6212 6418 p->pfnSurfaceBlitToScreen = vmsvga3dBackSurfaceBlitToScreen; 6419 p->pfnSurfaceUpdateHeapBuffers = vmsvga3dBackSurfaceUpdateHeapBuffers; 6213 6420 } 6214 6421 } … … 6263 6470 return rc; 6264 6471 } 6472 6473 6474 extern VMSVGA3DBACKENDDESC const g_BackendLegacy = 6475 { 6476 "LEGACY", 6477 vmsvga3dBackQueryInterface 6478 }; -
trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d.cpp
r89121 r89163 94 94 95 95 RT_ZERO(*pSurface); 96 pSurface->id = SVGA3D_INVALID_ID; /* Keep this value until the surface init completes */ 97 #ifdef VMSVGA3D_OPENGL 98 pSurface->idWeakContextAssociation = SVGA3D_INVALID_ID; 99 pSurface->oglId.buffer = OPENGL_INVALID_ID; 100 #elif defined(VMSVGA3D_D3D11) 96 // pSurface->pBackendSurface = NULL; 97 pSurface->id = SVGA3D_INVALID_ID; /* Keep this value until the surface init completes */ 101 98 pSurface->idAssociatedContext = SVGA3D_INVALID_ID; 102 // pSurface->pBackendSurface = NULL;103 #else /* VMSVGA3D_DIRECT3D */104 pSurface->idAssociatedContext = SVGA3D_INVALID_ID;105 pSurface->hSharedObject = NULL;106 pSurface->pSharedObjectTree = NULL;107 #endif108 99 109 100 /** @todo This 'switch' and the surfaceFlags tweaks should not be necessary. … … 278 269 AssertLogRelRCReturnStmt(rc, RTMemFree(pSurface->paMipmapLevels), rc); 279 270 271 if (vmsvga3dIsLegacyBackend(pThisCC)) 272 { 280 273 #ifdef VMSVGA3D_DIRECT3D 281 /* Translate the format and usage flags to D3D.*/282 pSurface->d3dfmtRequested = vmsvga3dSurfaceFormat2D3D(format);283 pSurface->formatD3D = D3D9GetActualFormat(pState, pSurface->d3dfmtRequested);284 pSurface->multiSampleTypeD3D= vmsvga3dMultipeSampleCount2D3D(multisampleCount);285 pSurface->fUsageD3D = 0;286 if (surfaceFlags & SVGA3D_SURFACE_HINT_DYNAMIC)287 pSurface->fUsageD3D |= D3DUSAGE_DYNAMIC;288 if (surfaceFlags & SVGA3D_SURFACE_HINT_RENDERTARGET)289 pSurface->fUsageD3D |= D3DUSAGE_RENDERTARGET;290 if (surfaceFlags & SVGA3D_SURFACE_HINT_DEPTHSTENCIL)291 pSurface->fUsageD3D |= D3DUSAGE_DEPTHSTENCIL;292 if (surfaceFlags & SVGA3D_SURFACE_HINT_WRITEONLY)293 pSurface->fUsageD3D |= D3DUSAGE_WRITEONLY;294 if (surfaceFlags & SVGA3D_SURFACE_AUTOGENMIPMAPS)295 pSurface->fUsageD3D |= D3DUSAGE_AUTOGENMIPMAP;296 pSurface->enmD3DResType = VMSVGA3D_D3DRESTYPE_NONE;297 /* pSurface->u.pSurface = NULL; */298 /* pSurface->bounce.pTexture = NULL; */299 /* pSurface->emulated.pTexture = NULL; */300 #elif defined(VMSVGA3D_D3D11) 301 /* Nothing, because all backend specific data reside in pSurface->pBackendSurface.*/274 /* pSurface->hSharedObject = NULL; */ 275 /* pSurface->pSharedObjectTree = NULL; */ 276 /* Translate the format and usage flags to D3D. */ 277 pSurface->d3dfmtRequested = vmsvga3dSurfaceFormat2D3D(format); 278 pSurface->formatD3D = D3D9GetActualFormat(pState, pSurface->d3dfmtRequested); 279 pSurface->multiSampleTypeD3D= vmsvga3dMultipeSampleCount2D3D(multisampleCount); 280 pSurface->fUsageD3D = 0; 281 if (surfaceFlags & SVGA3D_SURFACE_HINT_DYNAMIC) 282 pSurface->fUsageD3D |= D3DUSAGE_DYNAMIC; 283 if (surfaceFlags & SVGA3D_SURFACE_HINT_RENDERTARGET) 284 pSurface->fUsageD3D |= D3DUSAGE_RENDERTARGET; 285 if (surfaceFlags & SVGA3D_SURFACE_HINT_DEPTHSTENCIL) 286 pSurface->fUsageD3D |= D3DUSAGE_DEPTHSTENCIL; 287 if (surfaceFlags & SVGA3D_SURFACE_HINT_WRITEONLY) 288 pSurface->fUsageD3D |= D3DUSAGE_WRITEONLY; 289 if (surfaceFlags & SVGA3D_SURFACE_AUTOGENMIPMAPS) 290 pSurface->fUsageD3D |= D3DUSAGE_AUTOGENMIPMAP; 291 pSurface->enmD3DResType = VMSVGA3D_D3DRESTYPE_NONE; 292 /* pSurface->u.pSurface = NULL; */ 293 /* pSurface->bounce.pTexture = NULL; */ 294 /* pSurface->emulated.pTexture = NULL; */ 302 295 #else 303 /* pSurface->fEmulated = false; */ 304 /* pSurface->idEmulated = OPENGL_INVALID_ID; */ 305 vmsvga3dSurfaceFormat2OGL(pSurface, format); 296 /* pSurface->oglId.buffer = OPENGL_INVALID_ID; */ 297 /* pSurface->fEmulated = false; */ 298 /* pSurface->idEmulated = OPENGL_INVALID_ID; */ 299 vmsvga3dSurfaceFormat2OGL(pSurface, format); 306 300 #endif 301 } 307 302 308 303 #ifdef LOG_ENABLED … … 559 554 AssertReturn(pMipLevel->pSurfaceData, VERR_INTERNAL_ERROR); 560 555 } 561 else 556 else if (vmsvga3dIsLegacyBackend(pThisCC)) 562 557 { 563 558 #ifdef VMSVGA3D_DIRECT3D 564 559 /* Flush the drawing pipeline for this surface as it could be used in a shared context. */ 565 560 vmsvga3dSurfaceFlush(pSurface); 566 #elif defined(VMSVGA3D_D3D11)567 /** @todo */568 561 #else /* VMSVGA3D_OPENGL */ 569 562 pContext = &pState->SharedCtx; … … 1166 1159 } 1167 1160 1161 /** 1162 * Updates the heap buffers for all surfaces or one specific one. 1163 * 1164 * @param pThisCC The VGA/VMSVGA state for ring-3. 1165 * @param sid The surface ID, UINT32_MAX if all. 1166 * @thread VMSVGAFIFO 1167 */ 1168 void vmsvga3dUpdateHeapBuffersForSurfaces(PVGASTATECC pThisCC, uint32_t sid) 1169 { 1170 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State; 1171 AssertReturnVoid(pSvgaR3State->pFuncs3D); 1172 1173 PVMSVGA3DSTATE pState = pThisCC->svga.p3dState; 1174 AssertReturnVoid(pState); 1175 1176 if (sid == UINT32_MAX) 1177 { 1178 uint32_t cSurfaces = pState->cSurfaces; 1179 for (sid = 0; sid < cSurfaces; sid++) 1180 { 1181 PVMSVGA3DSURFACE pSurface = pState->papSurfaces[sid]; 1182 if (pSurface && pSurface->id == sid) 1183 pSvgaR3State->pFuncs3D->pfnSurfaceUpdateHeapBuffers(pThisCC, pSurface); 1184 } 1185 } 1186 else if (sid < pState->cSurfaces) 1187 { 1188 PVMSVGA3DSURFACE pSurface = pState->papSurfaces[sid]; 1189 if (pSurface && pSurface->id == sid) 1190 pSvgaR3State->pFuncs3D->pfnSurfaceUpdateHeapBuffers(pThisCC, pSurface); 1191 } 1192 } 1193 1168 1194 1169 1195 /* … … 1313 1339 } 1314 1340 1341 /* 1342 * Whether a legacy 3D backend is used. 1343 * The new DX context can be built together with the legacy D3D9 or OpenGL backend. 1344 * The actual backend is selected at the VM startup. 1345 */ 1346 bool vmsvga3dIsLegacyBackend(PVGASTATECC pThisCC) 1347 { 1348 PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State; 1349 return pSvgaR3State->pFuncsDX == NULL; 1350 } 1351 -
trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d.h
r89121 r89163 264 264 * Backend interfaces. 265 265 */ 266 bool vmsvga3dIsLegacyBackend(PVGASTATECC pThisCC); 267 266 268 typedef struct VMSVGA3DSURFACE *PVMSVGA3DSURFACE; 267 269 typedef struct VMSVGA3DMIPMAPLEVEL *PVMSVGA3DMIPMAPLEVEL; … … 296 298 SVGASignedRect destRect, SVGA3dSurfaceImageId srcImage, 297 299 SVGASignedRect srcRect, uint32_t cRects, SVGASignedRect *paRects)); 300 /* Various helpers. */ 301 DECLCALLBACKMEMBER(int, pfnSurfaceUpdateHeapBuffers, (PVGASTATECC pThisCC, PVMSVGA3DSURFACE pSurface)); 298 302 } VMSVGA3DBACKENDFUNCS3D; 299 303 … … 472 476 } VMSVGA3DBACKENDFUNCSDX; 473 477 474 int vmsvga3dQueryInterface(PVGASTATECC pThisCC, char const *pszInterfaceName, void *pvInterfaceFuncs, size_t cbInterfaceFuncs); 478 typedef struct VMSVGA3DBACKENDDESC 479 { 480 char const *pszName; 481 DECLCALLBACKMEMBER(int, pfnQueryInterface, (PVGASTATECC pThisCC, char const *pszInterfaceName, void *pvInterfaceFuncs, size_t cbInterfaceFuncs)); 482 } VMSVGA3DBACKENDDESC; 475 483 476 484 #ifdef VMSVGA3D_DX -
trunk/src/VBox/Devices/Makefile.kmk
r88926 r89163 330 330 Graphics/DevVGA-SVGA3d-dx.cpp \ 331 331 Graphics/DevVGA-SVGA3d-dx-shader.cpp 332 if "$(KBUILD_TARGET)" == "win" 333 VBoxDD_SOURCES += \ 334 Graphics/DevVGA-SVGA3d-win-dx.cpp 335 endif 332 336 endif 333 337 VBoxDD_SOURCES += \ 334 338 Graphics/svgadump/svga_dump.c 335 339 if "$(KBUILD_TARGET)" == "win" && !defined(VBOX_WITH_VMSVGA3D_USE_OPENGL) 336 ifdef VBOX_WITH_VMSVGA3D_DX337 VBoxDD_DEFS += VMSVGA3D_D3D11338 VBoxDD_SOURCES += \339 Graphics/DevVGA-SVGA3d-win-dx.cpp340 else341 340 VBoxDD_DEFS += VMSVGA3D_DIRECT3D 342 341 VBoxDD_SOURCES += \ … … 345 344 VBoxDD_LIBS.win += d3d9.lib $(PATH_TOOL_$(VBOX_VCC_TOOL)_LIB)/delayimp.lib 346 345 VBoxDD_LDFLAGS.win += /DELAYLOAD:d3d9.dll 347 endif348 346 else 349 347 VBoxDD_DEFS += VMSVGA3D_OPENGL
Note:
See TracChangeset
for help on using the changeset viewer.