Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/Makefile.kmk
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/Makefile.kmk	(revision 39569)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/Makefile.kmk	(revision 39570)
@@ -176,4 +176,10 @@
     $(PATH_STAGE_LIB)/libWine$(VBOX_SUFF_LIB)
 wined3d_SDKS.amd64    = WINDDKWLH
+ifdef VBOX_WINE_WITH_IPRT
+wined3d_LIBS         += \
+							$(VBOX_LIB_IPRT_GUEST_R3) \
+							$(VBOX_LIB_VBGL_R3)
+wined3d_DEFS         += VBOX_WINE_WITH_IPRT
+endif
 
 ifdef VBOX_WITH_WDDM
@@ -195,10 +201,10 @@
 wined3dwddm_SDKS.amd64     = $(NO_SUCH_VARIABLE)
 #VBOX_WINE_WITH_IPRT is used for debugging currently to enable Assert & stuff
-ifdef VBOX_WINE_WITH_IPRT
-wined3dwddm_LIBS          += \
-							$(VBOX_LIB_IPRT_GUEST_R3) \
-							$(VBOX_LIB_VBGL_R3)
-wined3dwddm_DEFS          += VBOX_WINE_WITH_IPRT
-endif
+#ifdef VBOX_WINE_WITH_IPRT
+#wined3dwddm_LIBS          += \
+							$(VBOX_LIB_IPRT_GUEST_R3) \
+							$(VBOX_LIB_VBGL_R3)
+#wined3dwddm_DEFS          += VBOX_WINE_WITH_IPRT
+#endif
 wined3dwddm_DEFS          += VBOX_WINE_WITH_SINGLE_CONTEXT
 
@@ -253,4 +259,10 @@
 VBoxD3D8_SOURCES.amd64 = vbox/libWineStub/debug.c
 VBoxD3D8_SDKS.amd64    = WINDDKWLH
+ifdef VBOX_WINE_WITH_IPRT
+VBoxD3D8_LIBS         += \
+							$(VBOX_LIB_IPRT_GUEST_R3) \
+							$(VBOX_LIB_VBGL_R3)
+VBoxD3D8_DEFS         += VBOX_WINE_WITH_IPRT
+endif
 
 DLLS += VBoxD3D9
@@ -300,4 +312,10 @@
     $(PATH_STAGE_LIB)/wined3d$(VBOX_SUFF_LIB)
 VBoxD3D9_SDKS.amd64    = WINDDKWLH
+ifdef VBOX_WINE_WITH_IPRT
+VBoxD3D9_LIBS         += \
+							$(VBOX_LIB_IPRT_GUEST_R3) \
+							$(VBOX_LIB_VBGL_R3)
+VBoxD3D9_DEFS         += VBOX_WINE_WITH_IPRT
+endif
 
 ifdef VBOX_WITH_WDDM
@@ -315,14 +333,14 @@
 VBoxD3D9wddm_SOURCES.x86    = $(NO_SUCH_VARIABLE)
 VBoxD3D9wddm_SOURCES.amd64  = $(NO_SUCH_VARIABLE)
-VBoxD3D9wddm_LIBS           = $(PATH_STAGE_LIB)/wined3dwddm$(VBOX_SUFF_LIB)
+VBoxD3D9wddm_LIBS           = $(subst $(PATH_STAGE_LIB)/wined3d$(VBOX_SUFF_LIB),$(PATH_STAGE_LIB)/wined3dwddm$(VBOX_SUFF_LIB),$(VBoxD3D9_LIBS)) 
 VBoxD3D9wddm_LIBS.x86       = $(NO_SUCH_VARIABLE)
 VBoxD3D9wddm_SDKS           = WINDDKWLH
 VBoxD3D9wddm_SDKS.amd64     = $(NO_SUCH_VARIABLE)
-ifdef VBOX_WINE_WITH_IPRT
-VBoxD3D9wddm_LIBS          += \
-							$(VBOX_LIB_IPRT_GUEST_R3) \
-							$(VBOX_LIB_VBGL_R3)
-VBoxD3D9wddm_DEFS          += VBOX_WINE_WITH_IPRT
-endif
+#ifdef VBOX_WINE_WITH_IPRT
+#VBoxD3D9wddm_LIBS          += \
+							$(VBOX_LIB_IPRT_GUEST_R3) \
+							$(VBOX_LIB_VBGL_R3)
+#VBoxD3D9wddm_DEFS          += VBOX_WINE_WITH_IPRT
+#endif
 
 DLLS.amd64 += VBoxD3D9wddm-x86
@@ -348,4 +366,10 @@
     switcher/d3d8.rc
 d3d8_SDKS.amd64    = WINDDKWLH
