Index: trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispD3D.cpp
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispD3D.cpp	(revision 43489)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispD3D.cpp	(revision 43490)
@@ -51,8 +51,23 @@
 # ifdef VBOXDISPPROFILE_DDI_FUNCTION_LOGGER_ENABLE
 
-extern volatile uint32_t g_u322VBoxDispProfileFunctionLoggerIndex = 0;
+class VBoxDispProfileDevicePostProcess
+{
+public:
+    VBoxDispProfileDevicePostProcess(PVBOXWDDMDISP_DEVICE pDevice) :
+        m_pDevice(pDevice)
+    {}
+
+    void postProcess()
+    {
+        if (m_pDevice->pDevice9If)
+            m_pDevice->pAdapter->D3D.D3D.pfnVBoxWineExD3DDev9Finish((IDirect3DDevice9Ex *)m_pDevice->pDevice9If);
+    }
+private:
+    PVBOXWDDMDISP_DEVICE m_pDevice;
+};
 
 //static VBoxDispProfileSet g_VBoxDispProfileDDI("D3D_DDI");
-#  define VBOXDISPPROFILE_DDI_FUNCTION_LOGGER_PROLOGUE(_pObj) VBOXDISPPROFILE_FUNCTION_LOGGER_DEFINE((_pObj)->ProfileDdiFunc)
+#  define VBOXDISPPROFILE_DDI_FUNCTION_LOGGER_PROLOGUE_DEV(_pObj) VBOXDISPPROFILE_FUNCTION_LOGGER_DEFINE((_pObj)->ProfileDdiFunc, VBoxDispProfileDevicePostProcess, VBoxDispProfileDevicePostProcess(_pObj))
+#  define VBOXDISPPROFILE_DDI_FUNCTION_LOGGER_PROLOGUE_BASE(_pObj) VBOXDISPPROFILE_FUNCTION_LOGGER_DEFINE((_pObj)->ProfileDdiFunc, VBoxDispProfileDummyPostProcess, VBoxDispProfileDummyPostProcess())
 #  define VBOXDISPPROFILE_DDI_FUNCTION_LOGGER_DUMP(_pObj) do {\
         (_pObj)->ProfileDdiFunc.dump(_pObj); \
@@ -68,5 +83,5 @@
 
 #  define VBOXDISPPROFILE_DDI_FUNCTION_LOGGER_REPORT_FRAME(_pObj) do { \
-        if (!((_pObj)->ProfileDdiFunc.reportIteration() % 31) && !VBOXVDBG_IS_DWM()) {\
+        if (!((_pObj)->ProfileDdiFunc.reportIteration() % 31) /*&& !VBOXVDBG_IS_DWM()*/) {\
             VBOXDISPPROFILE_DDI_FUNCTION_LOGGER_DUMP(_pObj); \
             VBOXDISPPROFILE_DDI_FUNCTION_LOGGER_RESET(_pObj); \
@@ -75,5 +90,6 @@
 
 # else
-#  define VBOXDISPPROFILE_DDI_FUNCTION_LOGGER_PROLOGUE(_pObj) do {} while(0)
+#  define VBOXDISPPROFILE_DDI_FUNCTION_LOGGER_PROLOGUE_DEV(_pObj) do {} while(0)
+#  define VBOXDISPPROFILE_DDI_FUNCTION_LOGGER_PROLOGUE_BASE(_pObj) do {} while(0)
 #  define VBOXDISPPROFILE_DDI_FUNCTION_LOGGER_DUMP(_pObj) do {} while(0)
 #  define VBOXDISPPROFILE_DDI_FUNCTION_LOGGER_RESET(_pObj) do {} while(0)
@@ -85,5 +101,5 @@
 # ifdef VBOXDISPPROFILE_DDI_STATISTIC_LOGGER_ENABLE
 //static VBoxDispProfileFpsCounter g_VBoxDispFpsDDI(64);
-#  define VBOXDISPPROFILE_DDI_STATISTIC_LOGGER_PROLOGUE(_pObj) VBOXDISPPROFILE_STATISTIC_LOGGER_DEFINE(&(_pObj)->ProfileDdiFps)
+#  define VBOXDISPPROFILE_DDI_STATISTIC_LOGGER_PROLOGUE(_pObj) VBOXDISPPROFILE_STATISTIC_LOGGER_DEFINE(&(_pObj)->ProfileDdiFps, VBoxDispProfileDummyPostProcess, VBoxDispProfileDummyPostProcess())
 #  define VBOXDISPPROFILE_DDI_STATISTIC_LOGGER_DISABLE_CURRENT() do {\
         VBOXDISPPROFILE_STATISTIC_LOGGER_DISABLE_CURRENT();\
@@ -114,6 +130,10 @@
 # endif
 
-# define VBOXDISPPROFILE_FUNCTION_DDI_PROLOGUE(_pObj) \
-        VBOXDISPPROFILE_DDI_FUNCTION_LOGGER_PROLOGUE(_pObj); \
+# define VBOXDISPPROFILE_FUNCTION_DDI_PROLOGUE_DEV(_pObj) \
+        VBOXDISPPROFILE_DDI_FUNCTION_LOGGER_PROLOGUE_DEV(_pObj); \
+        VBOXDISPPROFILE_DDI_STATISTIC_LOGGER_PROLOGUE(_pObj);
+
+# define VBOXDISPPROFILE_FUNCTION_DDI_PROLOGUE_BASE(_pObj) \
+        VBOXDISPPROFILE_DDI_FUNCTION_LOGGER_PROLOGUE_BASE(_pObj); \
         VBOXDISPPROFILE_DDI_STATISTIC_LOGGER_PROLOGUE(_pObj);
 
@@ -128,4 +148,5 @@
     } while (0)
 
+#if 0
 # define VBOXDISPPROFILE_DDI_REPORT_FLUSH(_pDev) do {\
         VBOXDISPPROFILE_DDI_LOG_AND_DISABLE_CURRENT(); \
@@ -133,4 +154,7 @@
         VBOXDISPPROFILE_DDI_FUNCTION_LOGGER_REPORT_FRAME(_pDev); \
     } while (0)
