Index: trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxDispD3D.cpp
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxDispD3D.cpp	(revision 30162)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxDispD3D.cpp	(revision 30167)
@@ -35,5 +35,5 @@
 #endif
 
-/*#define VBOXWDDMDISP_WITH_TMPWORKAROUND 1*/
+#define VBOXWDDMDISP_WITH_TMPWORKAROUND 1
 
 static FORMATOP gVBoxFormatOps3D[] = {
@@ -1848,5 +1848,61 @@
     Assert(pDevice);
     Assert(pDevice->pDevice9If);
-    HRESULT hr = pDevice->pDevice9If->DrawPrimitive(pData->PrimitiveType, pData->FirstVertexOffset, pData->PrimitiveCount);
+    HRESULT hr;
+
+#if 0
+    int stream;
+    for (stream=0; stream<VBOXWDDMDISP_MAX_VERTEX_STREAMS; ++stream)
+    {
+        if (pDevice->aStreamSource[stream] && pDevice->aStreamSource[stream]->LockInfo.cLocks)
+        {
+            VBOXWDDMDISP_LOCKINFO *pLock = &pDevice->aStreamSource[stream]->LockInfo;
+            if (pLock->fFlags.MightDrawFromLocked && (pLock->fFlags.Discard || pLock->fFlags.NoOverwrite))
+            {
+                IDirect3DVertexBuffer9 *pD3D9VBuf = (IDirect3DVertexBuffer9*)pDevice->aStreamSource[stream]->pD3DIf;
+                Assert(pLock->fFlags.RangeValid);
+                pD3D9VBuf->Lock(pLock->Range.Offset, pLock->Range.Size,
+                                &pLock->LockedRect.pBits,
+                                vboxDDI2D3DLockFlags(pLock->fFlags));
+                RECT r;
+                r.top = 0;
+                r.left = pLock->Range.Offset;
+                r.bottom = 1;
+                r.right = pLock->Range.Offset + pLock->Range.Size;
+
+                vboxWddmLockUnlockMemSynch(pDevice->aStreamSource[stream], &pLock->LockedRect, &r, true /*bool bToLockInfo*/);
+
+                pD3D9VBuf->Unlock();
+            }
+        }
+    }
+
+    hr = pDevice->pDevice9If->DrawPrimitive(pData->PrimitiveType, pData->FirstVertexOffset, pData->PrimitiveCount);
+#else
+    int stream;
+    for (stream=0; stream<VBOXWDDMDISP_MAX_VERTEX_STREAMS; ++stream)
+    {
+        if (pDevice->aStreamSource[stream])
+        {
+            Assert(stream==0); /*only stream 0 should be accessed here*/
+            Assert(pDevice->StreamSourceInfo[stream].uiStride!=0);
+            VBOXWDDMDISP_LOCKINFO *pLock = &pDevice->aStreamSource[stream]->LockInfo;
+
+            if (pDevice->aStreamSource[stream]->LockInfo.cLocks)
+            {
+                Assert(pLock->fFlags.MightDrawFromLocked && (pLock->fFlags.Discard || pLock->fFlags.NoOverwrite));
+                hr = pDevice->pDevice9If->DrawPrimitiveUP(pData->PrimitiveType, pData->PrimitiveCount,
+                        (void*)((uintptr_t)pDevice->aStreamSource[stream]->pvMem+pDevice->StreamSourceInfo[stream].uiOffset+pData->FirstVertexOffset),
+                         pDevice->StreamSourceInfo[stream].uiStride);
+                Assert(hr == S_OK);
+                hr = pDevice->pDevice9If->SetStreamSource(stream, (IDirect3DVertexBuffer9*)pDevice->aStreamSource[stream]->pD3DIf, pDevice->StreamSourceInfo[stream].uiOffset, pDevice->StreamSourceInfo[stream].uiStride);
+            }
+            else
+            {
+                hr = pDevice->pDevice9If->DrawPrimitive(pData->PrimitiveType, pData->FirstVertexOffset/pDevice->StreamSourceInfo[stream].uiStride, pData->PrimitiveCount);
+            }
+        }
+    }
+#endif
+
     Assert(hr == S_OK);
     vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
@@ -2204,4 +2260,5 @@
             PVBOXWDDMDISP_ALLOCATION pAlloc = &pRc->aAllocations[pData->SubResourceIndex];
             IDirect3DVertexBuffer9 *pD3D9VBuf = (IDirect3DVertexBuffer9*)pAlloc->pD3DIf;
+            BOOL bLocked = false;
             Assert(pD3D9VBuf);
             Assert(!pData->Flags.AreaValid);
@@ -2218,29 +2275,13 @@
             if (!pAlloc->LockInfo.cLocks)
             {
-                hr = pD3D9VBuf->Lock(pRange ? pRange->Offset : 0,
-                                      pRange ? pRange->Size : 0,
-                                      &pAlloc->LockInfo.LockedRect.pBits,
-                                      vboxDDI2D3DLockFlags(pData->Flags));
-#ifdef VBOXWDDMDISP_WITH_TMPWORKAROUND
-                if (pData->Flags.MightDrawFromLocked)
-                {
-                        RECT r, *pr;
-                        if (pRange)
-                        {
-                            r.top = 0;
-                            r.left = pRange->Offset;
-                            r.bottom = 1;
-                            r.right = pRange->Offset + pRange->Size;
-                            pr = &r;
-                        }
-                        else
-                            pr = NULL;
-
-                        pAlloc->LockInfo.LockedRect.Pitch = pAlloc->SurfDesc.width;
-
-                        vboxWddmLockUnlockMemSynch(pAlloc, &pAlloc->LockInfo.LockedRect, pr, true /*bool bToLockInfo*/);
-                    pD3D9VBuf->Unlock();
+                if (!pData->Flags.MightDrawFromLocked || (!pData->Flags.Discard && !pData->Flags.NoOverwrite))
+                {
+                    hr = pD3D9VBuf->Lock(pRange ? pRange->Offset : 0,
+                                          pRange ? pRange->Size : 0,
+                                          &pAlloc->LockInfo.LockedRect.pBits,
+                                          vboxDDI2D3DLockFlags(pData->Flags));
+                    bLocked = true;
                 }
-#endif
+
                 Assert(hr == S_OK);
                 if (hr == S_OK)
@@ -2293,5 +2334,5 @@
                     Assert(pAlloc->pvMem);
                     Assert(pRc->RcDesc.enmPool == D3DDDIPOOL_SYSTEMMEM);
-                    if (/* !pData->Flags.WriteOnly && */ !pData->Flags.Discard)
+                    if (bLocked && !pData->Flags.Discard)
                     {
                         RECT r, *pr;
@@ -2419,10 +2460,7 @@
             --pAlloc->LockInfo.cLocks;
             Assert(pAlloc->LockInfo.cLocks < UINT32_MAX);
-//            pAlloc->LockInfo.cLocks = 0;
-#ifdef VBOXWDDMDISP_WITH_TMPWORKAROUND
-            if (!pAlloc->LockInfo.cLocks && !pAlloc->LockInfo.fFlags.MightDrawFromLocked)
-#else
-            if (!pAlloc->LockInfo.cLocks)
-#endif
+            if (!pAlloc->LockInfo.cLocks 
+                && (!pAlloc->LockInfo.fFlags.MightDrawFromLocked
+                    || (!pAlloc->LockInfo.fFlags.Discard && !pAlloc->LockInfo.fFlags.NoOverwrite)))
             {
 //                Assert(!pAlloc->LockInfo.cLocks);
@@ -3049,4 +3087,5 @@
     Assert(pDevice);
     Assert(pDevice->pDevice9If);
+#if 0
     HRESULT hr = pDevice->pDevice9If->Present(NULL, /* CONST RECT * pSourceRect */
             NULL, /* CONST RECT * pDestRect */
@@ -3055,4 +3094,7 @@
             );
     Assert(hr == S_OK);
+#else
+    HRESULT hr = S_OK;
+#endif
     vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
     return hr;
@@ -3217,4 +3259,8 @@
     IDirect3DVertexBuffer9 *pStreamData = (IDirect3DVertexBuffer9*)pAlloc->pD3DIf;
     HRESULT hr = pDevice->pDevice9If->SetStreamSource(pData->Stream, pStreamData, pData->Offset, pData->Stride);
+    Assert(pData->Stream<VBOXWDDMDISP_MAX_VERTEX_STREAMS);
+    pDevice->aStreamSource[pData->Stream] = pAlloc;
+    pDevice->StreamSourceInfo[pData->Stream].uiOffset = pData->Offset;
+    pDevice->StreamSourceInfo[pData->Stream].uiStride = pData->Stride;
     Assert(hr == S_OK);
     vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
Index: trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxDispD3D.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxDispD3D.h	(revision 30162)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxDispD3D.h	(revision 30167)
@@ -20,4 +20,6 @@
 
 #include <iprt/cdefs.h>
+
+#define VBOXWDDMDISP_MAX_VERTEX_STREAMS 16
 
 #ifdef VBOX_WITH_VIDEOHWACCEL
@@ -68,4 +70,12 @@
 } VBOXWDDMDISP_STREAMSOURCEUM, *PVBOXWDDMDISP_STREAMSOURCEUM;
 
+struct VBOXWDDMDISP_ALLOCATION;
+
+typedef struct VBOXWDDMDISP_STREAM_SOURCE_INFO
+{
+  UINT   uiOffset;
+  UINT   uiStride;
+} VBOXWDDMDISP_STREAM_SOURCE_INFO;
+
 typedef struct VBOXWDDMDISP_DEVICE
 {
@@ -81,5 +91,7 @@
     /* number of StreamSources set */
     UINT cStreamSources;
-    VBOXWDDMDISP_STREAMSOURCEUM aStreamSourceUm[16];
+    VBOXWDDMDISP_STREAMSOURCEUM aStreamSourceUm[VBOXWDDMDISP_MAX_VERTEX_STREAMS];
+    VBOXWDDMDISP_ALLOCATION *aStreamSource[VBOXWDDMDISP_MAX_VERTEX_STREAMS];
+    VBOXWDDMDISP_STREAM_SOURCE_INFO StreamSourceInfo[VBOXWDDMDISP_MAX_VERTEX_STREAMS];
     IDirect3DDevice9 *pDevice9If;
     /* need to cache the ViewPort data because IDirect3DDevice9::SetViewport
