Index: trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispD3D.cpp
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispD3D.cpp	(revision 39016)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispD3D.cpp	(revision 39044)
@@ -1631,36 +1631,69 @@
 }
 
+static HRESULT vboxWddmMemsetAlloc(PVBOXWDDMDISP_RESOURCE pRc, UINT iAlloc, char c)
+{
+    PVBOXWDDMDISP_ALLOCATION pAlloc = &pRc->aAllocations[iAlloc];
+    IDirect3DSurface9 *pD3D9Surf = NULL;
+    HRESULT hr = vboxWddmSurfGet(pRc, iAlloc, &pD3D9Surf);
+    if (SUCCEEDED(hr))
+    {
+        PVBOXWDDMDISP_DEVICE pDevice = pRc->pDevice;
+        hr = pRc->pDevice->pDevice9If->ColorFill(pD3D9Surf, NULL, D3DCOLOR_ARGB(c,c,c,c));
+        pD3D9Surf->Release();
+        if (SUCCEEDED(hr))
+        {
+            return hr;
+        }
+
+        WARN(("ColorFill failed, hr 0x%x", hr));
+        /* fallback to lock-memset-unlock */
+    }
+
+    /* unless this is a fallback */
+    Assert(pAlloc->enmD3DIfType == VBOXDISP_D3DIFTYPE_VERTEXBUFFER
+            || pAlloc->enmD3DIfType == VBOXDISP_D3DIFTYPE_INDEXBUFFER);
+
+    D3DLOCKED_RECT Rect;
+    hr = vboxWddmLockRect(pRc, iAlloc, &Rect, NULL, D3DLOCK_DISCARD);
+    if (FAILED(hr))
+    {
+        WARN(("vboxWddmLockRect failed, hr(0x%x)", hr));
+        return hr;
+    }
+
+    UINT cbAllocPitch = pAlloc->SurfDesc.pitch;
+    if(Rect.Pitch == cbAllocPitch)
+    {
+        memset(Rect.pBits, 0, Rect.Pitch * pAlloc->SurfDesc.height);
+    }
+    else
+    {
+        Assert(0);
+        Assert(cbAllocPitch < (UINT)Rect.Pitch);
+        uint8_t *pData = (uint8_t*)Rect.pBits;
+        for (UINT j = 0; j < pAlloc->SurfDesc.height; ++j)
+        {
+            memset(Rect.pBits, c, cbAllocPitch);
+            pData += Rect.Pitch;
+        }
+    }
+
+    hr = vboxWddmUnlockRect(pRc, iAlloc);
+    Assert(SUCCEEDED(hr));
+
+    return S_OK;
+}
+
 static HRESULT vboxWddmMemsetRc(PVBOXWDDMDISP_RESOURCE pRc, char c)
 {
+    HRESULT hr = S_OK;
     for (UINT i = 0; i < pRc->cAllocations; ++i)
     {
-        D3DLOCKED_RECT Rect;
-        HRESULT hr = vboxWddmLockRect(pRc, i, &Rect, NULL, D3DLOCK_DISCARD);
+        hr = vboxWddmMemsetAlloc(pRc, i, c);
         if (FAILED(hr))
         {
-            WARN(("vboxWddmLockRect failed, hr(0x%x)", hr));
+            WARN(("vboxWddmMemsetAlloc failed, hr(0x%x)", hr));
             return hr;
         }
-
-        PVBOXWDDMDISP_ALLOCATION pAlloc = &pRc->aAllocations[i];
-        UINT cbAllocPitch = pAlloc->SurfDesc.pitch;
-        if(Rect.Pitch == cbAllocPitch)
-        {
-            memset(Rect.pBits, 0, Rect.Pitch * pAlloc->SurfDesc.height);
-        }
-        else
-        {
-            Assert(0);
-            Assert(cbAllocPitch < (UINT)Rect.Pitch);
-            uint8_t *pData = (uint8_t*)Rect.pBits;
-            for (UINT j = 0; j < pAlloc->SurfDesc.height; ++j)
-            {
-                memset(Rect.pBits, c, cbAllocPitch);
-                pData += Rect.Pitch;
-            }
-        }
-
-        hr = vboxWddmUnlockRect(pRc, i);
-        Assert(SUCCEEDED(hr));
     }
     return S_OK;
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/surface.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/surface.c	(revision 39016)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/surface.c	(revision 39044)
@@ -1262,5 +1262,5 @@
             context = device->contexts[i];
             /* pretty hacky, @todo: check if the context is acquired and re-acquire it with the new swapchain */
-            if (context->current_rt  == This)
+            if (context->current_rt  == (IWineD3DSurface*)This)
             {
                 context->current_rt = NULL;
@@ -1807,5 +1807,6 @@
 
     surface_prepare_texture(This, gl_info, FALSE);
-    surface_bind_and_dirtify(This, FALSE);
+    /* no need to bind it here */
+//    surface_bind_and_dirtify(This, FALSE);
 
     if (context) context_release(context);
@@ -4804,4 +4805,48 @@
             }
         }
+
+#ifdef VBOX_WITH_WDDM
+        {
+            /* sometimes wine can call ModifyLocation(SFLAG_INTEXTURE, TRUE) for surfaces that do not yet have
+             * ogl texture backend assigned, e.g. when doing ColorFill right after surface creation
+             * to prevent wine state breakage that could occur later on in that case, we check
+             * whether tex gen is needed here and generate it accordingly */
+            if (!This->texture_name)
+            {
+                Assert(!(This->Flags & SFLAG_INTEXTURE));
+                if (flag & SFLAG_INTEXTURE)
+                {
+                    struct wined3d_context *context = NULL;
+                    IWineD3DDeviceImpl *device = This->resource.device;
+                    const struct wined3d_gl_info *gl_info;
+
+                    if (!device->isInDraw) context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD);
+                    gl_info = context->gl_info;
+
+                    surface_prepare_texture(This, gl_info, FALSE);
+
+                    if (context) context_release(context);
+                }
+            }
+
+            if (!This->texture_name_srgb)
+            {
+                Assert(!(This->Flags & SFLAG_INSRGBTEX));
+                if (flag & SFLAG_INSRGBTEX)
+                {
+                    struct wined3d_context *context = NULL;
+                    IWineD3DDeviceImpl *device = This->resource.device;
+                    const struct wined3d_gl_info *gl_info;
+
+                    if (!device->isInDraw) context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD);
+                    gl_info = context->gl_info;
+
+                    surface_prepare_texture(This, gl_info, TRUE);
+
+                    if (context) context_release(context);
+                }
+            }
+        }
+#endif
 
         This->Flags &= ~SFLAG_LOCATIONS;
