Index: /trunk/src/VBox/Additions/WINNT/Graphics/Video/common/wddm/VBoxMPIf.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Video/common/wddm/VBoxMPIf.h	(revision 49243)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Video/common/wddm/VBoxMPIf.h	(revision 49244)
@@ -478,4 +478,13 @@
     uint64_t hAlloc;
 } VBOXDISPIFESCAPE_SHRC_REF, *PVBOXDISPIFESCAPE_SHRC_REF;
+
+typedef struct VBOXDISPIFESCAPE_SETALLOCHOSTID
+{
+    VBOXDISPIFESCAPE EscapeHdr;
+    int32_t rc;
+    uint32_t hostID;
+    uint64_t hAlloc;
+
+} VBOXDISPIFESCAPE_SETALLOCHOSTID, *PVBOXDISPIFESCAPE_SETALLOCHOSTID;
 
 typedef struct VBOXDISPIFESCAPE_CRHGSMICTLCON_CALL
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxD3DIf.cpp
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxD3DIf.cpp	(revision 49243)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxD3DIf.cpp	(revision 49244)
@@ -868,2 +868,118 @@
 }
 
+int vboxD3DIfSetHostId(PVBOXWDDMDISP_ALLOCATION pAlloc, uint32_t hostID, uint32_t *pHostID)
+{
+    struct VBOXWDDMDISP_RESOURCE *pRc = pAlloc->pRc;
+    PVBOXWDDMDISP_DEVICE pDevice = pRc->pDevice;
+
+    VBOXDISPIFESCAPE_SETALLOCHOSTID SetHostID = {0};
+    SetHostID.EscapeHdr.escapeCode = VBOXESC_SETALLOCHOSTID;
+    SetHostID.hostID = hostID;
+    SetHostID.hAlloc = pAlloc->hAllocation;
+
+    D3DDDICB_ESCAPE DdiEscape = {0};
+    DdiEscape.hContext = pDevice->DefaultContext.ContextInfo.hContext;
+    DdiEscape.hDevice = pDevice->hDevice;
+//    DdiEscape.Flags.Value = 0;
+    DdiEscape.pPrivateDriverData = &SetHostID;
+    DdiEscape.PrivateDriverDataSize = sizeof (SetHostID);
+    HRESULT hr = pDevice->RtCallbacks.pfnEscapeCb(pDevice->pAdapter->hAdapter, &DdiEscape);
+    if (SUCCEEDED(hr))
+    {
+        if (pHostID)
+            *pHostID = SetHostID.EscapeHdr.u32CmdSpecific;
+
+        return SetHostID.rc;
+    }
+    else
+        WARN(("pfnEscapeCb VBOXESC_SETALLOCHOSTID failed hr 0x%x", hr));
+
+    return VERR_GENERAL_FAILURE;
+}
+
+IUnknown* vboxD3DIfCreateSharedPrimary(PVBOXWDDMDISP_ALLOCATION pAlloc)
+{
+    IDirect3DSurface9 *pSurfIf;
+    struct VBOXWDDMDISP_RESOURCE *pRc = pAlloc->pRc;
+    PVBOXWDDMDISP_DEVICE pDevice = pRc->pDevice;
+
+    HRESULT hr = VBoxD3DIfCreateForRc(pRc);
+    if (!SUCCEEDED(hr))
+    {
+        WARN(("VBoxD3DIfCreateForRc failed, hr 0x%x", hr));
+        return NULL;
+    }
+
+    Assert(pAlloc->pD3DIf);
+    Assert(pAlloc->enmD3DIfType == VBOXDISP_D3DIFTYPE_SURFACE);
+    Assert(pAlloc->pRc->RcDesc.fFlags.SharedResource);
+
+    hr = VBoxD3DIfSurfGet(pRc, pAlloc->iAlloc, &pSurfIf);
+    if (!SUCCEEDED(hr))
+    {
+        WARN(("VBoxD3DIfSurfGet failed hr %#x", hr));
+        return NULL;
+    }
+
+    uint32_t hostID, usedHostId;
+    hr = pDevice->pAdapter->D3D.D3D.pfnVBoxWineExD3DSurf9GetHostId(pSurfIf, &hostID);
+    if (SUCCEEDED(hr))
+    {
+        Assert(hostID);
+        int rc = vboxD3DIfSetHostId(pAlloc, hostID, &usedHostId);
+        if (!RT_SUCCESS(rc))
+        {
+            if (rc == VERR_NOT_EQUAL)
+            {
+                WARN(("another hostId % is in use, using it instead", usedHostId));
+                Assert(hostID != usedHostId);
+                Assert(usedHostId);
+                pSurfIf->Release();
+                pSurfIf = NULL;
+                for (UINT i = 0; i < pRc->cAllocations; ++i)
+                {
+                    PVBOXWDDMDISP_ALLOCATION pCurAlloc = &pRc->aAllocations[i];
+                    if (pCurAlloc->pD3DIf)
+                    {
+                        pCurAlloc->pD3DIf->Release();
+                        pCurAlloc->pD3DIf = NULL;
+                    }
+                }
+
+                pAlloc->hSharedHandle = (HANDLE)usedHostId;
+
+                hr = VBoxD3DIfCreateForRc(pRc);
+                if (!SUCCEEDED(hr))
+                {
+                    WARN(("VBoxD3DIfCreateForRc failed, hr 0x%x", hr));
+                    return NULL;
+                }
+
+                hr = VBoxD3DIfSurfGet(pRc, pAlloc->iAlloc, &pSurfIf);
+                if (!SUCCEEDED(hr))
+                {
+                    WARN(("VBoxD3DIfSurfGet failed hr %#x", hr));
+                    return NULL;
+                }
+            }
+            else
+            {
+                WARN(("vboxD3DIfSetHostId failed %#x, ignoring", hr));
+                hr = S_OK;
+                hostID = 0;
+                usedHostId = 0;
+            }
+        }
+        else
+        {
+            Assert(hostID == usedHostId);
+        }
+
+        pSurfIf->Release();
+        pSurfIf = NULL;
+    }
+    else
+        WARN(("pfnVBoxWineExD3DSurf9GetHostId failed, hr 0x%x", hr));
+
+    return pAlloc->pD3DIf;
+}
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxD3DIf.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxD3DIf.h	(revision 49243)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxD3DIf.h	(revision 49244)
@@ -41,6 +41,9 @@
 void VBoxD3DIfLockUnlockMemSynch(struct VBOXWDDMDISP_ALLOCATION *pAlloc, D3DLOCKED_RECT *pLockInfo, RECT *pRect, bool bToLockInfo);
 
