Switching D3D12 device in UWP app causes CreateSwapChainForCoreWindow to fail

136 views Asked by At

I have a UWP app which may need to switch between D3D12 devices. For that, I would create a new swap chain by calling CreateSwapChainForCoreWindow. However, this operation fails with E_ACCESSDENIED if I do a switch (it works in the first call) and the debug layer prints the following message:

DXGI ERROR: IDXGIFactory::CreateSwapChain: Only one flip model swap chain can be associate with an HWND, IWindow, or composition surface at a time. ClearState() and Flush() may need to be called on the D3D11 device context to trigger deferred destruction of old swapchains. [ MISCELLANEOUS ERROR #297: ]

On D3D11, I can do exactly this, call ClearState and Flush on the device context before creating a new swap chain, but I have no idea what the equivalent would be in D3D12.

1

There are 1 answers

0
Junjie Zhu - MSFT On BEST ANSWER

This error can be resolved by calling ID3D12GraphicsCommandList::ClearState and waiting for a fence before creating a new swap chain.