+ifdef VBOX_WINE_WITH_IPRT
+d3d8_LIBS         += \
+							$(VBOX_LIB_IPRT_GUEST_R3) \
+							$(VBOX_LIB_VBGL_R3)
+d3d8_DEFS         += VBOX_WINE_WITH_IPRT
+endif
 
 DLLS += d3d9
@@ -362,5 +386,10 @@
     switcher/sw_d3d9xpdm.def
 d3d9_SDKS.amd64    = WINDDKWLH
-
+ifdef VBOX_WINE_WITH_IPRT
+d3d9_LIBS         += \
+							$(VBOX_LIB_IPRT_GUEST_R3) \
+							$(VBOX_LIB_VBGL_R3)
+d3d9_DEFS         += VBOX_WINE_WITH_IPRT
+endif
 
 include $(KBUILD_PATH)/subfooter.kmk
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/d3d8_main.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/d3d8_main.c	(revision 39569)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/d3d8_main.c	(revision 39570)
@@ -28,4 +28,5 @@
  * of the LGPL is applied is otherwise unspecified.
  */
+#define VBOX_WINE_DEBUG_DEFINES
 
 #include "config.h"
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/d3d9_main.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/d3d9_main.c	(revision 39569)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/d3d9_main.c	(revision 39570)
@@ -30,4 +30,5 @@
  * of the LGPL is applied is otherwise unspecified.
  */
+#define VBOX_WINE_DEBUG_DEFINES
 
 #include "config.h"
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/device.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/device.c	(revision 39569)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/device.c	(revision 39570)
@@ -233,4 +233,5 @@
             IDirect3D9_Release(d3d);
             *ppobj = NULL;
+            ERR_D3D();
             return E_NOINTERFACE;
         }
@@ -246,4 +247,5 @@
     WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
     *ppobj = NULL;
+    ERR_D3D();
     return E_NOINTERFACE;
 }
@@ -302,4 +304,5 @@
     {
         TRACE("D3D9 device is marked not reset.\n");
+        ERR_D3D();
         return D3DERR_DEVICENOTRESET;
     }
@@ -318,4 +321,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(hr > 0x400000);
     return hr;
 }
@@ -331,4 +335,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -342,4 +347,5 @@
 
     if (NULL == ppD3D9) {
+        ERR_D3D();
         return D3DERR_INVALIDCALL;
     }
@@ -358,4 +364,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -369,8 +376,10 @@
 
     if(NULL == pCaps){
+        ERR_D3D();
         return D3DERR_INVALIDCALL;
     }
     pWineCaps = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WINED3DCAPS));
     if(pWineCaps == NULL){
+        ERR_D3D();
         return D3DERR_INVALIDCALL; /* well this is what MSDN says to return */
     }
@@ -391,4 +400,5 @@
 
     TRACE("Returning %p %p\n", This, pCaps);
+    ASSERT_D3D(hrc == S_OK);
     return hrc;
 }
@@ -406,4 +416,5 @@
     if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format);
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -419,4 +430,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -432,4 +444,5 @@
     if(!pCursorBitmap) {
         WARN("No cursor bitmap, returning WINED3DERR_INVALIDCALL\n");
+        ERR_D3D();
         return WINED3DERR_INVALIDCALL;
     }
@@ -439,4 +452,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -619,4 +633,5 @@
         wined3d_mutex_unlock();
 
+        ERR_D3D();
         return WINED3DERR_INVALIDCALL;
     }
@@ -662,4 +677,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -677,4 +693,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
  }
@@ -696,4 +713,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(rc == S_OK);
     return rc;
 }
@@ -708,4 +726,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -721,4 +740,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -866,4 +886,5 @@
     {
         ERR("Failed to allocate texture memory.\n");
+        ERR_D3D();
         return D3DERR_OUTOFVIDEOMEMORY;
     }
@@ -874,4 +895,5 @@
         WARN("Failed to initialize texture, hr %#x.\n", hr);
         HeapFree(GetProcessHeap(), 0, object);
+        ERR_D3D();
         return hr;
     }
@@ -901,4 +923,5 @@
     {
         ERR("Failed to allocate volume texture memory.\n");
+        ERR_D3D();
         return D3DERR_OUTOFVIDEOMEMORY;
     }