+IUnknown* vboxD3DIfCreateSharedPrimary(PVBOXWDDMDISP_ALLOCATION pAlloc);
+
+
 /* NOTE: does NOT increment a ref counter! NO Release needed!! */
-DECLINLINE(IUnknown*) VBoxD3DIfGet(PVBOXWDDMDISP_ALLOCATION pAlloc)
+DECLINLINE(IUnknown*) vboxD3DIfGet(PVBOXWDDMDISP_ALLOCATION pAlloc)
 {
     if (pAlloc->pD3DIf)
@@ -53,15 +56,5 @@
     }
 
-    HRESULT hr = VBoxD3DIfCreateForRc(pAlloc->pRc);
-    if (!SUCCEEDED(hr))
-    {
-        WARN(("VBoxD3DIfCreateForRc failed, hr 0x%x", hr));
-        return NULL;
-    }
-
-    Assert(pAlloc->pD3DIf);
-    Assert(pAlloc->enmD3DIfType == VBOXDISP_D3DIFTYPE_SURFACE);
-
-    return pAlloc->pD3DIf;
+    return vboxD3DIfCreateSharedPrimary(pAlloc);
 }
 
@@ -73,5 +66,5 @@
     Assert(pRc->cAllocations > iAlloc);
     *ppSurf = NULL;
