• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Ashkan_Irni

[SOLVED] Query Devices in D3D11

7 posts in this topic

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

0

Share this post


Link to post
Share on other sites
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;
}
0

Share this post


Link to post
Share on other sites

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.

1

Share this post


Link to post
Share on other sites

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.

0

Share this post


Link to post
Share on other sites

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.

1

Share this post


Link to post
Share on other sites
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
2

Share this post


Link to post
Share on other sites

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

0

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  
Followers 0