summaryrefslogtreecommitdiffstats
path: root/Graphics
diff options
context:
space:
mode:
authorEgor Yusov <egor.yusov@gmail.com>2018-03-31 23:20:15 +0000
committerEgor Yusov <egor.yusov@gmail.com>2018-03-31 23:20:15 +0000
commitc6a08259e93f63fbbac8517f8ecf7dc5536e29e3 (patch)
tree5d03fbdcb27100366cd70ae5525bb20479b81c34 /Graphics
parentFixed build error on iOS (diff)
downloadDiligentCore-c6a08259e93f63fbbac8517f8ecf7dc5536e29e3.tar.gz
DiligentCore-c6a08259e93f63fbbac8517f8ecf7dc5536e29e3.zip
Some minor updates to d3d swap chain
Diffstat (limited to 'Graphics')
-rw-r--r--Graphics/GraphicsEngineD3D11/src/SwapChainD3D11Impl.cpp9
-rw-r--r--Graphics/GraphicsEngineD3DBase/include/SwapChainD3DBase.h13
2 files changed, 20 insertions, 2 deletions
diff --git a/Graphics/GraphicsEngineD3D11/src/SwapChainD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/SwapChainD3D11Impl.cpp
index 7b0f99b5..ca5faf08 100644
--- a/Graphics/GraphicsEngineD3D11/src/SwapChainD3D11Impl.cpp
+++ b/Graphics/GraphicsEngineD3D11/src/SwapChainD3D11Impl.cpp
@@ -157,6 +157,15 @@ void SwapChainD3D11Impl::UpdateSwapChain(bool CreateNew)
if(CreateNew)
{
m_pSwapChain.Release();
+
+ // Only one flip presentation model swap chain can be associated with an HWND.
+ // We must make sure that the swap chain is actually released by D3D11 before creating a new one.
+ // To force the destruction, we need to ensure no views are bound to pipeline state, and then call Flush
+ // on the immediate context. Dstruction must be forced before calling IDXGIFactory2::CreateSwapChainForHwnd(), or
+ // IDXGIFactory2::CreateSwapChainForCoreWindow() again to create a new swap chain.
+ // https://msdn.microsoft.com/en-us/library/windows/desktop/ff476425(v=vs.85).aspx#Defer_Issues_with_Flip
+ pImmediateCtxD3D11->Flush();
+
auto *pd3d11Device = ValidatedCast<RenderDeviceD3D11Impl>(m_pRenderDevice.RawPtr())->GetD3D11Device();
CreateDXGISwapChain(pd3d11Device);
}
diff --git a/Graphics/GraphicsEngineD3DBase/include/SwapChainD3DBase.h b/Graphics/GraphicsEngineD3DBase/include/SwapChainD3DBase.h
index 0dc8bb0d..e61a3842 100644
--- a/Graphics/GraphicsEngineD3DBase/include/SwapChainD3DBase.h
+++ b/Graphics/GraphicsEngineD3DBase/include/SwapChainD3DBase.h
@@ -102,9 +102,18 @@ namespace Diligent
swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swapChainDesc.BufferCount = m_SwapChainDesc.BufferCount;
swapChainDesc.Scaling = DXGI_SCALING_NONE;
+
+ // DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL is the flip presentation model, where the contents of the back
+ // buffer is preserved after the call to Present. This flag cannot be used with multisampling.
+ // The only swap effect that supports multisampling is DXGI_SWAP_EFFECT_DISCARD.
// Windows Store apps must use DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL or DXGI_SWAP_EFFECT_FLIP_DISCARD.
swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL;
- swapChainDesc.AlphaMode = DXGI_ALPHA_MODE_UNSPECIFIED; // Not used
+
+ swapChainDesc.AlphaMode = DXGI_ALPHA_MODE_UNSPECIFIED; // Transparency behavior is not specified
+
+ // DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH enables an application to switch modes by calling
+ // IDXGISwapChain::ResizeTarget(). When switching from windowed to fullscreen mode, the display
+ // mode (or monitor resolution) will be changed to match the dimensions of the application window.
swapChainDesc.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
CComPtr<IDXGISwapChain1> pSwapChain1;
@@ -154,7 +163,7 @@ namespace Diligent
if (m_pSwapChain)
{
// If we are already in fullscreen mode, we need to switch to windowed mode first,
- // otherwise swap chain creation will fail
+ // because a swap chain must be in windowed mode when it is released.
if (m_FSDesc.Fullscreen)
m_pSwapChain->SetFullscreenState(FALSE, nullptr);
m_FSDesc.Fullscreen = True;