Index: /trunk/src/VBox/Additions/WINNT/Graphics/Miniport/VBoxVideo-win.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Miniport/VBoxVideo-win.h	(revision 34129)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Miniport/VBoxVideo-win.h	(revision 34130)
@@ -313,4 +313,5 @@
 PVBOXWDDM_VIDEOMODES_INFO vboxWddmGetVideoModesInfo(PDEVICE_EXTENSION DeviceExtension, D3DDDI_VIDEO_PRESENT_TARGET_ID VidPnTargetId);
 PVBOXWDDM_VIDEOMODES_INFO vboxWddmGetAllVideoModesInfos(PDEVICE_EXTENSION DeviceExtension);
+PVBOXWDDM_VIDEOMODES_INFO vboxWddmUpdateVideoModesInfo(PDEVICE_EXTENSION DeviceExtension, PVBOXWDDM_RECOMMENDVIDPN pVidPnInfo);
 
 void vboxVideoInitCustomVideoModes(PDEVICE_EXTENSION pDevExt);
@@ -322,5 +323,5 @@
         const D3DKMDT_2DREGION *pResolution, VIDEO_MODE_INFORMATION * pModes, uint32_t cModes, uint32_t *pcModes, int32_t *piPreferrableMode);
 
-int vboxWddmVideoModeFind(const VIDEO_MODE_INFORMATION *pModes, int cModes, const VIDEO_MODE_INFORMATION *pM);
+int vboxVideoModeFind(const VIDEO_MODE_INFORMATION *pModes, int cModes, const VIDEO_MODE_INFORMATION *pM);
 int vboxWddmVideoResolutionFind(const D3DKMDT_2DREGION *pResolutions, int cResolutions, const D3DKMDT_2DREGION *pRes);
 bool vboxWddmVideoResolutionsMatch(const D3DKMDT_2DREGION *pResolutions1, const D3DKMDT_2DREGION *pResolutions2, int cResolutions);
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Miniport/VBoxVideo.cpp
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Miniport/VBoxVideo.cpp	(revision 34129)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Miniport/VBoxVideo.cpp	(revision 34130)
@@ -601,5 +601,5 @@
 #ifdef VBOX_WITH_WDDM
 
-static bool vboxVideoModesMatch(VIDEO_MODE_INFORMATION *pMode1, VIDEO_MODE_INFORMATION *pMode2)
+static bool vboxVideoModesMatch(const VIDEO_MODE_INFORMATION *pMode1, const VIDEO_MODE_INFORMATION *pMode2)
 {
     return pMode1->VisScreenHeight == pMode2->VisScreenHeight
@@ -608,5 +608,16 @@
 }
 
-static DECLINLINE(void) vboxVideoCheckModeAdd(VIDEO_MODE_INFORMATION *pModes, int *pcNumModes)
+int vboxVideoModeFind(const VIDEO_MODE_INFORMATION *pModes, int cModes, const VIDEO_MODE_INFORMATION *pM)
+{
+    for (int i = 0; i < cModes; ++i)
+    {
+        const VIDEO_MODE_INFORMATION *pMode = &pModes[i];
+        if (vboxVideoModesMatch(pMode, pM))
+            return i;
+    }
+    return -1;
+}
+
+static DECLINLINE(int) vboxVideoCheckModeAdd(VIDEO_MODE_INFORMATION *pModes, int *pcNumModes, int *piPreferred)
 {
     const int cNumModes = *pcNumModes;
@@ -614,13 +625,121 @@
     {
         if (vboxVideoModesMatch(&pModes[i], &pModes[cNumModes]))
-            return;
-    }
-    (*pcNumModes)++;
-}
-
-# define VBOXVIDEOMODE_ADDED(_aModes, _pcModes) vboxVideoCheckModeAdd(_aModes, _pcModes)
+        {
+            if (piPreferred && *piPreferred == cNumModes)
+            {
+                *piPreferred = i;
+            }
+            return i;
+        }
+    }
+    ++(*pcNumModes);
+    return cNumModes;
+}
+
+static bool vboxVideoModeAdjustCheckSupported(PDEVICE_EXTENSION pDevExt, int iDisplay, VIDEO_MODE_INFORMATION *pMode)
+{
+    /* round down to multiple of 8 if necessary */
+    if (!pDevExt->fAnyX) {
+        if ((pMode->VisScreenWidth & 0xfff8) != pMode->VisScreenWidth)
+            dprintf(("VBoxVideo: rounding down xres from %d to %d\n", pMode->VisScreenWidth, pMode->VisScreenWidth & 0xfff8));
+        pMode->VisScreenWidth &= 0xfff8;
+    }
+
+    if (vboxLikesVideoMode(iDisplay, pMode->VisScreenWidth, pMode->VisScreenHeight, pMode->BitsPerPlane))
+        return true;
+    return false;
+}
+
+static int vboxVideoModeAdd(VIDEO_MODE_INFORMATION *pModes, uint32_t cModes, uint32_t *pcNumModes, const VIDEO_MODE_INFORMATION *pMode)
+{
+    const uint32_t cNumModes = *pcNumModes;
+    for (uint32_t i = 0; i < cNumModes; ++i)
+    {
+        if (vboxVideoModesMatch(&pModes[i], pMode))
+        {
+            return (int)i;
+        }
+    }
+
+    if (cNumModes < cModes)
+    {
+        pModes[cNumModes] = *pMode;
+        pModes[cNumModes].ModeIndex = cNumModes;
+        ++(*pcNumModes);
+        return (int)cNumModes;
+    }
+
+    return -1;
+}
+
+
+# define VBOXVIDEOMODE_ADDED(_aModes, _pcModes, _piPreferred) vboxVideoCheckModeAdd(_aModes, _pcModes, _piPreferred)
 #else
-# define VBOXVIDEOMODE_ADDED(_aModes, _pcModes) do { (*(_pcModes))++; } while (0)
-#endif
+# define VBOXVIDEOMODE_ADDED(_aModes, _pcModes, _piPreferred) ((*(_pcModes))++)
+#endif
+
+static void vboxVideoInitMode(VIDEO_MODE_INFORMATION *pVideoMode, ULONG xres, ULONG yres, ULONG bpp, ULONG index, ULONG yoffset)
+{
+    /*
+     * Build mode entry.
+     */
+    memset(pVideoMode, 0, sizeof(VIDEO_MODE_INFORMATION));
+
+    pVideoMode->Length                       = sizeof(VIDEO_MODE_INFORMATION);
+    pVideoMode->ModeIndex                    = index;
+    pVideoMode->VisScreenWidth               = xres;
+    pVideoMode->VisScreenHeight              = yres - yoffset;
+    pVideoMode->ScreenStride                 = xres * ((bpp + 7) / 8);
+    pVideoMode->NumberOfPlanes               = 1;
+    pVideoMode->BitsPerPlane                 = bpp;
+    pVideoMode->Frequency                    = 60;
+    pVideoMode->XMillimeter                  = 320;
+    pVideoMode->YMillimeter                  = 240;
+    switch (bpp)
+    {
+#ifdef VBOX_WITH_8BPP_MODES
+        case 8:
+            pVideoMode->NumberRedBits        = 6;
+            pVideoMode->NumberGreenBits      = 6;
+            pVideoMode->NumberBlueBits       = 6;
+            pVideoMode->RedMask              = 0;
+            pVideoMode->GreenMask            = 0;
+            pVideoMode->BlueMask             = 0;
+            break;
+#endif
+        case 16:
+            pVideoMode->NumberRedBits        = 5;
+            pVideoMode->NumberGreenBits      = 6;
+            pVideoMode->NumberBlueBits       = 5;
+            pVideoMode->RedMask              = 0xF800;
+            pVideoMode->GreenMask            = 0x7E0;
+            pVideoMode->BlueMask             = 0x1F;
+            break;
+        case 24:
+            pVideoMode->NumberRedBits        = 8;
+            pVideoMode->NumberGreenBits      = 8;
+            pVideoMode->NumberBlueBits       = 8;
+            pVideoMode->RedMask              = 0xFF0000;
+            pVideoMode->GreenMask            = 0xFF00;
+            pVideoMode->BlueMask             = 0xFF;
+            break;
+        case 32:
+            pVideoMode->NumberRedBits        = 8;
+            pVideoMode->NumberGreenBits      = 8;
+            pVideoMode->NumberBlueBits       = 8;
+            pVideoMode->RedMask              = 0xFF0000;
+            pVideoMode->GreenMask            = 0xFF00;
+            pVideoMode->BlueMask             = 0xFF;
+            break;
+    }
+    pVideoMode->AttributeFlags               = VIDEO_MODE_GRAPHICS | VIDEO_MODE_COLOR | VIDEO_MODE_NO_OFF_SCREEN;
+#ifdef VBOX_WITH_8BPP_MODES
+    if (bpp == 8)
+        pVideoMode->AttributeFlags          |= VIDEO_MODE_PALETTE_DRIVEN | VIDEO_MODE_MANAGED_PALETTE;
+#endif
+    pVideoMode->VideoMemoryBitmapWidth       = xres;
+    pVideoMode->VideoMemoryBitmapHeight      = yres - yoffset;
+    pVideoMode->DriverSpecificAttributeFlags = 0;
+}
 
 static int vboxVideoBuildModesTable(PDEVICE_EXTENSION DeviceExtension, int iDisplay,
@@ -1178,5 +1297,5 @@
             VideoModes[cNumVideoModes].DriverSpecificAttributeFlags = 0;
 
-            VBOXVIDEOMODE_ADDED(VideoModes, &cNumVideoModes);
+            VBOXVIDEOMODE_ADDED(VideoModes, &cNumVideoModes, &iPreferredVideoMode);
 
             /* next run */
@@ -1231,5 +1350,25 @@
             iPreferredVideoMode = cNumVideoModes;
 
-            VBOXVIDEOMODE_ADDED(VideoModes, &cNumVideoModes);
+            VBOXVIDEOMODE_ADDED(VideoModes, &cNumVideoModes, &iPreferredVideoMode);
+
+            for (UINT i = 32; i >= 8; i/=2 )
+            {
+                if (cModesTable <= cNumVideoModes)
+                {
+                    rc = VERR_BUFFER_OVERFLOW;
+                    break;
+                }
+
+                if (VideoModes[iPreferredVideoMode].BitsPerPlane != i)
+                {
+                    vboxVideoInitMode(&VideoModes[cNumVideoModes],
+                            VideoModes[iPreferredVideoMode].VisScreenWidth,
+                            VideoModes[iPreferredVideoMode].VisScreenHeight,
+                            i /* bpp*/ ,
+                            cNumVideoModes /* index*/,
+                            0 /* yoffset*/);
+                    VBOXVIDEOMODE_ADDED(VideoModes, &cNumVideoModes, NULL);
+                }
+            }
         }
 
