远程调试 DirectX 应用

可以使用 Visual Studio 和 Windows 8 SDK 远程调试 DirectX 应用。 除了 Visual Studio 提供的调试之外,Windows 8 SDK 还提供一组支持 DirectX 开发的组件,并提供错误检查和参数验证。 这些组件是D3D11_1SDKLayers.dll、D2D1Debug1.dll和Dxgidebug.dll。

如果要在未安装 Windows 8 SDK 的计算机上进行远程调试,并且需要此附加调试功能,则必须安装适合要调试的体系结构的远程调试包。 中的 C:\Program Files (x86)\Windows Kits\8.0\Remote\<arch> Windows 安装程序包安装相应的支持。

若要为 Direct2D 应用启用其他调试功能,请使用以下代码:

    D2D1_FACTORY_OPTIONS options;
    ZeroMemory(&options, sizeof(D2D1_FACTORY_OPTIONS));

#if defined(_DEBUG)
     // If the project is in a debug build, enable Direct2D debugging via SDK Layers.
    options.debugLevel = D2D1_DEBUG_LEVEL_INFORMATION;
#endif

    DX::ThrowIfFailed(
        D2D1CreateFactory(
            D2D1_FACTORY_TYPE_SINGLE_THREADED,
            __uuidof(ID2D1Factory1),
            &options,
            &m_d2dFactory
            )
        );         

若要为 Direct3D 应用启用其他调试功能,请使用以下代码:

    // This flag supports surfaces with a different color channel ordering than the API default.
    // It is recommended usage, and is required for compatibility with Direct2D.
    UINT creationFlags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
    ComPtr<IDXGIDevice> dxgiDevice;

#if defined(_DEBUG)
    // If the project is in a debug build, enable debugging via SDK Layers with this flag.
    creationFlags |= D3D11_CREATE_DEVICE_DEBUG;
#endif
    DX::ThrowIfFailed(
        D3D11CreateDevice(
            nullptr,                    // specify null to use the default adapter
            D3D_DRIVER_TYPE_HARDWARE,
            0,                          // leave as 0 unless software device
            creationFlags,              // optionally set debug and Direct2D compatibility flags
            featureLevels,              // list of feature levels this app can support
            ARRAYSIZE(featureLevels),   // number of entries in above list
            D3D11_SDK_VERSION,          // always set this to D3D11_SDK_VERSION for modern
            &device,                    // returns the Direct3D device created
            &m_featureLevel,            // returns feature level of device created
            &context                    // returns the device immediate context
            )
        );

有关调试 Direct2D 应用的详细信息,请参阅 Direct2D 调试层

有关调试 Direct3D 应用的详细信息,请参阅 Direct3D 调试层