CreateTexture2D E_INVALIDARG

  1. Ensure "Graphics Tools" installed.

    Go to the Settings panel, under System, Apps & features, Manage optional Features, Add a feature, and then look for "Graphics Tools".

  2. Enable the debug layer by code,

    1
    2
    3
    4
    5
    6
    
    D3D11CreateDevice(
    	nullptr,
    	D3D_DRIVER_TYPE_HARDWARE,
    	nullptr,
    	XXX | D3D11_CREATE_DEVICE_DEBUG, // add here!
    	...);

    or in Visual Studio, on the main menu, choose Debug, Graphics, setup in DirectX Control Panel.

  3. Restart debug session. And after CreateTexture2D returns E_INVALIDARG, there will be debug informations in VS IDE Output Panel, each one of which begins with like "D3D11 ERROR".

refer to:
https://docs.microsoft.com/en-us/visualstudio/debugger/graphics/getting-started-with-visual-studio-graphics-diagnostics
https://docs.microsoft.com/en-us/windows/win32/direct3d11/overviews-direct3d-11-devices-layers
https://stackoverflow.com/questions/53569263/directx-11-id3ddevicecreatetexture2d-with-initial-data-fail
https://blog.rthand.com/capture-directx-10-11-debug-output-to-visual-studio/
https://article.itxueyuan.com/dwlpL
https://walbourn.github.io/