Index: trunk/src/VBox/Additions/WINNT/Graphics/Video/common/wddm/VBoxMPIf.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Video/common/wddm/VBoxMPIf.h	(revision 40716)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Video/common/wddm/VBoxMPIf.h	(revision 40747)
@@ -239,9 +239,14 @@
 {
     VBOXWDDM_CONTEXT_TYPE_UNDEFINED = 0,
+    /* system-created context (for GDI rendering) */
     VBOXWDDM_CONTEXT_TYPE_SYSTEM,
+    /* context created by the D3D User-mode driver when crogl IS available */
     VBOXWDDM_CONTEXT_TYPE_CUSTOM_3D,
+    /* context created by the D3D User-mode driver when crogl is NOT available or for ddraw overlay acceleration */
     VBOXWDDM_CONTEXT_TYPE_CUSTOM_2D,
+    /* contexts created by the cromium HGSMI transport for HGSMI commands submission */
     VBOXWDDM_CONTEXT_TYPE_CUSTOM_UHGSMI_3D,
     VBOXWDDM_CONTEXT_TYPE_CUSTOM_UHGSMI_GL,
+    /* context created by the kernel->user communication mechanism for visible rects reporting, etc.  */
     VBOXWDDM_CONTEXT_TYPE_CUSTOM_SESSION
 } VBOXWDDM_CONTEXT_TYPE;
@@ -481,4 +486,20 @@
 
 /* submit cmd func */
+DECLINLINE(D3DDDIFORMAT) vboxWddmFmtNoAlphaFormat(D3DDDIFORMAT enmFormat)
+{
+    switch (enmFormat)
+    {
+        case D3DDDIFMT_A8R8G8B8:
+            return D3DDDIFMT_X8R8G8B8;
+        case D3DDDIFMT_A1R5G5B5:
+            return D3DDDIFMT_X1R5G5B5;
+        case D3DDDIFMT_A4R4G4B4:
+            return D3DDDIFMT_X4R4G4B4;
+        case D3DDDIFMT_A8B8G8R8:
+            return D3DDDIFMT_X8B8G8R8;
+        default:
+            return enmFormat;
+    }
+}
 
 /* tooling */
Index: trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/common/VBoxMPDevExt.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/common/VBoxMPDevExt.h	(revision 40716)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/common/VBoxMPDevExt.h	(revision 40747)
@@ -99,5 +99,9 @@
    KSPIN_LOCK SynchLock;
    volatile uint32_t cContexts3D;
+   volatile uint32_t cContexts2D;
+   volatile uint32_t cRenderFromShadowDisabledContexts;
    volatile uint32_t cUnlockedVBVADisabled;
+   /* this is examined and swicthed by DxgkDdiSubmitCommand only! */
+   volatile BOOLEAN fRenderToShadowDisabled;
 
    HVBOXCRCTL hCrCtl;
Index: trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPTypes.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPTypes.h	(revision 40716)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPTypes.h	(revision 40747)
@@ -221,4 +221,5 @@
     UINT  NodeOrdinal;
     UINT  EngineAffinity;
+    BOOLEAN fRenderFromShadowDisabled;
     uint32_t u32CrConClientID;
     VBOXWDDM_HTABLE Swapchains;
