Index: trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxDispD3D.cpp
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxDispD3D.cpp	(revision 30570)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxDispD3D.cpp	(revision 30582)
@@ -1187,4 +1187,23 @@
         fFlags |= D3DLOCK_DONOTWAIT;
     return fFlags;
+}
+
+D3DTEXTUREFILTERTYPE vboxDDI2D3DBltFlags(D3DDDI_BLTFLAGS fFlags)
+{
+    if (fFlags.Point)
+    {
+        /* no flags other than [Begin|Continue|End]PresentToDwm are set */
+        Assert((fFlags.Value & (~(0x00000100 | 0x00000200 | 0x00000400))) == 1);
+        return D3DTEXF_POINT;
+    }
+    if (fFlags.Linear)
+    {
+        /* no flags other than [Begin|Continue|End]PresentToDwm are set */
+        Assert((fFlags.Value & (~(0x00000100 | 0x00000200 | 0x00000400))) == 2);
+        return D3DTEXF_LINEAR;
+    }
+    /* no flags other than [Begin|Continue|End]PresentToDwm are set */
+    Assert((fFlags.Value & (~(0x00000100 | 0x00000200 | 0x00000400))) == 0);
+    return D3DTEXF_NONE;
 }
 
@@ -1618,5 +1637,13 @@
     PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)hTexture;
 //    Assert(pRc);
-    IDirect3DTexture9 *pD3DIfTex = pRc ? (IDirect3DTexture9*)pRc->aAllocations[0].pD3DIf : NULL;
+    IDirect3DTexture9 *pD3DIfTex;
+    if (pRc)
+    {
+        Assert(pRc->aAllocations[0].enmD3DIfType == VBOXDISP_D3DIFTYPE_TEXTURE);
+        pD3DIfTex = (IDirect3DTexture9*)pRc->aAllocations[0].pD3DIf;
+    }
+    else
+        pD3DIfTex = NULL;
+
 //    Assert(pD3DIfTex);
     HRESULT hr = pDevice->pDevice9If->SetTexture(Stage, pD3DIfTex);
@@ -2314,5 +2341,5 @@
     if (VBOXDISPMODE_IS_3D(pDevice->pAdapter))
     {
-        if (pRc->RcDesc.fFlags.Texture || pRc->RcDesc.fFlags.Value == 0)
+        if (pRc->aAllocations[0].enmD3DIfType == VBOXDISP_D3DIFTYPE_TEXTURE)
         {
             PVBOXWDDMDISP_ALLOCATION pTexAlloc = &pRc->aAllocations[0];
@@ -2420,5 +2447,5 @@
             }
         }
-        else if (pRc->RcDesc.fFlags.VertexBuffer)
+        else if (pRc->aAllocations[0].enmD3DIfType == VBOXDISP_D3DIFTYPE_VERTEXBUFFER)
         {
             Assert(pData->SubResourceIndex < pRc->cAllocations);
@@ -2517,5 +2544,5 @@
             }
         }
-        else if (pRc->RcDesc.fFlags.IndexBuffer)
+        else if (pRc->aAllocations[0].enmD3DIfType == VBOXDISP_D3DIFTYPE_INDEXBUFFER)
         {
             Assert(pData->SubResourceIndex < pRc->cAllocations);
@@ -2703,5 +2730,5 @@
     if (VBOXDISPMODE_IS_3D(pDevice->pAdapter))
     {
-        if (pRc->RcDesc.fFlags.Texture || pRc->RcDesc.fFlags.Value == 0)
+        if (pRc->aAllocations[0].enmD3DIfType == VBOXDISP_D3DIFTYPE_TEXTURE)
         {
             Assert(pData->SubResourceIndex < pRc->cAllocations);
@@ -2732,5 +2759,5 @@
             }
         }
-        else if (pRc->RcDesc.fFlags.VertexBuffer)
+        else if (pRc->aAllocations[0].enmD3DIfType == VBOXDISP_D3DIFTYPE_VERTEXBUFFER)
         {
             Assert(pData->SubResourceIndex < pRc->cAllocations);
@@ -2772,5 +2799,5 @@
             }
         }