@@ -2311,9 +2450,46 @@
 AssertCompile(RT_OFFSETOF(SIZE, cy) == RT_OFFSETOF(D3DKMDT_2DREGION, cy));
 static VOID vboxWddmBuildVideoModesInfo(PDEVICE_EXTENSION DeviceExtension, D3DDDI_VIDEO_PRESENT_TARGET_ID VidPnTargetId,
-        PVBOXWDDM_VIDEOMODES_INFO pModes)
+        PVBOXWDDM_VIDEOMODES_INFO pModes, VIDEO_MODE_INFORMATION *paAddlModes, UINT cAddlModes)
 {
     pModes->cModes = RT_ELEMENTS(pModes->aModes);
     pModes->cResolutions = RT_ELEMENTS(pModes->aResolutions);
     vboxVideoBuildModesTable(DeviceExtension, VidPnTargetId, pModes->aModes, &pModes->cModes, &pModes->iPreferredMode);
+    for (UINT i = 0; i < cAddlModes; ++i)
+    {
+        if (vboxVideoModeAdjustCheckSupported(DeviceExtension, VidPnTargetId, &paAddlModes[i]))
+        {
+            int iDx = vboxVideoModeAdd(pModes->aModes, RT_ELEMENTS(pModes->aModes), &pModes->cModes, &paAddlModes[i]);
+            Assert(iDx >= 0);
+            if (iDx >= 0)
+                pModes->iPreferredMode = iDx;
+        }
+    }
+#if 0
+    if (pModes->cPrevModes == pModes->cModes)
+    {
+        Assert(pModes->cModes < RT_ELEMENTS(pModes->aModes));
+        if (pModes->cModes < RT_ELEMENTS(pModes->aModes))
+        {
+            ULONG w = pModes->aModes[0].VisScreenWidth;
+            ULONG h = pModes->aModes[0].VisScreenHeight;
+            w += 8;
+            h += 8;
+
+            if (vboxWddmFillMode(&pModes->aModes[pModes->cModes], D3DDDIFMT_A8R8G8B8, w, h))
+            {
+                pModes->aModes[pModes->cModes].ModeIndex = pModes->cModes;
+                ++pModes->cModes;
+            }
+            else
+            {
+                Assert(0);
+            }
+        }
+        VIDEO_MODE_INFORMATION TmpMode = pModes->aModes[1];
+        pModes->aModes[1] = pModes->aModes[2];
+        pModes->aModes[2] = TmpMode;
+    }
+#endif
+    pModes->cPrevModes = pModes->cModes;
     vboxVideoBuildResolutionTable(pModes->aModes, pModes->cModes, (SIZE*)((void*)pModes->aResolutions), &pModes->cResolutions);
 }
@@ -2352,15 +2528,4 @@
 }
 
-int vboxWddmVideoModeFind(const VIDEO_MODE_INFORMATION *pModes, int cModes, const VIDEO_MODE_INFORMATION *pM)
-{
-    for (int i = 0; i < cModes; ++i)
-    {
-        const VIDEO_MODE_INFORMATION *pMode = &pModes[i];
-        if (pMode->VisScreenHeight == pM->VisScreenHeight && pMode->VisScreenWidth == pM->VisScreenWidth && pMode->BitsPerPlane == pM->BitsPerPlane)
-            return i;
-    }
-    return -1;
-}
-
 int vboxWddmVideoResolutionFind(const D3DKMDT_2DREGION *pResolutions, int cResolutions, const D3DKMDT_2DREGION *pRes)
 {
@@ -2491,4 +2656,6 @@
     pInfo->VideoMemoryBitmapWidth = w;
     pInfo->VideoMemoryBitmapHeight = h;
+    pInfo->XMillimeter = 320;
+    pInfo->YMillimeter = 240;
 
     switch (enmFormat)
@@ -2500,4 +2667,5 @@
             pInfo->GreenMask = 0xFF00;
             pInfo->BlueMask = 0xFF;
+            pInfo->ScreenStride = pInfo->VisScreenWidth * pInfo->BitsPerPlane / 8;
             return true;
         case D3DDDIFMT_R8G8B8:
@@ -2507,4 +2675,5 @@
             pInfo->GreenMask = 0xFF00;
             pInfo->BlueMask = 0xFF;
+            pInfo->ScreenStride = pInfo->VisScreenWidth * pInfo->BitsPerPlane / 8;
             return true;
         case D3DDDIFMT_R5G6B5:
@@ -2514,4 +2683,5 @@
             pInfo->GreenMask = 0x7E0;
             pInfo->BlueMask = 0x1F;
+            pInfo->ScreenStride = pInfo->VisScreenWidth * pInfo->BitsPerPlane / 8;
             return true;
         case D3DDDIFMT_P8:
@@ -2521,4 +2691,5 @@
             pInfo->GreenMask = 0;
             pInfo->BlueMask = 0;
+            pInfo->ScreenStride = pInfo->VisScreenWidth * pInfo->BitsPerPlane / 8;
             return true;
         default:
@@ -2541,10 +2712,13 @@
     }
 
-    if (!g_aVBoxVideoModeInfos[VidPnTargetId].cModes)
-    {
-        vboxWddmBuildVideoModesInfo(DeviceExtension, VidPnTargetId, &g_aVBoxVideoModeInfos[VidPnTargetId]);
-    }
-
-    return &g_aVBoxVideoModeInfos[VidPnTargetId];
+    PVBOXWDDM_VIDEOMODES_INFO pInfo = &g_aVBoxVideoModeInfos[VidPnTargetId];
+
+    if (!pInfo->cModes)
+    {
+        vboxWddmBuildVideoModesInfo(DeviceExtension, VidPnTargetId, pInfo, NULL, 0);
+        Assert(pInfo->cModes);
+    }
+
+    return pInfo;
 }
 
@@ -2566,4 +2740,58 @@
         g_aVBoxVideoModeInfos[i].cModes = 0;
     }
+}
+
+PVBOXWDDM_VIDEOMODES_INFO vboxWddmUpdateVideoModesInfo(PDEVICE_EXTENSION DeviceExtension, PVBOXWDDM_RECOMMENDVIDPN pVidPnInfo)
+{
+    vboxWddmInvalidateVideoModesInfo(DeviceExtension);
+
+    if (pVidPnInfo)
+    {
+        for (UINT i = 0; i < pVidPnInfo->cScreenInfos; ++i)
+        {
+            PVBOXWDDM_RECOMMENDVIDPN_SCREEN_INFO pScreenInfo = &pVidPnInfo->aScreenInfos[i];
+            Assert(pScreenInfo->Id < (DWORD)commonFromDeviceExt(DeviceExtension)->cDisplays);
+            if (pScreenInfo->Id < (DWORD)commonFromDeviceExt(DeviceExtension)->cDisplays)
+            {
+                PVBOXWDDM_VIDEOMODES_INFO pInfo = &g_aVBoxVideoModeInfos[pScreenInfo->Id];
+                VIDEO_MODE_INFORMATION ModeInfo = {0};
+                D3DDDIFORMAT enmFormat;
+                switch (pScreenInfo->BitsPerPixel)
+                {
+                    case 32:
+                        enmFormat = D3DDDIFMT_A8R8G8B8;
+                        break;
+                    case 24:
+                        enmFormat = D3DDDIFMT_R8G8B8;
+                        break;
+                    case 16:
+                        enmFormat = D3DDDIFMT_R5G6B5;
+                        break;
+                    case 8:
+                        enmFormat = D3DDDIFMT_P8;
+                        break;
+                    default:
+                        Assert(0);
+                        enmFormat = D3DDDIFMT_UNKNOWN;
+                        break;
+                }
+                if (enmFormat != D3DDDIFMT_UNKNOWN)
+                {
+                    if (vboxWddmFillMode(&ModeInfo, enmFormat, pScreenInfo->Width, pScreenInfo->Height))
+                    {
+                        vboxWddmBuildVideoModesInfo(DeviceExtension, pScreenInfo->Id, pInfo, &ModeInfo, 1);
+                    }
+                    else
+                    {
+                        Assert(0);
+                    }
+                }
+            }
+        }
+    }
+
+    /* ensure we have all the rest populated */
+    vboxWddmGetAllVideoModesInfos(DeviceExtension);
+    return g_aVBoxVideoModeInfos;
 }
 
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Miniport/wddm/VBoxVideoMisc.cpp
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Miniport/wddm/VBoxVideoMisc.cpp	(revision 34129)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Miniport/wddm/VBoxVideoMisc.cpp	(revision 34130)
@@ -644,5 +644,5 @@
 
     RtlInitUnicodeString(&RtlStr, pName);
-    InitializeObjectAttributes(&ObjAttr, &RtlStr, OBJ_CASE_INSENSITIVE, NULL, NULL);
+    InitializeObjectAttributes(&ObjAttr, &RtlStr, OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE, NULL, NULL);
 
     return ZwOpenKey(phKey, fAccess, &ObjAttr);
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Miniport/wddm/VBoxVideoVidPn.cpp
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Miniport/wddm/VBoxVideoVidPn.cpp	(revision 34129)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Miniport/wddm/VBoxVideoVidPn.cpp	(revision 34130)
@@ -23,5 +23,5 @@
     if (Status == STATUS_SUCCESS)
     {
-        BOOLEAN bFoundPrimary = TRUE;
+        BOOLEAN bFoundPrimary = FALSE;
 
         while (1)
@@ -29,6 +29,5 @@
             if (pNewVidPnPresentPathInfo->VidPnSourceId != pNewVidPnPresentPathInfo->VidPnTargetId)
             {
-                dprintf(("unsupported source(%d)->target(%d) pare\n", pNewVidPnPresentPathInfo->VidPnSourceId, pNewVidPnPresentPathInfo->VidPnTargetId));
-//                AssertBreakpoint();
+                dprintf(("unsupported source(%d)->target(%d) pair\n", pNewVidPnPresentPathInfo->VidPnSourceId, pNewVidPnPresentPathInfo->VidPnTargetId));
                 bSupported = FALSE;
                 break;
@@ -213,5 +212,5 @@
         }
 
-//        bSupported &= bFoundPrimary;
+        bSupported &= bFoundPrimary;
 
         if (pNewVidPnPresentPathInfo)
@@ -616,5 +615,7 @@
         pMonitorSourceMode->ColorCoeffDynamicRanges.FourthChannel = 0;
         pMonitorSourceMode->Origin = enmOrigin;
-        pMonitorSourceMode->Preference = bPreferred ? D3DKMDT_MP_PREFERRED : D3DKMDT_MP_NOTPREFERRED;
+        Assert(!bPreferred);
+//        pMonitorSourceMode->Preference = bPreferred ? D3DKMDT_MP_PREFERRED : D3DKMDT_MP_NOTPREFERRED;
+        pMonitorSourceMode->Preference = D3DKMDT_MP_PREFERRED;
     }
 
