VirtualBox

Changeset 94063 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Mar 2, 2022 3:41:38 PM (3 years ago)
Author:
vboxsync
Message:

Devices/Graphics: shader resource and render target views should be set before a Draw call; resource view cleanup: bugref:9830

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

Legend:

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

    r93115 r94063  
    205205    RT_UNTRUSTED_VALIDATED_FENCE();
    206206
     207    uint32_t const idxShaderState = pCmd->type - SVGA3D_SHADERTYPE_MIN;
     208    SVGA3dConstantBufferBinding *pCBB = &pDXContext->svgaDXContext.shaderState[idxShaderState].constantBuffers[pCmd->slot];
     209    pCBB->sid           = pCmd->sid;
     210    pCBB->offsetInBytes = pCmd->offsetInBytes;
     211    pCBB->sizeInBytes   = pCmd->sizeInBytes;
     212
    207213    rc = pSvgaR3State->pFuncsDX->pfnDXSetSingleConstantBuffer(pThisCC, pDXContext, pCmd->slot, pCmd->type, pCmd->sid, pCmd->offsetInBytes, pCmd->sizeInBytes);
    208     if (RT_SUCCESS(rc))
    209     {
    210         uint32_t const idxShaderState = pCmd->type - SVGA3D_SHADERTYPE_MIN;
    211         SVGA3dConstantBufferBinding *pCBB = &pDXContext->svgaDXContext.shaderState[idxShaderState].constantBuffers[pCmd->slot];
    212         pCBB->sid           = pCmd->sid;
    213         pCBB->offsetInBytes = pCmd->offsetInBytes;
    214         pCBB->sizeInBytes   = pCmd->sizeInBytes;
    215     }
    216214    return rc;
    217215}
     
    238236                            || paShaderResourceViewId[i] == SVGA3D_INVALID_ID, VERR_INVALID_PARAMETER);
    239237    RT_UNTRUSTED_VALIDATED_FENCE();
     238
     239    uint32_t const idxShaderState = pCmd->type - SVGA3D_SHADERTYPE_MIN;
     240    for (uint32_t i = 0; i < cShaderResourceViewId; ++i)
     241    {
     242        SVGA3dShaderResourceViewId const shaderResourceViewId = paShaderResourceViewId[i];
     243        pDXContext->svgaDXContext.shaderState[idxShaderState].shaderResources[pCmd->startView + i] = shaderResourceViewId;
     244    }
    240245
    241246    rc = pSvgaR3State->pFuncsDX->pfnDXSetShaderResources(pThisCC, pDXContext, pCmd->startView, pCmd->type, cShaderResourceViewId, paShaderResourceViewId);
     
    517522    AssertRCReturn(rc, rc);
    518523
     524    pDXContext->svgaDXContext.inputAssembly.indexBufferSid = pCmd->sid;
     525    pDXContext->svgaDXContext.inputAssembly.indexBufferOffset = pCmd->offset;
     526    pDXContext->svgaDXContext.inputAssembly.indexBufferFormat = pCmd->format;
     527
    519528    rc = pSvgaR3State->pFuncsDX->pfnDXSetIndexBuffer(pThisCC, pDXContext, pCmd->sid, pCmd->format, pCmd->offset);
    520     if (RT_SUCCESS(rc))
    521     {
    522         pDXContext->svgaDXContext.inputAssembly.indexBufferSid = pCmd->sid;
    523         pDXContext->svgaDXContext.inputAssembly.indexBufferOffset = pCmd->offset;
    524         pDXContext->svgaDXContext.inputAssembly.indexBufferFormat = pCmd->format;
    525     }
    526529    return rc;
    527530}
     
    542545    ASSERT_GUEST_RETURN(topology >= SVGA3D_PRIMITIVE_MIN && topology < SVGA3D_PRIMITIVE_MAX, VERR_INVALID_PARAMETER);
    543546
     547    pDXContext->svgaDXContext.inputAssembly.topology = topology;
     548
    544549    rc = pSvgaR3State->pFuncsDX->pfnDXSetTopology(pThisCC, pDXContext, topology);
    545     if (RT_SUCCESS(rc))
    546         pDXContext->svgaDXContext.inputAssembly.topology = topology;
    547550    return rc;
    548551}
     
    569572    RT_UNTRUSTED_VALIDATED_FENCE();
    570573
     574    pDXContext->svgaDXContext.renderState.depthStencilViewId = depthStencilViewId;
     575    for (uint32_t i = 0; i < cRenderTargetViewId; ++i)
     576        pDXContext->svgaDXContext.renderState.renderTargetViewIds[i] = paRenderTargetViewId[i];
     577
    571578    rc = pSvgaR3State->pFuncsDX->pfnDXSetRenderTargets(pThisCC, pDXContext, depthStencilViewId, cRenderTargetViewId, paRenderTargetViewId);
    572     if (RT_SUCCESS(rc))
    573     {
    574         pDXContext->svgaDXContext.renderState.depthStencilViewId = depthStencilViewId;
    575         for (uint32_t i = 0; i < cRenderTargetViewId; ++i)
    576             pDXContext->svgaDXContext.renderState.renderTargetViewIds[i] = paRenderTargetViewId[i];
    577     }
    578579    return rc;
    579580}
     
    10621063    RT_ZERO(*pEntry);
    10631064
     1065    for (uint32_t i = 0; i < SVGA3D_MAX_SIMULTANEOUS_RENDER_TARGETS; ++i)
     1066    {
     1067        if (pDXContext->svgaDXContext.renderState.renderTargetViewIds[i] == renderTargetViewId)
     1068            pDXContext->svgaDXContext.renderState.renderTargetViewIds[i] = SVGA_ID_INVALID;
     1069    }
     1070
    10641071    rc = pSvgaR3State->pFuncsDX->pfnDXDestroyRenderTargetView(pThisCC, pDXContext, renderTargetViewId);
    1065     /// @todo for (uint32_t i = 0; i < SVGA3D_MAX_SIMULTANEOUS_RENDER_TARGETS; ++i)
    1066     //{
    1067     //    if (pDXContext->svgaDXContext.renderState.renderTargetViewIds[i] == renderTargetViewId)
    1068     //        pDXContext->svgaDXContext.renderState.renderTargetViewIds[i] = SVGA_ID_INVALID;
    1069     //}
    10701072    return rc;
    10711073}
     
    17001702    RT_UNTRUSTED_VALIDATED_FENCE();
    17011703
     1704    pDXContext->svgaDXContext.streamOut.soid = soid;
     1705
    17021706    rc = pSvgaR3State->pFuncsDX->pfnDXSetStreamOutput(pThisCC, pDXContext, soid);
    1703     if (RT_SUCCESS(rc))
    1704         pDXContext->svgaDXContext.streamOut.soid = soid;
    1705 
    17061707    return rc;
    17071708}
  • trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-ogl.cpp

    r93115 r94063  
    20682068            break;
    20692069    }
     2070}
     2071
     2072
     2073static DECLCALLBACK(void) vmsvga3dBackSurfaceInvalidateImage(PVGASTATECC pThisCC, PVMSVGA3DSURFACE pSurface, uint32_t uFace, uint32_t uMipmap)
     2074{
     2075    RT_NOREF(pThisCC, pSurface, uFace, uMipmap);
    20702076}
    20712077
     
    78917897                p->pfnCreateTexture            = vmsvga3dBackCreateTexture;
    78927898                p->pfnSurfaceDestroy           = vmsvga3dBackSurfaceDestroy;
     7899                p->pfnSurfaceInvalidateImage   = vmsvga3dBackSurfaceInvalidateImage;
    78937900                p->pfnSurfaceCopy              = vmsvga3dBackSurfaceCopy;
    78947901                p->pfnSurfaceDMACopyBox        = vmsvga3dBackSurfaceDMACopyBox;
  • trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-win-dx.cpp

    r93739 r94063  
    7676} DXDEVICE;
    7777
     78/* Kind of a texture view. */
     79typedef enum VMSVGA3DBACKVIEWTYPE
     80{
     81    VMSVGA3D_VIEWTYPE_NONE           = 0,
     82    VMSVGA3D_VIEWTYPE_RENDERTARGET   = 1,
     83    VMSVGA3D_VIEWTYPE_DEPTHSTENCIL   = 2,
     84    VMSVGA3D_VIEWTYPE_SHADERRESOURCE = 3
     85} VMSVGA3DBACKVIEWTYPE;
     86
     87/* Information about a texture view to track all created views:.
     88 * when a surface is invalidated, then all views must deleted;
     89 * when a view is deleted, then the view must be unlinked from the surface.
     90 */
     91typedef struct DXVIEWINFO
     92{
     93    uint32_t sid;                                      /* Surface which the view was created for. */
     94    uint32_t cid;                                      /* DX context which created the view. */
     95    uint32_t viewId;                                   /* View id assigned by the guest. */
     96    VMSVGA3DBACKVIEWTYPE enmViewType;
     97} DXVIEWINFO;
     98
     99/* Context Object Table element for a texture view. */
     100typedef struct DXVIEW
     101{
     102    uint32_t cid;                                      /* DX context which created the view. */
     103    uint32_t sid;                                      /* Surface which the view was created for. */
     104    uint32_t viewId;                                   /* View id assigned by the guest. */
     105    VMSVGA3DBACKVIEWTYPE enmViewType;
     106
     107    union
     108    {
     109        ID3D11View               *pView;               /* The view object. */
     110        ID3D11RenderTargetView   *pRenderTargetView;
     111        ID3D11DepthStencilView   *pDepthStencilView;
     112        ID3D11ShaderResourceView *pShaderResourceView;
     113    } u;
     114
     115    RTLISTNODE nodeSurfaceView;                        /* Views are linked to the surface. */
     116} DXVIEW;
     117
    78118/* What kind of resource has been created for the VMSVGA3D surface. */
    79119typedef enum VMSVGA3DBACKRESTYPE
     
    82122    VMSVGA3D_RESTYPE_SCREEN_TARGET  = 1,
    83123    VMSVGA3D_RESTYPE_TEXTURE_1D     = 2,
    84     VMSVGA3D_RESTYPE_TEXTURE        = 3,
    85     VMSVGA3D_RESTYPE_CUBE_TEXTURE   = 4,
     124    VMSVGA3D_RESTYPE_TEXTURE_2D     = 3,
     125    VMSVGA3D_RESTYPE_TEXTURE_CUBE   = 4,
    86126    VMSVGA3D_RESTYPE_TEXTURE_3D     = 5,
    87127    VMSVGA3D_RESTYPE_BUFFER         = 6,
     
    95135    {
    96136        ID3D11Resource     *pResource;
     137        ID3D11Texture1D    *pTexture1D;
    97138        ID3D11Texture2D    *pTexture2D;
    98139        ID3D11Texture3D    *pTexture3D;
     
    116157    /** AVL tree containing DXSHAREDTEXTURE structures. */
    117158    AVLU32TREE SharedTextureTree;
     159
     160    union
     161    {
     162       struct
     163       {
     164           /* Render target views, depth stencil views and shader resource views created for this texture. */
     165           RTLISTANCHOR listView;                 /* DXVIEW */
     166       } Texture;
     167    } u2;
    118168
    119169} VMSVGA3DBACKENDSURFACE;
     
    170220} DXSTREAMOUTPUT;
    171221
    172 #define DX_DEFERRED_SET_RENDER_TARGETS
    173222typedef struct VMSVGA3DBACKENDDXCONTEXT
    174223{
    175     DXDEVICE                   device;                 /* DX device interfaces for this context operations. */
     224    DXDEVICE                   dxDevice;               /* DX device interfaces for this context operations. */
    176225
    177226    /* Arrays for Context-Object Tables. Number of entries depends on COTable size. */
     
    192241    ID3D11RasterizerState    **papRasterizerState;
    193242    DXELEMENTLAYOUT           *paElementLayout;
    194     ID3D11RenderTargetView   **papRenderTargetView;
    195     ID3D11DepthStencilView   **papDepthStencilView;
    196     ID3D11ShaderResourceView **papShaderResourceView;
     243    DXVIEW                    *paRenderTargetView;
     244    DXVIEW                    *paDepthStencilView;
     245    DXVIEW                    *paShaderResourceView;
    197246    ID3D11Query              **papQuery;
    198247    DXSHADER                  *paShader;
    199248    DXSTREAMOUTPUT            *paStreamOutput;
    200249
    201 #ifdef DX_DEFERRED_SET_RENDER_TARGETS
    202     struct
    203     {
    204         ID3D11RenderTargetView *papRenderTargetViews[SVGA3D_MAX_RENDER_TARGETS];
    205         uint32_t cRenderTargetViews;
    206         ID3D11DepthStencilView *pDepthStencilView;
    207     } state;
    208 #endif
    209 
    210250    uint32_t                   cSOTarget;              /* How many SO targets are currently set (SetSOTargets) */
    211251} VMSVGA3DBACKENDDXCONTEXT;
    212252
     253/* Shader disassembler function. Optional. */
    213254typedef HRESULT FN_D3D_DISASSEMBLE(LPCVOID pSrcData, SIZE_T SrcDataSize, UINT Flags, LPCSTR szComments, ID3D10Blob **ppDisassembly);
    214255typedef FN_D3D_DISASSEMBLE *PFN_D3D_DISASSEMBLE;
     
    222263    PFN_D3D_DISASSEMBLE        pfnD3DDisassemble;
    223264
    224     DXDEVICE                   device;                 /* Device for the VMSVGA3D context independent operation. */
     265    /** @todo This device will be used for all rendering for "single DX device" mode. */
     266    DXDEVICE                   dxDevice;               /* Device for the VMSVGA3D context independent operation. */
    225267} VMSVGA3DBACKEND;
    226268
    227269
     270/* Static function prototypes. */
    228271static int dxDeviceFlush(DXDEVICE *pDevice);
     272static int dxDefineShaderResourceView(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, SVGA3dShaderResourceViewId shaderResourceViewId, SVGACOTableDXSRViewEntry const *pEntry);
     273static int dxDefineRenderTargetView(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, SVGA3dRenderTargetViewId renderTargetViewId, SVGACOTableDXRTViewEntry const *pEntry);
     274static int dxDefineDepthStencilView(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, SVGA3dDepthStencilViewId depthStencilViewId, SVGACOTableDXDSViewEntry const *pEntry);
     275static int dxSetRenderTargets(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext);
    229276static DECLCALLBACK(void) vmsvga3dBackSurfaceDestroy(PVGASTATECC pThisCC, PVMSVGA3DSURFACE pSurface);
    230277
     
    259306}
    260307
     308/* This is to workaround issues with X8 formats, because they can't be used in some operations. */
    261309#define DX_REPLACE_X8_WITH_A8
    262310static DXGI_FORMAT vmsvgaDXSurfaceFormat2Dxgi(SVGA3dSurfaceFormat format)
     
    690738    if (dxgiFormat != DXGI_FORMAT_UNKNOWN)
    691739    {
    692         ID3D11Device *pDevice = pState->pBackend->device.pDevice;
     740        ID3D11Device *pDevice = pState->pBackend->dxDevice.pDevice;
    693741        UINT FormatSupport = 0;
    694742        HRESULT hr = pDevice->CheckFormatSupport(dxgiFormat, &FormatSupport);
     
    776824            {
    777825                pInfoQueue->SetBreakOnSeverity(D3D11_MESSAGE_SEVERITY_CORRUPTION, true);
    778                 pInfoQueue->SetBreakOnSeverity(D3D11_MESSAGE_SEVERITY_ERROR, true);
    779                 pInfoQueue->SetBreakOnSeverity(D3D11_MESSAGE_SEVERITY_WARNING, true);
     826//                pInfoQueue->SetBreakOnSeverity(D3D11_MESSAGE_SEVERITY_ERROR, true);
     827//                pInfoQueue->SetBreakOnSeverity(D3D11_MESSAGE_SEVERITY_WARNING, true);
    780828
    781829                /* No breakpoints for the following messages. */
     
    847895    if (SUCCEEDED(hr2))
    848896    {
     897        /// @todo Use this to see whether all resources have been properly released.
     898        //DEBUG_BREAKPOINT_TEST();
    849899        //pDebug->ReportLiveDeviceObjects(D3D11_RLDO_DETAIL | (D3D11_RLDO_FLAGS)0x4 /*D3D11_RLDO_IGNORE_INTERNAL*/);
    850900        D3D_RELEASE(pDebug);
     
    854904    D3D_RELEASE(pDevice->pDevice);
    855905    RT_ZERO(*pDevice);
     906}
     907
     908
     909static void dxViewAddToList(PVGASTATECC pThisCC, DXVIEW *pDXView)
     910{
     911    LogFunc(("cid = %u, sid = %u, viewId = %u, type = %u\n",
     912             pDXView->cid, pDXView->sid, pDXView->viewId, pDXView->enmViewType));
     913
     914    Assert(pDXView->u.pView); /* Only already created views should be added. Guard against mis-use by callers. */
     915
     916    PVMSVGA3DSURFACE pSurface;
     917    int rc = vmsvga3dSurfaceFromSid(pThisCC->svga.p3dState, pDXView->sid, &pSurface);
     918    AssertRCReturnVoid(rc);
     919
     920    RTListAppend(&pSurface->pBackendSurface->u2.Texture.listView, &pDXView->nodeSurfaceView);
     921}
     922
     923
     924static void dxViewRemoveFromList(DXVIEW *pDXView)
     925{
     926    LogFunc(("cid = %u, sid = %u, viewId = %u, type = %u\n",
     927             pDXView->cid, pDXView->sid, pDXView->viewId, pDXView->enmViewType));
     928    /* pView can be NULL, if COT entry is already empty. */
     929    if (pDXView->u.pView)
     930    {
     931        Assert(pDXView->nodeSurfaceView.pNext && pDXView->nodeSurfaceView.pPrev);
     932        RTListNodeRemove(&pDXView->nodeSurfaceView);
     933    }
     934}
     935
     936
     937static int dxViewDestroy(DXVIEW *pDXView)
     938{
     939    LogFunc(("cid = %u, sid = %u, viewId = %u, type = %u\n",
     940             pDXView->cid, pDXView->sid, pDXView->viewId, pDXView->enmViewType));
     941    if (pDXView->u.pView)
     942    {
     943        D3D_RELEASE(pDXView->u.pView);
     944        RTListNodeRemove(&pDXView->nodeSurfaceView);
     945        RT_ZERO(*pDXView);
     946    }
     947
     948    return VINF_SUCCESS;
     949}
     950
     951
     952static int dxViewInit(DXVIEW *pDXView, PVMSVGA3DSURFACE pSurface, VMSVGA3DDXCONTEXT *pDXContext, uint32_t viewId, VMSVGA3DBACKVIEWTYPE enmViewType, ID3D11View *pView)
     953{
     954    pDXView->cid         = pDXContext->cid;
     955    pDXView->sid         = pSurface->id;
     956    pDXView->viewId      = viewId;
     957    pDXView->enmViewType = enmViewType;
     958    pDXView->u.pView     = pView;
     959    RTListAppend(&pSurface->pBackendSurface->u2.Texture.listView, &pDXView->nodeSurfaceView);
     960
     961    LogFunc(("cid = %u, sid = %u, viewId = %u, type = %u\n",
     962              pDXView->cid, pDXView->sid, pDXView->viewId, pDXView->enmViewType));
     963
     964DXVIEW *pIter, *pNext;
     965RTListForEachSafe(&pSurface->pBackendSurface->u2.Texture.listView, pIter, pNext, DXVIEW, nodeSurfaceView)
     966{
     967    AssertPtr(pNext);
     968    LogFunc(("pIter=%p, pNext=%p\n", pIter, pNext));
     969}
     970
     971    return VINF_SUCCESS;
    856972}
    857973
     
    868984
    869985
    870 DXDEVICE *dxDeviceFromCid(uint32_t cid, PVMSVGA3DSTATE pState)
     986static DXDEVICE *dxDeviceFromCid(uint32_t cid, PVMSVGA3DSTATE pState)
    871987{
    872988    if (cid != DX_CID_BACKEND)
     
    875991        int rc = vmsvga3dDXContextFromCid(pState, cid, &pDXContext);
    876992        if (RT_SUCCESS(rc))
    877             return &pDXContext->pBackendDXContext->device;
     993            return &pDXContext->pBackendDXContext->dxDevice;
    878994    }
    879995    else
    880         return &pState->pBackend->device;
     996        return &pState->pBackend->dxDevice;
    881997
    882998    AssertFailed();
    883999    return NULL;
     1000}
     1001
     1002
     1003static DXDEVICE *dxDeviceFromContext(PVMSVGA3DSTATE p3dState, VMSVGA3DDXCONTEXT *pDXContext)
     1004{
     1005    if (pDXContext)
     1006        return &pDXContext->pBackendDXContext->dxDevice;
     1007
     1008    return &p3dState->pBackend->dxDevice;
    8841009}
    8851010
     
    9661091        if (!pSharedTexture)
    9671092        {
    968             DXDEVICE *pDevice = &pDXContext->pBackendDXContext->device;
     1093            DXDEVICE *pDevice = dxDeviceFromContext(pState, pDXContext);
    9691094            AssertReturn(pDevice->pDevice, NULL);
    9701095
     
    10101135
    10111136
    1012 static uint32_t dxGetShaderResourceViewSid(PVMSVGA3DDXCONTEXT pDXContext, uint32_t shaderResourceViewId)
    1013 {
    1014     ASSERT_GUEST_RETURN(shaderResourceViewId < pDXContext->cot.cSRView, SVGA_ID_INVALID);
     1137static SVGACOTableDXSRViewEntry const *dxGetShaderResourceViewEntry(PVMSVGA3DDXCONTEXT pDXContext, uint32_t shaderResourceViewId)
     1138{
     1139    ASSERT_GUEST_RETURN(shaderResourceViewId < pDXContext->cot.cSRView, NULL);
    10151140
    10161141    SVGACOTableDXSRViewEntry const *pSRViewEntry = &pDXContext->cot.paSRView[shaderResourceViewId];
    1017     return pSRViewEntry->sid;
     1142    return pSRViewEntry;
     1143}
     1144
     1145
     1146static SVGACOTableDXDSViewEntry const *dxGetDepthStencilViewEntry(PVMSVGA3DDXCONTEXT pDXContext, uint32_t depthStencilViewId)
     1147{
     1148    ASSERT_GUEST_RETURN(depthStencilViewId < pDXContext->cot.cDSView, NULL);
     1149
     1150    SVGACOTableDXDSViewEntry const *pDSViewEntry = &pDXContext->cot.paDSView[depthStencilViewId];
     1151    return pDSViewEntry;
     1152}
     1153
     1154
     1155static SVGACOTableDXRTViewEntry const *dxGetRenderTargetViewEntry(PVMSVGA3DDXCONTEXT pDXContext, uint32_t renderTargetViewId)
     1156{
     1157    ASSERT_GUEST_RETURN(renderTargetViewId < pDXContext->cot.cRTView, NULL);
     1158
     1159    SVGACOTableDXRTViewEntry const *pRTViewEntry = &pDXContext->cot.paRTView[renderTargetViewId];
     1160    return pRTViewEntry;
    10181161}
    10191162
     
    12091352static HRESULT dxRenderTargetViewCreate(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, SVGACOTableDXRTViewEntry const *pEntry, VMSVGA3DSURFACE *pSurface, ID3D11RenderTargetView **pp)
    12101353{
    1211     DXDEVICE *pDevice = &pDXContext->pBackendDXContext->device;
     1354    DXDEVICE *pDevice = dxDeviceFromContext(pThisCC->svga.p3dState, pDXContext);
    12121355
    12131356    ID3D11Resource *pResource = dxResource(pThisCC->svga.p3dState, pSurface, pDXContext);
     
    12831426static HRESULT dxShaderResourceViewCreate(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, SVGACOTableDXSRViewEntry const *pEntry, VMSVGA3DSURFACE *pSurface, ID3D11ShaderResourceView **pp)
    12841427{
    1285     DXDEVICE *pDevice = &pDXContext->pBackendDXContext->device;
     1428    DXDEVICE *pDevice = dxDeviceFromContext(pThisCC->svga.p3dState, pDXContext);
    12861429
    12871430    ID3D11Resource *pResource = dxResource(pThisCC->svga.p3dState, pSurface, pDXContext);
     
    13601503static HRESULT dxDepthStencilViewCreate(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, SVGACOTableDXDSViewEntry const *pEntry, VMSVGA3DSURFACE *pSurface, ID3D11DepthStencilView **pp)
    13611504{
    1362     DXDEVICE *pDevice = &pDXContext->pBackendDXContext->device;
     1505    DXDEVICE *pDevice = dxDeviceFromContext(pThisCC->svga.p3dState, pDXContext);
    13631506
    13641507    ID3D11Resource *pResource = dxResource(pThisCC->svga.p3dState, pSurface, pDXContext);
     
    14091552
    14101553
    1411 static HRESULT dxShaderCreate(PVMSVGA3DDXCONTEXT pDXContext, PVMSVGA3DSHADER pShader, DXSHADER *pDXShader)
    1412 {
    1413     DXDEVICE *pDevice = &pDXContext->pBackendDXContext->device;
     1554static HRESULT dxShaderCreate(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, PVMSVGA3DSHADER pShader, DXSHADER *pDXShader)
     1555{
     1556    DXDEVICE *pDevice = dxDeviceFromContext(pThisCC->svga.p3dState, pDXContext);
    14141557
    14151558    HRESULT hr = S_OK;
     
    14661609
    14671610
    1468 static void dxShaderSet(PVMSVGA3DDXCONTEXT pDXContext, SVGA3dShaderType type, DXSHADER *pDXShader)
    1469 {
    1470     DXDEVICE *pDevice = &pDXContext->pBackendDXContext->device;
     1611static void dxShaderSet(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, SVGA3dShaderType type, DXSHADER *pDXShader)
     1612{
     1613    DXDEVICE *pDevice = dxDeviceFromContext(pThisCC->svga.p3dState, pDXContext);
    14711614
    14721615    switch (type)
     
    15631706    AssertPtrReturn(pBackendSurface, VERR_NO_MEMORY);
    15641707    pBackendSurface->cidDrawing = SVGA_ID_INVALID;
     1708    RTListInit(&pBackendSurface->u2.Texture.listView);
    15651709    *ppBackendSurface = pBackendSurface;
    15661710    return VINF_SUCCESS;
     
    15761720    AssertReturn(pBackend, VERR_INVALID_STATE);
    15771721
    1578     DXDEVICE *pDXDevice = &pBackend->device;
     1722    DXDEVICE *pDXDevice = &pBackend->dxDevice;
    15791723    AssertReturn(pDXDevice->pDevice, VERR_INVALID_STATE);
    15801724
     
    16861830
    16871831
     1832static DXDEVICE *dxSurfaceDevice(PVMSVGA3DSTATE p3dState, PVMSVGA3DSURFACE pSurface, PVMSVGA3DDXCONTEXT pDXContext, UINT *pMiscFlags)
     1833{
     1834    if (dxIsSurfaceShareable(pSurface))
     1835    {
     1836        *pMiscFlags = D3D11_RESOURCE_MISC_SHARED;
     1837        return &p3dState->pBackend->dxDevice;
     1838    }
     1839
     1840    *pMiscFlags = 0;
     1841    return &pDXContext->pBackendDXContext->dxDevice;
     1842}
     1843
    16881844static int vmsvga3dBackSurfaceCreateTexture(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, PVMSVGA3DSURFACE pSurface)
    16891845{
     
    16951851
    16961852    UINT MiscFlags;
    1697     DXDEVICE *pDXDevice;
    1698     if (dxIsSurfaceShareable(pSurface))
    1699     {
    1700         pDXDevice = &pBackend->device;
    1701         MiscFlags = D3D11_RESOURCE_MISC_SHARED;
    1702     }
    1703     else
    1704     {
    1705         pDXDevice = &pDXContext->pBackendDXContext->device;
    1706         MiscFlags = 0;
    1707     }
     1853    DXDEVICE *pDXDevice = dxSurfaceDevice(p3dState, pSurface, pDXContext, &MiscFlags);
    17081854    AssertReturn(pDXDevice->pDevice, VERR_INVALID_STATE);
    17091855
     
    18802026        if (SUCCEEDED(hr))
    18812027        {
    1882             pBackendSurface->enmResType = VMSVGA3D_RESTYPE_CUBE_TEXTURE;
     2028            pBackendSurface->enmResType = VMSVGA3D_RESTYPE_TEXTURE_CUBE;
    18832029        }
    18842030    }
     
    20552201            if (SUCCEEDED(hr))
    20562202            {
    2057                 pBackendSurface->enmResType = VMSVGA3D_RESTYPE_TEXTURE;
     2203                pBackendSurface->enmResType = VMSVGA3D_RESTYPE_TEXTURE_2D;
    20582204            }
    20592205        }
     
    20932239static int vmsvga3dBackSurfaceCreateDepthStencilTexture(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, PVMSVGA3DSURFACE pSurface)
    20942240{
    2095     DXDEVICE *pDXDevice = &pDXContext->pBackendDXContext->device;
     2241    DXDEVICE *pDXDevice = dxDeviceFromContext(pThisCC->svga.p3dState, pDXContext);
    20962242    AssertReturn(pDXDevice->pDevice, VERR_INVALID_STATE);
    20972243
     
    21202266    if (pSurface->surfaceFlags & SVGA3D_SURFACE_CUBEMAP)
    21212267    {
    2122         AssertFailed(); /** @todo implement */
    2123         hr = E_FAIL;
     2268        /*
     2269         * CubeMap texture.
     2270         */
     2271        Assert(pSurface->cFaces == 6);
     2272        Assert(cWidth == cHeight);
     2273        Assert(cDepth == 1);
     2274        Assert(numMipLevels == 1);
     2275//DEBUG_BREAKPOINT_TEST();
     2276        D3D11_SUBRESOURCE_DATA *paInitialData = NULL;
     2277        D3D11_SUBRESOURCE_DATA aInitialData[6 * SVGA3D_MAX_MIP_LEVELS];
     2278        if (pSurface->paMipmapLevels[0].pSurfaceData)
     2279        {
     2280            /** @todo Can happen for a non GBO surface or if GBO texture was updated prior to creation if the hardware resource. Test this. */
     2281            /** @todo for (i = 0; i < pSurface->cFaces * numMipLevels; ++i) */
     2282            for (uint32_t iFace = 0; iFace < 6; ++iFace)
     2283            {
     2284                for (uint32_t i = 0; i < numMipLevels; ++i)
     2285                {
     2286                    uint32_t const iSubresource = vmsvga3dCalcSubresource(i, iFace, numMipLevels);
     2287
     2288                    PVMSVGA3DMIPMAPLEVEL pMipmapLevel = &pSurface->paMipmapLevels[iSubresource];
     2289                    D3D11_SUBRESOURCE_DATA *p = &aInitialData[iSubresource];
     2290                    p->pSysMem          = pMipmapLevel->pSurfaceData;
     2291                    p->SysMemPitch      = pMipmapLevel->cbSurfacePitch;
     2292                    p->SysMemSlicePitch = pMipmapLevel->cbSurfacePlane;
     2293                }
     2294            }
     2295            paInitialData = &aInitialData[0];
     2296        }
     2297
     2298        D3D11_TEXTURE2D_DESC td;
     2299        RT_ZERO(td);
     2300        td.Width              = cWidth;
     2301        td.Height             = cHeight;
     2302        td.MipLevels          = 1;
     2303        td.ArraySize          = 6;
     2304        td.Format             = dxgiFormat;
     2305        td.SampleDesc.Count   = 1;
     2306        td.SampleDesc.Quality = 0;
     2307        td.Usage              = D3D11_USAGE_DEFAULT;
     2308        td.BindFlags          = dxBindFlags(pSurface->surfaceFlags);
     2309        td.CPUAccessFlags     = 0;
     2310        td.MiscFlags          = D3D11_RESOURCE_MISC_TEXTURECUBE;
     2311
     2312        hr = pDXDevice->pDevice->CreateTexture2D(&td, paInitialData, &pBackendSurface->u.pTexture2D);
     2313        Assert(SUCCEEDED(hr));
     2314        if (SUCCEEDED(hr))
     2315        {
     2316            /* Map-able texture. */
     2317            td.MipLevels      = 1; /* Must be for D3D11_USAGE_DYNAMIC. */
     2318            td.ArraySize      = 1; /* Must be for D3D11_USAGE_DYNAMIC. */
     2319            td.Usage          = D3D11_USAGE_DYNAMIC;
     2320            td.BindFlags      = D3D11_BIND_SHADER_RESOURCE; /* Have to specify a supported flag, otherwise E_INVALIDARG will be returned. */
     2321            td.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
     2322            td.MiscFlags      = 0;
     2323            hr = pDXDevice->pDevice->CreateTexture2D(&td, paInitialData, &pBackendSurface->pDynamicTexture);
     2324            Assert(SUCCEEDED(hr));
     2325        }
     2326
     2327        if (SUCCEEDED(hr))
     2328        {
     2329            /* Staging texture. */
     2330            td.Usage          = D3D11_USAGE_STAGING;
     2331            td.BindFlags      = 0; /* No flags allowed. */
     2332            td.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
     2333            td.MiscFlags      = 0;
     2334            hr = pDXDevice->pDevice->CreateTexture2D(&td, paInitialData, &pBackendSurface->pStagingTexture);
     2335            Assert(SUCCEEDED(hr));
     2336        }
     2337
     2338        if (SUCCEEDED(hr))
     2339        {
     2340            pBackendSurface->enmResType = VMSVGA3D_RESTYPE_TEXTURE_CUBE;
     2341        }
    21242342    }
    21252343    else if (pSurface->surfaceFlags & SVGA3D_SURFACE_1D)
     
    21412359             */
    21422360            Assert(pSurface->cFaces == 1);
     2361            Assert(numMipLevels == 1);
    21432362
    21442363            D3D11_SUBRESOURCE_DATA *paInitialData = NULL;
     
    21622381            td.Width              = cWidth;
    21632382            td.Height             = cHeight;
    2164             Assert(pSurface->cLevels == 1);
    21652383            td.MipLevels          = 1;
    21662384            td.ArraySize          = 1;
     
    22002418            if (SUCCEEDED(hr))
    22012419            {
    2202                 pBackendSurface->enmResType = VMSVGA3D_RESTYPE_TEXTURE;
     2420                pBackendSurface->enmResType = VMSVGA3D_RESTYPE_TEXTURE_2D;
    22032421            }
    22042422        }
     
    22272445static int vmsvga3dBackSurfaceCreateBuffer(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, PVMSVGA3DSURFACE pSurface)
    22282446{
    2229     DXDEVICE *pDevice = &pDXContext->pBackendDXContext->device;
     2447    DXDEVICE *pDevice = dxDeviceFromContext(pThisCC->svga.p3dState, pDXContext);
    22302448    AssertReturn(pDevice->pDevice, VERR_INVALID_STATE);
    22312449
     
    22952513static int vmsvga3dBackSurfaceCreateSoBuffer(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, PVMSVGA3DSURFACE pSurface)
    22962514{
    2297     DXDEVICE *pDevice = &pDXContext->pBackendDXContext->device;
     2515    DXDEVICE *pDevice = dxDeviceFromContext(pThisCC->svga.p3dState, pDXContext);
    22982516    AssertReturn(pDevice->pDevice, VERR_INVALID_STATE);
    22992517
     
    23442562static int vmsvga3dBackSurfaceCreateConstantBuffer(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, PVMSVGA3DSURFACE pSurface)
    23452563{
    2346     DXDEVICE *pDevice = &pDXContext->pBackendDXContext->device;
     2564    DXDEVICE *pDevice = dxDeviceFromContext(pThisCC->svga.p3dState, pDXContext);
    23472565    AssertReturn(pDevice->pDevice, VERR_INVALID_STATE);
    23482566
     
    24432661static int vmsvga3dBackSurfaceCreate(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, PVMSVGA3DSURFACE pSurface)
    24442662{
    2445     DXDEVICE *pDevice = &pDXContext->pBackendDXContext->device;
     2663    DXDEVICE *pDevice = dxDeviceFromContext(pThisCC->svga.p3dState, pDXContext);
    24462664    AssertReturn(pDevice->pDevice, VERR_INVALID_STATE);
    24472665
     
    26032821    AssertReturn(pBackend, VERR_INVALID_STATE);
    26042822
    2605     int rc = dxDeviceCreate(pBackend, &pBackend->device);
     2823    int rc = dxDeviceCreate(pBackend, &pBackend->dxDevice);
    26062824    return rc;
    26072825}
    26082826
    26092827
    2610 static DECLCALLBACK(int) vmsvga3dBackTerminate(PVGASTATECC pThisCC)
     2828static DECLCALLBACK(int) vmsvga3dBackReset(PVGASTATECC pThisCC)
    26112829{
    26122830    PVMSVGA3DSTATE pState = pThisCC->svga.p3dState;
    26132831    AssertReturn(pState, VERR_INVALID_STATE);
    26142832
     2833    /** @todo This is generic code. Must be moved to in DevVGA-SVGA3d.cpp */
     2834    /* Destroy all leftover surfaces. */
     2835    for (uint32_t i = 0; i < pState->cSurfaces; i++)
     2836    {
     2837        if (pState->papSurfaces[i]->id != SVGA3D_INVALID_ID)
     2838            vmsvga3dSurfaceDestroy(pThisCC, pState->papSurfaces[i]->id);
     2839    }
     2840
     2841    /* Destroy all leftover DX contexts. */
     2842    for (uint32_t i = 0; i < pState->cDXContexts; i++)
     2843    {
     2844        if (pState->papDXContexts[i]->cid != SVGA3D_INVALID_ID)
     2845            vmsvga3dDXDestroyContext(pThisCC, pState->papDXContexts[i]->cid);
     2846    }
     2847
     2848    return VINF_SUCCESS;
     2849}
     2850
     2851
     2852static DECLCALLBACK(int) vmsvga3dBackTerminate(PVGASTATECC pThisCC)
     2853{
     2854    PVMSVGA3DSTATE pState = pThisCC->svga.p3dState;
     2855    AssertReturn(pState, VERR_INVALID_STATE);
     2856
    26152857    if (pState->pBackend)
    26162858    {
    2617         /** @todo Clean up backends. */
    2618 
    2619         dxDeviceDestroy(pState->pBackend, &pState->pBackend->device);
     2859        /* Clean up backends. For example release resources from surfaces. */
     2860        vmsvga3dBackReset(pThisCC);
     2861
     2862        dxDeviceDestroy(pState->pBackend, &pState->pBackend->dxDevice);
    26202863
    26212864        RTMemFree(pState->pBackend);
    26222865        pState->pBackend = NULL;
    26232866    }
    2624 
    2625     return VINF_SUCCESS;
    2626 }
    2627 
    2628 
    2629 static DECLCALLBACK(int) vmsvga3dBackReset(PVGASTATECC pThisCC)
    2630 {
    2631     PVMSVGA3DSTATE pState = pThisCC->svga.p3dState;
    2632     AssertReturn(pState, VERR_INVALID_STATE);
    2633 
    2634     /** @todo Cleanup all resources and recreate Device, ImmediateContext etc to be at the same state as after poweron. */
    26352867
    26362868    return VINF_SUCCESS;
     
    27272959    PVMSVGA3DBACKEND pBackend = pState->pBackend;
    27282960
    2729     DXDEVICE *pDXDevice = &pBackend->device;
     2961    DXDEVICE *pDXDevice = &pBackend->dxDevice;
    27302962    AssertReturn(pDXDevice->pDevice, VERR_INVALID_STATE);
    27312963
     
    29573189            rc = VERR_NOT_SUPPORTED;
    29583190    }
    2959     else if (   pBackendSurface->enmResType == VMSVGA3D_RESTYPE_TEXTURE
    2960              || pBackendSurface->enmResType == VMSVGA3D_RESTYPE_CUBE_TEXTURE
     3191    else if (   pBackendSurface->enmResType == VMSVGA3D_RESTYPE_TEXTURE_2D
     3192             || pBackendSurface->enmResType == VMSVGA3D_RESTYPE_TEXTURE_CUBE
    29613193             || pBackendSurface->enmResType == VMSVGA3D_RESTYPE_TEXTURE_3D)
    29623194    {
     
    31513383        }
    31523384    }
    3153     else if (   pBackendSurface->enmResType == VMSVGA3D_RESTYPE_TEXTURE
    3154              || pBackendSurface->enmResType == VMSVGA3D_RESTYPE_CUBE_TEXTURE
     3385    else if (   pBackendSurface->enmResType == VMSVGA3D_RESTYPE_TEXTURE_2D
     3386             || pBackendSurface->enmResType == VMSVGA3D_RESTYPE_TEXTURE_CUBE
    31553387             || pBackendSurface->enmResType == VMSVGA3D_RESTYPE_TEXTURE_3D)
    31563388    {
     
    33503582    if (result == S_OK)
    33513583    {
    3352         pBackend->device.pImmediateContext->CopyResource(pHwScreen->pTexture, pBackendSurface->u.pTexture2D);
    3353 
    3354         dxDeviceFlush(&pBackend->device);
     3584        pBackend->dxDevice.pImmediateContext->CopyResource(pHwScreen->pTexture, pBackendSurface->u.pTexture2D);
     3585
     3586        dxDeviceFlush(&pBackend->dxDevice);
    33553587
    33563588        result = pHwScreen->pDXGIKeyedMutex->ReleaseSync(1);
     
    33853617    }
    33863618
    3387     D3D_FEATURE_LEVEL const FeatureLevel = pState->pBackend->device.FeatureLevel;
     3619    D3D_FEATURE_LEVEL const FeatureLevel = pState->pBackend->dxDevice.FeatureLevel;
    33883620
    33893621    /* Most values are taken from:
     
    39634195             pDstSurface ? pDstSurface->idAssociatedContext : SVGA_ID_INVALID));
    39644196
    3965     //DXDEVICE *pDevice = &pDXContext->pBackendDXContext->device;
     4197    //DXDEVICE *pDevice = dxDeviceFromContext(pThisCC->svga.p3dState, pDXContext);
    39664198    //AssertReturn(pDevice->pDevice, VERR_INVALID_STATE);
    39674199
     
    39874219            dxSurfaceWait(pState, pSrcSurface, DX_CID_BACKEND);
    39884220
    3989             DXDEVICE *pDXDevice = &pBackend->device;
     4221            DXDEVICE *pDXDevice = &pBackend->dxDevice;
    39904222
    39914223            /* Clip the box. */
     
    43454577    LogFunc(("sid=%u\n", pSurface->id));
    43464578
     4579    /* If any views have been created for this resource, then also release them. */
     4580    DXVIEW *pIter, *pNext;
     4581    RTListForEachSafe(&pBackendSurface->u2.Texture.listView, pIter, pNext, DXVIEW, nodeSurfaceView)
     4582    {
     4583        LogFunc(("pIter=%p, pNext=%p\n", pIter, pNext));
     4584        dxViewDestroy(pIter);
     4585    }
     4586
    43474587    if (pBackendSurface->enmResType == VMSVGA3D_RESTYPE_SCREEN_TARGET)
    43484588    {
     
    43514591        D3D_RELEASE(pBackendSurface->u.pTexture2D);
    43524592    }
    4353     else if (   pBackendSurface->enmResType == VMSVGA3D_RESTYPE_TEXTURE
    4354              || pBackendSurface->enmResType == VMSVGA3D_RESTYPE_CUBE_TEXTURE)
     4593    else if (   pBackendSurface->enmResType == VMSVGA3D_RESTYPE_TEXTURE_2D
     4594             || pBackendSurface->enmResType == VMSVGA3D_RESTYPE_TEXTURE_CUBE)
    43554595    {
    43564596        D3D_RELEASE(pBackendSurface->pStagingTexture);
     
    43774617    /* No context has created the surface, because the surface does not exist anymore. */
    43784618    pSurface->idAssociatedContext = SVGA_ID_INVALID;
     4619}
     4620
     4621
     4622static DECLCALLBACK(void) vmsvga3dBackSurfaceInvalidateImage(PVGASTATECC pThisCC, PVMSVGA3DSURFACE pSurface, uint32_t uFace, uint32_t uMipmap)
     4623{
     4624    RT_NOREF(pThisCC, uFace, uMipmap);
     4625
     4626    /* The caller should not use the function for system memory surfaces. */
     4627    PVMSVGA3DBACKENDSURFACE pBackendSurface = pSurface->pBackendSurface;
     4628    if (!pBackendSurface)
     4629        return;
     4630
     4631    LogFunc(("sid=%u\n", pSurface->id));
     4632
     4633    /* The guest uses this to invalidate a buffer. */
     4634    if (pBackendSurface->enmResType == VMSVGA3D_RESTYPE_BUFFER)
     4635    {
     4636        Assert(uFace == 0 && uMipmap == 0); /* The caller ensures this. */
     4637        vmsvga3dBackSurfaceDestroy(pThisCC, pSurface);
     4638    }
     4639    else
     4640    {
     4641        /** @todo Delete views that have been created for this mipmap.
     4642         * For now just delete all views, they will be recte=reated if necessary.
     4643         */
     4644        ASSERT_GUEST_FAILED();
     4645        DXVIEW *pIter, *pNext;
     4646        RTListForEachSafe(&pBackendSurface->u2.Texture.listView, pIter, pNext, DXVIEW, nodeSurfaceView)
     4647        {
     4648            dxViewDestroy(pIter);
     4649        }
     4650    }
    43794651}
    43804652
     
    45194791#endif
    45204792    }
    4521     else if (pBackendSurface->enmResType == VMSVGA3D_RESTYPE_TEXTURE)
     4793    else if (   pBackendSurface->enmResType == VMSVGA3D_RESTYPE_TEXTURE_2D
     4794             || pBackendSurface->enmResType == VMSVGA3D_RESTYPE_TEXTURE_3D)
    45224795    {
    45234796        /** @todo This is generic code and should be in DevVGA-SVGA3d.cpp for backends which support Map/Unmap. */
     
    45304803        uint32_t const cBlocksX = (pBox->w + pSurface->cxBlock - 1) / pSurface->cxBlock;
    45314804        uint32_t const cBlocksY = (pBox->h + pSurface->cyBlock - 1) / pSurface->cyBlock;
    4532         AssertMsgReturn(cBlocksX && cBlocksY, ("Empty box %dx%d\n", pBox->w, pBox->h), VERR_INTERNAL_ERROR);
     4805        AssertMsgReturn(cBlocksX && cBlocksY && pBox->d, ("Empty box %dx%dx%d\n", pBox->w, pBox->h, pBox->d), VERR_INTERNAL_ERROR);
    45334806
    45344807        /* vmsvgaR3GmrTransfer verifies uGuestOffset.
     
    45364809         * to not cause 32 bit overflow when multiplied by cbBlock and cbGuestPitch.
    45374810         */
    4538         uint64_t const uGuestOffset = u32GuestBlockX * pSurface->cbBlock + u32GuestBlockY * cbGuestPitch;
     4811        uint64_t uGuestOffset = u32GuestBlockX * pSurface->cbBlock + u32GuestBlockY * cbGuestPitch;
    45394812        AssertReturn(uGuestOffset < UINT32_MAX, VERR_INVALID_PARAMETER);
     4813
     4814        /* 3D texture needs additional processing. */
     4815        ASSERT_GUEST_RETURN(   pBox->z < D3D11_REQ_TEXTURE3D_U_V_OR_W_DIMENSION
     4816                            && pBox->d <= D3D11_REQ_TEXTURE3D_U_V_OR_W_DIMENSION
     4817                            && pBox->d <= D3D11_REQ_TEXTURE3D_U_V_OR_W_DIMENSION - pBox->z,
     4818                            VERR_INVALID_PARAMETER);
     4819        ASSERT_GUEST_RETURN(   pBox->srcz < D3D11_REQ_TEXTURE3D_U_V_OR_W_DIMENSION
     4820                            && pBox->d <= D3D11_REQ_TEXTURE3D_U_V_OR_W_DIMENSION
     4821                            && pBox->d <= D3D11_REQ_TEXTURE3D_U_V_OR_W_DIMENSION - pBox->srcz,
     4822                            VERR_INVALID_PARAMETER);
     4823
     4824        uGuestOffset += pBox->srcz * pMipLevel->cbSurfacePlane;
    45404825
    45414826        SVGA3dSurfaceImageId image;
     
    45474832        box.x = pBox->x;
    45484833        box.y = pBox->y;
    4549         box.z = 0;
     4834        box.z = pBox->z;
    45504835        box.w = pBox->w;
    45514836        box.h = pBox->h;
    4552         box.d = 1;
     4837        box.d = pBox->d;
    45534838
    45544839        VMSVGA3D_SURFACE_MAP const enmMap = transfer == SVGA3D_WRITE_HOST_VRAM
     
    45704855             * and offset of the first scanline.
    45714856             */
    4572             uint32_t const cbLockedBuf = map.cbRowPitch * cBlocksY;
     4857            uint32_t cbLockedBuf = map.cbRowPitch * cBlocksY;
     4858            if (pBackendSurface->enmResType == VMSVGA3D_RESTYPE_TEXTURE_3D)
     4859                cbLockedBuf += map.cbDepthPitch * (pBox->d - 1); /// @todo why map does not compute this for 2D textures
    45734860            uint8_t *pu8LockedBuf = (uint8_t *)map.pvData;
    4574             uint32_t const offLockedBuf = 0;
    4575 
    4576             rc = vmsvgaR3GmrTransfer(pThis,
    4577                                      pThisCC,
    4578                                      transfer,
    4579                                      pu8LockedBuf,
    4580                                      cbLockedBuf,
    4581                                      offLockedBuf,
    4582                                      map.cbRowPitch,
    4583                                      GuestPtr,
    4584                                      (uint32_t)uGuestOffset,
    4585                                      cbGuestPitch,
    4586                                      cBlocksX * pSurface->cbBlock,
    4587                                      cBlocksY);
    4588             AssertRC(rc);
     4861            uint32_t offLockedBuf = 0;
     4862
     4863            for (uint32_t iPlane = 0; iPlane < pBox->d; ++iPlane)
     4864            {
     4865                AssertBreak(uGuestOffset < UINT32_MAX);
     4866
     4867                rc = vmsvgaR3GmrTransfer(pThis,
     4868                                         pThisCC,
     4869                                         transfer,
     4870                                         pu8LockedBuf,
     4871                                         cbLockedBuf,
     4872                                         offLockedBuf,
     4873                                         map.cbRowPitch,
     4874                                         GuestPtr,
     4875                                         (uint32_t)uGuestOffset,
     4876                                         cbGuestPitch,
     4877                                         cBlocksX * pSurface->cbBlock,
     4878                                         cBlocksY);
     4879                AssertRC(rc);
     4880
     4881                uGuestOffset += pMipLevel->cbSurfacePlane;
     4882                offLockedBuf += map.cbDepthPitch;
     4883            }
    45894884
    45904885            bool const fWritten = (transfer == SVGA3D_WRITE_HOST_VRAM);
     
    46814976    LogFunc(("cid %d\n", pDXContext->cid));
    46824977
    4683     int rc = dxDeviceCreate(pBackend, &pBackendDXContext->device);
     4978    int rc = dxDeviceCreate(pBackend, &pBackendDXContext->dxDevice);
    46844979    return rc;
    46854980}
     
    46974992        VMSVGA3DBACKENDDXCONTEXT *pBackendDXContext = pDXContext->pBackendDXContext;
    46984993
    4699         if (pBackendDXContext->papRenderTargetView)
    4700             DX_RELEASE_ARRAY(pBackendDXContext->cRenderTargetView, pBackendDXContext->papRenderTargetView);
    4701         if (pBackendDXContext->papDepthStencilView)
    4702             DX_RELEASE_ARRAY(pBackendDXContext->cDepthStencilView, pBackendDXContext->papDepthStencilView);
    4703         if (pBackendDXContext->papShaderResourceView)
    4704             DX_RELEASE_ARRAY(pBackendDXContext->cShaderResourceView, pBackendDXContext->papShaderResourceView);
     4994        if (pBackendDXContext->paRenderTargetView)
     4995        {
     4996            for (uint32_t i = 0; i < pBackendDXContext->cRenderTargetView; ++i)
     4997                D3D_RELEASE(pBackendDXContext->paRenderTargetView[i].u.pRenderTargetView);
     4998        }
     4999        if (pBackendDXContext->paDepthStencilView)
     5000        {
     5001            for (uint32_t i = 0; i < pBackendDXContext->cDepthStencilView; ++i)
     5002                D3D_RELEASE(pBackendDXContext->paDepthStencilView[i].u.pDepthStencilView);
     5003        }
     5004        if (pBackendDXContext->paShaderResourceView)
     5005        {
     5006            for (uint32_t i = 0; i < pBackendDXContext->cShaderResourceView; ++i)
     5007                D3D_RELEASE(pBackendDXContext->paShaderResourceView[i].u.pShaderResourceView);
     5008        }
    47055009        if (pBackendDXContext->paElementLayout)
    47065010        {
     
    47345038        RTMemFreeZ(pBackendDXContext->papRasterizerState, sizeof(pBackendDXContext->papRasterizerState[0]) * pBackendDXContext->cRasterizerState);
    47355039        RTMemFreeZ(pBackendDXContext->paElementLayout, sizeof(pBackendDXContext->paElementLayout[0]) * pBackendDXContext->cElementLayout);
    4736         RTMemFreeZ(pBackendDXContext->papRenderTargetView, sizeof(pBackendDXContext->papRenderTargetView[0]) * pBackendDXContext->cRenderTargetView);
    4737         RTMemFreeZ(pBackendDXContext->papDepthStencilView, sizeof(pBackendDXContext->papDepthStencilView[0]) * pBackendDXContext->cDepthStencilView);
    4738         RTMemFreeZ(pBackendDXContext->papShaderResourceView, sizeof(pBackendDXContext->papShaderResourceView[0]) * pBackendDXContext->cShaderResourceView);
     5040        RTMemFreeZ(pBackendDXContext->paRenderTargetView, sizeof(pBackendDXContext->paRenderTargetView[0]) * pBackendDXContext->cRenderTargetView);
     5041        RTMemFreeZ(pBackendDXContext->paDepthStencilView, sizeof(pBackendDXContext->paDepthStencilView[0]) * pBackendDXContext->cDepthStencilView);
     5042        RTMemFreeZ(pBackendDXContext->paShaderResourceView, sizeof(pBackendDXContext->paShaderResourceView[0]) * pBackendDXContext->cShaderResourceView);
    47395043        RTMemFreeZ(pBackendDXContext->papQuery, sizeof(pBackendDXContext->papQuery[0]) * pBackendDXContext->cQuery);
    47405044        RTMemFreeZ(pBackendDXContext->paShader, sizeof(pBackendDXContext->paShader[0]) * pBackendDXContext->cShader);
     
    47705074        }
    47715075
    4772         dxDeviceDestroy(pBackend, &pBackendDXContext->device);
     5076        dxDeviceDestroy(pBackend, &pBackendDXContext->dxDevice);
    47735077
    47745078        RTMemFreeZ(pBackendDXContext, sizeof(*pBackendDXContext));
     
    48105114    RT_NOREF(pBackend);
    48115115
    4812     DXDEVICE *pDevice = &pDXContext->pBackendDXContext->device;
     5116    DXDEVICE *pDevice = dxDeviceFromContext(pThisCC->svga.p3dState, pDXContext);
    48135117    AssertReturn(pDevice->pDevice, VERR_INVALID_STATE);
    48145118
     
    48665170}
    48675171
    4868 
    4869 static DECLCALLBACK(int) vmsvga3dBackDXSetShaderResources(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, uint32_t startView, SVGA3dShaderType type, uint32_t cShaderResourceViewId, SVGA3dShaderResourceViewId const *paShaderResourceViewId)
    4870 {
    4871     PVMSVGA3DBACKEND pBackend = pThisCC->svga.p3dState->pBackend;
    4872     RT_NOREF(pBackend);
    4873 
    4874     DXDEVICE *pDevice = &pDXContext->pBackendDXContext->device;
     5172static int dxSetShaderResources(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, SVGA3dShaderType type)
     5173{
     5174    DXDEVICE *pDevice = dxDeviceFromContext(pThisCC->svga.p3dState, pDXContext);
    48755175    AssertReturn(pDevice->pDevice, VERR_INVALID_STATE);
    48765176
     5177//DEBUG_BREAKPOINT_TEST();
     5178    AssertReturn(type >= SVGA3D_SHADERTYPE_MIN && type < SVGA3D_SHADERTYPE_MAX, VERR_INVALID_PARAMETER);
    48775179    uint32_t const idxShaderState = type - SVGA3D_SHADERTYPE_MIN;
     5180    uint32_t const *pSRIds = &pDXContext->svgaDXContext.shaderState[idxShaderState].shaderResources[0];
    48785181    ID3D11ShaderResourceView *papShaderResourceView[SVGA3D_DX_MAX_SRVIEWS];
    4879     for (uint32_t i = 0; i < cShaderResourceViewId; ++i)
    4880     {
    4881         SVGA3dShaderResourceViewId shaderResourceViewId = paShaderResourceViewId[i];
     5182    for (uint32_t i = 0; i < SVGA3D_DX_MAX_SRVIEWS; ++i)
     5183    {
     5184        SVGA3dShaderResourceViewId shaderResourceViewId = pSRIds[i];
    48825185        if (shaderResourceViewId != SVGA3D_INVALID_ID)
    48835186        {
    48845187            ASSERT_GUEST_RETURN(shaderResourceViewId < pDXContext->pBackendDXContext->cShaderResourceView, VERR_INVALID_PARAMETER);
    4885             papShaderResourceView[i] = pDXContext->pBackendDXContext->papShaderResourceView[shaderResourceViewId];
     5188
     5189            DXVIEW *pDXView = &pDXContext->pBackendDXContext->paShaderResourceView[shaderResourceViewId];
     5190            Assert(pDXView->u.pShaderResourceView);
     5191            papShaderResourceView[i] = pDXView->u.pShaderResourceView;
    48865192        }
    48875193        else
    48885194            papShaderResourceView[i] = NULL;
    4889 
    4890         pDXContext->svgaDXContext.shaderState[idxShaderState].shaderResources[startView + i] = shaderResourceViewId;
    4891     }
    4892 
    4893     dxShaderResourceViewSet(pDevice, type, startView, cShaderResourceViewId, papShaderResourceView);
     5195    }
     5196
     5197    dxShaderResourceViewSet(pDevice, type, 0, SVGA3D_DX_MAX_SRVIEWS, papShaderResourceView);
    48945198    return VINF_SUCCESS;
    48955199}
    48965200
    48975201
     5202static DECLCALLBACK(int) vmsvga3dBackDXSetShaderResources(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, uint32_t startView, SVGA3dShaderType type, uint32_t cShaderResourceViewId, SVGA3dShaderResourceViewId const *paShaderResourceViewId)
     5203{
     5204    PVMSVGA3DBACKEND pBackend = pThisCC->svga.p3dState->pBackend;
     5205    RT_NOREF(pBackend);
     5206
     5207    DXDEVICE *pDevice = dxDeviceFromContext(pThisCC->svga.p3dState, pDXContext);
     5208    AssertReturn(pDevice->pDevice, VERR_INVALID_STATE);
     5209
     5210    RT_NOREF(startView, type, cShaderResourceViewId, paShaderResourceViewId);
     5211
     5212    return VINF_SUCCESS;
     5213}
     5214
     5215
    48985216static DECLCALLBACK(int) vmsvga3dBackDXSetShader(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, SVGA3dShaderType type, PVMSVGA3DSHADER pShader)
    48995217{
     
    49015219    RT_NOREF(pBackend);
    49025220
    4903     DXDEVICE *pDevice = &pDXContext->pBackendDXContext->device;
     5221    DXDEVICE *pDevice = dxDeviceFromContext(pThisCC->svga.p3dState, pDXContext);
    49045222    AssertReturn(pDevice->pDevice, VERR_INVALID_STATE);
    49055223
     
    49165234        pDXShader = NULL;
    49175235
    4918     dxShaderSet(pDXContext, type, pDXShader);
     5236    dxShaderSet(pThisCC, pDXContext, type, pDXShader);
    49195237    return VINF_SUCCESS;
    49205238}
     
    49265244    RT_NOREF(pBackend);
    49275245
    4928     DXDEVICE *pDevice = &pDXContext->pBackendDXContext->device;
     5246    DXDEVICE *pDevice = dxDeviceFromContext(pThisCC->svga.p3dState, pDXContext);
    49295247    AssertReturn(pDevice->pDevice, VERR_INVALID_STATE);
    49305248
     
    49565274    AssertCompile(RT_ELEMENTS(pDXContext->svgaDXContext.shaderState[0].shaderResources) == SVGA3D_DX_MAX_SRVIEWS);
    49575275
    4958     for (uint32_t idxShaderState = 0; idxShaderState < SVGA3D_NUM_SHADERTYPE; ++idxShaderState)
    4959     {
    4960         for (uint32_t idxSR = 0; idxSR < SVGA3D_NUM_SHADERTYPE; ++idxSR)
     5276    int rc;
     5277
     5278    /* Unbind render target views because they mught be (re-)used as shader resource views. */
     5279    DXDEVICE *pDXDevice = dxDeviceFromContext(pThisCC->svga.p3dState, pDXContext);
     5280    pDXDevice->pImmediateContext->OMSetRenderTargets(0, NULL, NULL);
     5281
     5282    /* Make sure that the shader resource views exist. */
     5283    for (uint32_t idxShaderState = 0; idxShaderState < SVGA3D_NUM_SHADERTYPE_DX10 /** @todo SVGA3D_NUM_SHADERTYPE*/; ++idxShaderState)
     5284    {
     5285        for (uint32_t idxSR = 0; idxSR < SVGA3D_DX_MAX_SRVIEWS; ++idxSR)
    49615286        {
    49625287            SVGA3dShaderResourceViewId const shaderResourceViewId = pDXContext->svgaDXContext.shaderState[idxShaderState].shaderResources[idxSR];
     
    49655290                ASSERT_GUEST_RETURN_VOID(shaderResourceViewId < pDXContext->pBackendDXContext->cShaderResourceView);
    49665291
    4967                 uint32_t const sid = dxGetShaderResourceViewSid(pDXContext, shaderResourceViewId);
     5292                SVGACOTableDXSRViewEntry const *pSRViewEntry = dxGetShaderResourceViewEntry(pDXContext, shaderResourceViewId);
     5293                AssertContinue(pSRViewEntry != NULL);
     5294
     5295                uint32_t const sid = pSRViewEntry->sid;
    49685296
    49695297                PVMSVGA3DSURFACE pSurface;
    4970                 int rc = vmsvga3dSurfaceFromSid(pThisCC->svga.p3dState, sid, &pSurface);
     5298                rc = vmsvga3dSurfaceFromSid(pThisCC->svga.p3dState, sid, &pSurface);
    49715299                AssertRCReturnVoid(rc);
    49725300
    4973                 /** @todo The guest might have invalidated the surface. */
    4974                 AssertContinue(pSurface->pBackendSurface);
    4975 
    4976                 /* Wait for the surface to finish drawing. */
    4977                 dxSurfaceWait(pThisCC->svga.p3dState, pSurface, pDXContext->cid);
     5301                /* The guest might have invalidated the surface in which case pSurface->pBackendSurface is NULL. */
     5302                /** @todo This is not needed for "single DX device" mode. */
     5303                if (pSurface->pBackendSurface)
     5304                {
     5305                    /* Wait for the surface to finish drawing. */
     5306                    dxSurfaceWait(pThisCC->svga.p3dState, pSurface, pDXContext->cid);
     5307                }
     5308
     5309                /* If a view has not been created yet, do it now. */
     5310                if (!pDXContext->pBackendDXContext->paShaderResourceView[shaderResourceViewId].u.pView)
     5311                {
     5312//DEBUG_BREAKPOINT_TEST();
     5313                    LogFunc(("Re-creating SRV: sid=%u srvid = %u\n", sid, shaderResourceViewId));
     5314                    rc = dxDefineShaderResourceView(pThisCC, pDXContext, shaderResourceViewId, pSRViewEntry);
     5315                    AssertContinue(RT_SUCCESS(rc));
     5316                }
    49785317            }
    49795318        }
    4980     }
    4981 
    4982 #ifdef DX_DEFERRED_SET_RENDER_TARGETS
    4983     DXDEVICE *pDevice = &pDXContext->pBackendDXContext->device;
     5319
     5320        /* Set shader resources. */
     5321        rc = dxSetShaderResources(pThisCC, pDXContext, (SVGA3dShaderType)(idxShaderState + SVGA3D_SHADERTYPE_MIN));
     5322        AssertRC(rc);
     5323    }
     5324
     5325
     5326    DXDEVICE *pDevice = dxDeviceFromContext(pThisCC->svga.p3dState, pDXContext);
    49845327    AssertReturnVoid(pDevice->pDevice);
    49855328
    4986     pDevice->pImmediateContext->OMSetRenderTargets(pDXContext->pBackendDXContext->state.cRenderTargetViews,
    4987                                                    pDXContext->pBackendDXContext->state.papRenderTargetViews,
    4988                                                    pDXContext->pBackendDXContext->state.pDepthStencilView);
    4989 #endif
     5329    /** @todo Make sure that the render target views exist. Similar to SRVs. */
     5330    if (pDXContext->svgaDXContext.renderState.depthStencilViewId != SVGA3D_INVALID_ID)
     5331    {
     5332        uint32_t const viewId = pDXContext->svgaDXContext.renderState.depthStencilViewId;
     5333
     5334        ASSERT_GUEST_RETURN_VOID(viewId < pDXContext->pBackendDXContext->cDepthStencilView);
     5335
     5336        SVGACOTableDXDSViewEntry const *pDSViewEntry = dxGetDepthStencilViewEntry(pDXContext, viewId);
     5337        AssertReturnVoid(pDSViewEntry != NULL);
     5338
     5339        PVMSVGA3DSURFACE pSurface;
     5340        rc = vmsvga3dSurfaceFromSid(pThisCC->svga.p3dState, pDSViewEntry->sid, &pSurface);
     5341        AssertRCReturnVoid(rc);
     5342
     5343        /* If a view has not been created yet, do it now. */
     5344        if (!pDXContext->pBackendDXContext->paDepthStencilView[viewId].u.pView)
     5345        {
     5346//DEBUG_BREAKPOINT_TEST();
     5347            LogFunc(("Re-creating DSV: sid=%u dsvid = %u\n", pDSViewEntry->sid, viewId));
     5348            rc = dxDefineDepthStencilView(pThisCC, pDXContext, viewId, pDSViewEntry);
     5349            AssertReturnVoid(RT_SUCCESS(rc));
     5350        }
     5351    }
     5352
     5353    for (uint32_t i = 0; i < SVGA3D_MAX_SIMULTANEOUS_RENDER_TARGETS; ++i)
     5354    {
     5355        if (pDXContext->svgaDXContext.renderState.renderTargetViewIds[i] != SVGA3D_INVALID_ID)
     5356        {
     5357            uint32_t const viewId = pDXContext->svgaDXContext.renderState.renderTargetViewIds[i];
     5358
     5359            ASSERT_GUEST_RETURN_VOID(viewId < pDXContext->pBackendDXContext->cRenderTargetView);
     5360
     5361            SVGACOTableDXRTViewEntry const *pRTViewEntry = dxGetRenderTargetViewEntry(pDXContext, viewId);
     5362            AssertReturnVoid(pRTViewEntry != NULL);
     5363
     5364            PVMSVGA3DSURFACE pSurface;
     5365            rc = vmsvga3dSurfaceFromSid(pThisCC->svga.p3dState, pRTViewEntry->sid, &pSurface);
     5366            AssertRCReturnVoid(rc);
     5367
     5368            /* If a view has not been created yet, do it now. */
     5369            if (!pDXContext->pBackendDXContext->paRenderTargetView[viewId].u.pView)
     5370            {
     5371//DEBUG_BREAKPOINT_TEST();
     5372                LogFunc(("Re-creating RTV: sid=%u rtvid = %u\n", pRTViewEntry->sid, viewId));
     5373                rc = dxDefineRenderTargetView(pThisCC, pDXContext, viewId, pRTViewEntry);
     5374                AssertReturnVoid(RT_SUCCESS(rc));
     5375            }
     5376        }
     5377    }
     5378
     5379    /* Set render targets. */
     5380    rc = dxSetRenderTargets(pThisCC, pDXContext);
     5381    AssertRC(rc);
    49905382}
    49915383
     
    49965388    RT_NOREF(pBackend);
    49975389
    4998     DXDEVICE *pDevice = &pDXContext->pBackendDXContext->device;
     5390    DXDEVICE *pDevice = dxDeviceFromContext(pThisCC->svga.p3dState, pDXContext);
    49995391    AssertReturn(pDevice->pDevice, VERR_INVALID_STATE);
    50005392
     
    52465638    RT_NOREF(pBackend);
    52475639
    5248     DXDEVICE *pDevice = &pDXContext->pBackendDXContext->device;
     5640    DXDEVICE *pDevice = dxDeviceFromContext(pThisCC->svga.p3dState, pDXContext);
    52495641    AssertReturn(pDevice->pDevice, VERR_INVALID_STATE);
    52505642
     
    52715663    RT_NOREF(pBackend);
    52725664
    5273     DXDEVICE *pDevice = &pDXContext->pBackendDXContext->device;
     5665    DXDEVICE *pDevice = dxDeviceFromContext(pThisCC->svga.p3dState, pDXContext);
    52745666    AssertReturn(pDevice->pDevice, VERR_INVALID_STATE);
    52755667
     
    52935685    RT_NOREF(pBackend);
    52945686
    5295     DXDEVICE *pDevice = &pDXContext->pBackendDXContext->device;
     5687    DXDEVICE *pDevice = dxDeviceFromContext(pThisCC->svga.p3dState, pDXContext);
    52965688    AssertReturn(pDevice->pDevice, VERR_INVALID_STATE);
    52975689
     
    53275719    RT_NOREF(pBackend);
    53285720
    5329     DXDEVICE *pDevice = &pDXContext->pBackendDXContext->device;
     5721    DXDEVICE *pDevice = dxDeviceFromContext(pThisCC->svga.p3dState, pDXContext);
    53305722    AssertReturn(pDevice->pDevice, VERR_INVALID_STATE);
    53315723
     
    53625754    RT_NOREF(pBackend);
    53635755
    5364     DXDEVICE *pDevice = &pDXContext->pBackendDXContext->device;
     5756    DXDEVICE *pDevice = dxDeviceFromContext(pThisCC->svga.p3dState, pDXContext);
    53655757    AssertReturn(pDevice->pDevice, VERR_INVALID_STATE);
    53665758
     
    54435835    RT_NOREF(pBackend);
    54445836
    5445     DXDEVICE *pDevice = &pDXContext->pBackendDXContext->device;
     5837    DXDEVICE *pDevice = dxDeviceFromContext(pThisCC->svga.p3dState, pDXContext);
    54465838    AssertReturn(pDevice->pDevice, VERR_INVALID_STATE);
    54475839
     
    55535945    RT_NOREF(pBackend);
    55545946
    5555     DXDEVICE *pDevice = &pDXContext->pBackendDXContext->device;
     5947    DXDEVICE *pDevice = dxDeviceFromContext(pThisCC->svga.p3dState, pDXContext);
    55565948    AssertReturn(pDevice->pDevice, VERR_INVALID_STATE);
    55575949
     
    55625954
    55635955
    5564 static DECLCALLBACK(int) vmsvga3dBackDXSetRenderTargets(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, SVGA3dDepthStencilViewId depthStencilViewId, uint32_t cRenderTargetViewId, SVGA3dRenderTargetViewId const *paRenderTargetViewId)
    5565 {
    5566     PVMSVGA3DBACKEND pBackend = pThisCC->svga.p3dState->pBackend;
    5567     RT_NOREF(pBackend);
    5568 
    5569     DXDEVICE *pDevice = &pDXContext->pBackendDXContext->device;
     5956static int dxSetRenderTargets(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext)
     5957{
     5958    //pDXContext->svgaDXContext.renderState.depthStencilViewId = depthStencilViewId;
     5959    //for (uint32_t i = 0; i < cRenderTargetViewId; ++i)
     5960    //    pDXContext->svgaDXContext.renderState.renderTargetViewIds[i] = paRenderTargetViewId[i];
     5961
     5962    DXDEVICE *pDevice = dxDeviceFromContext(pThisCC->svga.p3dState, pDXContext);
    55705963    AssertReturn(pDevice->pDevice, VERR_INVALID_STATE);
    55715964
    5572     ID3D11RenderTargetView *papRenderTargetViews[SVGA3D_MAX_RENDER_TARGETS];
    5573     RT_ZERO(papRenderTargetViews);
    5574     for (uint32_t i = 0; i < cRenderTargetViewId; ++i)
    5575     {
    5576         SVGA3dRenderTargetViewId const renderTargetViewId = paRenderTargetViewId[i];
     5965    ID3D11RenderTargetView *apRenderTargetViews[SVGA3D_MAX_RENDER_TARGETS];
     5966    RT_ZERO(apRenderTargetViews);
     5967    for (uint32_t i = 0; i < SVGA3D_MAX_RENDER_TARGETS; ++i)
     5968    {
     5969        SVGA3dRenderTargetViewId const renderTargetViewId = pDXContext->svgaDXContext.renderState.renderTargetViewIds[i];
    55775970        if (renderTargetViewId != SVGA3D_INVALID_ID)
    55785971        {
    55795972            ASSERT_GUEST_RETURN(renderTargetViewId < pDXContext->pBackendDXContext->cRenderTargetView, VERR_INVALID_PARAMETER);
    5580             papRenderTargetViews[i] = pDXContext->pBackendDXContext->papRenderTargetView[renderTargetViewId];
     5973            apRenderTargetViews[i] = pDXContext->pBackendDXContext->paRenderTargetView[renderTargetViewId].u.pRenderTargetView;
    55815974        }
    55825975    }
    55835976
    5584     ID3D11DepthStencilView *pDepthStencilView;
     5977    ID3D11DepthStencilView *pDepthStencilView = NULL;
     5978    SVGA3dDepthStencilViewId const depthStencilViewId = pDXContext->svgaDXContext.renderState.depthStencilViewId;
    55855979    if (depthStencilViewId != SVGA_ID_INVALID)
    5586         pDepthStencilView = pDXContext->pBackendDXContext->papDepthStencilView[depthStencilViewId];
    5587     else
    5588         pDepthStencilView = NULL;
    5589 
    5590 #ifdef DX_DEFERRED_SET_RENDER_TARGETS
    5591     memcpy(pDXContext->pBackendDXContext->state.papRenderTargetViews, papRenderTargetViews, sizeof(papRenderTargetViews));
    5592     pDXContext->pBackendDXContext->state.cRenderTargetViews = cRenderTargetViewId;
    5593     pDXContext->pBackendDXContext->state.pDepthStencilView = pDepthStencilView;
    5594     pDevice->pImmediateContext->OMSetRenderTargets(0, NULL, NULL);
    5595 #else
    5596     pDevice->pImmediateContext->OMSetRenderTargets(cRenderTargetViewId, papRenderTargetViews, pDepthStencilView);
    5597 #endif
     5980        pDepthStencilView = pDXContext->pBackendDXContext->paDepthStencilView[depthStencilViewId].u.pDepthStencilView;
     5981
     5982    pDevice->pImmediateContext->OMSetRenderTargets(SVGA3D_MAX_RENDER_TARGETS,
     5983                                                   apRenderTargetViews,
     5984                                                   pDepthStencilView);
    55985985    return VINF_SUCCESS;
    55995986}
    56005987
    56015988
     5989static DECLCALLBACK(int) vmsvga3dBackDXSetRenderTargets(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, SVGA3dDepthStencilViewId depthStencilViewId, uint32_t cRenderTargetViewId, SVGA3dRenderTargetViewId const *paRenderTargetViewId)
     5990{
     5991    PVMSVGA3DBACKEND pBackend = pThisCC->svga.p3dState->pBackend;
     5992    RT_NOREF(pBackend);
     5993
     5994    DXDEVICE *pDevice = dxDeviceFromContext(pThisCC->svga.p3dState, pDXContext);
     5995    AssertReturn(pDevice->pDevice, VERR_INVALID_STATE);
     5996
     5997    RT_NOREF(depthStencilViewId, cRenderTargetViewId, paRenderTargetViewId);
     5998
     5999    return VINF_SUCCESS;
     6000}
     6001
     6002
    56026003static DECLCALLBACK(int) vmsvga3dBackDXSetBlendState(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, SVGA3dBlendStateId blendId, float const blendFactor[4], uint32_t sampleMask)
    56036004{
     
    56056006    RT_NOREF(pBackend);
    56066007
    5607     DXDEVICE *pDevice = &pDXContext->pBackendDXContext->device;
     6008    DXDEVICE *pDevice = dxDeviceFromContext(pThisCC->svga.p3dState, pDXContext);
    56086009    AssertReturn(pDevice->pDevice, VERR_INVALID_STATE);
    56096010
     
    56276028    RT_NOREF(pBackend);
    56286029
    5629     DXDEVICE *pDevice = &pDXContext->pBackendDXContext->device;
     6030    DXDEVICE *pDevice = dxDeviceFromContext(pThisCC->svga.p3dState, pDXContext);
    56306031    AssertReturn(pDevice->pDevice, VERR_INVALID_STATE);
    56316032
     
    56436044{
    56446045    PVMSVGA3DBACKEND pBackend = pThisCC->svga.p3dState->pBackend;
    5645     DXDEVICE *pDevice = &pDXContext->pBackendDXContext->device;
     6046    DXDEVICE *pDevice = dxDeviceFromContext(pThisCC->svga.p3dState, pDXContext);
    56466047    AssertReturn(pDevice->pDevice, VERR_INVALID_STATE);
    56476048
     
    57386139    RT_NOREF(pBackend);
    57396140
    5740     DXDEVICE *pDevice = &pDXContext->pBackendDXContext->device;
     6141    DXDEVICE *pDevice = dxDeviceFromContext(pThisCC->svga.p3dState, pDXContext);
    57416142    AssertReturn(pDevice->pDevice, VERR_INVALID_STATE);
    57426143
     
    57956196{
    57966197    PVMSVGA3DBACKEND pBackend = pThisCC->svga.p3dState->pBackend;
    5797     DXDEVICE *pDevice = &pDXContext->pBackendDXContext->device;
     6198    DXDEVICE *pDevice = dxDeviceFromContext(pThisCC->svga.p3dState, pDXContext);
    57986199    AssertReturn(pDevice->pDevice, VERR_INVALID_STATE);
    57996200
     
    58136214    RT_NOREF(pBackend);
    58146215
    5815     DXDEVICE *pDevice = &pDXContext->pBackendDXContext->device;
     6216    DXDEVICE *pDevice = dxDeviceFromContext(pThisCC->svga.p3dState, pDXContext);
    58166217    AssertReturn(pDevice->pDevice, VERR_INVALID_STATE);
    58176218
     
    58296230    RT_NOREF(pBackend);
    58306231
    5831     DXDEVICE *pDevice = &pDXContext->pBackendDXContext->device;
     6232    DXDEVICE *pDevice = dxDeviceFromContext(pThisCC->svga.p3dState, pDXContext);
    58326233    AssertReturn(pDevice->pDevice, VERR_INVALID_STATE);
    58336234
    5834     ID3D11RenderTargetView *pRenderTargetView = pDXContext->pBackendDXContext->papRenderTargetView[renderTargetViewId];
    5835     AssertReturn(pRenderTargetView, VERR_INVALID_STATE);
    5836     pDevice->pImmediateContext->ClearRenderTargetView(pRenderTargetView, pRGBA->value);
     6235    DXVIEW *pDXView = &pDXContext->pBackendDXContext->paRenderTargetView[renderTargetViewId];
     6236    if (!pDXView->u.pRenderTargetView)
     6237    {
     6238//DEBUG_BREAKPOINT_TEST();
     6239        /* (Re-)create the render target view, because a creation of a view is deferred until a draw or a clear call. */
     6240        SVGACOTableDXRTViewEntry const *pEntry = &pDXContext->cot.paRTView[renderTargetViewId];
     6241        int rc = dxDefineRenderTargetView(pThisCC, pDXContext, renderTargetViewId, pEntry);
     6242        AssertRCReturn(rc, rc);
     6243    }
     6244    pDevice->pImmediateContext->ClearRenderTargetView(pDXView->u.pRenderTargetView, pRGBA->value);
    58376245    return VINF_SUCCESS;
    58386246}
     
    58446252    RT_NOREF(pBackend);
    58456253
    5846     DXDEVICE *pDevice = &pDXContext->pBackendDXContext->device;
     6254    DXDEVICE *pDevice = dxDeviceFromContext(pThisCC->svga.p3dState, pDXContext);
    58476255    AssertReturn(pDevice->pDevice, VERR_INVALID_STATE);
    58486256
    5849     ID3D11DepthStencilView *pDepthStencilView = pDXContext->pBackendDXContext->papDepthStencilView[depthStencilViewId];
    5850     AssertReturn(pDepthStencilView, VERR_INVALID_STATE);
    5851     pDevice->pImmediateContext->ClearDepthStencilView(pDepthStencilView, flags, depth, stencil);
     6257    DXVIEW *pDXView = &pDXContext->pBackendDXContext->paDepthStencilView[depthStencilViewId];
     6258    if (!pDXView->u.pDepthStencilView)
     6259    {
     6260//DEBUG_BREAKPOINT_TEST();
     6261        /* (Re-)create the depth stencil view, because a creation of a view is deferred until a draw or a clear call. */
     6262        SVGACOTableDXDSViewEntry const *pEntry = &pDXContext->cot.paDSView[depthStencilViewId];
     6263        int rc = dxDefineDepthStencilView(pThisCC, pDXContext, depthStencilViewId, pEntry);
     6264        AssertRCReturn(rc, rc);
     6265    }
     6266    pDevice->pImmediateContext->ClearDepthStencilView(pDXView->u.pDepthStencilView, flags, depth, stencil);
    58526267    return VINF_SUCCESS;
    58536268}
     
    58596274    RT_NOREF(pBackend);
    58606275
    5861     DXDEVICE *pDevice = &pDXContext->pBackendDXContext->device;
     6276    DXDEVICE *pDevice = dxDeviceFromContext(pThisCC->svga.p3dState, pDXContext);
    58626277    AssertReturn(pDevice->pDevice, VERR_INVALID_STATE);
    58636278
     
    59646379    RT_NOREF(pBackend);
    59656380
    5966     DXDEVICE *pDevice = &pDXContext->pBackendDXContext->device;
     6381    DXDEVICE *pDevice = dxDeviceFromContext(pThisCC->svga.p3dState, pDXContext);
    59676382    AssertReturn(pDevice->pDevice, VERR_INVALID_STATE);
    59686383
    5969     ID3D11ShaderResourceView *pShaderResourceView = pDXContext->pBackendDXContext->papShaderResourceView[shaderResourceViewId];
     6384    ID3D11ShaderResourceView *pShaderResourceView = pDXContext->pBackendDXContext->paShaderResourceView[shaderResourceViewId].u.pShaderResourceView;
    59706385    AssertReturn(pShaderResourceView, VERR_INVALID_STATE);
    59716386
    5972     uint32_t const sid = dxGetShaderResourceViewSid(pDXContext, shaderResourceViewId);
     6387    SVGACOTableDXSRViewEntry const *pSRViewEntry = dxGetShaderResourceViewEntry(pDXContext, shaderResourceViewId);
     6388    AssertReturn(pSRViewEntry, VERR_INVALID_STATE);
     6389
     6390    uint32_t const sid = pSRViewEntry->sid;
    59736391
    59746392    PVMSVGA3DSURFACE pSurface;
     
    59916409    AssertRCReturn(rc, rc);
    59926410
     6411    ID3D11ShaderResourceView *pShaderResourceView;
     6412    DXVIEW *pView = &pDXContext->pBackendDXContext->paShaderResourceView[shaderResourceViewId];
     6413    Assert(pView->u.pView == NULL);
     6414
    59936415    if (pSurface->pBackendSurface == NULL)
    59946416    {
     
    59986420    }
    59996421
    6000     HRESULT hr = dxShaderResourceViewCreate(pThisCC, pDXContext, pEntry, pSurface, &pDXContext->pBackendDXContext->papShaderResourceView[shaderResourceViewId]);
    6001     if (SUCCEEDED(hr))
    6002         return VINF_SUCCESS;
    6003     return VERR_INVALID_STATE;
     6422    HRESULT hr = dxShaderResourceViewCreate(pThisCC, pDXContext, pEntry, pSurface, &pShaderResourceView);
     6423    AssertReturn(SUCCEEDED(hr), VERR_INVALID_STATE);
     6424
     6425    return dxViewInit(pView, pSurface, pDXContext, shaderResourceViewId, VMSVGA3D_VIEWTYPE_SHADERRESOURCE, pShaderResourceView);
    60046426}
    60056427
     
    60106432    RT_NOREF(pBackend);
    60116433
    6012     DXDEVICE *pDevice = &pDXContext->pBackendDXContext->device;
     6434    DXDEVICE *pDevice = dxDeviceFromContext(pThisCC->svga.p3dState, pDXContext);
    60136435    AssertReturn(pDevice->pDevice, VERR_INVALID_STATE);
    60146436
     
    60226444    RT_NOREF(pBackend);
    60236445
    6024     D3D_RELEASE(pDXContext->pBackendDXContext->papShaderResourceView[shaderResourceViewId]);
    6025     return VINF_SUCCESS;
     6446    return dxViewDestroy(&pDXContext->pBackendDXContext->paShaderResourceView[shaderResourceViewId]);
    60266447}
    60276448
     
    60346455    AssertRCReturn(rc, rc);
    60356456
     6457    DXVIEW *pView = &pDXContext->pBackendDXContext->paRenderTargetView[renderTargetViewId];
     6458    Assert(pView->u.pView == NULL);
     6459
    60366460    if (pSurface->pBackendSurface == NULL)
    60376461    {
     
    60416465    }
    60426466
    6043     HRESULT hr = dxRenderTargetViewCreate(pThisCC, pDXContext, pEntry, pSurface, &pDXContext->pBackendDXContext->papRenderTargetView[renderTargetViewId]);
    6044     if (SUCCEEDED(hr))
    6045         return VINF_SUCCESS;
    6046 
    6047     return VERR_INVALID_STATE;
     6467    ID3D11RenderTargetView *pRenderTargetView;
     6468    HRESULT hr = dxRenderTargetViewCreate(pThisCC, pDXContext, pEntry, pSurface, &pRenderTargetView);
     6469    AssertReturn(SUCCEEDED(hr), VERR_INVALID_STATE);
     6470
     6471    return dxViewInit(pView, pSurface, pDXContext, renderTargetViewId, VMSVGA3D_VIEWTYPE_RENDERTARGET, pRenderTargetView);
    60486472}
    60496473
     
    60546478    RT_NOREF(pBackend);
    60556479
    6056     DXDEVICE *pDevice = &pDXContext->pBackendDXContext->device;
     6480    DXDEVICE *pDevice = dxDeviceFromContext(pThisCC->svga.p3dState, pDXContext);
    60576481    AssertReturn(pDevice->pDevice, VERR_INVALID_STATE);
    60586482
     
    60666490    RT_NOREF(pBackend);
    60676491
    6068     D3D_RELEASE(pDXContext->pBackendDXContext->papRenderTargetView[renderTargetViewId]);
    6069     return VINF_SUCCESS;
     6492    return dxViewDestroy(&pDXContext->pBackendDXContext->paRenderTargetView[renderTargetViewId]);
    60706493}
    60716494
     
    60786501    AssertRCReturn(rc, rc);
    60796502
     6503    DXVIEW *pView = &pDXContext->pBackendDXContext->paDepthStencilView[depthStencilViewId];
     6504    Assert(pView->u.pView == NULL);
     6505
    60806506    if (   pSurface->pBackendSurface != NULL
    60816507        && pDXContext->cid != pSurface->idAssociatedContext)
     
    60926518    }
    60936519
    6094     HRESULT hr = dxDepthStencilViewCreate(pThisCC, pDXContext, pEntry, pSurface, &pDXContext->pBackendDXContext->papDepthStencilView[depthStencilViewId]);
    6095     if (SUCCEEDED(hr))
    6096         return VINF_SUCCESS;
    6097     return VERR_INVALID_STATE;
     6520    ID3D11DepthStencilView *pDepthStencilView;
     6521    HRESULT hr = dxDepthStencilViewCreate(pThisCC, pDXContext, pEntry, pSurface, &pDepthStencilView);
     6522    AssertReturn(SUCCEEDED(hr), VERR_INVALID_STATE);
     6523
     6524    return dxViewInit(pView, pSurface, pDXContext, depthStencilViewId, VMSVGA3D_VIEWTYPE_DEPTHSTENCIL, pDepthStencilView);
    60986525}
    60996526
     
    61036530    RT_NOREF(pBackend);
    61046531
    6105     DXDEVICE *pDevice = &pDXContext->pBackendDXContext->device;
     6532    DXDEVICE *pDevice = dxDeviceFromContext(pThisCC->svga.p3dState, pDXContext);
    61066533    AssertReturn(pDevice->pDevice, VERR_INVALID_STATE);
    61076534
     
    61156542    RT_NOREF(pBackend);
    61166543
    6117     D3D_RELEASE(pDXContext->pBackendDXContext->papDepthStencilView[depthStencilViewId]);
    6118     return VINF_SUCCESS;
     6544    return dxViewDestroy(&pDXContext->pBackendDXContext->paDepthStencilView[depthStencilViewId]);
    61196545}
    61206546
     
    61576583{
    61586584    PVMSVGA3DBACKEND pBackend = pThisCC->svga.p3dState->pBackend;
    6159     DXDEVICE *pDevice = &pDXContext->pBackendDXContext->device;
     6585    DXDEVICE *pDevice = dxDeviceFromContext(pThisCC->svga.p3dState, pDXContext);
    61606586    AssertReturn(pDevice->pDevice, VERR_INVALID_STATE);
    61616587
     
    61836609
    61846610
    6185 static int dxDefineBlendState(PVMSVGA3DDXCONTEXT pDXContext,
     6611static int dxDefineBlendState(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext,
    61866612                              SVGA3dBlendStateId blendId, SVGACOTableDXBlendStateEntry const *pEntry)
    61876613{
    6188     DXDEVICE *pDevice = &pDXContext->pBackendDXContext->device;
     6614    DXDEVICE *pDevice = dxDeviceFromContext(pThisCC->svga.p3dState, pDXContext);
    61896615    AssertReturn(pDevice->pDevice, VERR_INVALID_STATE);
    61906616
     
    62016627    RT_NOREF(pBackend);
    62026628
    6203     return dxDefineBlendState(pDXContext, blendId, pEntry);
     6629    return dxDefineBlendState(pThisCC, pDXContext, blendId, pEntry);
    62046630}
    62056631
     
    62156641
    62166642
    6217 static int dxDefineDepthStencilState(PVMSVGA3DDXCONTEXT pDXContext, SVGA3dDepthStencilStateId depthStencilId, SVGACOTableDXDepthStencilEntry const *pEntry)
    6218 {
    6219     DXDEVICE *pDevice = &pDXContext->pBackendDXContext->device;
     6643static int dxDefineDepthStencilState(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, SVGA3dDepthStencilStateId depthStencilId, SVGACOTableDXDepthStencilEntry const *pEntry)
     6644{
     6645    DXDEVICE *pDevice = dxDeviceFromContext(pThisCC->svga.p3dState, pDXContext);
    62206646    AssertReturn(pDevice->pDevice, VERR_INVALID_STATE);
    62216647
     
    62326658    RT_NOREF(pBackend);
    62336659
    6234     return dxDefineDepthStencilState(pDXContext, depthStencilId, pEntry);
     6660    return dxDefineDepthStencilState(pThisCC, pDXContext, depthStencilId, pEntry);
    62356661}
    62366662
     
    62466672
    62476673
    6248 static int dxDefineRasterizerState(PVMSVGA3DDXCONTEXT pDXContext, SVGA3dRasterizerStateId rasterizerId, SVGACOTableDXRasterizerStateEntry const *pEntry)
    6249 {
    6250     DXDEVICE *pDevice = &pDXContext->pBackendDXContext->device;
     6674static int dxDefineRasterizerState(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, SVGA3dRasterizerStateId rasterizerId, SVGACOTableDXRasterizerStateEntry const *pEntry)
     6675{
     6676    DXDEVICE *pDevice = dxDeviceFromContext(pThisCC->svga.p3dState, pDXContext);
    62516677    AssertReturn(pDevice->pDevice, VERR_INVALID_STATE);
    62526678
     
    62636689    RT_NOREF(pBackend);
    62646690
    6265     return dxDefineRasterizerState(pDXContext, rasterizerId, pEntry);
     6691    return dxDefineRasterizerState(pThisCC, pDXContext, rasterizerId, pEntry);
    62666692}
    62676693
     
    62776703
    62786704
    6279 static int dxDefineSamplerState(PVMSVGA3DDXCONTEXT pDXContext, SVGA3dSamplerId samplerId, SVGACOTableDXSamplerEntry const *pEntry)
    6280 {
    6281     DXDEVICE *pDevice = &pDXContext->pBackendDXContext->device;
     6705static int dxDefineSamplerState(PVGASTATECC pThisCC, PVMSVGA3DDXCONTEXT pDXContext, SVGA3dSamplerId samplerId, SVGACOTableDXSamplerEntry const *pEntry)
     6706{
     6707    DXDEVICE *pDevice = dxDeviceFromContext(pThisCC->svga.p3dState, pDXContext);
    62826708    AssertReturn(pDevice->pDevice, VERR_INVALID_STATE);
    62836709
     
    62946720    RT_NOREF(pBackend);
    62956721
    6296     return dxDefineSamplerState(pDXContext, samplerId, pEntry);
     6722    return dxDefineSamplerState(pThisCC, pDXContext, samplerId, pEntry);
    62976723}
    62986724
     
    63666792{
    63676793    PVMSVGA3DBACKEND pBackend = pThisCC->svga.p3dState->pBackend;
    6368     DXDEVICE *pDevice = &pDXContext->pBackendDXContext->device;
     6794    DXDEVICE *pDevice = dxDeviceFromContext(pThisCC->svga.p3dState, pDXContext);
    63696795    AssertReturn(pDevice->pDevice, VERR_INVALID_STATE);
    63706796
     
    64036829#endif
    64046830
    6405             HRESULT hr = dxShaderCreate(pDXContext, pShader, pDXShader);
     6831            HRESULT hr = dxShaderCreate(pThisCC, pDXContext, pShader, pDXShader);
    64066832            if (SUCCEEDED(hr))
    64076833            {
     
    65006926        case SVGA_COTABLE_RTVIEW:
    65016927            /* Clear current entries. */
    6502             if (pBackendDXContext->papRenderTargetView)
     6928            if (pBackendDXContext->paRenderTargetView)
    65036929            {
    6504                 for (uint32_t i = cValidEntries; i < pBackendDXContext->cRenderTargetView; ++i)
    6505                     D3D_RELEASE(pBackendDXContext->papRenderTargetView[i]);
     6930                for (uint32_t i = 0; i < pBackendDXContext->cRenderTargetView; ++i)
     6931                {
     6932                    DXVIEW *pDXView = &pBackendDXContext->paRenderTargetView[i];
     6933                    if (i < cValidEntries)
     6934                        dxViewRemoveFromList(pDXView); /* Remove from list because DXVIEW array will be reallocated. */
     6935                    else
     6936                        dxViewDestroy(pDXView);
     6937                }
    65066938            }
    65076939
    6508             rc = dxCOTableRealloc((void **)&pBackendDXContext->papRenderTargetView, &pBackendDXContext->cRenderTargetView,
    6509                                   sizeof(pBackendDXContext->papRenderTargetView[0]), pDXContext->cot.cRTView, cValidEntries);
     6940            rc = dxCOTableRealloc((void **)&pBackendDXContext->paRenderTargetView, &pBackendDXContext->cRenderTargetView,
     6941                                  sizeof(pBackendDXContext->paRenderTargetView[0]), pDXContext->cot.cRTView, cValidEntries);
    65106942            AssertRCBreak(rc);
    65116943
     
    65166948                    continue; /* Skip uninitialized entry. */
    65176949
    6518                 dxDefineRenderTargetView(pThisCC, pDXContext, i, pEntry);
     6950                DXVIEW *pDXView = &pBackendDXContext->paRenderTargetView[i];
     6951                /** @todo Verify that the pEntry content still corresponds to the view. */
     6952                if (pDXView->u.pView)
     6953                    dxViewAddToList(pThisCC, pDXView);
    65196954            }
    65206955            break;
    65216956        case SVGA_COTABLE_DSVIEW:
    6522             if (pBackendDXContext->papDepthStencilView)
     6957            if (pBackendDXContext->paDepthStencilView)
    65236958            {
    6524                 for (uint32_t i = cValidEntries; i < pBackendDXContext->cDepthStencilView; ++i)
    6525                     D3D_RELEASE(pBackendDXContext->papDepthStencilView[i]);
     6959                for (uint32_t i = 0; i < pBackendDXContext->cDepthStencilView; ++i)
     6960                {
     6961                    DXVIEW *pDXView = &pBackendDXContext->paDepthStencilView[i];
     6962                    if (i < cValidEntries)
     6963                        dxViewRemoveFromList(pDXView); /* Remove from list because DXVIEW array will be reallocated. */
     6964                    else
     6965                        dxViewDestroy(pDXView);
     6966                }
    65266967            }
    65276968
    6528             rc = dxCOTableRealloc((void **)&pBackendDXContext->papDepthStencilView, &pBackendDXContext->cDepthStencilView,
    6529                                   sizeof(pBackendDXContext->papDepthStencilView[0]), pDXContext->cot.cDSView, cValidEntries);
     6969            rc = dxCOTableRealloc((void **)&pBackendDXContext->paDepthStencilView, &pBackendDXContext->cDepthStencilView,
     6970                                  sizeof(pBackendDXContext->paDepthStencilView[0]), pDXContext->cot.cDSView, cValidEntries);
    65306971            AssertRCBreak(rc);
    65316972
     
    65366977                    continue; /* Skip uninitialized entry. */
    65376978
    6538                 dxDefineDepthStencilView(pThisCC, pDXContext, i, pEntry);
     6979                DXVIEW *pDXView = &pBackendDXContext->paDepthStencilView[i];
     6980                /** @todo Verify that the pEntry content still corresponds to the view. */
     6981                if (pDXView->u.pView)
     6982                    dxViewAddToList(pThisCC, pDXView);
    65396983            }
    65406984            break;
    65416985        case SVGA_COTABLE_SRVIEW:
    6542             if (pBackendDXContext->papShaderResourceView)
     6986            if (pBackendDXContext->paShaderResourceView)
    65436987            {
    6544                 for (uint32_t i = cValidEntries; i < pBackendDXContext->cShaderResourceView; ++i)
    6545                     D3D_RELEASE(pBackendDXContext->papShaderResourceView[i]);
     6988                for (uint32_t i = 0; i < pBackendDXContext->cShaderResourceView; ++i)
     6989                {
     6990                    DXVIEW *pDXView = &pBackendDXContext->paShaderResourceView[i];
     6991                    if (i < cValidEntries)
     6992                        dxViewRemoveFromList(pDXView); /* Remove from list because DXVIEW array will be reallocated. */
     6993                    else
     6994                        dxViewDestroy(pDXView);
     6995                }
    65466996            }
    65476997
    6548             rc = dxCOTableRealloc((void **)&pBackendDXContext->papShaderResourceView, &pBackendDXContext->cShaderResourceView,
    6549                                   sizeof(pBackendDXContext->papShaderResourceView[0]), pDXContext->cot.cSRView, cValidEntries);
     6998            rc = dxCOTableRealloc((void **)&pBackendDXContext->paShaderResourceView, &pBackendDXContext->cShaderResourceView,
     6999                                  sizeof(pBackendDXContext->paShaderResourceView[0]), pDXContext->cot.cSRView, cValidEntries);
    65507000            AssertRCBreak(rc);
    65517001
     
    65567006                    continue; /* Skip uninitialized entry. */
    65577007
    6558                 dxDefineShaderResourceView(pThisCC, pDXContext, i, pEntry);
     7008                DXVIEW *pDXView = &pBackendDXContext->paShaderResourceView[i];
     7009                /** @todo Verify that the pEntry content still corresponds to the view. */
     7010                if (pDXView->u.pView)
     7011                    dxViewAddToList(pThisCC, pDXView);
    65597012            }
    65607013            break;
     
    65967049                    continue; /* Skip uninitialized entry. */
    65977050
    6598                 dxDefineBlendState(pDXContext, i, pEntry);
     7051                dxDefineBlendState(pThisCC, pDXContext, i, pEntry);
    65997052            }
    66007053            break;
     
    66167069                    continue; /* Skip uninitialized entry. */
    66177070
    6618                 dxDefineDepthStencilState(pDXContext, i, pEntry);
     7071                dxDefineDepthStencilState(pThisCC, pDXContext, i, pEntry);
    66197072            }
    66207073            break;
     
    66367089                    continue; /* Skip uninitialized entry. */
    66377090
    6638                 dxDefineRasterizerState(pDXContext, i, pEntry);
     7091                dxDefineRasterizerState(pThisCC, pDXContext, i, pEntry);
    66397092            }
    66407093            break;
     
    66567109                    continue; /* Skip uninitialized entry. */
    66577110
    6658                 dxDefineSamplerState(pDXContext, i, pEntry);
     7111                dxDefineSamplerState(pThisCC, pDXContext, i, pEntry);
    66597112            }
    66607113            break;
     
    74657918                p->pfnCreateTexture            = vmsvga3dBackCreateTexture;
    74667919                p->pfnSurfaceDestroy           = vmsvga3dBackSurfaceDestroy;
     7920                p->pfnSurfaceInvalidateImage   = vmsvga3dBackSurfaceInvalidateImage;
    74677921                p->pfnSurfaceCopy              = vmsvga3dBackSurfaceCopy;
    74687922                p->pfnSurfaceDMACopyBox        = vmsvga3dBackSurfaceDMACopyBox;
  • trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-win.cpp

    r93115 r94063  
    11711171
    11721172
     1173static DECLCALLBACK(void) vmsvga3dBackSurfaceInvalidateImage(PVGASTATECC pThisCC, PVMSVGA3DSURFACE pSurface, uint32_t uFace, uint32_t uMipmap)
     1174{
     1175    RT_NOREF(pThisCC, pSurface, uFace, uMipmap);
     1176}
     1177
     1178
    11731179/*
    11741180 * Release all shared surface objects.
     
    63856391                p->pfnCreateTexture            = vmsvga3dBackCreateTexture;
    63866392                p->pfnSurfaceDestroy           = vmsvga3dBackSurfaceDestroy;
     6393                p->pfnSurfaceInvalidateImage   = vmsvga3dBackSurfaceInvalidateImage;
    63876394                p->pfnSurfaceCopy              = vmsvga3dBackSurfaceCopy;
    63886395                p->pfnSurfaceDMACopyBox        = vmsvga3dBackSurfaceDMACopyBox;
  • trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d.cpp

    r93115 r94063  
    11481148        AssertRCReturn(rc, rc);
    11491149
     1150        /* Invalidate views, etc. */
     1151        PVMSVGAR3STATE const pSvgaR3State = pThisCC->svga.pSvgaR3State;
     1152        if (pSvgaR3State->pFuncs3D)
     1153            pSvgaR3State->pFuncs3D->pfnSurfaceInvalidateImage(pThisCC, pSurface, face, mipmap);
     1154
    11501155        pMipmapLevel->fDirty = true;
    11511156    }
  • trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d.h

    r93115 r94063  
    321321    DECLCALLBACKMEMBER(int,  pfnCreateTexture,            (PVGASTATECC pThisCC, PVMSVGA3DCONTEXT pContext, uint32_t idAssociatedContext, PVMSVGA3DSURFACE pSurface));
    322322    DECLCALLBACKMEMBER(void, pfnSurfaceDestroy,           (PVGASTATECC pThisCC, PVMSVGA3DSURFACE pSurface));
     323    DECLCALLBACKMEMBER(void, pfnSurfaceInvalidateImage,   (PVGASTATECC pThisCC, PVMSVGA3DSURFACE pSurface, uint32_t uFace, uint32_t uMipmap));
    323324    DECLCALLBACKMEMBER(int,  pfnSurfaceCopy,              (PVGASTATECC pThisCC, SVGA3dSurfaceImageId dest, SVGA3dSurfaceImageId src, uint32_t cCopyBoxes, SVGA3dCopyBox *pBox));
    324325    DECLCALLBACKMEMBER(int,  pfnSurfaceDMACopyBox,        (PVGASTATE pThis, PVGASTATECC pThisCC, PVMSVGA3DSTATE pState, PVMSVGA3DSURFACE pSurface,
Note: See TracChangeset for help on using the changeset viewer.

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