1

I've been looking at the DirectX12 Documentation. It uses what are called Com pointers (ComPtr). in the guide most of the ComPtrs have a guides showing how a certain ID3D12 Interface is initialized. for example ID3D12CommandList is initialized using ID3D12Device::CreateCommandList(...) & the ID3D12Device. Although I'm trying to initialize the Debug layers that come in d3d12sdkLayers.h headers. I can't find anywhere in the documentation that shows how to initialize any of these layers (aside from the main DebugInterface itself.

Here is the list of interfaces I'm referring to /direct3d-12-sdklayers-interfaces

for example how do I initialize the ID3D12DebugCommandList

Simon Mourier
  • 132,049
  • 21
  • 248
  • 298
masonCherry
  • 894
  • 6
  • 14
  • 2
    Enable the debug layer (https://learn.microsoft.com/en-us/windows/win32/api/d3d12sdklayers/nf-d3d12sdklayers-id3d12debug-enabledebuglayer) and QueryInterface for `ID3D12DebugDevice` on an instance of `ID3D12Device`, same for `ID3D12DebugCommandList` on an instance of `ID3D12CommandList`, etc. – Simon Mourier Aug 06 '23 at 17:15
  • Hey thanks. I realized I didn't understand what COM model was fully; I didn't understand that some interface implementations are only reachable/provided from instances of of a particular kind. but also I don't know why the docs don't show this though. where would I have found out that `ID3D12DebugCommandList` needs to be queried from a regular `ID3D12CommandList`.. is this just a naming standard that is known. – masonCherry Aug 06 '23 at 20:37
  • Not this is not some kind of standard, this is specific to these interfaces. Usually, what you can get from an interface is documented, but I don't actually remember how I know these ones. – Simon Mourier Aug 06 '23 at 21:58

1 Answers1

1

The Debug Layer must be initialized before you create the device. This is done as:

#if defined(_DEBUG)
    // Enable the debug layer.
    {
        ComPtr<ID3D12Debug> debugController;
        if (SUCCEEDED(D3D12GetDebugInterface(IID_PPV_ARGS(&debugController))))
        {
            debugController->EnableDebugLayer();
        }
    }
#endif

Note that you have to have the "Graphics Tools" Windows optional feature enabled for this to actually succeed. See this blog post.

If the debug device is available at runtime, you can use COM QueryInterface to get specific interfaces from the DirectX 12 objects. For example:

ComPtr<ID3D12DebugCommandList> dbgCommandList;
if (SUCCEEDED(commandList->QueryInterface(IID_PPV_ARGS(&dbgCommandList))))
{
    D3D12_DEBUG_FEATURE t = dbgCommandList->GetFeatureMask();
...
}

See Programming DirectX with COM and Anatomy of Direct3D 12 Create Device.

ComPtr is just a C++ smart-pointer wrapper for COM interfaces that ensure the reference counts are properly updated. See this wiki page for more information.

Chuck Walbourn
  • 38,259
  • 2
  • 58
  • 81
  • Actually, the specific fact `ID3D12DebugXXX` can be queried from `ID3D12XXX` (when debug layer is enabled) doesn't seem to be documented anywhere, the doc should be updated IMHO. – Simon Mourier Aug 10 '23 at 07:34