-    IUnknown* pD3DIf = VBoxD3DIfGet(&pRc->aAllocations[iAlloc]);
+    IUnknown* pD3DIf = vboxD3DIfGet(&pRc->aAllocations[iAlloc]);
 
     switch (pRc->aAllocations[0].enmD3DIfType)
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispD3D.cpp
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispD3D.cpp	(revision 49243)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispD3D.cpp	(revision 49244)
@@ -5748,5 +5748,6 @@
             pRc->RcDesc.MultisampleQuality = 0;
             pRc->RcDesc.MipLevels = 0;
-            pRc->RcDesc.Fvf;
+            /*pRc->RcDesc.Fvf;*/
+            pRc->RcDesc.fFlags.SharedResource = 1;
 
             if (pData->NumAllocations != 1)
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPCr.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPCr.h	(revision 49243)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPCr.h	(revision 49244)
@@ -236,5 +236,5 @@
 
 #define VBOXMP_CRCMD_HEADER_SIZE sizeof (CRMessageOpcodes)
-/* last +4 below is 4-aligned comand opcode size (i.e. ((1 + 3) & ~3)) */
+/* last +4 below is 4-aligned command opcode size (i.e. ((1 + 3) & ~3)) */
 #define VBOXMP_CRCMD_SIZE_WINDOWPOSITION (20 + 4)
 #define VBOXMP_CRCMD_SIZE_WINDOWVISIBLEREGIONS(_cRects) (16 + (_cRects) * 4 * sizeof (GLint) + 4)
@@ -243,4 +243,9 @@
 #define VBOXMP_CRCMD_SIZE_WINDOWSIZE (20 + 4)
 #define VBOXMP_CRCMD_SIZE_GETCHROMIUMPARAMETERVCR (36 + 4)
+#define VBOXMP_CRCMD_SIZE_CHROMIUMPARAMETERICR (16 + 4)
+#define VBOXMP_CRCMD_SIZE_WINDOWCREATE (256 + 28 + 4)
+#define VBOXMP_CRCMD_SIZE_WINDOWDESTROY (12 + 4)
+#define VBOXMP_CRCMD_SIZE_CREATECONTEXT (256 + 32 + 4)
+#define VBOXMP_CRCMD_SIZE_DESTROYCONTEXT (12 + 4)
 
 #endif /* #ifndef ___VBoxMPCr_h__ */
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPTypes.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPTypes.h	(revision 49243)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPTypes.h	(revision 49244)
@@ -108,4 +108,5 @@
     VBOXWDDM_ADDR Addr;
     uint32_t hostID;
+    uint32_t cHostIDRefs;
     struct VBOXWDDM_SWAPCHAIN *pSwapchain;
 } VBOXWDDM_ALLOC_DATA, *PVBOXWDDM_ALLOC_DATA;
@@ -320,4 +321,5 @@
     uint32_t cShRcRefs;
     uint32_t cOpens;
+    uint32_t cHostIDRefs;
 } VBOXWDDM_OPENALLOCATION, *PVBOXWDDM_OPENALLOCATION;
 
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPVdma.cpp
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPVdma.cpp	(revision 49243)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPVdma.cpp	(revision 49244)
@@ -897,4 +897,43 @@
 }
 
