VirtualBox

Changeset 69153 in vbox for trunk


Ignore:
Timestamp:
Oct 22, 2017 9:38:04 AM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
118464
Message:

Devices/Graphics: VMSVGA: Initial support for volume textures. Remember the type of created D3D resource.

Location:
trunk/src/VBox/Devices/Graphics
Files:
6 edited

Legend:

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

    r69136 r69153  
    267267     * wast memory on them).
    268268     */
    269     uint32_t const fSwitchFlags = pSurface->flags & VMSVGA3D_SURFACE_HINT_SWITCH_MASK;
     269    uint32_t const fSwitchFlags = pSurface->surfaceFlags & VMSVGA3D_SURFACE_HINT_SWITCH_MASK;
    270270    if (   fSwitchFlags != SVGA3D_SURFACE_HINT_DEPTHSTENCIL
    271271        && fSwitchFlags != (SVGA3D_SURFACE_HINT_DEPTHSTENCIL | SVGA3D_SURFACE_HINT_TEXTURE))
     
    312312                     * D3D specifics.
    313313                     */
    314                     HRESULT  hr;
    315                     switch (fSwitchFlags)
     314                    Assert(pSurface->enmD3DResType != VMSVGA3D_D3DRESTYPE_NONE);
     315
     316                    HRESULT hr;
     317                    switch (pSurface->enmD3DResType)
    316318                    {
    317                         case SVGA3D_SURFACE_HINT_TEXTURE:
    318                         case SVGA3D_SURFACE_HINT_RENDERTARGET:
    319                         case SVGA3D_SURFACE_HINT_TEXTURE | SVGA3D_SURFACE_HINT_RENDERTARGET:
     319                        case VMSVGA3D_D3DRESTYPE_VOLUME_TEXTURE:
     320                            AssertFailed(); ///@todo
     321                            break;
     322
     323                        case VMSVGA3D_D3DRESTYPE_SURFACE:
     324                        case VMSVGA3D_D3DRESTYPE_TEXTURE:
     325                        case VMSVGA3D_D3DRESTYPE_CUBE_TEXTURE:
    320326                        {
    321327                            /*
     
    323329                             */
    324330                            D3DLOCKED_RECT LockedRect;
    325                             if (fSwitchFlags & SVGA3D_SURFACE_HINT_TEXTURE)
     331                            if (pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_CUBE_TEXTURE)
     332                            {
     333                                hr = pSurface->u.pCubeTexture->LockRect(vmsvga3dCubemapFaceFromIndex(iFace),
     334                                                                        i, /* texture level */
     335                                                                        &LockedRect,
     336                                                                        NULL,
     337                                                                        D3DLOCK_READONLY);
     338                            }
     339                            else if (pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_TEXTURE)
    326340                            {
    327341                                if (pSurface->bounce.pTexture)
    328342                                {
    329343                                    if (    !pSurface->fDirty
    330                                         &&  fSwitchFlags == (SVGA3D_SURFACE_HINT_TEXTURE | SVGA3D_SURFACE_HINT_RENDERTARGET)
     344                                        &&  RT_BOOL(fSwitchFlags & SVGA3D_SURFACE_HINT_RENDERTARGET)
    331345                                        &&  i == 0 /* only the first time */)
    332346                                    {
     
    403417                        }
    404418
    405                         case SVGA3D_SURFACE_HINT_VERTEXBUFFER | SVGA3D_SURFACE_HINT_INDEXBUFFER:
    406                         case SVGA3D_SURFACE_HINT_VERTEXBUFFER:
    407                         case SVGA3D_SURFACE_HINT_INDEXBUFFER:
     419                        case VMSVGA3D_D3DRESTYPE_VERTEX_BUFFER:
     420                        case VMSVGA3D_D3DRESTYPE_INDEX_BUFFER:
    408421                        {
    409422                            /* Current type of the buffer. */
    410                             const bool fVertex = RT_BOOL(pSurface->fu32ActualUsageFlags & SVGA3D_SURFACE_HINT_VERTEXBUFFER);
     423                            const bool fVertex = (pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_VERTEX_BUFFER);
    411424
    412425                            void *pvD3DData = NULL;
     
    428441
    429442                        default:
    430                             AssertMsgFailed(("%#x\n", fSwitchFlags));
     443                            AssertMsgFailed(("flags %#x, type %d\n", fSwitchFlags, pSurface->enmD3DResType));
    431444                    }
    432445
     
    18111824    pHlp->pfnPrintf(pHlp, "Format:                  %s\n",
    18121825                    vmsvgaFormatEnumValueEx(szTmp, sizeof(szTmp), NULL, (int)pSurface->format, false, &g_SVGA3dSurfaceFormat2String));
    1813     pHlp->pfnPrintf(pHlp, "Flags:                   %#x", pSurface->flags);
    1814     vmsvga3dInfoU32Flags(pHlp, pSurface->flags, "SVGA3D_SURFACE_", g_aSvga3DSurfaceFlags, RT_ELEMENTS(g_aSvga3DSurfaceFlags));
     1826    pHlp->pfnPrintf(pHlp, "Flags:                   %#x", pSurface->surfaceFlags);
     1827    vmsvga3dInfoU32Flags(pHlp, pSurface->surfaceFlags, "SVGA3D_SURFACE_", g_aSvga3DSurfaceFlags, RT_ELEMENTS(g_aSvga3DSurfaceFlags));
    18151828    pHlp->pfnPrintf(pHlp, "\n");
    18161829    if (pSurface->cFaces == 0)
  • trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-internal.h

    r69136 r69153  
    486486
    487487#ifdef VMSVGA3D_DIRECT3D
     488
     489/* What kind of Direct3D resource has been created for the VMSVGA3D surface. */
     490typedef enum VMSVGA3DD3DRESTYPE
     491{
     492    VMSVGA3D_D3DRESTYPE_NONE           = 0,
     493    VMSVGA3D_D3DRESTYPE_SURFACE        = 1,
     494    VMSVGA3D_D3DRESTYPE_TEXTURE        = 2,
     495    VMSVGA3D_D3DRESTYPE_CUBE_TEXTURE   = 3,
     496    VMSVGA3D_D3DRESTYPE_VOLUME_TEXTURE = 4,
     497    VMSVGA3D_D3DRESTYPE_VERTEX_BUFFER  = 5,
     498    VMSVGA3D_D3DRESTYPE_INDEX_BUFFER   = 6
     499} VMSVGA3DD3DRESTYPE;
     500
    488501/**
    489502 *
     
    498511        IDirect3DTexture9          *pTexture;
    499512        IDirect3DCubeTexture9      *pCubeTexture;
     513        IDirect3DVolumeTexture9    *pVolumeTexture;
    500514    } u;
    501515} VMSVGA3DSHAREDSURFACE;
     
    514528    uint32_t                idAssociatedContext;
    515529#endif
    516     uint32_t                flags;
     530    uint32_t                surfaceFlags;
    517531    SVGA3dSurfaceFormat     format;
    518532#ifdef VMSVGA3D_OPENGL
     
    552566    /** Event query inserted after each GPU operation that updates or uses this surface. */
    553567    IDirect3DQuery9        *pQuery;
    554     /** @todo Just remember the type of actually created D3D object. Do not always guess from flags.
    555      * Replace fu32ActualUsageFlags and possibly fStencilAsTexture. */
     568    /* The type of actually created D3D resource. */
     569    VMSVGA3DD3DRESTYPE      enmD3DResType;
    556570    union
    557571    {
    558572        IDirect3DSurface9          *pSurface;
     573        IDirect3DTexture9          *pTexture;
    559574        IDirect3DCubeTexture9      *pCubeTexture;
     575        IDirect3DVolumeTexture9    *pVolumeTexture;
     576        IDirect3DVertexBuffer9     *pVertexBuffer;
    560577        IDirect3DIndexBuffer9      *pIndexBuffer;
    561         IDirect3DTexture9          *pTexture;
    562         IDirect3DVertexBuffer9     *pVertexBuffer;
    563578    } u;
    564579    union
     
    566581        IDirect3DTexture9          *pTexture;
    567582        IDirect3DCubeTexture9      *pCubeTexture;
     583        IDirect3DVolumeTexture9    *pVolumeTexture;
    568584    } bounce;
    569585    /** AVL tree containing VMSVGA3DSHAREDSURFACE structures. */
    570586    AVLU32TREE              pSharedObjectTree;
    571587    bool                    fStencilAsTexture;
    572     uint32_t                fu32ActualUsageFlags;
    573588#endif
    574589} VMSVGA3DSURFACE;
     
    588603    SSMFIELD_ENTRY(                 VMSVGA3DSURFACE, idAssociatedContext),
    589604# endif
    590     SSMFIELD_ENTRY(                 VMSVGA3DSURFACE, flags),
     605    SSMFIELD_ENTRY(                 VMSVGA3DSURFACE, surfaceFlags),
    591606    SSMFIELD_ENTRY(                 VMSVGA3DSURFACE, format),
    592607# ifdef VMSVGA3D_OPENGL
     
    11221137}
    11231138
    1124 
    1125 #endif
    1126 
     1139#ifdef VMSVGA3D_DIRECT3D
     1140DECLINLINE(D3DCUBEMAP_FACES) vmsvga3dCubemapFaceFromIndex(uint32_t iFace)
     1141{
     1142    D3DCUBEMAP_FACES Face;
     1143    switch (iFace)
     1144    {
     1145        case 0: Face = D3DCUBEMAP_FACE_POSITIVE_X; break;
     1146        case 1: Face = D3DCUBEMAP_FACE_NEGATIVE_X; break;
     1147        case 2: Face = D3DCUBEMAP_FACE_POSITIVE_Y; break;
     1148        case 3: Face = D3DCUBEMAP_FACE_NEGATIVE_Y; break;
     1149        case 4: Face = D3DCUBEMAP_FACE_POSITIVE_Z; break;
     1150        default:
     1151        case 5: Face = D3DCUBEMAP_FACE_NEGATIVE_Z; break;
     1152    }
     1153    return Face;
     1154}
     1155#endif /* VMSVGA3D_DIRECT3D */
     1156
     1157#endif
     1158
  • trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-ogl.cpp

    r69136 r69153  
    18551855    VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
    18561856
    1857     switch (pSurface->flags & VMSVGA3D_SURFACE_HINT_SWITCH_MASK)
     1857    switch (pSurface->surfaceFlags & VMSVGA3D_SURFACE_HINT_SWITCH_MASK)
    18581858    {
    18591859    case SVGA3D_SURFACE_CUBEMAP:
     
    18911891
    18921892    default:
    1893         AssertMsg(!VMSVGA3DSURFACE_HAS_HW_SURFACE(pSurface), ("type=%x\n", (pSurface->flags & VMSVGA3D_SURFACE_HINT_SWITCH_MASK)));
     1893        AssertMsg(!VMSVGA3DSURFACE_HAS_HW_SURFACE(pSurface), ("type=%x\n", (pSurface->surfaceFlags & VMSVGA3D_SURFACE_HINT_SWITCH_MASK)));
    18941894        break;
    18951895    }
     
    21222122    VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
    21232123
    2124     pSurface->flags              |= SVGA3D_SURFACE_HINT_TEXTURE;
     2124    pSurface->surfaceFlags |= SVGA3D_SURFACE_HINT_TEXTURE;
    21252125
    21262126    if (idPrevCtx < pState->cContexts && pState->papContexts[idPrevCtx]->id == idPrevCtx)
     
    23442344    RT_NOREF(uHostFace); ///@todo
    23452345
    2346     switch (pSurface->flags & VMSVGA3D_SURFACE_HINT_SWITCH_MASK)
     2346    switch (pSurface->surfaceFlags & VMSVGA3D_SURFACE_HINT_SWITCH_MASK)
    23472347    {
    23482348    case SVGA3D_SURFACE_HINT_TEXTURE | SVGA3D_SURFACE_HINT_RENDERTARGET:
     
    25032503                {
    25042504                    Log(("Lock %s memory for rectangle (%d,%d)(%d,%d)\n",
    2505                          (pSurface->flags & VMSVGA3D_SURFACE_HINT_SWITCH_MASK) == SVGA3D_SURFACE_HINT_VERTEXBUFFER ? "vertex" :
    2506                            (pSurface->flags & VMSVGA3D_SURFACE_HINT_SWITCH_MASK) == SVGA3D_SURFACE_HINT_INDEXBUFFER ? "index" : "buffer",
     2505                         (pSurface->surfaceFlags & VMSVGA3D_SURFACE_HINT_SWITCH_MASK) == SVGA3D_SURFACE_HINT_VERTEXBUFFER ? "vertex" :
     2506                           (pSurface->surfaceFlags & VMSVGA3D_SURFACE_HINT_SWITCH_MASK) == SVGA3D_SURFACE_HINT_INDEXBUFFER ? "index" : "buffer",
    25072507                         pBox->x, pBox->y, pBox->x + pBox->w, pBox->y + pBox->h));
    25082508
     
    26532653    {
    26542654        /* Unknown surface type; turn it into a texture. */
    2655         Log(("vmsvga3dGenerateMipmaps: unknown src surface id=%x type=%d format=%d -> create texture\n", sid, pSurface->flags, pSurface->format));
     2655        Log(("vmsvga3dGenerateMipmaps: unknown src surface id=%x type=%d format=%d -> create texture\n", sid, pSurface->surfaceFlags, pSurface->format));
    26562656        rc = vmsvga3dBackCreateTexture(pState, pContext, cid, pSurface);
    26572657        AssertRCReturn(rc, rc);
     
    48024802        if (pRenderTarget->oglId.texture == OPENGL_INVALID_ID)
    48034803        {
    4804             Log(("vmsvga3dSetRenderTarget: create renderbuffer to be used as render target; surface id=%x type=%d format=%d\n", target.sid, pRenderTarget->flags, pRenderTarget->internalFormatGL));
     4804            Log(("vmsvga3dSetRenderTarget: create renderbuffer to be used as render target; surface id=%x type=%d format=%d\n", target.sid, pRenderTarget->surfaceFlags, pRenderTarget->internalFormatGL));
    48054805            pContext = &pState->SharedCtx;
    48064806            VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
     
    48314831        AssertReturn(pRenderTarget->oglId.texture != OPENGL_INVALID_ID, VERR_INVALID_PARAMETER);
    48324832
    4833         pRenderTarget->flags |= SVGA3D_SURFACE_HINT_DEPTHSTENCIL;
     4833        pRenderTarget->surfaceFlags |= SVGA3D_SURFACE_HINT_DEPTHSTENCIL;
    48344834
    48354835        pState->ext.glFramebufferRenderbuffer(GL_FRAMEBUFFER,
     
    48514851        if (pRenderTarget->oglId.texture == OPENGL_INVALID_ID)
    48524852        {
    4853             Log(("vmsvga3dSetRenderTarget: create texture to be used as render target; surface id=%x type=%d format=%d -> create texture\n", target.sid, pRenderTarget->flags, pRenderTarget->format));
     4853            Log(("vmsvga3dSetRenderTarget: create texture to be used as render target; surface id=%x type=%d format=%d -> create texture\n", target.sid, pRenderTarget->surfaceFlags, pRenderTarget->format));
    48544854            int rc = vmsvga3dBackCreateTexture(pState, pContext, cid, pRenderTarget);
    48554855            AssertRCReturn(rc, rc);
     
    48594859        Assert(!pRenderTarget->fDirty);
    48604860
    4861         pRenderTarget->flags |= SVGA3D_SURFACE_HINT_RENDERTARGET;
     4861        pRenderTarget->surfaceFlags |= SVGA3D_SURFACE_HINT_RENDERTARGET;
    48624862
    48634863        pState->ext.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + type - SVGA3D_RT_COLOR0, GL_TEXTURE_2D, pRenderTarget->oglId.texture, target.mipmap);
     
    59785978        pVertexSurface->fDirty = false;
    59795979
    5980         pVertexSurface->flags |= SVGA3D_SURFACE_HINT_VERTEXBUFFER;
     5980        pVertexSurface->surfaceFlags |= SVGA3D_SURFACE_HINT_VERTEXBUFFER;
    59815981
    59825982        pState->ext.glBindBuffer(GL_ARRAY_BUFFER, OPENGL_INVALID_ID);
     
    63126312                pIndexSurface->fDirty = false;
    63136313
    6314                 pIndexSurface->flags |= SVGA3D_SURFACE_HINT_INDEXBUFFER;
     6314                pIndexSurface->surfaceFlags |= SVGA3D_SURFACE_HINT_INDEXBUFFER;
    63156315
    63166316                pState->ext.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, OPENGL_INVALID_ID);
  • trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-savedstate.cpp

    r69136 r69153  
    357357                }
    358358
    359                 rc = vmsvga3dSurfaceDefine(pThis, sid, surface.flags, surface.format, surface.faces, surface.multiSampleCount, surface.autogenFilter, cMipLevels, pMipmapLevelSize);
     359                rc = vmsvga3dSurfaceDefine(pThis, sid, surface.surfaceFlags, surface.format, surface.faces, surface.multiSampleCount, surface.autogenFilter, cMipLevels, pMipmapLevelSize);
    360360                AssertRCReturn(rc, rc);
    361361
     
    607607                        AssertReturn(pData, VERR_NO_MEMORY);
    608608
    609                         switch (pSurface->flags & VMSVGA3D_SURFACE_HINT_SWITCH_MASK)
     609                        switch (pSurface->enmD3DResType)
    610610                        {
    611                         case SVGA3D_SURFACE_HINT_DEPTHSTENCIL:
    612                         case SVGA3D_SURFACE_HINT_DEPTHSTENCIL | SVGA3D_SURFACE_HINT_TEXTURE:
    613                             /** @todo unable to easily fetch depth surface data in d3d 9 */
     611                        case VMSVGA3D_D3DRESTYPE_CUBE_TEXTURE:
     612                        case VMSVGA3D_D3DRESTYPE_VOLUME_TEXTURE:
     613                            AssertFailed(); ///@todo
    614614                            fSkipSave = true;
    615615                            break;
    616                         case SVGA3D_SURFACE_HINT_TEXTURE | SVGA3D_SURFACE_HINT_RENDERTARGET:
    617                             fRenderTargetTexture = true;
    618                             /* no break */
    619                         case SVGA3D_SURFACE_HINT_TEXTURE:
    620                             fTexture = true;
    621                             /* no break */
    622                         case SVGA3D_SURFACE_HINT_RENDERTARGET:
     616                        case VMSVGA3D_D3DRESTYPE_SURFACE:
     617                        case VMSVGA3D_D3DRESTYPE_TEXTURE:
    623618                        {
     619                            if (pSurface->surfaceFlags & SVGA3D_SURFACE_HINT_DEPTHSTENCIL)
     620                            {
     621                               /** @todo unable to easily fetch depth surface data in d3d 9 */
     622                               fSkipSave = true;
     623                               break;
     624                            }
     625
     626                            fTexture = (pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_TEXTURE);
     627                            fRenderTargetTexture = fTexture && (pSurface->surfaceFlags & SVGA3D_SURFACE_HINT_RENDERTARGET);
     628
    624629                            D3DLOCKED_RECT LockedRect;
    625630
     
    698703                        }
    699704
    700                         case SVGA3D_SURFACE_HINT_VERTEXBUFFER | SVGA3D_SURFACE_HINT_INDEXBUFFER:
    701                         case SVGA3D_SURFACE_HINT_VERTEXBUFFER:
    702                         case SVGA3D_SURFACE_HINT_INDEXBUFFER:
     705                        case VMSVGA3D_D3DRESTYPE_VERTEX_BUFFER:
     706                        case VMSVGA3D_D3DRESTYPE_INDEX_BUFFER:
    703707                        {
    704708                            /* Current type of the buffer. */
    705                             const bool fVertex = RT_BOOL(pSurface->fu32ActualUsageFlags & SVGA3D_SURFACE_HINT_VERTEXBUFFER);
     709                            const bool fVertex = (pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_VERTEX_BUFFER);
    706710
    707711                            uint8_t *pD3DData;
     
    754758                        Assert(pMipmapLevel->cbSurface);
    755759
    756                         switch (pSurface->flags & VMSVGA3D_SURFACE_HINT_SWITCH_MASK)
     760                        switch (pSurface->surfaceFlags & VMSVGA3D_SURFACE_HINT_SWITCH_MASK)
    757761                        {
    758762                        default:
  • trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-win.cpp

    r69136 r69153  
    11051105    Assert(pSurface->pSharedObjectTree == NULL);
    11061106
    1107     switch (pSurface->flags & VMSVGA3D_SURFACE_HINT_SWITCH_MASK)
    1108     {
    1109     case SVGA3D_SURFACE_CUBEMAP:
    1110     case SVGA3D_SURFACE_CUBEMAP | SVGA3D_SURFACE_HINT_TEXTURE:
    1111     case SVGA3D_SURFACE_CUBEMAP | SVGA3D_SURFACE_HINT_TEXTURE | SVGA3D_SURFACE_HINT_RENDERTARGET:
     1107    switch (pSurface->enmD3DResType)
     1108    {
     1109    case VMSVGA3D_D3DRESTYPE_SURFACE:
     1110        D3D_RELEASE(pSurface->u.pSurface);
     1111        break;
     1112
     1113    case VMSVGA3D_D3DRESTYPE_TEXTURE:
     1114        D3D_RELEASE(pSurface->u.pTexture);
     1115        D3D_RELEASE(pSurface->bounce.pTexture);
     1116        break;
     1117
     1118    case VMSVGA3D_D3DRESTYPE_CUBE_TEXTURE:
    11121119        D3D_RELEASE(pSurface->u.pCubeTexture);
    11131120        D3D_RELEASE(pSurface->bounce.pCubeTexture);
    11141121        break;
    11151122
    1116     case SVGA3D_SURFACE_HINT_INDEXBUFFER | SVGA3D_SURFACE_HINT_VERTEXBUFFER:
    1117     case SVGA3D_SURFACE_HINT_INDEXBUFFER:
    1118     case SVGA3D_SURFACE_HINT_VERTEXBUFFER:
    1119         if (pSurface->fu32ActualUsageFlags == SVGA3D_SURFACE_HINT_VERTEXBUFFER)
    1120             D3D_RELEASE(pSurface->u.pVertexBuffer);
    1121         else if (pSurface->fu32ActualUsageFlags == SVGA3D_SURFACE_HINT_INDEXBUFFER)
    1122             D3D_RELEASE(pSurface->u.pIndexBuffer);
    1123         else
    1124             AssertMsg(pSurface->u.pVertexBuffer == NULL, ("fu32ActualUsageFlags %x\n", pSurface->fu32ActualUsageFlags));
    1125         break;
    1126 
    1127     case SVGA3D_SURFACE_HINT_TEXTURE:
    1128     case SVGA3D_SURFACE_HINT_TEXTURE | SVGA3D_SURFACE_HINT_RENDERTARGET:
    1129         D3D_RELEASE(pSurface->u.pTexture);
    1130         D3D_RELEASE(pSurface->bounce.pTexture);
    1131         break;
    1132 
    1133     case SVGA3D_SURFACE_HINT_RENDERTARGET:
    1134     case SVGA3D_SURFACE_HINT_DEPTHSTENCIL:
    1135     case SVGA3D_SURFACE_HINT_DEPTHSTENCIL | SVGA3D_SURFACE_HINT_TEXTURE:    /** @todo actual texture surface not supported */
    1136         if (pSurface->fStencilAsTexture)
    1137             D3D_RELEASE(pSurface->u.pTexture);
    1138         else
    1139             D3D_RELEASE(pSurface->u.pSurface);
     1123    case VMSVGA3D_D3DRESTYPE_VOLUME_TEXTURE:
     1124        D3D_RELEASE(pSurface->u.pVolumeTexture);
     1125        D3D_RELEASE(pSurface->bounce.pVolumeTexture);
     1126        break;
     1127
     1128    case VMSVGA3D_D3DRESTYPE_VERTEX_BUFFER:
     1129        D3D_RELEASE(pSurface->u.pVertexBuffer);
     1130        break;
     1131
     1132    case VMSVGA3D_D3DRESTYPE_INDEX_BUFFER:
     1133        D3D_RELEASE(pSurface->u.pIndexBuffer);
    11401134        break;
    11411135
    11421136    default:
    1143         AssertMsg(!VMSVGA3DSURFACE_HAS_HW_SURFACE(pSurface), ("type=%x\n", (pSurface->flags & VMSVGA3D_SURFACE_HINT_SWITCH_MASK)));
     1137        AssertMsg(!VMSVGA3DSURFACE_HAS_HW_SURFACE(pSurface),
     1138                  ("surfaceFlags=0x%x\n", (pSurface->surfaceFlags & VMSVGA3D_SURFACE_HINT_SWITCH_MASK)));
    11441139        break;
    11451140    }
     
    11571152    PVMSVGA3DSURFACE       pSurface = (PVMSVGA3DSURFACE)pvParam;
    11581153
    1159     switch (pSurface->flags & VMSVGA3D_SURFACE_HINT_SWITCH_MASK)
    1160     {
    1161     case SVGA3D_SURFACE_CUBEMAP:
    1162     case SVGA3D_SURFACE_CUBEMAP | SVGA3D_SURFACE_HINT_TEXTURE:
    1163     case SVGA3D_SURFACE_CUBEMAP | SVGA3D_SURFACE_HINT_TEXTURE | SVGA3D_SURFACE_HINT_RENDERTARGET:
     1154    switch (pSurface->enmD3DResType)
     1155    {
     1156    case VMSVGA3D_D3DRESTYPE_TEXTURE:
     1157        LogFunc(("release shared texture object for context %d\n", pNode->Key));
     1158        Assert(pSharedSurface->u.pTexture);
     1159        D3D_RELEASE(pSharedSurface->u.pTexture);
     1160        break;
     1161
     1162    case VMSVGA3D_D3DRESTYPE_CUBE_TEXTURE:
    11641163        LogFunc(("release shared cube texture object for context %d\n", pNode->Key));
    11651164        Assert(pSharedSurface->u.pCubeTexture);
     
    11671166        break;
    11681167
    1169     case SVGA3D_SURFACE_HINT_TEXTURE:
    1170     case SVGA3D_SURFACE_HINT_TEXTURE | SVGA3D_SURFACE_HINT_RENDERTARGET:
    1171         LogFunc(("release shared texture object for context %d\n", pNode->Key));
    1172         Assert(pSharedSurface->u.pTexture);
    1173         D3D_RELEASE(pSharedSurface->u.pTexture);
     1168    case VMSVGA3D_D3DRESTYPE_VOLUME_TEXTURE:
     1169        LogFunc(("release shared volume texture object for context %d\n", pNode->Key));
     1170        Assert(pSharedSurface->u.pVolumeTexture);
     1171        D3D_RELEASE(pSharedSurface->u.pVolumeTexture);
    11741172        break;
    11751173
     
    11901188    if (!pSharedSurface)
    11911189    {
    1192         const bool fCubeTexture = RT_BOOL(pSurface->flags & SVGA3D_SURFACE_CUBEMAP);
    11931190        const uint32_t cWidth = pSurface->pMipmapLevels[0].mipmapSize.width;
    11941191        const uint32_t cHeight = pSurface->pMipmapLevels[0].mipmapSize.height;
     1192        const uint32_t cDepth = pSurface->pMipmapLevels[0].mipmapSize.depth;
    11951193        const uint32_t numMipLevels = pSurface->faces[0].numMipLevels;
    11961194
    1197         LogFunc(("Create shared %stexture copy d3d (%d,%d) cMip=%d usage %x format %x.\n",
    1198                   fCubeTexture ? "cube " : "",
     1195        LogFunc(("Create shared %stexture copy d3d (%d,%d,%d) cMip=%d usage %x format %x.\n",
     1196                  pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_VOLUME_TEXTURE ? "volume " :
     1197                  pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_CUBE_TEXTURE ? "cube " :
     1198                  pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_TEXTURE ? "" : "UNKNOWN!!!",
    11991199                  cWidth,
    12001200                  cHeight,
     1201                  cDepth,
    12011202                  numMipLevels,
    12021203                  pSurface->fUsageD3D | D3DUSAGE_RENDERTARGET,
     
    12101211        AssertReturn(ret, NULL);
    12111212
    1212         /* Create shadow copy of the original shared texture. Shared d3d resources require Vista+ and have some restrictions. */
     1213        /* Create shadow copy of the original shared texture.
     1214         * Shared d3d resources require Vista+ and have some restrictions.
     1215         * D3DUSAGE_RENDERTARGET is required for use as a StretchRect destination.
     1216         */
    12131217        HRESULT hr;
    1214         if (fCubeTexture)
     1218        if (pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_VOLUME_TEXTURE)
     1219            hr = pContext->pDevice->CreateVolumeTexture(cWidth,
     1220                                                        cHeight,
     1221                                                        cDepth,
     1222                                                        numMipLevels,
     1223                                                        pSurface->fUsageD3D | D3DUSAGE_RENDERTARGET,
     1224                                                        pSurface->formatD3D,
     1225                                                        D3DPOOL_DEFAULT,
     1226                                                        &pSharedSurface->u.pVolumeTexture,
     1227                                                        &pSurface->hSharedObject);
     1228        else if (pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_CUBE_TEXTURE)
    12151229            hr = pContext->pDevice->CreateCubeTexture(cWidth,
    12161230                                                      numMipLevels,
    1217                                                       pSurface->fUsageD3D | D3DUSAGE_RENDERTARGET /* required for use as a StretchRect destination */,
     1231                                                      pSurface->fUsageD3D | D3DUSAGE_RENDERTARGET,
    12181232                                                      pSurface->formatD3D,
    12191233                                                      D3DPOOL_DEFAULT,
    12201234                                                      &pSharedSurface->u.pCubeTexture,
    12211235                                                      &pSurface->hSharedObject);
    1222         else
     1236        else if (pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_TEXTURE)
    12231237            hr = pContext->pDevice->CreateTexture(cWidth,
    12241238                                                  cHeight,
    12251239                                                  numMipLevels,
    1226                                                   pSurface->fUsageD3D | D3DUSAGE_RENDERTARGET /* required for use as a StretchRect destination */,
     1240                                                  pSurface->fUsageD3D | D3DUSAGE_RENDERTARGET,
    12271241                                                  pSurface->formatD3D,
    12281242                                                  D3DPOOL_DEFAULT,
    12291243                                                  &pSharedSurface->u.pTexture,
    12301244                                                  &pSurface->hSharedObject);
    1231         AssertMsgReturn(hr == D3D_OK, ("CreateTexture failed with %x\n", hr), NULL);
     1245        else
     1246            hr = E_FAIL;
     1247
     1248        if (RT_LIKELY(hr == D3D_OK))
     1249            /* likely */;
     1250        else
     1251        {
     1252            AssertMsgFailed(("CreateTexture type %d failed with %x\n", pSurface->enmD3DResType, hr));
     1253            RTAvlU32Remove(&pSurface->pSharedObjectTree, pContext->id);
     1254            RTMemFree(pSharedSurface);
     1255            return NULL;
     1256        }
    12321257    }
    12331258    return pSharedSurface;
     
    13121337}
    13131338
    1314 DECLINLINE(D3DCUBEMAP_FACES) vmsvga3dCubemapFaceFromIndex(uint32_t iFace)
    1315 {
    1316     D3DCUBEMAP_FACES Face;
    1317     switch (iFace)
    1318     {
    1319         case 0: Face = D3DCUBEMAP_FACE_POSITIVE_X; break;
    1320         case 1: Face = D3DCUBEMAP_FACE_NEGATIVE_X; break;
    1321         case 2: Face = D3DCUBEMAP_FACE_POSITIVE_Y; break;
    1322         case 3: Face = D3DCUBEMAP_FACE_NEGATIVE_Y; break;
    1323         case 4: Face = D3DCUBEMAP_FACE_POSITIVE_Z; break;
    1324         default:
    1325         case 5: Face = D3DCUBEMAP_FACE_NEGATIVE_Z; break;
    1326     }
    1327     return Face;
    1328 }
    1329 
    13301339/** Get IDirect3DSurface9 for the given face and mipmap.
    13311340 */
     
    13391348    AssertPtrReturn(pSurface->u.pSurface, VERR_INVALID_PARAMETER);
    13401349
    1341     const bool fTexture     = RT_BOOL(pSurface->flags & SVGA3D_SURFACE_HINT_TEXTURE);
    1342     const bool fCubeTexture = RT_BOOL(pSurface->flags & SVGA3D_SURFACE_CUBEMAP);
    1343 
    13441350    IDirect3DBaseTexture9 *pTexture;
    13451351    if (fLockable && pSurface->bounce.pTexture)
     
    13561362                        VERR_INVALID_PARAMETER);
    13571363
    1358         if (fTexture)
     1364        if (   pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_TEXTURE
     1365            || pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_CUBE_TEXTURE)
    13591366        {
    13601367            LogFunc(("using texture sid=%x created for another context (%d vs %d)\n",
     
    13761383#endif
    13771384
    1378     if (fCubeTexture)
     1385    if (pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_CUBE_TEXTURE)
    13791386    {
    13801387        Assert(pSurface->cFaces == 6);
     
    13851392        AssertMsgReturn(hr == D3D_OK, ("GetCubeMapSurface failed with %x\n", hr), VERR_INTERNAL_ERROR);
    13861393    }
    1387     else if (fTexture)
     1394    else if (pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_TEXTURE)
    13881395    {
    13891396        Assert(pSurface->cFaces == 1);
     
    13941401        AssertMsgReturn(hr == D3D_OK, ("GetSurfaceLevel failed with %x\n", hr), VERR_INTERNAL_ERROR);
    13951402    }
    1396     else
     1403    else if (pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_SURFACE)
    13971404    {
    13981405        pSurface->u.pSurface->AddRef();
    13991406        *ppD3DSurf = pSurface->u.pSurface;
     1407    }
     1408    else
     1409    {
     1410        AssertMsgFailedReturn(("No surface for type %d\n", pSurface->enmD3DResType), VERR_INTERNAL_ERROR);
    14001411    }
    14011412
     
    14291440    AssertRCReturn(rc, rc);
    14301441
    1431     const bool fDestTexture = RT_BOOL(pSurfaceDest->flags & SVGA3D_SURFACE_HINT_TEXTURE);
    1432 
    1433     if (    fDestTexture
    1434         &&  !pSurfaceDest->u.pSurface
    1435         &&  pSurfaceSrc->u.pSurface)
     1442    /* If src is HW and dst is not, then create the dst texture. */
     1443    if (   pSurfaceSrc->u.pSurface
     1444        && !pSurfaceDest->u.pSurface
     1445        && RT_BOOL(pSurfaceDest->surfaceFlags & SVGA3D_SURFACE_HINT_TEXTURE))
    14361446    {
    14371447        const uint32_t cid = pSurfaceSrc->idAssociatedContext;
     
    14411451        AssertRCReturn(rc, rc);
    14421452
    1443         LogFunc(("sid=%x type=%x format=%d -> create texture\n", sidDest, pSurfaceDest->flags, pSurfaceDest->format));
     1453        LogFunc(("sid=%x type=%x format=%d -> create texture\n", sidDest, pSurfaceDest->surfaceFlags, pSurfaceDest->format));
    14441454        rc = vmsvga3dBackCreateTexture(pState, pContext, cid, pSurfaceDest);
    14451455        AssertRCReturn(rc, rc);
    14461456    }
     1457
     1458    Assert(pSurfaceSrc->enmD3DResType != VMSVGA3D_D3DRESTYPE_VOLUME_TEXTURE); ///@todo
     1459    Assert(pSurfaceDest->enmD3DResType != VMSVGA3D_D3DRESTYPE_VOLUME_TEXTURE); ///@todo
    14471460
    14481461    if (   pSurfaceSrc->u.pSurface
     
    16471660
    16481661        /* If the destination bounce texture has been used, then update the actual texture. */
    1649         if (   pSurfaceDest->u.pSurface
    1650             && fDestTexture
    1651             && pSurfaceDest->bounce.pTexture)
     1662        if (   pSurfaceDest->u.pTexture
     1663            && pSurfaceDest->bounce.pTexture
     1664            && (   pSurfaceDest->enmD3DResType == VMSVGA3D_D3DRESTYPE_TEXTURE
     1665                || pSurfaceDest->enmD3DResType == VMSVGA3D_D3DRESTYPE_CUBE_TEXTURE))
    16521666        {
    16531667            AssertMsgReturn(pContext, ("Context is NULL\n"), VERR_INTERNAL_ERROR);
     
    16561670            IDirect3DBaseTexture9 *pSourceTexture;
    16571671            IDirect3DBaseTexture9 *pDestinationTexture;
    1658             if (pSurfaceDest->flags & SVGA3D_SURFACE_CUBEMAP)
     1672            if (pSurfaceDest->enmD3DResType == VMSVGA3D_D3DRESTYPE_CUBE_TEXTURE)
    16591673            {
    16601674                pSourceTexture = pSurfaceDest->bounce.pCubeTexture;
     
    16971711    Assert(pSurface->u.pTexture == NULL);
    16981712    Assert(pSurface->bounce.pTexture == NULL);
     1713    Assert(pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_NONE);
    16991714
    17001715    const uint32_t cWidth = pSurface->pMipmapLevels[0].mipmapSize.width;
    17011716    const uint32_t cHeight = pSurface->pMipmapLevels[0].mipmapSize.height;
     1717    const uint32_t cDepth = pSurface->pMipmapLevels[0].mipmapSize.depth;
    17021718    const uint32_t numMipLevels = pSurface->faces[0].numMipLevels;
    17031719
     
    17051721     * Create D3D texture object.
    17061722     */
    1707     if (pSurface->flags & SVGA3D_SURFACE_CUBEMAP)
     1723    if (pSurface->surfaceFlags & SVGA3D_SURFACE_CUBEMAP)
    17081724    {
    17091725        Assert(pSurface->cFaces == 6);
    17101726        Assert(cWidth == cHeight);
     1727        Assert(cDepth == 1);
    17111728
    17121729        hr = pContext->pDevice->CreateCubeTexture(cWidth,
     
    17451762            AssertMsgReturn(hr == D3D_OK, ("CreateCubeTexture (fallback) failed with %x\n", hr), VERR_INTERNAL_ERROR);
    17461763        }
     1764
     1765        pSurface->enmD3DResType = VMSVGA3D_D3DRESTYPE_CUBE_TEXTURE;
    17471766    }
    17481767    else if (   pSurface->formatD3D == D3DFMT_D24S8
     
    17511770        Assert(pSurface->cFaces == 1);
    17521771        Assert(pSurface->faces[0].numMipLevels == 1);
     1772        Assert(cDepth == 1);
    17531773
    17541774        /* Use the INTZ format for a depth/stencil surface that will be used as a texture */
    17551775        hr = pContext->pDevice->CreateTexture(cWidth,
    17561776                                              cHeight,
    1757                                               1,
     1777                                              1, /* mip levels */
    17581778                                              D3DUSAGE_DEPTHSTENCIL,
    17591779                                              FOURCC_INTZ,
     
    17641784
    17651785        pSurface->fStencilAsTexture = true;
     1786        pSurface->enmD3DResType = VMSVGA3D_D3DRESTYPE_TEXTURE;
    17661787    }
    17671788    else
    17681789    {
    1769         /** @todo if (depth > 1) CreateVolumeTexture */
    1770         Assert(pSurface->cFaces == 1);
    1771 
    1772         hr = pContext->pDevice->CreateTexture(cWidth,
    1773                                               cHeight,
    1774                                               numMipLevels,
    1775                                               pSurface->fUsageD3D | D3DUSAGE_RENDERTARGET /* required for use as a StretchRect destination */,
    1776                                               pSurface->formatD3D,
    1777                                               D3DPOOL_DEFAULT,
    1778                                               &pSurface->u.pTexture,
    1779                                               &pSurface->hSharedObject);
    1780         if (hr == D3D_OK)
    1781         {
    1782             /* Create another texture object to serve as a bounce buffer as the above texture surface can't be locked. */
     1790        if (cDepth > 1)
     1791        {
     1792            hr = pContext->pDevice->CreateVolumeTexture(cWidth,
     1793                                                        cHeight,
     1794                                                        cDepth,
     1795                                                        numMipLevels,
     1796                                                        pSurface->fUsageD3D,
     1797                                                        pSurface->formatD3D,
     1798                                                        D3DPOOL_DEFAULT,
     1799                                                        &pSurface->u.pVolumeTexture,
     1800                                                        &pSurface->hSharedObject);
     1801            if (hr == D3D_OK)
     1802            {
     1803                /* Create another texture object to serve as a bounce buffer as the above texture surface can't be locked. */
     1804                hr = pContext->pDevice->CreateVolumeTexture(cWidth,
     1805                                                            cHeight,
     1806                                                            cDepth,
     1807                                                            numMipLevels,
     1808                                                            (pSurface->fUsageD3D & ~D3DUSAGE_RENDERTARGET) | D3DUSAGE_DYNAMIC /* Lockable */,
     1809                                                            pSurface->formatD3D,
     1810                                                            D3DPOOL_SYSTEMMEM,
     1811                                                            &pSurface->bounce.pVolumeTexture,
     1812                                                            NULL);
     1813                AssertMsgReturnStmt(hr == D3D_OK,
     1814                                    ("CreateVolumeTexture (systemmem) failed with %x\n", hr),
     1815                                    D3D_RELEASE(pSurface->u.pVolumeTexture),
     1816                                    VERR_INTERNAL_ERROR);
     1817            }
     1818            else
     1819            {
     1820                Log(("Format not accepted -> try old method\n"));
     1821                /* The format was probably not accepted; fall back to our old mode. */
     1822                hr = pContext->pDevice->CreateVolumeTexture(cWidth,
     1823                                                            cHeight,
     1824                                                            cDepth,
     1825                                                            numMipLevels,
     1826                                                            (pSurface->fUsageD3D & ~D3DUSAGE_RENDERTARGET) |  D3DUSAGE_DYNAMIC /* Lockable */,
     1827                                                            pSurface->formatD3D,
     1828                                                            D3DPOOL_DEFAULT,
     1829                                                            &pSurface->u.pVolumeTexture,
     1830                                                            &pSurface->hSharedObject);
     1831                AssertMsgReturn(hr == D3D_OK, ("CreateVolumeTexture (fallback) failed with %x\n", hr), VERR_INTERNAL_ERROR);
     1832            }
     1833
     1834            pSurface->enmD3DResType = VMSVGA3D_D3DRESTYPE_VOLUME_TEXTURE;
     1835        }
     1836        else
     1837        {
     1838            Assert(pSurface->cFaces == 1);
     1839
    17831840            hr = pContext->pDevice->CreateTexture(cWidth,
    17841841                                                  cHeight,
    17851842                                                  numMipLevels,
    1786                                                   (pSurface->fUsageD3D & ~D3DUSAGE_RENDERTARGET) | D3DUSAGE_DYNAMIC /* Lockable */,
    1787                                                   pSurface->formatD3D,
    1788                                                   D3DPOOL_SYSTEMMEM,
    1789                                                   &pSurface->bounce.pTexture,
    1790                                                   NULL);
    1791             AssertMsgReturn(hr == D3D_OK, ("CreateTexture (systemmem) failed with %x\n", hr), VERR_INTERNAL_ERROR);
    1792         }
    1793         else
    1794         {
    1795             Log(("Format not accepted -> try old method\n"));
    1796             /* The format was probably not accepted; fall back to our old mode. */
    1797             hr = pContext->pDevice->CreateTexture(cWidth,
    1798                                                   cHeight,
    1799                                                   numMipLevels,
    1800                                                   (pSurface->fUsageD3D & ~D3DUSAGE_RENDERTARGET) |  D3DUSAGE_DYNAMIC /* Lockable */,
     1843                                                  pSurface->fUsageD3D | D3DUSAGE_RENDERTARGET /* required for use as a StretchRect destination */,
    18011844                                                  pSurface->formatD3D,
    18021845                                                  D3DPOOL_DEFAULT,
    18031846                                                  &pSurface->u.pTexture,
    1804                                                   &pSurface->hSharedObject /* might result in poor performance */);
    1805             AssertMsgReturn(hr == D3D_OK, ("CreateTexture failed with %x\n", hr), VERR_INTERNAL_ERROR);
    1806         }
    1807     }
     1847                                                  &pSurface->hSharedObject);
     1848            if (hr == D3D_OK)
     1849            {
     1850                /* Create another texture object to serve as a bounce buffer as the above texture surface can't be locked. */
     1851                hr = pContext->pDevice->CreateTexture(cWidth,
     1852                                                      cHeight,
     1853                                                      numMipLevels,
     1854                                                      (pSurface->fUsageD3D & ~D3DUSAGE_RENDERTARGET) | D3DUSAGE_DYNAMIC /* Lockable */,
     1855                                                      pSurface->formatD3D,
     1856                                                      D3DPOOL_SYSTEMMEM,
     1857                                                      &pSurface->bounce.pTexture,
     1858                                                      NULL);
     1859                AssertMsgReturn(hr == D3D_OK, ("CreateTexture (systemmem) failed with %x\n", hr), VERR_INTERNAL_ERROR);
     1860            }
     1861            else
     1862            {
     1863                Log(("Format not accepted -> try old method\n"));
     1864                /* The format was probably not accepted; fall back to our old mode. */
     1865                hr = pContext->pDevice->CreateTexture(cWidth,
     1866                                                      cHeight,
     1867                                                      numMipLevels,
     1868                                                      (pSurface->fUsageD3D & ~D3DUSAGE_RENDERTARGET) |  D3DUSAGE_DYNAMIC /* Lockable */,
     1869                                                      pSurface->formatD3D,
     1870                                                      D3DPOOL_DEFAULT,
     1871                                                      &pSurface->u.pTexture,
     1872                                                      &pSurface->hSharedObject /* might result in poor performance */);
     1873                AssertMsgReturn(hr == D3D_OK, ("CreateTexture failed with %x\n", hr), VERR_INTERNAL_ERROR);
     1874            }
     1875
     1876            pSurface->enmD3DResType = VMSVGA3D_D3DRESTYPE_TEXTURE;
     1877        }
     1878    }
     1879
     1880    Assert(hr == D3D_OK);
    18081881
    18091882    if (pSurface->autogenFilter != SVGA3D_TEX_FILTER_NONE)
    18101883    {
    18111884        /* Set the mip map generation filter settings. */
    1812         if (pSurface->flags & SVGA3D_SURFACE_CUBEMAP)
    1813             hr = pSurface->u.pCubeTexture->SetAutoGenFilterType((D3DTEXTUREFILTERTYPE)pSurface->autogenFilter);
     1885        IDirect3DBaseTexture9 *pBaseTexture;
     1886        if (pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_VOLUME_TEXTURE)
     1887            pBaseTexture = pSurface->u.pVolumeTexture;
     1888        else if (pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_CUBE_TEXTURE)
     1889            pBaseTexture = pSurface->u.pCubeTexture;
    18141890        else
    1815             hr = pSurface->u.pTexture->SetAutoGenFilterType((D3DTEXTUREFILTERTYPE)pSurface->autogenFilter);
     1891            pBaseTexture = pSurface->u.pTexture;
     1892        hr = pBaseTexture->SetAutoGenFilterType((D3DTEXTUREFILTERTYPE)pSurface->autogenFilter);
    18161893        AssertMsg(hr == D3D_OK, ("vmsvga3dBackCreateTexture: SetAutoGenFilterType failed with %x\n", hr));
    18171894    }
     
    18241901    Log(("vmsvga3dBackCreateTexture: sync texture\n"));
    18251902
    1826     if (pSurface->flags & SVGA3D_SURFACE_CUBEMAP)
     1903    if (pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_VOLUME_TEXTURE)
     1904    {
     1905        IDirect3DVolumeTexture9 *pVolumeTexture = pSurface->bounce.pVolumeTexture ?
     1906                                                      pSurface->bounce.pVolumeTexture :
     1907                                                      pSurface->u.pVolumeTexture;
     1908
     1909        for (uint32_t i = 0; i < numMipLevels; ++i)
     1910        {
     1911            D3DLOCKED_BOX LockedVolume;
     1912            hr = pVolumeTexture->LockBox(i, &LockedVolume, NULL, D3DLOCK_DISCARD);
     1913            AssertMsgBreak(hr == D3D_OK, ("LockBox failed with %x\n", hr));
     1914
     1915            PVMSVGA3DMIPMAPLEVEL pMipLevel = &pSurface->pMipmapLevels[i];
     1916
     1917            LogFunc(("sync volume texture mipmap level %d (pitch row %x vs %x, slice %x vs %x)\n",
     1918                      i, LockedVolume.RowPitch, pMipLevel->cbSurfacePitch, LockedVolume.SlicePitch, pMipLevel->cbSurfacePlane));
     1919
     1920
     1921            uint8_t *pDst = (uint8_t *)LockedVolume.pBits;
     1922            const uint8_t *pSrc = (uint8_t *)pMipLevel->pSurfaceData;
     1923            for (uint32_t d = 0; d < cDepth; ++d)
     1924            {
     1925                uint8_t *pRowDst = pDst;
     1926                const uint8_t *pRowSrc = pSrc;
     1927                for (uint32_t h = 0; h < pMipLevel->cBlocksY; ++h)
     1928                {
     1929//                    memcpy(pRowDst, pRowSrc, pMipLevel->cbSurfacePitch);
     1930                    pRowDst += LockedVolume.RowPitch;
     1931                    pRowSrc += pMipLevel->cbSurfacePitch;
     1932                }
     1933                pDst += LockedVolume.SlicePitch;
     1934                pSrc += pMipLevel->cbSurfacePlane;
     1935            }
     1936
     1937            hr = pVolumeTexture->UnlockBox(i);
     1938            AssertMsgBreak(hr == D3D_OK, ("UnlockBox failed with %x\n", hr));
     1939
     1940            pMipLevel->fDirty = false;
     1941        }
     1942    }
     1943    else if (pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_CUBE_TEXTURE)
    18271944    {
    18281945        IDirect3DCubeTexture9 *pCubeTexture = pSurface->bounce.pCubeTexture ?
     
    18912008            AssertMsgReturn(hr == D3D_OK, ("vmsvga3dBackCreateTexture: LockRect failed with %x\n", hr), VERR_INTERNAL_ERROR);
    18922009
    1893             Log(("vmsvga3dBackCreateTexture: sync texture mipmap level %d (pitch %x vs %x)\n", i, LockedRect.Pitch, pSurface->pMipmapLevels[i].cbSurfacePitch));
     2010            LogFunc(("sync texture mipmap level %d (pitch %x vs %x)\n", i, LockedRect.Pitch, pSurface->pMipmapLevels[i].cbSurfacePitch));
    18942011
    18952012            uint8_t *pDest = (uint8_t *)LockedRect.pBits;
     
    19142031        Log(("vmsvga3dBackCreateTexture: sync dirty texture from bounce buffer\n"));
    19152032
    1916         if (pSurface->flags & SVGA3D_SURFACE_CUBEMAP)
     2033        if (pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_VOLUME_TEXTURE)
     2034            hr = pContext->pDevice->UpdateTexture(pSurface->bounce.pVolumeTexture, pSurface->u.pVolumeTexture);
     2035        else if (pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_CUBE_TEXTURE)
    19172036            hr = pContext->pDevice->UpdateTexture(pSurface->bounce.pCubeTexture, pSurface->u.pCubeTexture);
    19182037        else
    19192038            hr = pContext->pDevice->UpdateTexture(pSurface->bounce.pTexture, pSurface->u.pTexture);
    1920         AssertMsgReturn(hr == D3D_OK, ("vmsvga3dBackCreateTexture: UpdateTexture failed with %x\n", hr), VERR_INTERNAL_ERROR);
     2039        AssertMsgReturn(hr == D3D_OK, ("UpdateTexture failed with %x\n", hr), VERR_INTERNAL_ERROR);
    19212040
    19222041        /* We will now use the bounce texture for all memory accesses, so free our surface memory buffer. */
     
    19292048    pSurface->fDirty = false;
    19302049
    1931     pSurface->flags              |= SVGA3D_SURFACE_HINT_TEXTURE;
     2050    Assert(pSurface->enmD3DResType != VMSVGA3D_D3DRESTYPE_NONE);
     2051
     2052    pSurface->surfaceFlags       |= SVGA3D_SURFACE_HINT_TEXTURE;
    19322053    pSurface->idAssociatedContext = idAssociatedContext;
    19332054    return VINF_SUCCESS;
     
    19602081    int rc;
    19612082
     2083    AssertReturn(pSrcSurface->enmD3DResType != VMSVGA3D_D3DRESTYPE_VOLUME_TEXTURE, VERR_NOT_IMPLEMENTED);
     2084    AssertReturn(pDstSurface->enmD3DResType != VMSVGA3D_D3DRESTYPE_VOLUME_TEXTURE, VERR_NOT_IMPLEMENTED);
     2085
    19622086    /* Flush the drawing pipeline for this surface as it could be used in a shared context. */
    19632087    vmsvga3dSurfaceFlush(pThis, pSrcSurface);
     
    20422166{
    20432167    HRESULT hr = D3D_OK;
    2044     const uint32_t u32SurfHints = pSurface->flags & VMSVGA3D_SURFACE_HINT_SWITCH_MASK;
     2168    const uint32_t u32SurfHints = pSurface->surfaceFlags & VMSVGA3D_SURFACE_HINT_SWITCH_MASK;
    20452169    const DWORD dwFlags = transfer == SVGA3D_READ_HOST_VRAM ? D3DLOCK_READONLY : 0;
    20462170    // if (u32SurfHints != 0x18 && u32SurfHints != 0x60) ASMBreakpoint();
    20472171
    2048     bool fTexture =    RT_BOOL(u32SurfHints & (SVGA3D_SURFACE_HINT_TEXTURE |
    2049                                                SVGA3D_SURFACE_CUBEMAP))
    2050                     || pSurface->fStencilAsTexture;
    2051 
    2052     bool fRenderTarget = RT_BOOL(u32SurfHints & SVGA3D_SURFACE_HINT_RENDERTARGET);
    2053 
    2054     if (fTexture || fRenderTarget)
     2172    AssertReturn(pSurface->enmD3DResType != VMSVGA3D_D3DRESTYPE_VOLUME_TEXTURE, VERR_NOT_IMPLEMENTED);
     2173
     2174    const bool fTexture =    pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_TEXTURE
     2175                          || pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_CUBE_TEXTURE;
     2176    if (   pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_SURFACE
     2177        || fTexture)
    20552178    {
    20562179        rc = vmsvga3dContextFromCid(pState, pSurface->idAssociatedContext, &pContext);
     
    20682191            {
    20692192                if (   transfer == SVGA3D_READ_HOST_VRAM
    2070                     && fRenderTarget
     2193                    && RT_BOOL(u32SurfHints & SVGA3D_SURFACE_HINT_RENDERTARGET)
    20712194                    && iBox == 0 /* only the first time */)
    20722195                {
     
    21462269        }
    21472270    }
    2148     else if (RT_BOOL(u32SurfHints & (SVGA3D_SURFACE_HINT_VERTEXBUFFER |
    2149                                      SVGA3D_SURFACE_HINT_INDEXBUFFER)))
     2271    else if (   pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_VERTEX_BUFFER
     2272             || pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_INDEX_BUFFER)
    21502273    {
    21512274        /*
     
    21622285
    21632286        /* Current type of the buffer. */
    2164         const bool fVertex = RT_BOOL(pSurface->fu32ActualUsageFlags & SVGA3D_SURFACE_HINT_VERTEXBUFFER);
     2287        const bool fVertex = pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_VERTEX_BUFFER;
    21652288
    21662289        /* Caller already clipped pBox and buffers are 1-dimensional. */
     
    22182341    else
    22192342    {
    2220         AssertMsgFailed(("Unsupported surface hint 0x%08X\n", u32SurfHints));
     2343        AssertMsgFailed(("Unsupported surface hint 0x%08X, type %d\n", u32SurfHints, pSurface->enmD3DResType));
    22212344    }
    22222345
     
    23772500
    23782501        /* Unknown surface type; turn it into a texture. */
    2379         Log(("vmsvga3dGenerateMipmaps: unknown src surface sid=%x type=%d format=%d -> create texture\n", sid, pSurface->flags, pSurface->format));
     2502        LogFunc(("unknown src surface sid=%x type=%d format=%d -> create texture\n", sid, pSurface->surfaceFlags, pSurface->format));
    23802503        rc = vmsvga3dBackCreateTexture(pState, pContext, cid, pSurface);
    23812504        AssertRCReturn(rc, rc);
     
    23842507    {
    23852508        hr = pSurface->u.pTexture->SetAutoGenFilterType((D3DTEXTUREFILTERTYPE)filter);
    2386         AssertMsg(hr == D3D_OK, ("vmsvga3dGenerateMipmaps: SetAutoGenFilterType failed with %x\n", hr));
     2509        AssertMsg(hr == D3D_OK, ("SetAutoGenFilterType failed with %x\n", hr));
    23872510    }
    23882511
     
    23982521    PVMSVGA3DSURFACE    pSurface;
    23992522    PVMSVGA3DCONTEXT    pContext;
    2400     uint32_t            cid;
    24012523    HRESULT             hr;
     2524    int                 rc;
    24022525    IDirect3DSurface9  *pBackBuffer;
    24032526    IDirect3DSurface9  *pSurfaceD3D;
    24042527
    24052528    AssertReturn(pState, VERR_NO_MEMORY);
    2406     AssertReturn(sid < SVGA3D_MAX_SURFACE_IDS, VERR_INVALID_PARAMETER);
    2407     AssertReturn(sid < pState->cSurfaces && pState->papSurfaces[sid]->id == sid, VERR_INVALID_PARAMETER);
    2408 
    2409     pSurface = pState->papSurfaces[sid];
     2529
     2530    rc = vmsvga3dSurfaceFromSid(pState, sid, &pSurface);
     2531    AssertRCReturn(rc, rc);
     2532
    24102533    AssertReturn(pSurface->idAssociatedContext != SVGA3D_INVALID_ID, VERR_INTERNAL_ERROR);
    24112534
    2412     /** @todo stricter checks for associated context */
    2413     cid = pSurface->idAssociatedContext;
    2414     Log(("vmsvga3dCommandPresent: sid=%x cRects=%d cid=%x\n", sid, cRects, cid));
    2415     for (uint32_t i=0; i < cRects; i++)
    2416     {
    2417         Log(("vmsvga3dCommandPresent: rectangle %d src=(%d,%d) (%d,%d)(%d,%d)\n", i, pRect[i].srcx, pRect[i].srcy, pRect[i].x, pRect[i].y, pRect[i].x + pRect[i].w, pRect[i].y + pRect[i].h));
    2418     }
    2419 
    2420     if (    cid >= pState->cContexts
    2421         ||  pState->papContexts[cid]->id != cid)
    2422     {
    2423         Log(("vmsvga3dCommandPresent invalid context id!\n"));
    2424         return VERR_INVALID_PARAMETER;
    2425     }
    2426     pContext = pState->papContexts[cid];
     2535    LogFunc(("sid=%x cRects=%d cid=%x\n", sid, cRects, pSurface->idAssociatedContext));
     2536    for (uint32_t i = 0; i < cRects; ++i)
     2537    {
     2538        LogFunc(("rectangle %d src=(%d,%d) (%d,%d)(%d,%d)\n", i, pRect[i].srcx, pRect[i].srcy, pRect[i].x, pRect[i].y, pRect[i].x + pRect[i].w, pRect[i].y + pRect[i].h));
     2539    }
     2540
     2541    rc = vmsvga3dContextFromCid(pState, pSurface->idAssociatedContext, &pContext);
     2542    AssertRCReturn(rc, rc);
    24272543
    24282544    hr = pContext->pDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer);
    2429     AssertMsgReturn(hr == D3D_OK, ("vmsvga3dCommandPresent: GetBackBuffer failed with %x\n", hr), VERR_INTERNAL_ERROR);
    2430 
    2431     if (pSurface->flags & SVGA3D_SURFACE_HINT_TEXTURE)
    2432     {
    2433         hr = pSurface->u.pTexture->GetSurfaceLevel(0, &pSurfaceD3D);
    2434         AssertMsgReturn(hr == D3D_OK, ("vmsvga3dCommandPresent: GetSurfaceLevel failed with %x\n", hr), VERR_INTERNAL_ERROR);
    2435     }
    2436     else
    2437         pSurfaceD3D = pSurface->u.pSurface;
     2545    AssertMsgReturn(hr == D3D_OK, ("GetBackBuffer failed with %x\n", hr), VERR_INTERNAL_ERROR);
     2546
     2547    rc = vmsvga3dGetD3DSurface(pContext, pSurface, 0, 0, false, &pSurfaceD3D);
     2548    AssertRCReturn(rc, rc);
    24382549
    24392550    /* Read the destination viewport specs in one go to try avoid some unnecessary update races. */
     
    26122723    }
    26132724
    2614     if (pSurface->flags & SVGA3D_SURFACE_HINT_TEXTURE)
    2615         D3D_RELEASE(pSurfaceD3D);
    2616 
    2617     AssertMsgReturn(hr == D3D_OK, ("vmsvga3dCommandPresent: StretchRect failed with %x\n", hr), VERR_INTERNAL_ERROR);
     2725    D3D_RELEASE(pSurfaceD3D);
     2726    D3D_RELEASE(pBackBuffer);
     2727
     2728    AssertMsgReturn(hr == D3D_OK, ("StretchRect failed with %x\n", hr), VERR_INTERNAL_ERROR);
    26182729
    26192730    hr = pContext->pDevice->Present(NULL, NULL, NULL, NULL);
    2620     AssertMsgReturn(hr == D3D_OK, ("vmsvga3dCommandPresent: Present failed with %x\n", hr), VERR_INTERNAL_ERROR);
    2621 
    2622     D3D_RELEASE(pBackBuffer);
     2731    AssertMsgReturn(hr == D3D_OK, ("Present failed with %x\n", hr), VERR_INTERNAL_ERROR);
     2732
    26232733    return VINF_SUCCESS;
    26242734}
     
    27762886                int rc;
    27772887
    2778                 Log(("vmsvga3dContextDestroy: remove all dependencies for surface sid=%x\n", sid));
    2779 
    2780                 uint32_t            surfaceFlags = pSurface->flags;
     2888                LogFunc(("Remove all dependencies for surface sid=%x\n", sid));
     2889
     2890                uint32_t            surfaceFlags = pSurface->surfaceFlags;
    27812891                SVGA3dSurfaceFormat format = pSurface->format;
    27822892                SVGA3dSurfaceFace   face[SVGA3D_MAX_SURFACE_FACES];
     
    28172927                if (pSharedSurface)
    28182928                {
    2819                     Log(("vmsvga3dContextDestroy: remove shared dependency for surface sid=%x\n", sid));
    2820 
    2821                     switch (pSurface->flags & VMSVGA3D_SURFACE_HINT_SWITCH_MASK)
     2929                    LogFunc(("Remove shared dependency for surface sid=%x\n", sid));
     2930
     2931                    switch (pSurface->enmD3DResType)
    28222932                    {
    2823                     case SVGA3D_SURFACE_HINT_TEXTURE:
    2824                     case SVGA3D_SURFACE_HINT_TEXTURE | SVGA3D_SURFACE_HINT_RENDERTARGET:
     2933                    case VMSVGA3D_D3DRESTYPE_TEXTURE:
    28252934                        Assert(pSharedSurface->u.pTexture);
    28262935                        D3D_RELEASE(pSharedSurface->u.pTexture);
     2936                        break;
     2937
     2938                    case VMSVGA3D_D3DRESTYPE_CUBE_TEXTURE:
     2939                        Assert(pSharedSurface->u.pCubeTexture);
     2940                        D3D_RELEASE(pSharedSurface->u.pCubeTexture);
     2941                        break;
     2942
     2943                    case VMSVGA3D_D3DRESTYPE_VOLUME_TEXTURE:
     2944                        Assert(pSharedSurface->u.pVolumeTexture);
     2945                        D3D_RELEASE(pSharedSurface->u.pVolumeTexture);
    28272946                        break;
    28282947
     
    39884107    AssertReturn(pState, VERR_NO_MEMORY);
    39894108    AssertReturn(type < SVGA3D_RT_MAX, VERR_INVALID_PARAMETER);
    3990     AssertReturn(target.face == 0, VERR_INVALID_PARAMETER);
    3991 
    3992     Log(("vmsvga3dSetRenderTarget cid=%x type=%x sid=%x\n", cid, type, target.sid));
    3993 
    3994     if (    cid >= pState->cContexts
    3995         ||  pState->papContexts[cid]->id != cid)
    3996     {
    3997         Log(("vmsvga3dSetRenderTarget invalid context id!\n"));
    3998         return VERR_INVALID_PARAMETER;
    3999     }
    4000     pContext = pState->papContexts[cid];
     4109
     4110    LogFunc(("cid=%x type=%x sid=%x\n", cid, type, target.sid));
     4111
     4112    int rc = vmsvga3dContextFromCid(pState, cid, &pContext);
     4113    AssertRCReturn(rc, rc);
    40014114
    40024115    /* Save for vm state save/restore. */
     
    40104123        case SVGA3D_RT_DEPTH:
    40114124            hr = pContext->pDevice->SetDepthStencilSurface(NULL);
    4012             AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSetRenderTarget: SetDepthStencilSurface failed with %x\n", hr), VERR_INTERNAL_ERROR);
     4125            AssertMsgReturn(hr == D3D_OK, ("SetDepthStencilSurface failed with %x\n", hr), VERR_INTERNAL_ERROR);
    40134126            break;
    40144127
     
    40294142            if (pState->fSupportedSurfaceNULL)
    40304143            {
    4031                 /* Create a dummy render target to satisfy D3D. This path is usually taken only to render into a depth buffer without
    4032                  * wishing to update an actual color render target
     4144                /* Create a dummy render target to satisfy D3D. This path is usually taken only to render
     4145                 * into a depth buffer without wishing to update an actual color render target.
    40334146                 */
    4034                 IDirect3DSurface9* pDummyRenderTarget;
     4147                IDirect3DSurface9 *pDummyRenderTarget;
    40354148                hr = pContext->pDevice->CreateRenderTarget(pThis->svga.uWidth,
    40364149                                                           pThis->svga.uHeight,
     
    40424155                                                           NULL);
    40434156
    4044                 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSetRenderTarget: CreateRenderTarget failed with %x\n", hr), VERR_INTERNAL_ERROR);
     4157                AssertMsgReturn(hr == D3D_OK, ("CreateRenderTarget failed with %x\n", hr), VERR_INTERNAL_ERROR);
    40454158
    40464159                hr = pContext->pDevice->SetRenderTarget(type - SVGA3D_RT_COLOR0, pDummyRenderTarget);
     
    40504163                hr = pContext->pDevice->SetRenderTarget(type - SVGA3D_RT_COLOR0, NULL);
    40514164
    4052             AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSetRenderTarget: SetRenderTarget failed with %x\n", hr), VERR_INTERNAL_ERROR);
     4165            AssertMsgReturn(hr == D3D_OK, ("SetRenderTarget failed with %x\n", hr), VERR_INTERNAL_ERROR);
    40534166            break;
    40544167
     
    40594172    }
    40604173
    4061     AssertReturn(target.sid < SVGA3D_MAX_SURFACE_IDS, VERR_INVALID_PARAMETER);
    4062     AssertReturn(target.sid < pState->cSurfaces && pState->papSurfaces[target.sid]->id == target.sid, VERR_INVALID_PARAMETER);
    4063     pRenderTarget = pState->papSurfaces[target.sid];
     4174    rc = vmsvga3dSurfaceFromSid(pState, target.sid, &pRenderTarget);
     4175    AssertRCReturn(rc, rc);
    40644176
    40654177    switch (type)
     
    40674179    case SVGA3D_RT_DEPTH:
    40684180    case SVGA3D_RT_STENCIL:
    4069         AssertReturn(target.mipmap == 0, VERR_INVALID_PARAMETER);
     4181        AssertReturn(target.face == 0 && target.mipmap == 0, VERR_INVALID_PARAMETER);
    40704182        if (!pRenderTarget->u.pSurface)
    40714183        {
     
    40894201                     || pRenderTarget->formatD3D == D3DFMT_D24X8))
    40904202            {
    4091                 Log(("vmsvga3dSetRenderTarget: Creating stencil surface as texture!\n"));
     4203                LogFunc(("Creating stencil surface as texture!\n"));
    40924204                int rc = vmsvga3dBackCreateTexture(pState, pContext, cid, pRenderTarget);
    4093                 AssertRC(rc);   /* non-fatal */
     4205                AssertRC(rc);   /* non-fatal, will use CreateDepthStencilSurface */
    40944206            }
    40954207
    40964208            if (!pRenderTarget->fStencilAsTexture)
    40974209            {
    4098                 Log(("vmsvga3dSetRenderTarget DEPTH/STENCIL; cQualityLevels=%d\n", cQualityLevels));
     4210                Assert(!pRenderTarget->u.pSurface);
     4211
     4212                LogFunc(("DEPTH/STENCIL; cQualityLevels=%d\n", cQualityLevels));
    40994213                hr = pContext->pDevice->CreateDepthStencilSurface(pRenderTarget->pMipmapLevels[0].mipmapSize.width,
    41004214                                                                  pRenderTarget->pMipmapLevels[0].mipmapSize.height,
     
    41054219                                                                  &pRenderTarget->u.pSurface,
    41064220                                                                  NULL);
    4107                 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSetRenderTarget: CreateDepthStencilSurface failed with %x\n", hr), VERR_INTERNAL_ERROR);
     4221                AssertMsgReturn(hr == D3D_OK, ("CreateDepthStencilSurface failed with %x\n", hr), VERR_INTERNAL_ERROR);
     4222                pRenderTarget->enmD3DResType = VMSVGA3D_D3DRESTYPE_SURFACE;
    41084223            }
    41094224
     
    41574272
    41584273        pRenderTarget->fUsageD3D            |= D3DUSAGE_DEPTHSTENCIL;
    4159         pRenderTarget->flags                |= SVGA3D_SURFACE_HINT_DEPTHSTENCIL;
     4274        pRenderTarget->surfaceFlags         |= SVGA3D_SURFACE_HINT_DEPTHSTENCIL;
    41604275
    41614276        if (pRenderTarget->fStencilAsTexture)
     
    41644279
    41654280            hr = pRenderTarget->u.pTexture->GetSurfaceLevel(0, &pStencilSurface);
    4166             AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSetRenderTarget: GetSurfaceLevel failed with %x\n", hr), VERR_INTERNAL_ERROR);
     4281            AssertMsgReturn(hr == D3D_OK, ("GetSurfaceLevel failed with %x\n", hr), VERR_INTERNAL_ERROR);
    41674282
    41684283            hr = pContext->pDevice->SetDepthStencilSurface(pStencilSurface);
    41694284            D3D_RELEASE(pStencilSurface);
    4170             AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSetRenderTarget: SetDepthStencilSurface failed with %x\n", hr), VERR_INTERNAL_ERROR);
     4285            AssertMsgReturn(hr == D3D_OK, ("SetDepthStencilSurface failed with %x\n", hr), VERR_INTERNAL_ERROR);
    41714286        }
    41724287        else
    41734288        {
    41744289            hr = pContext->pDevice->SetDepthStencilSurface(pRenderTarget->u.pSurface);
    4175             AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSetRenderTarget: SetDepthStencilSurface failed with %x\n", hr), VERR_INTERNAL_ERROR);
     4290            AssertMsgReturn(hr == D3D_OK, ("SetDepthStencilSurface failed with %x\n", hr), VERR_INTERNAL_ERROR);
    41764291        }
    41774292        break;
     
    41884303        IDirect3DSurface9 *pSurface;
    41894304        bool fTexture = false;
    4190         bool fShared = false;
    41914305
    41924306        /* Must flush the other context's 3d pipeline to make sure all drawing is complete for the surface we're about to use. */
    41934307        vmsvga3dSurfaceFlush(pThis, pRenderTarget);
    41944308
    4195         if (pRenderTarget->flags & SVGA3D_SURFACE_HINT_TEXTURE)
     4309        if (pRenderTarget->surfaceFlags & SVGA3D_SURFACE_HINT_TEXTURE)
    41964310        {
    41974311            fTexture = true;
     
    42004314            if (!pRenderTarget->u.pTexture)
    42014315            {
    4202                 Log(("vmsvga3dSetRenderTarget: create texture to be used as render target; sid=%x type=%d format=%d -> create texture\n", target.sid, pRenderTarget->flags, pRenderTarget->format));
     4316                LogFunc(("Create texture to be used as render target; sid=%x type=%d format=%d -> create texture\n", target.sid, pRenderTarget->surfaceFlags, pRenderTarget->format));
    42034317                int rc = vmsvga3dBackCreateTexture(pState, pContext, cid, pRenderTarget);
    42044318                AssertRCReturn(rc, rc);
    42054319            }
    42064320
    4207 #ifndef VBOX_VMSVGA3D_WITH_WINE_OPENGL
    4208             if (pRenderTarget->idAssociatedContext != cid)
    4209             {
    4210                 Log(("vmsvga3dSetRenderTarget; using texture sid=%x created for another context (%d vs %d)\n", target.sid, pRenderTarget->idAssociatedContext, cid));
    4211 
    4212                 PVMSVGA3DSHAREDSURFACE pSharedSurface = vmsvga3dSurfaceGetSharedCopy(pContext, pRenderTarget);
    4213                 AssertReturn(pSharedSurface, VERR_INTERNAL_ERROR);
    4214 
    4215                 hr = pSharedSurface->u.pTexture->GetSurfaceLevel(target.mipmap,
    4216                                                                  &pSurface);
    4217 
    4218                 fShared = true;
    4219             }
    4220             else
    4221 #endif
    4222                 hr = pRenderTarget->u.pTexture->GetSurfaceLevel(target.mipmap,
    4223                                                                 &pSurface);
    4224 
    4225             AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSetRenderTarget: GetSurfaceLevel failed with %x\n", hr), VERR_INTERNAL_ERROR);
     4321            rc = vmsvga3dGetD3DSurface(pContext,  pRenderTarget, target.face, target.mipmap, false, &pSurface);
     4322            AssertRCReturn(rc, rc);
    42264323        }
    42274324        else
    42284325        {
    4229             AssertReturn(target.mipmap == 0, VERR_INVALID_PARAMETER);
     4326            AssertReturn(target.face == 0 && target.mipmap == 0, VERR_INVALID_PARAMETER);
    42304327            if (!pRenderTarget->u.pSurface)
    42314328            {
     
    42444341                }
    42454342
    4246                 Log(("vmsvga3dSetRenderTarget COLOR; cQualityLevels=%d\n", cQualityLevels));
    4247                 Log(("Create rendertarget (%d,%d) format=%x multisample=%x\n", pRenderTarget->pMipmapLevels[0].mipmapSize.width, pRenderTarget->pMipmapLevels[0].mipmapSize.height, pRenderTarget->formatD3D, pRenderTarget->multiSampleTypeD3D));
     4343                LogFunc(("COLOR; cQualityLevels=%d\n", cQualityLevels));
     4344                LogFunc(("Create rendertarget (%d,%d) formatD3D=%x multisample=%x\n",
     4345                         pRenderTarget->pMipmapLevels[0].mipmapSize.width, pRenderTarget->pMipmapLevels[0].mipmapSize.height, pRenderTarget->formatD3D, pRenderTarget->multiSampleTypeD3D));
    42484346
    42494347                hr = pContext->pDevice->CreateRenderTarget(pRenderTarget->pMipmapLevels[0].mipmapSize.width,
     
    42574355                AssertReturn(hr == D3D_OK, VERR_INTERNAL_ERROR);
    42584356
    4259                 pRenderTarget->idAssociatedContext   = cid;
     4357                pRenderTarget->idAssociatedContext = cid;
     4358                pRenderTarget->enmD3DResType       = VMSVGA3D_D3DRESTYPE_SURFACE;
    42604359            }
    42614360            else
     
    42634362
    42644363            Assert(pRenderTarget->idAssociatedContext == cid);
     4364            Assert(pRenderTarget->enmD3DResType == VMSVGA3D_D3DRESTYPE_SURFACE);
    42654365            pSurface = pRenderTarget->u.pSurface;
    42664366        }
     
    42704370
    42714371        pRenderTarget->fUsageD3D            |= D3DUSAGE_RENDERTARGET;
    4272         pRenderTarget->flags                |= SVGA3D_SURFACE_HINT_RENDERTARGET;
     4372        pRenderTarget->surfaceFlags         |= SVGA3D_SURFACE_HINT_RENDERTARGET;
    42734373
    42744374        hr = pContext->pDevice->SetRenderTarget(type - SVGA3D_RT_COLOR0, pSurface);
    42754375        if (fTexture)
    42764376            D3D_RELEASE(pSurface);    /* Release reference to texture level 0 */
    4277         AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSetRenderTarget: SetRenderTarget failed with %x\n", hr), VERR_INTERNAL_ERROR);
     4377        AssertMsgReturn(hr == D3D_OK, ("SetRenderTarget failed with %x\n", hr), VERR_INTERNAL_ERROR);
    42784378
    42794379        pContext->sidRenderTarget = target.sid;
     
    44184518    AssertReturn(pState, VERR_NO_MEMORY);
    44194519
    4420     Log(("vmsvga3dSetTextureState %x cTextureState=%d\n", cid, cTextureStates));
    4421 
    4422     if (    cid >= pState->cContexts
    4423         ||  pState->papContexts[cid]->id != cid)
    4424     {
    4425         Log(("vmsvga3dSetTextureState invalid context id!\n"));
    4426         return VERR_INVALID_PARAMETER;
    4427     }
    4428     pContext = pState->papContexts[cid];
     4520    LogFunc(("%x cTextureState=%d\n", cid, cTextureStates));
     4521
     4522    int rc = vmsvga3dContextFromCid(pState, cid, &pContext);
     4523    AssertRCReturn(rc, rc);
    44294524
    44304525    for (unsigned i = 0; i < cTextureStates; i++)
     
    44344529        uint32_t                 currentStage = pTextureState[i].stage;
    44354530
    4436         Log(("vmsvga3dSetTextureState: cid=%x stage=%d type=%s (%x) val=%x\n", cid, currentStage, vmsvga3dTextureStateToString(pTextureState[i].name), pTextureState[i].name, pTextureState[i].value));
     4531        LogFunc(("cid=%x stage=%d type=%s (%x) val=%x\n", cid, currentStage, vmsvga3dTextureStateToString(pTextureState[i].name), pTextureState[i].name, pTextureState[i].value));
    44374532
    44384533        /** @todo Is this the appropriate limit for all kinds of textures?  It is the
     
    44404535        if (RT_UNLIKELY(currentStage >= SVGA3D_MAX_TEXTURE_STAGE))
    44414536        {
    4442             AssertMsgFailed(("pTextureState[%d].stage=%#x name=%#x\n", i, pTextureState[i].stage, pTextureState[i].name));
     4537            AssertMsgFailed(("pTextureState[%d].stage=%#x name=%#x value=%#x\n", i, pTextureState[i].stage, pTextureState[i].name, pTextureState[i].value));
    44434538            continue;
    44444539        }
     
    45414636                /* Unselect the currently associated texture. */
    45424637                hr = pContext->pDevice->SetTexture(currentStage, NULL);
    4543                 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSetTextureState: SetTexture failed with %x\n", hr), VERR_INTERNAL_ERROR);
     4638                AssertMsgReturn(hr == D3D_OK, ("SetTexture failed with %x\n", hr), VERR_INTERNAL_ERROR);
    45444639            }
    45454640            else
    45464641            {
    4547                 HRESULT hr;
    4548                 uint32_t sid = pTextureState[i].value;
    4549 
    4550                 AssertReturn(sid < SVGA3D_MAX_SURFACE_IDS, VERR_INVALID_PARAMETER);
    4551                 AssertReturn(sid < pState->cSurfaces && pState->papSurfaces[sid]->id == sid, VERR_INVALID_PARAMETER);
    4552 
    4553                 PVMSVGA3DSURFACE pSurface = pState->papSurfaces[sid];
     4642                PVMSVGA3DSURFACE pSurface;
     4643                const uint32_t sid = pTextureState[i].value;
     4644
     4645                rc = vmsvga3dSurfaceFromSid(pState, sid, &pSurface);
     4646                AssertRCReturn(rc, rc);
    45544647
    45554648                Log(("SVGA3D_TS_BIND_TEXTURE: stage %d, texture sid=%x (%d,%d)\n", currentStage, pTextureState[i].value, pSurface->pMipmapLevels[0].mipmapSize.width, pSurface->pMipmapLevels[0].mipmapSize.height));
     
    45584651                {
    45594652                    Assert(pSurface->idAssociatedContext == SVGA3D_INVALID_ID);
    4560                     Log(("CreateTexture (%d,%d) level=%d fUsage=%x format=%x\n", pSurface->pMipmapLevels[0].mipmapSize.width, pSurface->pMipmapLevels[0].mipmapSize.height, pSurface->faces[0].numMipLevels, pSurface->fUsageD3D, pSurface->formatD3D));
    4561                     int rc = vmsvga3dBackCreateTexture(pState, pContext, cid, pSurface);
     4653                    LogFunc(("CreateTexture (%d,%d) level=%d fUsage=%x format=%x\n", pSurface->pMipmapLevels[0].mipmapSize.width, pSurface->pMipmapLevels[0].mipmapSize.height, pSurface->faces[0].numMipLevels, pSurface->fUsageD3D, pSurface->formatD3D));
     4654                    rc = vmsvga3dBackCreateTexture(pState, pContext, cid, pSurface);
    45624655                    AssertRCReturn(rc, rc);
    45634656                }
     
    45714664                if (pSurface->idAssociatedContext != cid)
    45724665                {
    4573                     Log(("vmsvga3dSetTextureState; using texture sid=%x created for another context (%d vs %d)\n", sid, pSurface->idAssociatedContext, cid));
     4666                    LogFunc(("using texture sid=%x created for another context (%d vs %d)\n", sid, pSurface->idAssociatedContext, cid));
    45744667
    45754668                    PVMSVGA3DSHAREDSURFACE pSharedSurface = vmsvga3dSurfaceGetSharedCopy(pContext, pSurface);
     
    45824675                    hr = pContext->pDevice->SetTexture(currentStage, pSurface->u.pTexture);
    45834676
    4584                 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSetTextureState: SetTexture failed with %x\n", hr), VERR_INTERNAL_ERROR);
     4677                AssertMsgReturn(hr == D3D_OK, ("SetTexture failed with %x\n", hr), VERR_INTERNAL_ERROR);
    45854678
    45864679                pContext->aSidActiveTexture[currentStage] = sid;
     
    46914784    AssertReturn(pState, VERR_NO_MEMORY);
    46924785
    4693     Log(("vmsvga3dSetMaterial %x face %d\n", cid, face));
    4694 
    4695     if (    cid >= pState->cContexts
    4696         ||  pState->papContexts[cid]->id != cid)
    4697     {
    4698         Log(("vmsvga3dSetMaterial invalid context id!\n"));
    4699         return VERR_INVALID_PARAMETER;
    4700     }
    4701     pContext = pState->papContexts[cid];
     4786    LogFunc(("cid=%x face %d\n", cid, face));
     4787
     4788    int rc = vmsvga3dContextFromCid(pState, cid, &pContext);
     4789    AssertRCReturn(rc, rc);
    47024790
    47034791    AssertReturn(face < SVGA3D_FACE_MAX, VERR_INVALID_PARAMETER);
     
    47334821
    47344822    hr = pContext->pDevice->SetMaterial(&material);
    4735     AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSetMaterial: SetMaterial failed with %x\n", hr), VERR_INTERNAL_ERROR);
     4823    AssertMsgReturn(hr == D3D_OK, ("SetMaterial failed with %x\n", hr), VERR_INTERNAL_ERROR);
    47364824
    47374825    return VINF_SUCCESS;
     
    47484836    Log(("vmsvga3dSetLightData %x index=%d\n", cid, index));
    47494837
    4750     if (    cid >= pState->cContexts
    4751         ||  pState->papContexts[cid]->id != cid)
    4752     {
    4753         Log(("vmsvga3dSetLightData invalid context id!\n"));
    4754         return VERR_INVALID_PARAMETER;
    4755     }
    4756     pContext = pState->papContexts[cid];
     4838    int rc = vmsvga3dContextFromCid(pState, cid, &pContext);
     4839    AssertRCReturn(rc, rc);
    47574840
    47584841    switch (pData->type)
     
    48124895
    48134896    hr = pContext->pDevice->SetLight(index, &light);
    4814     AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSetLightData: SetLight failed with %x\n", hr), VERR_INTERNAL_ERROR);
     4897    AssertMsgReturn(hr == D3D_OK, ("SetLight failed with %x\n", hr), VERR_INTERNAL_ERROR);
    48154898
    48164899    return VINF_SUCCESS;
     
    48264909    Log(("vmsvga3dSetLightEnabled %x %d -> %d\n", cid, index, enabled));
    48274910
    4828     if (    cid >= pState->cContexts
    4829         ||  pState->papContexts[cid]->id != cid)
    4830     {
    4831         Log(("vmsvga3dSetLightEnabled invalid context id!\n"));
    4832         return VERR_INVALID_PARAMETER;
    4833     }
    4834     pContext = pState->papContexts[cid];
     4911    int rc = vmsvga3dContextFromCid(pState, cid, &pContext);
     4912    AssertRCReturn(rc, rc);
    48354913
    48364914    /* Store for vm state save/restore */
     
    48414919
    48424920    hr = pContext->pDevice->LightEnable(index, (BOOL)enabled);
    4843     AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSetLightEnabled: LightEnable failed with %x\n", hr), VERR_INTERNAL_ERROR);
     4921    AssertMsgReturn(hr == D3D_OK, ("LightEnable failed with %x\n", hr), VERR_INTERNAL_ERROR);
    48444922
    48454923    return VINF_SUCCESS;
     
    48564934    Log(("vmsvga3dSetViewPort %x (%d,%d)(%d,%d)\n", cid, pRect->x, pRect->y, pRect->w, pRect->h));
    48574935
    4858     if (    cid >= pState->cContexts
    4859         ||  pState->papContexts[cid]->id != cid)
    4860     {
    4861         Log(("vmsvga3dSetViewPort invalid context id!\n"));
    4862         return VERR_INVALID_PARAMETER;
    4863     }
     4936    int rc = vmsvga3dContextFromCid(pState, cid, &pContext);
     4937    AssertRCReturn(rc, rc);
     4938
    48644939    /* Save for vm state save/restore. */
    4865     pContext = pState->papContexts[cid];
    48664940    pContext->state.RectViewPort = *pRect;
    48674941    pContext->state.u32UpdateFlags |= VMSVGA3D_UPDATE_VIEWPORT;
    48684942
    48694943    hr = pContext->pDevice->GetViewport(&viewPort);
    4870     AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSetViewPort: GetViewport failed with %x\n", hr), VERR_INTERNAL_ERROR);
     4944    AssertMsgReturn(hr == D3D_OK, ("GetViewport failed with %x\n", hr), VERR_INTERNAL_ERROR);
    48714945
    48724946    viewPort.X      = pRect->x;
     
    48774951
    48784952    hr = pContext->pDevice->SetViewport(&viewPort);
    4879     AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSetViewPort: SetViewport failed with %x\n", hr), VERR_INTERNAL_ERROR);
     4953    AssertMsgReturn(hr == D3D_OK, ("SetViewport failed with %x\n", hr), VERR_INTERNAL_ERROR);
    48804954
    48814955    return VINF_SUCCESS;
    48824956}
    48834957
    4884 int vmsvga3dSetClipPlane(PVGASTATE pThis, uint32_t cid,  uint32_t index, float plane[4])
     4958int vmsvga3dSetClipPlane(PVGASTATE pThis, uint32_t cid, uint32_t index, float plane[4])
    48854959{
    48864960    HRESULT               hr;
     
    48924966    AssertReturn(index < SVGA3D_CLIPPLANE_MAX, VERR_INVALID_PARAMETER);
    48934967
    4894     if (    cid >= pState->cContexts
    4895         ||  pState->papContexts[cid]->id != cid)
    4896     {
    4897         Log(("vmsvga3dSetClipPlane invalid context id!\n"));
    4898         return VERR_INVALID_PARAMETER;
    4899     }
    4900     pContext = pState->papContexts[cid];
     4968    int rc = vmsvga3dContextFromCid(pState, cid, &pContext);
     4969    AssertRCReturn(rc, rc);
    49014970
    49024971    /* Store for vm state save/restore. */
     
    49054974
    49064975    hr = pContext->pDevice->SetClipPlane(index, plane);
    4907     AssertMsgReturn(hr == D3D_OK, ("vmsvga3dSetClipPlane: SetClipPlane failed with %x\n", hr), VERR_INTERNAL_ERROR);
     4976    AssertMsgReturn(hr == D3D_OK, ("SetClipPlane failed with %x\n", hr), VERR_INTERNAL_ERROR);
    49084977    return VINF_SUCCESS;
    49094978}
     
    49204989    Log(("vmsvga3dCommandClear %x clearFlag=%x color=%x depth=%d stencil=%x cRects=%d\n", cid, clearFlag, color, (uint32_t)(depth * 100.0), stencil, cRects));
    49214990
    4922     if (    cid >= pState->cContexts
    4923         ||  pState->papContexts[cid]->id != cid)
    4924     {
    4925         Log(("vmsvga3dCommandClear invalid context id!\n"));
    4926         return VERR_INVALID_PARAMETER;
    4927     }
    4928     pContext = pState->papContexts[cid];
     4991    int rc = vmsvga3dContextFromCid(pState, cid, &pContext);
     4992    AssertRCReturn(rc, rc);
    49294993
    49304994    if (clearFlag & SVGA3D_CLEAR_COLOR)
     
    49545018        RTMemFree(pRectD3D);
    49555019
    4956     AssertMsgReturn(hr == D3D_OK, ("vmsvga3dCommandClear: Clear failed with %x\n", hr), VERR_INTERNAL_ERROR);
     5020    AssertMsgReturn(hr == D3D_OK, ("Clear failed with %x\n", hr), VERR_INTERNAL_ERROR);
    49575021
    49585022    /* Make sure we can track drawing usage of active render targets. */
     
    49645028
    49655029/* Convert VMWare vertex declaration to its D3D equivalent. */
    4966 int vmsvga3dVertexDecl2D3D(SVGA3dVertexArrayIdentity &identity, D3DVERTEXELEMENT9 *pVertexElement)
     5030static int vmsvga3dVertexDecl2D3D(SVGA3dVertexArrayIdentity &identity, D3DVERTEXELEMENT9 *pVertexElement)
    49675031{
    49685032    /* usage, method and type are identical; make sure. */
     
    49845048
    49855049/* Convert VMWare primitive type to its D3D equivalent. */
    4986 int vmsvga3dPrimitiveType2D3D(SVGA3dPrimitiveType PrimitiveType, D3DPRIMITIVETYPE *pPrimitiveTypeD3D)
     5050static int vmsvga3dPrimitiveType2D3D(SVGA3dPrimitiveType PrimitiveType, D3DPRIMITIVETYPE *pPrimitiveTypeD3D)
    49875051{
    49885052    switch (PrimitiveType)
     
    50125076}
    50135077
    5014 int vmsvga3dDrawPrimitivesProcessVertexDecls(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext, uint32_t numVertexDecls, SVGA3dVertexDecl *pVertexDecl, uint32_t idStream, D3DVERTEXELEMENT9 *pVertexElement)
     5078static int vmsvga3dDrawPrimitivesProcessVertexDecls(PVMSVGA3DSTATE pState, PVMSVGA3DCONTEXT pContext, uint32_t numVertexDecls, SVGA3dVertexDecl *pVertexDecl, uint32_t idStream, D3DVERTEXELEMENT9 *pVertexElement)
    50155079{
    50165080    HRESULT               hr;
     
    50475111            uVertexMinOffset = pVertexDecl[iVertex].array.offset;
    50485112
    5049         /* pVertexSurface->u. is an union, so pVertexSurface->u.pIndexBuffer and pVertexSurface->u.pVertexBuffer are the same */
    5050         if (   pVertexSurface->u.pVertexBuffer
    5051             && !(pVertexSurface->fu32ActualUsageFlags & SVGA3D_SURFACE_HINT_VERTEXBUFFER))
     5113        if (   pVertexSurface->u.pSurface
     5114            && pVertexSurface->enmD3DResType != VMSVGA3D_D3DRESTYPE_VERTEX_BUFFER)
    50525115        {
    50535116            /* The buffer object is not an vertex one. Switch type. */
    5054             Assert(pVertexSurface->fu32ActualUsageFlags & SVGA3D_SURFACE_HINT_INDEXBUFFER);
    5055             pVertexSurface->fu32ActualUsageFlags &= ~SVGA3D_SURFACE_HINT_INDEXBUFFER;
    5056 
     5117            Assert(pVertexSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_INDEX_BUFFER);
    50575118            D3D_RELEASE(pVertexSurface->u.pIndexBuffer);
     5119            pVertexSurface->enmD3DResType = VMSVGA3D_D3DRESTYPE_NONE;
     5120
    50585121            LogFunc(("index -> vertex buffer sid=%x\n", sidVertex));
    50595122        }
     
    50635126            Assert(iVertex == 0);
    50645127
    5065             Log(("vmsvga3dDrawPrimitives: create vertex buffer fDirty=%d\n", pVertexSurface->fDirty));
     5128            LogFunc(("create vertex buffer fDirty=%d\n", pVertexSurface->fDirty));
    50665129            hr = pContext->pDevice->CreateVertexBuffer(pVertexSurface->pMipmapLevels[0].cbSurface,
    50675130                                                       D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY /* possible severe performance penalty otherwise (according to d3d debug output) */,
     
    50705133                                                       &pVertexSurface->u.pVertexBuffer,
    50715134                                                       NULL);
    5072             AssertMsgReturn(hr == D3D_OK, ("vmsvga3dDrawPrimitives: CreateVertexBuffer failed with %x\n", hr), VERR_INTERNAL_ERROR);
    5073 
     5135            AssertMsgReturn(hr == D3D_OK, ("CreateVertexBuffer failed with %x\n", hr), VERR_INTERNAL_ERROR);
     5136
     5137            pVertexSurface->enmD3DResType = VMSVGA3D_D3DRESTYPE_VERTEX_BUFFER;
    50745138            pVertexSurface->idAssociatedContext = pContext->id;
    50755139
     
    50795143
    50805144                hr = pVertexSurface->u.pVertexBuffer->Lock(0, 0, &pData, 0);
    5081                 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dDrawPrimitives: Lock vertex failed with %x\n", hr), VERR_INTERNAL_ERROR);
     5145                AssertMsgReturn(hr == D3D_OK, ("Lock vertex failed with %x\n", hr), VERR_INTERNAL_ERROR);
    50825146
    50835147                memcpy(pData, pVertexSurface->pMipmapLevels[0].pSurfaceData, pVertexSurface->pMipmapLevels[0].cbSurface);
    50845148
    50855149                hr = pVertexSurface->u.pVertexBuffer->Unlock();
    5086                 AssertMsgReturn(hr == D3D_OK, ("vmsvga3dDrawPrimitives: Unlock vertex failed with %x\n", hr), VERR_INTERNAL_ERROR);
     5150                AssertMsgReturn(hr == D3D_OK, ("Unlock vertex failed with %x\n", hr), VERR_INTERNAL_ERROR);
    50875151                pVertexSurface->pMipmapLevels[0].fDirty = false;
    50885152                pVertexSurface->fDirty = false;
    50895153            }
    5090             pVertexSurface->flags |= SVGA3D_SURFACE_HINT_VERTEXBUFFER;
    5091             pVertexSurface->fu32ActualUsageFlags |= SVGA3D_SURFACE_HINT_VERTEXBUFFER;
     5154            pVertexSurface->surfaceFlags |= SVGA3D_SURFACE_HINT_VERTEXBUFFER;
    50925155        }
    50935156    }
     
    50995162#ifdef LOG_ENABLED
    51005163        if (pVertexElement[iVertex].Offset >= pVertexDecl[0].array.stride)
    5101             Log(("vmsvga3dDrawPrimitives: WARNING: offset > stride!!\n"));
     5164            LogFunc(("WARNING: offset > stride!!\n"));
    51025165#endif
    51035166
    5104         Log(("vmsvga3dDrawPrimitives: vertex %d offset = %d (stride %d) (min=%d max=%d)\n", iVertex, pVertexDecl[iVertex].array.offset, pVertexDecl[iVertex].array.stride, uVertexMinOffset, uVertexMaxOffset));
     5167        LogFunc(("vertex %d offset = %d (stride %d) (min=%d max=%d)\n", iVertex, pVertexDecl[iVertex].array.offset, pVertexDecl[iVertex].array.stride, uVertexMinOffset, uVertexMaxOffset));
    51055168    }
    51065169
     
    51115174    pVertexSurface = pState->papSurfaces[sidVertex];
    51125175
    5113     Log(("vmsvga3dDrawPrimitives: SetStreamSource %d min offset=%d stride=%d\n", idStream, uVertexMinOffset, strideVertex));
     5176    LogFunc(("SetStreamSource %d min offset=%d stride=%d\n", idStream, uVertexMinOffset, strideVertex));
    51145177    hr = pContext->pDevice->SetStreamSource(idStream,
    51155178                                            pVertexSurface->u.pVertexBuffer,
     
    51175180                                            strideVertex);
    51185181
    5119     AssertMsgReturn(hr == D3D_OK, ("vmsvga3dDrawPrimitives: SetStreamSource failed with %x\n", hr), VERR_INTERNAL_ERROR);
     5182    AssertMsgReturn(hr == D3D_OK, ("SetStreamSource failed with %x\n", hr), VERR_INTERNAL_ERROR);
    51205183    return VINF_SUCCESS;
    51215184}
     
    51365199    D3DVERTEXELEMENT9            VertexEnd = D3DDECL_END();
    51375200
    5138     Log(("vmsvga3dDrawPrimitives %x numVertexDecls=%d numRanges=%d, cVertexDivisor=%d\n", cid, numVertexDecls, numRanges, cVertexDivisor));
     5201    LogFunc(("%x numVertexDecls=%d numRanges=%d, cVertexDivisor=%d\n", cid, numVertexDecls, numRanges, cVertexDivisor));
    51395202
    51405203    AssertReturn(numVertexDecls && numVertexDecls <= SVGA3D_MAX_VERTEX_ARRAYS, VERR_INVALID_PARAMETER);
     
    51445207    Assert(!cVertexDivisor);
    51455208
    5146     if (    cid >= pState->cContexts
    5147         ||  pState->papContexts[cid]->id != cid)
    5148     {
    5149         Log(("vmsvga3dDrawPrimitives invalid context id!\n"));
    5150         return VERR_INVALID_PARAMETER;
    5151     }
    5152 
    5153     pContext = pState->papContexts[cid];
     5209    rc = vmsvga3dContextFromCid(pState, cid, &pContext);
     5210    AssertRCReturn(rc, rc);
    51545211
    51555212    /* Begin a scene before rendering anything. */
     
    52465303            AssertMsg(pRange[iPrimitive].indexWidth == sizeof(uint32_t) || pRange[iPrimitive].indexWidth == sizeof(uint16_t), ("Unsupported primitive width %d\n", pRange[iPrimitive].indexWidth));
    52475304
    5248             if (    sidIndex >= SVGA3D_MAX_SURFACE_IDS
    5249                 ||  sidIndex >= pState->cSurfaces
    5250                 ||  pState->papSurfaces[sidIndex]->id != sidIndex)
    5251             {
    5252                 Assert(sidIndex < SVGA3D_MAX_SURFACE_IDS);
    5253                 Assert(sidIndex < pState->cSurfaces && pState->papSurfaces[sidIndex]->id == sidIndex);
    5254                 rc = VERR_INVALID_PARAMETER;
     5305            rc = vmsvga3dSurfaceFromSid(pState, sidIndex, &pIndexSurface);
     5306            if (RT_FAILURE(rc))
    52555307                goto internal_error;
    5256             }
    5257             pIndexSurface = pState->papSurfaces[sidIndex];
     5308
    52585309            Log(("vmsvga3dDrawPrimitives: index sid=%x\n", sidIndex));
    52595310
    5260             /* pIndexSurface->u. is an union, so pIndexSurface->u.pIndexBuffer and pIndexSurface->u.pVertexBuffer are the same */
    5261             if (   pIndexSurface->u.pIndexBuffer
    5262                 && !(pIndexSurface->fu32ActualUsageFlags & SVGA3D_SURFACE_HINT_INDEXBUFFER))
     5311            if (   pIndexSurface->u.pSurface
     5312                && pIndexSurface->enmD3DResType != VMSVGA3D_D3DRESTYPE_INDEX_BUFFER)
    52635313            {
    52645314                /* The buffer object is not an index one. Switch type. */
    5265                 Assert(pIndexSurface->fu32ActualUsageFlags & SVGA3D_SURFACE_HINT_VERTEXBUFFER);
    5266                 pIndexSurface->fu32ActualUsageFlags &= ~SVGA3D_SURFACE_HINT_VERTEXBUFFER;
    5267 
     5315                Assert(pIndexSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_VERTEX_BUFFER);
    52685316                D3D_RELEASE(pIndexSurface->u.pVertexBuffer);
     5317                pIndexSurface->enmD3DResType = VMSVGA3D_D3DRESTYPE_NONE;
     5318
    52695319                LogFunc(("vertex -> index buffer sid=%x\n", sidIndex));
    52705320            }
     
    52865336                    goto internal_error;
    52875337                }
     5338                pIndexSurface->enmD3DResType = VMSVGA3D_D3DRESTYPE_INDEX_BUFFER;
    52885339
    52895340                if (pIndexSurface->fDirty)
     
    53045355                    pIndexSurface->fDirty = false;
    53055356                }
    5306                 pIndexSurface->flags |= SVGA3D_SURFACE_HINT_INDEXBUFFER;
    5307                 pIndexSurface->fu32ActualUsageFlags |= SVGA3D_SURFACE_HINT_INDEXBUFFER;
     5357                pIndexSurface->surfaceFlags |= SVGA3D_SURFACE_HINT_INDEXBUFFER;
    53085358            }
    53095359
    53105360            hr = pContext->pDevice->SetIndices(pIndexSurface->u.pIndexBuffer);
    5311             AssertMsg(hr == D3D_OK, ("vmsvga3dDrawPrimitives: SetIndices vertex failed with %x\n", hr));
     5361            AssertMsg(hr == D3D_OK, ("SetIndices vertex failed with %x\n", hr));
    53125362        }
    53135363        else
    53145364        {
    53155365            hr = pContext->pDevice->SetIndices(NULL);
    5316             AssertMsg(hr == D3D_OK, ("vmsvga3dDrawPrimitives: SetIndices vertex (NULL) failed with %x\n", hr));
     5366            AssertMsg(hr == D3D_OK, ("SetIndices vertex (NULL) failed with %x\n", hr));
    53175367        }
    53185368
  • trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d.cpp

    r69136 r69153  
    209209    }
    210210
    211     pSurface->flags             = surfaceFlags;
     211    pSurface->surfaceFlags      = surfaceFlags;
    212212    pSurface->format            = format;
    213213    memcpy(pSurface->faces, face, sizeof(pSurface->faces));
     
    242242    if (surfaceFlags & SVGA3D_SURFACE_AUTOGENMIPMAPS)
    243243        pSurface->fUsageD3D |= D3DUSAGE_AUTOGENMIPMAP;
    244     pSurface->fu32ActualUsageFlags = 0;
     244    pSurface->enmD3DResType = VMSVGA3D_D3DRESTYPE_NONE;
     245    /* pSurface->u.pSurface = NULL; */
     246    /* pSurface->bounce.pTexture = NULL; */
    245247#else
    246248    vmsvga3dSurfaceFormat2OGL(pSurface, format);
     
    429431    {
    430432        /* Unknown surface type; turn it into a texture, which can be used for other purposes too. */
    431         LogFunc(("unknown src sid=%x type=%d format=%d -> create texture\n", sidSrc, pSrcSurface->flags, pSrcSurface->format));
     433        LogFunc(("unknown src sid=%x type=%d format=%d -> create texture\n", sidSrc, pSrcSurface->surfaceFlags, pSrcSurface->format));
    432434        rc = vmsvga3dBackCreateTexture(pState, pContext, pContext->id, pSrcSurface);
    433435        AssertRCReturn(rc, rc);
     
    437439    {
    438440        /* Unknown surface type; turn it into a texture, which can be used for other purposes too. */
    439         LogFunc(("unknown dest sid=%x type=%d format=%d -> create texture\n", sidDst, pDstSurface->flags, pDstSurface->format));
     441        LogFunc(("unknown dest sid=%x type=%d format=%d -> create texture\n", sidDst, pDstSurface->surfaceFlags, pDstSurface->format));
    440442        rc = vmsvga3dBackCreateTexture(pState, pContext, pContext->id, pDstSurface);
    441443        AssertRCReturn(rc, rc);
     
    483485
    484486    LogFunc(("%sguestptr gmr=%x offset=%x pitch=%x host sid=%x face=%d mipmap=%d transfer=%s cCopyBoxes=%d\n",
    485              (pSurface->flags & SVGA3D_SURFACE_HINT_TEXTURE) ? "TEXTURE " : "",
     487             (pSurface->surfaceFlags & SVGA3D_SURFACE_HINT_TEXTURE) ? "TEXTURE " : "",
    486488             guest.ptr.gmrId, guest.ptr.offset, guest.pitch,
    487489             host.sid, host.face, host.mipmap, (transfer == SVGA3D_WRITE_HOST_VRAM) ? "READ" : "WRITE", cCopyBoxes));
Note: See TracChangeset for help on using the changeset viewer.

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