'Is there a way to receive as a string, the errors from DX12?

Example: Here's the debug log for CreateGraphicsPipelineState, it tells me what went wrong:

D3D12 ERROR: ID3D12Device::CreateGraphicsPipelineState: Root Signature doesn't match Vertex Shader: Shader CBV descriptor range (RegisterSpace=0, NumDescriptors=1, BaseShaderRegister=0) is not fully bound in root signature

However, a call to windows FormatMessage(MESSAGE_FROM_SYSTEM...) will return this for the exact same error:

The parameter is incorrect.

The first is obviously far more useful... We used to have dxerr.lib, and we have source for dxerr.cpp in DXUT. But this doesn't cover DX12. I can't see any way for a shader-tool to retrieve the error and present it to the user from the API.



Solution 1:[1]

This can be done with the ID3D12InfoQueue interface, as documented here:

https://docs.microsoft.com/en-us/windows/win32/api/d3d12sdklayers/nn-d3d12sdklayers-id3d12infoqueue

As far as I can tell it's currently not possible to set a callback, which means that you'll need to explicitly query for feedback.

Solution 2:[2]

There are two different sources of error/status information involved here. The error code you have returned from the API call is E_INVALIDARG and you obtained a good string for it. This is the status code from the API.

The descriptive message you see in debug output is emitted by Direct3D 12 debug layer, which you loaded during API initialization. It is, generally speaking, an optional component and might be not available in the system while the API itself is available.

To intercept debug output programmatically you can either

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ObsequiousNewt
Solution 2 Roman R.