+typedef struct VBOXMP_CRHGSMIMGR
+{
+    VBOXMP_CRPACKER CrPacker;
+    void *pvCommandBuffer;
+} VBOXMP_CRHGSMIMGR;
+
+DECLINLINE(CRPackContext*) vboxVdmaCrHmGetPackContext(VBOXMP_CRHGSMIMGR *pMgr)
+{
+    return &pMgr->CrPacker.CrPacker;
+}
+
+NTSTATUS vboxVdmaCrHmCreate(PVBOXMP_DEVEXT pDevExt, VBOXMP_CRHGSMIMGR *pMgr, uint32_t cbCommandBuffer, uint32_t cCommands)
+{
+    pMgr->pvCommandBuffer = VBoxMpCrShgsmiTransportBufAlloc(&pDevExt->CrHgsmiTransport, cbCommandBuffer);
+    if (!pMgr->pvCommandBuffer)
+    {
+        WARN(("VBoxMpCrShgsmiTransportBufAlloc failed!"));
+        return VERR_OUT_OF_RESOURCES;
+    }
+
+    VBoxMpCrPackerInit(&pMgr->CrPacker);
+
+    VBoxMpCrPackerTxBufferInit(&pMgr->CrPacker, pMgr->pvCommandBuffer, cbCommandBuffer, cCommands);
+
+    return STATUS_SUCCESS;
+}
+
+NTSTATUS vboxVdmaCrHmSubmitWrSync(PVBOXMP_DEVEXT pDevExt, VBOXMP_CRHGSMIMGR *pMgr, uint32_t u32CrConClientID)
+{
+    NTSTATUS Status = vboxVdmaCrRxGenericSync(pDevExt, &pMgr->CrPacker, u32CrConClientID);
+    if (!NT_SUCCESS(Status))
+    {
+        WARN(("vboxVdmaCrRxGenericSync failed Status 0x%x", Status));
+        VBoxMpCrShgsmiTransportBufFree(&pDevExt->CrHgsmiTransport, pMgr->pvCommandBuffer);
+        return Status;
+    }
+
+    return STATUS_SUCCESS;
+}
 #if 0
 NTSTATUS vboxVdmaCrCmdGetChromiumParametervCR(PVBOXMP_DEVEXT pDevExt, uint32_t u32CrConClientID, GLenum target, GLuint index, GLenum type, GLsizei count, GLvoid * values)
@@ -902,30 +941,113 @@
     uint32_t cbCommandBuffer = VBOXMP_CRCMD_HEADER_SIZE + VBOXMP_CRCMD_SIZE_GETCHROMIUMPARAMETERVCR;
     uint32_t cCommands = 1;
-    void *pvCommandBuffer = VBoxMpCrShgsmiTransportBufAlloc(&pDevExt->CrHgsmiTransport, cbCommandBuffer);
-    if (!pvCommandBuffer)
-    {
-        WARN(("VBoxMpCrShgsmiTransportBufAlloc failed!"));
-        return VERR_OUT_OF_RESOURCES;
-    }
-
-    VBOXMP_CRPACKER CrPacker;
-    VBoxMpCrPackerInit(&CrPacker);
-
-    VBoxMpCrPackerTxBufferInit(&CrPacker, pvCommandBuffer, cbCommandBuffer, cCommands);
+
+    VBOXMP_CRHGSMIMGR Mgr;
+    NTSTATUS Status = vboxVdmaCrHmCreate(pDevExt, &Mgr, cbCommandBuffer, cCommands);
+    if (!NT_SUCCESS(Status))
+    {
+        WARN(("vboxVdmaCrHmCreate failed Status 0x%x", Status));
+        return Status;
+    }
 
     int dummy = 1;
 
-    crPackGetChromiumParametervCR(&CrPacker.CrPacker, target, index, type, count, values, &dummy);
-
-
-    NTSTATUS Status = vboxVdmaCrRxGenericSync(pDevExt, &CrPacker, u32CrConClientID);
+    crPackGetChromiumParametervCR(vboxVdmaCrHmGetPackContext(&Mgr), target, index, type, count, values, &dummy);
+
+    Status = vboxVdmaCrHmSubmitWrSync(pDevExt, &Mgr, u32CrConClientID);
     if (!NT_SUCCESS(Status))
     {
-        WARN(("vboxVdmaCrRxGenericSync failed Status 0x%x", Status));
-        VBoxMpCrShgsmiTransportBufFree(&pDevExt->CrHgsmiTransport, pvCommandBuffer);
+        WARN(("vboxVdmaCrHmSubmitWrSync failed Status 0x%x", Status));
         return Status;
     }
 
