Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


Could Not initialize Direct3D


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
12 replies to this topic

#1 oldgregg   Members   -  Reputation: 231

Like
1Likes
Like

Posted 01 December 2012 - 02:15 PM

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.

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...


Any help would be really appreciated, Thanks!

Sponsor:

#2 Celiasson   Members   -  Reputation: 508

Like
2Likes
Like

Posted 01 December 2012 - 03:03 PM

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

D3D_DRIVER_TYPE_HARDWARE

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

#3 riverreal   Members   -  Reputation: 616

Like
0Likes
Like

Posted 01 December 2012 - 03:04 PM

You downloaded the source code directly? or copied it by hand?

#4 oldgregg   Members   -  Reputation: 231

Like
0Likes
Like

Posted 01 December 2012 - 03:18 PM

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

D3D_DRIVER_TYPE_HARDWARE

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! Posted Image



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.

#5 oldgregg   Members   -  Reputation: 231

Like
0Likes
Like

Posted 01 December 2012 - 03:19 PM

You downloaded the source code directly? or copied it by hand?


I tried both, Same result each time!

#6 Celiasson   Members   -  Reputation: 508

Like
0Likes
Like

Posted 01 December 2012 - 05:12 PM

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.


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 ^^

#7 Bacterius   Crossbones+   -  Reputation: 9293

Like
0Likes
Like

Posted 01 December 2012 - 07:24 PM

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..)

The slowsort algorithm is a perfect illustration of the multiply and surrender paradigm, which is perhaps the single most important paradigm in the development of reluctant algorithms. The basic multiply and surrender strategy consists in replacing the problem at hand by two or more subproblems, each slightly simpler than the original, and continue multiplying subproblems and subsubproblems recursively in this fashion as long as possible. At some point the subproblems will all become so simple that their solution can no longer be postponed, and we will have to surrender. Experience shows that, in most cases, by the time this point is reached the total work will be substantially higher than what could have been wasted by a more direct approach.

 

- Pessimal Algorithms and Simplexity Analysis


#8 oldgregg   Members   -  Reputation: 231

Like
0Likes
Like

Posted 01 December 2012 - 07:42 PM

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..)


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

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:
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 );
}


#9 Bacterius   Crossbones+   -  Reputation: 9293

Like
0Likes
Like

Posted 01 December 2012 - 07:47 PM

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).

The slowsort algorithm is a perfect illustration of the multiply and surrender paradigm, which is perhaps the single most important paradigm in the development of reluctant algorithms. The basic multiply and surrender strategy consists in replacing the problem at hand by two or more subproblems, each slightly simpler than the original, and continue multiplying subproblems and subsubproblems recursively in this fashion as long as possible. At some point the subproblems will all become so simple that their solution can no longer be postponed, and we will have to surrender. Experience shows that, in most cases, by the time this point is reached the total work will be substantially higher than what could have been wasted by a more direct approach.

 

- Pessimal Algorithms and Simplexity Analysis


#10 oldgregg   Members   -  Reputation: 231

Like
0Likes
Like

Posted 02 December 2012 - 02:04 PM

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).


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!

#11 clashie   Validating   -  Reputation: 479

Like
2Likes
Like

Posted 02 December 2012 - 08:26 PM

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.

#12 kunos   Crossbones+   -  Reputation: 2207

Like
2Likes
Like

Posted 03 December 2012 - 12:11 AM

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.
Stefano Casillo
Lead Programmer
TWITTER: @KunosStefano
AssettoCorsa - netKar PRO - Kunos Simulazioni

#13 oldgregg   Members   -  Reputation: 231

Like
0Likes
Like

Posted 04 December 2012 - 06:47 AM

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.


It wasn't doing this, MY GPU doesn't support Feature level11 so I needed 10/10.1:
// 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
Then I needed to add a flag to my shader code 'D3D10_SHADER_ENABLE_BACKWARDS_COMPATIBILITY' and change it to use 'vs_4_0' :
// 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);
(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, 04 December 2012 - 06:48 AM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS