Index: trunk/src/VBox/Additions/WINNT/Graphics/Miniport/wddm/VBoxVideoIf.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Miniport/wddm/VBoxVideoIf.h	(revision 30532)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Miniport/wddm/VBoxVideoIf.h	(revision 30536)
@@ -328,4 +328,19 @@
 }
 
+DECLINLINE(bool) vboxWddmRectIsEqual(const RECT *pRect1, const RECT *pRect2)
+{
+    Assert(pRect1);
+    Assert(pRect2);
+    if (pRect1->left != pRect2->left)
+        return false;
+    if (pRect1->top != pRect2->top)
+        return false;
+    if (pRect1->right != pRect2->right)
+        return false;
+    if (pRect1->bottom != pRect2->bottom)
+        return false;
+    return true;
+}
+
 DECLINLINE(bool) vboxWddmRectIsCoveres(const RECT *pRect, const RECT *pCovered)
 {
Index: trunk/src/VBox/Additions/WINNT/Graphics/Miniport/wddm/VBoxVideoWddm.cpp
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Miniport/wddm/VBoxVideoWddm.cpp	(revision 30532)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Miniport/wddm/VBoxVideoWddm.cpp	(revision 30536)
@@ -1491,4 +1491,5 @@
         {
             pAllocation->enmType = pAllocInfo->enmType;
+            pAllocation->fRcFlags = pAllocInfo->fFlags;
             pAllocation->offVram = VBOXVIDEOOFFSET_VOID;
             pAllocation->SurfDesc = pAllocInfo->SurfDesc;
@@ -1933,20 +1934,16 @@
                 Assert(pPatchList->AllocationIndex == DXGK_PRESENT_SOURCE_INDEX);
                 Assert(pPatchList->PatchOffset == 0);
-                const DXGK_ALLOCATIONLIST *pAllocationList = &pPatch->pAllocationList[pPatchList->AllocationIndex];
-                Assert(pAllocationList->SegmentId);
-                pPrivateData->SrcAllocInfo.segmentIdAlloc = pAllocationList->SegmentId;
-                pPrivateData->SrcAllocInfo.offAlloc = (VBOXVIDEOOFFSET)pAllocationList->PhysicalAddress.QuadPart;
-#ifdef VBOXWDDM_RENDER_FROM_SHADOW
-                if (!pPrivateData->fFlags.bShadow2PrimaryUpdate)
-#endif
-                {
-                    pPatchList = &pPatch->pPatchLocationList[1];
-                    Assert(pPatchList->AllocationIndex == DXGK_PRESENT_DESTINATION_INDEX);
-                    Assert(pPatchList->PatchOffset == 4);
-                    const DXGK_ALLOCATIONLIST *pAllocationList = &pPatch->pAllocationList[pPatchList->AllocationIndex];
-                    Assert(pAllocationList->SegmentId);
-                    pPrivateData->DstAllocInfo.segmentIdAlloc = pAllocationList->SegmentId;
-                    pPrivateData->DstAllocInfo.offAlloc = (VBOXVIDEOOFFSET)pAllocationList->PhysicalAddress.QuadPart;
-                }
+                const DXGK_ALLOCATIONLIST *pSrcAllocationList = &pPatch->pAllocationList[pPatchList->AllocationIndex];
+                Assert(pSrcAllocationList->SegmentId);
+                pPrivateData->SrcAllocInfo.segmentIdAlloc = pSrcAllocationList->SegmentId;
+                pPrivateData->SrcAllocInfo.offAlloc = (VBOXVIDEOOFFSET)pSrcAllocationList->PhysicalAddress.QuadPart;
+
+                pPatchList = &pPatch->pPatchLocationList[1];
+                Assert(pPatchList->AllocationIndex == DXGK_PRESENT_DESTINATION_INDEX);
+                Assert(pPatchList->PatchOffset == 4);
+                const DXGK_ALLOCATIONLIST *pDstAllocationList = &pPatch->pAllocationList[pPatchList->AllocationIndex];
+                Assert(pDstAllocationList->SegmentId);
+                pPrivateData->DstAllocInfo.segmentIdAlloc = pDstAllocationList->SegmentId;
+                pPrivateData->DstAllocInfo.offAlloc = (VBOXVIDEOOFFSET)pDstAllocationList->PhysicalAddress.QuadPart;
                 break;
             }
@@ -2021,4 +2018,18 @@
 #endif
 
+static void vboxWddmSubmitBltCmd(PDEVICE_EXTENSION pDevExt, PVBOXWDDM_CONTEXT pContext, PVBOXWDDM_DMA_PRESENT_BLT pBlt)
+{
+    PVBOXVDMAPIPE_CMD_RECTSINFO pRectsCmd = (PVBOXVDMAPIPE_CMD_RECTSINFO)vboxVdmaGgCmdCreate(&pDevExt->u.primary.Vdma.DmaGg, VBOXVDMAPIPE_CMD_TYPE_RECTSINFO, RT_OFFSETOF(VBOXVDMAPIPE_CMD_RECTSINFO, ContextsRects.UpdateRects.aRects[pBlt->DstRects.UpdateRects.cRects]));
+    Assert(pRectsCmd);
+    if (pRectsCmd)
+    {
+        pRectsCmd->pContext = pContext;
+        memcpy(&pRectsCmd->ContextsRects, &pBlt->DstRects, RT_OFFSETOF(VBOXVDMAPIPE_RECTS, UpdateRects.aRects[pBlt->DstRects.UpdateRects.cRects]));
+        NTSTATUS tmpStatus = vboxVdmaGgCmdSubmit(&pDevExt->u.primary.Vdma.DmaGg, &pRectsCmd->Hdr);
+        Assert(tmpStatus == STATUS_SUCCESS);
+        if (tmpStatus != STATUS_SUCCESS)
+            vboxVdmaGgCmdDestroy(&pRectsCmd->Hdr);
+    }
+}
 
 NTSTATUS
@@ -2079,44 +2090,75 @@
         case VBOXVDMACMD_TYPE_DMA_PRESENT_BLT:
         {
+            PVBOXWDDM_CONTEXT pContext = (PVBOXWDDM_CONTEXT)pSubmitCommand->hContext;
+            Assert(pContext);
+            Assert(pContext->pDevice);
+            Assert(pContext->pDevice->pAdapter == pDevExt);
             PVBOXWDDM_DMA_PRESENT_BLT pBlt = (PVBOXWDDM_DMA_PRESENT_BLT)pPrivateData;
+            PVBOXWDDM_ALLOCATION pDstAlloc = pPrivateData->DstAllocInfo.pAlloc;
+            PVBOXWDDM_ALLOCATION pSrcAlloc = pPrivateData->SrcAllocInfo.pAlloc;
             uint32_t cContexts3D = ASMAtomicReadU32(&pDevExt->cContexts3D);
-            if (cContexts3D)
-            {
-                if (pPrivateData->fFlags.bShadow2PrimaryUpdate)
+            switch (pDstAlloc->enmType)
+            {
+                case VBOXWDDM_ALLOC_TYPE_STD_SHAREDPRIMARYSURFACE:
                 {
-                    RECT rect;
-                    if (pBlt->DstRects.UpdateRects.cRects)
+                    VBOXWDDM_SOURCE *pSource = &pDevExt->aSources[pPrivateData->DstAllocInfo.srcId];
+                    Assert(pSource->pPrimaryAllocation == pDstAlloc);
+                    switch (pSrcAlloc->enmType)
                     {
-                        rect = pBlt->DstRects.UpdateRects.aRects[0];
-                        for (UINT i = 1; i < pBlt->DstRects.UpdateRects.cRects; ++i)
+                        case VBOXWDDM_ALLOC_TYPE_STD_SHADOWSURFACE:
                         {
-                            vboxWddmRectUnited(&rect, &rect, &pBlt->DstRects.UpdateRects.aRects[i]);
+                            RECT rect;
+                            Assert(pContext->enmType == VBOXWDDM_CONTEXT_TYPE_SYSTEM);
+                            vboxWddmCheckUpdateShadowAddress(pDevExt, pSource, pPrivateData->SrcAllocInfo.segmentIdAlloc, pPrivateData->SrcAllocInfo.offAlloc);
+                            if (pBlt->DstRects.UpdateRects.cRects)
+                            {
+                                rect = pBlt->DstRects.UpdateRects.aRects[0];
+                                for (UINT i = 1; i < pBlt->DstRects.UpdateRects.cRects; ++i)
+                                {
+                                    vboxWddmRectUnited(&rect, &rect, &pBlt->DstRects.UpdateRects.aRects[i]);
+                                }
+                            }
+                            else
+                                rect = pBlt->DstRects.ContextRect;
+
+                            VBOXVBVA_OP(ReportDirtyRect, pDevExt, &pSource->Vbva, &rect);
+                            vboxWddmSubmitBltCmd(pDevExt, pContext, pBlt);
+                            break;
                         }
+                        case VBOXWDDM_ALLOC_TYPE_UMD_RC_GENERIC:
+                        {
+                            Assert(pContext->enmType == VBOXWDDM_CONTEXT_TYPE_CUSTOM_3D);
+                            Assert(pSrcAlloc->fRcFlags.RenderTarget);
+                            if (pSrcAlloc->fRcFlags.RenderTarget)
+                            {
+                                vboxWddmSubmitBltCmd(pDevExt, pContext, pBlt);
+                            }
+                            break;
+                        }
+                        default:
+                            AssertBreakpoint();
+                            break;
                     }
-                    else
-                        rect = pBlt->DstRects.ContextRect;
-
-                    VBOXWDDM_SOURCE *pSource = &pDevExt->aSources[pPrivateData->SrcAllocInfo.srcId];
-                    VBOXVBVA_OP(ReportDirtyRect, pDevExt, &pSource->Vbva, &rect);
+                    break;
                 }
-
-                PVBOXWDDM_CONTEXT pContext = (PVBOXWDDM_CONTEXT)pSubmitCommand->hContext;
-                Assert(pContext);
-                Assert(pContext->pDevice);
-                Assert(pContext->pDevice->pAdapter == pDevExt);
-                PVBOXVDMAPIPE_CMD_RECTSINFO pRectsCmd = (PVBOXVDMAPIPE_CMD_RECTSINFO)vboxVdmaGgCmdCreate(&pDevExt->u.primary.Vdma.DmaGg, VBOXVDMAPIPE_CMD_TYPE_RECTSINFO, RT_OFFSETOF(VBOXVDMAPIPE_CMD_RECTSINFO, ContextsRects.UpdateRects.aRects[pBlt->DstRects.UpdateRects.cRects]));
-                Assert(pRectsCmd);
-                if (pRectsCmd)
+                case VBOXWDDM_ALLOC_TYPE_STD_STAGINGSURFACE:
                 {
-                    pRectsCmd->pContext = pContext;
-                    memcpy(&pRectsCmd->ContextsRects, &pBlt->DstRects, RT_OFFSETOF(VBOXVDMAPIPE_RECTS, UpdateRects.aRects[pBlt->DstRects.UpdateRects.cRects]));
-                    NTSTATUS tmpStatus = vboxVdmaGgCmdSubmit(&pDevExt->u.primary.Vdma.DmaGg, &pRectsCmd->Hdr);
-                    Assert(tmpStatus == STATUS_SUCCESS);
-                    if (tmpStatus != STATUS_SUCCESS)
-                        vboxVdmaGgCmdDestroy(&pRectsCmd->Hdr);
+                    Assert(pContext->enmType == VBOXWDDM_CONTEXT_TYPE_CUSTOM_3D);
+                    Assert(pSrcAlloc->enmType == VBOXWDDM_ALLOC_TYPE_UMD_RC_GENERIC);
+                    Assert(pSrcAlloc->fRcFlags.RenderTarget);
+                    Assert(vboxWddmRectIsEqual(&pBlt->SrcRect, &pBlt->DstRects.ContextRect));
+                    Assert(pBlt->DstRects.UpdateRects.cRects == 1);
+                    Assert(vboxWddmRectIsEqual(&pBlt->SrcRect, pBlt->DstRects.UpdateRects.aRects));
+                    break;
                 }
-            }
-            else
-                Assert(!pPrivateData->fFlags.bShadow2PrimaryUpdate);
+                case VBOXWDDM_ALLOC_TYPE_STD_SHADOWSURFACE:
+                {
+                    Assert(pSrcAlloc->enmType == VBOXWDDM_ALLOC_TYPE_STD_SHAREDPRIMARYSURFACE);
+                    break;
+                }
+                default:
+                    AssertBreakpoint();
+                    break;
+            }
 
             VBOXWDDM_SHADOW_UPDATE_COMPLETION context;
@@ -2134,4 +2176,5 @@
         default:
         {
+            AssertBreakpoint();
             PVBOXVDMACBUF_DR pDr = vboxVdmaCBufDrCreate (&pDevExt->u.primary.Vdma, 0);
             if (!pDr)
@@ -3722,5 +3765,4 @@
 
                                     /* we do not know the shadow address yet, perform dummy DMA cycle */
-                                    pPrivateData->fFlags.bShadow2PrimaryUpdate = 1;
                                     pPrivateData->enmCmd = VBOXVDMACMD_TYPE_DMA_PRESENT_SHADOW2PRIMARY;
                                     vboxWddmPopulateDmaAllocInfo(&pPrivateData->SrcAllocInfo, pSrcAlloc, pSrc);
@@ -3746,25 +3788,6 @@
                     pPrivateData->enmCmd = VBOXVDMACMD_TYPE_DMA_PRESENT_BLT;
 
-                    if (pContext->enmType != VBOXWDDM_CONTEXT_TYPE_CUSTOM_3D)
-                    {
-                        vboxWddmPopulateDmaAllocInfo(&pPrivateData->SrcAllocInfo, pSrcAlloc, pSrc);
-
-                        if (pDstAlloc->enmType == VBOXWDDM_ALLOC_TYPE_STD_SHAREDPRIMARYSURFACE
-                                && pSrcAlloc->enmType == VBOXWDDM_ALLOC_TYPE_STD_SHADOWSURFACE)
-                        {
-#ifdef VBOXWDDM_RENDER_FROM_SHADOW
-                            Assert(cContexts3D);
-#endif
-                            pPrivateData->fFlags.bShadow2PrimaryUpdate = 1;
-                            Assert(pContext->enmType == VBOXWDDM_CONTEXT_TYPE_SYSTEM);
-                        }
-#ifdef VBOXWDDM_RENDER_FROM_SHADOW /* <- no need to fill dst surf info here */
-                        else
-#endif
-                        {
-                            vboxWddmPopulateDmaAllocInfo(&pPrivateData->DstAllocInfo, pDstAlloc, pDst);
-                        }
-                    }
-                    /* else - no need to fill any surf info since we need this request for visible rects */
+                    vboxWddmPopulateDmaAllocInfo(&pPrivateData->SrcAllocInfo, pSrcAlloc, pSrc);
+                    vboxWddmPopulateDmaAllocInfo(&pPrivateData->DstAllocInfo, pDstAlloc, pDst);
 
                     PVBOXWDDM_DMA_PRESENT_BLT pBlt = (PVBOXWDDM_DMA_PRESENT_BLT)pPrivateData;
Index: trunk/src/VBox/Additions/WINNT/Graphics/Miniport/wddm/VBoxVideoWddm.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Miniport/wddm/VBoxVideoWddm.h	(revision 30532)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Miniport/wddm/VBoxVideoWddm.h	(revision 30536)
@@ -54,5 +54,5 @@
 {
     VBOXWDDM_ALLOC_TYPE enmType;
-//    D3DDDI_RESOURCEFLAGS fRcFlags;
+    D3DDDI_RESOURCEFLAGS fRcFlags;
     UINT SegmentId;
     VBOXVIDEOOFFSET offVram;
@@ -149,8 +149,5 @@
         {
             UINT bCmdInDmaBuffer : 1;
-            UINT bShadow2PrimaryUpdate : 1;
-            UINT bSrcAllocValid : 1;
-            UINT bDstAllocValid : 1;
-            UINT bReserved : 28;
+            UINT bReserved : 31;
         };
         uint32_t Value;