-        else if (pRc->RcDesc.fFlags.IndexBuffer)
+        else if (pRc->aAllocations[0].enmD3DIfType == VBOXDISP_D3DIFTYPE_INDEXBUFFER)
         {
             Assert(pData->SubResourceIndex < pRc->cAllocations);
@@ -2979,4 +3006,6 @@
                     {
                         Assert(pD3D9Surf);
+                        pAllocation->enmD3DIfType = VBOXDISP_D3DIFTYPE_SURFACE;
+                        pAllocation->pD3DIf = pD3D9Surf;
                         if (pResource->Pool == D3DDDIPOOL_SYSTEMMEM)
                         {
@@ -2996,5 +3025,4 @@
                             Assert(!pAllocation->pvMem);
                         }
-                        pAllocation->pD3DIf = pD3D9Surf;
                     }
                     else
@@ -3025,4 +3053,6 @@
                     {
                         Assert(pD3D9VBuf);
+                        pAllocation->enmD3DIfType = VBOXDISP_D3DIFTYPE_VERTEXBUFFER;
+                        pAllocation->pD3DIf = pD3D9VBuf;
                         if (pResource->Pool == D3DDDIPOOL_SYSTEMMEM)
                         {
@@ -3043,5 +3073,4 @@
                             Assert(!pAllocation->pvMem);
                         }
-                        pAllocation->pD3DIf = pD3D9VBuf;
                     }
                     else
@@ -3074,4 +3103,6 @@
                     {
                         Assert(pD3D9IBuf);
+                        pAllocation->enmD3DIfType = VBOXDISP_D3DIFTYPE_INDEXBUFFER;
+                        pAllocation->pD3DIf = pD3D9IBuf;
                         if (pResource->Pool == D3DDDIPOOL_SYSTEMMEM)
                         {
@@ -3092,5 +3123,4 @@
                             Assert(!pAllocation->pvMem);
                         }
-                        pAllocation->pD3DIf = pD3D9IBuf;
                     }
                     else
@@ -3121,4 +3151,7 @@
                 }
 #endif
+
+                if (pResource->Flags.RenderTarget)
+                    bIssueCreateResource = true;
 
                 PVBOXWDDMDISP_ALLOCATION pAllocation = &pRc->aAllocations[0];
@@ -3138,4 +3171,6 @@
                 {
                     Assert(pD3DIfTex);
+                    pAllocation->enmD3DIfType = VBOXDISP_D3DIFTYPE_TEXTURE;
+                    pAllocation->pD3DIf = pD3DIfTex;
                     if (pResource->Pool == D3DDDIPOOL_SYSTEMMEM)
                     {
@@ -3160,5 +3195,4 @@
                         }
                     }
-                    pAllocation->pD3DIf = pD3DIfTex;
                 }
 #ifdef DEBUG
@@ -3192,6 +3226,6 @@
                         D3DPRESENT_PARAMETERS params;
                         memset(&params, 0, sizeof (params));
-            //            params.BackBufferWidth = 0;
-            //            params.BackBufferHeight = 0;
+                        //            params.BackBufferWidth = 0;
+                        //            params.BackBufferHeight = 0;
                         params.BackBufferFormat = vboxDDI2D3DFormat(pResource->Format);
                         Assert(pResource->SurfCount);
@@ -3201,12 +3235,12 @@
                             params.SwapEffect = D3DSWAPEFFECT_DISCARD;
                         params.hDeviceWindow = hWnd;
-                        /* @todo: it seems there should be a way to detect this correctly since
-                         * our vboxWddmDDevSetDisplayMode will be called in case we are using full-screen */
+                                    /* @todo: it seems there should be a way to detect this correctly since
+                                     * our vboxWddmDDevSetDisplayMode will be called in case we are using full-screen */
                         params.Windowed = TRUE;
