Debugging graphics applications is always a tricky affair. The following can help in this regard.
Debugging tools
There are several graphics debugging tools to consider when working with graphics APIs. In most cases, when not obtaining the expected result, attaching a frame debugger is recommended. A list of compatible frame debuggers follows:
- Direct3D 11: Visual Studio Graphics Analyzer & Renderdoc
- Direct3D 12: Visual Studio Graphics Analyzer
- Vulkan: Renderdoc
Increasing debuggability
Several actions can be taken in order to make debugging in frame debuggers a little bit easier. All of the above graphics APIs support giving any API objects names. This means that rather than showing a Depth Stencil View as “Depth stencil view 1", the depth stencil view can instead be called “Shadow map (spotlight 1)". This can allow for resources to be more easily distinguishable at face value.
The API for renaming objects is as follows:
- Direct3D 11:
SetPrivateDatawithWKPDID_D3DDebugObjectNameas GUID, the string length asDataSize, and the string aspData - Direct3D 12:
SetNameon any object the name can be set on - Vulkan:
vkDebugMarkerSetObjectNameEXTon the object. (RequiresVK_EXT_debug_markerto be enabled)
- DrawIndexed ( ... )
- DrawIndexed ( ... )
- DrawIndexed ( ... )
- DrawIndexed ( ... )
- DrawIndexed ( ... )
To be turned into a list like this:
- Shadow rendering
- Spotlight 1
- DrawIndexed ( ... )
- DrawIndexed ( ... )
- Spotlight 2
- DrawIndexed ( ... )
- Main render
- DrawIndexed ( ... )
- DrawIndexed ( ... )
This will allow for jumping to the draw call you are interested in as soon as possible, aiding in the debugging process.
The API for placing event markers:
- Direct3D 11:
BeginEventon theID3D11DeviceContext2. Note that earlier versions ofID3D11DeviceContextdo not support debug markers. - Direct3D 12:
BeginEventon the graphics command list to start an event,EndEventto close the event. InBeginEvent,Metadataindicates the type of event. The values we are interested in in this case are0and1.0indicates thatpDatarefers to a string ofwchar_tcharacters, whereas1indicates the string is ofcharcharacters - Vulkan:
vkCmdDebugMarkerBeginEXTto start a debug marker,vkCmdDebugMarkerEndEXT