summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngineD3D12
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/GraphicsEngineD3D12
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/GraphicsEngineD3D12')
-rw-r--r--Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp51
-rw-r--r--Graphics/GraphicsEngineD3D12/src/EngineFactoryD3D12.cpp29
-rw-r--r--Graphics/GraphicsEngineD3D12/src/SwapChainD3D12Impl.cpp28
3 files changed, 27 insertions, 81 deletions
diff --git a/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp
index 5d35eb82..73238d21 100644
--- a/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp
+++ b/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp
@@ -25,7 +25,6 @@
#include <sstream>
#include "RenderDeviceD3D12Impl.h"
#include "DeviceContextD3D12Impl.h"
-#include "SwapChainD3D12.h"
#include "PipelineStateD3D12Impl.h"
#include "CommandContext.h"
#include "TextureD3D12Impl.h"
@@ -618,20 +617,12 @@ void DeviceContextD3D12Impl::ClearDepthStencil(ITextureView* pV
}
else
{
- if (m_pSwapChain)
+ if (m_pBoundDepthStencil == nullptr)
{
- pViewD3D12 = ValidatedCast<ITextureViewD3D12>(m_pSwapChain.RawPtr<ISwapChainD3D12>()->GetDepthBufferDSV());
- if (pViewD3D12 == 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;
}
+ pViewD3D12 = m_pBoundDepthStencil;
}
auto* pTextureD3D12 = ValidatedCast<TextureD3D12Impl>(pViewD3D12->GetTexture());
@@ -661,15 +652,14 @@ void DeviceContextD3D12Impl::ClearRenderTarget(ITextureView* pView, const float*
}
else
{
- if (m_pSwapChain)
+ if (m_NumBoundRenderTargets != 1)
{
- pViewD3D12 = ValidatedCast<ITextureViewD3D12>(m_pSwapChain.RawPtr<ISwapChainD3D12>()->GetCurrentBackBufferRTV());
- }
- else
- {
- 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;
}
+ pViewD3D12 = m_pBoundRenderTargets[0];
}
static constexpr float Zero[4] = {0.f, 0.f, 0.f, 0.f};
@@ -930,27 +920,10 @@ void DeviceContextD3D12Impl::CommitRenderTargets(RESOURCE_STATE_TRANSITION_MODE
ITextureViewD3D12* ppRTVs[MaxD3D12RTs]; // Do not initialize with zeroes!
ITextureViewD3D12* pDSV = nullptr;
- if (m_IsDefaultFramebufferBound)
- {
- if (m_pSwapChain)
- {
- NumRenderTargets = 1;
- auto* pSwapChainD3D12 = m_pSwapChain.RawPtr<ISwapChainD3D12>();
- ppRTVs[0] = ValidatedCast<ITextureViewD3D12>(pSwapChainD3D12->GetCurrentBackBufferRTV());
- pDSV = ValidatedCast<ITextureViewD3D12>(pSwapChainD3D12->GetDepthBufferDSV());
- }
- else
- {
- LOG_WARNING_MESSAGE("Failed to bind default render targets and depth-stencil buffer: swap chain is not initialized in the device context");
- return;
- }
- }
- else
- {
- for (Uint32 rt = 0; rt < NumRenderTargets; ++rt)
- ppRTVs[rt] = m_pBoundRenderTargets[rt].RawPtr();
- pDSV = m_pBoundDepthStencil.RawPtr();
- }
+
+ for (Uint32 rt = 0; rt < NumRenderTargets; ++rt)
+ ppRTVs[rt] = m_pBoundRenderTargets[rt].RawPtr();
+ pDSV = m_pBoundDepthStencil.RawPtr();
auto& CmdCtx = GetCmdContext();
diff --git a/Graphics/GraphicsEngineD3D12/src/EngineFactoryD3D12.cpp b/Graphics/GraphicsEngineD3D12/src/EngineFactoryD3D12.cpp
index 0526f672..28c62a1c 100644
--- a/Graphics/GraphicsEngineD3D12/src/EngineFactoryD3D12.cpp
+++ b/Graphics/GraphicsEngineD3D12/src/EngineFactoryD3D12.cpp
@@ -391,37 +391,8 @@ void EngineFactoryD3D12Impl::CreateSwapChainD3D12(IRenderDevice* pDev
auto* pDeviceContextD3D12 = ValidatedCast<DeviceContextD3D12Impl>(pImmediateContext);
auto& RawMemAllocator = GetRawAllocator();
- if (pDeviceContextD3D12->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* pSwapChainD3D12 = NEW_RC_OBJ(RawMemAllocator, "SwapChainD3D12Impl instance", SwapChainD3D12Impl)(SCDesc, FSDesc, pDeviceD3D12, pDeviceContextD3D12, pNativeWndHandle);
pSwapChainD3D12->QueryInterface(IID_SwapChain, reinterpret_cast<IObject**>(ppSwapChain));
-
- if (SCDesc.IsPrimary)
- {
- pDeviceContextD3D12->SetSwapChain(pSwapChainD3D12);
- // Bind default render target
- pDeviceContextD3D12->SetRenderTargets(0, nullptr, nullptr, RESOURCE_STATE_TRANSITION_MODE_TRANSITION);
- // Set default viewport
- pDeviceContextD3D12->SetViewports(1, nullptr, 0, 0);
-
- auto NumDeferredCtx = pDeviceD3D12->GetNumDeferredContexts();
- for (size_t ctx = 0; ctx < NumDeferredCtx; ++ctx)
- {
- if (auto pDeferredCtx = pDeviceD3D12->GetDeferredContext(ctx))
- {
- auto* pDeferredCtxD3D12 = pDeferredCtx.RawPtr<DeviceContextD3D12Impl>();
- pDeferredCtxD3D12->SetSwapChain(pSwapChainD3D12);
- // We cannot bind default render target here because
- // there is no guarantee that deferred context will be used
- // in this frame. It is an error to bind
- // RTV of an inactive buffer in the swap chain
- }
- }
- }
}
catch (const std::runtime_error&)
{
diff --git a/Graphics/GraphicsEngineD3D12/src/SwapChainD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/SwapChainD3D12Impl.cpp
index fe9d135f..74cedd1c 100644
--- a/Graphics/GraphicsEngineD3D12/src/SwapChainD3D12Impl.cpp
+++ b/Graphics/GraphicsEngineD3D12/src/SwapChainD3D12Impl.cpp
@@ -177,11 +177,18 @@ void SwapChainD3D12Impl::UpdateSwapChain(bool CreateNew)
try
{
auto* pImmediateCtxD3D12 = pDeviceContext.RawPtr<DeviceContextD3D12Impl>();
+ bool RenderTargetsReset = false;
+ for (Uint32 i = 0; i < m_pBackBufferRTV.size() && !RenderTargetsReset; ++i)
+ {
+ auto* pCurrentBackBuffer = ValidatedCast<TextureD3D12Impl>(m_pBackBufferRTV[i]->GetTexture());
+ RenderTargetsReset = pImmediateCtxD3D12->UnbindTextureFromFramebuffer(pCurrentBackBuffer, false);
+ }
- std::vector<ITextureView*> pBackBufferRTVs(m_pBackBufferRTV.size());
- for (size_t i = 0; i < m_pBackBufferRTV.size(); ++i)
- pBackBufferRTVs[i] = m_pBackBufferRTV[i];
- bool RebindRenderTargets = UnbindRenderTargets(pImmediateCtxD3D12, pBackBufferRTVs.data(), static_cast<Uint32>(m_pBackBufferRTV.size()), m_pDepthBufferDSV);
+ 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.");
+ }
// All references to the swap chain must be released before it can be resized
m_pBackBufferRTV.clear();
@@ -196,9 +203,11 @@ void SwapChainD3D12Impl::UpdateSwapChain(bool CreateNew)
m_pSwapChain.Release();
m_pRenderDevice.RawPtr<RenderDeviceD3D12Impl>()->LockCmdQueueAndRun(
0,
- [this](ICommandQueueD3D12* pCmdQueue) {
+ [this](ICommandQueueD3D12* pCmdQueue) //
+ {
CreateDXGISwapChain(pCmdQueue->GetD3D12CommandQueue());
- });
+ } //
+ );
}
else
{
@@ -212,13 +221,6 @@ void SwapChainD3D12Impl::UpdateSwapChain(bool CreateNew)
}
InitBuffersAndViews();
-
- if (m_SwapChainDesc.IsPrimary && RebindRenderTargets)
- {
- // Set default render target and viewport
- pDeviceContext->SetRenderTargets(0, nullptr, nullptr, RESOURCE_STATE_TRANSITION_MODE_TRANSITION);
- pDeviceContext->SetViewports(1, nullptr, 0, 0);
- }
}
catch (const std::runtime_error&)
{