VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispDbg.cpp@ 49263

Last change on this file since 49263 was 49263, checked in by vboxsync, 11 years ago

wddm/3d: profiling/logging

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette