Jump to content

  • Log In with Google      Sign In   
  • Create Account


[SOLVED] Query Devices in D3D11


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

#1 Ashkan_Irni   Members   -  Reputation: 103

Like
0Likes
Like

Posted 30 December 2012 - 12:41 PM

Hi there,

 

I'm not familiar with D3D11 but for my C++ AMP application I need to query the available devices, choose one that is not connected to a display to use it as a dedicated accelerator, and to turn off the TDR for that device.

 

This blog post discusses how to create a D3D11 device with TDR turned off. My problem is that I don't know how to choose the correct pAdapter parameter (an adapter without a display).

 

I tried to find the solution on MSDN, I think I should enumerate IDXGIAdapter2 and store the available adapters on an std::vector<IDXGIAdapter2*>, then use GetDesc2 on each element in the vector to get a DXGI_ADAPTER_DESC2 structure, then read its Description data member.

 

The problem is that there is no example or guidelines on how to enumerate IDXGIAdapter2. Two examples with descriptions exist but they are for IDXGIAdapter and IDXGIAdapter1.

 

So I would like to ask you guys to kindly help me or give me some hints on how to query the available devices and check their description.

 

Thanks in advance smile.png



Sponsor:

#2 MJP   Moderators   -  Reputation: 10117

Like
0Likes
Like

Posted 30 December 2012 - 03:51 PM

The way I do this for DXGI 1.1 is I create an IDXGIFactory1 with CreateDXGIFactory1, and then I call EnumAdapters. The docs for IDXGIFactory2 suggest that the same approach will work, you just need to pass __uuidof(IDXGIFactory2) when calling CreateDXGIFactory.



#3 Ashkan_Irni   Members   -  Reputation: 103

Like
0Likes
Like

Posted 30 December 2012 - 09:36 PM

The way I do this for DXGI 1.1 is I create an IDXGIFactory1 with CreateDXGIFactory1, and then I call EnumAdapters. The docs for IDXGIFactory2 suggest that the same approach will work, you just need to pass __uuidof(IDXGIFactory2) when calling CreateDXGIFactory.

 

Hi MJP,

 

Thank you for your help.

 

The documentation on IDXGIFactory2 is not clear because if I use 1.1 approach to get the devices then I won't have GetDesc2() method available, and another problem is that if I use IDXGI 1 or 1.1 I can't get any descriptions using GetDesc() and GetDesc1()I wrote the following code to test IDXGI 1.1 and 2 and in both cases the pointers that I get from enumerating adapters point to nothing:

 

2cfpqh0.jpg

 

and this is the whole test code:

#include <iostream>
#include <tchar.h>
#include <vector>
#include <d3d11.h>
#include <dxgi.h>
#include <dxgi1_2.h>

#pragma comment(lib, "dxgi.lib")

typedef unsigned int uint32_t;

void Test_DXGI_1()
{
	IDXGIFactory1*	DXGI_device_ptr	  = nullptr;
	IDXGIAdapter1*	adapter_ptr	  = nullptr;

	if( FAILED( CreateDXGIFactory1( __uuidof( IDXGIFactory1 ), ( void** ) &DXGI_device_ptr ) ) )
	{
		fprintf( stderr, "\tCould not Create IDXGIFactory\n" );
	}

	uint32_t i = 0;
	std::vector<IDXGIAdapter1*> adapter_list;
	
	while ( DXGI_device_ptr->EnumAdapters1( i, &adapter_ptr ) != DXGI_ERROR_NOT_FOUND )
	{
		adapter_list.push_back( adapter_ptr );
		++i;
	}

	DXGI_ADAPTER_DESC1* temp_desc = nullptr;
	
	for ( int i = 0; i < adapter_list.size(); ++i )
	{
		adapter_list[i]->GetDesc1( temp_desc );
		std::wcout << temp_desc->Description;

		std::cin.get();	// wait
	}
}


void Test_DXGI_2()
{
	IDXGIFactory2*	DXGI_device_ptr	  = nullptr;
	IDXGIAdapter2*	adapter_ptr	  = nullptr;

	if( FAILED( CreateDXGIFactory( __uuidof( IDXGIFactory2 ), ( void** ) &DXGI_device_ptr ) ) )
	{
		fprintf( stderr, "\tCould not Create IDXGIFactory\n" );
	}

	uint32_t i = 0;
	std::vector<IDXGIAdapter1*> adapter_list;
	IDXGIAdapter1* adapter1_ptr = nullptr;

	while ( DXGI_device_ptr->EnumAdapters1( i, &adapter1_ptr ) != DXGI_ERROR_NOT_FOUND )
	{
		adapter_list.push_back( adapter1_ptr );
		++i;
	}

	DXGI_ADAPTER_DESC1* temp_desc = nullptr;

	for ( int i = 0; i < adapter_list.size(); ++i )
	{
		adapter_list[i]->GetDesc1( temp_desc );
		std::wcout << temp_desc->Description;

		std::cin.get();	// wait
	}
}


