Index: trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxDispD3D.cpp
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxDispD3D.cpp	(revision 30139)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxDispD3D.cpp	(revision 30144)
@@ -938,5 +938,5 @@
         }
 
-        uint32_t cPixCopyLine = pRect->left - pRect->right;
+        uint32_t cPixCopyLine = pRect->right - pRect->left;
 
         if (cPixCopyLine == pAlloc->SurfDesc.width && srcPitch == dstPitch)
@@ -1792,8 +1792,12 @@
 static HRESULT APIENTRY vboxWddmDDevDrawPrimitive2(HANDLE hDevice, CONST D3DDDIARG_DRAWPRIMITIVE2* pData)
 {
-    vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
-    AssertBreakpoint();
-    vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
-    return E_FAIL;
+    vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
+    PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
+    Assert(pDevice);
+    Assert(pDevice->pDevice9If);
+    HRESULT hr = pDevice->pDevice9If->DrawPrimitive(pData->PrimitiveType, pData->FirstVertexOffset, pData->PrimitiveCount);
+    Assert(hr == S_OK);
+    vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
+    return hr;
 }
 
@@ -2045,16 +2049,11 @@
             Assert(pD3DIfTex);
             RECT *pRect = NULL;
+            Assert(!pData->Flags.RangeValid);
+            Assert(!pData->Flags.BoxValid);
             if (pData->Flags.AreaValid)
             {
                 pRect = &pData->Area;
             }
-            else if (pData->Flags.RangeValid)
-            {
-                AssertBreakpoint();
-            }
-            else if (pData->Flags.BoxValid)
-            {
-                AssertBreakpoint();
-            }
+
             /* else - we lock the entire texture, pRect == NULL */
 
@@ -2123,4 +2122,95 @@
             }
         }
