Index: /trunk/src/VBox/Additions/WINNT/Graphics/Miniport/Makefile.kmk
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Miniport/Makefile.kmk	(revision 32765)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Miniport/Makefile.kmk	(revision 32766)
@@ -89,5 +89,7 @@
   endif
  endif
- #VBoxVideoWddm_DEFS       += LOG_ENABLED
+ ifdef DEBUG_misha
+  VBoxVideoWddm_DEFS       += LOG_ENABLED
+ endif
  #VBoxVideoWddm_DEFS       += VBOX_WITH_MULTIMONITOR_FIX
  #VBoxVideoWddm_DEFS       += LOG_TO_BACKDOOR
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Miniport/VBoxVideo.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Miniport/VBoxVideo.h	(revision 32765)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Miniport/VBoxVideo.h	(revision 32766)
@@ -305,4 +305,6 @@
 #ifdef VBOX_WITH_WDDM
    PDEVICE_OBJECT pPDO;
+   UNICODE_STRING RegKeyName;
+   UNICODE_STRING VideoGuid;
 
    uint8_t * pvVisibleVram;
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Miniport/wddm/VBoxVideoMisc.cpp
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Miniport/wddm/VBoxVideoMisc.cpp	(revision 32765)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Miniport/wddm/VBoxVideoMisc.cpp	(revision 32766)
@@ -12,6 +12,9 @@
 
 #include "../VBoxVideo.h"
+#include "../Helper.h"
 
 #include <iprt/asm.h>
+
+#include <stdio.h>
 
 NTSTATUS vboxWddmHTableCreate(PVBOXWDDM_HTABLE pTbl, uint32_t cSize)
@@ -458,2 +461,297 @@
     return STATUS_SUCCESS;
 }
