Jump to content
  • Advertisement
Sign in to follow this  
Jess1997

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.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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;
}
Edited by Jess1997

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
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.


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:

Edited by Alessio1989

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites

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.

Edited by Dave Hunt

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!