Index: /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispD3D.cpp
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispD3D.cpp	(revision 43339)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispD3D.cpp	(revision 43340)
@@ -1094,5 +1094,5 @@
             continue;
         BOOL fHasSurf = pRT->pAlloc->enmD3DIfType == VBOXDISP_D3DIFTYPE_SURFACE ?
-                !!pRT->pAlloc->pRc->aAllocations[i].pD3DIf
+                !!pRT->pAlloc->pD3DIf
                 :
                 !!pRT->pAlloc->pRc->aAllocations[0].pD3DIf;
@@ -2312,4 +2312,15 @@
     Assert(pData->Stream < RT_ELEMENTS(pDevice->aStreamSourceUm));
     PVBOXWDDMDISP_STREAMSOURCEUM pStrSrcUm = &pDevice->aStreamSourceUm[pData->Stream];
+    if (pStrSrcUm->pvBuffer && !pUMBuffer)
+    {
+        --pDevice->cStreamSourcesUm;
+        Assert(pDevice->cStreamSourcesUm < UINT32_MAX/2);
+    }
+    else if (!pStrSrcUm->pvBuffer && pUMBuffer)
+    {
+        ++pDevice->cStreamSourcesUm;
+        Assert(pDevice->cStreamSourcesUm <= RT_ELEMENTS(pDevice->aStreamSourceUm));
+    }
+
     pStrSrcUm->pvBuffer = pUMBuffer;
     pStrSrcUm->cbStride = pData->Stride;
@@ -2351,6 +2362,7 @@
     if (hr == S_OK)
     {
-        pDevice->pIndicesAlloc = pAlloc;
+        pDevice->IndiciesInfo.pIndicesAlloc = pAlloc;
         pDevice->IndiciesInfo.uiStride = pData->Stride;
+        pDevice->IndiciesInfo.pvIndicesUm = NULL;
     }
     vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
@@ -2366,7 +2378,24 @@
     VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
 
+    IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);
+
     HRESULT hr = S_OK;
-    pDevice->IndiciesUm.pvBuffer = pUMBuffer;
-    pDevice->IndiciesUm.cbSize = IndexSize;
+    if (pDevice->IndiciesInfo.pIndicesAlloc)
+    {
+        hr = pDevice9If->SetIndices(NULL);
+    }
+
+    if (SUCCEEDED(hr))
+    {
+        pDevice->IndiciesInfo.pvIndicesUm = pUMBuffer;
+        pDevice->IndiciesInfo.uiStride = IndexSize;
+        pDevice->IndiciesInfo.pIndicesAlloc = NULL;
+        hr = S_OK;
+    }
+    else
+    {
+        WARN(("SetIndices failed hr 0x%x", hr));
+    }
+
     vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
     return hr;
@@ -2465,35 +2494,112 @@
     VBOXVDBG_DUMP_DRAWPRIM_ENTER(pDevice);
 
+
 #ifdef DEBUG
