Reputation: 13
The code for the creation of the d3d11 device and swapchain fails to run on some computers and returns an E_INVALIDARG error. This also differs for computers with the same version of DirectX. I don't seem to find the reason for the different behaviours.
DXGI_MODE_DESC bufferDesc;
ZeroMemory(&bufferDesc, sizeof(DXGI_MODE_DESC));
bufferDesc.Width = width;
bufferDesc.Height = height;
bufferDesc.RefreshRate.Numerator = 60;
bufferDesc.RefreshRate.Denominator = 1;
bufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
bufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
bufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
DXGI_SWAP_CHAIN_DESC swapChainDesc;
ZeroMemory(&swapChainDesc, sizeof(DXGI_SWAP_CHAIN_DESC));
swapChainDesc.BufferDesc = bufferDesc;
swapChainDesc.SampleDesc.Count = aaCount;
swapChainDesc.SampleDesc.Quality = aaQuality;
swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swapChainDesc.BufferCount = 1;
swapChainDesc.OutputWindow = *hwnd;
swapChainDesc.Windowed = TRUE;
swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
//results in E_INVALIDARG in some cases
hr = D3D11CreateDeviceAndSwapChain(
nullptr,
D3D_DRIVER_TYPE_HARDWARE,
nullptr,
NULL,
nullptr,
NULL,
D3D11_SDK_VERSION,
&swapChainDesc,
&SwapChain,
&d3d11Device,
nullptr,
&d3d11DevCon);
ID3D11Texture2D* BackBuffer;
hr = SwapChain->GetBuffer( 0, __uuidof( ID3D11Texture2D ), (void**)(&BackBuffer) );
hr = d3d11Device->CreateRenderTargetView( BackBuffer, nullptr, &renderTargetView );
Upvotes: 1
Views: 2531
Reputation: 10049
As discovered from comments, the reason for the device creation failure was an unsupported combination of multisample quality and/or count. This support can be queried after device creation, and before swapchain creation by using the D3D11CreateDevice
function, and then ID3D11Device::CheckMultisampleQualityLevels
. Afterwards, a swap chain can be created with appropriate parameters.
Also, there is some guaranteed MSAA support based on the feature level, thus, if you require a certain feature level when creating the device, it can also be a way to validate the MSAA parameters (eg. and still using the D3D11CreateDeviceAndSwapChain
function). From the CheckMultisampleQualityLevels documentation, this guaranteed support is:
Note that FEATURE_LEVEL_10_1 devices are required to support 4x MSAA for all render targets except R32G32B32A32 and R32G32B32. FEATURE_LEVEL_11_0 devices are required to support 4x MSAA for all render target formats, and 8x MSAA for all render target formats except R32G32B32A32 formats.
Upvotes: 0
Reputation: 13
The problem was the high setting for the antialiasing (aaCount, aaQuality), some systems couldn't handle them and therefore failed to create the D3D11Device/Swapchain.
Upvotes: 0
Reputation: 3584
Replace the 'Flags' argument (currently NULL) with D3D11_CREATE_DEVICE_DEBUG and you'll get a human readable error message in the output that tells you what's wrong.
Upvotes: 1