@@ -907,4 +930,5 @@
     if (FAILED(hr))
     {
+        ERR_D3D();
         WARN("Failed to initialize volume texture, hr %#x.\n", hr);
         HeapFree(GetProcessHeap(), 0, object);
@@ -937,4 +961,5 @@
     {
         ERR("Failed to allocate cube texture memory.\n");
+        ERR_D3D();
         return D3DERR_OUTOFVIDEOMEMORY;
     }
@@ -943,4 +968,5 @@
     if (FAILED(hr))
     {
+        ERR_D3D();
         WARN("Failed to initialize cube texture, hr %#x.\n", hr);
         HeapFree(GetProcessHeap(), 0, object);
@@ -968,4 +994,5 @@
     if (!object)
     {
+        ERR_D3D();
         ERR("Failed to allocate buffer memory.\n");
         return D3DERR_OUTOFVIDEOMEMORY;
@@ -975,4 +1002,5 @@
     if (FAILED(hr))
     {
+        ERR_D3D();
         WARN("Failed to initialize vertex buffer, hr %#x.\n", hr);
         HeapFree(GetProcessHeap(), 0, object);
@@ -999,4 +1027,5 @@
     if (!object)
     {
+        ERR_D3D();
         ERR("Failed to allocate buffer memory.\n");
         return D3DERR_OUTOFVIDEOMEMORY;
@@ -1006,4 +1035,5 @@
     if (FAILED(hr))
     {
+        ERR_D3D();
         WARN("Failed to initialize index buffer, hr %#x.\n", hr);
         HeapFree(GetProcessHeap(), 0, object);
@@ -1038,4 +1068,5 @@
     if (!object)
     {
+        ERR_D3D();
         FIXME("Failed to allocate surface memory.\n");
         return D3DERR_OUTOFVIDEOMEMORY;
@@ -1051,4 +1082,5 @@
     if (FAILED(hr))
     {
+        ERR_D3D();
         WARN("Failed to initialize surface, hr %#x.\n", hr);
         HeapFree(GetProcessHeap(), 0, object);
@@ -1081,4 +1113,5 @@
             );
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -1103,4 +1136,5 @@
             );
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -1118,4 +1152,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -1131,4 +1166,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -1147,4 +1183,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -1161,4 +1198,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -1178,4 +1216,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -1205,4 +1244,5 @@
         wined3d_mutex_unlock();
         WARN("Surface is not a render target, or not a stand-alone D3DPOOL_DEFAULT surface\n");
+        ERR_D3D();
         return D3DERR_INVALIDCALL;
     }
@@ -1214,4 +1254,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -1224,4 +1265,5 @@
 
     if(Pool == D3DPOOL_MANAGED ){
+        ERR_D3D();
         FIXME("Attempting to create a managed offscreen plain surface\n");
         return D3DERR_INVALIDCALL;
@@ -1243,4 +1285,5 @@
             );
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -1256,4 +1299,5 @@
     if (RenderTargetIndex >= D3D9_MAX_SIMULTANEOUS_RENDERTARGETS)
     {
+        ERR_D3D();
         WARN("Invalid index %u specified.\n", RenderTargetIndex);
         return D3DERR_INVALIDCALL;
@@ -1264,4 +1308,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -1275,4 +1320,5 @@
 
     if (ppRenderTarget == NULL) {
+        ERR_D3D();
         return D3DERR_INVALIDCALL;
     }
@@ -1280,4 +1326,5 @@
     if (RenderTargetIndex >= D3D9_MAX_SIMULTANEOUS_RENDERTARGETS)
     {
+        ERR_D3D();
         WARN("Invalid index %u specified.\n", RenderTargetIndex);
         return D3DERR_INVALIDCALL;
@@ -1304,4 +1351,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -1329,4 +1377,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -1340,4 +1389,5 @@
 
     if(ppZStencilSurface == NULL){
+        ERR_D3D();
         return D3DERR_INVALIDCALL;
     }
@@ -1355,4 +1405,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -1368,4 +1419,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -1381,4 +1433,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -1396,4 +1449,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -1424,4 +1478,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -1438,4 +1493,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -1452,4 +1508,6 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(hr == S_OK);
+
     return hr;
 }
@@ -1466,4 +1524,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -1480,4 +1539,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -1494,4 +1554,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -1508,4 +1569,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -1522,4 +1584,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -1535,4 +1598,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -1548,4 +1612,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -1561,4 +1626,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -1574,4 +1640,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -1587,4 +1654,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -1600,4 +1668,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -1614,4 +1683,5 @@
     if (type != D3DSBT_ALL && type != D3DSBT_PIXELSTATE && type != D3DSBT_VERTEXSTATE)
     {
+        ERR_D3D();
         WARN("Unexpected stateblock type, returning D3DERR_INVALIDCALL.\n");
         return D3DERR_INVALIDCALL;
@@ -1621,4 +1691,5 @@
     if (!object)
     {
+        ERR_D3D();
         ERR("Failed to allocate stateblock memory.\n");
         return E_OUTOFMEMORY;
@@ -1628,4 +1699,5 @@
     if (FAILED(hr))
     {
+        ERR_D3D();
         WARN("Failed to initialize stateblock, hr %#x.\n", hr);
         HeapFree(GetProcessHeap(), 0, object);
@@ -1650,4 +1722,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -1667,4 +1740,5 @@
     if (FAILED(hr))
     {
+        ERR_D3D();
        WARN("IWineD3DDevice_EndStateBlock() failed, hr %#x.\n", hr);
        return hr;
@@ -1674,4 +1748,5 @@
     if (!object)
     {
+        ERR_D3D();
         ERR("Failed to allocate stateblock memory.\n");
         IWineD3DStateBlock_Release(wined3d_stateblock);
@@ -1682,4 +1757,5 @@
     if (FAILED(hr))
     {
+        ERR_D3D();
         WARN("Failed to initialize stateblock, hr %#x.\n", hr);
         IWineD3DStateBlock_Release(wined3d_stateblock);
@@ -1704,4 +1780,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -1717,4 +1794,6 @@
     wined3d_mutex_unlock();
 
+
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -1728,4 +1807,5 @@
 
     if(ppTexture == NULL){
+        ERR_D3D();
         return D3DERR_INVALIDCALL;
     }
@@ -1744,4 +1824,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(rc == S_OK);
     return rc;
 }
@@ -1758,4 +1839,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -1808,4 +1890,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -1821,4 +1904,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -1836,4 +1920,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -1849,4 +1934,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -1862,4 +1948,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -1877,4 +1964,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -1890,4 +1978,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -1903,4 +1992,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -1916,4 +2006,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -1929,4 +2020,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -1942,4 +2034,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -1955,4 +2048,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -1981,4 +2075,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -2012,4 +2107,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -2032,4 +2128,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -2051,4 +2148,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -2072,4 +2170,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -2088,4 +2187,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -2102,4 +2202,5 @@
     if (!declaration)
     {
+        ERR_D3D();
         WARN("Caller passed a NULL declaration, returning D3DERR_INVALIDCALL.\n");
         return D3DERR_INVALIDCALL;
@@ -2109,4 +2210,5 @@
     if (!object)
     {
+        ERR_D3D();
         ERR("Failed to allocate vertex declaration memory.\n");
         return E_OUTOFMEMORY;
@@ -2116,4 +2218,5 @@
     if (FAILED(hr))
     {
+        ERR_D3D();
         WARN("Failed to initialize vertex declaration, hr %#x.\n", hr);
         HeapFree(GetProcessHeap(), 0, object);
@@ -2203,4 +2306,5 @@
     if (!decl)
     {
+        ERR_D3D();
          /* Any situation when this should happen, except out of memory? */
          ERR("Failed to create a converted vertex declaration\n");
@@ -2211,4 +2315,5 @@
     if (FAILED(hr)) ERR("Failed to set vertex declaration\n");
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -2224,4 +2329,5 @@
     if (FAILED(hr))
     {
+        ERR_D3D();
         WARN("Failed to get vertex declaration, %#x\n", hr);
         *pFVF = 0;
@@ -2241,4 +2347,5 @@
     TRACE("Returning FVF %#x\n", *pFVF);
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -2256,4 +2363,5 @@
     if (!object)
     {
+        ERR_D3D();
         ERR("Failed to allocate vertex shader memory.\n");
         return E_OUTOFMEMORY;
@@ -2263,4 +2371,5 @@
     if (FAILED(hr))
     {
+        ERR_D3D();
         WARN("Failed to initialize vertex shader, hr %#x.\n", hr);
         HeapFree(GetProcessHeap(), 0, object);
@@ -2287,4 +2396,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -2299,4 +2409,5 @@
 
     if(pStream == NULL){
+        ERR_D3D();
         return D3DERR_INVALIDCALL;
     }
@@ -2315,4 +2426,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(rc == S_OK);
     return rc;
 }
@@ -2330,4 +2442,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -2343,4 +2456,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -2359,4 +2473,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -2370,4 +2485,5 @@
 
     if(ppIndexData == NULL){
+        ERR_D3D();
         return D3DERR_INVALIDCALL;
     }
@@ -2384,4 +2500,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(rc == S_OK);
     return rc;
 }
@@ -2399,4 +2516,5 @@
     if (!object)
     {
+        ERR_D3D();
         FIXME("Failed to allocate pixel shader memory.\n");
         return E_OUTOFMEMORY;
@@ -2406,4 +2524,5 @@
     if (FAILED(hr))
     {
+        ERR_D3D();
         WARN("Failed to initialize pixel shader, hr %#x.\n", hr);
         HeapFree(GetProcessHeap(), 0, object);
@@ -2428,4 +2547,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -2442,4 +2562,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -2455,4 +2576,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -2470,4 +2592,5 @@
     if (!object)
     {
+        ERR_D3D();
         ERR("Failed to allocate query memory.\n");
         return E_OUTOFMEMORY;
@@ -2477,4 +2600,5 @@
     if (FAILED(hr))
     {
+        ERR_D3D();
         WARN("Failed to initialize query, hr %#x.\n", hr);
         HeapFree(GetProcessHeap(), 0, object);
@@ -2495,4 +2619,5 @@
             iface, width, height, rows, columns);
 
+    ERR_D3D();
     return WINED3DERR_INVALIDCALL;
 }
@@ -2507,4 +2632,5 @@
             dst_descs, operation, offset_x, offset_y);
 
+    ERR_D3D();
     return WINED3DERR_INVALIDCALL;
 }
@@ -2517,4 +2643,5 @@
             iface, src_rect, dst_rect, dst_window_override, dirty_region, flags);
 
+    ERR_D3D();
     return WINED3DERR_INVALIDCALL;
 }
@@ -2524,4 +2651,5 @@
     FIXME("iface %p, priority %p stub!\n", iface, priority);
 
+    ERR_D3D();
     return WINED3DERR_INVALIDCALL;
 }
@@ -2531,4 +2659,5 @@
     FIXME("iface %p, priority %d stub!\n", iface, priority);
 
+    ERR_D3D();
     return WINED3DERR_INVALIDCALL;
 }
@@ -2538,4 +2667,5 @@
     FIXME("iface %p, swapchain_idx %u stub!\n", iface, swapchain_idx);
 
+    ERR_D3D();
     return WINED3DERR_INVALIDCALL;
 }
@@ -2547,4 +2677,5 @@
             iface, resources, resource_count);
 
+    ERR_D3D();
     return WINED3DERR_INVALIDCALL;
 }
@@ -2554,4 +2685,5 @@
     FIXME("iface %p, max_latency %u stub!\n", iface, max_latency);
 
+    ERR_D3D();
     return WINED3DERR_INVALIDCALL;
 }
@@ -2563,4 +2695,5 @@
     *max_latency = 2;
 
+    ERR_D3D();
     return WINED3DERR_INVALIDCALL;
 }
@@ -2570,4 +2703,5 @@
     FIXME("iface %p, dst_window %p stub!\n", iface, dst_window);
 
+    ERR_D3D();
     return WINED3DERR_INVALIDCALL;
 }
@@ -2582,4 +2716,5 @@
             lockable, surface, shared_handle, usage);
 
+    ERR_D3D();
     return WINED3DERR_INVALIDCALL;
 }
@@ -2592,4 +2727,5 @@
             iface, width, height, format, pool, surface, shared_handle, usage);
 
+    ERR_D3D();
     return WINED3DERR_INVALIDCALL;
 }
@@ -2604,4 +2740,5 @@
             discard, surface, shared_handle, usage);
 
+    ERR_D3D();
     return WINED3DERR_INVALIDCALL;
 }
