Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine the system DirectX is 11 or 11.1?

I am running Windows 7. When I use DxDiag, it shows the version as 11.

When I use Visual Studio 2012 which can access Windows API, it can run the code with feature level D3D_FEATURE_LEVEL_11_1

So I agot confused, what is the exact version of my DirectX version?

like image 442
Adam Lee Avatar asked Dec 24 '22 20:12

Adam Lee


1 Answers

There are a number of confounding factors at work here, so let's take them one at a time:

  1. DXDIAG is part of the OS along with the DirectX Runtime but is also manually updated for that string, so it is often less than detailed/accurate about reporting "DirectX" version. For Windows Vista SP1 it doesn't say "DirectX 10.1" and says "DirectX 10". Similarly, with both Windows 8 and Windows 7 SP 1 + KB2670838 installed it still says "DirectX 11" and not "DirectX 11.1". On Windows 8.1 it still says "DirectX 11" and not "DirectX 11.2". In short, DXDIAG is not your best option for technical details like this. You could try using the latest version of dxcapsviewer in the Windows 8.1 SDK which is a bit more sophisticated in how it check things, but still needs manually updating over time so it currently says nothing about Windows 10 features like DX 11.3 or DX 12.
  2. If you pass NULL for pFeatureLevels to D3DCreateDevice even on Windows 8.x, you will still not get D3D_FEATURE_LEVEL_11_1. This is for backcompat reasons and ensures the behavior doesn't change where NULL gets you 9.1 - 11.0. You have to manually list the 11.1 value in the array to get it--assuming the system+driver combo actually supports it. Note that if you do include 11.1 in the array, the call will fail with E_INVALIDARG on Windows Vista SP2, Windows 7 RTM, or Windows 7 SP1 without KB2670838.
  3. Windows 7 SP1 + KB2670838 provides the DirectX 11.1 API, but does not support D3D_FEATURE_LEVEL_11_1 or any of the new optional hardware features because it doesn't include support for the new WDDM 1.2 driver model. You have to be using Windows 8 or later to get D3D_FEATURE_LEVEL_11_1 with a WDDM 1.2 driver and appropriate hardware. See Microsoft Docs

In general, the proper way to handle all this for Windows desktop applications is:

D3D_FEATURE_LEVEL lvl[] = {
   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
};

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_HARDWARE, nullptr,
    createDeviceFlags, lvl, _countof(lvl),
     D3D11_SDK_VERSION, &pDevice, &fl, &pContext );
if ( hr == E_INVALIDARG )
{
    hr = D3D11CreateDevice( nullptr, D3D_DRIVER_TYPE_HARDWARE, nullptr,
         createDeviceFlags, &lvl[1], _countof(lvl)-1,
         D3D11_SDK_VERSION, &pDevice, &fl, &pContext );
}
if (FAILED(hr))
   ...

Then to detect support for Direct3D 11.1, you see if you can obtain the Direct3D 11.1 interfaces:

ID3D11Device1* pDevice1 = nullptr;
ID3D11DeviceContext1* pContext1 = nullptr;
hr = pDevice->QueryInterface( __uuidof( ID3D11Device1 ),
    reinterpret_cast<void**>( &pDevice1 ) );
if ( SUCCEEDED(hr) )
{
    // DirectX 11.1 is present, otherwise only DirectX 11.0
    (void)pContext->QueryInterface( __uuidof( ID3D11DeviceContext1 ),
         reinterpret_cast<void**>( &pContext1 ) );
}

Don't make assumptions based on Direct3D Feature Level what version of DirectX is installed or vice-versa.

  • Windows 8 Store apps can assume that DirectX 11.1 is present, but can't assume any particular Direct3D Feature Level (although 9.1 is the minimum you'll ever see).
  • Windows 8.1 Store apps can assume DirectX 11.2 is present, but again can't assume anything about Direct3D Feature Level.
  • Windows phone 8.0 apps can assume DirectX 11.0 is present and the devices only support 9.3.
  • Windows phone 8.1 apps can assume DirectX 11.1 is present and the devices only support 9.3.
  • Xbox One apps can assume DirectX 11.1 is present. Exclusive apps can assume FL 11.1 is present. Shared apps have to use FL 10.0.

See this post for details on the various nuances of device creation and DirectX 11.x version detection.

See this post and this one for important notes about DirectX 11.1 on Windows 7.

like image 55
Chuck Walbourn Avatar answered Jan 30 '23 23:01

Chuck Walbourn