1

I'm getting DXGI_ERROR_INVALID_CALL while calling CreateSwapChain. Here's my code to create command queque.

D3D12_COMMAND_QUEUE_DESC cqDesc = {};
cqDesc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;
cqDesc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;

hr = g_pDevice->CreateCommandQueue(&cqDesc, IID_PPV_ARGS(&g_pCommandQueue));
if (FAILED(hr)) {
    return false;
}

Here's where I'm calling CreateSwapChain.

DXGI_MODE_DESC bBuffDesc = {}; //To describe the display model.
SecureZeroMemory(&bBuffDesc, sizeof(bBuffDesc));
bBuffDesc.Height = Height; // ** Might have to give condition for windowed mode
bBuffDesc.Width = Width;
bBuffDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
bBuffDesc.RefreshRate.Denominator = Denominator;
bBuffDesc.RefreshRate.Numerator = Numerator;
bBuffDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
bBuffDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
DXGI_SAMPLE_DESC sampleDesc; //To describe multi-sampling preference. 
sampleDesc.Count = 1; //We are not using multi-sampling. We take 1 sample per pixel.
sampleDesc.Quality = 0; // no antialiasing
DXGI_SWAP_CHAIN_DESC swapChainDesc = {}; //To describe the swap chain.
swapChainDesc.BufferCount = g_cnFrameBufferCount;
swapChainDesc.BufferDesc = bBuffDesc;
swapChainDesc.SampleDesc = sampleDesc;
swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; //Tells the pipeline that this is a remder target and not a shader input.
swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD; //Discard the buffer after calling present.
swapChainDesc.OutputWindow = hwnd;
//swapChainDesc.Flags = DXGI_SWAP_CHAIN_FLAG_DISPLAY_ONLY;
//swapChainDesc.Windowed = false;

if (g_bWindowed) { // Windowed mode
    swapChainDesc.Windowed = true;
}
else { //Full-Screen mode
    swapChainDesc.Windowed = false;
}


IDXGISwapChain * tempSwapChain = nullptr;

hr = dxgiFactory->CreateSwapChain(g_pCommandQueue, &swapChainDesc, &tempSwapChain);

My hr returns the above error. Any help would be appreciated.

Updates (Problem still exists)

  • Removed unnecessary use of SecureZeroMemory as pointed out by Adam in the comment
  • Found that hr returns S_OK windowed mode. Seems like the problem has to do something with full-screen mode
ngub05
  • 566
  • 1
  • 8
  • 15
  • Why are you SecureZeroMemory'ing your swapChainDesc just before you call CreateSwapChain? – Adam Miles Mar 02 '16 at 13:43
  • Thanks for pointing out that Adam Miles. I just found that was absolutely unnecessary. Anyways the problem is not because of that. – ngub05 Mar 02 '16 at 13:48

1 Answers1

3

First you should turn on the debug layer for a chance of a more meaningful message using D3D12GetDebugInterface and also set the flag DXGI_CREATE_FACTORY_DEBUG when you create the factory.

You should also give a try to CreateSwapChainForHwnd because CreateSwapChain is close to deprecation. For fullscreen mode, it has a separate argument. In the two cases, you need the flag DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH for it to succeed. And the recommanded practice is to create a swap chain windowed and then use SetFullScreenState because windows can deny you the switch anyway and this has to be handled.

galop1n
  • 8,573
  • 22
  • 36