summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngineD3D11
diff options
context:
space:
mode:
authorassiduous <assiduous@diligentgraphics.com>2019-12-24 05:24:13 +0000
committerassiduous <assiduous@diligentgraphics.com>2019-12-24 05:24:13 +0000
commit4fd74ca8444da6491d5ec5f5e2b569c09cba2b3a (patch)
tree34bc4400307614539e044c0582f33ee2ce4dd643 /Graphics/GraphicsEngineD3D11
parentOpenGL backend: fixed issue with copying default framebuffer (diff)
downloadDiligentCore-4fd74ca8444da6491d5ec5f5e2b569c09cba2b3a.tar.gz
DiligentCore-4fd74ca8444da6491d5ec5f5e2b569c09cba2b3a.zip
Disabled SetRenderTarget(0, nullptr, nullptr) usage (fixed https://github.com/DiligentGraphics/DiligentCore/issues/81)
Diffstat (limited to 'Graphics/GraphicsEngineD3D11')
-rwxr-xr-xGraphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp66
-rw-r--r--Graphics/GraphicsEngineD3D11/src/EngineFactoryD3D11.cpp31
-rw-r--r--Graphics/GraphicsEngineD3D11/src/SwapChainD3D11Impl.cpp18
3 files changed, 24 insertions, 91 deletions
diff --git a/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp
index c3962a0a..676c6d73 100755
--- a/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp
+++ b/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp
@@ -32,7 +32,6 @@
#include "D3D11TypeConversions.h"
#include "TextureViewD3D11Impl.h"
#include "PipelineStateD3D11Impl.h"
-#include "SwapChainD3D11.h"
#include "ShaderResourceBindingD3D11Impl.h"
#include "EngineD3D11Defines.h"
#include "CommandListD3D11Impl.h"
@@ -914,20 +913,12 @@ void DeviceContextD3D11Impl::ClearDepthStencil(ITextureView* pV
{
if (pView == nullptr)
{
- if (m_pSwapChain)
+ if (m_pBoundDepthStencil == nullptr)
{
- pView = m_pSwapChain->GetDepthBufferDSV();
- if (pView == nullptr)
- {
- LOG_WARNING_MESSAGE("Depth buffer is not initialized in the swap chain. Clear operation will be ignored.");
- return;
- }
- }
- else
- {
- LOG_ERROR("Failed to clear default depth stencil buffer: swap chain is not initialized in the device context");
+ LOG_ERROR_MESSAGE("ClearDepthStencil(nullptr, ...) is invalid because no depth-stencil buffer is currently bound.");
return;
}
+ pView = m_pBoundDepthStencil;
}
#ifdef DEVELOPMENT
@@ -949,15 +940,14 @@ void DeviceContextD3D11Impl::ClearRenderTarget(ITextureView* pView, const float*
{
if (pView == nullptr)
{
- if (m_pSwapChain != nullptr)
- {
- pView = m_pSwapChain->GetCurrentBackBufferRTV();
- }
- else
+ if (m_NumBoundRenderTargets != 1)
{
- LOG_ERROR("Failed to clear default render target: swap chain is not initialized in the device context");
+ LOG_ERROR_MESSAGE("ClearRenderTarget(nullptr, ...) semantic is only allowed when single render target is bound to the context. ",
+ m_NumBoundRenderTargets, " render ",
+ (m_NumBoundRenderTargets != 1 ? "targets are" : "target is"), " currently bound");
return;
}
+ pView = m_pBoundRenderTargets[0];
}
#ifdef DEVELOPMENT
@@ -1294,45 +1284,21 @@ void DeviceContextD3D11Impl::CommitRenderTargets()
ID3D11RenderTargetView* pd3d11RTs[MaxD3D11RTs];
ID3D11DepthStencilView* pd3d11DSV = nullptr;
- if (m_IsDefaultFramebufferBound)
+ for (Uint32 rt = 0; rt < NumRenderTargets; ++rt)
{
- if (m_pSwapChain)
- {
- NumRenderTargets = 1;
- auto* pSwapChainD3D11 = m_pSwapChain.RawPtr<ISwapChainD3D11>();
- auto* pBackBufferViewD3D11 = pSwapChainD3D11->GetCurrentBackBufferRTV();
- pd3d11RTs[0] = static_cast<ID3D11RenderTargetView*>(pBackBufferViewD3D11->GetD3D11View());
- VERIFY_EXPR(pd3d11RTs[0] != nullptr);
- if (auto* pDepthBufferViewD3D11 = pSwapChainD3D11->GetDepthBufferDSV())
- {
- pd3d11DSV = static_cast<ID3D11DepthStencilView*>(pDepthBufferViewD3D11->GetD3D11View());
- VERIFY_EXPR(pd3d11DSV != nullptr);
- }
- }
- else
- {
- LOG_ERROR("Failed to commit default render target and depth stencil: swap chain is not initialized in the device context");
- return;
- }
+ auto* pViewD3D11 = m_pBoundRenderTargets[rt].RawPtr();
+ pd3d11RTs[rt] = pViewD3D11 != nullptr ? static_cast<ID3D11RenderTargetView*>(pViewD3D11->GetD3D11View()) : nullptr;
}
- else
- {
- for (Uint32 rt = 0; rt < NumRenderTargets; ++rt)
- {
- auto* pViewD3D11 = m_pBoundRenderTargets[rt].RawPtr();
- pd3d11RTs[rt] = pViewD3D11 != nullptr ? static_cast<ID3D11RenderTargetView*>(pViewD3D11->GetD3D11View()) : nullptr;
- }
- if (m_pBoundDepthStencil != nullptr)
- {
- pd3d11DSV = static_cast<ID3D11DepthStencilView*>(m_pBoundDepthStencil->GetD3D11View());
- }
+ if (m_pBoundDepthStencil != nullptr)
+ {
+ pd3d11DSV = static_cast<ID3D11DepthStencilView*>(m_pBoundDepthStencil->GetD3D11View());
}
auto& NumCommittedPixelShaderUAVs = m_NumCommittedUAVs[PSInd];
if (NumCommittedPixelShaderUAVs > 0)
{
- m_pd3d11DeviceContext->OMSetRenderTargetsAndUnorderedAccessViews(NumRenderTargets, pd3d11RTs, pd3d11DSV,
+ m_pd3d11DeviceContext->OMSetRenderTargetsAndUnorderedAccessViews(NumRenderTargets, NumRenderTargets > 0 ? pd3d11RTs : nullptr, pd3d11DSV,
0, D3D11_KEEP_UNORDERED_ACCESS_VIEWS, nullptr, nullptr);
auto CommittedD3D11UAVs = m_CommittedD3D11UAVs[PSInd];
@@ -1347,7 +1313,7 @@ void DeviceContextD3D11Impl::CommitRenderTargets()
}
else
{
- m_pd3d11DeviceContext->OMSetRenderTargets(NumRenderTargets, pd3d11RTs, pd3d11DSV);
+ m_pd3d11DeviceContext->OMSetRenderTargets(NumRenderTargets, NumRenderTargets > 0 ? pd3d11RTs : nullptr, pd3d11DSV);
}
}
diff --git a/Graphics/GraphicsEngineD3D11/src/EngineFactoryD3D11.cpp b/Graphics/GraphicsEngineD3D11/src/EngineFactoryD3D11.cpp
index 161ab79c..bfc22eaa 100644
--- a/Graphics/GraphicsEngineD3D11/src/EngineFactoryD3D11.cpp
+++ b/Graphics/GraphicsEngineD3D11/src/EngineFactoryD3D11.cpp
@@ -286,39 +286,8 @@ void EngineFactoryD3D11Impl::CreateSwapChainD3D11(IRenderDevice* pDev
auto* pDeviceContextD3D11 = ValidatedCast<DeviceContextD3D11Impl>(pImmediateContext);
auto& RawMemAllocator = GetRawAllocator();
- if (pDeviceContextD3D11->GetSwapChain() != nullptr && SCDesc.IsPrimary)
- {
- LOG_ERROR_AND_THROW("Another swap chain labeled as primary has already been created. "
- "There must only be one primary swap chain.");
- }
-
auto* pSwapChainD3D11 = NEW_RC_OBJ(RawMemAllocator, "SwapChainD3D11Impl instance", SwapChainD3D11Impl)(SCDesc, FSDesc, pDeviceD3D11, pDeviceContextD3D11, pNativeWndHandle);
pSwapChainD3D11->QueryInterface(IID_SwapChain, reinterpret_cast<IObject**>(ppSwapChain));
-
- if (SCDesc.IsPrimary)
- {
- pDeviceContextD3D11->SetSwapChain(pSwapChainD3D11);
- // Bind default render target
- pDeviceContextD3D11->SetRenderTargets(0, nullptr, nullptr, RESOURCE_STATE_TRANSITION_MODE_TRANSITION);
- // Set default viewport
- pDeviceContextD3D11->SetViewports(1, nullptr, 0, 0);
-
- auto NumDeferredCtx = pDeviceD3D11->GetNumDeferredContexts();
- for (size_t ctx = 0; ctx < NumDeferredCtx; ++ctx)
- {
- if (auto pDeferredCtx = pDeviceD3D11->GetDeferredContext(ctx))
- {
- auto* pDeferredCtxD3D11 = pDeferredCtx.RawPtr<DeviceContextD3D11Impl>();
- pDeferredCtxD3D11->SetSwapChain(pSwapChainD3D11);
- // Do not bind default render target and viewport to be
- // consistent with D3D12
- //// Bind default render target
- //pDeferredCtxD3D11->SetRenderTargets( 0, nullptr, nullptr );
- //// Set default viewport
- //pDeferredCtxD3D11->SetViewports( 1, nullptr, 0, 0 );
- }
- }
- }
}
catch (const std::runtime_error&)
{
diff --git a/Graphics/GraphicsEngineD3D11/src/SwapChainD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/SwapChainD3D11Impl.cpp
index 003c70c4..305a0b93 100644
--- a/Graphics/GraphicsEngineD3D11/src/SwapChainD3D11Impl.cpp
+++ b/Graphics/GraphicsEngineD3D11/src/SwapChainD3D11Impl.cpp
@@ -157,9 +157,14 @@ void SwapChainD3D11Impl::UpdateSwapChain(bool CreateNew)
VERIFY(pDeviceContext, "Immediate context has been released");
if (pDeviceContext)
{
- auto* pImmediateCtxD3D11 = pDeviceContext.RawPtr<DeviceContextD3D11Impl>();
- ITextureView* pBackBufferRTVs[] = {m_pRenderTargetView};
- bool RebindRenderTargets = UnbindRenderTargets(pImmediateCtxD3D11, pBackBufferRTVs, 1, m_pDepthStencilView);
+ auto* pImmediateCtxD3D11 = pDeviceContext.RawPtr<DeviceContextD3D11Impl>();
+ auto* pCurrentBackBuffer = ValidatedCast<TextureBaseD3D11>(m_pRenderTargetView->GetTexture());
+ auto RenderTargetsReset = pImmediateCtxD3D11->UnbindTextureFromFramebuffer(pCurrentBackBuffer, false);
+ if (RenderTargetsReset)
+ {
+ LOG_INFO_MESSAGE_ONCE("Resizing the swap chain requires back and depth-stencil buffers to be unbound from the device context. "
+ "An application should use SetRenderTargets() to restore them.");
+ }
// Swap chain cannot be resized until all references are released
m_pRenderTargetView.Release();
@@ -197,13 +202,6 @@ void SwapChainD3D11Impl::UpdateSwapChain(bool CreateNew)
}
CreateRTVandDSV();
-
- if (m_SwapChainDesc.IsPrimary && RebindRenderTargets)
- {
- // Set default render target and viewport
- pImmediateCtxD3D11->SetRenderTargets(0, nullptr, nullptr, RESOURCE_STATE_TRANSITION_MODE_TRANSITION);
- pImmediateCtxD3D11->SetViewports(1, nullptr, 0, 0);
- }
}
catch (const std::runtime_error&)
{