Index: trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispD3D.cpp
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispD3D.cpp	(revision 39899)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispD3D.cpp	(revision 39900)
@@ -3580,7 +3580,53 @@
             Assert(0);
         }
+
+#ifdef VBOXWDDMDISP_DEBUG
+        Assert(pDevice->cSamplerTextures < RT_ELEMENTS(pDevice->aSamplerTextures));
+        int idx = VBOXWDDMDISP_SAMPLER_IDX(Stage);
+        if (idx >= 0)
+        {
+            Assert(idx < RT_ELEMENTS(pDevice->aSamplerTextures));
+#ifdef DEBUG_misha
+            if (VBOXWDDMDISP_SAMPLER_IDX_IS_SPECIAL(Stage))
+            {
+                WARN(("non-zero special sampler index not tested!\n"));
+            }
+#endif
+            if (!pDevice->aSamplerTextures[idx])
+            {
+                ++pDevice->cSamplerTextures;
+            }
+            Assert(pDevice->cSamplerTextures < RT_ELEMENTS(pDevice->aSamplerTextures));
+            pDevice->aSamplerTextures[idx] = pRc;
+        }
+        else
+        {
+            WARN(("incorrect dampler index1! (%d)\n", Stage));
+        }
+#endif
     }
     else
+    {
         pD3DIfTex = NULL;
+#ifdef VBOXWDDMDISP_DEBUG
+        Assert(pDevice->cSamplerTextures < RT_ELEMENTS(pDevice->aSamplerTextures));
+        int idx = VBOXWDDMDISP_SAMPLER_IDX(Stage);
+        if (idx >= 0)
+        {
+            Assert(idx < RT_ELEMENTS(pDevice->aSamplerTextures));
+            if (pDevice->aSamplerTextures[idx])
+            {
+                Assert(pDevice->cSamplerTextures);
+                --pDevice->cSamplerTextures;
+            }
+            Assert(pDevice->cSamplerTextures < RT_ELEMENTS(pDevice->aSamplerTextures));
+            pDevice->aSamplerTextures[idx] = NULL;
+        }
+        else
+        {
+            WARN(("incorrect dampler index2! (%d)\n", Stage));
+        }
+#endif
+    }
 
     HRESULT hr = pDevice9If->SetTexture(Stage, pD3DIfTex);
@@ -3703,4 +3749,6 @@
     HRESULT hr = S_OK;
 
+    VBOXVDBG_BREAK_SHARED_DEV(pDevice);
+
     VBOXVDBG_DUMP_DRAWPRIM_ENTER(pDevice);
 
@@ -3776,4 +3824,7 @@
 
     IDirect3DDevice9 * pDevice9If = VBOXDISP_D3DEV(pDevice);
+
+    VBOXVDBG_BREAK_SHARED_DEV(pDevice);
+
     VBOXVDBG_DUMP_DRAWPRIM_ENTER(pDevice);
 
@@ -3884,4 +3935,6 @@
     hr = pDevice9If->DrawPrimitive(pData->PrimitiveType, pData->FirstVertexOffset, pData->PrimitiveCount);
 #else
+    VBOXVDBG_BREAK_SHARED_DEV(pDevice);
+
     VBOXVDBG_DUMP_DRAWPRIM_ENTER(pDevice);
 
@@ -6085,4 +6138,8 @@
     IDirect3DSurface9 *pDstSurfIf = NULL;
     Assert(!pDstSwapchain || vboxWddmSwapchainGetFb(pDstSwapchain)->pAlloc != pDstAlloc || vboxWddmSwapchainNumRTs(pDstSwapchain) == 1);
+
+    VBOXVDBG_BREAK_SHARED(pSrcRc);
+    VBOXVDBG_BREAK_SHARED(pDstRc);
+
     hr = vboxWddmSurfGet(pDstRc, pData->DstSubResourceIndex, &pDstSurfIf);
     Assert(hr == S_OK);
@@ -7356,5 +7413,5 @@
     vboxVDbgPrint(("==> "__FUNCTION__"\n"));
 
-#ifdef DEBUG_misha
+#if 0 //def DEBUG_misha
     DWORD dwVersion = 0;
     DWORD dwMajorVersion = 0;
Index: trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispD3D.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispD3D.h	(revision 39899)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispD3D.h	(revision 39900)
@@ -31,4 +31,11 @@
 #define VBOXWDDMDISP_MAX_VERTEX_STREAMS 16
 #define VBOXWDDMDISP_MAX_SWAPCHAIN_SIZE 16