+
+#define VBOXWDDM_REG_DRVKEY_PREFIX L"\\Registry\\Machine\\System\\CurrentControlSet\\Control\\Class\\"
+
+NTSTATUS vboxWddmRegQueryDrvKeyName(PDEVICE_EXTENSION pDevExt, ULONG cbBuf, PWCHAR pBuf, PULONG pcbResult)
+{
+    WCHAR fallBackBuf[2];
+    PWCHAR pSuffix;
+    bool bFallback = false;
+
+    if (cbBuf > sizeof(VBOXWDDM_REG_DRVKEY_PREFIX))
+    {
+        memcpy(pBuf, VBOXWDDM_REG_DRVKEY_PREFIX, sizeof (VBOXWDDM_REG_DRVKEY_PREFIX));
+        pSuffix = pBuf + (sizeof (VBOXWDDM_REG_DRVKEY_PREFIX)-2)/2;
+        cbBuf -= sizeof (VBOXWDDM_REG_DRVKEY_PREFIX)-2;
+    }
+    else
+    {
+        pSuffix = fallBackBuf;
+        cbBuf = sizeof (fallBackBuf);
+        bFallback = true;
+    }
+
+    NTSTATUS Status = IoGetDeviceProperty (pDevExt->pPDO,
+                                  DevicePropertyDriverKeyName,
+                                  cbBuf,
+                                  pSuffix,
+                                  &cbBuf);
+    if (Status == STATUS_SUCCESS && bFallback)
+        Status = STATUS_BUFFER_TOO_SMALL;
+    if (Status == STATUS_BUFFER_TOO_SMALL)
+        *pcbResult = cbBuf + sizeof (VBOXWDDM_REG_DRVKEY_PREFIX)-2;
+
+    return Status;
+}
+
+#define VBOXWDDM_REG_DISPLAYSETTINGSKEY_PREFIX_VISTA L"\\Registry\\Machine\\System\\CurrentControlSet\\Hardware Profiles\\Current\\System\\CurrentControlSet\\Control\\VIDEO\\"
+#define VBOXWDDM_REG_DISPLAYSETTINGSKEY_PREFIX_WIN7 L"\\Registry\\Machine\\System\\CurrentControlSet\\Hardware Profiles\\UnitedVideo\\CONTROL\\VIDEO\\"
+
+#define VBOXWDDM_REG_DISPLAYSETTINGS_ATTACH_RELX L"Attach.RelativeX"
+#define VBOXWDDM_REG_DISPLAYSETTINGS_ATTACH_RELY L"Attach.RelativeY"
+#define VBOXWDDM_REG_DISPLAYSETTINGS_ATTACH_DESKTOP L"Attach.ToDesktop"
+
+NTSTATUS vboxWddmRegQueryDisplaySettingsKeyName(PDEVICE_EXTENSION pDevExt, D3DDDI_VIDEO_PRESENT_SOURCE_ID VidPnSourceId,
+        ULONG cbBuf, PWCHAR pBuf, PULONG pcbResult)
+{
+    NTSTATUS Status = STATUS_SUCCESS;
+    PWCHAR pSuffix;
+    bool bFallback = false;
+    const WCHAR* pKeyPrefix;
+    UINT cbKeyPrefix;
+    winVersion_t ver = vboxQueryWinVersion();
+    if (ver == WINVISTA)
+    {
+        pKeyPrefix = VBOXWDDM_REG_DISPLAYSETTINGSKEY_PREFIX_VISTA;
+        cbKeyPrefix = sizeof (VBOXWDDM_REG_DISPLAYSETTINGSKEY_PREFIX_VISTA);
+    }
+    else
+    {
+        Assert(ver == WIN7);
+        pKeyPrefix = VBOXWDDM_REG_DISPLAYSETTINGSKEY_PREFIX_WIN7;
+        cbKeyPrefix = sizeof (VBOXWDDM_REG_DISPLAYSETTINGSKEY_PREFIX_WIN7);
+    }
+
+    ULONG cbResult = cbKeyPrefix + pDevExt->VideoGuid.Length + 2 + 8; // L"\\" + "XXXX"
+    if (cbBuf >= cbResult)
+    {
+        wcscpy(pBuf, pKeyPrefix);
+        pSuffix = pBuf + (cbKeyPrefix-2)/2;
+        memcpy(pSuffix, pDevExt->VideoGuid.Buffer, pDevExt->VideoGuid.Length);
+        pSuffix += pDevExt->VideoGuid.Length/2;
+        pSuffix[0] = L'\\';
+        pSuffix += 1;
+        swprintf(pSuffix, L"%04d", VidPnSourceId);
+    }
+    else
+    {
+        Status = STATUS_BUFFER_TOO_SMALL;
+    }
+
+    *pcbResult = cbResult;
+
+    return Status;
+}
+
+#define VBOXWDDM_REG_DISPLAYSETTINGSVIDEOKEY L"\\Registry\\Machine\\System\\CurrentControlSet\\Control\\Video\\"
+#define VBOXWDDM_REG_DISPLAYSETTINGSVIDEOKEY_SUBKEY L"\\Video"
+
+NTSTATUS vboxWddmRegQueryVideoGuidString(ULONG cbBuf, PWCHAR pBuf, PULONG pcbResult)
+{
+    HANDLE hKey;
+    NTSTATUS Status = vboxWddmRegOpenKey(&hKey, VBOXWDDM_REG_DISPLAYSETTINGSVIDEOKEY, GENERIC_READ);
+    Assert(Status == STATUS_SUCCESS);
+    if (Status == STATUS_SUCCESS)
+    {
+        struct
+        {
+            KEY_BASIC_INFORMATION Name;
+            WCHAR Buf[256];
+        } Buf;
+        WCHAR KeyBuf[sizeof (VBOXWDDM_REG_DISPLAYSETTINGSVIDEOKEY)/2 + 256 + 64];
+        wcscpy(KeyBuf, VBOXWDDM_REG_DISPLAYSETTINGSVIDEOKEY);
+        ULONG ResultLength;
+        BOOL bFound = FALSE;
+        for (ULONG i = 0; !bFound; ++i)
+        {
+            RtlZeroMemory(&Buf, sizeof (Buf));
+            Status = ZwEnumerateKey(hKey, i, KeyBasicInformation, &Buf, sizeof (Buf), &ResultLength);
+            Assert(Status == STATUS_SUCCESS);
+            /* we should not encounter STATUS_NO_MORE_ENTRIES here since this would mean we did not find our entry */
+            if (Status != STATUS_SUCCESS)
+                break;
+
+            HANDLE hSubKey;
+            PWCHAR pSubBuf = KeyBuf + (sizeof (VBOXWDDM_REG_DISPLAYSETTINGSVIDEOKEY) - 2)/2;
+            memcpy(pSubBuf, Buf.Name.Name, Buf.Name.NameLength);
+            pSubBuf += Buf.Name.NameLength/2;
+            memcpy(pSubBuf, VBOXWDDM_REG_DISPLAYSETTINGSVIDEOKEY_SUBKEY, sizeof (VBOXWDDM_REG_DISPLAYSETTINGSVIDEOKEY_SUBKEY));
+            Status = vboxWddmRegOpenKey(&hSubKey, KeyBuf, GENERIC_READ);
+            Assert(Status == STATUS_SUCCESS);
+            if (Status == STATUS_SUCCESS)
+            {
+                struct
+                {
+                    KEY_VALUE_PARTIAL_INFORMATION Info;
+                    UCHAR Buf[sizeof (L"VBoxVideoWddm")]; /* should be enough */
+                } KeyData;
+                ULONG cbResult;
+                UNICODE_STRING RtlStr;
+                RtlInitUnicodeString(&RtlStr, L"Service");
+                Status = ZwQueryValueKey(hSubKey,
+                            &RtlStr,
+                            KeyValuePartialInformation,
+                            &KeyData.Info,
+                            sizeof(KeyData),
+                            &cbResult);
+                Assert(Status == STATUS_SUCCESS || STATUS_BUFFER_TOO_SMALL || STATUS_BUFFER_OVERFLOW);
+                if (Status == STATUS_SUCCESS)
+                {
+                    if (KeyData.Info.Type == REG_SZ)
+                    {
+                        if (KeyData.Info.DataLength == sizeof (L"VBoxVideoWddm"))
+                        {
+                            if (!wcscmp(L"VBoxVideoWddm", (PWCHAR)KeyData.Info.Data))
+                            {
+                                bFound = TRUE;
+                                *pcbResult = Buf.Name.NameLength + 2;
+                                if (cbBuf >= Buf.Name.NameLength + 2)
+                                {
+                                    memcpy(pBuf, Buf.Name.Name, Buf.Name.NameLength + 2);
+                                }
+                                else
+                                {
+                                    Status = STATUS_BUFFER_TOO_SMALL;
+                                }
+                            }
+                        }
+                    }
+                }
+
+                NTSTATUS tmpStatus = ZwClose(hSubKey);
+                Assert(tmpStatus == STATUS_SUCCESS);
+            }
+            else
+                break;
+        }
+        NTSTATUS tmpStatus = ZwClose(hKey);
+        Assert(tmpStatus == STATUS_SUCCESS);
+    }
+
+    return Status;
+}
+
+NTSTATUS vboxWddmRegOpenKey(OUT PHANDLE phKey, IN PWCHAR pName, IN ACCESS_MASK fAccess)
+{
+    OBJECT_ATTRIBUTES ObjAttr;
+    UNICODE_STRING RtlStr;
+
+    RtlInitUnicodeString(&RtlStr, pName);
+    InitializeObjectAttributes(&ObjAttr, &RtlStr, OBJ_CASE_INSENSITIVE, NULL, NULL);
+
+    return ZwOpenKey(phKey, fAccess, &ObjAttr);
+}
+
+NTSTATUS vboxWddmRegOpenDisplaySettingsKey(IN PDEVICE_EXTENSION pDeviceExtension, D3DDDI_VIDEO_PRESENT_SOURCE_ID VidPnSourceId, OUT PHANDLE phKey)
+{
+    WCHAR Buf[512];
+    ULONG cbBuf = sizeof(Buf);
+    NTSTATUS Status = vboxWddmRegQueryDisplaySettingsKeyName(pDeviceExtension, VidPnSourceId, cbBuf, Buf, &cbBuf);
+    Assert(Status == STATUS_SUCCESS);
+    if (Status == STATUS_SUCCESS)
+    {
+        Status = vboxWddmRegOpenKey(phKey, Buf, GENERIC_READ);
+        Assert(Status == STATUS_SUCCESS);
+        if(Status == STATUS_SUCCESS)
+            return STATUS_SUCCESS;
+    }
+
+    /* fall-back to make the subsequent VBoxVideoCmnRegXxx calls treat the fail accordingly
+     * basically needed to make as less modifications to the current XPDM code as possible */
+    *phKey = NULL;
+
+    return Status;
+}
+
+NTSTATUS vboxWddmRegDisplaySettingsQueryRelX(HANDLE hKey, int * pResult)
+{
+    DWORD dwVal;
+    NTSTATUS Status = vboxWddmRegQueryValueDword(hKey, VBOXWDDM_REG_DISPLAYSETTINGS_ATTACH_RELX, &dwVal);
+    Assert(Status == STATUS_SUCCESS);
+    if (Status == STATUS_SUCCESS)
+    {
+        *pResult = (int)dwVal;
+    }
+
+    return Status;
+}
+
+NTSTATUS vboxWddmRegDisplaySettingsQueryRelY(HANDLE hKey, int * pResult)
+{
+    DWORD dwVal;
+    NTSTATUS Status = vboxWddmRegQueryValueDword(hKey, VBOXWDDM_REG_DISPLAYSETTINGS_ATTACH_RELY, &dwVal);
+    Assert(Status == STATUS_SUCCESS);
+    if (Status == STATUS_SUCCESS)
+    {
+        *pResult = (int)dwVal;
+    }
+
+    return Status;
+}
+
+NTSTATUS vboxWddmDisplaySettingsQueryPos(IN PDEVICE_EXTENSION pDeviceExtension, D3DDDI_VIDEO_PRESENT_SOURCE_ID VidPnSourceId, POINT * pPos)
+{
+    HANDLE hKey;
+    NTSTATUS Status = vboxWddmRegOpenDisplaySettingsKey(pDeviceExtension, VidPnSourceId, &hKey);
+    Assert(Status == STATUS_SUCCESS);
+    if (Status == STATUS_SUCCESS)
+    {
+        int x, y;
+        Status = vboxWddmRegDisplaySettingsQueryRelX(hKey, &x);
+        Assert(Status == STATUS_SUCCESS);
+        if (Status == STATUS_SUCCESS)
+        {
+            Status = vboxWddmRegDisplaySettingsQueryRelY(hKey, &y);
+            Assert(Status == STATUS_SUCCESS);
+            if (Status == STATUS_SUCCESS)
+            {
+                pPos->x = x;
+                pPos->y = y;
+            }
+        }
+        NTSTATUS tmpStatus = ZwClose(hKey);
+        Assert(tmpStatus == STATUS_SUCCESS);
+    }
+    return Status;
+}
+
+NTSTATUS vboxWddmRegQueryValueDword(IN HANDLE hKey, IN PWCHAR pName, OUT PDWORD pDword)
+{
+    struct
+    {
+        KEY_VALUE_PARTIAL_INFORMATION Info;
+        UCHAR Buf[32]; /* should be enough */
+    } Buf;
+    ULONG cbBuf;
+    UNICODE_STRING RtlStr;
+    RtlInitUnicodeString(&RtlStr, pName);
+    NTSTATUS Status = ZwQueryValueKey(hKey,
+                &RtlStr,
+                KeyValuePartialInformation,
+                &Buf.Info,
+                sizeof(Buf),
+                &cbBuf);
+    if (Status == STATUS_SUCCESS)
+    {
+        if (Buf.Info.Type == REG_DWORD)
+        {
+            Assert(Buf.Info.DataLength == 4);
+            *pDword = *((PULONG)Buf.Info.Data);
+            return STATUS_SUCCESS;
+        }
+    }
+
+    return STATUS_INVALID_PARAMETER;
+}
+
+NTSTATUS vboxWddmRegSetValueDword(IN HANDLE hKey, IN PWCHAR pName, OUT DWORD val)
+{
+    UNICODE_STRING RtlStr;
+    RtlInitUnicodeString(&RtlStr, pName);
+    return ZwSetValueKey(hKey, &RtlStr,
+            NULL, /* IN ULONG  TitleIndex  OPTIONAL, reserved */
+            REG_DWORD,
+            &val,
+            sizeof(val));
+}
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Miniport/wddm/VBoxVideoMisc.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Miniport/wddm/VBoxVideoMisc.h	(revision 32765)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Miniport/wddm/VBoxVideoMisc.h	(revision 32766)
@@ -60,3 +60,17 @@
 NTSTATUS vboxWddmSwapchainCtxEscape(PDEVICE_EXTENSION pDevExt, PVBOXWDDM_CONTEXT pContext, PVBOXDISPIFESCAPE_SWAPCHAININFO pSwapchainInfo, UINT cbSize);
 