@@ -645,5 +646,7 @@
             {
                 Status = pMonitorSMSIf->pfnAddMode(hMonitorSMS, pMonitorSMI);
-                Assert(Status == STATUS_SUCCESS);
+                Assert(Status == STATUS_SUCCESS/* || Status == STATUS_GRAPHICS_MODE_ALREADY_IN_MODESET*/);
+//                if (Status == STATUS_GRAPHICS_MODE_ALREADY_IN_MODESET)
+//                    Status = STATUS_SUCCESS;
                 if (Status == STATUS_SUCCESS)
                     break;
@@ -672,5 +675,6 @@
 {
     Assert(!bPreferred);
-    pNewVidPnTargetModeInfo->Preference = bPreferred ? D3DKMDT_MP_PREFERRED : D3DKMDT_MP_NOTPREFERRED;
+//    pNewVidPnTargetModeInfo->Preference = bPreferred ? D3DKMDT_MP_PREFERRED : D3DKMDT_MP_NOTPREFERRED;
+    pNewVidPnTargetModeInfo->Preference = D3DKMDT_MP_PREFERRED;
 
     return vboxVidPnPopulateVideoSignalInfo(&pNewVidPnTargetModeInfo->VideoSignalInfo, pResolution, 60 /* ULONG VSync */);
@@ -869,4 +873,31 @@
 }
 
+typedef struct VBOXVIDPNCHECKMONMODESENUM
+{
+    D3DKMDT_2DREGION Region;
+    const D3DKMDT_MONITOR_SOURCE_MODE * pMonitorSMI;
+} VBOXVIDPNCHECKMONMODESENUM, *PVBOXVIDPNCHECKMONMODESENUM;
+
+static DECLCALLBACK(BOOLEAN) vboxFidPnCheckMonitorModesEnum(D3DKMDT_HMONITORSOURCEMODESET hMonitorSMS, CONST DXGK_MONITORSOURCEMODESET_INTERFACE *pMonitorSMSIf,
+        CONST D3DKMDT_MONITOR_SOURCE_MODE *pMonitorSMI, PVOID pContext)
+{
+    PVBOXVIDPNCHECKMONMODESENUM pInfo = (PVBOXVIDPNCHECKMONMODESENUM)pContext;
+    if (pMonitorSMI->VideoSignalInfo.ActiveSize.cx == pInfo->Region.cx
+            && pMonitorSMI->VideoSignalInfo.ActiveSize.cy == pInfo->Region.cy)
+    {
+        Assert(!pInfo->pMonitorSMI);
+        if (pInfo->pMonitorSMI)
+        {
+            pMonitorSMSIf->pfnReleaseModeInfo(hMonitorSMS, pInfo->pMonitorSMI);
+        }
+        pInfo->pMonitorSMI = pMonitorSMI;
+    }
+    else
+    {
+        pMonitorSMSIf->pfnReleaseModeInfo(hMonitorSMS, pMonitorSMI);
+    }
+    return TRUE;
+}
+
 NTSTATUS vboxVidPnCheckAddMonitorModes(PDEVICE_EXTENSION pDevExt,
         D3DDDI_VIDEO_PRESENT_TARGET_ID targetId, D3DKMDT_MONITOR_CAPABILITIES_ORIGIN enmOrigin,
@@ -874,87 +905,65 @@
 {
     NTSTATUS Status;
-#if 0
-    D3DKMDT_2DREGION *pResolutionsCopy = (D3DKMDT_2DREGION*)vboxWddmMemAlloc(cResolutions * sizeof (D3DKMDT_2DREGION));
-    if (pResolutionsCopy)
-    {
-        memcpy(pResolutionsCopy, pResolutions, cResolutions * sizeof (D3DKMDT_2DREGION));
-#endif
-        CONST DXGK_MONITOR_INTERFACE *pMonitorInterface;
-        Status = pDevExt->u.primary.DxgkInterface.DxgkCbQueryMonitorInterface(pDevExt->u.primary.DxgkInterface.DeviceHandle, DXGK_MONITOR_INTERFACE_VERSION_V1, &pMonitorInterface);
+    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,
+                                        targetId,
+                                        &hMonitorSMS,
+                                        &pMonitorSMSIf);
         Assert(Status == STATUS_SUCCESS);
         if (Status == STATUS_SUCCESS)
         {
-            D3DKMDT_HMONITORSOURCEMODESET hMonitorSMS;
-            CONST DXGK_MONITORSOURCEMODESET_INTERFACE *pMonitorSMSIf;
-            Status = pMonitorInterface->pfnAcquireMonitorSourceModeSet(pDevExt->u.primary.DxgkInterface.DeviceHandle,
-                                            targetId,
-                                            &hMonitorSMS,
-                                            &pMonitorSMSIf);
-            Assert(Status == STATUS_SUCCESS);
-            if (Status == STATUS_SUCCESS)
-            {
-#if 0
-                VBOXVIDPNCHECKADDMONITORMODES EnumData = {0};
-                EnumData.cResolutions = cResolutions;
-                EnumData.pResolutions = pResolutionsCopy;
-                Status = vboxVidPnEnumMonitorSourceModes(pDevExt, hMonitorSMS, pMonitorSMSIf,
-                        vboxVidPnCheckAddMonitorModesEnum, &EnumData);
+            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)
                 {
-                    Assert(EnumData.Status == STATUS_SUCCESS);
-                    if (EnumData.Status == STATUS_SUCCESS)
+                    if (!ChkInfo.pMonitorSMI)
                     {
-#endif
-                        for (uint32_t i = 0; i < cResolutions; ++i)
+                        Status = vboxVidPnCreatePopulateMonitorSourceModeInfoFromLegacy(pDevExt,
+                                hMonitorSMS,
+                                pMonitorSMSIf,
+                                pRes,
+                                enmOrigin,
+                                FALSE//i == (uint32_t)iPreferred
+                                );
+                        Assert(Status == STATUS_SUCCESS);
+                        if (Status != STATUS_SUCCESS)
                         {
-#if 0
-                            D3DKMDT_2DREGION *pRes = &pResolutionsCopy[i];
-#else
-                            D3DKMDT_2DREGION *pRes = &pResolutions[i];
-#endif
-                            if (pRes->cx)
-                            {
-                                Status = vboxVidPnCreatePopulateMonitorSourceModeInfoFromLegacy(pDevExt,
-                                        hMonitorSMS,
-                                        pMonitorSMSIf,
-                                        pRes,
-                                        enmOrigin,
-                                        i == (uint32_t)iPreferred);
-                                Assert(Status == STATUS_SUCCESS || Status == STATUS_GRAPHICS_MODE_ALREADY_IN_MODESET);
-                                if (Status == STATUS_GRAPHICS_MODE_ALREADY_IN_MODESET)
-                                {
-                                    Status = STATUS_SUCCESS;
-                                }
-                                else if (Status != STATUS_SUCCESS)
-                                {
-                                    drprintf((__FUNCTION__": vboxVidPnCreatePopulateMonitorSourceModeInfoFromLegacy failed Status(0x%x)\n", Status));
-                                    break;
-                                }
-                            }
+                            drprintf((__FUNCTION__": vboxVidPnCreatePopulateMonitorSourceModeInfoFromLegacy failed Status(0x%x)\n", Status));
+                            break;
                         }
-#if 0
+                    }
+                    else
+                    {
+                        pMonitorSMSIf->pfnReleaseModeInfo(hMonitorSMS, ChkInfo.pMonitorSMI);
                     }
                 }
-#endif
-                NTSTATUS tmpStatus = pMonitorInterface->pfnReleaseMonitorSourceModeSet(pDevExt->u.primary.DxgkInterface.DeviceHandle, hMonitorSMS);
-                Assert(tmpStatus == STATUS_SUCCESS);
-                if (tmpStatus != STATUS_SUCCESS)
-                    drprintf((__FUNCTION__": pfnReleaseMonitorSourceModeSet failed tmpStatus(0x%x)\n", tmpStatus));
-            }
-            else
-                drprintf((__FUNCTION__": pfnAcquireMonitorSourceModeSet failed Status(0x%x)\n", Status));
+                else
+                {
+                    drprintf((__FUNCTION__": vboxVidPnEnumMonitorSourceModes failed Status(0x%x)\n", Status));
+                    break;
+                }
+            }
+            NTSTATUS tmpStatus = pMonitorInterface->pfnReleaseMonitorSourceModeSet(pDevExt->u.primary.DxgkInterface.DeviceHandle, hMonitorSMS);
+            Assert(tmpStatus == STATUS_SUCCESS);
+            if (tmpStatus != STATUS_SUCCESS)
+                drprintf((__FUNCTION__": pfnReleaseMonitorSourceModeSet failed tmpStatus(0x%x)\n", tmpStatus));
         }
         else
-            drprintf((__FUNCTION__": DxgkCbQueryMonitorInterface failed Status(0x%x)\n", Status));
-#if 0
-        vboxWddmMemFree(pResolutionsCopy);
+            drprintf((__FUNCTION__": pfnAcquireMonitorSourceModeSet failed Status(0x%x)\n", Status));
     }
     else
-    {
-        drprintf((__FUNCTION__": failed to allocate resolution copy of size (%d)\n", cResolutions));
-        Status = STATUS_NO_MEMORY;
-    }
-#endif
+        drprintf((__FUNCTION__": DxgkCbQueryMonitorInterface failed Status(0x%x)\n", Status));
 
     return Status;
@@ -1005,5 +1014,5 @@
                     Status = vboxVidPnPopulateTargetModeSetFromLegacy(pDevExt,
                                 hNewVidPnTargetModeSet, pNewVidPnTargetModeSetInterface,
-                                pResolutions, cResolutions, pPreferredMode, 0, &PreferredTrgModeId);
+                                pResolutions, cResolutions, pPreferredMode, 0 /* flags */, &PreferredTrgModeId);
                     Assert(Status == STATUS_SUCCESS);
                     if (Status == STATUS_SUCCESS)