+        else if (pRc->RcDesc.fFlags.VertexBuffer)
+        {
+            Assert(pData->SubResourceIndex < pRc->cAllocations);
+            PVBOXWDDMDISP_ALLOCATION pAlloc = &pRc->aAllocations[pData->SubResourceIndex];
+            IDirect3DVertexBuffer9 *pD3D9VBuf = (IDirect3DVertexBuffer9*)pAlloc->pD3DIf;
+            Assert(pD3D9VBuf);
+            Assert(!pData->Flags.AreaValid);
+            Assert(!pData->Flags.BoxValid);
+            D3DDDIRANGE *pRange = NULL;
+            if (pData->Flags.RangeValid)
+            {
+                pRange = &pData->Range;
+            }
+
+            /* else - we lock the entire texture, pRect == NULL */
+
+//            Assert(!pLockAlloc->LockInfo.cLocks);
+            if (!pAlloc->LockInfo.cLocks)
+            {
+                hr = pD3D9VBuf->Lock(pRange ? pRange->Offset : 0,
+                                      pRange ? pRange->Size : 0,
+                                      &pAlloc->LockInfo.LockedRect.pBits,
+                                      vboxDDI2D3DLockFlags(pData->Flags));
+                Assert(hr == S_OK);
+                if (hr == S_OK)
+                {
+                    pAlloc->LockInfo.LockedRect.Pitch = pAlloc->SurfDesc.width;
+//                    Assert(pLockAlloc->LockInfo.fFlags.Value == 0);
+                    pAlloc->LockInfo.fFlags = pData->Flags;
+                    if (pRange)
+                    {
+                        pAlloc->LockInfo.Range = *pRange;
+                        Assert(pAlloc->LockInfo.fFlags.RangeValid == 1);
+//                        pAlloc->LockInfo.fFlags.RangeValid = 1;
+                    }
+                    else
+                    {
+                        Assert(pAlloc->LockInfo.fFlags.RangeValid == 0);
+//                        pAlloc->LockInfo.fFlags.RangeValid = 0;
+                    }
+
+                    ++pAlloc->LockInfo.cLocks;
+                }
+            }
+            else
+            {
+//                Assert(pAlloc->LockInfo.fFlags.Value == pData->Flags.Value);
+//                if (pAlloc->LockInfo.fFlags.Value != pData->Flags.Value)
+//                {
+//                }
+                Assert(pAlloc->LockInfo.fFlags.RangeValid == pData->Flags.RangeValid);
+                if (pAlloc->LockInfo.fFlags.RangeValid && pData->Flags.RangeValid)
+                {
+                    Assert(pAlloc->LockInfo.Range.Offset == pData->Range.Offset);
+                    Assert(pAlloc->LockInfo.Range.Size == pData->Range.Size);
+                }
+                Assert(pAlloc->LockInfo.LockedRect.pBits);
+            }
+
+
+            ++pAlloc->LockInfo.cLocks;
+
+            if (!pData->Flags.NotifyOnly)
+            {
+                pData->pSurfData = pAlloc->LockInfo.LockedRect.pBits;
+                pData->Pitch = pAlloc->LockInfo.LockedRect.Pitch;
+                pData->SlicePitch = 0;
+                Assert(pAlloc->SurfDesc.slicePitch == 0);
+                Assert(!pAlloc->pvMem);
+            }
+            else
+            {
+                Assert(pAlloc->pvMem);
+                Assert(pRc->RcDesc.enmPool == D3DDDIPOOL_SYSTEMMEM);
+                if (/* !pData->Flags.WriteOnly && */ !pData->Flags.Discard)
+                {
+                    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;
+                    vboxWddmLockUnlockMemSynch(pAlloc, &pAlloc->LockInfo.LockedRect, pr, false /*bool bToLockInfo*/);
+                }
+            }
+        }
         else
         {
@@ -2201,8 +2291,10 @@
 
             --pLockAlloc->LockInfo.cLocks;
+            Assert(pLockAlloc->LockInfo.cLocks < UINT32_MAX);
+//            pLockAlloc->LockInfo.cLocks = 0;
             if (!pLockAlloc->LockInfo.cLocks)
             {
                 PVBOXWDDMDISP_ALLOCATION pTexAlloc = &pRc->aAllocations[0];
-                Assert(pLockAlloc->LockInfo.cLocks);
+//                Assert(!pLockAlloc->LockInfo.cLocks);
                 IDirect3DTexture9 *pD3DIfTex = (IDirect3DTexture9*)pTexAlloc->pD3DIf;
                 Assert(pD3DIfTex);
@@ -2220,4 +2312,43 @@
             {
                 Assert(pLockAlloc->LockInfo.cLocks < UINT32_MAX);
+            }
+        }
+        else if (pRc->RcDesc.fFlags.VertexBuffer)
+        {
+            Assert(pData->SubResourceIndex < pRc->cAllocations);
+            PVBOXWDDMDISP_ALLOCATION pAlloc = &pRc->aAllocations[pData->SubResourceIndex];
+
+            --pAlloc->LockInfo.cLocks;
+            Assert(pAlloc->LockInfo.cLocks < UINT32_MAX);
+//            pAlloc->LockInfo.cLocks = 0;
+            if (!pAlloc->LockInfo.cLocks)
+            {
+//                Assert(!pAlloc->LockInfo.cLocks);
+                IDirect3DVertexBuffer9 *pD3D9VBuf = (IDirect3DVertexBuffer9*)pAlloc->pD3DIf;
+                Assert(pD3D9VBuf);
+                /* this is a sysmem texture, update  */
+                if (pAlloc->pvMem && !pAlloc->LockInfo.fFlags.ReadOnly)
+                {
+                    RECT r, *pr;
+                    if (pAlloc->LockInfo.fFlags.RangeValid)
+                    {
+                        r.top = 0;
+                        r.left = pAlloc->LockInfo.Range.Offset;
+                        r.bottom = 1;
+                        r.right = pAlloc->LockInfo.Range.Offset + pAlloc->LockInfo.Range.Size;
+                        pr = &r;
+                    }
+                    else
+                        pr = NULL;
+                    vboxWddmLockUnlockMemSynch(pAlloc, &pAlloc->LockInfo.LockedRect,
+                            pr,
+                            true /*bool bToLockInfo*/);
+                }
+                hr = pD3D9VBuf->Unlock();
+                Assert(hr == S_OK);
+            }
+            else
+            {
+                Assert(pAlloc->LockInfo.cLocks < UINT32_MAX);
             }
         }
@@ -2973,8 +3104,18 @@
 static HRESULT APIENTRY vboxWddmDDevSetStreamSource(HANDLE hDevice, CONST D3DDDIARG_SETSTREAMSOURCE* pData)
 {
-    vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
-    AssertBreakpoint();
-    vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
-    return E_FAIL;
+    vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
+    PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
+    Assert(pDevice);
+    Assert(pDevice->pDevice9If);
+    PVBOXWDDMDISP_RESOURCE pRc = (PVBOXWDDMDISP_RESOURCE)pData->hVertexBuffer;
+    Assert(pRc);
+    Assert(pRc->cAllocations == 1);
+    PVBOXWDDMDISP_ALLOCATION pAlloc = &pRc->aAllocations[0];
+    Assert(pAlloc->pD3DIf);
+    IDirect3DVertexBuffer9 *pStreamData = (IDirect3DVertexBuffer9*)pAlloc->pD3DIf;
+    HRESULT hr = pDevice->pDevice9If->SetStreamSource(pData->Stream, pStreamData, pData->Offset, pData->Stride);
+    Assert(hr == S_OK);
+    vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
+    return hr;
 }
 static HRESULT APIENTRY vboxWddmDDevSetStreamSourceFreq(HANDLE hDevice, CONST D3DDDIARG_SETSTREAMSOURCEFREQ* pData)
