Advertisement

Enumoutputs do not work in Win10

Started by August 01, 2017 02:30 AM
4 comments, last by laiyierjiangsu 7 years, 6 months ago

            for (Foundation::UInt32 i = 0; ; i++)
            {
                hr = pAdapterInfo->pDXGIAdapter->EnumOutputs(i, &pDXGIOutput);
				if (SUCCEEDED(hr))
				{
		
						//EnumDisplayModes(pOutputInfo)
	
					}

					SAFE_RELEASE(pDXGIOutput);
				}
				else
				{
					//None output will be found
					if (i==0)
					{
						//error("EnumOupput error i:%u, error %s", i,str);
					}
					break;
                }
            }
            return true;
        }

Hi , guys!

         I used the upper code to get all resolutions supported by video card which will be selected by players.

But the code works perfectly in win7 , but it couldn't find any output in win10, I read a lot of papers ,but can not

find why.

    If anyone else has encountered this problem before ,please gives me some insight!

   Thanks a lot!

Stay hungry, stay foolish!

Which adapter are you enumerating outputs for? You should make sure that it's the adapter for a video card with a display attached (if you have multiple video cards and one of them does not have any displays attached, then it will have 0 DXGI outputs). If you call IDXGIAdapter::GetDesc and check the "Description" member of the returned struct, you can get the name of the adapter.

You should also read this bit of documentation about the WARP device on Windows 8+. I would make sure that you're not trying to enumerate displays for the WARP device.

Advertisement
On 2017/8/1 at 4:32 PM, MJP said:

Which adapter are you enumerating outputs for? You should make sure that it's the adapter for a video card with a display attached (if you have multiple video cards and one of them does not have any displays attached, then it will have 0 DXGI outputs). If you call IDXGIAdapter::GetDesc and check the "Description" member of the returned struct, you can get the name of the adapter.

You should also read this bit of documentation about the WARP device on Windows 8+. I would make sure that you're not trying to enumerate displays for the WARP device.

Thank you very much ! I have found the reason, but I still have another doubt.


bool D3D11EnumComponent::Check_DifferentDevice()
{
		HRESULT hr = S_OK;

		// get supported driver types
		D3D_DRIVER_TYPE* pDriverTypes = nullptr;
		int numDriverTypes = 0;

		D3D_DRIVER_TYPE   vecDriverTypeSupported[] =
		{
			D3D_DRIVER_TYPE_HARDWARE,
			D3D_DRIVER_TYPE_WARP,
			D3D_DRIVER_TYPE_REFERENCE
		};
		pDriverTypes = vecDriverTypeSupported;
		numDriverTypes = sizeof(vecDriverTypeSupported)/sizeof(vecDriverTypeSupported[0]);

		int numberofFeature = 1;
		D3D_FEATURE_LEVEL vecFeatureLevelsSupported[] =
		{
			D3D_FEATURE_LEVEL_11_0,
		};



		// for each type of driver, check device available.
		for (int iDriverTypeIndex = 0; iDriverTypeIndex < numDriverTypes; iDriverTypeIndex++)
		{
			// device creation flag
			UINT creationFlags = 0;
#if defined(_DEBUG)
			creationFlags |= D3D11_CREATE_DEVICE_DEBUG;
#endif

			ID3D11Device* pD3dDevice = NULL;
			ID3D11DeviceContext* pd3dDeviceContext = NULL;
			D3D_FEATURE_LEVEL eMaxFeatureLevel ;
			auto drivertype = pDriverTypes[iDriverTypeIndex];
			hr = D3D11CreateDevice(
				drivertype == D3D_DRIVER_TYPE_UNKNOWN ? g_pAdapter : nullptr,  // should be null if driver type not D3D_DRIVER_TYPE_UNKNOWN
				drivertype,
				nullptr,
				creationFlags,
				vecFeatureLevelsSupported,
				numberofFeature,
				D3D11_SDK_VERSION,
				&pD3dDevice,
				&eMaxFeatureLevel,
				&pd3dDeviceContext);


			if (FAILED(hr))
			{

				continue;
			}
			
			// update adapter interface
			IDXGIDevice* pDXGIDev = NULL;
			IDXGIAdapter* pAdapter = nullptr;
			hr = pD3dDevice->QueryInterface(__uuidof(IDXGIDevice), (LPVOID*)&pDXGIDev);
			if (SUCCEEDED(hr) && pDXGIDev)
			{
				hr = pDXGIDev->GetAdapter(&pAdapter);
				if (!SUCCEEDED(hr))
				{
					assert(false);
				}
				else
				{
					if(pAdapter != g_pAdapter)
					{
					//	assert(false);
						MessageBox(nullptr,L"a",L"bbbb",MB_OK);
					}
				}
			}
			else
			{
				assert(false);
			}
			SAFE_RELEASE(pDXGIDev);
		}	
		return true;

g_pAdapter is the best adapter I selected from Dxfactory, and it was the first adapter enumerated by dxfactory.

After I created the device, I got the adpter from the device ,  the two device wasn't same.

I cann't figure out why . How does D3D11CreateDevice choose a adapter to using?

I think there is something I do not know, Please help me!

Stay hungry, stay foolish!

If you picked an adapter from the factory, then why are you creating D3D_DRIVER_TYPE_HARDWARE instead of passing that adapter into D3D11CreateDevice?

Internally, D3D11 will create a factory and EnumAdapters(0) on it if you don't provide it an adapter. That's why your pointer compare doesn't work... the adapters may be logically the same, but they won't be the same pointer.

14 hours ago, SoldierOfLight said:

If you picked an adapter from the factory, then why are you creating D3D_DRIVER_TYPE_HARDWARE instead of passing that adapter into D3D11CreateDevice?

Internally, D3D11 will create a factory and EnumAdapters(0) on it if you don't provide it an adapter. That's why your pointer compare doesn't work... the adapters may be logically the same, but they won't be the same pointer.

Thanks, I see.

Stay hungry, stay foolish!

This topic is closed to new replies.

Advertisement