+
+NTSTATUS vboxWddmRegQueryDisplaySettingsKeyName(PDEVICE_EXTENSION pDevExt, D3DDDI_VIDEO_PRESENT_SOURCE_ID VidPnSourceId,
+        ULONG cbBuf, PWCHAR pBuf, PULONG pcbResult);
+NTSTATUS vboxWddmRegOpenDisplaySettingsKey(IN PDEVICE_EXTENSION pDeviceExtension, D3DDDI_VIDEO_PRESENT_SOURCE_ID VidPnSourceId, OUT PHANDLE phKey);
+NTSTATUS vboxWddmRegDisplaySettingsQueryRelX(HANDLE hKey, int * pResult);
+NTSTATUS vboxWddmRegDisplaySettingsQueryRelY(HANDLE hKey, int * pResult);
+NTSTATUS vboxWddmDisplaySettingsQueryPos(IN PDEVICE_EXTENSION pDeviceExtension, D3DDDI_VIDEO_PRESENT_SOURCE_ID VidPnSourceId, POINT * pPos);
+NTSTATUS vboxWddmRegQueryVideoGuidString(ULONG cbBuf, PWCHAR pBuf, PULONG pcbResult);
+
+NTSTATUS vboxWddmRegQueryDrvKeyName(PDEVICE_EXTENSION pDevExt, ULONG cbBuf, PWCHAR pBuf, PULONG pcbResult);
+
+NTSTATUS vboxWddmRegOpenKey(OUT PHANDLE phKey, IN PWCHAR pName, IN ACCESS_MASK fAccess);
+NTSTATUS vboxWddmRegQueryValueDword(IN HANDLE hKey, IN PWCHAR pName, OUT PDWORD pDword);
+NTSTATUS vboxWddmRegSetValueDword(IN HANDLE hKey, IN PWCHAR pName, OUT DWORD val);
 #endif /* #ifndef ___VBoxVideoMisc_h__ */
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Miniport/wddm/VBoxVideoWddm.cpp
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Miniport/wddm/VBoxVideoWddm.cpp	(revision 32765)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Miniport/wddm/VBoxVideoWddm.cpp	(revision 32766)
@@ -185,5 +185,5 @@
 }
 
