Sign in to follow this  
laiyierjiangsu

Two graphics cards in one computer, How to make decision when createdevice!

Recommended Posts

Hi, all

    Firstly , I enumrate all adapter in pc.I choose the one with one ranking score.

IDXGIAdapter* LOBBYWINDOW::GetMostSuitableAdapter() {
	IDXGIAdapter* pBestAdapter = NULL;
	size_t BestAdapterVMem = 0;
	IDXGIAdapter* pAdapter = NULL;

	for ( uint32_t i = 0; DXGIFactory->EnumAdapters( i, &pAdapter ) != DXGI_ERROR_NOT_FOUND; i++ ) {
		DXGI_ADAPTER_DESC AdapterDesc;
		pAdapter->GetDesc( &AdapterDesc );
		if ( AdapterDesc.DedicatedVideoMemory > BestAdapterVMem ) {
			BestAdapterVMem = AdapterDesc.DedicatedVideoMemory;
			pBestAdapter = pAdapter;
		}
	}

	return pBestAdapter;
}

  As msdn tells us ,

 

EnumAdapters first returns the adapter with the output on which the desktop primary is displayed. This adapter corresponds with an index of zero.

Then , I use the best adapter to createdevice.


	res = D3D11CreateDevice(
		pBestAdapter,					// DXGI Adapter
		D3D_DRIVER_TYPE_UNKNOWN,	// DriverType needs to be UNKNOWN when passing pAdapter != NULL
		NULL,						// Software Rasterizer Pointer (if DriverType is Software)
		FeatureFlags,				// Flags
		featureLevels,				// Supported features levels
		ARRAYSIZE( featureLevels ),	// number of supported features
		D3D11_SDK_VERSION,			// SDK Version
		&D3DDevice,					// out Device
		&selectedFeatureLevel,		// out The feature level that the adapter chose
		&D3DDeviceContext			// out DeviceContext
	);

But I found that  the dapter with high score isn't the first one in the enumrating list. In some guys's pc, the first adapter is integrated video card, How can I solve this situation?

I have two ideas, one is  that  I show a message box to tip the player to change the independent card for displaying , and the other way is just

using the integrate vido card to createdevice (this way sometimes may failed to createdevice).

Can anyone have some experience on this problem ? Please help me.

 

Share this post


Link to post
Share on other sites

Thanks  a lot ,Hodgman

 

Then if you just pass NULL for the adaptor argument in D3D11CreateDevice, you should get the right one by default. This is generally the right thing to do as it leaves the decision up to the OS and the driver

 I did as you told me ,

			hr = D3D11API->D3D11DynamicCreateDevice(
				nullptr,
				eD3DDriverType,
				nullptr,
				creationFlags,
				&FeatureLevel,
				numFeatureLevels,
				D3D11_SDK_VERSION,
				&m_pD3D11Device,
				&selectedFeatureLevel,
				&m_pD3D11DeviceContext);

the return error code is 80070057,

HRESULT: 0x80070057 (2147942487)
Name: E_INVALIDARG
Description: An invalid parameter was passed to the returning function
Severity code: Failed
Facility Code: FACILITY_WIN32 (7)
Error Code: 0x0057 (87)

I do not know, I will try it letter?

Share this post


Link to post
Share on other sites

Don't rank by them by video-memory size -- integrated cards often report the entire system ram size in there, which will be more than what the "real" GPU has.
If you add this code into one of your CPP files, it tells hybrid laptops that you want to use the "real" GPU by default.

extern "C" { // Hint to Hybrid laptop drivers that our app would really rather use the NVidia/AMD GPU that you've got sitting over there rather than Intel Graphics...
	_declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001;
	_declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1;
}
Then if you just pass NULL for the adaptor argument in D3D11CreateDevice, you should get the right one by default. This is generally the right thing to do as it leaves the decision up to the OS and the driver. The user can actually choose which GPU is the default under their driver control panel on most laptops!

What does this mean? This means the system will choose the best video card to create device. If the user have two cards , Intel HD and nvidia 960,and user set intel hd card as the main output,  the I configured as you suggestions ,the system will choose nvidia card automatically??  It's really bothering me.


I would definitely suggest providing a proper UI (and/or command line argument) for selecting the adapter. Many many PC's have multiple video cards in them, and Windows 10 now has much better support for so-called "hybrid" systems without having to go through proprietary layers like Optimus.

Also, make sure that you're passing "D3D_DRIVER_TYPE_HARDWARE" if you're passing NULL as the adapter to D3D11CreateDevice.

proprietary layers like Optimus.   Is this just the way hodgman suggested?

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