@@ -2612,4 +2749,5 @@
     FIXME("iface %p, present_parameters %p, mode %p stub!\n", iface, present_parameters, mode);
 
+    ERR_D3D();
     return WINED3DERR_INVALIDCALL;
 }
@@ -2620,4 +2758,5 @@
     FIXME("iface %p, swapchain_idx %u, mode %p, rotation %p stub!\n", iface, swapchain_idx, mode, rotation);
 
+    ERR_D3D();
     return WINED3DERR_INVALIDCALL;
 }
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/directx.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/directx.c	(revision 39569)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/directx.c	(revision 39570)
@@ -32,4 +32,6 @@
 #include "d3d9_private.h"
 
+#include <iprt/cdefs.h>
+
 WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
 
@@ -52,8 +54,10 @@
             TRACE("Returning IDirect3D9Ex interface at %p\n", *ppobj);
             IDirect3D9Ex_AddRef((IDirect3D9Ex *)*ppobj);
+            return S_OK;
         } else {
             WARN("Application asks for IDirect3D9Ex, but this instance wasn't created with Direct3DCreate9Ex\n");
             WARN("Returning E_NOINTERFACE\n");
             *ppobj = NULL;
+            ERR_D3D();
             return E_NOINTERFACE;
         }
@@ -62,4 +66,5 @@
     WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
     *ppobj = NULL;