+#ifdef VBOXWDDMDISP_DEBUG
+# define VBOXWDDMDISP_MAX_TEX_SAMPLERS 16
+# define VBOXWDDMDISP_TOTAL_SAMPLERS VBOXWDDMDISP_MAX_TEX_SAMPLERS + 5
+# define VBOXWDDMDISP_SAMPLER_IDX_IS_SPECIAL(_i) ((_i) >= D3DDMAPSAMPLER && (_i) <= D3DVERTEXTEXTURESAMPLER3)
+# define VBOXWDDMDISP_SAMPLER_IDX_SPECIAL(_i) (VBOXWDDMDISP_SAMPLER_IDX_IS_SPECIAL(_i) ? (int)((_i) - D3DDMAPSAMPLER + VBOXWDDMDISP_MAX_TEX_SAMPLERS) : (int)-1)
+# define VBOXWDDMDISP_SAMPLER_IDX(_i) (((_i) < VBOXWDDMDISP_MAX_TEX_SAMPLERS) ? (int)(_i) : VBOXWDDMDISP_SAMPLER_IDX_SPECIAL(_i))
+#endif
 /* maximum number of direct render targets to be used before
  * switching to offscreen rendering */
@@ -195,4 +202,9 @@
     /* no lock is needed for this since we're guaranteed the per-device calls are not reentrant */
     RTLISTANCHOR DirtyAllocList;
+
+#ifdef VBOXWDDMDISP_DEBUG
+    UINT cSamplerTextures;
+    struct VBOXWDDMDISP_RESOURCE *aSamplerTextures[VBOXWDDMDISP_TOTAL_SAMPLERS];
+#endif
 
     UINT cRTs;
Index: trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispDbg.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispDbg.h	(revision 39899)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispDbg.h	(revision 39900)
@@ -314,4 +314,12 @@
             if (pRtVar->pRc->RcDesc.fFlags.SharedResource) { *(_pIsShared) = TRUE; break; } \
         } \
+        if (!*(_pIsShared)) { \
+            for (UINT i = 0, iSampler = 0; iSampler < (_pDevice)->cSamplerTextures; ++i) { \
+                Assert(i < RT_ELEMENTS((_pDevice)->aSamplerTextures)); \
+                if (!(_pDevice)->aSamplerTextures[i]) continue; \
+                *(_pIsShared) = TRUE; break; \
+                ++iSampler; \
+            } \
+        } \
     } while (0)
 
@@ -321,4 +329,12 @@
         { \
             *(_pIsAllowed) = VBOXVDBG_IS_DUMP_ALLOWED(Shared); \
+        } \
+    } while (0)
+
+#define VBOXVDBG_IS_BREAK_SHARED_ALLOWED_DEV(_pDevice, _pIsAllowed) do { \
+        VBOXVDBG_DEV_CHECK_SHARED(_pDevice, _pIsAllowed); \
+        if (*(_pIsAllowed)) \
+        { \
+            *(_pIsAllowed) = VBOXVDBG_IS_BREAK_ALLOWED(Shared); \
         } \
     } while (0)
@@ -342,4 +358,13 @@
             vboxVDbgDoDumpRt("<=="__FUNCTION__": RenderTarget Dump\n", (_pDevice), "\n"); \
         }\
+    } while (0)
+
+#define VBOXVDBG_BREAK_SHARED_DEV(_pDevice)  do { \
+        BOOL fBreakShaded = FALSE; \
+        VBOXVDBG_IS_BREAK_SHARED_ALLOWED_DEV(_pDevice, &fBreakShaded); \
+        if (fBreakShaded) { \
+            vboxVDbgPrint((__FUNCTION__"== Break on shared access\n")); \
+            AssertFailed(); \
+        } \
     } while (0)
 
@@ -567,4 +592,5 @@
 #define VBOXVDBG_DUMP_PRESENT_LEAVE(_pDevice, _pSwapchain) do { } while (0)
 #define VBOXVDBG_BREAK_SHARED(_pRc) do { } while (0)
+#define VBOXVDBG_BREAK_SHARED_DEV(_pDevice) do { } while (0)
 #define VBOXVDBG_BREAK_DDI() do { } while (0)
 #define VBOXVDBG_CHECK_SMSYNC(_pRc) do { } while (0)