-
+    return STATUS_SUCCESS;
+}
+
+static NTSTATUS vboxVdmaCrCmdCreateContext(PVBOXMP_DEVEXT pDevExt, int32_t visualBits, int32_t *pi32CtxID)
+{
+    uint32_t cbCommandBuffer = VBOXMP_CRCMD_HEADER_SIZE + VBOXMP_CRCMD_SIZE_CREATECONTEXT;
+    uint32_t cCommands = 1;
+
+    VBOXMP_CRHGSMIMGR Mgr;
+    NTSTATUS Status = vboxVdmaCrHmCreate(pDevExt, &Mgr, cbCommandBuffer, cCommands);
+    if (!NT_SUCCESS(Status))
+    {
+        WARN(("vboxVdmaCrHmCreate failed Status 0x%x", Status));
+        return Status;
+    }
+
+    int dummy = 1;
+
+    crPackCreateContext(&CrPacker.CrPacker, "", visualBits, 0, &pi32CtxID, &dummy);
+
+    Status = vboxVdmaCrHmSubmitWrSync(pDevExt, &Mgr, u32CrConClientID);
+    if (!NT_SUCCESS(Status))
+    {
+        WARN(("vboxVdmaCrHmSubmitWrSync failed Status 0x%x", Status));
+        return Status;
+    }
+
+    return STATUS_SUCCESS;
+}
+
+static NTSTATUS vboxVdmaCrCmdWindowCreate(PVBOXMP_DEVEXT pDevExt, int32_t visualBits, int32_t *pi32WinID)
+{
+    uint32_t cbCommandBuffer = VBOXMP_CRCMD_HEADER_SIZE + VBOXMP_CRCMD_SIZE_WINDOWCREATE;
+    uint32_t cCommands = 1;
+
+    VBOXMP_CRHGSMIMGR Mgr;
+    NTSTATUS Status = vboxVdmaCrHmCreate(pDevExt, &Mgr, cbCommandBuffer, cCommands);
+    if (!NT_SUCCESS(Status))
+    {
+        WARN(("vboxVdmaCrHmCreate failed Status 0x%x", Status));
+        return Status;
+    }
+
+    int dummy = 1;
+
+    crPackWindowCreate(&CrPacker.CrPacker, "", visualBits, 0, &pi32CtxID, &dummy);
+
+    Status = vboxVdmaCrHmSubmitWrSync(pDevExt, &Mgr, u32CrConClientID);
+    if (!NT_SUCCESS(Status))
+    {
+        WARN(("vboxVdmaCrHmSubmitWrSync failed Status 0x%x", Status));
+        return Status;
+    }
+
+    return STATUS_SUCCESS;
+}
+
+static NTSTATUS vboxVdmaCrCtlGetDefaultCtxId(PVBOXMP_DEVEXT pDevExt, int32_t *pi32CtxID)
+{
+    if (!pDevExt->i32CrConDefaultCtxID)
+    {
+        if (!pDevExt->f3DEnabled)
+        {
+            WARN(("3D disabled, should not be here!"));
+            return STATUS_UNSUCCESSFUL;
+        }
+
+        uint32_t u32ClienID;
+        NTSTATUS Status = vboxVdmaCrCtlGetDefaultClientId(pDevExt, &u32ClienID);
+        if (!NT_SUCCESS(Status))
+        {
+            WARN(("vboxVdmaCrCtlGetDefaultClientId failed, Status %#x", Status));
+            return Status;
+        }
+
+        Status = vboxVdmaCrCmdWindowCreate(PVBOXMP_DEVEXT pDevExt, int32_t visualBits, int32_t *pi32WinID)
+
+        VBOXMP_CRPACKER CrPacker;
+        VBoxMpCrPackerInit(&CrPacker);
+
+        int rc = VBoxMpCrCtlConConnect(&pDevExt->CrCtlCon, CR_PROTOCOL_VERSION_MAJOR, CR_PROTOCOL_VERSION_MINOR, &pDevExt->u32CrConDefaultClientID);
+        if (!RT_SUCCESS(rc))
+        {
+            WARN(("VBoxMpCrCtlConConnect failed, rc %d", rc));
+            return STATUS_UNSUCCESSFUL;
+        }
+    }
+
+    *pi32CtxID = pDevExt->i32CrConDefaultCtxID;
     return STATUS_SUCCESS;
 }
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPWddm.cpp
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPWddm.cpp	(revision 49243)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPWddm.cpp	(revision 49244)
@@ -57,4 +57,22 @@
 }
 
