Index: trunk/src/VBox/Additions/WINNT/Graphics/Video/common/VBoxVideoLog.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Video/common/VBoxVideoLog.h	(revision 37423)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Video/common/VBoxVideoLog.h	(revision 37490)
@@ -44,4 +44,10 @@
 #endif
 
+#define _LOGMSG_EXACT(_logger, _a)                                          \
+    do                                                                      \
+    {                                                                       \
+        _logger(_a);                                                        \
+    } while (0)
+
 #define _LOGMSG(_logger, _a)                                                \
     do                                                                      \
@@ -66,4 +72,5 @@
 #define LOGF_ENTER() LOGF(("ENTER"))
 #define LOGF_LEAVE() LOGF(("LEAVE"))
+#define LOGREL_EXACT(_a) _LOGMSG_EXACT(Log, _a)
 
 #endif /*VBOXVIDEOLOG_H*/
Index: trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/common/VBoxMPVidModes.cpp
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/common/VBoxMPVidModes.cpp	(revision 37423)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/common/VBoxMPVidModes.cpp	(revision 37490)
@@ -25,4 +25,8 @@
 #include <wchar.h>
 
+#ifdef VBOX_WITH_WDDM
+# define VBOX_WITHOUT_24BPP_MODES
+#endif
+
 /* Custom video modes which are being read from registry at driver startup. */
 static VIDEO_MODE_INFORMATION g_CustomVideoModes[64] = { 0 };
@@ -36,4 +40,32 @@
 /* Number of available video modes, set by VBoxMPCmnBuildVideoModesTable. */
 static uint32_t g_NumVideoModes = 0;
+
+static BOOLEAN
+VBoxMPValidateVideoModeParamsGuest(PVBOXMP_DEVEXT pExt, uint32_t iDisplay, uint32_t xres, uint32_t yres, uint32_t bpp)
+{
+    switch (bpp)
+    {
+        case 32:
+            break;
+        case 24:
+#ifdef VBOX_WITHOUT_24BPP_MODES
+            return FALSE;
+#else
+            break;
+#endif
+        case 16:
+            break;
+        case 8:
+#ifndef VBOX_WITH_8BPP_MODES
+            return FALSE;
+#else
+            break;
+#endif
+        default:
+            WARN(("Unexpected bpp (%d)", bpp));
+            return FALSE;
+    }
+    return TRUE;
+}
 
 /* Fills given video mode BPP related fields */
@@ -161,5 +193,8 @@
             }
 
-            VBoxFillVidModeInfo(&g_CustomVideoModes[iMode], CustomXRes, CustomYRes, CustomBPP, 0, 0);
+            if (VBoxMPValidateVideoModeParamsGuest(pExt, iMode, CustomXRes, CustomYRes, CustomBPP))
+            {
+                VBoxFillVidModeInfo(&g_CustomVideoModes[iMode], CustomXRes, CustomYRes, CustomBPP, 0, 0);
+            }
         }
     }
@@ -271,4 +306,7 @@
         }
 
+        if (!VBoxMPValidateVideoModeParamsGuest(pExt, iMode, 800, 600, bitsPerPixel))
+            continue;
+
         VBoxFillVidModeInfo(&pModesTable[iMode], 800, 600, bitsPerPixel, iMode+1, 0);
 
@@ -311,4 +349,10 @@
             {
                 /* host doesn't like this mode */
+                continue;
+            }
+
+            if (!VBoxMPValidateVideoModeParamsGuest(pExt, iDisplay, resolutionMatrix[resIndex].xRes, resolutionMatrix[resIndex].yRes, bitsPerPixel))
+            {
+                /* guest does not like this mode */
                 continue;
             }
@@ -389,4 +433,10 @@
             /* host doesn't like this mode */
             break;
+        }
+
+        if (!VBoxMPValidateVideoModeParamsGuest(pExt, iDisplay, xres, yres, bpp))
+        {
+            /* guest does not like this mode */
+            continue;
         }
 
@@ -479,4 +529,7 @@
         bpp=32;
     }
+
+    if (!VBoxMPValidateVideoModeParamsGuest(pExt, iDisplay, xres, yres, bpp))
+        return FALSE;
 
     /* Check if host likes this mode */
@@ -767,18 +820,38 @@
 static VBOXWDDM_VIDEOMODES_INFO g_aVBoxVideoModeInfos[VBOX_VIDEO_MAX_SCREENS] = {0};
 
-bool VBoxWddmFillMode(VIDEO_MODE_INFORMATION *pInfo, D3DDDIFORMAT enmFormat, ULONG w, ULONG h)
+bool VBoxWddmFillMode(PVBOXMP_DEVEXT pExt, uint32_t iDisplay, VIDEO_MODE_INFORMATION *pInfo, D3DDDIFORMAT enmFormat, ULONG w, ULONG h)
 {
     switch (enmFormat)
     {
         case D3DDDIFMT_A8R8G8B8:
+            if (!VBoxMPValidateVideoModeParamsGuest(pExt, iDisplay, w, h, 32))
+            {
+                WARN(("unsupported mode info for format(%d)", enmFormat));
+                return false;
+            }
             VBoxFillVidModeInfo(pInfo, w, h, 32, 0, 0);
             return true;
         case D3DDDIFMT_R8G8B8:
+            if (!VBoxMPValidateVideoModeParamsGuest(pExt, iDisplay, w, h, 24))
+            {
+                WARN(("unsupported mode info for format(%d)", enmFormat));
+                return false;
+            }
             VBoxFillVidModeInfo(pInfo, w, h, 24, 0, 0);
             return true;
         case D3DDDIFMT_R5G6B5:
+            if (!VBoxMPValidateVideoModeParamsGuest(pExt, iDisplay, w, h, 16))
+            {
+                WARN(("unsupported mode info for format(%d)", enmFormat));
+                return false;
+            }
             VBoxFillVidModeInfo(pInfo, w, h, 16, 0, 0);
             return true;
         case D3DDDIFMT_P8:
+            if (!VBoxMPValidateVideoModeParamsGuest(pExt, iDisplay, w, h, 8))
+            {
+                WARN(("unsupported mode info for format(%d)", enmFormat));
+                return false;
+            }
             VBoxFillVidModeInfo(pInfo, w, h, 8, 0, 0);
             return true;
@@ -793,14 +866,16 @@
 
 static void
-VBoxWddmBuildResolutionTable(PVIDEO_MODE_INFORMATION pModesTable, size_t tableSize,
-                             SIZE *pResolutions, uint32_t * pcResolutions)
+VBoxWddmBuildResolutionTable(PVIDEO_MODE_INFORMATION pModesTable, size_t tableSize, int iPreferredMode,
+                             SIZE *pResolutions, uint32_t * pcResolutions, int *piPreferredResolution)
 {
     uint32_t cResolutionsArray = *pcResolutions;
     uint32_t cResolutions = 0;
 
+    *piPreferredResolution = -1;
+
     for (uint32_t i=0; i<tableSize; ++i)
     {
         PVIDEO_MODE_INFORMATION pMode = &pModesTable[i];
-        BOOLEAN bFound = FALSE;
+        int iResolution = -1;
 
         for (uint32_t j=0; j<cResolutions; ++j)
@@ -809,10 +884,10 @@
                 && pResolutions[j].cy == pMode->VisScreenHeight)
             {
-                bFound = TRUE;
+                iResolution = j;
                 break;
             }
         }
 
-        if (!bFound)
+        if (iResolution < 0)
         {
             if (cResolutions == cResolutionsArray)
@@ -822,11 +897,29 @@
             }
 
+            iResolution = cResolutions;
             pResolutions[cResolutions].cx = pMode->VisScreenWidth;
             pResolutions[cResolutions].cy = pMode->VisScreenHeight;
             ++cResolutions;
         }
+
+        Assert(iResolution >= 0);
+        if (i == iPreferredMode)
+        {
+            Assert(*piPreferredResolution == -1);
+            *piPreferredResolution = iResolution;
+        }
     }
 
     *pcResolutions = cResolutions;
+    Assert(*piPreferredResolution >= 0);
+}
+
+static void VBoxWddmBuildResolutionTableForModes(PVBOXWDDM_VIDEOMODES_INFO pModes)
+{
+    pModes->cResolutions = RT_ELEMENTS(pModes->aResolutions);
+    VBoxWddmBuildResolutionTable(pModes->aModes, pModes->cModes, pModes->iPreferredMode,
+            (SIZE*)((void*)pModes->aResolutions), &pModes->cResolutions, &pModes->iPreferredResolution);
+    Assert(pModes->aResolutions[pModes->iPreferredResolution].cx == pModes->aModes[pModes->iPreferredMode].VisScreenWidth
+            && pModes->aResolutions[pModes->iPreferredResolution].cy == pModes->aModes[pModes->iPreferredMode].VisScreenHeight);
 }
 
@@ -913,14 +1006,20 @@
                 AssertRelease(RT_ELEMENTS(pModes->aModes) > pModes->cModes); /* if not - the driver state is screwed up, @todo: better do KeBugCheckEx here */
 
-                if (pModes->aModes[pModes->iPreferredMode].BitsPerPlane != bpp)
-                {
-                    VBoxFillVidModeInfo(&pModes->aModes[pModes->cModes],
+                if (pModes->aModes[pModes->iPreferredMode].BitsPerPlane == bpp)
+                    continue;
+
+                if (!VBoxMPValidateVideoModeParamsGuest(pExt, VidPnTargetId,
+                        pModes->aModes[pModes->iPreferredMode].VisScreenWidth,
+                        pModes->aModes[pModes->iPreferredMode].VisScreenHeight,
+                        bpp))
+                    continue;
+
+                VBoxFillVidModeInfo(&pModes->aModes[pModes->cModes],
                                         pModes->aModes[pModes->iPreferredMode].VisScreenWidth,
                                         pModes->aModes[pModes->iPreferredMode].VisScreenHeight,
                                         bpp, pModes->cModes, 0);
-                    if (VBoxMPFindVideoMode(pModes->aModes, pModes->cModes, &pModes->aModes[pModes->cModes]) < 0)
-                    {
-                        ++pModes->cModes;
-                    }
+                if (VBoxMPFindVideoMode(pModes->aModes, pModes->cModes, &pModes->aModes[pModes->cModes]) < 0)
+                {
+                    ++pModes->cModes;
                 }
             }
@@ -973,8 +1072,6 @@
     }
 
-    pModes->cPrevModes = pModes->cModes;
-
     /* Build resolution table */
-    VBoxWddmBuildResolutionTable(pModes->aModes, pModes->cModes, (SIZE*)((void*)pModes->aResolutions), &pModes->cResolutions);
+    VBoxWddmBuildResolutionTableForModes(pModes);
 }
 
