Index: trunk/src/VBox/Additions/WINNT/Graphics/Display/Makefile.kmk
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Display/Makefile.kmk	(revision 32877)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Display/Makefile.kmk	(revision 32889)
@@ -88,4 +88,7 @@
  VBoxDispD3D_DEFS   += VBOX_WDDMDISP_WITH_PROFILE
 endif
+ifdef VBOXWDDM_TEST_UHGSMI
+ VBoxDispD3D_DEFS   += VBOXWDDM_TEST_UHGSMI
+endif
 VBoxDispD3D_SOURCES  = \
 	wddm/VBoxDispD3D.cpp \
Index: trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxDispD3D.cpp
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxDispD3D.cpp	(revision 32877)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxDispD3D.cpp	(revision 32889)
@@ -5364,4 +5364,9 @@
     return hr;
 }
+
+#ifdef VBOXWDDM_TEST_UHGSMI
+int vboxUhgsmiTst(PVBOXUHGSMI pUhgsmi, uint32_t cbBuf, uint32_t cNumCals, uint64_t * pTimeMs);
+#endif
+
 static HRESULT APIENTRY vboxWddmDDevPresent(HANDLE hDevice, CONST D3DDDIARG_PRESENT* pData)
 {
@@ -5374,4 +5379,16 @@
     if (VBOXDISPMODE_IS_3D(pDevice->pAdapter))
     {
+#ifdef VBOXWDDM_TEST_UHGSMI
+        {
+            Assert(0);
+            static uint32_t cCals = 10000;
+            static uint32_t cbData = 8 * 1024 * 1024;
+            uint64_t TimeMs;
+            int rc = vboxUhgsmiTst(&pDevice->Uhgsmi.Base, cbData, cCals, &TimeMs);
+            uint32_t cCPS = (((uint64_t)cCals) * 1000ULL)/TimeMs;
+            Assert(0);
+            vboxVDbgDoMpPrintF(pDevice, "Time : %I64u ms, calls: %d, cps: %d\n", TimeMs, cCals, cCPS);
+        }
+#endif
 #if 1
         PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)pData->hSrcResource;
@@ -7122,54 +7139,59 @@
                     && !pCreateData->PatchLocationListSize)
             {
-                hr = vboxDispCmCtxCreate(pDevice, &pDevice->DefaultContext);
+                hr = vboxUhgsmiD3DInit(&pDevice->Uhgsmi, pDevice);
                 Assert(hr == S_OK);
                 if (hr == S_OK)
                 {
-#ifdef VBOXDISP_EARLYCREATEDEVICE
-                    PVBOXWDDMDISP_RESOURCE pRc = vboxResourceAlloc(2);
-                    Assert(pRc);
-                    if (pRc)
+                    hr = vboxDispCmCtxCreate(pDevice, &pDevice->DefaultContext);
+                    Assert(hr == S_OK);
+                    if (hr == S_OK)
                     {
-                        D3DPRESENT_PARAMETERS params;
-                        memset(&params, 0, sizeof (params));
-//                        params.BackBufferWidth = 640;
-//                        params.BackBufferHeight = 480;
-                        params.BackBufferWidth = 0x400;
-                        params.BackBufferHeight = 0x300;
-                        params.BackBufferFormat = D3DFMT_A8R8G8B8;
-//                        params.BackBufferCount = 0;
-                        params.BackBufferCount = 1;
-                        params.MultiSampleType = D3DMULTISAMPLE_NONE;
-                        params.SwapEffect = D3DSWAPEFFECT_DISCARD;
-    //                    params.hDeviceWindow = hWnd;
-                                    /* @todo: it seems there should be a way to detect this correctly since
-                                     * our vboxWddmDDevSetDisplayMode will be called in case we are using full-screen */
-                        params.Windowed = TRUE;
-                        //            params.EnableAutoDepthStencil = FALSE;
-                        //            params.AutoDepthStencilFormat = D3DFMT_UNKNOWN;
-                        //            params.Flags;
-                        //            params.FullScreen_RefreshRateInHz;
-                        //            params.FullScreen_PresentationInterval;
-
-                        hr = vboxWddmD3DDeviceCreate(pDevice, 0, pRc, &params, TRUE /*BOOL bLockable*/);
-                        Assert(hr == S_OK);
-                        if (hr == S_OK)
-                            break;
-                        vboxResourceFree(pRc);
+    #ifdef VBOXDISP_EARLYCREATEDEVICE
+                        PVBOXWDDMDISP_RESOURCE pRc = vboxResourceAlloc(2);
+                        Assert(pRc);
+                        if (pRc)
+                        {
+                            D3DPRESENT_PARAMETERS params;
+                            memset(&params, 0, sizeof (params));
+    //                        params.BackBufferWidth = 640;
+    //                        params.BackBufferHeight = 480;
+                            params.BackBufferWidth = 0x400;
+                            params.BackBufferHeight = 0x300;
+                            params.BackBufferFormat = D3DFMT_A8R8G8B8;
+    //                        params.BackBufferCount = 0;
+                            params.BackBufferCount = 1;
+                            params.MultiSampleType = D3DMULTISAMPLE_NONE;
+                            params.SwapEffect = D3DSWAPEFFECT_DISCARD;
+        //                    params.hDeviceWindow = hWnd;
+                                        /* @todo: it seems there should be a way to detect this correctly since
+                                         * our vboxWddmDDevSetDisplayMode will be called in case we are using full-screen */
+                            params.Windowed = TRUE;
+                            //            params.EnableAutoDepthStencil = FALSE;
+                            //            params.AutoDepthStencilFormat = D3DFMT_UNKNOWN;
+                            //            params.Flags;
+                            //            params.FullScreen_RefreshRateInHz;
+                            //            params.FullScreen_PresentationInterval;
+
+                            hr = vboxWddmD3DDeviceCreate(pDevice, 0, pRc, &params, TRUE /*BOOL bLockable*/);
+                            Assert(hr == S_OK);
+                            if (hr == S_OK)
+                                break;
+                            vboxResourceFree(pRc);
+                        }
+                        else
+                        {
+                            hr = E_OUTOFMEMORY;
+                        }
+    #else
+    //# define VBOXDISP_TEST_SWAPCHAIN
+    # ifdef VBOXDISP_TEST_SWAPCHAIN
+                        VBOXDISP_D3DEV(pDevice);
+    # endif
+                        break;
+    #endif
+
+                        HRESULT tmpHr = vboxDispCmCtxDestroy(pDevice, &pDevice->DefaultContext);
+                        Assert(tmpHr == S_OK);
                     }
-                    else
-                    {
-                        hr = E_OUTOFMEMORY;
-                    }
-#else
-//# define VBOXDISP_TEST_SWAPCHAIN
-# ifdef VBOXDISP_TEST_SWAPCHAIN
-                    VBOXDISP_D3DEV(pDevice);
-# endif
-                    break;
-#endif
-
-                    HRESULT tmpHr = vboxDispCmCtxDestroy(pDevice, &pDevice->DefaultContext);
-                    Assert(tmpHr == S_OK);
                 }
             }
