How to enable DX debug layer D3D11_CREATE_DEVICE_DEBUG?

I’m developing on Windows and my target platform is also desktop Windows (not metro). I have a native DX plugin that I need more help debugging. How do I enable DX debug layer in Unity? In a non-Unity DX app, I would add the flag D3D11_CREATE_DEVICE_DEBUG to the D3D11CreateDevice call. However, I can’t do this in Unity due to the fact that Unity internally creates the device on my behalf.

I also tried the following:

  • Using the DirectX Control Panel to enable the debug layer. However, using it to add debug layer support for my .exe did not make any difference.
  • Using Visual Studio Debugger to break on d3d11!D3D11CreateDevice as inspired by the post here for Windows Phone 8. However, it seems the Watch value for the Flags parameter is not editable.

Does anyone have any good ideas on how to activate DX debug layers in Unity?

I figured this out. Follow these instructions for Windows Phone 8 debugging even if you are building for Windows. The main difference is that when you break on d3d11!D3D11CreateDevice, if you have an x86_64 target, you will need to set register r9 to xor with the value 2 which corresponds to

Just wanted to say, Thank you very much!

This helped me solve a problem in my Unity x64 plugin in minutes.

Still r9 in Win10, and the starting value for me was r9=3 to enable Debug layer. Unity version 2017.4.24f1.

Also worth noting that to set the breakpoint on CreateDevice, it is case-sensitive, so it must be precisely “d3d11!D3D11CreateDevice”

Now you can just append -force-d3d11-debug to command line arguments. (tested on Unity 2020.3)