如何确定Direct3D WARP支持的功能级别?

时间:2015-02-26 23:36:25

标签: direct3d direct3d11 warp

Windows Advanced Rasterization Platform (WARP)支持variety of feature levels根据所安装的DirectX API的版本而有所不同:

  • 安装Direct3D 11时的功能级别9_1,9_2,9_3,10_0和10_1
  • 在Windows 7上安装Direct3D 11.1时,所有上述功能级别加上11_0
  • 在Windows 8上安装Direct3D 11.1时,以上所有功能级别加上11_1

如何通过WARP轻松确定可用的功能级别?我知道硬件设备我可以运行ID3D11Device::GetFeatureLevel,但我没有看到WARP的等价物。

1 个答案:

答案 0 :(得分:2)

使用Anatomy of Direct3D 11 Create Device中的代码,但改为使用WARP设备类型。

D3D_FEATURE_LEVEL lvl[] = {
    D3D_FEATURE_LEVEL_11_1, D3D_FEATURE_LEVEL_11_0,
    D3D_FEATURE_LEVEL_10_1, D3D_FEATURE_LEVEL_10_0 };

DWORD createDeviceFlags = 0;
#ifdef _DEBUG
createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
#endif

ID3D11Device* pDevice = nullptr;
ID3D11DeviceContext* pContext = nullptr;
D3D_FEATURE_LEVEL fl;
HRESULT hr = D3D11CreateDevice( nullptr, D3D_DRIVER_TYPE_WARP, nullptr,
    createDeviceFlags, lvl, _countof(lvl),
    D3D11_SDK_VERSION, &pDevice, &fl, &pContext );
if ( hr == E_INVALIDARG )
{
    hr = D3D11CreateDevice( nullptr, D3D_DRIVER_TYPE_WARP, nullptr,
       createDeviceFlags, &lvl[1], _countof(lvl)-1,
       D3D11_SDK_VERSION, &pDevice, &fl, &pContext );
}
if ( FAILED(hr) )
    // error handling

然后检查fl以查看它是10.1,11.0还是11.1。我们不需要在lvl中列出9.1,9.2或9.3功能级别,因为WARP在Windows桌面PC上至少支持10.1。为了获得稳健性,我建议也列出10.0。