+    ERR_D3D();
     return E_NOINTERFACE;
 }
@@ -102,4 +107,6 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(hr == S_OK);
+
     return hr;
 }
@@ -114,4 +121,6 @@
     hr = IWineD3D_GetAdapterCount(This->WineD3D);
     wined3d_mutex_unlock();
+
+    ASSERT_D3D(hr == S_OK);
 
     return hr;
@@ -145,4 +154,6 @@
     pIdentifier->WHQLLevel = adapter_id.whql_level;
 
+    ASSERT_D3D(hr == S_OK);
+
     return hr;
 }
@@ -156,4 +167,5 @@
     /* Others than that not supported by d3d9, but reported by wined3d for ddraw. Filter them out */
     if(Format != D3DFMT_X8R8G8B8 && Format != D3DFMT_R5G6B5) {
+        ERR_D3D();
         return 0;
     }
@@ -163,4 +175,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -176,5 +189,8 @@
        It's supposed to fail anyway, so no harm returning failure. */
     if(Format != D3DFMT_X8R8G8B8 && Format != D3DFMT_R5G6B5)
+    {
+        ERR_D3D();
         return D3DERR_INVALIDCALL;
+    }
 
     wined3d_mutex_lock();
@@ -185,4 +201,5 @@
     if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format);
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -200,4 +217,5 @@
     if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format);
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -217,4 +235,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -239,4 +258,5 @@
     {
         WARN("D3DFMT_R8G8B8 is not available on windows, returning D3DERR_NOTAVAILABLE\n");
+        ERR_D3D();
         return D3DERR_NOTAVAILABLE;
     }