Index: trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPVdma.cpp
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPVdma.cpp	(revision 40716)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPVdma.cpp	(revision 40747)
@@ -621,6 +621,4 @@
 {
     uint8_t* pvVramBase = pDevExt->pvVisibleVram;
-    /* we do not support color conversion */
-    Assert(pSrcAlloc->SurfDesc.format == pDstAlloc->SurfDesc.format);
     /* we do not support stretching */
     uint32_t srcWidth = pSrcRect->right - pSrcRect->left;
@@ -632,7 +630,21 @@
     Assert(pDstAlloc->offVram != VBOXVIDEOOFFSET_VOID);
     Assert(pSrcAlloc->offVram != VBOXVIDEOOFFSET_VOID);
-
-    if (pSrcAlloc->SurfDesc.format != pDstAlloc->SurfDesc.format)
-        return STATUS_INVALID_PARAMETER;
+    D3DDDIFORMAT enmSrcFormat, enmDstFormat;
+
+    enmSrcFormat = pSrcAlloc->SurfDesc.format;
+    enmDstFormat = pDstAlloc->SurfDesc.format;
+
+    if (enmSrcFormat != enmDstFormat)
+    {
+        /* just ignore the alpha component
+         * this is ok since our software-based stuff can not handle alpha channel in any way */
+        enmSrcFormat = vboxWddmFmtNoAlphaFormat(enmSrcFormat);
+        enmDstFormat = vboxWddmFmtNoAlphaFormat(enmDstFormat);
+        if (enmSrcFormat != enmDstFormat)
+        {
+            WARN(("color conversion src(%d), dst(%d) not supported!", pSrcAlloc->SurfDesc.format, pDstAlloc->SurfDesc.format));
+            return STATUS_INVALID_PARAMETER;
+        }
+    }
     if (srcHeight != dstHeight)
             return STATUS_INVALID_PARAMETER;
@@ -678,5 +690,5 @@
         for (uint32_t i = 0; i < cRows; ++i)
         {
-            memcpy (pvDstStart, pvSrcStart, cbDstLine);
+            memcpy(pvDstStart, pvSrcStart, cbDstLine);
             pvDstStart += cbDstSkip;
             pvSrcStart += cbSrcSkip;
@@ -689,28 +701,26 @@
  * @return on success the number of bytes the command contained, otherwise - VERR_xxx error code
  */
-static NTSTATUS vboxVdmaGgDmaBlt(PVBOXMP_DEVEXT pDevExt, PVBOXVDMAPIPE_CMD_DMACMD_BLT pBlt)
+static NTSTATUS vboxVdmaGgDmaBlt(PVBOXMP_DEVEXT pDevExt, PVBOXVDMA_BLT pBlt)
 {
     /* we do not support stretching for now */
-    Assert(pBlt->Blt.SrcRect.right - pBlt->Blt.SrcRect.left == pBlt->Blt.DstRects.ContextRect.right - pBlt->Blt.DstRects.ContextRect.left);
-    Assert(pBlt->Blt.SrcRect.bottom - pBlt->Blt.SrcRect.top == pBlt->Blt.DstRects.ContextRect.bottom - pBlt->Blt.DstRects.ContextRect.top);
-    if (pBlt->Blt.SrcRect.right - pBlt->Blt.SrcRect.left != pBlt->Blt.DstRects.ContextRect.right - pBlt->Blt.DstRects.ContextRect.left)
+    Assert(pBlt->SrcRect.right - pBlt->SrcRect.left == pBlt->DstRects.ContextRect.right - pBlt->DstRects.ContextRect.left);
+    Assert(pBlt->SrcRect.bottom - pBlt->SrcRect.top == pBlt->DstRects.ContextRect.bottom - pBlt->DstRects.ContextRect.top);
+    if (pBlt->SrcRect.right - pBlt->SrcRect.left != pBlt->DstRects.ContextRect.right - pBlt->DstRects.ContextRect.left)
         return STATUS_INVALID_PARAMETER;
-    if (pBlt->Blt.SrcRect.bottom - pBlt->Blt.SrcRect.top != pBlt->Blt.DstRects.ContextRect.bottom - pBlt->Blt.DstRects.ContextRect.top)
+    if (pBlt->SrcRect.bottom - pBlt->SrcRect.top != pBlt->DstRects.ContextRect.bottom - pBlt->DstRects.ContextRect.top)
         return STATUS_INVALID_PARAMETER;
-    Assert(pBlt->Blt.DstRects.UpdateRects.cRects);
+    Assert(pBlt->DstRects.UpdateRects.cRects);
 
     NTSTATUS Status = STATUS_SUCCESS;
 
-    if (pBlt->Blt.DstRects.UpdateRects.cRects)
-    {
-        for (uint32_t i = 0; i < pBlt->Blt.DstRects.UpdateRects.cRects; ++i)
-        {
-            RECT DstRect;
+    if (pBlt->DstRects.UpdateRects.cRects)
+    {
+        for (uint32_t i = 0; i < pBlt->DstRects.UpdateRects.cRects; ++i)
+        {
             RECT SrcRect;
-            vboxWddmRectTranslated(&DstRect, &pBlt->Blt.DstRects.UpdateRects.aRects[i], pBlt->Blt.DstRects.ContextRect.left, pBlt->Blt.DstRects.ContextRect.top);
-            vboxWddmRectTranslated(&SrcRect, &pBlt->Blt.DstRects.UpdateRects.aRects[i], pBlt->Blt.SrcRect.left, pBlt->Blt.SrcRect.top);
-
-            Status = vboxVdmaGgDmaBltPerform(pDevExt, pBlt->Blt.SrcAlloc.pAlloc, &SrcRect,
-                    pBlt->Blt.DstAlloc.pAlloc, &DstRect);
+            vboxWddmRectTranslated(&SrcRect, &pBlt->DstRects.UpdateRects.aRects[i], -pBlt->DstRects.ContextRect.left, -pBlt->DstRects.ContextRect.top);
+
+            Status = vboxVdmaGgDmaBltPerform(pDevExt, pBlt->SrcAlloc.pAlloc, &SrcRect,
+                    pBlt->DstAlloc.pAlloc, &pBlt->DstRects.UpdateRects.aRects[i]);
             Assert(Status == STATUS_SUCCESS);
             if (Status != STATUS_SUCCESS)
@@ -720,6 +730,6 @@
     else
     {
-        Status = vboxVdmaGgDmaBltPerform(pDevExt, pBlt->Blt.SrcAlloc.pAlloc, &pBlt->Blt.SrcRect,
-                pBlt->Blt.DstAlloc.pAlloc, &pBlt->Blt.DstRects.ContextRect);
+        Status = vboxVdmaGgDmaBltPerform(pDevExt, pBlt->SrcAlloc.pAlloc, &pBlt->SrcRect,
+                pBlt->DstAlloc.pAlloc, &pBlt->DstRects.ContextRect);
         Assert(Status == STATUS_SUCCESS);
         if (Status != STATUS_SUCCESS)
@@ -752,103 +762,39 @@
             PVBOXWDDM_ALLOCATION pDstAlloc = pBlt->Blt.DstAlloc.pAlloc;
             PVBOXWDDM_ALLOCATION pSrcAlloc = pBlt->Blt.SrcAlloc.pAlloc;
-            BOOLEAN bComplete = TRUE;
-            switch (pDstAlloc->enmType)
+
+            if (pBlt->Hdr.fFlags.fRealOp)
             {
-                case VBOXWDDM_ALLOC_TYPE_STD_SHAREDPRIMARYSURFACE:
-                case VBOXWDDM_ALLOC_TYPE_UMD_RC_GENERIC:
+                vboxVdmaGgDmaBlt(pDevExt, &pBlt->Blt);
+
+                if ((pDstAlloc->enmType == VBOXWDDM_ALLOC_TYPE_STD_SHAREDPRIMARYSURFACE
+                        || pDstAlloc->enmType == VBOXWDDM_ALLOC_TYPE_UMD_RC_GENERIC)
+                        && pDstAlloc->bAssigned)
                 {
-                    if (pDstAlloc->bAssigned)
+                    VBOXWDDM_SOURCE *pSource = &pDevExt->aSources[pDstAlloc->SurfDesc.VidPnSourceId];
+                    Assert(pDstAlloc->SurfDesc.VidPnSourceId < VBOX_VIDEO_MAX_SCREENS);
+                    Assert(pSource->pPrimaryAllocation == pDstAlloc);
+
+                    RECT UpdateRect;
+                    UpdateRect = pBlt->Blt.DstRects.UpdateRects.aRects[0];
+                    for (UINT i = 1; i < pBlt->Blt.DstRects.UpdateRects.cRects; ++i)
                     {
-                        VBOXWDDM_SOURCE *pSource = &pDevExt->aSources[pDstAlloc->SurfDesc.VidPnSourceId];
-                        Assert(pSource->pPrimaryAllocation == pDstAlloc);
-                        switch (pSrcAlloc->enmType)
-                        {
-                            case VBOXWDDM_ALLOC_TYPE_STD_SHADOWSURFACE:
-                            {
-                                Assert(pContext->enmType == VBOXWDDM_CONTEXT_TYPE_SYSTEM);
-
-                                if (pBlt->Hdr.fFlags.b2DRelated)
-                                {
-                                    RECT OverlayUnionRect;
-                                    RECT UpdateRect;
-                                    UpdateRect = pBlt->Blt.DstRects.UpdateRects.aRects[0];
-                                    for (UINT i = 1; i < pBlt->Blt.DstRects.UpdateRects.cRects; ++i)
-                                    {
-                                        vboxWddmRectUnite(&UpdateRect, &pBlt->Blt.DstRects.UpdateRects.aRects[i]);
-                                    }
-                                    vboxVhwaHlpOverlayDstRectUnion(pDevExt, pDstAlloc->SurfDesc.VidPnSourceId, &OverlayUnionRect);
-                                    Assert(pBlt->Blt.DstRects.ContextRect.left == 0); /* <-| otherwise we would probably need to translate the UpdateRects to left;top first??*/
-                                    Assert(pBlt->Blt.DstRects.ContextRect.top == 0); /* <--| */
-                                    vboxVdmaDirtyRectsCalcIntersection(&OverlayUnionRect, &pBlt->Blt.DstRects.UpdateRects, &pBlt->Blt.DstRects.UpdateRects);
-                                    if (pBlt->Blt.DstRects.UpdateRects.cRects)
-                                    {
-                                        vboxVdmaGgDmaBlt(pDevExt, pBlt);
-                                    }
-
-                                    uint32_t cUnlockedVBVADisabled = ASMAtomicReadU32(&pDevExt->cUnlockedVBVADisabled);
-                                    if (!cUnlockedVBVADisabled)
-                                    {
-                                        VBOXVBVA_OP(ReportDirtyRect, pDevExt, pSource, &UpdateRect);
-                                    }
-                                    else
-                                    {
-                                        VBOXVBVA_OP_WITHLOCK(ReportDirtyRect, pDevExt, pSource, &UpdateRect);
-                                    }
-
-                                }
-
-                                if (pBlt->Hdr.fFlags.b3DRelated)
-                                {
-                                    Status = STATUS_MORE_PROCESSING_REQUIRED;
-                                }
-
-                                break;
-                            }
-                            case VBOXWDDM_ALLOC_TYPE_UMD_RC_GENERIC:
-                            {
-                                Assert(pContext->enmType == VBOXWDDM_CONTEXT_TYPE_CUSTOM_3D);
-                                Assert(pSrcAlloc->fRcFlags.RenderTarget);
-                                if (pSrcAlloc->fRcFlags.RenderTarget)
-                                {
-                                    if (pBlt->Hdr.fFlags.b3DRelated)
-                                    {
-                                        Status = STATUS_MORE_PROCESSING_REQUIRED;
-                                    }
-                                }
-                                break;
-                            }
-                            default:
-                                AssertBreakpoint();
-                                break;
-                        }
+                        vboxWddmRectUnite(&UpdateRect, &pBlt->Blt.DstRects.UpdateRects.aRects[i]);
                     }
-                    break;
-                }
-                case VBOXWDDM_ALLOC_TYPE_STD_SHADOWSURFACE:
-                {
-                    if (pBlt->Hdr.fFlags.b2DRelated)
+
+                    uint32_t cUnlockedVBVADisabled = ASMAtomicReadU32(&pDevExt->cUnlockedVBVADisabled);
+                    if (!cUnlockedVBVADisabled)
                     {
-                        RECT OverlayUnionRect;
-                        vboxVhwaHlpOverlayDstRectUnion(pDevExt, pDstAlloc->SurfDesc.VidPnSourceId, &OverlayUnionRect);
-                        Assert(pBlt->Blt.DstRects.ContextRect.left == 0); /* <-| otherwise we would probably need to translate the UpdateRects to left;top first??*/
-                        Assert(pBlt->Blt.DstRects.ContextRect.top == 0); /* <--| */
-                        vboxVdmaDirtyRectsCalcIntersection(&OverlayUnionRect, &pBlt->Blt.DstRects.UpdateRects, &pBlt->Blt.DstRects.UpdateRects);
-                        if (pBlt->Blt.DstRects.UpdateRects.cRects)
-                        {
-                            vboxVdmaGgDmaBlt(pDevExt, pBlt);
-                        }
+                        VBOXVBVA_OP(ReportDirtyRect, pDevExt, pSource, &UpdateRect);
                     }
                     else
                     {
-                        Assert(0);
+                        VBOXVBVA_OP_WITHLOCK(ReportDirtyRect, pDevExt, pSource, &UpdateRect);
                     }
-                    break;
                 }
-                default:
-                    Assert(0);
             }
 
-            if (Status == STATUS_MORE_PROCESSING_REQUIRED)
+            if (pBlt->Hdr.fFlags.fVisibleRegions)
             {
+                Status = STATUS_MORE_PROCESSING_REQUIRED;
                 vboxWddmAllocationRetain(pDstAlloc);
                 vboxWddmAllocationRetain(pSrcAlloc);
@@ -856,10 +802,11 @@
             break;
         }
+
         case VBOXVDMACMD_TYPE_DMA_PRESENT_FLIP:
         {
             PVBOXVDMAPIPE_CMD_DMACMD_FLIP pFlip = (PVBOXVDMAPIPE_CMD_DMACMD_FLIP)pDmaCmd;
-            Assert(pFlip->Hdr.fFlags.b3DRelated);
-            Assert(!pFlip->Hdr.fFlags.b2DRelated);
-            if (pFlip->Hdr.fFlags.b3DRelated)
+            Assert(pFlip->Hdr.fFlags.fVisibleRegions);
+            Assert(!pFlip->Hdr.fFlags.fRealOp);
+            if (pFlip->Hdr.fFlags.fVisibleRegions)
             {
                 Status = STATUS_MORE_PROCESSING_REQUIRED;
@@ -872,6 +819,6 @@
         {
             PVBOXVDMAPIPE_CMD_DMACMD_CLRFILL pCF = (PVBOXVDMAPIPE_CMD_DMACMD_CLRFILL)pDmaCmd;
-            Assert(pCF->Hdr.fFlags.b2DRelated);
-            Assert(!pCF->Hdr.fFlags.b3DRelated);
+            Assert(pCF->Hdr.fFlags.fRealOp);
+            Assert(!pCF->Hdr.fFlags.fVisibleRegions);
             Status = vboxVdmaGgDmaColorFill(pDevExt, pCF);
             Assert(Status == STATUS_SUCCESS);
@@ -899,4 +846,8 @@
     PVBOXWDDM_CONTEXT pContext = pDmaCmd->pContext;
     DXGK_INTERRUPT_TYPE enmComplType = DXGK_INTERRUPT_DMA_COMPLETED;
+
+    Assert(pDmaCmd->fFlags.Value);
+    Assert(!pDmaCmd->fFlags.fRealOp);
+
     switch (pDmaCmd->enmCmd)
     {
@@ -907,84 +858,36 @@
             PVBOXWDDM_ALLOCATION pSrcAlloc = pBlt->Blt.SrcAlloc.pAlloc;
             BOOLEAN bComplete = TRUE;
-            switch (pDstAlloc->enmType)
+            VBOXWDDM_SOURCE *pSource = &pDevExt->aSources[pDstAlloc->SurfDesc.VidPnSourceId];
+            Assert(pDstAlloc->SurfDesc.VidPnSourceId < VBOX_VIDEO_MAX_SCREENS);
+
+            if (pBlt->Hdr.fFlags.fVisibleRegions)
             {
-                case VBOXWDDM_ALLOC_TYPE_STD_SHAREDPRIMARYSURFACE:
-                case VBOXWDDM_ALLOC_TYPE_UMD_RC_GENERIC:
+                POINT pos = pSource->VScreenPos;
+                if (pos.x || pos.y)
                 {
-                    if (pDstAlloc->bAssigned)
-                    {
-                        VBOXWDDM_SOURCE *pSource = &pDevExt->aSources[pDstAlloc->SurfDesc.VidPnSourceId];
-                        Assert(pSource->pPrimaryAllocation == pDstAlloc);
-                        switch (pSrcAlloc->enmType)
-                        {
-                            case VBOXWDDM_ALLOC_TYPE_STD_SHADOWSURFACE:
-                            {
-                                Assert(pContext->enmType == VBOXWDDM_CONTEXT_TYPE_SYSTEM);
-
-                                if (pBlt->Hdr.fFlags.b3DRelated)
-                                {
-                                    POINT pos = pSource->VScreenPos;
-                                    if (pos.x || pos.y)
-                                    {
-                                        /* note: do NOT trans;ate the src rect since it is used for screen pos calculation */
-                                        vboxWddmBltPipeRectsTranslate(&pBlt->Blt.DstRects, pos.x, pos.y);
-                                    }
-
-                                    Status = vboxVdmaGgDirtyRectsProcess(pDevExt, pContext, NULL, &pBlt->Blt.SrcRect, &pBlt->Blt.DstRects);
-                                    Assert(Status == STATUS_SUCCESS);
-                                }
-
-                                break;
-                            }
-                            case VBOXWDDM_ALLOC_TYPE_UMD_RC_GENERIC:
-                            {
-                                Assert(pContext->enmType == VBOXWDDM_CONTEXT_TYPE_CUSTOM_3D);
-                                Assert(pSrcAlloc->fRcFlags.RenderTarget);
-                                if (pSrcAlloc->fRcFlags.RenderTarget)
-                                {
-                                    if (pBlt->Hdr.fFlags.b3DRelated)
-                                    {
-                                        POINT pos = pSource->VScreenPos;
-                                        if (pos.x || pos.y)
-                                        {
-                                            /* note: do NOT trans;ate the src rect since it is used for screen pos calculation */
-                                            vboxWddmBltPipeRectsTranslate(&pBlt->Blt.DstRects, pos.x, pos.y);
-                                        }
-
-                                        PVBOXWDDM_SWAPCHAIN pSwapchain;
-                                        pSwapchain = vboxWddmSwapchainRetainByAlloc(pDevExt, pSrcAlloc);
-                                        if (pSwapchain)
-                                        {
-                                            Status = vboxVdmaGgDirtyRectsProcess(pDevExt, pContext, pSwapchain, &pBlt->Blt.SrcRect, &pBlt->Blt.DstRects);
-                                            Assert(Status == STATUS_SUCCESS);
-                                            vboxWddmSwapchainRelease(pSwapchain);
-                                        }
-                                    }
-                                }
-                                break;
-                            }
-                            default:
-                                AssertBreakpoint();
-                                break;
-                        }
-                    }
-                    break;
+                    /* note: do NOT translate the src rect since it is used for screen pos calculation */
+                    vboxWddmBltPipeRectsTranslate(&pBlt->Blt.DstRects, pos.x, pos.y);
                 }
-                default:
-                    Assert(0);
+
+                Status = vboxVdmaGgDirtyRectsProcess(pDevExt, pContext, NULL, &pBlt->Blt.SrcRect, &pBlt->Blt.DstRects);
+                Assert(Status == STATUS_SUCCESS);
+            }
+            else
+            {
+                WARN(("not expected!"));
             }
 
             vboxWddmAllocationRelease(pDstAlloc);
             vboxWddmAllocationRelease(pSrcAlloc);
-            break;
-        }
+
+            break;
+        }
+
         case VBOXVDMACMD_TYPE_DMA_PRESENT_FLIP:
         {
             PVBOXVDMAPIPE_CMD_DMACMD_FLIP pFlip = (PVBOXVDMAPIPE_CMD_DMACMD_FLIP)pDmaCmd;
-            Assert(pFlip->Hdr.fFlags.b3DRelated);
-            Assert(!pFlip->Hdr.fFlags.b2DRelated);
             PVBOXWDDM_ALLOCATION pAlloc = pFlip->Flip.Alloc.pAlloc;
             VBOXWDDM_SOURCE *pSource = &pDevExt->aSources[pAlloc->SurfDesc.VidPnSourceId];
-            if (pFlip->Hdr.fFlags.b3DRelated)
+            if (pFlip->Hdr.fFlags.fVisibleRegions)
             {
                 PVBOXWDDM_SWAPCHAIN pSwapchain;
@@ -1010,4 +913,8 @@
                 }
             }
+            else
+            {
+                WARN(("not expected!"));
+            }
 
             vboxWddmAllocationRelease(pAlloc);
@@ -1015,7 +922,10 @@
             break;
         }
+
         default:
-            Assert(0);
-            break;
+        {
+            WARN(("not expected!"));
+            break;
+        }
     }
 
Index: trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPVdma.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPVdma.h	(revision 40716)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPVdma.h	(revision 40747)
@@ -218,7 +218,7 @@
         struct
         {
-            UINT b2DRelated     : 1;
-            UINT b3DRelated     : 1;
-            UINT Reserved       : 30;
+            UINT fRealOp             : 1;
+            UINT fVisibleRegions     : 1;
+            UINT Reserve             : 30;
         };
         UINT Value;
@@ -341,4 +341,7 @@
         PFNVBOXVDMADDICMDCOMPLETE_DPC pfnComplete, PVOID pvComplete);
 
+NTSTATUS vboxVdmaGgDmaBltPerform(PVBOXMP_DEVEXT pDevExt, PVBOXWDDM_ALLOCATION pSrcAlloc, RECT* pSrcRect,
+        PVBOXWDDM_ALLOCATION pDstAlloc, RECT* pDstRect);
+
 #define VBOXVDMAPIPE_CMD_DR_FROM_DDI_CMD(_pCmd) ((PVBOXVDMAPIPE_CMD_DR)(((uint8_t*)(_pCmd)) - RT_OFFSETOF(VBOXVDMAPIPE_CMD_DR, DdiCmd)))
 DECLCALLBACK(VOID) vboxVdmaGgDdiCmdDestroy(PVBOXMP_DEVEXT pDevExt, PVBOXVDMADDI_CMD pCmd, PVOID pvContext);
Index: trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPWddm.cpp
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPWddm.cpp	(revision 40716)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPWddm.cpp	(revision 40747)
@@ -223,5 +223,5 @@
     pSource->VScreenPos = *pVScreenPos;
 
-    PVBOXWDDM_ALLOCATION pAllocation = VBOXWDDM_FB_ALLOCATION(pSource);
+    PVBOXWDDM_ALLOCATION pAllocation = VBOXWDDM_FB_ALLOCATION(pDevExt, pSource);
     NTSTATUS Status = vboxWddmGhDisplayPostInfoScreen(pDevExt, pAllocation, &pSource->VScreenPos);
     Assert(Status == STATUS_SUCCESS);
@@ -231,5 +231,5 @@
 NTSTATUS vboxWddmGhDisplaySetInfo(PVBOXMP_DEVEXT pDevExt, PVBOXWDDM_SOURCE pSource, D3DDDI_VIDEO_PRESENT_SOURCE_ID VidPnSourceId)
 {
-    PVBOXWDDM_ALLOCATION pAllocation = VBOXWDDM_FB_ALLOCATION(pSource);
+    PVBOXWDDM_ALLOCATION pAllocation = VBOXWDDM_FB_ALLOCATION(pDevExt, pSource);
     VBOXVIDEOOFFSET offVram = vboxWddmValidatePrimary(pAllocation);
     Assert(offVram != VBOXVIDEOOFFSET_VOID);
@@ -264,7 +264,88 @@
 }
 
+static VOID vboxWddmModeRenderFromShadowDisableOnSubmitCommand(PVBOXMP_DEVEXT pDevExt, BOOLEAN fDisable)
+{
+    for (int i = 0; i < VBoxCommonFromDeviceExt(pDevExt)->cDisplays; ++i)
+    {
+        PVBOXWDDM_SOURCE pSource = &pDevExt->aSources[i];
+        PVBOXWDDM_ALLOCATION pFromAllocation;
+        PVBOXWDDM_ALLOCATION pToAllocation;
+        if (fDisable)
+        {
+            pFromAllocation = pSource->pShadowAllocation;
+            pToAllocation = pSource->pPrimaryAllocation;
+        }
+        else
+        {
+            pToAllocation = pSource->pShadowAllocation;
+            pFromAllocation = pSource->pPrimaryAllocation;
+        }
+
+        Assert(pToAllocation->offVram != VBOXVIDEOOFFSET_VOID);
+        Assert(pFromAllocation->offVram != VBOXVIDEOOFFSET_VOID);
+        if (pToAllocation->offVram != VBOXVIDEOOFFSET_VOID
+                && pFromAllocation->offVram != VBOXVIDEOOFFSET_VOID)
+        {
+            RECT Rect;
+            Rect.left = 0;
+            Rect.top = 0;
+            Rect.right = pToAllocation->SurfDesc.width;
+            Rect.bottom = pToAllocation->SurfDesc.height;
+            vboxVdmaGgDmaBltPerform(pDevExt, pFromAllocation, &Rect,
+                    pToAllocation, &Rect);
+        }
+
+        /* ensure we issue resize command on next update */
+        pSource->offVram = VBOXVIDEOOFFSET_VOID;
+    }
+}
+
+static BOOLEAN vboxWddmModeRenderFromShadowCheckOnSubmitCommand(PVBOXMP_DEVEXT pDevExt, BOOLEAN *pbSwitched)
+{
+    BOOLEAN fDisabled, fNeedSwitch;
+    uint32_t cCount = ASMAtomicUoReadU32(&pDevExt->cRenderFromShadowDisabledContexts);
+
+    fDisabled = !!cCount;
+    fNeedSwitch = (!fDisabled != !pDevExt->fRenderToShadowDisabled);
+
+    if (fNeedSwitch)
+    {
+        vboxWddmModeRenderFromShadowDisableOnSubmitCommand(pDevExt, fDisabled);
+        pDevExt->fRenderToShadowDisabled = fDisabled;
+    }
+
+    if (pbSwitched)
+        *pbSwitched = fNeedSwitch;
+
+    return fDisabled;
+}
+
+
+static VOID vboxWddmModeRenderFromShadowDisableRegister(PVBOXMP_DEVEXT pDevExt, VBOXWDDM_CONTEXT *pContext)
+{
+    if (pContext->fRenderFromShadowDisabled)
+        return;
+    ASMAtomicIncU32(&pDevExt->cRenderFromShadowDisabledContexts);
+    pContext->fRenderFromShadowDisabled = TRUE;
+}
+
+static VOID vboxWddmModeRenderFromShadowDisableUnregister(PVBOXMP_DEVEXT pDevExt, VBOXWDDM_CONTEXT *pContext)
+{
+    if (!pContext->fRenderFromShadowDisabled)
+        return;
+
+    uint32_t cCount = ASMAtomicDecU32(&pDevExt->cRenderFromShadowDisabledContexts);
+    Assert(cCount < UINT32_MAX);
+    pContext->fRenderFromShadowDisabled = FALSE;
+}
+
+DECLINLINE(VOID) vboxWddmAllocUpdateAddress(PVBOXWDDM_ALLOCATION pAllocation, UINT SegmentId, VBOXVIDEOOFFSET offVram)
+{
+    pAllocation->SegmentId = SegmentId;
+    pAllocation->offVram = offVram;
+}
+
 #ifdef VBOXWDDM_RENDER_FROM_SHADOW
-bool vboxWddmCheckUpdateShadowAddress(PVBOXMP_DEVEXT pDevExt, PVBOXWDDM_SOURCE pSource,
-        D3DDDI_VIDEO_PRESENT_SOURCE_ID VidPnSourceId, UINT SegmentId, VBOXVIDEOOFFSET offVram)
+bool vboxWddmCheckUpdateFramebufferAddress(PVBOXMP_DEVEXT pDevExt, PVBOXWDDM_SOURCE pSource, D3DDDI_VIDEO_PRESENT_SOURCE_ID VidPnSourceId)
 {
     if (pSource->pPrimaryAllocation->enmType == VBOXWDDM_ALLOC_TYPE_UMD_RC_GENERIC)
@@ -273,12 +354,13 @@
         return false;
     }
-    if (pSource->offVram == offVram)
+
+    PVBOXWDDM_ALLOCATION pAllocation = VBOXWDDM_FB_ALLOCATION(pDevExt, pSource);
+    Assert(VBOXVIDEOOFFSET_VOID != pAllocation->offVram);
+
+    if (pSource->offVram == pAllocation->offVram)
         return false;
-    pSource->offVram = offVram;
-    pSource->pShadowAllocation->SegmentId = SegmentId;
-    pSource->pShadowAllocation->offVram = offVram;
+    pSource->offVram = pAllocation->offVram;
 
     NTSTATUS Status = vboxWddmGhDisplaySetInfo(pDevExt, pSource, VidPnSourceId);
-    Assert(Status == STATUS_SUCCESS);
     if (Status != STATUS_SUCCESS)
         WARN(("vboxWddmGhDisplaySetInfo failed, Status (0x%x)", Status));
@@ -965,4 +1047,6 @@
                     InitializeListHead(&pDevExt->SwapchainList3D);
                     pDevExt->cContexts3D = 0;
+                    pDevExt->cContexts2D = 0;
+                    pDevExt->cUnlockedVBVADisabled = 0;
                     ExInitializeFastMutex(&pDevExt->ContextMutex);
                     KeInitializeSpinLock(&pDevExt->SynchLock);
@@ -2709,4 +2793,9 @@
     }
 
+    if (pContext->enmType == VBOXWDDM_CONTEXT_TYPE_CUSTOM_2D)
+        vboxWddmModeRenderFromShadowDisableRegister(pDevExt, pContext);
+
+    BOOLEAN fRenderFromSharedDisabled = pDevExt->fRenderToShadowDisabled;
+
     switch (enmCmd)
     {
@@ -2718,6 +2807,7 @@
             PVBOXWDDM_ALLOCATION pSrcAlloc = pS2P->Shadow2Primary.ShadowAlloc.pAlloc;
             vboxWddmAssignShadow(pDevExt, pSource, pSrcAlloc, pS2P->Shadow2Primary.VidPnSourceId);
-            vboxWddmCheckUpdateShadowAddress(pDevExt, pSource, pS2P->Shadow2Primary.VidPnSourceId,
-                    pS2P->Shadow2Primary.ShadowAlloc.segmentIdAlloc, pS2P->Shadow2Primary.ShadowAlloc.offAlloc);
+            vboxWddmAllocUpdateAddress(pSrcAlloc, pS2P->Shadow2Primary.ShadowAlloc.segmentIdAlloc, pS2P->Shadow2Primary.ShadowAlloc.offAlloc);
+            fRenderFromSharedDisabled = vboxWddmModeRenderFromShadowCheckOnSubmitCommand(pDevExt, NULL);
+            vboxWddmCheckUpdateFramebufferAddress(pDevExt, pSource, pS2P->Shadow2Primary.VidPnSourceId);
             uint32_t cUnlockedVBVADisabled = ASMAtomicReadU32(&pDevExt->cUnlockedVBVADisabled);
             if (!cUnlockedVBVADisabled)
@@ -2740,7 +2830,44 @@
             PVBOXWDDM_ALLOCATION pDstAlloc = pBlt->Blt.DstAlloc.pAlloc;
             PVBOXWDDM_ALLOCATION pSrcAlloc = pBlt->Blt.SrcAlloc.pAlloc;
+            VBOXWDDM_SOURCE *pSource = &pDevExt->aSources[pDstAlloc->SurfDesc.VidPnSourceId];
+
+            Assert(pDstAlloc->SurfDesc.VidPnSourceId < VBOX_VIDEO_MAX_SCREENS);
+
+            vboxWddmAllocUpdateAddress(pDstAlloc, pBlt->Blt.DstAlloc.segmentIdAlloc, pBlt->Blt.DstAlloc.offAlloc);
+            vboxWddmAllocUpdateAddress(pSrcAlloc, pBlt->Blt.SrcAlloc.segmentIdAlloc, pBlt->Blt.SrcAlloc.offAlloc);
 
             uint32_t cContexts3D = ASMAtomicReadU32(&pDevExt->cContexts3D);
-            BOOLEAN bComplete = TRUE;
+
+            VBOXVDMAPIPE_FLAGS_DMACMD fBltFlags;
+            fBltFlags.Value = 0;
+
+            if (pDstAlloc->bAssigned &&
+                    (pDstAlloc->enmType == VBOXWDDM_ALLOC_TYPE_STD_SHAREDPRIMARYSURFACE
+                        || pDstAlloc->enmType == VBOXWDDM_ALLOC_TYPE_STD_SHAREDPRIMARYSURFACE)
+                    )
+            {
+                if (pSrcAlloc->enmType == VBOXWDDM_ALLOC_TYPE_STD_SHADOWSURFACE)
+                    vboxWddmAssignShadow(pDevExt, pSource, pSrcAlloc, pDstAlloc->SurfDesc.VidPnSourceId);
+                fRenderFromSharedDisabled = vboxWddmModeRenderFromShadowCheckOnSubmitCommand(pDevExt, NULL);
+                if(pContext->enmType != VBOXWDDM_CONTEXT_TYPE_CUSTOM_3D
+                        || pDstAlloc->enmType !=VBOXWDDM_ALLOC_TYPE_UMD_RC_GENERIC)
+                    vboxWddmCheckUpdateFramebufferAddress(pDevExt, pSource, pDstAlloc->SurfDesc.VidPnSourceId);
+            }
+            else if (pSrcAlloc->bAssigned &&
+                    (pSrcAlloc->enmType == VBOXWDDM_ALLOC_TYPE_STD_SHAREDPRIMARYSURFACE
+                        || pSrcAlloc->enmType == VBOXWDDM_ALLOC_TYPE_STD_SHAREDPRIMARYSURFACE)
+                    )
+            {
+                if (pDstAlloc->enmType == VBOXWDDM_ALLOC_TYPE_STD_SHADOWSURFACE)
+                    vboxWddmAssignShadow(pDevExt, pSource, pDstAlloc, pSrcAlloc->SurfDesc.VidPnSourceId);
+                fRenderFromSharedDisabled = vboxWddmModeRenderFromShadowCheckOnSubmitCommand(pDevExt, NULL);
+                if(pContext->enmType != VBOXWDDM_CONTEXT_TYPE_CUSTOM_3D
+                        || pSrcAlloc->enmType !=VBOXWDDM_ALLOC_TYPE_UMD_RC_GENERIC)
+                    vboxWddmCheckUpdateFramebufferAddress(pDevExt, pSource, pSrcAlloc->SurfDesc.VidPnSourceId);
+            }
+
+            if (pContext->enmType != VBOXWDDM_CONTEXT_TYPE_CUSTOM_3D && fRenderFromSharedDisabled)
+                fBltFlags.fRealOp = 1;
+
             switch (pDstAlloc->enmType)
             {
@@ -2750,18 +2877,14 @@
                     if (pDstAlloc->bAssigned)
                     {
-                        VBOXWDDM_SOURCE *pSource = &pDevExt->aSources[pDstAlloc->SurfDesc.VidPnSourceId];
                         Assert(pSource->pPrimaryAllocation == pDstAlloc);
+
                         switch (pSrcAlloc->enmType)
                         {
                             case VBOXWDDM_ALLOC_TYPE_STD_SHADOWSURFACE:
                             {
-                                VBOXVDMAPIPE_FLAGS_DMACMD fBltFlags;
-                                fBltFlags.Value = 0;
-                                fBltFlags.b3DRelated = !!cContexts3D;
+                                fBltFlags.fVisibleRegions = !!cContexts3D;
                                 Assert(pContext->enmType == VBOXWDDM_CONTEXT_TYPE_SYSTEM);
-                                vboxWddmAssignShadow(pDevExt, pSource, pSrcAlloc, pDstAlloc->SurfDesc.VidPnSourceId);
-                                vboxWddmCheckUpdateShadowAddress(pDevExt, pSource,
-                                        pDstAlloc->SurfDesc.VidPnSourceId, pBlt->Blt.SrcAlloc.segmentIdAlloc, pBlt->Blt.SrcAlloc.offAlloc);
-                                if (vboxVhwaHlpOverlayListIsEmpty(pDevExt, pDstAlloc->SurfDesc.VidPnSourceId))
+
+                                if (!fRenderFromSharedDisabled)
                                 {
                                     RECT rect;
@@ -2787,40 +2910,30 @@
                                     }
                                 }
-                                else
-                                {
-                                    fBltFlags.b2DRelated = 1;
-                                }
-
-                                if (fBltFlags.Value)
-                                {
-                                    Status = vboxWddmSubmitBltCmd(pDevExt, pContext, pSubmitCommand->SubmissionFenceId, pBlt, fBltFlags);
-                                    bComplete = FALSE;
-                                }
+
                                 break;
                             }
                             case VBOXWDDM_ALLOC_TYPE_UMD_RC_GENERIC:
                             {
-                                Assert(pContext->enmType == VBOXWDDM_CONTEXT_TYPE_CUSTOM_3D);
-                                Assert(pSrcAlloc->fRcFlags.RenderTarget);
-                                if (pSrcAlloc->fRcFlags.RenderTarget)
+                                if(pContext->enmType == VBOXWDDM_CONTEXT_TYPE_CUSTOM_3D)
                                 {
-                                    VBOXVDMAPIPE_FLAGS_DMACMD fBltFlags;
-                                    fBltFlags.Value = 0;
-                                    fBltFlags.b3DRelated = 1;
-                                    Status = vboxWddmSubmitBltCmd(pDevExt, pContext, pSubmitCommand->SubmissionFenceId, pBlt, fBltFlags);
-                                    bComplete = FALSE;
+                                    Assert(pSrcAlloc->fRcFlags.RenderTarget);
+                                    if (pSrcAlloc->fRcFlags.RenderTarget)
+                                        fBltFlags.fVisibleRegions = 1;
                                 }
                                 break;
                             }
                             default:
+                            {
                                 AssertBreakpoint();
                                 break;
+                            }
                         }
                     }
+
                     break;
                 }
                 case VBOXWDDM_ALLOC_TYPE_STD_STAGINGSURFACE:
                 {
-                    Assert(pContext->enmType == VBOXWDDM_CONTEXT_TYPE_CUSTOM_3D);
+//                    Assert(pContext->enmType == VBOXWDDM_CONTEXT_TYPE_CUSTOM_3D);
                     Assert(pSrcAlloc->enmType == VBOXWDDM_ALLOC_TYPE_UMD_RC_GENERIC);
                     Assert(pSrcAlloc->fRcFlags.RenderTarget);
@@ -2834,13 +2947,4 @@
                     Assert(pSrcAlloc->enmType == VBOXWDDM_ALLOC_TYPE_STD_SHAREDPRIMARYSURFACE);
                     Assert(pContext->enmType == VBOXWDDM_CONTEXT_TYPE_SYSTEM);
-                    VBOXVDMAPIPE_FLAGS_DMACMD fBltFlags;
-                    fBltFlags.Value = 0;
-                    if (pDstAlloc->SurfDesc.VidPnSourceId != D3DDDI_ID_UNINITIALIZED &&
-                            !vboxVhwaHlpOverlayListIsEmpty(pDevExt, pDstAlloc->SurfDesc.VidPnSourceId))
-                    {
-                        fBltFlags.b2DRelated = 1;
-                        Status = vboxWddmSubmitBltCmd(pDevExt, pContext, pSubmitCommand->SubmissionFenceId, pBlt, fBltFlags);
-                        bComplete = FALSE;
-                    }
                     break;
                 }
@@ -2850,5 +2954,9 @@
             }
 
-            if (bComplete)
+            if (fBltFlags.Value)
+            {
+                Status = vboxWddmSubmitBltCmd(pDevExt, pContext, pSubmitCommand->SubmissionFenceId, pBlt, fBltFlags);
+            }
+            else
             {
                 Status = vboxVdmaDdiCmdFenceComplete(pDevExt, pContext->NodeOrdinal, pSubmitCommand->SubmissionFenceId, DXGK_INTERRUPT_DMA_COMPLETED);
@@ -2920,5 +3028,5 @@
                 vboxVdmaGgCmdDmaNotifyInit(&pFlipCmd->Hdr, pContext->NodeOrdinal, pSubmitCommand->SubmissionFenceId, NULL, NULL);
                 pFlipCmd->Hdr.fFlags.Value = 0;
-                pFlipCmd->Hdr.fFlags.b3DRelated = 1;
+                pFlipCmd->Hdr.fFlags.fVisibleRegions = 1;
                 pFlipCmd->Hdr.pContext = pContext;
                 pFlipCmd->Hdr.enmCmd = VBOXVDMACMD_TYPE_DMA_PRESENT_FLIP;
@@ -2945,5 +3053,5 @@
                 vboxVdmaGgCmdDmaNotifyInit(&pCFCmd->Hdr, pContext->NodeOrdinal, pSubmitCommand->SubmissionFenceId, NULL, NULL);
                 pCFCmd->Hdr.fFlags.Value = 0;
-                pCFCmd->Hdr.fFlags.b2DRelated = 1;
+                pCFCmd->Hdr.fFlags.fRealOp = 1;
                 pCFCmd->Hdr.pContext = pContext;
                 pCFCmd->Hdr.enmCmd = VBOXVDMACMD_TYPE_DMA_PRESENT_CLRFILL;
@@ -4340,6 +4448,5 @@
         {
 //            Assert(pAllocation->enmType == VBOXWDDM_ALLOC_TYPE_STD_SHAREDPRIMARYSURFACE);
-            pAllocation->offVram = (VBOXVIDEOOFFSET)pSetVidPnSourceAddress->PrimaryAddress.QuadPart;
-            pAllocation->SegmentId = pSetVidPnSourceAddress->PrimarySegment;
+            vboxWddmAllocUpdateAddress(pAllocation, pSetVidPnSourceAddress->PrimarySegment, (VBOXVIDEOOFFSET)pSetVidPnSourceAddress->PrimaryAddress.QuadPart);
             Assert (pAllocation->SegmentId);
             Assert (!pAllocation->bVisible);
@@ -4368,5 +4475,5 @@
         else
         {
-            LOGREL(("no allocation data available!!"));
+            WARN(("no allocation data available!!"));
             Status = STATUS_INVALID_PARAMETER;
         }
@@ -4374,5 +4481,5 @@
     else
     {
-        LOGREL(("invalid VidPnSourceId (%d), should be smaller than (%d)", pSetVidPnSourceAddress->VidPnSourceId, VBoxCommonFromDeviceExt(pDevExt)->cDisplays));
+        WARN(("invalid VidPnSourceId (%d), should be smaller than (%d)", pSetVidPnSourceAddress->VidPnSourceId, VBoxCommonFromDeviceExt(pDevExt)->cDisplays));
         Status = STATUS_INVALID_PARAMETER;
     }
@@ -5109,4 +5216,5 @@
     pPrivateData->BaseHdr.fFlags.Value = 0;
     uint32_t cContexts3D = ASMAtomicReadU32(&pDevExt->cContexts3D);
+    uint32_t cContexts2D = ASMAtomicReadU32(&pDevExt->cContexts2D);
 #define VBOXWDDM_DUMMY_DMABUFFER_SIZE sizeof(RECT)
 
@@ -5141,5 +5249,5 @@
                     /* issue VBOXWDDM_ALLOC_TYPE_STD_SHADOWSURFACE ONLY in case there are no 3D contexts currently
                      * otherwise we would need info about all rects being updated on primary for visible rect reporting */
-                    if (!cContexts3D)
+                    if (!cContexts3D && !cContexts2D)
                     {
                         if (pDstAlloc->enmType == VBOXWDDM_ALLOC_TYPE_STD_SHAREDPRIMARYSURFACE
@@ -5153,5 +5261,5 @@
                             {
 #ifdef VBOX_WITH_VIDEOHWACCEL
-                                if (vboxVhwaHlpOverlayListIsEmpty(pDevExt, pDstAlloc->SurfDesc.VidPnSourceId))
+//                                if (vboxVhwaHlpOverlayListIsEmpty(pDevExt, pDstAlloc->SurfDesc.VidPnSourceId))
 #endif
                                 {
@@ -5160,5 +5268,5 @@
                                     {
                                         VBOXWDDM_SOURCE *pSource = &pDevExt->aSources[pDstAlloc->SurfDesc.VidPnSourceId];
-                                        vboxWddmAssignShadow(pDevExt, pSource, pSrcAlloc, pDstAlloc->SurfDesc.VidPnSourceId);
+//                                        vboxWddmAssignShadow(pDevExt, pSource, pSrcAlloc, pDstAlloc->SurfDesc.VidPnSourceId);
                                         Assert(pPresent->SrcRect.left == pPresent->DstRect.left);
                                         Assert(pPresent->SrcRect.right == pPresent->DstRect.right);
@@ -5690,8 +5798,5 @@
                                     if (RT_SUCCESS(rc))
                                     {
-            //                            Assert(KeGetCurrentIrql() < DISPATCH_LEVEL);
-            //                            ExAcquireFastMutex(&pDevExt->ContextMutex);
                                         ASMAtomicIncU32(&pDevExt->cContexts3D);
-            //                            ExReleaseFastMutex(&pDevExt->ContextMutex);
                                         break;
                                     }
@@ -5727,4 +5832,5 @@
                             if (RT_SUCCESS(rc))
                             {
+                                ASMAtomicIncU32(&pDevExt->cContexts3D);
                                 break;
                             }
@@ -5736,4 +5842,5 @@
                     {
                         pContext->enmType = pInfo->enmType;
+                        ASMAtomicIncU32(&pDevExt->cContexts2D);
                         break;
                     }
@@ -5784,15 +5891,9 @@
     {
         case VBOXWDDM_CONTEXT_TYPE_CUSTOM_3D:
-        {
-            Assert(KeGetCurrentIrql() < DISPATCH_LEVEL);
-    //        ExAcquireFastMutex(&pDevExt->ContextMutex);
-    //        RemoveEntryList(&pContext->ListEntry);
-            uint32_t cContexts = ASMAtomicDecU32(&pDevExt->cContexts3D);
-    //        ExReleaseFastMutex(&pDevExt->ContextMutex);
-            Assert(cContexts < UINT32_MAX/2);
-            /* don't break! */
-        }
         case VBOXWDDM_CONTEXT_TYPE_CUSTOM_UHGSMI_3D:
         case VBOXWDDM_CONTEXT_TYPE_CUSTOM_UHGSMI_GL:
+        {
+            uint32_t cContexts = ASMAtomicDecU32(&pDevExt->cContexts3D);
+            Assert(cContexts < UINT32_MAX/2);
             if (pContext->u32CrConClientID)
             {
@@ -5800,7 +5901,16 @@
             }
             break;
+        }
+        case VBOXWDDM_CONTEXT_TYPE_CUSTOM_2D:
+        {
+            uint32_t cContexts = ASMAtomicDecU32(&pDevExt->cContexts2D);
+            Assert(cContexts < UINT32_MAX/2);
+            break;
+        }
         default:
             break;
     }
+
+    vboxWddmModeRenderFromShadowDisableUnregister(pDevExt, pContext);
 
     /* first terminate the swapchain, this will also ensure
Index: trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPWddm.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPWddm.h	(revision 40716)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPWddm.h	(revision 40747)
@@ -74,7 +74,7 @@
 
 #ifdef VBOXWDDM_RENDER_FROM_SHADOW
-# define VBOXWDDM_FB_ALLOCATION(_pSrc) ((_pSrc)->pShadowAllocation)
+# define VBOXWDDM_FB_ALLOCATION(_pDevExt, _pSrc) ((_pDevExt)->fRenderToShadowDisabled ? (_pSrc)->pPrimaryAllocation : (_pSrc)->pShadowAllocation)
 #else
-# define VBOXWDDM_FB_ALLOCATION(_pSrc) ((_pSrc)->pPrimaryAllocation)
+# define VBOXWDDM_FB_ALLOCATION(_pDevExt, _pSrc) ((_pSrc)->pPrimaryAllocation)
 #endif
 