@@ -1023,5 +1120,5 @@
                 if (enmFormat != D3DDDIFMT_UNKNOWN)
                 {
-                    if (VBoxWddmFillMode(&ModeInfo, enmFormat, pScreenInfo->Width, pScreenInfo->Height))
+                    if (VBoxWddmFillMode(pExt, pScreenInfo->Id, &ModeInfo, enmFormat, pScreenInfo->Width, pScreenInfo->Height))
                     {
                         VBoxWddmBuildVideoModesInfo(pExt, pScreenInfo->Id, pInfo, &ModeInfo, 1);
@@ -1074,4 +1171,39 @@
 }
 
+static PVBOXWDDM_VIDEOMODES_INFO vboxWddmGetVideoModesInfoInternal(PVBOXMP_DEVEXT pExt, D3DDDI_VIDEO_PRESENT_TARGET_ID VidPnTargetId)
+{
+    Assert(VidPnTargetId < (D3DDDI_VIDEO_PRESENT_TARGET_ID)VBoxCommonFromDeviceExt(pExt)->cDisplays);
+    if (VidPnTargetId >= (D3DDDI_VIDEO_PRESENT_TARGET_ID)VBoxCommonFromDeviceExt(pExt)->cDisplays)
+    {
+        return NULL;
+    }
+
+    PVBOXWDDM_VIDEOMODES_INFO pInfo = &g_aVBoxVideoModeInfos[VidPnTargetId];
+
+    if (!pInfo->cModes)
+    {
+        VBoxWddmBuildVideoModesInfo(pExt, VidPnTargetId, pInfo, NULL, 0);
+        Assert(pInfo->cModes);
+    }
+
+    return pInfo;
+}
+
+static VOID vboxWddmAddVideoModes(PVBOXMP_DEVEXT pExt, PVBOXWDDM_VIDEOMODES_INFO pDstInfo, PVBOXWDDM_VIDEOMODES_INFO pSrcInfo)
+{
+    for (int i = 0; i < (int)pSrcInfo->cModes; ++i)
+    {
+        int foundIdx = VBoxMPFindVideoMode(pDstInfo->aModes, pDstInfo->cModes, &pSrcInfo->aModes[i]);
+        if (foundIdx >= 0)
+            continue;
+
+        Assert(0);
+        pDstInfo->aModes[pDstInfo->cModes] = pSrcInfo->aModes[i];
+        ++pDstInfo->cModes;
+    }
+
+    VBoxWddmBuildResolutionTableForModes(pDstInfo);
+}
+
 PVBOXWDDM_VIDEOMODES_INFO VBoxWddmGetAllVideoModesInfos(PVBOXMP_DEVEXT pExt)
 {
@@ -1079,5 +1211,5 @@
     for (int i = 0; i < VBoxCommonFromDeviceExt(pExt)->cDisplays; ++i)
     {
-        VBoxWddmGetVideoModesInfo(pExt, (D3DDDI_VIDEO_PRESENT_TARGET_ID)i);
+        vboxWddmGetVideoModesInfoInternal(pExt, (D3DDDI_VIDEO_PRESENT_TARGET_ID)i);
     }
 
@@ -1087,19 +1219,5 @@
 PVBOXWDDM_VIDEOMODES_INFO VBoxWddmGetVideoModesInfo(PVBOXMP_DEVEXT pExt, D3DDDI_VIDEO_PRESENT_TARGET_ID VidPnTargetId)
 {
-    Assert(VidPnTargetId < (D3DDDI_VIDEO_PRESENT_TARGET_ID)VBoxCommonFromDeviceExt(pExt)->cDisplays);
-    if (VidPnTargetId >= (D3DDDI_VIDEO_PRESENT_TARGET_ID)VBoxCommonFromDeviceExt(pExt)->cDisplays)
-    {
-        return NULL;
-    }
-
-    PVBOXWDDM_VIDEOMODES_INFO pInfo = &g_aVBoxVideoModeInfos[VidPnTargetId];
-
-    if (!pInfo->cModes)
-    {
-        VBoxWddmBuildVideoModesInfo(pExt, VidPnTargetId, pInfo, NULL, 0);
-        Assert(pInfo->cModes);
-    }
-
-    return pInfo;
+    return &VBoxWddmGetAllVideoModesInfos(pExt)[VidPnTargetId];
 }
 
Index: trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPCm.cpp
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPCm.cpp	(revision 37423)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPCm.cpp	(revision 37490)
@@ -225,4 +225,7 @@
 static void vboxVideoCmSessionDestroy(PVBOXVIDEOCM_SESSION pSession)
 {
+    /* signal event so that user-space client can figure out the context is destroyed
+     * in case the context destroyal is caused by Graphics device reset or miniport driver update */
+    KeSetEvent(pSession->pUmEvent, 0, FALSE);
     ObDereferenceObject(pSession->pUmEvent);
     Assert(IsListEmpty(&pSession->ContextList));
Index: trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPMisc.cpp
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPMisc.cpp	(revision 37423)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPMisc.cpp	(revision 37490)
@@ -1180,4 +1180,7 @@
 static DECLCALLBACK(VOID) vboxVideoAMgrAllocSubmitCompletion(PVBOXMP_DEVEXT pDevExt, PVBOXVDMADDI_CMD pCmd, PVOID pvContext)
 {
+    /* we should be called from our DPC routine */
+    Assert(KeGetCurrentIrql() == DISPATCH_LEVEL);
+
     PVBOXVDMACBUF_DR pDr = (PVBOXVDMACBUF_DR)pvContext;
     PVBOXVDMACMD pHdr = VBOXVDMACBUF_DR_TAIL(pDr, VBOXVDMACMD);
@@ -1215,4 +1218,5 @@
 }
 
+/* submits a set of chromium uhgsmi buffers to host for processing */
 NTSTATUS vboxVideoAMgrCtxAllocSubmit(PVBOXMP_DEVEXT pDevExt, PVBOXVIDEOCM_ALLOC_CONTEXT pContext, UINT cBuffers, VBOXWDDM_UHGSMI_BUFFER_UI_INFO_ESCAPE *paBuffers)
 {
@@ -1257,4 +1261,5 @@
             PVBOXVDMADDI_CMD pDdiCmd = VBOXVDMADDI_CMD_FROM_BUF_DR(pDr);
             vboxVdmaDdiCmdInit(pDdiCmd, 0, NULL, vboxVideoAMgrAllocSubmitCompletion, pDr);
+            /* mark command as submitted & invisible for the dx runtime since dx did not originate it */
             vboxVdmaDdiCmdSubmittedNotDx(pDdiCmd);
             int rc = vboxVdmaCBufDrSubmit(pDevExt, &pDevExt->u.primary.Vdma, pDr);
Index: trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPTypes.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPTypes.h	(revision 37423)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPTypes.h	(revision 37490)
@@ -258,6 +258,6 @@
     int32_t iPreferredMode;
     uint32_t cModes;
-    uint32_t cPrevModes;
     VIDEO_MODE_INFORMATION aModes[VBOXWDDM_MAX_VIDEOMODES];
+    int32_t iPreferredResolution;
     uint32_t cResolutions;
     D3DKMDT_2DREGION aResolutions[VBOXWDDM_MAX_VIDEOMODES];
Index: trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPVdma.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPVdma.h	(revision 37423)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPVdma.h	(revision 37490)
@@ -78,4 +78,7 @@
 }
 
+/* marks the command a submitted in a way that it is invisible for dx runtime,
+ * i.e. the dx runtime won't be notified about the command completion
+ * this is used to submit commands initiated by the driver, but not by the dx runtime */
 DECLINLINE(VOID) vboxVdmaDdiCmdSubmittedNotDx(PVBOXVDMADDI_CMD pCmd)
 {
Index: trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPVidPn.cpp
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPVidPn.cpp	(revision 37423)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPVidPn.cpp	(revision 37490)
@@ -395,7 +395,5 @@
         pMonitorSourceMode->ColorCoeffDynamicRanges.FourthChannel = 0;
         pMonitorSourceMode->Origin = enmOrigin;
-        Assert(!bPreferred);
-//        pMonitorSourceMode->Preference = bPreferred ? D3DKMDT_MP_PREFERRED : D3DKMDT_MP_NOTPREFERRED;
-        pMonitorSourceMode->Preference = D3DKMDT_MP_PREFERRED;
+        pMonitorSourceMode->Preference = bPreferred ? D3DKMDT_MP_PREFERRED : D3DKMDT_MP_NOTPREFERRED;
     }
 
@@ -451,7 +449,7 @@
 }
 
-NTSTATUS vboxVidPnPopulateTargetModeInfoFromLegacy(D3DKMDT_VIDPN_TARGET_MODE *pNewVidPnTargetModeInfo, D3DKMDT_2DREGION *pResolution)
-{
-    pNewVidPnTargetModeInfo->Preference = D3DKMDT_MP_NOTPREFERRED;
+NTSTATUS vboxVidPnPopulateTargetModeInfoFromLegacy(D3DKMDT_VIDPN_TARGET_MODE *pNewVidPnTargetModeInfo, D3DKMDT_2DREGION *pResolution, BOOLEAN fPreferred)
+{
+    pNewVidPnTargetModeInfo->Preference = fPreferred ? D3DKMDT_MP_PREFERRED : D3DKMDT_MP_NOTPREFERRED;
     return vboxVidPnPopulateVideoSignalInfo(&pNewVidPnTargetModeInfo->VideoSignalInfo, pResolution, 60 /* ULONG VSync */);
 }
@@ -473,5 +471,5 @@
     {
         D3DKMDT_VIDPN_TARGET_MODE dummyMode = {0};
-        Status = vboxVidPnPopulateTargetModeInfoFromLegacy(&dummyMode, &pData->pResolutions[i]);
+        Status = vboxVidPnPopulateTargetModeInfoFromLegacy(&dummyMode, &pData->pResolutions[i], FALSE /* preference does not matter for now */);
         Assert(Status == STATUS_SUCCESS);
         if (Status == STATUS_SUCCESS)
@@ -525,75 +523,145 @@
 }
 
+typedef struct VBOXVIDPNMATCHMONMODESENUM
+{
+    D3DKMDT_2DREGION *paResolutions;
+    uint32_t cResolutions;
+    BOOLEAN fMatch;
+} VBOXVIDPNMATCHMONMODESENUM, *PVBOXVIDPNMATCHMONMODESENUM;
+
+static DECLCALLBACK(BOOLEAN) vboxFidPnMatchMonitorModesEnum(D3DKMDT_HMONITORSOURCEMODESET hMonitorSMS, CONST DXGK_MONITORSOURCEMODESET_INTERFACE *pMonitorSMSIf,
+        CONST D3DKMDT_MONITOR_SOURCE_MODE *pMonitorSMI, PVOID pContext)
+{
+    PVBOXVIDPNMATCHMONMODESENUM pInfo = (PVBOXVIDPNMATCHMONMODESENUM)pContext;
+
+    Assert(pInfo->fMatch);
+
+    for (UINT i = 0; i < pInfo->cResolutions; ++i)
+    {
+        D3DKMDT_2DREGION *pResolution = &pInfo->paResolutions[i];
+        if (pMonitorSMI->VideoSignalInfo.ActiveSize.cx != pResolution->cx
+                || pMonitorSMI->VideoSignalInfo.ActiveSize.cy != pResolution->cy)
+        {
+            pInfo->fMatch = FALSE;
+            break;
+        }
+    }
+
+    pMonitorSMSIf->pfnReleaseModeInfo(hMonitorSMS, pMonitorSMI);
+
+    return pInfo->fMatch;
+}
+
+/* matches the monitor mode set for the given target id with the resolution set, and sets the pfMatch to true if they match, otherwise sets it to false */
+NTSTATUS vboxVidPnMatchMonitorModes(PVBOXMP_DEVEXT pDevExt, D3DDDI_VIDEO_PRESENT_TARGET_ID targetId,
+        D3DKMDT_2DREGION *pResolutions, uint32_t cResolutions, BOOLEAN *pfMatch)
+{
+    *pfMatch = FALSE;
+    CONST DXGK_MONITOR_INTERFACE *pMonitorInterface;
+    NTSTATUS Status = pDevExt->u.primary.DxgkInterface.DxgkCbQueryMonitorInterface(pDevExt->u.primary.DxgkInterface.DeviceHandle, DXGK_MONITOR_INTERFACE_VERSION_V1, &pMonitorInterface);
+    if (!NT_SUCCESS(Status))
+    {
+        WARN(("DxgkCbQueryMonitorInterface failed, Status (0x%x)", Status));
+        return Status;
+    }
+
+    D3DKMDT_HMONITORSOURCEMODESET hMonitorSMS;
+    CONST DXGK_MONITORSOURCEMODESET_INTERFACE *pMonitorSMSIf;
+    Status = pMonitorInterface->pfnAcquireMonitorSourceModeSet(pDevExt->u.primary.DxgkInterface.DeviceHandle,
+                                        targetId,
+                                        &hMonitorSMS,
+                                        &pMonitorSMSIf);
+    if (!NT_SUCCESS(Status))
+    {
+        WARN(("pfnAcquireMonitorSourceModeSet failed, Status (0x%x)", Status));
+        if (Status == STATUS_GRAPHICS_MONITOR_NOT_CONNECTED)
+        {
+            /* this is ok in case we replug the monitor to pick up the monitor modes properly,
+             * so pretend success  */
+            *pfMatch = TRUE;
+            Status = STATUS_SUCCESS;
+        }
+        return Status;
+    }
+
+    VBOXVIDPNMATCHMONMODESENUM Info;
+    Info.paResolutions = pResolutions;
+    Info.cResolutions = cResolutions;
+    Info.fMatch = TRUE;
+
+    Status = vboxVidPnEnumMonitorSourceModes(hMonitorSMS, pMonitorSMSIf, vboxFidPnMatchMonitorModesEnum, &Info);
+    if (NT_SUCCESS(Status))
+    {
+        *pfMatch = Info.fMatch;
+    }
+
+    NTSTATUS tmpStatus = pMonitorInterface->pfnReleaseMonitorSourceModeSet(pDevExt->u.primary.DxgkInterface.DeviceHandle, hMonitorSMS);
+    if (!NT_SUCCESS(tmpStatus))
+        WARN(("pfnReleaseMonitorSourceModeSet failed tmpStatus(0x%x)", tmpStatus));
+
+    return Status;
+}
+
 NTSTATUS vboxVidPnCheckAddMonitorModes(PVBOXMP_DEVEXT pDevExt,
         D3DDDI_VIDEO_PRESENT_TARGET_ID targetId, D3DKMDT_MONITOR_CAPABILITIES_ORIGIN enmOrigin,
-        D3DKMDT_2DREGION *pResolutions, uint32_t cResolutions)
+        D3DKMDT_2DREGION *pResolutions, uint32_t cResolutions, int iPreferred)
 {
     NTSTATUS Status;
     CONST DXGK_MONITOR_INTERFACE *pMonitorInterface;
     Status = pDevExt->u.primary.DxgkInterface.DxgkCbQueryMonitorInterface(pDevExt->u.primary.DxgkInterface.DeviceHandle, DXGK_MONITOR_INTERFACE_VERSION_V1, &pMonitorInterface);
-    Assert(Status == STATUS_SUCCESS);
-    if (Status == STATUS_SUCCESS)
-    {
-        D3DKMDT_HMONITORSOURCEMODESET hMonitorSMS;
-        CONST DXGK_MONITORSOURCEMODESET_INTERFACE *pMonitorSMSIf;
-        Status = pMonitorInterface->pfnAcquireMonitorSourceModeSet(pDevExt->u.primary.DxgkInterface.DeviceHandle,
+    if (!NT_SUCCESS(Status))
+    {
+        WARN(("DxgkCbQueryMonitorInterface failed, Status()0x%x", Status));
+        return Status;
+    }
+
+    D3DKMDT_HMONITORSOURCEMODESET hMonitorSMS;
+    CONST DXGK_MONITORSOURCEMODESET_INTERFACE *pMonitorSMSIf;
+
+    Status = pMonitorInterface->pfnAcquireMonitorSourceModeSet(pDevExt->u.primary.DxgkInterface.DeviceHandle,
                                         targetId,
                                         &hMonitorSMS,
                                         &pMonitorSMSIf);
+    if (!NT_SUCCESS(Status))
+    {
+        WARN(("DxgkCbQueryMonitorInterface failed, Status()0x%x", Status));
+        if (Status == STATUS_GRAPHICS_MONITOR_NOT_CONNECTED)
+        {
+            /* this is ok in case we replug the monitor to pick up the monitor modes properly,
+             * so pretend success  */
+            Status = STATUS_SUCCESS;
+        }
+        return Status;
+    }
+
+    for (uint32_t i = 0; i < cResolutions; ++i)
+    {
+        D3DKMDT_2DREGION *pRes = &pResolutions[i];
+
+        Status = vboxVidPnCreatePopulateMonitorSourceModeInfoFromLegacy(pDevExt,
+                hMonitorSMS,
+                pMonitorSMSIf,
+                pRes,
+                enmOrigin,
+                iPreferred == i
+                );
         Assert(Status == STATUS_SUCCESS);
-        if (Status == STATUS_SUCCESS)
-        {
-            for (uint32_t i = 0; i < cResolutions; ++i)
-            {
-                D3DKMDT_2DREGION *pRes = &pResolutions[i];
-//                VBOXVIDPNCHECKMONMODESENUM ChkInfo = {0};
-//                ChkInfo.Region = *pRes;
-//                Status = vboxVidPnEnumMonitorSourceModes(hMonitorSMS, pMonitorSMSIf,
-//                        vboxFidPnCheckMonitorModesEnum, &ChkInfo);
-//                Assert(Status == STATUS_SUCCESS);
-//                if (Status == STATUS_SUCCESS)
-//                {
-//                    if (!ChkInfo.pMonitorSMI)
-//                    {
-                        Status = vboxVidPnCreatePopulateMonitorSourceModeInfoFromLegacy(pDevExt,
-                                hMonitorSMS,
-                                pMonitorSMSIf,
-                                pRes,
-                                enmOrigin,
-                                FALSE
-                                );
-                        Assert(Status == STATUS_SUCCESS);
-                        if (Status != STATUS_SUCCESS)
-                        {
-                            LOGREL(("vboxVidPnCreatePopulateMonitorSourceModeInfoFromLegacy failed Status(0x%x)", Status));
-                            break;
-                        }
-//                    }
-//                    else
-//                    {
-//                        pMonitorSMSIf->pfnReleaseModeInfo(hMonitorSMS, ChkInfo.pMonitorSMI);
-//                    }
-//                }
-//                else
-//                {
-//                    LOGREL(("vboxVidPnEnumMonitorSourceModes failed Status(0x%x)", Status));
-//                    break;
-//                }
-            }
-            NTSTATUS tmpStatus = pMonitorInterface->pfnReleaseMonitorSourceModeSet(pDevExt->u.primary.DxgkInterface.DeviceHandle, hMonitorSMS);
-            Assert(tmpStatus == STATUS_SUCCESS);
-            if (tmpStatus != STATUS_SUCCESS)
-                LOGREL(("pfnReleaseMonitorSourceModeSet failed tmpStatus(0x%x)", tmpStatus));
-        }
-        else
-            LOGREL(("pfnAcquireMonitorSourceModeSet failed Status(0x%x)", Status));
-    }
-    else
-        LOGREL(("DxgkCbQueryMonitorInterface failed Status(0x%x)", Status));
+        if (Status != STATUS_SUCCESS)
+        {
+            LOGREL(("vboxVidPnCreatePopulateMonitorSourceModeInfoFromLegacy failed Status(0x%x)", Status));
+            break;
+        }
+    }
+
+    NTSTATUS tmpStatus = pMonitorInterface->pfnReleaseMonitorSourceModeSet(pDevExt->u.primary.DxgkInterface.DeviceHandle, hMonitorSMS);
+    if (!NT_SUCCESS(tmpStatus))
+    {
+        WARN(("pfnReleaseMonitorSourceModeSet failed tmpStatus(0x%x)", tmpStatus));
+    }
 
     return Status;
 }
 
-static NTSTATUS vboxVidPnPathAdd(D3DKMDT_HVIDPN hVidPn, const DXGK_VIDPN_INTERFACE* pVidPnInterface,
+NTSTATUS vboxVidPnPathAdd(D3DKMDT_HVIDPN hVidPn, const DXGK_VIDPN_INTERFACE* pVidPnInterface,
         const D3DDDI_VIDEO_PRESENT_SOURCE_ID VidPnSourceId, const D3DDDI_VIDEO_PRESENT_TARGET_ID VidPnTargetId)
 {
@@ -704,5 +772,4 @@
             if (NT_SUCCESS(Status))
             {
-
                 /* success */
                 continue;
@@ -766,4 +833,5 @@
         VIDEO_MODE_INFORMATION *pModeToPin,
         D3DKMDT_VIDEO_PRESENT_TARGET_MODE_ID *pModeIdToPin,
+        BOOLEAN fSetPreferred,
         BOOLEAN fDoPin
         )
@@ -798,9 +866,11 @@
         }
 
-        Status = vboxVidPnPopulateTargetModeInfoFromLegacy(pNewVidPnTargetModeInfo, pResolution);
+        BOOLEAN fIsPinMode = pModeToPin && pModeToPin->VisScreenWidth == pResolution->cx
+                && pModeToPin->VisScreenHeight == pResolution->cy;
+
+        Status = vboxVidPnPopulateTargetModeInfoFromLegacy(pNewVidPnTargetModeInfo, pResolution, fIsPinMode && fSetPreferred);
         if (NT_SUCCESS(Status))
         {
-            if (pModeToPin && pModeToPin->VisScreenWidth == pResolution->cx
-                    && pModeToPin->VisScreenHeight == pResolution->cy)
+            if (fIsPinMode)
             {
                 targetModeId = pNewVidPnTargetModeInfo->Id;
@@ -875,4 +945,5 @@
     NTSTATUS Status;
 
+#if 0
     Status = vboxVidPnPathAdd(hVidPn, pVidPnInterface, VidPnSourceId, VidPnTargetId);
     if (!NT_SUCCESS(Status))
@@ -881,7 +952,8 @@
         return Status;
     }
+#endif
 
     VIDEO_MODE_INFORMATION *pModeToPin = iModeToPin >= 0 ? &pModes[iModeToPin] : NULL;
-    Status = vboxVidPnCreatePopulateTargetModeInfoFromLegacy(hVidPn, pVidPnInterface, VidPnTargetId, pResolutions, cResolutions, pModeToPin, NULL, TRUE);
+    Status = vboxVidPnCreatePopulateTargetModeInfoFromLegacy(hVidPn, pVidPnInterface, VidPnTargetId, pResolutions, cResolutions, pModeToPin, NULL, TRUE, TRUE);
     if (!NT_SUCCESS(Status))
     {
@@ -1162,4 +1234,9 @@
     const DXGK_VIDPNTARGETMODESET_INTERFACE *pNewVidPnTargetModeSetInterface;
 
+    if (VidPnSourceId != VidPnTargetId || pCbContext->apPathInfos[VidPnTargetId].enmState != VBOXVIDPNPATHITEM_STATE_PRESENT)
+    {
+        return STATUS_SUCCESS;
+    }
+
     D3DKMDT_HVIDPNSOURCEMODESET hCurVidPnSourceModeSet;
     const DXGK_VIDPNSOURCEMODESET_INTERFACE *pCurVidPnSourceModeSetInterface;
@@ -1200,5 +1277,5 @@
         {
             Assert(hNewVidPnTargetModeSet);
-            if (pCbContext->apPathInfos[VidPnSourceId].enmState == VBOXVIDPNPATHITEM_STATE_PRESENT)
+            if (VidPnSourceId == VidPnTargetId && pCbContext->apPathInfos[VidPnTargetId].enmState == VBOXVIDPNPATHITEM_STATE_PRESENT)
             {
                 Assert(VidPnSourceId == VidPnTargetId);
@@ -1221,5 +1298,5 @@
                     if (NT_SUCCESS(Status))
                     {
-                        Status = vboxVidPnPopulateTargetModeInfoFromLegacy(pNewVidPnTargetModeInfo, pResolution);
+                        Status = vboxVidPnPopulateTargetModeInfoFromLegacy(pNewVidPnTargetModeInfo, pResolution, i == pInfo->iPreferredResolution);
                         Assert(Status == STATUS_SUCCESS);
                         if (NT_SUCCESS(Status))
@@ -1268,5 +1345,5 @@
         if (!NT_SUCCESS(Status))
         {
-            AssertFailed();
+            WARN(("\n\n!!!!!!!\n\n pfnAssignTargetModeSet failed, Status(0x%x)", Status));
             tmpStatus = pVidPnInterface->pfnReleaseTargetModeSet(hVidPn, hNewVidPnTargetModeSet);
             Assert(tmpStatus == STATUS_SUCCESS);
@@ -1286,4 +1363,9 @@
     D3DKMDT_HVIDPNSOURCEMODESET hNewVidPnSourceModeSet = NULL;
     const DXGK_VIDPNSOURCEMODESET_INTERFACE *pNewVidPnSourceModeSetInterface;
+
+    if (VidPnSourceId != VidPnTargetId || pCbContext->apPathInfos[VidPnSourceId].enmState != VBOXVIDPNPATHITEM_STATE_PRESENT)
+    {
+        return STATUS_SUCCESS;
+    }
 
     D3DKMDT_HVIDPNTARGETMODESET hCurVidPnTargetModeSet;
@@ -1325,5 +1407,5 @@
         {
             Assert(hNewVidPnSourceModeSet);
-            if (pCbContext->apPathInfos[VidPnSourceId].enmState == VBOXVIDPNPATHITEM_STATE_PRESENT)
+            if (VidPnSourceId == VidPnTargetId && pCbContext->apPathInfos[VidPnSourceId].enmState == VBOXVIDPNPATHITEM_STATE_PRESENT)
             {
                 Assert(VidPnSourceId == VidPnTargetId);
@@ -1392,5 +1474,5 @@
         if (!NT_SUCCESS(Status))
         {
-            AssertFailed();
+            WARN(("\n\n!!!!!!!\n\n pfnAssignSourceModeSet failed, Status(0x%x)", Status));
             tmpStatus = pVidPnInterface->pfnReleaseSourceModeSet(hVidPn, hNewVidPnSourceModeSet);
             Assert(tmpStatus == STATUS_SUCCESS);
@@ -2423,5 +2505,5 @@
 void vboxVidPnDumpCopyProtectoin(const char *pPrefix, const D3DKMDT_VIDPN_PRESENT_PATH_COPYPROTECTION *pCopyProtection, const char *pSuffix)
 {
-    LOGREL(("%sType(%s), TODO%s", pPrefix,
+    LOGREL_EXACT(("%sType(%s), TODO%s", pPrefix,
             vboxVidPnDumpStrCopyProtectionType(pCopyProtection->CopyProtectionType), pSuffix));
 }
@@ -2430,5 +2512,5 @@
 void vboxVidPnDumpPathTransformation(const D3DKMDT_VIDPN_PRESENT_PATH_TRANSFORMATION *pContentTransformation)
 {
-    LOGREL(("  --Transformation: Scaling(%s), ScalingSupport(%d), Rotation(%s), RotationSupport(%d)--",
+    LOGREL_EXACT(("  --Transformation: Scaling(%s), ScalingSupport(%d), Rotation(%s), RotationSupport(%d)--",
             vboxVidPnDumpStrScaling(pContentTransformation->Scaling), pContentTransformation->ScalingSupport,
             vboxVidPnDumpStrRotation(pContentTransformation->Rotation), pContentTransformation->RotationSupport));
@@ -2437,15 +2519,15 @@
 void vboxVidPnDumpRegion(const char *pPrefix, const D3DKMDT_2DREGION *pRegion, const char *pSuffix)
 {
-    LOGREL(("%s%dX%d%s", pPrefix, pRegion->cx, pRegion->cy, pSuffix));
+    LOGREL_EXACT(("%s%dX%d%s", pPrefix, pRegion->cx, pRegion->cy, pSuffix));
 }
 
 void vboxVidPnDumpRational(const char *pPrefix, const D3DDDI_RATIONAL *pRational, const char *pSuffix)
 {
-    LOGREL(("%s%d/%d=%d%s", pPrefix, pRational->Numerator, pRational->Denominator, pRational->Numerator/pRational->Denominator, pSuffix));
+    LOGREL_EXACT(("%s%d/%d=%d%s", pPrefix, pRational->Numerator, pRational->Denominator, pRational->Numerator/pRational->Denominator, pSuffix));
 }
 
 void vboxVidPnDumpRanges(const char *pPrefix, const D3DKMDT_COLOR_COEFF_DYNAMIC_RANGES *pDynamicRanges, const char *pSuffix)
 {
-    LOGREL(("%sFirstChannel(%d), SecondChannel(%d), ThirdChannel(%d), FourthChannel(%d)%s", pPrefix,
+    LOGREL_EXACT(("%sFirstChannel(%d), SecondChannel(%d), ThirdChannel(%d), FourthChannel(%d)%s", pPrefix,
             pDynamicRanges->FirstChannel,
             pDynamicRanges->SecondChannel,
@@ -2457,5 +2539,5 @@
 void vboxVidPnDumpGammaRamp(const char *pPrefix, const D3DKMDT_GAMMA_RAMP *pGammaRamp, const char *pSuffix)
 {
-    LOGREL(("%sType(%s), DataSize(%d), TODO: dump the rest%s", pPrefix,
+    LOGREL_EXACT(("%sType(%s), DataSize(%d), TODO: dump the rest%s", pPrefix,
             vboxVidPnDumpStrGammaRampType(pGammaRamp->Type), pGammaRamp->DataSize,
             pSuffix));
@@ -2464,27 +2546,27 @@
 void vboxVidPnDumpSourceMode(const char *pPrefix, const D3DKMDT_VIDPN_SOURCE_MODE* pVidPnSourceModeInfo, const char *pSuffix)
 {
-    LOGREL(("%sType(%s), ", pPrefix, vboxVidPnDumpStrSourceModeType(pVidPnSourceModeInfo->Type)));
+    LOGREL_EXACT(("%sType(%s), ", pPrefix, vboxVidPnDumpStrSourceModeType(pVidPnSourceModeInfo->Type)));
     vboxVidPnDumpRegion("surf(", &pVidPnSourceModeInfo->Format.Graphics.PrimSurfSize, "), ");
     vboxVidPnDumpRegion("vis(", &pVidPnSourceModeInfo->Format.Graphics.VisibleRegionSize, "), ");
-    LOGREL(("stride(%d), ", pVidPnSourceModeInfo->Format.Graphics.Stride));
-    LOGREL(("format(%s), ", vboxVidPnDumpStrPixFormat(pVidPnSourceModeInfo->Format.Graphics.PixelFormat)));
-    LOGREL(("clrBasis(%s), ", vboxVidPnDumpStrColorBasis(pVidPnSourceModeInfo->Format.Graphics.ColorBasis)));
-    LOGREL(("pvam(%s)%s", vboxVidPnDumpStrPvam(pVidPnSourceModeInfo->Format.Graphics.PixelValueAccessMode), pSuffix));
+    LOGREL_EXACT(("stride(%d), ", pVidPnSourceModeInfo->Format.Graphics.Stride));
+    LOGREL_EXACT(("format(%s), ", vboxVidPnDumpStrPixFormat(pVidPnSourceModeInfo->Format.Graphics.PixelFormat)));
+    LOGREL_EXACT(("clrBasis(%s), ", vboxVidPnDumpStrColorBasis(pVidPnSourceModeInfo->Format.Graphics.ColorBasis)));
+    LOGREL_EXACT(("pvam(%s)%s", vboxVidPnDumpStrPvam(pVidPnSourceModeInfo->Format.Graphics.PixelValueAccessMode), pSuffix));
 }
 
 void vboxVidPnDumpSignalInfo(const char *pPrefix, const D3DKMDT_VIDEO_SIGNAL_INFO *pVideoSignalInfo, const char *pSuffix)
 {
-    LOGREL(("%sVStd(%s), ", pPrefix, vboxVidPnDumpStrSignalStandard(pVideoSignalInfo->VideoStandard)));
+    LOGREL_EXACT(("%sVStd(%s), ", pPrefix, vboxVidPnDumpStrSignalStandard(pVideoSignalInfo->VideoStandard)));
     vboxVidPnDumpRegion("totSize(", &pVideoSignalInfo->TotalSize, "), ");
     vboxVidPnDumpRegion("activeSize(", &pVideoSignalInfo->ActiveSize, "), ");
     vboxVidPnDumpRational("VSynch(", &pVideoSignalInfo->VSyncFreq, "), ");
-    LOGREL(("PixelRate(%d), ScanLineOrdering(%s)%s", pVideoSignalInfo->PixelRate, vboxVidPnDumpStrScanLineOrdering(pVideoSignalInfo->ScanLineOrdering), pSuffix));
+    LOGREL_EXACT(("PixelRate(%d), ScanLineOrdering(%s)%s", pVideoSignalInfo->PixelRate, vboxVidPnDumpStrScanLineOrdering(pVideoSignalInfo->ScanLineOrdering), pSuffix));
 }
 
 void vboxVidPnDumpTargetMode(const char *pPrefix, const D3DKMDT_VIDPN_TARGET_MODE* CONST  pVidPnTargetModeInfo, const char *pSuffix)
 {
-    LOGREL(("%s", pPrefix));
+    LOGREL_EXACT(("%s", pPrefix));
     vboxVidPnDumpSignalInfo("VSI: ", &pVidPnTargetModeInfo->VideoSignalInfo, ", ");
-    LOGREL(("Preference(%s)%s", vboxVidPnDumpStrModePreference(pVidPnTargetModeInfo->Preference), pSuffix));
+    LOGREL_EXACT(("Preference(%s)%s", vboxVidPnDumpStrModePreference(pVidPnTargetModeInfo->Preference), pSuffix));
 }
 
@@ -2512,9 +2594,9 @@
         else if (Status == STATUS_GRAPHICS_MODE_NOT_PINNED)
         {
-            LOGREL(("Source NOT Pinned"));
+            LOGREL_EXACT(("Source NOT Pinned\n"));
         }
         else
         {
-            LOGREL(("ERROR getting piined Source Mode(0x%x)", Status));
+            LOGREL_EXACT(("ERROR getting piined Source Mode(0x%x)\n", Status));
         }
         pVidPnInterface->pfnReleaseSourceModeSet(hVidPn, hCurVidPnSourceModeSet);
@@ -2522,10 +2604,10 @@
     else
     {
-        LOGREL(("ERROR getting SourceModeSet(0x%x)", Status));
-    }
-}
-
-
-static DECLCALLBACK(BOOLEAN) vboxVidPnDumpSourceModeSetEnum(D3DKMDT_HVIDPNSOURCEMODESET hNewVidPnSourceModeSet, const DXGK_VIDPNSOURCEMODESET_INTERFACE *pVidPnSourceModeSetInterface,
+        LOGREL_EXACT(("ERROR getting SourceModeSet(0x%x)\n", Status));
+    }
+}
+
+
+DECLCALLBACK(BOOLEAN) vboxVidPnDumpSourceModeSetEnum(D3DKMDT_HVIDPNSOURCEMODESET hNewVidPnSourceModeSet, const DXGK_VIDPNSOURCEMODESET_INTERFACE *pVidPnSourceModeSetInterface,
         const D3DKMDT_VIDPN_SOURCE_MODE *pNewVidPnSourceModeInfo, PVOID pContext)
 {
@@ -2536,5 +2618,5 @@
 void vboxVidPnDumpSourceModeSet(PVBOXMP_DEVEXT pDevExt, const D3DKMDT_HVIDPN hVidPn, const DXGK_VIDPN_INTERFACE* pVidPnInterface, D3DDDI_VIDEO_PRESENT_SOURCE_ID VidPnSourceId)
 {
-    LOGREL(("  >>>+++SourceMode Set for Source(%d)+++", VidPnSourceId));
+    LOGREL_EXACT(("  >>>+++SourceMode Set for Source(%d)+++\n", VidPnSourceId));
     D3DKMDT_HVIDPNSOURCEMODESET hCurVidPnSourceModeSet;
     const DXGK_VIDPNSOURCEMODESET_INTERFACE *pCurVidPnSourceModeSetInterface;
@@ -2553,5 +2635,5 @@
         if (Status != STATUS_SUCCESS)
         {
-            LOGREL(("ERROR enumerating Source Modes(0x%x)", Status));
+            LOGREL_EXACT(("ERROR enumerating Source Modes(0x%x)\n", Status));
         }
         pVidPnInterface->pfnReleaseSourceModeSet(hVidPn, hCurVidPnSourceModeSet);
@@ -2559,8 +2641,8 @@
     else
     {
-        LOGREL(("ERROR getting SourceModeSet for Source(%d), Status(0x%x)", VidPnSourceId, Status));
-    }
-
-    LOGREL(("  <<<+++End Of SourceMode Set for Source(%d)+++", VidPnSourceId));
+        LOGREL_EXACT(("ERROR getting SourceModeSet for Source(%d), Status(0x%x)\n", VidPnSourceId, Status));
+    }
+
+    LOGREL_EXACT(("  <<<+++End Of SourceMode Set for Source(%d)+++", VidPnSourceId));
 }
 
@@ -2574,5 +2656,5 @@
 void vboxVidPnDumpTargetModeSet(PVBOXMP_DEVEXT pDevExt, const D3DKMDT_HVIDPN hVidPn, const DXGK_VIDPN_INTERFACE* pVidPnInterface, D3DDDI_VIDEO_PRESENT_TARGET_ID VidPnTargetId)
 {
-    LOGREL(("  >>>---TargetMode Set for Target(%d)---", VidPnTargetId));
+    LOGREL_EXACT(("  >>>---TargetMode Set for Target(%d)---\n", VidPnTargetId));
     D3DKMDT_HVIDPNTARGETMODESET hCurVidPnTargetModeSet;
     const DXGK_VIDPNTARGETMODESET_INTERFACE *pCurVidPnTargetModeSetInterface;
@@ -2591,5 +2673,5 @@
         if (Status != STATUS_SUCCESS)
         {
-            LOGREL(("ERROR enumerating Target Modes(0x%x)", Status));
+            LOGREL_EXACT(("ERROR enumerating Target Modes(0x%x)\n", Status));
         }
         pVidPnInterface->pfnReleaseTargetModeSet(hVidPn, hCurVidPnTargetModeSet);
@@ -2597,8 +2679,8 @@
     else
     {
-        LOGREL(("ERROR getting TargetModeSet for Target(%d), Status(0x%x)", VidPnTargetId, Status));
-    }
-
-    LOGREL(("  <<<---End Of TargetMode Set for Target(%d)---", VidPnTargetId));
+        LOGREL_EXACT(("ERROR getting TargetModeSet for Target(%d), Status(0x%x)\n", VidPnTargetId, Status));
+    }
+
+    LOGREL_EXACT(("  <<<---End Of TargetMode Set for Target(%d)---", VidPnTargetId));
 }
 
@@ -2627,9 +2709,9 @@
         else if (Status == STATUS_GRAPHICS_MODE_NOT_PINNED)
         {
-            LOGREL(("Target NOT Pinned"));
+            LOGREL_EXACT(("Target NOT Pinned\n"));
         }
         else
         {
-            LOGREL(("ERROR getting piined Target Mode(0x%x)", Status));
+            LOGREL_EXACT(("ERROR getting piined Target Mode(0x%x)\n", Status));
         }
         pVidPnInterface->pfnReleaseTargetModeSet(hVidPn, hCurVidPnTargetModeSet);
@@ -2637,5 +2719,5 @@
     else
     {
-        LOGREL(("ERROR getting TargetModeSet(0x%x)", Status));
+        LOGREL_EXACT(("ERROR getting TargetModeSet(0x%x)\n", Status));
     }
 }
@@ -2643,5 +2725,5 @@
 void vboxVidPnDumpCofuncModalityArg(const char *pPrefix, CONST DXGKARG_ENUMVIDPNCOFUNCMODALITY* CONST  pEnumCofuncModalityArg, const char *pSuffix)
 {
-    LOGREL(("%sPivotType(%s), SourceId(0x%x), TargetId(0x%x),%s", pPrefix, vboxVidPnDumpStrCFMPivotType(pEnumCofuncModalityArg->EnumPivotType),
+    LOGREL_EXACT(("%sPivotType(%s), SourceId(0x%x), TargetId(0x%x),%s", pPrefix, vboxVidPnDumpStrCFMPivotType(pEnumCofuncModalityArg->EnumPivotType),
             pEnumCofuncModalityArg->EnumPivot.VidPnSourceId, pEnumCofuncModalityArg->EnumPivot.VidPnTargetId, pSuffix));
 }
@@ -2649,6 +2731,6 @@
 void vboxVidPnDumpPath(const D3DKMDT_HVIDPN hVidPn, const DXGK_VIDPN_INTERFACE* pVidPnInterface, const D3DKMDT_VIDPN_PRESENT_PATH *pVidPnPresentPathInfo)
 {
-    LOGREL((" >>**** Start Dump VidPn Path ****>>"));
-    LOGREL(("VidPnSourceId(%d),  VidPnTargetId(%d)",
+    LOGREL_EXACT((" >>**** Start Dump VidPn Path ****>>\n"));
+    LOGREL_EXACT(("VidPnSourceId(%d),  VidPnTargetId(%d)\n",
             pVidPnPresentPathInfo->VidPnSourceId, pVidPnPresentPathInfo->VidPnTargetId));
 
@@ -2658,5 +2740,5 @@
     vboxVidPnDumpPathTransformation(&pVidPnPresentPathInfo->ContentTransformation);
 
-    LOGREL(("Importance(%s), TargetColorBasis(%s), Content(%s), ",
+    LOGREL_EXACT(("Importance(%s), TargetColorBasis(%s), Content(%s), ",
             vboxVidPnDumpStrImportance(pVidPnPresentPathInfo->ImportanceOrdinal),
             vboxVidPnDumpStrColorBasis(pVidPnPresentPathInfo->VidPnTargetColorBasis),
@@ -2668,5 +2750,5 @@
     vboxVidPnDumpGammaRamp("GammaRamp: ", &pVidPnPresentPathInfo->GammaRamp, "\n");
 
-    LOGREL((" <<**** Stop Dump VidPn Path ****<<"));
+    LOGREL_EXACT((" <<**** Stop Dump VidPn Path ****<<"));
 }
 
@@ -2689,5 +2771,5 @@
 void vboxVidPnDumpVidPn(const char * pPrefix, PVBOXMP_DEVEXT pDevExt, D3DKMDT_HVIDPN hVidPn, const DXGK_VIDPN_INTERFACE* pVidPnInterface, const char * pSuffix)
 {
-    LOGREL(("%s", pPrefix));
+    LOGREL_EXACT(("%s", pPrefix));
 
     VBOXVIDPNDUMPPATHENUM CbData;
@@ -2711,4 +2793,4 @@
     }
 
-    LOGREL(("%s", pSuffix));
-}
+    LOGREL_EXACT(("%s", pSuffix));
+}
Index: trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPVidPn.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPVidPn.h	(revision 37423)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPVidPn.h	(revision 37490)
@@ -139,5 +139,8 @@
 NTSTATUS vboxVidPnCheckAddMonitorModes(PVBOXMP_DEVEXT pDevExt,
         D3DDDI_VIDEO_PRESENT_TARGET_ID targetId, D3DKMDT_MONITOR_CAPABILITIES_ORIGIN enmOrigin,
-        D3DKMDT_2DREGION *pResolutions, uint32_t cResolutions);
+        D3DKMDT_2DREGION *pResolutions, uint32_t cResolutions, int iPreferred);
+
+NTSTATUS vboxVidPnMatchMonitorModes(PVBOXMP_DEVEXT pDevExt, D3DDDI_VIDEO_PRESENT_TARGET_ID targetId,
+        D3DKMDT_2DREGION *pResolutions, uint32_t cResolutions, BOOLEAN *pfMatch);
 
 NTSTATUS vboxVidPnCofuncModalityForPath(PVBOXVIDPNCOFUNCMODALITY pCbContext, D3DDDI_VIDEO_PRESENT_SOURCE_ID VidPnSourceId, D3DDDI_VIDEO_PRESENT_TARGET_ID VidPnTargetId);
@@ -146,5 +149,13 @@
                                     BOOLEAN fBreakOnDisabled, UINT cItems, PVBOXVIDPNPATHITEM paItems, BOOLEAN *pfDisabledFound);
 
+NTSTATUS vboxVidPnPathAdd(D3DKMDT_HVIDPN hVidPn, const DXGK_VIDPN_INTERFACE* pVidPnInterface,
+        const D3DDDI_VIDEO_PRESENT_SOURCE_ID VidPnSourceId, const D3DDDI_VIDEO_PRESENT_TARGET_ID VidPnTargetId);
+
 void vboxVidPnDumpVidPn(const char * pPrefix, PVBOXMP_DEVEXT pDevExt, D3DKMDT_HVIDPN hVidPn, const DXGK_VIDPN_INTERFACE* pVidPnInterface, const char * pSuffix);
 void vboxVidPnDumpCofuncModalityArg(const char *pPrefix, CONST DXGKARG_ENUMVIDPNCOFUNCMODALITY* CONST  pEnumCofuncModalityArg, const char *pSuffix);
+DECLCALLBACK(BOOLEAN) vboxVidPnDumpSourceModeSetEnum(D3DKMDT_HVIDPNSOURCEMODESET hNewVidPnSourceModeSet, const DXGK_VIDPNSOURCEMODESET_INTERFACE *pVidPnSourceModeSetInterface,
+        const D3DKMDT_VIDPN_SOURCE_MODE *pNewVidPnSourceModeInfo, PVOID pContext);
+DECLCALLBACK(BOOLEAN) vboxVidPnDumpTargetModeSetEnum(D3DKMDT_HVIDPNTARGETMODESET hNewVidPnTargetModeSet, const DXGK_VIDPNTARGETMODESET_INTERFACE *pVidPnTargetModeSetInterface,
+        const D3DKMDT_VIDPN_TARGET_MODE *pNewVidPnTargetModeInfo, PVOID pContext);
+
 #endif /* #ifndef ___VBoxMPVidPn_h___ */
Index: trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPWddm.cpp
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPWddm.cpp	(revision 37423)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPWddm.cpp	(revision 37490)
@@ -91,18 +91,4 @@
 }
 
-//VBOXVIDEOOFFSET vboxWddmVRAMAddressToOffset(PVBOXMP_DEVEXT pDevExt, PHYSICAL_ADDRESS phAddress)
-//{
-//    Assert(phAddress.QuadPart >= VBE_DISPI_LFB_PHYSICAL_ADDRESS);
-//    if (phAddress.QuadPart < VBE_DISPI_LFB_PHYSICAL_ADDRESS)
-//        return VBOXVIDEOOFFSET_VOID;
-//
-//    VBOXVIDEOOFFSET off = phAddress.QuadPart - VBE_DISPI_LFB_PHYSICAL_ADDRESS;
-//    Assert(off < pDevExt->u.primary.cbVRAM);
-//    if (off >= pDevExt->u.primary.cbVRAM)
-//        return VBOXVIDEOOFFSET_VOID;
-//
-//    return off;
-//}
-
 VBOXVIDEOOFFSET vboxWddmValidatePrimary(PVBOXWDDM_ALLOCATION pAllocation)
 {
@@ -330,4 +316,294 @@
         return VBOXWDDM_HGSMICMD_TYPE_CTL;
     return VBOXWDDM_HGSMICMD_TYPE_UNDEFINED;
+}
+
+static NTSTATUS vboxWddmChildStatusReportPerform(PVBOXMP_DEVEXT pDevExt, PVBOXVDMA_CHILD_STATUS pChildStatus, D3DDDI_VIDEO_PRESENT_TARGET_ID iChild)
+{
+    DXGK_CHILD_STATUS DdiChildStatus;
+    if (pChildStatus->fFlags & VBOXVDMA_CHILD_STATUS_F_DISCONNECTED)
+    {
+        /* report disconnected */
+        memset(&DdiChildStatus, 0, sizeof (DdiChildStatus));
+        DdiChildStatus.Type = StatusConnection;
+        if (iChild != D3DDDI_ID_UNINITIALIZED)
+        {
+            Assert(iChild < UINT32_MAX/2);
+            Assert(iChild < (UINT)VBoxCommonFromDeviceExt(pDevExt)->cDisplays);
+            DdiChildStatus.ChildUid = iChild;
+        }
+        else
+        {
+            Assert(pChildStatus->iChild < UINT32_MAX/2);
+            Assert(pChildStatus->iChild < (UINT)VBoxCommonFromDeviceExt(pDevExt)->cDisplays);
+            DdiChildStatus.ChildUid = pChildStatus->iChild;
+        }
+        DdiChildStatus.HotPlug.Connected = FALSE;
+        NTSTATUS Status = pDevExt->u.primary.DxgkInterface.DxgkCbIndicateChildStatus(pDevExt->u.primary.DxgkInterface.DeviceHandle, &DdiChildStatus);
+        if (!NT_SUCCESS(Status))
+        {
+            WARN(("DxgkCbIndicateChildStatus failed with Status (0x%x)", Status));
+            return Status;
+        }
+    }
+
+    if (pChildStatus->fFlags & VBOXVDMA_CHILD_STATUS_F_CONNECTED)
+    {
+        /* report disconnected */
+        memset(&DdiChildStatus, 0, sizeof (DdiChildStatus));
+        DdiChildStatus.Type = StatusConnection;
+        if (iChild != D3DDDI_ID_UNINITIALIZED)
+        {
+            Assert(iChild < UINT32_MAX/2);
+            Assert(iChild < (UINT)VBoxCommonFromDeviceExt(pDevExt)->cDisplays);
+            DdiChildStatus.ChildUid = iChild;
+        }
+        else
+        {
+            Assert(pChildStatus->iChild < UINT32_MAX/2);
+            Assert(pChildStatus->iChild < (UINT)VBoxCommonFromDeviceExt(pDevExt)->cDisplays);
+            DdiChildStatus.ChildUid = pChildStatus->iChild;
+        }
+        DdiChildStatus.HotPlug.Connected = TRUE;
+        NTSTATUS Status = pDevExt->u.primary.DxgkInterface.DxgkCbIndicateChildStatus(pDevExt->u.primary.DxgkInterface.DeviceHandle, &DdiChildStatus);
+        if (!NT_SUCCESS(Status))
+        {
+            WARN(("DxgkCbIndicateChildStatus failed with Status (0x%x)", Status));
+            return Status;
+        }
+    }
+
+    if (pChildStatus->fFlags & VBOXVDMA_CHILD_STATUS_F_ROTATED)
+    {
+        /* report disconnected */
+        memset(&DdiChildStatus, 0, sizeof (DdiChildStatus));
+        DdiChildStatus.Type = StatusRotation;
+        if (iChild != D3DDDI_ID_UNINITIALIZED)
+        {
+            Assert(iChild < UINT32_MAX/2);
+            Assert(iChild < (UINT)VBoxCommonFromDeviceExt(pDevExt)->cDisplays);
+            DdiChildStatus.ChildUid = iChild;
+        }
+        else
+        {
+            Assert(pChildStatus->iChild < UINT32_MAX/2);
+            Assert(pChildStatus->iChild < (UINT)VBoxCommonFromDeviceExt(pDevExt)->cDisplays);
+            DdiChildStatus.ChildUid = pChildStatus->iChild;
+        }
+        DdiChildStatus.Rotation.Angle = pChildStatus->u8RotationAngle;
+        NTSTATUS Status = pDevExt->u.primary.DxgkInterface.DxgkCbIndicateChildStatus(pDevExt->u.primary.DxgkInterface.DeviceHandle, &DdiChildStatus);
+        if (!NT_SUCCESS(Status))
+        {
+            WARN(("DxgkCbIndicateChildStatus failed with Status (0x%x)", Status));
+            return Status;
+        }
+    }
+
+    return STATUS_SUCCESS;
+}
+
+typedef struct VBOXWDDMCHILDSTATUSCB
+{
+    PVBOXVDMACBUF_DR pDr;
+    PKEVENT pEvent;
+} VBOXWDDMCHILDSTATUSCB, *PVBOXWDDMCHILDSTATUSCB;
+
+static DECLCALLBACK(VOID) vboxWddmChildStatusReportCompletion(PVBOXMP_DEVEXT pDevExt, PVBOXVDMADDI_CMD pCmd, PVOID pvContext)
+{
+    /* we should be called from our DPC routine */
+    Assert(KeGetCurrentIrql() == DISPATCH_LEVEL);
+
+    PVBOXWDDMCHILDSTATUSCB pCtx = (PVBOXWDDMCHILDSTATUSCB)pvContext;
+    PVBOXVDMACBUF_DR pDr = pCtx->pDr;
+    PVBOXVDMACMD pHdr = VBOXVDMACBUF_DR_TAIL(pDr, VBOXVDMACMD);
+    VBOXVDMACMD_CHILD_STATUS_IRQ *pBody = VBOXVDMACMD_BODY(pHdr, VBOXVDMACMD_CHILD_STATUS_IRQ);
+
+    for (UINT i = 0; i < pBody->cInfos; ++i)
+    {
+        PVBOXVDMA_CHILD_STATUS pInfo = &pBody->aInfos[i];
+        if (pBody->fFlags & VBOXVDMACMD_CHILD_STATUS_IRQ_F_APPLY_TO_ALL)
+        {
+            for (D3DDDI_VIDEO_PRESENT_TARGET_ID iChild = 0; iChild < (UINT)VBoxCommonFromDeviceExt(pDevExt)->cDisplays; ++iChild)
+            {
+                NTSTATUS Status = vboxWddmChildStatusReportPerform(pDevExt, pInfo, iChild);
+                if (!NT_SUCCESS(Status))
+                {
+                    WARN(("vboxWddmChildStatusReportPerform failed with Status (0x%x)", Status));
+                    break;
+                }
+            }
+        }
+        else
+        {
+            NTSTATUS Status = vboxWddmChildStatusReportPerform(pDevExt, pInfo, D3DDDI_ID_UNINITIALIZED);
+            if (!NT_SUCCESS(Status))
+            {
+                WARN(("vboxWddmChildStatusReportPerform failed with Status (0x%x)", Status));
+                break;
+            }
+        }
+    }
+
+    vboxVdmaCBufDrFree(&pDevExt->u.primary.Vdma, pDr);
+
+    if (pCtx->pEvent)
+    {
+        KeSetEvent(pCtx->pEvent, 0, FALSE);
+    }
+}
+
+static NTSTATUS vboxWddmChildStatusReportReconnected(PVBOXMP_DEVEXT pDevExt, D3DDDI_VIDEO_PRESENT_TARGET_ID idTarget)
+{
+    NTSTATUS Status = STATUS_UNSUCCESSFUL;
+    UINT cbCmd = VBOXVDMACMD_SIZE_FROMBODYSIZE(sizeof (VBOXVDMACMD_CHILD_STATUS_IRQ));
+
+    PVBOXVDMACBUF_DR pDr = vboxVdmaCBufDrCreate(&pDevExt->u.primary.Vdma, cbCmd);
+    if (pDr)
+    {
+        // vboxVdmaCBufDrCreate zero initializes the pDr
+        /* the command data follows the descriptor */
+        pDr->fFlags = VBOXVDMACBUF_FLAG_BUF_FOLLOWS_DR;
+        pDr->cbBuf = cbCmd;
+        pDr->rc = VERR_NOT_IMPLEMENTED;
+
+        PVBOXVDMACMD pHdr = VBOXVDMACBUF_DR_TAIL(pDr, VBOXVDMACMD);
+        pHdr->enmType = VBOXVDMACMD_TYPE_CHILD_STATUS_IRQ;
+        pHdr->u32CmdSpecific = 0;
+        PVBOXVDMACMD_CHILD_STATUS_IRQ pBody = VBOXVDMACMD_BODY(pHdr, VBOXVDMACMD_CHILD_STATUS_IRQ);
+        pBody->cInfos = 1;
+        if (idTarget == D3DDDI_ID_ALL)
+        {
+            pBody->fFlags |= VBOXVDMACMD_CHILD_STATUS_IRQ_F_APPLY_TO_ALL;
+        }
+        pBody->aInfos[0].iChild = idTarget;
+        pBody->aInfos[0].fFlags = VBOXVDMA_CHILD_STATUS_F_DISCONNECTED | VBOXVDMA_CHILD_STATUS_F_CONNECTED;
+
+        /* we're going to KeWaitForSingleObject */
+        Assert(KeGetCurrentIrql() < DISPATCH_LEVEL);
+
+        PVBOXVDMADDI_CMD pDdiCmd = VBOXVDMADDI_CMD_FROM_BUF_DR(pDr);
+        VBOXWDDMCHILDSTATUSCB Ctx;
+        KEVENT Event;
+        KeInitializeEvent(&Event, NotificationEvent, FALSE);
+        Ctx.pDr = pDr;
+        Ctx.pEvent = &Event;
+        vboxVdmaDdiCmdInit(pDdiCmd, 0, NULL, vboxWddmChildStatusReportCompletion, &Ctx);
+        /* mark command as submitted & invisible for the dx runtime since dx did not originate it */
+        vboxVdmaDdiCmdSubmittedNotDx(pDdiCmd);
+        int rc = vboxVdmaCBufDrSubmit(pDevExt, &pDevExt->u.primary.Vdma, pDr);
+        Assert(rc == VINF_SUCCESS);
+        if (RT_SUCCESS(rc))
+        {
+            Status = KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL);
+            Assert(Status == STATUS_SUCCESS);
+            return STATUS_SUCCESS;
+        }
+
+        Status = STATUS_UNSUCCESSFUL;
+
+        vboxVdmaCBufDrFree(&pDevExt->u.primary.Vdma, pDr);
+    }
+    else
+    {
+        Assert(0);
+        /* @todo: try flushing.. */
+        LOGREL(("vboxVdmaCBufDrCreate returned NULL"));
+        Status = STATUS_INSUFFICIENT_RESOURCES;
+    }
+
+    return Status;
+}
+
+static NTSTATUS vboxWddmChildStatusCheck(PVBOXMP_DEVEXT pDevExt, PVBOXWDDM_VIDEOMODES_INFO paInfos)
+{
+    NTSTATUS Status = STATUS_SUCCESS;
+    bool bChanged[VBOX_VIDEO_MAX_SCREENS] = {};
+    int i;
+
+    Assert(!bChanged[0]);
+    for (i = 1; i < VBoxCommonFromDeviceExt(pDevExt)->cDisplays; ++i)
+    {
+        /* @todo: check that we actually need the current source->target */
+        PVBOXWDDM_VIDEOMODES_INFO pInfo = &paInfos[i];
+        VIDEO_MODE_INFORMATION *pModeInfo = &pInfo->aModes[pInfo->iPreferredMode];
+        BOOLEAN fMatch = FALSE;
+        Status = vboxVidPnMatchMonitorModes(pDevExt, i, pInfo->aResolutions, pInfo->cResolutions, &fMatch);
+        if (!NT_SUCCESS(Status))
+        {
+            WARN(("vboxVidPnMatchMonitorModes failed Status(0x%x)", Status));
+            /* ignore the failures here, although we probably should not?? */
+            break;
+        }
+
+        bChanged[i] = !fMatch;
+
+        if (!fMatch)
+        {
+            Status = vboxWddmChildStatusReportReconnected(pDevExt, i);
+            if (!NT_SUCCESS(Status))
+            {
+                WARN(("vboxWddmChildStatusReportReconnected failed Status(0x%x)", Status));
+                /* ignore the failures here, although we probably should not?? */
+                break;
+            }
+        }
+    }
+
+    if (!NT_SUCCESS(Status))
+    {
+        WARN(("updating monitor modes failed, Status(0x%x)", Status));
+        return Status;
+    }
+
+    /* wait for the reconnected monitor data to be picked up */
+    CONST DXGK_MONITOR_INTERFACE *pMonitorInterface;
+    Status = pDevExt->u.primary.DxgkInterface.DxgkCbQueryMonitorInterface(pDevExt->u.primary.DxgkInterface.DeviceHandle, DXGK_MONITOR_INTERFACE_VERSION_V1, &pMonitorInterface);
+    if (!NT_SUCCESS(Status))
+    {
+        WARN(("DxgkCbQueryMonitorInterface failed, Status()0x%x", Status));
+        return Status;
+    }
+
+    for (i = 0; i < VBoxCommonFromDeviceExt(pDevExt)->cDisplays; ++i)
+    {
+        D3DKMDT_HMONITORSOURCEMODESET hMonitorSMS;
+        CONST DXGK_MONITORSOURCEMODESET_INTERFACE *pMonitorSMSIf;
+        if (!bChanged[i])
+            continue;
+
+        while (1)
+        {
+            Status = pMonitorInterface->pfnAcquireMonitorSourceModeSet(pDevExt->u.primary.DxgkInterface.DeviceHandle,
+                                                i,
+                                                &hMonitorSMS,
+                                                &pMonitorSMSIf);
+            if (NT_SUCCESS(Status))
+            {
+                NTSTATUS tmpStatus = pMonitorInterface->pfnReleaseMonitorSourceModeSet(pDevExt->u.primary.DxgkInterface.DeviceHandle, hMonitorSMS);
+                if (!NT_SUCCESS(tmpStatus))
+                {
+                    WARN(("pfnReleaseMonitorSourceModeSet failed tmpStatus(0x%x)", tmpStatus));
+                }
+                break;
+            }
+
+            if (Status != STATUS_GRAPHICS_MONITOR_NOT_CONNECTED)
+            {
+                WARN(("DxgkCbQueryMonitorInterface failed, Status()0x%x", Status));
+                break;
+            }
+
+            Assert(KeGetCurrentIrql() < DISPATCH_LEVEL);
+
+            LARGE_INTEGER Interval;
+            Interval.QuadPart = -(int64_t) 2 /* ms */ * 10000;
+            NTSTATUS tmpStatus = KeDelayExecutionThread(KernelMode, FALSE, &Interval);
+            if (!NT_SUCCESS(tmpStatus))
+            {
+                WARN(("KeDelayExecutionThread failed tmpStatus(0x%x)", tmpStatus));
+            }
+        }
+    }
+
+    return STATUS_SUCCESS;
 }
 
@@ -1109,5 +1385,5 @@
         ChildRelations[i].ChildCapabilities.Type.VideoOutput.MonitorOrientationAwareness = D3DKMDT_MOA_INTERRUPTIBLE; /* ?? D3DKMDT_MOA_NONE*/
         ChildRelations[i].ChildCapabilities.Type.VideoOutput.SupportsSdtvModes = FALSE;
-        ChildRelations[i].ChildCapabilities.HpdAwareness = HpdAwarenessAlwaysConnected; //HpdAwarenessInterruptible; /* ?? HpdAwarenessAlwaysConnected; */
+        ChildRelations[i].ChildCapabilities.HpdAwareness = HpdAwarenessInterruptible; /* ?? HpdAwarenessAlwaysConnected; */
         ChildRelations[i].AcpiUid =  0; /* */
         ChildRelations[i].ChildUid = i; /* should be == target id */
@@ -2796,5 +3072,5 @@
                     )
             {
-                /* we do now care about the others for now */
+                /* we do not care about the others for now */
                 Status = STATUS_SUCCESS;
                 break;
@@ -3414,5 +3690,5 @@
                     /* ensure the last char is \0*/
                     *((uint8_t*)pDbgPrint + pEscape->PrivateDriverDataSize - 1) = '\0';
-                    DbgPrint(pDbgPrint->aStringBuf);
+                    LOGREL(("%s", pDbgPrint->aStringBuf));
                 }
                 Status = STATUS_SUCCESS;
@@ -3584,92 +3860,106 @@
             (PVBOXWDDM_RECOMMENDVIDPN)pRecommendFunctionalVidPnArg->pPrivateDriverData : NULL;
     PVBOXWDDM_VIDEOMODES_INFO pInfos = VBoxWddmUpdateVideoModesInfo(pDevExt, NULL /*pVidPnInfo*/);
+    int i;
+
+    for (i = 0; i < VBoxCommonFromDeviceExt(pDevExt)->cDisplays; ++i)
+    {
+        /* @todo: check that we actually need the current source->target */
+        PVBOXWDDM_VIDEOMODES_INFO pInfo = &pInfos[i];
+        VIDEO_MODE_INFORMATION *pModeInfo = &pInfo->aModes[pInfo->iPreferredMode];
+#if 0
+        D3DKMDT_2DREGION Resolution;
+        Resolution.cx = pModeInfo->VisScreenWidth;
+        Resolution.cy = pModeInfo->VisScreenHeight;
+        Status = vboxVidPnCheckAddMonitorModes(pDevExt, i, D3DKMDT_MCO_DRIVER, &Resolution, 1, 0);
+#else
+        Status = vboxVidPnCheckAddMonitorModes(pDevExt, i, D3DKMDT_MCO_DRIVER, pInfo->aResolutions, pInfo->cResolutions, pInfo->iPreferredResolution);
+#endif
+        Assert(Status == STATUS_SUCCESS);
+        if (Status != STATUS_SUCCESS)
+        {
+            LOGREL(("vboxVidPnCheckAddMonitorModes failed Status(0x%x)", Status));
+            break;
+        }
+    }
+
     const DXGK_VIDPN_INTERFACE* pVidPnInterface = NULL;
     Status = pDevExt->u.primary.DxgkInterface.DxgkCbQueryVidPnInterface(pRecommendFunctionalVidPnArg->hRecommendedFunctionalVidPn, DXGK_VIDPN_INTERFACE_VERSION_V1, &pVidPnInterface);
-    Assert(Status == STATUS_SUCCESS);
-    if (Status == STATUS_SUCCESS)
-    {
-        VIDEO_MODE_INFORMATION *pResModes = NULL;
-        uint32_t cResModes = 0;
-        int i;
-        for (i = 0; i < VBoxCommonFromDeviceExt(pDevExt)->cDisplays; ++i)
-        {
-            /* @todo: check that we actually need the current source->target */
-            PVBOXWDDM_VIDEOMODES_INFO pInfo = &pInfos[i];
-            VIDEO_MODE_INFORMATION *pModeInfo = &pInfo->aModes[pInfo->iPreferredMode];
-#if 1
-            D3DKMDT_2DREGION Resolution;
-            Resolution.cx = pModeInfo->VisScreenWidth;
-            Resolution.cy = pModeInfo->VisScreenHeight;
-            Status = vboxVidPnCheckAddMonitorModes(pDevExt, i, D3DKMDT_MCO_DRIVER, &Resolution, 1);
-#else
-            Status = vboxVidPnCheckAddMonitorModes(pDevExt, i, D3DKMDT_MCO_DRIVER, pInfo->aResolutions, pInfo->cResolutions);
-#endif
+    if (!NT_SUCCESS(Status))
+    {
+        WARN(("DxgkCbQueryVidPnInterface failed Status(0x%x)", Status));
+        return Status;
+    }
+
+    for (i = 0; i < VBoxCommonFromDeviceExt(pDevExt)->cDisplays; ++i)
+    {
+        Status = vboxVidPnPathAdd(pRecommendFunctionalVidPnArg->hRecommendedFunctionalVidPn, pVidPnInterface, i, i);
+        if (!NT_SUCCESS(Status))
+        {
+            WARN(("vboxVidPnPathAdd failed Status(0x%x)", Status));
+            return Status;
+        }
+    }
+
+    VIDEO_MODE_INFORMATION *pResModes = NULL;
+    uint32_t cResModes = 0;
+
+    for (i = 0; i < VBoxCommonFromDeviceExt(pDevExt)->cDisplays; ++i)
+    {
+        D3DKMDT_2DREGION Resolution;
+        PVBOXWDDM_VIDEOMODES_INFO pInfo = &pInfos[i];
+        VIDEO_MODE_INFORMATION *pModeInfo = &pInfo->aModes[pInfo->iPreferredMode];
+        Resolution.cx = pModeInfo->VisScreenWidth;
+        Resolution.cy = pModeInfo->VisScreenHeight;
+        int32_t iPreferableResMode;
+        uint32_t cActualResModes;
+
+        Status = VBoxWddmGetModesForResolution(pInfo->aModes, pInfo->cModes, pInfo->iPreferredMode, &Resolution,
+                pResModes, cResModes, &cActualResModes, &iPreferableResMode);
+        Assert(Status == STATUS_SUCCESS || Status == STATUS_BUFFER_TOO_SMALL);
+        if (Status == STATUS_BUFFER_TOO_SMALL)
+        {
+            Assert(cResModes < cActualResModes);
+            if (pResModes)
+            {
+                vboxWddmMemFree(pResModes);
+            }
+            pResModes = (VIDEO_MODE_INFORMATION*)vboxWddmMemAllocZero(sizeof (*pResModes) * cActualResModes);
+            Assert(pResModes);
+            if (!pResModes)
+            {
+                Status = STATUS_NO_MEMORY;
+                break;
+            }
+            cResModes = cActualResModes;
+            Status = VBoxWddmGetModesForResolution(pInfo->aModes, pInfo->cModes, pInfo->iPreferredMode, &Resolution,
+                                pResModes, cResModes, &cActualResModes, &iPreferableResMode);
             Assert(Status == STATUS_SUCCESS);
             if (Status != STATUS_SUCCESS)
-            {
-                LOGREL(("vboxVidPnCheckAddMonitorModes failed Status(0x%x)", Status));
                 break;
-            }
-        }
-
-        for (i = 0; i < VBoxCommonFromDeviceExt(pDevExt)->cDisplays; ++i)
-        {
-            D3DKMDT_2DREGION Resolution;
-            PVBOXWDDM_VIDEOMODES_INFO pInfo = &pInfos[i];
-            VIDEO_MODE_INFORMATION *pModeInfo = &pInfo->aModes[pInfo->iPreferredMode];
-            Resolution.cx = pModeInfo->VisScreenWidth;
-            Resolution.cy = pModeInfo->VisScreenHeight;
-            int32_t iPreferableResMode;
-            uint32_t cActualResModes;
-
-            Status = VBoxWddmGetModesForResolution(pInfo->aModes, pInfo->cModes, pInfo->iPreferredMode, &Resolution,
-                    pResModes, cResModes, &cActualResModes, &iPreferableResMode);
-            Assert(Status == STATUS_SUCCESS || Status == STATUS_BUFFER_TOO_SMALL);
-            if (Status == STATUS_BUFFER_TOO_SMALL)
-            {
-                Assert(cResModes < cActualResModes);
-                if (pResModes)
-                {
-                    vboxWddmMemFree(pResModes);
-                }
-                pResModes = (VIDEO_MODE_INFORMATION*)vboxWddmMemAllocZero(sizeof (*pResModes) * cActualResModes);
-                Assert(pResModes);
-                if (!pResModes)
-                {
-                    Status = STATUS_NO_MEMORY;
-                    break;
-                }
-                cResModes = cActualResModes;
-                Status = VBoxWddmGetModesForResolution(pInfo->aModes, pInfo->cModes, pInfo->iPreferredMode, &Resolution,
-                                    pResModes, cResModes, &cActualResModes, &iPreferableResMode);
-                Assert(Status == STATUS_SUCCESS);
-                if (Status != STATUS_SUCCESS)
-                    break;
-            }
-            else if (Status != STATUS_SUCCESS)
-                break;
-
-            Assert(iPreferableResMode >= 0);
-            Assert(cActualResModes);
-
-            Status = vboxVidPnCreatePopulateVidPnPathFromLegacy(pDevExt, pRecommendFunctionalVidPnArg->hRecommendedFunctionalVidPn, pVidPnInterface,
-                            pResModes, cActualResModes, iPreferableResMode,
-                            &Resolution, 1 /* cResolutions */,
-                            i, i); /* srcId, tgtId */
-            Assert(Status == STATUS_SUCCESS);
-            if (Status != STATUS_SUCCESS)
-            {
-                LOGREL(("vboxVidPnCreatePopulateVidPnFromLegacy failed Status(0x%x)", Status));
-                break;
-            }
-        }
-
-        if(pResModes)
-            vboxWddmMemFree(pResModes);
+        }
+        else if (Status != STATUS_SUCCESS)
+            break;
+
+        Assert(iPreferableResMode >= 0);
+        Assert(cActualResModes);
+
+        Status = vboxVidPnCreatePopulateVidPnPathFromLegacy(pDevExt, pRecommendFunctionalVidPnArg->hRecommendedFunctionalVidPn, pVidPnInterface,
+                        pResModes, cActualResModes, iPreferableResMode,
+                        &Resolution, 1 /* cResolutions */,
+                        i, i); /* srcId, tgtId */
+        Assert(Status == STATUS_SUCCESS);
+        if (Status != STATUS_SUCCESS)
+        {
+            LOGREL(("vboxVidPnCreatePopulateVidPnFromLegacy failed Status(0x%x)", Status));
+            break;
+        }
+    }
+
+    if(pResModes)
+        vboxWddmMemFree(pResModes);
 
 #ifdef VBOXWDDM_DEBUG_VIDPN
         vboxVidPnDumpVidPn("\n>>>>Recommended VidPN: >>>>", pDevExt, pRecommendFunctionalVidPnArg->hRecommendedFunctionalVidPn, pVidPnInterface, "<<<<<<<<<<<<<<<<<<<<\n");
 #endif
-    }
 
     LOGF(("LEAVE, status(0x%x), context(0x%x)", Status, hAdapter));
@@ -4028,4 +4318,6 @@
     NTSTATUS Status;
     PVBOXWDDM_VIDEOMODES_INFO pInfo = VBoxWddmGetVideoModesInfo(pDevExt, pRecommendMonitorModesArg->VideoPresentTargetId);
+    PVIDEO_MODE_INFORMATION pPreferredMode = &pInfo->aModes[pInfo->iPreferredMode];
+
 
     for (uint32_t i = 0; i < pInfo->cResolutions; i++)
@@ -4041,5 +4333,6 @@
                     &pInfo->aResolutions[i],
                     D3DKMDT_MCO_DRIVER,
-                    FALSE);
+                    pPreferredMode->VisScreenWidth == pInfo->aResolutions[i].cx
+                    && pPreferredMode->VisScreenHeight == pInfo->aResolutions[i].cy);
             Assert(Status == STATUS_SUCCESS);
             if (Status == STATUS_SUCCESS)
Index: trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxDispIf.cpp
===================================================================
--- trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxDispIf.cpp	(revision 37423)
+++ trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxDispIf.cpp	(revision 37490)
@@ -265,5 +265,4 @@
 {
     PVBOXDISPIFWDDM_RESIZEOP_CONTEXT pCtx = (PVBOXDISPIFWDDM_RESIZEOP_CONTEXT)pContext;
-
     D3DKMT_INVALIDATEACTIVEVIDPN IAVidPnData = {0};
     uint32_t cbData = VBOXWDDM_RECOMMENDVIDPN_SIZE(1);