@@ -258,4 +278,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -276,4 +297,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -294,4 +316,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -309,4 +332,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -372,4 +396,12 @@
 }
 
+#ifndef VBOX_WINE_WITHOUT_LIBWINE
+#define D3DDEVCAPS_FLOATTLVERTEX        0x00000001
+#define D3DPMISCCAPS_FOGINFVF           0x00002000
+#define D3DPRASTERCAPS_SUBPIXEL         0x00000020
+#define D3DPRASTERCAPS_STIPPLE          0x00000200
+#define D3DPTEXTURECAPS_TRANSPARENCY    0x00000008
+#endif
+
 static HRESULT WINAPI IDirect3D9Impl_GetDeviceCaps(LPDIRECT3D9EX iface, UINT Adapter, D3DDEVTYPE DeviceType, D3DCAPS9* pCaps) {
     IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
@@ -400,5 +432,60 @@
     filter_caps(pCaps);
 
+    /* fixup caps  */
+#ifdef VBOX_WITH_WDDM
+    pCaps->Caps2 |= 0x00080000 /*D3DCAPS2_CANRENDERWINDOWED*/;
+    pCaps->Caps2 |= D3DCAPS2_CANSHARERESOURCE;
+    pCaps->DevCaps |= D3DDEVCAPS_FLOATTLVERTEX /* <- must be set according to the docs */
+            /*| D3DDEVCAPS_HWVERTEXBUFFER | D3DDEVCAPS_HWINDEXBUFFER |  D3DDEVCAPS_SUBVOLUMELOCK */;
+    pCaps->PrimitiveMiscCaps |= D3DPMISCCAPS_INDEPENDENTWRITEMASKS
+            | D3DPMISCCAPS_FOGINFVF
+            | D3DPMISCCAPS_SEPARATEALPHABLEND | D3DPMISCCAPS_MRTINDEPENDENTBITDEPTHS;
+    pCaps->RasterCaps |= D3DPRASTERCAPS_SUBPIXEL | D3DPRASTERCAPS_STIPPLE | D3DPRASTERCAPS_ZBIAS | D3DPRASTERCAPS_COLORPERSPECTIVE /* keep */;
+    pCaps->TextureCaps |= D3DPTEXTURECAPS_TRANSPARENCY | D3DPTEXTURECAPS_TEXREPEATNOTSCALEDBYSIZE;
+    pCaps->TextureAddressCaps |= D3DPTADDRESSCAPS_MIRRORONCE;
+    pCaps->VolumeTextureAddressCaps |= D3DPTADDRESSCAPS_MIRRORONCE;
+    pCaps->StencilCaps |= D3DSTENCILCAPS_TWOSIDED;
+    pCaps->DeclTypes |= D3DDTCAPS_FLOAT16_2 | D3DDTCAPS_FLOAT16_4;
+    pCaps->VertexTextureFilterCaps |= D3DPTFILTERCAPS_MINFPOINT | D3DPTFILTERCAPS_MAGFPOINT;
+    pCaps->GuardBandLeft = -8192.;
+    pCaps->GuardBandTop = -8192.;
+    pCaps->GuardBandRight = 8192.;
+    pCaps->GuardBandBottom = 8192.;
+    pCaps->VS20Caps.DynamicFlowControlDepth = 24;
+    pCaps->VS20Caps.NumTemps = D3DVS20_MAX_NUMTEMPS;
+    pCaps->PS20Caps.DynamicFlowControlDepth = 24;
+    pCaps->PS20Caps.NumTemps = D3DVS20_MAX_NUMTEMPS;
+#endif
+    /* workaround for wine not returning InstructionSlots correctly for  shaders v3.0 */
+    if ((pCaps->VertexShaderVersion & 0xff00) == 0x0300)
+    {
+        pCaps->MaxVertexShader30InstructionSlots = RT_MIN(32768, pCaps->MaxVertexShader30InstructionSlots);
+        pCaps->MaxPixelShader30InstructionSlots = RT_MIN(32768, pCaps->MaxPixelShader30InstructionSlots);
+    }
+#if defined(DEBUG)
+    if ((pCaps->VertexShaderVersion & 0xff00) == 0x0300)
+    {
+        ASSERT_D3D(pCaps->MaxVertexShader30InstructionSlots >= 512);
+        ASSERT_D3D(pCaps->MaxVertexShader30InstructionSlots <= 32768);
+        ASSERT_D3D(pCaps->MaxPixelShader30InstructionSlots >= 512);
+        ASSERT_D3D(pCaps->MaxPixelShader30InstructionSlots <= 32768);
+    }
+    else if ((pCaps->VertexShaderVersion & 0xff00) == 0x0200)
+    {
+        ASSERT_D3D(pCaps->MaxVertexShader30InstructionSlots == 0);
+        ASSERT_D3D(pCaps->MaxPixelShader30InstructionSlots == 0);
+    }
+    else
+    {
+        ERR_D3D();
+    }
+#endif
+
+    /* needed for Windows Media Player to work properly */
+    pCaps->Caps |= D3DCAPS_READ_SCANLINE;
+
     TRACE("(%p) returning %p\n", This, pCaps);
+
+    ASSERT_D3D(hrc == S_OK);
     return hrc;
 }
