码迷,mamicode.com
首页 > 其他好文 > 详细

【转载】DXUT11框架浅析(4)--调试相关

时间:2016-05-27 23:42:41      阅读:297      评论:0      收藏:0      [点我收藏+]

标签:

原文:DXUT11框架浅析(4)--调试相关

 

DXUT11框架浅析(4)--调试相关

 

 

 

1. D3D8/9和D3D10/11的调试区别

 

        只要安装了DXSDK,有个调试工具DirectX ControlPanel,如下图所示。这里可以将Direct3D 9设置为调试运行时(Debug D3D9 Runtime)或零售运行时(RetailD3D9 Runtime)。注意这里的设置是全局的,如果改成调试运行时,则所有用到D3D9的程序都会进入调试模式,这会使这些程序运行的很慢。

技术分享

 

        从Vista开始系统自己的界面都使用D3D做渲染,从而必须改变上面的方法,否则系统很容易卡死。从Direct3D 10.0开始,采用了API分层机制,从而有了SDK Debug Layer用于调试。如果需要调试程序,可以在创建D3D设备时使用D3Dxx_CREATE_DEVICE_DEBUG标记或用上面的Control Panel工具把要调试的程序加入调试列表:

 

 技术分享

 

2. 调试信息输出函数

 

下面的函数在DXUTmisc.h中定义:

 

 

[cpp] view plain copy
 
  1. void WINAPI DXUTOutputDebugStringW( LPCWSTRstrMsg, ... );  
  2. void WINAPI DXUTOutputDebugStringA( LPCSTRstrMsg, ... );  
  3.    
  4. #ifdef UNICODE  
  5. #define DXUTOutputDebugString DXUTOutputDebugStringW  
  6. #else  
  7. #define DXUTOutputDebugString DXUTOutputDebugStringA  
  8. #endif  

 

格式化字符串并通过调用API函数OutputDebugString打印调试信息。比如我们在EmptyProject11这个sample的OnD3D11FrameRender中写一句:

DXUTOutputDebugString(L"Test测试\n" );

调试运行,每当运行到这句时,在Output窗口中都会打印出这个调试信息:

 

 技术分享

 

 

3. D3D结构转成字符串以便于显示

 

[cpp] view plain copy
 
  1. void WINAPI DXUTTraceDecl( D3DVERTEXELEMENT9decl[MAX_FVF_DECL_SIZE]);  
  2. WCHAR* WINAPI DXUTTraceD3DDECLUSAGEtoString( BYTE u );  
  3. WCHAR* WINAPI DXUTTraceD3DDECLMETHODtoString( BYTE m );  
  4. WCHAR* WINAPI DXUTTraceD3DDECLTYPEtoString( BYTE t );  
  5. WCHAR* WINAPI DXUTTraceWindowsMessage( UINTuMsg );  

 

 

 

 

4. D3D10以上版本调试信息

[cpp] view plain copy
 
  1. void DXUT_SetDebugName( IDirect3DResource9* pObj,const CHAR* pstrName )  
  2. void DXUT_SetDebugName( IDXGIObject* pObj,const CHAR* pstrName )  
  3. void DXUT_SetDebugName( ID3D10Device* pObj,const CHAR* pstrName )  
  4. void DXUT_SetDebugName( ID3D10DeviceChild* pObj,const CHAR* pstrName )  
  5. void DXUT_SetDebugName( ID3D11Device* pObj,const CHAR* pstrName )  
  6. void DXUT_SetDebugName( ID3D11DeviceChild* pObj,const CHAR* pstrName )<span style="font-size:18px;">  
  7. </span>  

为对象指定一个易读的名称,在调试层出现内存泄漏时,可以很容易看到哪个对象出的问题。

 

 

 

5. PIX辅助调试

[cpp] view plain copy
 
  1. #ifdef PROFILE  
  2. // PROFILE is defined, so these macros call the D3DPERFfunctions  
  3. #define DXUT_BeginPerfEvent( color, pstrMessage)   DXUT_Dynamic_D3DPERF_BeginEvent(color, pstrMessage)  
  4. #define DXUT_EndPerfEvent()                         DXUT_Dynamic_D3DPERF_EndEvent()  
  5. #define DXUT_SetPerfMarker( color, pstrMessage)    DXUT_Dynamic_D3DPERF_SetMarker(color, pstrMessage)  
  6. #else  
  7. // PROFILE is not defined, so these macros do nothing  
  8. #define DXUT_BeginPerfEvent( color, pstrMessage)   (__noop)  
  9. #define DXUT_EndPerfEvent()                         (__noop)  
  10. #define DXUT_SetPerfMarker( color, pstrMessage)    (__noop)  
  11. #endif  
  12.    
  13. class CDXUTPerfEventGenerator  

 

这里实现对D3DPERF_BeginEvent、D3DPERF_BeginEvent、和D3DPERF_BeginEvent三个API的简化使用的封装。主要用于PIX调试Direct3D程序。CDXUTPerfEventGenerator通过类的方式简化了D3DPERF_BeginEvent和D3DPERF_BeginEvent需要配对调用的实现。

 

 

 

参考资料

 

 

http://blogs.msdn.com/b/chuckw/archive/2012/11/30/direct3d-sdk-debug-layer-tricks.aspx

 

http://msdn.microsoft.com/en-us/library/windows/desktop/ff476881(v=vs.85).aspx#Debug

【转载】DXUT11框架浅析(4)--调试相关

标签:

原文地址:http://www.cnblogs.com/zhehan54/p/5536389.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!