-NTSTATUS vboxWddmGhDisplaySetInfo(PDEVICE_EXTENSION pDevExt, PVBOXWDDM_SOURCE pSource)
+NTSTATUS vboxWddmGhDisplaySetInfo(PDEVICE_EXTENSION pDevExt, PVBOXWDDM_SOURCE pSource, D3DDDI_VIDEO_PRESENT_SOURCE_ID VidPnSourceId)
 {
     PVBOXWDDM_ALLOCATION pAllocation = VBOXWDDM_FB_ALLOCATION(pSource);
@@ -196,5 +196,7 @@
      * Set the current mode into the hardware.
      */
-    NTSTATUS Status = vboxWddmGhDisplaySetMode(pDevExt, pAllocation);
+    NTSTATUS Status= vboxWddmDisplaySettingsQueryPos(pDevExt, VidPnSourceId, &pSource->VScreenPos);
+    Assert(Status == STATUS_SUCCESS);
+    Status = vboxWddmGhDisplaySetMode(pDevExt, pAllocation);
     Assert(Status == STATUS_SUCCESS);
     if (Status == STATUS_SUCCESS)
@@ -219,5 +221,6 @@
 
 #ifdef VBOXWDDM_RENDER_FROM_SHADOW
-bool vboxWddmCheckUpdateShadowAddress(PDEVICE_EXTENSION pDevExt, PVBOXWDDM_SOURCE pSource, UINT SegmentId, VBOXVIDEOOFFSET offVram)
+bool vboxWddmCheckUpdateShadowAddress(PDEVICE_EXTENSION pDevExt, PVBOXWDDM_SOURCE pSource,
+        D3DDDI_VIDEO_PRESENT_SOURCE_ID VidPnSourceId, UINT SegmentId, VBOXVIDEOOFFSET offVram)
 {
     if (pSource->pPrimaryAllocation->enmType == VBOXWDDM_ALLOC_TYPE_UMD_RC_GENERIC)
@@ -232,5 +235,5 @@
     pSource->pShadowAllocation->offVram = offVram;
 
-    NTSTATUS Status = vboxWddmGhDisplaySetInfo(pDevExt, pSource);
+    NTSTATUS Status = vboxWddmGhDisplaySetInfo(pDevExt, pSource, VidPnSourceId);
     Assert(Status == STATUS_SUCCESS);
     if (Status != STATUS_SUCCESS)
@@ -272,94 +275,4 @@
 }
 
-
-#define VBOXWDDM_REG_DRVKEY_PREFIX L"\\Registry\\Machine\\System\\CurrentControlSet\\Control\\Class\\"
-
-NTSTATUS vboxWddmRegQueryDrvKeyName(PDEVICE_EXTENSION pDevExt, ULONG cbBuf, PWCHAR pBuf, PULONG pcbResult)
-{
-    WCHAR fallBackBuf[2];
-    PWCHAR pSuffix;
-    bool bFallback = false;
-
-    if (cbBuf > sizeof(VBOXWDDM_REG_DRVKEY_PREFIX))
-    {
-        wcscpy(pBuf, VBOXWDDM_REG_DRVKEY_PREFIX);
-        pSuffix = pBuf + (sizeof (VBOXWDDM_REG_DRVKEY_PREFIX)-2);
-        cbBuf -= sizeof (VBOXWDDM_REG_DRVKEY_PREFIX)-2;
-    }
-    else
-    {
-        pSuffix = fallBackBuf;
-        cbBuf = sizeof (fallBackBuf);
-        bFallback = true;
-    }
-
-    NTSTATUS Status = IoGetDeviceProperty (pDevExt->pPDO,
-                                  DevicePropertyDriverKeyName,
-                                  cbBuf,
-                                  pSuffix,
-                                  &cbBuf);
-    if (Status == STATUS_SUCCESS && bFallback)
-        Status = STATUS_BUFFER_TOO_SMALL;
-    if (Status == STATUS_BUFFER_TOO_SMALL)
-        *pcbResult = cbBuf + sizeof (VBOXWDDM_REG_DRVKEY_PREFIX)-2;
-
-    return Status;
-}
-
-NTSTATUS vboxWddmRegOpenKey(OUT PHANDLE phKey, IN PWCHAR pName, IN ACCESS_MASK fAccess)
-{
-    OBJECT_ATTRIBUTES ObjAttr;
-    UNICODE_STRING RtlStr;
-    RtlStr.Buffer = pName;
-    RtlStr.Length = USHORT(wcslen(pName) * sizeof(WCHAR));
-    RtlStr.MaximumLength = RtlStr.Length + sizeof(WCHAR);
-
-    InitializeObjectAttributes(&ObjAttr, &RtlStr, OBJ_CASE_INSENSITIVE, NULL, NULL);
-
-    return ZwOpenKey(phKey, fAccess, &ObjAttr);
-}
-
-NTSTATUS vboxWddmRegQueryValueDword(IN HANDLE hKey, IN PWCHAR pName, OUT PDWORD pDword)
-{
-    UCHAR Buf[32]; /* should be enough */
-    ULONG cbBuf;
-    PKEY_VALUE_PARTIAL_INFORMATION pInfo = (PKEY_VALUE_PARTIAL_INFORMATION)Buf;
-    UNICODE_STRING RtlStr;
-    RtlStr.Buffer = pName;
-    RtlStr.Length = USHORT(wcslen(pName) * sizeof(WCHAR));
-    RtlStr.MaximumLength = RtlStr.Length + sizeof(WCHAR);
-    NTSTATUS Status = ZwQueryValueKey(hKey,
-                &RtlStr,
-                KeyValuePartialInformation,
-                pInfo,
-                sizeof(Buf),
-                &cbBuf);
-    if (Status == STATUS_SUCCESS)
-    {
-        if (pInfo->Type == REG_DWORD)
-        {
-            Assert(pInfo->DataLength == 4);
-            *pDword = *((PULONG)pInfo->Data);
-            return STATUS_SUCCESS;
-        }
-    }
-
-    return STATUS_INVALID_PARAMETER;
-}
-
-NTSTATUS vboxWddmRegSetValueDword(IN HANDLE hKey, IN PWCHAR pName, OUT DWORD val)
-{
-    UCHAR Buf[32]; /* should be enough */
-    PKEY_VALUE_PARTIAL_INFORMATION pInfo = (PKEY_VALUE_PARTIAL_INFORMATION)Buf;
-    UNICODE_STRING RtlStr;
-    RtlStr.Buffer = pName;
-    RtlStr.Length = USHORT(wcslen(pName) * sizeof(WCHAR));
-    RtlStr.MaximumLength = RtlStr.Length + sizeof(WCHAR);
-    return ZwSetValueKey(hKey, &RtlStr,
-            NULL, /* IN ULONG  TitleIndex  OPTIONAL, reserved */
-            REG_DWORD,
-            &val,
-            sizeof(val));
-}
 
 VP_STATUS VBoxVideoCmnRegQueryDword(IN VBOXCMNREG Reg, PWSTR pName, uint32_t *pVal)
@@ -542,4 +455,8 @@
     memset(pDevExt, 0, sizeof (DEVICE_EXTENSION));
     pDevExt->pPDO = pPDO;
+    PWCHAR pName = (PWCHAR)(((uint8_t*)pDevExt) + VBOXWDDM_ROUNDBOUND(sizeof (DEVICE_EXTENSION), 8));
+    RtlInitUnicodeString(&pDevExt->RegKeyName, pName);
+    pName += (pDevExt->RegKeyName.Length + 2)/2;
+    RtlInitUnicodeString(&pDevExt->VideoGuid, pName);
 #ifdef VBOXWDDM_RENDER_FROM_SHADOW
     for (int i = 0; i < RT_ELEMENTS(pDevExt->aSources); ++i)
@@ -564,18 +481,43 @@
 
     NTSTATUS Status = STATUS_SUCCESS;
-
-    PDEVICE_EXTENSION pContext = (PDEVICE_EXTENSION)vboxWddmMemAllocZero(sizeof (DEVICE_EXTENSION));
-    if (pContext)
-    {
-        vboxWddmDevExtZeroinit(pContext, PhysicalDeviceObject);
-        *MiniportDeviceContext = pContext;
-    }
-    else
-    {
-        Status  = STATUS_NO_MEMORY;
-        drprintf(("VBoxVideoWddm: ERROR, failed to create context\n"));
-    }
-
-    dfprintf(("<== "__FUNCTION__ ", status(0x%x), pContext(0x%x)\n", Status, pContext));
+    PDEVICE_EXTENSION pDevExt;
+
+    WCHAR RegKeyBuf[512];
+    ULONG cbRegKeyBuf = sizeof (RegKeyBuf);
+
+    Status = IoGetDeviceProperty (PhysicalDeviceObject,
+                                  DevicePropertyDriverKeyName,
+                                  cbRegKeyBuf,
+                                  RegKeyBuf,
+                                  &cbRegKeyBuf);
+    Assert(Status == STATUS_SUCCESS);
+    if (Status == STATUS_SUCCESS)
+    {
+        WCHAR VideoGuidBuf[512];
+        ULONG cbVideoGuidBuf = sizeof (VideoGuidBuf);
+
+        Status = vboxWddmRegQueryVideoGuidString(cbVideoGuidBuf, VideoGuidBuf, &cbVideoGuidBuf);
+        Assert(Status == STATUS_SUCCESS);
+        if (Status == STATUS_SUCCESS)
+        {
+            pDevExt = (PDEVICE_EXTENSION)vboxWddmMemAllocZero(VBOXWDDM_ROUNDBOUND(sizeof (DEVICE_EXTENSION), 8) + cbRegKeyBuf + cbVideoGuidBuf);
+            if (pDevExt)
+            {
+                PWCHAR pName = (PWCHAR)(((uint8_t*)pDevExt) + VBOXWDDM_ROUNDBOUND(sizeof (DEVICE_EXTENSION), 8));
+                memcpy(pName, RegKeyBuf, cbRegKeyBuf);
+                pName += cbRegKeyBuf/2;
+                memcpy(pName, VideoGuidBuf, cbVideoGuidBuf);
+                vboxWddmDevExtZeroinit(pDevExt, PhysicalDeviceObject);
+                *MiniportDeviceContext = pDevExt;
+            }
+            else
+            {
+                Status  = STATUS_NO_MEMORY;
+                drprintf(("VBoxVideoWddm: ERROR, failed to create context\n"));
+            }
+        }
+    }
+
+    dfprintf(("<== "__FUNCTION__ ", Status(0x%x), pDevExt(0x%x)\n", Status, pDevExt));
 
     return Status;
@@ -2181,5 +2123,6 @@
             PVBOXWDDM_ALLOCATION pSrcAlloc = pPrivateData->SrcAllocInfo.pAlloc;
             vboxWddmAssignShadow(pDevExt, pSource, pSrcAlloc, pDstAlloc->SurfDesc.VidPnSourceId);
-            vboxWddmCheckUpdateShadowAddress(pDevExt, pSource, pPrivateData->SrcAllocInfo.segmentIdAlloc, pPrivateData->SrcAllocInfo.offAlloc);
+            vboxWddmCheckUpdateShadowAddress(pDevExt, pSource, pDstAlloc->SurfDesc.VidPnSourceId,
+                    pPrivateData->SrcAllocInfo.segmentIdAlloc, pPrivateData->SrcAllocInfo.offAlloc);
             PVBOXWDDM_DMA_PRESENT_RENDER_FROM_SHADOW pRFS = (PVBOXWDDM_DMA_PRESENT_RENDER_FROM_SHADOW)pPrivateData;
             uint32_t cDMACmdsOutstanding = ASMAtomicReadU32(&pDevExt->cDMACmdsOutstanding);
@@ -2224,5 +2167,6 @@
                                 Assert(pContext->enmType == VBOXWDDM_CONTEXT_TYPE_SYSTEM);
                                 vboxWddmAssignShadow(pDevExt, pSource, pSrcAlloc, pDstAlloc->SurfDesc.VidPnSourceId);
-                                vboxWddmCheckUpdateShadowAddress(pDevExt, pSource, pPrivateData->SrcAllocInfo.segmentIdAlloc, pPrivateData->SrcAllocInfo.offAlloc);
+                                vboxWddmCheckUpdateShadowAddress(pDevExt, pSource,
+                                        pDstAlloc->SurfDesc.VidPnSourceId, pPrivateData->SrcAllocInfo.segmentIdAlloc, pPrivateData->SrcAllocInfo.offAlloc);
                                 if (pBlt->DstRects.UpdateRects.cRects)
                                 {
@@ -3382,5 +3326,5 @@
 #endif
                 /* should not generally happen, but still inform host*/
-                Status = vboxWddmGhDisplaySetInfo(pDevExt, pSource);
+                Status = vboxWddmGhDisplaySetInfo(pDevExt, pSource, pSetVidPnSourceAddress->VidPnSourceId);
                 Assert(Status == STATUS_SUCCESS);
                 if (Status != STATUS_SUCCESS)
@@ -3447,5 +3391,5 @@
                         pSource->offVram = VBOXVIDEOOFFSET_VOID;
 #endif
-                        Status = vboxWddmGhDisplaySetInfo(pDevExt, pSource);
+                        Status = vboxWddmGhDisplaySetInfo(pDevExt, pSource, pSetVidPnSourceVisibility->VidPnSourceId);
                         Assert(Status == STATUS_SUCCESS);
                         if (Status != STATUS_SUCCESS)
@@ -4531,4 +4475,8 @@
             Assert(pCreateContext->Flags.Value <= 2); /* 2 is a GDI context in Win7 */
             pContext->enmType = VBOXWDDM_CONTEXT_TYPE_SYSTEM;
+            for (int i = 0; i < pDevExt->u.primary.cDisplays; ++i)
+            {
+                pDevExt->aSources[i].offVram = VBOXVIDEOOFFSET_VOID;
+            }
         }
         else
