I have a GTX 570 graphics card which SHOULD support DirectX 11, but the highest feature level that D3D11CreateDevice selects is 10_1. I had a look around on these forums and it seems that other people have had this problem and that it might be Nvidia Optimus selecting the Intel integrated graphics chipset instead of the dedicated Nvidia GPU. So I added my .exe to the list of programs in the Nvidia control panel and then used the following code to iterate through the available adapters to hopefully select the correct adapter.
Here's the code:
/* Create the dxgi factory. */
Microsoft::WRL::ComPtr<IDXGIFactory1> dxgi_factory;
HRESULT hr = CreateDXGIFactory1(__uuidof(IDXGIFactory2), (void**)&dxgi_factory);
if (FAILED(hr)) {
throw std::runtime_error("Failed to create dxgi factory.");
}
if (FAILED(dxgi_factory.As(&m_dxgi_factory))) {
throw std::runtime_error("Failed to obtain IDXGIFactory2 interface.");
}
D3D_FEATURE_LEVEL feature_levels[] =
{
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
};
int num_feature_levels = ARRAYSIZE(feature_levels);
Microsoft::WRL::ComPtr<ID3D11Device> device;
Microsoft::WRL::ComPtr<ID3D11DeviceContext> context;
/* Iterate through each feature level. */
for (int f = 0; f < num_feature_levels; f++) {
/* Iterate through available adapters. */
while (m_dxgi_factory->EnumAdapters1(f, &m_dxgi_adapter) != DXGI_ERROR_NOT_FOUND) {
hr = D3D11CreateDevice(m_dxgi_adapter.Get(), D3D_DRIVER_TYPE_UNKNOWN, 0,
create_device_flags, feature_levels, num_feature_levels, D3D11_SDK_VERSION,
&device, &m_feature_level, &context);
/* If success break out of loop. */
if(SUCCEEDED(hr))
break;
}
if(SUCCEEDED(hr))
break;
}
This still doesn't work. Someone on these forums also suggested looking in the DirectX caps viewer and in the DXGI 1.1 > NVIDIA GeForce GTX 570 > Direct3D 11 folder it only lists D3D_FEATURE_LEVEL_10_1. It's like my gpu isn't being recognized as a DirectX 11 capable device.
Does anyone have any suggestions? Thanks.