From 97a72224ba1788ade4890b3f737f150b240610e1 Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Sat, 1 Dec 2018 10:42:38 -0800 Subject: Added explicit state transition mode to ClearRenderTarget() command --- .../GraphicsEngineD3D12/include/CommandContext.h | 2 +- .../include/DeviceContextD3D12Impl.h | 2 +- Graphics/GraphicsEngineD3D12/src/CommandContext.cpp | 20 +++++++++++++++++--- .../src/DeviceContextD3D12Impl.cpp | 4 ++-- 4 files changed, 21 insertions(+), 7 deletions(-) (limited to 'Graphics/GraphicsEngineD3D12') diff --git a/Graphics/GraphicsEngineD3D12/include/CommandContext.h b/Graphics/GraphicsEngineD3D12/include/CommandContext.h index 9de975df..6b89ba2c 100644 --- a/Graphics/GraphicsEngineD3D12/include/CommandContext.h +++ b/Graphics/GraphicsEngineD3D12/include/CommandContext.h @@ -174,7 +174,7 @@ protected: class GraphicsContext : public CommandContext { public: - void ClearRenderTarget( ITextureViewD3D12 *pRTV, const float *Color ); + void ClearRenderTarget( ITextureViewD3D12 *pRTV, const float *Color, CLEAR_RENDER_TARGET_STATE_TRANSITION_MODE StateTransitionMode ); void ClearDepthStencil( ITextureViewD3D12 *pDSV, D3D12_CLEAR_FLAGS ClearFlags, float Depth, UINT8 Stencil ); void SetRootSignature( ID3D12RootSignature *pRootSig ) diff --git a/Graphics/GraphicsEngineD3D12/include/DeviceContextD3D12Impl.h b/Graphics/GraphicsEngineD3D12/include/DeviceContextD3D12Impl.h index 7eaebfcd..ce36f432 100644 --- a/Graphics/GraphicsEngineD3D12/include/DeviceContextD3D12Impl.h +++ b/Graphics/GraphicsEngineD3D12/include/DeviceContextD3D12Impl.h @@ -91,7 +91,7 @@ public: virtual void ClearDepthStencil( ITextureView* pView, CLEAR_DEPTH_STENCIL_FLAGS ClearFlags, float fDepth, Uint8 Stencil)override final; - virtual void ClearRenderTarget( ITextureView* pView, const float* RGBA )override final; + virtual void ClearRenderTarget( ITextureView* pView, const float* RGBA, CLEAR_RENDER_TARGET_STATE_TRANSITION_MODE StateTransitionMode )override final; virtual void Flush()override final; diff --git a/Graphics/GraphicsEngineD3D12/src/CommandContext.cpp b/Graphics/GraphicsEngineD3D12/src/CommandContext.cpp index a08fe172..992b6e3b 100644 --- a/Graphics/GraphicsEngineD3D12/src/CommandContext.cpp +++ b/Graphics/GraphicsEngineD3D12/src/CommandContext.cpp @@ -191,11 +191,25 @@ void CommandContext::ClearUAVUint( ITextureViewD3D12* pTexView, const UINT* Colo } -void GraphicsContext::ClearRenderTarget( ITextureViewD3D12* pRTV, const float* Color ) +void GraphicsContext::ClearRenderTarget( ITextureViewD3D12* pRTV, const float* Color, CLEAR_RENDER_TARGET_STATE_TRANSITION_MODE StateTransitionMode ) { auto *pTexture = ValidatedCast( pRTV->GetTexture() ); - if (pTexture->IsInKnownState() && !pTexture->CheckState(RESOURCE_STATE_RENDER_TARGET)) - TransitionResource(pTexture, RESOURCE_STATE_RENDER_TARGET); + if (StateTransitionMode == CLEAR_RENDER_TARGET_TRANSITION_STATE) + { + if (pTexture->IsInKnownState() && !pTexture->CheckState(RESOURCE_STATE_RENDER_TARGET)) + TransitionResource(pTexture, RESOURCE_STATE_RENDER_TARGET); + } +#ifdef DEVELOPMENT + else if (StateTransitionMode == CLEAR_RENDER_TARGET_VERIFY_STATE) + { + if (pTexture->IsInKnownState() && !pTexture->CheckState(RESOURCE_STATE_RENDER_TARGET)) + { + LOG_ERROR_MESSAGE("Render target '", pTexture->GetDesc().Name, "' being cleared is not transitioned to RESOURCE_STATE_RENDER_TARGET state. " + "Actual texture state: ", GetResourceStateString(pTexture->GetState()), ". " + "Use CLEAR_RENDER_TARGET_TRANSITION_STATE mode or explicitly transition the resource using IDeviceContext::TransitionResourceStates() method."); + } + } +#endif FlushResourceBarriers(); m_pCommandList->ClearRenderTargetView(pRTV->GetCPUDescriptorHandle(), Color, 0, nullptr); } diff --git a/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp index 01bc7e7a..3bd3a096 100644 --- a/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp @@ -617,7 +617,7 @@ namespace Diligent ++m_State.NumCommands; } - void DeviceContextD3D12Impl::ClearRenderTarget( ITextureView* pView, const float* RGBA ) + void DeviceContextD3D12Impl::ClearRenderTarget( ITextureView* pView, const float* RGBA, CLEAR_RENDER_TARGET_STATE_TRANSITION_MODE StateTransitionMode ) { ITextureViewD3D12 *pd3d12RTV = nullptr; if( pView != nullptr ) @@ -647,7 +647,7 @@ namespace Diligent // The full extent of the resource view is always cleared. // Viewport and scissor settings are not applied?? - GetCmdContext().AsGraphicsContext().ClearRenderTarget( pd3d12RTV, RGBA ); + GetCmdContext().AsGraphicsContext().ClearRenderTarget( pd3d12RTV, RGBA, StateTransitionMode ); ++m_State.NumCommands; } -- cgit v1.2.3