+    uint32_t cStreams = 0;
+    for (UINT i = 0; i < RT_ELEMENTS(pDevice->aStreamSourceUm); ++i)
+    {
+        if(pDevice->aStreamSourceUm[i].pvBuffer)
+            ++cStreams;
+    }
+
+    Assert(cStreams == pDevice->cStreamSourcesUm);
+
+    cStreams = 0;
+
+    for (UINT i = 0; i < RT_ELEMENTS(pDevice->aStreamSource); ++i)
+    {
+        if (pDevice->aStreamSource[i])
+        {
+            ++cStreams;
+            Assert(!pDevice->aStreamSource[i]->LockInfo.cLocks);
+        }
+    }
+
+    Assert(cStreams == pDevice->cStreamSources);
+#endif
+
+    HRESULT hr;
+
+    if (pDevice->cStreamSources)
+    {
+        Assert(pDevice->IndiciesInfo.pIndicesAlloc);
+        Assert(!pDevice->IndiciesInfo.pvIndicesUm);
+        Assert(!pDevice->IndiciesInfo.pIndicesAlloc->LockInfo.cLocks);
+        Assert(!pDevice->cStreamSourcesUm);
+
+        hr = pDevice9If->DrawIndexedPrimitive(
+                pData->PrimitiveType,
+                pData->BaseVertexIndex,
+                pData->MinIndex,
+                pData->NumVertices,
+                pData->StartIndex,
+                pData->PrimitiveCount);
+
+        if(SUCCEEDED(hr))
+            hr = S_OK;
+        else
+            WARN(("DrawIndexedPrimitive failed hr = 0x%x", hr));
+    }
+    else
+    {
+        Assert(pDevice->cStreamSourcesUm == 1);
+        Assert(pDevice->IndiciesInfo.uiStride == 2 || pDevice->IndiciesInfo.uiStride == 4);
+        const uint8_t * pvIndexBuffer;
+        hr = S_OK;
+
+        if (pDevice->IndiciesInfo.pIndicesAlloc)
+        {
+            Assert(!pDevice->IndiciesInfo.pvIndicesUm);
+            if (pDevice->IndiciesInfo.pIndicesAlloc->pvMem)
+                pvIndexBuffer = (const uint8_t*)pDevice->IndiciesInfo.pIndicesAlloc->pvMem;
+            else
+            {
+                WARN(("not expected!"));
+                hr = E_FAIL;
+                pvIndexBuffer = NULL;
+            }
+        }
+        else
+        {
+            pvIndexBuffer = (const uint8_t*)pDevice->IndiciesInfo.pvIndicesUm;
+            if (!pvIndexBuffer)
+            {
+                WARN(("not expected!"));
+                hr = E_FAIL;
+            }
+        }
+
+        if (SUCCEEDED(hr))
+        {
             for (UINT i = 0; i < RT_ELEMENTS(pDevice->aStreamSourceUm); ++i)
             {
-                Assert(!pDevice->aStreamSourceUm[i].pvBuffer);
-            }
-
-            Assert(pDevice->pIndicesAlloc);
-            Assert(!pDevice->pIndicesAlloc->LockInfo.cLocks);
-
-            uint32_t cStreams = 0;
-            for (UINT i = 0; i < RT_ELEMENTS(pDevice->aStreamSource); ++i)
-            {
-                if (pDevice->aStreamSource[i])
-                {
-                    ++cStreams;
-                    Assert(!pDevice->aStreamSource[i]->LockInfo.cLocks);
-                }
-            }
-
-            Assert(cStreams);
-            Assert(cStreams == pDevice->cStreamSources);
-#endif
-
-    HRESULT hr = pDevice9If->DrawIndexedPrimitive(
-            pData->PrimitiveType,
-            pData->BaseVertexIndex,
-            pData->MinIndex,
-            pData->NumVertices,
-            pData->StartIndex,
-            pData->PrimitiveCount);
-    Assert(hr == S_OK);
+                if(pDevice->aStreamSourceUm[i].pvBuffer)
+                {
+                    hr = pDevice9If->DrawIndexedPrimitiveUP(pData->PrimitiveType,
+                                    pData->MinIndex,
+                                    pData->NumVertices,
+                                    pData->PrimitiveCount,
+                                    pvIndexBuffer + pDevice->IndiciesInfo.uiStride * pData->StartIndex,
+                                    pDevice->IndiciesInfo.uiStride == 2 ? D3DFMT_INDEX16 : D3DFMT_INDEX32,
+                                    pDevice->aStreamSourceUm[i].pvBuffer,
+                                    pDevice->aStreamSourceUm[i].cbStride);
+                    if(SUCCEEDED(hr))
+                    {
+                        if (pDevice->IndiciesInfo.pIndicesAlloc)
+                        {
+                            HRESULT tmpHr = pDevice9If->SetIndices((IDirect3DIndexBuffer9*)pDevice->IndiciesInfo.pIndicesAlloc->pD3DIf);
+                            if(!SUCCEEDED(tmpHr))
+                                WARN(("SetIndices failed hr = 0x%x", tmpHr));
+                        }
+
+                        hr = S_OK;
+                    }
+                    else
+                        WARN(("DrawIndexedPrimitiveUP failed hr = 0x%x", hr));
+                    break;
+                }
+            }
+        }
+    }
 
     vboxWddmDalCheckAddRtsSamplers(pDevice);
@@ -2695,7 +2801,7 @@
         }
 
-        if (pDevice->pIndicesAlloc)
-        {
-            HRESULT tmpHr = pDevice9If->SetIndices((IDirect3DIndexBuffer9*)pDevice->pIndicesAlloc->pD3DIf);
+        if (pDevice->IndiciesInfo.pIndicesAlloc)
+        {
+            HRESULT tmpHr = pDevice9If->SetIndices((IDirect3DIndexBuffer9*)pDevice->IndiciesInfo.pIndicesAlloc->pD3DIf);
             if(!SUCCEEDED(tmpHr))
                 WARN(("SetIndices failed hr = 0x%x", tmpHr));
@@ -4630,6 +4736,11 @@
 
         PVBOXWDDMDISP_STREAMSOURCEUM pStrSrcUm = &pDevice->aStreamSourceUm[pData->Stream];
-        pStrSrcUm->pvBuffer = NULL;
-        pStrSrcUm->cbStride = 0;
+        if (pStrSrcUm->pvBuffer)
+        {
+            --pDevice->cStreamSourcesUm;
+            Assert(pDevice->cStreamSourcesUm < UINT32_MAX/2);
+            pStrSrcUm->pvBuffer = NULL;
+            pStrSrcUm->cbStride = 0;
+        }
     }
     vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispD3D.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispD3D.h	(revision 43339)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispD3D.h	(revision 43340)
@@ -118,5 +118,7 @@
 typedef struct VBOXWDDMDISP_INDICES_INFO
 {
-  UINT   uiStride;
+    struct VBOXWDDMDISP_ALLOCATION *pIndicesAlloc;
+    const void *pvIndicesUm;
+    UINT uiStride;
 } VBOXWDDMDISP_INDICES_INFO;
 
@@ -192,9 +194,8 @@
     /* number of StreamSources set */
     UINT cStreamSources;
+    UINT cStreamSourcesUm;
     VBOXWDDMDISP_STREAMSOURCEUM aStreamSourceUm[VBOXWDDMDISP_MAX_VERTEX_STREAMS];
     struct VBOXWDDMDISP_ALLOCATION *aStreamSource[VBOXWDDMDISP_MAX_VERTEX_STREAMS];
     VBOXWDDMDISP_STREAM_SOURCE_INFO StreamSourceInfo[VBOXWDDMDISP_MAX_VERTEX_STREAMS];
-    VBOXWDDMDISP_INDICIESUM IndiciesUm;
-    struct VBOXWDDMDISP_ALLOCATION *pIndicesAlloc;
     VBOXWDDMDISP_INDICES_INFO IndiciesInfo;
     /* need to cache the ViewPort data because IDirect3DDevice9::SetViewport
