Sign in to follow this  
oldgregg

Could Not initialize Direct3D

Recommended Posts

oldgregg    231
Hi guys,

I'm following this tutorial:
http://rastertek.com/dx11tut04.html

And I've done everything, However when I hit play I get the pop up message.
'Could Not initialize Direct3D'

The only thing I can think of is, Could this be because I'm using a GTX 295? I know it's not DX11 compat. But I've done all my other DX11 programming on this and it's been fine!

Also I think the problem can been narrowed down to the D3DClass.cpp
on line 171.

[CODE]
result = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, &featureLevel, 1,
D3D11_SDK_VERSION, &swapChainDesc, &m_swapChain, &m_device, NULL, &m_deviceContext);///////////These are mostly 0...
[/CODE]


Any help would be really appreciated, Thanks!

Share this post


Link to post
Share on other sites
PwFClockWise    512
I've also done a few tutorials on that site and if your card can't support DX11 that error message will show up. You can go pass this by changing to your CPU to take care of the graphics, but this will lower your fps to like 0.1/s and it will take a lot of time to start the project. But it works.

result = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, &featureLevel, 1,
D3D11_SDK_VERSION, &swapChainDesc, &m_swapChain, &m_device, NULL, &m_deviceContext);

To change to run it on the CPU instead you change this part
[quote]D3D_DRIVER_TYPE_HARDWARE[/quote] to D3D_DRIVER_TYPE_REFERENCE

so it will be like this: result = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_REFERENCE, NULL, 0, &featureLevel, 1,
D3D11_SDK_VERSION, &swapChainDesc, &m_swapChain, &m_device, NULL, &m_deviceContext);

This should fix your problem. If it doesn't work then there is something else in your code that isn't working, but I'm pretty sure this will fix it since me and a friend did a project together on one computer that didn't support DX11 and thus had to do this change.

Hope it works, gl! :D

Share this post


Link to post
Share on other sites
oldgregg    231
[quote name='PwFClockWise' timestamp='1354395788' post='5006092']
I've also done a few tutorials on that site and if your card can't support DX11 that error message will show up. You can go pass this by changing to your CPU to take care of the graphics, but this will lower your fps to like 0.1/s and it will take a lot of time to start the project. But it works.

result = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, &featureLevel, 1,
D3D11_SDK_VERSION, &swapChainDesc, &m_swapChain, &m_device, NULL, &m_deviceContext);

To change to run it on the CPU instead you change this part
[quote]D3D_DRIVER_TYPE_HARDWARE[/quote] to D3D_DRIVER_TYPE_REFERENCE

so it will be like this: result = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_REFERENCE, NULL, 0, &featureLevel, 1,
D3D11_SDK_VERSION, &swapChainDesc, &m_swapChain, &m_device, NULL, &m_deviceContext);

This should fix your problem. If it doesn't work then there is something else in your code that isn't working, but I'm pretty sure this will fix it since me and a friend did a project together on one computer that didn't support DX11 and thus had to do this change.

Hope it works, gl! [img]http://public.gamedev.net//public/style_emoticons/default/biggrin.png[/img]
[/quote]


That's done it! Thanks so much!
Is it just the way that that specific code runs that ruins it, Because all my other work has worked fine! I've had the multicoloured triangle going and everything lol.

Share this post


Link to post
Share on other sites
oldgregg    231
[quote name='riverreal' timestamp='1354395872' post='5006094']
You downloaded the source code directly? or copied it by hand?
[/quote]

I tried both, Same result each time!

Share this post


Link to post
Share on other sites
PwFClockWise    512
[quote name='oldgregg' timestamp='1354396731' post='5006096']
That's done it! Thanks so much!
Is it just the way that that specific code runs that ruins it, Because all my other work has worked fine! I've had the multicoloured triangle going and everything lol.
[/quote]

Glad I could help!

I have no idea, really. If you followed his tutorials from the start then you should've been doing DX11 the entire time. But even if you code in DX11 you can still adjust flags to run on earlier versions of DX, maybe that's what you've done earlier...not really sure, I find it a bit odd that your triangle worked in DX11 when your card doesn't support it ^^

Share this post


