VirtualBox

Changeset 89163 in vbox


Ignore:
Timestamp:
May 19, 2021 1:12:44 PM (4 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
144504
Message:

Devices/Graphics: Build new and old 3D backend. bugref:9830

Location:
trunk/src/VBox/Devices
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Graphics/DevVGA-SVGA.cpp

    r89124 r89163  
    58235823} VMSVGA3DINTERFACE;
    58245824
     5825extern VMSVGA3DBACKENDDESC const g_BackendLegacy;
     5826#ifdef VMSVGA3D_DX
     5827extern VMSVGA3DBACKENDDESC const g_BackendDX;
     5828#endif
     5829
    58255830/**
    58265831 * Initializes the optional host 3D backend interfaces.
     
    58295834 * @param   pThisCC   The VGA/VMSVGA state for ring-3.
    58305835 */
    5831 static int vmsvgaR3Init3dInterfaces(PVGASTATECC pThisCC)
    5832 {
     5836static int vmsvgaR3Init3dInterfaces(PVGASTATE pThis, PVGASTATECC pThisCC)
     5837{
     5838#ifndef VMSVGA3D_DX
     5839    RT_NOREF(pThis);
     5840#endif
     5841
    58335842    PVMSVGAR3STATE pSVGAState = pThisCC->svga.pSvgaR3State;
    58345843
     
    58445853#undef ENTRY_3D_INTERFACE
    58455854
     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
    58465863    int rc = VINF_SUCCESS;
    58475864    for (uint32_t i = 0; i < RT_ELEMENTS(a3dInterface); ++i)
     
    58495866        VMSVGA3DINTERFACE *p = &a3dInterface[i];
    58505867
    5851         int rc2 = vmsvga3dQueryInterface(pThisCC, p->pcszName, NULL, p->cbFuncs);
     5868        int rc2 = pBackend->pfnQueryInterface(pThisCC, p->pcszName, NULL, p->cbFuncs);
    58525869        if (RT_SUCCESS(rc2))
    58535870        {
     
    58555872            AssertBreakStmt(*p->ppvFuncs, rc = VERR_NO_MEMORY);
    58565873
    5857             vmsvga3dQueryInterface(pThisCC, p->pcszName, *p->ppvFuncs, p->cbFuncs);
     5874            pBackend->pfnQueryInterface(pThisCC, p->pcszName, *p->ppvFuncs, p->cbFuncs);
    58585875        }
    58595876    }
     
    61896206    {
    61906207        /* Load a 3D backend. */
    6191         rc = vmsvgaR3Init3dInterfaces(pThisCC);
     6208        rc = vmsvgaR3Init3dInterfaces(pThis, pThisCC);
    61926209        if (RT_SUCCESS(rc))
    61936210            rc = pSVGAState->pFuncs3D->pfnInit(pDevIns, pThis, pThisCC);
  • trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-info.cpp

    r88787 r89163  
    354354
    355355
    356 /**
    357  * Worker for vmsvga3dUpdateHeapBuffersForSurfaces.
    358  *
    359  * This will allocate heap buffers if necessary, thus increasing the memory
    360  * 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 DEPTHSTENCIL
    372      * surfaces both for OpenGL and D3D, so skip these here (don't
    373      * wast memory on them).
    374      */
    375     uint32_t const fSwitchFlags = pSurface->surfaceFlags & VMSVGA3D_SURFACE_HINT_SWITCH_MASK;
    376     if (   fSwitchFlags != SVGA3D_SURFACE_HINT_DEPTHSTENCIL
    377         && fSwitchFlags != (SVGA3D_SURFACE_HINT_DEPTHSTENCIL | SVGA3D_SURFACE_HINT_TEXTURE))
    378     {
    379 
    380 #ifdef VMSVGA3D_OPENGL
    381         /*
    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 #endif
    387 
    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_DIRECT3D
    412                     /*
    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(); /// @todo
    422                             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->fDirty
    445                                         && 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                                 else
    474                                     hr = pSurface->u.pTexture->LockRect(i, /* texture level */
    475                                                                         &LockedRect,
    476                                                                         NULL,
    477                                                                         D3DLOCK_READONLY);
    478                             }
    479                             else
    480                                 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                             else
    491                                 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                                 else
    507                                     hr = pSurface->u.pTexture->UnlockRect(i);
    508                             }
    509                             else
    510                                 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                             else
    525                                 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                             else
    533                                 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                             else
    586                                 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 #else
    603 # error "misconfigured"
    604 #endif
    605                 }
    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  VMSVGAFIFO
    621  */
    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 
    648356void vmsvga3dInfoU32Flags(PCDBGFINFOHLP pHlp, uint32_t fFlags, const char *pszPrefix, PCVMSVGAINFOFLAGS32 paFlags, uint32_t cFlags)
    649357{
     
    16241332# ifdef VMSVGA3D_DIRECT3D
    16251333    pHlp->pfnPrintf(pHlp, "pDevice:                 %p\n", pContext->pDevice);
    1626 # elif defined(VMSVGA3D_D3D11)
    1627     /** @todo */
    16281334# else
    16291335    pHlp->pfnPrintf(pHlp, "hdc:                     %p\n", pContext->hdc);
     
    20721778
    20731779    pHlp->pfnPrintf(pHlp, "*** VMSVGA 3d surface %#x (%d)%s ***\n", pSurface->id, pSurface->id, pSurface->fDirty ? " - dirty" : "");
    2074 #ifdef VMSVGA3D_OPENGL
    2075     pHlp->pfnPrintf(pHlp, "idWeakContextAssociation: %#x\n", pSurface->idWeakContextAssociation);
    2076 #else
    20771780    pHlp->pfnPrintf(pHlp, "idAssociatedContext:     %#x\n", pSurface->idAssociatedContext);
    2078 #endif
    20791781    pHlp->pfnPrintf(pHlp, "Format:                  %s\n",
    20801782                    vmsvgaFormatEnumValueEx(szTmp, sizeof(szTmp), NULL, (int)pSurface->format, false, &g_SVGA3dSurfaceFormat2String));
     
    21321834    pHlp->pfnPrintf(pHlp, "fStencilAsTexture:       %RTbool\n", pSurface->fStencilAsTexture);
    21331835
    2134 #elif defined(VMSVGA3D_D3D11)
    2135     /** @todo */
    21361836#elif defined(VMSVGA3D_OPENGL)
    21371837    /** @todo   */
  • trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-internal.h

    r89121 r89163  
    2929#endif
    3030#ifdef VMSVGA3D_OPENGL
    31 # if defined(VMSVGA3D_DIRECT3D) || defined(VMSVGA3D_D3D11)
     31# if defined(VMSVGA3D_DIRECT3D)
    3232#  error "Both VMSVGA3D_DIRECT3D and VMSVGA3D_OPENGL cannot be defined at the same time."
    3333# endif
    34 #elif !defined(VMSVGA3D_DIRECT3D) && !defined(VMSVGA3D_D3D11)
     34#elif !defined(VMSVGA3D_DIRECT3D)
    3535# error "Either VMSVGA3D_OPENGL or VMSVGA3D_DIRECT3D must be defined."
    3636#endif
     
    5151#  include <d3d9.h>
    5252#  include <iprt/avl.h>
    53 # elif defined(VMSVGA3D_D3D11)
    54 #  include <d3d11.h>
    5553# else
    5654#  include <GL/gl.h>
     
    552550    PVMSVGA3DBACKENDSURFACE pBackendSurface;
    553551
    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     */
    558558    uint32_t                idAssociatedContext;
    559 #endif
    560     SVGA3dSurface1Flags     surfaceFlags; /* @todo SVGA3dSurfaceAllFlags as an union. */
     559
     560    SVGA3dSurface1Flags     surfaceFlags; /** @todo SVGA3dSurfaceAllFlags as an union. */
    561561    SVGA3dSurfaceFormat     format;
    562562#ifdef VMSVGA3D_OPENGL
     
    645645{
    646646    SSMFIELD_ENTRY(                 VMSVGA3DSURFACE, id),
    647 # ifdef VMSVGA3D_OPENGL
    648     SSMFIELD_ENTRY(                 VMSVGA3DSURFACE, idWeakContextAssociation),
    649 # else
    650647    SSMFIELD_ENTRY(                 VMSVGA3DSURFACE, idAssociatedContext),
    651 # endif
    652648    SSMFIELD_ENTRY(                 VMSVGA3DSURFACE, surfaceFlags),
    653649    SSMFIELD_ENTRY(                 VMSVGA3DSURFACE, format),
     
    679675 */
    680676#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)
    684678#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)
    686680#endif
    687681
     
    696690   (   (a_pSurface)->enmD3DResType == VMSVGA3D_D3DRESTYPE_VERTEX_BUFFER \
    697691    || (a_pSurface)->enmD3DResType == VMSVGA3D_D3DRESTYPE_INDEX_BUFFER)
    698 #elif defined(VMSVGA3D_D3D11)
    699   /** @todo */
    700 # define VMSVGA3DSURFACE_NEEDS_DATA(a_pSurface) (false)
    701692#else
    702693# define VMSVGA3DSURFACE_NEEDS_DATA(a_pSurface) \
     
    717708        IDirect3DVertexShader9     *pVertexShader;
    718709        IDirect3DPixelShader9      *pPixelShader;
    719 #elif defined(VMSVGA3D_D3D11)
    720         /* Nothing */
    721710#else
    722711        void                       *pVertexShader;
     
    773762#ifdef VMSVGA3D_DIRECT3D
    774763    IDirect3DQuery9    *pQuery;
    775 #elif defined(VMSVGA3D_D3D11)
    776     /** @todo */
    777764#else /* VMSVGA3D_OPENGL */
    778765    GLuint              idQuery;
     
    790777#ifdef VMSVGA3D_DIRECT3D
    791778    SSMFIELD_ENTRY_IGN_HCPTR(       VMSVGA3DQUERY, pQuery),
    792 #elif defined(VMSVGA3D_D3D11)
    793     /** @todo */
    794779#else /* VMSVGA3D_OPENGL */
    795780    SSMFIELD_ENTRY_IGNORE(          VMSVGA3DQUERY, idQuery),
     
    803788#ifdef VMSVGA3D_DIRECT3D
    804789#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)
    808790#else
    809791#define VMSVGA3DQUERY_EXISTS(p) ((p)->idQuery && (p)->enmQueryState != VMSVGA3DQUERYSTATE_NULL)
     
    815797typedef struct VMSVGA3DCONTEXT
    816798{
     799    /** @todo Legacy contexts with DX backend. */
     800
    817801    uint32_t                id;
    818802#ifdef RT_OS_WINDOWS
     
    823807    IDirect3DDevice9Ex     *pDevice;
    824808#  endif
    825 # elif defined(VMSVGA3D_D3D11)
    826     /** @todo Legacy contexts with DX backend. */
    827809# else
    828810    /* Device context of the context window. */
     
    923905#  ifdef VMSVGA3D_DIRECT3D
    924906    SSMFIELD_ENTRY_IGN_HCPTR(       VMSVGA3DCONTEXT, pDevice),
    925 #  elif defined(VMSVGA3D_D3D11)
    926     /** @todo */
    927907#  else
    928908    SSMFIELD_ENTRY_IGNORE(          VMSVGA3DCONTEXT, hdc),
     
    10451025typedef struct VMSVGA3DSTATE
    10461026{
     1027    /** Backend specific data. */
     1028    PVMSVGA3DBACKEND        pBackend;
     1029
    10471030    /** The size of papContexts. */
    10481031    uint32_t                cContexts;
     
    10771060    bool                    fSupportedFormatYUY2 : 1;
    10781061    bool                    fSupportedFormatA8B8G8R8 : 1;
    1079 # elif defined(VMSVGA3D_D3D11)
    1080     PVMSVGA3DBACKEND        pBackend;
    10811062# endif
    10821063    /** Window Thread. */
     
    13881369}
    13891370
    1390 #ifdef VMSVGA3D_DIRECT3D
    1391 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 #endif
    1439 
    14401371void vmsvga3dInfoSurfaceToBitmap(PCDBGFINFOHLP pHlp, PVMSVGA3DSURFACE pSurface,
    14411372                                 const char *pszPath, const char *pszNamePrefix, const char *pszNameSuffix);
    14421373
    1443 #if defined(VMSVGA3D_DIRECT3D) || defined(VMSVGA3D_D3D11)
     1374#if defined(RT_OS_WINDOWS)
    14441375#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    } \
    14501381} while (0)
    14511382#endif
  • trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-ogl.cpp

    r89123 r89163  
    824824
    825825    return VINF_SUCCESS;
     826}
     827
     828
     829DECLINLINE(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;
    826843}
    827844
     
    53615378            pContext = pState->papContexts[cid];
    53625379            VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
    5363             pRenderTarget->idWeakContextAssociation = cid;
    53645380        }
    53655381
     
    77347750}
    77357751
    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 */
     7764static 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
     7872static DECLCALLBACK(int) vmsvga3dBackQueryInterface(PVGASTATECC pThisCC, char const *pszInterfaceName, void *pvInterfaceFuncs, size_t cbInterfaceFuncs)
    77377873{
    77387874    RT_NOREF(pThisCC);
     
    77617897                p->pfnDestroyScreen            = vmsvga3dBackDestroyScreen;
    77627898                p->pfnSurfaceBlitToScreen      = vmsvga3dBackSurfaceBlitToScreen;
     7899                p->pfnSurfaceUpdateHeapBuffers = vmsvga3dBackSurfaceUpdateHeapBuffers;
    77637900            }
    77647901        }
     
    78137950    return rc;
    78147951}
     7952
     7953
     7954extern VMSVGA3DBACKENDDESC const g_BackendLegacy =
     7955{
     7956    "LEGACY",
     7957    vmsvga3dBackQueryInterface
     7958};
  • trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-savedstate.cpp

    r89121 r89163  
    152152    {
    153153        uint32_t            id;
    154 #ifdef VMSVGA3D_OPENGL
    155         uint32_t            idWeakContextAssociation;
    156 #else
    157154        uint32_t            idAssociatedContext;
    158 #endif
    159155        uint32_t            surfaceFlags;
    160156        SVGA3dSurfaceFormat format;
     
    174170    {
    175171        SSMFIELD_ENTRY(struct VMSVGA3DSURFACEPreMipLevels, id),
    176 #ifdef VMSVGA3D_OPENGL
    177         SSMFIELD_ENTRY(struct VMSVGA3DSURFACEPreMipLevels, idWeakContextAssociation),
    178 #else
    179172        SSMFIELD_ENTRY(struct VMSVGA3DSURFACEPreMipLevels, idAssociatedContext),
    180 #endif
    181173        SSMFIELD_ENTRY(struct VMSVGA3DSURFACEPreMipLevels, surfaceFlags),
    182174        SSMFIELD_ENTRY(struct VMSVGA3DSURFACEPreMipLevels, format),
     
    202194    {
    203195        pSurface->id                       = surfacePreMipLevels.id;
    204 #ifdef VMSVGA3D_OPENGL
    205         pSurface->idWeakContextAssociation = surfacePreMipLevels.idWeakContextAssociation;
    206 #else
    207196        pSurface->idAssociatedContext      = surfacePreMipLevels.idAssociatedContext;
    208 #endif
    209197        pSurface->surfaceFlags             = surfacePreMipLevels.surfaceFlags;
    210198        pSurface->format                   = surfacePreMipLevels.format;
     
    803791                        }
    804792                    }
    805                     else
     793                    else if (vmsvga3dIsLegacyBackend(pThisCC))
    806794                    {
    807795#ifdef VMSVGA3D_DIRECT3D
     
    956944
    957945                        RTMemFree(pData);
    958 #elif defined(VMSVGA3D_D3D11)
    959                         /** @todo */
     946
    960947#elif defined(VMSVGA3D_OPENGL)
    961948                        void *pData = NULL;
     
    10511038#endif
    10521039                    }
     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                    }
    10531049                }
    10541050            }
  • trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-win-d3d9.cpp

    r82968 r89163  
    3131    D3D9TextureType_Emulated
    3232} D3D9TextureType;
     33
     34DECLINLINE(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}
    3349
    3450IDirect3DTexture9 *D3D9GetTexture(PVMSVGA3DSURFACE pSurface,
  • trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-win-dx.cpp

    r89123 r89163  
    188188
    189189static DECLCALLBACK(void) vmsvga3dBackSurfaceDestroy(PVGASTATECC pThisCC, PVMSVGA3DSURFACE pSurface);
     190
     191
     192DECLINLINE(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}
    190207
    191208
     
    30963113}
    30973114
     3115
     3116static DECLCALLBACK(int) vmsvga3dBackSurfaceUpdateHeapBuffers(PVGASTATECC pThisCC, PVMSVGA3DSURFACE pSurface)
     3117{
     3118    /** @todo */
     3119    RT_NOREF(pThisCC, pSurface);
     3120    return VERR_NOT_IMPLEMENTED;
     3121}
     3122
     3123
    30983124/**
    30993125 * Create a new 3d context
     
    57815807
    57825808
    5783 int vmsvga3dQueryInterface(PVGASTATECC pThisCC, char const *pszInterfaceName, void *pvInterfaceFuncs, size_t cbInterfaceFuncs)
     5809static DECLCALLBACK(int) vmsvga3dBackQueryInterface(PVGASTATECC pThisCC, char const *pszInterfaceName, void *pvInterfaceFuncs, size_t cbInterfaceFuncs)
    57845810{
    57855811    RT_NOREF(pThisCC);
     
    59786004                p->pfnDestroyScreen            = vmsvga3dBackDestroyScreen;
    59796005                p->pfnSurfaceBlitToScreen      = vmsvga3dBackSurfaceBlitToScreen;
     6006                p->pfnSurfaceUpdateHeapBuffers = vmsvga3dBackSurfaceUpdateHeapBuffers;
    59806007            }
    59816008        }
     
    59906017    return rc;
    59916018}
     6019
     6020
     6021extern VMSVGA3DBACKENDDESC const g_BackendDX =
     6022{
     6023    "DX",
     6024    vmsvga3dBackQueryInterface
     6025};
  • trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-win.cpp

    r89123 r89163  
    170170static DECLCALLBACK(int) vmsvga3dBackCreateTexture(PVGASTATECC pThisCC, PVMSVGA3DCONTEXT pContext, uint32_t idAssociatedContext, PVMSVGA3DSURFACE pSurface);
    171171
     172
     173DECLINLINE(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}
    172188
    173189static DECLCALLBACK(int) vmsvga3dBackInit(PPDMDEVINS pDevIns, PVGASTATE pThis, PVGASTATECC pThisCC)
     
    61846200}
    61856201
    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 */
     6214static 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
     6392static DECLCALLBACK(int) vmsvga3dBackQueryInterface(PVGASTATECC pThisCC, char const *pszInterfaceName, void *pvInterfaceFuncs, size_t cbInterfaceFuncs)
    61876393{
    61886394    RT_NOREF(pThisCC);
     
    62116417                p->pfnDestroyScreen            = vmsvga3dBackDestroyScreen;
    62126418                p->pfnSurfaceBlitToScreen      = vmsvga3dBackSurfaceBlitToScreen;
     6419                p->pfnSurfaceUpdateHeapBuffers = vmsvga3dBackSurfaceUpdateHeapBuffers;
    62136420            }
    62146421        }
     
    62636470    return rc;
    62646471}
     6472
     6473
     6474extern VMSVGA3DBACKENDDESC const g_BackendLegacy =
     6475{
     6476    "LEGACY",
     6477    vmsvga3dBackQueryInterface
     6478};
  • trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d.cpp

    r89121 r89163  
    9494
    9595    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 */
    10198    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 #endif
    10899
    109100    /** @todo This 'switch' and the surfaceFlags tweaks should not be necessary.
     
    278269    AssertLogRelRCReturnStmt(rc, RTMemFree(pSurface->paMipmapLevels), rc);
    279270
     271    if (vmsvga3dIsLegacyBackend(pThisCC))
     272    {
    280273#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; */
    302295#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);
    306300#endif
     301    }
    307302
    308303#ifdef LOG_ENABLED
     
    559554        AssertReturn(pMipLevel->pSurfaceData, VERR_INTERNAL_ERROR);
    560555    }
    561     else
     556    else if (vmsvga3dIsLegacyBackend(pThisCC))
    562557    {
    563558#ifdef VMSVGA3D_DIRECT3D
    564559        /* Flush the drawing pipeline for this surface as it could be used in a shared context. */
    565560        vmsvga3dSurfaceFlush(pSurface);
    566 #elif defined(VMSVGA3D_D3D11)
    567         /** @todo */
    568561#else /* VMSVGA3D_OPENGL */
    569562        pContext = &pState->SharedCtx;
     
    11661159}
    11671160
     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 */
     1168void 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
    11681194
    11691195/*
     
    13131339}
    13141340
     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 */
     1346bool 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  
    264264 * Backend interfaces.
    265265 */
     266bool vmsvga3dIsLegacyBackend(PVGASTATECC pThisCC);
     267
    266268typedef struct VMSVGA3DSURFACE *PVMSVGA3DSURFACE;
    267269typedef struct VMSVGA3DMIPMAPLEVEL *PVMSVGA3DMIPMAPLEVEL;
     
    296298                                                           SVGASignedRect destRect, SVGA3dSurfaceImageId srcImage,
    297299                                                           SVGASignedRect srcRect, uint32_t cRects, SVGASignedRect *paRects));
     300    /* Various helpers. */
     301    DECLCALLBACKMEMBER(int,  pfnSurfaceUpdateHeapBuffers, (PVGASTATECC pThisCC, PVMSVGA3DSURFACE pSurface));
    298302} VMSVGA3DBACKENDFUNCS3D;
    299303
     
    472476} VMSVGA3DBACKENDFUNCSDX;
    473477
    474 int vmsvga3dQueryInterface(PVGASTATECC pThisCC, char const *pszInterfaceName, void *pvInterfaceFuncs, size_t cbInterfaceFuncs);
     478typedef struct VMSVGA3DBACKENDDESC
     479{
     480    char const *pszName;
     481    DECLCALLBACKMEMBER(int, pfnQueryInterface, (PVGASTATECC pThisCC, char const *pszInterfaceName, void *pvInterfaceFuncs, size_t cbInterfaceFuncs));
     482} VMSVGA3DBACKENDDESC;
    475483
    476484#ifdef VMSVGA3D_DX
  • trunk/src/VBox/Devices/Makefile.kmk

    r88926 r89163  
    330330       Graphics/DevVGA-SVGA3d-dx.cpp \
    331331       Graphics/DevVGA-SVGA3d-dx-shader.cpp
     332   if "$(KBUILD_TARGET)" == "win"
     333    VBoxDD_SOURCES      += \
     334       Graphics/DevVGA-SVGA3d-win-dx.cpp
     335   endif
    332336  endif
    333337  VBoxDD_SOURCES       += \
    334338       Graphics/svgadump/svga_dump.c
    335339  if  "$(KBUILD_TARGET)" == "win" && !defined(VBOX_WITH_VMSVGA3D_USE_OPENGL)
    336    ifdef VBOX_WITH_VMSVGA3D_DX
    337     VBoxDD_DEFS          += VMSVGA3D_D3D11
    338     VBoxDD_SOURCES       += \
    339         Graphics/DevVGA-SVGA3d-win-dx.cpp
    340    else
    341340    VBoxDD_DEFS          += VMSVGA3D_DIRECT3D
    342341    VBoxDD_SOURCES       += \
     
    345344    VBoxDD_LIBS.win      += d3d9.lib $(PATH_TOOL_$(VBOX_VCC_TOOL)_LIB)/delayimp.lib
    346345    VBoxDD_LDFLAGS.win   += /DELAYLOAD:d3d9.dll
    347    endif
    348346  else
    349347   VBoxDD_DEFS          += VMSVGA3D_OPENGL
Note: See TracChangeset for help on using the changeset viewer.

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