int main( int argc, char* argv[] )
{
	Test_DXGI_1();
	Test_DXGI_2();

	std::cin.get();	// wait

	return 0;
}


#4 NewDisplayName   Members   -  Reputation: 351

Like
1Likes
Like

Posted 30 December 2012 - 11:35 PM

First of all, you won't need IDXGIAdapter2. From the problem statement that you have put forth, this just seems to be "too much info".

 

Regarding something like "EnumAdapters2", there is no separate method for Factory2, when it already inherits these methods from Factory1.

There is a separate list of methods, that Factory2 additionally provides, but like I said before, looking at your needs it's just TMI.

 

Looking at Test_DXGI_1 method, I don't see any obvious issues but I can give you some pointers for debugging it properly.

I think you should first check for values that are being pushed into the vector. If Enum itself is not working fine, then GetDesc can't do much.

Your Enum needs to work before GetDesc, so you should focus more on that and begin trying from 1.0 and then move onto 1.1 or 2.0.

 

Just one more thing to confirm is that you're building your project with /clr. I'm curious about nullptr behaviour if built without /clr. Ideally, it shouldn't do any damage but jic.



#5 Ashkan_Irni   Members   -  Reputation: 103

Like
0Likes
Like

Posted 31 December 2012 - 12:27 AM

Hello there smile.png

 

thanks for your reply.

 

I checked the while loop where the enumeration is being done, it appears that the pointer to the device (adapter_ptr) contains an address and it does have the GetDesc1() method, the method receives a DXGI_ADAPTER_DESC1 pointer and it is supposed to fill the pointer with an address, but when the method returns the DXGI_ADAPTER_DESC1 pointer, it is NULL so something is wrong with the GetDesc1() method but I'm not sure what.

 

Here is a screenshot from debugging:

ibyvqr.jpg

 

I have also changed nullptr to NULL the problem still exists. I don't think nullptr needs /clr, I thought /clr is only needed when Microsoft's C++ managed extensions are being used, nullptr is standard C++. Honestly I'm not a fan of managed C++ so I prefer not using /clr... unless I have to. Even then it will cause other problems since I have to turn off quite a number of other compiler options.



#6 NewDisplayName   Members   -  Reputation: 351

Like
1Likes
Like

Posted 31 December 2012 - 01:18 AM

I think you're a bit confused about /clr option. It works even for an application which doesn't have managed data. You may want to read more about both nullptr and /clr. But anyhow, that isn't the problem at hand.

 

I think you're already quite close to the solution.

Unfortunately, I am unable to try out your code on my setup and check this issue firsthand.

But maybe you should get some pointers from this code here --> http://www.csh.rit.edu/~oguns/src/graphics.cpp

 

Hope this helps.



#7 Martins Mozeiko   Crossbones+   -  Reputation: 1413

Like
2Likes
Like

Posted 31 December 2012 - 01:21 AM

You should check that EnumAdapters1 returns S_OK.
Also you should check that GetDesc1 return S_OK.
If they don't return S_OK, then their error return code should hint where the problem lies - Get Desc1 expects pointer to existing structure, not NULL. It write to the object passed, but if you pass NULL there's nowhere to write adapter properties.

So you should write:

DXGI_ADAPTER_DESC1 temp_desc;
if (FAILED(adapter_ptr->GetDesc1(&temp_desc)) { error }

@NewDisplayName: nullptr is now standard way in C++11 how to say NULL.

Edited by Martins Mozeiko, 31 December 2012 - 01:24 AM.


#8 Ashkan_Irni   Members   -  Reputation: 103

Like
0Likes
Like

Posted 31 December 2012 - 02:01 AM

You should check that EnumAdapters1 returns S_OK.
Also you should check that GetDesc1 return S_OK.
If they don't return S_OK, then their error return code should hint where the problem lies - Get Desc1 expects pointer to existing structure, not NULL. It write to the object passed, but if you pass NULL there's nowhere to write adapter properties.

So you should write:
 

DXGI_ADAPTER_DESC1 temp_desc;
if (FAILED(adapter_ptr->GetDesc1(&temp_desc)) { error }

@NewDisplayName: nullptr is now standard way in C++11 how to say NULL.

 

Thank you so mcuh Martins Mozeiko for your help, you are correct the problem was passing NULL pointer to GetDesc1().

 

@NewDisplayName thanks for the link and for your replies






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