+DECLINLINE(void) VBoxWddmOaHostIDReleaseLocked(PVBOXWDDM_OPENALLOCATION pOa)
+{
+    Assert(pOa->cHostIDRefs);
+    PVBOXWDDM_ALLOCATION pAllocation = pOa->pAllocation;
+    Assert(pAllocation->AllocData.cHostIDRefs >= pOa->cHostIDRefs);
+    Assert(pAllocation->AllocData.hostID);
+    --pOa->cHostIDRefs;
+    --pAllocation->AllocData.cHostIDRefs;
+    if (!pAllocation->AllocData.cHostIDRefs)
+        pAllocation->AllocData.hostID = 0;
+}
+
+DECLINLINE(void) VBoxWddmOaHostIDCheckReleaseLocked(PVBOXWDDM_OPENALLOCATION pOa)
+{
+    if (pOa->cHostIDRefs)
+        VBoxWddmOaHostIDReleaseLocked(pOa);
+}
+
 DECLINLINE(void) VBoxWddmOaRelease(PVBOXWDDM_OPENALLOCATION pOa)
 {
@@ -63,4 +81,5 @@
     KeAcquireSpinLock(&pAllocation->OpenLock, &OldIrql);
     Assert(pAllocation->cOpens);
+    VBoxWddmOaHostIDCheckReleaseLocked(pOa);
     --pAllocation->cOpens;
     uint32_t cOpens = --pOa->cOpens;
@@ -97,4 +116,45 @@
     KeReleaseSpinLock(&pAllocation->OpenLock, OldIrql);
     return pOa;
+}
+
+DECLINLINE(int) VBoxWddmOaSetHostID(PVBOXWDDM_DEVICE pDevice, PVBOXWDDM_ALLOCATION pAllocation, uint32_t hostID, uint32_t *pHostID)
+{
+    PVBOXWDDM_OPENALLOCATION pOa;
+    KIRQL OldIrql;
+    int rc = VINF_SUCCESS;
+    KeAcquireSpinLock(&pAllocation->OpenLock, &OldIrql);
+    pOa = VBoxWddmOaSearchLocked(pDevice, pAllocation);
+    if (!pOa)
+    {
+        KeReleaseSpinLock(&pAllocation->OpenLock, OldIrql);;
+        WARN(("no open allocation!"));
+        return VERR_INVALID_STATE;
+    }
+
+    if (hostID)
+    {
+        if (pAllocation->AllocData.hostID == 0)
+        {
+            pAllocation->AllocData.hostID = hostID;
+        }
+        else if (pAllocation->AllocData.hostID != hostID)
+        {
+            WARN(("hostID differ: alloc(%d), trying to assign(%d)", pAllocation->AllocData.hostID, hostID));
+            hostID = pAllocation->AllocData.hostID;
+            rc = VERR_NOT_EQUAL;
+        }
+
+        ++pAllocation->AllocData.cHostIDRefs;
+        ++pOa->cHostIDRefs;
+    }
+    else
+        VBoxWddmOaHostIDCheckReleaseLocked(pOa);
+
+    KeReleaseSpinLock(&pAllocation->OpenLock, OldIrql);
+
+    if (pHostID)
+        *pHostID = hostID;
+
+    return rc;
 }
 
@@ -4041,8 +4101,53 @@
                 break;
             }