@@ -414,4 +501,5 @@
     wined3d_mutex_unlock();
 
+    ASSERT_D3D(ret);
     return ret;
 }
@@ -432,4 +520,5 @@
     {
         ERR("Failed to allocate device memory.\n");
+        ERR_D3D();
         return E_OUTOFMEMORY;
     }
@@ -438,4 +527,5 @@
     if (FAILED(hr))
     {
+        ERR_D3D();
         WARN("Failed to initialize device, hr %#x.\n", hr);
         HeapFree(GetProcessHeap(), 0, object);
@@ -454,4 +544,5 @@
     FIXME("iface %p, adapter %u, filter %p stub!\n", iface, adapter, filter);
 
+    ERR_D3D();
     return D3DERR_DRIVERINTERNALERROR;
 }
@@ -463,4 +554,5 @@
             iface, adapter, filter, mode_idx, mode);
 
+    ERR_D3D();
     return D3DERR_DRIVERINTERNALERROR;
 }
@@ -517,4 +609,5 @@
     }
 */
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
@@ -531,4 +624,5 @@
     *device = NULL;
 
+    ERR_D3D();
     return D3DERR_DRIVERINTERNALERROR;
 }
@@ -552,4 +646,5 @@
     memcpy(luid, &adapter_id.adapter_luid, sizeof(*luid));
 
+    ASSERT_D3D(hr == S_OK);
     return hr;
 }
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/debug.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/debug.h	(revision 39569)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/debug.h	(revision 39570)
@@ -41,12 +41,10 @@
 #endif
 
-#ifdef VBOX_WITH_WDDM
-# ifdef VBOX_WINE_WITH_IPRT
-#  include <iprt/assert.h>
-# else
-#  define AssertBreakpoint() do { } while (0)
-#  define Assert(_expr) do { } while (0)
-#  define RT_BREAKPOINT()
-# endif
+#ifdef VBOX_WINE_WITH_IPRT
+# include <iprt/assert.h>
+#else
+# define AssertBreakpoint() do { } while (0)
+# define Assert(_expr) do { } while (0)
+# define RT_BREAKPOINT()
 #endif
 
@@ -60,4 +58,36 @@
 
 struct _GUID;
