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;
}