Index: trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxDispD3D.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxDispD3D.h	(revision 32877)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxDispD3D.h	(revision 32889)
@@ -18,4 +18,5 @@
 #include "VBoxDispD3DIf.h"
 #include "../../Miniport/wddm/VBoxVideoIf.h"
+#include "VBoxUhgsmiDisp.h"
 
 #include <iprt/cdefs.h>
@@ -177,4 +178,5 @@
     D3DVIEWPORT9 ViewPort;
     VBOXWDDMDISP_CONTEXT DefaultContext;
+    VBOXUHGSMI_PRIVATE_D3D Uhgsmi;
 
     CRITICAL_SECTION DirtyAllocListLock;
Index: trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxDispD3DCmn.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxDispD3DCmn.h	(revision 32877)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxDispD3DCmn.h	(revision 32889)
@@ -33,4 +33,5 @@
 #include "../../Miniport/wddm/VBoxVideoIf.h"
 #include "VBoxDispCm.h"
+#include "VBoxUhgsmiDisp.h"
 #include "VBoxDispD3D.h"
 
@@ -41,5 +42,5 @@
 #endif
 
-#if defined(VBOXWDDMDISP_DEBUG) || defined(VBOX_WDDMDISP_WITH_PROFILE)
+#if defined(VBOXWDDMDISP_DEBUG) || defined(VBOX_WDDMDISP_WITH_PROFILE) || defined(VBOXWDDM_TEST_UHGSMI)
 # define VBOXWDDMDISP_DEBUG_PRINT
 #endif
Index: trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxDispMpTst.cpp
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxDispMpTst.cpp	(revision 32877)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxDispMpTst.cpp	(revision 32889)
@@ -16,6 +16,9 @@
 
 #include <iprt/thread.h>