@@ -1199,5 +1208,5 @@
             pNewVidPnSourceModeInfo->Format.Graphics.VisibleRegionSize.cy))
     {
-        if (vboxWddmVideoModeFind(pInfo->pModes, pInfo->cModes, &Mode) < 0)
+        if (vboxVideoModeFind(pInfo->pModes, pInfo->cModes, &Mode) < 0)
         {
             if (pInfo->cResultModes < pInfo->cModes)
@@ -1251,8 +1260,8 @@
 }
 
-DECLCALLBACK(BOOLEAN) vboxVidPnCofuncModalityPathEnum(D3DKMDT_HVIDPNTOPOLOGY hVidPnTopology, const DXGK_VIDPNTOPOLOGY_INTERFACE* pVidPnTopologyInterface,
-        const D3DKMDT_VIDPN_PRESENT_PATH *pNewVidPnPresentPathInfo, PVOID pContext)
-{
-    PVBOXVIDPNCOFUNCMODALITY pCbContext = (PVBOXVIDPNCOFUNCMODALITY)pContext;
+NTSTATUS vboxVidPnCofuncModalityForPath(PVBOXVIDPNCOFUNCMODALITY pCbContext,
+        D3DDDI_VIDEO_PRESENT_SOURCE_ID VidPnSourceId, D3DDDI_VIDEO_PRESENT_TARGET_ID VidPnTargetId,
+        BOOLEAN bModesAllowed)
+{
     PDEVICE_EXTENSION pDevExt = pCbContext->pDevExt;
     D3DKMDT_HVIDPN hDesiredVidPn = pCbContext->pEnumCofuncModalityArg->hConstrainingVidPn;
@@ -1260,19 +1269,6 @@
     NTSTATUS Status = STATUS_SUCCESS;
     pCbContext->Status = STATUS_SUCCESS;
-    PVBOXWDDM_VIDEOMODES_INFO pInfo = &pCbContext->pInfos[pNewVidPnPresentPathInfo->VidPnTargetId];
-    bool bConversionSupported =
-               (
-                       pNewVidPnPresentPathInfo->ContentTransformation.Scaling == D3DKMDT_VPPS_UNINITIALIZED
-                    || pNewVidPnPresentPathInfo->ContentTransformation.Scaling == D3DKMDT_VPPS_IDENTITY
-                    || pNewVidPnPresentPathInfo->ContentTransformation.Scaling == D3DKMDT_VPPS_UNPINNED
-                    || pNewVidPnPresentPathInfo->ContentTransformation.Scaling == D3DKMDT_VPPS_NOTSPECIFIED
-               )
-            && (
-                       pNewVidPnPresentPathInfo->ContentTransformation.Rotation == D3DKMDT_VPPR_UNINITIALIZED
-                    || pNewVidPnPresentPathInfo->ContentTransformation.Rotation == D3DKMDT_VPPR_IDENTITY
-                    || pNewVidPnPresentPathInfo->ContentTransformation.Rotation == D3DKMDT_VPPR_UNPINNED
-                    || pNewVidPnPresentPathInfo->ContentTransformation.Rotation == D3DKMDT_VPPR_NOTSPECIFIED
-                );
-
+    PVBOXWDDM_VIDEOMODES_INFO pInfo = &pCbContext->pInfos[VidPnTargetId];
+    BOOLEAN bConversionSupported = bModesAllowed;
 
     D3DKMDT_HVIDPNSOURCEMODESET hCurVidPnSourceModeSet;
@@ -1280,5 +1276,5 @@
 
     Status = pVidPnInterface->pfnAcquireSourceModeSet(hDesiredVidPn,
-                pNewVidPnPresentPathInfo->VidPnSourceId,
+                VidPnSourceId,
                 &hCurVidPnSourceModeSet,
                 &pCurVidPnSourceModeSetInterface);
@@ -1300,5 +1296,5 @@
         const DXGK_VIDPNTARGETMODESET_INTERFACE *pCurVidPnTargetModeSetInterface;
         Status = pVidPnInterface->pfnAcquireTargetModeSet(hDesiredVidPn,
-                            pNewVidPnPresentPathInfo->VidPnTargetId,
+                            VidPnTargetId,
                             &hCurVidPnTargetModeSet,
                             &pCurVidPnTargetModeSetInterface);
@@ -1319,9 +1315,9 @@
             bool bSrcPinned = pPinnedVidPnSourceModeInfo
                     || (pCbContext->pEnumCofuncModalityArg->EnumPivotType == D3DKMDT_EPT_VIDPNSOURCE
-                        && (pCbContext->pEnumCofuncModalityArg->EnumPivot.VidPnSourceId == pNewVidPnPresentPathInfo->VidPnSourceId
+                        && (pCbContext->pEnumCofuncModalityArg->EnumPivot.VidPnSourceId == VidPnSourceId
                             || pCbContext->pEnumCofuncModalityArg->EnumPivot.VidPnSourceId == D3DDDI_ID_ALL));
             bool bTgtPinned = pPinnedVidPnTargetModeInfo
                     || (pCbContext->pEnumCofuncModalityArg->EnumPivotType == D3DKMDT_EPT_VIDPNTARGET
-                            && (pCbContext->pEnumCofuncModalityArg->EnumPivot.VidPnTargetId == pNewVidPnPresentPathInfo->VidPnTargetId
+                            && (pCbContext->pEnumCofuncModalityArg->EnumPivot.VidPnTargetId == VidPnTargetId
                                 || pCbContext->pEnumCofuncModalityArg->EnumPivot.VidPnTargetId == D3DDDI_ID_ALL));
             if (bSrcPinned)
@@ -1329,4 +1325,15 @@
                 if (!bTgtPinned)
                 {
+#if 1
+                    uint32_t cResolutions = bConversionSupported ? pInfo->cResolutions : 0;
+                    Status = vboxVidPnCreatePopulateTargetModeSetFromLegacy(pDevExt, hDesiredVidPn, pVidPnInterface,
+                                            VidPnTargetId,
+                                            pInfo->aResolutions,
+                                            cResolutions,
+                                            NULL,
+                                            0, /* flags */
+                                            NULL);
+                    Assert(Status == STATUS_SUCCESS);
+#else
                     /* adjust target mode set relative to source mode set */
                     /* 1. get list of resolutions for source and for target
@@ -1394,9 +1401,9 @@
                                                     {
                                                         Status = vboxVidPnCreatePopulateTargetModeSetFromLegacy(pDevExt, hDesiredVidPn, pVidPnInterface,
-                                                                                pNewVidPnPresentPathInfo->VidPnTargetId,
+                                                                                VidPnTargetId,
                                                                                 pSrcResolutions,
                                                                                 cSrcResolutions,
                                                                                 NULL,
-                                                                                0,
+                                                                                0, /* flags */
                                                                                 NULL);
                                                         Assert(Status == STATUS_SUCCESS);
@@ -1431,8 +1438,16 @@
                         }
                     }
+#endif
                 }
             }
             else if (bTgtPinned)
             {
+#if 1
+                uint32_t cModes = bConversionSupported ? pInfo->cModes : 0;
+                Status = Status = vboxVidPnCreatePopulateSourceModeSetFromLegacy(pDevExt, hDesiredVidPn, pVidPnInterface,
+                        VidPnSourceId,
+                        pInfo->aModes, cModes, -1, NULL);
+                Assert(Status == STATUS_SUCCESS);
+#else
                 /* adjust source mode set relative to target mode set */
                 /* 1. get list of modes for target resolutions
@@ -1504,5 +1519,5 @@
                                                 {
                                                     Status = Status = vboxVidPnCreatePopulateSourceModeSetFromLegacy(pDevExt, hDesiredVidPn, pVidPnInterface,
-                                                            pNewVidPnPresentPathInfo->VidPnSourceId,
+                                                            VidPnSourceId,
                                                             pTgtModes, Info.Base.cResultModes, -1, NULL);
                                                     Assert(Status == STATUS_SUCCESS);
@@ -1537,7 +1552,25 @@
                     }
                 }
+#endif
             }
             else
             {
+#if 1
+                uint32_t cModes = bConversionSupported ? pInfo->cModes : 0;
+                Status = Status = vboxVidPnCreatePopulateSourceModeSetFromLegacy(pDevExt, hDesiredVidPn, pVidPnInterface,
+                        VidPnSourceId,
+                        pInfo->aModes, cModes, -1, NULL);
+                Assert(Status == STATUS_SUCCESS);
+
+                uint32_t cResolutions = bConversionSupported ? pInfo->cResolutions : 0;
+                Status = vboxVidPnCreatePopulateTargetModeSetFromLegacy(pDevExt, hDesiredVidPn, pVidPnInterface,
+                                        VidPnTargetId,
+                                        pInfo->aResolutions,
+                                        cResolutions,
+                                        NULL,
+                                        0,
+                                        NULL);
+                Assert(Status == STATUS_SUCCESS);
+#else
                 /* neither Source nor Target are pinned */
                 /* 1. get list of target resolutions
@@ -1601,5 +1634,5 @@
                     {
                         Status = Status = vboxVidPnCreatePopulateSourceModeSetFromLegacy(pDevExt, hDesiredVidPn, pVidPnInterface,
-                                pNewVidPnPresentPathInfo->VidPnSourceId,
+                                VidPnSourceId,
                                 pInfo->aModes, cModes, -1, NULL);
                         Assert(Status == STATUS_SUCCESS);
@@ -1667,9 +1700,9 @@
                             {
                                 Status = vboxVidPnCreatePopulateTargetModeSetFromLegacy(pDevExt, hDesiredVidPn, pVidPnInterface,
-                                                        pNewVidPnPresentPathInfo->VidPnTargetId,
+                                                        VidPnTargetId,
                                                         pInfo->aResolutions,
                                                         cResolutions,
                                                         NULL,
-                                                        0,
+                                                        0, /* flags */
                                                         NULL);
                                 Assert(Status == STATUS_SUCCESS);
@@ -1678,8 +1711,11 @@
                     }
                 }
+#endif
             }
 
             if (pPinnedVidPnTargetModeInfo)
+            {
                 pCurVidPnTargetModeSetInterface->pfnReleaseModeInfo(hCurVidPnTargetModeSet, pPinnedVidPnTargetModeInfo);
+            }
             pVidPnInterface->pfnReleaseTargetModeSet(hDesiredVidPn, hCurVidPnTargetModeSet);
         }
@@ -1688,9 +1724,48 @@
 
         if (pPinnedVidPnSourceModeInfo)
+        {
+            if (Status == STATUS_SUCCESS)
+            {
+                D3DDDI_MULTISAMPLINGMETHOD Msm;
+                Msm.NumSamples = 1;
+                Msm.NumQualityLevels = 0;
+
+                Status = pVidPnInterface->pfnAssignMultisamplingMethodSet(hDesiredVidPn, VidPnSourceId, 1, &Msm);
+                Assert(Status == STATUS_SUCCESS);
+            }
+
             pCurVidPnSourceModeSetInterface->pfnReleaseModeInfo(hCurVidPnSourceModeSet, pPinnedVidPnSourceModeInfo);
+        }
         pVidPnInterface->pfnReleaseSourceModeSet(hDesiredVidPn, hCurVidPnSourceModeSet);
     }
     else
         drprintf((__FUNCTION__": pfnAcquireSourceModeSet failed Status(0x%x)\n", Status));
+
+    Assert(Status == STATUS_SUCCESS);
+    return Status;
+
+}
+
+DECLCALLBACK(BOOLEAN) vboxVidPnCofuncModalityPathEnum(D3DKMDT_HVIDPNTOPOLOGY hVidPnTopology, const DXGK_VIDPNTOPOLOGY_INTERFACE* pVidPnTopologyInterface,
+        const D3DKMDT_VIDPN_PRESENT_PATH *pNewVidPnPresentPathInfo, PVOID pContext)
+{
+    PVBOXVIDPNCOFUNCMODALITY pCbContext = (PVBOXVIDPNCOFUNCMODALITY)pContext;
+    bool bConversionSupported =
+               (
+                       pNewVidPnPresentPathInfo->ContentTransformation.Scaling == D3DKMDT_VPPS_UNINITIALIZED
+                    || pNewVidPnPresentPathInfo->ContentTransformation.Scaling == D3DKMDT_VPPS_IDENTITY
+                    || pNewVidPnPresentPathInfo->ContentTransformation.Scaling == D3DKMDT_VPPS_UNPINNED
+                    || pNewVidPnPresentPathInfo->ContentTransformation.Scaling == D3DKMDT_VPPS_NOTSPECIFIED
+               )
+            && (
+                       pNewVidPnPresentPathInfo->ContentTransformation.Rotation == D3DKMDT_VPPR_UNINITIALIZED
+                    || pNewVidPnPresentPathInfo->ContentTransformation.Rotation == D3DKMDT_VPPR_IDENTITY
+                    || pNewVidPnPresentPathInfo->ContentTransformation.Rotation == D3DKMDT_VPPR_UNPINNED
+                    || pNewVidPnPresentPathInfo->ContentTransformation.Rotation == D3DKMDT_VPPR_NOTSPECIFIED
+                )
+            && (pNewVidPnPresentPathInfo->VidPnSourceId == pNewVidPnPresentPathInfo->VidPnTargetId);
+
+    NTSTATUS Status = vboxVidPnCofuncModalityForPath(pCbContext,
+            pNewVidPnPresentPathInfo->VidPnSourceId, pNewVidPnPresentPathInfo->VidPnTargetId, bConversionSupported);
 
     pVidPnTopologyInterface->pfnReleasePathInfo(hVidPnTopology, pNewVidPnPresentPathInfo);
@@ -1701,5 +1776,34 @@
 }
 