-            //            params.EnableAutoDepthStencil = FALSE;
-            //            params.AutoDepthStencilFormat = D3DFMT_UNKNOWN;
-            //            params.Flags;
-            //            params.FullScreen_RefreshRateInHz;
-            //            params.FullScreen_PresentationInterval;
+                        //            params.EnableAutoDepthStencil = FALSE;
+                        //            params.AutoDepthStencilFormat = D3DFMT_UNKNOWN;
+                        //            params.Flags;
+                        //            params.FullScreen_RefreshRateInHz;
+                        //            params.FullScreen_PresentationInterval;
                         hr = pAdapter->pD3D9If->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, fFlags, &params, &pDevice9If);
                         Assert(hr == S_OK);
@@ -3222,5 +3256,4 @@
                 {
                     Assert(pDevice->hWnd);
-
                 }
 
@@ -3235,16 +3268,18 @@
                         IDirect3DSurface9* pD3D9Surf;
                         hr = pDevice->pDevice9If->CreateRenderTarget(pAllocation->SurfDesc.width,
-                                    pAllocation->SurfDesc.height,
-                                    vboxDDI2D3DFormat(pResource->Format),
-                                    vboxDDI2D3DMultiSampleType(pResource->MultisampleType),
-                                    pResource->MultisampleQuality,
-                                    !pResource->Flags.NotLockable /* BOOL Lockable */,
-                                    &pD3D9Surf,
-                                    NULL /* HANDLE* pSharedHandle */
-                                  );
+                                pAllocation->SurfDesc.height,
+                                vboxDDI2D3DFormat(pResource->Format),
+                                vboxDDI2D3DMultiSampleType(pResource->MultisampleType),
+                                pResource->MultisampleQuality,
+                                !pResource->Flags.NotLockable /* BOOL Lockable */,
+                                &pD3D9Surf,
+                                NULL /* HANDLE* pSharedHandle */
+                                );
                         Assert(hr == S_OK);
                         if (hr == S_OK)
                         {
                             Assert(pD3D9Surf);
+                            pAllocation->enmD3DIfType = VBOXDISP_D3DIFTYPE_SURFACE;
+                            pAllocation->pD3DIf = pD3D9Surf;
                             if (pResource->Pool == D3DDDIPOOL_SYSTEMMEM)
                             {
@@ -3264,5 +3299,4 @@
                                 Assert(!pAllocation->pvMem);
                             }
-                            pAllocation->pD3DIf = pD3D9Surf;
                         }
                         else
@@ -3472,4 +3506,5 @@
     PVBOXWDDMDISP_ALLOCATION pAlloc = &pRc->aAllocations[pData->SubResourceIndex];
     Assert(pRc->RcDesc.fFlags.RenderTarget);
+    Assert(pRc->aAllocations[pData->SubResourceIndex].enmD3DIfType == VBOXDISP_D3DIFTYPE_SURFACE);
     Assert(pAlloc->hAllocation);
     D3DDDICB_SETDISPLAYMODE DdiDm = {0};
@@ -3610,6 +3645,6 @@
     Assert(pDevice->pDevice9If);
     IDirect3DVertexDeclaration9 *pDecl = (IDirect3DVertexDeclaration9*)hShaderHandle;
-    HRESULT hr = pDecl->Release();
-    Assert(hr == S_OK);
+    HRESULT hr = S_OK;
+    pDecl->Release();
     vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
     return hr;
@@ -3653,6 +3688,6 @@
     Assert(pDevice->pDevice9If);
     IDirect3DVertexShader9 *pShader = (IDirect3DVertexShader9*)hShaderHandle;
-    HRESULT hr = pShader->Release();
-    Assert(hr == S_OK);
+    HRESULT hr = S_OK;
+    pShader->Release();
     vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
     return hr;
@@ -3750,5 +3785,5 @@
     return E_FAIL;
 }
