Jump to content

  • Log In with Google      Sign In   
  • Create Account


Direct X 11: Creating the device issue


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
2 replies to this topic

#1 noodleBowl   Members   -  Reputation: 183

Like
0Likes
Like

Posted 03 November 2013 - 06:19 PM

I'm trying to jump into Direct X 11 and I'm having some issues creating a device when the adapter is specified

 

I currently have this custom struct to hold the information of each adapter that could exist. I also have a vector to hold them all in

//Struct to hold adapter information
struct DisplayAdapter
{
	IDXGIAdapter* adapter;
	DXGI_MODE_DESC* resolutions;
	DXGI_ADAPTER_DESC description;
	UINT numberOfResolutions;
};

//Vector of all the devices
std::vector<DisplayAdapter> availableDisplayAdapters;

I use this method to find all of the available adapters, which then fills my adapter vector

bool SystemX11::findDisplayAdapters()
{
        //Clean out the vector of adapters and set the current adapter to 0
	cleanDisplayAdapters();
	currentAdapter = 0;

	HRESULT result;

        //Create the factory
	IDXGIFactory *factory = NULL;
	result = CreateDXGIFactory(__uuidof(IDXGIFactory), (void**) (&factory));

	if(FAILED(result))
	{
		std::cout<<"Failed to create the factory"<<std::endl;
		return false;
	}
        
        //Create all the items needs to store and find the display adapters
	DisplayAdapter tempAdapter;
	IDXGIOutput *adapterOutput;
	ZeroMemory(&tempAdapter, sizeof(DisplayAdapter));
	ZeroMemory(&adapterOutput, sizeof(IDXGIOutput));
        
        //Find all the display adapters
	for(UINT i = 0; factory->EnumAdapters(i, &tempAdapter.adapter) != DXGI_ERROR_NOT_FOUND; ++i)
	{
		//Get the description
		tempAdapter.adapter->GetDesc(&tempAdapter.description);
		
		//Get the display modes
		tempAdapter.adapter->EnumOutputs(0, &adapterOutput);
		adapterOutput->GetDisplayModeList(supportedDisplayFormat, 0, &tempAdapter.numberOfResolutions, NULL);
		tempAdapter.resolutions = new DXGI_MODE_DESC[tempAdapter.numberOfResolutions];
		adapterOutput->GetDisplayModeList(supportedDisplayFormat, 0, &tempAdapter.numberOfResolutions, tempAdapter.resolutions);

		//[Debug Stuff]
		std::wcout<<"Display Adapter: "<<tempAdapter.description.Description<<std::endl;
		for(int i = 0; i < tempAdapter.numberOfResolutions; i++)
		{
			if(tempAdapter.resolutions[i].Scaling == 0)
				std::cout<<tempAdapter.resolutions[i].Width<<" x "<<tempAdapter.resolutions[i].Height<<" "<<tempAdapter.resolutions[i].RefreshRate.Numerator/tempAdapter.resolutions[i].RefreshRate.Denominator<<"hz"<<std::endl;
		}
		
                //Put the new adapter in the vector of available adapters
		availableDisplayAdapters.push_back(tempAdapter);
	}

	//Clean up of stuff

        //CLean up the factor
	if(factory != NULL)
		factory ->Release();
	
        //Clean up the temp adapter
	if(tempAdapter.adapter != NULL)
		tempAdapter.adapter->Release();

        ///Clean the temp resolutions
	if(tempAdapter.resolutions != NULL)
		delete [] tempAdapter.resolutions;

        //Clear the adapter output
	if(adapterOutput != NULL)
		adapterOutput->Release();

	return true;
}

Here is the clean up adapter method above just in case