Link to post
Share on other sites
Bacterius    13165
Well what does your other "working" code do to initialize the device? That would seem the logical starting point to investigate the issue (unless you don't want to find out..)

Share this post


Link to post
Share on other sites
oldgregg    231
[quote name='Bacterius' timestamp='1354411452' post='5006170']
Well what does your other "working" code do to initialize the device? That would seem the logical starting point to investigate the issue (unless you don't want to find out..)
[/quote]

[CODE]
hr = D3D11CreateDeviceAndSwapChain( NULL, g_driverType, NULL, createDeviceFlags, featureLevels, numFeatureLevels,
D3D11_SDK_VERSION, &sd, &g_pSwapChain, &g_pd3dDevice, &g_featureLevel, &g_pImmediateContext );
[/CODE]

That's the code I'm using in the other project. I think it's detecting I can only run DX 10.1 and is selecting that.
Full code listing of InitDevice:
[CODE]
HRESULT Graphics::InitDevice(HWND mHWnd)
{
HRESULT hr = S_OK;
RECT rc;
GetClientRect( mHWnd, &rc );
UINT width = rc.right - rc.left;
UINT height = rc.bottom - rc.top;
UINT createDeviceFlags = 0;
#ifdef _DEBUG
createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
#endif
D3D_DRIVER_TYPE driverTypes[] =
{
D3D_DRIVER_TYPE_HARDWARE,
D3D_DRIVER_TYPE_WARP,
D3D_DRIVER_TYPE_REFERENCE,
};
UINT numDriverTypes = ARRAYSIZE( driverTypes );
D3D_FEATURE_LEVEL featureLevels[] =
{
D3D_FEATURE_LEVEL_11_0,
D3D_FEATURE_LEVEL_10_1,
D3D_FEATURE_LEVEL_10_0,
};
UINT numFeatureLevels = ARRAYSIZE( featureLevels );
DXGI_SWAP_CHAIN_DESC sd;
ZeroMemory( &sd, sizeof( sd ) );
sd.BufferCount = 1;
sd.BufferDesc.Width = width;
sd.BufferDesc.Height = height;
sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
sd.BufferDesc.RefreshRate.Numerator = 60;
sd.BufferDesc.RefreshRate.Denominator = 1;
sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
sd.OutputWindow = mHWnd;
sd.SampleDesc.Count = 1;
sd.SampleDesc.Quality = 0;
sd.Windowed = TRUE;
for( UINT driverTypeIndex = 0; driverTypeIndex < numDriverTypes; driverTypeIndex++ )
{
g_driverType = driverTypes[driverTypeIndex];
hr = D3D11CreateDeviceAndSwapChain( NULL, g_driverType, NULL, createDeviceFlags, featureLevels, numFeatureLevels,
D3D11_SDK_VERSION, &sd, &g_pSwapChain, &g_pd3dDevice, &g_featureLevel, &g_pImmediateContext );
if( SUCCEEDED( hr ) )
break;
}
if( FAILED( hr ) )
return hr;
// Create a render target view
ID3D11Texture2D* pBackBuffer = NULL;
hr = g_pSwapChain->GetBuffer( 0, __uuidof( ID3D11Texture2D ), ( LPVOID* )&pBackBuffer );
if( FAILED( hr ) )
return hr;
hr = g_pd3dDevice->CreateRenderTargetView( pBackBuffer, NULL, &g_pRenderTargetView );
pBackBuffer->Release();
if( FAILED( hr ) )
return hr;
g_pImmediateContext->OMSetRenderTargets( 1, &g_pRenderTargetView, NULL );
// Setup the viewport
D3D11_VIEWPORT vp;
vp.Width = (FLOAT)width;
vp.Height = (FLOAT)height;
vp.MinDepth = 0.0f;
vp.MaxDepth = 1.0f;
vp.TopLeftX = 0;
vp.TopLeftY = 0;
g_pImmediateContext->RSSetViewports( 1, &vp );
}
[/CODE]

Share this post


Link to post
Share on other sites
Bacterius    13165
Does tutorial 4 require a D3D11-exclusive feature? (like tessellation, etc..)? If not, then using feature levels should work equally well for this tutorial (the code is longer, but you could write a helper function that you can reuse in multiple projects).

Share this post


Link to post
Share on other sites
oldgregg    231
[quote name='Bacterius' timestamp='1354412856' post='5006178']
Does tutorial 4 require a D3D11-exclusive feature? (like tessellation, etc..)? If not, then using feature levels should work equally well for this tutorial (the code is longer, but you could write a helper function that you can reuse in multiple projects).
[/quote]

I don't think tutorial 4 does no, Even that tutorial is only drawing a triangle to the screen, But it set up buffers and other things in a way I found much better.

I might actually do what you said and write the helper function though! good call!

Share this post


Link to post
Share on other sites
clashie    632
Make sure that you're definitely ending up picking the 10 feature level. You'll also need to change the shader profile argument for D3DX11CompileFromFile. It's probably "ps_5_0" / "vs_5_0" right now. Change it accordingly -- on your card you'd need to use 4 instead.

Share this post


Link to post
Share on other sites
kunos    2254
I think your problem is in the "1" in this line:
result = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, &featureLevel, 1,

That parameter tells the function how many "features levels" are in "featureLevel", you are passing 1, so if your featureLevel array looks like this:
D3D_FEATURE_LEVEL featureLevels[] =
{
D3D_FEATURE_LEVEL_11_0,
D3D_FEATURE_LEVEL_10_1,
D3D_FEATURE_LEVEL_10_0,
};

You are asking for feature level 11.

To fix, pass 3 instead of 1 and the other feature levels will also be considered by the function.

Share this post


Link to post
Share on other sites
oldgregg    231
[quote name='clashie' timestamp='1354501565' post='5006471']
Make sure that you're definitely ending up picking the 10 feature level. You'll also need to change the shader profile argument for D3DX11CompileFromFile. It's probably "ps_5_0" / "vs_5_0" right now. Change it accordingly -- on your card you'd need to use 4 instead.
[/quote]

It wasn't doing this, MY GPU doesn't support Feature level11 so I needed 10/10.1:
[CODE]
// Set the feature level to DirectX 11.
featureLevel = D3D_FEATURE_LEVEL_10_0;
// Create the swap chain, Direct3D device, and Direct3D device context.
result = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, &amp;featureLevel, 1,
D3D11_SDK_VERSION, &amp;swapChainDesc, &amp;m_swapChain, &amp;m_device, NULL, &amp;m_deviceContext); //Used for GPU
[/CODE]
Then I needed to add a flag to my shader code 'D3D10_SHADER_ENABLE_BACKWARDS_COMPATIBILITY' and change it to use 'vs_4_0' :
[CODE]
// Compile the vertex shader code.
result = D3DX11CompileFromFile(vsFilename, NULL, NULL, "LightVertexShader", "vs_4_0", D3D10_SHADER_ENABLE_BACKWARDS_COMPATIBILITY, 0, NULL,
&amp;vertexShaderBuffer, &amp;errorMessage, NULL);
[/CODE]
(Same for PS)

Sorted now, It all runs on GPU and not CPU emulation :3!


EDIT: Thanks for all your help guys! Edited by oldgregg

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this