From 97b32f52cc123544a1352527c2509c804fd3d190 Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Mon, 12 Aug 2019 22:00:42 -0700 Subject: D3D12 backend: enabled multiple swap chain support --- Graphics/GraphicsEngine/include/SwapChainBase.h | 50 +++++++++++++++++++++++-- Graphics/GraphicsEngine/interface/SwapChain.h | 3 ++ 2 files changed, 50 insertions(+), 3 deletions(-) (limited to 'Graphics/GraphicsEngine') diff --git a/Graphics/GraphicsEngine/include/SwapChainBase.h b/Graphics/GraphicsEngine/include/SwapChainBase.h index 8b9aa86f..5a60c9ed 100644 --- a/Graphics/GraphicsEngine/include/SwapChainBase.h +++ b/Graphics/GraphicsEngine/include/SwapChainBase.h @@ -26,6 +26,8 @@ /// \file /// Implementation of the Diligent::SwapChainBase template class +#include + #include "RenderDevice.h" #include "DeviceContext.h" #include "SwapChain.h" @@ -89,13 +91,55 @@ protected: return false; } - + + template + bool UnbindRenderTargets(DeviceContextImplType* pImmediateCtx, + ITextureView* ppBackBufferRTVs[], + Uint32 NumBackBufferRTVs, + ITextureView* pDSV) + { + bool RebindRenderTargets = false; + bool UnbindRenderTargets = false; + if (m_SwapChainDesc.IsPrimary) + { + RebindRenderTargets = UnbindRenderTargets = pImmediateCtx->IsDefaultFBBound(); + } + else + { + std::array pBoundRTVs = {}; + RefCntAutoPtr pBoundDSV; + Uint32 NumRenderTargets = 0; + pImmediateCtx->GetRenderTargets(NumRenderTargets, pBoundRTVs.data(), &pBoundDSV); + for (Uint32 i=0; i < NumRenderTargets; ++i) + { + for (Uint32 j=0; j < NumBackBufferRTVs; ++j) + { + if (pBoundRTVs[i] == ppBackBufferRTVs[j]) + UnbindRenderTargets = true; + } + } + if (pBoundDSV == pDSV) + UnbindRenderTargets = true; + + for (auto pRTV : pBoundRTVs) + { + if (pRTV != nullptr) + pRTV->Release(); + } + } + + if (UnbindRenderTargets) + pImmediateCtx->ResetRenderTargets(); + + return RebindRenderTargets; + } + /// Strong reference to the render device - Diligent::RefCntAutoPtr m_pRenderDevice; + RefCntAutoPtr m_pRenderDevice; /// Weak references to the immediate device context. The context holds /// the strong reference to the swap chain. - Diligent::RefCntWeakPtr m_wpDeviceContext; + RefCntWeakPtr m_wpDeviceContext; /// Swap chain description SwapChainDesc m_SwapChainDesc; diff --git a/Graphics/GraphicsEngine/interface/SwapChain.h b/Graphics/GraphicsEngine/interface/SwapChain.h index 5e780292..164608e1 100644 --- a/Graphics/GraphicsEngine/interface/SwapChain.h +++ b/Graphics/GraphicsEngine/interface/SwapChain.h @@ -54,6 +54,9 @@ public: /// \param [in] NewWidth - New swap chain width, in pixels /// \param [in] NewHeight - New swap chain height, in pixels + /// + /// \note When resizing non-primary swap chains, the engine unbinds the + /// swap chain buffers from the output. virtual void Resize( Uint32 NewWidth, Uint32 NewHeight ) = 0; /// Sets fullscreen mode (only supported on Win32 platform) -- cgit v1.2.3