VirtualBox

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

Last change on this file since 38331 was 38331, checked in by vboxsync, 13 years ago

wddm/wine: fix winsat crashes (context adjustments for multiswapchains), basics for window creation inside wine

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 18.6 KB
Line 
1/* $Id: VBoxDispDbg.cpp 38331 2011-08-05 15:29:06Z vboxsync $ */
2
3/** @file
4 * VBoxVideo Display D3D User mode dll
5 */
6
7/*
8 * Copyright (C) 2011 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
51#ifdef VBOXWDDMDISP_DEBUG
52#define VBOXWDDMDISP_DEBUG_DUMP_DEFAULT 0
53DWORD g_VBoxVDbgFDumpSetTexture = VBOXWDDMDISP_DEBUG_DUMP_DEFAULT;
54DWORD g_VBoxVDbgFDumpDrawPrim = VBOXWDDMDISP_DEBUG_DUMP_DEFAULT;
55DWORD g_VBoxVDbgFDumpTexBlt = VBOXWDDMDISP_DEBUG_DUMP_DEFAULT;
56DWORD g_VBoxVDbgFDumpBlt = VBOXWDDMDISP_DEBUG_DUMP_DEFAULT;
57DWORD g_VBoxVDbgFDumpRtSynch = VBOXWDDMDISP_DEBUG_DUMP_DEFAULT;
58DWORD g_VBoxVDbgFDumpFlush = VBOXWDDMDISP_DEBUG_DUMP_DEFAULT;
59DWORD g_VBoxVDbgFDumpShared = VBOXWDDMDISP_DEBUG_DUMP_DEFAULT;
60DWORD g_VBoxVDbgFDumpLock = VBOXWDDMDISP_DEBUG_DUMP_DEFAULT;
61DWORD g_VBoxVDbgFDumpUnlock = VBOXWDDMDISP_DEBUG_DUMP_DEFAULT;
62
63DWORD g_VBoxVDbgFBreakShared = VBOXWDDMDISP_DEBUG_DUMP_DEFAULT;
64
65DWORD g_VBoxVDbgPid = 0;
66typedef enum
67{
68 VBOXDISPDBG_STATE_UNINITIALIZED = 0,
69 VBOXDISPDBG_STATE_INITIALIZING,
70 VBOXDISPDBG_STATE_INITIALIZED,
71} VBOXDISPDBG_STATE;
72
73typedef struct VBOXDISPDBG
74{
75 VBOXDISPKMT_CALLBACKS KmtCallbacks;
76 VBOXDISPDBG_STATE enmState;
77} VBOXDISPDBG, *PVBOXDISPDBG;
78
79static VBOXDISPDBG g_VBoxDispDbg = {0};
80
81PVBOXDISPDBG vboxDispDbgGet()
82{
83 if (ASMAtomicCmpXchgU32((volatile uint32_t *)&g_VBoxDispDbg.enmState, VBOXDISPDBG_STATE_INITIALIZING, VBOXDISPDBG_STATE_UNINITIALIZED))
84 {
85 HRESULT hr = vboxDispKmtCallbacksInit(&g_VBoxDispDbg.KmtCallbacks);
86 Assert(hr == S_OK);
87 if (hr == S_OK)
88 {
89 ASMAtomicWriteU32((volatile uint32_t *)&g_VBoxDispDbg.enmState, VBOXDISPDBG_STATE_INITIALIZED);
90 return &g_VBoxDispDbg;
91 }
92 else
93 {
94 ASMAtomicWriteU32((volatile uint32_t *)&g_VBoxDispDbg.enmState, VBOXDISPDBG_STATE_UNINITIALIZED);
95 }
96 }
97 else if (ASMAtomicReadU32((volatile uint32_t *)&g_VBoxDispDbg.enmState) == VBOXDISPDBG_STATE_INITIALIZED)
98 {
99 return &g_VBoxDispDbg;
100 }
101 Assert(0);
102 return NULL;
103}
104
105void vboxDispLogDrv(char * szString)
106{
107 PVBOXDISPDBG pDbg = vboxDispDbgGet();
108 if (!pDbg)
109 {
110 /* do not use WARN her esince this would lead to a recursion */
111 WARN_BREAK();
112 return;
113 }
114
115 VBOXDISPKMT_ADAPTER Adapter;
116 HRESULT hr = vboxDispKmtOpenAdapter(&pDbg->KmtCallbacks, &Adapter);
117 if (hr == S_OK)
118 {
119 uint32_t cbString = (uint32_t)strlen(szString) + 1;
120 uint32_t cbCmd = RT_OFFSETOF(VBOXDISPIFESCAPE_DBGPRINT, aStringBuf[cbString]);
121 PVBOXDISPIFESCAPE_DBGPRINT pCmd = (PVBOXDISPIFESCAPE_DBGPRINT)RTMemAllocZ(cbCmd);
122 if (pCmd)
123 {
124 pCmd->EscapeHdr.escapeCode = VBOXESC_DBGPRINT;
125 memcpy(pCmd->aStringBuf, szString, cbString);
126
127 D3DKMT_ESCAPE EscapeData = {0};
128 EscapeData.hAdapter = Adapter.hAdapter;
129 //EscapeData.hDevice = NULL;
130 EscapeData.Type = D3DKMT_ESCAPE_DRIVERPRIVATE;
131 // EscapeData.Flags.HardwareAccess = 1;
132 EscapeData.pPrivateDriverData = pCmd;
133 EscapeData.PrivateDriverDataSize = cbCmd;
134 //EscapeData.hContext = NULL;
135
136 int Status = pDbg->KmtCallbacks.pfnD3DKMTEscape(&EscapeData);
137 if (Status)
138 {
139 WARN_BREAK();
140 }
141
142 RTMemFree(pCmd);
143 }
144 else
145 {
146 WARN_BREAK();
147 }
148 hr = vboxDispKmtCloseAdapter(&Adapter);
149 if(hr != S_OK)
150 {
151 WARN_BREAK();
152 }
153 }
154}
155
156void vboxDispLogDrvF(char * szString, ...)
157{
158 char szBuffer[4096] = {0};
159 va_list pArgList;
160 va_start(pArgList, szString);
161 _vsnprintf(szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0]), szString, pArgList);
162 va_end(pArgList);
163
164 vboxDispLogDrv(szBuffer);
165}
166
167void vboxDispLogDbgPrintF(char * szString, ...)
168{
169 char szBuffer[4096] = {0};
170 va_list pArgList;
171 va_start(pArgList, szString);
172 _vsnprintf(szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0]), szString, pArgList);
173 va_end(pArgList);
174
175 OutputDebugStringA(szBuffer);
176}
177
178
179VOID vboxVDbgDoDumpSurfRectByAlloc(const char * pPrefix, PVBOXWDDMDISP_ALLOCATION pAlloc, const RECT *pRect, const char* pSuffix)
180{
181 vboxVDbgDoDumpSurfRectByRc(pPrefix, pAlloc->pRc, pAlloc->iAlloc, pRect, pSuffix);
182}
183
184VOID vboxVDbgDoPrintDumpCmd(const void *pvData, uint32_t width, uint32_t height, uint32_t bpp, uint32_t pitch)
185{
186 vboxVDbgPrint(("<?dml?><exec cmd=\"!vbvdbg.ms 0x%p 0n%d 0n%d 0n%d 0n%d\">surface info</exec>, ( !vbvdbg.ms 0x%p 0n%d 0n%d 0n%d 0n%d )\n",
187 pvData, width, height, bpp, pitch,
188 pvData, width, height, bpp, pitch));
189}
190
191VOID vboxVDbgDoDumpAllocRect(const char * pPrefix, PVBOXWDDMDISP_ALLOCATION pAlloc, const RECT *pRect, const char* pSuffix)
192{
193 if (pPrefix)
194 {
195 vboxVDbgPrint(("%s", pPrefix));
196 }
197
198 Assert(pAlloc->hAllocation);
199
200 HANDLE hSharedHandle = pAlloc->hSharedHandle;
201
202 vboxVDbgPrint(("SharedHandle: (0x%p)\n", hSharedHandle));
203
204 D3DDDICB_LOCK LockData;
205 LockData.hAllocation = pAlloc->hAllocation;
206 LockData.PrivateDriverData = 0;
207 LockData.NumPages = 0;
208 LockData.pPages = NULL;
209 LockData.pData = NULL; /* out */
210 LockData.Flags.Value = 0;
211 LockData.Flags.LockEntire =1;
212 LockData.Flags.ReadOnly = 1;
213
214 PVBOXWDDMDISP_DEVICE pDevice = pAlloc->pRc->pDevice;
215
216 HRESULT hr = pDevice->RtCallbacks.pfnLockCb(pDevice->hDevice, &LockData);
217 Assert(hr == S_OK);
218 if (hr == S_OK)
219 {
220 UINT bpp = vboxWddmCalcBitsPerPixel(pAlloc->SurfDesc.format);
221 vboxVDbgDoPrintDumpCmd(LockData.pData, pAlloc->D3DWidth, pAlloc->SurfDesc.height, bpp, pAlloc->SurfDesc.pitch);
222 if (pRect)
223 {
224 Assert(pRect->right > pRect->left);
225 Assert(pRect->bottom > pRect->top);
226 vboxVDbgDoPrintRect("rect: ", pRect, "\n");
227 vboxVDbgDoPrintDumpCmd(((uint8_t*)LockData.pData) + (pRect->top * pAlloc->SurfDesc.pitch) + ((pRect->left * bpp) >> 3),
228 pRect->right - pRect->left, pRect->bottom - pRect->top, bpp, pAlloc->SurfDesc.pitch);
229 }
230 Assert(0);
231
232 D3DDDICB_UNLOCK DdiUnlock;
233
234 DdiUnlock.NumAllocations = 1;
235 DdiUnlock.phAllocations = &pAlloc->hAllocation;
236
237 hr = pDevice->RtCallbacks.pfnUnlockCb(pDevice->hDevice, &DdiUnlock);
238 Assert(hr == S_OK);
239 }
240 if (pSuffix)
241 {
242 vboxVDbgPrint(("%s\n", pSuffix));
243 }
244}
245
246
247VOID vboxVDbgDoDumpSurfRectByRc(const char * pPrefix, const PVBOXWDDMDISP_RESOURCE pRc, uint32_t iAlloc, const RECT *pRect, const char* pSuffix)
248{
249 Assert(pRc->cAllocations > iAlloc);
250 BOOL bReleaseSurf = false;
251 IDirect3DSurface9 *pSurf;
252 HRESULT hr = vboxWddmSurfGet(pRc, iAlloc, &pSurf);
253 Assert(hr == S_OK);
254 if (hr == S_OK)
255 {
256 vboxVDbgDoDumpSurfRect(pPrefix, pSurf, pRect, pSuffix, true);
257 pSurf->Release();
258 }
259}
260
261VOID vboxVDbgDoDumpSurfRect(const char * pPrefix, IDirect3DSurface9 *pSurf, const RECT *pRect, const char * pSuffix, bool bBreak)
262{
263 if (pPrefix)
264 {
265 vboxVDbgPrint(("%s", pPrefix));
266 }
267
268 D3DSURFACE_DESC Desc;
269 HRESULT hr = pSurf->GetDesc(&Desc);
270 Assert(hr == S_OK);
271 if (hr == S_OK)
272 {
273 D3DLOCKED_RECT Lr;
274 hr = pSurf->LockRect(&Lr, NULL, D3DLOCK_READONLY);
275 Assert(hr == S_OK);
276 if (hr == S_OK)
277 {
278 UINT bpp = vboxWddmCalcBitsPerPixel((D3DDDIFORMAT)Desc.Format);
279 vboxVDbgDoPrintDumpCmd(Lr.pBits, Desc.Width, Desc.Height, bpp, Lr.Pitch);
280 if (pRect)
281 {
282 Assert(pRect->right > pRect->left);
283 Assert(pRect->bottom > pRect->top);
284 vboxVDbgDoPrintRect("rect: ", pRect, "\n");
285 vboxVDbgDoPrintDumpCmd(((uint8_t*)Lr.pBits) + (pRect->top * Lr.Pitch) + ((pRect->left * bpp) >> 3),
286 pRect->right - pRect->left, pRect->bottom - pRect->top, bpp, Lr.Pitch);
287 }
288
289 if (bBreak)
290 {
291 Assert(0);
292
293 hr = pSurf->UnlockRect();
294 Assert(hr == S_OK);
295 }
296 }
297 }
298
299 if (pSuffix)
300 {
301 vboxVDbgPrint(("%s", pSuffix));
302 }
303}
304
305VOID vboxVDbgDoDumpSurf(const char * pPrefix, IDirect3DSurface9 *pSurf, const char * pSuffix)
306{
307 vboxVDbgDoDumpSurfRect(pPrefix, pSurf, NULL, pSuffix, true);
308}
309
310#define VBOXVDBG_STRCASE(_t) \
311 case _t: return #_t;
312#define VBOXVDBG_STRCASE_UNKNOWN() \
313 default: Assert(0); return "Unknown";
314
315const char* vboxVDbgStrCubeFaceType(D3DCUBEMAP_FACES enmFace)
316{
317 switch (enmFace)
318 {
319 VBOXVDBG_STRCASE(D3DCUBEMAP_FACE_POSITIVE_X);
320 VBOXVDBG_STRCASE(D3DCUBEMAP_FACE_NEGATIVE_X);
321 VBOXVDBG_STRCASE(D3DCUBEMAP_FACE_POSITIVE_Y);
322 VBOXVDBG_STRCASE(D3DCUBEMAP_FACE_NEGATIVE_Y);
323 VBOXVDBG_STRCASE(D3DCUBEMAP_FACE_POSITIVE_Z);
324 VBOXVDBG_STRCASE(D3DCUBEMAP_FACE_NEGATIVE_Z);
325 VBOXVDBG_STRCASE_UNKNOWN();
326 }
327}
328
329VOID vboxVDbgDoDumpRcRect(const char * pPrefix, IDirect3DResource9 *pRc, const RECT *pRect, const char * pSuffix)
330{
331 if (pPrefix)
332 {
333 vboxVDbgPrint(("%s", pPrefix));
334 }
335
336 switch (pRc->GetType())
337 {
338 case D3DRTYPE_TEXTURE:
339 {
340 vboxVDbgPrint(("this is a texture\n"));
341
342 IDirect3DTexture9 *pTex = (IDirect3DTexture9*)pRc;
343 IDirect3DSurface9 *pSurf;
344 HRESULT hr = pTex->GetSurfaceLevel(0, &pSurf);
345 Assert(hr == S_OK);
346 if (hr == S_OK)
347 {
348 vboxVDbgDoDumpSurfRect("", pSurf, pRect, "\n", true);
349 pSurf->Release();
350 }
351 break;
352 }
353 case D3DRTYPE_CUBETEXTURE:
354 {
355 vboxVDbgPrint(("this is a cube texture\n"));
356
357 IDirect3DCubeTexture9 *pCubeTex = (IDirect3DCubeTexture9*)pRc;
358 IDirect3DSurface9 *apSurf[6] = {0};
359 for (UINT i = D3DCUBEMAP_FACE_POSITIVE_X; i < D3DCUBEMAP_FACE_POSITIVE_X + 6; ++i)
360 {
361 vboxVDbgPrint(("face %s: ", vboxVDbgStrCubeFaceType((D3DCUBEMAP_FACES)i)));
362
363 HRESULT hr = pCubeTex->GetCubeMapSurface((D3DCUBEMAP_FACES)i, 0, &apSurf[i]);
364 Assert(hr == S_OK);
365 if (hr == S_OK)
366 {
367 vboxVDbgDoDumpSurfRect("", apSurf[i], pRect, "\n", false);
368 }
369 else
370 {
371 Assert(0);
372 }
373 }
374
375 Assert(0);
376
377 for (UINT i = D3DCUBEMAP_FACE_POSITIVE_X; i < D3DCUBEMAP_FACE_POSITIVE_X + 6; ++i)
378 {
379 apSurf[i]->UnlockRect();
380 apSurf[i]->Release();
381 }
382
383 break;
384 }
385 case D3DRTYPE_SURFACE:
386 {
387 vboxVDbgPrint(("this is a surface\n"));
388 IDirect3DSurface9 *pSurf = (IDirect3DSurface9 *)pRc;
389 vboxVDbgDoDumpSurfRect("", pSurf, pRect, "\n", true);
390 break;
391 }
392 default:
393 vboxVDbgPrint(("unsupported rc type\n"));
394 Assert(0);
395 }
396
397 if (pSuffix)
398 {
399 vboxVDbgPrint(("%s", pSuffix));
400 }
401}
402
403VOID vboxVDbgDoDumpRcRectByAlloc(const char * pPrefix, const PVBOXWDDMDISP_ALLOCATION pAlloc, IDirect3DResource9 *pD3DIf, const RECT *pRect, const char* pSuffix)
404{
405 if (pPrefix)
406 vboxVDbgPrint(("%s", pPrefix));
407
408 if (!pD3DIf)
409 {
410 pD3DIf = (IDirect3DResource9*)pAlloc->pD3DIf;
411 }
412
413 vboxVDbgPrint(("Rc(0x%p), pAlloc(0x%x), pD3DIf(0x%p), SharedHandle(0x%p)\n", pAlloc->pRc, pAlloc, pD3DIf, pAlloc->pRc->aAllocations[0].hSharedHandle));
414
415 vboxVDbgDoDumpRcRect("", pD3DIf, pRect, pSuffix);
416}
417
418VOID vboxVDbgDoDumpRcRectByRc(const char * pPrefix, const PVBOXWDDMDISP_RESOURCE pRc, const RECT *pRect, const char* pSuffix)
419{
420 vboxVDbgDoDumpRcRectByAlloc(pPrefix, &pRc->aAllocations[0], NULL, pRect, pSuffix);
421}
422
423VOID vboxVDbgDoDumpTex(const char * pPrefix, IDirect3DBaseTexture9 *pTexBase, const char * pSuffix)
424{
425 vboxVDbgDoDumpRcRect(pPrefix, pTexBase, NULL, pSuffix);
426}
427
428VOID vboxVDbgDoDumpRt(const char * pPrefix, PVBOXWDDMDISP_DEVICE pDevice, const char * pSuffix)
429{
430 for (UINT i = 0; i < pDevice->cRTs; ++i)
431 {
432 IDirect3DSurface9 *pRt;
433 PVBOXWDDMDISP_ALLOCATION pAlloc = pDevice->apRTs[i];
434 IDirect3DDevice9 *pDeviceIf = pDevice->pDevice9If;
435 HRESULT hr = pDeviceIf->GetRenderTarget(i, &pRt);
436 Assert(hr == S_OK);
437 if (hr == S_OK)
438 {
439// Assert(pAlloc->pD3DIf == pRt);
440 vboxVDbgDoDumpRcRectByAlloc(pPrefix, pAlloc, NULL, NULL, "\n");
441 pRt->Release();
442 }
443 else
444 {
445 vboxVDbgPrint((__FUNCTION__": ERROR getting rt: 0x%x", hr));
446 }
447 }
448}
449
450VOID vboxVDbgDoDumpLockUnlockSurfTex(const char * pPrefix, const PVBOXWDDMDISP_ALLOCATION pAlloc, const char * pSuffix, bool fBreak)
451{
452 if (pPrefix)
453 {
454 vboxVDbgPrint(("%s", pPrefix));
455 }
456
457 Assert(!pAlloc->hSharedHandle);
458
459 UINT bpp = vboxWddmCalcBitsPerPixel(pAlloc->SurfDesc.format);
460 uint32_t width, height, pitch;
461 RECT Rect, *pRect;
462 void *pvData;
463 Assert(!pAlloc->LockInfo.fFlags.RangeValid);
464 Assert(!pAlloc->LockInfo.fFlags.BoxValid);
465 if (pAlloc->LockInfo.fFlags.AreaValid)
466 {
467 pRect = &pAlloc->LockInfo.Area;
468 width = pAlloc->LockInfo.Area.left - pAlloc->LockInfo.Area.right;
469 height = pAlloc->LockInfo.Area.bottom - pAlloc->LockInfo.Area.top;
470 }
471 else
472 {
473 width = pAlloc->SurfDesc.width;
474 height = pAlloc->SurfDesc.height;
475 Rect.top = 0;
476 Rect.bottom = height;
477 Rect.left = 0;
478 Rect.right = width;
479 pRect = &Rect;
480 }
481
482 if (pAlloc->LockInfo.fFlags.NotifyOnly)
483 {
484 pitch = pAlloc->SurfDesc.pitch;
485 pvData = ((uint8_t*)pAlloc->pvMem) + pitch*pRect->top + ((bpp*pRect->left) >> 3);
486 }
487 else
488 {
489 pvData = pAlloc->LockInfo.pvData;
490 }
491
492 vboxVDbgPrint(("pRc(0x%p) iAlloc(%d), type(%d), cLocks(%d)\n", pAlloc->pRc, pAlloc->iAlloc, pAlloc->enmD3DIfType, pAlloc->LockInfo.cLocks));
493
494 vboxVDbgDoPrintDumpCmd(pvData, width, height, bpp, pitch);
495
496 if (fBreak)
497 {
498 Assert(0);
499 }
500
501 if (pSuffix)
502 {
503 vboxVDbgPrint(("%s", pSuffix));
504 }
505
506}
507
508VOID vboxVDbgDoDumpLockSurfTex(const char * pPrefix, const D3DDDIARG_LOCK* pData, const char * pSuffix, bool fBreak)
509{
510 const PVBOXWDDMDISP_RESOURCE pRc = (const PVBOXWDDMDISP_RESOURCE)pData->hResource;
511 const PVBOXWDDMDISP_ALLOCATION pAlloc = &pRc->aAllocations[pData->SubResourceIndex];
512 pAlloc->LockInfo.pvData = pData->pSurfData;
513 vboxVDbgDoDumpLockUnlockSurfTex(pPrefix, pAlloc, pSuffix, fBreak);
514}
515
516VOID vboxVDbgDoDumpUnlockSurfTex(const char * pPrefix, const D3DDDIARG_UNLOCK* pData, const char * pSuffix, bool fBreak)
517{
518 const PVBOXWDDMDISP_RESOURCE pRc = (const PVBOXWDDMDISP_RESOURCE)pData->hResource;
519 const PVBOXWDDMDISP_ALLOCATION pAlloc = &pRc->aAllocations[pData->SubResourceIndex];
520 vboxVDbgDoDumpLockUnlockSurfTex(pPrefix, pAlloc, pSuffix, fBreak);
521}
522
523void vboxVDbgDoPrintAlloc(const char * pPrefix, const PVBOXWDDMDISP_RESOURCE pRc, uint32_t iAlloc, const char * pSuffix)
524{
525 Assert(pRc->cAllocations > iAlloc);
526 const PVBOXWDDMDISP_ALLOCATION pAlloc = &pRc->aAllocations[iAlloc];
527 BOOL bPrimary = pRc->RcDesc.fFlags.Primary;
528 BOOL bFrontBuf = FALSE;
529 if (bPrimary)
530 {
531 PVBOXWDDMDISP_SWAPCHAIN pSwapchain = vboxWddmSwapchainForAlloc(pAlloc);
532 Assert(pSwapchain);
533 bFrontBuf = (vboxWddmSwapchainGetFb(pSwapchain)->pAlloc == pAlloc);
534 }
535 vboxVDbgPrint(("%s D3DWidth(%d), width(%d), height(%d), format(%d), usage(%s), %s", pPrefix,
536 pAlloc->D3DWidth, pAlloc->SurfDesc.width, pAlloc->SurfDesc.height, pAlloc->SurfDesc.format,
537 bPrimary ?
538 (bFrontBuf ? "Front Buffer" : "Back Buffer")
539 : "?Everage? Alloc",
540 pSuffix));
541}
542
543void vboxVDbgDoPrintRect(const char * pPrefix, const RECT *pRect, const char * pSuffix)
544{
545 vboxVDbgPrint(("%s left(%d), top(%d), right(%d), bottom(%d) %s", pPrefix, pRect->left, pRect->top, pRect->right, pRect->bottom, pSuffix));
546}
547#endif
548
549#ifdef VBOXWDDMDISP_DEBUG_VEHANDLER
550
551static PVOID g_VBoxWDbgVEHandler = NULL;
552LONG WINAPI vboxVDbgVectoredHandler(struct _EXCEPTION_POINTERS *pExceptionInfo)
553{
554 PEXCEPTION_RECORD pExceptionRecord = pExceptionInfo->ExceptionRecord;
555 PCONTEXT pContextRecord = pExceptionInfo->ContextRecord;
556 switch (pExceptionRecord->ExceptionCode)
557 {
558 case 0xc0000005: /* only access violation and debug exceptions actually matter */
559 case 0xc0000003:
560 AssertRelease(0);
561 break;
562 default:
563 break;
564 }
565 return EXCEPTION_CONTINUE_SEARCH;
566}
567
568void vboxVDbgVEHandlerRegister()
569{
570 Assert(!g_VBoxWDbgVEHandler);
571 g_VBoxWDbgVEHandler = AddVectoredExceptionHandler(1,vboxVDbgVectoredHandler);
572 Assert(g_VBoxWDbgVEHandler);
573}
574
575void vboxVDbgVEHandlerUnregister()
576{
577 Assert(g_VBoxWDbgVEHandler);
578 ULONG uResult = RemoveVectoredExceptionHandler(g_VBoxWDbgVEHandler);
579 Assert(uResult);
580 g_VBoxWDbgVEHandler = NULL;
581}
582
583#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