+#else
+# define VBOXDISPPROFILE_DDI_REPORT_FLUSH(_pDev) do {} while (0)
+#endif
 
 # define VBOXDISPPROFILE_DDI_INIT_CMN(_pObj, _name, _cEntries) do { \
@@ -157,5 +181,6 @@
 # define VBOXDISPPROFILE_DDI_INIT_DEV(_pDev) VBOXDISPPROFILE_DDI_INIT_CMN(_pDev, "DDI_Dev", 64)
 #else
-# define VBOXDISPPROFILE_FUNCTION_DDI_PROLOGUE(_pObj) do {} while (0)
+# define VBOXDISPPROFILE_FUNCTION_DDI_PROLOGUE_DEV(_pObj) do {} while (0)
+# define VBOXDISPPROFILE_FUNCTION_DDI_PROLOGUE_BASE(_pObj) do {} while (0)
 # define VBOXDISPPROFILE_DDI_REPORT_FRAME(_pDev) do {} while (0)
 # define VBOXDISPPROFILE_DDI_REPORT_FLUSH(_pDev) do {} while (0)
@@ -175,13 +200,13 @@
 #define VBOXDISP_DDI_PROLOGUE_DEV(_hDevice) \
     VBOXDISP_DDI_PROLOGUE_CMN(); \
-    VBOXDISPPROFILE_FUNCTION_DDI_PROLOGUE((PVBOXWDDMDISP_DEVICE)(_hDevice));
+    VBOXDISPPROFILE_FUNCTION_DDI_PROLOGUE_DEV((PVBOXWDDMDISP_DEVICE)(_hDevice));
 
 #define VBOXDISP_DDI_PROLOGUE_ADP(_hAdapter) \
     VBOXDISP_DDI_PROLOGUE_CMN(); \
-    VBOXDISPPROFILE_FUNCTION_DDI_PROLOGUE((PVBOXWDDMDISP_ADAPTER)(_hAdapter));
+    VBOXDISPPROFILE_FUNCTION_DDI_PROLOGUE_BASE((PVBOXWDDMDISP_ADAPTER)(_hAdapter));
 
 #define VBOXDISP_DDI_PROLOGUE_GLBL() \
     VBOXDISP_DDI_PROLOGUE_CMN(); \
-    VBOXDISPPROFILE_FUNCTION_DDI_PROLOGUE(&g_VBoxDispProfile);
+    VBOXDISPPROFILE_FUNCTION_DDI_PROLOGUE_BASE(&g_VBoxDispProfile);
 
 #ifdef VBOXDISPMP_TEST
Index: trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispD3DIf.cpp
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispD3DIf.cpp	(revision 43489)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispD3DIf.cpp	(revision 43490)
@@ -77,4 +77,18 @@
         {
             WARN(("no VBoxWineExD3DDev9Flush"));
+            break;
+        }
+
+        pD3D->pfnVBoxWineExD3DDev9FlushToHost = (PFNVBOXWINEEXD3DDEV9_FLUSHTOHOST)GetProcAddress(pD3D->hD3DLib, "VBoxWineExD3DDev9FlushToHost");
+        if (!pD3D->pfnVBoxWineExD3DDev9FlushToHost)
+        {
+            WARN(("no VBoxWineExD3DDev9FlushToHost"));
+            break;
+        }
+
+        pD3D->pfnVBoxWineExD3DDev9Finish = (PFNVBOXWINEEXD3DDEV9_FINISH)GetProcAddress(pD3D->hD3DLib, "VBoxWineExD3DDev9Finish");
+        if (!pD3D->pfnVBoxWineExD3DDev9Finish)
+        {
+            WARN(("no VBoxWineExD3DDev9Finish"));
             break;
         }
