DirectX9 CreateDevice failed with D3DERR_NOTAVAILA

2019-08-29 04:17发布

问题:

There is initializing code for dx9 device

D3DDISPLAYMODE display;
m_pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &display);

ZeroMemory(&m_d3dpp, sizeof(m_d3dpp));
m_d3dpp.Windowed = false;
m_d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
m_d3dpp.BackBufferFormat = display.Format;
m_d3dpp.EnableAutoDepthStencil = false;
m_d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE;
/*BackBufferHeight and BackBufferWidth also set from elsewhere*/
DWORD flags = D3DCREATE_FPU_PRESERVE|D3DCREATE_MULTITHREADED;
m_pD3D->CreateDevice(D3DADAPTER_DEFAULT, m_Devtype, hWnd, flags, &m_d3dpp, &m_pd3dDevice)

The fact is that this works well with both m_Devtype = D3DDEVTYPE_HAL and m_Devtype = D3DDEVTYPE_REF.

But on some particular computer (winXP, sp3, last dx installed) CreateDevice returns D3DERR_INVALIDCALL for D3DDEVTYPE_HAL and D3DERR_NOTAVAILABLE for D3DDEVTYPE_REF. m_pD3D and display are both valid. display struct has rgb565 in format field.

Seems to be important: "DX Caps Viewer" shows no hardware adapters and only one software, with format rgb565.

Looks like every parameter is right in CreateDevice and i expect that it must return D3D_OK for reference device, why not?

UPD1: Now i know, that this unlucky XP runs on some virtual machine. That's why there is just one software adapter, i guess.

回答1:

You didn't specify any vertex processing method in CreateDevice function. try set it as D3DCREATE_SOFTWARE_VERTEXPROCESSING, you must set one of the vertex process method, this is mandatory accroding to DirectX SDK document.

D3DCREATE_HARDWARE_VERTEXPROCESSING, D3DCREATE_MIXED_VERTEXPROCESSING, and D3DCREATE_SOFTWARE_VERTEXPROCESSING are mutually exclusive flags. At least one of these vertex processing flags must be specified when calling CreateDevice.