從遠端偵錯 DirectX 應用程式
您可以使用 Visual Studio 和 Windows 8 SDK 從遠端偵錯 DirectX 應用程式。 Windows 8 SDK 提供一組元件,可支援 DirectX 開發,並提供錯誤檢查和參數驗證,以及 Visual Studio 所提供的偵錯。 這些元件D3D11_1SDKLayers.dll、D2D1Debug1.dll和Dxgidebug.dll。
如果您想要在未安裝 Windows 8 SDK 的電腦上遠端偵錯,而且您想要此額外的偵錯功能,您必須安裝適合您要偵錯之架構的遠端偵錯套件。 安裝適當支援的 Windows Installer 套件 C:\Program Files (x86)\Windows Kits\8.0\Remote\<arch>
。
若要啟用 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 偵錯層。