Index: trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispD3DIf.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispD3DIf.h	(revision 43489)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispD3DIf.h	(revision 43490)
@@ -75,4 +75,8 @@
     PFNVBOXWINEEXD3DSWAPCHAIN9_PRESENT pfnVBoxWineExD3DSwapchain9Present;
 
+    PFNVBOXWINEEXD3DDEV9_FLUSHTOHOST pfnVBoxWineExD3DDev9FlushToHost;
+
+    PFNVBOXWINEEXD3DDEV9_FINISH pfnVBoxWineExD3DDev9Finish;
+
     /* module handle */
     HMODULE hD3DLib;
Index: trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispProfile.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispProfile.h	(revision 43489)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispProfile.h	(revision 43490)
@@ -194,9 +194,16 @@
 };
 
-template<typename T> class VBoxDispProfileScopeLogger
+class VBoxDispProfileDummyPostProcess
 {
 public:
-    VBoxDispProfileScopeLogger(T *pEntry) :
+    void postProcess(){}
+};
+
+template<typename T, typename P> class VBoxDispProfileScopeLogger
+{
+public:
+    VBoxDispProfileScopeLogger(T *pEntry, P PostProcess) :
         m_pEntry(pEntry),
+        m_PostProcess(PostProcess),
         m_bDisable(FALSE)
     {
@@ -226,8 +233,10 @@
     void logStep()
     {
+        m_PostProcess.postProcess();
         uint64_t cNewTime = VBOXDISPPROFILE_GET_TIME_NANO();
         m_pEntry->step(cNewTime - m_cTime);
     }
     T *m_pEntry;
+    P m_PostProcess;
     uint64_t m_cTime;
     BOOL m_bDisable;
@@ -373,16 +382,16 @@
 
 #ifdef VBOXDISPPROFILE_FUNCTION_LOGGER_GLOBAL_PROFILE
-# define VBOXDISPPROFILE_FUNCTION_LOGGER_DEFINE(_p)  \
+# define VBOXDISPPROFILE_FUNCTION_LOGGER_DEFINE(_p, _T, _v)  \
         static VBoxDispProfileEntry * __pVBoxDispProfileEntry = NULL; \
         if (!__pVBoxDispProfileEntry) { __pVBoxDispProfileEntry = _p.alloc(__FUNCTION__); } \
-        VBoxDispProfileScopeLogger<VBoxDispProfileEntry> __vboxDispProfileFunctionLogger(__pVBoxDispProfileEntry);
+        VBoxDispProfileScopeLogger<VBoxDispProfileEntry, _T> __vboxDispProfileFunctionLogger(__pVBoxDispProfileEntry, _v);
 #else
 # ifndef VBOXDISPPROFILE_FUNCTION_LOGGER_INDEX_GEN
 #  error "VBOXDISPPROFILE_FUNCTION_LOGGER_INDEX_GEN should be fedined!"
 # endif
-# define VBOXDISPPROFILE_FUNCTION_LOGGER_DEFINE(_p)  \
+# define VBOXDISPPROFILE_FUNCTION_LOGGER_DEFINE(_p, _T, _v)  \
         static uint32_t __u32VBoxDispProfileIndex = VBOXDISPPROFILE_FUNCTION_LOGGER_INDEX_GEN(); \
         VBoxDispProfileEntry * __pVBoxDispProfileEntry = _p.get(__u32VBoxDispProfileIndex, __FUNCTION__); \
-        VBoxDispProfileScopeLogger<VBoxDispProfileEntry> __vboxDispProfileFunctionLogger(__pVBoxDispProfileEntry);
+        VBoxDispProfileScopeLogger<VBoxDispProfileEntry, _T> __vboxDispProfileFunctionLogger(__pVBoxDispProfileEntry, _v);
 #endif
 
@@ -396,6 +405,6 @@
 
 
-#define VBOXDISPPROFILE_STATISTIC_LOGGER_DEFINE(_p)  \
-        VBoxDispProfileScopeLogger<VBoxDispProfileFpsCounter> __vboxDispProfileStatisticLogger(_p);
+#define VBOXDISPPROFILE_STATISTIC_LOGGER_DEFINE(_p, _T, _v)  \
+        VBoxDispProfileScopeLogger<VBoxDispProfileFpsCounter, _T> __vboxDispProfileStatisticLogger(_p, _v);
 
 //#define VBOXDISPPROFILE_FUNCTION_PROLOGUE(_p) \
