Reputation: 364
I am currently writing a DirectX 11 game engine in C++ based off a tutorial, but I ran into a problem. Here is where the error is:
result = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL,
0, &featureLevel, 1, D3D11_SDK_VERSION, &swapChainDesc, &m_swapChain,
&m_device, NULL, &m_deviceContext);
result = HRESULT
, featureLevel = D3D_FEATURE_LEVEL
, swapChainDesc = DXGI_SWAP_CHAIN_DESC
, m_swapChain = IDXGISwapChain*
, m_device = ID3D11Device*
, and finally m_deviceContext = ID3D11DeviceContext*
.
When I run this, I get a value of something like -5027..., so that doesn't work. I also looked at this article to try what they had, but it ended up crashing my computer(I had modified the code a little to my varibles, ending up with D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, &swapChainDesc, &m_swapChain, &m_device, &featureLevel, &m_deviceContext);
).
Does anyone know how to solve this issue? I can upload my whole program to pastebin, just ask. Also, here is the link to the tutorial if you want to look over it.
Thanks in advance.
Upvotes: 0
Views: 2219
Reputation: 91
Maybe your hardware does not fully support DirectX11 feature level, so try to use this
result = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_WARP, NULL,
0, &featureLevel, 1, D3D11_SDK_VERSION, &swapChainDesc, &m_swapChain,
&m_device, NULL, &m_deviceContext);
D3D_DRIVER_TYPE_HARDWARE
Flag means that the D3Device will be created on hardware mode if the graphics's card support DX11 feature level, the Program will use full capability of this graphics's card, otherwise the creation will fails.
D3D_DRIVER_TYPE_WARP
Flag, made D3Device use the software mode this make the Program able to run on graphics's card tha t don't support DX11 but not on the full speed.
for more information about driver types please see https://msdn.microsoft.com/en-us/library/windows/desktop/ff476328(v=vs.85).aspx
because you are not sure about the hardware that your app running on so the good practice is to do:
// Driver types
D3D_DRIVER_TYPE driverTypes[] =
{
D3D_DRIVER_TYPE_HARDWARE,
D3D_DRIVER_TYPE_WARP,
D3D_DRIVER_TYPE_REFERENCE,
};
// feature levels
D3D_FEATURE_LEVEL featureLevels[] =
{
D3D_FEATURE_LEVEL_11_0,
D3D_FEATURE_LEVEL_10_1,
D3D_FEATURE_LEVEL_10_0,
};
int numDriverTypes = ARRAYSIZE( driverTypes );
int numFeatureLevels = ARRAYSIZE( featureLevels );
your app will loop and test every driver type with every feature level in those arrays, if succeeds then DXDevice will created with the correct feature level and driver mode
for( int driverTypeIndex = 0; driverTypeIndex < numDriverTypes; driverTypeIndex ++ )
{
result = D3D11CreateDeviceAndSwapChain( NULL, driverTypes[driverTypeIndex], NULL, createDeviceFlags, featureLevels, numFeatureLevels,
D3D11_SDK_VERSION, &swapChainDesc, &swapChain, &m_device, &featureLevel, &m_deviceContext);
if( SUCCEEDED( result ) )
break;
}
Upvotes: 2