-static HRESULT vboxWddmLockRect(PVBOXWDDMDISP_ALLOCATION pAlloc, UINT iAlloc, D3DDDI_RESOURCEFLAGS fAllocType,
+static HRESULT vboxWddmLockRect(PVBOXWDDMDISP_RESOURCE pRc, UINT iAlloc,
         D3DLOCKED_RECT * pLockedRect,
         CONST RECT *pRect,
@@ -3756,49 +3791,97 @@
 {
     HRESULT hr = E_FAIL;
-    Assert(!pAlloc->LockInfo.cLocks);
-    if (fAllocType.Texture || fAllocType.Value == 0)
-    {
-        IDirect3DTexture9 *pD3DIfTex = (IDirect3DTexture9*)pAlloc->pD3DIf;
-        Assert(pD3DIfTex);
-        hr = pD3DIfTex->LockRect(iAlloc, pLockedRect, pRect, fLockFlags);
-        Assert(hr == S_OK);
-    }
-    else if (fAllocType.RenderTarget)
-    {
-        IDirect3DSurface9 *pD3DIfSurf = (IDirect3DSurface9*)pAlloc->pD3DIf;
-        Assert(pD3DIfSurf);
-        hr = pD3DIfSurf->LockRect(pLockedRect, pRect, fLockFlags);
-        Assert(hr == S_OK);
-    }
-    else
-    {
-        AssertBreakpoint();
-    }
-    return hr;
-}
-static HRESULT vboxWddmUnlockRect(PVBOXWDDMDISP_ALLOCATION pAlloc, UINT iAlloc, D3DDDI_RESOURCEFLAGS fAllocType)
-{
-    HRESULT hr = E_FAIL;
-    Assert(!pAlloc->LockInfo.cLocks);
-    if (fAllocType.Texture || fAllocType.Value == 0)
-    {
-        IDirect3DTexture9 *pD3DIfTex = (IDirect3DTexture9*)pAlloc->pD3DIf;
-        Assert(pD3DIfTex);
-        hr = pD3DIfTex->UnlockRect(iAlloc);
-        Assert(hr == S_OK);
-    }
-    else if (fAllocType.RenderTarget)
-    {
-        IDirect3DSurface9 *pD3DIfSurf = (IDirect3DSurface9*)pAlloc->pD3DIf;
-        Assert(pD3DIfSurf);
-        hr = pD3DIfSurf->UnlockRect();
-        Assert(hr == S_OK);
-    }
-    else
-    {
-        AssertBreakpoint();
-    }
-    return hr;
-}
+    Assert(!pRc->aAllocations[iAlloc].LockInfo.cLocks);
+    Assert(pRc->cAllocations > iAlloc);
+    switch (pRc->aAllocations[0].enmD3DIfType)
+    {
+        case VBOXDISP_D3DIFTYPE_SURFACE:
+        {
+            IDirect3DSurface9 *pD3DIfSurf = (IDirect3DSurface9*)pRc->aAllocations[iAlloc].pD3DIf;
+            Assert(pD3DIfSurf);
+            hr = pD3DIfSurf->LockRect(pLockedRect, pRect, fLockFlags);
+            Assert(hr == S_OK);
+            break;
+        }
+        case VBOXDISP_D3DIFTYPE_TEXTURE:
+        {
+            IDirect3DTexture9 *pD3DIfTex = (IDirect3DTexture9*)pRc->aAllocations[0].pD3DIf;
+            Assert(pD3DIfTex);
+            hr = pD3DIfTex->LockRect(iAlloc, pLockedRect, pRect, fLockFlags);
+            Assert(hr == S_OK);
+            break;
+        }
+        default:
+            AssertBreakpoint();
+            break;
+    }
+    return hr;
+}
+static HRESULT vboxWddmUnlockRect(PVBOXWDDMDISP_RESOURCE pRc, UINT iAlloc)
+{
+    HRESULT hr = S_OK;
+    Assert(pRc->cAllocations > iAlloc);
+    switch (pRc->aAllocations[0].enmD3DIfType)
+    {
+        case VBOXDISP_D3DIFTYPE_SURFACE:
+        {
+            IDirect3DSurface9 *pD3DIfSurf = (IDirect3DSurface9*)pRc->aAllocations[iAlloc].pD3DIf;
+            Assert(pD3DIfSurf);
+            hr = pD3DIfSurf->UnlockRect();
+            Assert(hr == S_OK);
+            break;
+        }
+        case VBOXDISP_D3DIFTYPE_TEXTURE:
+        {
+            IDirect3DTexture9 *pD3DIfTex = (IDirect3DTexture9*)pRc->aAllocations[0].pD3DIf;
+            Assert(pD3DIfTex);
+            hr = pD3DIfTex->UnlockRect(iAlloc);
+            Assert(hr == S_OK);
+            break;
+        }
+        default:
+            AssertBreakpoint();
+            hr = E_FAIL;
+            break;
+    }
+    return hr;
+}
+
+/* on success increments the surface ref counter,
+ * i.e. one must call pSurf->Release() once the surface is not needed*/
+static HRESULT vboxWddmSurfGet(PVBOXWDDMDISP_RESOURCE pRc, UINT iAlloc, IDirect3DSurface9 **ppSurf)
+{
+    HRESULT hr = S_OK;
+    Assert(pRc->cAllocations > iAlloc);
+    switch (pRc->aAllocations[0].enmD3DIfType)
+    {
+        case VBOXDISP_D3DIFTYPE_SURFACE:
+        {
+            IDirect3DSurface9 *pD3DIfSurf = (IDirect3DSurface9*)pRc->aAllocations[iAlloc].pD3DIf;
+            Assert(pD3DIfSurf);
+            pD3DIfSurf->AddRef();
+            *ppSurf = pD3DIfSurf;
+            break;
+        }
+        case VBOXDISP_D3DIFTYPE_TEXTURE:
+        {
+            IDirect3DTexture9 *pD3DIfTex = (IDirect3DTexture9*)pRc->aAllocations[0].pD3DIf;
+            IDirect3DSurface9 *pSurfaceLevel;
+            Assert(pD3DIfTex);
+            hr = pD3DIfTex->GetSurfaceLevel(iAlloc, &pSurfaceLevel);
+            Assert(hr == S_OK);
+            if (hr == S_OK)
+            {
+                *ppSurf = pSurfaceLevel;
+            }
+            break;
+        }
+        default:
+            AssertBreakpoint();
+            hr = E_FAIL;
+            break;
+    }
+    return hr;
+}
+
 static HRESULT APIENTRY vboxWddmDDevBlt(HANDLE hDevice, CONST D3DDDIARG_BLT* pData)
 {
@@ -3811,8 +3894,40 @@
     Assert(pDstRc->cAllocations > pData->DstSubResourceIndex);
     Assert(pSrcRc->cAllocations > pData->SrcSubResourceIndex);
-    PVBOXWDDMDISP_ALLOCATION pSrcAlloc = &pSrcRc->aAllocations[pData->SrcSubResourceIndex];
-    PVBOXWDDMDISP_ALLOCATION pDstAlloc = &pDstRc->aAllocations[pData->DstSubResourceIndex];
     HRESULT hr = S_OK;
-    if ((pDstRc->RcDesc.fFlags.Texture || pDstRc->RcDesc.fFlags.Value == 0)
+    /* try StretchRect */
+    IDirect3DSurface9 *pSrcSurfIf = NULL;
+    IDirect3DSurface9 *pDstSurfIf = NULL;
+    hr = vboxWddmSurfGet(pSrcRc, pData->SrcSubResourceIndex, &pSrcSurfIf);
+    Assert(hr == S_OK);
+    if (hr == S_OK)
+    {
+        Assert(pSrcSurfIf);
+        hr = vboxWddmSurfGet(pDstRc, pData->DstSubResourceIndex, &pDstSurfIf);
+        Assert(hr == S_OK);
+        if (hr == S_OK)
+        {
+            Assert(pDstSurfIf);
+            /* we support only Point & Linear, we ignore [Begin|Continue|End]PresentToDwm */
+            Assert((pData->Flags.Value & (~(0x00000100 | 0x00000200 | 0x00000400 | 0x00000001  | 0x00000002))) == 0);
+            hr = pDevice->pDevice9If->StretchRect(pSrcSurfIf,
+                                &pData->SrcRect,
+                                pDstSurfIf,
+                                &pData->DstRect,
+                                vboxDDI2D3DBltFlags(pData->Flags));
+            Assert(hr == S_OK);
+            pDstSurfIf->Release();
+        }
+        pSrcSurfIf->Release();
+    }
+
+    if (hr != S_OK)
+    {
+        /* todo: fallback to memcpy or whatever ? */
+        AssertBreakpoint();
+    }
+
+
+#if 0
+    if ((use pAlloc->enmD3DIfType instead!!! pDstRc->RcDesc.fFlags.Texture || pDstRc->RcDesc.fFlags.Value == 0)
             && (pSrcRc->RcDesc.fFlags.Texture || pSrcRc->RcDesc.fFlags.Value == 0))
     {
@@ -3915,4 +4030,5 @@
         }
     }
+#endif
 
     vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
@@ -4050,6 +4166,6 @@
     Assert(pDevice->pDevice9If);
     IDirect3DPixelShader9 *pShader = (IDirect3DPixelShader9*)hShaderHandle;
-    HRESULT hr = pShader->Release();
-    Assert(hr == S_OK);
+    HRESULT hr = S_OK;
+    pShader->Release();
     vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
     return hr;
@@ -4701,6 +4817,5 @@
         HRESULT hr = VBoxDispWorkerDestroy(&pAdapter->WndWorker);
         Assert(hr == S_OK);
-        hr = pAdapter->pD3D9If->Release();
-        Assert(hr == S_OK);
+        pAdapter->pD3D9If->Release();
         VBoxDispD3DClose(&pAdapter->D3D);
     }
Index: trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxDispD3D.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxDispD3D.h	(revision 30570)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxDispD3D.h	(revision 30582)
@@ -129,4 +129,13 @@
 } VBOXWDDMDISP_LOCKINFO;
 