-NTSTATUS vboxVidPnEnumMonitorSourceModes(PDEVICE_EXTENSION pDevExt, D3DKMDT_HMONITORSOURCEMODESET hMonitorSMS, CONST DXGK_MONITORSOURCEMODESET_INTERFACE *pMonitorSMSIf,
+DECLCALLBACK(BOOLEAN) vboxVidPnCofuncModalityCheckPathsSupportedEnum(D3DKMDT_HVIDPNTOPOLOGY hVidPnTopology, const DXGK_VIDPNTOPOLOGY_INTERFACE* pVidPnTopologyInterface,
+        const D3DKMDT_VIDPN_PRESENT_PATH *pNewVidPnPresentPathInfo, PVOID pContext)
+{
+    PVBOXVIDPNCOFUNCMODALITY pCbContext = (PVBOXVIDPNCOFUNCMODALITY)pContext;
+    bool bConversionSupported =
+               (
+                       pNewVidPnPresentPathInfo->ContentTransformation.Scaling == D3DKMDT_VPPS_UNINITIALIZED
+                    || pNewVidPnPresentPathInfo->ContentTransformation.Scaling == D3DKMDT_VPPS_IDENTITY
+                    || pNewVidPnPresentPathInfo->ContentTransformation.Scaling == D3DKMDT_VPPS_UNPINNED
+                    || pNewVidPnPresentPathInfo->ContentTransformation.Scaling == D3DKMDT_VPPS_NOTSPECIFIED
+               )
+            && (
+                       pNewVidPnPresentPathInfo->ContentTransformation.Rotation == D3DKMDT_VPPR_UNINITIALIZED
+                    || pNewVidPnPresentPathInfo->ContentTransformation.Rotation == D3DKMDT_VPPR_IDENTITY
+                    || pNewVidPnPresentPathInfo->ContentTransformation.Rotation == D3DKMDT_VPPR_UNPINNED
+                    || pNewVidPnPresentPathInfo->ContentTransformation.Rotation == D3DKMDT_VPPR_NOTSPECIFIED
+                )
+            && (pNewVidPnPresentPathInfo->VidPnSourceId == pNewVidPnPresentPathInfo->VidPnTargetId);
+
+    NTSTATUS Status = vboxVidPnCofuncModalityForPath(pCbContext,
+            pNewVidPnPresentPathInfo->VidPnSourceId, pNewVidPnPresentPathInfo->VidPnTargetId, bConversionSupported);
+
+    pVidPnTopologyInterface->pfnReleasePathInfo(hVidPnTopology, pNewVidPnPresentPathInfo);
+
+    pCbContext->Status = Status;
+    Assert(Status == STATUS_SUCCESS);
+    return Status == STATUS_SUCCESS;
+}
+
+NTSTATUS vboxVidPnEnumMonitorSourceModes(D3DKMDT_HMONITORSOURCEMODESET hMonitorSMS, CONST DXGK_MONITORSOURCEMODESET_INTERFACE *pMonitorSMSIf,
         PFNVBOXVIDPNENUMMONITORSOURCEMODES pfnCallback, PVOID pContext)
 {
@@ -1714,5 +1818,5 @@
             CONST D3DKMDT_MONITOR_SOURCE_MODE *pNextMonitorSMI;
             Status = pMonitorSMSIf->pfnAcquireNextModeInfo(hMonitorSMS, pMonitorSMI, &pNextMonitorSMI);
-            if (!pfnCallback(pDevExt, hMonitorSMS, pMonitorSMSIf, pMonitorSMI, pContext))
+            if (!pfnCallback(hMonitorSMS, pMonitorSMSIf, pMonitorSMI, pContext))
             {
                 Assert(Status == STATUS_SUCCESS || Status == STATUS_GRAPHICS_NO_MORE_ELEMENTS_IN_DATASET);
@@ -2394,8 +2498,8 @@
 }
 
-void vboxVidPnDumpCopyProtectoin(const D3DKMDT_VIDPN_PRESENT_PATH_COPYPROTECTION *pCopyProtection)
-{
-    drprintf(("CopyProtection: CopyProtectionType(%s),  TODO: Dump All the rest\n",
-            vboxVidPnDumpStrCopyProtectionType(pCopyProtection->CopyProtectionType)));
+void vboxVidPnDumpCopyProtectoin(const char *pPrefix, const D3DKMDT_VIDPN_PRESENT_PATH_COPYPROTECTION *pCopyProtection, const char *pSuffix)
+{
+    drprintf(("%sType(%s), TODO%s", pPrefix,
+            vboxVidPnDumpStrCopyProtectionType(pCopyProtection->CopyProtectionType), pSuffix));
 }
 
@@ -2403,5 +2507,5 @@
 void vboxVidPnDumpPathTransformation(const D3DKMDT_VIDPN_PRESENT_PATH_TRANSFORMATION *pContentTransformation)
 {
-    drprintf(("Transformation: Scaling(%s),  ScalingSupport(%d), Rotation(%s), RotationSupport(%d)\n",
+    drprintf(("  --Transformation: Scaling(%s), ScalingSupport(%d), Rotation(%s), RotationSupport(%d)--\n",
             vboxVidPnDumpStrScaling(pContentTransformation->Scaling), pContentTransformation->ScalingSupport,
             vboxVidPnDumpStrRotation(pContentTransformation->Rotation), pContentTransformation->RotationSupport));
@@ -2452,5 +2556,5 @@
     vboxVidPnDumpRegion("activeSize(", &pVideoSignalInfo->ActiveSize, "), ");
     vboxVidPnDumpRational("VSynch(", &pVideoSignalInfo->VSyncFreq, "), ");
-    drprintf(("PixelRate(%d), ScanLineOrdering(%s)%s\n", pVideoSignalInfo->PixelRate, vboxVidPnDumpStrScanLineOrdering(pVideoSignalInfo->ScanLineOrdering), pSuffix));
+    drprintf(("PixelRate(%d), ScanLineOrdering(%s)%s", pVideoSignalInfo->PixelRate, vboxVidPnDumpStrScanLineOrdering(pVideoSignalInfo->ScanLineOrdering), pSuffix));
 }
 
@@ -2459,5 +2563,5 @@
     drprintf(("%s", pPrefix));
     vboxVidPnDumpSignalInfo("VSI: ", &pVidPnTargetModeInfo->VideoSignalInfo, ", ");
-    drprintf(("Preference(%s)%s", vboxVidPnDumpStrModePreference(pVidPnTargetModeInfo->Preference), pPrefix));
+    drprintf(("Preference(%s)%s", vboxVidPnDumpStrModePreference(pVidPnTargetModeInfo->Preference), pSuffix));
 }
 
@@ -2629,13 +2733,14 @@
     vboxVidPnDumpPinnedTargetMode(hVidPn, pVidPnInterface, pVidPnPresentPathInfo->VidPnTargetId);
 
-    drprintf(("ImportanceOrdinal(%s), VidPnTargetColorBasis(%s), Content(%s)\n",
+    vboxVidPnDumpPathTransformation(&pVidPnPresentPathInfo->ContentTransformation);
+
+    drprintf(("Importance(%s), TargetColorBasis(%s), Content(%s), ",
             vboxVidPnDumpStrImportance(pVidPnPresentPathInfo->ImportanceOrdinal),
             vboxVidPnDumpStrColorBasis(pVidPnPresentPathInfo->VidPnTargetColorBasis),
             vboxVidPnDumpStrContent(pVidPnPresentPathInfo->Content)));
-    vboxVidPnDumpPathTransformation(&pVidPnPresentPathInfo->ContentTransformation);
-    vboxVidPnDumpRegion("VisibleFromActiveTLOffset(", &pVidPnPresentPathInfo->VisibleFromActiveTLOffset, ")\n");
-    vboxVidPnDumpRegion("VisibleFromActiveBROffset(", &pVidPnPresentPathInfo->VisibleFromActiveBROffset, ")\n");
-    vboxVidPnDumpRanges("VidPnTargetColorCoeffDynamicRanges: ", &pVidPnPresentPathInfo->VidPnTargetColorCoeffDynamicRanges, "\n");
-    vboxVidPnDumpCopyProtectoin(&pVidPnPresentPathInfo->CopyProtection);
+    vboxVidPnDumpRegion("VFA_TL_O(", &pVidPnPresentPathInfo->VisibleFromActiveTLOffset, "), ");
+    vboxVidPnDumpRegion("VFA_BR_O(", &pVidPnPresentPathInfo->VisibleFromActiveBROffset, "), ");
+    vboxVidPnDumpRanges("CCDynamicRanges: ", &pVidPnPresentPathInfo->VidPnTargetColorCoeffDynamicRanges, "| ");
+    vboxVidPnDumpCopyProtectoin("CProtection: ", &pVidPnPresentPathInfo->CopyProtection, "| ");
     vboxVidPnDumpGammaRamp("GammaRamp: ", &pVidPnPresentPathInfo->GammaRamp, "\n");
 
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Miniport/wddm/VBoxVideoVidPn.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Miniport/wddm/VBoxVideoVidPn.h	(revision 34129)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Miniport/wddm/VBoxVideoVidPn.h	(revision 34130)
@@ -71,5 +71,5 @@
 
 /* !!!NOTE: The callback is responsible for releasing the source mode info */
-typedef DECLCALLBACK(BOOLEAN) FNVBOXVIDPNENUMMONITORSOURCEMODES(struct _DEVICE_EXTENSION* pDevExt, D3DKMDT_HMONITORSOURCEMODESET hMonitorSMS, CONST DXGK_MONITORSOURCEMODESET_INTERFACE *pMonitorSMSIf,
+typedef DECLCALLBACK(BOOLEAN) FNVBOXVIDPNENUMMONITORSOURCEMODES(D3DKMDT_HMONITORSOURCEMODESET hMonitorSMS, CONST DXGK_MONITORSOURCEMODESET_INTERFACE *pMonitorSMSIf,
         CONST D3DKMDT_MONITOR_SOURCE_MODE *pMonitorSMI, PVOID pContext);
 typedef FNVBOXVIDPNENUMMONITORSOURCEMODES *PFNVBOXVIDPNENUMMONITORSOURCEMODES;
@@ -104,5 +104,5 @@
         PFNVBOXVIDPNENUMTARGETMODES pfnCallback, PVOID pContext);
 
-NTSTATUS vboxVidPnEnumMonitorSourceModes(struct _DEVICE_EXTENSION* pDevExt, D3DKMDT_HMONITORSOURCEMODESET hMonitorSMS, CONST DXGK_MONITORSOURCEMODESET_INTERFACE *pMonitorSMSIf,
+NTSTATUS vboxVidPnEnumMonitorSourceModes(D3DKMDT_HMONITORSOURCEMODESET hMonitorSMS, CONST DXGK_MONITORSOURCEMODESET_INTERFACE *pMonitorSMSIf,
         PFNVBOXVIDPNENUMMONITORSOURCEMODES pfnCallback, PVOID pContext);
 
@@ -126,4 +126,8 @@
         D3DKMDT_2DREGION *pResolutions, uint32_t cResolutions, int32_t iPreferred);
 
+NTSTATUS vboxVidPnCofuncModalityForPath(PVBOXVIDPNCOFUNCMODALITY pCbContext,
+        D3DDDI_VIDEO_PRESENT_SOURCE_ID VidPnSourceId, D3DDDI_VIDEO_PRESENT_TARGET_ID VidPnTargetId,
+        BOOLEAN bModesAllowed);
+
 void vboxVidPnDumpVidPn(const char * pPrefix, PDEVICE_EXTENSION 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);
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Miniport/wddm/VBoxVideoWddm.cpp
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Miniport/wddm/VBoxVideoWddm.cpp	(revision 34129)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Miniport/wddm/VBoxVideoWddm.cpp	(revision 34130)
@@ -1084,5 +1084,5 @@
         ChildRelations[i].ChildCapabilities.Type.VideoOutput.MonitorOrientationAwareness = D3DKMDT_MOA_INTERRUPTIBLE; /* ?? D3DKMDT_MOA_NONE*/
         ChildRelations[i].ChildCapabilities.Type.VideoOutput.SupportsSdtvModes = FALSE;
-        ChildRelations[i].ChildCapabilities.HpdAwareness = HpdAwarenessInterruptible; /* ?? HpdAwarenessAlwaysConnected; */
+        ChildRelations[i].ChildCapabilities.HpdAwareness = HpdAwarenessAlwaysConnected; //HpdAwarenessInterruptible; /* ?? HpdAwarenessAlwaysConnected; */
         ChildRelations[i].AcpiUid =  i; /* */
         ChildRelations[i].ChildUid = i; /* should be == target id */
@@ -3555,5 +3555,5 @@
     {
 #ifdef VBOXWDDM_DEBUG_VIDPN
-        vboxVidPnDumpVidPn("\n>>>>IS SUPPORTED VidPN : >>>>\n", pContext, pIsSupportedVidPnArg->hDesiredVidPn, pVidPnInterface, "<<<<<<<<<<<<<<<<<<<<\n\n");
+        vboxVidPnDumpVidPn("\n>>>>IS SUPPORTED VidPN : >>>>\n", pContext, pIsSupportedVidPnArg->hDesiredVidPn, pVidPnInterface, "<<<<<<<<<<<<<<<<<<<<\n");
 #endif
 
@@ -3566,4 +3566,5 @@
             if (Status == STATUS_SUCCESS && bSupported)
             {
+#if 0
                 for (int id = 0; id < commonFromDeviceExt(pContext)->cDisplays; ++id)
                 {
@@ -3577,4 +3578,6 @@
                     {
                         Status = vboxVidPnCheckSourceModeSet(pIsSupportedVidPnArg->hDesiredVidPn, hNewVidPnSourceModeSet, pVidPnSourceModeSetInterface, &bSupported);
+
+                        Assert(bSupported);
 
                         pVidPnInterface->pfnReleaseSourceModeSet(pIsSupportedVidPnArg->hDesiredVidPn, hNewVidPnSourceModeSet);
@@ -3608,4 +3611,6 @@
                         {
                             Status = vboxVidPnCheckTargetModeSet(pIsSupportedVidPnArg->hDesiredVidPn, hNewVidPnTargetModeSet, pVidPnTargetModeSetInterface, &bSupported);
+
+                            Assert(bSupported);
 
                             pVidPnInterface->pfnReleaseTargetModeSet(pIsSupportedVidPnArg->hDesiredVidPn, hNewVidPnTargetModeSet);
@@ -3626,4 +3631,5 @@
                     }
                 }
+#endif
             }
         }
@@ -3640,5 +3646,5 @@
 
 #ifdef VBOXWDDM_DEBUG_VIDPN
-    drprintf(("The Given VidPn is %ssupported", pIsSupportedVidPnArg->IsVidPnSupported ? "" : "!!NOT!! "));
+    drprintf(("The Given VidPn is %ssupported\n\n", pIsSupportedVidPnArg->IsVidPnSupported ? "" : "!!NOT!! "));
 #endif
 
@@ -3664,6 +3670,7 @@
     PDEVICE_EXTENSION pDevExt = (PDEVICE_EXTENSION)hAdapter;
     NTSTATUS Status;
-    vboxWddmInvalidateVideoModesInfo(pDevExt);
-    PVBOXWDDM_VIDEOMODES_INFO pInfos = vboxWddmGetAllVideoModesInfos(pDevExt);
+    PVBOXWDDM_RECOMMENDVIDPN pVidPnInfo = pRecommendFunctionalVidPnArg->PrivateDriverDataSize >= sizeof (VBOXWDDM_RECOMMENDVIDPN) ?
+            (PVBOXWDDM_RECOMMENDVIDPN)pRecommendFunctionalVidPnArg->pPrivateDriverData : NULL;
+    PVBOXWDDM_VIDEOMODES_INFO pInfos = vboxWddmUpdateVideoModesInfo(pDevExt, pVidPnInfo);
     const DXGK_VIDPN_INTERFACE* pVidPnInterface = NULL;
     Status = pDevExt->u.primary.DxgkInterface.DxgkCbQueryVidPnInterface(pRecommendFunctionalVidPnArg->hRecommendedFunctionalVidPn, DXGK_VIDPN_INTERFACE_VERSION_V1, &pVidPnInterface);
@@ -3720,7 +3727,8 @@
 
             Assert(iPreferableResMode >= 0);
+            Assert(cActualResModes);
 
             Status = vboxVidPnCreatePopulateVidPnFromLegacy(pDevExt, pRecommendFunctionalVidPnArg->hRecommendedFunctionalVidPn, pVidPnInterface,
-                            pResModes, cResModes, iPreferableResMode,
+                            pResModes, cActualResModes, iPreferableResMode,
                             &Resolution, 1 /* cResolutions */,
                             i, i); /* srcId, tgtId */
@@ -3776,4 +3784,9 @@
         if (Status == STATUS_SUCCESS)
         {
+            BOOLEAN bSupported = FALSE;
+            Status = vboxVidPnCheckTopology(pDevExt, pEnumCofuncModalityArg->hConstrainingVidPn, hVidPnTopology, pVidPnTopologyInterface, &bSupported);
+            Assert(Status == STATUS_SUCCESS);
+            Assert(bSupported);
+
             VBOXVIDPNCOFUNCMODALITY CbContext = {0};
             CbContext.pDevExt = pDevExt;
@@ -3781,4 +3794,11 @@
             CbContext.pEnumCofuncModalityArg = pEnumCofuncModalityArg;
             CbContext.pInfos = vboxWddmGetAllVideoModesInfos(pDevExt);
+
+#if 1
+            for (int i = 0; i < commonFromDeviceExt(pDevExt)->cDisplays; ++i)
+            {
+                vboxVidPnCofuncModalityForPath(&CbContext, i, i, TRUE);
+            }
+#else
             Status = vboxVidPnEnumPaths(hVidPnTopology, pVidPnTopologyInterface,
                     vboxVidPnCofuncModalityPathEnum, &CbContext);
@@ -3793,4 +3813,5 @@
             else
                 drprintf((__FUNCTION__ ": vboxVidPnEnumPaths failed Status(0x%x)\n", Status));
+#endif
         }
         else
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Miniport/wddm/VBoxVideoWddm.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Miniport/wddm/VBoxVideoWddm.h	(revision 34129)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Miniport/wddm/VBoxVideoWddm.h	(revision 34130)
@@ -228,4 +228,5 @@
     int32_t iPreferredMode;
     uint32_t cModes;
+    uint32_t cPrevModes;
     VIDEO_MODE_INFORMATION aModes[VBOXWDDM_MAX_VIDEOMODES];
     uint32_t cResolutions;
Index: /trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxDispIf.cpp
===================================================================
--- /trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxDispIf.cpp	(revision 34129)
+++ /trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxDispIf.cpp	(revision 34130)
@@ -21,4 +21,6 @@
 #include <iprt/assert.h>
 
+#include <malloc.h>
+
 /* display driver interface abstraction for XPDM & WDDM
  * with WDDM we can not use ExtEscape to communicate with our driver
@@ -58,41 +60,60 @@
     OSinfo.dwOSVersionInfoSize = sizeof (OSinfo);
     GetVersionEx (&OSinfo);
+    bool bSupported = true;
+
     if (OSinfo.dwMajorVersion >= 6)
     {
-        /* this is vista and up */
         Log((__FUNCTION__": this is vista and up\n"));
-        HMODULE hGdi32 = GetModuleHandle("gdi32");
-        if (hGdi32 != NULL)
-        {
-            bool bSupported = true;
-            pIf->modeData.wddm.pfnD3DKMTOpenAdapterFromHdc = (PFND3DKMT_OPENADAPTERFROMHDC)GetProcAddress(hGdi32, "D3DKMTOpenAdapterFromHdc");
-            Log((__FUNCTION__"pfnD3DKMTOpenAdapterFromHdc = %p\n", pIf->modeData.wddm.pfnD3DKMTOpenAdapterFromHdc));
-            bSupported &= !!(pIf->modeData.wddm.pfnD3DKMTOpenAdapterFromHdc);
-
-            pIf->modeData.wddm.pfnD3DKMTOpenAdapterFromGdiDisplayName = (PFND3DKMT_OPENADAPTERFROMGDIDISPLAYNAME)GetProcAddress(hGdi32, "D3DKMTOpenAdapterFromGdiDisplayName");
-            Log((__FUNCTION__": pfnD3DKMTOpenAdapterFromGdiDisplayName = %p\n", pIf->modeData.wddm.pfnD3DKMTOpenAdapterFromGdiDisplayName));
-            bSupported &= !!(pIf->modeData.wddm.pfnD3DKMTOpenAdapterFromGdiDisplayName);
-
-            pIf->modeData.wddm.pfnD3DKMTCloseAdapter = (PFND3DKMT_CLOSEADAPTER)GetProcAddress(hGdi32, "D3DKMTCloseAdapter");
-            Log((__FUNCTION__": pfnD3DKMTCloseAdapter = %p\n", pIf->modeData.wddm.pfnD3DKMTCloseAdapter));
-            bSupported &= !!(pIf->modeData.wddm.pfnD3DKMTCloseAdapter);
-
-            pIf->modeData.wddm.pfnD3DKMTEscape = (PFND3DKMT_ESCAPE)GetProcAddress(hGdi32, "D3DKMTEscape");
-            Log((__FUNCTION__": pfnD3DKMTEscape = %p\n", pIf->modeData.wddm.pfnD3DKMTEscape));
-            bSupported &= !!(pIf->modeData.wddm.pfnD3DKMTCloseAdapter);
-
-            pIf->modeData.wddm.pfnD3DKMTInvalidateActiveVidPn = (PFND3DKMT_INVALIDATEACTIVEVIDPN)GetProcAddress(hGdi32, "D3DKMTInvalidateActiveVidPn");
-            Log((__FUNCTION__": pfnD3DKMTInvalidateActiveVidPn = %p\n", pIf->modeData.wddm.pfnD3DKMTInvalidateActiveVidPn));
-            bSupported &= !!(pIf->modeData.wddm.pfnD3DKMTInvalidateActiveVidPn);
-
-            if (!bSupported)
-            {
-                Log((__FUNCTION__": one of pfnD3DKMT function pointers failed to initialize\n"));
+        HMODULE hUser = GetModuleHandle("USER32");
+        if (hUser)
+        {
+            *(uintptr_t *)&pIf->modeData.wddm.pfnChangeDisplaySettingsEx = (uintptr_t)GetProcAddress(hUser, "ChangeDisplaySettingsExA");
+            Log((__FUNCTION__": VBoxDisplayInit: pfnChangeDisplaySettingsEx = %p\n", pIf->modeData.wddm.pfnChangeDisplaySettingsEx));
+            bSupported &= !!(pIf->modeData.wddm.pfnChangeDisplaySettingsEx);
+
+            *(uintptr_t *)&pIf->modeData.wddm.pfnEnumDisplayDevices = (uintptr_t)GetProcAddress(hUser, "EnumDisplayDevicesA");
+            Log((__FUNCTION__": VBoxDisplayInit: pfnEnumDisplayDevices = %p\n", pIf->modeData.wddm.pfnEnumDisplayDevices));
+            bSupported &= !!(pIf->modeData.wddm.pfnEnumDisplayDevices);
+
+            /* this is vista and up */
+            HMODULE hGdi32 = GetModuleHandle("gdi32");
+            if (hGdi32 != NULL)
+            {
+                pIf->modeData.wddm.pfnD3DKMTOpenAdapterFromHdc = (PFND3DKMT_OPENADAPTERFROMHDC)GetProcAddress(hGdi32, "D3DKMTOpenAdapterFromHdc");
+                Log((__FUNCTION__"pfnD3DKMTOpenAdapterFromHdc = %p\n", pIf->modeData.wddm.pfnD3DKMTOpenAdapterFromHdc));
+                bSupported &= !!(pIf->modeData.wddm.pfnD3DKMTOpenAdapterFromHdc);
+
+                pIf->modeData.wddm.pfnD3DKMTOpenAdapterFromGdiDisplayName = (PFND3DKMT_OPENADAPTERFROMGDIDISPLAYNAME)GetProcAddress(hGdi32, "D3DKMTOpenAdapterFromGdiDisplayName");
+                Log((__FUNCTION__": pfnD3DKMTOpenAdapterFromGdiDisplayName = %p\n", pIf->modeData.wddm.pfnD3DKMTOpenAdapterFromGdiDisplayName));
+                bSupported &= !!(pIf->modeData.wddm.pfnD3DKMTOpenAdapterFromGdiDisplayName);
+
+                pIf->modeData.wddm.pfnD3DKMTCloseAdapter = (PFND3DKMT_CLOSEADAPTER)GetProcAddress(hGdi32, "D3DKMTCloseAdapter");
+                Log((__FUNCTION__": pfnD3DKMTCloseAdapter = %p\n", pIf->modeData.wddm.pfnD3DKMTCloseAdapter));
+                bSupported &= !!(pIf->modeData.wddm.pfnD3DKMTCloseAdapter);
+
+                pIf->modeData.wddm.pfnD3DKMTEscape = (PFND3DKMT_ESCAPE)GetProcAddress(hGdi32, "D3DKMTEscape");
+                Log((__FUNCTION__": pfnD3DKMTEscape = %p\n", pIf->modeData.wddm.pfnD3DKMTEscape));
+                bSupported &= !!(pIf->modeData.wddm.pfnD3DKMTCloseAdapter);
+
+                pIf->modeData.wddm.pfnD3DKMTInvalidateActiveVidPn = (PFND3DKMT_INVALIDATEACTIVEVIDPN)GetProcAddress(hGdi32, "D3DKMTInvalidateActiveVidPn");
+                Log((__FUNCTION__": pfnD3DKMTInvalidateActiveVidPn = %p\n", pIf->modeData.wddm.pfnD3DKMTInvalidateActiveVidPn));
+                bSupported &= !!(pIf->modeData.wddm.pfnD3DKMTInvalidateActiveVidPn);
+
+                if (!bSupported)
+                {
+                    Log((__FUNCTION__": one of pfnD3DKMT function pointers failed to initialize\n"));
+                    err = ERROR_NOT_SUPPORTED;
+                }
+            }
+            else
+            {
+                Log((__FUNCTION__": GetModuleHandle(gdi32) failed, err(%d)\n", GetLastError()));
                 err = ERROR_NOT_SUPPORTED;
             }
+
         }
         else
         {
-            Log((__FUNCTION__": GetModuleHandle(gdi32) failed, err(%d)\n", GetLastError()));
+            Log((__FUNCTION__": GetModuleHandle(USER32) failed, err(%d)\n", GetLastError()));
             err = ERROR_NOT_SUPPORTED;
         }
@@ -259,4 +280,5 @@
 
         pCtx->Status = pIf->modeData.wddm.pfnD3DKMTInvalidateActiveVidPn(&IAVidPnData);
+        Assert(!pCtx->Status);
         if (pCtx->Status)
             Log((__FUNCTION__": pfnD3DKMTInvalidateActiveVidPn failed, Status (0x%x)\n", pCtx->Status));
@@ -342,4 +364,245 @@
 }
 
+static BOOL vboxDispIfValidateResize(DISPLAY_DEVICE *paDisplayDevices, DEVMODE *paDeviceModes, UINT cDevModes)
+{
+    DISPLAY_DEVICE DisplayDevice;
+    int i = 0;
+    UINT cMatched = 0;
+    DEVMODE DeviceMode;
+    for (int i = 0; ; ++i)
+    {
+        ZeroMemory(&DisplayDevice, sizeof(DISPLAY_DEVICE));
+        DisplayDevice.cb = sizeof(DISPLAY_DEVICE);
+
+        if (!EnumDisplayDevices (NULL, i, &DisplayDevice, 0))
+            break;
+
+        Log(("VBoxTray: vboxDispIfValidateResize: [%d(%d)] %s\n", i, cMatched, DisplayDevice.DeviceName));
+
+        BOOL bFetchDevice = FALSE;
+
+        if (DisplayDevice.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE)
+        {
+            Log(("VBoxTray: vboxDispIfValidateResize: Found primary device. err %d\n", GetLastError ()));
+            bFetchDevice = TRUE;
+        }
+        else if (!(DisplayDevice.StateFlags & DISPLAY_DEVICE_MIRRORING_DRIVER))
+        {
+
+            Log(("VBoxTray: vboxDispIfValidateResize: Found secondary device. err %d\n", GetLastError ()));
+            bFetchDevice = TRUE;
+        }
+
+        if (bFetchDevice)
+        {
+            if (cMatched >= cDevModes)
+            {
+                Log(("VBoxTray: vboxDispIfValidateResize: %d >= %d\n", cDevModes, cMatched));
+                return FALSE;
+            }
+
+            /* First try to get the video mode stored in registry (ENUM_REGISTRY_SETTINGS).
+             * A secondary display could be not active at the moment and would not have
+             * a current video mode (ENUM_CURRENT_SETTINGS).
+             */
+            ZeroMemory(&DeviceMode, sizeof(DeviceMode));
+            DeviceMode.dmSize = sizeof(DEVMODE);
+            if (!EnumDisplaySettings((LPSTR)DisplayDevice.DeviceName,
+                 ENUM_REGISTRY_SETTINGS, &DeviceMode))
+            {
+                Log(("VBoxTray: vboxDispIfValidateResize: EnumDisplaySettings error %d\n", GetLastError ()));
+                return FALSE;
+            }
+
+            if (   DeviceMode.dmPelsWidth == 0
+                || DeviceMode.dmPelsHeight == 0)
+            {
+                /* No ENUM_REGISTRY_SETTINGS yet. Seen on Vista after installation.
+                 * Get the current video mode then.
+                 */
+                ZeroMemory(&DeviceMode, sizeof(DeviceMode));
+                DeviceMode.dmSize = sizeof(DeviceMode);
+                if (!EnumDisplaySettings((LPSTR)DisplayDevice.DeviceName,
+                     ENUM_CURRENT_SETTINGS, &DeviceMode))
+                {
+                    /* ENUM_CURRENT_SETTINGS returns FALSE when the display is not active:
+                     * for example a disabled secondary display */
+                    Log(("VBoxTray: vboxDispIfValidateResize: EnumDisplaySettings(ENUM_CURRENT_SETTINGS) error %d\n", GetLastError ()));
+                    return FALSE;
+                }
+            }
+
+            UINT j = 0;
+            for (; j < cDevModes; ++j)
+            {
+                if (!strncmp(DisplayDevice.DeviceName, paDisplayDevices[j].DeviceName, RT_ELEMENTS(DeviceMode.dmDeviceName)))
+                {
+                    if (paDeviceModes[j].dmBitsPerPel != DeviceMode.dmBitsPerPel
+                            || (paDeviceModes[j].dmPelsWidth & 0xfff8) != (DeviceMode.dmPelsWidth & 0xfff8)
+                            || (paDeviceModes[j].dmPelsHeight & 0xfff8) != (DeviceMode.dmPelsHeight & 0xfff8)
+                            || (paDeviceModes[j].dmPosition.x & 0xfff8) != (DeviceMode.dmPosition.x & 0xfff8)
+                            || (paDeviceModes[j].dmPosition.y & 0xfff8) != (DeviceMode.dmPosition.y & 0xfff8)
+                            || (paDisplayDevices[j].StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP) == (DisplayDevice.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP))
+                    {
+                        return FALSE;
+                    }
+                    break;
+                }
+            }
+
+            if (j == cDevModes)
+                return FALSE;
+
+            ++cMatched;
+        }
+    }
+
+    return cMatched == cDevModes;
+}
+
+DWORD vboxDispIfResizeModesWDDM(PCVBOXDISPIF const pIf, DISPLAY_DEVICE *paDisplayDevices, DEVMODE *paDeviceModes, UINT cDevModes)
+{
+    UINT cbVidPnInfo = VBOXWDDM_RECOMMENDVIDPN_SIZE(cDevModes);
+    PVBOXWDDM_RECOMMENDVIDPN pVidPnInfo = (PVBOXWDDM_RECOMMENDVIDPN)alloca(cbVidPnInfo);
+    pVidPnInfo->cScreenInfos = cDevModes;
+    D3DKMT_HANDLE hAdapter = NULL;
+    NTSTATUS Status;
+    DWORD winEr = NO_ERROR;
+    UINT i = 0;
+
+    for (; i < cDevModes; i++)
+    {
+        PVBOXWDDM_RECOMMENDVIDPN_SCREEN_INFO pInfo = &pVidPnInfo->aScreenInfos[i];
+        D3DKMT_OPENADAPTERFROMHDC OpenAdapterData = {0};
+        OpenAdapterData.hDc = CreateDC(NULL, paDisplayDevices[i].DeviceName, NULL, NULL);
+        if (!OpenAdapterData.hDc)
+        {
+            winEr = GetLastError();
+            Assert(0);
+            break;
+        }
+
+        Status = pIf->modeData.wddm.pfnD3DKMTOpenAdapterFromHdc(&OpenAdapterData);
+        Assert(!Status);
+        if (Status)
+        {
+            winEr = ERROR_GEN_FAILURE;
+            Assert(0);
+            break;
+        }
+
+        pInfo->Id = OpenAdapterData.VidPnSourceId;
+        pInfo->Width = paDeviceModes[i].dmPelsWidth;
+        pInfo->Height = paDeviceModes[i].dmPelsHeight;
+        pInfo->BitsPerPixel = paDeviceModes[i].dmBitsPerPel;
+
+        if (!hAdapter)
+        {
+            hAdapter = OpenAdapterData.hAdapter;
+        }
+        else
+        {
+            D3DKMT_CLOSEADAPTER ClosaAdapterData = {0};
+            ClosaAdapterData.hAdapter = OpenAdapterData.hAdapter;
+            Status = pIf->modeData.wddm.pfnD3DKMTCloseAdapter(&ClosaAdapterData);
+            Assert(!Status);
+        }
+    }
+
+    if (winEr == NO_ERROR)
+    {
+        Assert(hAdapter);
+
+        D3DKMT_INVALIDATEACTIVEVIDPN IAVidPnData = {0};
+        IAVidPnData.hAdapter = hAdapter;
+        IAVidPnData.pPrivateDriverData = pVidPnInfo;
+        IAVidPnData.PrivateDriverDataSize = cbVidPnInfo;
+
+        DWORD winEr = NO_ERROR;
+        Status = pIf->modeData.wddm.pfnD3DKMTInvalidateActiveVidPn(&IAVidPnData);
+        Assert(!Status);
+        if (Status)
+        {
+            Log((__FUNCTION__": pfnD3DKMTInvalidateActiveVidPn failed, Status (0x%x)\n", Status));
+            winEr = ERROR_GEN_FAILURE;
+        }
+    }
+
+    if (hAdapter)
+    {
+        D3DKMT_CLOSEADAPTER ClosaAdapterData = {0};
+        ClosaAdapterData.hAdapter = hAdapter;
+        Status = pIf->modeData.wddm.pfnD3DKMTCloseAdapter(&ClosaAdapterData);
+        Assert(!Status);
+    }
+
+    /* ignore any prev errors and just check if resize is OK */
+    if (!vboxDispIfValidateResize(paDisplayDevices, paDeviceModes, cDevModes))
+    {
+        /* now try to resize in a "regular" way */
+        /* Assign the new rectangles to displays. */
+        for (i = 0; i < cDevModes; i++)
+        {
+            /* On Vista one must specify DM_BITSPERPEL.
+             * Note that the current mode dmBitsPerPel is already in the DEVMODE structure.
+             */
+            paDeviceModes[i].dmFields = DM_POSITION | DM_PELSHEIGHT | DM_PELSWIDTH | DM_BITSPERPEL;
+
+            Log(("VBoxTray: ResizeDisplayDevice: pfnChangeDisplaySettingsEx %x: %dx%dx%d at %d,%d\n",
+                    pIf->modeData.wddm.pfnChangeDisplaySettingsEx,
+                  paDeviceModes[i].dmPelsWidth,
+                  paDeviceModes[i].dmPelsHeight,
+                  paDeviceModes[i].dmBitsPerPel,
+                  paDeviceModes[i].dmPosition.x,
+                  paDeviceModes[i].dmPosition.y));
+
+            LONG status = pIf->modeData.wddm.pfnChangeDisplaySettingsEx((LPSTR)paDisplayDevices[i].DeviceName,
+                                            &paDeviceModes[i], NULL, CDS_NORESET | CDS_UPDATEREGISTRY, NULL);
+            Log(("VBoxTray: ResizeDisplayDevice: ChangeDisplaySettingsEx position status %d, err %d\n", status, GetLastError ()));
+        }
+
+        /* A second call to ChangeDisplaySettings updates the monitor. */
+        LONG status = pIf->modeData.wddm.pfnChangeDisplaySettingsEx(NULL, NULL, NULL, 0, NULL);
+        Log(("VBoxTray: ResizeDisplayDevice: ChangeDisplaySettings update status %d\n", status));
+        if (status == DISP_CHANGE_SUCCESSFUL)
+        {
+            winEr = NO_ERROR;
+        }
+        else if (status == DISP_CHANGE_BADMODE)
+        {
+            /* Successfully set new video mode or our driver can not set the requested mode. Stop trying. */
+            winEr = ERROR_RETRY;
+        }
+        else
+        {
+            winEr = ERROR_GEN_FAILURE;
+        }
+    }
+    else
+    {
+        winEr = NO_ERROR;
+    }
+
+    return winEr;
+}
+
+DWORD VBoxDispIfResizeModes(PCVBOXDISPIF const pIf, DISPLAY_DEVICE *paDisplayDevices, DEVMODE *paDeviceModes, UINT cDevModes)
+{
+    switch (pIf->enmMode)
+    {
+        case VBOXDISPIF_MODE_XPDM_NT4:
+            return ERROR_NOT_SUPPORTED;
+        case VBOXDISPIF_MODE_XPDM:
+            return ERROR_NOT_SUPPORTED;
+#ifdef VBOX_WITH_WDDM
+        case VBOXDISPIF_MODE_WDDM:
+            return vboxDispIfResizeModesWDDM(pIf, paDisplayDevices, paDeviceModes, cDevModes);
+#endif
+        default:
+            Log((__FUNCTION__": unknown mode (%d)\n", pIf->enmMode));
+            return ERROR_INVALID_PARAMETER;
+    }
+}
+
 static DWORD vboxDispIfSwitchToXPDM_NT4(PVBOXDISPIF pIf)
 {
Index: /trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxDispIf.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxDispIf.h	(revision 34129)
+++ /trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxDispIf.h	(revision 34130)
@@ -53,4 +53,10 @@
         struct
         {
+            /* ChangeDisplaySettingsEx does not exist in NT. ResizeDisplayDevice uses the function. */
+            LONG (WINAPI * pfnChangeDisplaySettingsEx)(LPCTSTR lpszDeviceName, LPDEVMODE lpDevMode, HWND hwnd, DWORD dwflags, LPVOID lParam);
+
+            /* EnumDisplayDevices does not exist in NT. isVBoxDisplayDriverActive et al. are using these functions. */
+            BOOL (WINAPI * pfnEnumDisplayDevices)(IN LPCSTR lpDevice, IN DWORD iDevNum, OUT PDISPLAY_DEVICEA lpDisplayDevice, IN DWORD dwFlags);
+
             /* open adapter */
             PFND3DKMT_OPENADAPTERFROMHDC pfnD3DKMTOpenAdapterFromHdc;
@@ -77,2 +83,3 @@
 DWORD VBoxDispIfEscape(PCVBOXDISPIF const pIf, PVBOXDISPIFESCAPE pEscape, int cbData);
 DWORD VBoxDispIfResize(PCVBOXDISPIF const pIf, ULONG Id, DWORD Width, DWORD Height, DWORD BitsPerPixel);
+DWORD VBoxDispIfResizeModes(PCVBOXDISPIF const pIf, DISPLAY_DEVICE *paDisplayDevices, DEVMODE *paDeviceModes, UINT cDevModes);
Index: /trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxDisplay.cpp
===================================================================
--- /trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxDisplay.cpp	(revision 34129)
+++ /trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxDisplay.cpp	(revision 34130)
@@ -212,5 +212,6 @@
 
 /* Returns TRUE to try again. */
-static BOOL ResizeDisplayDevice(ULONG Id, DWORD Width, DWORD Height, DWORD BitsPerPixel)
+static BOOL ResizeDisplayDevice(ULONG Id, DWORD Width, DWORD Height, DWORD BitsPerPixel,
+                                        VBOXDISPLAYCONTEXT *pCtx)
 {
     BOOL fModeReset = (Width == 0 && Height == 0 && BitsPerPixel == 0);
@@ -382,4 +383,52 @@
 #endif /* Log */
 
+#ifdef VBOX_WITH_WDDM
+    VBOXDISPLAY_DRIVER_TYPE enmDriverType = getVBoxDisplayDriverType (pCtx);
+    if (enmDriverType == VBOXDISPLAY_DRIVER_TYPE_WDDM)
+    {
+        /* Assign the new rectangles to displays. */
+        for (i = 0; i < NumDevices; i++)
+        {
+            paDeviceModes[i].dmPosition.x = paRects[i].left;
+            paDeviceModes[i].dmPosition.y = paRects[i].top;
+            paDeviceModes[i].dmPelsWidth  = paRects[i].right - paRects[i].left;
+            paDeviceModes[i].dmPelsHeight = paRects[i].bottom - paRects[i].top;
+
+            /* On Vista one must specify DM_BITSPERPEL.
+             * Note that the current mode dmBitsPerPel is already in the DEVMODE structure.
+             */
+            paDeviceModes[i].dmFields = DM_POSITION | DM_PELSHEIGHT | DM_PELSWIDTH | DM_BITSPERPEL;
+
+            if (   i == Id
+                && BitsPerPixel != 0)
+            {
+                /* Change dmBitsPerPel if requested. */
+                paDeviceModes[i].dmBitsPerPel = BitsPerPixel;
+            }
+
+            Log(("VBoxTray: ResizeDisplayDevice: pfnChangeDisplaySettingsEx %x: %dx%dx%d at %d,%d\n",
+                  gCtx.pfnChangeDisplaySettingsEx,
+                  paDeviceModes[i].dmPelsWidth,
+                  paDeviceModes[i].dmPelsHeight,
+                  paDeviceModes[i].dmBitsPerPel,
+                  paDeviceModes[i].dmPosition.x,
+                  paDeviceModes[i].dmPosition.y));
+
+        }
+
+        DWORD err = VBoxDispIfResizeModes(&pCtx->pEnv->dispIf, paDisplayDevices, paDeviceModes, NumDevices);
+        if (err == NO_ERROR || err != ERROR_RETRY)
+        {
+            if (err == NO_ERROR)
+                Log(("VBoxTray: VBoxDisplayThread: (WDDM) VBoxDispIfResizeModes succeeded\n"));
+            else
+                Log(("VBoxTray: VBoxDisplayThread: (WDDM) Failure VBoxDispIfResizeModes (%d)\n", err));
+            return FALSE;
+        }
+
+        Log(("VBoxTray: ResizeDisplayDevice: (WDDM) RETRY requested\n"));
+        return TRUE;
+    }
+#endif
     /* Without this, Windows will not ask the miniport for its
      * mode table but uses an internal cache instead.
@@ -550,25 +599,10 @@
                                 Log(("VBoxTray: VBoxDisplayThread: Detected W2K or later\n"));
 
-#ifdef  VBOX_WITH_WDDM
-                                if (enmDriverType == VBOXDISPLAY_DRIVER_TYPE_WDDM)
-                                {
-                                    DWORD err = VBoxDispIfResize(&pCtx->pEnv->dispIf,
-                                                        displayChangeRequest.display,
-                                                        displayChangeRequest.xres,
-                                                        displayChangeRequest.yres,
-                                                        displayChangeRequest.bpp);
-                                    if (err == NO_ERROR)
-                                    {
-                                        Log(("VBoxTray: VBoxDisplayThread: VBoxDispIfResize succeeded\n"));
-                                        break;
-                                    }
-                                    Log(("VBoxTray: VBoxDisplayThread: VBoxDispIfResize failed err(%d)\n", err));
-                                }
-#endif
                                 /* W2K or later. */
                                 if (!ResizeDisplayDevice(displayChangeRequest.display,
                                                          displayChangeRequest.xres,
                                                          displayChangeRequest.yres,
-                                                         displayChangeRequest.bpp
+                                                         displayChangeRequest.bpp,
+                                                         pCtx
                                                          ))
                                 {
Index: /trunk/src/VBox/Additions/WINNT/include/VBoxDisplay.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/include/VBoxDisplay.h	(revision 34129)
+++ /trunk/src/VBox/Additions/WINNT/include/VBoxDisplay.h	(revision 34130)
@@ -33,5 +33,5 @@
 typedef struct
 {
-    ULONG Id;
+    DWORD Id;
     DWORD Width;
     DWORD Height;
