summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngine
diff options
context:
space:
mode:
authorassiduous <assiduous@diligentgraphics.com>2019-12-19 18:11:08 +0000
committerassiduous <assiduous@diligentgraphics.com>2019-12-19 18:11:08 +0000
commitc32095993f3e5734b3b6a112aeef0a9536db8f7d (patch)
tree998e0cf73c2417606913152cf53286cc22d4afde /Graphics/GraphicsEngine
parentAdded CopyTexture tests (diff)
downloadDiligentCore-c32095993f3e5734b3b6a112aeef0a9536db8f7d.tar.gz
DiligentCore-c32095993f3e5734b3b6a112aeef0a9536db8f7d.zip
Added ClearRenderTarget test; fixed issue with bound render targets in D3D12 and Vk backends
Diffstat (limited to 'Graphics/GraphicsEngine')
-rw-r--r--Graphics/GraphicsEngine/include/DeviceContextBase.h80
1 files changed, 78 insertions, 2 deletions
diff --git a/Graphics/GraphicsEngine/include/DeviceContextBase.h b/Graphics/GraphicsEngine/include/DeviceContextBase.h
index c822dacf..d357c4f6 100644
--- a/Graphics/GraphicsEngine/include/DeviceContextBase.h
+++ b/Graphics/GraphicsEngine/include/DeviceContextBase.h
@@ -190,7 +190,7 @@ public:
/// Returns the render device
IRenderDevice* GetDevice() { return m_pDevice; }
- inline void ResetRenderTargets();
+ virtual void ResetRenderTargets();
bool IsDeferred() const { return m_bIsDeferred; }
@@ -204,6 +204,17 @@ protected:
/// Clears all cached resources
inline void ClearStateCache();
+ /// Checks if the texture is currently bound as a render target.
+ bool CheckIfBoundAsRenderTarget(TextureImplType* pTexture);
+
+ /// Checks if the texture is currently bound as depth-stencil buffer.
+ bool CheckIfBoundAsDepthStencil(TextureImplType* pTexture);
+
+ /// Checks if the texture is bound as a render target or depth-stencil buffer and
+ /// resets render targets if it is.
+ bool UnbindTextureFromFramebuffer(TextureImplType* pTexture, bool bShowMessage);
+
+
#ifdef DEVELOPMENT
// clang-format off
bool DvpVerifyDrawArguments (const DrawAttribs& Attribs)const;
@@ -722,7 +733,72 @@ inline void DeviceContextBase<BaseInterface, ImplementationTraits>::ClearStateCa
}
template <typename BaseInterface, typename ImplementationTraits>
-inline void DeviceContextBase<BaseInterface, ImplementationTraits>::ResetRenderTargets()
+bool DeviceContextBase<BaseInterface, ImplementationTraits>::CheckIfBoundAsRenderTarget(TextureImplType* pTexture)
+{
+ if (pTexture == nullptr)
+ return false;
+
+ for (Uint32 rt = 0; rt < m_NumBoundRenderTargets; ++rt)
+ {
+ if (m_pBoundRenderTargets[rt] && m_pBoundRenderTargets[rt]->GetTexture() == pTexture)
+ {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+template <typename BaseInterface, typename ImplementationTraits>
+bool DeviceContextBase<BaseInterface, ImplementationTraits>::CheckIfBoundAsDepthStencil(TextureImplType* pTexture)
+{
+ if (pTexture == nullptr)
+ return false;
+
+ return m_pBoundDepthStencil && m_pBoundDepthStencil->GetTexture() == pTexture;
+}
+
+template <typename BaseInterface, typename ImplementationTraits>
+bool DeviceContextBase<BaseInterface, ImplementationTraits>::UnbindTextureFromFramebuffer(TextureImplType* pTexture, bool bShowMessage)
+{
+ if (pTexture == nullptr)
+ return false;
+
+ if (pTexture->IsInKnownState() && !pTexture->CheckState(RESOURCE_STATE_RENDER_TARGET) && !pTexture->CheckState(RESOURCE_STATE_DEPTH_WRITE))
+ return false;
+
+ bool bResetRenderTargets = false;
+ if (CheckIfBoundAsRenderTarget(pTexture))
+ {
+ if (bShowMessage)
+ {
+ LOG_INFO_MESSAGE("Texture '", pTexture->GetDesc().Name,
+ "' is currently bound as render target and will be unset along with all "
+ "other render targets and depth-stencil buffer. "
+ "Call SetRenderTargets() to reset the render targets.");
+ }
+
+ bResetRenderTargets = true;
+ }
+ else if (CheckIfBoundAsDepthStencil(pTexture))
+ {
+ LOG_INFO_MESSAGE("Texture '", pTexture->GetDesc().Name,
+ "' is currently bound as depth buffer and will be unset along with "
+ "all render targets. Call SetRenderTargets() to reset the render targets.");
+
+ bResetRenderTargets = true;
+ }
+
+ if (bResetRenderTargets)
+ {
+ ResetRenderTargets();
+ }
+
+ return bResetRenderTargets;
+}
+
+template <typename BaseInterface, typename ImplementationTraits>
+void DeviceContextBase<BaseInterface, ImplementationTraits>::ResetRenderTargets()
{
for (Uint32 rt = 0; rt < m_NumBoundRenderTargets; ++rt)
m_pBoundRenderTargets[rt].Release();