[D3D12] Failure to create a swap chain

Started by
12 comments, last by Jess1997 8 years, 8 months ago

Hello, ladies and gentlemen.

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.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD;
	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;
}
Advertisement

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.

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.


DXGI_SWAP_EFFECT_FLIP_DISCARD has been added with D3D12. DirectX 12 graphics comes with several changes with presentation modes, you can learn more about here:

"Recursion is the first step towards madness." - "Skegg?ld, Skálm?ld, Skildir ro Klofnir!"
Direct3D 12 quick reference: https://github.com/alessiot89/D3D12QuickRef/

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.

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.

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
"Recursion is the first step towards madness." - "Skegg?ld, Skálm?ld, Skildir ro Klofnir!"
Direct3D 12 quick reference: https://github.com/alessiot89/D3D12QuickRef/

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.

Do the MS samples run on your hardware?

"Recursion is the first step towards madness." - "Skegg?ld, Skálm?ld, Skildir ro Klofnir!"
Direct3D 12 quick reference: https://github.com/alessiot89/D3D12QuickRef/

DXGI_SWAP_EFFECT_FLIP_DISCARD has been added with D3D12.

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.

Do the MS samples run on your hardware?

They run perfectly.

This topic is closed to new replies.

Advertisement