bool SystemX11::cleanDisplayAdapters()
{
        //If there is nothing to clean backout
	if(availableDisplayAdapters.empty())
		return false;

        //For every device do clean up
	for(std::vector<DisplayAdapter>::iterator i = availableDisplayAdapters.begin(); i != availableDisplayAdapters.end(); i++)
	{
		(*i).adapter->Release();
		(*i).numberOfResolutions = NULL;
		ZeroMemory(&(*i).description, sizeof(DXGI_ADAPTER_DESC));
		delete [] (*i).resolutions;
	}
        
        //Clear the vector
	availableDisplayAdapters.clear();

	return true;
}

Now my issue is when I acutally try to create the device, for some reason it fails to create when I use my first adapter in my vector. This is the only adatper I have. Also for some reason if I use NULL in the first parameter the device creates just fine.

 

Here is my create device code

bool SystemX11::createDirectDevice(int adapterToUse)
{
	HRESULT hr;
        
        //Make sure we are creating on the right device, adapterToUse is 0 in this case. The first slot in the vector
	std::wcout<<"Creating device from: "<<availableDisplayAdapters[adapterToUse].description.Description<<std::endl;

        //Attempt to create the device
	hr = D3D11CreateDevice(availableDisplayAdapters[adapterToUse].adapter,
							D3D_DRIVER_TYPE_HARDWARE,
							NULL,
							NULL,
							NULL,
							0,
							D3D11_SDK_VERSION,
							&device,
							&supportedFeatureLevel,
							&deviceContext);

        //If we failed
	if(FAILED(hr))
	{
		std::cout<<"Failed to create the Direct X device. HR Error: "<<hr<<std::endl;
		return false;
	}

	return true;
}

What am I doing wrong?

I'm not really sure why this is happening, the hr error code printed out is -2147024809


Edited by noodleBowl, 03 November 2013 - 07:24 PM.


Sponsor:

#2 MJP   Moderators   -  Reputation: 10214

Like
3Likes
Like

Posted 03 November 2013 - 11:52 PM

If you specify an adapter as the first parameter of D3D11CreateDevice, then you have to pass D3D_DRIVER_TYPE_UNKNOWN as the driver type. I believe the docs for D3D11CreateDevice say this if you read through the remarks section.

As for the error code, if you're using the old headers and libs from the June 2010 DirectX SDK you can use DXGetErrorString/DXGetErrorDescription to get the string name of an HRESULT. If you're using the new headers and libs from the Windows 8 or Windows 8.1 SDK, then you can use FormatMessage to get the string. Or if you want Chuck Walbourn provided replacements for the DX error functions on his blog. Either way in your case the error code is probably just going to be E_INVALIDARG, which isn't particularly helpful for figuring out what you did wrong. However if you pass D3D11_CREATE_DEVICE_DEBUG as the flags parameter of D3D11CreateDevice, then any further failing function calls after creating the device will output a detailed message in the debugger output window. You can also use the ID3D11Debug interface to make the runtime break on errors or warnings, which is pretty helpful. Just make sure you don't pass it for Release builds, since end-users typically won't have the debug runtimes installed on their system.


Edited by MJP, 04 November 2013 - 12:01 AM.


#3 noodleBowl   Members   -  Reputation: 183

Like
0Likes
Like

Posted 05 November 2013 - 09:46 PM

If you specify an adapter as the first parameter of D3D11CreateDevice, then you have to pass D3D_DRIVER_TYPE_UNKNOWN as the driver type. I believe the docs for D3D11CreateDevice say this if you read through the remarks section.

 

<Other portions of quote>

 

While this is something to try out. Is it possible that because I use a "temp" DisplayAdapter struct and clean it up that I'm faced with null memory area?

Also maybe the scope of the "temp" object could be effecting it? Seeing as the method to find the adapters and the method to create the device are seperated

 

I would solve this using a deep copy but I'm unsure how to do this.  Especially since the struct includes pointers for the IDXGIAdapter COM object and array of DXGI_MODE_DESCs. Or am I just thinking wayout in left field?

 

Then at least I would know the error lies in the D3D_DRIVER_TYPE_UNKNOWN and not something else.


Edited by noodleBowl, 05 November 2013 - 10:00 PM.





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