+
+#ifdef DEBUG
+# define VBOX_WINE_DEBUG
+#endif
+
+#ifdef VBOX_WINE_DEBUG
+# ifndef VBOX_WINE_DEBUG_DEFINES
+extern DWORD g_VBoxVDbgBreakOnD3DErr;
+# else
+#  ifdef DEBUG_misha
+#   define _ERR_BREAK_DEFAULT 1
+#  else
+#   define _ERR_BREAK_DEFAULT 0
+#  endif
+DWORD g_VBoxVDbgBreakOnD3DErr = _ERR_BREAK_DEFAULT;
+# endif
+
+# define _ERR_BREAK() Assert(0)
+# define _ERR_ASSERT(_e) Assert((_e))
+# define _ERR_CHECK_BREAK(_t) do { \
+        if (g_VBoxVDbgBreakOn##_t) { _ERR_BREAK(); } \
+    } while (0)
+# define _ERR_CHECK_ASSERT(_t, _e) do { \
+        if (g_VBoxVDbgBreakOn##_t) { _ERR_ASSERT(_e); } \
+    } while (0)
+
+# define ERR_D3D() _ERR_CHECK_BREAK(D3DErr)
+# define ASSERT_D3D(_e) _ERR_CHECK_ASSERT(D3DErr, _e)
+#else
+# define ERR_D3D() do {} while (0)
+# define ASSERT_D3D(_e) do {} while (0)
+#endif /* #ifdef VBOX_WINE_DEBUG */
 
 /*
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/vbox/libWineStub/include/d3d9.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/vbox/libWineStub/include/d3d9.h	(revision 39569)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/vbox/libWineStub/include/d3d9.h	(revision 39570)
@@ -34,4 +34,7 @@
 #endif
 
+
+
+#ifndef VBOX_WINE_WITHOUT_LIBWINE
 #include <stdlib.h>
 
@@ -39,10 +42,15 @@
 #include <objbase.h>
 
-#ifndef __WINESRC__
+# ifndef __WINESRC__
 # include <windows.h>
-#endif
-
+# endif
+#endif
 #include <d3d9types.h>
 #include <d3d9caps.h>
+#ifdef VBOX_WINE_WITHOUT_LIBWINE
+# include <d3dhal.h>
+# include <d3dtypes.h>
+# include <d3dcaps.h>
+#endif
 
 /*****************************************************************************
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/vbox/libWineStub/include/wine/debug.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/vbox/libWineStub/include/wine/debug.h	(revision 39569)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/vbox/libWineStub/include/wine/debug.h	(revision 39570)
@@ -40,13 +40,11 @@
 #endif
 
-#ifdef VBOX_WITH_WDDM
-# ifdef VBOX_WINE_WITH_IPRT
-#  include <iprt/assert.h>
-# else
-#  define AssertBreakpoint() do { } while (0)
-#  define Assert(_expr) do { } while (0)
-#  ifdef DEBUG_misha
-#   include <iprt/cdefs.h>
-#  endif
+#ifdef VBOX_WINE_WITH_IPRT
+# include <iprt/assert.h>
+#else
+# define AssertBreakpoint() do { } while (0)
+# define Assert(_expr) do { } while (0)
+# ifdef DEBUG_misha
+#  include <iprt/cdefs.h>
 # endif
 #endif
@@ -57,4 +55,36 @@
 
 struct _GUID;
+
+#ifdef DEBUG
+# define VBOX_WINE_DEBUG
+#endif
+
+#ifdef VBOX_WINE_DEBUG
+# ifndef VBOX_WINE_DEBUG_DEFINES
+extern DWORD g_VBoxVDbgBreakOnD3DErr;
+# else
+#  ifdef DEBUG_misha
+#   define _ERR_BREAK_DEFAULT 1
+#  else
+#   define _ERR_BREAK_DEFAULT 0
+#  endif
+DWORD g_VBoxVDbgBreakOnD3DErr = _ERR_BREAK_DEFAULT;
+# endif
+
+# define _ERR_BREAK() Assert(0)
+# define _ERR_ASSERT(_e) Assert((_e))
+# define _ERR_CHECK_BREAK(_t) do { \
+        if (g_VBoxVDbgBreakOn##_t) { _ERR_BREAK(); } \
+    } while (0)
+# define _ERR_CHECK_ASSERT(_t, _e) do { \
+        if (g_VBoxVDbgBreakOn##_t) { _ERR_ASSERT(_e); } \
+    } while (0)
+
+# define ERR_D3D() _ERR_CHECK_BREAK(D3DErr)
+# define ASSERT_D3D(_e) _ERR_CHECK_ASSERT(D3DErr, _e)
+#else
+# define ERR_D3D() do {} while (0)
+# define ASSERT_D3D(_e) do {} while (0)
+#endif /* #ifdef VBOX_WINE_DEBUG */
 
 #ifdef inline
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/wined3d_main.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/wined3d_main.c	(revision 39569)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/wined3d_main.c	(revision 39570)
@@ -31,4 +31,5 @@
  * of the LGPL is applied is otherwise unspecified.
  */
+#define VBOX_WINE_DEBUG_DEFINES
 
 #include "config.h"
