Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/resource.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/resource.c	(revision 31885)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/resource.c	(revision 31936)
@@ -66,16 +66,16 @@
         resource->heapMemory = NULL;
     }
-    else if (pool == WINED3DPOOL_DEFAULT && shared_handle)
-    {
-        resource->allocatedMemory = NULL;
-        resource->heapMemory = NULL;
-        resource->sharerc_handle = shared_handle;
-        resource->sharerc_flags = VBOXSHRC_F_SHARED;
-        if (*shared_handle)
-            resource->sharerc_flags |= VBOXSHRC_F_SHARED_OPENED;
-    }
     else
 #endif
     {
+#ifdef VBOXWDDM
+        if (pool == WINED3DPOOL_DEFAULT && shared_handle)
+        {
+            resource->sharerc_handle = *shared_handle;
+            resource->sharerc_flags = VBOXSHRC_F_SHARED;
+            if (*shared_handle)
+                resource->sharerc_flags |= VBOXSHRC_F_SHARED_OPENED;
+        }
+#endif
         if (size)
         {
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/surface.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/surface.c	(revision 31885)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/surface.c	(revision 31936)
@@ -495,4 +495,11 @@
 {
     IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
+
+#if defined(DEBUG_misha) && defined (VBOXWDDM)
+    if (VBOXSHRC_IS_SHARED(This))
+    {
+        Assert(0);
+    }
+#endif
 
     This->Flags &= ~(SFLAG_ALLOCATED | SFLAG_SRGBALLOCATED);
@@ -887,14 +894,19 @@
     }
 
-    if (format_desc->Flags & WINED3DFMT_FLAG_COMPRESSED && mem)
-    {
-        GL_EXTCALL(glCompressedTexImage2DARB(This->texture_target, This->texture_level,
-                internal, width, height, 0, This->resource.size, mem));
-    }
-    else
-    {
-        glTexImage2D(This->texture_target, This->texture_level,
-                internal, width, height, 0, format_desc->glFormat, format_desc->glType, mem);
-        checkGLcall("glTexImage2D");
+#ifdef VBOXWDDM
+    if (!VBOXSHRC_IS_SHARED_OPENED(This))
+#endif
+    {
+        if (format_desc->Flags & WINED3DFMT_FLAG_COMPRESSED && mem)
+        {
+            GL_EXTCALL(glCompressedTexImage2DARB(This->texture_target, This->texture_level,
+                    internal, width, height, 0, This->resource.size, mem));
+        }
+        else
+        {
+            glTexImage2D(This->texture_target, This->texture_level,
+                    internal, width, height, 0, format_desc->glFormat, format_desc->glType, mem);
+            checkGLcall("glTexImage2D");
+        }
     }
 
@@ -1001,20 +1013,8 @@
     IWineD3DBaseTexture *baseTexture = NULL;
 
-#ifdef VBOXWDDM
-    if (VBOXSHRC_IS_SHARED(This))
-    {
-        if (!VBOXSHRC_IS_SHARED_OPENED(This))
-            IWineD3DSurfaceImpl_LoadLocation(iface, SFLAG_INTEXTURE, NULL);
-        else
-            This->Flags |= SFLAG_INTEXTURE;
-    }
-    else
-#endif
-    {
-        if (!(This->Flags & SFLAG_INSYSMEM) && (This->Flags & SFLAG_INTEXTURE))
-            IWineD3DSurface_LoadLocation(iface, SFLAG_INSYSMEM, NULL /* no partial locking for textures yet */);
-
-        IWineD3DSurface_ModifyLocation(iface, SFLAG_INSYSMEM, TRUE);
-    }
+    if (!(This->Flags & SFLAG_INSYSMEM) && (This->Flags & SFLAG_INTEXTURE))
+        IWineD3DSurface_LoadLocation(iface, SFLAG_INSYSMEM, NULL /* no partial locking for textures yet */);
+
+    IWineD3DSurface_ModifyLocation(iface, SFLAG_INSYSMEM, TRUE);
 
     if (dirty_rect)
@@ -3982,4 +3982,8 @@
 }
 
+#ifdef VBOXWDDM
+static HRESULT WINAPI IWineD3DSurfaceImpl_LoadLocation(IWineD3DSurface *iface, DWORD flag, const RECT *rect);
+#endif
+
 static HRESULT WINAPI IWineD3DSurfaceImpl_PrivateSetup(IWineD3DSurface *iface) {
     /** Check against the maximum texture sizes supported by the video card **/
@@ -4066,10 +4070,5 @@
     }
 
-#ifdef VBOXWDDM
-    if (!VBOXSHRC_IS_SHARED(This))
-#endif
-    {
-        This->Flags |= SFLAG_INSYSMEM;
-    }
+    This->Flags |= SFLAG_INSYSMEM;
 
     return WINED3D_OK;
@@ -4281,4 +4280,11 @@
         if(((This->Flags & SFLAG_INTEXTURE) && !(flag & SFLAG_INTEXTURE)) ||
            ((This->Flags & SFLAG_INSRGBTEX) && !(flag & SFLAG_INSRGBTEX))) {
+#ifdef VBOXWDDM
+            if (VBOXSHRC_IS_SHARED(This))
+            {
+                IWineD3DSurfaceImpl_LoadLocation(iface, SFLAG_INTEXTURE, NULL);
+            }
+            else
+#endif
             if (IWineD3DSurface_GetContainer(iface, &IID_IWineD3DBaseTexture, (void **)&texture) == WINED3D_OK) {
                 TRACE("Passing to container\n");
@@ -4298,4 +4304,11 @@
     } else {
         if((This->Flags & (SFLAG_INTEXTURE | SFLAG_INSRGBTEX)) && (flag & (SFLAG_INTEXTURE | SFLAG_INSRGBTEX))) {
+#ifdef VBOXWDDM
+            if (VBOXSHRC_IS_SHARED(This))
+            {
+                IWineD3DSurfaceImpl_LoadLocation(iface, SFLAG_INTEXTURE, NULL);
+            }
+            else
+#endif
             if (IWineD3DSurface_GetContainer(iface, &IID_IWineD3DBaseTexture, (void **)&texture) == WINED3D_OK) {
                 TRACE("Passing to container\n");
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/texture.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/texture.c	(revision 31885)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/texture.c	(revision 31936)
@@ -616,4 +616,31 @@
     texture->baseTexture.internal_preload = texture_internal_preload;
 
+#ifdef VBOXWDDM
+    if (VBOXSHRC_IS_SHARED(texture))
+    {
+        Assert(shared_handle);
+        IWineD3DSurface_LoadLocation(texture->surfaces[0], SFLAG_INTEXTURE, NULL);
+        if (!VBOXSHRC_IS_SHARED_OPENED(texture))
+        {
+            Assert(!(*shared_handle));
+            *shared_handle = VBOXSHRC_GET_SHAREHANDLE(texture);
+        }
+        else
+        {
+            Assert(*shared_handle);
+        }
+#ifdef DEBUG
+        for (i = 0; i < texture->baseTexture.levels; ++i)
+        {
+            Assert((*shared_handle) == ((IWineD3DSurfaceImpl*)texture->surfaces[i])->texture_name);
+        }
+#endif
+    }
+    else
+    {
+        Assert(!shared_handle);
+    }
+#endif
+
     return WINED3D_OK;
 }
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/vboxsharedrc.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/vboxsharedrc.h	(revision 31885)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/vboxsharedrc.h	(revision 31936)
@@ -26,3 +26,14 @@
 #define VBOXSHRC_IS_SHARED_OPENED(_o) (!!(VBOXSHRC_GET_SHAREFLAFS(_o) & VBOXSHRC_F_SHARED_OPENED))
 
+#ifdef DEBUG_misha
+/* just for simplicity */
+#define AssertBreakpoint() do { __asm {int 3} } while (0)
+#define Assert(_expr) do { \
+        if (!(_expr)) AssertBreakpoint(); \
+    } while (0)
+#else
+#define AssertBreakpoint() do { } while (0)
+#define Assert(_expr) do { } while (0)
+#endif
+
 #endif /* #ifndef ___vboxsharedrc_h___ */
