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