DX12 [D3D12] Failure to create a swap chain

This topic is 1077 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Today, I've been trying to create a swap chain to no avail and I really can't figure out why.

When I call CreateSwapChain(), it fails with 0x887a0001 (DXGI_ERROR_INVALID_CALL) and the debug layer doesn't even report anything.

The way I create my swap chain is no different than the way the official samples do (The samples run just fine on my computer and my GPU fully support DX12). In fact, the code below is almost the same as the code found in the samples, so where could the problem be?

Any help is appreciated.

Here's the code:

bool Renderer::InitializePipeline(HWND hWnd)
{
HRESULT HR;

ID3D12Debug *debugController;

HR = D3D12GetDebugInterface(IID_PPV_ARGS(&debugController));

if (SUCCEEDED(HR))
{
debugController->EnableDebugLayer();
}

HR = D3D12CreateDevice(nullptr, D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&device));

if (FAILED(HR)) return false;

D3D12_COMMAND_QUEUE_DESC commandQueueDesc = {};

commandQueueDesc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
commandQueueDesc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;

HR = device->CreateCommandQueue(&commandQueueDesc, IID_PPV_ARGS(&commandQueue));

if (FAILED(HR)) return false;

DXGI_SWAP_CHAIN_DESC swapChainDesc = {};

swapChainDesc.BufferCount = 2; //Used to be 1, but changed it to 2 thanks to Alessio1989. There's still a problem I haven't figured out...
swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
swapChainDesc.BufferDesc.Height = 600;
swapChainDesc.BufferDesc.Width = 800;
swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swapChainDesc.OutputWindow = hWnd;
swapChainDesc.SampleDesc.Count = 1;
swapChainDesc.Windowed = true;

IDXGIFactory4 *factory;

HR = CreateDXGIFactory1(IID_PPV_ARGS(&factory));

if (FAILED(HR))
{
factory->Release();

return false;
}

HR = factory->CreateSwapChain(commandQueue, &swapChainDesc, &swapChain); //Fails every single time.

factory->Release();

if (FAILED(HR)) debugController->Release(); return false;

debugController->Release();

return true;
}
Edited by Jess1997

Share on other sites

Is that your actual code? As far as I know, there is no DXGI_SWAP_EFFECT_FLIP_DISCARD, so the above shouldn't compile.

If that's a typo, then please post the actual code as it appears in your source file.

Share on other sites
BufferCount must be greater or equal then 2 in flip mode.

Is that your actual code? As far as I know, there is no DXGI_SWAP_EFFECT_FLIP_DISCARD, so the above shouldn't compile.

If that's a typo, then please post the actual code as it appears in your source file.

Edited by Alessio1989

Share on other sites

Is that your actual code? As far as I know, there is no DXGI_SWAP_EFFECT_FLIP_DISCARD, so the above shouldn't compile.

If that's a typo, then please post the actual code as it appears in your source file.

Well, that's what they use in the samples and it does compile.

Share on other sites

Hmm, I did try to change the buffercount to 2 before and it didn't work. If that was a problem, it isn't the only one.

Edited by Jess1997

Share on other sites

Hmm, I did try to change the buffercount to 2 before and it didn't work. If that was a problem, it isn't the only one.

I think you should have a look to the first public samples https://github.com/Microsoft/DirectX-Graphics-Samples

Share on other sites

I think you should have a look to the first public samples https://github.com/Microsoft/DirectX-Graphics-Samples

My swap chain description is exactly the same as the one in the samples. It wasn't before when my buffercount was 1, but since I changed it to 2 like you told me to, it's exactly the same. I really don't get it, but I'll try to see if it could be the handle to my window (Even though my window works properly), because the rest is exactly as it is in the samples (Except for the fact that they use an IDXGISwapChain and then query the interface of a IDXGISwapChain3 right after they're done creating the swap chain, but I doubt it has anything to do with it). Anyway, I really appreciate your help.

Edited by Jess1997

Share on other sites

Do the MS samples run on your hardware?

Share on other sites

Sorry for the bum steer. I did a search and couldn't find it. I suspect I was looking at an earlier version of the D3D12 docs.

Edited by Dave Hunt

Share on other sites

Do the MS samples run on your hardware?

They run perfectly.

1. 1
2. 2
Rutin
23
3. 3
JoeJ
20
4. 4
5. 5

• 24
• 40
• 23
• 13
• 13
• Forum Statistics

• Total Topics
631734
• Total Posts
3001933
×