+typedef enum
+{
+    VBOXDISP_D3DIFTYPE_UNDEFINED = 0,
+    VBOXDISP_D3DIFTYPE_SURFACE,
+    VBOXDISP_D3DIFTYPE_TEXTURE,
+    VBOXDISP_D3DIFTYPE_VERTEXBUFFER,
+    VBOXDISP_D3DIFTYPE_INDEXBUFFER
+} VBOXDISP_D3DIFTYPE;
+
 typedef struct VBOXWDDMDISP_ALLOCATION
 {
@@ -134,6 +143,7 @@
     VBOXWDDM_ALLOC_TYPE enmType;
     void* pvMem;
-    /* object type depends on resource type */
+    /* object type is defined by enmD3DIfType enum */
     IUnknown *pD3DIf;
+    VBOXDISP_D3DIFTYPE enmD3DIfType;
     VBOXWDDMDISP_LOCKINFO LockInfo;
     VBOXWDDM_DIRTYREGION DirtyRegion; /* <- dirty region to notify host about */
Index: trunk/src/VBox/Additions/WINNT/Graphics/Miniport/wddm/VBoxVideoWddm.cpp
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Miniport/wddm/VBoxVideoWddm.cpp	(revision 30570)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Miniport/wddm/VBoxVideoWddm.cpp	(revision 30582)
@@ -1931,7 +1931,7 @@
             case VBOXVDMACMD_TYPE_DMA_PRESENT_SHADOW2PRIMARY:
             case VBOXVDMACMD_TYPE_DMA_PRESENT_BLT:
-            case VBOXVDMACMD_TYPE_DMA_PRESENT_FLIP:
-            {
-                const D3DDDI_PATCHLOCATIONLIST* pPatchList = &pPatch->pPatchLocationList[0];
+            {
+                Assert(pPatch->PatchLocationListSubmissionLength == 2);
+                const D3DDDI_PATCHLOCATIONLIST* pPatchList = &pPatch->pPatchLocationList[pPatch->PatchLocationListSubmissionStart];
                 Assert(pPatchList->AllocationIndex == DXGK_PRESENT_SOURCE_INDEX);
                 Assert(pPatchList->PatchOffset == 0);
@@ -1941,5 +1941,5 @@
                 pPrivateData->SrcAllocInfo.offAlloc = (VBOXVIDEOOFFSET)pSrcAllocationList->PhysicalAddress.QuadPart;
 
-                pPatchList = &pPatch->pPatchLocationList[1];
+                pPatchList = &pPatch->pPatchLocationList[pPatch->PatchLocationListSubmissionStart + 1];
                 Assert(pPatchList->AllocationIndex == DXGK_PRESENT_DESTINATION_INDEX);
                 Assert(pPatchList->PatchOffset == 4);
@@ -1949,4 +1949,15 @@
                 pPrivateData->DstAllocInfo.offAlloc = (VBOXVIDEOOFFSET)pDstAllocationList->PhysicalAddress.QuadPart;
                 break;
+            }
+            case VBOXVDMACMD_TYPE_DMA_PRESENT_FLIP:
+            {
+                Assert(pPatch->PatchLocationListSubmissionLength == 1);
+                const D3DDDI_PATCHLOCATIONLIST* pPatchList = &pPatch->pPatchLocationList[pPatch->PatchLocationListSubmissionStart];
+                Assert(pPatchList->AllocationIndex == DXGK_PRESENT_SOURCE_INDEX);
+                Assert(pPatchList->PatchOffset == 0);
+                const DXGK_ALLOCATIONLIST *pSrcAllocationList = &pPatch->pAllocationList[pPatchList->AllocationIndex];
+                Assert(pSrcAllocationList->SegmentId);
+                pPrivateData->SrcAllocInfo.segmentIdAlloc = pSrcAllocationList->SegmentId;
+                pPrivateData->SrcAllocInfo.offAlloc = (VBOXVIDEOOFFSET)pSrcAllocationList->PhysicalAddress.QuadPart;
             }
             default:
@@ -2187,11 +2198,11 @@
             if (pRectsCmd)
             {
-                PVBOXWDDM_ALLOCATION pDstAlloc = pPrivateData->DstAllocInfo.pAlloc;
+                PVBOXWDDM_ALLOCATION pAlloc = pPrivateData->SrcAllocInfo.pAlloc;
                 pRectsCmd->pContext = pContext;
                 RECT r;
                 r.top = 0;
                 r.left = 0;
-                r.right = pDstAlloc->SurfDesc.width;
-                r.bottom = pDstAlloc->SurfDesc.height;
+                r.right = pAlloc->SurfDesc.width;
+                r.bottom = pAlloc->SurfDesc.height;
                 pRectsCmd->ContextsRects.ContextRect = r;
                 pRectsCmd->ContextsRects.UpdateRects.cRects = 1;
@@ -4047,45 +4058,29 @@
     else if (pPresent->Flags.Flip)
     {
-        Assert(pPresent->Flags.Value == 1); /* only Blt is set, we do not support anything else for now */
+        Assert(pPresent->Flags.Value == 4); /* only Blt is set, we do not support anything else for now */
         DXGK_ALLOCATIONLIST *pSrc =  &pPresent->pAllocationList[DXGK_PRESENT_SOURCE_INDEX];
-        DXGK_ALLOCATIONLIST *pDst =  &pPresent->pAllocationList[DXGK_PRESENT_DESTINATION_INDEX];
         PVBOXWDDM_ALLOCATION pSrcAlloc = vboxWddmGetAllocationFromAllocList(pDevExt, pSrc);
         Assert(pSrcAlloc);
         if (pSrcAlloc)
         {
-            PVBOXWDDM_ALLOCATION pDstAlloc = vboxWddmGetAllocationFromAllocList(pDevExt, pDst);
-            Assert(pDstAlloc);
-            if (pDstAlloc)
-            {
-                Assert(cContexts3D);
-                pPrivateData->enmCmd = VBOXVDMACMD_TYPE_DMA_PRESENT_FLIP;
-
-                vboxWddmPopulateDmaAllocInfo(&pPrivateData->SrcAllocInfo, pSrcAlloc, pSrc);
-                vboxWddmPopulateDmaAllocInfo(&pPrivateData->DstAllocInfo, pDstAlloc, pDst);
-
-                UINT cbCmd = sizeof (VBOXVDMACMD_DMA_PRESENT_FLIP);
-                pPresent->pDmaBufferPrivateData = (uint8_t*)pPresent->pDmaBufferPrivateData + cbCmd;
-                pPresent->pDmaBuffer = ((uint8_t*)pPresent->pDmaBuffer) + VBOXWDDM_DUMMY_DMABUFFER_SIZE;
-                Assert(pPresent->DmaSize >= VBOXWDDM_DUMMY_DMABUFFER_SIZE);
-
-                memset(pPresent->pPatchLocationListOut, 0, 2*sizeof (D3DDDI_PATCHLOCATIONLIST));
-                pPresent->pPatchLocationListOut->PatchOffset = 0;
-                pPresent->pPatchLocationListOut->AllocationIndex = DXGK_PRESENT_SOURCE_INDEX;
-                ++pPresent->pPatchLocationListOut;
-                pPresent->pPatchLocationListOut->PatchOffset = 4;
-                pPresent->pPatchLocationListOut->AllocationIndex = DXGK_PRESENT_DESTINATION_INDEX;
-                ++pPresent->pPatchLocationListOut;
-            }
-            else
-            {
-                /* this should not happen actually */
-                drprintf((__FUNCTION__": failed to get Dst Allocation info for hDeviceSpecificAllocation(0x%x)\n",pDst->hDeviceSpecificAllocation));
-                Status = STATUS_INVALID_HANDLE;
-            }
+            Assert(cContexts3D);
+            pPrivateData->enmCmd = VBOXVDMACMD_TYPE_DMA_PRESENT_FLIP;
+
+            vboxWddmPopulateDmaAllocInfo(&pPrivateData->SrcAllocInfo, pSrcAlloc, pSrc);
+
+            UINT cbCmd = sizeof (VBOXVDMACMD_DMA_PRESENT_FLIP);
+            pPresent->pDmaBufferPrivateData = (uint8_t*)pPresent->pDmaBufferPrivateData + cbCmd;
+            pPresent->pDmaBuffer = ((uint8_t*)pPresent->pDmaBuffer) + VBOXWDDM_DUMMY_DMABUFFER_SIZE;
+            Assert(pPresent->DmaSize >= VBOXWDDM_DUMMY_DMABUFFER_SIZE);
+
+            memset(pPresent->pPatchLocationListOut, 0, sizeof (D3DDDI_PATCHLOCATIONLIST));
+            pPresent->pPatchLocationListOut->PatchOffset = 0;
+            pPresent->pPatchLocationListOut->AllocationIndex = DXGK_PRESENT_SOURCE_INDEX;
+            ++pPresent->pPatchLocationListOut;
         }
         else
         {
             /* this should not happen actually */
-            drprintf((__FUNCTION__": failed to get Src Allocation info for hDeviceSpecificAllocation(0x%x)\n",pSrc->hDeviceSpecificAllocation));
+            drprintf((__FUNCTION__": failed to get pSrc Allocation info for hDeviceSpecificAllocation(0x%x)\n",pSrc->hDeviceSpecificAllocation));
             Status = STATUS_INVALID_HANDLE;
         }
