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?
There are a number of confounding factors at work here, so let's take them one at a time:
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.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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With