[D3D11]No display modes found?

Started by
3 comments, last by hupsilardee 12 years, 2 months ago
I'm experimenting with D3D11 for fun. I can create a device and swap chain, RTV, DSV, and get them all working fine. Now in my D3D9 framework I have the capability to change display modes on the fly, and switch fullscreen etc, so I wanted to replicate this functionality in D3D11. (My laptop is rather old and only DirectX 9.0c capable, but D3D11 works through the feature levels).

Here's the code I use to (try to) enumerate display modes and display them in the console output

// Create DXGI factory, enum display modes
IDXGIFactory* pFactory = NULL;
CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&pFactory);
IDXGIAdapter* pAdapter;
for (int i = 0; true; i++)
{
HRESULT enumhr = pFactory->EnumAdapters(i, &pAdapter);
if (DXGI_ERROR_NOT_FOUND == enumhr || FAILED(enumhr) || NULL == pAdapter)
{
break;
}
DXGI_ADAPTER_DESC adapterDesc;
pAdapter->GetDesc(&adapterDesc);
if (pAdapter)
{
char data[256] = { 0 };
wcstombs(data, adapterDesc.Description, 256);
std::cout << "Found adapter: " << std::endl;
std::cout << " Name: " << data << std::endl;
std::cout << " System Memory: " << adapterDesc.DedicatedSystemMemory << std::endl;
std::cout << " Dedicated Memory: " << adapterDesc.DedicatedVideoMemory << std::endl;
std::cout << " Shared Memory: " << adapterDesc.SharedSystemMemory << std::endl;
std::cout << std::endl;

IDXGIOutput* pOutput;
HRESULT outputhr = pAdapter->EnumOutputs(0, &pOutput);
if (DXGI_ERROR_NOT_FOUND == outputhr || FAILED(outputhr) || NULL == pAdapter)
{
continue;
}

DXGI_FORMAT format = DXGI_FORMAT_R8G8B8A8_UNORM;
UINT modeCount = 0;
HRESULT modehr = pOutput->GetDisplayModeList(format, 0, &modeCount, NULL);
DXGI_MODE_DESC* displayModes = new DXGI_MODE_DESC[modeCount];
pOutput->GetDisplayModeList(format, 0, NULL, displayModes);
std::cout << " " << modeCount << " Display modes available: " << std::endl;
for (int k = 0; k < modeCount; k++)
{
std::cout << " " << displayModes[k].Width << "x" << displayModes[k].Height
<< " @ " << displayModes[k].RefreshRate.Numerator / displayModes[k].RefreshRate.Denominator
<< " Hz" << std::endl;
}
delete[] displayModes;

pOutput->Release();
pAdapter->Release();
}
}


The problem is, modeCount returns 0, and no display modes are found... Why is this happening?
Advertisement
I'm reasonably certain that your second call to GetDisplayModeList also needs the pNumModes param - at least that's the way I do it and it works fine (and is also consistent with the sample code given in the documentation).

Here's my full code:
void D3D11Vid_EnumerateModes (void)
{
IDXGIFactory *pFactory = NULL;
IDXGIAdapter *pAdapter = NULL;

CreateDXGIFactory (__uuidof (IDXGIFactory), (void **) &pFactory);

for (UINT i = 0; pFactory->EnumAdapters (i, &pAdapter) != DXGI_ERROR_NOT_FOUND; i++)
{
d3d_adapterdesc_t *adapterdesc = new d3d_adapterdesc_t;
IDXGIOutput *pOutput = NULL;

pAdapter->GetDesc (&adapterdesc->Desc);

for (UINT j = 0; pAdapter->EnumOutputs (j, &pOutput) != DXGI_ERROR_NOT_FOUND; j++)
{
d3d_outputdesc_t *outputdesc = new d3d_outputdesc_t;

outputdesc->NumModes = 0;
outputdesc->ModeList = NULL;

pOutput->GetDesc (&outputdesc->Desc);
pOutput->GetDisplayModeList (DXGI_FORMAT_R8G8B8A8_UNORM, 0, &outputdesc->NumModes, outputdesc->ModeList);
outputdesc->ModeList = new DXGI_MODE_DESC[outputdesc->NumModes];
pOutput->GetDisplayModeList (DXGI_FORMAT_R8G8B8A8_UNORM, 0, &outputdesc->NumModes, outputdesc->ModeList);

outputdesc->Output = pOutput;
adapterdesc->Outputs.push_back (outputdesc);
pOutput = NULL;
}

adapterdesc->Adapter = pAdapter;
d3d_Adapters.push_back (adapterdesc);

// for the next one
pAdapter = NULL;
}

pFactory->Release ();
}

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

Looks like our codes are pretty similar, but I copied yours over anyway, and got rid of/refactored some stuff. (Whats wrong with camel casing???)

Here's the new code

void EnumDisplayModes()
{
IDXGIFactory *pFactory = NULL;
IDXGIAdapter *pAdapter = NULL;
IDXGIOutput *pOutput = NULL;

CreateDXGIFactory (__uuidof (IDXGIFactory), (void **) &pFactory);

for (UINT i = 0; pFactory->EnumAdapters (i, &pAdapter) != DXGI_ERROR_NOT_FOUND; i++)
{
DXGI_ADAPTER_DESC adapterDesc;

pAdapter->GetDesc(&adapterDesc);
char data[256];
wcstombs(data, adapterDesc.Description, 256);

std::cout << "Graphics adapter: " << data << std::endl;

for (UINT j = 0; pAdapter->EnumOutputs (j, &pOutput) != DXGI_ERROR_NOT_FOUND; j++)
{
UINT numModes;
DXGI_MODE_DESC* pModes = NULL;

pOutput->GetDisplayModeList (DXGI_FORMAT_R8G8B8A8_UNORM, 0, &numModes, pModes);
pModes = new DXGI_MODE_DESC[numModes];
pOutput->GetDisplayModeList (DXGI_FORMAT_R8G8B8A8_UNORM, 0, &numModes, pModes);

std::cout << "Display modes found: " << numModes << std::endl;
for (int k = 0; k < numModes; k++)
{
std::cout << pModes[k].Width << "x" << pModes[k].Height << " @ " <<
pModes[k].RefreshRate.Numerator / pModes[k].RefreshRate.Denominator << std::endl;
}
delete[] pModes;

pOutput->Release();
pOutput = NULL;
}

pAdapter->Release();
pAdapter = NULL;
}

pFactory->Release();
}


And the output

Graphics adapter : Mobile Intel(R) 965 Express Chipset Family
Display modes found: 0


can't try it on my desktop (ATI RHD 6670) because I didn't bring that with me to uni...

(Whats wrong with camel casing???)


I learned Pascal back in university in 1988 - I wouldn't care if I never saw camel casing ever again. ;)

The only remaining reason why I can think you're not getting any modes is because your adapter doesn't support any modes in the format you're using. Which would be very odd indeed, but it might be worth trying other formats to see what you get back.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

But.. that can't be right, because I can create the device and render out triangles (with D3D_FEATURE_LEVEL_9_3), and exactly the same back buffer format!

This topic is closed to new replies.

Advertisement