+#include <iprt/err.h>
 
 #include "VBoxDispD3DCmn.h"
+
+#include "VBoxDispProfile.h"
 
 static RTTHREAD g_VBoxDispMpTstThread;
@@ -143,2 +146,52 @@
 }
 
+int vboxUhgsmiTst(PVBOXUHGSMI pUhgsmi, uint32_t cbBuf, uint32_t cNumCals, uint64_t * pTimeMs)
+{
+    PVBOXUHGSMI_BUFFER pBuf;
+    int rc = pUhgsmi->pfnBufferCreate(pUhgsmi, cbBuf, VBOXUHGSMI_SYNCHOBJECT_TYPE_EVENT, NULL, &pBuf);
+    AssertRC(rc);
+    if (RT_SUCCESS(rc))
+    {
+        uint64_t TimeMs = VBOXDISPPROFILE_GET_TIME_MILLI();
+        do
+        {
+            VBOXUHGSMI_BUFFER_LOCK_FLAGS fFlags;
+            fFlags.Value = 0;
+            fFlags.bLockEntire = 1;
+            fFlags.bDiscard = 1;
+
+            void *pvLock;
+            rc = pBuf->pfnLock(pBuf, 0, cbBuf, fFlags, &pvLock);
+            AssertRC(rc);
+            if (!RT_SUCCESS(rc))
+                break;
+
+            rc = pBuf->pfnUnlock(pBuf);
+            AssertRC(rc);
+            if (!RT_SUCCESS(rc))
+                break;
+
+            VBOXUHGSMI_BUFFER_SUBMIT SubmitData;
+            SubmitData.pBuf = pBuf;
+            SubmitData.fFlags.Value = 0;
+            SubmitData.fFlags.bDoNotRetire = 1;
+            SubmitData.fFlags.bEntireBuffer = 1;
+
+            rc = pUhgsmi->pfnBufferSubmitAsynch(pUhgsmi, &SubmitData, 1);
+            AssertRC(rc);
+            if (!RT_SUCCESS(rc))
+                break;
+
+            DWORD dw = WaitForSingleObject(pBuf->hSynch, INFINITE);
+            Assert(dw == WAIT_OBJECT_0);
+            if (dw)
+                break;
+        } while (--cNumCals);
+
+        TimeMs = VBOXDISPPROFILE_GET_TIME_MILLI() - TimeMs;
+        *pTimeMs = TimeMs;
+
+        pBuf->pfnDestroy(pBuf);
+    }
+    return rc;
+}
Index: trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxUhgsmiDisp.cpp
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxUhgsmiDisp.cpp	(revision 32877)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxUhgsmiDisp.cpp	(revision 32889)
@@ -13,5 +13,5 @@
  * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
  */
-#include "VBoxUhgsmiDisp.h"
+#include "VBoxDispD3DCmn.h"
 
 #include <iprt/mem.h>
