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:
SetPrivateData
withWKPDID_D3DDebugObjectName
as GUID, the string length asDataSize
, and the string aspData
- Direct3D 12:
SetName
on any object the name can be set on - Vulkan:
vkDebugMarkerSetObjectNameEXT
on the object. (RequiresVK_EXT_debug_marker
to 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:
BeginEvent
on theID3D11DeviceContext2
. Note that earlier versions ofID3D11DeviceContext
do not support debug markers. - Direct3D 12:
BeginEvent
on the graphics command list to start an event,EndEvent
to close the event. InBeginEvent
,Metadata
indicates the type of event. The values we are interested in in this case are0
and1
.0
indicates thatpData
refers to a string ofwchar_t
characters, whereas1
indicates the string is ofchar
characters - Vulkan:
vkCmdDebugMarkerBeginEXT
to start a debug marker,vkCmdDebugMarkerEndEXT