Reputation: 141
I am developing my first DirectX 12 C++ application in Visual Studio Community 2019 and I am having trouble getting useful information from the debug logs output in the Visual Studio Output window.
My issue is I that am trying to create a swap chain with a call to CreateSwapChain but a call to this function fails with an HRESULT that produces the following error message:
The application made a call that is invalid. Either the parameters of the call or the state of some object was incorrect. Enable the D3D debug layer in order to see details via debug messages.
In addition to this, I can see the standard debug output from Visual Studio in the Output window. It shows which .dll files were loaded and that an exception was thrown. I do not believe any of this output is from DirectX.
To enable the debug layer, I try the following code, starting at the first line of my WinMain function:
#if defined(DEBUG) || defined(_DEBUG)
Microsoft::WRL::ComPtr<ID3D12Debug> debugController;
ThrowIfFailed(D3D12GetDebugInterface(IID_PPV_ARGS(&debugController)));
debugController->EnableDebugLayer();
#endif
In addition, I run dxcpl.exe to open the DirectX Control Panel, add my executable to the Scope list, and select the "Application Controlled" radio button for the Direct3D/DXGI Debug Layer option.
I execute the code again by selecting Debug->Start Debugging and in the Visual Studio Output window I can now see INFO messages reported from "D3D12" such as:
...
D3D12 INFO: Create ID3D12CommandAllocator: Addr=0x0C3CBD78, ExtRef=1, IntRef=0 [ STATE_CREATION INFO #558: CREATE_COMMANDALLOCATOR]
D3D12 INFO: Create ID3D12GraphicsCommandList: Addr=0x0C42EA78, ExtRef=1, IntRef=0 [ STATE_CREATION INFO #560: CREATE_COMMANDLIST12]
D3D12 INFO: Create ID3D12GraphicsCommandList: Addr=0x0C479C68, ExtRef=1, IntRef=0 [ STATE_CREATION INFO #560: CREATE_COMMANDLIST12]
Exception thrown at 0x7705B5B2 in D3DX12.exe: Microsoft C++ exception: _com_error at memory location 0x003ADDC8.
Exception thrown at 0x7705B5B2 in D3DX12.exe: Microsoft C++ exception: _com_error at memory location 0x003ADDC8.
Exception thrown at 0x7705B5B2 in D3DX12.exe: Microsoft C++ exception: D3DAppException at memory location 0x003AE670.
D3D12 INFO: Destroy ID3D12GraphicsCommandList: Name="unnamed", Addr=0x0C479C68 [ STATE_CREATION INFO #586: DESTROY_COMMANDLIST12]
D3D12 INFO: Destroy ID3D12GraphicsCommandList: Name="unnamed", Addr=0x0C42EA78 [ STATE_CREATION INFO #586: DESTROY_COMMANDLIST12]
D3D12 INFO: Destroy ID3D12CommandAllocator: Name="unnamed", Addr=0x0C3CBD78 [ STATE_CREATION INFO #584: DESTROY_COMMANDALLOCATOR]
...
Notice that the last INFO message before the series of Exception messages is for creating a command list. A command list is what I create immediately before creating my Swap Chain. My suspicion is that there is an issue with the window I am passing to the swap chain, but my suspicion isn't really what's important. I believe that DirectX 12 should be telling me exactly what the issue is (i.e. "ERROR: Your window handle is invalid for <insert specific reason here>") because I believe that's the purpose of the debug layer and why it's telling me to enable it. I believe that I've enabled the debug layer per my code above, but yet, I am not receiving anymore useful information than from before I had enabled it.
So, the real question here is why are there only DirectX 12 INFO logs and no ERROR, WARN, or any other sort of message indicating why the call to create the swap chain failed?
Thanks for any help in advance.
Upvotes: 2
Views: 5017
Reputation: 141
It took a few hours of searching, but I've found the reason for why I was not receiving ERROR logs for my DirectX 12 application.
I created my DXGI Factory using the following:
ThrowIfFailed(CreateDXGIFactory1(IID_PPV_ARGS(&factory)));
This creates a DXGI factory for DXGI version 1.1. Instead, the function CreateDXGIFactory2's first parameter accepts a flag for debugging:
ThrowIfFailed(CreateDXGIFactory2(DXGI_CREATE_FACTORY_DEBUG, IID_PPV_ARGS(&factory)));
Using this instead now shows errors logs:
D3D12 INFO: Create ID3D12CommandAllocator: Addr=0x0D6D1D18, ExtRef=1, IntRef=0 [ STATE_CREATION INFO #558: CREATE_COMMANDALLOCATOR]
D3D12 INFO: Create ID3D12GraphicsCommandList: Addr=0x0D7358C8, ExtRef=1, IntRef=0 [ STATE_CREATION INFO #560: CREATE_COMMANDLIST12]
D3D12 INFO: Create ID3D12GraphicsCommandList: Addr=0x0D777D40, ExtRef=1, IntRef=0 [ STATE_CREATION INFO #560: CREATE_COMMANDLIST12]
DXGI ERROR: IDXGIFactory::CreateSwapChain: Flip model swapchains (DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL and DXGI_SWAP_EFFECT_FLIP_DISCARD) do not support multisampling. DXGI_SWAP_CHAIN_DESC{ SwapChainType = ..._HWND, BufferDesc = DXGI_MODE_DESC1{Width = 1920, Height = 1080, RefreshRate = DXGI_RATIONAL{ Numerator = 144, Denominator = 1 }, Format = R8G8B8A8_UNORM, ScanlineOrdering = ..._UNSPECIFIED, Scaling = ..._UNSPECIFIED, Stereo = FALSE }, SampleDesc = DXGI_SAMPLE_DESC{ Count = 4, Quality = 1 }, BufferUsage = 0x20, BufferCount = 2, OutputWindow = 0x001C0808, Scaling = ..._STRETCH, Windowed = TRUE, SwapEffect = ..._FLIP_DISCARD, AlphaMode = ..._IGNORE, Flags = 0x2 } [ MISCELLANEOUS ERROR #102: ]
Exception thrown at 0x7705B5B2 in D3DX12.exe: Microsoft C++ exception: _com_error at memory location 0x012FDD00.
DXGI ERROR: IDXGIFactory::CreateSwapChain: Flip model swapchains (DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL and DXGI_SWAP_EFFECT_FLIP_DISCARD) do not support multisampling. DXGI_SWAP_CHAIN_DESC{ SwapChainType = ..._HWND, BufferDesc = DXGI_MODE_DESC1{Width = 1920, Height = 1080, RefreshRate = DXGI_RATIONAL{ Numerator = 144, Denominator = 1 }, Format = R8G8B8A8_UNORM, ScanlineOrdering = ..._UNSPECIFIED, Scaling = ..._UNSPECIFIED, Stereo = FALSE }, SampleDesc = DXGI_SAMPLE_DESC{ Count = 4, Quality = 1 }, BufferUsage = 0x20, BufferCount = 2, OutputWindow = 0x001C0808, Scaling = ..._STRETCH, Windowed = TRUE, SwapEffect = ..._FLIP_DISCARD, AlphaMode = ..._IGNORE, Flags = 0x2 } [ MISCELLANEOUS ERROR #102: ]
Exception thrown at 0x7705B5B2 in D3DX12.exe: Microsoft C++ exception: _com_error at memory location 0x012FDD00.
Exception thrown at 0x7705B5B2 in D3DX12.exe: Microsoft C++ exception: D3DAppException at memory location 0x012FE5A8.
D3D12 INFO: Destroy ID3D12GraphicsCommandList: Name="unnamed", Addr=0x0D777D40 [ STATE_CREATION INFO #586: DESTROY_COMMANDLIST12]
D3D12 INFO: Destroy ID3D12GraphicsCommandList: Name="unnamed", Addr=0x0D7358C8 [ STATE_CREATION INFO #586: DESTROY_COMMANDLIST12]
D3D12 INFO: Destroy ID3D12CommandAllocator: Name="unnamed", Addr=0x0D6D1D18 [ STATE_CREATION INFO #584: DESTROY_COMMANDALLOCATOR]
I'm unsure of the history of the DXGI API, but I hope this helps others with this issue as this has been a big headache for me. I am currently working through Frank Luna's Introduction to 3D Game Programming with DirectX 12. He has you enable the debug layer, but I do not see any setting of this flag in his examples. I cloned his sample project directory, attempted to cause errors in his application, and I found that no ERROR logs were reported. Only a message dialog would come up giving the same HRESULT error that I posted earlier (which also says that the debug layer should be enabled).
Thank you.
Upvotes: 10