Hi everyone, here's a fun one. I've been using DX11 for ages and I've never seen anything like this happen before.
I found a bug in an application I'm developing when changing the resolution in full-screen mode. In order to handle arbitrary display mode changes (such as changes to MSAA settings), I destroy and recreate the swap chain whenever the display mode changes (rather than just using IDXGISwapChain::ResizeBuffers and IDXGISwapChain::ResizeTarget).
On application startup, the device and initial swapchain are created via D3D11CreateDeviceAndSwapChain. When the display mode changes, this initial swap chain is destroyed, and a new one is created using IDXGIFactory::CreateSwapChain, with a new DXGI_SWAP_CHAIN_DESC.
What I've found is that, despite the new DXGI_SWAP_CHAIN_DESC being correct when supplied to IDXGIFactory::CreateSwapChain, if I then retrieve the desc from the resulting swap chain, it has values from the old one. For example, if the resolution is changed, the swap chain is created with new (correct) values for BufferDesc.Width and BufferDesc.Height, but this new swap chain contains the old values which the initial (now destroyed) swap chain desc had.
Consequently the back buffer is the wrong size, which leads to obvious problems and errors.
Has anyone encountered a similar situation, or can think of anything useful to investigate?
Here's a simplified version of the code for the display mode change:
m_pDeviceContext->ClearState();
m_pDeviceContext->OMSetRenderTargets(0, nullptr, nullptr);
m_pSwapChain->Release();
m_pSwapChain = nullptr;
IDXGIFactory *pFactory = nullptr;
CheckResult(CreateDXGIFactory(__uuidof(IDXGIFactory), reinterpret_cast<void **>(&pFactory)));
IDXGISwapChain *pSwapChain = nullptr;
DXGI_SWAP_CHAIN_DESC swapChainDesc = CreateSwapChainDesc(...); // Returns populated DXGI_SWAP_CHAIN_DESC with correct values.
CheckResult(pFactory->CreateSwapChain(impl.m_pDevice, &swapChainDesc, &pSwapChain));
DXGI_SWAP_CHAIN_DESC verifySwapChainDesc;
ZeroMemory(&verifySwapChainDesc, sizeof(DXGI_SWAP_CHAIN_DESC));
pSwapChain->GetDesc(&verifySwapChainDesc);
// swapChainDesc does not equal verifySwapChainDesc.