Main page | About | Articles | Previous Posts | Archives

Sunday, June 11, 2006

How to get more debug data from DirectX?

I thought I'd write up something on getting more details on debug stuff from DirectX with managed languages as there's not much stuff up about that.

Tired of the "InvalidCallException" or "InvalidDataException" or whatever comes up in your app, with no data on what might be the cause?

Well, for the users of Visual Studio Express Edition line, tough luck. Unmanaged debugging is only in "proper" Visual Studio's.

Okay here we go!

Step 1:
Go to your projects properties by right clicking it in the solution explorer and choosing properties. On the debug page, tick "Enable unmanaged code debugging"

Step 2:
Go to control panel and from there, DirectX. On the Direct3D tab, crank "Debug Output Level" to max, tick "Use Debug version of Direct3D" and "Break on D3D Error"
Then go to Managed tab and go to Microsoft.DirectX and right click on the assembly name/number and choose "Switch to debug version". Do the same for Microsoft.DirectX.Direct3D

Step 3:
Start debugging your app. You should see a tab called "Output" in the debugger. If not, go to View menu in Visual Studio and select Output.
The Output tab will contain the messages your app receives from the DirectX debugger.

This was quite helpful for me when I tried to figure out what was wrong with my rendering, as the map editor just kept on crashing without giving me any clues on what was going wrong. In the end, it was something as simple as missing device.VertexFormat = something definition.
The Direct3D error I got wasn't very helpful either, but after a bit of googling with it, I found an answer. More than I could ever find with "InvalidCallException" which is just waaaay too generic.

Seems the D3D debug also displays small tidbits like redundant state changes.
I mean, device.RenderState changes. If you are using a Pure device, they aren't filtered out and will probably result in decreased performance.

Another thing it seems to report is if a static buffer is locked more than twice in one frame, which is something which will cause a major performance hit if it's done often.

Maybe others too.


Post a Comment

<< Home