VirtualBox

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

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

wddm: proper surf release

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 24.9 KB
Line 
1/* $Id: VBoxDispDbg.cpp 49449 2013-11-12 12:19:26Z 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 pSurf->Release();
324}
325
326VOID vboxVDbgDoDumpRcRect(const char * pPrefix, PVBOXWDDMDISP_ALLOCATION pAlloc,
327 IDirect3DResource9 *pD3DRc, RECT *pRect, const char * pSuffix, DWORD fFlags)
328{
329 VBOXVDBG_DUMP_INFO Info;
330 Info.fFlags = fFlags;
331 Info.pAlloc = pAlloc;
332 Info.pD3DRc = pD3DRc;
333 Info.pRect = pRect;
334 vboxVDbgDoDumpPerform(pPrefix, &Info, pSuffix, vboxVDbgRcRectContentsDumperCb, NULL);
335}
336
337VOID vboxVDbgDoDumpBb(const char * pPrefix, IDirect3DSwapChain9 *pSwapchainIf, const char * pSuffix, DWORD fFlags)
338{
339 IDirect3DSurface9 *pBb = NULL;
340 HRESULT hr = pSwapchainIf->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &pBb);
341 Assert(hr == S_OK);
342 if (FAILED(hr))
343 {
344 return;
345 }
346
347 Assert(pBb);
348 vboxVDbgDoDumpRcRect(pPrefix, NULL, pBb, NULL, pSuffix, fFlags);
349 pBb->Release();
350}
351
352VOID vboxVDbgDoDumpFb(const char * pPrefix, IDirect3DSwapChain9 *pSwapchainIf, const char * pSuffix, DWORD fFlags)
353{
354 IDirect3DSurface9 *pBb = NULL;
355 HRESULT hr = pSwapchainIf->GetBackBuffer(-1, D3DBACKBUFFER_TYPE_MONO, &pBb);
356 Assert(hr == S_OK);
357 if (FAILED(hr))
358 {
359 return;
360 }
361
362 Assert(pBb);
363 vboxVDbgDoDumpRcRect(pPrefix, NULL, pBb, NULL, pSuffix, fFlags);
364 pBb->Release();
365}
366
367
368#define VBOXVDBG_STRCASE(_t) \
369 case _t: return #_t;
370#define VBOXVDBG_STRCASE_UNKNOWN() \
371 default: Assert(0); return "Unknown";
372
373const char* vboxVDbgStrCubeFaceType(D3DCUBEMAP_FACES enmFace)
374{
375 switch (enmFace)
376 {
377 VBOXVDBG_STRCASE(D3DCUBEMAP_FACE_POSITIVE_X);
378 VBOXVDBG_STRCASE(D3DCUBEMAP_FACE_NEGATIVE_X);
379 VBOXVDBG_STRCASE(D3DCUBEMAP_FACE_POSITIVE_Y);
380 VBOXVDBG_STRCASE(D3DCUBEMAP_FACE_NEGATIVE_Y);
381 VBOXVDBG_STRCASE(D3DCUBEMAP_FACE_POSITIVE_Z);
382 VBOXVDBG_STRCASE(D3DCUBEMAP_FACE_NEGATIVE_Z);
383 VBOXVDBG_STRCASE_UNKNOWN();
384 }
385}
386
387VOID vboxVDbgDoDumpRt(const char * pPrefix, PVBOXWDDMDISP_DEVICE pDevice, const char * pSuffix, DWORD fFlags)
388{
389 for (UINT i = 0; i < pDevice->cRTs; ++i)
390 {
391 IDirect3DSurface9 *pRt;
392 PVBOXWDDMDISP_ALLOCATION pAlloc = pDevice->apRTs[i];
393 IDirect3DDevice9 *pDeviceIf = pDevice->pDevice9If;
394 HRESULT hr = pDeviceIf->GetRenderTarget(i, &pRt);
395 Assert(hr == S_OK);
396 if (hr == S_OK)
397 {
398// Assert(pAlloc->pD3DIf == pRt);
399 vboxVDbgDoDumpRcRect(pPrefix, pAlloc, NULL, NULL, pSuffix, fFlags);
400 pRt->Release();
401 }
402 else
403 {
404 vboxVDbgPrint((__FUNCTION__": ERROR getting rt: 0x%x", hr));
405 }
406 }
407}
408
409VOID vboxVDbgDoDumpSamplers(const char * pPrefix, PVBOXWDDMDISP_DEVICE pDevice, const char * pSuffix, DWORD fFlags)
410{
411 for (UINT i = 0, iSampler = 0; iSampler < pDevice->cSamplerTextures; ++i)
412 {
413 Assert(i < RT_ELEMENTS(pDevice->aSamplerTextures));
414 if (!pDevice->aSamplerTextures[i]) continue;
415 PVBOXWDDMDISP_RESOURCE pRc = pDevice->aSamplerTextures[i];
416 for (UINT j = 0; j < pRc->cAllocations; ++j)
417 {
418 PVBOXWDDMDISP_ALLOCATION pAlloc = &pRc->aAllocations[j];
419 vboxVDbgDoDumpRcRect(pPrefix, pAlloc, NULL, NULL, pSuffix, fFlags);
420 }
421 ++iSampler;
422 }
423}
424
425static DECLCALLBACK(void) vboxVDbgLockUnlockSurfTexContentsDumperCb(PVBOXVDBG_DUMP_INFO pInfo, BOOLEAN fBreak, void *pvDumper)
426{
427 const VBOXWDDMDISP_ALLOCATION *pAlloc = pInfo->pAlloc;
428 const RECT *pRect = pInfo->pRect;
429 UINT bpp = vboxWddmCalcBitsPerPixel(pAlloc->SurfDesc.format);
430 uint32_t width, height, pitch;
431 void *pvData;
432 if (pAlloc->LockInfo.fFlags.AreaValid)
433 {
434 width = pAlloc->LockInfo.Area.left - pAlloc->LockInfo.Area.right;
435 height = pAlloc->LockInfo.Area.bottom - pAlloc->LockInfo.Area.top;
436 }
437 else
438 {
439 width = pAlloc->SurfDesc.width;
440 height = pAlloc->SurfDesc.height;
441 }
442
443 if (pAlloc->LockInfo.fFlags.NotifyOnly)
444 {
445 pitch = pAlloc->SurfDesc.pitch;
446 pvData = ((uint8_t*)pAlloc->pvMem) + pitch*pRect->top + ((bpp*pRect->left) >> 3);
447 }
448 else
449 {
450 pvData = pAlloc->LockInfo.pvData;
451 }
452
453 vboxVDbgDoPrintDumpCmd("Surf Info", pvData, width, height, bpp, pitch);
454
455 if (fBreak)
456 {
457 Assert(0);
458 }
459}
460
461VOID vboxVDbgDoDumpLockUnlockSurfTex(const char * pPrefix, const VBOXWDDMDISP_ALLOCATION *pAlloc, const char * pSuffix, DWORD fFlags)
462{
463 Assert(!pAlloc->hSharedHandle);
464
465 RECT Rect;
466 const RECT *pRect;
467 Assert(!pAlloc->LockInfo.fFlags.RangeValid);
468 Assert(!pAlloc->LockInfo.fFlags.BoxValid);
469 if (pAlloc->LockInfo.fFlags.AreaValid)
470 {
471 pRect = &pAlloc->LockInfo.Area;
472 }
473 else
474 {
475 Rect.top = 0;
476 Rect.bottom = pAlloc->SurfDesc.height;
477 Rect.left = 0;
478 Rect.right = pAlloc->SurfDesc.width;
479 pRect = &Rect;
480 }
481
482 VBOXVDBG_DUMP_INFO Info;
483 Info.fFlags = fFlags;
484 Info.pAlloc = pAlloc;
485 Info.pD3DRc = NULL;
486 Info.pRect = pRect;
487 vboxVDbgDoDumpPerform(pPrefix, &Info, pSuffix, vboxVDbgLockUnlockSurfTexContentsDumperCb, NULL);
488}
489
490VOID vboxVDbgDoDumpLockSurfTex(const char * pPrefix, const D3DDDIARG_LOCK* pData, const char * pSuffix, DWORD fFlags)
491{
492 const VBOXWDDMDISP_RESOURCE *pRc = (const VBOXWDDMDISP_RESOURCE*)pData->hResource;
493 const VBOXWDDMDISP_ALLOCATION *pAlloc = &pRc->aAllocations[pData->SubResourceIndex];
494#ifdef VBOXWDDMDISP_DEBUG
495 VBOXWDDMDISP_ALLOCATION *pUnconstpAlloc = (VBOXWDDMDISP_ALLOCATION *)pAlloc;
496 pUnconstpAlloc->LockInfo.pvData = pData->pSurfData;
497#endif
498 vboxVDbgDoDumpLockUnlockSurfTex(pPrefix, pAlloc, pSuffix, fFlags);
499}
500
501VOID vboxVDbgDoDumpUnlockSurfTex(const char * pPrefix, const D3DDDIARG_UNLOCK* pData, const char * pSuffix, DWORD fFlags)
502{
503 const VBOXWDDMDISP_RESOURCE *pRc = (const VBOXWDDMDISP_RESOURCE*)pData->hResource;
504 const VBOXWDDMDISP_ALLOCATION *pAlloc = &pRc->aAllocations[pData->SubResourceIndex];
505 vboxVDbgDoDumpLockUnlockSurfTex(pPrefix, pAlloc, pSuffix, fFlags);
506}
507
508BOOL vboxVDbgDoCheckLRects(D3DLOCKED_RECT *pDstLRect, const RECT *pDstRect, D3DLOCKED_RECT *pSrcLRect, const RECT *pSrcRect, DWORD bpp, BOOL fBreakOnMismatch)
509{
510 LONG DstH, DstW, SrcH, SrcW, DstWBytes;
511 BOOL fMatch = FALSE;
512 DstH = pDstRect->bottom - pDstRect->top;
513 DstW = pDstRect->right - pDstRect->left;
514 SrcH = pSrcRect->bottom - pSrcRect->top;
515 SrcW = pSrcRect->right - pSrcRect->left;
516
517 DstWBytes = ((DstW * bpp + 7) >> 3);
518
519 if(DstW != SrcW && DstH != SrcH)
520 {
521 WARN(("stretched comparison not supported!!"));
522 return FALSE;
523 }
524
525 uint8_t *pDst = (uint8_t*)pDstLRect->pBits;
526 uint8_t *pSrc = (uint8_t*)pSrcLRect->pBits;
527 for (LONG i = 0; i < DstH; ++i)
528 {
529 if (!(fMatch = !memcmp(pDst, pSrc, DstWBytes)))
530 {
531 vboxVDbgPrint(("not match!\n"));
532 if (fBreakOnMismatch)
533 Assert(0);
534 break;
535 }
536 pDst += pDstLRect->Pitch;
537 pSrc += pSrcLRect->Pitch;
538 }
539 return fMatch;
540}
541
542BOOL vboxVDbgDoCheckRectsMatch(const VBOXWDDMDISP_RESOURCE *pDstRc, uint32_t iDstAlloc,
543 const VBOXWDDMDISP_RESOURCE *pSrcRc, uint32_t iSrcAlloc,
544 const RECT *pDstRect,
545 const RECT *pSrcRect,
546 BOOL fBreakOnMismatch)
547{
548 BOOL fMatch = FALSE;
549 RECT DstRect = {0}, SrcRect = {0};
550 if (!pDstRect)
551 {
552 DstRect.left = 0;
553 DstRect.right = pDstRc->aAllocations[iDstAlloc].SurfDesc.width;
554 DstRect.top = 0;
555 DstRect.bottom = pDstRc->aAllocations[iDstAlloc].SurfDesc.height;
556 pDstRect = &DstRect;
557 }
558
559 if (!pSrcRect)
560 {
561 SrcRect.left = 0;
562 SrcRect.right = pSrcRc->aAllocations[iSrcAlloc].SurfDesc.width;
563 SrcRect.top = 0;
564 SrcRect.bottom = pSrcRc->aAllocations[iSrcAlloc].SurfDesc.height;
565 pSrcRect = &SrcRect;
566 }
567
568 if (pDstRc == pSrcRc
569 && iDstAlloc == iSrcAlloc)
570 {
571 if (!memcmp(pDstRect, pSrcRect, sizeof (*pDstRect)))
572 {
573 vboxVDbgPrint(("matching same rect of one allocation, skipping..\n"));
574 return TRUE;
575 }
576 WARN(("matching different rects of the same allocation, unsupported!"));
577 return FALSE;
578 }
579
580 if (pDstRc->RcDesc.enmFormat != pSrcRc->RcDesc.enmFormat)
581 {
582 WARN(("matching different formats, unsupported!"));
583 return FALSE;
584 }
585
586 DWORD bpp = pDstRc->aAllocations[iDstAlloc].SurfDesc.bpp;
587 if (!bpp)
588 {
589 WARN(("uninited bpp! unsupported!"));
590 return FALSE;
591 }
592
593 LONG DstH, DstW, SrcH, SrcW;
594 DstH = pDstRect->bottom - pDstRect->top;
595 DstW = pDstRect->right - pDstRect->left;
596 SrcH = pSrcRect->bottom - pSrcRect->top;
597 SrcW = pSrcRect->right - pSrcRect->left;
598
599 if(DstW != SrcW && DstH != SrcH)
600 {
601 WARN(("stretched comparison not supported!!"));
602 return FALSE;
603 }
604
605 D3DLOCKED_RECT SrcLRect, DstLRect;
606 HRESULT hr = VBoxD3DIfLockRect((VBOXWDDMDISP_RESOURCE *)pDstRc, iDstAlloc, &DstLRect, pDstRect, D3DLOCK_READONLY);
607 if (FAILED(hr))
608 {
609 WARN(("VBoxD3DIfLockRect failed, hr(0x%x)", hr));
610 return FALSE;
611 }
612
613 hr = VBoxD3DIfLockRect((VBOXWDDMDISP_RESOURCE *)pSrcRc, iSrcAlloc, &SrcLRect, pSrcRect, D3DLOCK_READONLY);
614 if (FAILED(hr))
615 {
616 WARN(("VBoxD3DIfLockRect failed, hr(0x%x)", hr));
617 hr = VBoxD3DIfUnlockRect((VBOXWDDMDISP_RESOURCE *)pDstRc, iDstAlloc);
618 return FALSE;
619 }
620
621 fMatch = vboxVDbgDoCheckLRects(&DstLRect, pDstRect, &SrcLRect, pSrcRect, bpp, fBreakOnMismatch);
622
623 hr = VBoxD3DIfUnlockRect((VBOXWDDMDISP_RESOURCE *)pDstRc, iDstAlloc);
624 Assert(hr == S_OK);
625
626 hr = VBoxD3DIfUnlockRect((VBOXWDDMDISP_RESOURCE *)pSrcRc, iSrcAlloc);
627 Assert(hr == S_OK);
628
629 return fMatch;
630}
631
632void vboxVDbgDoPrintAlloc(const char * pPrefix, const VBOXWDDMDISP_RESOURCE *pRc, uint32_t iAlloc, const char * pSuffix)
633{
634 Assert(pRc->cAllocations > iAlloc);
635 const VBOXWDDMDISP_ALLOCATION *pAlloc = &pRc->aAllocations[iAlloc];
636 BOOL bPrimary = pRc->RcDesc.fFlags.Primary;
637 BOOL bFrontBuf = FALSE;
638 if (bPrimary)
639 {
640 PVBOXWDDMDISP_SWAPCHAIN pSwapchain = vboxWddmSwapchainForAlloc((VBOXWDDMDISP_ALLOCATION *)pAlloc);
641 Assert(pSwapchain);
642 bFrontBuf = (vboxWddmSwapchainGetFb(pSwapchain)->pAlloc == pAlloc);
643 }
644 vboxVDbgPrint(("%s d3dWidth(%d), width(%d), height(%d), format(%d), usage(%s), %s", pPrefix,
645 pAlloc->SurfDesc.d3dWidth, pAlloc->SurfDesc.width, pAlloc->SurfDesc.height, pAlloc->SurfDesc.format,
646 bPrimary ?
647 (bFrontBuf ? "Front Buffer" : "Back Buffer")
648 : "?Everage? Alloc",
649 pSuffix));
650}
651
652void vboxVDbgDoPrintRect(const char * pPrefix, const RECT *pRect, const char * pSuffix)
653{
654 vboxVDbgPrint(("%s left(%d), top(%d), right(%d), bottom(%d) %s", pPrefix, pRect->left, pRect->top, pRect->right, pRect->bottom, pSuffix));
655}
656
657# endif
658
659static VOID CALLBACK vboxVDbgTimerCb(__in PVOID lpParameter, __in BOOLEAN TimerOrWaitFired)
660{
661 Assert(0);
662}
663
664HRESULT vboxVDbgTimerStart(HANDLE hTimerQueue, HANDLE *phTimer, DWORD msTimeout)
665{
666 if (!CreateTimerQueueTimer(phTimer, hTimerQueue,
667 vboxVDbgTimerCb,
668 NULL,
669 msTimeout, /* ms*/
670 0,
671 WT_EXECUTEONLYONCE))
672 {
673 DWORD winEr = GetLastError();
674 AssertMsgFailed(("CreateTimerQueueTimer failed, winEr (%d)\n", winEr));
675 return E_FAIL;
676 }
677 return S_OK;
678}
679
680HRESULT vboxVDbgTimerStop(HANDLE hTimerQueue, HANDLE hTimer)
681{
682 if (!DeleteTimerQueueTimer(hTimerQueue, hTimer, NULL))
683 {
684 DWORD winEr = GetLastError();
685 AssertMsg(winEr == ERROR_IO_PENDING, ("DeleteTimerQueueTimer failed, winEr (%d)\n", winEr));
686 }
687 return S_OK;
688}
689#endif
690
691#if defined(VBOXWDDMDISP_DEBUG) || defined(VBOX_WDDMDISP_WITH_PROFILE)
692BOOL vboxVDbgDoCheckExe(const char * pszName)
693{
694 char *pszModule = vboxVDbgDoGetModuleName();
695 if (!pszModule)
696 return FALSE;
697 DWORD cbModule, cbName;
698 cbModule = strlen(pszModule);
699 cbName = strlen(pszName);
700 if (cbName > cbModule)
701 return FALSE;
702 if (_stricmp(pszName, pszModule + (cbModule - cbName)))
703 return FALSE;
704 return TRUE;
705}
706#endif
707
708#ifdef VBOXWDDMDISP_DEBUG_VEHANDLER
709
710static PVOID g_VBoxWDbgVEHandler = NULL;
711LONG WINAPI vboxVDbgVectoredHandler(struct _EXCEPTION_POINTERS *pExceptionInfo)
712{
713 PEXCEPTION_RECORD pExceptionRecord = pExceptionInfo->ExceptionRecord;
714 PCONTEXT pContextRecord = pExceptionInfo->ContextRecord;
715 switch (pExceptionRecord->ExceptionCode)
716 {
717 case EXCEPTION_BREAKPOINT:
718 case EXCEPTION_ACCESS_VIOLATION:
719 case EXCEPTION_STACK_OVERFLOW:
720 case EXCEPTION_ARRAY_BOUNDS_EXCEEDED:
721 case EXCEPTION_FLT_DIVIDE_BY_ZERO:
722 case EXCEPTION_FLT_INVALID_OPERATION:
723 case EXCEPTION_INT_DIVIDE_BY_ZERO:
724 case EXCEPTION_ILLEGAL_INSTRUCTION:
725 AssertRelease(0);
726 break;
727 default:
728 break;
729 }
730 return EXCEPTION_CONTINUE_SEARCH;
731}
732
733void vboxVDbgVEHandlerRegister()
734{
735 Assert(!g_VBoxWDbgVEHandler);
736 g_VBoxWDbgVEHandler = AddVectoredExceptionHandler(1,vboxVDbgVectoredHandler);
737 Assert(g_VBoxWDbgVEHandler);
738}
739
740void vboxVDbgVEHandlerUnregister()
741{
742 Assert(g_VBoxWDbgVEHandler);
743 ULONG uResult = RemoveVectoredExceptionHandler(g_VBoxWDbgVEHandler);
744 Assert(uResult);
745 g_VBoxWDbgVEHandler = NULL;
746}
747
748#endif
749
750#if defined(VBOXWDDMDISP_DEBUG) || defined(LOG_TO_BACKDOOR_DRV)
751void vboxDispLogDrvF(char * szString, ...)
752{
753 char szBuffer[4096] = {0};
754 va_list pArgList;
755 va_start(pArgList, szString);
756 vboxDispLogDbgFormatStringV(szBuffer, sizeof (szBuffer), szString, pArgList);
757 va_end(pArgList);
758
759 VBoxDispMpLoggerLog(szBuffer);
760}
761#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