+            case VBOXESC_SETALLOCHOSTID:
+            {
+                PVBOXWDDM_DEVICE pDevice = (PVBOXWDDM_DEVICE)pEscape->hDevice;
+                if (!pDevice)
+                {
+                    WARN(("VBOXESC_SETALLOCHOSTID called without no device specified, failing"));
+                    Status = STATUS_INVALID_PARAMETER;
+                    break;
+                }
+
+                if (pEscape->PrivateDriverDataSize != sizeof (VBOXDISPIFESCAPE_SETALLOCHOSTID))
+                {
+                    WARN(("invalid buffer size for VBOXDISPIFESCAPE_SHRC_REF, was(%d), but expected (%d)",
+                            pEscape->PrivateDriverDataSize, sizeof (VBOXDISPIFESCAPE_SHRC_REF)));
+                    Status = STATUS_INVALID_PARAMETER;
+                    break;
+                }
+
+                PVBOXDISPIFESCAPE_SETALLOCHOSTID pSetHostID = (PVBOXDISPIFESCAPE_SETALLOCHOSTID)pEscapeHdr;
+                PVBOXWDDM_ALLOCATION pAlloc = vboxWddmGetAllocationFromHandle(pDevExt, (D3DKMT_HANDLE)pSetHostID->hAlloc);
+                if (!pAlloc)
+                {
+                    WARN(("failed to get allocation from handle"));
+                    Status = STATUS_INVALID_PARAMETER;
+                    break;
+                }
+
+                if (pAlloc->enmType != VBOXWDDM_ALLOC_TYPE_STD_SHAREDPRIMARYSURFACE)
+                {
+                    WARN(("setHostID: invalid allocation type: %d", pAlloc->enmType));
+                    Status = STATUS_INVALID_PARAMETER;
+                    break;
+                }
+
+                pSetHostID->rc = VBoxWddmOaSetHostID(pDevice, pAlloc, pSetHostID->hostID, &pSetHostID->EscapeHdr.u32CmdSpecific);
+                Status = STATUS_SUCCESS;
+                break;
+            }
             case VBOXESC_SHRC_ADDREF:
             case VBOXESC_SHRC_RELEASE:
             {
                 PVBOXWDDM_DEVICE pDevice = (PVBOXWDDM_DEVICE)pEscape->hDevice;
+                if (!pDevice)
+                {
+                    WARN(("VBOXESC_SHRC_ADDREF|VBOXESC_SHRC_RELEASE called without no device specified, failing"));
+                    Status = STATUS_INVALID_PARAMETER;
+                    break;
+                }
+
                 /* query whether the allocation represanted by the given [wine-generated] shared resource handle still exists */
                 if (pEscape->PrivateDriverDataSize != sizeof (VBOXDISPIFESCAPE_SHRC_REF))
@@ -5002,7 +5107,6 @@
     if (pOpenAllocation->PrivateDriverSize)
     {
-        Assert(pOpenAllocation->PrivateDriverSize == sizeof (VBOXWDDM_RCINFO));
         Assert(pOpenAllocation->pPrivateDriverData);
-        if (pOpenAllocation->PrivateDriverSize >= sizeof (VBOXWDDM_RCINFO))
+        if (pOpenAllocation->PrivateDriverSize == sizeof (VBOXWDDM_RCINFO))
         {
             pRcInfo = (PVBOXWDDM_RCINFO)pOpenAllocation->pPrivateDriverData;
@@ -5010,5 +5114,8 @@
         }
         else
+        {
+            WARN(("Invalid PrivateDriverSize %d", pOpenAllocation->PrivateDriverSize));
             Status = STATUS_INVALID_PARAMETER;
+        }
     }
 
Index: /trunk/src/VBox/Additions/WINNT/include/VBoxDisplay.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/include/VBoxDisplay.h	(revision 49243)
+++ /trunk/src/VBox/Additions/WINNT/include/VBoxDisplay.h	(revision 49244)
@@ -39,4 +39,5 @@
 # define VBOXESC_SETCTXHOSTID               0xABCD9012
 # define VBOXESC_CONFIGURETARGETS           0xABCD9013
+# define VBOXESC_SETALLOCHOSTID             0xABCD9014
 #endif /* #ifdef VBOX_WITH_WDDM */
 
