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!