diff options
| author | Egor Yusov <egor.yusov@gmail.com> | 2018-12-01 19:45:38 +0000 |
|---|---|---|
| committer | Egor Yusov <egor.yusov@gmail.com> | 2018-12-01 19:45:38 +0000 |
| commit | da6bb5d0d93e550a32da19550df21521ce2da505 (patch) | |
| tree | 82a17cbe9c06967e93e3d258a329ce55afe829ec /Graphics/GraphicsEngineD3D12 | |
| parent | Added explicit state transition mode to ClearRenderTarget() command (diff) | |
| download | DiligentCore-da6bb5d0d93e550a32da19550df21521ce2da505.tar.gz DiligentCore-da6bb5d0d93e550a32da19550df21521ce2da505.zip | |
Added explicit state transition control flags to CLEAR_DEPTH_STENCIL_FLAGS
Diffstat (limited to 'Graphics/GraphicsEngineD3D12')
| -rw-r--r-- | Graphics/GraphicsEngineD3D12/include/CommandContext.h | 2 | ||||
| -rw-r--r-- | Graphics/GraphicsEngineD3D12/src/CommandContext.cpp | 26 | ||||
| -rw-r--r-- | Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp | 5 |
3 files changed, 24 insertions, 9 deletions
diff --git a/Graphics/GraphicsEngineD3D12/include/CommandContext.h b/Graphics/GraphicsEngineD3D12/include/CommandContext.h index 6b89ba2c..35546844 100644 --- a/Graphics/GraphicsEngineD3D12/include/CommandContext.h +++ b/Graphics/GraphicsEngineD3D12/include/CommandContext.h @@ -175,7 +175,7 @@ class GraphicsContext : public CommandContext { public: 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 ClearDepthStencil( ITextureViewD3D12 *pDSV, CLEAR_DEPTH_STENCIL_FLAGS ClearFlags, float Depth, UINT8 Stencil ); void SetRootSignature( ID3D12RootSignature *pRootSig ) { diff --git a/Graphics/GraphicsEngineD3D12/src/CommandContext.cpp b/Graphics/GraphicsEngineD3D12/src/CommandContext.cpp index 992b6e3b..54babb58 100644 --- a/Graphics/GraphicsEngineD3D12/src/CommandContext.cpp +++ b/Graphics/GraphicsEngineD3D12/src/CommandContext.cpp @@ -214,13 +214,31 @@ void GraphicsContext::ClearRenderTarget( ITextureViewD3D12* pRTV, const float* C m_pCommandList->ClearRenderTargetView(pRTV->GetCPUDescriptorHandle(), Color, 0, nullptr); } -void GraphicsContext::ClearDepthStencil( ITextureViewD3D12* pDSV, D3D12_CLEAR_FLAGS ClearFlags, float Depth, UINT8 Stencil ) +void GraphicsContext::ClearDepthStencil( ITextureViewD3D12* pDSV, CLEAR_DEPTH_STENCIL_FLAGS ClearFlags, float Depth, UINT8 Stencil ) { auto *pTexture = ValidatedCast<TextureD3D12Impl>( pDSV->GetTexture() ); - if (pTexture->IsInKnownState() && !pTexture->CheckState(RESOURCE_STATE_DEPTH_WRITE)) - TransitionResource( pTexture, RESOURCE_STATE_DEPTH_WRITE); + if (ClearFlags & CLEAR_DEPTH_STENCIL_TRANSITION_STATE_FLAG) + { + if (pTexture->IsInKnownState() && !pTexture->CheckState(RESOURCE_STATE_DEPTH_WRITE)) + TransitionResource( pTexture, RESOURCE_STATE_DEPTH_WRITE); + } +#ifdef DEVELOPMENT + else if(ClearFlags & CLEAR_DEPTH_STENCIL_VERIFY_STATE_FLAG) + { + if (pTexture->IsInKnownState() && !pTexture->CheckState(RESOURCE_STATE_DEPTH_WRITE)) + { + LOG_ERROR_MESSAGE("Depth-stencil buffer '", pTexture->GetDesc().Name, "' being cleared is not transitioned to RESOURCE_STATE_DEPTH_WRITE state. " + "Actual texture state: ", GetResourceStateString(pTexture->GetState()), ". " + "Use CLEAR_DEPTH_STENCIL_TRANSITION_STATE_FLAG flag or explicitly transition the resource using IDeviceContext::TransitionResourceStates() method."); + } + } +#endif FlushResourceBarriers(); - m_pCommandList->ClearDepthStencilView(pDSV->GetCPUDescriptorHandle(), ClearFlags, Depth, Stencil, 0, nullptr); + + D3D12_CLEAR_FLAGS d3d12ClearFlags = (D3D12_CLEAR_FLAGS)0; + if( ClearFlags & CLEAR_DEPTH_FLAG ) d3d12ClearFlags |= D3D12_CLEAR_FLAG_DEPTH; + if( ClearFlags & CLEAR_STENCIL_FLAG ) d3d12ClearFlags |= D3D12_CLEAR_FLAG_STENCIL; + m_pCommandList->ClearDepthStencilView(pDSV->GetCPUDescriptorHandle(), d3d12ClearFlags, Depth, Stencil, 0, nullptr); } diff --git a/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp index 3bd3a096..e54dbc8b 100644 --- a/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp @@ -608,12 +608,9 @@ namespace Diligent return; } } - D3D12_CLEAR_FLAGS d3d12ClearFlags = (D3D12_CLEAR_FLAGS)0; - if( ClearFlags & CLEAR_DEPTH_FLAG ) d3d12ClearFlags |= D3D12_CLEAR_FLAG_DEPTH; - if( ClearFlags & CLEAR_STENCIL_FLAG ) d3d12ClearFlags |= D3D12_CLEAR_FLAG_STENCIL; // The full extent of the resource view is always cleared. // Viewport and scissor settings are not applied?? - GetCmdContext().AsGraphicsContext().ClearDepthStencil( pDSVD3D12, d3d12ClearFlags, fDepth, Stencil ); + GetCmdContext().AsGraphicsContext().ClearDepthStencil( pDSVD3D12, ClearFlags, fDepth, Stencil ); ++m_State.NumCommands; } |
