1 | /* $Id: VBoxDispDbg.cpp 45132 2013-03-21 16:11:28Z vboxsync $ */
|
---|
2 |
|
---|
3 | /** @file
|
---|
4 | * VBoxVideo Display D3D User mode dll
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2011-2012 Oracle Corporation
|
---|
9 | *
|
---|
10 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
11 | * available from http://www.virtualbox.org. This file is free software;
|
---|
12 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
13 | * General Public License (GPL) as published by the Free Software
|
---|
14 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
15 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
16 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
17 | */
|
---|
18 |
|
---|
19 | /* @todo: move this to VBoxDispD3DCmn.h ? */
|
---|
20 | # if (_MSC_VER >= 1400) && !defined(VBOX_WITH_PATCHED_DDK)
|
---|
21 | # define _InterlockedExchange _InterlockedExchange_StupidDDKVsCompilerCrap
|
---|
22 | # define _InterlockedExchangeAdd _InterlockedExchangeAdd_StupidDDKVsCompilerCrap
|
---|
23 | # define _InterlockedCompareExchange _InterlockedCompareExchange_StupidDDKVsCompilerCrap
|
---|
24 | # define _InterlockedAddLargeStatistic _InterlockedAddLargeStatistic_StupidDDKVsCompilerCrap
|
---|
25 | # define _interlockedbittestandset _interlockedbittestandset_StupidDDKVsCompilerCrap
|
---|
26 | # define _interlockedbittestandreset _interlockedbittestandreset_StupidDDKVsCompilerCrap
|
---|
27 | # define _interlockedbittestandset64 _interlockedbittestandset64_StupidDDKVsCompilerCrap
|
---|
28 | # define _interlockedbittestandreset64 _interlockedbittestandreset64_StupidDDKVsCompilerCrap
|
---|
29 | # pragma warning(disable : 4163)
|
---|
30 | # include <windows.h>
|
---|
31 | # pragma warning(default : 4163)
|
---|
32 | # undef _InterlockedExchange
|
---|
33 | # undef _InterlockedExchangeAdd
|
---|
34 | # undef _InterlockedCompareExchange
|
---|
35 | # undef _InterlockedAddLargeStatistic
|
---|
36 | # undef _interlockedbittestandset
|
---|
37 | # undef _interlockedbittestandreset
|
---|
38 | # undef _interlockedbittestandset64
|
---|
39 | # undef _interlockedbittestandreset64
|
---|
40 | # else
|
---|
41 | # include <windows.h>
|
---|
42 | # endif
|
---|
43 |
|
---|
44 | #include "VBoxDispD3DCmn.h"
|
---|
45 |
|
---|
46 | #include <stdio.h>
|
---|
47 | #include <stdarg.h>
|
---|
48 |
|
---|
49 | #include <iprt/asm.h>
|
---|
50 | #include <iprt/assert.h>
|
---|
51 |
|
---|
52 | static DWORD g_VBoxVDbgFIsModuleNameInited = 0;
|
---|
53 | static char g_VBoxVDbgModuleName[MAX_PATH];
|
---|
54 |
|
---|
55 | char *vboxVDbgDoGetModuleName()
|
---|
56 | {
|
---|
57 | if (!g_VBoxVDbgFIsModuleNameInited)
|
---|
58 | {
|
---|
59 | DWORD cName = GetModuleFileNameA(NULL, g_VBoxVDbgModuleName, RT_ELEMENTS(g_VBoxVDbgModuleName));
|
---|
60 | if (!cName)
|
---|
61 | {
|
---|
62 | DWORD winEr = GetLastError();
|
---|
63 | WARN(("GetModuleFileNameA failed, winEr %d", winEr));
|
---|
64 | return NULL;
|
---|
65 | }
|
---|
66 | g_VBoxVDbgFIsModuleNameInited = TRUE;
|
---|
67 | }
|
---|
68 | return g_VBoxVDbgModuleName;
|
---|
69 | }
|
---|
70 |
|
---|
71 | static void vboxDispLogDbgFormatStringV(char * szBuffer, uint32_t cbBuffer, const char * szString, va_list pArgList)
|
---|
72 | {
|
---|
73 | uint32_t cbWritten = sprintf(szBuffer, "['%s' 0x%x.0x%x] Disp: ", vboxVDbgDoGetModuleName(), GetCurrentProcessId(), GetCurrentThreadId());
|
---|
74 | if (cbWritten > cbBuffer)
|
---|
75 | {
|
---|
76 | AssertReleaseFailed();
|
---|
77 | return;
|
---|
78 | }
|
---|
79 |
|
---|
80 | _vsnprintf(szBuffer + cbWritten, cbBuffer - cbWritten, szString, pArgList);
|
---|
81 | }
|
---|
82 |
|
---|
83 | #if defined(VBOXWDDMDISP_DEBUG) || defined(VBOX_WDDMDISP_WITH_PROFILE)
|
---|
84 | LONG g_VBoxVDbgFIsDwm = -1;
|
---|
85 |
|
---|
86 | DWORD g_VBoxVDbgPid = 0;
|
---|
87 | #endif
|
---|
88 |
|
---|
89 | #ifdef VBOXWDDMDISP_DEBUG
|
---|
90 |
|
---|
91 | DWORD g_VBoxVDbgFLogRel = 1;
|
---|
92 | DWORD g_VBoxVDbgFLog = 1;
|
---|
93 | DWORD g_VBoxVDbgFLogFlow = 0;
|
---|
94 |
|
---|
95 | # ifndef IN_VBOXCRHGSMI
|
---|
96 | #define VBOXWDDMDISP_DEBUG_DUMP_DEFAULT 0
|
---|
97 | DWORD g_VBoxVDbgFDumpSetTexture = VBOXWDDMDISP_DEBUG_DUMP_DEFAULT;
|
---|
98 | DWORD g_VBoxVDbgFDumpDrawPrim = VBOXWDDMDISP_DEBUG_DUMP_DEFAULT;
|
---|
99 | DWORD g_VBoxVDbgFDumpTexBlt = VBOXWDDMDISP_DEBUG_DUMP_DEFAULT;
|
---|
100 | DWORD g_VBoxVDbgFDumpBlt = VBOXWDDMDISP_DEBUG_DUMP_DEFAULT;
|
---|
101 | DWORD g_VBoxVDbgFDumpRtSynch = VBOXWDDMDISP_DEBUG_DUMP_DEFAULT;
|
---|
102 | DWORD g_VBoxVDbgFDumpFlush = VBOXWDDMDISP_DEBUG_DUMP_DEFAULT;
|
---|
103 | DWORD g_VBoxVDbgFDumpShared = VBOXWDDMDISP_DEBUG_DUMP_DEFAULT;
|
---|
104 | DWORD g_VBoxVDbgFDumpLock = VBOXWDDMDISP_DEBUG_DUMP_DEFAULT;
|
---|
105 | DWORD g_VBoxVDbgFDumpUnlock = VBOXWDDMDISP_DEBUG_DUMP_DEFAULT;
|
---|
106 | DWORD g_VBoxVDbgFDumpPresentEnter = VBOXWDDMDISP_DEBUG_DUMP_DEFAULT;
|
---|
107 | DWORD g_VBoxVDbgFDumpPresentLeave = VBOXWDDMDISP_DEBUG_DUMP_DEFAULT;
|
---|
108 | DWORD g_VBoxVDbgFDumpScSync = VBOXWDDMDISP_DEBUG_DUMP_DEFAULT;
|
---|
109 |
|
---|
110 | DWORD g_VBoxVDbgFBreakShared = VBOXWDDMDISP_DEBUG_DUMP_DEFAULT;
|
---|
111 | DWORD g_VBoxVDbgFBreakDdi = 0;
|
---|
112 |
|
---|
113 | DWORD g_VBoxVDbgFCheckSysMemSync = 0;
|
---|
114 | DWORD g_VBoxVDbgFCheckBlt = 0;
|
---|
115 | DWORD g_VBoxVDbgFCheckTexBlt = 0;
|
---|
116 | DWORD g_VBoxVDbgFCheckScSync = 0;
|
---|
117 |
|
---|
118 | DWORD g_VBoxVDbgFSkipCheckTexBltDwmWndUpdate = 1;
|
---|
119 |
|
---|
120 | DWORD g_VBoxVDbgCfgMaxDirectRts = 3;
|
---|
121 | DWORD g_VBoxVDbgCfgForceDummyDevCreate = 0;
|
---|
122 |
|
---|
123 | PVBOXWDDMDISP_DEVICE g_VBoxVDbgInternalDevice = NULL;
|
---|
124 | PVBOXWDDMDISP_RESOURCE g_VBoxVDbgInternalRc = NULL;
|
---|
125 |
|
---|
126 | DWORD g_VBoxVDbgCfgCreateSwapchainOnDdiOnce = 0;
|
---|
127 |
|
---|
128 | void vboxDispLogDbgPrintF(char * szString, ...)
|
---|
129 | {
|
---|
130 | char szBuffer[4096] = {0};
|
---|
131 | va_list pArgList;
|
---|
132 | va_start(pArgList, szString);
|
---|
133 | vboxDispLogDbgFormatStringV(szBuffer, sizeof (szBuffer), szString, pArgList);
|
---|
134 | va_end(pArgList);
|
---|
135 |
|
---|
136 | OutputDebugStringA(szBuffer);
|
---|
137 | }
|
---|
138 |
|
---|
139 | VOID vboxVDbgDoPrintDmlCmd(const char* pszDesc, const char* pszCmd)
|
---|
140 | {
|
---|
141 | vboxVDbgPrint(("<?dml?><exec cmd=\"%s\">%s</exec>, ( %s )\n", pszCmd, pszDesc, pszCmd));
|
---|
142 | }
|
---|
143 |
|
---|
144 | VOID vboxVDbgDoPrintDumpCmd(const char* pszDesc, const void *pvData, uint32_t width, uint32_t height, uint32_t bpp, uint32_t pitch)
|
---|
145 | {
|
---|
146 | char Cmd[1024];
|
---|
147 | sprintf(Cmd, "!vbvdbg.ms 0x%p 0n%d 0n%d 0n%d 0n%d", pvData, width, height, bpp, pitch);
|
---|
148 | vboxVDbgDoPrintDmlCmd(pszDesc, Cmd);
|
---|
149 | }
|
---|
150 |
|
---|
151 | VOID vboxVDbgDoPrintLopLastCmd(const char* pszDesc)
|
---|
152 | {
|
---|
153 | vboxVDbgDoPrintDmlCmd(pszDesc, "ed @@(&vboxVDbgLoop) 0");
|
---|
154 | }
|
---|
155 |
|
---|
156 | typedef struct VBOXVDBG_DUMP_INFO
|
---|
157 | {
|
---|
158 | DWORD fFlags;
|
---|
159 | const VBOXWDDMDISP_ALLOCATION *pAlloc;
|
---|
160 | IDirect3DResource9 *pD3DRc;
|
---|
161 | const RECT *pRect;
|
---|
162 | } VBOXVDBG_DUMP_INFO, *PVBOXVDBG_DUMP_INFO;
|
---|
163 |
|
---|
164 | typedef DECLCALLBACK(void) FNVBOXVDBG_CONTENTS_DUMPER(PVBOXVDBG_DUMP_INFO pInfo, BOOLEAN fBreak, void *pvDumper);
|
---|
165 | typedef FNVBOXVDBG_CONTENTS_DUMPER *PFNVBOXVDBG_CONTENTS_DUMPER;
|
---|
166 |
|
---|
167 | static VOID vboxVDbgDoDumpSummary(const char * pPrefix, PVBOXVDBG_DUMP_INFO pInfo, const char * pSuffix)
|
---|
168 | {
|
---|
169 | const VBOXWDDMDISP_ALLOCATION *pAlloc = pInfo->pAlloc;
|
---|
170 | IDirect3DResource9 *pD3DRc = pInfo->pD3DRc;
|
---|
171 | char rectBuf[24];
|
---|
172 | if (pInfo->pRect)
|
---|
173 | _snprintf(rectBuf, sizeof(rectBuf) / sizeof(rectBuf[0]), "(%d:%d);(%d:%d)",
|
---|
174 | pInfo->pRect->left, pInfo->pRect->top,
|
---|
175 | pInfo->pRect->right, pInfo->pRect->bottom);
|
---|
176 | else
|
---|
177 | strcpy(rectBuf, "n/a");
|
---|
178 |
|
---|
179 | vboxVDbgPrint(("%s Sh(0x%p), Rc(0x%p), pAlloc(0x%x), pD3DIf(0x%p), Type(%s), Rect(%s), Locks(%d) %s",
|
---|
180 | pPrefix ? pPrefix : "",
|
---|
181 | pAlloc ? pAlloc->pRc->aAllocations[0].hSharedHandle : NULL,
|
---|
182 | pAlloc ? pAlloc->pRc : NULL,
|
---|
183 | pAlloc,
|
---|
184 | pD3DRc,
|
---|
185 | pD3DRc ? vboxDispLogD3DRcType(pD3DRc->GetType()) : "n/a",
|
---|
186 | rectBuf,
|
---|
187 | pAlloc ? pAlloc->LockInfo.cLocks : 0,
|
---|
188 | pSuffix ? pSuffix : ""));
|
---|
189 | }
|
---|
190 |
|
---|
191 | VOID vboxVDbgDoDumpPerform(const char * pPrefix, PVBOXVDBG_DUMP_INFO pInfo, const char * pSuffix,
|
---|
192 | PFNVBOXVDBG_CONTENTS_DUMPER pfnCd, void *pvCd)
|
---|
193 | {
|
---|
194 | DWORD fFlags = pInfo->fFlags;
|
---|
195 |
|
---|
196 | if (!VBOXVDBG_DUMP_TYPE_ENABLED_FOR_INFO(pInfo, fFlags))
|
---|
197 | return;
|
---|
198 |
|
---|
199 | if (!pInfo->pD3DRc && pInfo->pAlloc)
|
---|
200 | pInfo->pD3DRc = (IDirect3DResource9*)pInfo->pAlloc->pD3DIf;
|
---|
201 |
|
---|
202 | BOOLEAN bLogOnly = VBOXVDBG_DUMP_TYPE_FLOW_ONLY(fFlags);
|
---|
203 | if (bLogOnly || !pfnCd)
|
---|
204 | {
|
---|
205 | vboxVDbgDoDumpSummary(pPrefix, pInfo, pSuffix);
|
---|
206 | if (VBOXVDBG_DUMP_FLAGS_IS_SET(fFlags, VBOXVDBG_DUMP_TYPEF_BREAK_ON_FLOW)
|
---|
207 | || (!bLogOnly && VBOXVDBG_DUMP_FLAGS_IS_CLEARED(fFlags, VBOXVDBG_DUMP_TYPEF_DONT_BREAK_ON_CONTENTS)))
|
---|
208 | Assert(0);
|
---|
209 | return;
|
---|
210 | }
|
---|
211 |
|
---|
212 | vboxVDbgDoDumpSummary(pPrefix, pInfo, NULL);
|
---|
213 |
|
---|
214 | pfnCd(pInfo, VBOXVDBG_DUMP_FLAGS_IS_CLEARED(fFlags, VBOXVDBG_DUMP_TYPEF_DONT_BREAK_ON_CONTENTS), pvCd);
|
---|
215 |
|
---|
216 | if (pSuffix && pSuffix[0] != '\0')
|
---|
217 | vboxVDbgPrint(("%s", pSuffix));
|
---|
218 | }
|
---|
219 |
|
---|
220 | static DECLCALLBACK(void) vboxVDbgAllocRectContentsDumperCb(PVBOXVDBG_DUMP_INFO pInfo, BOOLEAN fBreak, void *pvDumper)
|
---|
221 | {
|
---|
222 | const VBOXWDDMDISP_ALLOCATION *pAlloc = pInfo->pAlloc;
|
---|
223 | const RECT *pRect = pInfo->pRect;
|
---|
224 |
|
---|
225 | Assert(pAlloc->hAllocation);
|
---|
226 |
|
---|
227 | D3DDDICB_LOCK LockData;
|
---|
228 | LockData.hAllocation = pAlloc->hAllocation;
|
---|
229 | LockData.PrivateDriverData = 0;
|
---|
230 | LockData.NumPages = 0;
|
---|
231 | LockData.pPages = NULL;
|
---|
232 | LockData.pData = NULL; /* out */
|
---|
233 | LockData.Flags.Value = 0;
|
---|
234 | LockData.Flags.LockEntire =1;
|
---|
235 | LockData.Flags.ReadOnly = 1;
|
---|
236 |
|
---|
237 | PVBOXWDDMDISP_DEVICE pDevice = pAlloc->pRc->pDevice;
|
---|
238 |
|
---|
239 | HRESULT hr = pDevice->RtCallbacks.pfnLockCb(pDevice->hDevice, &LockData);
|
---|
240 | Assert(hr == S_OK);
|
---|
241 | if (hr == S_OK)
|
---|
242 | {
|
---|
243 | UINT bpp = vboxWddmCalcBitsPerPixel(pAlloc->SurfDesc.format);
|
---|
244 | vboxVDbgDoPrintDumpCmd("Surf Info", LockData.pData, pAlloc->SurfDesc.d3dWidth, pAlloc->SurfDesc.height, bpp, pAlloc->SurfDesc.pitch);
|
---|
245 | if (pRect)
|
---|
246 | {
|
---|
247 | Assert(pRect->right > pRect->left);
|
---|
248 | Assert(pRect->bottom > pRect->top);
|
---|
249 | vboxVDbgDoPrintRect("rect: ", pRect, "\n");
|
---|
250 | vboxVDbgDoPrintDumpCmd("Rect Info", ((uint8_t*)LockData.pData) + (pRect->top * pAlloc->SurfDesc.pitch) + ((pRect->left * bpp) >> 3),
|
---|
251 | pRect->right - pRect->left, pRect->bottom - pRect->top, bpp, pAlloc->SurfDesc.pitch);
|
---|
252 | }
|
---|
253 | Assert(0);
|
---|
254 |
|
---|
255 | D3DDDICB_UNLOCK DdiUnlock;
|
---|
256 |
|
---|
257 | DdiUnlock.NumAllocations = 1;
|
---|
258 | DdiUnlock.phAllocations = &pAlloc->hAllocation;
|
---|
259 |
|
---|
260 | hr = pDevice->RtCallbacks.pfnUnlockCb(pDevice->hDevice, &DdiUnlock);
|
---|
261 | Assert(hr == S_OK);
|
---|
262 | }
|
---|
263 | }
|
---|
264 |
|
---|
265 | VOID vboxVDbgDoDumpAllocRect(const char * pPrefix, PVBOXWDDMDISP_ALLOCATION pAlloc, RECT *pRect, const char* pSuffix, DWORD fFlags)
|
---|
266 | {
|
---|
267 | VBOXVDBG_DUMP_INFO Info;
|
---|
268 | Info.fFlags = fFlags;
|
---|
269 | Info.pAlloc = pAlloc;
|
---|
270 | Info.pD3DRc = NULL;
|
---|
271 | Info.pRect = pRect;
|
---|
272 | vboxVDbgDoDumpPerform(pPrefix, &Info, pSuffix, vboxVDbgAllocRectContentsDumperCb, NULL);
|
---|
273 | }
|
---|
274 |
|
---|
275 | static DECLCALLBACK(void) vboxVDbgRcRectContentsDumperCb(PVBOXVDBG_DUMP_INFO pInfo, BOOLEAN fBreak, void *pvDumper)
|
---|
276 | {
|
---|
277 | const VBOXWDDMDISP_ALLOCATION *pAlloc = pInfo->pAlloc;
|
---|
278 | IDirect3DResource9 *pD3DRc = pInfo->pD3DRc;
|
---|
279 | const RECT *pRect = pInfo->pRect;
|
---|
280 | IDirect3DSurface9 *pSurf;
|
---|
281 | HRESULT hr = VBoxD3DIfSurfGet(pAlloc->pRc, pAlloc->iAlloc, &pSurf);
|
---|
282 | if (hr != S_OK)
|
---|
283 | {
|
---|
284 | WARN(("VBoxD3DIfSurfGet failed, hr 0x%x", hr));
|
---|
285 | return;
|
---|
286 | }
|
---|
287 |
|
---|
288 | D3DSURFACE_DESC Desc;
|
---|
289 | hr = pSurf->GetDesc(&Desc);
|
---|
290 | Assert(hr == S_OK);
|
---|
291 | if (hr == S_OK)
|
---|
292 | {
|
---|
293 | D3DLOCKED_RECT Lr;
|
---|
294 | hr = pSurf->LockRect(&Lr, NULL, D3DLOCK_READONLY);
|
---|
295 | Assert(hr == S_OK);
|
---|
296 | if (hr == S_OK)
|
---|
297 | {
|
---|
298 | UINT bpp = vboxWddmCalcBitsPerPixel((D3DDDIFORMAT)Desc.Format);
|
---|
299 | vboxVDbgDoPrintDumpCmd("Surf Info", Lr.pBits, Desc.Width, Desc.Height, bpp, Lr.Pitch);
|
---|
300 | if (pRect)
|
---|
301 | {
|
---|
302 | Assert(pRect->right > pRect->left);
|
---|
303 | Assert(pRect->bottom > pRect->top);
|
---|
304 | vboxVDbgDoPrintRect("rect: ", pRect, "\n");
|
---|
305 | vboxVDbgDoPrintDumpCmd("Rect Info", ((uint8_t*)Lr.pBits) + (pRect->top * Lr.Pitch) + ((pRect->left * bpp) >> 3),
|
---|
306 | pRect->right - pRect->left, pRect->bottom - pRect->top, bpp, Lr.Pitch);
|
---|
307 | }
|
---|
308 |
|
---|
309 | if (fBreak)
|
---|
310 | {
|
---|
311 | Assert(0);
|
---|
312 | }
|
---|
313 | hr = pSurf->UnlockRect();
|
---|
314 | Assert(hr == S_OK);
|
---|
315 | }
|
---|
316 | }
|
---|
317 | }
|
---|
318 |
|
---|
319 | VOID vboxVDbgDoDumpRcRect(const char * pPrefix, PVBOXWDDMDISP_ALLOCATION pAlloc,
|
---|
320 | IDirect3DResource9 *pD3DRc, RECT *pRect, const char * pSuffix, DWORD fFlags)
|
---|
321 | {
|
---|
322 | VBOXVDBG_DUMP_INFO Info;
|
---|
323 | Info.fFlags = fFlags;
|
---|
324 | Info.pAlloc = pAlloc;
|
---|
325 | Info.pD3DRc = pD3DRc;
|
---|
326 | Info.pRect = pRect;
|
---|
327 | vboxVDbgDoDumpPerform(pPrefix, &Info, pSuffix, vboxVDbgRcRectContentsDumperCb, NULL);
|
---|
328 | }
|
---|
329 |
|
---|
330 | VOID vboxVDbgDoDumpBb(const char * pPrefix, IDirect3DSwapChain9 *pSwapchainIf, const char * pSuffix, DWORD fFlags)
|
---|
331 | {
|
---|
332 | IDirect3DSurface9 *pBb = NULL;
|
---|
333 | HRESULT hr = pSwapchainIf->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &pBb);
|
---|
334 | Assert(hr == S_OK);
|
---|
335 | if (FAILED(hr))
|
---|
336 | {
|
---|
337 | return;
|
---|
338 | }
|
---|
339 |
|
---|
340 | Assert(pBb);
|
---|
341 | vboxVDbgDoDumpRcRect(pPrefix, NULL, pBb, NULL, pSuffix, fFlags);
|
---|
342 | pBb->Release();
|
---|
343 | }
|
---|
344 |
|
---|
345 | VOID vboxVDbgDoDumpFb(const char * pPrefix, IDirect3DSwapChain9 *pSwapchainIf, const char * pSuffix, DWORD fFlags)
|
---|
346 | {
|
---|
347 | IDirect3DSurface9 *pBb = NULL;
|
---|
348 | HRESULT hr = pSwapchainIf->GetBackBuffer(-1, D3DBACKBUFFER_TYPE_MONO, &pBb);
|
---|
349 | Assert(hr == S_OK);
|
---|
350 | if (FAILED(hr))
|
---|
351 | {
|
---|
352 | return;
|
---|
353 | }
|
---|
354 |
|
---|
355 | Assert(pBb);
|
---|
356 | vboxVDbgDoDumpRcRect(pPrefix, NULL, pBb, NULL, pSuffix, fFlags);
|
---|
357 | pBb->Release();
|
---|
358 | }
|
---|
359 |
|
---|
360 |
|
---|
361 | #define VBOXVDBG_STRCASE(_t) \
|
---|
362 | case _t: return #_t;
|
---|
363 | #define VBOXVDBG_STRCASE_UNKNOWN() \
|
---|
364 | default: Assert(0); return "Unknown";
|
---|
365 |
|
---|
366 | const char* vboxVDbgStrCubeFaceType(D3DCUBEMAP_FACES enmFace)
|
---|
367 | {
|
---|
368 | switch (enmFace)
|
---|
369 | {
|
---|
370 | VBOXVDBG_STRCASE(D3DCUBEMAP_FACE_POSITIVE_X);
|
---|
371 | VBOXVDBG_STRCASE(D3DCUBEMAP_FACE_NEGATIVE_X);
|
---|
372 | VBOXVDBG_STRCASE(D3DCUBEMAP_FACE_POSITIVE_Y);
|
---|
373 | VBOXVDBG_STRCASE(D3DCUBEMAP_FACE_NEGATIVE_Y);
|
---|
374 | VBOXVDBG_STRCASE(D3DCUBEMAP_FACE_POSITIVE_Z);
|
---|
375 | VBOXVDBG_STRCASE(D3DCUBEMAP_FACE_NEGATIVE_Z);
|
---|
376 | VBOXVDBG_STRCASE_UNKNOWN();
|
---|
377 | }
|
---|
378 | }
|
---|
379 |
|
---|
380 | VOID vboxVDbgDoDumpRt(const char * pPrefix, PVBOXWDDMDISP_DEVICE pDevice, const char * pSuffix, DWORD fFlags)
|
---|
381 | {
|
---|
382 | for (UINT i = 0; i < pDevice->cRTs; ++i)
|
---|
383 | {
|
---|
384 | IDirect3DSurface9 *pRt;
|
---|
385 | PVBOXWDDMDISP_ALLOCATION pAlloc = pDevice->apRTs[i];
|
---|
386 | IDirect3DDevice9 *pDeviceIf = pDevice->pDevice9If;
|
---|
387 | HRESULT hr = pDeviceIf->GetRenderTarget(i, &pRt);
|
---|
388 | Assert(hr == S_OK);
|
---|
389 | if (hr == S_OK)
|
---|
390 | {
|
---|
391 | // Assert(pAlloc->pD3DIf == pRt);
|
---|
392 | vboxVDbgDoDumpRcRect(pPrefix, pAlloc, NULL, NULL, pSuffix, fFlags);
|
---|
393 | pRt->Release();
|
---|
394 | }
|
---|
395 | else
|
---|
396 | {
|
---|
397 | vboxVDbgPrint((__FUNCTION__": ERROR getting rt: 0x%x", hr));
|
---|
398 | }
|
---|
399 | }
|
---|
400 | }
|
---|
401 |
|
---|
402 | VOID vboxVDbgDoDumpSamplers(const char * pPrefix, PVBOXWDDMDISP_DEVICE pDevice, const char * pSuffix, DWORD fFlags)
|
---|
403 | {
|
---|
404 | for (UINT i = 0, iSampler = 0; iSampler < pDevice->cSamplerTextures; ++i)
|
---|
405 | {
|
---|
406 | Assert(i < RT_ELEMENTS(pDevice->aSamplerTextures));
|
---|
407 | if (!pDevice->aSamplerTextures[i]) continue;
|
---|
408 | PVBOXWDDMDISP_RESOURCE pRc = pDevice->aSamplerTextures[i];
|
---|
409 | for (UINT j = 0; j < pRc->cAllocations; ++j)
|
---|
410 | {
|
---|
411 | PVBOXWDDMDISP_ALLOCATION pAlloc = &pRc->aAllocations[j];
|
---|
412 | vboxVDbgDoDumpRcRect(pPrefix, pAlloc, NULL, NULL, pSuffix, fFlags);
|
---|
413 | }
|
---|
414 | ++iSampler;
|
---|
415 | }
|
---|
416 | }
|
---|
417 |
|
---|
418 | static DECLCALLBACK(void) vboxVDbgLockUnlockSurfTexContentsDumperCb(PVBOXVDBG_DUMP_INFO pInfo, BOOLEAN fBreak, void *pvDumper)
|
---|
419 | {
|
---|
420 | const VBOXWDDMDISP_ALLOCATION *pAlloc = pInfo->pAlloc;
|
---|
421 | const RECT *pRect = pInfo->pRect;
|
---|
422 | UINT bpp = vboxWddmCalcBitsPerPixel(pAlloc->SurfDesc.format);
|
---|
423 | uint32_t width, height, pitch;
|
---|
424 | void *pvData;
|
---|
425 | if (pAlloc->LockInfo.fFlags.AreaValid)
|
---|
426 | {
|
---|
427 | width = pAlloc->LockInfo.Area.left - pAlloc->LockInfo.Area.right;
|
---|
428 | height = pAlloc->LockInfo.Area.bottom - pAlloc->LockInfo.Area.top;
|
---|
429 | }
|
---|
430 | else
|
---|
431 | {
|
---|
432 | width = pAlloc->SurfDesc.width;
|
---|
433 | height = pAlloc->SurfDesc.height;
|
---|
434 | }
|
---|
435 |
|
---|
436 | if (pAlloc->LockInfo.fFlags.NotifyOnly)
|
---|
437 | {
|
---|
438 | pitch = pAlloc->SurfDesc.pitch;
|
---|
439 | pvData = ((uint8_t*)pAlloc->pvMem) + pitch*pRect->top + ((bpp*pRect->left) >> 3);
|
---|
440 | }
|
---|
441 | else
|
---|
442 | {
|
---|
443 | pvData = pAlloc->LockInfo.pvData;
|
---|
444 | }
|
---|
445 |
|
---|
446 | vboxVDbgDoPrintDumpCmd("Surf Info", pvData, width, height, bpp, pitch);
|
---|
447 |
|
---|
448 | if (fBreak)
|
---|
449 | {
|
---|
450 | Assert(0);
|
---|
451 | }
|
---|
452 | }
|
---|
453 |
|
---|
454 | VOID vboxVDbgDoDumpLockUnlockSurfTex(const char * pPrefix, const VBOXWDDMDISP_ALLOCATION *pAlloc, const char * pSuffix, DWORD fFlags)
|
---|
455 | {
|
---|
456 | Assert(!pAlloc->hSharedHandle);
|
---|
457 |
|
---|
458 | RECT Rect;
|
---|
459 | const RECT *pRect;
|
---|
460 | Assert(!pAlloc->LockInfo.fFlags.RangeValid);
|
---|
461 | Assert(!pAlloc->LockInfo.fFlags.BoxValid);
|
---|
462 | if (pAlloc->LockInfo.fFlags.AreaValid)
|
---|
463 | {
|
---|
464 | pRect = &pAlloc->LockInfo.Area;
|
---|
465 | }
|
---|
466 | else
|
---|
467 | {
|
---|
468 | Rect.top = 0;
|
---|
469 | Rect.bottom = pAlloc->SurfDesc.height;
|
---|
470 | Rect.left = 0;
|
---|
471 | Rect.right = pAlloc->SurfDesc.width;
|
---|
472 | pRect = &Rect;
|
---|
473 | }
|
---|
474 |
|
---|
475 | VBOXVDBG_DUMP_INFO Info;
|
---|
476 | Info.fFlags = fFlags;
|
---|
477 | Info.pAlloc = pAlloc;
|
---|
478 | Info.pD3DRc = NULL;
|
---|
479 | Info.pRect = pRect;
|
---|
480 | vboxVDbgDoDumpPerform(pPrefix, &Info, pSuffix, vboxVDbgLockUnlockSurfTexContentsDumperCb, NULL);
|
---|
481 | }
|
---|
482 |
|
---|
483 | VOID vboxVDbgDoDumpLockSurfTex(const char * pPrefix, const D3DDDIARG_LOCK* pData, const char * pSuffix, DWORD fFlags)
|
---|
484 | {
|
---|
485 | const VBOXWDDMDISP_RESOURCE *pRc = (const VBOXWDDMDISP_RESOURCE*)pData->hResource;
|
---|
486 | const VBOXWDDMDISP_ALLOCATION *pAlloc = &pRc->aAllocations[pData->SubResourceIndex];
|
---|
487 | #ifdef VBOXWDDMDISP_DEBUG
|
---|
488 | VBOXWDDMDISP_ALLOCATION *pUnconstpAlloc = (VBOXWDDMDISP_ALLOCATION *)pAlloc;
|
---|
489 | pUnconstpAlloc->LockInfo.pvData = pData->pSurfData;
|
---|
490 | #endif
|
---|
491 | vboxVDbgDoDumpLockUnlockSurfTex(pPrefix, pAlloc, pSuffix, fFlags);
|
---|
492 | }
|
---|
493 |
|
---|
494 | VOID vboxVDbgDoDumpUnlockSurfTex(const char * pPrefix, const D3DDDIARG_UNLOCK* pData, const char * pSuffix, DWORD fFlags)
|
---|
495 | {
|
---|
496 | const VBOXWDDMDISP_RESOURCE *pRc = (const VBOXWDDMDISP_RESOURCE*)pData->hResource;
|
---|
497 | const VBOXWDDMDISP_ALLOCATION *pAlloc = &pRc->aAllocations[pData->SubResourceIndex];
|
---|
498 | vboxVDbgDoDumpLockUnlockSurfTex(pPrefix, pAlloc, pSuffix, fFlags);
|
---|
499 | }
|
---|
500 |
|
---|
501 | BOOL vboxVDbgDoCheckLRects(D3DLOCKED_RECT *pDstLRect, const RECT *pDstRect, D3DLOCKED_RECT *pSrcLRect, const RECT *pSrcRect, DWORD bpp, BOOL fBreakOnMismatch)
|
---|
502 | {
|
---|
503 | LONG DstH, DstW, SrcH, SrcW, DstWBytes;
|
---|
504 | BOOL fMatch = FALSE;
|
---|
505 | DstH = pDstRect->bottom - pDstRect->top;
|
---|
506 | DstW = pDstRect->right - pDstRect->left;
|
---|
507 | SrcH = pSrcRect->bottom - pSrcRect->top;
|
---|
508 | SrcW = pSrcRect->right - pSrcRect->left;
|
---|
509 |
|
---|
510 | DstWBytes = ((DstW * bpp + 7) >> 3);
|
---|
511 |
|
---|
512 | if(DstW != SrcW && DstH != SrcH)
|
---|
513 | {
|
---|
514 | WARN(("stretched comparison not supported!!"));
|
---|
515 | return FALSE;
|
---|
516 | }
|
---|
517 |
|
---|
518 | uint8_t *pDst = (uint8_t*)pDstLRect->pBits;
|
---|
519 | uint8_t *pSrc = (uint8_t*)pSrcLRect->pBits;
|
---|
520 | for (LONG i = 0; i < DstH; ++i)
|
---|
521 | {
|
---|
522 | if (!(fMatch = !memcmp(pDst, pSrc, DstWBytes)))
|
---|
523 | {
|
---|
524 | vboxVDbgPrint(("not match!\n"));
|
---|
525 | if (fBreakOnMismatch)
|
---|
526 | Assert(0);
|
---|
527 | break;
|
---|
528 | }
|
---|
529 | pDst += pDstLRect->Pitch;
|
---|
530 | pSrc += pSrcLRect->Pitch;
|
---|
531 | }
|
---|
532 | return fMatch;
|
---|
533 | }
|
---|
534 |
|
---|
535 | BOOL vboxVDbgDoCheckRectsMatch(const VBOXWDDMDISP_RESOURCE *pDstRc, uint32_t iDstAlloc,
|
---|
536 | const VBOXWDDMDISP_RESOURCE *pSrcRc, uint32_t iSrcAlloc,
|
---|
537 | const RECT *pDstRect,
|
---|
538 | const RECT *pSrcRect,
|
---|
539 | BOOL fBreakOnMismatch)
|
---|
540 | {
|
---|
541 | BOOL fMatch = FALSE;
|
---|
542 | RECT DstRect = {0}, SrcRect = {0};
|
---|
543 | if (!pDstRect)
|
---|
544 | {
|
---|
545 | DstRect.left = 0;
|
---|
546 | DstRect.right = pDstRc->aAllocations[iDstAlloc].SurfDesc.width;
|
---|
547 | DstRect.top = 0;
|
---|
548 | DstRect.bottom = pDstRc->aAllocations[iDstAlloc].SurfDesc.height;
|
---|
549 | pDstRect = &DstRect;
|
---|
550 | }
|
---|
551 |
|
---|
552 | if (!pSrcRect)
|
---|
553 | {
|
---|
554 | SrcRect.left = 0;
|
---|
555 | SrcRect.right = pSrcRc->aAllocations[iSrcAlloc].SurfDesc.width;
|
---|
556 | SrcRect.top = 0;
|
---|
557 | SrcRect.bottom = pSrcRc->aAllocations[iSrcAlloc].SurfDesc.height;
|
---|
558 | pSrcRect = &SrcRect;
|
---|
559 | }
|
---|
560 |
|
---|
561 | if (pDstRc == pSrcRc
|
---|
562 | && iDstAlloc == iSrcAlloc)
|
---|
563 | {
|
---|
564 | if (!memcmp(pDstRect, pSrcRect, sizeof (*pDstRect)))
|
---|
565 | {
|
---|
566 | vboxVDbgPrint(("matching same rect of one allocation, skipping..\n"));
|
---|
567 | return TRUE;
|
---|
568 | }
|
---|
569 | WARN(("matching different rects of the same allocation, unsupported!"));
|
---|
570 | return FALSE;
|
---|
571 | }
|
---|
572 |
|
---|
573 | if (pDstRc->RcDesc.enmFormat != pSrcRc->RcDesc.enmFormat)
|
---|
574 | {
|
---|
575 | WARN(("matching different formats, unsupported!"));
|
---|
576 | return FALSE;
|
---|
577 | }
|
---|
578 |
|
---|
579 | DWORD bpp = pDstRc->aAllocations[iDstAlloc].SurfDesc.bpp;
|
---|
580 | if (!bpp)
|
---|
581 | {
|
---|
582 | WARN(("uninited bpp! unsupported!"));
|
---|
583 | return FALSE;
|
---|
584 | }
|
---|
585 |
|
---|
586 | LONG DstH, DstW, SrcH, SrcW;
|
---|
587 | DstH = pDstRect->bottom - pDstRect->top;
|
---|
588 | DstW = pDstRect->right - pDstRect->left;
|
---|
589 | SrcH = pSrcRect->bottom - pSrcRect->top;
|
---|
590 | SrcW = pSrcRect->right - pSrcRect->left;
|
---|
591 |
|
---|
592 | if(DstW != SrcW && DstH != SrcH)
|
---|
593 | {
|
---|
594 | WARN(("stretched comparison not supported!!"));
|
---|
595 | return FALSE;
|
---|
596 | }
|
---|
597 |
|
---|
598 | D3DLOCKED_RECT SrcLRect, DstLRect;
|
---|
599 | HRESULT hr = VBoxD3DIfLockRect((VBOXWDDMDISP_RESOURCE *)pDstRc, iDstAlloc, &DstLRect, pDstRect, D3DLOCK_READONLY);
|
---|
600 | if (FAILED(hr))
|
---|
601 | {
|
---|
602 | WARN(("VBoxD3DIfLockRect failed, hr(0x%x)", hr));
|
---|
603 | return FALSE;
|
---|
604 | }
|
---|
605 |
|
---|
606 | hr = VBoxD3DIfLockRect((VBOXWDDMDISP_RESOURCE *)pSrcRc, iSrcAlloc, &SrcLRect, pSrcRect, D3DLOCK_READONLY);
|
---|
607 | if (FAILED(hr))
|
---|
608 | {
|
---|
609 | WARN(("VBoxD3DIfLockRect failed, hr(0x%x)", hr));
|
---|
610 | hr = VBoxD3DIfUnlockRect((VBOXWDDMDISP_RESOURCE *)pDstRc, iDstAlloc);
|
---|
611 | return FALSE;
|
---|
612 | }
|
---|
613 |
|
---|
614 | fMatch = vboxVDbgDoCheckLRects(&DstLRect, pDstRect, &SrcLRect, pSrcRect, bpp, fBreakOnMismatch);
|
---|
615 |
|
---|
616 | hr = VBoxD3DIfUnlockRect((VBOXWDDMDISP_RESOURCE *)pDstRc, iDstAlloc);
|
---|
617 | Assert(hr == S_OK);
|
---|
618 |
|
---|
619 | hr = VBoxD3DIfUnlockRect((VBOXWDDMDISP_RESOURCE *)pSrcRc, iSrcAlloc);
|
---|
620 | Assert(hr == S_OK);
|
---|
621 |
|
---|
622 | return fMatch;
|
---|
623 | }
|
---|
624 |
|
---|
625 | void vboxVDbgDoPrintAlloc(const char * pPrefix, const VBOXWDDMDISP_RESOURCE *pRc, uint32_t iAlloc, const char * pSuffix)
|
---|
626 | {
|
---|
627 | Assert(pRc->cAllocations > iAlloc);
|
---|
628 | const VBOXWDDMDISP_ALLOCATION *pAlloc = &pRc->aAllocations[iAlloc];
|
---|
629 | BOOL bPrimary = pRc->RcDesc.fFlags.Primary;
|
---|
630 | BOOL bFrontBuf = FALSE;
|
---|
631 | if (bPrimary)
|
---|
632 | {
|
---|
633 | PVBOXWDDMDISP_SWAPCHAIN pSwapchain = vboxWddmSwapchainForAlloc((VBOXWDDMDISP_ALLOCATION *)pAlloc);
|
---|
634 | Assert(pSwapchain);
|
---|
635 | bFrontBuf = (vboxWddmSwapchainGetFb(pSwapchain)->pAlloc == pAlloc);
|
---|
636 | }
|
---|
637 | vboxVDbgPrint(("%s d3dWidth(%d), width(%d), height(%d), format(%d), usage(%s), %s", pPrefix,
|
---|
638 | pAlloc->SurfDesc.d3dWidth, pAlloc->SurfDesc.width, pAlloc->SurfDesc.height, pAlloc->SurfDesc.format,
|
---|
639 | bPrimary ?
|
---|
640 | (bFrontBuf ? "Front Buffer" : "Back Buffer")
|
---|
641 | : "?Everage? Alloc",
|
---|
642 | pSuffix));
|
---|
643 | }
|
---|
644 |
|
---|
645 | void vboxVDbgDoPrintRect(const char * pPrefix, const RECT *pRect, const char * pSuffix)
|
---|
646 | {
|
---|
647 | vboxVDbgPrint(("%s left(%d), top(%d), right(%d), bottom(%d) %s", pPrefix, pRect->left, pRect->top, pRect->right, pRect->bottom, pSuffix));
|
---|
648 | }
|
---|
649 |
|
---|
650 | # endif
|
---|
651 |
|
---|
652 | static VOID CALLBACK vboxVDbgTimerCb(__in PVOID lpParameter, __in BOOLEAN TimerOrWaitFired)
|
---|
653 | {
|
---|
654 | Assert(0);
|
---|
655 | }
|
---|
656 |
|
---|
657 | HRESULT vboxVDbgTimerStart(HANDLE hTimerQueue, HANDLE *phTimer, DWORD msTimeout)
|
---|
658 | {
|
---|
659 | if (!CreateTimerQueueTimer(phTimer, hTimerQueue,
|
---|
660 | vboxVDbgTimerCb,
|
---|
661 | NULL,
|
---|
662 | msTimeout, /* ms*/
|
---|
663 | 0,
|
---|
664 | WT_EXECUTEONLYONCE))
|
---|
665 | {
|
---|
666 | DWORD winEr = GetLastError();
|
---|
667 | AssertMsgFailed(("CreateTimerQueueTimer failed, winEr (%d)\n", winEr));
|
---|
668 | return E_FAIL;
|
---|
669 | }
|
---|
670 | return S_OK;
|
---|
671 | }
|
---|
672 |
|
---|
673 | HRESULT vboxVDbgTimerStop(HANDLE hTimerQueue, HANDLE hTimer)
|
---|
674 | {
|
---|
675 | if (!DeleteTimerQueueTimer(hTimerQueue, hTimer, NULL))
|
---|
676 | {
|
---|
677 | DWORD winEr = GetLastError();
|
---|
678 | AssertMsg(winEr == ERROR_IO_PENDING, ("DeleteTimerQueueTimer failed, winEr (%d)\n", winEr));
|
---|
679 | }
|
---|
680 | return S_OK;
|
---|
681 | }
|
---|
682 | #endif
|
---|
683 |
|
---|
684 | #if defined(VBOXWDDMDISP_DEBUG) || defined(VBOX_WDDMDISP_WITH_PROFILE)
|
---|
685 | BOOL vboxVDbgDoCheckExe(const char * pszName)
|
---|
686 | {
|
---|
687 | char *pszModule = vboxVDbgDoGetModuleName();
|
---|
688 | if (!pszModule)
|
---|
689 | return FALSE;
|
---|
690 | DWORD cbModule, cbName;
|
---|
691 | cbModule = strlen(pszModule);
|
---|
692 | cbName = strlen(pszName);
|
---|
693 | if (cbName > cbModule)
|
---|
694 | return FALSE;
|
---|
695 | if (_stricmp(pszName, pszModule + (cbModule - cbName)))
|
---|
696 | return FALSE;
|
---|
697 | return TRUE;
|
---|
698 | }
|
---|
699 | #endif
|
---|
700 |
|
---|
701 | #ifdef VBOXWDDMDISP_DEBUG_VEHANDLER
|
---|
702 |
|
---|
703 | static PVOID g_VBoxWDbgVEHandler = NULL;
|
---|
704 | LONG WINAPI vboxVDbgVectoredHandler(struct _EXCEPTION_POINTERS *pExceptionInfo)
|
---|
705 | {
|
---|
706 | PEXCEPTION_RECORD pExceptionRecord = pExceptionInfo->ExceptionRecord;
|
---|
707 | PCONTEXT pContextRecord = pExceptionInfo->ContextRecord;
|
---|
708 | switch (pExceptionRecord->ExceptionCode)
|
---|
709 | {
|
---|
710 | case EXCEPTION_BREAKPOINT:
|
---|
711 | case EXCEPTION_ACCESS_VIOLATION:
|
---|
712 | case EXCEPTION_STACK_OVERFLOW:
|
---|
713 | case EXCEPTION_ARRAY_BOUNDS_EXCEEDED:
|
---|
714 | case EXCEPTION_FLT_DIVIDE_BY_ZERO:
|
---|
715 | case EXCEPTION_FLT_INVALID_OPERATION:
|
---|
716 | case EXCEPTION_INT_DIVIDE_BY_ZERO:
|
---|
717 | case EXCEPTION_ILLEGAL_INSTRUCTION:
|
---|
718 | AssertRelease(0);
|
---|
719 | break;
|
---|
720 | default:
|
---|
721 | break;
|
---|
722 | }
|
---|
723 | return EXCEPTION_CONTINUE_SEARCH;
|
---|
724 | }
|
---|
725 |
|
---|
726 | void vboxVDbgVEHandlerRegister()
|
---|
727 | {
|
---|
728 | Assert(!g_VBoxWDbgVEHandler);
|
---|
729 | g_VBoxWDbgVEHandler = AddVectoredExceptionHandler(1,vboxVDbgVectoredHandler);
|
---|
730 | Assert(g_VBoxWDbgVEHandler);
|
---|
731 | }
|
---|
732 |
|
---|
733 | void vboxVDbgVEHandlerUnregister()
|
---|
734 | {
|
---|
735 | Assert(g_VBoxWDbgVEHandler);
|
---|
736 | ULONG uResult = RemoveVectoredExceptionHandler(g_VBoxWDbgVEHandler);
|
---|
737 | Assert(uResult);
|
---|
738 | g_VBoxWDbgVEHandler = NULL;
|
---|
739 | }
|
---|
740 |
|
---|
741 | #endif
|
---|
742 |
|
---|
743 | #if defined(VBOXWDDMDISP_DEBUG) || defined(LOG_TO_BACKDOOR_DRV)
|
---|
744 | void vboxDispLogDrvF(char * szString, ...)
|
---|
745 | {
|
---|
746 | char szBuffer[4096] = {0};
|
---|
747 | va_list pArgList;
|
---|
748 | va_start(pArgList, szString);
|
---|
749 | vboxDispLogDbgFormatStringV(szBuffer, sizeof (szBuffer), szString, pArgList);
|
---|
750 | va_end(pArgList);
|
---|
751 |
|
---|
752 | VBoxDispMpLoggerLog(szBuffer);
|
---|
753 | }
|
---|
754 | #endif
|
---|