How To: Get the Device Feature Level

This topics shows how to get the highest feature level supported by a device. Direct3D 11 devices support a fixed set of feature levels that are defined in the D3D_FEATURE_LEVEL enumeration. When you know the highest feature level supported by a device, you can run code paths that are appropriate for that device.

To get the device feature level

  1. Call either the D3D11CreateDevice function or the D3D11CreateDeviceAndSwapChain functions while specifying NULL for the ppDevice parameter. You can do this before device creation.

    - or -

    Call ID3D11Device::GetFeatureLevel after device creation.

  2. Examine the value of the returned D3D_FEATURE_LEVEL enumeration from the last step to determine the supported feature level.

The following code example demonstrates how to determine the highest supported feature level by calling the D3D11CreateDevice function. D3D11CreateDevice stores the highest supported feature level in the FeatureLevel variable. You can use this code to examine the value of the D3D_FEATURE_LEVEL enumerated type that D3D11CreateDevice returns. Note that this code lists all feature levels explicitly (for Direct3D 11.1 and Direct3D 11.2).

Note

If the Direct3D 11.1 runtime is present on the computer and pFeatureLevels is set to NULL, this function won't create a D3D_FEATURE_LEVEL_11_1 device. To create a D3D_FEATURE_LEVEL_11_1 device, you must explicitly provide a D3D_FEATURE_LEVEL array that includes D3D_FEATURE_LEVEL_11_1. If you provide a D3D_FEATURE_LEVEL array that contains D3D_FEATURE_LEVEL_11_1 on a computer that doesn't have the Direct3D 11.1 runtime installed, this function immediately fails with E_INVALIDARG.

 

HRESULT hr = E_FAIL;
D3D_FEATURE_LEVEL MaxSupportedFeatureLevel = D3D_FEATURE_LEVEL_9_1;
D3D_FEATURE_LEVEL FeatureLevels[] = {
    D3D_FEATURE_LEVEL_11_1,
    D3D_FEATURE_LEVEL_11_0,
    D3D_FEATURE_LEVEL_10_1,
    D3D_FEATURE_LEVEL_10_0,
    D3D_FEATURE_LEVEL_9_3,
    D3D_FEATURE_LEVEL_9_2,
    D3D_FEATURE_LEVEL_9_1
    };

hr = D3D11CreateDevice(
    NULL,
    D3D_DRIVER_TYPE_HARDWARE,
    NULL, 
    0, 
    &FeatureLevels, 
    ARRAYSIZE(FeatureLevels), 
    D3D11_SDK_VERSION, 
    NULL, 
    &MaxSupportedFeatureLevel, 
    NULL 
    );

if(FAILED(hr))
{
    return hr;
}

The 10Level9 Reference section lists the differences between how various ID3D11Device and ID3D11DeviceContext methods behave at various 10Level9 feature levels.

Direct3D 11 on Downlevel Hardware

How to Use Direct3D 11