Index: trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxDispD3D.cpp
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxDispD3D.cpp	(revision 30556)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxDispD3D.cpp	(revision 30563)
@@ -1645,5 +1645,4 @@
     else
     {
-        AssertBreakpoint();
         hr = pDevice->pDevice9If->DrawPrimitive(pData->PrimitiveType,
                                                 pData->VStart,
@@ -2193,5 +2192,5 @@
     if (VBOXDISPMODE_IS_3D(pDevice->pAdapter))
     {
-        if (pRc->RcDesc.fFlags.Texture)
+        if (pRc->RcDesc.fFlags.Texture || pRc->RcDesc.fFlags.Value == 0)
         {
             PVBOXWDDMDISP_ALLOCATION pTexAlloc = &pRc->aAllocations[0];
@@ -2396,4 +2395,101 @@
             }
         }
+        else if (pRc->RcDesc.fFlags.IndexBuffer)
+        {
+            Assert(pData->SubResourceIndex < pRc->cAllocations);
+            PVBOXWDDMDISP_ALLOCATION pAlloc = &pRc->aAllocations[pData->SubResourceIndex];
+            IDirect3DIndexBuffer9 *pD3D9IBuf = (IDirect3DIndexBuffer9*)pAlloc->pD3DIf;
+            BOOL bLocked = false;
+            Assert(pD3D9IBuf);
+            Assert(!pData->Flags.AreaValid);
+            Assert(!pData->Flags.BoxValid);
+            D3DDDIRANGE *pRange = NULL;
+            if (pData->Flags.RangeValid)
+            {
+                pRange = &pData->Range;
+            }
+
+            /* else - we lock the entire vertex buffer, pRect == NULL */
+
+            Assert(!pAlloc->LockInfo.cLocks);
+            if (!pAlloc->LockInfo.cLocks)
+            {
+                if (!pData->Flags.MightDrawFromLocked || (!pData->Flags.Discard && !pData->Flags.NoOverwrite))
+                {
+                    hr = pD3D9IBuf->Lock(pRange ? pRange->Offset : 0,
+                                          pRange ? pRange->Size : 0,
+                                          &pAlloc->LockInfo.LockedRect.pBits,
+                                          vboxDDI2D3DLockFlags(pData->Flags));
+                    bLocked = true;
+                }
+
+                Assert(hr == S_OK);
+                if (hr == S_OK)
+                {
+                    pAlloc->LockInfo.LockedRect.Pitch = pAlloc->SurfDesc.width;
+//                    Assert(pLockAlloc->LockInfo.fFlags.Value == 0);
+                    pAlloc->LockInfo.fFlags = pData->Flags;
+                    if (pRange)
+                    {
+                        pAlloc->LockInfo.Range = *pRange;
+                        Assert(pAlloc->LockInfo.fFlags.RangeValid == 1);
+//                        pAlloc->LockInfo.fFlags.RangeValid = 1;
+                    }
+                    else
+                    {
+                        Assert(pAlloc->LockInfo.fFlags.RangeValid == 0);
+//                        pAlloc->LockInfo.fFlags.RangeValid = 0;
+                    }
+                }
+            }
+            else
+            {
+//                Assert(pAlloc->LockInfo.fFlags.Value == pData->Flags.Value);
+//                if (pAlloc->LockInfo.fFlags.Value != pData->Flags.Value)
+//                {
+//                }
+                Assert(pAlloc->LockInfo.fFlags.RangeValid == pData->Flags.RangeValid);
+                if (pAlloc->LockInfo.fFlags.RangeValid && pData->Flags.RangeValid)
+                {
+                    Assert(pAlloc->LockInfo.Range.Offset == pData->Range.Offset);
+                    Assert(pAlloc->LockInfo.Range.Size == pData->Range.Size);
+                }
+                Assert(pAlloc->LockInfo.LockedRect.pBits);
+            }
+
+            if (hr == S_OK)
+            {
+                ++pAlloc->LockInfo.cLocks;
+
+                if (!pData->Flags.NotifyOnly)
+                {
+                    pData->pSurfData = pAlloc->LockInfo.LockedRect.pBits;
+                    pData->Pitch = pAlloc->LockInfo.LockedRect.Pitch;
+                    pData->SlicePitch = 0;
+                    Assert(pAlloc->SurfDesc.slicePitch == 0);
+                    Assert(!pAlloc->pvMem);
+                }
+                else
+                {
+                    Assert(pAlloc->pvMem);
+                    Assert(pRc->RcDesc.enmPool == D3DDDIPOOL_SYSTEMMEM);
+                    if (bLocked && !pData->Flags.Discard)
+                    {
+                        RECT r, *pr;
+                        if (pRange)
+                        {
+                            r.top = 0;
+                            r.left = pRange->Offset;
+                            r.bottom = 1;
+                            r.right = pRange->Offset + pRange->Size;
+                            pr = &r;
+                        }
+                        else
+                            pr = NULL;
+                        vboxWddmLockUnlockMemSynch(pAlloc, &pAlloc->LockInfo.LockedRect, pr, false /*bool bToLockInfo*/);
+                    }
+                }
+            }
+        }
         else
         {
@@ -2485,5 +2581,5 @@
     if (VBOXDISPMODE_IS_3D(pDevice->pAdapter))
     {
-        if (pRc->RcDesc.fFlags.Texture)
+        if (pRc->RcDesc.fFlags.Texture || pRc->RcDesc.fFlags.Value == 0)
         {
             Assert(pData->SubResourceIndex < pRc->cAllocations);
@@ -2549,4 +2645,29 @@
                 Assert(hr == S_OK);
             }
+            else if (pRc->RcDesc.fFlags.IndexBuffer)
+            {
+                IDirect3DIndexBuffer9 *pD3D9IBuf = (IDirect3DIndexBuffer9*)pAlloc->pD3DIf;
+                Assert(pD3D9IBuf);
+                /* this is a sysmem texture, update  */
+                if (pAlloc->pvMem && !pAlloc->LockInfo.fFlags.ReadOnly)
+                {
+                    RECT r, *pr;
+                    if (pAlloc->LockInfo.fFlags.RangeValid)
+                    {
+                        r.top = 0;
+                        r.left = pAlloc->LockInfo.Range.Offset;
+                        r.bottom = 1;
+                        r.right = pAlloc->LockInfo.Range.Offset + pAlloc->LockInfo.Range.Size;
+                        pr = &r;
+                    }
+                    else
+                        pr = NULL;
+                    vboxWddmLockUnlockMemSynch(pAlloc, &pAlloc->LockInfo.LockedRect,
+                            pr,
+                            true /*bool bToLockInfo*/);
+                }
+                hr = pD3D9IBuf->Unlock();
+                Assert(hr == S_OK);
+            }
             else
             {
@@ -2702,5 +2823,218 @@
             }
 
-            if (pResource->Flags.RenderTarget)
+            if (pResource->Flags.ZBuffer)
+            {
+                Assert(pDevice->pDevice9If);
+                for (UINT i = 0; i < pResource->SurfCount; ++i)
+                {
+                    PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[i];
+                    IDirect3DSurface9 *pD3D9Surf;
+                    hr = pDevice->pDevice9If->CreateDepthStencilSurface(pAllocation->SurfDesc.width,
+                            pAllocation->SurfDesc.height,
+                            vboxDDI2D3DFormat(pResource->Format),
+                            vboxDDI2D3DMultiSampleType(pResource->MultisampleType),
+                            pResource->MultisampleQuality,
+                            TRUE /* @todo: BOOL Discard */,
+                            &pD3D9Surf,
+                            NULL /*HANDLE* pSharedHandle*/);
+                    Assert(hr == S_OK);
+                    if (hr == S_OK)
+                    {
+                        Assert(pD3D9Surf);
+                        if (pResource->Pool == D3DDDIPOOL_SYSTEMMEM)
+                        {
+                            Assert(pAllocation->pvMem);
+                            D3DLOCKED_RECT lockInfo;
+                            hr = pD3D9Surf->LockRect(&lockInfo, NULL, D3DLOCK_DISCARD);
+                            Assert(hr == S_OK);
+                            if (hr == S_OK)
+                            {
+                                vboxWddmLockUnlockMemSynch(pAllocation, &lockInfo, NULL, true /*bool bToLockInfo*/);
+                                HRESULT tmpHr = pD3D9Surf->UnlockRect();
+                                Assert(tmpHr == S_OK);
+                            }
+                        }
+                        else
+                        {
+                            Assert(!pAllocation->pvMem);
+                        }
+                        pAllocation->pD3DIf = pD3D9Surf;
+                    }
+                    else
+                    {
+                        for (UINT j = 0; j < i; ++j)
+                        {
+                            pRc->aAllocations[j].pD3DIf->Release();
+                        }
+                        break;
+                    }
+                }
+            }
+            else if (pResource->Flags.VertexBuffer)
+            {
+                Assert(pDevice->pDevice9If);
+                for (UINT i = 0; i < pResource->SurfCount; ++i)
+                {
+                    PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[i];
+                    IDirect3DVertexBuffer9  *pD3D9VBuf;
+                    hr = pDevice->pDevice9If->CreateVertexBuffer(pAllocation->SurfDesc.width,
+                            vboxDDI2D3DUsage(pResource->Flags),
+                            pResource->Fvf,
+                            vboxDDI2D3DPool(pResource->Pool),
+                            &pD3D9VBuf,
+                            NULL /*HANDLE* pSharedHandle*/);
+                    Assert(hr == S_OK);
+                    if (hr == S_OK)
+                    {
+                        Assert(pD3D9VBuf);
+                        if (pResource->Pool == D3DDDIPOOL_SYSTEMMEM)
+                        {
+                            Assert(pAllocation->pvMem);
+                            D3DLOCKED_RECT lockInfo;
+                            hr = pD3D9VBuf->Lock(0, pAllocation->SurfDesc.width, &lockInfo.pBits, D3DLOCK_DISCARD);
+                            Assert(hr == S_OK);
+                            if (hr == S_OK)
+                            {
+                                lockInfo.Pitch = pAllocation->SurfDesc.pitch;
+                                vboxWddmLockUnlockMemSynch(pAllocation, &lockInfo, NULL, true /*bool bToLockInfo*/);
+                                HRESULT tmpHr = pD3D9VBuf->Unlock();
+                                Assert(tmpHr == S_OK);
+                            }
+                        }
+                        else
+                        {
+                            Assert(!pAllocation->pvMem);
+                        }
+                        pAllocation->pD3DIf = pD3D9VBuf;
+                    }
+                    else
+                    {
+                        for (UINT j = 0; j < i; ++j)
+                        {
+                            pRc->aAllocations[j].pD3DIf->Release();
+                        }
+                        break;
+                    }
+                }
+            }
+            else if (pResource->Flags.IndexBuffer)
+            {
+                Assert(pDevice->pDevice9If);
+                for (UINT i = 0; i < pResource->SurfCount; ++i)
+                {
+                    PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[i];
+                    CONST D3DDDI_SURFACEINFO* pSurf = &pResource->pSurfList[i];
+                    IDirect3DIndexBuffer9  *pD3D9IBuf;
+                    hr = pDevice->pDevice9If->CreateIndexBuffer(pSurf->Width,
+                            vboxDDI2D3DUsage(pResource->Flags),
+                            vboxDDI2D3DFormat(pResource->Format),
+                            vboxDDI2D3DPool(pResource->Pool),
+                            &pD3D9IBuf,
+                            NULL /*HANDLE* pSharedHandle*/
+                          );
+                    Assert(hr == S_OK);
+                    if (hr == S_OK)
+                    {
+                        Assert(pD3D9IBuf);
+                        if (pResource->Pool == D3DDDIPOOL_SYSTEMMEM)
+                        {
+                            Assert(pAllocation->pvMem);
+                            D3DLOCKED_RECT lockInfo;
+                            hr = pD3D9IBuf->Lock(0, pAllocation->SurfDesc.width, &lockInfo.pBits, D3DLOCK_DISCARD);
+                            Assert(hr == S_OK);
+                            if (hr == S_OK)
+                            {
+                                lockInfo.Pitch = pAllocation->SurfDesc.pitch;
+                                vboxWddmLockUnlockMemSynch(pAllocation, &lockInfo, NULL, true /*bool bToLockInfo*/);
+                                HRESULT tmpHr = pD3D9IBuf->Unlock();
+                                Assert(tmpHr == S_OK);
+                            }
+                        }
+                        else
+                        {
+                            Assert(!pAllocation->pvMem);
+                        }
+                        pAllocation->pD3DIf = pD3D9IBuf;
+                    }
+                    else
+                    {
+                        for (UINT j = 0; j < i; ++j)
+                        {
+                            pRc->aAllocations[j].pD3DIf->Release();
+                        }
+                        break;
+                    }
+                }
+            }
+            else if (pResource->Flags.Texture || pResource->Flags.Value == 0)
+            {
+                Assert(pDevice->pDevice9If);
+#ifdef DEBUG
+                {
+                    uint32_t tstW = pResource->pSurfList[0].Width;
+                    uint32_t tstH = pResource->pSurfList[0].Height;
+                    for (UINT i = 1; i < pResource->SurfCount; ++i)
+                    {
+                        tstW /= 2;
+                        tstH /= 2;
+                        CONST D3DDDI_SURFACEINFO* pSurf = &pResource->pSurfList[i];
+                        Assert(pSurf->Width == tstW);
+                        Assert(pSurf->Height == tstH);
+                    }
+                }
+#endif
+
+                PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[0];
+                CONST D3DDDI_SURFACEINFO* pSurf = &pResource->pSurfList[0];
+                IDirect3DTexture9 *pD3DIfTex;
+                hr = pDevice->pDevice9If->CreateTexture(pSurf->Width,
+                                            pSurf->Height,
+                                            pResource->SurfCount,
+                                            vboxDDI2D3DUsage(pResource->Flags),
+                                            vboxDDI2D3DFormat(pResource->Format),
+                                            vboxDDI2D3DPool(pResource->Pool),
+                                            &pD3DIfTex,
+                                            NULL /* HANDLE* pSharedHandle */
+                                            );
+                Assert(hr == S_OK);
+                if (hr == S_OK)
+                {
+                    Assert(pD3DIfTex);
+                    if (pResource->Pool == D3DDDIPOOL_SYSTEMMEM)
+                    {
+                        for (UINT i = 0; i < pResource->SurfCount; ++i)
+                        {
+                            D3DLOCKED_RECT lockInfo;
+                            PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[i];
+                            Assert(pAllocation->pvMem);
+                            hr = pD3DIfTex->LockRect(i, &lockInfo, NULL, D3DLOCK_DISCARD);
+                            Assert(hr == S_OK);
+                            if (hr == S_OK)
+                            {
+                                vboxWddmLockUnlockMemSynch(pAllocation, &lockInfo, NULL, true /*bool bToLockInfo*/);
+                                HRESULT tmpHr = pD3DIfTex->UnlockRect(i);
+                                Assert(tmpHr == S_OK);
+                            }
+                            else
+                            {
+                                pD3DIfTex->Release();
+                                break;
+                            }
+                        }
+                    }
+                    pAllocation->pD3DIf = pD3DIfTex;
+                }
+#ifdef DEBUG
+                else
+                {
+                    for (UINT i = 0; i < pResource->SurfCount; ++i)
+                    {
+                        PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[i];
+                        Assert(!pAllocation->pvMem);
+                    }
+                }
+#endif
+            }
+            else if (pResource->Flags.RenderTarget)
             {
                 HWND hWnd = NULL;
@@ -2815,217 +3149,4 @@
                 }
             }
-            else if (pResource->Flags.ZBuffer)
-            {
-                Assert(pDevice->pDevice9If);
-                for (UINT i = 0; i < pResource->SurfCount; ++i)
-                {
-                    PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[i];
-                    IDirect3DSurface9 *pD3D9Surf;
-                    hr = pDevice->pDevice9If->CreateDepthStencilSurface(pAllocation->SurfDesc.width,
-                            pAllocation->SurfDesc.height,
-                            vboxDDI2D3DFormat(pResource->Format),
-                            vboxDDI2D3DMultiSampleType(pResource->MultisampleType),
-                            pResource->MultisampleQuality,
-                            TRUE /* @todo: BOOL Discard */,
-                            &pD3D9Surf,
-                            NULL /*HANDLE* pSharedHandle*/);
-                    Assert(hr == S_OK);
-                    if (hr == S_OK)
-                    {
-                        Assert(pD3D9Surf);
-                        if (pResource->Pool == D3DDDIPOOL_SYSTEMMEM)
-                        {
-                            Assert(pAllocation->pvMem);
-                            D3DLOCKED_RECT lockInfo;
-                            hr = pD3D9Surf->LockRect(&lockInfo, NULL, D3DLOCK_DISCARD);
-                            Assert(hr == S_OK);
-                            if (hr == S_OK)
-                            {
-                                vboxWddmLockUnlockMemSynch(pAllocation, &lockInfo, NULL, true /*bool bToLockInfo*/);
-                                HRESULT tmpHr = pD3D9Surf->UnlockRect();
-                                Assert(tmpHr == S_OK);
-                            }
-                        }
-                        else
-                        {
-                            Assert(!pAllocation->pvMem);
-                        }
-                        pAllocation->pD3DIf = pD3D9Surf;
-                    }
-                    else
-                    {
-                        for (UINT j = 0; j < i; ++j)
-                        {
-                            pRc->aAllocations[j].pD3DIf->Release();
-                        }
-                        break;
-                    }
-                }
-            }
-            else if (pResource->Flags.VertexBuffer)
-            {
-                Assert(pDevice->pDevice9If);
-                for (UINT i = 0; i < pResource->SurfCount; ++i)
-                {
-                    PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[i];
-                    IDirect3DVertexBuffer9  *pD3D9VBuf;
-                    hr = pDevice->pDevice9If->CreateVertexBuffer(pAllocation->SurfDesc.width,
-                            vboxDDI2D3DUsage(pResource->Flags),
-                            pResource->Fvf,
-                            vboxDDI2D3DPool(pResource->Pool),
-                            &pD3D9VBuf,
-                            NULL /*HANDLE* pSharedHandle*/);
-                    Assert(hr == S_OK);
-                    if (hr == S_OK)
-                    {
-                        Assert(pD3D9VBuf);
-                        if (pResource->Pool == D3DDDIPOOL_SYSTEMMEM)
-                        {
-                            Assert(pAllocation->pvMem);
-                            D3DLOCKED_RECT lockInfo;
-                            hr = pD3D9VBuf->Lock(0, pAllocation->SurfDesc.width, &lockInfo.pBits, D3DLOCK_DISCARD);
-                            Assert(hr == S_OK);
-                            if (hr == S_OK)
-                            {
-                                lockInfo.Pitch = pAllocation->SurfDesc.pitch;
-                                vboxWddmLockUnlockMemSynch(pAllocation, &lockInfo, NULL, true /*bool bToLockInfo*/);
-                                HRESULT tmpHr = pD3D9VBuf->Unlock();
-                                Assert(tmpHr == S_OK);
-                            }
-                        }
-                        else
-                        {
-                            Assert(!pAllocation->pvMem);
-                        }
-                        pAllocation->pD3DIf = pD3D9VBuf;
-                    }
-                    else
-                    {
-                        for (UINT j = 0; j < i; ++j)
-                        {
-                            pRc->aAllocations[j].pD3DIf->Release();
-                        }
-                        break;
-                    }
-                }
-            }
-            else if (pResource->Flags.IndexBuffer)
-            {
-                Assert(pDevice->pDevice9If);
-                for (UINT i = 0; i < pResource->SurfCount; ++i)
-                {
-                    PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[i];
-                    CONST D3DDDI_SURFACEINFO* pSurf = &pResource->pSurfList[i];
-                    IDirect3DIndexBuffer9  *pD3D9IBuf;
-                    hr = pDevice->pDevice9If->CreateIndexBuffer(pSurf->Width,
-                            vboxDDI2D3DUsage(pResource->Flags),
-                            vboxDDI2D3DFormat(pResource->Format),
-                            vboxDDI2D3DPool(pResource->Pool),
-                            &pD3D9IBuf,
-                            NULL /*HANDLE* pSharedHandle*/
-                          );
-                    Assert(hr == S_OK);
-                    if (hr == S_OK)
-                    {
-                        Assert(pD3D9IBuf);
-                        if (pResource->Pool == D3DDDIPOOL_SYSTEMMEM)
-                        {
-                            Assert(pAllocation->pvMem);
-                            D3DLOCKED_RECT lockInfo;
-                            hr = pD3D9IBuf->Lock(0, pAllocation->SurfDesc.width, &lockInfo.pBits, D3DLOCK_DISCARD);
-                            Assert(hr == S_OK);
-                            if (hr == S_OK)
-                            {
-                                lockInfo.Pitch = pAllocation->SurfDesc.pitch;
-                                vboxWddmLockUnlockMemSynch(pAllocation, &lockInfo, NULL, true /*bool bToLockInfo*/);
-                                HRESULT tmpHr = pD3D9IBuf->Unlock();
-                                Assert(tmpHr == S_OK);
-                            }
-                        }
-                        else
-                        {
-                            Assert(!pAllocation->pvMem);
-                        }
-                        pAllocation->pD3DIf = pD3D9IBuf;
-                    }
-                    else
-                    {
-                        for (UINT j = 0; j < i; ++j)
-                        {
-                            pRc->aAllocations[j].pD3DIf->Release();
-                        }
-                        break;
-                    }
-                }
-            }
-            else if (pResource->Flags.Texture)
-            {
-                Assert(pDevice->pDevice9If);
-#ifdef DEBUG
-                {
-                    uint32_t tstW = pResource->pSurfList[0].Width;
-                    uint32_t tstH = pResource->pSurfList[0].Height;
-                    for (UINT i = 1; i < pResource->SurfCount; ++i)
-                    {
-                        tstW /= 2;
-                        tstH /= 2;
-                        CONST D3DDDI_SURFACEINFO* pSurf = &pResource->pSurfList[i];
-                        Assert(pSurf->Width == tstW);
-                        Assert(pSurf->Height == tstH);
-                    }
-                }
-#endif
-
-                PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[0];
-                CONST D3DDDI_SURFACEINFO* pSurf = &pResource->pSurfList[0];
-                IDirect3DTexture9 *pD3DIfTex;
-                hr = pDevice->pDevice9If->CreateTexture(pSurf->Width,
-                                            pSurf->Height,
-                                            pResource->SurfCount,
-                                            vboxDDI2D3DUsage(pResource->Flags),
-                                            vboxDDI2D3DFormat(pResource->Format),
-                                            vboxDDI2D3DPool(pResource->Pool),
-                                            &pD3DIfTex,
-                                            NULL /* HANDLE* pSharedHandle */
-                                            );
-                Assert(hr == S_OK);
-                if (hr == S_OK)
-                {
-                    Assert(pD3DIfTex);
-                    if (pResource->Pool == D3DDDIPOOL_SYSTEMMEM)
-                    {
-                        for (UINT i = 0; i < pResource->SurfCount; ++i)
-                        {
-                            D3DLOCKED_RECT lockInfo;
-                            PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[i];
-                            Assert(pAllocation->pvMem);
-                            hr = pD3DIfTex->LockRect(i, &lockInfo, NULL, D3DLOCK_DISCARD);
-                            Assert(hr == S_OK);
-                            if (hr == S_OK)
-                            {
-                                vboxWddmLockUnlockMemSynch(pAllocation, &lockInfo, NULL, true /*bool bToLockInfo*/);
-                                HRESULT tmpHr = pD3DIfTex->UnlockRect(i);
-                                Assert(tmpHr == S_OK);
-                            }
-                            else
-                            {
-                                pD3DIfTex->Release();
-                                break;
-                            }
-                        }
-                    }
-                    pAllocation->pD3DIf = pD3DIfTex;
-                }
-#ifdef DEBUG
-                else
-                {
-                    for (UINT i = 0; i < pResource->SurfCount; ++i)
-                    {
-                        PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[i];
-                        Assert(!pAllocation->pvMem);
-                    }
-                }
-#endif
-            }
             else
             {
@@ -3163,10 +3284,4 @@
             Assert(pDevice->hWnd);
             Assert(pDevice->pDevice9If);
-            if (pDevice->pDevice9If)
-            {
-                pDevice->pDevice9If->Release();
-                HRESULT tmpHr = VBoxDispWndDestroy(pAdapter, pDevice->hWnd);
-                Assert(tmpHr == S_OK);
-            }
         }
 
@@ -3500,8 +3615,55 @@
 static HRESULT APIENTRY vboxWddmDDevBlt(HANDLE hDevice, CONST D3DDDIARG_BLT* pData)
 {
-    vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
-    AssertBreakpoint();
-    vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
-    return E_FAIL;
+    vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
+    PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
+    Assert(pDevice);
+    Assert(pDevice->pDevice9If);
+    PVBOXWDDMDISP_RESOURCE pDstRc = (PVBOXWDDMDISP_RESOURCE)pData->hDstResource;
+    PVBOXWDDMDISP_RESOURCE pSrcRc = (PVBOXWDDMDISP_RESOURCE)pData->hSrcResource;
+    HRESULT hr = S_OK;
+    if ((pDstRc->RcDesc.fFlags.Texture || pDstRc->RcDesc.fFlags.Value == 0)
+            && (pSrcRc->RcDesc.fFlags.Texture || pSrcRc->RcDesc.fFlags.Value == 0))
+    {
+        IDirect3DTexture9 *pD3DIfSrcTex = (IDirect3DTexture9*)pSrcRc->aAllocations[0].pD3DIf;
+        IDirect3DTexture9 *pD3DIfDstTex = (IDirect3DTexture9*)pDstRc->aAllocations[0].pD3DIf;
+        Assert(pD3DIfSrcTex);
+        Assert(pD3DIfDstTex);
+
+        if (pSrcRc->aAllocations[0].SurfDesc.width == pDstRc->aAllocations[0].SurfDesc.width
+                && pSrcRc->aAllocations[0].SurfDesc.height == pDstRc->aAllocations[0].SurfDesc.height
+                && pSrcRc->RcDesc.enmFormat == pDstRc->RcDesc.enmFormat)
+        {
+            /* first check if we can do IDirect3DDevice9::UpdateTexture */
+            if (pData->DstRect.left == 0 && pData->DstRect.top == 0
+                    && pData->SrcRect.left == 0 && pData->SrcRect.top == 0
+                    && pData->SrcRect.right - pData->SrcRect.left == pSrcRc->aAllocations[0].SurfDesc.width
+                    && pData->SrcRect.bottom - pData->SrcRect.top == pSrcRc->aAllocations[0].SurfDesc.height
+                    && pData->DstRect.right - pData->DstRect.left == pDstRc->aAllocations[0].SurfDesc.width
+                    && pData->DstRect.bottom - pData->DstRect.top == pDstRc->aAllocations[0].SurfDesc.height
+                    )
+            {
+                hr = pDevice->pDevice9If->UpdateTexture(pD3DIfSrcTex, pD3DIfDstTex);
+                Assert(hr == S_OK);
+            }
+            else
+            {
+                AssertBreakpoint();
+                /* @todo: impl */
+            }
+        }
+        else
+        {
+            AssertBreakpoint();
+            /* @todo: impl */
+        }
+    }
+    else
+    {
+        AssertBreakpoint();
+        /* @todo: impl */
+    }
+
+    vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
+    return hr;
 }
 static HRESULT APIENTRY vboxWddmDDevColorFill(HANDLE hDevice, CONST D3DDDIARG_COLORFILL* pData)
@@ -3758,4 +3920,12 @@
 
     PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
+    PVBOXWDDMDISP_ADAPTER pAdapter = pDevice->pAdapter;
+    if (pDevice->pDevice9If)
+    {
+        pDevice->pDevice9If->Release();
+        Assert(pDevice->hWnd);
+        HRESULT tmpHr = VBoxDispWndDestroy(pAdapter, pDevice->hWnd);
+        Assert(tmpHr == S_OK);
+    }
     HRESULT hr = vboxDispCmCtxDestroy(pDevice, &pDevice->DefaultContext);
     Assert(hr == S_OK);
