How to debug D3D11 device removal?

In a game I am developing, at certain point a device removal occurs:

D3D11: Removing Device.
D3D11 ERROR: ID3D11Device::RemoveDevice: Device removal has been triggered for the following reason (DXGI_ERROR_DEVICE_HUNG: The Device took an unreasonable amount of time to execute its commands, or the hardware crashed/hung. As a result, the TDR (Timeout Detection and Recovery) mechanism has been triggered. The current Device Context was executing commands when the hang occurred. The application may want to respawn and fallback to less aggressive use of the display hardware). [ EXECUTION ERROR #378: DEVICE_REMOVAL_PROCESS_AT_FAULT]

This occurs only in a release build, and not every time but often. This seems to occur on Nvidia cards only. I have GeForce GTX 1060 on my Windows 10 system with driver version 430.39.

There are no messages from the D3D11 debug layer, other than the one above when the removal occurs. All ID3D11DeviceContext and DXGI calls (including swap chain present) are done in the same thread that runs the window message pump, so this shouldn’t be a multithreading issue.

The message for DXGI_ERROR_DEVICE_HUNG says: “The application’s device failed due to badly formed commands sent by the application. This is an design-time issue that should be investigated and fixed.” How can I investigate what is causing the device removal?

Apparently the issue was caused by a shader constant buffer that had some uninitialised values. Solved.