@@ -54,26 +54,11 @@
 {
     PVBOXUHGSMI_BUFFER_PRIVATE_D3D pBuffer = VBOXUHGSMID3D_GET_BUFFER(pBuf);
-    if (!cbLock)
-    {
-        Assert(0);
-        return VERR_INVALID_PARAMETER;
-    }
-    if (offLock + cbLock > pBuf->cbBuffer)
-    {
-        Assert(0);
-        return VERR_INVALID_PARAMETER;
-    }
-    uint32_t iFirstPage = offLock >> 0x1000;
-    uint32_t iAfterLastPage = (cbLock + 0xfff) >> 0x1000;
-    uint32_t cPages = iAfterLastPage - iFirstPage;
-    uint32_t cBufPages = pBuf->cbBuffer >> 0x1000;
-    Assert(cPages <= (cBufPages));
     D3DDDICB_LOCK DdiLock;
     DdiLock.hAllocation = pBuffer->hAllocation;
     DdiLock.PrivateDriverData = 0;
-    if (cPages == cBufPages)
-    {
-        DdiLock.NumPages = 0;
-        DdiLock.pPages = NULL;
+
+    if (fFlags.bLockEntire)
+    {
+        offLock = 0;
         DdiLock.Flags.Value = 0;
         DdiLock.Flags.LockEntire = 1;
@@ -81,11 +66,39 @@
     else
     {
-        DdiLock.NumPages = cPages;
-        DdiLock.pPages = pBuffer->aLockPageIndices;
-        DdiLock.Flags.Value = 0;
-        for (UINT i = 0, j = iFirstPage; i < cPages; ++i, ++j)
-        {
-            pBuffer->aLockPageIndices[i] = j;
-        }
+        if (!cbLock)
+        {
+            Assert(0);
+            return VERR_INVALID_PARAMETER;
+        }
+        if (offLock + cbLock > pBuf->cbBuffer)
+        {
+            Assert(0);
+            return VERR_INVALID_PARAMETER;
+        }
+
+        uint32_t iFirstPage = offLock >> 0x1000;
+        uint32_t iAfterLastPage = (cbLock + 0xfff) >> 0x1000;
+        uint32_t cPages = iAfterLastPage - iFirstPage;
+        uint32_t cBufPages = pBuf->cbBuffer >> 0x1000;
+        Assert(cPages <= (cBufPages));
+
+        if (cPages == cBufPages)
+        {
+            DdiLock.NumPages = 0;
+            DdiLock.pPages = NULL;
+            DdiLock.Flags.Value = 0;
+            DdiLock.Flags.LockEntire = 1;
+        }
+        else
+        {
+            DdiLock.NumPages = cPages;
+            DdiLock.pPages = pBuffer->aLockPageIndices;
+            DdiLock.Flags.Value = 0;
+            for (UINT i = 0, j = iFirstPage; i < cPages; ++i, ++j)
+            {
+                pBuffer->aLockPageIndices[i] = j;
+            }
+        }
+
     }
     DdiLock.pData = NULL;
@@ -93,5 +106,5 @@
     DdiLock.Flags.WriteOnly = fFlags.bWriteOnly;
     DdiLock.Flags.DonotWait = fFlags.bDonotWait;
-    DdiLock.Flags.Discard = fFlags.bDiscard;
+//    DdiLock.Flags.Discard = fFlags.bDiscard;
 
     HRESULT hr = pBuffer->pDevice->RtCallbacks.pfnLockCb(pBuffer->pDevice->hDevice, &DdiLock);
@@ -99,5 +112,5 @@
     if (hr == S_OK)
     {
-        *pvLock = (void*)(((uint8_t*)DdiLock.pPages) + (offLock & 0xfff));
+        *pvLock = (void*)(((uint8_t*)DdiLock.pData) + (offLock & 0xfff));
         return VINF_SUCCESS;
     }
@@ -217,4 +230,7 @@
             pBuf->pDevice = pPrivate->pDevice;
             pBuf->hAllocation = Buf.DdiAllocInfo.hAllocation;
+
+            *ppBuf = &pBuf->Base;
+
             return VINF_SUCCESS;
         }
@@ -264,6 +280,14 @@
         pAllocationList->DoNotRetireInstance = pBufInfo->fFlags.bDoNotRetire;
         pBufSubmInfo->fSubFlags = pBufInfo->fFlags;
-        pBufSubmInfo->offData = pBufInfo->offData;
-        pBufSubmInfo->cbData = pBufInfo->cbData;
+        if (pBufInfo->fFlags.bEntireBuffer)
+        {
+            pBufSubmInfo->offData = 0;
+            pBufSubmInfo->cbData = pBuffer->Base.cbBuffer;
+        }
+        else
+        {
+            pBufSubmInfo->offData = pBufInfo->offData;
+            pBufSubmInfo->cbData = pBufInfo->cbData;
+        }
 
         ++pAllocationList;
Index: trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxUhgsmiDisp.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxUhgsmiDisp.h	(revision 32877)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxUhgsmiDisp.h	(revision 32889)
@@ -22,7 +22,7 @@
 {
     VBOXUHGSMI Base;
-    PVBOXWDDMDISP_DEVICE pDevice;
+    struct VBOXWDDMDISP_DEVICE *pDevice;
 } VBOXUHGSMI_PRIVATE_D3D, *PVBOXUHGSMI_PRIVATE_D3D;
 
-HRESULT vboxUhgsmiD3DInit(PVBOXUHGSMI_PRIVATE_D3D pHgsmi, PVBOXWDDMDISP_DEVICE pDevice);
+HRESULT vboxUhgsmiD3DInit(PVBOXUHGSMI_PRIVATE_D3D pHgsmi, struct VBOXWDDMDISP_DEVICE *pDevice);
 #endif /* #ifndef ___VBoxUhgsmiDisp_h__ */
